1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2020 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
105 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
106 attributes_section_data_(NULL
)
108 this->set_abiversion(0);
112 { delete this->attributes_section_data_
; }
114 // Read the symbols then set up st_other vector.
116 do_read_symbols(Read_symbols_data
*);
118 // Arrange to always relocate .toc first.
120 do_relocate_sections(
121 const Symbol_table
* symtab
, const Layout
* layout
,
122 const unsigned char* pshdrs
, Output_file
* of
,
123 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
125 // The .toc section index.
132 // Mark .toc entry at OFF as not optimizable.
134 set_no_toc_opt(Address off
)
136 if (this->no_toc_opt_
.empty())
137 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
140 if (off
< this->no_toc_opt_
.size())
141 this->no_toc_opt_
[off
] = true;
144 // Mark the entire .toc as not optimizable.
148 this->no_toc_opt_
.resize(1);
149 this->no_toc_opt_
[0] = true;
152 // Return true if code using the .toc entry at OFF should not be edited.
154 no_toc_opt(Address off
) const
156 if (this->no_toc_opt_
.empty())
159 if (off
>= this->no_toc_opt_
.size())
161 return this->no_toc_opt_
[off
];
164 // The .got2 section shndx.
169 return this->special_
;
174 // The .opd section shndx.
181 return this->special_
;
184 // Init OPD entry arrays.
186 init_opd(size_t opd_size
)
188 size_t count
= this->opd_ent_ndx(opd_size
);
189 this->opd_ent_
.resize(count
);
192 // Return section and offset of function entry for .opd + R_OFF.
194 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
196 size_t ndx
= this->opd_ent_ndx(r_off
);
197 gold_assert(ndx
< this->opd_ent_
.size());
198 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
200 *value
= this->opd_ent_
[ndx
].off
;
201 return this->opd_ent_
[ndx
].shndx
;
204 // Set section and offset of function entry for .opd + R_OFF.
206 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
208 size_t ndx
= this->opd_ent_ndx(r_off
);
209 gold_assert(ndx
< this->opd_ent_
.size());
210 this->opd_ent_
[ndx
].shndx
= shndx
;
211 this->opd_ent_
[ndx
].off
= value
;
214 // Return discard flag for .opd + R_OFF.
216 get_opd_discard(Address r_off
) const
218 size_t ndx
= this->opd_ent_ndx(r_off
);
219 gold_assert(ndx
< this->opd_ent_
.size());
220 return this->opd_ent_
[ndx
].discard
;
223 // Set discard flag for .opd + R_OFF.
225 set_opd_discard(Address r_off
)
227 size_t ndx
= this->opd_ent_ndx(r_off
);
228 gold_assert(ndx
< this->opd_ent_
.size());
229 this->opd_ent_
[ndx
].discard
= true;
234 { return this->opd_valid_
; }
238 { this->opd_valid_
= true; }
240 // Examine .rela.opd to build info about function entry points.
242 scan_opd_relocs(size_t reloc_count
,
243 const unsigned char* prelocs
,
244 const unsigned char* plocal_syms
);
246 // Returns true if a code sequence loading a TOC entry can be
247 // converted into code calculating a TOC pointer relative offset.
249 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
253 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
254 const Symbol_value
<size
>* psymval
,
258 // Perform the Sized_relobj_file method, then set up opd info from
261 do_read_relocs(Read_relocs_data
*);
264 do_find_special_sections(Read_symbols_data
* sd
);
266 // Adjust this local symbol value. Return false if the symbol
267 // should be discarded from the output file.
269 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
271 if (size
== 64 && this->opd_shndx() != 0)
274 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
276 if (this->get_opd_discard(lv
->input_value()))
284 { return &this->access_from_map_
; }
286 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
287 // section at DST_OFF.
289 add_reference(Relobj
* src_obj
,
290 unsigned int src_indx
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
293 Section_id
src_id(src_obj
, src_indx
);
294 this->access_from_map_
[dst_off
].insert(src_id
);
297 // Add a reference to the code section specified by the .opd entry
300 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
302 size_t ndx
= this->opd_ent_ndx(dst_off
);
303 if (ndx
>= this->opd_ent_
.size())
304 this->opd_ent_
.resize(ndx
+ 1);
305 this->opd_ent_
[ndx
].gc_mark
= true;
309 process_gc_mark(Symbol_table
* symtab
)
311 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
312 if (this->opd_ent_
[i
].gc_mark
)
314 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
315 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
319 // Return offset in output GOT section that this object will use
320 // as a TOC pointer. Won't be just a constant with multi-toc support.
322 toc_base_offset() const
326 set_has_small_toc_reloc()
327 { has_small_toc_reloc_
= true; }
330 has_small_toc_reloc() const
331 { return has_small_toc_reloc_
; }
334 set_has_14bit_branch(unsigned int shndx
)
336 if (shndx
>= this->has14_
.size())
337 this->has14_
.resize(shndx
+ 1);
338 this->has14_
[shndx
] = true;
342 has_14bit_branch(unsigned int shndx
) const
343 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
346 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
348 if (shndx
>= this->stub_table_index_
.size())
349 this->stub_table_index_
.resize(shndx
+ 1, -1);
350 this->stub_table_index_
[shndx
] = stub_index
;
353 Stub_table
<size
, big_endian
>*
354 stub_table(unsigned int shndx
)
356 if (shndx
< this->stub_table_index_
.size())
358 Target_powerpc
<size
, big_endian
>* target
359 = static_cast<Target_powerpc
<size
, big_endian
>*>(
360 parameters
->sized_target
<size
, big_endian
>());
361 unsigned int indx
= this->stub_table_index_
[shndx
];
362 if (indx
< target
->stub_tables().size())
363 return target
->stub_tables()[indx
];
371 this->stub_table_index_
.clear();
376 { return this->uniq_
; }
380 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
382 // Set ABI version for input and output
384 set_abiversion(int ver
);
387 st_other (unsigned int symndx
) const
389 return this->st_other_
[symndx
];
393 ppc64_local_entry_offset(const Symbol
* sym
) const
394 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
397 ppc64_local_entry_offset(unsigned int symndx
) const
398 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
401 ppc64_needs_toc(const Symbol
* sym
) const
402 { return sym
->nonvis() > 1 << 3; }
405 ppc64_needs_toc(unsigned int symndx
) const
406 { return this->st_other_
[symndx
] > 1 << 5; }
408 // The contents of the .gnu.attributes section if there is one.
409 const Attributes_section_data
*
410 attributes_section_data() const
411 { return this->attributes_section_data_
; }
422 // Return index into opd_ent_ array for .opd entry at OFF.
423 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
424 // apart when the language doesn't use the last 8-byte word, the
425 // environment pointer. Thus dividing the entry section offset by
426 // 16 will give an index into opd_ent_ that works for either layout
427 // of .opd. (It leaves some elements of the vector unused when .opd
428 // entries are spaced 24 bytes apart, but we don't know the spacing
429 // until relocations are processed, and in any case it is possible
430 // for an object to have some entries spaced 16 bytes apart and
431 // others 24 bytes apart.)
433 opd_ent_ndx(size_t off
) const
436 // Per object unique identifier
439 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
440 unsigned int special_
;
442 // For 64-bit the .rela.toc and .toc section shdnx.
443 unsigned int relatoc_
;
446 // For 64-bit, whether this object uses small model relocs to access
448 bool has_small_toc_reloc_
;
450 // Set at the start of gc_process_relocs, when we know opd_ent_
451 // vector is valid. The flag could be made atomic and set in
452 // do_read_relocs with memory_order_release and then tested with
453 // memory_order_acquire, potentially resulting in fewer entries in
458 elfcpp::Elf_Word e_flags_
;
460 // For 64-bit, an array with one entry per 64-bit word in the .toc
461 // section, set if accesses using that word cannot be optimised.
462 std::vector
<bool> no_toc_opt_
;
464 // The first 8-byte word of an OPD entry gives the address of the
465 // entry point of the function. Relocatable object files have a
466 // relocation on this word. The following vector records the
467 // section and offset specified by these relocations.
468 std::vector
<Opd_ent
> opd_ent_
;
470 // References made to this object's .opd section when running
471 // gc_process_relocs for another object, before the opd_ent_ vector
472 // is valid for this object.
473 Access_from access_from_map_
;
475 // Whether input section has a 14-bit branch reloc.
476 std::vector
<bool> has14_
;
478 // The stub table to use for a given input section.
479 std::vector
<unsigned int> stub_table_index_
;
481 // ELF st_other field for local symbols.
482 std::vector
<unsigned char> st_other_
;
484 // Object attributes if there is a .gnu.attributes section.
485 Attributes_section_data
* attributes_section_data_
;
488 template<int size
, bool big_endian
>
489 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
492 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
494 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
495 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
496 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
497 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
498 attributes_section_data_(NULL
)
500 this->set_abiversion(0);
504 { delete this->attributes_section_data_
; }
506 // Call Sized_dynobj::do_read_symbols to read the symbols then
507 // read .opd from a dynamic object, filling in opd_ent_ vector,
509 do_read_symbols(Read_symbols_data
*);
511 // The .opd section shndx.
515 return this->opd_shndx_
;
518 // The .opd section address.
522 return this->opd_address_
;
525 // Init OPD entry arrays.
527 init_opd(size_t opd_size
)
529 size_t count
= this->opd_ent_ndx(opd_size
);
530 this->opd_ent_
.resize(count
);
533 // Return section and offset of function entry for .opd + R_OFF.
535 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
537 size_t ndx
= this->opd_ent_ndx(r_off
);
538 gold_assert(ndx
< this->opd_ent_
.size());
539 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
541 *value
= this->opd_ent_
[ndx
].off
;
542 return this->opd_ent_
[ndx
].shndx
;
545 // Set section and offset of function entry for .opd + R_OFF.
547 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
549 size_t ndx
= this->opd_ent_ndx(r_off
);
550 gold_assert(ndx
< this->opd_ent_
.size());
551 this->opd_ent_
[ndx
].shndx
= shndx
;
552 this->opd_ent_
[ndx
].off
= value
;
557 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
559 // Set ABI version for input and output.
561 set_abiversion(int ver
);
563 // The contents of the .gnu.attributes section if there is one.
564 const Attributes_section_data
*
565 attributes_section_data() const
566 { return this->attributes_section_data_
; }
569 // Used to specify extent of executable sections.
572 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
573 : start(start_
), len(len_
), shndx(shndx_
)
577 operator<(const Sec_info
& that
) const
578 { return this->start
< that
.start
; }
591 // Return index into opd_ent_ array for .opd entry at OFF.
593 opd_ent_ndx(size_t off
) const
596 // For 64-bit the .opd section shndx and address.
597 unsigned int opd_shndx_
;
598 Address opd_address_
;
601 elfcpp::Elf_Word e_flags_
;
603 // The first 8-byte word of an OPD entry gives the address of the
604 // entry point of the function. Records the section and offset
605 // corresponding to the address. Note that in dynamic objects,
606 // offset is *not* relative to the section.
607 std::vector
<Opd_ent
> opd_ent_
;
609 // Object attributes if there is a .gnu.attributes section.
610 Attributes_section_data
* attributes_section_data_
;
613 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
614 // base class will emit.
616 template<int sh_type
, int size
, bool big_endian
>
617 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
620 Powerpc_copy_relocs()
621 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
624 // Emit any saved relocations which turn out to be needed. This is
625 // called after all the relocs have been scanned.
627 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
630 template<int size
, bool big_endian
>
631 class Target_powerpc
: public Sized_target
<size
, big_endian
>
635 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
636 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
637 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
638 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
639 static const Address invalid_address
= static_cast<Address
>(0) - 1;
640 // Offset of tp and dtp pointers from start of TLS block.
641 static const Address tp_offset
= 0x7000;
642 static const Address dtp_offset
= 0x8000;
645 : Sized_target
<size
, big_endian
>(&powerpc_info
),
646 got_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
), brlt_section_(NULL
),
647 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
648 tlsld_got_offset_(-1U),
649 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
650 power10_relocs_(false), plt_thread_safe_(false), plt_localentry0_(false),
651 plt_localentry0_init_(false), has_localentry0_(false),
652 has_tls_get_addr_opt_(false),
653 tprel_opt_(parameters
->options().tls_optimize()),
654 relax_failed_(false), relax_fail_count_(0),
655 stub_group_size_(0), savres_section_(0),
656 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
657 attributes_section_data_(NULL
),
658 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
662 // Process the relocations to determine unreferenced sections for
663 // garbage collection.
665 gc_process_relocs(Symbol_table
* symtab
,
667 Sized_relobj_file
<size
, big_endian
>* object
,
668 unsigned int data_shndx
,
669 unsigned int sh_type
,
670 const unsigned char* prelocs
,
672 Output_section
* output_section
,
673 bool needs_special_offset_handling
,
674 size_t local_symbol_count
,
675 const unsigned char* plocal_symbols
);
677 // Scan the relocations to look for symbol adjustments.
679 scan_relocs(Symbol_table
* symtab
,
681 Sized_relobj_file
<size
, big_endian
>* object
,
682 unsigned int data_shndx
,
683 unsigned int sh_type
,
684 const unsigned char* prelocs
,
686 Output_section
* output_section
,
687 bool needs_special_offset_handling
,
688 size_t local_symbol_count
,
689 const unsigned char* plocal_symbols
);
691 // Map input .toc section to output .got section.
693 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
695 if (size
== 64 && strcmp(name
, ".toc") == 0)
703 // Provide linker defined save/restore functions.
705 define_save_restore_funcs(Layout
*, Symbol_table
*);
707 // No stubs unless a final link.
710 { return !parameters
->options().relocatable(); }
713 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
716 do_plt_fde_location(const Output_data
*, unsigned char*,
717 uint64_t*, off_t
*) const;
719 // Stash info about branches, for stub generation.
721 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
722 unsigned int data_shndx
, Address r_offset
,
723 unsigned int r_type
, unsigned int r_sym
, Address addend
)
725 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
726 this->branch_info_
.push_back(info
);
727 if (r_type
== elfcpp::R_POWERPC_REL14
728 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
729 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
730 ppc_object
->set_has_14bit_branch(data_shndx
);
733 // Return whether the last branch is a plt call, and if so, mark the
734 // branch as having an R_PPC64_TOCSAVE.
736 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
737 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
740 && !this->branch_info_
.empty()
741 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
742 r_offset
, this, symtab
));
745 // Say the given location, that of a nop in a function prologue with
746 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
747 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
749 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
750 unsigned int shndx
, Address offset
)
753 loc
.object
= ppc_object
;
756 this->tocsave_loc_
.insert(loc
);
763 return this->tocsave_loc_
;
767 do_define_standard_symbols(Symbol_table
*, Layout
*);
769 // Finalize the sections.
771 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
773 // Return the value to use for a dynamic which requires special
776 do_dynsym_value(const Symbol
*) const;
778 // Return the PLT address to use for a local symbol.
780 do_plt_address_for_local(const Relobj
*, unsigned int) const;
782 // Return the PLT address to use for a global symbol.
784 do_plt_address_for_global(const Symbol
*) const;
786 // Return the offset to use for the GOT_INDX'th got entry which is
787 // for a local tls symbol specified by OBJECT, SYMNDX.
789 do_tls_offset_for_local(const Relobj
* object
,
791 unsigned int got_indx
) const;
793 // Return the offset to use for the GOT_INDX'th got entry which is
794 // for global tls symbol GSYM.
796 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
799 do_function_location(Symbol_location
*) const;
802 do_can_check_for_function_pointers() const
805 // Adjust -fsplit-stack code which calls non-split-stack code.
807 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
808 section_offset_type fnoffset
, section_size_type fnsize
,
809 const unsigned char* prelocs
, size_t reloc_count
,
810 unsigned char* view
, section_size_type view_size
,
811 std::string
* from
, std::string
* to
) const;
813 // Relocate a section.
815 relocate_section(const Relocate_info
<size
, big_endian
>*,
816 unsigned int sh_type
,
817 const unsigned char* prelocs
,
819 Output_section
* output_section
,
820 bool needs_special_offset_handling
,
822 Address view_address
,
823 section_size_type view_size
,
824 const Reloc_symbol_changes
*);
826 // Scan the relocs during a relocatable link.
828 scan_relocatable_relocs(Symbol_table
* symtab
,
830 Sized_relobj_file
<size
, big_endian
>* object
,
831 unsigned int data_shndx
,
832 unsigned int sh_type
,
833 const unsigned char* prelocs
,
835 Output_section
* output_section
,
836 bool needs_special_offset_handling
,
837 size_t local_symbol_count
,
838 const unsigned char* plocal_symbols
,
839 Relocatable_relocs
*);
841 // Scan the relocs for --emit-relocs.
843 emit_relocs_scan(Symbol_table
* symtab
,
845 Sized_relobj_file
<size
, big_endian
>* object
,
846 unsigned int data_shndx
,
847 unsigned int sh_type
,
848 const unsigned char* prelocs
,
850 Output_section
* output_section
,
851 bool needs_special_offset_handling
,
852 size_t local_symbol_count
,
853 const unsigned char* plocal_syms
,
854 Relocatable_relocs
* rr
);
856 // Emit relocations for a section.
858 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
859 unsigned int sh_type
,
860 const unsigned char* prelocs
,
862 Output_section
* output_section
,
863 typename
elfcpp::Elf_types
<size
>::Elf_Off
864 offset_in_output_section
,
866 Address view_address
,
868 unsigned char* reloc_view
,
869 section_size_type reloc_view_size
);
871 // Return whether SYM is defined by the ABI.
873 do_is_defined_by_abi(const Symbol
* sym
) const
875 return strcmp(sym
->name(), "__tls_get_addr") == 0;
878 // Return the size of the GOT section.
882 gold_assert(this->got_
!= NULL
);
883 return this->got_
->data_size();
886 // Get the PLT section.
887 const Output_data_plt_powerpc
<size
, big_endian
>*
890 gold_assert(this->plt_
!= NULL
);
894 // Get the IPLT section.
895 const Output_data_plt_powerpc
<size
, big_endian
>*
898 gold_assert(this->iplt_
!= NULL
);
902 // Get the LPLT section.
903 const Output_data_plt_powerpc
<size
, big_endian
>*
909 // Return the plt offset and section for the given global sym.
911 plt_off(const Symbol
* gsym
,
912 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
914 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
915 && gsym
->can_use_relative_reloc(false))
916 *sec
= this->iplt_section();
918 *sec
= this->plt_section();
919 return gsym
->plt_offset();
922 // Return the plt offset and section for the given local sym.
924 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
925 unsigned int local_sym_index
,
926 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
928 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
929 if (lsym
->is_ifunc_symbol())
930 *sec
= this->iplt_section();
932 *sec
= this->lplt_section();
933 return relobj
->local_plt_offset(local_sym_index
);
936 // Get the .glink section.
937 const Output_data_glink
<size
, big_endian
>*
938 glink_section() const
940 gold_assert(this->glink_
!= NULL
);
944 Output_data_glink
<size
, big_endian
>*
947 gold_assert(this->glink_
!= NULL
);
951 bool has_glink() const
952 { return this->glink_
!= NULL
; }
954 // Get the GOT section.
955 const Output_data_got_powerpc
<size
, big_endian
>*
958 gold_assert(this->got_
!= NULL
);
962 // Get the GOT section, creating it if necessary.
963 Output_data_got_powerpc
<size
, big_endian
>*
964 got_section(Symbol_table
*, Layout
*);
967 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
968 const elfcpp::Ehdr
<size
, big_endian
>&);
970 // Return the number of entries in the GOT.
972 got_entry_count() const
974 if (this->got_
== NULL
)
976 return this->got_size() / (size
/ 8);
979 // Return the number of entries in the PLT.
981 plt_entry_count() const;
983 // Return the offset of the first non-reserved PLT entry.
985 first_plt_entry_offset() const
989 if (this->abiversion() >= 2)
994 // Return the size of each PLT entry.
996 plt_entry_size() const
1000 if (this->abiversion() >= 2)
1005 Output_data_save_res
<size
, big_endian
>*
1006 savres_section() const
1008 return this->savres_section_
;
1011 // Add any special sections for this symbol to the gc work list.
1012 // For powerpc64, this adds the code section of a function
1015 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1017 // Handle target specific gc actions when adding a gc reference from
1018 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1019 // and DST_OFF. For powerpc64, this adds a referenc to the code
1020 // section of a function descriptor.
1022 do_gc_add_reference(Symbol_table
* symtab
,
1024 unsigned int src_shndx
,
1026 unsigned int dst_shndx
,
1027 Address dst_off
) const;
1029 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1032 { return this->stub_tables_
; }
1034 const Output_data_brlt_powerpc
<size
, big_endian
>*
1035 brlt_section() const
1036 { return this->brlt_section_
; }
1039 add_branch_lookup_table(Address to
)
1041 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1042 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1046 find_branch_lookup_table(Address to
)
1048 typename
Branch_lookup_table::const_iterator p
1049 = this->branch_lookup_table_
.find(to
);
1050 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1054 write_branch_lookup_table(unsigned char *oview
)
1056 for (typename
Branch_lookup_table::const_iterator p
1057 = this->branch_lookup_table_
.begin();
1058 p
!= this->branch_lookup_table_
.end();
1061 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1065 // Wrapper used after relax to define a local symbol in output data,
1066 // from the end if value < 0.
1068 define_local(Symbol_table
* symtab
, const char* name
,
1069 Output_data
* od
, Address value
, unsigned int symsize
)
1072 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1073 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1074 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1075 static_cast<Signed_address
>(value
) < 0,
1077 // We are creating this symbol late, so need to fix up things
1078 // done early in Layout::finalize.
1079 sym
->set_dynsym_index(-1U);
1083 set_power10_relocs()
1085 this->power10_relocs_
= true;
1089 power10_stubs() const
1091 return (this->power10_relocs_
1092 && (parameters
->options().power10_stubs_enum()
1093 != General_options::POWER10_STUBS_NO
));
1097 power10_stubs_auto() const
1099 return (parameters
->options().power10_stubs_enum()
1100 == General_options::POWER10_STUBS_AUTO
);
1104 plt_thread_safe() const
1105 { return this->plt_thread_safe_
; }
1108 plt_localentry0() const
1109 { return this->plt_localentry0_
; }
1112 has_localentry0() const
1113 { return this->has_localentry0_
; }
1116 set_has_localentry0()
1118 this->has_localentry0_
= true;
1122 is_elfv2_localentry0(const Symbol
* gsym
) const
1125 && this->abiversion() >= 2
1126 && this->plt_localentry0()
1127 && gsym
->type() == elfcpp::STT_FUNC
1128 && gsym
->is_defined()
1129 && gsym
->nonvis() >> 3 == 0
1130 && !gsym
->non_zero_localentry());
1134 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1135 unsigned int r_sym
) const
1137 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1138 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1141 && this->abiversion() >= 2
1142 && this->plt_localentry0()
1143 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1145 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1147 if (!psymval
->is_ifunc_symbol()
1148 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1157 { return this->tprel_opt_
; }
1160 set_tprel_opt(bool val
)
1161 { this->tprel_opt_
= val
; }
1163 // Remember any symbols seen with non-zero localentry, even those
1164 // not providing a definition
1166 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1171 unsigned char st_other
= sym
.get_st_other();
1172 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1173 to
->set_non_zero_localentry();
1175 // We haven't resolved anything, continue normal processing.
1181 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1184 set_abiversion(int ver
)
1186 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1187 flags
&= ~elfcpp::EF_PPC64_ABI
;
1188 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1189 this->set_processor_specific_flags(flags
);
1193 tls_get_addr_opt() const
1194 { return this->tls_get_addr_opt_
; }
1197 tls_get_addr() const
1198 { return this->tls_get_addr_
; }
1200 // If optimizing __tls_get_addr calls, whether this is the
1201 // "__tls_get_addr" symbol.
1203 is_tls_get_addr_opt(const Symbol
* gsym
) const
1205 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1206 || gsym
== this->tls_get_addr_opt_
);
1210 replace_tls_get_addr(const Symbol
* gsym
) const
1211 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1214 set_has_tls_get_addr_opt()
1215 { this->has_tls_get_addr_opt_
= true; }
1217 // Offset to toc save stack slot
1220 { return this->abiversion() < 2 ? 40 : 24; }
1222 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1223 // so use the CR save slot. Used only by __tls_get_addr call stub,
1224 // relying on __tls_get_addr not saving CR itself.
1227 { return this->abiversion() < 2 ? 32 : 8; }
1229 // Merge object attributes from input object with those in the output.
1231 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1247 : tls_get_addr_state_(NOT_EXPECTED
),
1248 relinfo_(NULL
), relnum_(0), r_offset_(0)
1253 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1260 if (this->relinfo_
!= NULL
)
1261 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1262 _("missing expected __tls_get_addr call"));
1266 expect_tls_get_addr_call(
1267 const Relocate_info
<size
, big_endian
>* relinfo
,
1271 this->tls_get_addr_state_
= EXPECTED
;
1272 this->relinfo_
= relinfo
;
1273 this->relnum_
= relnum
;
1274 this->r_offset_
= r_offset
;
1278 expect_tls_get_addr_call()
1279 { this->tls_get_addr_state_
= EXPECTED
; }
1282 skip_next_tls_get_addr_call()
1283 {this->tls_get_addr_state_
= SKIP
; }
1286 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1287 unsigned int r_type
, const Symbol
* gsym
)
1290 = ((r_type
== elfcpp::R_POWERPC_REL24
1291 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1292 || r_type
== elfcpp::R_PPC_PLTREL24
1293 || is_plt16_reloc
<size
>(r_type
)
1294 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1295 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1296 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1297 || r_type
== elfcpp::R_POWERPC_PLTCALL
1298 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1299 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1301 && (gsym
== target
->tls_get_addr()
1302 || gsym
== target
->tls_get_addr_opt()));
1303 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1304 this->tls_get_addr_state_
= NOT_EXPECTED
;
1305 if (is_tls_call
&& last_tls
!= EXPECTED
)
1307 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1316 // What we're up to regarding calls to __tls_get_addr.
1317 // On powerpc, the branch and link insn making a call to
1318 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1319 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1320 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1321 // The marker relocation always comes first, and has the same
1322 // symbol as the reloc on the insn setting up the __tls_get_addr
1323 // argument. This ties the arg setup insn with the call insn,
1324 // allowing ld to safely optimize away the call. We check that
1325 // every call to __tls_get_addr has a marker relocation, and that
1326 // every marker relocation is on a call to __tls_get_addr.
1327 Tls_get_addr tls_get_addr_state_
;
1328 // Info about the last reloc for error message.
1329 const Relocate_info
<size
, big_endian
>* relinfo_
;
1334 // The class which scans relocations.
1335 class Scan
: protected Track_tls
1338 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1341 : Track_tls(), issued_non_pic_error_(false)
1345 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1348 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1349 Sized_relobj_file
<size
, big_endian
>* object
,
1350 unsigned int data_shndx
,
1351 Output_section
* output_section
,
1352 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1353 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1357 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1358 Sized_relobj_file
<size
, big_endian
>* object
,
1359 unsigned int data_shndx
,
1360 Output_section
* output_section
,
1361 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1365 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1367 Sized_relobj_file
<size
, big_endian
>* relobj
,
1370 const elfcpp::Rela
<size
, big_endian
>& ,
1371 unsigned int r_type
,
1372 const elfcpp::Sym
<size
, big_endian
>&)
1374 // PowerPC64 .opd is not folded, so any identical function text
1375 // may be folded and we'll still keep function addresses distinct.
1376 // That means no reloc is of concern here.
1379 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1380 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1381 if (ppcobj
->abiversion() == 1)
1384 // For 32-bit and ELFv2, conservatively assume anything but calls to
1385 // function code might be taking the address of the function.
1386 return !is_branch_reloc
<size
>(r_type
);
1390 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1392 Sized_relobj_file
<size
, big_endian
>* relobj
,
1395 const elfcpp::Rela
<size
, big_endian
>& ,
1396 unsigned int r_type
,
1402 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1403 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1404 if (ppcobj
->abiversion() == 1)
1407 return !is_branch_reloc
<size
>(r_type
);
1411 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1412 Sized_relobj_file
<size
, big_endian
>* object
,
1413 unsigned int r_type
, bool report_err
);
1417 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1418 unsigned int r_type
);
1421 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1422 unsigned int r_type
, Symbol
*);
1425 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1426 Target_powerpc
* target
);
1429 check_non_pic(Relobj
*, unsigned int r_type
);
1431 // Whether we have issued an error about a non-PIC compilation.
1432 bool issued_non_pic_error_
;
1436 symval_for_branch(const Symbol_table
* symtab
,
1437 const Sized_symbol
<size
>* gsym
,
1438 Powerpc_relobj
<size
, big_endian
>* object
,
1439 Address
*value
, unsigned int *dest_shndx
);
1441 // The class which implements relocation.
1442 class Relocate
: protected Track_tls
1445 // Use 'at' branch hints when true, 'y' when false.
1446 // FIXME maybe: set this with an option.
1447 static const bool is_isa_v2
= true;
1453 // Do a relocation. Return false if the caller should not issue
1454 // any warnings about this relocation.
1456 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1457 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1458 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1459 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1463 class Relocate_comdat_behavior
1466 // Decide what the linker should do for relocations that refer to
1467 // discarded comdat sections.
1468 inline Comdat_behavior
1469 get(const char* name
)
1471 gold::Default_comdat_behavior default_behavior
;
1472 Comdat_behavior ret
= default_behavior
.get(name
);
1473 if (ret
== CB_ERROR
)
1476 && (strcmp(name
, ".fixup") == 0
1477 || strcmp(name
, ".got2") == 0))
1480 && (strcmp(name
, ".opd") == 0
1481 || strcmp(name
, ".toc") == 0
1482 || strcmp(name
, ".toc1") == 0))
1489 // Optimize the TLS relocation type based on what we know about the
1490 // symbol. IS_FINAL is true if the final address of this symbol is
1491 // known at link time.
1493 tls::Tls_optimization
1494 optimize_tls_gd(bool is_final
)
1496 // If we are generating a shared library, then we can't do anything
1498 if (parameters
->options().shared()
1499 || !parameters
->options().tls_optimize())
1500 return tls::TLSOPT_NONE
;
1503 return tls::TLSOPT_TO_IE
;
1504 return tls::TLSOPT_TO_LE
;
1507 tls::Tls_optimization
1510 if (parameters
->options().shared()
1511 || !parameters
->options().tls_optimize())
1512 return tls::TLSOPT_NONE
;
1514 return tls::TLSOPT_TO_LE
;
1517 tls::Tls_optimization
1518 optimize_tls_ie(bool is_final
)
1521 || parameters
->options().shared()
1522 || !parameters
->options().tls_optimize())
1523 return tls::TLSOPT_NONE
;
1525 return tls::TLSOPT_TO_LE
;
1530 make_glink_section(Layout
*);
1532 // Create the PLT section.
1534 make_plt_section(Symbol_table
*, Layout
*);
1537 make_iplt_section(Symbol_table
*, Layout
*);
1540 make_lplt_section(Layout
*);
1543 make_brlt_section(Layout
*);
1545 // Create a PLT entry for a global symbol.
1547 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1549 // Create a PLT entry for a local IFUNC symbol.
1551 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1552 Sized_relobj_file
<size
, big_endian
>*,
1555 // Create a PLT entry for a local non-IFUNC symbol.
1557 make_local_plt_entry(Layout
*,
1558 Sized_relobj_file
<size
, big_endian
>*,
1562 // Create a GOT entry for local dynamic __tls_get_addr.
1564 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1565 Sized_relobj_file
<size
, big_endian
>* object
);
1568 tlsld_got_offset() const
1570 return this->tlsld_got_offset_
;
1573 // Get the dynamic reloc section, creating it if necessary.
1575 rela_dyn_section(Layout
*);
1577 // Similarly, but for ifunc symbols get the one for ifunc.
1579 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1581 // Copy a relocation against a global symbol.
1583 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1584 Sized_relobj_file
<size
, big_endian
>* object
,
1585 unsigned int shndx
, Output_section
* output_section
,
1586 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1588 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1589 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1590 symtab
->get_sized_symbol
<size
>(sym
),
1591 object
, shndx
, output_section
,
1592 r_type
, reloc
.get_r_offset(),
1593 reloc
.get_r_addend(),
1594 this->rela_dyn_section(layout
));
1597 // Look over all the input sections, deciding where to place stubs.
1599 group_sections(Layout
*, const Task
*, bool);
1601 // Sort output sections by address.
1602 struct Sort_sections
1605 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1606 { return sec1
->address() < sec2
->address(); }
1612 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1613 unsigned int data_shndx
,
1615 unsigned int r_type
,
1618 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1619 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1625 // Return whether this branch is going via a plt call stub, and if
1626 // so, mark it as having an R_PPC64_TOCSAVE.
1628 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1629 unsigned int shndx
, Address offset
,
1630 Target_powerpc
* target
, Symbol_table
* symtab
);
1632 // If this branch needs a plt call stub, or a long branch stub, make one.
1634 make_stub(Stub_table
<size
, big_endian
>*,
1635 Stub_table
<size
, big_endian
>*,
1636 Symbol_table
*) const;
1639 // The branch location..
1640 Powerpc_relobj
<size
, big_endian
>* object_
;
1641 unsigned int shndx_
;
1643 // ..and the branch type and destination.
1644 unsigned int r_type_
: 31;
1645 unsigned int tocsave_
: 1;
1646 unsigned int r_sym_
;
1650 // Information about this specific target which we pass to the
1651 // general Target structure.
1652 static Target::Target_info powerpc_info
;
1654 // The types of GOT entries needed for this platform.
1655 // These values are exposed to the ABI in an incremental link.
1656 // Do not renumber existing values without changing the version
1657 // number of the .gnu_incremental_inputs section.
1661 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1662 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1663 GOT_TYPE_TPREL
// entry for @got@tprel
1667 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1668 // The PLT section. This is a container for a table of addresses,
1669 // and their relocations. Each address in the PLT has a dynamic
1670 // relocation (R_*_JMP_SLOT) and each address will have a
1671 // corresponding entry in .glink for lazy resolution of the PLT.
1672 // ppc32 initialises the PLT to point at the .glink entry, while
1673 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1674 // linker adds a stub that loads the PLT entry into ctr then
1675 // branches to ctr. There may be more than one stub for each PLT
1676 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1677 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1678 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1679 // The IPLT section. Like plt_, this is a container for a table of
1680 // addresses and their relocations, specifically for STT_GNU_IFUNC
1681 // functions that resolve locally (STT_GNU_IFUNC functions that
1682 // don't resolve locally go in PLT). Unlike plt_, these have no
1683 // entry in .glink for lazy resolution, and the relocation section
1684 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1685 // the relocation section may contain relocations against
1686 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1687 // relocation section will appear at the end of other dynamic
1688 // relocations, so that ld.so applies these relocations after other
1689 // dynamic relocations. In a static executable, the relocation
1690 // section is emitted and marked with __rela_iplt_start and
1691 // __rela_iplt_end symbols.
1692 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1693 // A PLT style section for local, non-ifunc symbols
1694 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1695 // Section holding long branch destinations.
1696 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1697 // The .glink section.
1698 Output_data_glink
<size
, big_endian
>* glink_
;
1699 // The dynamic reloc section.
1700 Reloc_section
* rela_dyn_
;
1701 // Relocs saved to avoid a COPY reloc.
1702 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1703 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1704 unsigned int tlsld_got_offset_
;
1706 Stub_tables stub_tables_
;
1707 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1708 Branch_lookup_table branch_lookup_table_
;
1710 typedef std::vector
<Branch_info
> Branches
;
1711 Branches branch_info_
;
1712 Tocsave_loc tocsave_loc_
;
1714 bool power10_relocs_
;
1715 bool plt_thread_safe_
;
1716 bool plt_localentry0_
;
1717 bool plt_localentry0_init_
;
1718 bool has_localentry0_
;
1719 bool has_tls_get_addr_opt_
;
1723 int relax_fail_count_
;
1724 int32_t stub_group_size_
;
1726 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1728 // The "__tls_get_addr" symbol, if present
1729 Symbol
* tls_get_addr_
;
1730 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1731 Symbol
* tls_get_addr_opt_
;
1733 // Attributes in output.
1734 Attributes_section_data
* attributes_section_data_
;
1736 // Last input file to change various attribute tags
1737 const char* last_fp_
;
1738 const char* last_ld_
;
1739 const char* last_vec_
;
1740 const char* last_struct_
;
1744 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1747 true, // is_big_endian
1748 elfcpp::EM_PPC
, // machine_code
1749 false, // has_make_symbol
1750 false, // has_resolve
1751 false, // has_code_fill
1752 true, // is_default_stack_executable
1753 false, // can_icf_inline_merge_sections
1755 "/usr/lib/ld.so.1", // dynamic_linker
1756 0x10000000, // default_text_segment_address
1757 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1758 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1759 false, // isolate_execinstr
1761 elfcpp::SHN_UNDEF
, // small_common_shndx
1762 elfcpp::SHN_UNDEF
, // large_common_shndx
1763 0, // small_common_section_flags
1764 0, // large_common_section_flags
1765 NULL
, // attributes_section
1766 NULL
, // attributes_vendor
1767 "_start", // entry_symbol_name
1768 32, // hash_entry_size
1769 elfcpp::SHT_PROGBITS
, // unwind_section_type
1773 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1776 false, // is_big_endian
1777 elfcpp::EM_PPC
, // machine_code
1778 false, // has_make_symbol
1779 false, // has_resolve
1780 false, // has_code_fill
1781 true, // is_default_stack_executable
1782 false, // can_icf_inline_merge_sections
1784 "/usr/lib/ld.so.1", // dynamic_linker
1785 0x10000000, // default_text_segment_address
1786 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1787 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1788 false, // isolate_execinstr
1790 elfcpp::SHN_UNDEF
, // small_common_shndx
1791 elfcpp::SHN_UNDEF
, // large_common_shndx
1792 0, // small_common_section_flags
1793 0, // large_common_section_flags
1794 NULL
, // attributes_section
1795 NULL
, // attributes_vendor
1796 "_start", // entry_symbol_name
1797 32, // hash_entry_size
1798 elfcpp::SHT_PROGBITS
, // unwind_section_type
1802 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1805 true, // is_big_endian
1806 elfcpp::EM_PPC64
, // machine_code
1807 false, // has_make_symbol
1808 true, // has_resolve
1809 false, // has_code_fill
1810 false, // is_default_stack_executable
1811 false, // can_icf_inline_merge_sections
1813 "/usr/lib/ld.so.1", // dynamic_linker
1814 0x10000000, // default_text_segment_address
1815 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1816 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1817 false, // isolate_execinstr
1819 elfcpp::SHN_UNDEF
, // small_common_shndx
1820 elfcpp::SHN_UNDEF
, // large_common_shndx
1821 0, // small_common_section_flags
1822 0, // large_common_section_flags
1823 NULL
, // attributes_section
1824 NULL
, // attributes_vendor
1825 "_start", // entry_symbol_name
1826 32, // hash_entry_size
1827 elfcpp::SHT_PROGBITS
, // unwind_section_type
1831 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1834 false, // is_big_endian
1835 elfcpp::EM_PPC64
, // machine_code
1836 false, // has_make_symbol
1837 true, // has_resolve
1838 false, // has_code_fill
1839 false, // is_default_stack_executable
1840 false, // can_icf_inline_merge_sections
1842 "/usr/lib/ld.so.1", // dynamic_linker
1843 0x10000000, // default_text_segment_address
1844 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1845 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1846 false, // isolate_execinstr
1848 elfcpp::SHN_UNDEF
, // small_common_shndx
1849 elfcpp::SHN_UNDEF
, // large_common_shndx
1850 0, // small_common_section_flags
1851 0, // large_common_section_flags
1852 NULL
, // attributes_section
1853 NULL
, // attributes_vendor
1854 "_start", // entry_symbol_name
1855 32, // hash_entry_size
1856 elfcpp::SHT_PROGBITS
, // unwind_section_type
1861 is_branch_reloc(unsigned int r_type
)
1863 return (r_type
== elfcpp::R_POWERPC_REL24
1864 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1865 || r_type
== elfcpp::R_PPC_PLTREL24
1866 || r_type
== elfcpp::R_PPC_LOCAL24PC
1867 || r_type
== elfcpp::R_POWERPC_REL14
1868 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1869 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1870 || r_type
== elfcpp::R_POWERPC_ADDR24
1871 || r_type
== elfcpp::R_POWERPC_ADDR14
1872 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1873 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1876 // Reloc resolves to plt entry.
1879 is_plt16_reloc(unsigned int r_type
)
1881 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1882 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1883 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1884 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1887 // If INSN is an opcode that may be used with an @tls operand, return
1888 // the transformed insn for TLS optimisation, otherwise return 0. If
1889 // REG is non-zero only match an insn with RB or RA equal to REG.
1891 at_tls_transform(uint32_t insn
, unsigned int reg
)
1893 if ((insn
& (0x3f << 26)) != 31 << 26)
1897 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1898 rtra
= insn
& ((1 << 26) - (1 << 16));
1899 else if (((insn
>> 16) & 0x1f) == reg
)
1900 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1904 if ((insn
& (0x3ff << 1)) == 266 << 1)
1907 else if ((insn
& (0x1f << 1)) == 23 << 1
1908 && ((insn
& (0x1f << 6)) < 14 << 6
1909 || ((insn
& (0x1f << 6)) >= 16 << 6
1910 && (insn
& (0x1f << 6)) < 24 << 6)))
1911 // load and store indexed -> dform
1912 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1913 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1914 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1915 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1916 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1918 insn
= (58 << 26) | 2;
1926 template<int size
, bool big_endian
>
1927 class Powerpc_relocate_functions
1947 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1948 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1949 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1951 template<int valsize
>
1953 has_overflow_signed(Address value
)
1955 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1956 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1957 limit
<<= ((valsize
- 1) >> 1);
1958 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1959 return value
+ limit
> (limit
<< 1) - 1;
1962 template<int valsize
>
1964 has_overflow_unsigned(Address value
)
1966 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1967 limit
<<= ((valsize
- 1) >> 1);
1968 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1969 return value
> (limit
<< 1) - 1;
1972 template<int valsize
>
1974 has_overflow_bitfield(Address value
)
1976 return (has_overflow_unsigned
<valsize
>(value
)
1977 && has_overflow_signed
<valsize
>(value
));
1980 template<int valsize
>
1981 static inline Status
1982 overflowed(Address value
, Overflow_check overflow
)
1984 if (overflow
== CHECK_SIGNED
)
1986 if (has_overflow_signed
<valsize
>(value
))
1987 return STATUS_OVERFLOW
;
1989 else if (overflow
== CHECK_UNSIGNED
)
1991 if (has_overflow_unsigned
<valsize
>(value
))
1992 return STATUS_OVERFLOW
;
1994 else if (overflow
== CHECK_BITFIELD
)
1996 if (has_overflow_bitfield
<valsize
>(value
))
1997 return STATUS_OVERFLOW
;
2002 // Do a simple RELA relocation
2003 template<int fieldsize
, int valsize
>
2004 static inline Status
2005 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2007 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2008 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2009 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2010 return overflowed
<valsize
>(value
, overflow
);
2013 template<int fieldsize
, int valsize
>
2014 static inline Status
2015 rela(unsigned char* view
,
2016 unsigned int right_shift
,
2017 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2019 Overflow_check overflow
)
2021 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2022 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2023 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2024 if (overflow
== CHECK_SIGNED
)
2025 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2027 value
= value
>> right_shift
;
2028 Valtype reloc
= value
;
2031 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2032 return overflowed
<valsize
>(value
, overflow
);
2035 // Do a simple RELA relocation, unaligned.
2036 template<int fieldsize
, int valsize
>
2037 static inline Status
2038 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2040 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2041 return overflowed
<valsize
>(value
, overflow
);
2044 template<int fieldsize
, int valsize
>
2045 static inline Status
2046 rela_ua(unsigned char* view
,
2047 unsigned int right_shift
,
2048 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2050 Overflow_check overflow
)
2052 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2054 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2055 if (overflow
== CHECK_SIGNED
)
2056 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2058 value
= value
>> right_shift
;
2059 Valtype reloc
= value
;
2062 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2063 return overflowed
<valsize
>(value
, overflow
);
2067 // R_PPC64_ADDR64: (Symbol + Addend)
2069 addr64(unsigned char* view
, Address value
)
2070 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2072 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2074 addr64_u(unsigned char* view
, Address value
)
2075 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2077 // R_POWERPC_ADDR32: (Symbol + Addend)
2078 static inline Status
2079 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2080 { return This::template rela
<32,32>(view
, value
, overflow
); }
2082 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2083 static inline Status
2084 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2085 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2087 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2088 static inline Status
2089 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2091 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2093 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2094 stat
= STATUS_OVERFLOW
;
2098 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2099 static inline Status
2100 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2101 { return This::template rela
<16,16>(view
, value
, overflow
); }
2103 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2104 static inline Status
2105 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2106 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2108 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2109 static inline Status
2110 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2112 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2113 if ((value
& 3) != 0)
2114 stat
= STATUS_OVERFLOW
;
2118 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2119 static inline Status
2120 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2122 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2123 if ((value
& 15) != 0)
2124 stat
= STATUS_OVERFLOW
;
2128 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2130 addr16_hi(unsigned char* view
, Address value
)
2131 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2133 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2135 addr16_ha(unsigned char* view
, Address value
)
2136 { This::addr16_hi(view
, value
+ 0x8000); }
2138 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2140 addr16_hi2(unsigned char* view
, Address value
)
2141 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2143 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2145 addr16_ha2(unsigned char* view
, Address value
)
2146 { This::addr16_hi2(view
, value
+ 0x8000); }
2148 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2150 addr16_hi3(unsigned char* view
, Address value
)
2151 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2153 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2155 addr16_ha3(unsigned char* view
, Address value
)
2156 { This::addr16_hi3(view
, value
+ 0x8000); }
2158 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2159 static inline Status
2160 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2162 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2163 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2164 stat
= STATUS_OVERFLOW
;
2168 // R_POWERPC_REL16DX_HA
2169 static inline Status
2170 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2172 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2173 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2174 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2176 value
= static_cast<SignedAddress
>(value
) >> 16;
2177 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2178 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2179 return overflowed
<16>(value
, overflow
);
2183 static inline Status
2184 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2186 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2188 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2194 addr34_hi(unsigned char *view
, uint64_t value
)
2195 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2199 addr34_ha(unsigned char *view
, uint64_t value
)
2200 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2203 static inline Status
2204 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2206 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2208 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2212 // R_PPC64_ADDR16_HIGHER34
2214 addr16_higher34(unsigned char* view
, uint64_t value
)
2215 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2217 // R_PPC64_ADDR16_HIGHERA34
2219 addr16_highera34(unsigned char* view
, uint64_t value
)
2220 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2222 // R_PPC64_ADDR16_HIGHEST34
2224 addr16_highest34(unsigned char* view
, uint64_t value
)
2225 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2227 // R_PPC64_ADDR16_HIGHESTA34
2229 addr16_highesta34(unsigned char* view
, uint64_t value
)
2230 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2233 // Set ABI version for input and output.
2235 template<int size
, bool big_endian
>
2237 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2239 this->e_flags_
|= ver
;
2240 if (this->abiversion() != 0)
2242 Target_powerpc
<size
, big_endian
>* target
=
2243 static_cast<Target_powerpc
<size
, big_endian
>*>(
2244 parameters
->sized_target
<size
, big_endian
>());
2245 if (target
->abiversion() == 0)
2246 target
->set_abiversion(this->abiversion());
2247 else if (target
->abiversion() != this->abiversion())
2248 gold_error(_("%s: ABI version %d is not compatible "
2249 "with ABI version %d output"),
2250 this->name().c_str(),
2251 this->abiversion(), target
->abiversion());
2256 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2257 // relocatable object, if such sections exists.
2259 template<int size
, bool big_endian
>
2261 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2262 Read_symbols_data
* sd
)
2264 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2265 const unsigned char* namesu
= sd
->section_names
->data();
2266 const char* names
= reinterpret_cast<const char*>(namesu
);
2267 section_size_type names_size
= sd
->section_names_size
;
2268 const unsigned char* s
;
2270 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2271 size
== 32 ? ".got2" : ".opd",
2272 names
, names_size
, NULL
);
2275 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2276 this->special_
= ndx
;
2279 if (this->abiversion() == 0)
2280 this->set_abiversion(1);
2281 else if (this->abiversion() > 1)
2282 gold_error(_("%s: .opd invalid in abiv%d"),
2283 this->name().c_str(), this->abiversion());
2288 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2289 names
, names_size
, NULL
);
2292 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2293 this->relatoc_
= ndx
;
2294 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2295 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2298 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2301 // Examine .rela.opd to build info about function entry points.
2303 template<int size
, bool big_endian
>
2305 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2307 const unsigned char* prelocs
,
2308 const unsigned char* plocal_syms
)
2312 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2313 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2314 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2315 Address expected_off
= 0;
2316 bool regular
= true;
2317 unsigned int opd_ent_size
= 0;
2319 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2321 Reltype
reloc(prelocs
);
2322 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2323 = reloc
.get_r_info();
2324 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2325 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2327 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2328 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2331 if (r_sym
< this->local_symbol_count())
2333 typename
elfcpp::Sym
<size
, big_endian
>
2334 lsym(plocal_syms
+ r_sym
* sym_size
);
2335 shndx
= lsym
.get_st_shndx();
2336 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2337 value
= lsym
.get_st_value();
2340 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2342 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2343 value
+ reloc
.get_r_addend());
2346 expected_off
= reloc
.get_r_offset();
2347 opd_ent_size
= expected_off
;
2349 else if (expected_off
!= reloc
.get_r_offset())
2351 expected_off
+= opd_ent_size
;
2353 else if (r_type
== elfcpp::R_PPC64_TOC
)
2355 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2360 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2361 this->name().c_str(), r_type
);
2365 if (reloc_count
<= 2)
2366 opd_ent_size
= this->section_size(this->opd_shndx());
2367 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2371 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2372 this->name().c_str());
2378 // Returns true if a code sequence loading the TOC entry at VALUE
2379 // relative to the TOC pointer can be converted into code calculating
2380 // a TOC pointer relative offset.
2381 // If so, the TOC pointer relative offset is stored to VALUE.
2383 template<int size
, bool big_endian
>
2385 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2386 Target_powerpc
<size
, big_endian
>* target
,
2392 // With -mcmodel=medium code it is quite possible to have
2393 // toc-relative relocs referring to objects outside the TOC.
2394 // Don't try to look at a non-existent TOC.
2395 if (this->toc_shndx() == 0)
2398 // Convert VALUE back to an address by adding got_base (see below),
2399 // then to an offset in the TOC by subtracting the TOC output
2400 // section address and the TOC output offset. Since this TOC output
2401 // section and the got output section are one and the same, we can
2402 // omit adding and subtracting the output section address.
2403 Address off
= (*value
+ this->toc_base_offset()
2404 - this->output_section_offset(this->toc_shndx()));
2405 // Is this offset in the TOC? -mcmodel=medium code may be using
2406 // TOC relative access to variables outside the TOC. Those of
2407 // course can't be optimized. We also don't try to optimize code
2408 // that is using a different object's TOC.
2409 if (off
>= this->section_size(this->toc_shndx()))
2412 if (this->no_toc_opt(off
))
2415 section_size_type vlen
;
2416 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2417 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2419 Address got_base
= (target
->got_section()->output_section()->address()
2420 + this->toc_base_offset());
2422 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2429 template<int size
, bool big_endian
>
2431 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2432 Target_powerpc
<size
, big_endian
>* target
,
2433 const Symbol_value
<size
>* psymval
,
2437 Address addr
= psymval
->value(this, addend
);
2438 Address got_base
= (target
->got_section()->output_section()->address()
2439 + this->toc_base_offset());
2441 if (addr
+ 0x80008000 > 0xffffffff)
2448 // Perform the Sized_relobj_file method, then set up opd info from
2451 template<int size
, bool big_endian
>
2453 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2455 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2458 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2459 p
!= rd
->relocs
.end();
2462 if (p
->data_shndx
== this->opd_shndx())
2464 uint64_t opd_size
= this->section_size(this->opd_shndx());
2465 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2468 this->init_opd(opd_size
);
2469 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2470 rd
->local_symbols
->data());
2478 // Read the symbols then set up st_other vector.
2480 template<int size
, bool big_endian
>
2482 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2484 this->base_read_symbols(sd
);
2485 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2489 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2490 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2491 const unsigned int loccount
= this->do_local_symbol_count();
2494 this->st_other_
.resize(loccount
);
2495 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2496 off_t locsize
= loccount
* sym_size
;
2497 const unsigned int symtab_shndx
= this->symtab_shndx();
2498 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2499 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2500 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2501 locsize
, true, false);
2503 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2505 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2506 unsigned char st_other
= sym
.get_st_other();
2507 this->st_other_
[i
] = st_other
;
2508 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2510 if (this->abiversion() == 0)
2511 this->set_abiversion(2);
2512 else if (this->abiversion() < 2)
2513 gold_error(_("%s: local symbol %d has invalid st_other"
2514 " for ABI version 1"),
2515 this->name().c_str(), i
);
2521 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2522 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2523 bool merge_attributes
= false;
2524 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2526 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2527 switch (shdr
.get_sh_type())
2529 case elfcpp::SHT_GNU_ATTRIBUTES
:
2531 gold_assert(this->attributes_section_data_
== NULL
);
2532 section_offset_type section_offset
= shdr
.get_sh_offset();
2533 section_size_type section_size
=
2534 convert_to_section_size_type(shdr
.get_sh_size());
2535 const unsigned char* view
=
2536 this->get_view(section_offset
, section_size
, true, false);
2537 this->attributes_section_data_
=
2538 new Attributes_section_data(view
, section_size
);
2542 case elfcpp::SHT_SYMTAB
:
2544 // Sometimes an object has no contents except the section
2545 // name string table and an empty symbol table with the
2546 // undefined symbol. We don't want to merge
2547 // processor-specific flags from such an object.
2548 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2549 elfcpp::Elf_sizes
<size
>::sym_size
;
2550 if (shdr
.get_sh_size() > sym_size
)
2551 merge_attributes
= true;
2555 case elfcpp::SHT_STRTAB
:
2559 merge_attributes
= true;
2564 if (!merge_attributes
)
2566 // Should rarely happen.
2567 delete this->attributes_section_data_
;
2568 this->attributes_section_data_
= NULL
;
2572 template<int size
, bool big_endian
>
2574 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2576 this->e_flags_
|= ver
;
2577 if (this->abiversion() != 0)
2579 Target_powerpc
<size
, big_endian
>* target
=
2580 static_cast<Target_powerpc
<size
, big_endian
>*>(
2581 parameters
->sized_target
<size
, big_endian
>());
2582 if (target
->abiversion() == 0)
2583 target
->set_abiversion(this->abiversion());
2584 else if (target
->abiversion() != this->abiversion())
2585 gold_error(_("%s: ABI version %d is not compatible "
2586 "with ABI version %d output"),
2587 this->name().c_str(),
2588 this->abiversion(), target
->abiversion());
2593 // Call Sized_dynobj::base_read_symbols to read the symbols then
2594 // read .opd from a dynamic object, filling in opd_ent_ vector,
2596 template<int size
, bool big_endian
>
2598 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2600 this->base_read_symbols(sd
);
2601 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2602 const unsigned char* ps
=
2603 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2604 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2606 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2607 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2609 section_offset_type section_offset
= shdr
.get_sh_offset();
2610 section_size_type section_size
=
2611 convert_to_section_size_type(shdr
.get_sh_size());
2612 const unsigned char* view
=
2613 this->get_view(section_offset
, section_size
, true, false);
2614 this->attributes_section_data_
=
2615 new Attributes_section_data(view
, section_size
);
2621 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2622 const unsigned char* namesu
= sd
->section_names
->data();
2623 const char* names
= reinterpret_cast<const char*>(namesu
);
2624 const unsigned char* s
= NULL
;
2625 const unsigned char* opd
;
2626 section_size_type opd_size
;
2628 // Find and read .opd section.
2631 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2632 sd
->section_names_size
,
2637 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2638 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2639 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2641 if (this->abiversion() == 0)
2642 this->set_abiversion(1);
2643 else if (this->abiversion() > 1)
2644 gold_error(_("%s: .opd invalid in abiv%d"),
2645 this->name().c_str(), this->abiversion());
2647 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2648 this->opd_address_
= shdr
.get_sh_addr();
2649 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2650 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2656 // Build set of executable sections.
2657 // Using a set is probably overkill. There is likely to be only
2658 // a few executable sections, typically .init, .text and .fini,
2659 // and they are generally grouped together.
2660 typedef std::set
<Sec_info
> Exec_sections
;
2661 Exec_sections exec_sections
;
2663 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2665 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2666 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2667 && ((shdr
.get_sh_flags()
2668 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2669 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2670 && shdr
.get_sh_size() != 0)
2672 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2673 shdr
.get_sh_size(), i
));
2676 if (exec_sections
.empty())
2679 // Look over the OPD entries. This is complicated by the fact
2680 // that some binaries will use two-word entries while others
2681 // will use the standard three-word entries. In most cases
2682 // the third word (the environment pointer for languages like
2683 // Pascal) is unused and will be zero. If the third word is
2684 // used it should not be pointing into executable sections,
2686 this->init_opd(opd_size
);
2687 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2689 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2690 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2691 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2693 // Chances are that this is the third word of an OPD entry.
2695 typename
Exec_sections::const_iterator e
2696 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2697 if (e
!= exec_sections
.begin())
2700 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2702 // We have an address in an executable section.
2703 // VAL ought to be the function entry, set it up.
2704 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2705 // Skip second word of OPD entry, the TOC pointer.
2709 // If we didn't match any executable sections, we likely
2710 // have a non-zero third word in the OPD entry.
2715 // Relocate sections.
2717 template<int size
, bool big_endian
>
2719 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2720 const Symbol_table
* symtab
, const Layout
* layout
,
2721 const unsigned char* pshdrs
, Output_file
* of
,
2722 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2724 unsigned int start
= 1;
2726 && this->relatoc_
!= 0
2727 && !parameters
->options().relocatable())
2729 // Relocate .toc first.
2730 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2731 this->relatoc_
, this->relatoc_
);
2732 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2733 1, this->relatoc_
- 1);
2734 start
= this->relatoc_
+ 1;
2736 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2737 start
, this->shnum() - 1);
2739 if (!parameters
->options().output_is_position_independent())
2741 Target_powerpc
<size
, big_endian
>* target
2742 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2743 parameters
->sized_target
<size
, big_endian
>());
2744 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2746 const section_size_type offset
= target
->lplt_section()->offset();
2747 const section_size_type oview_size
2748 = convert_to_section_size_type(target
->lplt_section()->data_size());
2749 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2751 bool modified
= false;
2752 unsigned int nsyms
= this->local_symbol_count();
2753 for (unsigned int i
= 0; i
< nsyms
; i
++)
2754 if (this->local_has_plt_offset(i
))
2756 Address value
= this->local_symbol_value(i
, 0);
2758 value
+= ppc64_local_entry_offset(i
);
2759 size_t off
= this->local_plt_offset(i
);
2760 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2764 of
->write_output_view(offset
, oview_size
, oview
);
2769 // Set up some symbols.
2771 template<int size
, bool big_endian
>
2773 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2774 Symbol_table
* symtab
,
2779 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2780 // undefined when scanning relocs (and thus requires
2781 // non-relative dynamic relocs). The proper value will be
2783 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2784 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2786 Target_powerpc
<size
, big_endian
>* target
=
2787 static_cast<Target_powerpc
<size
, big_endian
>*>(
2788 parameters
->sized_target
<size
, big_endian
>());
2789 Output_data_got_powerpc
<size
, big_endian
>* got
2790 = target
->got_section(symtab
, layout
);
2791 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2792 Symbol_table::PREDEFINED
,
2796 elfcpp::STV_HIDDEN
, 0,
2800 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2801 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2802 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2804 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2806 = layout
->add_output_section_data(".sdata", 0,
2808 | elfcpp::SHF_WRITE
,
2809 sdata
, ORDER_SMALL_DATA
, false);
2810 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2811 Symbol_table::PREDEFINED
,
2812 os
, 32768, 0, elfcpp::STT_OBJECT
,
2813 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2819 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2820 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2821 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2823 Target_powerpc
<size
, big_endian
>* target
=
2824 static_cast<Target_powerpc
<size
, big_endian
>*>(
2825 parameters
->sized_target
<size
, big_endian
>());
2826 Output_data_got_powerpc
<size
, big_endian
>* got
2827 = target
->got_section(symtab
, layout
);
2828 symtab
->define_in_output_data(".TOC.", NULL
,
2829 Symbol_table::PREDEFINED
,
2833 elfcpp::STV_HIDDEN
, 0,
2838 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2839 if (parameters
->options().tls_get_addr_optimize()
2840 && this->tls_get_addr_
!= NULL
2841 && this->tls_get_addr_
->in_reg())
2842 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2843 if (this->tls_get_addr_opt_
!= NULL
)
2845 if (this->tls_get_addr_
->is_undefined()
2846 || this->tls_get_addr_
->is_from_dynobj())
2848 // Make it seem as if references to __tls_get_addr are
2849 // really to __tls_get_addr_opt, so the latter symbol is
2850 // made dynamic, not the former.
2851 this->tls_get_addr_
->clear_in_reg();
2852 this->tls_get_addr_opt_
->set_in_reg();
2854 // We have a non-dynamic definition for __tls_get_addr.
2855 // Make __tls_get_addr_opt the same, if it does not already have
2856 // a non-dynamic definition.
2857 else if (this->tls_get_addr_opt_
->is_undefined()
2858 || this->tls_get_addr_opt_
->is_from_dynobj())
2860 Sized_symbol
<size
>* from
2861 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2862 Sized_symbol
<size
>* to
2863 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2864 symtab
->clone
<size
>(to
, from
);
2869 // Set up PowerPC target specific relobj.
2871 template<int size
, bool big_endian
>
2873 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2874 const std::string
& name
,
2875 Input_file
* input_file
,
2876 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2878 int et
= ehdr
.get_e_type();
2879 // ET_EXEC files are valid input for --just-symbols/-R,
2880 // and we treat them as relocatable objects.
2881 if (et
== elfcpp::ET_REL
2882 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2884 Powerpc_relobj
<size
, big_endian
>* obj
=
2885 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2889 else if (et
== elfcpp::ET_DYN
)
2891 Powerpc_dynobj
<size
, big_endian
>* obj
=
2892 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2898 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2903 template<int size
, bool big_endian
>
2904 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2907 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2908 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2910 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2911 : Output_data_got
<size
, big_endian
>(),
2912 symtab_(symtab
), layout_(layout
),
2913 header_ent_cnt_(size
== 32 ? 3 : 1),
2914 header_index_(size
== 32 ? 0x2000 : 0)
2917 this->set_addralign(256);
2920 // Override all the Output_data_got methods we use so as to first call
2923 add_global(Symbol
* gsym
, unsigned int got_type
)
2925 this->reserve_ent();
2926 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2930 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2932 this->reserve_ent();
2933 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2937 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2938 { return this->add_global_plt(gsym
, got_type
); }
2941 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2942 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2944 this->reserve_ent();
2945 Output_data_got
<size
, big_endian
>::
2946 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2950 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2951 Output_data_reloc_generic
* rel_dyn
,
2952 unsigned int r_type_1
, unsigned int r_type_2
)
2954 if (gsym
->has_got_offset(got_type
))
2957 this->reserve_ent(2);
2958 Output_data_got
<size
, big_endian
>::
2959 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2963 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2965 this->reserve_ent();
2966 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2971 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2973 this->reserve_ent();
2974 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2979 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2980 { return this->add_local_plt(object
, sym_index
, got_type
); }
2983 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2984 unsigned int got_type
,
2985 Output_data_reloc_generic
* rel_dyn
,
2986 unsigned int r_type
)
2988 if (object
->local_has_got_offset(sym_index
, got_type
))
2991 this->reserve_ent(2);
2992 Output_data_got
<size
, big_endian
>::
2993 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2997 add_constant(Valtype constant
)
2999 this->reserve_ent();
3000 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3004 add_constant_pair(Valtype c1
, Valtype c2
)
3006 this->reserve_ent(2);
3007 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3010 // Offset of _GLOBAL_OFFSET_TABLE_.
3014 return this->got_offset(this->header_index_
);
3017 // Offset of base used to access the GOT/TOC.
3018 // The got/toc pointer reg will be set to this value.
3020 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
3023 return this->g_o_t();
3025 return (this->output_section()->address()
3026 + object
->toc_base_offset()
3030 // Ensure our GOT has a header.
3032 set_final_data_size()
3034 if (this->header_ent_cnt_
!= 0)
3035 this->make_header();
3036 Output_data_got
<size
, big_endian
>::set_final_data_size();
3039 // First word of GOT header needs some values that are not
3040 // handled by Output_data_got so poke them in here.
3041 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3043 do_write(Output_file
* of
)
3046 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3047 val
= this->layout_
->dynamic_section()->address();
3049 val
= this->output_section()->address() + 0x8000;
3050 this->replace_constant(this->header_index_
, val
);
3051 Output_data_got
<size
, big_endian
>::do_write(of
);
3056 reserve_ent(unsigned int cnt
= 1)
3058 if (this->header_ent_cnt_
== 0)
3060 if (this->num_entries() + cnt
> this->header_index_
)
3061 this->make_header();
3067 this->header_ent_cnt_
= 0;
3068 this->header_index_
= this->num_entries();
3071 Output_data_got
<size
, big_endian
>::add_constant(0);
3072 Output_data_got
<size
, big_endian
>::add_constant(0);
3073 Output_data_got
<size
, big_endian
>::add_constant(0);
3075 // Define _GLOBAL_OFFSET_TABLE_ at the header
3076 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3079 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3080 sym
->set_value(this->g_o_t());
3083 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3084 Symbol_table::PREDEFINED
,
3085 this, this->g_o_t(), 0,
3088 elfcpp::STV_HIDDEN
, 0,
3092 Output_data_got
<size
, big_endian
>::add_constant(0);
3095 // Stashed pointers.
3096 Symbol_table
* symtab_
;
3100 unsigned int header_ent_cnt_
;
3101 // GOT header index.
3102 unsigned int header_index_
;
3105 // Get the GOT section, creating it if necessary.
3107 template<int size
, bool big_endian
>
3108 Output_data_got_powerpc
<size
, big_endian
>*
3109 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3112 if (this->got_
== NULL
)
3114 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3117 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3119 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3120 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3121 this->got_
, ORDER_DATA
, false);
3127 // Get the dynamic reloc section, creating it if necessary.
3129 template<int size
, bool big_endian
>
3130 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3131 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3133 if (this->rela_dyn_
== NULL
)
3135 gold_assert(layout
!= NULL
);
3136 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3137 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3138 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3139 ORDER_DYNAMIC_RELOCS
, false);
3141 return this->rela_dyn_
;
3144 // Similarly, but for ifunc symbols get the one for ifunc.
3146 template<int size
, bool big_endian
>
3147 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3148 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3153 return this->rela_dyn_section(layout
);
3155 if (this->iplt_
== NULL
)
3156 this->make_iplt_section(symtab
, layout
);
3157 return this->iplt_
->rel_plt();
3163 // Determine the stub group size. The group size is the absolute
3164 // value of the parameter --stub-group-size. If --stub-group-size
3165 // is passed a negative value, we restrict stubs to be always after
3166 // the stubbed branches.
3167 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3168 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3169 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3170 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3171 owner_(NULL
), output_section_(NULL
)
3175 // Return true iff input section can be handled by current stub
3178 can_add_to_stub_group(Output_section
* o
,
3179 const Output_section::Input_section
* i
,
3182 const Output_section::Input_section
*
3188 { return output_section_
; }
3191 set_output_and_owner(Output_section
* o
,
3192 const Output_section::Input_section
* i
)
3194 this->output_section_
= o
;
3203 // Adding group sections before the stubs.
3204 FINDING_STUB_SECTION
,
3205 // Adding group sections after the stubs.
3209 uint32_t stub_group_size_
;
3210 bool stubs_always_after_branch_
;
3211 bool suppress_size_errors_
;
3212 // True if a stub group can serve multiple output sections.
3215 // Current max size of group. Starts at stub_group_size_ but is
3216 // reduced to stub_group_size_/1024 on seeing a section with
3217 // external conditional branches.
3218 uint32_t group_size_
;
3219 uint64_t group_start_addr_
;
3220 // owner_ and output_section_ specify the section to which stubs are
3221 // attached. The stubs are placed at the end of this section.
3222 const Output_section::Input_section
* owner_
;
3223 Output_section
* output_section_
;
3226 // Return true iff input section can be handled by current stub
3227 // group. Sections are presented to this function in order,
3228 // so the first section is the head of the group.
3231 Stub_control::can_add_to_stub_group(Output_section
* o
,
3232 const Output_section::Input_section
* i
,
3235 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3237 uint64_t start_addr
= o
->address();
3240 // .init and .fini sections are pasted together to form a single
3241 // function. We can't be adding stubs in the middle of the function.
3242 this_size
= o
->data_size();
3245 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3246 this_size
= i
->data_size();
3249 uint64_t end_addr
= start_addr
+ this_size
;
3250 uint32_t group_size
= this->stub_group_size_
;
3252 this->group_size_
= group_size
= group_size
>> 10;
3254 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3255 gold_warning(_("%s:%s exceeds group size"),
3256 i
->relobj()->name().c_str(),
3257 i
->relobj()->section_name(i
->shndx()).c_str());
3259 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3260 has14
? " 14bit" : "",
3261 i
->relobj()->name().c_str(),
3262 i
->relobj()->section_name(i
->shndx()).c_str(),
3263 (long long) this_size
,
3264 (this->state_
== NO_GROUP
3266 : (long long) end_addr
- this->group_start_addr_
));
3268 if (this->state_
== NO_GROUP
)
3270 // Only here on very first use of Stub_control
3272 this->output_section_
= o
;
3273 this->state_
= FINDING_STUB_SECTION
;
3274 this->group_size_
= group_size
;
3275 this->group_start_addr_
= start_addr
;
3278 else if (!this->multi_os_
&& this->output_section_
!= o
)
3280 else if (this->state_
== HAS_STUB_SECTION
)
3282 // Can we add this section, which is after the stubs, to the
3284 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3287 else if (this->state_
== FINDING_STUB_SECTION
)
3289 if ((whole_sec
&& this->output_section_
== o
)
3290 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3292 // Stubs are added at the end of "owner_".
3294 this->output_section_
= o
;
3297 // The group before the stubs has reached maximum size.
3298 // Now see about adding sections after the stubs to the
3299 // group. If the current section has a 14-bit branch and
3300 // the group before the stubs exceeds group_size_ (because
3301 // they didn't have 14-bit branches), don't add sections
3302 // after the stubs: The size of stubs for such a large
3303 // group may exceed the reach of a 14-bit branch.
3304 if (!this->stubs_always_after_branch_
3305 && this_size
<= this->group_size_
3306 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3308 gold_debug(DEBUG_TARGET
, "adding after stubs");
3309 this->state_
= HAS_STUB_SECTION
;
3310 this->group_start_addr_
= start_addr
;
3317 gold_debug(DEBUG_TARGET
,
3318 !this->multi_os_
&& this->output_section_
!= o
3319 ? "nope, new output section\n"
3320 : "nope, didn't fit\n");
3322 // The section fails to fit in the current group. Set up a few
3323 // things for the next group. owner_ and output_section_ will be
3324 // set later after we've retrieved those values for the current
3326 this->state_
= FINDING_STUB_SECTION
;
3327 this->group_size_
= group_size
;
3328 this->group_start_addr_
= start_addr
;
3332 // Look over all the input sections, deciding where to place stubs.
3334 template<int size
, bool big_endian
>
3336 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3338 bool no_size_errors
)
3340 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3341 parameters
->options().stub_group_multi());
3343 // Group input sections and insert stub table
3344 Stub_table_owner
* table_owner
= NULL
;
3345 std::vector
<Stub_table_owner
*> tables
;
3346 Layout::Section_list section_list
;
3347 layout
->get_executable_sections(§ion_list
);
3348 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3349 for (Layout::Section_list::iterator o
= section_list
.begin();
3350 o
!= section_list
.end();
3353 typedef Output_section::Input_section_list Input_section_list
;
3354 for (Input_section_list::const_iterator i
3355 = (*o
)->input_sections().begin();
3356 i
!= (*o
)->input_sections().end();
3359 if (i
->is_input_section()
3360 || i
->is_relaxed_input_section())
3362 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3363 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3364 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3365 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3367 table_owner
->output_section
= stub_control
.output_section();
3368 table_owner
->owner
= stub_control
.owner();
3369 stub_control
.set_output_and_owner(*o
, &*i
);
3372 if (table_owner
== NULL
)
3374 table_owner
= new Stub_table_owner
;
3375 tables
.push_back(table_owner
);
3377 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3381 if (table_owner
!= NULL
)
3383 table_owner
->output_section
= stub_control
.output_section();
3384 table_owner
->owner
= stub_control
.owner();;
3386 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3390 Stub_table
<size
, big_endian
>* stub_table
;
3392 if ((*t
)->owner
->is_input_section())
3393 stub_table
= new Stub_table
<size
, big_endian
>(this,
3394 (*t
)->output_section
,
3396 this->stub_tables_
.size());
3397 else if ((*t
)->owner
->is_relaxed_input_section())
3398 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3399 (*t
)->owner
->relaxed_input_section());
3402 this->stub_tables_
.push_back(stub_table
);
3408 static unsigned long
3409 max_branch_delta (unsigned int r_type
)
3411 if (r_type
== elfcpp::R_POWERPC_REL14
3412 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3413 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3415 if (r_type
== elfcpp::R_POWERPC_REL24
3416 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3417 || r_type
== elfcpp::R_PPC_PLTREL24
3418 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3423 // Return whether this branch is going via a plt call stub.
3425 template<int size
, bool big_endian
>
3427 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3428 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3431 Target_powerpc
* target
,
3432 Symbol_table
* symtab
)
3434 if (this->object_
!= ppc_object
3435 || this->shndx_
!= shndx
3436 || this->offset_
!= offset
)
3439 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3440 if (sym
!= NULL
&& sym
->is_forwarder())
3441 sym
= symtab
->resolve_forwards(sym
);
3442 if (target
->replace_tls_get_addr(sym
))
3443 sym
= target
->tls_get_addr_opt();
3444 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3446 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3447 && !target
->is_elfv2_localentry0(gsym
))
3448 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3449 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3457 // If this branch needs a plt call stub, or a long branch stub, make one.
3459 template<int size
, bool big_endian
>
3461 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3462 Stub_table
<size
, big_endian
>* stub_table
,
3463 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3464 Symbol_table
* symtab
) const
3466 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3467 Target_powerpc
<size
, big_endian
>* target
=
3468 static_cast<Target_powerpc
<size
, big_endian
>*>(
3469 parameters
->sized_target
<size
, big_endian
>());
3470 if (sym
!= NULL
&& sym
->is_forwarder())
3471 sym
= symtab
->resolve_forwards(sym
);
3472 if (target
->replace_tls_get_addr(sym
))
3473 sym
= target
->tls_get_addr_opt();
3474 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3478 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3479 : this->object_
->local_has_plt_offset(this->r_sym_
))
3483 && target
->abiversion() >= 2
3484 && !parameters
->options().output_is_position_independent()
3485 && !is_branch_reloc
<size
>(this->r_type_
))
3486 target
->glink_section()->add_global_entry(gsym
);
3489 if (stub_table
== NULL
3492 && !parameters
->options().output_is_position_independent()
3493 && !is_branch_reloc
<size
>(this->r_type_
)))
3494 stub_table
= this->object_
->stub_table(this->shndx_
);
3495 if (stub_table
== NULL
)
3497 // This is a ref from a data section to an ifunc symbol,
3498 // or a non-branch reloc for which we always want to use
3499 // one set of stubs for resolving function addresses.
3500 stub_table
= ifunc_stub_table
;
3502 gold_assert(stub_table
!= NULL
);
3503 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3504 if (from
!= invalid_address
)
3505 from
+= (this->object_
->output_section(this->shndx_
)->address()
3508 ok
= stub_table
->add_plt_call_entry(from
,
3509 this->object_
, gsym
,
3510 this->r_type_
, this->addend_
,
3513 ok
= stub_table
->add_plt_call_entry(from
,
3514 this->object_
, this->r_sym_
,
3515 this->r_type_
, this->addend_
,
3521 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3522 if (max_branch_offset
== 0)
3524 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3525 gold_assert(from
!= invalid_address
);
3526 from
+= (this->object_
->output_section(this->shndx_
)->address()
3531 switch (gsym
->source())
3533 case Symbol::FROM_OBJECT
:
3535 Object
* symobj
= gsym
->object();
3536 if (symobj
->is_dynamic()
3537 || symobj
->pluginobj() != NULL
)
3540 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3541 if (shndx
== elfcpp::SHN_UNDEF
)
3546 case Symbol::IS_UNDEFINED
:
3552 Symbol_table::Compute_final_value_status status
;
3553 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3554 if (status
!= Symbol_table::CFVS_OK
)
3557 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3561 const Symbol_value
<size
>* psymval
3562 = this->object_
->local_symbol(this->r_sym_
);
3563 Symbol_value
<size
> symval
;
3564 if (psymval
->is_section_symbol())
3565 symval
.set_is_section_symbol();
3566 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3567 typename
ObjType::Compute_final_local_value_status status
3568 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3570 if (status
!= ObjType::CFLV_OK
3571 || !symval
.has_output_value())
3573 to
= symval
.value(this->object_
, 0);
3575 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3577 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3578 to
+= this->addend_
;
3579 if (stub_table
== NULL
)
3580 stub_table
= this->object_
->stub_table(this->shndx_
);
3581 if (size
== 64 && target
->abiversion() < 2)
3583 unsigned int dest_shndx
;
3584 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3588 Address delta
= to
- from
;
3589 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3591 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3593 ? this->object_
->ppc64_needs_toc(gsym
)
3594 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3596 if (stub_table
== NULL
)
3598 gold_warning(_("%s:%s: branch in non-executable section,"
3599 " no long branch stub for you"),
3600 this->object_
->name().c_str(),
3601 this->object_
->section_name(this->shndx_
).c_str());
3604 bool save_res
= (size
== 64
3606 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3607 && gsym
->output_data() == target
->savres_section());
3608 ok
= stub_table
->add_long_branch_entry(this->object_
,
3610 from
, to
, save_res
);
3614 gold_debug(DEBUG_TARGET
,
3615 "branch at %s:%s+%#lx\n"
3616 "can't reach stub attached to %s:%s",
3617 this->object_
->name().c_str(),
3618 this->object_
->section_name(this->shndx_
).c_str(),
3619 (unsigned long) this->offset_
,
3620 stub_table
->relobj()->name().c_str(),
3621 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3626 // Relaxation hook. This is where we do stub generation.
3628 template<int size
, bool big_endian
>
3630 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3631 const Input_objects
*,
3632 Symbol_table
* symtab
,
3636 unsigned int prev_brlt_size
= 0;
3640 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3642 && this->abiversion() < 2
3644 && !parameters
->options().user_set_plt_thread_safe())
3646 static const char* const thread_starter
[] =
3650 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3652 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3653 "mq_notify", "create_timer",
3658 "GOMP_parallel_start",
3659 "GOMP_parallel_loop_static",
3660 "GOMP_parallel_loop_static_start",
3661 "GOMP_parallel_loop_dynamic",
3662 "GOMP_parallel_loop_dynamic_start",
3663 "GOMP_parallel_loop_guided",
3664 "GOMP_parallel_loop_guided_start",
3665 "GOMP_parallel_loop_runtime",
3666 "GOMP_parallel_loop_runtime_start",
3667 "GOMP_parallel_sections",
3668 "GOMP_parallel_sections_start",
3673 if (parameters
->options().shared())
3677 for (unsigned int i
= 0;
3678 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3681 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3682 thread_safe
= (sym
!= NULL
3684 && sym
->in_real_elf());
3690 this->plt_thread_safe_
= thread_safe
;
3695 this->stub_group_size_
= parameters
->options().stub_group_size();
3696 bool no_size_errors
= true;
3697 if (this->stub_group_size_
== 1)
3698 this->stub_group_size_
= 0x1c00000;
3699 else if (this->stub_group_size_
== -1)
3700 this->stub_group_size_
= -0x1e00000;
3702 no_size_errors
= false;
3703 this->group_sections(layout
, task
, no_size_errors
);
3705 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3707 this->branch_lookup_table_
.clear();
3708 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3709 p
!= this->stub_tables_
.end();
3712 (*p
)->clear_stubs(true);
3714 this->stub_tables_
.clear();
3715 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3716 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3717 program_name
, this->stub_group_size_
);
3718 this->group_sections(layout
, task
, true);
3721 // We need address of stub tables valid for make_stub.
3722 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3723 p
!= this->stub_tables_
.end();
3726 const Powerpc_relobj
<size
, big_endian
>* object
3727 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3728 Address off
= object
->get_output_section_offset((*p
)->shndx());
3729 gold_assert(off
!= invalid_address
);
3730 Output_section
* os
= (*p
)->output_section();
3731 (*p
)->set_address_and_size(os
, off
);
3736 // Clear plt call stubs, long branch stubs and branch lookup table.
3737 prev_brlt_size
= this->branch_lookup_table_
.size();
3738 this->branch_lookup_table_
.clear();
3739 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3740 p
!= this->stub_tables_
.end();
3743 (*p
)->clear_stubs(false);
3747 // Build all the stubs.
3748 this->relax_failed_
= false;
3749 Stub_table
<size
, big_endian
>* ifunc_stub_table
3750 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3751 Stub_table
<size
, big_endian
>* one_stub_table
3752 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3753 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3754 b
!= this->branch_info_
.end();
3757 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3758 && !this->relax_failed_
)
3760 this->relax_failed_
= true;
3761 this->relax_fail_count_
++;
3762 if (this->relax_fail_count_
< 3)
3766 bool do_resize
= false;
3767 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3768 p
!= this->stub_tables_
.end();
3770 if ((*p
)->need_resize())
3777 this->branch_lookup_table_
.clear();
3778 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3779 p
!= this->stub_tables_
.end();
3781 (*p
)->set_resizing(true);
3782 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3783 b
!= this->branch_info_
.end();
3786 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3787 && !this->relax_failed_
)
3789 this->relax_failed_
= true;
3790 this->relax_fail_count_
++;
3791 if (this->relax_fail_count_
< 3)
3795 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3796 p
!= this->stub_tables_
.end();
3798 (*p
)->set_resizing(false);
3801 // Did anything change size?
3802 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3803 bool again
= num_huge_branches
!= prev_brlt_size
;
3804 if (size
== 64 && num_huge_branches
!= 0)
3805 this->make_brlt_section(layout
);
3806 if (size
== 64 && again
)
3807 this->brlt_section_
->set_current_size(num_huge_branches
);
3809 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3810 p
!= this->stub_tables_
.rend();
3812 (*p
)->remove_eh_frame(layout
);
3814 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3815 p
!= this->stub_tables_
.end();
3817 (*p
)->add_eh_frame(layout
);
3819 typedef Unordered_set
<Output_section
*> Output_sections
;
3820 Output_sections os_need_update
;
3821 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3822 p
!= this->stub_tables_
.end();
3825 if ((*p
)->size_update())
3828 os_need_update
.insert((*p
)->output_section());
3832 // Set output section offsets for all input sections in an output
3833 // section that just changed size. Anything past the stubs will
3835 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3836 p
!= os_need_update
.end();
3839 Output_section
* os
= *p
;
3841 typedef Output_section::Input_section_list Input_section_list
;
3842 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3843 i
!= os
->input_sections().end();
3846 off
= align_address(off
, i
->addralign());
3847 if (i
->is_input_section() || i
->is_relaxed_input_section())
3848 i
->relobj()->set_section_offset(i
->shndx(), off
);
3849 if (i
->is_relaxed_input_section())
3851 Stub_table
<size
, big_endian
>* stub_table
3852 = static_cast<Stub_table
<size
, big_endian
>*>(
3853 i
->relaxed_input_section());
3854 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3855 off
+= stub_table_size
;
3856 // After a few iterations, set current stub table size
3857 // as min size threshold, so later stub tables can only
3860 stub_table
->set_min_size_threshold(stub_table_size
);
3863 off
+= i
->data_size();
3865 // If .branch_lt is part of this output section, then we have
3866 // just done the offset adjustment.
3867 os
->clear_section_offsets_need_adjustment();
3872 && num_huge_branches
!= 0
3873 && parameters
->options().output_is_position_independent())
3875 // Fill in the BRLT relocs.
3876 this->brlt_section_
->reset_brlt_sizes();
3877 for (typename
Branch_lookup_table::const_iterator p
3878 = this->branch_lookup_table_
.begin();
3879 p
!= this->branch_lookup_table_
.end();
3882 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3884 this->brlt_section_
->finalize_brlt_sizes();
3888 && (parameters
->options().user_set_emit_stub_syms()
3889 ? parameters
->options().emit_stub_syms()
3891 || parameters
->options().output_is_position_independent()
3892 || parameters
->options().emit_relocs())))
3894 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3895 p
!= this->stub_tables_
.end();
3897 (*p
)->define_stub_syms(symtab
);
3899 if (this->glink_
!= NULL
)
3901 int stub_size
= this->glink_
->pltresolve_size();
3902 Address value
= -stub_size
;
3908 this->define_local(symtab
, "__glink_PLTresolve",
3909 this->glink_
, value
, stub_size
);
3912 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3919 template<int size
, bool big_endian
>
3921 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3922 unsigned char* oview
,
3926 uint64_t address
= plt
->address();
3927 off_t len
= plt
->data_size();
3929 if (plt
== this->glink_
)
3931 // See Output_data_glink::do_write() for glink contents.
3934 gold_assert(parameters
->doing_static_link());
3935 // Static linking may need stubs, to support ifunc and long
3936 // branches. We need to create an output section for
3937 // .eh_frame early in the link process, to have a place to
3938 // attach stub .eh_frame info. We also need to have
3939 // registered a CIE that matches the stub CIE. Both of
3940 // these requirements are satisfied by creating an FDE and
3941 // CIE for .glink, even though static linking will leave
3942 // .glink zero length.
3943 // ??? Hopefully generating an FDE with a zero address range
3944 // won't confuse anything that consumes .eh_frame info.
3946 else if (size
== 64)
3948 // There is one word before __glink_PLTresolve
3952 else if (parameters
->options().output_is_position_independent())
3954 // There are two FDEs for a position independent glink.
3955 // The first covers the branch table, the second
3956 // __glink_PLTresolve at the end of glink.
3957 off_t resolve_size
= this->glink_
->pltresolve_size();
3958 if (oview
[9] == elfcpp::DW_CFA_nop
)
3959 len
-= resolve_size
;
3962 address
+= len
- resolve_size
;
3969 // Must be a stub table.
3970 const Stub_table
<size
, big_endian
>* stub_table
3971 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3972 uint64_t stub_address
= stub_table
->stub_address();
3973 len
-= stub_address
- address
;
3974 address
= stub_address
;
3977 *paddress
= address
;
3981 // A class to handle the PLT data.
3983 template<int size
, bool big_endian
>
3984 class Output_data_plt_powerpc
: public Output_section_data_build
3987 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3988 size
, big_endian
> Reloc_section
;
3990 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3991 Reloc_section
* plt_rel
,
3993 : Output_section_data_build(size
== 32 ? 4 : 8),
3999 // Add an entry to the PLT.
4004 add_ifunc_entry(Symbol
*);
4007 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4010 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4012 // Return the .rela.plt section data.
4019 // Return the number of PLT entries.
4023 if (this->current_data_size() == 0)
4025 return ((this->current_data_size() - this->first_plt_entry_offset())
4026 / this->plt_entry_size());
4031 do_adjust_output_section(Output_section
* os
)
4036 // Write to a map file.
4038 do_print_to_mapfile(Mapfile
* mapfile
) const
4039 { mapfile
->print_output_data(this, this->name_
); }
4042 // Return the offset of the first non-reserved PLT entry.
4044 first_plt_entry_offset() const
4046 // IPLT and LPLT have no reserved entry.
4047 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4049 return this->targ_
->first_plt_entry_offset();
4052 // Return the size of each PLT entry.
4054 plt_entry_size() const
4056 return this->targ_
->plt_entry_size();
4059 // Write out the PLT data.
4061 do_write(Output_file
*);
4063 // The reloc section.
4064 Reloc_section
* rel_
;
4065 // Allows access to .glink for do_write.
4066 Target_powerpc
<size
, big_endian
>* targ_
;
4067 // What to report in map file.
4071 // Add an entry to the PLT.
4073 template<int size
, bool big_endian
>
4075 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4077 if (!gsym
->has_plt_offset())
4079 section_size_type off
= this->current_data_size();
4081 off
+= this->first_plt_entry_offset();
4082 gsym
->set_plt_offset(off
);
4083 gsym
->set_needs_dynsym_entry();
4084 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4085 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4086 off
+= this->plt_entry_size();
4087 this->set_current_data_size(off
);
4091 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4093 template<int size
, bool big_endian
>
4095 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4097 if (!gsym
->has_plt_offset())
4099 section_size_type off
= this->current_data_size();
4100 gsym
->set_plt_offset(off
);
4101 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4102 if (size
== 64 && this->targ_
->abiversion() < 2)
4103 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4104 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4105 off
+= this->plt_entry_size();
4106 this->set_current_data_size(off
);
4110 // Add an entry for a local symbol to the PLT.
4112 template<int size
, bool big_endian
>
4114 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4115 Sized_relobj_file
<size
, big_endian
>* relobj
,
4116 unsigned int local_sym_index
)
4118 if (!relobj
->local_has_plt_offset(local_sym_index
))
4120 section_size_type off
= this->current_data_size();
4121 relobj
->set_local_plt_offset(local_sym_index
, off
);
4124 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4125 if (size
== 64 && this->targ_
->abiversion() < 2)
4126 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4127 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4128 dynrel
, this, off
, 0);
4130 off
+= this->plt_entry_size();
4131 this->set_current_data_size(off
);
4135 // Add an entry for a local ifunc symbol to the IPLT.
4137 template<int size
, bool big_endian
>
4139 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4140 Sized_relobj_file
<size
, big_endian
>* relobj
,
4141 unsigned int local_sym_index
)
4143 if (!relobj
->local_has_plt_offset(local_sym_index
))
4145 section_size_type off
= this->current_data_size();
4146 relobj
->set_local_plt_offset(local_sym_index
, off
);
4147 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4148 if (size
== 64 && this->targ_
->abiversion() < 2)
4149 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4150 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4152 off
+= this->plt_entry_size();
4153 this->set_current_data_size(off
);
4157 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4158 static const uint32_t add_2_2_11
= 0x7c425a14;
4159 static const uint32_t add_2_2_12
= 0x7c426214;
4160 static const uint32_t add_3_3_2
= 0x7c631214;
4161 static const uint32_t add_3_3_13
= 0x7c636a14;
4162 static const uint32_t add_3_12_2
= 0x7c6c1214;
4163 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4164 static const uint32_t add_11_0_11
= 0x7d605a14;
4165 static const uint32_t add_11_2_11
= 0x7d625a14;
4166 static const uint32_t add_11_11_2
= 0x7d6b1214;
4167 static const uint32_t add_12_11_12
= 0x7d8b6214;
4168 static const uint32_t addi_0_12
= 0x380c0000;
4169 static const uint32_t addi_2_2
= 0x38420000;
4170 static const uint32_t addi_3_3
= 0x38630000;
4171 static const uint32_t addi_11_11
= 0x396b0000;
4172 static const uint32_t addi_12_1
= 0x39810000;
4173 static const uint32_t addi_12_11
= 0x398b0000;
4174 static const uint32_t addi_12_12
= 0x398c0000;
4175 static const uint32_t addis_0_2
= 0x3c020000;
4176 static const uint32_t addis_0_13
= 0x3c0d0000;
4177 static const uint32_t addis_2_12
= 0x3c4c0000;
4178 static const uint32_t addis_11_2
= 0x3d620000;
4179 static const uint32_t addis_11_11
= 0x3d6b0000;
4180 static const uint32_t addis_11_30
= 0x3d7e0000;
4181 static const uint32_t addis_12_1
= 0x3d810000;
4182 static const uint32_t addis_12_2
= 0x3d820000;
4183 static const uint32_t addis_12_11
= 0x3d8b0000;
4184 static const uint32_t addis_12_12
= 0x3d8c0000;
4185 static const uint32_t b
= 0x48000000;
4186 static const uint32_t bcl_20_31
= 0x429f0005;
4187 static const uint32_t bctr
= 0x4e800420;
4188 static const uint32_t bctrl
= 0x4e800421;
4189 static const uint32_t beqlr
= 0x4d820020;
4190 static const uint32_t blr
= 0x4e800020;
4191 static const uint32_t bnectr_p4
= 0x4ce20420;
4192 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4193 static const uint32_t cmpldi_2_0
= 0x28220000;
4194 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4195 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4196 static const uint32_t cror_15_15_15
= 0x4def7b82;
4197 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4198 static const uint32_t ld_0_1
= 0xe8010000;
4199 static const uint32_t ld_0_11
= 0xe80b0000;
4200 static const uint32_t ld_0_12
= 0xe80c0000;
4201 static const uint32_t ld_2_1
= 0xe8410000;
4202 static const uint32_t ld_2_2
= 0xe8420000;
4203 static const uint32_t ld_2_11
= 0xe84b0000;
4204 static const uint32_t ld_2_12
= 0xe84c0000;
4205 static const uint32_t ld_11_1
= 0xe9610000;
4206 static const uint32_t ld_11_2
= 0xe9620000;
4207 static const uint32_t ld_11_3
= 0xe9630000;
4208 static const uint32_t ld_11_11
= 0xe96b0000;
4209 static const uint32_t ld_12_2
= 0xe9820000;
4210 static const uint32_t ld_12_3
= 0xe9830000;
4211 static const uint32_t ld_12_11
= 0xe98b0000;
4212 static const uint32_t ld_12_12
= 0xe98c0000;
4213 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4214 static const uint32_t lfd_0_1
= 0xc8010000;
4215 static const uint32_t li_0_0
= 0x38000000;
4216 static const uint32_t li_11_0
= 0x39600000;
4217 static const uint32_t li_12_0
= 0x39800000;
4218 static const uint32_t lis_0
= 0x3c000000;
4219 static const uint32_t lis_2
= 0x3c400000;
4220 static const uint32_t lis_11
= 0x3d600000;
4221 static const uint32_t lis_12
= 0x3d800000;
4222 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4223 static const uint32_t lwz_0_12
= 0x800c0000;
4224 static const uint32_t lwz_11_3
= 0x81630000;
4225 static const uint32_t lwz_11_11
= 0x816b0000;
4226 static const uint32_t lwz_11_30
= 0x817e0000;
4227 static const uint32_t lwz_12_3
= 0x81830000;
4228 static const uint32_t lwz_12_12
= 0x818c0000;
4229 static const uint32_t lwzu_0_12
= 0x840c0000;
4230 static const uint32_t mflr_0
= 0x7c0802a6;
4231 static const uint32_t mflr_11
= 0x7d6802a6;
4232 static const uint32_t mflr_12
= 0x7d8802a6;
4233 static const uint32_t mr_0_3
= 0x7c601b78;
4234 static const uint32_t mr_3_0
= 0x7c030378;
4235 static const uint32_t mtctr_0
= 0x7c0903a6;
4236 static const uint32_t mtctr_11
= 0x7d6903a6;
4237 static const uint32_t mtctr_12
= 0x7d8903a6;
4238 static const uint32_t mtlr_0
= 0x7c0803a6;
4239 static const uint32_t mtlr_11
= 0x7d6803a6;
4240 static const uint32_t mtlr_12
= 0x7d8803a6;
4241 static const uint32_t nop
= 0x60000000;
4242 static const uint32_t ori_0_0_0
= 0x60000000;
4243 static const uint32_t ori_11_11_0
= 0x616b0000;
4244 static const uint32_t ori_12_12_0
= 0x618c0000;
4245 static const uint32_t oris_12_12_0
= 0x658c0000;
4246 static const uint32_t sldi_11_11_34
= 0x796b1746;
4247 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4248 static const uint32_t srdi_0_0_2
= 0x7800f082;
4249 static const uint32_t std_0_1
= 0xf8010000;
4250 static const uint32_t std_0_12
= 0xf80c0000;
4251 static const uint32_t std_2_1
= 0xf8410000;
4252 static const uint32_t std_11_1
= 0xf9610000;
4253 static const uint32_t stfd_0_1
= 0xd8010000;
4254 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4255 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4256 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4257 static const uint32_t xor_2_12_12
= 0x7d826278;
4258 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4260 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4261 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4262 static const uint64_t pnop
= 0x0700000000000000ULL
;
4264 // Write out the PLT.
4266 template<int size
, bool big_endian
>
4268 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4270 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4272 const section_size_type offset
= this->offset();
4273 const section_size_type oview_size
4274 = convert_to_section_size_type(this->data_size());
4275 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4276 unsigned char* pov
= oview
;
4277 unsigned char* endpov
= oview
+ oview_size
;
4279 // The address of the .glink branch table
4280 const Output_data_glink
<size
, big_endian
>* glink
4281 = this->targ_
->glink_section();
4282 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4284 while (pov
< endpov
)
4286 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4291 of
->write_output_view(offset
, oview_size
, oview
);
4295 // Create the PLT section.
4297 template<int size
, bool big_endian
>
4299 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4302 if (this->plt_
== NULL
)
4304 if (this->got_
== NULL
)
4305 this->got_section(symtab
, layout
);
4307 if (this->glink_
== NULL
)
4308 make_glink_section(layout
);
4310 // Ensure that .rela.dyn always appears before .rela.plt This is
4311 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4312 // needs to include .rela.plt in its range.
4313 this->rela_dyn_section(layout
);
4315 Reloc_section
* plt_rel
= new Reloc_section(false);
4316 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4317 elfcpp::SHF_ALLOC
, plt_rel
,
4318 ORDER_DYNAMIC_PLT_RELOCS
, false);
4320 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4322 layout
->add_output_section_data(".plt",
4324 ? elfcpp::SHT_PROGBITS
4325 : elfcpp::SHT_NOBITS
),
4326 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4333 Output_section
* rela_plt_os
= plt_rel
->output_section();
4334 rela_plt_os
->set_info_section(this->plt_
->output_section());
4338 // Create the IPLT section.
4340 template<int size
, bool big_endian
>
4342 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4345 if (this->iplt_
== NULL
)
4347 this->make_plt_section(symtab
, layout
);
4348 this->make_lplt_section(layout
);
4350 Reloc_section
* iplt_rel
= new Reloc_section(false);
4351 if (this->rela_dyn_
->output_section())
4352 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4354 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4356 if (this->plt_
->output_section())
4357 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4361 // Create the LPLT section.
4363 template<int size
, bool big_endian
>
4365 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4367 if (this->lplt_
== NULL
)
4369 Reloc_section
* lplt_rel
= NULL
;
4370 if (parameters
->options().output_is_position_independent())
4372 lplt_rel
= new Reloc_section(false);
4373 this->rela_dyn_section(layout
);
4374 if (this->rela_dyn_
->output_section())
4375 this->rela_dyn_
->output_section()
4376 ->add_output_section_data(lplt_rel
);
4379 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4381 this->make_brlt_section(layout
);
4382 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4383 this->brlt_section_
->output_section()
4384 ->add_output_section_data(this->lplt_
);
4386 layout
->add_output_section_data(".branch_lt",
4387 elfcpp::SHT_PROGBITS
,
4388 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4395 // A section for huge long branch addresses, similar to plt section.
4397 template<int size
, bool big_endian
>
4398 class Output_data_brlt_powerpc
: public Output_section_data_build
4401 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4402 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4403 size
, big_endian
> Reloc_section
;
4405 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4406 Reloc_section
* brlt_rel
)
4407 : Output_section_data_build(size
== 32 ? 4 : 8),
4415 this->reset_data_size();
4416 this->rel_
->reset_data_size();
4420 finalize_brlt_sizes()
4422 this->finalize_data_size();
4423 this->rel_
->finalize_data_size();
4426 // Add a reloc for an entry in the BRLT.
4428 add_reloc(Address to
, unsigned int off
)
4429 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4431 // Update section and reloc section size.
4433 set_current_size(unsigned int num_branches
)
4435 this->reset_address_and_file_offset();
4436 this->set_current_data_size(num_branches
* 16);
4437 this->finalize_data_size();
4438 Output_section
* os
= this->output_section();
4439 os
->set_section_offsets_need_adjustment();
4440 if (this->rel_
!= NULL
)
4442 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4443 this->rel_
->reset_address_and_file_offset();
4444 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4445 this->rel_
->finalize_data_size();
4446 Output_section
* os
= this->rel_
->output_section();
4447 os
->set_section_offsets_need_adjustment();
4453 do_adjust_output_section(Output_section
* os
)
4458 // Write to a map file.
4460 do_print_to_mapfile(Mapfile
* mapfile
) const
4461 { mapfile
->print_output_data(this, "** BRLT"); }
4464 // Write out the BRLT data.
4466 do_write(Output_file
*);
4468 // The reloc section.
4469 Reloc_section
* rel_
;
4470 Target_powerpc
<size
, big_endian
>* targ_
;
4473 // Make the branch lookup table section.
4475 template<int size
, bool big_endian
>
4477 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4479 if (size
== 64 && this->brlt_section_
== NULL
)
4481 Reloc_section
* brlt_rel
= NULL
;
4482 bool is_pic
= parameters
->options().output_is_position_independent();
4485 // When PIC we can't fill in .branch_lt but must initialise at
4486 // runtime via dynamic relocations.
4487 this->rela_dyn_section(layout
);
4488 brlt_rel
= new Reloc_section(false);
4489 if (this->rela_dyn_
->output_section())
4490 this->rela_dyn_
->output_section()
4491 ->add_output_section_data(brlt_rel
);
4494 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4495 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4496 this->plt_
->output_section()
4497 ->add_output_section_data(this->brlt_section_
);
4499 layout
->add_output_section_data(".branch_lt",
4500 elfcpp::SHT_PROGBITS
,
4501 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4502 this->brlt_section_
,
4508 // Write out .branch_lt when non-PIC.
4510 template<int size
, bool big_endian
>
4512 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4514 if (size
== 64 && !parameters
->options().output_is_position_independent())
4516 const section_size_type offset
= this->offset();
4517 const section_size_type oview_size
4518 = convert_to_section_size_type(this->data_size());
4519 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4521 this->targ_
->write_branch_lookup_table(oview
);
4522 of
->write_output_view(offset
, oview_size
, oview
);
4526 static inline uint32_t
4532 static inline uint32_t
4538 static inline uint32_t
4541 return hi(a
+ 0x8000);
4544 static inline uint64_t
4547 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4550 static inline uint64_t
4553 return (v
+ (1ULL << 33)) >> 34;
4559 static const unsigned char eh_frame_cie
[12];
4563 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4566 'z', 'R', 0, // Augmentation string.
4567 4, // Code alignment.
4568 0x80 - size
/ 8 , // Data alignment.
4570 1, // Augmentation size.
4571 (elfcpp::DW_EH_PE_pcrel
4572 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4573 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4576 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4577 static const unsigned char glink_eh_frame_fde_64v1
[] =
4579 0, 0, 0, 0, // Replaced with offset to .glink.
4580 0, 0, 0, 0, // Replaced with size of .glink.
4581 0, // Augmentation size.
4582 elfcpp::DW_CFA_advance_loc
+ 2,
4583 elfcpp::DW_CFA_register
, 65, 12,
4584 elfcpp::DW_CFA_advance_loc
+ 4,
4585 elfcpp::DW_CFA_restore_extended
, 65
4588 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4589 static const unsigned char glink_eh_frame_fde_64v2
[] =
4591 0, 0, 0, 0, // Replaced with offset to .glink.
4592 0, 0, 0, 0, // Replaced with size of .glink.
4593 0, // Augmentation size.
4594 elfcpp::DW_CFA_advance_loc
+ 2,
4595 elfcpp::DW_CFA_register
, 65, 0,
4596 elfcpp::DW_CFA_advance_loc
+ 2,
4597 elfcpp::DW_CFA_restore_extended
, 65
4600 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4602 0, 0, 0, 0, // Replaced with offset to .glink.
4603 0, 0, 0, 0, // Replaced with size of .glink.
4604 0, // Augmentation size.
4605 elfcpp::DW_CFA_advance_loc
+ 3,
4606 elfcpp::DW_CFA_register
, 65, 0,
4607 elfcpp::DW_CFA_advance_loc
+ 2,
4608 elfcpp::DW_CFA_restore_extended
, 65
4611 // Describe __glink_PLTresolve use of LR, 32-bit version.
4612 static const unsigned char glink_eh_frame_fde_32
[] =
4614 0, 0, 0, 0, // Replaced with offset to .glink.
4615 0, 0, 0, 0, // Replaced with size of .glink.
4616 0, // Augmentation size.
4617 elfcpp::DW_CFA_advance_loc
+ 2,
4618 elfcpp::DW_CFA_register
, 65, 0,
4619 elfcpp::DW_CFA_advance_loc
+ 4,
4620 elfcpp::DW_CFA_restore_extended
, 65
4623 static const unsigned char default_fde
[] =
4625 0, 0, 0, 0, // Replaced with offset to stubs.
4626 0, 0, 0, 0, // Replaced with size of stubs.
4627 0, // Augmentation size.
4628 elfcpp::DW_CFA_nop
, // Pad.
4633 template<bool big_endian
>
4635 write_insn(unsigned char* p
, uint32_t v
)
4637 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4641 static inline unsigned int
4644 if (!parameters
->options().user_set_plt_align())
4645 return size
== 64 ? 32 : 8;
4646 return 1 << parameters
->options().plt_align();
4649 // Stub_table holds information about plt and long branch stubs.
4650 // Stubs are built in an area following some input section determined
4651 // by group_sections(). This input section is converted to a relaxed
4652 // input section allowing it to be resized to accommodate the stubs
4654 template<int size
, bool big_endian
>
4655 class Stub_table
: public Output_relaxed_input_section
4660 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4661 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4662 r2save_(0), localentry0_(0), tocoff_(0)
4667 unsigned int iter_
: 1;
4668 unsigned int notoc_
: 1;
4669 unsigned int toc_
: 1;
4670 unsigned int r2save_
: 1;
4671 unsigned int localentry0_
: 1;
4672 unsigned int tocoff_
: 8;
4674 struct Branch_stub_ent
4676 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4677 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4682 unsigned int iter_
: 1;
4683 unsigned int notoc_
: 1;
4684 unsigned int toc_
: 1;
4685 unsigned int save_res_
: 1;
4686 unsigned int tocoff_
: 8;
4688 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4689 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4691 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4692 Output_section
* output_section
,
4693 const Output_section::Input_section
* owner
,
4695 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4697 ->section_addralign(owner
->shndx())),
4698 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4699 orig_data_size_(owner
->current_data_size()),
4700 plt_size_(0), last_plt_size_(0),
4701 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4702 need_save_res_(false), need_resize_(false), resizing_(false),
4705 this->set_output_section(output_section
);
4707 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4708 new_relaxed
.push_back(this);
4709 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4712 // Add a plt call stub.
4714 add_plt_call_entry(Address
,
4715 const Sized_relobj_file
<size
, big_endian
>*,
4722 add_plt_call_entry(Address
,
4723 const Sized_relobj_file
<size
, big_endian
>*,
4729 // Find a given plt call stub.
4731 find_plt_call_entry(const Symbol
*) const;
4734 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4735 unsigned int) const;
4738 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4744 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4749 // Add a long branch stub.
4751 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4752 unsigned int, Address
, Address
, bool);
4754 const Branch_stub_ent
*
4755 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4759 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4761 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4762 if (max_branch_offset
== 0)
4764 gold_assert(from
!= invalid_address
);
4765 Address loc
= off
+ this->stub_address();
4766 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4770 clear_stubs(bool all
)
4772 this->plt_call_stubs_
.clear();
4773 this->plt_size_
= 0;
4774 this->long_branch_stubs_
.clear();
4775 this->branch_size_
= 0;
4776 this->need_save_res_
= false;
4779 this->last_plt_size_
= 0;
4780 this->last_branch_size_
= 0;
4786 { return need_resize_
; }
4789 set_resizing(bool val
)
4791 this->resizing_
= val
;
4794 this->need_resize_
= false;
4795 this->plt_size_
= 0;
4796 this->branch_size_
= 0;
4797 this->need_save_res_
= false;
4802 set_address_and_size(const Output_section
* os
, Address off
)
4804 Address start_off
= off
;
4805 off
+= this->orig_data_size_
;
4806 Address my_size
= this->plt_size_
+ this->branch_size_
;
4807 if (this->need_save_res_
)
4808 my_size
+= this->targ_
->savres_section()->data_size();
4810 off
= align_address(off
, this->stub_align());
4811 // Include original section size and alignment padding in size
4812 my_size
+= off
- start_off
;
4813 // Ensure new size is always larger than min size
4814 // threshold. Alignment requirement is included in "my_size", so
4815 // increase "my_size" does not invalidate alignment.
4816 if (my_size
< this->min_size_threshold_
)
4817 my_size
= this->min_size_threshold_
;
4818 this->reset_address_and_file_offset();
4819 this->set_current_data_size(my_size
);
4820 this->set_address_and_file_offset(os
->address() + start_off
,
4821 os
->offset() + start_off
);
4826 stub_address() const
4828 return align_address(this->address() + this->orig_data_size_
,
4829 this->stub_align());
4835 return align_address(this->offset() + this->orig_data_size_
,
4836 this->stub_align());
4841 { return this->plt_size_
; }
4845 { return this->branch_size_
; }
4848 set_min_size_threshold(Address min_size
)
4849 { this->min_size_threshold_
= min_size
; }
4852 define_stub_syms(Symbol_table
*);
4857 Output_section
* os
= this->output_section();
4858 if (os
->addralign() < this->stub_align())
4860 os
->set_addralign(this->stub_align());
4861 // FIXME: get rid of the insane checkpointing.
4862 // We can't increase alignment of the input section to which
4863 // stubs are attached; The input section may be .init which
4864 // is pasted together with other .init sections to form a
4865 // function. Aligning might insert zero padding resulting in
4866 // sigill. However we do need to increase alignment of the
4867 // output section so that the align_address() on offset in
4868 // set_address_and_size() adds the same padding as the
4869 // align_address() on address in stub_address().
4870 // What's more, we need this alignment for the layout done in
4871 // relaxation_loop_body() so that the output section starts at
4872 // a suitably aligned address.
4873 os
->checkpoint_set_addralign(this->stub_align());
4875 if (this->last_plt_size_
!= this->plt_size_
4876 || this->last_branch_size_
!= this->branch_size_
)
4878 this->last_plt_size_
= this->plt_size_
;
4879 this->last_branch_size_
= this->branch_size_
;
4885 // Add .eh_frame info for this stub section.
4887 add_eh_frame(Layout
* layout
);
4889 // Remove .eh_frame info for this stub section.
4891 remove_eh_frame(Layout
* layout
);
4893 Target_powerpc
<size
, big_endian
>*
4899 class Plt_stub_key_hash
;
4900 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4901 Plt_stub_key_hash
> Plt_stub_entries
;
4902 class Branch_stub_key
;
4903 class Branch_stub_key_hash
;
4904 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4905 Branch_stub_key_hash
> Branch_stub_entries
;
4907 // Alignment of stub section.
4911 unsigned int min_align
= size
== 64 ? 32 : 16;
4912 unsigned int user_align
= 1 << parameters
->options().plt_align();
4913 return std::max(user_align
, min_align
);
4916 // Return the plt offset for the given call stub.
4918 plt_off(typename
Plt_stub_entries::const_iterator p
,
4919 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4921 const Symbol
* gsym
= p
->first
.sym_
;
4923 return this->targ_
->plt_off(gsym
, sec
);
4926 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4927 unsigned int local_sym_index
= p
->first
.locsym_
;
4928 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4932 // Size of a given plt call stub.
4934 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4937 plt_call_align(unsigned int bytes
) const
4939 unsigned int align
= param_plt_align
<size
>();
4940 return (bytes
+ align
- 1) & -align
;
4943 // Return long branch stub size.
4945 branch_stub_size(typename
Branch_stub_entries::iterator p
,
4949 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
4952 build_tls_opt_tail(unsigned char* p
);
4955 plt_error(const Plt_stub_key
& p
);
4959 do_write(Output_file
*);
4961 // Plt call stub keys.
4965 Plt_stub_key(const Symbol
* sym
)
4966 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4969 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4970 unsigned int locsym_index
)
4971 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4974 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4976 unsigned int r_type
,
4978 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4981 this->addend_
= addend
;
4982 else if (parameters
->options().output_is_position_independent()
4983 && (r_type
== elfcpp::R_PPC_PLTREL24
4984 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4986 this->addend_
= addend
;
4987 if (this->addend_
>= 32768)
4988 this->object_
= object
;
4992 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4993 unsigned int locsym_index
,
4994 unsigned int r_type
,
4996 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4999 this->addend_
= addend
;
5000 else if (parameters
->options().output_is_position_independent()
5001 && (r_type
== elfcpp::R_PPC_PLTREL24
5002 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5003 this->addend_
= addend
;
5006 bool operator==(const Plt_stub_key
& that
) const
5008 return (this->sym_
== that
.sym_
5009 && this->object_
== that
.object_
5010 && this->addend_
== that
.addend_
5011 && this->locsym_
== that
.locsym_
);
5015 const Sized_relobj_file
<size
, big_endian
>* object_
;
5016 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5017 unsigned int locsym_
;
5020 class Plt_stub_key_hash
5023 size_t operator()(const Plt_stub_key
& ent
) const
5025 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5026 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5032 // Long branch stub keys.
5033 class Branch_stub_key
5036 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5037 : dest_(to
), toc_base_off_(0)
5040 toc_base_off_
= obj
->toc_base_offset();
5043 bool operator==(const Branch_stub_key
& that
) const
5045 return (this->dest_
== that
.dest_
5047 || this->toc_base_off_
== that
.toc_base_off_
));
5051 unsigned int toc_base_off_
;
5054 class Branch_stub_key_hash
5057 size_t operator()(const Branch_stub_key
& key
) const
5058 { return key
.dest_
^ key
.toc_base_off_
; }
5061 // In a sane world this would be a global.
5062 Target_powerpc
<size
, big_endian
>* targ_
;
5063 // Map sym/object/addend to stub offset.
5064 Plt_stub_entries plt_call_stubs_
;
5065 // Map destination address to stub offset.
5066 Branch_stub_entries long_branch_stubs_
;
5067 // size of input section
5068 section_size_type orig_data_size_
;
5070 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5071 // Some rare cases cause (PR/20529) fluctuation in stub table
5072 // size, which leads to an endless relax loop. This is to be fixed
5073 // by, after the first few iterations, allowing only increase of
5074 // stub table size. This variable sets the minimal possible size of
5075 // a stub table, it is zero for the first few iterations, then
5076 // increases monotonically.
5077 Address min_size_threshold_
;
5078 // Set if this stub group needs a copy of out-of-line register
5079 // save/restore functions.
5080 bool need_save_res_
;
5081 // Set when notoc_/r2save_ changes after sizing a stub
5083 // Set when resizing stubs
5085 // Per stub table unique identifier.
5089 // Add a plt call stub, if we do not already have one for this
5090 // sym/object/addend combo.
5092 template<int size
, bool big_endian
>
5094 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5096 const Sized_relobj_file
<size
, big_endian
>* object
,
5098 unsigned int r_type
,
5102 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5103 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5104 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5105 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5109 && this->targ_
->is_elfv2_localentry0(gsym
))
5111 p
.first
->second
.localentry0_
= 1;
5112 this->targ_
->set_has_localentry0();
5114 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5116 if (!p
.second
&& !p
.first
->second
.notoc_
5117 && (!this->targ_
->power10_stubs()
5118 || this->targ_
->power10_stubs_auto()))
5119 this->need_resize_
= true;
5120 p
.first
->second
.notoc_
= 1;
5124 if (!p
.second
&& !p
.first
->second
.toc_
)
5125 this->need_resize_
= true;
5126 p
.first
->second
.toc_
= 1;
5127 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5129 if (!p
.second
&& !p
.first
->second
.r2save_
)
5130 this->need_resize_
= true;
5131 p
.first
->second
.r2save_
= 1;
5135 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5137 if (this->resizing_
)
5139 p
.first
->second
.iter_
= 1;
5140 p
.first
->second
.off_
= this->plt_size_
;
5142 this->plt_size_
+= this->plt_call_size(p
.first
);
5143 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5144 this->targ_
->set_has_tls_get_addr_opt();
5145 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5147 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5150 template<int size
, bool big_endian
>
5152 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5154 const Sized_relobj_file
<size
, big_endian
>* object
,
5155 unsigned int locsym_index
,
5156 unsigned int r_type
,
5160 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5161 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5162 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5163 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5167 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5169 p
.first
->second
.localentry0_
= 1;
5170 this->targ_
->set_has_localentry0();
5172 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5174 if (!p
.second
&& !p
.first
->second
.notoc_
5175 && (!this->targ_
->power10_stubs()
5176 || this->targ_
->power10_stubs_auto()))
5177 this->need_resize_
= true;
5178 p
.first
->second
.notoc_
= 1;
5182 if (!p
.second
&& !p
.first
->second
.toc_
)
5183 this->need_resize_
= true;
5184 p
.first
->second
.toc_
= 1;
5185 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5187 if (!p
.second
&& !p
.first
->second
.r2save_
)
5188 this->need_resize_
= true;
5189 p
.first
->second
.r2save_
= 1;
5193 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5195 if (this->resizing_
)
5197 p
.first
->second
.iter_
= 1;
5198 p
.first
->second
.off_
= this->plt_size_
;
5200 this->plt_size_
+= this->plt_call_size(p
.first
);
5201 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5203 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5206 // Find a plt call stub.
5208 template<int size
, bool big_endian
>
5209 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5210 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5211 const Sized_relobj_file
<size
, big_endian
>* object
,
5213 unsigned int r_type
,
5214 Address addend
) const
5216 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5217 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5218 if (p
== this->plt_call_stubs_
.end())
5223 template<int size
, bool big_endian
>
5224 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5225 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5227 Plt_stub_key
key(gsym
);
5228 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5229 if (p
== this->plt_call_stubs_
.end())
5234 template<int size
, bool big_endian
>
5235 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5236 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5237 const Sized_relobj_file
<size
, big_endian
>* object
,
5238 unsigned int locsym_index
,
5239 unsigned int r_type
,
5240 Address addend
) const
5242 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5243 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5244 if (p
== this->plt_call_stubs_
.end())
5249 template<int size
, bool big_endian
>
5250 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5251 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5252 const Sized_relobj_file
<size
, big_endian
>* object
,
5253 unsigned int locsym_index
) const
5255 Plt_stub_key
key(object
, locsym_index
);
5256 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5257 if (p
== this->plt_call_stubs_
.end())
5262 // Add a long branch stub if we don't already have one to given
5265 template<int size
, bool big_endian
>
5267 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5268 const Powerpc_relobj
<size
, big_endian
>* object
,
5269 unsigned int r_type
,
5274 Branch_stub_key
key(object
, to
);
5275 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5276 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5277 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5278 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5281 if (!p
.second
&& !p
.first
->second
.notoc_
)
5282 this->need_resize_
= true;
5283 p
.first
->second
.notoc_
= true;
5287 if (!p
.second
&& !p
.first
->second
.toc_
)
5288 this->need_resize_
= true;
5289 p
.first
->second
.toc_
= true;
5291 gold_assert(save_res
== p
.first
->second
.save_res_
);
5292 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5294 if (this->resizing_
)
5296 p
.first
->second
.iter_
= 1;
5297 p
.first
->second
.off_
= this->branch_size_
;
5300 this->need_save_res_
= true;
5303 bool need_lt
= false;
5304 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5305 this->branch_size_
+= stub_size
;
5306 if (size
== 64 && need_lt
)
5307 this->targ_
->add_branch_lookup_table(to
);
5310 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5313 // Find long branch stub offset.
5315 template<int size
, bool big_endian
>
5316 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5317 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5318 const Powerpc_relobj
<size
, big_endian
>* object
,
5321 Branch_stub_key
key(object
, to
);
5322 typename
Branch_stub_entries::const_iterator p
5323 = this->long_branch_stubs_
.find(key
);
5324 if (p
== this->long_branch_stubs_
.end())
5329 template<bool big_endian
>
5331 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5335 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5336 else if (delta
< 256)
5338 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5339 fde
.push_back(delta
);
5341 else if (delta
< 65536)
5343 fde
.resize(fde
.size() + 3);
5344 unsigned char *p
= &*fde
.end() - 3;
5345 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5346 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5350 fde
.resize(fde
.size() + 5);
5351 unsigned char *p
= &*fde
.end() - 5;
5352 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5353 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5357 template<typename T
>
5359 stub_sort(T s1
, T s2
)
5361 return s1
->second
.off_
< s2
->second
.off_
;
5364 // Add .eh_frame info for this stub section. Unlike other linker
5365 // generated .eh_frame this is added late in the link, because we
5366 // only want the .eh_frame info if this particular stub section is
5369 template<int size
, bool big_endian
>
5371 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5374 || !parameters
->options().ld_generated_unwind_info())
5377 // Since we add stub .eh_frame info late, it must be placed
5378 // after all other linker generated .eh_frame info so that
5379 // merge mapping need not be updated for input sections.
5380 // There is no provision to use a different CIE to that used
5382 if (!this->targ_
->has_glink())
5385 typedef typename
Plt_stub_entries::iterator plt_iter
;
5386 std::vector
<plt_iter
> calls
;
5387 if (!this->plt_call_stubs_
.empty())
5388 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5389 cs
!= this->plt_call_stubs_
.end();
5391 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5392 && cs
->second
.r2save_
5393 && !cs
->second
.localentry0_
)
5394 || (cs
->second
.notoc_
5395 && !this->targ_
->power10_stubs()))
5396 calls
.push_back(cs
);
5397 if (calls
.size() > 1)
5398 std::stable_sort(calls
.begin(), calls
.end(),
5399 stub_sort
<plt_iter
>);
5401 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5402 std::vector
<branch_iter
> branches
;
5403 if (!this->long_branch_stubs_
.empty()
5404 && !this->targ_
->power10_stubs())
5405 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5406 bs
!= this->long_branch_stubs_
.end();
5408 if (bs
->second
.notoc_
)
5409 branches
.push_back(bs
);
5410 if (branches
.size() > 1)
5411 std::stable_sort(branches
.begin(), branches
.end(),
5412 stub_sort
<branch_iter
>);
5414 if (calls
.empty() && branches
.empty())
5417 unsigned int last_eh_loc
= 0;
5418 // offset pcrel sdata4, size udata4, and augmentation size byte.
5419 std::vector
<unsigned char> fde(9, 0);
5421 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5423 plt_iter cs
= calls
[i
];
5424 unsigned int off
= cs
->second
.off_
;
5425 // The __tls_get_addr_opt call stub needs to describe where
5426 // it saves LR, to support exceptions that might be thrown
5427 // from __tls_get_addr, and to support asynchronous exceptions.
5428 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5431 if (cs
->second
.r2save_
5432 && !cs
->second
.localentry0_
)
5435 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5436 fde
.resize(fde
.size() + 6);
5437 unsigned char* p
= &*fde
.end() - 6;
5438 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5440 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5441 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5442 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5443 *p
++ = elfcpp::DW_CFA_restore_extended
;
5445 last_eh_loc
= off
+ delta
;
5449 // notoc stubs also should describe LR changes, to support
5450 // asynchronous exceptions.
5451 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5452 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5453 fde
.resize(fde
.size() + 6);
5454 unsigned char* p
= &*fde
.end() - 6;
5455 *p
++ = elfcpp::DW_CFA_register
;
5458 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5459 *p
++ = elfcpp::DW_CFA_restore_extended
;
5461 last_eh_loc
= off
+ 8;
5464 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5466 branch_iter bs
= branches
[i
];
5467 unsigned int off
= bs
->second
.off_
+ 8;
5468 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5469 fde
.resize(fde
.size() + 6);
5470 unsigned char* p
= &*fde
.end() - 6;
5471 *p
++ = elfcpp::DW_CFA_register
;
5474 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5475 *p
++ = elfcpp::DW_CFA_restore_extended
;
5477 last_eh_loc
= off
+ 8;
5480 layout
->add_eh_frame_for_plt(this,
5481 Eh_cie
<size
>::eh_frame_cie
,
5482 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5483 &*fde
.begin(), fde
.size());
5486 template<int size
, bool big_endian
>
5488 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5491 && parameters
->options().ld_generated_unwind_info()
5492 && this->targ_
->has_glink())
5493 layout
->remove_eh_frame_for_plt(this,
5494 Eh_cie
<size
>::eh_frame_cie
,
5495 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5498 // A class to handle .glink.
5500 template<int size
, bool big_endian
>
5501 class Output_data_glink
: public Output_section_data
5504 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5505 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5507 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5508 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5509 end_branch_table_(), ge_size_(0)
5513 add_eh_frame(Layout
* layout
);
5516 add_global_entry(const Symbol
*);
5519 find_global_entry(const Symbol
*) const;
5522 global_entry_align(unsigned int off
) const
5524 unsigned int align
= param_plt_align
<size
>();
5525 return (off
+ align
- 1) & -align
;
5529 global_entry_off() const
5531 return this->global_entry_align(this->end_branch_table_
);
5535 global_entry_address() const
5537 gold_assert(this->is_data_size_valid());
5538 return this->address() + this->global_entry_off();
5542 pltresolve_size() const
5546 + (this->targ_
->abiversion() < 2 ? 11 * 4
5547 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5552 // Write to a map file.
5554 do_print_to_mapfile(Mapfile
* mapfile
) const
5555 { mapfile
->print_output_data(this, _("** glink")); }
5559 set_final_data_size();
5563 do_write(Output_file
*);
5565 // Allows access to .got and .plt for do_write.
5566 Target_powerpc
<size
, big_endian
>* targ_
;
5568 // Map sym to stub offset.
5569 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5570 Global_entry_stub_entries global_entry_stubs_
;
5572 unsigned int end_branch_table_
, ge_size_
;
5575 template<int size
, bool big_endian
>
5577 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5579 if (!parameters
->options().ld_generated_unwind_info())
5584 if (this->targ_
->abiversion() < 2)
5585 layout
->add_eh_frame_for_plt(this,
5586 Eh_cie
<64>::eh_frame_cie
,
5587 sizeof (Eh_cie
<64>::eh_frame_cie
),
5588 glink_eh_frame_fde_64v1
,
5589 sizeof (glink_eh_frame_fde_64v1
));
5590 else if (this->targ_
->has_localentry0())
5591 layout
->add_eh_frame_for_plt(this,
5592 Eh_cie
<64>::eh_frame_cie
,
5593 sizeof (Eh_cie
<64>::eh_frame_cie
),
5594 glink_eh_frame_fde_64v2_localentry0
,
5595 sizeof (glink_eh_frame_fde_64v2
));
5597 layout
->add_eh_frame_for_plt(this,
5598 Eh_cie
<64>::eh_frame_cie
,
5599 sizeof (Eh_cie
<64>::eh_frame_cie
),
5600 glink_eh_frame_fde_64v2
,
5601 sizeof (glink_eh_frame_fde_64v2
));
5605 // 32-bit .glink can use the default since the CIE return
5606 // address reg, LR, is valid.
5607 layout
->add_eh_frame_for_plt(this,
5608 Eh_cie
<32>::eh_frame_cie
,
5609 sizeof (Eh_cie
<32>::eh_frame_cie
),
5611 sizeof (default_fde
));
5612 // Except where LR is used in a PIC __glink_PLTresolve.
5613 if (parameters
->options().output_is_position_independent())
5614 layout
->add_eh_frame_for_plt(this,
5615 Eh_cie
<32>::eh_frame_cie
,
5616 sizeof (Eh_cie
<32>::eh_frame_cie
),
5617 glink_eh_frame_fde_32
,
5618 sizeof (glink_eh_frame_fde_32
));
5622 template<int size
, bool big_endian
>
5624 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5626 unsigned int off
= this->global_entry_align(this->ge_size_
);
5627 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5628 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5630 this->ge_size_
= off
+ 16;
5633 template<int size
, bool big_endian
>
5634 typename Output_data_glink
<size
, big_endian
>::Address
5635 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5637 typename
Global_entry_stub_entries::const_iterator p
5638 = this->global_entry_stubs_
.find(gsym
);
5639 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5642 template<int size
, bool big_endian
>
5644 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5646 unsigned int count
= this->targ_
->plt_entry_count();
5647 section_size_type total
= 0;
5653 // space for branch table
5654 total
+= 4 * (count
- 1);
5656 total
+= -total
& 15;
5657 total
+= this->pltresolve_size();
5661 total
+= this->pltresolve_size();
5663 // space for branch table
5665 if (this->targ_
->abiversion() < 2)
5669 total
+= 4 * (count
- 0x8000);
5673 this->end_branch_table_
= total
;
5674 total
= this->global_entry_align(total
);
5675 total
+= this->ge_size_
;
5677 this->set_data_size(total
);
5680 // Define symbols on stubs, identifying the stub.
5682 template<int size
, bool big_endian
>
5684 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5686 if (!this->plt_call_stubs_
.empty())
5688 // The key for the plt call stub hash table includes addresses,
5689 // therefore traversal order depends on those addresses, which
5690 // can change between runs if gold is a PIE. Unfortunately the
5691 // output .symtab ordering depends on the order in which symbols
5692 // are added to the linker symtab. We want reproducible output
5693 // so must sort the call stub symbols.
5694 typedef typename
Plt_stub_entries::iterator plt_iter
;
5695 std::vector
<plt_iter
> sorted
;
5696 sorted
.resize(this->plt_call_stubs_
.size());
5698 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5699 cs
!= this->plt_call_stubs_
.end();
5701 sorted
[cs
->second
.indx_
] = cs
;
5703 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5705 plt_iter cs
= sorted
[i
];
5708 if (cs
->first
.addend_
!= 0)
5709 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5712 if (cs
->first
.object_
)
5714 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5715 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5716 sprintf(obj
, "%x:", ppcobj
->uniq());
5719 const char *symname
;
5720 if (cs
->first
.sym_
== NULL
)
5722 sprintf(localname
, "%x", cs
->first
.locsym_
);
5723 symname
= localname
;
5725 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5726 symname
= this->targ_
->tls_get_addr_opt()->name();
5728 symname
= cs
->first
.sym_
->name();
5729 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5730 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5732 = this->stub_address() - this->address() + cs
->second
.off_
;
5733 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5734 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5738 typedef typename
Branch_stub_entries::iterator branch_iter
;
5739 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5740 bs
!= this->long_branch_stubs_
.end();
5743 if (bs
->second
.save_res_
)
5746 char* name
= new char[8 + 13 + 16 + 1];
5747 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5748 static_cast<unsigned long long>(bs
->first
.dest_
));
5749 Address value
= (this->stub_address() - this->address()
5750 + this->plt_size_
+ bs
->second
.off_
);
5751 bool need_lt
= false;
5752 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5753 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5757 // Emit the start of a __tls_get_addr_opt plt call stub.
5759 template<int size
, bool big_endian
>
5761 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5764 unsigned char* p
= *pp
;
5767 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5769 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5771 write_insn
<big_endian
>(p
, mr_0_3
);
5773 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5775 write_insn
<big_endian
>(p
, add_3_12_13
);
5777 write_insn
<big_endian
>(p
, beqlr
);
5779 write_insn
<big_endian
>(p
, mr_3_0
);
5783 write_insn
<big_endian
>(p
, mflr_11
);
5785 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5791 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5793 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5795 write_insn
<big_endian
>(p
, mr_0_3
);
5797 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5799 write_insn
<big_endian
>(p
, add_3_12_2
);
5801 write_insn
<big_endian
>(p
, beqlr
);
5803 write_insn
<big_endian
>(p
, mr_3_0
);
5805 write_insn
<big_endian
>(p
, nop
);
5811 // Emit the tail of a __tls_get_addr_opt plt call stub.
5813 template<int size
, bool big_endian
>
5815 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5817 write_insn
<big_endian
>(p
, bctrl
);
5819 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5821 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5823 write_insn
<big_endian
>(p
, mtlr_11
);
5825 write_insn
<big_endian
>(p
, blr
);
5828 // Emit pc-relative plt call stub code.
5830 template<bool big_endian
>
5831 static unsigned char*
5832 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5835 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5840 write_insn
<big_endian
>(p
, nop
);
5848 write_insn
<big_endian
>(p
, insn
>> 32);
5850 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5852 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5855 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5859 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5862 insn
= paddi_12_pc
| d34(off
);
5863 write_insn
<big_endian
>(p
, insn
>> 32);
5865 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5869 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5873 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5875 write_insn
<big_endian
>(p
, add_12_11_12
);
5880 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5882 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5886 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5889 insn
= paddi_12_pc
| d34(off
);
5890 write_insn
<big_endian
>(p
, insn
>> 32);
5892 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5896 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5900 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5902 write_insn
<big_endian
>(p
, add_12_11_12
);
5908 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5909 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5914 // lis %r12,xxx-1b@highest
5915 // ori %r12,%r12,xxx-1b@higher
5916 // sldi %r12,%r12,32
5917 // oris %r12,%r12,xxx-1b@high
5918 // ori %r12,%r12,xxx-1b@l
5919 // add/ldx %r12,%r11,%r12
5921 template<bool big_endian
>
5922 static unsigned char*
5923 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5925 write_insn
<big_endian
>(p
, mflr_12
);
5927 write_insn
<big_endian
>(p
, bcl_20_31
);
5929 write_insn
<big_endian
>(p
, mflr_11
);
5931 write_insn
<big_endian
>(p
, mtlr_12
);
5933 if (off
+ 0x8000 < 0x10000)
5936 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5938 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5940 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5942 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5945 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5947 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5951 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5953 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5958 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5960 if (((off
>> 32) & 0xffff) != 0)
5962 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5966 if (((off
>> 32) & 0xffffffffULL
) != 0)
5968 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5973 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5978 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5982 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5984 write_insn
<big_endian
>(p
, add_12_11_12
);
5990 // Size of a given plt call stub.
5992 template<int size
, bool big_endian
>
5994 Stub_table
<size
, big_endian
>::plt_call_size(
5995 typename
Plt_stub_entries::iterator p
) const
5999 const Symbol
* gsym
= p
->first
.sym_
;
6001 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
6004 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6005 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6006 plt_addr
+= plt
->address();
6007 if (this->targ_
->power10_stubs()
6008 && this->targ_
->power10_stubs_auto())
6010 unsigned int bytes
= 0;
6011 if (p
->second
.notoc_
)
6013 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6015 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6016 uint64_t odd
= from
& 4;
6017 uint64_t off
= plt_addr
- from
;
6018 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6019 bytes
+= odd
+ 4 * 4;
6020 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6024 bytes
= this->plt_call_align(bytes
);
6026 unsigned int tail
= 0;
6029 p
->second
.tocoff_
= bytes
;
6030 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6033 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6039 if (p
->second
.r2save_
)
6042 = this->targ_
->got_section()->output_section()->address();
6043 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6044 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6045 got_addr
+= ppcobj
->toc_base_offset();
6046 uint64_t off
= plt_addr
- got_addr
;
6047 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6049 return bytes
+ tail
;
6053 unsigned int bytes
= 0;
6054 unsigned int tail
= 0;
6055 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6058 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6065 if (p
->second
.r2save_
)
6068 if (this->targ_
->power10_stubs())
6070 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6071 uint64_t odd
= from
& 4;
6072 uint64_t off
= plt_addr
- from
;
6073 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6074 bytes
+= odd
+ 4 * 4;
6075 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6079 return bytes
+ tail
;
6082 if (p
->second
.notoc_
)
6084 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6085 uint64_t off
= plt_addr
- from
;
6086 if (off
+ 0x8000 < 0x10000)
6088 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6093 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6094 && ((off
>> 32) & 0xffff) != 0)
6096 if (((off
>> 32) & 0xffffffffULL
) != 0)
6103 return bytes
+ tail
;
6106 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6107 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6108 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6109 got_addr
+= ppcobj
->toc_base_offset();
6110 uint64_t off
= plt_addr
- got_addr
;
6111 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6112 if (this->targ_
->abiversion() < 2)
6114 bool static_chain
= parameters
->options().plt_static_chain();
6115 bool thread_safe
= this->targ_
->plt_thread_safe();
6119 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6121 return bytes
+ tail
;
6125 // Return long branch stub size.
6127 template<int size
, bool big_endian
>
6129 Stub_table
<size
, big_endian
>::branch_stub_size(
6130 typename
Branch_stub_entries::iterator p
,
6133 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6136 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6138 if (parameters
->options().output_is_position_independent())
6143 uint64_t off
= p
->first
.dest_
- loc
;
6144 unsigned int bytes
= 0;
6145 if (p
->second
.notoc_
)
6147 if (this->targ_
->power10_stubs())
6149 Address odd
= loc
& 4;
6150 if (off
+ (1 << 25) < 2 << 25)
6152 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6154 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6158 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6160 p
->second
.tocoff_
= bytes
;
6165 if (off
+ 0x8000 < 0x10000)
6167 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6169 if (off
+ 24 + (1 << 25) < 2 << 25)
6175 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6176 && ((off
>> 32) & 0xffff) != 0)
6178 if (((off
>> 32) & 0xffffffffULL
) != 0)
6188 if (off
+ (1 << 25) < 2 << 25)
6190 if (!this->targ_
->power10_stubs()
6191 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6196 template<int size
, bool big_endian
>
6198 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6201 gold_error(_("linkage table error against `%s'"),
6202 p
.sym_
->demangled_name().c_str());
6204 gold_error(_("linkage table error against `%s:[local %u]'"),
6205 p
.object_
->name().c_str(),
6209 // Write out plt and long branch stub code.
6211 template<int size
, bool big_endian
>
6213 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6215 if (this->plt_call_stubs_
.empty()
6216 && this->long_branch_stubs_
.empty())
6219 const section_size_type start_off
= this->offset();
6220 const section_size_type off
= this->stub_offset();
6221 const section_size_type oview_size
=
6222 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6223 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6227 && this->targ_
->power10_stubs())
6229 const Output_data_got_powerpc
<size
, big_endian
>* got
6230 = this->targ_
->got_section();
6231 Address got_os_addr
= got
->output_section()->address();
6233 if (!this->plt_call_stubs_
.empty())
6235 // Write out plt call stubs.
6236 typename
Plt_stub_entries::const_iterator cs
;
6237 for (cs
= this->plt_call_stubs_
.begin();
6238 cs
!= this->plt_call_stubs_
.end();
6241 p
= oview
+ cs
->second
.off_
;
6242 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6243 Address pltoff
= this->plt_off(cs
, &plt
);
6244 Address plt_addr
= pltoff
+ plt
->address();
6245 if (this->targ_
->power10_stubs_auto())
6247 if (cs
->second
.notoc_
)
6249 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6250 this->build_tls_opt_head(&p
, false);
6251 Address from
= this->stub_address() + (p
- oview
);
6252 Address delta
= plt_addr
- from
;
6253 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6255 write_insn
<big_endian
>(p
, mtctr_12
);
6257 write_insn
<big_endian
>(p
, bctr
);
6259 p
= oview
+ this->plt_call_align(p
- oview
);
6261 if (cs
->second
.toc_
)
6263 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6266 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6267 this->build_tls_opt_head(&p
, save_lr
);
6269 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6270 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6272 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6273 Address off
= plt_addr
- got_addr
;
6275 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6276 this->plt_error(cs
->first
);
6278 if (cs
->second
.r2save_
)
6280 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6285 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6287 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6292 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6295 write_insn
<big_endian
>(p
, mtctr_12
);
6297 if (cs
->second
.r2save_
6298 && !cs
->second
.localentry0_
6299 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6300 this->build_tls_opt_tail(p
);
6302 write_insn
<big_endian
>(p
, bctr
);
6307 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6310 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6311 this->build_tls_opt_head(&p
, save_lr
);
6313 if (cs
->second
.r2save_
)
6315 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6318 Address from
= this->stub_address() + (p
- oview
);
6319 Address delta
= plt_addr
- from
;
6320 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6321 write_insn
<big_endian
>(p
, mtctr_12
);
6323 if (cs
->second
.r2save_
6324 && !cs
->second
.localentry0_
6325 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6326 this->build_tls_opt_tail(p
);
6328 write_insn
<big_endian
>(p
, bctr
);
6333 // Write out long branch stubs.
6334 typename
Branch_stub_entries::const_iterator bs
;
6335 for (bs
= this->long_branch_stubs_
.begin();
6336 bs
!= this->long_branch_stubs_
.end();
6339 if (bs
->second
.save_res_
)
6341 Address off
= this->plt_size_
+ bs
->second
.off_
;
6343 Address loc
= this->stub_address() + off
;
6344 Address delta
= bs
->first
.dest_
- loc
;
6345 if (this->targ_
->power10_stubs_auto())
6347 if (bs
->second
.notoc_
)
6349 unsigned char* startp
= p
;
6350 p
= build_power10_offset
<big_endian
>(p
, delta
,
6352 delta
-= p
- startp
;
6354 if (delta
+ (1 << 25) < 2 << 25)
6355 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6358 write_insn
<big_endian
>(p
, mtctr_12
);
6360 write_insn
<big_endian
>(p
, bctr
);
6363 delta
-= p
- startp
;
6365 if (bs
->second
.toc_
)
6367 if (delta
+ (1 << 25) >= 2 << 25)
6370 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6371 gold_assert(brlt_addr
!= invalid_address
);
6372 brlt_addr
+= this->targ_
->brlt_section()->address();
6373 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6374 Address brltoff
= brlt_addr
- got_addr
;
6375 if (ha(brltoff
) == 0)
6377 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6382 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6384 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6388 if (delta
+ (1 << 25) < 2 << 25)
6389 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6392 write_insn
<big_endian
>(p
, mtctr_12
);
6394 write_insn
<big_endian
>(p
, bctr
);
6400 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6402 unsigned char* startp
= p
;
6403 p
= build_power10_offset
<big_endian
>(p
, delta
,
6405 delta
-= p
- startp
;
6407 if (delta
+ (1 << 25) < 2 << 25)
6408 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6411 write_insn
<big_endian
>(p
, mtctr_12
);
6413 write_insn
<big_endian
>(p
, bctr
);
6418 else if (size
== 64)
6420 const Output_data_got_powerpc
<size
, big_endian
>* got
6421 = this->targ_
->got_section();
6422 Address got_os_addr
= got
->output_section()->address();
6424 if (!this->plt_call_stubs_
.empty()
6425 && this->targ_
->abiversion() >= 2)
6427 // Write out plt call stubs for ELFv2.
6428 typename
Plt_stub_entries::const_iterator cs
;
6429 for (cs
= this->plt_call_stubs_
.begin();
6430 cs
!= this->plt_call_stubs_
.end();
6433 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6434 Address pltoff
= this->plt_off(cs
, &plt
);
6435 Address plt_addr
= pltoff
+ plt
->address();
6437 p
= oview
+ cs
->second
.off_
;
6438 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6440 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6441 this->build_tls_opt_head(&p
, save_lr
);
6443 if (cs
->second
.r2save_
)
6445 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6448 if (cs
->second
.notoc_
)
6450 Address from
= this->stub_address() + (p
- oview
) + 8;
6451 Address off
= plt_addr
- from
;
6452 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6456 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6457 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6458 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6459 Address off
= plt_addr
- got_addr
;
6461 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6462 this->plt_error(cs
->first
);
6466 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6468 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6473 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6477 write_insn
<big_endian
>(p
, mtctr_12
);
6479 if (cs
->second
.r2save_
6480 && !cs
->second
.localentry0_
6481 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6482 this->build_tls_opt_tail(p
);
6484 write_insn
<big_endian
>(p
, bctr
);
6487 else if (!this->plt_call_stubs_
.empty())
6489 // Write out plt call stubs for ELFv1.
6490 typename
Plt_stub_entries::const_iterator cs
;
6491 for (cs
= this->plt_call_stubs_
.begin();
6492 cs
!= this->plt_call_stubs_
.end();
6495 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6496 Address pltoff
= this->plt_off(cs
, &plt
);
6497 Address plt_addr
= pltoff
+ plt
->address();
6498 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6499 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6500 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6501 Address off
= plt_addr
- got_addr
;
6503 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6504 || cs
->second
.notoc_
)
6505 this->plt_error(cs
->first
);
6507 bool static_chain
= parameters
->options().plt_static_chain();
6508 bool thread_safe
= this->targ_
->plt_thread_safe();
6509 bool use_fake_dep
= false;
6510 Address cmp_branch_off
= 0;
6513 unsigned int pltindex
6514 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6515 / this->targ_
->plt_entry_size());
6517 = (this->targ_
->glink_section()->pltresolve_size()
6519 if (pltindex
> 32768)
6520 glinkoff
+= (pltindex
- 32768) * 4;
6522 = this->targ_
->glink_section()->address() + glinkoff
;
6524 = (this->stub_address() + cs
->second
.off_
+ 20
6525 + 4 * cs
->second
.r2save_
6526 + 4 * (ha(off
) != 0)
6527 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6528 + 4 * static_chain
);
6529 cmp_branch_off
= to
- from
;
6530 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6533 p
= oview
+ cs
->second
.off_
;
6534 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6536 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6537 this->build_tls_opt_head(&p
, save_lr
);
6538 use_fake_dep
= thread_safe
;
6540 if (cs
->second
.r2save_
)
6542 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6547 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6549 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6551 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6553 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6557 write_insn
<big_endian
>(p
, mtctr_12
);
6561 write_insn
<big_endian
>(p
, xor_2_12_12
);
6563 write_insn
<big_endian
>(p
, add_11_11_2
);
6566 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6570 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6576 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6578 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6580 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6584 write_insn
<big_endian
>(p
, mtctr_12
);
6588 write_insn
<big_endian
>(p
, xor_11_12_12
);
6590 write_insn
<big_endian
>(p
, add_2_2_11
);
6595 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6598 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6601 if (cs
->second
.r2save_
6602 && !cs
->second
.localentry0_
6603 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6604 this->build_tls_opt_tail(p
);
6605 else if (thread_safe
&& !use_fake_dep
)
6607 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6609 write_insn
<big_endian
>(p
, bnectr_p4
);
6611 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6614 write_insn
<big_endian
>(p
, bctr
);
6618 // Write out long branch stubs.
6619 typename
Branch_stub_entries::const_iterator bs
;
6620 for (bs
= this->long_branch_stubs_
.begin();
6621 bs
!= this->long_branch_stubs_
.end();
6624 if (bs
->second
.save_res_
)
6626 Address off
= this->plt_size_
+ bs
->second
.off_
;
6628 Address loc
= this->stub_address() + off
;
6629 Address delta
= bs
->first
.dest_
- loc
;
6630 if (bs
->second
.notoc_
)
6632 unsigned char* startp
= p
;
6633 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6634 delta
-= p
- startp
;
6636 else if (delta
+ (1 << 25) >= 2 << 25)
6639 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6640 gold_assert(brlt_addr
!= invalid_address
);
6641 brlt_addr
+= this->targ_
->brlt_section()->address();
6642 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6643 Address brltoff
= brlt_addr
- got_addr
;
6644 if (ha(brltoff
) == 0)
6646 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6651 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6653 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6657 if (delta
+ (1 << 25) < 2 << 25)
6658 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6661 write_insn
<big_endian
>(p
, mtctr_12
);
6663 write_insn
<big_endian
>(p
, bctr
);
6669 if (!this->plt_call_stubs_
.empty())
6671 // The address of _GLOBAL_OFFSET_TABLE_.
6672 Address g_o_t
= invalid_address
;
6674 // Write out plt call stubs.
6675 typename
Plt_stub_entries::const_iterator cs
;
6676 for (cs
= this->plt_call_stubs_
.begin();
6677 cs
!= this->plt_call_stubs_
.end();
6680 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6681 Address plt_addr
= this->plt_off(cs
, &plt
);
6682 plt_addr
+= plt
->address();
6684 p
= oview
+ cs
->second
.off_
;
6685 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6686 this->build_tls_opt_head(&p
, false);
6687 if (parameters
->options().output_is_position_independent())
6690 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6691 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6692 (cs
->first
.object_
));
6693 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6695 unsigned int got2
= ppcobj
->got2_shndx();
6696 got_addr
= ppcobj
->get_output_section_offset(got2
);
6697 gold_assert(got_addr
!= invalid_address
);
6698 got_addr
+= (ppcobj
->output_section(got2
)->address()
6699 + cs
->first
.addend_
);
6703 if (g_o_t
== invalid_address
)
6705 const Output_data_got_powerpc
<size
, big_endian
>* got
6706 = this->targ_
->got_section();
6707 g_o_t
= got
->address() + got
->g_o_t();
6712 Address off
= plt_addr
- got_addr
;
6714 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6717 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6719 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6724 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6726 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6729 write_insn
<big_endian
>(p
, mtctr_11
);
6731 write_insn
<big_endian
>(p
, bctr
);
6735 // Write out long branch stubs.
6736 typename
Branch_stub_entries::const_iterator bs
;
6737 for (bs
= this->long_branch_stubs_
.begin();
6738 bs
!= this->long_branch_stubs_
.end();
6741 if (bs
->second
.save_res_
)
6743 Address off
= this->plt_size_
+ bs
->second
.off_
;
6745 Address loc
= this->stub_address() + off
;
6746 Address delta
= bs
->first
.dest_
- loc
;
6747 if (delta
+ (1 << 25) < 2 << 25)
6748 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6749 else if (!parameters
->options().output_is_position_independent())
6751 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6753 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6758 write_insn
<big_endian
>(p
, mflr_0
);
6760 write_insn
<big_endian
>(p
, bcl_20_31
);
6762 write_insn
<big_endian
>(p
, mflr_12
);
6764 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6766 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6768 write_insn
<big_endian
>(p
, mtlr_0
);
6771 write_insn
<big_endian
>(p
, mtctr_12
);
6773 write_insn
<big_endian
>(p
, bctr
);
6776 if (this->need_save_res_
)
6778 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6779 memcpy (p
, this->targ_
->savres_section()->contents(),
6780 this->targ_
->savres_section()->data_size());
6784 // Write out .glink.
6786 template<int size
, bool big_endian
>
6788 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6790 const section_size_type off
= this->offset();
6791 const section_size_type oview_size
=
6792 convert_to_section_size_type(this->data_size());
6793 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6796 // The base address of the .plt section.
6797 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6798 Address plt_base
= this->targ_
->plt_section()->address();
6802 if (this->end_branch_table_
!= 0)
6804 // Write pltresolve stub.
6806 Address after_bcl
= this->address() + 16;
6807 Address pltoff
= plt_base
- after_bcl
;
6809 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6811 if (this->targ_
->abiversion() < 2)
6813 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6814 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6815 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6816 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6817 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6818 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6819 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6820 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6821 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6822 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6826 if (this->targ_
->has_localentry0())
6828 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6830 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6831 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6832 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6833 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6834 if (this->targ_
->has_localentry0())
6836 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
6840 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
6842 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6843 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
6844 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
6845 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6846 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6847 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6848 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6850 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6851 gold_assert(p
== oview
+ this->pltresolve_size());
6853 // Write lazy link call stubs.
6855 while (p
< oview
+ this->end_branch_table_
)
6857 if (this->targ_
->abiversion() < 2)
6861 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6865 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6866 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6869 uint32_t branch_off
= 8 - (p
- oview
);
6870 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6875 Address plt_base
= this->targ_
->plt_section()->address();
6876 Address iplt_base
= invalid_address
;
6877 unsigned int global_entry_off
= this->global_entry_off();
6878 Address global_entry_base
= this->address() + global_entry_off
;
6879 typename
Global_entry_stub_entries::const_iterator ge
;
6880 for (ge
= this->global_entry_stubs_
.begin();
6881 ge
!= this->global_entry_stubs_
.end();
6884 p
= oview
+ global_entry_off
+ ge
->second
;
6885 Address plt_addr
= ge
->first
->plt_offset();
6886 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6887 && ge
->first
->can_use_relative_reloc(false))
6889 if (iplt_base
== invalid_address
)
6890 iplt_base
= this->targ_
->iplt_section()->address();
6891 plt_addr
+= iplt_base
;
6894 plt_addr
+= plt_base
;
6895 Address my_addr
= global_entry_base
+ ge
->second
;
6896 Address off
= plt_addr
- my_addr
;
6898 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6899 gold_error(_("linkage table error against `%s'"),
6900 ge
->first
->demangled_name().c_str());
6902 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6903 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6904 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6905 write_insn
<big_endian
>(p
, bctr
);
6910 const Output_data_got_powerpc
<size
, big_endian
>* got
6911 = this->targ_
->got_section();
6912 // The address of _GLOBAL_OFFSET_TABLE_.
6913 Address g_o_t
= got
->address() + got
->g_o_t();
6915 // Write out pltresolve branch table.
6917 unsigned int the_end
= oview_size
- this->pltresolve_size();
6918 unsigned char* end_p
= oview
+ the_end
;
6919 while (p
< end_p
- 8 * 4)
6920 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6922 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6924 // Write out pltresolve call stub.
6925 end_p
= oview
+ oview_size
;
6926 if (parameters
->options().output_is_position_independent())
6928 Address res0_off
= 0;
6929 Address after_bcl_off
= the_end
+ 12;
6930 Address bcl_res0
= after_bcl_off
- res0_off
;
6932 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6934 write_insn
<big_endian
>(p
, mflr_0
);
6936 write_insn
<big_endian
>(p
, bcl_20_31
);
6938 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6940 write_insn
<big_endian
>(p
, mflr_12
);
6942 write_insn
<big_endian
>(p
, mtlr_0
);
6944 write_insn
<big_endian
>(p
, sub_11_11_12
);
6947 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6949 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6951 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6953 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6955 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6959 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6961 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6964 write_insn
<big_endian
>(p
, mtctr_0
);
6966 write_insn
<big_endian
>(p
, add_0_11_11
);
6968 write_insn
<big_endian
>(p
, add_11_0_11
);
6972 Address res0
= this->address();
6974 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6976 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6978 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6979 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6981 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6983 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6985 write_insn
<big_endian
>(p
, mtctr_0
);
6987 write_insn
<big_endian
>(p
, add_0_11_11
);
6989 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6990 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6992 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6994 write_insn
<big_endian
>(p
, add_11_0_11
);
6997 write_insn
<big_endian
>(p
, bctr
);
7001 write_insn
<big_endian
>(p
, nop
);
7006 of
->write_output_view(off
, oview_size
, oview
);
7010 // A class to handle linker generated save/restore functions.
7012 template<int size
, bool big_endian
>
7013 class Output_data_save_res
: public Output_section_data_build
7016 Output_data_save_res(Symbol_table
* symtab
);
7018 const unsigned char*
7025 // Write to a map file.
7027 do_print_to_mapfile(Mapfile
* mapfile
) const
7028 { mapfile
->print_output_data(this, _("** save/restore")); }
7031 do_write(Output_file
*);
7034 // The maximum size of save/restore contents.
7035 static const unsigned int savres_max
= 218*4;
7038 savres_define(Symbol_table
* symtab
,
7040 unsigned int lo
, unsigned int hi
,
7041 unsigned char* write_ent(unsigned char*, int),
7042 unsigned char* write_tail(unsigned char*, int));
7044 unsigned char *contents_
;
7047 template<bool big_endian
>
7048 static unsigned char*
7049 savegpr0(unsigned char* p
, int r
)
7051 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7052 write_insn
<big_endian
>(p
, insn
);
7056 template<bool big_endian
>
7057 static unsigned char*
7058 savegpr0_tail(unsigned char* p
, int r
)
7060 p
= savegpr0
<big_endian
>(p
, r
);
7061 uint32_t insn
= std_0_1
+ 16;
7062 write_insn
<big_endian
>(p
, insn
);
7064 write_insn
<big_endian
>(p
, blr
);
7068 template<bool big_endian
>
7069 static unsigned char*
7070 restgpr0(unsigned char* p
, int r
)
7072 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7073 write_insn
<big_endian
>(p
, insn
);
7077 template<bool big_endian
>
7078 static unsigned char*
7079 restgpr0_tail(unsigned char* p
, int r
)
7081 uint32_t insn
= ld_0_1
+ 16;
7082 write_insn
<big_endian
>(p
, insn
);
7084 p
= restgpr0
<big_endian
>(p
, r
);
7085 write_insn
<big_endian
>(p
, mtlr_0
);
7089 p
= restgpr0
<big_endian
>(p
, 30);
7090 p
= restgpr0
<big_endian
>(p
, 31);
7092 write_insn
<big_endian
>(p
, blr
);
7096 template<bool big_endian
>
7097 static unsigned char*
7098 savegpr1(unsigned char* p
, int r
)
7100 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7101 write_insn
<big_endian
>(p
, insn
);
7105 template<bool big_endian
>
7106 static unsigned char*
7107 savegpr1_tail(unsigned char* p
, int r
)
7109 p
= savegpr1
<big_endian
>(p
, r
);
7110 write_insn
<big_endian
>(p
, blr
);
7114 template<bool big_endian
>
7115 static unsigned char*
7116 restgpr1(unsigned char* p
, int r
)
7118 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7119 write_insn
<big_endian
>(p
, insn
);
7123 template<bool big_endian
>
7124 static unsigned char*
7125 restgpr1_tail(unsigned char* p
, int r
)
7127 p
= restgpr1
<big_endian
>(p
, r
);
7128 write_insn
<big_endian
>(p
, blr
);
7132 template<bool big_endian
>
7133 static unsigned char*
7134 savefpr(unsigned char* p
, int r
)
7136 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7137 write_insn
<big_endian
>(p
, insn
);
7141 template<bool big_endian
>
7142 static unsigned char*
7143 savefpr0_tail(unsigned char* p
, int r
)
7145 p
= savefpr
<big_endian
>(p
, r
);
7146 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7148 write_insn
<big_endian
>(p
, blr
);
7152 template<bool big_endian
>
7153 static unsigned char*
7154 restfpr(unsigned char* p
, int r
)
7156 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7157 write_insn
<big_endian
>(p
, insn
);
7161 template<bool big_endian
>
7162 static unsigned char*
7163 restfpr0_tail(unsigned char* p
, int r
)
7165 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7167 p
= restfpr
<big_endian
>(p
, r
);
7168 write_insn
<big_endian
>(p
, mtlr_0
);
7172 p
= restfpr
<big_endian
>(p
, 30);
7173 p
= restfpr
<big_endian
>(p
, 31);
7175 write_insn
<big_endian
>(p
, blr
);
7179 template<bool big_endian
>
7180 static unsigned char*
7181 savefpr1_tail(unsigned char* p
, int r
)
7183 p
= savefpr
<big_endian
>(p
, r
);
7184 write_insn
<big_endian
>(p
, blr
);
7188 template<bool big_endian
>
7189 static unsigned char*
7190 restfpr1_tail(unsigned char* p
, int r
)
7192 p
= restfpr
<big_endian
>(p
, r
);
7193 write_insn
<big_endian
>(p
, blr
);
7197 template<bool big_endian
>
7198 static unsigned char*
7199 savevr(unsigned char* p
, int r
)
7201 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7202 write_insn
<big_endian
>(p
, insn
);
7204 insn
= stvx_0_12_0
+ (r
<< 21);
7205 write_insn
<big_endian
>(p
, insn
);
7209 template<bool big_endian
>
7210 static unsigned char*
7211 savevr_tail(unsigned char* p
, int r
)
7213 p
= savevr
<big_endian
>(p
, r
);
7214 write_insn
<big_endian
>(p
, blr
);
7218 template<bool big_endian
>
7219 static unsigned char*
7220 restvr(unsigned char* p
, int r
)
7222 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7223 write_insn
<big_endian
>(p
, insn
);
7225 insn
= lvx_0_12_0
+ (r
<< 21);
7226 write_insn
<big_endian
>(p
, insn
);
7230 template<bool big_endian
>
7231 static unsigned char*
7232 restvr_tail(unsigned char* p
, int r
)
7234 p
= restvr
<big_endian
>(p
, r
);
7235 write_insn
<big_endian
>(p
, blr
);
7240 template<int size
, bool big_endian
>
7241 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7242 Symbol_table
* symtab
)
7243 : Output_section_data_build(4),
7246 this->savres_define(symtab
,
7247 "_savegpr0_", 14, 31,
7248 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7249 this->savres_define(symtab
,
7250 "_restgpr0_", 14, 29,
7251 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7252 this->savres_define(symtab
,
7253 "_restgpr0_", 30, 31,
7254 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7255 this->savres_define(symtab
,
7256 "_savegpr1_", 14, 31,
7257 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7258 this->savres_define(symtab
,
7259 "_restgpr1_", 14, 31,
7260 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7261 this->savres_define(symtab
,
7262 "_savefpr_", 14, 31,
7263 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7264 this->savres_define(symtab
,
7265 "_restfpr_", 14, 29,
7266 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7267 this->savres_define(symtab
,
7268 "_restfpr_", 30, 31,
7269 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7270 this->savres_define(symtab
,
7272 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7273 this->savres_define(symtab
,
7275 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7276 this->savres_define(symtab
,
7278 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7279 this->savres_define(symtab
,
7281 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7284 template<int size
, bool big_endian
>
7286 Output_data_save_res
<size
, big_endian
>::savres_define(
7287 Symbol_table
* symtab
,
7289 unsigned int lo
, unsigned int hi
,
7290 unsigned char* write_ent(unsigned char*, int),
7291 unsigned char* write_tail(unsigned char*, int))
7293 size_t len
= strlen(name
);
7294 bool writing
= false;
7297 memcpy(sym
, name
, len
);
7300 for (unsigned int i
= lo
; i
<= hi
; i
++)
7302 sym
[len
+ 0] = i
/ 10 + '0';
7303 sym
[len
+ 1] = i
% 10 + '0';
7304 Symbol
* gsym
= symtab
->lookup(sym
);
7305 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7306 writing
= writing
|| refd
;
7309 if (this->contents_
== NULL
)
7310 this->contents_
= new unsigned char[this->savres_max
];
7312 section_size_type value
= this->current_data_size();
7313 unsigned char* p
= this->contents_
+ value
;
7315 p
= write_ent(p
, i
);
7317 p
= write_tail(p
, i
);
7318 section_size_type cur_size
= p
- this->contents_
;
7319 this->set_current_data_size(cur_size
);
7321 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7322 this, value
, cur_size
- value
,
7323 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7324 elfcpp::STV_HIDDEN
, 0, false, false);
7329 // Write out save/restore.
7331 template<int size
, bool big_endian
>
7333 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7335 const section_size_type off
= this->offset();
7336 const section_size_type oview_size
=
7337 convert_to_section_size_type(this->data_size());
7338 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7339 memcpy(oview
, this->contents_
, oview_size
);
7340 of
->write_output_view(off
, oview_size
, oview
);
7344 // Create the glink section.
7346 template<int size
, bool big_endian
>
7348 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7350 if (this->glink_
== NULL
)
7352 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7353 this->glink_
->add_eh_frame(layout
);
7354 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7355 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7356 this->glink_
, ORDER_TEXT
, false);
7360 // Create a PLT entry for a global symbol.
7362 template<int size
, bool big_endian
>
7364 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7368 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7369 && gsym
->can_use_relative_reloc(false))
7371 if (this->iplt_
== NULL
)
7372 this->make_iplt_section(symtab
, layout
);
7373 this->iplt_
->add_ifunc_entry(gsym
);
7377 if (this->plt_
== NULL
)
7378 this->make_plt_section(symtab
, layout
);
7379 this->plt_
->add_entry(gsym
);
7383 // Make a PLT entry for a local symbol.
7385 template<int size
, bool big_endian
>
7387 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7389 Sized_relobj_file
<size
, big_endian
>* relobj
,
7392 if (this->lplt_
== NULL
)
7393 this->make_lplt_section(layout
);
7394 this->lplt_
->add_local_entry(relobj
, r_sym
);
7397 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7399 template<int size
, bool big_endian
>
7401 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7402 Symbol_table
* symtab
,
7404 Sized_relobj_file
<size
, big_endian
>* relobj
,
7407 if (this->iplt_
== NULL
)
7408 this->make_iplt_section(symtab
, layout
);
7409 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7412 // Return the number of entries in the PLT.
7414 template<int size
, bool big_endian
>
7416 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7418 if (this->plt_
== NULL
)
7420 return this->plt_
->entry_count();
7423 // Create a GOT entry for local dynamic __tls_get_addr calls.
7425 template<int size
, bool big_endian
>
7427 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7428 Symbol_table
* symtab
,
7430 Sized_relobj_file
<size
, big_endian
>* object
)
7432 if (this->tlsld_got_offset_
== -1U)
7434 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7435 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7436 Output_data_got_powerpc
<size
, big_endian
>* got
7437 = this->got_section(symtab
, layout
);
7438 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7439 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7441 this->tlsld_got_offset_
= got_offset
;
7443 return this->tlsld_got_offset_
;
7446 // Get the Reference_flags for a particular relocation.
7448 template<int size
, bool big_endian
>
7450 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7451 unsigned int r_type
,
7452 const Target_powerpc
* target
)
7458 case elfcpp::R_POWERPC_NONE
:
7459 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7460 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7461 case elfcpp::R_PPC64_TOC
:
7462 // No symbol reference.
7465 case elfcpp::R_PPC64_ADDR64
:
7466 case elfcpp::R_PPC64_UADDR64
:
7467 case elfcpp::R_POWERPC_ADDR32
:
7468 case elfcpp::R_POWERPC_UADDR32
:
7469 case elfcpp::R_POWERPC_ADDR16
:
7470 case elfcpp::R_POWERPC_UADDR16
:
7471 case elfcpp::R_POWERPC_ADDR16_LO
:
7472 case elfcpp::R_POWERPC_ADDR16_HI
:
7473 case elfcpp::R_POWERPC_ADDR16_HA
:
7474 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7475 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7476 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7477 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7478 case elfcpp::R_PPC64_D34
:
7479 case elfcpp::R_PPC64_D34_LO
:
7480 case elfcpp::R_PPC64_D34_HI30
:
7481 case elfcpp::R_PPC64_D34_HA30
:
7482 case elfcpp::R_PPC64_D28
:
7483 ref
= Symbol::ABSOLUTE_REF
;
7486 case elfcpp::R_POWERPC_ADDR24
:
7487 case elfcpp::R_POWERPC_ADDR14
:
7488 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7489 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7490 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7493 case elfcpp::R_PPC64_REL64
:
7494 case elfcpp::R_POWERPC_REL32
:
7495 case elfcpp::R_PPC_LOCAL24PC
:
7496 case elfcpp::R_POWERPC_REL16
:
7497 case elfcpp::R_POWERPC_REL16_LO
:
7498 case elfcpp::R_POWERPC_REL16_HI
:
7499 case elfcpp::R_POWERPC_REL16_HA
:
7500 case elfcpp::R_PPC64_REL16_HIGH
:
7501 case elfcpp::R_PPC64_REL16_HIGHA
:
7502 case elfcpp::R_PPC64_REL16_HIGHER
:
7503 case elfcpp::R_PPC64_REL16_HIGHERA
:
7504 case elfcpp::R_PPC64_REL16_HIGHEST
:
7505 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7506 case elfcpp::R_PPC64_PCREL34
:
7507 case elfcpp::R_PPC64_REL16_HIGHER34
:
7508 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7509 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7510 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7511 case elfcpp::R_PPC64_PCREL28
:
7512 ref
= Symbol::RELATIVE_REF
;
7515 case elfcpp::R_PPC64_REL24_NOTOC
:
7519 case elfcpp::R_POWERPC_REL24
:
7520 case elfcpp::R_PPC_PLTREL24
:
7521 case elfcpp::R_POWERPC_REL14
:
7522 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7523 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7524 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7527 case elfcpp::R_POWERPC_GOT16
:
7528 case elfcpp::R_POWERPC_GOT16_LO
:
7529 case elfcpp::R_POWERPC_GOT16_HI
:
7530 case elfcpp::R_POWERPC_GOT16_HA
:
7531 case elfcpp::R_PPC64_GOT16_DS
:
7532 case elfcpp::R_PPC64_GOT16_LO_DS
:
7533 case elfcpp::R_PPC64_GOT_PCREL34
:
7534 case elfcpp::R_PPC64_TOC16
:
7535 case elfcpp::R_PPC64_TOC16_LO
:
7536 case elfcpp::R_PPC64_TOC16_HI
:
7537 case elfcpp::R_PPC64_TOC16_HA
:
7538 case elfcpp::R_PPC64_TOC16_DS
:
7539 case elfcpp::R_PPC64_TOC16_LO_DS
:
7540 case elfcpp::R_POWERPC_PLT16_LO
:
7541 case elfcpp::R_POWERPC_PLT16_HI
:
7542 case elfcpp::R_POWERPC_PLT16_HA
:
7543 case elfcpp::R_PPC64_PLT16_LO_DS
:
7544 case elfcpp::R_PPC64_PLT_PCREL34
:
7545 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7546 ref
= Symbol::RELATIVE_REF
;
7549 case elfcpp::R_POWERPC_GOT_TPREL16
:
7550 case elfcpp::R_POWERPC_TLS
:
7551 case elfcpp::R_PPC64_TLSGD
:
7552 case elfcpp::R_PPC64_TLSLD
:
7553 case elfcpp::R_PPC64_TPREL34
:
7554 case elfcpp::R_PPC64_DTPREL34
:
7555 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7556 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7557 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7558 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7559 ref
= Symbol::TLS_REF
;
7562 case elfcpp::R_POWERPC_COPY
:
7563 case elfcpp::R_POWERPC_GLOB_DAT
:
7564 case elfcpp::R_POWERPC_JMP_SLOT
:
7565 case elfcpp::R_POWERPC_RELATIVE
:
7566 case elfcpp::R_POWERPC_DTPMOD
:
7568 // Not expected. We will give an error later.
7572 if (size
== 64 && target
->abiversion() < 2)
7573 ref
|= Symbol::FUNC_DESC_ABI
;
7577 // Report an unsupported relocation against a local symbol.
7579 template<int size
, bool big_endian
>
7581 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7582 Sized_relobj_file
<size
, big_endian
>* object
,
7583 unsigned int r_type
)
7585 gold_error(_("%s: unsupported reloc %u against local symbol"),
7586 object
->name().c_str(), r_type
);
7589 // We are about to emit a dynamic relocation of type R_TYPE. If the
7590 // dynamic linker does not support it, issue an error.
7592 template<int size
, bool big_endian
>
7594 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7595 unsigned int r_type
)
7597 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7599 // These are the relocation types supported by glibc for both 32-bit
7600 // and 64-bit powerpc.
7603 case elfcpp::R_POWERPC_NONE
:
7604 case elfcpp::R_POWERPC_RELATIVE
:
7605 case elfcpp::R_POWERPC_GLOB_DAT
:
7606 case elfcpp::R_POWERPC_DTPMOD
:
7607 case elfcpp::R_POWERPC_DTPREL
:
7608 case elfcpp::R_POWERPC_TPREL
:
7609 case elfcpp::R_POWERPC_JMP_SLOT
:
7610 case elfcpp::R_POWERPC_COPY
:
7611 case elfcpp::R_POWERPC_IRELATIVE
:
7612 case elfcpp::R_POWERPC_ADDR32
:
7613 case elfcpp::R_POWERPC_UADDR32
:
7614 case elfcpp::R_POWERPC_ADDR24
:
7615 case elfcpp::R_POWERPC_ADDR16
:
7616 case elfcpp::R_POWERPC_UADDR16
:
7617 case elfcpp::R_POWERPC_ADDR16_LO
:
7618 case elfcpp::R_POWERPC_ADDR16_HI
:
7619 case elfcpp::R_POWERPC_ADDR16_HA
:
7620 case elfcpp::R_POWERPC_ADDR14
:
7621 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7622 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7623 case elfcpp::R_POWERPC_REL32
:
7624 case elfcpp::R_POWERPC_TPREL16
:
7625 case elfcpp::R_POWERPC_TPREL16_LO
:
7626 case elfcpp::R_POWERPC_TPREL16_HI
:
7627 case elfcpp::R_POWERPC_TPREL16_HA
:
7638 // These are the relocation types supported only on 64-bit.
7639 case elfcpp::R_PPC64_ADDR64
:
7640 case elfcpp::R_PPC64_UADDR64
:
7641 case elfcpp::R_PPC64_JMP_IREL
:
7642 case elfcpp::R_PPC64_ADDR16_DS
:
7643 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7644 case elfcpp::R_PPC64_ADDR16_HIGH
:
7645 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7646 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7647 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7648 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7649 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7650 case elfcpp::R_PPC64_REL64
:
7651 case elfcpp::R_POWERPC_ADDR30
:
7652 case elfcpp::R_PPC64_TPREL16_DS
:
7653 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7654 case elfcpp::R_PPC64_TPREL16_HIGH
:
7655 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7656 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7657 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7658 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7659 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7670 // These are the relocation types supported only on 32-bit.
7671 // ??? glibc ld.so doesn't need to support these.
7672 case elfcpp::R_POWERPC_REL24
:
7673 case elfcpp::R_POWERPC_DTPREL16
:
7674 case elfcpp::R_POWERPC_DTPREL16_LO
:
7675 case elfcpp::R_POWERPC_DTPREL16_HI
:
7676 case elfcpp::R_POWERPC_DTPREL16_HA
:
7684 // This prevents us from issuing more than one error per reloc
7685 // section. But we can still wind up issuing more than one
7686 // error per object file.
7687 if (this->issued_non_pic_error_
)
7689 gold_assert(parameters
->options().output_is_position_independent());
7690 object
->error(_("requires unsupported dynamic reloc; "
7691 "recompile with -fPIC"));
7692 this->issued_non_pic_error_
= true;
7696 // Return whether we need to make a PLT entry for a relocation of the
7697 // given type against a STT_GNU_IFUNC symbol.
7699 template<int size
, bool big_endian
>
7701 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7702 Target_powerpc
<size
, big_endian
>* target
,
7703 Sized_relobj_file
<size
, big_endian
>* object
,
7704 unsigned int r_type
,
7707 // In non-pic code any reference will resolve to the plt call stub
7708 // for the ifunc symbol.
7709 if ((size
== 32 || target
->abiversion() >= 2)
7710 && !parameters
->options().output_is_position_independent())
7715 // Word size refs from data sections are OK, but don't need a PLT entry.
7716 case elfcpp::R_POWERPC_ADDR32
:
7717 case elfcpp::R_POWERPC_UADDR32
:
7722 case elfcpp::R_PPC64_ADDR64
:
7723 case elfcpp::R_PPC64_UADDR64
:
7728 // GOT refs are good, but also don't need a PLT entry.
7729 case elfcpp::R_POWERPC_GOT16
:
7730 case elfcpp::R_POWERPC_GOT16_LO
:
7731 case elfcpp::R_POWERPC_GOT16_HI
:
7732 case elfcpp::R_POWERPC_GOT16_HA
:
7733 case elfcpp::R_PPC64_GOT16_DS
:
7734 case elfcpp::R_PPC64_GOT16_LO_DS
:
7735 case elfcpp::R_PPC64_GOT_PCREL34
:
7738 // PLT relocs are OK and need a PLT entry.
7739 case elfcpp::R_POWERPC_PLT16_LO
:
7740 case elfcpp::R_POWERPC_PLT16_HI
:
7741 case elfcpp::R_POWERPC_PLT16_HA
:
7742 case elfcpp::R_PPC64_PLT16_LO_DS
:
7743 case elfcpp::R_POWERPC_PLTSEQ
:
7744 case elfcpp::R_POWERPC_PLTCALL
:
7745 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7746 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7747 case elfcpp::R_PPC64_PLT_PCREL34
:
7748 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7752 // Function calls are good, and these do need a PLT entry.
7753 case elfcpp::R_PPC64_REL24_NOTOC
:
7757 case elfcpp::R_POWERPC_ADDR24
:
7758 case elfcpp::R_POWERPC_ADDR14
:
7759 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7760 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7761 case elfcpp::R_POWERPC_REL24
:
7762 case elfcpp::R_PPC_PLTREL24
:
7763 case elfcpp::R_POWERPC_REL14
:
7764 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7765 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7772 // Anything else is a problem.
7773 // If we are building a static executable, the libc startup function
7774 // responsible for applying indirect function relocations is going
7775 // to complain about the reloc type.
7776 // If we are building a dynamic executable, we will have a text
7777 // relocation. The dynamic loader will set the text segment
7778 // writable and non-executable to apply text relocations. So we'll
7779 // segfault when trying to run the indirection function to resolve
7782 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7783 object
->name().c_str(), r_type
);
7787 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7791 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7793 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7794 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7795 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7796 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7797 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7798 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7799 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7800 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7801 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7802 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7803 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7804 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7805 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7806 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7807 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7808 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7809 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7810 /* Exclude lfqu by testing reloc. If relocs are ever
7811 defined for the reduced D field in psq_lu then those
7812 will need testing too. */
7813 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7814 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7815 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7817 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7818 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7819 /* Exclude stfqu. psq_stu as above for psq_lu. */
7820 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7821 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7822 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7823 && (insn
& 1) == 0));
7826 // Scan a relocation for a local symbol.
7828 template<int size
, bool big_endian
>
7830 Target_powerpc
<size
, big_endian
>::Scan::local(
7831 Symbol_table
* symtab
,
7833 Target_powerpc
<size
, big_endian
>* target
,
7834 Sized_relobj_file
<size
, big_endian
>* object
,
7835 unsigned int data_shndx
,
7836 Output_section
* output_section
,
7837 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7838 unsigned int r_type
,
7839 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7842 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7844 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7845 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7847 this->expect_tls_get_addr_call();
7848 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7849 if (tls_type
!= tls::TLSOPT_NONE
)
7850 this->skip_next_tls_get_addr_call();
7852 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7853 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7855 this->expect_tls_get_addr_call();
7856 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7857 if (tls_type
!= tls::TLSOPT_NONE
)
7858 this->skip_next_tls_get_addr_call();
7861 Powerpc_relobj
<size
, big_endian
>* ppc_object
7862 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7867 && data_shndx
== ppc_object
->opd_shndx()
7868 && r_type
== elfcpp::R_PPC64_ADDR64
)
7869 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7873 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7874 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7875 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7877 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7878 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7879 r_type
, r_sym
, reloc
.get_r_addend());
7880 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7885 case elfcpp::R_POWERPC_NONE
:
7886 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7887 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7888 case elfcpp::R_POWERPC_TLS
:
7889 case elfcpp::R_PPC64_ENTRY
:
7890 case elfcpp::R_POWERPC_PLTSEQ
:
7891 case elfcpp::R_POWERPC_PLTCALL
:
7892 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7893 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7894 case elfcpp::R_PPC64_PCREL_OPT
:
7895 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7896 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7897 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7898 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7899 case elfcpp::R_PPC64_REL16_HIGHER34
:
7900 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7901 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7902 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7903 case elfcpp::R_PPC64_D34
:
7904 case elfcpp::R_PPC64_D34_LO
:
7905 case elfcpp::R_PPC64_D34_HI30
:
7906 case elfcpp::R_PPC64_D34_HA30
:
7907 case elfcpp::R_PPC64_D28
:
7908 case elfcpp::R_PPC64_PCREL34
:
7909 case elfcpp::R_PPC64_PCREL28
:
7910 case elfcpp::R_PPC64_TPREL34
:
7911 case elfcpp::R_PPC64_DTPREL34
:
7914 case elfcpp::R_PPC64_TOC
:
7916 Output_data_got_powerpc
<size
, big_endian
>* got
7917 = target
->got_section(symtab
, layout
);
7918 if (parameters
->options().output_is_position_independent())
7920 Address off
= reloc
.get_r_offset();
7922 && target
->abiversion() < 2
7923 && data_shndx
== ppc_object
->opd_shndx()
7924 && ppc_object
->get_opd_discard(off
- 8))
7927 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7928 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7929 rela_dyn
->add_output_section_relative(got
->output_section(),
7930 elfcpp::R_POWERPC_RELATIVE
,
7932 object
, data_shndx
, off
,
7933 symobj
->toc_base_offset());
7938 case elfcpp::R_PPC64_ADDR64
:
7939 case elfcpp::R_PPC64_UADDR64
:
7940 case elfcpp::R_POWERPC_ADDR32
:
7941 case elfcpp::R_POWERPC_UADDR32
:
7942 case elfcpp::R_POWERPC_ADDR24
:
7943 case elfcpp::R_POWERPC_ADDR16
:
7944 case elfcpp::R_POWERPC_ADDR16_LO
:
7945 case elfcpp::R_POWERPC_ADDR16_HI
:
7946 case elfcpp::R_POWERPC_ADDR16_HA
:
7947 case elfcpp::R_POWERPC_UADDR16
:
7948 case elfcpp::R_PPC64_ADDR16_HIGH
:
7949 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7950 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7951 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7952 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7953 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7954 case elfcpp::R_PPC64_ADDR16_DS
:
7955 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7956 case elfcpp::R_POWERPC_ADDR14
:
7957 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7958 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7959 // If building a shared library (or a position-independent
7960 // executable), we need to create a dynamic relocation for
7962 if (parameters
->options().output_is_position_independent()
7963 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7965 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7967 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7968 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7969 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7971 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7972 : elfcpp::R_POWERPC_RELATIVE
);
7973 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7974 output_section
, data_shndx
,
7975 reloc
.get_r_offset(),
7976 reloc
.get_r_addend(), false);
7978 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7980 check_non_pic(object
, r_type
);
7981 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7982 data_shndx
, reloc
.get_r_offset(),
7983 reloc
.get_r_addend());
7987 gold_assert(lsym
.get_st_value() == 0);
7988 unsigned int shndx
= lsym
.get_st_shndx();
7990 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7993 object
->error(_("section symbol %u has bad shndx %u"),
7996 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7997 output_section
, data_shndx
,
7998 reloc
.get_r_offset());
8003 case elfcpp::R_PPC64_PLT_PCREL34
:
8004 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8005 case elfcpp::R_POWERPC_PLT16_LO
:
8006 case elfcpp::R_POWERPC_PLT16_HI
:
8007 case elfcpp::R_POWERPC_PLT16_HA
:
8008 case elfcpp::R_PPC64_PLT16_LO_DS
:
8011 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8012 target
->make_local_plt_entry(layout
, object
, r_sym
);
8016 case elfcpp::R_PPC64_REL24_NOTOC
:
8020 case elfcpp::R_POWERPC_REL24
:
8021 case elfcpp::R_PPC_PLTREL24
:
8022 case elfcpp::R_PPC_LOCAL24PC
:
8023 case elfcpp::R_POWERPC_REL14
:
8024 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8025 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8028 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8029 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8030 r_type
, r_sym
, reloc
.get_r_addend());
8034 case elfcpp::R_PPC64_TOCSAVE
:
8035 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8036 // caller has already saved r2 and thus a plt call stub need not
8039 && target
->mark_pltcall(ppc_object
, data_shndx
,
8040 reloc
.get_r_offset() - 4, symtab
))
8042 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8043 unsigned int shndx
= lsym
.get_st_shndx();
8045 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8047 object
->error(_("tocsave symbol %u has bad shndx %u"),
8050 target
->add_tocsave(ppc_object
, shndx
,
8051 lsym
.get_st_value() + reloc
.get_r_addend());
8055 case elfcpp::R_PPC64_REL64
:
8056 case elfcpp::R_POWERPC_REL32
:
8057 case elfcpp::R_POWERPC_REL16
:
8058 case elfcpp::R_POWERPC_REL16_LO
:
8059 case elfcpp::R_POWERPC_REL16_HI
:
8060 case elfcpp::R_POWERPC_REL16_HA
:
8061 case elfcpp::R_POWERPC_REL16DX_HA
:
8062 case elfcpp::R_PPC64_REL16_HIGH
:
8063 case elfcpp::R_PPC64_REL16_HIGHA
:
8064 case elfcpp::R_PPC64_REL16_HIGHER
:
8065 case elfcpp::R_PPC64_REL16_HIGHERA
:
8066 case elfcpp::R_PPC64_REL16_HIGHEST
:
8067 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8068 case elfcpp::R_POWERPC_SECTOFF
:
8069 case elfcpp::R_POWERPC_SECTOFF_LO
:
8070 case elfcpp::R_POWERPC_SECTOFF_HI
:
8071 case elfcpp::R_POWERPC_SECTOFF_HA
:
8072 case elfcpp::R_PPC64_SECTOFF_DS
:
8073 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8074 case elfcpp::R_POWERPC_TPREL16
:
8075 case elfcpp::R_POWERPC_TPREL16_LO
:
8076 case elfcpp::R_POWERPC_TPREL16_HI
:
8077 case elfcpp::R_POWERPC_TPREL16_HA
:
8078 case elfcpp::R_PPC64_TPREL16_DS
:
8079 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8080 case elfcpp::R_PPC64_TPREL16_HIGH
:
8081 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8082 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8083 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8084 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8085 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8086 case elfcpp::R_POWERPC_DTPREL16
:
8087 case elfcpp::R_POWERPC_DTPREL16_LO
:
8088 case elfcpp::R_POWERPC_DTPREL16_HI
:
8089 case elfcpp::R_POWERPC_DTPREL16_HA
:
8090 case elfcpp::R_PPC64_DTPREL16_DS
:
8091 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8092 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8093 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8094 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8095 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8096 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8097 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8098 case elfcpp::R_PPC64_TLSGD
:
8099 case elfcpp::R_PPC64_TLSLD
:
8100 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8103 case elfcpp::R_PPC64_GOT_PCREL34
:
8104 case elfcpp::R_POWERPC_GOT16
:
8105 case elfcpp::R_POWERPC_GOT16_LO
:
8106 case elfcpp::R_POWERPC_GOT16_HI
:
8107 case elfcpp::R_POWERPC_GOT16_HA
:
8108 case elfcpp::R_PPC64_GOT16_DS
:
8109 case elfcpp::R_PPC64_GOT16_LO_DS
:
8111 // The symbol requires a GOT entry.
8112 Output_data_got_powerpc
<size
, big_endian
>* got
8113 = target
->got_section(symtab
, layout
);
8114 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8116 if (!parameters
->options().output_is_position_independent())
8119 && (size
== 32 || target
->abiversion() >= 2))
8120 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8122 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8124 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8126 // If we are generating a shared object or a pie, this
8127 // symbol's GOT entry will be set by a dynamic relocation.
8129 off
= got
->add_constant(0);
8130 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8132 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8134 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8135 : elfcpp::R_POWERPC_RELATIVE
);
8136 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8137 got
, off
, 0, false);
8142 case elfcpp::R_PPC64_TOC16
:
8143 case elfcpp::R_PPC64_TOC16_LO
:
8144 case elfcpp::R_PPC64_TOC16_HI
:
8145 case elfcpp::R_PPC64_TOC16_HA
:
8146 case elfcpp::R_PPC64_TOC16_DS
:
8147 case elfcpp::R_PPC64_TOC16_LO_DS
:
8148 // We need a GOT section.
8149 target
->got_section(symtab
, layout
);
8152 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8153 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8154 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8155 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8156 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8158 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8159 if (tls_type
== tls::TLSOPT_NONE
)
8161 Output_data_got_powerpc
<size
, big_endian
>* got
8162 = target
->got_section(symtab
, layout
);
8163 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8164 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8165 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8166 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8168 else if (tls_type
== tls::TLSOPT_TO_LE
)
8170 // no GOT relocs needed for Local Exec.
8177 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8178 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8179 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8180 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8181 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8183 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8184 if (tls_type
== tls::TLSOPT_NONE
)
8185 target
->tlsld_got_offset(symtab
, layout
, object
);
8186 else if (tls_type
== tls::TLSOPT_TO_LE
)
8188 // no GOT relocs needed for Local Exec.
8189 if (parameters
->options().emit_relocs())
8191 Output_section
* os
= layout
->tls_segment()->first_section();
8192 gold_assert(os
!= NULL
);
8193 os
->set_needs_symtab_index();
8201 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8202 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8203 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8204 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8205 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8207 Output_data_got_powerpc
<size
, big_endian
>* got
8208 = target
->got_section(symtab
, layout
);
8209 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8210 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8214 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8215 case elfcpp::R_POWERPC_GOT_TPREL16
:
8216 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8217 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8218 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8220 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8221 if (tls_type
== tls::TLSOPT_NONE
)
8223 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8224 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8226 Output_data_got_powerpc
<size
, big_endian
>* got
8227 = target
->got_section(symtab
, layout
);
8228 unsigned int off
= got
->add_constant(0);
8229 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8231 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8232 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8233 elfcpp::R_POWERPC_TPREL
,
8237 else if (tls_type
== tls::TLSOPT_TO_LE
)
8239 // no GOT relocs needed for Local Exec.
8247 unsupported_reloc_local(object
, r_type
);
8252 && parameters
->options().toc_optimize())
8254 if (data_shndx
== ppc_object
->toc_shndx())
8257 if (r_type
!= elfcpp::R_PPC64_ADDR64
8258 || (is_ifunc
&& target
->abiversion() < 2))
8260 else if (parameters
->options().output_is_position_independent())
8266 unsigned int shndx
= lsym
.get_st_shndx();
8267 if (shndx
>= elfcpp::SHN_LORESERVE
8268 && shndx
!= elfcpp::SHN_XINDEX
)
8273 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8276 enum {no_check
, check_lo
, check_ha
} insn_check
;
8280 insn_check
= no_check
;
8283 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8284 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8285 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8286 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8287 case elfcpp::R_POWERPC_GOT16_HA
:
8288 case elfcpp::R_PPC64_TOC16_HA
:
8289 insn_check
= check_ha
;
8292 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8293 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8294 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8295 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8296 case elfcpp::R_POWERPC_GOT16_LO
:
8297 case elfcpp::R_PPC64_GOT16_LO_DS
:
8298 case elfcpp::R_PPC64_TOC16_LO
:
8299 case elfcpp::R_PPC64_TOC16_LO_DS
:
8300 insn_check
= check_lo
;
8304 section_size_type slen
;
8305 const unsigned char* view
= NULL
;
8306 if (insn_check
!= no_check
)
8308 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8309 section_size_type off
=
8310 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8313 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8314 if (insn_check
== check_lo
8315 ? !ok_lo_toc_insn(insn
, r_type
)
8316 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8317 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8319 ppc_object
->set_no_toc_opt();
8320 gold_warning(_("%s: toc optimization is not supported "
8321 "for %#08x instruction"),
8322 ppc_object
->name().c_str(), insn
);
8331 case elfcpp::R_PPC64_TOC16
:
8332 case elfcpp::R_PPC64_TOC16_LO
:
8333 case elfcpp::R_PPC64_TOC16_HI
:
8334 case elfcpp::R_PPC64_TOC16_HA
:
8335 case elfcpp::R_PPC64_TOC16_DS
:
8336 case elfcpp::R_PPC64_TOC16_LO_DS
:
8337 unsigned int shndx
= lsym
.get_st_shndx();
8338 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8340 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8341 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8343 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8344 if (dst_off
< ppc_object
->section_size(shndx
))
8347 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8349 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8351 // Need to check that the insn is a ld
8353 view
= ppc_object
->section_contents(data_shndx
,
8356 section_size_type off
=
8357 (convert_to_section_size_type(reloc
.get_r_offset())
8358 + (big_endian
? -2 : 3));
8360 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8364 ppc_object
->set_no_toc_opt(dst_off
);
8375 case elfcpp::R_POWERPC_REL32
:
8376 if (ppc_object
->got2_shndx() != 0
8377 && parameters
->options().output_is_position_independent())
8379 unsigned int shndx
= lsym
.get_st_shndx();
8380 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8382 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8383 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8384 && (ppc_object
->section_flags(data_shndx
)
8385 & elfcpp::SHF_EXECINSTR
) != 0)
8386 gold_error(_("%s: unsupported -mbss-plt code"),
8387 ppc_object
->name().c_str());
8397 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8398 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8399 case elfcpp::R_POWERPC_GOT_TPREL16
:
8400 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8401 case elfcpp::R_POWERPC_GOT16
:
8402 case elfcpp::R_PPC64_GOT16_DS
:
8403 case elfcpp::R_PPC64_TOC16
:
8404 case elfcpp::R_PPC64_TOC16_DS
:
8405 ppc_object
->set_has_small_toc_reloc();
8413 case elfcpp::R_PPC64_TPREL16_DS
:
8414 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8415 case elfcpp::R_PPC64_TPREL16_HIGH
:
8416 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8417 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8418 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8419 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8420 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8421 case elfcpp::R_PPC64_TPREL34
:
8425 case elfcpp::R_POWERPC_TPREL16
:
8426 case elfcpp::R_POWERPC_TPREL16_LO
:
8427 case elfcpp::R_POWERPC_TPREL16_HI
:
8428 case elfcpp::R_POWERPC_TPREL16_HA
:
8429 layout
->set_has_static_tls();
8437 case elfcpp::R_POWERPC_TPREL16_HA
:
8438 if (target
->tprel_opt())
8440 section_size_type slen
;
8441 const unsigned char* view
= NULL
;
8442 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8443 section_size_type off
8444 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8447 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8448 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8449 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8450 target
->set_tprel_opt(false);
8455 case elfcpp::R_PPC64_TPREL16_HIGH
:
8456 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8457 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8458 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8459 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8460 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8464 case elfcpp::R_POWERPC_TPREL16_HI
:
8465 target
->set_tprel_opt(false);
8473 case elfcpp::R_PPC64_D34
:
8474 case elfcpp::R_PPC64_D34_LO
:
8475 case elfcpp::R_PPC64_D34_HI30
:
8476 case elfcpp::R_PPC64_D34_HA30
:
8477 case elfcpp::R_PPC64_D28
:
8478 case elfcpp::R_PPC64_PCREL34
:
8479 case elfcpp::R_PPC64_PCREL28
:
8480 case elfcpp::R_PPC64_TPREL34
:
8481 case elfcpp::R_PPC64_DTPREL34
:
8482 case elfcpp::R_PPC64_PLT_PCREL34
:
8483 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8484 case elfcpp::R_PPC64_GOT_PCREL34
:
8485 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8486 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8487 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8488 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8489 target
->set_power10_relocs();
8496 // Report an unsupported relocation against a global symbol.
8498 template<int size
, bool big_endian
>
8500 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8501 Sized_relobj_file
<size
, big_endian
>* object
,
8502 unsigned int r_type
,
8505 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8506 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8509 // Scan a relocation for a global symbol.
8511 template<int size
, bool big_endian
>
8513 Target_powerpc
<size
, big_endian
>::Scan::global(
8514 Symbol_table
* symtab
,
8516 Target_powerpc
<size
, big_endian
>* target
,
8517 Sized_relobj_file
<size
, big_endian
>* object
,
8518 unsigned int data_shndx
,
8519 Output_section
* output_section
,
8520 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8521 unsigned int r_type
,
8524 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8528 if (target
->replace_tls_get_addr(gsym
))
8529 // Change a __tls_get_addr reference to __tls_get_addr_opt
8530 // so dynamic relocs are emitted against the latter symbol.
8531 gsym
= target
->tls_get_addr_opt();
8533 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8534 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8536 this->expect_tls_get_addr_call();
8537 const bool final
= gsym
->final_value_is_known();
8538 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8539 if (tls_type
!= tls::TLSOPT_NONE
)
8540 this->skip_next_tls_get_addr_call();
8542 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8543 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8545 this->expect_tls_get_addr_call();
8546 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8547 if (tls_type
!= tls::TLSOPT_NONE
)
8548 this->skip_next_tls_get_addr_call();
8551 Powerpc_relobj
<size
, big_endian
>* ppc_object
8552 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8554 // A STT_GNU_IFUNC symbol may require a PLT entry.
8555 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8556 bool pushed_ifunc
= false;
8557 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8559 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8560 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8561 r_type
, r_sym
, reloc
.get_r_addend());
8562 target
->make_plt_entry(symtab
, layout
, gsym
);
8563 pushed_ifunc
= true;
8568 case elfcpp::R_POWERPC_NONE
:
8569 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8570 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8571 case elfcpp::R_PPC_LOCAL24PC
:
8572 case elfcpp::R_POWERPC_TLS
:
8573 case elfcpp::R_PPC64_ENTRY
:
8574 case elfcpp::R_POWERPC_PLTSEQ
:
8575 case elfcpp::R_POWERPC_PLTCALL
:
8576 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8577 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8578 case elfcpp::R_PPC64_PCREL_OPT
:
8579 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8580 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8581 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8582 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8583 case elfcpp::R_PPC64_REL16_HIGHER34
:
8584 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8585 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8586 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8587 case elfcpp::R_PPC64_D34
:
8588 case elfcpp::R_PPC64_D34_LO
:
8589 case elfcpp::R_PPC64_D34_HI30
:
8590 case elfcpp::R_PPC64_D34_HA30
:
8591 case elfcpp::R_PPC64_D28
:
8592 case elfcpp::R_PPC64_PCREL34
:
8593 case elfcpp::R_PPC64_PCREL28
:
8594 case elfcpp::R_PPC64_TPREL34
:
8595 case elfcpp::R_PPC64_DTPREL34
:
8598 case elfcpp::R_PPC64_TOC
:
8600 Output_data_got_powerpc
<size
, big_endian
>* got
8601 = target
->got_section(symtab
, layout
);
8602 if (parameters
->options().output_is_position_independent())
8604 Address off
= reloc
.get_r_offset();
8606 && data_shndx
== ppc_object
->opd_shndx()
8607 && ppc_object
->get_opd_discard(off
- 8))
8610 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8611 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8612 if (data_shndx
!= ppc_object
->opd_shndx())
8613 symobj
= static_cast
8614 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8615 rela_dyn
->add_output_section_relative(got
->output_section(),
8616 elfcpp::R_POWERPC_RELATIVE
,
8618 object
, data_shndx
, off
,
8619 symobj
->toc_base_offset());
8624 case elfcpp::R_PPC64_ADDR64
:
8626 && target
->abiversion() < 2
8627 && data_shndx
== ppc_object
->opd_shndx()
8628 && (gsym
->is_defined_in_discarded_section()
8629 || gsym
->object() != object
))
8631 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8635 case elfcpp::R_PPC64_UADDR64
:
8636 case elfcpp::R_POWERPC_ADDR32
:
8637 case elfcpp::R_POWERPC_UADDR32
:
8638 case elfcpp::R_POWERPC_ADDR24
:
8639 case elfcpp::R_POWERPC_ADDR16
:
8640 case elfcpp::R_POWERPC_ADDR16_LO
:
8641 case elfcpp::R_POWERPC_ADDR16_HI
:
8642 case elfcpp::R_POWERPC_ADDR16_HA
:
8643 case elfcpp::R_POWERPC_UADDR16
:
8644 case elfcpp::R_PPC64_ADDR16_HIGH
:
8645 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8646 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8647 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8648 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8649 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8650 case elfcpp::R_PPC64_ADDR16_DS
:
8651 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8652 case elfcpp::R_POWERPC_ADDR14
:
8653 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8654 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8656 // Make a PLT entry if necessary.
8657 if (gsym
->needs_plt_entry())
8659 // Since this is not a PC-relative relocation, we may be
8660 // taking the address of a function. In that case we need to
8661 // set the entry in the dynamic symbol table to the address of
8662 // the PLT call stub.
8663 bool need_ifunc_plt
= false;
8664 if ((size
== 32 || target
->abiversion() >= 2)
8665 && gsym
->is_from_dynobj()
8666 && !parameters
->options().output_is_position_independent())
8668 gsym
->set_needs_dynsym_value();
8669 need_ifunc_plt
= true;
8671 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8673 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8674 target
->push_branch(ppc_object
, data_shndx
,
8675 reloc
.get_r_offset(), r_type
, r_sym
,
8676 reloc
.get_r_addend());
8677 target
->make_plt_entry(symtab
, layout
, gsym
);
8680 // Make a dynamic relocation if necessary.
8681 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8682 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8684 if (!parameters
->options().output_is_position_independent()
8685 && gsym
->may_need_copy_reloc())
8687 target
->copy_reloc(symtab
, layout
, object
,
8688 data_shndx
, output_section
, gsym
, reloc
);
8690 else if ((((size
== 32
8691 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8693 && r_type
== elfcpp::R_PPC64_ADDR64
8694 && target
->abiversion() >= 2))
8695 && gsym
->can_use_relative_reloc(false)
8696 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8697 && parameters
->options().shared()))
8699 && r_type
== elfcpp::R_PPC64_ADDR64
8700 && target
->abiversion() < 2
8701 && (gsym
->can_use_relative_reloc(false)
8702 || data_shndx
== ppc_object
->opd_shndx())))
8704 Reloc_section
* rela_dyn
8705 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8706 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8707 : elfcpp::R_POWERPC_RELATIVE
);
8708 rela_dyn
->add_symbolless_global_addend(
8709 gsym
, dynrel
, output_section
, object
, data_shndx
,
8710 reloc
.get_r_offset(), reloc
.get_r_addend());
8714 Reloc_section
* rela_dyn
8715 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8716 check_non_pic(object
, r_type
);
8717 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8719 reloc
.get_r_offset(),
8720 reloc
.get_r_addend());
8723 && parameters
->options().toc_optimize()
8724 && data_shndx
== ppc_object
->toc_shndx())
8725 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8731 case elfcpp::R_PPC64_PLT_PCREL34
:
8732 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8733 case elfcpp::R_POWERPC_PLT16_LO
:
8734 case elfcpp::R_POWERPC_PLT16_HI
:
8735 case elfcpp::R_POWERPC_PLT16_HA
:
8736 case elfcpp::R_PPC64_PLT16_LO_DS
:
8738 target
->make_plt_entry(symtab
, layout
, gsym
);
8741 case elfcpp::R_PPC64_REL24_NOTOC
:
8745 case elfcpp::R_PPC_PLTREL24
:
8746 case elfcpp::R_POWERPC_REL24
:
8749 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8750 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8751 r_type
, r_sym
, reloc
.get_r_addend());
8752 if (gsym
->needs_plt_entry()
8753 || (!gsym
->final_value_is_known()
8754 && (gsym
->is_undefined()
8755 || gsym
->is_from_dynobj()
8756 || gsym
->is_preemptible())))
8757 target
->make_plt_entry(symtab
, layout
, gsym
);
8761 case elfcpp::R_PPC64_REL64
:
8762 case elfcpp::R_POWERPC_REL32
:
8763 // Make a dynamic relocation if necessary.
8764 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8766 if (!parameters
->options().output_is_position_independent()
8767 && gsym
->may_need_copy_reloc())
8769 target
->copy_reloc(symtab
, layout
, object
,
8770 data_shndx
, output_section
, gsym
,
8775 Reloc_section
* rela_dyn
8776 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8777 check_non_pic(object
, r_type
);
8778 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8779 data_shndx
, reloc
.get_r_offset(),
8780 reloc
.get_r_addend());
8785 case elfcpp::R_POWERPC_REL14
:
8786 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8787 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8790 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8791 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8792 r_type
, r_sym
, reloc
.get_r_addend());
8796 case elfcpp::R_PPC64_TOCSAVE
:
8797 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8798 // caller has already saved r2 and thus a plt call stub need not
8801 && target
->mark_pltcall(ppc_object
, data_shndx
,
8802 reloc
.get_r_offset() - 4, symtab
))
8804 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8806 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8808 object
->error(_("tocsave symbol %u has bad shndx %u"),
8812 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8813 target
->add_tocsave(ppc_object
, shndx
,
8814 sym
->value() + reloc
.get_r_addend());
8819 case elfcpp::R_POWERPC_REL16
:
8820 case elfcpp::R_POWERPC_REL16_LO
:
8821 case elfcpp::R_POWERPC_REL16_HI
:
8822 case elfcpp::R_POWERPC_REL16_HA
:
8823 case elfcpp::R_POWERPC_REL16DX_HA
:
8824 case elfcpp::R_PPC64_REL16_HIGH
:
8825 case elfcpp::R_PPC64_REL16_HIGHA
:
8826 case elfcpp::R_PPC64_REL16_HIGHER
:
8827 case elfcpp::R_PPC64_REL16_HIGHERA
:
8828 case elfcpp::R_PPC64_REL16_HIGHEST
:
8829 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8830 case elfcpp::R_POWERPC_SECTOFF
:
8831 case elfcpp::R_POWERPC_SECTOFF_LO
:
8832 case elfcpp::R_POWERPC_SECTOFF_HI
:
8833 case elfcpp::R_POWERPC_SECTOFF_HA
:
8834 case elfcpp::R_PPC64_SECTOFF_DS
:
8835 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8836 case elfcpp::R_POWERPC_TPREL16
:
8837 case elfcpp::R_POWERPC_TPREL16_LO
:
8838 case elfcpp::R_POWERPC_TPREL16_HI
:
8839 case elfcpp::R_POWERPC_TPREL16_HA
:
8840 case elfcpp::R_PPC64_TPREL16_DS
:
8841 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8842 case elfcpp::R_PPC64_TPREL16_HIGH
:
8843 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8844 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8845 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8846 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8847 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8848 case elfcpp::R_POWERPC_DTPREL16
:
8849 case elfcpp::R_POWERPC_DTPREL16_LO
:
8850 case elfcpp::R_POWERPC_DTPREL16_HI
:
8851 case elfcpp::R_POWERPC_DTPREL16_HA
:
8852 case elfcpp::R_PPC64_DTPREL16_DS
:
8853 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8854 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8855 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8856 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8857 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8858 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8859 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8860 case elfcpp::R_PPC64_TLSGD
:
8861 case elfcpp::R_PPC64_TLSLD
:
8862 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8865 case elfcpp::R_PPC64_GOT_PCREL34
:
8866 case elfcpp::R_POWERPC_GOT16
:
8867 case elfcpp::R_POWERPC_GOT16_LO
:
8868 case elfcpp::R_POWERPC_GOT16_HI
:
8869 case elfcpp::R_POWERPC_GOT16_HA
:
8870 case elfcpp::R_PPC64_GOT16_DS
:
8871 case elfcpp::R_PPC64_GOT16_LO_DS
:
8873 // The symbol requires a GOT entry.
8874 Output_data_got_powerpc
<size
, big_endian
>* got
;
8876 got
= target
->got_section(symtab
, layout
);
8877 if (gsym
->final_value_is_known())
8880 && (size
== 32 || target
->abiversion() >= 2))
8881 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8883 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8885 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8887 // If we are generating a shared object or a pie, this
8888 // symbol's GOT entry will be set by a dynamic relocation.
8889 unsigned int off
= got
->add_constant(0);
8890 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8892 Reloc_section
* rela_dyn
8893 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8895 if (gsym
->can_use_relative_reloc(false)
8897 || target
->abiversion() >= 2)
8898 && gsym
->visibility() == elfcpp::STV_PROTECTED
8899 && parameters
->options().shared()))
8901 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8902 : elfcpp::R_POWERPC_RELATIVE
);
8903 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8907 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8908 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8914 case elfcpp::R_PPC64_TOC16
:
8915 case elfcpp::R_PPC64_TOC16_LO
:
8916 case elfcpp::R_PPC64_TOC16_HI
:
8917 case elfcpp::R_PPC64_TOC16_HA
:
8918 case elfcpp::R_PPC64_TOC16_DS
:
8919 case elfcpp::R_PPC64_TOC16_LO_DS
:
8920 // We need a GOT section.
8921 target
->got_section(symtab
, layout
);
8924 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8925 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8926 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8927 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8928 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8930 const bool final
= gsym
->final_value_is_known();
8931 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8932 if (tls_type
== tls::TLSOPT_NONE
)
8934 Output_data_got_powerpc
<size
, big_endian
>* got
8935 = target
->got_section(symtab
, layout
);
8936 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8937 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8938 elfcpp::R_POWERPC_DTPMOD
,
8939 elfcpp::R_POWERPC_DTPREL
);
8941 else if (tls_type
== tls::TLSOPT_TO_IE
)
8943 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8945 Output_data_got_powerpc
<size
, big_endian
>* got
8946 = target
->got_section(symtab
, layout
);
8947 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8948 if (gsym
->is_undefined()
8949 || gsym
->is_from_dynobj())
8951 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8952 elfcpp::R_POWERPC_TPREL
);
8956 unsigned int off
= got
->add_constant(0);
8957 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8958 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8959 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8964 else if (tls_type
== tls::TLSOPT_TO_LE
)
8966 // no GOT relocs needed for Local Exec.
8973 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8974 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8975 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8976 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8977 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8979 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8980 if (tls_type
== tls::TLSOPT_NONE
)
8981 target
->tlsld_got_offset(symtab
, layout
, object
);
8982 else if (tls_type
== tls::TLSOPT_TO_LE
)
8984 // no GOT relocs needed for Local Exec.
8985 if (parameters
->options().emit_relocs())
8987 Output_section
* os
= layout
->tls_segment()->first_section();
8988 gold_assert(os
!= NULL
);
8989 os
->set_needs_symtab_index();
8997 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8998 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8999 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9000 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9001 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9003 Output_data_got_powerpc
<size
, big_endian
>* got
9004 = target
->got_section(symtab
, layout
);
9005 if (!gsym
->final_value_is_known()
9006 && (gsym
->is_from_dynobj()
9007 || gsym
->is_undefined()
9008 || gsym
->is_preemptible()))
9009 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
9010 target
->rela_dyn_section(layout
),
9011 elfcpp::R_POWERPC_DTPREL
);
9013 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
9017 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9018 case elfcpp::R_POWERPC_GOT_TPREL16
:
9019 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9020 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9021 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9023 const bool final
= gsym
->final_value_is_known();
9024 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9025 if (tls_type
== tls::TLSOPT_NONE
)
9027 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
9029 Output_data_got_powerpc
<size
, big_endian
>* got
9030 = target
->got_section(symtab
, layout
);
9031 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9032 if (gsym
->is_undefined()
9033 || gsym
->is_from_dynobj())
9035 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9036 elfcpp::R_POWERPC_TPREL
);
9040 unsigned int off
= got
->add_constant(0);
9041 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9042 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9043 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9048 else if (tls_type
== tls::TLSOPT_TO_LE
)
9050 // no GOT relocs needed for Local Exec.
9058 unsupported_reloc_global(object
, r_type
, gsym
);
9063 && parameters
->options().toc_optimize())
9065 if (data_shndx
== ppc_object
->toc_shndx())
9068 if (r_type
!= elfcpp::R_PPC64_ADDR64
9069 || (is_ifunc
&& target
->abiversion() < 2))
9071 else if (parameters
->options().output_is_position_independent()
9072 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9075 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9078 enum {no_check
, check_lo
, check_ha
} insn_check
;
9082 insn_check
= no_check
;
9085 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9086 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9087 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9088 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9089 case elfcpp::R_POWERPC_GOT16_HA
:
9090 case elfcpp::R_PPC64_TOC16_HA
:
9091 insn_check
= check_ha
;
9094 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9095 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9096 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9097 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9098 case elfcpp::R_POWERPC_GOT16_LO
:
9099 case elfcpp::R_PPC64_GOT16_LO_DS
:
9100 case elfcpp::R_PPC64_TOC16_LO
:
9101 case elfcpp::R_PPC64_TOC16_LO_DS
:
9102 insn_check
= check_lo
;
9106 section_size_type slen
;
9107 const unsigned char* view
= NULL
;
9108 if (insn_check
!= no_check
)
9110 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9111 section_size_type off
=
9112 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9115 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9116 if (insn_check
== check_lo
9117 ? !ok_lo_toc_insn(insn
, r_type
)
9118 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9119 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9121 ppc_object
->set_no_toc_opt();
9122 gold_warning(_("%s: toc optimization is not supported "
9123 "for %#08x instruction"),
9124 ppc_object
->name().c_str(), insn
);
9133 case elfcpp::R_PPC64_TOC16
:
9134 case elfcpp::R_PPC64_TOC16_LO
:
9135 case elfcpp::R_PPC64_TOC16_HI
:
9136 case elfcpp::R_PPC64_TOC16_HA
:
9137 case elfcpp::R_PPC64_TOC16_DS
:
9138 case elfcpp::R_PPC64_TOC16_LO_DS
:
9139 if (gsym
->source() == Symbol::FROM_OBJECT
9140 && !gsym
->object()->is_dynamic())
9142 Powerpc_relobj
<size
, big_endian
>* sym_object
9143 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9145 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9146 if (shndx
== sym_object
->toc_shndx())
9148 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9149 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9150 if (dst_off
< sym_object
->section_size(shndx
))
9153 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9155 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9157 // Need to check that the insn is a ld
9159 view
= ppc_object
->section_contents(data_shndx
,
9162 section_size_type off
=
9163 (convert_to_section_size_type(reloc
.get_r_offset())
9164 + (big_endian
? -2 : 3));
9166 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9170 sym_object
->set_no_toc_opt(dst_off
);
9182 case elfcpp::R_PPC_LOCAL24PC
:
9183 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9184 gold_error(_("%s: unsupported -mbss-plt code"),
9185 ppc_object
->name().c_str());
9194 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9195 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9196 case elfcpp::R_POWERPC_GOT_TPREL16
:
9197 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9198 case elfcpp::R_POWERPC_GOT16
:
9199 case elfcpp::R_PPC64_GOT16_DS
:
9200 case elfcpp::R_PPC64_TOC16
:
9201 case elfcpp::R_PPC64_TOC16_DS
:
9202 ppc_object
->set_has_small_toc_reloc();
9210 case elfcpp::R_PPC64_TPREL16_DS
:
9211 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9212 case elfcpp::R_PPC64_TPREL16_HIGH
:
9213 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9214 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9215 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9216 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9217 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9218 case elfcpp::R_PPC64_TPREL34
:
9222 case elfcpp::R_POWERPC_TPREL16
:
9223 case elfcpp::R_POWERPC_TPREL16_LO
:
9224 case elfcpp::R_POWERPC_TPREL16_HI
:
9225 case elfcpp::R_POWERPC_TPREL16_HA
:
9226 layout
->set_has_static_tls();
9234 case elfcpp::R_POWERPC_TPREL16_HA
:
9235 if (target
->tprel_opt())
9237 section_size_type slen
;
9238 const unsigned char* view
= NULL
;
9239 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9240 section_size_type off
9241 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9244 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9245 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9246 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9247 target
->set_tprel_opt(false);
9252 case elfcpp::R_PPC64_TPREL16_HIGH
:
9253 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9254 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9255 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9256 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9257 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9261 case elfcpp::R_POWERPC_TPREL16_HI
:
9262 target
->set_tprel_opt(false);
9270 case elfcpp::R_PPC64_D34
:
9271 case elfcpp::R_PPC64_D34_LO
:
9272 case elfcpp::R_PPC64_D34_HI30
:
9273 case elfcpp::R_PPC64_D34_HA30
:
9274 case elfcpp::R_PPC64_D28
:
9275 case elfcpp::R_PPC64_PCREL34
:
9276 case elfcpp::R_PPC64_PCREL28
:
9277 case elfcpp::R_PPC64_TPREL34
:
9278 case elfcpp::R_PPC64_DTPREL34
:
9279 case elfcpp::R_PPC64_PLT_PCREL34
:
9280 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9281 case elfcpp::R_PPC64_GOT_PCREL34
:
9282 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9283 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9284 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9285 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9286 target
->set_power10_relocs();
9293 // Process relocations for gc.
9295 template<int size
, bool big_endian
>
9297 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9298 Symbol_table
* symtab
,
9300 Sized_relobj_file
<size
, big_endian
>* object
,
9301 unsigned int data_shndx
,
9303 const unsigned char* prelocs
,
9305 Output_section
* output_section
,
9306 bool needs_special_offset_handling
,
9307 size_t local_symbol_count
,
9308 const unsigned char* plocal_symbols
)
9310 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9311 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9314 Powerpc_relobj
<size
, big_endian
>* ppc_object
9315 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9317 ppc_object
->set_opd_valid();
9318 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9320 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9321 for (p
= ppc_object
->access_from_map()->begin();
9322 p
!= ppc_object
->access_from_map()->end();
9325 Address dst_off
= p
->first
;
9326 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9327 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9328 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9330 Relobj
* src_obj
= s
->first
;
9331 unsigned int src_indx
= s
->second
;
9332 symtab
->gc()->add_reference(src_obj
, src_indx
,
9333 ppc_object
, dst_indx
);
9337 ppc_object
->access_from_map()->clear();
9338 ppc_object
->process_gc_mark(symtab
);
9339 // Don't look at .opd relocs as .opd will reference everything.
9343 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9352 needs_special_offset_handling
,
9357 // Handle target specific gc actions when adding a gc reference from
9358 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9359 // and DST_OFF. For powerpc64, this adds a referenc to the code
9360 // section of a function descriptor.
9362 template<int size
, bool big_endian
>
9364 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9365 Symbol_table
* symtab
,
9367 unsigned int src_shndx
,
9369 unsigned int dst_shndx
,
9370 Address dst_off
) const
9372 if (size
!= 64 || dst_obj
->is_dynamic())
9375 Powerpc_relobj
<size
, big_endian
>* ppc_object
9376 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9377 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9379 if (ppc_object
->opd_valid())
9381 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9382 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9386 // If we haven't run scan_opd_relocs, we must delay
9387 // processing this function descriptor reference.
9388 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9393 // Add any special sections for this symbol to the gc work list.
9394 // For powerpc64, this adds the code section of a function
9397 template<int size
, bool big_endian
>
9399 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9400 Symbol_table
* symtab
,
9403 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9405 Powerpc_relobj
<size
, big_endian
>* ppc_object
9406 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9408 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9409 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9411 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9412 Address dst_off
= gsym
->value();
9413 if (ppc_object
->opd_valid())
9415 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9416 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9420 ppc_object
->add_gc_mark(dst_off
);
9425 // For a symbol location in .opd, set LOC to the location of the
9428 template<int size
, bool big_endian
>
9430 Target_powerpc
<size
, big_endian
>::do_function_location(
9431 Symbol_location
* loc
) const
9433 if (size
== 64 && loc
->shndx
!= 0)
9435 if (loc
->object
->is_dynamic())
9437 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9438 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9439 if (loc
->shndx
== ppc_object
->opd_shndx())
9442 Address off
= loc
->offset
- ppc_object
->opd_address();
9443 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9444 loc
->offset
= dest_off
;
9449 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9450 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9451 if (loc
->shndx
== ppc_object
->opd_shndx())
9454 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9455 loc
->offset
= dest_off
;
9461 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9462 // compiled with -fsplit-stack. The function calls non-split-stack
9463 // code. Change the function to ensure it has enough stack space to
9464 // call some random function.
9466 template<int size
, bool big_endian
>
9468 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9471 section_offset_type fnoffset
,
9472 section_size_type fnsize
,
9473 const unsigned char* prelocs
,
9475 unsigned char* view
,
9476 section_size_type view_size
,
9478 std::string
* to
) const
9480 // 32-bit not supported.
9484 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9485 prelocs
, reloc_count
, view
, view_size
,
9490 // The function always starts with
9491 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9492 // addis %r12,%r1,-allocate@ha
9493 // addi %r12,%r12,-allocate@l
9495 // but note that the addis or addi may be replaced with a nop
9497 unsigned char *entry
= view
+ fnoffset
;
9498 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9500 if ((insn
& 0xffff0000) == addis_2_12
)
9502 /* Skip ELFv2 global entry code. */
9504 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9507 unsigned char *pinsn
= entry
;
9509 const uint32_t ld_private_ss
= 0xe80d8fc0;
9510 if (insn
== ld_private_ss
)
9512 int32_t allocate
= 0;
9516 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9517 if ((insn
& 0xffff0000) == addis_12_1
)
9518 allocate
+= (insn
& 0xffff) << 16;
9519 else if ((insn
& 0xffff0000) == addi_12_1
9520 || (insn
& 0xffff0000) == addi_12_12
)
9521 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9522 else if (insn
!= nop
)
9525 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9527 int extra
= parameters
->options().split_stack_adjust_size();
9529 if (allocate
>= 0 || extra
< 0)
9531 object
->error(_("split-stack stack size overflow at "
9532 "section %u offset %0zx"),
9533 shndx
, static_cast<size_t>(fnoffset
));
9537 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9538 if (insn
!= addis_12_1
)
9540 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9542 insn
= addi_12_12
| (allocate
& 0xffff);
9543 if (insn
!= addi_12_12
)
9545 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9551 insn
= addi_12_1
| (allocate
& 0xffff);
9552 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9555 if (pinsn
!= entry
+ 12)
9556 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9564 if (!object
->has_no_split_stack())
9565 object
->error(_("failed to match split-stack sequence at "
9566 "section %u offset %0zx"),
9567 shndx
, static_cast<size_t>(fnoffset
));
9571 // Scan relocations for a section.
9573 template<int size
, bool big_endian
>
9575 Target_powerpc
<size
, big_endian
>::scan_relocs(
9576 Symbol_table
* symtab
,
9578 Sized_relobj_file
<size
, big_endian
>* object
,
9579 unsigned int data_shndx
,
9580 unsigned int sh_type
,
9581 const unsigned char* prelocs
,
9583 Output_section
* output_section
,
9584 bool needs_special_offset_handling
,
9585 size_t local_symbol_count
,
9586 const unsigned char* plocal_symbols
)
9588 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9589 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9592 if (!this->plt_localentry0_init_
)
9594 bool plt_localentry0
= false;
9596 && this->abiversion() >= 2)
9598 if (parameters
->options().user_set_plt_localentry())
9599 plt_localentry0
= parameters
->options().plt_localentry();
9601 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9602 gold_warning(_("--plt-localentry is especially dangerous without "
9603 "ld.so support to detect ABI violations"));
9605 this->plt_localentry0_
= plt_localentry0
;
9606 this->plt_localentry0_init_
= true;
9609 if (sh_type
== elfcpp::SHT_REL
)
9611 gold_error(_("%s: unsupported REL reloc section"),
9612 object
->name().c_str());
9616 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9625 needs_special_offset_handling
,
9629 if (this->plt_localentry0_
&& this->power10_relocs_
)
9631 gold_warning(_("--plt-localentry is incompatible with "
9632 "power10 pc-relative code"));
9633 this->plt_localentry0_
= false;
9637 // Functor class for processing the global symbol table.
9638 // Removes symbols defined on discarded opd entries.
9640 template<bool big_endian
>
9641 class Global_symbol_visitor_opd
9644 Global_symbol_visitor_opd()
9648 operator()(Sized_symbol
<64>* sym
)
9650 if (sym
->has_symtab_index()
9651 || sym
->source() != Symbol::FROM_OBJECT
9652 || !sym
->in_real_elf())
9655 if (sym
->object()->is_dynamic())
9658 Powerpc_relobj
<64, big_endian
>* symobj
9659 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9660 if (symobj
->opd_shndx() == 0)
9664 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9665 if (shndx
== symobj
->opd_shndx()
9666 && symobj
->get_opd_discard(sym
->value()))
9668 sym
->set_undefined();
9669 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9670 sym
->set_is_defined_in_discarded_section();
9671 sym
->set_symtab_index(-1U);
9676 template<int size
, bool big_endian
>
9678 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9680 Symbol_table
* symtab
)
9684 Output_data_save_res
<size
, big_endian
>* savres
9685 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9686 this->savres_section_
= savres
;
9687 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9688 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9689 savres
, ORDER_TEXT
, false);
9693 // Sort linker created .got section first (for the header), then input
9694 // sections belonging to files using small model code.
9696 template<bool big_endian
>
9697 class Sort_toc_sections
9701 operator()(const Output_section::Input_section
& is1
,
9702 const Output_section::Input_section
& is2
) const
9704 if (!is1
.is_input_section() && is2
.is_input_section())
9707 = (is1
.is_input_section()
9708 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9709 ->has_small_toc_reloc()));
9711 = (is2
.is_input_section()
9712 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9713 ->has_small_toc_reloc()));
9714 return small1
&& !small2
;
9718 // Finalize the sections.
9720 template<int size
, bool big_endian
>
9722 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9724 const Input_objects
* input_objects
,
9725 Symbol_table
* symtab
)
9727 if (parameters
->doing_static_link())
9729 // At least some versions of glibc elf-init.o have a strong
9730 // reference to __rela_iplt marker syms. A weak ref would be
9732 if (this->iplt_
!= NULL
)
9734 Reloc_section
* rel
= this->iplt_
->rel_plt();
9735 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9736 Symbol_table::PREDEFINED
, rel
, 0, 0,
9737 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9738 elfcpp::STV_HIDDEN
, 0, false, true);
9739 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9740 Symbol_table::PREDEFINED
, rel
, 0, 0,
9741 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9742 elfcpp::STV_HIDDEN
, 0, true, true);
9746 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9747 Symbol_table::PREDEFINED
, 0, 0,
9748 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9749 elfcpp::STV_HIDDEN
, 0, true, false);
9750 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9751 Symbol_table::PREDEFINED
, 0, 0,
9752 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9753 elfcpp::STV_HIDDEN
, 0, true, false);
9759 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9760 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9762 if (!parameters
->options().relocatable())
9764 this->define_save_restore_funcs(layout
, symtab
);
9766 // Annoyingly, we need to make these sections now whether or
9767 // not we need them. If we delay until do_relax then we
9768 // need to mess with the relaxation machinery checkpointing.
9769 this->got_section(symtab
, layout
);
9770 this->make_brlt_section(layout
);
9772 if (parameters
->options().toc_sort())
9774 Output_section
* os
= this->got_
->output_section();
9775 if (os
!= NULL
&& os
->input_sections().size() > 1)
9776 std::stable_sort(os
->input_sections().begin(),
9777 os
->input_sections().end(),
9778 Sort_toc_sections
<big_endian
>());
9783 // Fill in some more dynamic tags.
9784 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9787 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9789 : this->plt_
->rel_plt());
9790 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9791 this->rela_dyn_
, true, size
== 32);
9795 if (this->got_
!= NULL
)
9797 this->got_
->finalize_data_size();
9798 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9799 this->got_
, this->got_
->g_o_t());
9801 if (this->has_tls_get_addr_opt_
)
9802 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9806 if (this->glink_
!= NULL
)
9808 this->glink_
->finalize_data_size();
9809 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9811 (this->glink_
->pltresolve_size()
9814 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9815 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9816 ((this->has_localentry0_
9817 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9818 | (this->has_tls_get_addr_opt_
9819 ? elfcpp::PPC64_OPT_TLS
: 0)));
9823 // Emit any relocs we saved in an attempt to avoid generating COPY
9825 if (this->copy_relocs_
.any_saved_relocs())
9826 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9828 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9829 p
!= input_objects
->relobj_end();
9832 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9833 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9834 if (ppc_relobj
->attributes_section_data())
9835 this->merge_object_attributes(ppc_relobj
,
9836 ppc_relobj
->attributes_section_data());
9838 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9839 p
!= input_objects
->dynobj_end();
9842 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9843 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9844 if (ppc_dynobj
->attributes_section_data())
9845 this->merge_object_attributes(ppc_dynobj
,
9846 ppc_dynobj
->attributes_section_data());
9849 // Create a .gnu.attributes section if we have merged any attributes
9851 if (this->attributes_section_data_
!= NULL
9852 && this->attributes_section_data_
->size() != 0)
9854 Output_attributes_section_data
* attributes_section
9855 = new Output_attributes_section_data(*this->attributes_section_data_
);
9856 layout
->add_output_section_data(".gnu.attributes",
9857 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9858 attributes_section
, ORDER_INVALID
, false);
9862 // Merge object attributes from input file called NAME with those of the
9863 // output. The input object attributes are in the object pointed by PASD.
9865 template<int size
, bool big_endian
>
9867 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9869 const Attributes_section_data
* pasd
)
9871 // Return if there is no attributes section data.
9875 // Create output object attributes.
9876 if (this->attributes_section_data_
== NULL
)
9877 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9879 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9880 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9881 Object_attribute
* out_attr
9882 = this->attributes_section_data_
->known_attributes(vendor
);
9884 const char* name
= obj
->name().c_str();
9888 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9889 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9890 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9891 bool warn_only
= obj
->is_dynamic();
9892 if (in_fp
!= out_fp
)
9895 if ((in_fp
& 3) == 0)
9897 else if ((out_fp
& 3) == 0)
9901 out_fp
|= in_fp
& 3;
9902 out_attr
[tag
].set_int_value(out_fp
);
9903 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9904 this->last_fp_
= name
;
9907 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9909 err
= N_("%s uses hard float, %s uses soft float");
9910 first
= this->last_fp_
;
9913 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9915 err
= N_("%s uses hard float, %s uses soft float");
9917 second
= this->last_fp_
;
9919 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9921 err
= N_("%s uses double-precision hard float, "
9922 "%s uses single-precision hard float");
9923 first
= this->last_fp_
;
9926 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9928 err
= N_("%s uses double-precision hard float, "
9929 "%s uses single-precision hard float");
9931 second
= this->last_fp_
;
9934 if (err
|| (in_fp
& 0xc) == 0)
9936 else if ((out_fp
& 0xc) == 0)
9940 out_fp
|= in_fp
& 0xc;
9941 out_attr
[tag
].set_int_value(out_fp
);
9942 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9943 this->last_ld_
= name
;
9946 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9948 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9950 second
= this->last_ld_
;
9952 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9954 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9955 first
= this->last_ld_
;
9958 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9960 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9961 first
= this->last_ld_
;
9964 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9966 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9968 second
= this->last_ld_
;
9973 if (parameters
->options().warn_mismatch())
9976 gold_warning(_(err
), first
, second
);
9978 gold_error(_(err
), first
, second
);
9980 // Arrange for this attribute to be deleted. It's better to
9981 // say "don't know" about a file than to wrongly claim compliance.
9983 out_attr
[tag
].set_type(0);
9989 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9990 int in_vec
= in_attr
[tag
].int_value() & 3;
9991 int out_vec
= out_attr
[tag
].int_value() & 3;
9992 if (in_vec
!= out_vec
)
9997 else if (out_vec
== 0)
10000 out_attr
[tag
].set_int_value(out_vec
);
10001 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10002 this->last_vec_
= name
;
10004 // For now, allow generic to transition to AltiVec or SPE
10005 // without a warning. If GCC marked files with their stack
10006 // alignment and used don't-care markings for files which are
10007 // not affected by the vector ABI, we could warn about this
10009 else if (in_vec
== 1)
10011 else if (out_vec
== 1)
10014 out_attr
[tag
].set_int_value(out_vec
);
10015 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10016 this->last_vec_
= name
;
10018 else if (out_vec
< in_vec
)
10020 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10021 first
= this->last_vec_
;
10024 else if (out_vec
> in_vec
)
10026 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10028 second
= this->last_vec_
;
10032 if (parameters
->options().warn_mismatch())
10033 gold_error(_(err
), first
, second
);
10034 out_attr
[tag
].set_type(0);
10038 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10039 int in_struct
= in_attr
[tag
].int_value() & 3;
10040 int out_struct
= out_attr
[tag
].int_value() & 3;
10041 if (in_struct
!= out_struct
)
10044 if (in_struct
== 0 || in_struct
== 3)
10046 else if (out_struct
== 0)
10048 out_struct
= in_struct
;
10049 out_attr
[tag
].set_int_value(out_struct
);
10050 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10051 this->last_struct_
= name
;
10053 else if (out_struct
< in_struct
)
10055 err
= N_("%s uses r3/r4 for small structure returns, "
10057 first
= this->last_struct_
;
10060 else if (out_struct
> in_struct
)
10062 err
= N_("%s uses r3/r4 for small structure returns, "
10065 second
= this->last_struct_
;
10069 if (parameters
->options().warn_mismatch())
10070 gold_error(_(err
), first
, second
);
10071 out_attr
[tag
].set_type(0);
10076 // Merge Tag_compatibility attributes and any common GNU ones.
10077 this->attributes_section_data_
->merge(name
, pasd
);
10080 // Emit any saved relocs, and mark toc entries using any of these
10081 // relocs as not optimizable.
10083 template<int sh_type
, int size
, bool big_endian
>
10085 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10086 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10089 && parameters
->options().toc_optimize())
10091 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10092 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10093 p
!= this->entries_
.end();
10096 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10099 // If the symbol is no longer defined in a dynamic object,
10100 // then we emitted a COPY relocation. If it is still
10101 // dynamic then we'll need dynamic relocations and thus
10102 // can't optimize toc entries.
10103 if (entry
.sym_
->is_from_dynobj())
10105 Powerpc_relobj
<size
, big_endian
>* ppc_object
10106 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10107 if (entry
.shndx_
== ppc_object
->toc_shndx())
10108 ppc_object
->set_no_toc_opt(entry
.address_
);
10113 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10116 // Return the value to use for a branch relocation.
10118 template<int size
, bool big_endian
>
10120 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10121 const Symbol_table
* symtab
,
10122 const Sized_symbol
<size
>* gsym
,
10123 Powerpc_relobj
<size
, big_endian
>* object
,
10125 unsigned int *dest_shndx
)
10127 if (size
== 32 || this->abiversion() >= 2)
10128 gold_unreachable();
10131 // If the symbol is defined in an opd section, ie. is a function
10132 // descriptor, use the function descriptor code entry address
10133 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10135 && (gsym
->source() != Symbol::FROM_OBJECT
10136 || gsym
->object()->is_dynamic()))
10139 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10140 unsigned int shndx
= symobj
->opd_shndx();
10143 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10144 if (opd_addr
== invalid_address
)
10146 opd_addr
+= symobj
->output_section_address(shndx
);
10147 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10150 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10151 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10154 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10155 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10156 *dest_shndx
= folded
.second
;
10158 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10159 if (sec_addr
== invalid_address
)
10162 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10163 *value
= sec_addr
+ sec_off
;
10170 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10172 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10175 if (gsym
->is_from_dynobj()
10176 || gsym
->is_undefined()
10177 || gsym
->is_preemptible())
10180 if (gsym
->is_absolute())
10181 return !parameters
->options().output_is_position_independent();
10188 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10190 if (psymval
->is_ifunc_symbol())
10194 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10196 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10199 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10200 // pld ra,symbol@got@pcrel
10201 // load/store rt,0(ra)
10203 // pla ra,symbol@pcrel
10204 // load/store rt,0(ra)
10205 // may be translated to
10206 // pload/pstore rt,symbol@pcrel
10208 // This function returns true if the optimization is possible, placing
10209 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10211 // On entry to this function, the linker has already determined that
10212 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10213 // while *PINSN2 is the second instruction.
10216 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10218 uint32_t insn2
= *pinsn2
>> 32;
10221 // Check that regs match.
10222 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10225 switch ((insn2
>> 26) & 63)
10241 // These are the PMLS cases, where we just need to tack a prefix
10242 // on the insn. Check that the D field is zero.
10243 if ((insn2
& 0xffff) != 0)
10245 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10246 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10249 case 58: // lwa, ld
10250 if ((insn2
& 0xfffd) != 0)
10252 i1new
= ((1ULL << 58) | (1ULL << 52)
10253 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10254 | (insn2
& (31ULL << 21)));
10257 case 57: // lxsd, lxssp
10258 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10260 i1new
= ((1ULL << 58) | (1ULL << 52)
10261 | ((40ULL | (insn2
& 3)) << 26)
10262 | (insn2
& (31ULL << 21)));
10265 case 61: // stxsd, stxssp, lxv, stxv
10266 if ((insn2
& 3) == 0)
10268 else if ((insn2
& 3) >= 2)
10270 if ((insn2
& 0xfffc) != 0)
10272 i1new
= ((1ULL << 58) | (1ULL << 52)
10273 | ((44ULL | (insn2
& 3)) << 26)
10274 | (insn2
& (31ULL << 21)));
10278 if ((insn2
& 0xfff0) != 0)
10280 i1new
= ((1ULL << 58) | (1ULL << 52)
10281 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10282 | (insn2
& (31ULL << 21)));
10287 if ((insn2
& 0xffff) != 0)
10289 i1new
= ((1ULL << 58) | (1ULL << 52)
10290 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10293 case 62: // std, stq
10294 if ((insn2
& 0xfffd) != 0)
10296 i1new
= ((1ULL << 58) | (1ULL << 52)
10297 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10298 | (insn2
& (31ULL << 21)));
10303 *pinsn2
= (uint64_t) nop
<< 32;
10307 // Perform a relocation.
10309 template<int size
, bool big_endian
>
10311 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10312 const Relocate_info
<size
, big_endian
>* relinfo
,
10314 Target_powerpc
* target
,
10315 Output_section
* os
,
10317 const unsigned char* preloc
,
10318 const Sized_symbol
<size
>* gsym
,
10319 const Symbol_value
<size
>* psymval
,
10320 unsigned char* view
,
10322 section_size_type view_size
)
10324 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10325 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10326 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10331 if (target
->replace_tls_get_addr(gsym
))
10332 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10334 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10335 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10336 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10338 case Track_tls::NOT_EXPECTED
:
10339 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10340 _("__tls_get_addr call lacks marker reloc"));
10342 case Track_tls::EXPECTED
:
10343 // We have already complained.
10345 case Track_tls::SKIP
:
10346 if (is_plt16_reloc
<size
>(r_type
)
10347 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10348 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10350 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10351 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10353 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10355 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10356 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10358 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10359 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10361 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10362 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10363 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10366 case Track_tls::NORMAL
:
10370 // Offset from start of insn to d-field reloc.
10371 const int d_offset
= big_endian
? 2 : 0;
10373 Powerpc_relobj
<size
, big_endian
>* const object
10374 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10376 bool has_stub_value
= false;
10377 bool localentry0
= false;
10378 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10379 bool has_plt_offset
10381 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10382 : object
->local_has_plt_offset(r_sym
));
10384 && !is_plt16_reloc
<size
>(r_type
)
10385 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10386 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10387 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10388 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10389 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10390 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10391 && (!psymval
->is_ifunc_symbol()
10392 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10396 && target
->abiversion() >= 2
10397 && !parameters
->options().output_is_position_independent()
10398 && !is_branch_reloc
<size
>(r_type
))
10400 Address off
= target
->glink_section()->find_global_entry(gsym
);
10401 if (off
!= invalid_address
)
10403 value
= target
->glink_section()->global_entry_address() + off
;
10404 has_stub_value
= true;
10409 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10410 if (target
->stub_tables().size() == 1)
10411 stub_table
= target
->stub_tables()[0];
10412 if (stub_table
== NULL
10415 && !parameters
->options().output_is_position_independent()
10416 && !is_branch_reloc
<size
>(r_type
)))
10417 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10418 if (stub_table
== NULL
)
10420 // This is a ref from a data section to an ifunc symbol,
10421 // or a non-branch reloc for which we always want to use
10422 // one set of stubs for resolving function addresses.
10423 if (target
->stub_tables().size() != 0)
10424 stub_table
= target
->stub_tables()[0];
10426 if (stub_table
!= NULL
)
10428 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10430 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10431 rela
.get_r_addend());
10433 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10434 rela
.get_r_addend());
10437 value
= stub_table
->stub_address() + ent
->off_
;
10438 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10439 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10440 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10442 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10443 value
+= ent
->tocoff_
;
10447 && target
->is_tls_get_addr_opt(gsym
)))
10449 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10451 if (!(target
->power10_stubs()
10452 && target
->power10_stubs_auto()))
10455 else if (relnum
< reloc_count
- 1)
10457 Reltype
next_rela(preloc
+ reloc_size
);
10458 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10459 == elfcpp::R_PPC64_TOCSAVE
10460 && (next_rela
.get_r_offset()
10461 == rela
.get_r_offset() + 4))
10465 localentry0
= ent
->localentry0_
;
10466 has_stub_value
= true;
10470 // We don't care too much about bogus debug references to
10471 // non-local functions, but otherwise there had better be a plt
10472 // call stub or global entry stub as appropriate.
10473 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10476 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10477 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10478 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10480 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10482 value
= target
->plt_off(gsym
, &plt
);
10484 value
= target
->plt_off(object
, r_sym
, &plt
);
10485 value
+= plt
->address();
10489 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10490 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10491 value
-= (target
->got_section()->output_section()->address()
10492 + object
->toc_base_offset());
10494 else if (parameters
->options().output_is_position_independent())
10496 if (rela
.get_r_addend() >= 32768)
10498 unsigned int got2
= object
->got2_shndx();
10499 value
-= (object
->get_output_section_offset(got2
)
10500 + object
->output_section(got2
)->address()
10501 + rela
.get_r_addend());
10504 value
-= (target
->got_section()->address()
10505 + target
->got_section()->g_o_t());
10508 else if (!has_plt_offset
10509 && (is_plt16_reloc
<size
>(r_type
)
10510 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10511 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10513 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10514 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10515 r_type
= elfcpp::R_POWERPC_NONE
;
10517 else if (!has_plt_offset
10518 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10519 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10521 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10522 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10523 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10524 r_type
= elfcpp::R_POWERPC_NONE
;
10526 else if (r_type
== elfcpp::R_POWERPC_GOT16
10527 || r_type
== elfcpp::R_POWERPC_GOT16_LO
10528 || r_type
== elfcpp::R_POWERPC_GOT16_HI
10529 || r_type
== elfcpp::R_POWERPC_GOT16_HA
10530 || r_type
== elfcpp::R_PPC64_GOT16_DS
10531 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10532 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10536 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10537 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10541 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10542 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10544 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10545 value
+= target
->got_section()->address();
10547 value
-= target
->got_section()->got_base_offset(object
);
10549 else if (r_type
== elfcpp::R_PPC64_TOC
)
10551 value
= (target
->got_section()->output_section()->address()
10552 + object
->toc_base_offset());
10554 else if (gsym
!= NULL
10555 && (r_type
== elfcpp::R_POWERPC_REL24
10556 || r_type
== elfcpp::R_PPC_PLTREL24
)
10561 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10562 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10563 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10564 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10566 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10567 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10568 if ((insn
& 1) != 0
10570 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10572 elfcpp::Swap
<32, big_endian
>::
10573 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10574 can_plt_call
= true;
10579 // If we don't have a branch and link followed by a nop,
10580 // we can't go via the plt because there is no place to
10581 // put a toc restoring instruction.
10582 // Unless we know we won't be returning.
10583 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10584 can_plt_call
= true;
10588 // g++ as of 20130507 emits self-calls without a
10589 // following nop. This is arguably wrong since we have
10590 // conflicting information. On the one hand a global
10591 // symbol and on the other a local call sequence, but
10592 // don't error for this special case.
10593 // It isn't possible to cheaply verify we have exactly
10594 // such a call. Allow all calls to the same section.
10596 Address code
= value
;
10597 if (gsym
->source() == Symbol::FROM_OBJECT
10598 && gsym
->object() == object
)
10600 unsigned int dest_shndx
= 0;
10601 if (target
->abiversion() < 2)
10603 Address addend
= rela
.get_r_addend();
10604 code
= psymval
->value(object
, addend
);
10605 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10606 &code
, &dest_shndx
);
10609 if (dest_shndx
== 0)
10610 dest_shndx
= gsym
->shndx(&is_ordinary
);
10611 ok
= dest_shndx
== relinfo
->data_shndx
;
10615 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10616 _("call lacks nop, can't restore toc; "
10617 "recompile with -fPIC"));
10623 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10624 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10625 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10626 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10627 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10629 // First instruction of a global dynamic sequence, arg setup insn.
10630 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10631 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10632 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10633 if (tls_type
== tls::TLSOPT_NONE
)
10634 got_type
= GOT_TYPE_TLSGD
;
10635 else if (tls_type
== tls::TLSOPT_TO_IE
)
10636 got_type
= GOT_TYPE_TPREL
;
10637 if (got_type
!= GOT_TYPE_STANDARD
)
10641 gold_assert(gsym
->has_got_offset(got_type
));
10642 value
= gsym
->got_offset(got_type
);
10646 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10647 value
= object
->local_got_offset(r_sym
, got_type
);
10649 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10650 value
+= target
->got_section()->address();
10652 value
-= target
->got_section()->got_base_offset(object
);
10654 if (tls_type
== tls::TLSOPT_TO_IE
)
10656 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10658 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10659 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10661 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10663 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10664 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10665 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10666 pinsn
& 0xffffffff);
10667 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10671 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10672 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10674 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10675 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10676 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10678 insn
|= 32 << 26; // lwz
10680 insn
|= 58 << 26; // ld
10681 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10683 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10684 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10687 else if (tls_type
== tls::TLSOPT_TO_LE
)
10689 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10691 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10692 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10694 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10695 // pla pcrel -> paddi r13
10696 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10697 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10698 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10699 pinsn
& 0xffffffff);
10700 r_type
= elfcpp::R_PPC64_TPREL34
;
10701 value
= psymval
->value(object
, rela
.get_r_addend());
10705 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10706 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10708 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10709 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10710 insn
&= (1 << 26) - (1 << 21); // extract rt
10714 insn
|= addis_0_13
;
10715 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10716 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10717 value
= psymval
->value(object
, rela
.get_r_addend());
10721 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10723 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10724 r_type
= elfcpp::R_POWERPC_NONE
;
10729 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10730 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10731 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10732 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10733 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10735 // First instruction of a local dynamic sequence, arg setup insn.
10736 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10737 if (tls_type
== tls::TLSOPT_NONE
)
10739 value
= target
->tlsld_got_offset();
10740 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10741 value
+= target
->got_section()->address();
10743 value
-= target
->got_section()->got_base_offset(object
);
10747 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10748 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10750 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10751 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10753 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10754 // pla pcrel -> paddi r13
10755 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10756 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10757 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10758 pinsn
& 0xffffffff);
10759 r_type
= elfcpp::R_PPC64_TPREL34
;
10760 value
= dtp_offset
;
10762 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10763 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10765 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10766 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10767 insn
&= (1 << 26) - (1 << 21); // extract rt
10771 insn
|= addis_0_13
;
10772 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10773 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10774 value
= dtp_offset
;
10778 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10780 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10781 r_type
= elfcpp::R_POWERPC_NONE
;
10785 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10786 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10787 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10788 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10789 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10791 // Accesses relative to a local dynamic sequence address,
10792 // no optimisation here.
10795 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10796 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10800 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10801 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10803 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10804 value
+= target
->got_section()->address();
10806 value
-= target
->got_section()->got_base_offset(object
);
10808 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10809 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10810 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10811 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10812 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10814 // First instruction of initial exec sequence.
10815 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10816 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10817 if (tls_type
== tls::TLSOPT_NONE
)
10821 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10822 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10826 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10827 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10829 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10830 value
+= target
->got_section()->address();
10832 value
-= target
->got_section()->got_base_offset(object
);
10836 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10837 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10839 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10840 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10842 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10843 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10844 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10845 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10846 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10847 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10848 pinsn
& 0xffffffff);
10849 r_type
= elfcpp::R_PPC64_TPREL34
;
10850 value
= psymval
->value(object
, rela
.get_r_addend());
10852 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10853 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10855 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10856 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10857 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10861 insn
|= addis_0_13
;
10862 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10863 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10864 value
= psymval
->value(object
, rela
.get_r_addend());
10868 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10870 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10871 r_type
= elfcpp::R_POWERPC_NONE
;
10875 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10876 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10878 // Second instruction of a global dynamic sequence,
10879 // the __tls_get_addr call
10880 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10881 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10882 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10883 if (tls_type
!= tls::TLSOPT_NONE
)
10885 if (tls_type
== tls::TLSOPT_TO_IE
)
10887 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10888 Insn insn
= add_3_3_13
;
10891 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10892 r_type
= elfcpp::R_POWERPC_NONE
;
10896 bool is_pcrel
= false;
10897 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10898 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10899 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10900 if (relnum
< reloc_count
- 1)
10902 Reltype
next_rela(preloc
+ reloc_size
);
10903 unsigned int r_type2
10904 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10905 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10906 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10907 && next_rela
.get_r_offset() == rela
.get_r_offset())
10910 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10913 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10914 r_type
= elfcpp::R_POWERPC_NONE
;
10918 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10919 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10921 value
= psymval
->value(object
, rela
.get_r_addend());
10924 this->skip_next_tls_get_addr_call();
10927 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10928 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10930 // Second instruction of a local dynamic sequence,
10931 // the __tls_get_addr call
10932 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10933 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10934 if (tls_type
== tls::TLSOPT_TO_LE
)
10936 bool is_pcrel
= false;
10937 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10938 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10939 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10940 if (relnum
< reloc_count
- 1)
10942 Reltype
next_rela(preloc
+ reloc_size
);
10943 unsigned int r_type2
10944 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10945 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10946 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10947 && next_rela
.get_r_offset() == rela
.get_r_offset())
10950 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10953 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10954 r_type
= elfcpp::R_POWERPC_NONE
;
10958 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10959 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10961 value
= dtp_offset
;
10963 this->skip_next_tls_get_addr_call();
10966 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10968 // Second instruction of an initial exec sequence
10969 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10970 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10971 if (tls_type
== tls::TLSOPT_TO_LE
)
10973 Address roff
= rela
.get_r_offset() & 3;
10974 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10975 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10976 unsigned int reg
= size
== 32 ? 2 : 13;
10977 insn
= at_tls_transform(insn
, reg
);
10978 gold_assert(insn
!= 0);
10981 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10982 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10984 value
= psymval
->value(object
, rela
.get_r_addend());
10986 else if (roff
== 1)
10988 // For pcrel IE to LE we already have the full offset
10989 // and thus don't need an addi here. A nop or mr will do.
10990 if ((insn
& (0x3f << 26)) == 14 << 26)
10992 // Extract regs from addi rt,ra,si.
10993 unsigned int rt
= (insn
>> 21) & 0x1f;
10994 unsigned int ra
= (insn
>> 16) & 0x1f;
10999 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11000 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11001 insn
|= (31u << 26) | (444u << 1);
11004 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11005 r_type
= elfcpp::R_POWERPC_NONE
;
11009 else if (!has_stub_value
)
11011 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11012 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11014 // PLTCALL without plt entry => convert to direct call
11015 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11016 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11017 insn
= (insn
& 1) | b
;
11018 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11020 r_type
= elfcpp::R_PPC_PLTREL24
;
11021 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11022 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11024 r_type
= elfcpp::R_POWERPC_REL24
;
11026 Address addend
= 0;
11028 && (r_type
== elfcpp::R_PPC_PLTREL24
11029 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11030 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11031 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11032 addend
= rela
.get_r_addend();
11033 value
= psymval
->value(object
, addend
);
11034 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11036 if (target
->abiversion() >= 2)
11039 value
+= object
->ppc64_local_entry_offset(gsym
);
11041 value
+= object
->ppc64_local_entry_offset(r_sym
);
11045 unsigned int dest_shndx
;
11046 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11047 &value
, &dest_shndx
);
11050 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
11051 if (max_branch_offset
!= 0
11052 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
11054 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11056 ? object
->ppc64_needs_toc(gsym
)
11057 : object
->ppc64_needs_toc(r_sym
)))))
11059 Stub_table
<size
, big_endian
>* stub_table
11060 = object
->stub_table(relinfo
->data_shndx
);
11061 if (stub_table
!= NULL
)
11063 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11064 = stub_table
->find_long_branch_entry(object
, value
);
11067 if (ent
->save_res_
)
11068 value
= (value
- target
->savres_section()->address()
11069 + stub_table
->branch_size());
11072 value
= (stub_table
->stub_address()
11073 + stub_table
->plt_size()
11076 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11077 value
+= ent
->tocoff_
;
11079 has_stub_value
= true;
11087 case elfcpp::R_PPC64_REL24_NOTOC
:
11091 case elfcpp::R_PPC64_REL64
:
11092 case elfcpp::R_POWERPC_REL32
:
11093 case elfcpp::R_POWERPC_REL24
:
11094 case elfcpp::R_PPC_PLTREL24
:
11095 case elfcpp::R_PPC_LOCAL24PC
:
11096 case elfcpp::R_POWERPC_REL16
:
11097 case elfcpp::R_POWERPC_REL16_LO
:
11098 case elfcpp::R_POWERPC_REL16_HI
:
11099 case elfcpp::R_POWERPC_REL16_HA
:
11100 case elfcpp::R_POWERPC_REL16DX_HA
:
11101 case elfcpp::R_PPC64_REL16_HIGH
:
11102 case elfcpp::R_PPC64_REL16_HIGHA
:
11103 case elfcpp::R_PPC64_REL16_HIGHER
:
11104 case elfcpp::R_PPC64_REL16_HIGHERA
:
11105 case elfcpp::R_PPC64_REL16_HIGHEST
:
11106 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11107 case elfcpp::R_POWERPC_REL14
:
11108 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11109 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11110 case elfcpp::R_PPC64_PCREL34
:
11111 case elfcpp::R_PPC64_GOT_PCREL34
:
11112 case elfcpp::R_PPC64_PLT_PCREL34
:
11113 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11114 case elfcpp::R_PPC64_PCREL28
:
11115 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11116 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11117 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11118 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11119 case elfcpp::R_PPC64_REL16_HIGHER34
:
11120 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11121 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11122 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11126 case elfcpp::R_PPC64_TOC16
:
11127 case elfcpp::R_PPC64_TOC16_LO
:
11128 case elfcpp::R_PPC64_TOC16_HI
:
11129 case elfcpp::R_PPC64_TOC16_HA
:
11130 case elfcpp::R_PPC64_TOC16_DS
:
11131 case elfcpp::R_PPC64_TOC16_LO_DS
:
11132 // Subtract the TOC base address.
11133 value
-= (target
->got_section()->output_section()->address()
11134 + object
->toc_base_offset());
11137 case elfcpp::R_POWERPC_SECTOFF
:
11138 case elfcpp::R_POWERPC_SECTOFF_LO
:
11139 case elfcpp::R_POWERPC_SECTOFF_HI
:
11140 case elfcpp::R_POWERPC_SECTOFF_HA
:
11141 case elfcpp::R_PPC64_SECTOFF_DS
:
11142 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11144 value
-= os
->address();
11147 case elfcpp::R_PPC64_TPREL16_DS
:
11148 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11149 case elfcpp::R_PPC64_TPREL16_HIGH
:
11150 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11152 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11155 case elfcpp::R_POWERPC_TPREL16
:
11156 case elfcpp::R_POWERPC_TPREL16_LO
:
11157 case elfcpp::R_POWERPC_TPREL16_HI
:
11158 case elfcpp::R_POWERPC_TPREL16_HA
:
11159 case elfcpp::R_POWERPC_TPREL
:
11160 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11161 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11162 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11163 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11164 case elfcpp::R_PPC64_TPREL34
:
11165 // tls symbol values are relative to tls_segment()->vaddr()
11166 value
-= tp_offset
;
11169 case elfcpp::R_PPC64_DTPREL16_DS
:
11170 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11171 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11172 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11173 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11174 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11176 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11177 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11180 case elfcpp::R_POWERPC_DTPREL16
:
11181 case elfcpp::R_POWERPC_DTPREL16_LO
:
11182 case elfcpp::R_POWERPC_DTPREL16_HI
:
11183 case elfcpp::R_POWERPC_DTPREL16_HA
:
11184 case elfcpp::R_POWERPC_DTPREL
:
11185 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11186 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11187 case elfcpp::R_PPC64_DTPREL34
:
11188 // tls symbol values are relative to tls_segment()->vaddr()
11189 value
-= dtp_offset
;
11192 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11194 value
+= object
->ppc64_local_entry_offset(gsym
);
11196 value
+= object
->ppc64_local_entry_offset(r_sym
);
11203 Insn branch_bit
= 0;
11206 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11207 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11208 branch_bit
= 1 << 21;
11210 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11211 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11213 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11214 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11215 insn
&= ~(1 << 21);
11216 insn
|= branch_bit
;
11217 if (this->is_isa_v2
)
11219 // Set 'a' bit. This is 0b00010 in BO field for branch
11220 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11221 // for branch on CTR insns (BO == 1a00t or 1a01t).
11222 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11223 insn
|= 0x02 << 21;
11224 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11225 insn
|= 0x08 << 21;
11231 // Invert 'y' bit if not the default.
11232 if (static_cast<Signed_address
>(value
) < 0)
11235 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11239 case elfcpp::R_POWERPC_PLT16_HA
:
11241 && !parameters
->options().output_is_position_independent())
11243 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11244 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11246 // Convert addis to lis.
11247 if ((insn
& (0x3f << 26)) == 15u << 26
11248 && (insn
& (0x1f << 16)) != 0)
11250 insn
&= ~(0x1f << 16);
11251 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11261 ? relative_value_is_known(gsym
)
11262 : relative_value_is_known(psymval
))
11267 uint64_t pinsn
, pinsn2
;
11274 // Multi-instruction sequences that access the GOT/TOC can
11275 // be optimized, eg.
11276 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11277 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11279 // addis ra,r2,0; addi rb,ra,x@toc@l;
11280 // to nop; addi rb,r2,x@toc;
11281 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11282 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11283 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11284 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11285 case elfcpp::R_POWERPC_GOT16_HA
:
11286 case elfcpp::R_PPC64_TOC16_HA
:
11287 if (size
== 64 && parameters
->options().toc_optimize())
11289 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11290 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11291 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11292 && object
->make_toc_relative(target
, &value
))
11293 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11294 && object
->make_got_relative(target
, psymval
,
11295 rela
.get_r_addend(),
11298 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11299 == ((15u << 26) | (2 << 16)));
11301 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11302 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11303 && value
+ 0x8000 < 0x10000)
11305 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11311 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11312 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11313 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11314 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11315 case elfcpp::R_POWERPC_GOT16_LO
:
11316 case elfcpp::R_PPC64_GOT16_LO_DS
:
11317 case elfcpp::R_PPC64_TOC16_LO
:
11318 case elfcpp::R_PPC64_TOC16_LO_DS
:
11319 if (size
== 64 && parameters
->options().toc_optimize())
11321 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11322 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11323 bool changed
= false;
11324 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11325 && object
->make_toc_relative(target
, &value
))
11326 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11327 && object
->make_got_relative(target
, psymval
,
11328 rela
.get_r_addend(),
11331 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11332 insn
^= (14u << 26) ^ (58u << 26);
11333 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11336 if (ok_lo_toc_insn(insn
, r_type
)
11337 && value
+ 0x8000 < 0x10000)
11339 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11341 // Transform addic to addi when we change reg.
11342 insn
&= ~((0x3f << 26) | (0x1f << 16));
11343 insn
|= (14u << 26) | (2 << 16);
11347 insn
&= ~(0x1f << 16);
11353 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11357 case elfcpp::R_PPC64_GOT_PCREL34
:
11358 if (size
== 64 && parameters
->options().toc_optimize())
11360 iview
= reinterpret_cast<Insn
*>(view
);
11361 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11363 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11364 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11365 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11368 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11370 if (relval
+ (1ULL << 33) < 1ULL << 34)
11373 // Replace with paddi
11374 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11375 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11376 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11377 pinsn
& 0xffffffff);
11383 case elfcpp::R_PPC64_PCREL34
:
11386 iview
= reinterpret_cast<Insn
*>(view
);
11387 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11389 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11390 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11391 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11392 | (14ULL << 26) /* paddi */))
11396 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11397 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11398 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11399 if (relnum
>= reloc_count
- 1)
11402 Reltype
next_rela(preloc
+ reloc_size
);
11403 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11404 != elfcpp::R_PPC64_PCREL_OPT
)
11405 || next_rela
.get_r_offset() != rela
.get_r_offset())
11408 Address off
= next_rela
.get_r_addend();
11410 off
= 8; // zero means next insn.
11411 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11414 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11415 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11417 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11419 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11421 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11422 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11423 pinsn
& 0xffffffff);
11424 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11429 case elfcpp::R_POWERPC_TPREL16_HA
:
11430 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11432 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11433 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11438 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11440 // R_PPC_TLSGD, R_PPC_TLSLD
11443 case elfcpp::R_POWERPC_TPREL16_LO
:
11444 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11446 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11447 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11448 insn
&= ~(0x1f << 16);
11449 insn
|= (size
== 32 ? 2 : 13) << 16;
11450 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11454 case elfcpp::R_PPC64_ENTRY
:
11457 value
= (target
->got_section()->output_section()->address()
11458 + object
->toc_base_offset());
11459 if (value
+ 0x80008000 <= 0xffffffff
11460 && !parameters
->options().output_is_position_independent())
11462 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11463 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11464 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11466 if ((insn1
& ~0xfffc) == ld_2_12
11467 && insn2
== add_2_2_12
)
11469 insn1
= lis_2
+ ha(value
);
11470 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11471 insn2
= addi_2_2
+ l(value
);
11472 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11479 if (value
+ 0x80008000 <= 0xffffffff)
11481 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11482 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11483 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11485 if ((insn1
& ~0xfffc) == ld_2_12
11486 && insn2
== add_2_2_12
)
11488 insn1
= addis_2_12
+ ha(value
);
11489 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11490 insn2
= addi_2_2
+ l(value
);
11491 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11499 case elfcpp::R_POWERPC_REL16_LO
:
11500 // If we are generating a non-PIC executable, edit
11501 // 0: addis 2,12,.TOC.-0b@ha
11502 // addi 2,2,.TOC.-0b@l
11503 // used by ELFv2 global entry points to set up r2, to
11505 // addi 2,2,.TOC.@l
11506 // if .TOC. is in range. */
11508 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11511 && target
->abiversion() >= 2
11512 && !parameters
->options().output_is_position_independent()
11513 && rela
.get_r_addend() == d_offset
+ 4
11515 && strcmp(gsym
->name(), ".TOC.") == 0)
11517 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11518 Reltype
prev_rela(preloc
- reloc_size
);
11519 if ((prev_rela
.get_r_info()
11520 == elfcpp::elf_r_info
<size
>(r_sym
,
11521 elfcpp::R_POWERPC_REL16_HA
))
11522 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11523 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11525 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11526 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11527 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11529 if ((insn1
& 0xffff0000) == addis_2_12
11530 && (insn2
& 0xffff0000) == addi_2_2
)
11532 insn1
= lis_2
+ ha(value
+ address
- 4);
11533 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11534 insn2
= addi_2_2
+ l(value
+ address
- 4);
11535 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11538 relinfo
->rr
->set_strategy(relnum
- 1,
11539 Relocatable_relocs::RELOC_SPECIAL
);
11540 relinfo
->rr
->set_strategy(relnum
,
11541 Relocatable_relocs::RELOC_SPECIAL
);
11551 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11552 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11555 case elfcpp::R_POWERPC_ADDR32
:
11556 case elfcpp::R_POWERPC_UADDR32
:
11558 overflow
= Reloc::CHECK_BITFIELD
;
11561 case elfcpp::R_POWERPC_REL32
:
11562 case elfcpp::R_POWERPC_REL16DX_HA
:
11564 overflow
= Reloc::CHECK_SIGNED
;
11567 case elfcpp::R_POWERPC_UADDR16
:
11568 overflow
= Reloc::CHECK_BITFIELD
;
11571 case elfcpp::R_POWERPC_ADDR16
:
11572 // We really should have three separate relocations,
11573 // one for 16-bit data, one for insns with 16-bit signed fields,
11574 // and one for insns with 16-bit unsigned fields.
11575 overflow
= Reloc::CHECK_BITFIELD
;
11576 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11577 overflow
= Reloc::CHECK_LOW_INSN
;
11580 case elfcpp::R_POWERPC_ADDR16_HI
:
11581 case elfcpp::R_POWERPC_ADDR16_HA
:
11582 case elfcpp::R_POWERPC_GOT16_HI
:
11583 case elfcpp::R_POWERPC_GOT16_HA
:
11584 case elfcpp::R_POWERPC_PLT16_HI
:
11585 case elfcpp::R_POWERPC_PLT16_HA
:
11586 case elfcpp::R_POWERPC_SECTOFF_HI
:
11587 case elfcpp::R_POWERPC_SECTOFF_HA
:
11588 case elfcpp::R_PPC64_TOC16_HI
:
11589 case elfcpp::R_PPC64_TOC16_HA
:
11590 case elfcpp::R_PPC64_PLTGOT16_HI
:
11591 case elfcpp::R_PPC64_PLTGOT16_HA
:
11592 case elfcpp::R_POWERPC_TPREL16_HI
:
11593 case elfcpp::R_POWERPC_TPREL16_HA
:
11594 case elfcpp::R_POWERPC_DTPREL16_HI
:
11595 case elfcpp::R_POWERPC_DTPREL16_HA
:
11596 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11597 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11598 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11599 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11600 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11601 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11602 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11603 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11604 case elfcpp::R_POWERPC_REL16_HI
:
11605 case elfcpp::R_POWERPC_REL16_HA
:
11607 overflow
= Reloc::CHECK_HIGH_INSN
;
11610 case elfcpp::R_POWERPC_REL16
:
11611 case elfcpp::R_PPC64_TOC16
:
11612 case elfcpp::R_POWERPC_GOT16
:
11613 case elfcpp::R_POWERPC_SECTOFF
:
11614 case elfcpp::R_POWERPC_TPREL16
:
11615 case elfcpp::R_POWERPC_DTPREL16
:
11616 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11617 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11618 case elfcpp::R_POWERPC_GOT_TPREL16
:
11619 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11620 overflow
= Reloc::CHECK_LOW_INSN
;
11623 case elfcpp::R_PPC64_REL24_NOTOC
:
11627 case elfcpp::R_POWERPC_ADDR24
:
11628 case elfcpp::R_POWERPC_ADDR14
:
11629 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11630 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11631 case elfcpp::R_PPC64_ADDR16_DS
:
11632 case elfcpp::R_POWERPC_REL24
:
11633 case elfcpp::R_PPC_PLTREL24
:
11634 case elfcpp::R_PPC_LOCAL24PC
:
11635 case elfcpp::R_PPC64_TPREL16_DS
:
11636 case elfcpp::R_PPC64_DTPREL16_DS
:
11637 case elfcpp::R_PPC64_TOC16_DS
:
11638 case elfcpp::R_PPC64_GOT16_DS
:
11639 case elfcpp::R_PPC64_SECTOFF_DS
:
11640 case elfcpp::R_POWERPC_REL14
:
11641 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11642 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11643 case elfcpp::R_PPC64_D34
:
11644 case elfcpp::R_PPC64_PCREL34
:
11645 case elfcpp::R_PPC64_GOT_PCREL34
:
11646 case elfcpp::R_PPC64_PLT_PCREL34
:
11647 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11648 case elfcpp::R_PPC64_D28
:
11649 case elfcpp::R_PPC64_PCREL28
:
11650 case elfcpp::R_PPC64_TPREL34
:
11651 case elfcpp::R_PPC64_DTPREL34
:
11652 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11653 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11654 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11655 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11656 overflow
= Reloc::CHECK_SIGNED
;
11660 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11663 if (overflow
== Reloc::CHECK_LOW_INSN
11664 || overflow
== Reloc::CHECK_HIGH_INSN
)
11666 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11668 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11669 overflow
= Reloc::CHECK_BITFIELD
;
11670 else if (overflow
== Reloc::CHECK_LOW_INSN
11671 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11672 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11673 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11674 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11675 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11676 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11677 overflow
= Reloc::CHECK_UNSIGNED
;
11679 overflow
= Reloc::CHECK_SIGNED
;
11682 bool maybe_dq_reloc
= false;
11683 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11684 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11687 case elfcpp::R_POWERPC_NONE
:
11688 case elfcpp::R_POWERPC_TLS
:
11689 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11690 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11691 case elfcpp::R_POWERPC_PLTSEQ
:
11692 case elfcpp::R_POWERPC_PLTCALL
:
11693 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11694 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11695 case elfcpp::R_PPC64_PCREL_OPT
:
11698 case elfcpp::R_PPC64_ADDR64
:
11699 case elfcpp::R_PPC64_REL64
:
11700 case elfcpp::R_PPC64_TOC
:
11701 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11702 Reloc::addr64(view
, value
);
11705 case elfcpp::R_POWERPC_TPREL
:
11706 case elfcpp::R_POWERPC_DTPREL
:
11708 Reloc::addr64(view
, value
);
11710 status
= Reloc::addr32(view
, value
, overflow
);
11713 case elfcpp::R_PPC64_UADDR64
:
11714 Reloc::addr64_u(view
, value
);
11717 case elfcpp::R_POWERPC_ADDR32
:
11718 status
= Reloc::addr32(view
, value
, overflow
);
11721 case elfcpp::R_POWERPC_REL32
:
11722 case elfcpp::R_POWERPC_UADDR32
:
11723 status
= Reloc::addr32_u(view
, value
, overflow
);
11726 case elfcpp::R_PPC64_REL24_NOTOC
:
11728 goto unsupp
; // R_PPC_EMB_RELSDA
11730 case elfcpp::R_POWERPC_ADDR24
:
11731 case elfcpp::R_POWERPC_REL24
:
11732 case elfcpp::R_PPC_PLTREL24
:
11733 case elfcpp::R_PPC_LOCAL24PC
:
11734 status
= Reloc::addr24(view
, value
, overflow
);
11737 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11738 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11739 case elfcpp::R_POWERPC_GOT_TPREL16
:
11740 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11743 // On ppc64 these are all ds form
11744 maybe_dq_reloc
= true;
11748 case elfcpp::R_POWERPC_ADDR16
:
11749 case elfcpp::R_POWERPC_REL16
:
11750 case elfcpp::R_PPC64_TOC16
:
11751 case elfcpp::R_POWERPC_GOT16
:
11752 case elfcpp::R_POWERPC_SECTOFF
:
11753 case elfcpp::R_POWERPC_TPREL16
:
11754 case elfcpp::R_POWERPC_DTPREL16
:
11755 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11756 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11757 case elfcpp::R_POWERPC_ADDR16_LO
:
11758 case elfcpp::R_POWERPC_REL16_LO
:
11759 case elfcpp::R_PPC64_TOC16_LO
:
11760 case elfcpp::R_POWERPC_GOT16_LO
:
11761 case elfcpp::R_POWERPC_PLT16_LO
:
11762 case elfcpp::R_POWERPC_SECTOFF_LO
:
11763 case elfcpp::R_POWERPC_TPREL16_LO
:
11764 case elfcpp::R_POWERPC_DTPREL16_LO
:
11765 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11766 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11768 status
= Reloc::addr16(view
, value
, overflow
);
11770 maybe_dq_reloc
= true;
11773 case elfcpp::R_POWERPC_UADDR16
:
11774 status
= Reloc::addr16_u(view
, value
, overflow
);
11777 case elfcpp::R_PPC64_ADDR16_HIGH
:
11778 case elfcpp::R_PPC64_TPREL16_HIGH
:
11779 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11781 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11784 case elfcpp::R_POWERPC_ADDR16_HI
:
11785 case elfcpp::R_POWERPC_REL16_HI
:
11786 case elfcpp::R_PPC64_REL16_HIGH
:
11787 case elfcpp::R_PPC64_TOC16_HI
:
11788 case elfcpp::R_POWERPC_GOT16_HI
:
11789 case elfcpp::R_POWERPC_PLT16_HI
:
11790 case elfcpp::R_POWERPC_SECTOFF_HI
:
11791 case elfcpp::R_POWERPC_TPREL16_HI
:
11792 case elfcpp::R_POWERPC_DTPREL16_HI
:
11793 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11794 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11795 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11796 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11797 Reloc::addr16_hi(view
, value
);
11800 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11801 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11802 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11804 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11807 case elfcpp::R_POWERPC_ADDR16_HA
:
11808 case elfcpp::R_POWERPC_REL16_HA
:
11809 case elfcpp::R_PPC64_REL16_HIGHA
:
11810 case elfcpp::R_PPC64_TOC16_HA
:
11811 case elfcpp::R_POWERPC_GOT16_HA
:
11812 case elfcpp::R_POWERPC_PLT16_HA
:
11813 case elfcpp::R_POWERPC_SECTOFF_HA
:
11814 case elfcpp::R_POWERPC_TPREL16_HA
:
11815 case elfcpp::R_POWERPC_DTPREL16_HA
:
11816 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11817 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11818 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11819 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11820 Reloc::addr16_ha(view
, value
);
11823 case elfcpp::R_POWERPC_REL16DX_HA
:
11824 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11827 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11829 // R_PPC_EMB_NADDR16_LO
11832 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11833 case elfcpp::R_PPC64_REL16_HIGHER
:
11834 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11835 Reloc::addr16_hi2(view
, value
);
11838 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11840 // R_PPC_EMB_NADDR16_HI
11843 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11844 case elfcpp::R_PPC64_REL16_HIGHERA
:
11845 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11846 Reloc::addr16_ha2(view
, value
);
11849 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11851 // R_PPC_EMB_NADDR16_HA
11854 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11855 case elfcpp::R_PPC64_REL16_HIGHEST
:
11856 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11857 Reloc::addr16_hi3(view
, value
);
11860 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11862 // R_PPC_EMB_SDAI16
11865 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11866 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11867 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11868 Reloc::addr16_ha3(view
, value
);
11871 case elfcpp::R_PPC64_DTPREL16_DS
:
11872 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11874 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11877 case elfcpp::R_PPC64_TPREL16_DS
:
11878 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11880 // R_PPC_TLSGD, R_PPC_TLSLD
11883 case elfcpp::R_PPC64_ADDR16_DS
:
11884 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11885 case elfcpp::R_PPC64_TOC16_DS
:
11886 case elfcpp::R_PPC64_TOC16_LO_DS
:
11887 case elfcpp::R_PPC64_GOT16_DS
:
11888 case elfcpp::R_PPC64_GOT16_LO_DS
:
11889 case elfcpp::R_PPC64_PLT16_LO_DS
:
11890 case elfcpp::R_PPC64_SECTOFF_DS
:
11891 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11892 maybe_dq_reloc
= true;
11895 case elfcpp::R_POWERPC_ADDR14
:
11896 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11897 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11898 case elfcpp::R_POWERPC_REL14
:
11899 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11900 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11901 status
= Reloc::addr14(view
, value
, overflow
);
11904 case elfcpp::R_POWERPC_COPY
:
11905 case elfcpp::R_POWERPC_GLOB_DAT
:
11906 case elfcpp::R_POWERPC_JMP_SLOT
:
11907 case elfcpp::R_POWERPC_RELATIVE
:
11908 case elfcpp::R_POWERPC_DTPMOD
:
11909 case elfcpp::R_PPC64_JMP_IREL
:
11910 case elfcpp::R_POWERPC_IRELATIVE
:
11911 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11912 _("unexpected reloc %u in object file"),
11916 case elfcpp::R_PPC64_TOCSAVE
:
11922 Symbol_location loc
;
11923 loc
.object
= relinfo
->object
;
11924 loc
.shndx
= relinfo
->data_shndx
;
11925 loc
.offset
= rela
.get_r_offset();
11926 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11927 if (p
!= target
->tocsave_loc().end())
11929 // If we've generated plt calls using this tocsave, then
11930 // the nop needs to be changed to save r2.
11931 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11932 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11933 elfcpp::Swap
<32, big_endian
>::
11934 writeval(iview
, std_2_1
+ target
->stk_toc());
11939 case elfcpp::R_PPC_EMB_SDA2I16
:
11940 case elfcpp::R_PPC_EMB_SDA2REL
:
11943 // R_PPC64_TLSGD, R_PPC64_TLSLD
11946 case elfcpp::R_PPC64_D34
:
11947 case elfcpp::R_PPC64_D34_LO
:
11948 case elfcpp::R_PPC64_PCREL34
:
11949 case elfcpp::R_PPC64_GOT_PCREL34
:
11950 case elfcpp::R_PPC64_PLT_PCREL34
:
11951 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11952 case elfcpp::R_PPC64_TPREL34
:
11953 case elfcpp::R_PPC64_DTPREL34
:
11954 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11955 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11956 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11957 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11960 status
= Reloc::addr34(view
, value
, overflow
);
11963 case elfcpp::R_PPC64_D34_HI30
:
11966 Reloc::addr34_hi(view
, value
);
11969 case elfcpp::R_PPC64_D34_HA30
:
11972 Reloc::addr34_ha(view
, value
);
11975 case elfcpp::R_PPC64_D28
:
11976 case elfcpp::R_PPC64_PCREL28
:
11979 status
= Reloc::addr28(view
, value
, overflow
);
11982 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11983 case elfcpp::R_PPC64_REL16_HIGHER34
:
11986 Reloc::addr16_higher34(view
, value
);
11989 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11990 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11993 Reloc::addr16_highera34(view
, value
);
11996 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11997 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12000 Reloc::addr16_highest34(view
, value
);
12003 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12004 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12007 Reloc::addr16_highesta34(view
, value
);
12010 case elfcpp::R_POWERPC_PLT32
:
12011 case elfcpp::R_POWERPC_PLTREL32
:
12012 case elfcpp::R_PPC_SDAREL16
:
12013 case elfcpp::R_POWERPC_ADDR30
:
12014 case elfcpp::R_PPC64_PLT64
:
12015 case elfcpp::R_PPC64_PLTREL64
:
12016 case elfcpp::R_PPC64_PLTGOT16
:
12017 case elfcpp::R_PPC64_PLTGOT16_LO
:
12018 case elfcpp::R_PPC64_PLTGOT16_HI
:
12019 case elfcpp::R_PPC64_PLTGOT16_HA
:
12020 case elfcpp::R_PPC64_PLTGOT16_DS
:
12021 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12022 case elfcpp::R_PPC_TOC16
:
12025 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12026 _("unsupported reloc %u"),
12031 if (maybe_dq_reloc
)
12034 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12036 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12037 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12038 && (insn
& 3) == 1))
12039 status
= Reloc::addr16_dq(view
, value
, overflow
);
12040 else if (size
== 64
12041 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12042 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12043 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12044 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12045 status
= Reloc::addr16_ds(view
, value
, overflow
);
12047 status
= Reloc::addr16(view
, value
, overflow
);
12050 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12053 && gsym
->is_undefined()
12054 && is_branch_reloc
<size
>(r_type
))))
12056 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12057 _("relocation overflow"));
12058 if (has_stub_value
)
12059 gold_info(_("try relinking with a smaller --stub-group-size"));
12065 // Relocate section data.
12067 template<int size
, bool big_endian
>
12069 Target_powerpc
<size
, big_endian
>::relocate_section(
12070 const Relocate_info
<size
, big_endian
>* relinfo
,
12071 unsigned int sh_type
,
12072 const unsigned char* prelocs
,
12073 size_t reloc_count
,
12074 Output_section
* output_section
,
12075 bool needs_special_offset_handling
,
12076 unsigned char* view
,
12078 section_size_type view_size
,
12079 const Reloc_symbol_changes
* reloc_symbol_changes
)
12081 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12082 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12083 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12084 Powerpc_comdat_behavior
;
12085 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12088 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12090 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12091 Powerpc_comdat_behavior
, Classify_reloc
>(
12097 needs_special_offset_handling
,
12101 reloc_symbol_changes
);
12104 template<int size
, bool big_endian
>
12105 class Powerpc_scan_relocatable_reloc
12108 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12109 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12110 static const int sh_type
= elfcpp::SHT_RELA
;
12112 // Return the symbol referred to by the relocation.
12113 static inline unsigned int
12114 get_r_sym(const Reltype
* reloc
)
12115 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12117 // Return the type of the relocation.
12118 static inline unsigned int
12119 get_r_type(const Reltype
* reloc
)
12120 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12122 // Return the strategy to use for a local symbol which is not a
12123 // section symbol, given the relocation type.
12124 inline Relocatable_relocs::Reloc_strategy
12125 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12127 if (r_type
== 0 && r_sym
== 0)
12128 return Relocatable_relocs::RELOC_DISCARD
;
12129 return Relocatable_relocs::RELOC_COPY
;
12132 // Return the strategy to use for a local symbol which is a section
12133 // symbol, given the relocation type.
12134 inline Relocatable_relocs::Reloc_strategy
12135 local_section_strategy(unsigned int, Relobj
*)
12137 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12140 // Return the strategy to use for a global symbol, given the
12141 // relocation type, the object, and the symbol index.
12142 inline Relocatable_relocs::Reloc_strategy
12143 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12146 && (r_type
== elfcpp::R_PPC_PLTREL24
12147 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12148 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12149 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12150 return Relocatable_relocs::RELOC_SPECIAL
;
12151 return Relocatable_relocs::RELOC_COPY
;
12155 // Scan the relocs during a relocatable link.
12157 template<int size
, bool big_endian
>
12159 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12160 Symbol_table
* symtab
,
12162 Sized_relobj_file
<size
, big_endian
>* object
,
12163 unsigned int data_shndx
,
12164 unsigned int sh_type
,
12165 const unsigned char* prelocs
,
12166 size_t reloc_count
,
12167 Output_section
* output_section
,
12168 bool needs_special_offset_handling
,
12169 size_t local_symbol_count
,
12170 const unsigned char* plocal_symbols
,
12171 Relocatable_relocs
* rr
)
12173 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12175 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12177 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12185 needs_special_offset_handling
,
12186 local_symbol_count
,
12191 // Scan the relocs for --emit-relocs.
12193 template<int size
, bool big_endian
>
12195 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12196 Symbol_table
* symtab
,
12198 Sized_relobj_file
<size
, big_endian
>* object
,
12199 unsigned int data_shndx
,
12200 unsigned int sh_type
,
12201 const unsigned char* prelocs
,
12202 size_t reloc_count
,
12203 Output_section
* output_section
,
12204 bool needs_special_offset_handling
,
12205 size_t local_symbol_count
,
12206 const unsigned char* plocal_syms
,
12207 Relocatable_relocs
* rr
)
12209 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12211 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12212 Emit_relocs_strategy
;
12214 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12216 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12224 needs_special_offset_handling
,
12225 local_symbol_count
,
12230 // Emit relocations for a section.
12231 // This is a modified version of the function by the same name in
12232 // target-reloc.h. Using relocate_special_relocatable for
12233 // R_PPC_PLTREL24 would require duplication of the entire body of the
12234 // loop, so we may as well duplicate the whole thing.
12236 template<int size
, bool big_endian
>
12238 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12239 const Relocate_info
<size
, big_endian
>* relinfo
,
12240 unsigned int sh_type
,
12241 const unsigned char* prelocs
,
12242 size_t reloc_count
,
12243 Output_section
* output_section
,
12244 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12246 Address view_address
,
12248 unsigned char* reloc_view
,
12249 section_size_type reloc_view_size
)
12251 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12253 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12254 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12255 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12256 // Offset from start of insn to d-field reloc.
12257 const int d_offset
= big_endian
? 2 : 0;
12259 Powerpc_relobj
<size
, big_endian
>* const object
12260 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12261 const unsigned int local_count
= object
->local_symbol_count();
12262 unsigned int got2_shndx
= object
->got2_shndx();
12263 Address got2_addend
= 0;
12264 if (got2_shndx
!= 0)
12266 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12267 gold_assert(got2_addend
!= invalid_address
);
12270 const bool relocatable
= parameters
->options().relocatable();
12272 unsigned char* pwrite
= reloc_view
;
12273 bool zap_next
= false;
12274 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12276 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12277 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12280 Reltype
reloc(prelocs
);
12281 Reltype_write
reloc_write(pwrite
);
12283 Address offset
= reloc
.get_r_offset();
12284 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12285 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12286 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12287 const unsigned int orig_r_sym
= r_sym
;
12288 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12289 = reloc
.get_r_addend();
12290 const Symbol
* gsym
= NULL
;
12294 // We could arrange to discard these and other relocs for
12295 // tls optimised sequences in the strategy methods, but for
12296 // now do as BFD ld does.
12297 r_type
= elfcpp::R_POWERPC_NONE
;
12301 // Get the new symbol index.
12302 Output_section
* os
= NULL
;
12303 if (r_sym
< local_count
)
12307 case Relocatable_relocs::RELOC_COPY
:
12308 case Relocatable_relocs::RELOC_SPECIAL
:
12311 r_sym
= object
->symtab_index(r_sym
);
12312 gold_assert(r_sym
!= -1U);
12316 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12318 // We are adjusting a section symbol. We need to find
12319 // the symbol table index of the section symbol for
12320 // the output section corresponding to input section
12321 // in which this symbol is defined.
12322 gold_assert(r_sym
< local_count
);
12324 unsigned int shndx
=
12325 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12326 gold_assert(is_ordinary
);
12327 os
= object
->output_section(shndx
);
12328 gold_assert(os
!= NULL
);
12329 gold_assert(os
->needs_symtab_index());
12330 r_sym
= os
->symtab_index();
12335 gold_unreachable();
12340 gsym
= object
->global_symbol(r_sym
);
12341 gold_assert(gsym
!= NULL
);
12342 if (gsym
->is_forwarder())
12343 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12345 gold_assert(gsym
->has_symtab_index());
12346 r_sym
= gsym
->symtab_index();
12349 // Get the new offset--the location in the output section where
12350 // this relocation should be applied.
12351 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12352 offset
+= offset_in_output_section
;
12355 section_offset_type sot_offset
=
12356 convert_types
<section_offset_type
, Address
>(offset
);
12357 section_offset_type new_sot_offset
=
12358 output_section
->output_offset(object
, relinfo
->data_shndx
,
12360 gold_assert(new_sot_offset
!= -1);
12361 offset
= new_sot_offset
;
12364 // In an object file, r_offset is an offset within the section.
12365 // In an executable or dynamic object, generated by
12366 // --emit-relocs, r_offset is an absolute address.
12369 offset
+= view_address
;
12370 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12371 offset
-= offset_in_output_section
;
12374 // Handle the reloc addend based on the strategy.
12375 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12377 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12379 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12380 addend
= psymval
->value(object
, addend
);
12381 // In a relocatable link, the symbol value is relative to
12382 // the start of the output section. For a non-relocatable
12383 // link, we need to adjust the addend.
12386 gold_assert(os
!= NULL
);
12387 addend
-= os
->address();
12390 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12394 if (addend
>= 32768)
12395 addend
+= got2_addend
;
12397 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12399 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12400 addend
-= d_offset
;
12402 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12404 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12405 addend
-= d_offset
+ 4;
12409 gold_unreachable();
12413 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12414 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12415 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12416 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12418 // First instruction of a global dynamic sequence,
12420 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12421 switch (this->optimize_tls_gd(final
))
12423 case tls::TLSOPT_TO_IE
:
12424 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12425 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12427 case tls::TLSOPT_TO_LE
:
12428 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12429 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12430 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12433 r_type
= elfcpp::R_POWERPC_NONE
;
12434 offset
-= d_offset
;
12441 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12442 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12443 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12444 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12446 // First instruction of a local dynamic sequence,
12448 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12450 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12451 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12453 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12454 const Output_section
* os
= relinfo
->layout
->tls_segment()
12456 gold_assert(os
!= NULL
);
12457 gold_assert(os
->needs_symtab_index());
12458 r_sym
= os
->symtab_index();
12459 addend
= dtp_offset
;
12463 r_type
= elfcpp::R_POWERPC_NONE
;
12464 offset
-= d_offset
;
12468 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12469 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12470 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12471 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12473 // First instruction of initial exec sequence.
12474 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12475 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12477 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12478 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12479 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12482 r_type
= elfcpp::R_POWERPC_NONE
;
12483 offset
-= d_offset
;
12487 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12488 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12490 // Second instruction of a global dynamic sequence,
12491 // the __tls_get_addr call
12492 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12493 switch (this->optimize_tls_gd(final
))
12495 case tls::TLSOPT_TO_IE
:
12496 r_type
= elfcpp::R_POWERPC_NONE
;
12499 case tls::TLSOPT_TO_LE
:
12500 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12501 offset
+= d_offset
;
12508 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12509 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12511 // Second instruction of a local dynamic sequence,
12512 // the __tls_get_addr call
12513 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12515 const Output_section
* os
= relinfo
->layout
->tls_segment()
12517 gold_assert(os
!= NULL
);
12518 gold_assert(os
->needs_symtab_index());
12519 r_sym
= os
->symtab_index();
12520 addend
= dtp_offset
;
12521 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12522 offset
+= d_offset
;
12526 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12528 // Second instruction of an initial exec sequence
12529 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12530 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12532 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12533 offset
+= d_offset
;
12538 reloc_write
.put_r_offset(offset
);
12539 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12540 reloc_write
.put_r_addend(addend
);
12542 pwrite
+= reloc_size
;
12545 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12546 == reloc_view_size
);
12549 // Return the value to use for a dynamic symbol which requires special
12550 // treatment. This is how we support equality comparisons of function
12551 // pointers across shared library boundaries, as described in the
12552 // processor specific ABI supplement.
12554 template<int size
, bool big_endian
>
12556 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12560 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12561 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12562 p
!= this->stub_tables_
.end();
12565 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12566 = (*p
)->find_plt_call_entry(gsym
);
12568 return (*p
)->stub_address() + ent
->off_
;
12571 else if (this->abiversion() >= 2)
12573 Address off
= this->glink_section()->find_global_entry(gsym
);
12574 if (off
!= invalid_address
)
12575 return this->glink_section()->global_entry_address() + off
;
12577 gold_unreachable();
12580 // Return the PLT address to use for a local symbol.
12581 template<int size
, bool big_endian
>
12583 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12584 const Relobj
* object
,
12585 unsigned int symndx
) const
12589 const Sized_relobj
<size
, big_endian
>* relobj
12590 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12591 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12592 p
!= this->stub_tables_
.end();
12595 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12596 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12598 return (*p
)->stub_address() + ent
->off_
;
12601 gold_unreachable();
12604 // Return the PLT address to use for a global symbol.
12605 template<int size
, bool big_endian
>
12607 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12608 const Symbol
* gsym
) const
12612 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12613 p
!= this->stub_tables_
.end();
12616 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12617 = (*p
)->find_plt_call_entry(gsym
);
12619 return (*p
)->stub_address() + ent
->off_
;
12622 else if (this->abiversion() >= 2)
12624 Address off
= this->glink_section()->find_global_entry(gsym
);
12625 if (off
!= invalid_address
)
12626 return this->glink_section()->global_entry_address() + off
;
12628 gold_unreachable();
12631 // Return the offset to use for the GOT_INDX'th got entry which is
12632 // for a local tls symbol specified by OBJECT, SYMNDX.
12633 template<int size
, bool big_endian
>
12635 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12636 const Relobj
* object
,
12637 unsigned int symndx
,
12638 unsigned int got_indx
) const
12640 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12641 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12642 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12644 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12645 got_type
<= GOT_TYPE_TPREL
;
12646 got_type
= Got_type(got_type
+ 1))
12647 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12649 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12650 if (got_type
== GOT_TYPE_TLSGD
)
12652 if (off
== got_indx
* (size
/ 8))
12654 if (got_type
== GOT_TYPE_TPREL
)
12657 return -dtp_offset
;
12661 gold_unreachable();
12664 // Return the offset to use for the GOT_INDX'th got entry which is
12665 // for global tls symbol GSYM.
12666 template<int size
, bool big_endian
>
12668 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12670 unsigned int got_indx
) const
12672 if (gsym
->type() == elfcpp::STT_TLS
)
12674 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12675 got_type
<= GOT_TYPE_TPREL
;
12676 got_type
= Got_type(got_type
+ 1))
12677 if (gsym
->has_got_offset(got_type
))
12679 unsigned int off
= gsym
->got_offset(got_type
);
12680 if (got_type
== GOT_TYPE_TLSGD
)
12682 if (off
== got_indx
* (size
/ 8))
12684 if (got_type
== GOT_TYPE_TPREL
)
12687 return -dtp_offset
;
12691 gold_unreachable();
12694 // The selector for powerpc object files.
12696 template<int size
, bool big_endian
>
12697 class Target_selector_powerpc
: public Target_selector
12700 Target_selector_powerpc()
12701 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12704 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12705 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12707 ? (big_endian
? "elf64ppc" : "elf64lppc")
12708 : (big_endian
? "elf32ppc" : "elf32lppc")))
12712 do_instantiate_target()
12713 { return new Target_powerpc
<size
, big_endian
>(); }
12716 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12717 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12718 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12719 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12721 // Instantiate these constants for -O0
12722 template<int size
, bool big_endian
>
12723 const typename Output_data_glink
<size
, big_endian
>::Address
12724 Output_data_glink
<size
, big_endian
>::invalid_address
;
12725 template<int size
, bool big_endian
>
12726 const typename Stub_table
<size
, big_endian
>::Address
12727 Stub_table
<size
, big_endian
>::invalid_address
;
12728 template<int size
, bool big_endian
>
12729 const typename Target_powerpc
<size
, big_endian
>::Address
12730 Target_powerpc
<size
, big_endian
>::invalid_address
;
12732 } // End anonymous namespace.