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_stubs_(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 power10_stubs() const
1084 { return this->power10_stubs_
; }
1089 if (parameters
->options().power10_stubs_enum()
1090 != General_options::POWER10_STUBS_NO
)
1091 this->power10_stubs_
= true;
1095 power10_stubs_auto() const
1097 return (parameters
->options().power10_stubs_enum()
1098 == General_options::POWER10_STUBS_AUTO
);
1102 plt_thread_safe() const
1103 { return this->plt_thread_safe_
; }
1106 plt_localentry0() const
1107 { return this->plt_localentry0_
; }
1110 set_has_localentry0()
1112 this->has_localentry0_
= true;
1116 is_elfv2_localentry0(const Symbol
* gsym
) const
1119 && this->abiversion() >= 2
1120 && this->plt_localentry0()
1121 && gsym
->type() == elfcpp::STT_FUNC
1122 && gsym
->is_defined()
1123 && gsym
->nonvis() >> 3 == 0
1124 && !gsym
->non_zero_localentry());
1128 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1129 unsigned int r_sym
) const
1131 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1132 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1135 && this->abiversion() >= 2
1136 && this->plt_localentry0()
1137 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1139 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1141 if (!psymval
->is_ifunc_symbol()
1142 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1151 { return this->tprel_opt_
; }
1154 set_tprel_opt(bool val
)
1155 { this->tprel_opt_
= val
; }
1157 // Remember any symbols seen with non-zero localentry, even those
1158 // not providing a definition
1160 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1165 unsigned char st_other
= sym
.get_st_other();
1166 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1167 to
->set_non_zero_localentry();
1169 // We haven't resolved anything, continue normal processing.
1175 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1178 set_abiversion(int ver
)
1180 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1181 flags
&= ~elfcpp::EF_PPC64_ABI
;
1182 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1183 this->set_processor_specific_flags(flags
);
1187 tls_get_addr_opt() const
1188 { return this->tls_get_addr_opt_
; }
1191 tls_get_addr() const
1192 { return this->tls_get_addr_
; }
1194 // If optimizing __tls_get_addr calls, whether this is the
1195 // "__tls_get_addr" symbol.
1197 is_tls_get_addr_opt(const Symbol
* gsym
) const
1199 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1200 || gsym
== this->tls_get_addr_opt_
);
1204 replace_tls_get_addr(const Symbol
* gsym
) const
1205 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1208 set_has_tls_get_addr_opt()
1209 { this->has_tls_get_addr_opt_
= true; }
1211 // Offset to toc save stack slot
1214 { return this->abiversion() < 2 ? 40 : 24; }
1216 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1217 // so use the CR save slot. Used only by __tls_get_addr call stub,
1218 // relying on __tls_get_addr not saving CR itself.
1221 { return this->abiversion() < 2 ? 32 : 8; }
1223 // Merge object attributes from input object with those in the output.
1225 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1241 : tls_get_addr_state_(NOT_EXPECTED
),
1242 relinfo_(NULL
), relnum_(0), r_offset_(0)
1247 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1254 if (this->relinfo_
!= NULL
)
1255 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1256 _("missing expected __tls_get_addr call"));
1260 expect_tls_get_addr_call(
1261 const Relocate_info
<size
, big_endian
>* relinfo
,
1265 this->tls_get_addr_state_
= EXPECTED
;
1266 this->relinfo_
= relinfo
;
1267 this->relnum_
= relnum
;
1268 this->r_offset_
= r_offset
;
1272 expect_tls_get_addr_call()
1273 { this->tls_get_addr_state_
= EXPECTED
; }
1276 skip_next_tls_get_addr_call()
1277 {this->tls_get_addr_state_
= SKIP
; }
1280 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1281 unsigned int r_type
, const Symbol
* gsym
)
1284 = ((r_type
== elfcpp::R_POWERPC_REL24
1285 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1286 || r_type
== elfcpp::R_PPC_PLTREL24
1287 || is_plt16_reloc
<size
>(r_type
)
1288 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1289 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1290 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1291 || r_type
== elfcpp::R_POWERPC_PLTCALL
1292 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1293 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1295 && (gsym
== target
->tls_get_addr()
1296 || gsym
== target
->tls_get_addr_opt()));
1297 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1298 this->tls_get_addr_state_
= NOT_EXPECTED
;
1299 if (is_tls_call
&& last_tls
!= EXPECTED
)
1301 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1310 // What we're up to regarding calls to __tls_get_addr.
1311 // On powerpc, the branch and link insn making a call to
1312 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1313 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1314 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1315 // The marker relocation always comes first, and has the same
1316 // symbol as the reloc on the insn setting up the __tls_get_addr
1317 // argument. This ties the arg setup insn with the call insn,
1318 // allowing ld to safely optimize away the call. We check that
1319 // every call to __tls_get_addr has a marker relocation, and that
1320 // every marker relocation is on a call to __tls_get_addr.
1321 Tls_get_addr tls_get_addr_state_
;
1322 // Info about the last reloc for error message.
1323 const Relocate_info
<size
, big_endian
>* relinfo_
;
1328 // The class which scans relocations.
1329 class Scan
: protected Track_tls
1332 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1335 : Track_tls(), issued_non_pic_error_(false)
1339 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1342 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1343 Sized_relobj_file
<size
, big_endian
>* object
,
1344 unsigned int data_shndx
,
1345 Output_section
* output_section
,
1346 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1347 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1351 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1352 Sized_relobj_file
<size
, big_endian
>* object
,
1353 unsigned int data_shndx
,
1354 Output_section
* output_section
,
1355 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1359 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1361 Sized_relobj_file
<size
, big_endian
>* relobj
,
1364 const elfcpp::Rela
<size
, big_endian
>& ,
1365 unsigned int r_type
,
1366 const elfcpp::Sym
<size
, big_endian
>&)
1368 // PowerPC64 .opd is not folded, so any identical function text
1369 // may be folded and we'll still keep function addresses distinct.
1370 // That means no reloc is of concern here.
1373 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1374 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1375 if (ppcobj
->abiversion() == 1)
1378 // For 32-bit and ELFv2, conservatively assume anything but calls to
1379 // function code might be taking the address of the function.
1380 return !is_branch_reloc
<size
>(r_type
);
1384 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1386 Sized_relobj_file
<size
, big_endian
>* relobj
,
1389 const elfcpp::Rela
<size
, big_endian
>& ,
1390 unsigned int r_type
,
1396 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1397 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1398 if (ppcobj
->abiversion() == 1)
1401 return !is_branch_reloc
<size
>(r_type
);
1405 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1406 Sized_relobj_file
<size
, big_endian
>* object
,
1407 unsigned int r_type
, bool report_err
);
1411 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1412 unsigned int r_type
);
1415 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1416 unsigned int r_type
, Symbol
*);
1419 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1420 Target_powerpc
* target
);
1423 check_non_pic(Relobj
*, unsigned int r_type
);
1425 // Whether we have issued an error about a non-PIC compilation.
1426 bool issued_non_pic_error_
;
1430 symval_for_branch(const Symbol_table
* symtab
,
1431 const Sized_symbol
<size
>* gsym
,
1432 Powerpc_relobj
<size
, big_endian
>* object
,
1433 Address
*value
, unsigned int *dest_shndx
);
1435 // The class which implements relocation.
1436 class Relocate
: protected Track_tls
1439 // Use 'at' branch hints when true, 'y' when false.
1440 // FIXME maybe: set this with an option.
1441 static const bool is_isa_v2
= true;
1447 // Do a relocation. Return false if the caller should not issue
1448 // any warnings about this relocation.
1450 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1451 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1452 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1453 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1457 class Relocate_comdat_behavior
1460 // Decide what the linker should do for relocations that refer to
1461 // discarded comdat sections.
1462 inline Comdat_behavior
1463 get(const char* name
)
1465 gold::Default_comdat_behavior default_behavior
;
1466 Comdat_behavior ret
= default_behavior
.get(name
);
1467 if (ret
== CB_ERROR
)
1470 && (strcmp(name
, ".fixup") == 0
1471 || strcmp(name
, ".got2") == 0))
1474 && (strcmp(name
, ".opd") == 0
1475 || strcmp(name
, ".toc") == 0
1476 || strcmp(name
, ".toc1") == 0))
1483 // Optimize the TLS relocation type based on what we know about the
1484 // symbol. IS_FINAL is true if the final address of this symbol is
1485 // known at link time.
1487 tls::Tls_optimization
1488 optimize_tls_gd(bool is_final
)
1490 // If we are generating a shared library, then we can't do anything
1492 if (parameters
->options().shared()
1493 || !parameters
->options().tls_optimize())
1494 return tls::TLSOPT_NONE
;
1497 return tls::TLSOPT_TO_IE
;
1498 return tls::TLSOPT_TO_LE
;
1501 tls::Tls_optimization
1504 if (parameters
->options().shared()
1505 || !parameters
->options().tls_optimize())
1506 return tls::TLSOPT_NONE
;
1508 return tls::TLSOPT_TO_LE
;
1511 tls::Tls_optimization
1512 optimize_tls_ie(bool is_final
)
1515 || parameters
->options().shared()
1516 || !parameters
->options().tls_optimize())
1517 return tls::TLSOPT_NONE
;
1519 return tls::TLSOPT_TO_LE
;
1524 make_glink_section(Layout
*);
1526 // Create the PLT section.
1528 make_plt_section(Symbol_table
*, Layout
*);
1531 make_iplt_section(Symbol_table
*, Layout
*);
1534 make_lplt_section(Layout
*);
1537 make_brlt_section(Layout
*);
1539 // Create a PLT entry for a global symbol.
1541 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1543 // Create a PLT entry for a local IFUNC symbol.
1545 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1546 Sized_relobj_file
<size
, big_endian
>*,
1549 // Create a PLT entry for a local non-IFUNC symbol.
1551 make_local_plt_entry(Layout
*,
1552 Sized_relobj_file
<size
, big_endian
>*,
1556 // Create a GOT entry for local dynamic __tls_get_addr.
1558 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1559 Sized_relobj_file
<size
, big_endian
>* object
);
1562 tlsld_got_offset() const
1564 return this->tlsld_got_offset_
;
1567 // Get the dynamic reloc section, creating it if necessary.
1569 rela_dyn_section(Layout
*);
1571 // Similarly, but for ifunc symbols get the one for ifunc.
1573 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1575 // Copy a relocation against a global symbol.
1577 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1578 Sized_relobj_file
<size
, big_endian
>* object
,
1579 unsigned int shndx
, Output_section
* output_section
,
1580 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1582 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1583 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1584 symtab
->get_sized_symbol
<size
>(sym
),
1585 object
, shndx
, output_section
,
1586 r_type
, reloc
.get_r_offset(),
1587 reloc
.get_r_addend(),
1588 this->rela_dyn_section(layout
));
1591 // Look over all the input sections, deciding where to place stubs.
1593 group_sections(Layout
*, const Task
*, bool);
1595 // Sort output sections by address.
1596 struct Sort_sections
1599 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1600 { return sec1
->address() < sec2
->address(); }
1606 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1607 unsigned int data_shndx
,
1609 unsigned int r_type
,
1612 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1613 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1619 // Return whether this branch is going via a plt call stub, and if
1620 // so, mark it as having an R_PPC64_TOCSAVE.
1622 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1623 unsigned int shndx
, Address offset
,
1624 Target_powerpc
* target
, Symbol_table
* symtab
);
1626 // If this branch needs a plt call stub, or a long branch stub, make one.
1628 make_stub(Stub_table
<size
, big_endian
>*,
1629 Stub_table
<size
, big_endian
>*,
1630 Symbol_table
*) const;
1633 // The branch location..
1634 Powerpc_relobj
<size
, big_endian
>* object_
;
1635 unsigned int shndx_
;
1637 // ..and the branch type and destination.
1638 unsigned int r_type_
: 31;
1639 unsigned int tocsave_
: 1;
1640 unsigned int r_sym_
;
1644 // Information about this specific target which we pass to the
1645 // general Target structure.
1646 static Target::Target_info powerpc_info
;
1648 // The types of GOT entries needed for this platform.
1649 // These values are exposed to the ABI in an incremental link.
1650 // Do not renumber existing values without changing the version
1651 // number of the .gnu_incremental_inputs section.
1655 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1656 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1657 GOT_TYPE_TPREL
// entry for @got@tprel
1661 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1662 // The PLT section. This is a container for a table of addresses,
1663 // and their relocations. Each address in the PLT has a dynamic
1664 // relocation (R_*_JMP_SLOT) and each address will have a
1665 // corresponding entry in .glink for lazy resolution of the PLT.
1666 // ppc32 initialises the PLT to point at the .glink entry, while
1667 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1668 // linker adds a stub that loads the PLT entry into ctr then
1669 // branches to ctr. There may be more than one stub for each PLT
1670 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1671 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1672 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1673 // The IPLT section. Like plt_, this is a container for a table of
1674 // addresses and their relocations, specifically for STT_GNU_IFUNC
1675 // functions that resolve locally (STT_GNU_IFUNC functions that
1676 // don't resolve locally go in PLT). Unlike plt_, these have no
1677 // entry in .glink for lazy resolution, and the relocation section
1678 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1679 // the relocation section may contain relocations against
1680 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1681 // relocation section will appear at the end of other dynamic
1682 // relocations, so that ld.so applies these relocations after other
1683 // dynamic relocations. In a static executable, the relocation
1684 // section is emitted and marked with __rela_iplt_start and
1685 // __rela_iplt_end symbols.
1686 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1687 // A PLT style section for local, non-ifunc symbols
1688 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1689 // Section holding long branch destinations.
1690 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1691 // The .glink section.
1692 Output_data_glink
<size
, big_endian
>* glink_
;
1693 // The dynamic reloc section.
1694 Reloc_section
* rela_dyn_
;
1695 // Relocs saved to avoid a COPY reloc.
1696 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1697 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1698 unsigned int tlsld_got_offset_
;
1700 Stub_tables stub_tables_
;
1701 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1702 Branch_lookup_table branch_lookup_table_
;
1704 typedef std::vector
<Branch_info
> Branches
;
1705 Branches branch_info_
;
1706 Tocsave_loc tocsave_loc_
;
1708 bool power10_stubs_
;
1709 bool plt_thread_safe_
;
1710 bool plt_localentry0_
;
1711 bool plt_localentry0_init_
;
1712 bool has_localentry0_
;
1713 bool has_tls_get_addr_opt_
;
1717 int relax_fail_count_
;
1718 int32_t stub_group_size_
;
1720 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1722 // The "__tls_get_addr" symbol, if present
1723 Symbol
* tls_get_addr_
;
1724 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1725 Symbol
* tls_get_addr_opt_
;
1727 // Attributes in output.
1728 Attributes_section_data
* attributes_section_data_
;
1730 // Last input file to change various attribute tags
1731 const char* last_fp_
;
1732 const char* last_ld_
;
1733 const char* last_vec_
;
1734 const char* last_struct_
;
1738 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1741 true, // is_big_endian
1742 elfcpp::EM_PPC
, // machine_code
1743 false, // has_make_symbol
1744 false, // has_resolve
1745 false, // has_code_fill
1746 true, // is_default_stack_executable
1747 false, // can_icf_inline_merge_sections
1749 "/usr/lib/ld.so.1", // dynamic_linker
1750 0x10000000, // default_text_segment_address
1751 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1752 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1753 false, // isolate_execinstr
1755 elfcpp::SHN_UNDEF
, // small_common_shndx
1756 elfcpp::SHN_UNDEF
, // large_common_shndx
1757 0, // small_common_section_flags
1758 0, // large_common_section_flags
1759 NULL
, // attributes_section
1760 NULL
, // attributes_vendor
1761 "_start", // entry_symbol_name
1762 32, // hash_entry_size
1763 elfcpp::SHT_PROGBITS
, // unwind_section_type
1767 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1770 false, // is_big_endian
1771 elfcpp::EM_PPC
, // machine_code
1772 false, // has_make_symbol
1773 false, // has_resolve
1774 false, // has_code_fill
1775 true, // is_default_stack_executable
1776 false, // can_icf_inline_merge_sections
1778 "/usr/lib/ld.so.1", // dynamic_linker
1779 0x10000000, // default_text_segment_address
1780 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1781 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1782 false, // isolate_execinstr
1784 elfcpp::SHN_UNDEF
, // small_common_shndx
1785 elfcpp::SHN_UNDEF
, // large_common_shndx
1786 0, // small_common_section_flags
1787 0, // large_common_section_flags
1788 NULL
, // attributes_section
1789 NULL
, // attributes_vendor
1790 "_start", // entry_symbol_name
1791 32, // hash_entry_size
1792 elfcpp::SHT_PROGBITS
, // unwind_section_type
1796 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1799 true, // is_big_endian
1800 elfcpp::EM_PPC64
, // machine_code
1801 false, // has_make_symbol
1802 true, // has_resolve
1803 false, // has_code_fill
1804 false, // is_default_stack_executable
1805 false, // can_icf_inline_merge_sections
1807 "/usr/lib/ld.so.1", // dynamic_linker
1808 0x10000000, // default_text_segment_address
1809 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1810 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1811 false, // isolate_execinstr
1813 elfcpp::SHN_UNDEF
, // small_common_shndx
1814 elfcpp::SHN_UNDEF
, // large_common_shndx
1815 0, // small_common_section_flags
1816 0, // large_common_section_flags
1817 NULL
, // attributes_section
1818 NULL
, // attributes_vendor
1819 "_start", // entry_symbol_name
1820 32, // hash_entry_size
1821 elfcpp::SHT_PROGBITS
, // unwind_section_type
1825 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1828 false, // is_big_endian
1829 elfcpp::EM_PPC64
, // machine_code
1830 false, // has_make_symbol
1831 true, // has_resolve
1832 false, // has_code_fill
1833 false, // is_default_stack_executable
1834 false, // can_icf_inline_merge_sections
1836 "/usr/lib/ld.so.1", // dynamic_linker
1837 0x10000000, // default_text_segment_address
1838 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1839 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1840 false, // isolate_execinstr
1842 elfcpp::SHN_UNDEF
, // small_common_shndx
1843 elfcpp::SHN_UNDEF
, // large_common_shndx
1844 0, // small_common_section_flags
1845 0, // large_common_section_flags
1846 NULL
, // attributes_section
1847 NULL
, // attributes_vendor
1848 "_start", // entry_symbol_name
1849 32, // hash_entry_size
1850 elfcpp::SHT_PROGBITS
, // unwind_section_type
1855 is_branch_reloc(unsigned int r_type
)
1857 return (r_type
== elfcpp::R_POWERPC_REL24
1858 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1859 || r_type
== elfcpp::R_PPC_PLTREL24
1860 || r_type
== elfcpp::R_PPC_LOCAL24PC
1861 || r_type
== elfcpp::R_POWERPC_REL14
1862 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1863 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1864 || r_type
== elfcpp::R_POWERPC_ADDR24
1865 || r_type
== elfcpp::R_POWERPC_ADDR14
1866 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1867 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1870 // Reloc resolves to plt entry.
1873 is_plt16_reloc(unsigned int r_type
)
1875 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1876 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1877 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1878 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1881 // If INSN is an opcode that may be used with an @tls operand, return
1882 // the transformed insn for TLS optimisation, otherwise return 0. If
1883 // REG is non-zero only match an insn with RB or RA equal to REG.
1885 at_tls_transform(uint32_t insn
, unsigned int reg
)
1887 if ((insn
& (0x3f << 26)) != 31 << 26)
1891 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1892 rtra
= insn
& ((1 << 26) - (1 << 16));
1893 else if (((insn
>> 16) & 0x1f) == reg
)
1894 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1898 if ((insn
& (0x3ff << 1)) == 266 << 1)
1901 else if ((insn
& (0x1f << 1)) == 23 << 1
1902 && ((insn
& (0x1f << 6)) < 14 << 6
1903 || ((insn
& (0x1f << 6)) >= 16 << 6
1904 && (insn
& (0x1f << 6)) < 24 << 6)))
1905 // load and store indexed -> dform
1906 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1907 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1908 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1909 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1910 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1912 insn
= (58 << 26) | 2;
1920 template<int size
, bool big_endian
>
1921 class Powerpc_relocate_functions
1941 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1942 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1943 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1945 template<int valsize
>
1947 has_overflow_signed(Address value
)
1949 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1950 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1951 limit
<<= ((valsize
- 1) >> 1);
1952 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1953 return value
+ limit
> (limit
<< 1) - 1;
1956 template<int valsize
>
1958 has_overflow_unsigned(Address value
)
1960 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1961 limit
<<= ((valsize
- 1) >> 1);
1962 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1963 return value
> (limit
<< 1) - 1;
1966 template<int valsize
>
1968 has_overflow_bitfield(Address value
)
1970 return (has_overflow_unsigned
<valsize
>(value
)
1971 && has_overflow_signed
<valsize
>(value
));
1974 template<int valsize
>
1975 static inline Status
1976 overflowed(Address value
, Overflow_check overflow
)
1978 if (overflow
== CHECK_SIGNED
)
1980 if (has_overflow_signed
<valsize
>(value
))
1981 return STATUS_OVERFLOW
;
1983 else if (overflow
== CHECK_UNSIGNED
)
1985 if (has_overflow_unsigned
<valsize
>(value
))
1986 return STATUS_OVERFLOW
;
1988 else if (overflow
== CHECK_BITFIELD
)
1990 if (has_overflow_bitfield
<valsize
>(value
))
1991 return STATUS_OVERFLOW
;
1996 // Do a simple RELA relocation
1997 template<int fieldsize
, int valsize
>
1998 static inline Status
1999 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2001 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2002 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2003 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2004 return overflowed
<valsize
>(value
, overflow
);
2007 template<int fieldsize
, int valsize
>
2008 static inline Status
2009 rela(unsigned char* view
,
2010 unsigned int right_shift
,
2011 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2013 Overflow_check overflow
)
2015 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2016 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2017 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2018 if (overflow
== CHECK_SIGNED
)
2019 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2021 value
= value
>> right_shift
;
2022 Valtype reloc
= value
;
2025 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2026 return overflowed
<valsize
>(value
, overflow
);
2029 // Do a simple RELA relocation, unaligned.
2030 template<int fieldsize
, int valsize
>
2031 static inline Status
2032 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2034 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2035 return overflowed
<valsize
>(value
, overflow
);
2038 template<int fieldsize
, int valsize
>
2039 static inline Status
2040 rela_ua(unsigned char* view
,
2041 unsigned int right_shift
,
2042 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2044 Overflow_check overflow
)
2046 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2048 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2049 if (overflow
== CHECK_SIGNED
)
2050 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2052 value
= value
>> right_shift
;
2053 Valtype reloc
= value
;
2056 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2057 return overflowed
<valsize
>(value
, overflow
);
2061 // R_PPC64_ADDR64: (Symbol + Addend)
2063 addr64(unsigned char* view
, Address value
)
2064 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2066 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2068 addr64_u(unsigned char* view
, Address value
)
2069 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2071 // R_POWERPC_ADDR32: (Symbol + Addend)
2072 static inline Status
2073 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2074 { return This::template rela
<32,32>(view
, value
, overflow
); }
2076 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2077 static inline Status
2078 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2079 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2081 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2082 static inline Status
2083 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2085 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2087 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2088 stat
= STATUS_OVERFLOW
;
2092 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2093 static inline Status
2094 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2095 { return This::template rela
<16,16>(view
, value
, overflow
); }
2097 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2098 static inline Status
2099 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2100 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2102 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2103 static inline Status
2104 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2106 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2107 if ((value
& 3) != 0)
2108 stat
= STATUS_OVERFLOW
;
2112 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2113 static inline Status
2114 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2116 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2117 if ((value
& 15) != 0)
2118 stat
= STATUS_OVERFLOW
;
2122 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2124 addr16_hi(unsigned char* view
, Address value
)
2125 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2127 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2129 addr16_ha(unsigned char* view
, Address value
)
2130 { This::addr16_hi(view
, value
+ 0x8000); }
2132 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2134 addr16_hi2(unsigned char* view
, Address value
)
2135 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2137 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2139 addr16_ha2(unsigned char* view
, Address value
)
2140 { This::addr16_hi2(view
, value
+ 0x8000); }
2142 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2144 addr16_hi3(unsigned char* view
, Address value
)
2145 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2147 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2149 addr16_ha3(unsigned char* view
, Address value
)
2150 { This::addr16_hi3(view
, value
+ 0x8000); }
2152 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2153 static inline Status
2154 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2156 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2157 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2158 stat
= STATUS_OVERFLOW
;
2162 // R_POWERPC_REL16DX_HA
2163 static inline Status
2164 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2166 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2167 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2168 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2170 value
= static_cast<SignedAddress
>(value
) >> 16;
2171 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2172 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2173 return overflowed
<16>(value
, overflow
);
2177 static inline Status
2178 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2180 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2182 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2188 addr34_hi(unsigned char *view
, uint64_t value
)
2189 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2193 addr34_ha(unsigned char *view
, uint64_t value
)
2194 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2197 static inline Status
2198 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2200 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2202 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2206 // R_PPC64_ADDR16_HIGHER34
2208 addr16_higher34(unsigned char* view
, uint64_t value
)
2209 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2211 // R_PPC64_ADDR16_HIGHERA34
2213 addr16_highera34(unsigned char* view
, uint64_t value
)
2214 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2216 // R_PPC64_ADDR16_HIGHEST34
2218 addr16_highest34(unsigned char* view
, uint64_t value
)
2219 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2221 // R_PPC64_ADDR16_HIGHESTA34
2223 addr16_highesta34(unsigned char* view
, uint64_t value
)
2224 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2227 // Set ABI version for input and output.
2229 template<int size
, bool big_endian
>
2231 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2233 this->e_flags_
|= ver
;
2234 if (this->abiversion() != 0)
2236 Target_powerpc
<size
, big_endian
>* target
=
2237 static_cast<Target_powerpc
<size
, big_endian
>*>(
2238 parameters
->sized_target
<size
, big_endian
>());
2239 if (target
->abiversion() == 0)
2240 target
->set_abiversion(this->abiversion());
2241 else if (target
->abiversion() != this->abiversion())
2242 gold_error(_("%s: ABI version %d is not compatible "
2243 "with ABI version %d output"),
2244 this->name().c_str(),
2245 this->abiversion(), target
->abiversion());
2250 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2251 // relocatable object, if such sections exists.
2253 template<int size
, bool big_endian
>
2255 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2256 Read_symbols_data
* sd
)
2258 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2259 const unsigned char* namesu
= sd
->section_names
->data();
2260 const char* names
= reinterpret_cast<const char*>(namesu
);
2261 section_size_type names_size
= sd
->section_names_size
;
2262 const unsigned char* s
;
2264 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2265 size
== 32 ? ".got2" : ".opd",
2266 names
, names_size
, NULL
);
2269 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2270 this->special_
= ndx
;
2273 if (this->abiversion() == 0)
2274 this->set_abiversion(1);
2275 else if (this->abiversion() > 1)
2276 gold_error(_("%s: .opd invalid in abiv%d"),
2277 this->name().c_str(), this->abiversion());
2282 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2283 names
, names_size
, NULL
);
2286 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2287 this->relatoc_
= ndx
;
2288 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2289 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2292 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2295 // Examine .rela.opd to build info about function entry points.
2297 template<int size
, bool big_endian
>
2299 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2301 const unsigned char* prelocs
,
2302 const unsigned char* plocal_syms
)
2306 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2307 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2308 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2309 Address expected_off
= 0;
2310 bool regular
= true;
2311 unsigned int opd_ent_size
= 0;
2313 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2315 Reltype
reloc(prelocs
);
2316 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2317 = reloc
.get_r_info();
2318 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2319 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2321 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2322 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2325 if (r_sym
< this->local_symbol_count())
2327 typename
elfcpp::Sym
<size
, big_endian
>
2328 lsym(plocal_syms
+ r_sym
* sym_size
);
2329 shndx
= lsym
.get_st_shndx();
2330 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2331 value
= lsym
.get_st_value();
2334 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2336 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2337 value
+ reloc
.get_r_addend());
2340 expected_off
= reloc
.get_r_offset();
2341 opd_ent_size
= expected_off
;
2343 else if (expected_off
!= reloc
.get_r_offset())
2345 expected_off
+= opd_ent_size
;
2347 else if (r_type
== elfcpp::R_PPC64_TOC
)
2349 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2354 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2355 this->name().c_str(), r_type
);
2359 if (reloc_count
<= 2)
2360 opd_ent_size
= this->section_size(this->opd_shndx());
2361 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2365 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2366 this->name().c_str());
2372 // Returns true if a code sequence loading the TOC entry at VALUE
2373 // relative to the TOC pointer can be converted into code calculating
2374 // a TOC pointer relative offset.
2375 // If so, the TOC pointer relative offset is stored to VALUE.
2377 template<int size
, bool big_endian
>
2379 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2380 Target_powerpc
<size
, big_endian
>* target
,
2386 // With -mcmodel=medium code it is quite possible to have
2387 // toc-relative relocs referring to objects outside the TOC.
2388 // Don't try to look at a non-existent TOC.
2389 if (this->toc_shndx() == 0)
2392 // Convert VALUE back to an address by adding got_base (see below),
2393 // then to an offset in the TOC by subtracting the TOC output
2394 // section address and the TOC output offset. Since this TOC output
2395 // section and the got output section are one and the same, we can
2396 // omit adding and subtracting the output section address.
2397 Address off
= (*value
+ this->toc_base_offset()
2398 - this->output_section_offset(this->toc_shndx()));
2399 // Is this offset in the TOC? -mcmodel=medium code may be using
2400 // TOC relative access to variables outside the TOC. Those of
2401 // course can't be optimized. We also don't try to optimize code
2402 // that is using a different object's TOC.
2403 if (off
>= this->section_size(this->toc_shndx()))
2406 if (this->no_toc_opt(off
))
2409 section_size_type vlen
;
2410 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2411 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2413 Address got_base
= (target
->got_section()->output_section()->address()
2414 + this->toc_base_offset());
2416 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2423 template<int size
, bool big_endian
>
2425 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2426 Target_powerpc
<size
, big_endian
>* target
,
2427 const Symbol_value
<size
>* psymval
,
2431 Address addr
= psymval
->value(this, addend
);
2432 Address got_base
= (target
->got_section()->output_section()->address()
2433 + this->toc_base_offset());
2435 if (addr
+ 0x80008000 > 0xffffffff)
2442 // Perform the Sized_relobj_file method, then set up opd info from
2445 template<int size
, bool big_endian
>
2447 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2449 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2452 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2453 p
!= rd
->relocs
.end();
2456 if (p
->data_shndx
== this->opd_shndx())
2458 uint64_t opd_size
= this->section_size(this->opd_shndx());
2459 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2462 this->init_opd(opd_size
);
2463 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2464 rd
->local_symbols
->data());
2472 // Read the symbols then set up st_other vector.
2474 template<int size
, bool big_endian
>
2476 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2478 this->base_read_symbols(sd
);
2479 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2483 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2484 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2485 const unsigned int loccount
= this->do_local_symbol_count();
2488 this->st_other_
.resize(loccount
);
2489 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2490 off_t locsize
= loccount
* sym_size
;
2491 const unsigned int symtab_shndx
= this->symtab_shndx();
2492 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2493 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2494 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2495 locsize
, true, false);
2497 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2499 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2500 unsigned char st_other
= sym
.get_st_other();
2501 this->st_other_
[i
] = st_other
;
2502 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2504 if (this->abiversion() == 0)
2505 this->set_abiversion(2);
2506 else if (this->abiversion() < 2)
2507 gold_error(_("%s: local symbol %d has invalid st_other"
2508 " for ABI version 1"),
2509 this->name().c_str(), i
);
2515 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2516 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2517 bool merge_attributes
= false;
2518 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2520 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2521 switch (shdr
.get_sh_type())
2523 case elfcpp::SHT_GNU_ATTRIBUTES
:
2525 gold_assert(this->attributes_section_data_
== NULL
);
2526 section_offset_type section_offset
= shdr
.get_sh_offset();
2527 section_size_type section_size
=
2528 convert_to_section_size_type(shdr
.get_sh_size());
2529 const unsigned char* view
=
2530 this->get_view(section_offset
, section_size
, true, false);
2531 this->attributes_section_data_
=
2532 new Attributes_section_data(view
, section_size
);
2536 case elfcpp::SHT_SYMTAB
:
2538 // Sometimes an object has no contents except the section
2539 // name string table and an empty symbol table with the
2540 // undefined symbol. We don't want to merge
2541 // processor-specific flags from such an object.
2542 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2543 elfcpp::Elf_sizes
<size
>::sym_size
;
2544 if (shdr
.get_sh_size() > sym_size
)
2545 merge_attributes
= true;
2549 case elfcpp::SHT_STRTAB
:
2553 merge_attributes
= true;
2558 if (!merge_attributes
)
2560 // Should rarely happen.
2561 delete this->attributes_section_data_
;
2562 this->attributes_section_data_
= NULL
;
2566 template<int size
, bool big_endian
>
2568 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2570 this->e_flags_
|= ver
;
2571 if (this->abiversion() != 0)
2573 Target_powerpc
<size
, big_endian
>* target
=
2574 static_cast<Target_powerpc
<size
, big_endian
>*>(
2575 parameters
->sized_target
<size
, big_endian
>());
2576 if (target
->abiversion() == 0)
2577 target
->set_abiversion(this->abiversion());
2578 else if (target
->abiversion() != this->abiversion())
2579 gold_error(_("%s: ABI version %d is not compatible "
2580 "with ABI version %d output"),
2581 this->name().c_str(),
2582 this->abiversion(), target
->abiversion());
2587 // Call Sized_dynobj::base_read_symbols to read the symbols then
2588 // read .opd from a dynamic object, filling in opd_ent_ vector,
2590 template<int size
, bool big_endian
>
2592 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2594 this->base_read_symbols(sd
);
2595 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2596 const unsigned char* ps
=
2597 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2598 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2600 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2601 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2603 section_offset_type section_offset
= shdr
.get_sh_offset();
2604 section_size_type section_size
=
2605 convert_to_section_size_type(shdr
.get_sh_size());
2606 const unsigned char* view
=
2607 this->get_view(section_offset
, section_size
, true, false);
2608 this->attributes_section_data_
=
2609 new Attributes_section_data(view
, section_size
);
2615 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2616 const unsigned char* namesu
= sd
->section_names
->data();
2617 const char* names
= reinterpret_cast<const char*>(namesu
);
2618 const unsigned char* s
= NULL
;
2619 const unsigned char* opd
;
2620 section_size_type opd_size
;
2622 // Find and read .opd section.
2625 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2626 sd
->section_names_size
,
2631 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2632 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2633 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2635 if (this->abiversion() == 0)
2636 this->set_abiversion(1);
2637 else if (this->abiversion() > 1)
2638 gold_error(_("%s: .opd invalid in abiv%d"),
2639 this->name().c_str(), this->abiversion());
2641 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2642 this->opd_address_
= shdr
.get_sh_addr();
2643 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2644 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2650 // Build set of executable sections.
2651 // Using a set is probably overkill. There is likely to be only
2652 // a few executable sections, typically .init, .text and .fini,
2653 // and they are generally grouped together.
2654 typedef std::set
<Sec_info
> Exec_sections
;
2655 Exec_sections exec_sections
;
2657 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2659 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2660 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2661 && ((shdr
.get_sh_flags()
2662 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2663 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2664 && shdr
.get_sh_size() != 0)
2666 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2667 shdr
.get_sh_size(), i
));
2670 if (exec_sections
.empty())
2673 // Look over the OPD entries. This is complicated by the fact
2674 // that some binaries will use two-word entries while others
2675 // will use the standard three-word entries. In most cases
2676 // the third word (the environment pointer for languages like
2677 // Pascal) is unused and will be zero. If the third word is
2678 // used it should not be pointing into executable sections,
2680 this->init_opd(opd_size
);
2681 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2683 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2684 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2685 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2687 // Chances are that this is the third word of an OPD entry.
2689 typename
Exec_sections::const_iterator e
2690 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2691 if (e
!= exec_sections
.begin())
2694 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2696 // We have an address in an executable section.
2697 // VAL ought to be the function entry, set it up.
2698 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2699 // Skip second word of OPD entry, the TOC pointer.
2703 // If we didn't match any executable sections, we likely
2704 // have a non-zero third word in the OPD entry.
2709 // Relocate sections.
2711 template<int size
, bool big_endian
>
2713 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2714 const Symbol_table
* symtab
, const Layout
* layout
,
2715 const unsigned char* pshdrs
, Output_file
* of
,
2716 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2718 unsigned int start
= 1;
2720 && this->relatoc_
!= 0
2721 && !parameters
->options().relocatable())
2723 // Relocate .toc first.
2724 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2725 this->relatoc_
, this->relatoc_
);
2726 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2727 1, this->relatoc_
- 1);
2728 start
= this->relatoc_
+ 1;
2730 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2731 start
, this->shnum() - 1);
2733 if (!parameters
->options().output_is_position_independent())
2735 Target_powerpc
<size
, big_endian
>* target
2736 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2737 parameters
->sized_target
<size
, big_endian
>());
2738 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2740 const section_size_type offset
= target
->lplt_section()->offset();
2741 const section_size_type oview_size
2742 = convert_to_section_size_type(target
->lplt_section()->data_size());
2743 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2745 bool modified
= false;
2746 unsigned int nsyms
= this->local_symbol_count();
2747 for (unsigned int i
= 0; i
< nsyms
; i
++)
2748 if (this->local_has_plt_offset(i
))
2750 Address value
= this->local_symbol_value(i
, 0);
2752 value
+= ppc64_local_entry_offset(i
);
2753 size_t off
= this->local_plt_offset(i
);
2754 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2758 of
->write_output_view(offset
, oview_size
, oview
);
2763 // Set up some symbols.
2765 template<int size
, bool big_endian
>
2767 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2768 Symbol_table
* symtab
,
2773 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2774 // undefined when scanning relocs (and thus requires
2775 // non-relative dynamic relocs). The proper value will be
2777 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2778 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2780 Target_powerpc
<size
, big_endian
>* target
=
2781 static_cast<Target_powerpc
<size
, big_endian
>*>(
2782 parameters
->sized_target
<size
, big_endian
>());
2783 Output_data_got_powerpc
<size
, big_endian
>* got
2784 = target
->got_section(symtab
, layout
);
2785 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2786 Symbol_table::PREDEFINED
,
2790 elfcpp::STV_HIDDEN
, 0,
2794 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2795 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2796 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2798 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2800 = layout
->add_output_section_data(".sdata", 0,
2802 | elfcpp::SHF_WRITE
,
2803 sdata
, ORDER_SMALL_DATA
, false);
2804 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2805 Symbol_table::PREDEFINED
,
2806 os
, 32768, 0, elfcpp::STT_OBJECT
,
2807 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2813 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2814 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2815 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2817 Target_powerpc
<size
, big_endian
>* target
=
2818 static_cast<Target_powerpc
<size
, big_endian
>*>(
2819 parameters
->sized_target
<size
, big_endian
>());
2820 Output_data_got_powerpc
<size
, big_endian
>* got
2821 = target
->got_section(symtab
, layout
);
2822 symtab
->define_in_output_data(".TOC.", NULL
,
2823 Symbol_table::PREDEFINED
,
2827 elfcpp::STV_HIDDEN
, 0,
2832 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2833 if (parameters
->options().tls_get_addr_optimize()
2834 && this->tls_get_addr_
!= NULL
2835 && this->tls_get_addr_
->in_reg())
2836 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2837 if (this->tls_get_addr_opt_
!= NULL
)
2839 if (this->tls_get_addr_
->is_undefined()
2840 || this->tls_get_addr_
->is_from_dynobj())
2842 // Make it seem as if references to __tls_get_addr are
2843 // really to __tls_get_addr_opt, so the latter symbol is
2844 // made dynamic, not the former.
2845 this->tls_get_addr_
->clear_in_reg();
2846 this->tls_get_addr_opt_
->set_in_reg();
2848 // We have a non-dynamic definition for __tls_get_addr.
2849 // Make __tls_get_addr_opt the same, if it does not already have
2850 // a non-dynamic definition.
2851 else if (this->tls_get_addr_opt_
->is_undefined()
2852 || this->tls_get_addr_opt_
->is_from_dynobj())
2854 Sized_symbol
<size
>* from
2855 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2856 Sized_symbol
<size
>* to
2857 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2858 symtab
->clone
<size
>(to
, from
);
2863 // Set up PowerPC target specific relobj.
2865 template<int size
, bool big_endian
>
2867 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2868 const std::string
& name
,
2869 Input_file
* input_file
,
2870 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2872 int et
= ehdr
.get_e_type();
2873 // ET_EXEC files are valid input for --just-symbols/-R,
2874 // and we treat them as relocatable objects.
2875 if (et
== elfcpp::ET_REL
2876 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2878 Powerpc_relobj
<size
, big_endian
>* obj
=
2879 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2883 else if (et
== elfcpp::ET_DYN
)
2885 Powerpc_dynobj
<size
, big_endian
>* obj
=
2886 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2892 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2897 template<int size
, bool big_endian
>
2898 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2901 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2902 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2904 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2905 : Output_data_got
<size
, big_endian
>(),
2906 symtab_(symtab
), layout_(layout
),
2907 header_ent_cnt_(size
== 32 ? 3 : 1),
2908 header_index_(size
== 32 ? 0x2000 : 0)
2911 this->set_addralign(256);
2914 // Override all the Output_data_got methods we use so as to first call
2917 add_global(Symbol
* gsym
, unsigned int got_type
)
2919 this->reserve_ent();
2920 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2924 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2926 this->reserve_ent();
2927 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2931 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2932 { return this->add_global_plt(gsym
, got_type
); }
2935 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2936 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2938 this->reserve_ent();
2939 Output_data_got
<size
, big_endian
>::
2940 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2944 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2945 Output_data_reloc_generic
* rel_dyn
,
2946 unsigned int r_type_1
, unsigned int r_type_2
)
2948 if (gsym
->has_got_offset(got_type
))
2951 this->reserve_ent(2);
2952 Output_data_got
<size
, big_endian
>::
2953 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2957 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2959 this->reserve_ent();
2960 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2965 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2967 this->reserve_ent();
2968 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2973 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2974 { return this->add_local_plt(object
, sym_index
, got_type
); }
2977 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2978 unsigned int got_type
,
2979 Output_data_reloc_generic
* rel_dyn
,
2980 unsigned int r_type
)
2982 if (object
->local_has_got_offset(sym_index
, got_type
))
2985 this->reserve_ent(2);
2986 Output_data_got
<size
, big_endian
>::
2987 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2991 add_constant(Valtype constant
)
2993 this->reserve_ent();
2994 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2998 add_constant_pair(Valtype c1
, Valtype c2
)
3000 this->reserve_ent(2);
3001 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3004 // Offset of _GLOBAL_OFFSET_TABLE_.
3008 return this->got_offset(this->header_index_
);
3011 // Offset of base used to access the GOT/TOC.
3012 // The got/toc pointer reg will be set to this value.
3014 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
3017 return this->g_o_t();
3019 return (this->output_section()->address()
3020 + object
->toc_base_offset()
3024 // Ensure our GOT has a header.
3026 set_final_data_size()
3028 if (this->header_ent_cnt_
!= 0)
3029 this->make_header();
3030 Output_data_got
<size
, big_endian
>::set_final_data_size();
3033 // First word of GOT header needs some values that are not
3034 // handled by Output_data_got so poke them in here.
3035 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3037 do_write(Output_file
* of
)
3040 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3041 val
= this->layout_
->dynamic_section()->address();
3043 val
= this->output_section()->address() + 0x8000;
3044 this->replace_constant(this->header_index_
, val
);
3045 Output_data_got
<size
, big_endian
>::do_write(of
);
3050 reserve_ent(unsigned int cnt
= 1)
3052 if (this->header_ent_cnt_
== 0)
3054 if (this->num_entries() + cnt
> this->header_index_
)
3055 this->make_header();
3061 this->header_ent_cnt_
= 0;
3062 this->header_index_
= this->num_entries();
3065 Output_data_got
<size
, big_endian
>::add_constant(0);
3066 Output_data_got
<size
, big_endian
>::add_constant(0);
3067 Output_data_got
<size
, big_endian
>::add_constant(0);
3069 // Define _GLOBAL_OFFSET_TABLE_ at the header
3070 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3073 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3074 sym
->set_value(this->g_o_t());
3077 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3078 Symbol_table::PREDEFINED
,
3079 this, this->g_o_t(), 0,
3082 elfcpp::STV_HIDDEN
, 0,
3086 Output_data_got
<size
, big_endian
>::add_constant(0);
3089 // Stashed pointers.
3090 Symbol_table
* symtab_
;
3094 unsigned int header_ent_cnt_
;
3095 // GOT header index.
3096 unsigned int header_index_
;
3099 // Get the GOT section, creating it if necessary.
3101 template<int size
, bool big_endian
>
3102 Output_data_got_powerpc
<size
, big_endian
>*
3103 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3106 if (this->got_
== NULL
)
3108 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3111 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3113 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3114 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3115 this->got_
, ORDER_DATA
, false);
3121 // Get the dynamic reloc section, creating it if necessary.
3123 template<int size
, bool big_endian
>
3124 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3125 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3127 if (this->rela_dyn_
== NULL
)
3129 gold_assert(layout
!= NULL
);
3130 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3131 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3132 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3133 ORDER_DYNAMIC_RELOCS
, false);
3135 return this->rela_dyn_
;
3138 // Similarly, but for ifunc symbols get the one for ifunc.
3140 template<int size
, bool big_endian
>
3141 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3142 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3147 return this->rela_dyn_section(layout
);
3149 if (this->iplt_
== NULL
)
3150 this->make_iplt_section(symtab
, layout
);
3151 return this->iplt_
->rel_plt();
3157 // Determine the stub group size. The group size is the absolute
3158 // value of the parameter --stub-group-size. If --stub-group-size
3159 // is passed a negative value, we restrict stubs to be always after
3160 // the stubbed branches.
3161 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3162 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3163 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3164 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3165 owner_(NULL
), output_section_(NULL
)
3169 // Return true iff input section can be handled by current stub
3172 can_add_to_stub_group(Output_section
* o
,
3173 const Output_section::Input_section
* i
,
3176 const Output_section::Input_section
*
3182 { return output_section_
; }
3185 set_output_and_owner(Output_section
* o
,
3186 const Output_section::Input_section
* i
)
3188 this->output_section_
= o
;
3197 // Adding group sections before the stubs.
3198 FINDING_STUB_SECTION
,
3199 // Adding group sections after the stubs.
3203 uint32_t stub_group_size_
;
3204 bool stubs_always_after_branch_
;
3205 bool suppress_size_errors_
;
3206 // True if a stub group can serve multiple output sections.
3209 // Current max size of group. Starts at stub_group_size_ but is
3210 // reduced to stub_group_size_/1024 on seeing a section with
3211 // external conditional branches.
3212 uint32_t group_size_
;
3213 uint64_t group_start_addr_
;
3214 // owner_ and output_section_ specify the section to which stubs are
3215 // attached. The stubs are placed at the end of this section.
3216 const Output_section::Input_section
* owner_
;
3217 Output_section
* output_section_
;
3220 // Return true iff input section can be handled by current stub
3221 // group. Sections are presented to this function in order,
3222 // so the first section is the head of the group.
3225 Stub_control::can_add_to_stub_group(Output_section
* o
,
3226 const Output_section::Input_section
* i
,
3229 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3231 uint64_t start_addr
= o
->address();
3234 // .init and .fini sections are pasted together to form a single
3235 // function. We can't be adding stubs in the middle of the function.
3236 this_size
= o
->data_size();
3239 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3240 this_size
= i
->data_size();
3243 uint64_t end_addr
= start_addr
+ this_size
;
3244 uint32_t group_size
= this->stub_group_size_
;
3246 this->group_size_
= group_size
= group_size
>> 10;
3248 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3249 gold_warning(_("%s:%s exceeds group size"),
3250 i
->relobj()->name().c_str(),
3251 i
->relobj()->section_name(i
->shndx()).c_str());
3253 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3254 has14
? " 14bit" : "",
3255 i
->relobj()->name().c_str(),
3256 i
->relobj()->section_name(i
->shndx()).c_str(),
3257 (long long) this_size
,
3258 (this->state_
== NO_GROUP
3260 : (long long) end_addr
- this->group_start_addr_
));
3262 if (this->state_
== NO_GROUP
)
3264 // Only here on very first use of Stub_control
3266 this->output_section_
= o
;
3267 this->state_
= FINDING_STUB_SECTION
;
3268 this->group_size_
= group_size
;
3269 this->group_start_addr_
= start_addr
;
3272 else if (!this->multi_os_
&& this->output_section_
!= o
)
3274 else if (this->state_
== HAS_STUB_SECTION
)
3276 // Can we add this section, which is after the stubs, to the
3278 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3281 else if (this->state_
== FINDING_STUB_SECTION
)
3283 if ((whole_sec
&& this->output_section_
== o
)
3284 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3286 // Stubs are added at the end of "owner_".
3288 this->output_section_
= o
;
3291 // The group before the stubs has reached maximum size.
3292 // Now see about adding sections after the stubs to the
3293 // group. If the current section has a 14-bit branch and
3294 // the group before the stubs exceeds group_size_ (because
3295 // they didn't have 14-bit branches), don't add sections
3296 // after the stubs: The size of stubs for such a large
3297 // group may exceed the reach of a 14-bit branch.
3298 if (!this->stubs_always_after_branch_
3299 && this_size
<= this->group_size_
3300 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3302 gold_debug(DEBUG_TARGET
, "adding after stubs");
3303 this->state_
= HAS_STUB_SECTION
;
3304 this->group_start_addr_
= start_addr
;
3311 gold_debug(DEBUG_TARGET
,
3312 !this->multi_os_
&& this->output_section_
!= o
3313 ? "nope, new output section\n"
3314 : "nope, didn't fit\n");
3316 // The section fails to fit in the current group. Set up a few
3317 // things for the next group. owner_ and output_section_ will be
3318 // set later after we've retrieved those values for the current
3320 this->state_
= FINDING_STUB_SECTION
;
3321 this->group_size_
= group_size
;
3322 this->group_start_addr_
= start_addr
;
3326 // Look over all the input sections, deciding where to place stubs.
3328 template<int size
, bool big_endian
>
3330 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3332 bool no_size_errors
)
3334 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3335 parameters
->options().stub_group_multi());
3337 // Group input sections and insert stub table
3338 Stub_table_owner
* table_owner
= NULL
;
3339 std::vector
<Stub_table_owner
*> tables
;
3340 Layout::Section_list section_list
;
3341 layout
->get_executable_sections(§ion_list
);
3342 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3343 for (Layout::Section_list::iterator o
= section_list
.begin();
3344 o
!= section_list
.end();
3347 typedef Output_section::Input_section_list Input_section_list
;
3348 for (Input_section_list::const_iterator i
3349 = (*o
)->input_sections().begin();
3350 i
!= (*o
)->input_sections().end();
3353 if (i
->is_input_section()
3354 || i
->is_relaxed_input_section())
3356 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3357 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3358 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3359 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3361 table_owner
->output_section
= stub_control
.output_section();
3362 table_owner
->owner
= stub_control
.owner();
3363 stub_control
.set_output_and_owner(*o
, &*i
);
3366 if (table_owner
== NULL
)
3368 table_owner
= new Stub_table_owner
;
3369 tables
.push_back(table_owner
);
3371 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3375 if (table_owner
!= NULL
)
3377 table_owner
->output_section
= stub_control
.output_section();
3378 table_owner
->owner
= stub_control
.owner();;
3380 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3384 Stub_table
<size
, big_endian
>* stub_table
;
3386 if ((*t
)->owner
->is_input_section())
3387 stub_table
= new Stub_table
<size
, big_endian
>(this,
3388 (*t
)->output_section
,
3390 this->stub_tables_
.size());
3391 else if ((*t
)->owner
->is_relaxed_input_section())
3392 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3393 (*t
)->owner
->relaxed_input_section());
3396 this->stub_tables_
.push_back(stub_table
);
3402 static unsigned long
3403 max_branch_delta (unsigned int r_type
)
3405 if (r_type
== elfcpp::R_POWERPC_REL14
3406 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3407 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3409 if (r_type
== elfcpp::R_POWERPC_REL24
3410 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3411 || r_type
== elfcpp::R_PPC_PLTREL24
3412 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3417 // Return whether this branch is going via a plt call stub.
3419 template<int size
, bool big_endian
>
3421 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3422 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3425 Target_powerpc
* target
,
3426 Symbol_table
* symtab
)
3428 if (this->object_
!= ppc_object
3429 || this->shndx_
!= shndx
3430 || this->offset_
!= offset
)
3433 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3434 if (sym
!= NULL
&& sym
->is_forwarder())
3435 sym
= symtab
->resolve_forwards(sym
);
3436 if (target
->replace_tls_get_addr(sym
))
3437 sym
= target
->tls_get_addr_opt();
3438 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3440 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3441 && !target
->is_elfv2_localentry0(gsym
))
3442 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3443 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3451 // If this branch needs a plt call stub, or a long branch stub, make one.
3453 template<int size
, bool big_endian
>
3455 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3456 Stub_table
<size
, big_endian
>* stub_table
,
3457 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3458 Symbol_table
* symtab
) const
3460 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3461 Target_powerpc
<size
, big_endian
>* target
=
3462 static_cast<Target_powerpc
<size
, big_endian
>*>(
3463 parameters
->sized_target
<size
, big_endian
>());
3464 if (sym
!= NULL
&& sym
->is_forwarder())
3465 sym
= symtab
->resolve_forwards(sym
);
3466 if (target
->replace_tls_get_addr(sym
))
3467 sym
= target
->tls_get_addr_opt();
3468 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3472 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3473 : this->object_
->local_has_plt_offset(this->r_sym_
))
3477 && target
->abiversion() >= 2
3478 && !parameters
->options().output_is_position_independent()
3479 && !is_branch_reloc
<size
>(this->r_type_
))
3480 target
->glink_section()->add_global_entry(gsym
);
3483 if (stub_table
== NULL
3486 && !parameters
->options().output_is_position_independent()
3487 && !is_branch_reloc
<size
>(this->r_type_
)))
3488 stub_table
= this->object_
->stub_table(this->shndx_
);
3489 if (stub_table
== NULL
)
3491 // This is a ref from a data section to an ifunc symbol,
3492 // or a non-branch reloc for which we always want to use
3493 // one set of stubs for resolving function addresses.
3494 stub_table
= ifunc_stub_table
;
3496 gold_assert(stub_table
!= NULL
);
3497 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3498 if (from
!= invalid_address
)
3499 from
+= (this->object_
->output_section(this->shndx_
)->address()
3502 ok
= stub_table
->add_plt_call_entry(from
,
3503 this->object_
, gsym
,
3504 this->r_type_
, this->addend_
,
3507 ok
= stub_table
->add_plt_call_entry(from
,
3508 this->object_
, this->r_sym_
,
3509 this->r_type_
, this->addend_
,
3515 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3516 if (max_branch_offset
== 0)
3518 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3519 gold_assert(from
!= invalid_address
);
3520 from
+= (this->object_
->output_section(this->shndx_
)->address()
3525 switch (gsym
->source())
3527 case Symbol::FROM_OBJECT
:
3529 Object
* symobj
= gsym
->object();
3530 if (symobj
->is_dynamic()
3531 || symobj
->pluginobj() != NULL
)
3534 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3535 if (shndx
== elfcpp::SHN_UNDEF
)
3540 case Symbol::IS_UNDEFINED
:
3546 Symbol_table::Compute_final_value_status status
;
3547 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3548 if (status
!= Symbol_table::CFVS_OK
)
3551 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3555 const Symbol_value
<size
>* psymval
3556 = this->object_
->local_symbol(this->r_sym_
);
3557 Symbol_value
<size
> symval
;
3558 if (psymval
->is_section_symbol())
3559 symval
.set_is_section_symbol();
3560 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3561 typename
ObjType::Compute_final_local_value_status status
3562 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3564 if (status
!= ObjType::CFLV_OK
3565 || !symval
.has_output_value())
3567 to
= symval
.value(this->object_
, 0);
3569 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3571 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3572 to
+= this->addend_
;
3573 if (stub_table
== NULL
)
3574 stub_table
= this->object_
->stub_table(this->shndx_
);
3575 if (size
== 64 && target
->abiversion() < 2)
3577 unsigned int dest_shndx
;
3578 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3582 Address delta
= to
- from
;
3583 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3585 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3587 ? this->object_
->ppc64_needs_toc(gsym
)
3588 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3590 if (stub_table
== NULL
)
3592 gold_warning(_("%s:%s: branch in non-executable section,"
3593 " no long branch stub for you"),
3594 this->object_
->name().c_str(),
3595 this->object_
->section_name(this->shndx_
).c_str());
3598 bool save_res
= (size
== 64
3600 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3601 && gsym
->output_data() == target
->savres_section());
3602 ok
= stub_table
->add_long_branch_entry(this->object_
,
3604 from
, to
, save_res
);
3608 gold_debug(DEBUG_TARGET
,
3609 "branch at %s:%s+%#lx\n"
3610 "can't reach stub attached to %s:%s",
3611 this->object_
->name().c_str(),
3612 this->object_
->section_name(this->shndx_
).c_str(),
3613 (unsigned long) this->offset_
,
3614 stub_table
->relobj()->name().c_str(),
3615 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3620 // Relaxation hook. This is where we do stub generation.
3622 template<int size
, bool big_endian
>
3624 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3625 const Input_objects
*,
3626 Symbol_table
* symtab
,
3630 unsigned int prev_brlt_size
= 0;
3634 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3636 && this->abiversion() < 2
3638 && !parameters
->options().user_set_plt_thread_safe())
3640 static const char* const thread_starter
[] =
3644 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3646 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3647 "mq_notify", "create_timer",
3652 "GOMP_parallel_start",
3653 "GOMP_parallel_loop_static",
3654 "GOMP_parallel_loop_static_start",
3655 "GOMP_parallel_loop_dynamic",
3656 "GOMP_parallel_loop_dynamic_start",
3657 "GOMP_parallel_loop_guided",
3658 "GOMP_parallel_loop_guided_start",
3659 "GOMP_parallel_loop_runtime",
3660 "GOMP_parallel_loop_runtime_start",
3661 "GOMP_parallel_sections",
3662 "GOMP_parallel_sections_start",
3667 if (parameters
->options().shared())
3671 for (unsigned int i
= 0;
3672 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3675 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3676 thread_safe
= (sym
!= NULL
3678 && sym
->in_real_elf());
3684 this->plt_thread_safe_
= thread_safe
;
3689 this->stub_group_size_
= parameters
->options().stub_group_size();
3690 bool no_size_errors
= true;
3691 if (this->stub_group_size_
== 1)
3692 this->stub_group_size_
= 0x1c00000;
3693 else if (this->stub_group_size_
== -1)
3694 this->stub_group_size_
= -0x1e00000;
3696 no_size_errors
= false;
3697 this->group_sections(layout
, task
, no_size_errors
);
3699 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3701 this->branch_lookup_table_
.clear();
3702 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3703 p
!= this->stub_tables_
.end();
3706 (*p
)->clear_stubs(true);
3708 this->stub_tables_
.clear();
3709 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3710 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3711 program_name
, this->stub_group_size_
);
3712 this->group_sections(layout
, task
, true);
3715 // We need address of stub tables valid for make_stub.
3716 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3717 p
!= this->stub_tables_
.end();
3720 const Powerpc_relobj
<size
, big_endian
>* object
3721 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3722 Address off
= object
->get_output_section_offset((*p
)->shndx());
3723 gold_assert(off
!= invalid_address
);
3724 Output_section
* os
= (*p
)->output_section();
3725 (*p
)->set_address_and_size(os
, off
);
3730 // Clear plt call stubs, long branch stubs and branch lookup table.
3731 prev_brlt_size
= this->branch_lookup_table_
.size();
3732 this->branch_lookup_table_
.clear();
3733 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3734 p
!= this->stub_tables_
.end();
3737 (*p
)->clear_stubs(false);
3741 // Build all the stubs.
3742 this->relax_failed_
= false;
3743 Stub_table
<size
, big_endian
>* ifunc_stub_table
3744 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3745 Stub_table
<size
, big_endian
>* one_stub_table
3746 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3747 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3748 b
!= this->branch_info_
.end();
3751 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3752 && !this->relax_failed_
)
3754 this->relax_failed_
= true;
3755 this->relax_fail_count_
++;
3756 if (this->relax_fail_count_
< 3)
3760 bool do_resize
= false;
3761 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3762 p
!= this->stub_tables_
.end();
3764 if ((*p
)->need_resize())
3771 this->branch_lookup_table_
.clear();
3772 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3773 p
!= this->stub_tables_
.end();
3775 (*p
)->set_resizing(true);
3776 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3777 b
!= this->branch_info_
.end();
3780 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3781 && !this->relax_failed_
)
3783 this->relax_failed_
= true;
3784 this->relax_fail_count_
++;
3785 if (this->relax_fail_count_
< 3)
3789 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3790 p
!= this->stub_tables_
.end();
3792 (*p
)->set_resizing(false);
3795 // Did anything change size?
3796 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3797 bool again
= num_huge_branches
!= prev_brlt_size
;
3798 if (size
== 64 && num_huge_branches
!= 0)
3799 this->make_brlt_section(layout
);
3800 if (size
== 64 && again
)
3801 this->brlt_section_
->set_current_size(num_huge_branches
);
3803 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3804 p
!= this->stub_tables_
.rend();
3806 (*p
)->remove_eh_frame(layout
);
3808 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3809 p
!= this->stub_tables_
.end();
3811 (*p
)->add_eh_frame(layout
);
3813 typedef Unordered_set
<Output_section
*> Output_sections
;
3814 Output_sections os_need_update
;
3815 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3816 p
!= this->stub_tables_
.end();
3819 if ((*p
)->size_update())
3822 os_need_update
.insert((*p
)->output_section());
3826 // Set output section offsets for all input sections in an output
3827 // section that just changed size. Anything past the stubs will
3829 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3830 p
!= os_need_update
.end();
3833 Output_section
* os
= *p
;
3835 typedef Output_section::Input_section_list Input_section_list
;
3836 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3837 i
!= os
->input_sections().end();
3840 off
= align_address(off
, i
->addralign());
3841 if (i
->is_input_section() || i
->is_relaxed_input_section())
3842 i
->relobj()->set_section_offset(i
->shndx(), off
);
3843 if (i
->is_relaxed_input_section())
3845 Stub_table
<size
, big_endian
>* stub_table
3846 = static_cast<Stub_table
<size
, big_endian
>*>(
3847 i
->relaxed_input_section());
3848 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3849 off
+= stub_table_size
;
3850 // After a few iterations, set current stub table size
3851 // as min size threshold, so later stub tables can only
3854 stub_table
->set_min_size_threshold(stub_table_size
);
3857 off
+= i
->data_size();
3859 // If .branch_lt is part of this output section, then we have
3860 // just done the offset adjustment.
3861 os
->clear_section_offsets_need_adjustment();
3866 && num_huge_branches
!= 0
3867 && parameters
->options().output_is_position_independent())
3869 // Fill in the BRLT relocs.
3870 this->brlt_section_
->reset_brlt_sizes();
3871 for (typename
Branch_lookup_table::const_iterator p
3872 = this->branch_lookup_table_
.begin();
3873 p
!= this->branch_lookup_table_
.end();
3876 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3878 this->brlt_section_
->finalize_brlt_sizes();
3882 && (parameters
->options().user_set_emit_stub_syms()
3883 ? parameters
->options().emit_stub_syms()
3885 || parameters
->options().output_is_position_independent()
3886 || parameters
->options().emit_relocs())))
3888 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3889 p
!= this->stub_tables_
.end();
3891 (*p
)->define_stub_syms(symtab
);
3893 if (this->glink_
!= NULL
)
3895 int stub_size
= this->glink_
->pltresolve_size();
3896 Address value
= -stub_size
;
3902 this->define_local(symtab
, "__glink_PLTresolve",
3903 this->glink_
, value
, stub_size
);
3906 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3913 template<int size
, bool big_endian
>
3915 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3916 unsigned char* oview
,
3920 uint64_t address
= plt
->address();
3921 off_t len
= plt
->data_size();
3923 if (plt
== this->glink_
)
3925 // See Output_data_glink::do_write() for glink contents.
3928 gold_assert(parameters
->doing_static_link());
3929 // Static linking may need stubs, to support ifunc and long
3930 // branches. We need to create an output section for
3931 // .eh_frame early in the link process, to have a place to
3932 // attach stub .eh_frame info. We also need to have
3933 // registered a CIE that matches the stub CIE. Both of
3934 // these requirements are satisfied by creating an FDE and
3935 // CIE for .glink, even though static linking will leave
3936 // .glink zero length.
3937 // ??? Hopefully generating an FDE with a zero address range
3938 // won't confuse anything that consumes .eh_frame info.
3940 else if (size
== 64)
3942 // There is one word before __glink_PLTresolve
3946 else if (parameters
->options().output_is_position_independent())
3948 // There are two FDEs for a position independent glink.
3949 // The first covers the branch table, the second
3950 // __glink_PLTresolve at the end of glink.
3951 off_t resolve_size
= this->glink_
->pltresolve_size();
3952 if (oview
[9] == elfcpp::DW_CFA_nop
)
3953 len
-= resolve_size
;
3956 address
+= len
- resolve_size
;
3963 // Must be a stub table.
3964 const Stub_table
<size
, big_endian
>* stub_table
3965 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3966 uint64_t stub_address
= stub_table
->stub_address();
3967 len
-= stub_address
- address
;
3968 address
= stub_address
;
3971 *paddress
= address
;
3975 // A class to handle the PLT data.
3977 template<int size
, bool big_endian
>
3978 class Output_data_plt_powerpc
: public Output_section_data_build
3981 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3982 size
, big_endian
> Reloc_section
;
3984 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3985 Reloc_section
* plt_rel
,
3987 : Output_section_data_build(size
== 32 ? 4 : 8),
3993 // Add an entry to the PLT.
3998 add_ifunc_entry(Symbol
*);
4001 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4004 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4006 // Return the .rela.plt section data.
4013 // Return the number of PLT entries.
4017 if (this->current_data_size() == 0)
4019 return ((this->current_data_size() - this->first_plt_entry_offset())
4020 / this->plt_entry_size());
4025 do_adjust_output_section(Output_section
* os
)
4030 // Write to a map file.
4032 do_print_to_mapfile(Mapfile
* mapfile
) const
4033 { mapfile
->print_output_data(this, this->name_
); }
4036 // Return the offset of the first non-reserved PLT entry.
4038 first_plt_entry_offset() const
4040 // IPLT and LPLT have no reserved entry.
4041 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4043 return this->targ_
->first_plt_entry_offset();
4046 // Return the size of each PLT entry.
4048 plt_entry_size() const
4050 return this->targ_
->plt_entry_size();
4053 // Write out the PLT data.
4055 do_write(Output_file
*);
4057 // The reloc section.
4058 Reloc_section
* rel_
;
4059 // Allows access to .glink for do_write.
4060 Target_powerpc
<size
, big_endian
>* targ_
;
4061 // What to report in map file.
4065 // Add an entry to the PLT.
4067 template<int size
, bool big_endian
>
4069 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4071 if (!gsym
->has_plt_offset())
4073 section_size_type off
= this->current_data_size();
4075 off
+= this->first_plt_entry_offset();
4076 gsym
->set_plt_offset(off
);
4077 gsym
->set_needs_dynsym_entry();
4078 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4079 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4080 off
+= this->plt_entry_size();
4081 this->set_current_data_size(off
);
4085 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4087 template<int size
, bool big_endian
>
4089 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4091 if (!gsym
->has_plt_offset())
4093 section_size_type off
= this->current_data_size();
4094 gsym
->set_plt_offset(off
);
4095 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4096 if (size
== 64 && this->targ_
->abiversion() < 2)
4097 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4098 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4099 off
+= this->plt_entry_size();
4100 this->set_current_data_size(off
);
4104 // Add an entry for a local symbol to the PLT.
4106 template<int size
, bool big_endian
>
4108 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4109 Sized_relobj_file
<size
, big_endian
>* relobj
,
4110 unsigned int local_sym_index
)
4112 if (!relobj
->local_has_plt_offset(local_sym_index
))
4114 section_size_type off
= this->current_data_size();
4115 relobj
->set_local_plt_offset(local_sym_index
, off
);
4118 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4119 if (size
== 64 && this->targ_
->abiversion() < 2)
4120 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4121 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4122 dynrel
, this, off
, 0);
4124 off
+= this->plt_entry_size();
4125 this->set_current_data_size(off
);
4129 // Add an entry for a local ifunc symbol to the IPLT.
4131 template<int size
, bool big_endian
>
4133 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4134 Sized_relobj_file
<size
, big_endian
>* relobj
,
4135 unsigned int local_sym_index
)
4137 if (!relobj
->local_has_plt_offset(local_sym_index
))
4139 section_size_type off
= this->current_data_size();
4140 relobj
->set_local_plt_offset(local_sym_index
, off
);
4141 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4142 if (size
== 64 && this->targ_
->abiversion() < 2)
4143 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4144 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4146 off
+= this->plt_entry_size();
4147 this->set_current_data_size(off
);
4151 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4152 static const uint32_t add_2_2_11
= 0x7c425a14;
4153 static const uint32_t add_2_2_12
= 0x7c426214;
4154 static const uint32_t add_3_3_2
= 0x7c631214;
4155 static const uint32_t add_3_3_13
= 0x7c636a14;
4156 static const uint32_t add_3_12_2
= 0x7c6c1214;
4157 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4158 static const uint32_t add_11_0_11
= 0x7d605a14;
4159 static const uint32_t add_11_2_11
= 0x7d625a14;
4160 static const uint32_t add_11_11_2
= 0x7d6b1214;
4161 static const uint32_t add_12_11_12
= 0x7d8b6214;
4162 static const uint32_t addi_0_12
= 0x380c0000;
4163 static const uint32_t addi_2_2
= 0x38420000;
4164 static const uint32_t addi_3_3
= 0x38630000;
4165 static const uint32_t addi_11_11
= 0x396b0000;
4166 static const uint32_t addi_12_1
= 0x39810000;
4167 static const uint32_t addi_12_11
= 0x398b0000;
4168 static const uint32_t addi_12_12
= 0x398c0000;
4169 static const uint32_t addis_0_2
= 0x3c020000;
4170 static const uint32_t addis_0_13
= 0x3c0d0000;
4171 static const uint32_t addis_2_12
= 0x3c4c0000;
4172 static const uint32_t addis_11_2
= 0x3d620000;
4173 static const uint32_t addis_11_11
= 0x3d6b0000;
4174 static const uint32_t addis_11_30
= 0x3d7e0000;
4175 static const uint32_t addis_12_1
= 0x3d810000;
4176 static const uint32_t addis_12_2
= 0x3d820000;
4177 static const uint32_t addis_12_11
= 0x3d8b0000;
4178 static const uint32_t addis_12_12
= 0x3d8c0000;
4179 static const uint32_t b
= 0x48000000;
4180 static const uint32_t bcl_20_31
= 0x429f0005;
4181 static const uint32_t bctr
= 0x4e800420;
4182 static const uint32_t bctrl
= 0x4e800421;
4183 static const uint32_t beqlr
= 0x4d820020;
4184 static const uint32_t blr
= 0x4e800020;
4185 static const uint32_t bnectr_p4
= 0x4ce20420;
4186 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4187 static const uint32_t cmpldi_2_0
= 0x28220000;
4188 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4189 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4190 static const uint32_t cror_15_15_15
= 0x4def7b82;
4191 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4192 static const uint32_t ld_0_1
= 0xe8010000;
4193 static const uint32_t ld_0_12
= 0xe80c0000;
4194 static const uint32_t ld_2_1
= 0xe8410000;
4195 static const uint32_t ld_2_2
= 0xe8420000;
4196 static const uint32_t ld_2_11
= 0xe84b0000;
4197 static const uint32_t ld_2_12
= 0xe84c0000;
4198 static const uint32_t ld_11_1
= 0xe9610000;
4199 static const uint32_t ld_11_2
= 0xe9620000;
4200 static const uint32_t ld_11_3
= 0xe9630000;
4201 static const uint32_t ld_11_11
= 0xe96b0000;
4202 static const uint32_t ld_12_2
= 0xe9820000;
4203 static const uint32_t ld_12_3
= 0xe9830000;
4204 static const uint32_t ld_12_11
= 0xe98b0000;
4205 static const uint32_t ld_12_12
= 0xe98c0000;
4206 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4207 static const uint32_t lfd_0_1
= 0xc8010000;
4208 static const uint32_t li_0_0
= 0x38000000;
4209 static const uint32_t li_11_0
= 0x39600000;
4210 static const uint32_t li_12_0
= 0x39800000;
4211 static const uint32_t lis_0
= 0x3c000000;
4212 static const uint32_t lis_2
= 0x3c400000;
4213 static const uint32_t lis_11
= 0x3d600000;
4214 static const uint32_t lis_12
= 0x3d800000;
4215 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4216 static const uint32_t lwz_0_12
= 0x800c0000;
4217 static const uint32_t lwz_11_3
= 0x81630000;
4218 static const uint32_t lwz_11_11
= 0x816b0000;
4219 static const uint32_t lwz_11_30
= 0x817e0000;
4220 static const uint32_t lwz_12_3
= 0x81830000;
4221 static const uint32_t lwz_12_12
= 0x818c0000;
4222 static const uint32_t lwzu_0_12
= 0x840c0000;
4223 static const uint32_t mflr_0
= 0x7c0802a6;
4224 static const uint32_t mflr_11
= 0x7d6802a6;
4225 static const uint32_t mflr_12
= 0x7d8802a6;
4226 static const uint32_t mr_0_3
= 0x7c601b78;
4227 static const uint32_t mr_3_0
= 0x7c030378;
4228 static const uint32_t mtctr_0
= 0x7c0903a6;
4229 static const uint32_t mtctr_11
= 0x7d6903a6;
4230 static const uint32_t mtctr_12
= 0x7d8903a6;
4231 static const uint32_t mtlr_0
= 0x7c0803a6;
4232 static const uint32_t mtlr_11
= 0x7d6803a6;
4233 static const uint32_t mtlr_12
= 0x7d8803a6;
4234 static const uint32_t nop
= 0x60000000;
4235 static const uint32_t ori_0_0_0
= 0x60000000;
4236 static const uint32_t ori_11_11_0
= 0x616b0000;
4237 static const uint32_t ori_12_12_0
= 0x618c0000;
4238 static const uint32_t oris_12_12_0
= 0x658c0000;
4239 static const uint32_t sldi_11_11_34
= 0x796b1746;
4240 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4241 static const uint32_t srdi_0_0_2
= 0x7800f082;
4242 static const uint32_t std_0_1
= 0xf8010000;
4243 static const uint32_t std_0_12
= 0xf80c0000;
4244 static const uint32_t std_2_1
= 0xf8410000;
4245 static const uint32_t std_11_1
= 0xf9610000;
4246 static const uint32_t stfd_0_1
= 0xd8010000;
4247 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4248 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4249 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4250 static const uint32_t xor_2_12_12
= 0x7d826278;
4251 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4253 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4254 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4255 static const uint64_t pnop
= 0x0700000000000000ULL
;
4257 // Write out the PLT.
4259 template<int size
, bool big_endian
>
4261 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4263 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4265 const section_size_type offset
= this->offset();
4266 const section_size_type oview_size
4267 = convert_to_section_size_type(this->data_size());
4268 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4269 unsigned char* pov
= oview
;
4270 unsigned char* endpov
= oview
+ oview_size
;
4272 // The address of the .glink branch table
4273 const Output_data_glink
<size
, big_endian
>* glink
4274 = this->targ_
->glink_section();
4275 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4277 while (pov
< endpov
)
4279 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4284 of
->write_output_view(offset
, oview_size
, oview
);
4288 // Create the PLT section.
4290 template<int size
, bool big_endian
>
4292 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4295 if (this->plt_
== NULL
)
4297 if (this->got_
== NULL
)
4298 this->got_section(symtab
, layout
);
4300 if (this->glink_
== NULL
)
4301 make_glink_section(layout
);
4303 // Ensure that .rela.dyn always appears before .rela.plt This is
4304 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4305 // needs to include .rela.plt in its range.
4306 this->rela_dyn_section(layout
);
4308 Reloc_section
* plt_rel
= new Reloc_section(false);
4309 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4310 elfcpp::SHF_ALLOC
, plt_rel
,
4311 ORDER_DYNAMIC_PLT_RELOCS
, false);
4313 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4315 layout
->add_output_section_data(".plt",
4317 ? elfcpp::SHT_PROGBITS
4318 : elfcpp::SHT_NOBITS
),
4319 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4326 Output_section
* rela_plt_os
= plt_rel
->output_section();
4327 rela_plt_os
->set_info_section(this->plt_
->output_section());
4331 // Create the IPLT section.
4333 template<int size
, bool big_endian
>
4335 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4338 if (this->iplt_
== NULL
)
4340 this->make_plt_section(symtab
, layout
);
4341 this->make_lplt_section(layout
);
4343 Reloc_section
* iplt_rel
= new Reloc_section(false);
4344 if (this->rela_dyn_
->output_section())
4345 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4347 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4349 if (this->plt_
->output_section())
4350 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4354 // Create the LPLT section.
4356 template<int size
, bool big_endian
>
4358 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4360 if (this->lplt_
== NULL
)
4362 Reloc_section
* lplt_rel
= NULL
;
4363 if (parameters
->options().output_is_position_independent())
4365 lplt_rel
= new Reloc_section(false);
4366 this->rela_dyn_section(layout
);
4367 if (this->rela_dyn_
->output_section())
4368 this->rela_dyn_
->output_section()
4369 ->add_output_section_data(lplt_rel
);
4372 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4374 this->make_brlt_section(layout
);
4375 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4376 this->brlt_section_
->output_section()
4377 ->add_output_section_data(this->lplt_
);
4379 layout
->add_output_section_data(".branch_lt",
4380 elfcpp::SHT_PROGBITS
,
4381 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4388 // A section for huge long branch addresses, similar to plt section.
4390 template<int size
, bool big_endian
>
4391 class Output_data_brlt_powerpc
: public Output_section_data_build
4394 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4395 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4396 size
, big_endian
> Reloc_section
;
4398 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4399 Reloc_section
* brlt_rel
)
4400 : Output_section_data_build(size
== 32 ? 4 : 8),
4408 this->reset_data_size();
4409 this->rel_
->reset_data_size();
4413 finalize_brlt_sizes()
4415 this->finalize_data_size();
4416 this->rel_
->finalize_data_size();
4419 // Add a reloc for an entry in the BRLT.
4421 add_reloc(Address to
, unsigned int off
)
4422 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4424 // Update section and reloc section size.
4426 set_current_size(unsigned int num_branches
)
4428 this->reset_address_and_file_offset();
4429 this->set_current_data_size(num_branches
* 16);
4430 this->finalize_data_size();
4431 Output_section
* os
= this->output_section();
4432 os
->set_section_offsets_need_adjustment();
4433 if (this->rel_
!= NULL
)
4435 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4436 this->rel_
->reset_address_and_file_offset();
4437 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4438 this->rel_
->finalize_data_size();
4439 Output_section
* os
= this->rel_
->output_section();
4440 os
->set_section_offsets_need_adjustment();
4446 do_adjust_output_section(Output_section
* os
)
4451 // Write to a map file.
4453 do_print_to_mapfile(Mapfile
* mapfile
) const
4454 { mapfile
->print_output_data(this, "** BRLT"); }
4457 // Write out the BRLT data.
4459 do_write(Output_file
*);
4461 // The reloc section.
4462 Reloc_section
* rel_
;
4463 Target_powerpc
<size
, big_endian
>* targ_
;
4466 // Make the branch lookup table section.
4468 template<int size
, bool big_endian
>
4470 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4472 if (size
== 64 && this->brlt_section_
== NULL
)
4474 Reloc_section
* brlt_rel
= NULL
;
4475 bool is_pic
= parameters
->options().output_is_position_independent();
4478 // When PIC we can't fill in .branch_lt but must initialise at
4479 // runtime via dynamic relocations.
4480 this->rela_dyn_section(layout
);
4481 brlt_rel
= new Reloc_section(false);
4482 if (this->rela_dyn_
->output_section())
4483 this->rela_dyn_
->output_section()
4484 ->add_output_section_data(brlt_rel
);
4487 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4488 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4489 this->plt_
->output_section()
4490 ->add_output_section_data(this->brlt_section_
);
4492 layout
->add_output_section_data(".branch_lt",
4493 elfcpp::SHT_PROGBITS
,
4494 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4495 this->brlt_section_
,
4501 // Write out .branch_lt when non-PIC.
4503 template<int size
, bool big_endian
>
4505 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4507 if (size
== 64 && !parameters
->options().output_is_position_independent())
4509 const section_size_type offset
= this->offset();
4510 const section_size_type oview_size
4511 = convert_to_section_size_type(this->data_size());
4512 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4514 this->targ_
->write_branch_lookup_table(oview
);
4515 of
->write_output_view(offset
, oview_size
, oview
);
4519 static inline uint32_t
4525 static inline uint32_t
4531 static inline uint32_t
4534 return hi(a
+ 0x8000);
4537 static inline uint64_t
4540 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4543 static inline uint64_t
4546 return (v
+ (1ULL << 33)) >> 34;
4552 static const unsigned char eh_frame_cie
[12];
4556 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4559 'z', 'R', 0, // Augmentation string.
4560 4, // Code alignment.
4561 0x80 - size
/ 8 , // Data alignment.
4563 1, // Augmentation size.
4564 (elfcpp::DW_EH_PE_pcrel
4565 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4566 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4569 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4570 static const unsigned char glink_eh_frame_fde_64v1
[] =
4572 0, 0, 0, 0, // Replaced with offset to .glink.
4573 0, 0, 0, 0, // Replaced with size of .glink.
4574 0, // Augmentation size.
4575 elfcpp::DW_CFA_advance_loc
+ 1,
4576 elfcpp::DW_CFA_register
, 65, 12,
4577 elfcpp::DW_CFA_advance_loc
+ 5,
4578 elfcpp::DW_CFA_restore_extended
, 65
4581 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4582 static const unsigned char glink_eh_frame_fde_64v2
[] =
4584 0, 0, 0, 0, // Replaced with offset to .glink.
4585 0, 0, 0, 0, // Replaced with size of .glink.
4586 0, // Augmentation size.
4587 elfcpp::DW_CFA_advance_loc
+ 1,
4588 elfcpp::DW_CFA_register
, 65, 0,
4589 elfcpp::DW_CFA_advance_loc
+ 7,
4590 elfcpp::DW_CFA_restore_extended
, 65
4593 // Describe __glink_PLTresolve use of LR, 32-bit version.
4594 static const unsigned char glink_eh_frame_fde_32
[] =
4596 0, 0, 0, 0, // Replaced with offset to .glink.
4597 0, 0, 0, 0, // Replaced with size of .glink.
4598 0, // Augmentation size.
4599 elfcpp::DW_CFA_advance_loc
+ 2,
4600 elfcpp::DW_CFA_register
, 65, 0,
4601 elfcpp::DW_CFA_advance_loc
+ 4,
4602 elfcpp::DW_CFA_restore_extended
, 65
4605 static const unsigned char default_fde
[] =
4607 0, 0, 0, 0, // Replaced with offset to stubs.
4608 0, 0, 0, 0, // Replaced with size of stubs.
4609 0, // Augmentation size.
4610 elfcpp::DW_CFA_nop
, // Pad.
4615 template<bool big_endian
>
4617 write_insn(unsigned char* p
, uint32_t v
)
4619 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4623 static inline unsigned int
4626 if (!parameters
->options().user_set_plt_align())
4627 return size
== 64 ? 32 : 8;
4628 return 1 << parameters
->options().plt_align();
4631 // Stub_table holds information about plt and long branch stubs.
4632 // Stubs are built in an area following some input section determined
4633 // by group_sections(). This input section is converted to a relaxed
4634 // input section allowing it to be resized to accommodate the stubs
4636 template<int size
, bool big_endian
>
4637 class Stub_table
: public Output_relaxed_input_section
4642 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4643 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4644 r2save_(0), localentry0_(0), tocoff_(0)
4649 unsigned int iter_
: 1;
4650 unsigned int notoc_
: 1;
4651 unsigned int toc_
: 1;
4652 unsigned int r2save_
: 1;
4653 unsigned int localentry0_
: 1;
4654 unsigned int tocoff_
: 8;
4656 struct Branch_stub_ent
4658 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4659 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4664 unsigned int iter_
: 1;
4665 unsigned int notoc_
: 1;
4666 unsigned int toc_
: 1;
4667 unsigned int save_res_
: 1;
4668 unsigned int tocoff_
: 8;
4670 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4671 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4673 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4674 Output_section
* output_section
,
4675 const Output_section::Input_section
* owner
,
4677 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4679 ->section_addralign(owner
->shndx())),
4680 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4681 orig_data_size_(owner
->current_data_size()),
4682 plt_size_(0), last_plt_size_(0),
4683 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4684 need_save_res_(false), need_resize_(false), resizing_(false),
4687 this->set_output_section(output_section
);
4689 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4690 new_relaxed
.push_back(this);
4691 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4694 // Add a plt call stub.
4696 add_plt_call_entry(Address
,
4697 const Sized_relobj_file
<size
, big_endian
>*,
4704 add_plt_call_entry(Address
,
4705 const Sized_relobj_file
<size
, big_endian
>*,
4711 // Find a given plt call stub.
4713 find_plt_call_entry(const Symbol
*) const;
4716 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4717 unsigned int) const;
4720 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4726 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4731 // Add a long branch stub.
4733 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4734 unsigned int, Address
, Address
, bool);
4736 const Branch_stub_ent
*
4737 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4741 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4743 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4744 if (max_branch_offset
== 0)
4746 gold_assert(from
!= invalid_address
);
4747 Address loc
= off
+ this->stub_address();
4748 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4752 clear_stubs(bool all
)
4754 this->plt_call_stubs_
.clear();
4755 this->plt_size_
= 0;
4756 this->long_branch_stubs_
.clear();
4757 this->branch_size_
= 0;
4758 this->need_save_res_
= false;
4761 this->last_plt_size_
= 0;
4762 this->last_branch_size_
= 0;
4768 { return need_resize_
; }
4771 set_resizing(bool val
)
4773 this->resizing_
= val
;
4776 this->need_resize_
= false;
4777 this->plt_size_
= 0;
4778 this->branch_size_
= 0;
4779 this->need_save_res_
= false;
4784 set_address_and_size(const Output_section
* os
, Address off
)
4786 Address start_off
= off
;
4787 off
+= this->orig_data_size_
;
4788 Address my_size
= this->plt_size_
+ this->branch_size_
;
4789 if (this->need_save_res_
)
4790 my_size
+= this->targ_
->savres_section()->data_size();
4792 off
= align_address(off
, this->stub_align());
4793 // Include original section size and alignment padding in size
4794 my_size
+= off
- start_off
;
4795 // Ensure new size is always larger than min size
4796 // threshold. Alignment requirement is included in "my_size", so
4797 // increase "my_size" does not invalidate alignment.
4798 if (my_size
< this->min_size_threshold_
)
4799 my_size
= this->min_size_threshold_
;
4800 this->reset_address_and_file_offset();
4801 this->set_current_data_size(my_size
);
4802 this->set_address_and_file_offset(os
->address() + start_off
,
4803 os
->offset() + start_off
);
4808 stub_address() const
4810 return align_address(this->address() + this->orig_data_size_
,
4811 this->stub_align());
4817 return align_address(this->offset() + this->orig_data_size_
,
4818 this->stub_align());
4823 { return this->plt_size_
; }
4827 { return this->branch_size_
; }
4830 set_min_size_threshold(Address min_size
)
4831 { this->min_size_threshold_
= min_size
; }
4834 define_stub_syms(Symbol_table
*);
4839 Output_section
* os
= this->output_section();
4840 if (os
->addralign() < this->stub_align())
4842 os
->set_addralign(this->stub_align());
4843 // FIXME: get rid of the insane checkpointing.
4844 // We can't increase alignment of the input section to which
4845 // stubs are attached; The input section may be .init which
4846 // is pasted together with other .init sections to form a
4847 // function. Aligning might insert zero padding resulting in
4848 // sigill. However we do need to increase alignment of the
4849 // output section so that the align_address() on offset in
4850 // set_address_and_size() adds the same padding as the
4851 // align_address() on address in stub_address().
4852 // What's more, we need this alignment for the layout done in
4853 // relaxation_loop_body() so that the output section starts at
4854 // a suitably aligned address.
4855 os
->checkpoint_set_addralign(this->stub_align());
4857 if (this->last_plt_size_
!= this->plt_size_
4858 || this->last_branch_size_
!= this->branch_size_
)
4860 this->last_plt_size_
= this->plt_size_
;
4861 this->last_branch_size_
= this->branch_size_
;
4867 // Add .eh_frame info for this stub section.
4869 add_eh_frame(Layout
* layout
);
4871 // Remove .eh_frame info for this stub section.
4873 remove_eh_frame(Layout
* layout
);
4875 Target_powerpc
<size
, big_endian
>*
4881 class Plt_stub_key_hash
;
4882 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4883 Plt_stub_key_hash
> Plt_stub_entries
;
4884 class Branch_stub_key
;
4885 class Branch_stub_key_hash
;
4886 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4887 Branch_stub_key_hash
> Branch_stub_entries
;
4889 // Alignment of stub section.
4893 unsigned int min_align
= size
== 64 ? 32 : 16;
4894 unsigned int user_align
= 1 << parameters
->options().plt_align();
4895 return std::max(user_align
, min_align
);
4898 // Return the plt offset for the given call stub.
4900 plt_off(typename
Plt_stub_entries::const_iterator p
,
4901 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4903 const Symbol
* gsym
= p
->first
.sym_
;
4905 return this->targ_
->plt_off(gsym
, sec
);
4908 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4909 unsigned int local_sym_index
= p
->first
.locsym_
;
4910 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4914 // Size of a given plt call stub.
4916 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4919 plt_call_align(unsigned int bytes
) const
4921 unsigned int align
= param_plt_align
<size
>();
4922 return (bytes
+ align
- 1) & -align
;
4925 // Return long branch stub size.
4927 branch_stub_size(typename
Branch_stub_entries::iterator p
,
4931 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
4934 build_tls_opt_tail(unsigned char* p
);
4937 plt_error(const Plt_stub_key
& p
);
4941 do_write(Output_file
*);
4943 // Plt call stub keys.
4947 Plt_stub_key(const Symbol
* sym
)
4948 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4951 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4952 unsigned int locsym_index
)
4953 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4956 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4958 unsigned int r_type
,
4960 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4963 this->addend_
= addend
;
4964 else if (parameters
->options().output_is_position_independent()
4965 && (r_type
== elfcpp::R_PPC_PLTREL24
4966 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4968 this->addend_
= addend
;
4969 if (this->addend_
>= 32768)
4970 this->object_
= object
;
4974 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4975 unsigned int locsym_index
,
4976 unsigned int r_type
,
4978 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
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
))
4985 this->addend_
= addend
;
4988 bool operator==(const Plt_stub_key
& that
) const
4990 return (this->sym_
== that
.sym_
4991 && this->object_
== that
.object_
4992 && this->addend_
== that
.addend_
4993 && this->locsym_
== that
.locsym_
);
4997 const Sized_relobj_file
<size
, big_endian
>* object_
;
4998 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4999 unsigned int locsym_
;
5002 class Plt_stub_key_hash
5005 size_t operator()(const Plt_stub_key
& ent
) const
5007 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5008 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5014 // Long branch stub keys.
5015 class Branch_stub_key
5018 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5019 : dest_(to
), toc_base_off_(0)
5022 toc_base_off_
= obj
->toc_base_offset();
5025 bool operator==(const Branch_stub_key
& that
) const
5027 return (this->dest_
== that
.dest_
5029 || this->toc_base_off_
== that
.toc_base_off_
));
5033 unsigned int toc_base_off_
;
5036 class Branch_stub_key_hash
5039 size_t operator()(const Branch_stub_key
& key
) const
5040 { return key
.dest_
^ key
.toc_base_off_
; }
5043 // In a sane world this would be a global.
5044 Target_powerpc
<size
, big_endian
>* targ_
;
5045 // Map sym/object/addend to stub offset.
5046 Plt_stub_entries plt_call_stubs_
;
5047 // Map destination address to stub offset.
5048 Branch_stub_entries long_branch_stubs_
;
5049 // size of input section
5050 section_size_type orig_data_size_
;
5052 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5053 // Some rare cases cause (PR/20529) fluctuation in stub table
5054 // size, which leads to an endless relax loop. This is to be fixed
5055 // by, after the first few iterations, allowing only increase of
5056 // stub table size. This variable sets the minimal possible size of
5057 // a stub table, it is zero for the first few iterations, then
5058 // increases monotonically.
5059 Address min_size_threshold_
;
5060 // Set if this stub group needs a copy of out-of-line register
5061 // save/restore functions.
5062 bool need_save_res_
;
5063 // Set when notoc_/r2save_ changes after sizing a stub
5065 // Set when resizing stubs
5067 // Per stub table unique identifier.
5071 // Add a plt call stub, if we do not already have one for this
5072 // sym/object/addend combo.
5074 template<int size
, bool big_endian
>
5076 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5078 const Sized_relobj_file
<size
, big_endian
>* object
,
5080 unsigned int r_type
,
5084 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5085 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5086 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5087 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5091 && this->targ_
->is_elfv2_localentry0(gsym
))
5093 p
.first
->second
.localentry0_
= 1;
5094 this->targ_
->set_has_localentry0();
5096 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5098 if (!p
.second
&& !p
.first
->second
.notoc_
5099 && (!this->targ_
->power10_stubs()
5100 || this->targ_
->power10_stubs_auto()))
5101 this->need_resize_
= true;
5102 p
.first
->second
.notoc_
= 1;
5106 if (!p
.second
&& !p
.first
->second
.toc_
)
5107 this->need_resize_
= true;
5108 p
.first
->second
.toc_
= 1;
5109 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5111 if (!p
.second
&& !p
.first
->second
.r2save_
)
5112 this->need_resize_
= true;
5113 p
.first
->second
.r2save_
= 1;
5117 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5119 if (this->resizing_
)
5121 p
.first
->second
.iter_
= 1;
5122 p
.first
->second
.off_
= this->plt_size_
;
5124 this->plt_size_
+= this->plt_call_size(p
.first
);
5125 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5126 this->targ_
->set_has_tls_get_addr_opt();
5127 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5129 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5132 template<int size
, bool big_endian
>
5134 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5136 const Sized_relobj_file
<size
, big_endian
>* object
,
5137 unsigned int locsym_index
,
5138 unsigned int r_type
,
5142 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5143 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5144 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5145 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5149 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5151 p
.first
->second
.localentry0_
= 1;
5152 this->targ_
->set_has_localentry0();
5154 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5156 if (!p
.second
&& !p
.first
->second
.notoc_
5157 && (!this->targ_
->power10_stubs()
5158 || this->targ_
->power10_stubs_auto()))
5159 this->need_resize_
= true;
5160 p
.first
->second
.notoc_
= 1;
5164 if (!p
.second
&& !p
.first
->second
.toc_
)
5165 this->need_resize_
= true;
5166 p
.first
->second
.toc_
= 1;
5167 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5169 if (!p
.second
&& !p
.first
->second
.r2save_
)
5170 this->need_resize_
= true;
5171 p
.first
->second
.r2save_
= 1;
5175 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5177 if (this->resizing_
)
5179 p
.first
->second
.iter_
= 1;
5180 p
.first
->second
.off_
= this->plt_size_
;
5182 this->plt_size_
+= this->plt_call_size(p
.first
);
5183 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5185 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5188 // Find a plt call stub.
5190 template<int size
, bool big_endian
>
5191 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5192 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5193 const Sized_relobj_file
<size
, big_endian
>* object
,
5195 unsigned int r_type
,
5196 Address addend
) const
5198 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5199 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5200 if (p
== this->plt_call_stubs_
.end())
5205 template<int size
, bool big_endian
>
5206 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5207 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5209 Plt_stub_key
key(gsym
);
5210 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5211 if (p
== this->plt_call_stubs_
.end())
5216 template<int size
, bool big_endian
>
5217 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5218 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5219 const Sized_relobj_file
<size
, big_endian
>* object
,
5220 unsigned int locsym_index
,
5221 unsigned int r_type
,
5222 Address addend
) const
5224 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5225 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5226 if (p
== this->plt_call_stubs_
.end())
5231 template<int size
, bool big_endian
>
5232 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5233 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5234 const Sized_relobj_file
<size
, big_endian
>* object
,
5235 unsigned int locsym_index
) const
5237 Plt_stub_key
key(object
, locsym_index
);
5238 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5239 if (p
== this->plt_call_stubs_
.end())
5244 // Add a long branch stub if we don't already have one to given
5247 template<int size
, bool big_endian
>
5249 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5250 const Powerpc_relobj
<size
, big_endian
>* object
,
5251 unsigned int r_type
,
5256 Branch_stub_key
key(object
, to
);
5257 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5258 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5259 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5260 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5263 if (!p
.second
&& !p
.first
->second
.notoc_
)
5264 this->need_resize_
= true;
5265 p
.first
->second
.notoc_
= true;
5269 if (!p
.second
&& !p
.first
->second
.toc_
)
5270 this->need_resize_
= true;
5271 p
.first
->second
.toc_
= true;
5273 gold_assert(save_res
== p
.first
->second
.save_res_
);
5274 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5276 if (this->resizing_
)
5278 p
.first
->second
.iter_
= 1;
5279 p
.first
->second
.off_
= this->branch_size_
;
5282 this->need_save_res_
= true;
5285 bool need_lt
= false;
5286 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5287 this->branch_size_
+= stub_size
;
5288 if (size
== 64 && need_lt
)
5289 this->targ_
->add_branch_lookup_table(to
);
5292 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5295 // Find long branch stub offset.
5297 template<int size
, bool big_endian
>
5298 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5299 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5300 const Powerpc_relobj
<size
, big_endian
>* object
,
5303 Branch_stub_key
key(object
, to
);
5304 typename
Branch_stub_entries::const_iterator p
5305 = this->long_branch_stubs_
.find(key
);
5306 if (p
== this->long_branch_stubs_
.end())
5311 template<bool big_endian
>
5313 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5317 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5318 else if (delta
< 256)
5320 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5321 fde
.push_back(delta
);
5323 else if (delta
< 65536)
5325 fde
.resize(fde
.size() + 3);
5326 unsigned char *p
= &*fde
.end() - 3;
5327 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5328 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5332 fde
.resize(fde
.size() + 5);
5333 unsigned char *p
= &*fde
.end() - 5;
5334 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5335 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5339 template<typename T
>
5341 stub_sort(T s1
, T s2
)
5343 return s1
->second
.off_
< s2
->second
.off_
;
5346 // Add .eh_frame info for this stub section. Unlike other linker
5347 // generated .eh_frame this is added late in the link, because we
5348 // only want the .eh_frame info if this particular stub section is
5351 template<int size
, bool big_endian
>
5353 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5356 || !parameters
->options().ld_generated_unwind_info())
5359 // Since we add stub .eh_frame info late, it must be placed
5360 // after all other linker generated .eh_frame info so that
5361 // merge mapping need not be updated for input sections.
5362 // There is no provision to use a different CIE to that used
5364 if (!this->targ_
->has_glink())
5367 typedef typename
Plt_stub_entries::iterator plt_iter
;
5368 std::vector
<plt_iter
> calls
;
5369 if (!this->plt_call_stubs_
.empty())
5370 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5371 cs
!= this->plt_call_stubs_
.end();
5373 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5374 && cs
->second
.r2save_
5375 && !cs
->second
.localentry0_
)
5376 || (cs
->second
.notoc_
5377 && !this->targ_
->power10_stubs()))
5378 calls
.push_back(cs
);
5379 if (calls
.size() > 1)
5380 std::stable_sort(calls
.begin(), calls
.end(),
5381 stub_sort
<plt_iter
>);
5383 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5384 std::vector
<branch_iter
> branches
;
5385 if (!this->long_branch_stubs_
.empty()
5386 && !this->targ_
->power10_stubs())
5387 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5388 bs
!= this->long_branch_stubs_
.end();
5390 if (bs
->second
.notoc_
)
5391 branches
.push_back(bs
);
5392 if (branches
.size() > 1)
5393 std::stable_sort(branches
.begin(), branches
.end(),
5394 stub_sort
<branch_iter
>);
5396 if (calls
.empty() && branches
.empty())
5399 unsigned int last_eh_loc
= 0;
5400 // offset pcrel sdata4, size udata4, and augmentation size byte.
5401 std::vector
<unsigned char> fde(9, 0);
5403 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5405 plt_iter cs
= calls
[i
];
5406 unsigned int off
= cs
->second
.off_
;
5407 // The __tls_get_addr_opt call stub needs to describe where
5408 // it saves LR, to support exceptions that might be thrown
5409 // from __tls_get_addr, and to support asynchronous exceptions.
5410 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5413 if (cs
->second
.r2save_
5414 && !cs
->second
.localentry0_
)
5417 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5418 fde
.resize(fde
.size() + 6);
5419 unsigned char* p
= &*fde
.end() - 6;
5420 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5422 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5423 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5424 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5425 *p
++ = elfcpp::DW_CFA_restore_extended
;
5427 last_eh_loc
= off
+ delta
;
5431 // notoc stubs also should describe LR changes, to support
5432 // asynchronous exceptions.
5433 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5434 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5435 fde
.resize(fde
.size() + 6);
5436 unsigned char* p
= &*fde
.end() - 6;
5437 *p
++ = elfcpp::DW_CFA_register
;
5440 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5441 *p
++ = elfcpp::DW_CFA_restore_extended
;
5443 last_eh_loc
= off
+ 8;
5446 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5448 branch_iter bs
= branches
[i
];
5449 unsigned int off
= bs
->second
.off_
+ 8;
5450 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5451 fde
.resize(fde
.size() + 6);
5452 unsigned char* p
= &*fde
.end() - 6;
5453 *p
++ = elfcpp::DW_CFA_register
;
5456 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5457 *p
++ = elfcpp::DW_CFA_restore_extended
;
5459 last_eh_loc
= off
+ 8;
5462 layout
->add_eh_frame_for_plt(this,
5463 Eh_cie
<size
>::eh_frame_cie
,
5464 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5465 &*fde
.begin(), fde
.size());
5468 template<int size
, bool big_endian
>
5470 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5473 && parameters
->options().ld_generated_unwind_info()
5474 && this->targ_
->has_glink())
5475 layout
->remove_eh_frame_for_plt(this,
5476 Eh_cie
<size
>::eh_frame_cie
,
5477 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5480 // A class to handle .glink.
5482 template<int size
, bool big_endian
>
5483 class Output_data_glink
: public Output_section_data
5486 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5487 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5489 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5490 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5491 end_branch_table_(), ge_size_(0)
5495 add_eh_frame(Layout
* layout
);
5498 add_global_entry(const Symbol
*);
5501 find_global_entry(const Symbol
*) const;
5504 global_entry_align(unsigned int off
) const
5506 unsigned int align
= param_plt_align
<size
>();
5507 return (off
+ align
- 1) & -align
;
5511 global_entry_off() const
5513 return this->global_entry_align(this->end_branch_table_
);
5517 global_entry_address() const
5519 gold_assert(this->is_data_size_valid());
5520 return this->address() + this->global_entry_off();
5524 pltresolve_size() const
5528 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
5533 // Write to a map file.
5535 do_print_to_mapfile(Mapfile
* mapfile
) const
5536 { mapfile
->print_output_data(this, _("** glink")); }
5540 set_final_data_size();
5544 do_write(Output_file
*);
5546 // Allows access to .got and .plt for do_write.
5547 Target_powerpc
<size
, big_endian
>* targ_
;
5549 // Map sym to stub offset.
5550 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5551 Global_entry_stub_entries global_entry_stubs_
;
5553 unsigned int end_branch_table_
, ge_size_
;
5556 template<int size
, bool big_endian
>
5558 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5560 if (!parameters
->options().ld_generated_unwind_info())
5565 if (this->targ_
->abiversion() < 2)
5566 layout
->add_eh_frame_for_plt(this,
5567 Eh_cie
<64>::eh_frame_cie
,
5568 sizeof (Eh_cie
<64>::eh_frame_cie
),
5569 glink_eh_frame_fde_64v1
,
5570 sizeof (glink_eh_frame_fde_64v1
));
5572 layout
->add_eh_frame_for_plt(this,
5573 Eh_cie
<64>::eh_frame_cie
,
5574 sizeof (Eh_cie
<64>::eh_frame_cie
),
5575 glink_eh_frame_fde_64v2
,
5576 sizeof (glink_eh_frame_fde_64v2
));
5580 // 32-bit .glink can use the default since the CIE return
5581 // address reg, LR, is valid.
5582 layout
->add_eh_frame_for_plt(this,
5583 Eh_cie
<32>::eh_frame_cie
,
5584 sizeof (Eh_cie
<32>::eh_frame_cie
),
5586 sizeof (default_fde
));
5587 // Except where LR is used in a PIC __glink_PLTresolve.
5588 if (parameters
->options().output_is_position_independent())
5589 layout
->add_eh_frame_for_plt(this,
5590 Eh_cie
<32>::eh_frame_cie
,
5591 sizeof (Eh_cie
<32>::eh_frame_cie
),
5592 glink_eh_frame_fde_32
,
5593 sizeof (glink_eh_frame_fde_32
));
5597 template<int size
, bool big_endian
>
5599 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5601 unsigned int off
= this->global_entry_align(this->ge_size_
);
5602 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5603 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5605 this->ge_size_
= off
+ 16;
5608 template<int size
, bool big_endian
>
5609 typename Output_data_glink
<size
, big_endian
>::Address
5610 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5612 typename
Global_entry_stub_entries::const_iterator p
5613 = this->global_entry_stubs_
.find(gsym
);
5614 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5617 template<int size
, bool big_endian
>
5619 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5621 unsigned int count
= this->targ_
->plt_entry_count();
5622 section_size_type total
= 0;
5628 // space for branch table
5629 total
+= 4 * (count
- 1);
5631 total
+= -total
& 15;
5632 total
+= this->pltresolve_size();
5636 total
+= this->pltresolve_size();
5638 // space for branch table
5640 if (this->targ_
->abiversion() < 2)
5644 total
+= 4 * (count
- 0x8000);
5648 this->end_branch_table_
= total
;
5649 total
= this->global_entry_align(total
);
5650 total
+= this->ge_size_
;
5652 this->set_data_size(total
);
5655 // Define symbols on stubs, identifying the stub.
5657 template<int size
, bool big_endian
>
5659 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5661 if (!this->plt_call_stubs_
.empty())
5663 // The key for the plt call stub hash table includes addresses,
5664 // therefore traversal order depends on those addresses, which
5665 // can change between runs if gold is a PIE. Unfortunately the
5666 // output .symtab ordering depends on the order in which symbols
5667 // are added to the linker symtab. We want reproducible output
5668 // so must sort the call stub symbols.
5669 typedef typename
Plt_stub_entries::iterator plt_iter
;
5670 std::vector
<plt_iter
> sorted
;
5671 sorted
.resize(this->plt_call_stubs_
.size());
5673 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5674 cs
!= this->plt_call_stubs_
.end();
5676 sorted
[cs
->second
.indx_
] = cs
;
5678 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5680 plt_iter cs
= sorted
[i
];
5683 if (cs
->first
.addend_
!= 0)
5684 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5687 if (cs
->first
.object_
)
5689 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5690 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5691 sprintf(obj
, "%x:", ppcobj
->uniq());
5694 const char *symname
;
5695 if (cs
->first
.sym_
== NULL
)
5697 sprintf(localname
, "%x", cs
->first
.locsym_
);
5698 symname
= localname
;
5700 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5701 symname
= this->targ_
->tls_get_addr_opt()->name();
5703 symname
= cs
->first
.sym_
->name();
5704 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5705 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5707 = this->stub_address() - this->address() + cs
->second
.off_
;
5708 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5709 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5713 typedef typename
Branch_stub_entries::iterator branch_iter
;
5714 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5715 bs
!= this->long_branch_stubs_
.end();
5718 if (bs
->second
.save_res_
)
5721 char* name
= new char[8 + 13 + 16 + 1];
5722 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5723 static_cast<unsigned long long>(bs
->first
.dest_
));
5724 Address value
= (this->stub_address() - this->address()
5725 + this->plt_size_
+ bs
->second
.off_
);
5726 bool need_lt
= false;
5727 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5728 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5732 // Emit the start of a __tls_get_addr_opt plt call stub.
5734 template<int size
, bool big_endian
>
5736 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5739 unsigned char* p
= *pp
;
5742 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5744 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5746 write_insn
<big_endian
>(p
, mr_0_3
);
5748 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5750 write_insn
<big_endian
>(p
, add_3_12_13
);
5752 write_insn
<big_endian
>(p
, beqlr
);
5754 write_insn
<big_endian
>(p
, mr_3_0
);
5758 write_insn
<big_endian
>(p
, mflr_11
);
5760 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5766 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5768 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5770 write_insn
<big_endian
>(p
, mr_0_3
);
5772 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5774 write_insn
<big_endian
>(p
, add_3_12_2
);
5776 write_insn
<big_endian
>(p
, beqlr
);
5778 write_insn
<big_endian
>(p
, mr_3_0
);
5780 write_insn
<big_endian
>(p
, nop
);
5786 // Emit the tail of a __tls_get_addr_opt plt call stub.
5788 template<int size
, bool big_endian
>
5790 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5792 write_insn
<big_endian
>(p
, bctrl
);
5794 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5796 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5798 write_insn
<big_endian
>(p
, mtlr_11
);
5800 write_insn
<big_endian
>(p
, blr
);
5803 // Emit pc-relative plt call stub code.
5805 template<bool big_endian
>
5806 static unsigned char*
5807 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5810 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5815 write_insn
<big_endian
>(p
, nop
);
5823 write_insn
<big_endian
>(p
, insn
>> 32);
5825 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5827 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5830 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5834 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5837 insn
= paddi_12_pc
| d34(off
);
5838 write_insn
<big_endian
>(p
, insn
>> 32);
5840 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5844 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5848 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5850 write_insn
<big_endian
>(p
, add_12_11_12
);
5855 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5857 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5861 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5864 insn
= paddi_12_pc
| d34(off
);
5865 write_insn
<big_endian
>(p
, insn
>> 32);
5867 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5871 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5875 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5877 write_insn
<big_endian
>(p
, add_12_11_12
);
5883 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5884 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5889 // lis %r12,xxx-1b@highest
5890 // ori %r12,%r12,xxx-1b@higher
5891 // sldi %r12,%r12,32
5892 // oris %r12,%r12,xxx-1b@high
5893 // ori %r12,%r12,xxx-1b@l
5894 // add/ldx %r12,%r11,%r12
5896 template<bool big_endian
>
5897 static unsigned char*
5898 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5900 write_insn
<big_endian
>(p
, mflr_12
);
5902 write_insn
<big_endian
>(p
, bcl_20_31
);
5904 write_insn
<big_endian
>(p
, mflr_11
);
5906 write_insn
<big_endian
>(p
, mtlr_12
);
5908 if (off
+ 0x8000 < 0x10000)
5911 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5913 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5915 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5917 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5920 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5922 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5926 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5928 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5933 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5935 if (((off
>> 32) & 0xffff) != 0)
5937 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5941 if (((off
>> 32) & 0xffffffffULL
) != 0)
5943 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5948 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5953 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5957 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5959 write_insn
<big_endian
>(p
, add_12_11_12
);
5965 // Size of a given plt call stub.
5967 template<int size
, bool big_endian
>
5969 Stub_table
<size
, big_endian
>::plt_call_size(
5970 typename
Plt_stub_entries::iterator p
) const
5974 const Symbol
* gsym
= p
->first
.sym_
;
5976 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
5979 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5980 uint64_t plt_addr
= this->plt_off(p
, &plt
);
5981 plt_addr
+= plt
->address();
5982 if (this->targ_
->power10_stubs()
5983 && this->targ_
->power10_stubs_auto())
5985 unsigned int bytes
= 0;
5986 if (p
->second
.notoc_
)
5988 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
5990 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
5991 uint64_t odd
= from
& 4;
5992 uint64_t off
= plt_addr
- from
;
5993 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5994 bytes
+= odd
+ 4 * 4;
5995 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5999 bytes
= this->plt_call_align(bytes
);
6001 unsigned int tail
= 0;
6004 p
->second
.tocoff_
= bytes
;
6005 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6008 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6014 if (p
->second
.r2save_
)
6017 = this->targ_
->got_section()->output_section()->address();
6018 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6019 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6020 got_addr
+= ppcobj
->toc_base_offset();
6021 uint64_t off
= plt_addr
- got_addr
;
6022 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6024 return bytes
+ tail
;
6028 unsigned int bytes
= 0;
6029 unsigned int tail
= 0;
6030 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6033 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6040 if (p
->second
.r2save_
)
6043 if (this->targ_
->power10_stubs())
6045 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6046 uint64_t odd
= from
& 4;
6047 uint64_t off
= plt_addr
- from
;
6048 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6049 bytes
+= odd
+ 4 * 4;
6050 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6054 return bytes
+ tail
;
6057 if (p
->second
.notoc_
)
6059 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6060 uint64_t off
= plt_addr
- from
;
6061 if (off
+ 0x8000 < 0x10000)
6063 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6068 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6069 && ((off
>> 32) & 0xffff) != 0)
6071 if (((off
>> 32) & 0xffffffffULL
) != 0)
6078 return bytes
+ tail
;
6081 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6082 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6083 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6084 got_addr
+= ppcobj
->toc_base_offset();
6085 uint64_t off
= plt_addr
- got_addr
;
6086 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6087 if (this->targ_
->abiversion() < 2)
6089 bool static_chain
= parameters
->options().plt_static_chain();
6090 bool thread_safe
= this->targ_
->plt_thread_safe();
6094 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6096 return bytes
+ tail
;
6100 // Return long branch stub size.
6102 template<int size
, bool big_endian
>
6104 Stub_table
<size
, big_endian
>::branch_stub_size(
6105 typename
Branch_stub_entries::iterator p
,
6108 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6111 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6113 if (parameters
->options().output_is_position_independent())
6118 uint64_t off
= p
->first
.dest_
- loc
;
6119 unsigned int bytes
= 0;
6120 if (p
->second
.notoc_
)
6122 if (this->targ_
->power10_stubs())
6124 Address odd
= loc
& 4;
6125 if (off
+ (1 << 25) < 2 << 25)
6127 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6129 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6133 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6135 p
->second
.tocoff_
= bytes
;
6140 if (off
+ 0x8000 < 0x10000)
6142 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6144 if (off
+ 24 + (1 << 25) < 2 << 25)
6150 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6151 && ((off
>> 32) & 0xffff) != 0)
6153 if (((off
>> 32) & 0xffffffffULL
) != 0)
6163 if (off
+ (1 << 25) < 2 << 25)
6165 if (!this->targ_
->power10_stubs()
6166 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6171 template<int size
, bool big_endian
>
6173 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6176 gold_error(_("linkage table error against `%s'"),
6177 p
.sym_
->demangled_name().c_str());
6179 gold_error(_("linkage table error against `%s:[local %u]'"),
6180 p
.object_
->name().c_str(),
6184 // Write out plt and long branch stub code.
6186 template<int size
, bool big_endian
>
6188 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6190 if (this->plt_call_stubs_
.empty()
6191 && this->long_branch_stubs_
.empty())
6194 const section_size_type start_off
= this->offset();
6195 const section_size_type off
= this->stub_offset();
6196 const section_size_type oview_size
=
6197 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6198 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6202 && this->targ_
->power10_stubs())
6204 const Output_data_got_powerpc
<size
, big_endian
>* got
6205 = this->targ_
->got_section();
6206 Address got_os_addr
= got
->output_section()->address();
6208 if (!this->plt_call_stubs_
.empty())
6210 // Write out plt call stubs.
6211 typename
Plt_stub_entries::const_iterator cs
;
6212 for (cs
= this->plt_call_stubs_
.begin();
6213 cs
!= this->plt_call_stubs_
.end();
6216 p
= oview
+ cs
->second
.off_
;
6217 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6218 Address pltoff
= this->plt_off(cs
, &plt
);
6219 Address plt_addr
= pltoff
+ plt
->address();
6220 if (this->targ_
->power10_stubs_auto())
6222 if (cs
->second
.notoc_
)
6224 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6225 this->build_tls_opt_head(&p
, false);
6226 Address from
= this->stub_address() + (p
- oview
);
6227 Address delta
= plt_addr
- from
;
6228 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6230 write_insn
<big_endian
>(p
, mtctr_12
);
6232 write_insn
<big_endian
>(p
, bctr
);
6234 p
= oview
+ this->plt_call_align(p
- oview
);
6236 if (cs
->second
.toc_
)
6238 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6241 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6242 this->build_tls_opt_head(&p
, save_lr
);
6244 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6245 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6247 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6248 Address off
= plt_addr
- got_addr
;
6250 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6251 this->plt_error(cs
->first
);
6253 if (cs
->second
.r2save_
)
6255 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6260 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6262 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6267 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6270 write_insn
<big_endian
>(p
, mtctr_12
);
6272 if (cs
->second
.r2save_
6273 && !cs
->second
.localentry0_
6274 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6275 this->build_tls_opt_tail(p
);
6277 write_insn
<big_endian
>(p
, bctr
);
6282 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6285 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6286 this->build_tls_opt_head(&p
, save_lr
);
6288 if (cs
->second
.r2save_
)
6290 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6293 Address from
= this->stub_address() + (p
- oview
);
6294 Address delta
= plt_addr
- from
;
6295 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6296 write_insn
<big_endian
>(p
, mtctr_12
);
6298 if (cs
->second
.r2save_
6299 && !cs
->second
.localentry0_
6300 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6301 this->build_tls_opt_tail(p
);
6303 write_insn
<big_endian
>(p
, bctr
);
6308 // Write out long branch stubs.
6309 typename
Branch_stub_entries::const_iterator bs
;
6310 for (bs
= this->long_branch_stubs_
.begin();
6311 bs
!= this->long_branch_stubs_
.end();
6314 if (bs
->second
.save_res_
)
6316 Address off
= this->plt_size_
+ bs
->second
.off_
;
6318 Address loc
= this->stub_address() + off
;
6319 Address delta
= bs
->first
.dest_
- loc
;
6320 if (this->targ_
->power10_stubs_auto())
6322 if (bs
->second
.notoc_
)
6324 unsigned char* startp
= p
;
6325 p
= build_power10_offset
<big_endian
>(p
, delta
,
6327 delta
-= p
- startp
;
6329 if (delta
+ (1 << 25) < 2 << 25)
6330 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6333 write_insn
<big_endian
>(p
, mtctr_12
);
6335 write_insn
<big_endian
>(p
, bctr
);
6338 delta
-= p
- startp
;
6340 if (bs
->second
.toc_
)
6342 if (delta
+ (1 << 25) >= 2 << 25)
6345 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6346 gold_assert(brlt_addr
!= invalid_address
);
6347 brlt_addr
+= this->targ_
->brlt_section()->address();
6348 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6349 Address brltoff
= brlt_addr
- got_addr
;
6350 if (ha(brltoff
) == 0)
6352 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6357 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6359 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6363 if (delta
+ (1 << 25) < 2 << 25)
6364 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6367 write_insn
<big_endian
>(p
, mtctr_12
);
6369 write_insn
<big_endian
>(p
, bctr
);
6375 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6377 unsigned char* startp
= p
;
6378 p
= build_power10_offset
<big_endian
>(p
, delta
,
6380 delta
-= p
- startp
;
6382 if (delta
+ (1 << 25) < 2 << 25)
6383 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6386 write_insn
<big_endian
>(p
, mtctr_12
);
6388 write_insn
<big_endian
>(p
, bctr
);
6393 else if (size
== 64)
6395 const Output_data_got_powerpc
<size
, big_endian
>* got
6396 = this->targ_
->got_section();
6397 Address got_os_addr
= got
->output_section()->address();
6399 if (!this->plt_call_stubs_
.empty()
6400 && this->targ_
->abiversion() >= 2)
6402 // Write out plt call stubs for ELFv2.
6403 typename
Plt_stub_entries::const_iterator cs
;
6404 for (cs
= this->plt_call_stubs_
.begin();
6405 cs
!= this->plt_call_stubs_
.end();
6408 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6409 Address pltoff
= this->plt_off(cs
, &plt
);
6410 Address plt_addr
= pltoff
+ plt
->address();
6412 p
= oview
+ cs
->second
.off_
;
6413 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6415 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6416 this->build_tls_opt_head(&p
, save_lr
);
6418 if (cs
->second
.r2save_
)
6420 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6423 if (cs
->second
.notoc_
)
6425 Address from
= this->stub_address() + (p
- oview
) + 8;
6426 Address off
= plt_addr
- from
;
6427 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6431 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6432 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6433 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6434 Address off
= plt_addr
- got_addr
;
6436 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6437 this->plt_error(cs
->first
);
6441 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6443 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6448 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6452 write_insn
<big_endian
>(p
, mtctr_12
);
6454 if (cs
->second
.r2save_
6455 && !cs
->second
.localentry0_
6456 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6457 this->build_tls_opt_tail(p
);
6459 write_insn
<big_endian
>(p
, bctr
);
6462 else if (!this->plt_call_stubs_
.empty())
6464 // Write out plt call stubs for ELFv1.
6465 typename
Plt_stub_entries::const_iterator cs
;
6466 for (cs
= this->plt_call_stubs_
.begin();
6467 cs
!= this->plt_call_stubs_
.end();
6470 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6471 Address pltoff
= this->plt_off(cs
, &plt
);
6472 Address plt_addr
= pltoff
+ plt
->address();
6473 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6474 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6475 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6476 Address off
= plt_addr
- got_addr
;
6478 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6479 || cs
->second
.notoc_
)
6480 this->plt_error(cs
->first
);
6482 bool static_chain
= parameters
->options().plt_static_chain();
6483 bool thread_safe
= this->targ_
->plt_thread_safe();
6484 bool use_fake_dep
= false;
6485 Address cmp_branch_off
= 0;
6488 unsigned int pltindex
6489 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6490 / this->targ_
->plt_entry_size());
6492 = (this->targ_
->glink_section()->pltresolve_size()
6494 if (pltindex
> 32768)
6495 glinkoff
+= (pltindex
- 32768) * 4;
6497 = this->targ_
->glink_section()->address() + glinkoff
;
6499 = (this->stub_address() + cs
->second
.off_
+ 20
6500 + 4 * cs
->second
.r2save_
6501 + 4 * (ha(off
) != 0)
6502 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6503 + 4 * static_chain
);
6504 cmp_branch_off
= to
- from
;
6505 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6508 p
= oview
+ cs
->second
.off_
;
6509 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6511 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6512 this->build_tls_opt_head(&p
, save_lr
);
6513 use_fake_dep
= thread_safe
;
6515 if (cs
->second
.r2save_
)
6517 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6522 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6524 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6526 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6528 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6532 write_insn
<big_endian
>(p
, mtctr_12
);
6536 write_insn
<big_endian
>(p
, xor_2_12_12
);
6538 write_insn
<big_endian
>(p
, add_11_11_2
);
6541 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6545 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6551 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6553 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6555 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6559 write_insn
<big_endian
>(p
, mtctr_12
);
6563 write_insn
<big_endian
>(p
, xor_11_12_12
);
6565 write_insn
<big_endian
>(p
, add_2_2_11
);
6570 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6573 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6576 if (cs
->second
.r2save_
6577 && !cs
->second
.localentry0_
6578 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6579 this->build_tls_opt_tail(p
);
6580 else if (thread_safe
&& !use_fake_dep
)
6582 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6584 write_insn
<big_endian
>(p
, bnectr_p4
);
6586 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6589 write_insn
<big_endian
>(p
, bctr
);
6593 // Write out long branch stubs.
6594 typename
Branch_stub_entries::const_iterator bs
;
6595 for (bs
= this->long_branch_stubs_
.begin();
6596 bs
!= this->long_branch_stubs_
.end();
6599 if (bs
->second
.save_res_
)
6601 Address off
= this->plt_size_
+ bs
->second
.off_
;
6603 Address loc
= this->stub_address() + off
;
6604 Address delta
= bs
->first
.dest_
- loc
;
6605 if (bs
->second
.notoc_
)
6607 unsigned char* startp
= p
;
6608 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6609 delta
-= p
- startp
;
6611 else if (delta
+ (1 << 25) >= 2 << 25)
6614 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6615 gold_assert(brlt_addr
!= invalid_address
);
6616 brlt_addr
+= this->targ_
->brlt_section()->address();
6617 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6618 Address brltoff
= brlt_addr
- got_addr
;
6619 if (ha(brltoff
) == 0)
6621 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6626 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6628 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6632 if (delta
+ (1 << 25) < 2 << 25)
6633 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6636 write_insn
<big_endian
>(p
, mtctr_12
);
6638 write_insn
<big_endian
>(p
, bctr
);
6644 if (!this->plt_call_stubs_
.empty())
6646 // The address of _GLOBAL_OFFSET_TABLE_.
6647 Address g_o_t
= invalid_address
;
6649 // Write out plt call stubs.
6650 typename
Plt_stub_entries::const_iterator cs
;
6651 for (cs
= this->plt_call_stubs_
.begin();
6652 cs
!= this->plt_call_stubs_
.end();
6655 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6656 Address plt_addr
= this->plt_off(cs
, &plt
);
6657 plt_addr
+= plt
->address();
6659 p
= oview
+ cs
->second
.off_
;
6660 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6661 this->build_tls_opt_head(&p
, false);
6662 if (parameters
->options().output_is_position_independent())
6665 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6666 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6667 (cs
->first
.object_
));
6668 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6670 unsigned int got2
= ppcobj
->got2_shndx();
6671 got_addr
= ppcobj
->get_output_section_offset(got2
);
6672 gold_assert(got_addr
!= invalid_address
);
6673 got_addr
+= (ppcobj
->output_section(got2
)->address()
6674 + cs
->first
.addend_
);
6678 if (g_o_t
== invalid_address
)
6680 const Output_data_got_powerpc
<size
, big_endian
>* got
6681 = this->targ_
->got_section();
6682 g_o_t
= got
->address() + got
->g_o_t();
6687 Address off
= plt_addr
- got_addr
;
6689 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6692 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6694 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6699 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6701 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6704 write_insn
<big_endian
>(p
, mtctr_11
);
6706 write_insn
<big_endian
>(p
, bctr
);
6710 // Write out long branch stubs.
6711 typename
Branch_stub_entries::const_iterator bs
;
6712 for (bs
= this->long_branch_stubs_
.begin();
6713 bs
!= this->long_branch_stubs_
.end();
6716 if (bs
->second
.save_res_
)
6718 Address off
= this->plt_size_
+ bs
->second
.off_
;
6720 Address loc
= this->stub_address() + off
;
6721 Address delta
= bs
->first
.dest_
- loc
;
6722 if (delta
+ (1 << 25) < 2 << 25)
6723 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6724 else if (!parameters
->options().output_is_position_independent())
6726 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6728 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6733 write_insn
<big_endian
>(p
, mflr_0
);
6735 write_insn
<big_endian
>(p
, bcl_20_31
);
6737 write_insn
<big_endian
>(p
, mflr_12
);
6739 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6741 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6743 write_insn
<big_endian
>(p
, mtlr_0
);
6746 write_insn
<big_endian
>(p
, mtctr_12
);
6748 write_insn
<big_endian
>(p
, bctr
);
6751 if (this->need_save_res_
)
6753 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6754 memcpy (p
, this->targ_
->savres_section()->contents(),
6755 this->targ_
->savres_section()->data_size());
6759 // Write out .glink.
6761 template<int size
, bool big_endian
>
6763 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6765 const section_size_type off
= this->offset();
6766 const section_size_type oview_size
=
6767 convert_to_section_size_type(this->data_size());
6768 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6771 // The base address of the .plt section.
6772 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6773 Address plt_base
= this->targ_
->plt_section()->address();
6777 if (this->end_branch_table_
!= 0)
6779 // Write pltresolve stub.
6781 Address after_bcl
= this->address() + 16;
6782 Address pltoff
= plt_base
- after_bcl
;
6784 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6786 if (this->targ_
->abiversion() < 2)
6788 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6789 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6790 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6791 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6792 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6793 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6794 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6795 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6796 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6797 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6801 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6802 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6803 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6804 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6805 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6806 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6807 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6808 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6809 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
6810 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6811 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6812 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6813 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6815 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6816 gold_assert(p
== oview
+ this->pltresolve_size());
6818 // Write lazy link call stubs.
6820 while (p
< oview
+ this->end_branch_table_
)
6822 if (this->targ_
->abiversion() < 2)
6826 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6830 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6831 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6834 uint32_t branch_off
= 8 - (p
- oview
);
6835 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6840 Address plt_base
= this->targ_
->plt_section()->address();
6841 Address iplt_base
= invalid_address
;
6842 unsigned int global_entry_off
= this->global_entry_off();
6843 Address global_entry_base
= this->address() + global_entry_off
;
6844 typename
Global_entry_stub_entries::const_iterator ge
;
6845 for (ge
= this->global_entry_stubs_
.begin();
6846 ge
!= this->global_entry_stubs_
.end();
6849 p
= oview
+ global_entry_off
+ ge
->second
;
6850 Address plt_addr
= ge
->first
->plt_offset();
6851 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6852 && ge
->first
->can_use_relative_reloc(false))
6854 if (iplt_base
== invalid_address
)
6855 iplt_base
= this->targ_
->iplt_section()->address();
6856 plt_addr
+= iplt_base
;
6859 plt_addr
+= plt_base
;
6860 Address my_addr
= global_entry_base
+ ge
->second
;
6861 Address off
= plt_addr
- my_addr
;
6863 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6864 gold_error(_("linkage table error against `%s'"),
6865 ge
->first
->demangled_name().c_str());
6867 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6868 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6869 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6870 write_insn
<big_endian
>(p
, bctr
);
6875 const Output_data_got_powerpc
<size
, big_endian
>* got
6876 = this->targ_
->got_section();
6877 // The address of _GLOBAL_OFFSET_TABLE_.
6878 Address g_o_t
= got
->address() + got
->g_o_t();
6880 // Write out pltresolve branch table.
6882 unsigned int the_end
= oview_size
- this->pltresolve_size();
6883 unsigned char* end_p
= oview
+ the_end
;
6884 while (p
< end_p
- 8 * 4)
6885 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6887 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6889 // Write out pltresolve call stub.
6890 end_p
= oview
+ oview_size
;
6891 if (parameters
->options().output_is_position_independent())
6893 Address res0_off
= 0;
6894 Address after_bcl_off
= the_end
+ 12;
6895 Address bcl_res0
= after_bcl_off
- res0_off
;
6897 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6899 write_insn
<big_endian
>(p
, mflr_0
);
6901 write_insn
<big_endian
>(p
, bcl_20_31
);
6903 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6905 write_insn
<big_endian
>(p
, mflr_12
);
6907 write_insn
<big_endian
>(p
, mtlr_0
);
6909 write_insn
<big_endian
>(p
, sub_11_11_12
);
6912 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6914 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6916 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6918 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6920 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6924 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6926 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6929 write_insn
<big_endian
>(p
, mtctr_0
);
6931 write_insn
<big_endian
>(p
, add_0_11_11
);
6933 write_insn
<big_endian
>(p
, add_11_0_11
);
6937 Address res0
= this->address();
6939 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6941 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6943 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6944 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6946 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6948 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6950 write_insn
<big_endian
>(p
, mtctr_0
);
6952 write_insn
<big_endian
>(p
, add_0_11_11
);
6954 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6955 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6957 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6959 write_insn
<big_endian
>(p
, add_11_0_11
);
6962 write_insn
<big_endian
>(p
, bctr
);
6966 write_insn
<big_endian
>(p
, nop
);
6971 of
->write_output_view(off
, oview_size
, oview
);
6975 // A class to handle linker generated save/restore functions.
6977 template<int size
, bool big_endian
>
6978 class Output_data_save_res
: public Output_section_data_build
6981 Output_data_save_res(Symbol_table
* symtab
);
6983 const unsigned char*
6990 // Write to a map file.
6992 do_print_to_mapfile(Mapfile
* mapfile
) const
6993 { mapfile
->print_output_data(this, _("** save/restore")); }
6996 do_write(Output_file
*);
6999 // The maximum size of save/restore contents.
7000 static const unsigned int savres_max
= 218*4;
7003 savres_define(Symbol_table
* symtab
,
7005 unsigned int lo
, unsigned int hi
,
7006 unsigned char* write_ent(unsigned char*, int),
7007 unsigned char* write_tail(unsigned char*, int));
7009 unsigned char *contents_
;
7012 template<bool big_endian
>
7013 static unsigned char*
7014 savegpr0(unsigned char* p
, int r
)
7016 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7017 write_insn
<big_endian
>(p
, insn
);
7021 template<bool big_endian
>
7022 static unsigned char*
7023 savegpr0_tail(unsigned char* p
, int r
)
7025 p
= savegpr0
<big_endian
>(p
, r
);
7026 uint32_t insn
= std_0_1
+ 16;
7027 write_insn
<big_endian
>(p
, insn
);
7029 write_insn
<big_endian
>(p
, blr
);
7033 template<bool big_endian
>
7034 static unsigned char*
7035 restgpr0(unsigned char* p
, int r
)
7037 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7038 write_insn
<big_endian
>(p
, insn
);
7042 template<bool big_endian
>
7043 static unsigned char*
7044 restgpr0_tail(unsigned char* p
, int r
)
7046 uint32_t insn
= ld_0_1
+ 16;
7047 write_insn
<big_endian
>(p
, insn
);
7049 p
= restgpr0
<big_endian
>(p
, r
);
7050 write_insn
<big_endian
>(p
, mtlr_0
);
7054 p
= restgpr0
<big_endian
>(p
, 30);
7055 p
= restgpr0
<big_endian
>(p
, 31);
7057 write_insn
<big_endian
>(p
, blr
);
7061 template<bool big_endian
>
7062 static unsigned char*
7063 savegpr1(unsigned char* p
, int r
)
7065 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7066 write_insn
<big_endian
>(p
, insn
);
7070 template<bool big_endian
>
7071 static unsigned char*
7072 savegpr1_tail(unsigned char* p
, int r
)
7074 p
= savegpr1
<big_endian
>(p
, r
);
7075 write_insn
<big_endian
>(p
, blr
);
7079 template<bool big_endian
>
7080 static unsigned char*
7081 restgpr1(unsigned char* p
, int r
)
7083 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7084 write_insn
<big_endian
>(p
, insn
);
7088 template<bool big_endian
>
7089 static unsigned char*
7090 restgpr1_tail(unsigned char* p
, int r
)
7092 p
= restgpr1
<big_endian
>(p
, r
);
7093 write_insn
<big_endian
>(p
, blr
);
7097 template<bool big_endian
>
7098 static unsigned char*
7099 savefpr(unsigned char* p
, int r
)
7101 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7102 write_insn
<big_endian
>(p
, insn
);
7106 template<bool big_endian
>
7107 static unsigned char*
7108 savefpr0_tail(unsigned char* p
, int r
)
7110 p
= savefpr
<big_endian
>(p
, r
);
7111 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7113 write_insn
<big_endian
>(p
, blr
);
7117 template<bool big_endian
>
7118 static unsigned char*
7119 restfpr(unsigned char* p
, int r
)
7121 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7122 write_insn
<big_endian
>(p
, insn
);
7126 template<bool big_endian
>
7127 static unsigned char*
7128 restfpr0_tail(unsigned char* p
, int r
)
7130 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7132 p
= restfpr
<big_endian
>(p
, r
);
7133 write_insn
<big_endian
>(p
, mtlr_0
);
7137 p
= restfpr
<big_endian
>(p
, 30);
7138 p
= restfpr
<big_endian
>(p
, 31);
7140 write_insn
<big_endian
>(p
, blr
);
7144 template<bool big_endian
>
7145 static unsigned char*
7146 savefpr1_tail(unsigned char* p
, int r
)
7148 p
= savefpr
<big_endian
>(p
, r
);
7149 write_insn
<big_endian
>(p
, blr
);
7153 template<bool big_endian
>
7154 static unsigned char*
7155 restfpr1_tail(unsigned char* p
, int r
)
7157 p
= restfpr
<big_endian
>(p
, r
);
7158 write_insn
<big_endian
>(p
, blr
);
7162 template<bool big_endian
>
7163 static unsigned char*
7164 savevr(unsigned char* p
, int r
)
7166 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7167 write_insn
<big_endian
>(p
, insn
);
7169 insn
= stvx_0_12_0
+ (r
<< 21);
7170 write_insn
<big_endian
>(p
, insn
);
7174 template<bool big_endian
>
7175 static unsigned char*
7176 savevr_tail(unsigned char* p
, int r
)
7178 p
= savevr
<big_endian
>(p
, r
);
7179 write_insn
<big_endian
>(p
, blr
);
7183 template<bool big_endian
>
7184 static unsigned char*
7185 restvr(unsigned char* p
, int r
)
7187 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7188 write_insn
<big_endian
>(p
, insn
);
7190 insn
= lvx_0_12_0
+ (r
<< 21);
7191 write_insn
<big_endian
>(p
, insn
);
7195 template<bool big_endian
>
7196 static unsigned char*
7197 restvr_tail(unsigned char* p
, int r
)
7199 p
= restvr
<big_endian
>(p
, r
);
7200 write_insn
<big_endian
>(p
, blr
);
7205 template<int size
, bool big_endian
>
7206 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7207 Symbol_table
* symtab
)
7208 : Output_section_data_build(4),
7211 this->savres_define(symtab
,
7212 "_savegpr0_", 14, 31,
7213 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7214 this->savres_define(symtab
,
7215 "_restgpr0_", 14, 29,
7216 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7217 this->savres_define(symtab
,
7218 "_restgpr0_", 30, 31,
7219 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7220 this->savres_define(symtab
,
7221 "_savegpr1_", 14, 31,
7222 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7223 this->savres_define(symtab
,
7224 "_restgpr1_", 14, 31,
7225 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7226 this->savres_define(symtab
,
7227 "_savefpr_", 14, 31,
7228 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7229 this->savres_define(symtab
,
7230 "_restfpr_", 14, 29,
7231 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7232 this->savres_define(symtab
,
7233 "_restfpr_", 30, 31,
7234 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7235 this->savres_define(symtab
,
7237 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7238 this->savres_define(symtab
,
7240 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7241 this->savres_define(symtab
,
7243 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7244 this->savres_define(symtab
,
7246 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7249 template<int size
, bool big_endian
>
7251 Output_data_save_res
<size
, big_endian
>::savres_define(
7252 Symbol_table
* symtab
,
7254 unsigned int lo
, unsigned int hi
,
7255 unsigned char* write_ent(unsigned char*, int),
7256 unsigned char* write_tail(unsigned char*, int))
7258 size_t len
= strlen(name
);
7259 bool writing
= false;
7262 memcpy(sym
, name
, len
);
7265 for (unsigned int i
= lo
; i
<= hi
; i
++)
7267 sym
[len
+ 0] = i
/ 10 + '0';
7268 sym
[len
+ 1] = i
% 10 + '0';
7269 Symbol
* gsym
= symtab
->lookup(sym
);
7270 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7271 writing
= writing
|| refd
;
7274 if (this->contents_
== NULL
)
7275 this->contents_
= new unsigned char[this->savres_max
];
7277 section_size_type value
= this->current_data_size();
7278 unsigned char* p
= this->contents_
+ value
;
7280 p
= write_ent(p
, i
);
7282 p
= write_tail(p
, i
);
7283 section_size_type cur_size
= p
- this->contents_
;
7284 this->set_current_data_size(cur_size
);
7286 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7287 this, value
, cur_size
- value
,
7288 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7289 elfcpp::STV_HIDDEN
, 0, false, false);
7294 // Write out save/restore.
7296 template<int size
, bool big_endian
>
7298 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7300 const section_size_type off
= this->offset();
7301 const section_size_type oview_size
=
7302 convert_to_section_size_type(this->data_size());
7303 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7304 memcpy(oview
, this->contents_
, oview_size
);
7305 of
->write_output_view(off
, oview_size
, oview
);
7309 // Create the glink section.
7311 template<int size
, bool big_endian
>
7313 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7315 if (this->glink_
== NULL
)
7317 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7318 this->glink_
->add_eh_frame(layout
);
7319 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7320 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7321 this->glink_
, ORDER_TEXT
, false);
7325 // Create a PLT entry for a global symbol.
7327 template<int size
, bool big_endian
>
7329 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7333 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7334 && gsym
->can_use_relative_reloc(false))
7336 if (this->iplt_
== NULL
)
7337 this->make_iplt_section(symtab
, layout
);
7338 this->iplt_
->add_ifunc_entry(gsym
);
7342 if (this->plt_
== NULL
)
7343 this->make_plt_section(symtab
, layout
);
7344 this->plt_
->add_entry(gsym
);
7348 // Make a PLT entry for a local symbol.
7350 template<int size
, bool big_endian
>
7352 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7354 Sized_relobj_file
<size
, big_endian
>* relobj
,
7357 if (this->lplt_
== NULL
)
7358 this->make_lplt_section(layout
);
7359 this->lplt_
->add_local_entry(relobj
, r_sym
);
7362 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7364 template<int size
, bool big_endian
>
7366 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7367 Symbol_table
* symtab
,
7369 Sized_relobj_file
<size
, big_endian
>* relobj
,
7372 if (this->iplt_
== NULL
)
7373 this->make_iplt_section(symtab
, layout
);
7374 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7377 // Return the number of entries in the PLT.
7379 template<int size
, bool big_endian
>
7381 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7383 if (this->plt_
== NULL
)
7385 return this->plt_
->entry_count();
7388 // Create a GOT entry for local dynamic __tls_get_addr calls.
7390 template<int size
, bool big_endian
>
7392 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7393 Symbol_table
* symtab
,
7395 Sized_relobj_file
<size
, big_endian
>* object
)
7397 if (this->tlsld_got_offset_
== -1U)
7399 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7400 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7401 Output_data_got_powerpc
<size
, big_endian
>* got
7402 = this->got_section(symtab
, layout
);
7403 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7404 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7406 this->tlsld_got_offset_
= got_offset
;
7408 return this->tlsld_got_offset_
;
7411 // Get the Reference_flags for a particular relocation.
7413 template<int size
, bool big_endian
>
7415 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7416 unsigned int r_type
,
7417 const Target_powerpc
* target
)
7423 case elfcpp::R_POWERPC_NONE
:
7424 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7425 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7426 case elfcpp::R_PPC64_TOC
:
7427 // No symbol reference.
7430 case elfcpp::R_PPC64_ADDR64
:
7431 case elfcpp::R_PPC64_UADDR64
:
7432 case elfcpp::R_POWERPC_ADDR32
:
7433 case elfcpp::R_POWERPC_UADDR32
:
7434 case elfcpp::R_POWERPC_ADDR16
:
7435 case elfcpp::R_POWERPC_UADDR16
:
7436 case elfcpp::R_POWERPC_ADDR16_LO
:
7437 case elfcpp::R_POWERPC_ADDR16_HI
:
7438 case elfcpp::R_POWERPC_ADDR16_HA
:
7439 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7440 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7441 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7442 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7443 case elfcpp::R_PPC64_D34
:
7444 case elfcpp::R_PPC64_D34_LO
:
7445 case elfcpp::R_PPC64_D34_HI30
:
7446 case elfcpp::R_PPC64_D34_HA30
:
7447 case elfcpp::R_PPC64_D28
:
7448 ref
= Symbol::ABSOLUTE_REF
;
7451 case elfcpp::R_POWERPC_ADDR24
:
7452 case elfcpp::R_POWERPC_ADDR14
:
7453 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7454 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7455 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7458 case elfcpp::R_PPC64_REL64
:
7459 case elfcpp::R_POWERPC_REL32
:
7460 case elfcpp::R_PPC_LOCAL24PC
:
7461 case elfcpp::R_POWERPC_REL16
:
7462 case elfcpp::R_POWERPC_REL16_LO
:
7463 case elfcpp::R_POWERPC_REL16_HI
:
7464 case elfcpp::R_POWERPC_REL16_HA
:
7465 case elfcpp::R_PPC64_REL16_HIGH
:
7466 case elfcpp::R_PPC64_REL16_HIGHA
:
7467 case elfcpp::R_PPC64_REL16_HIGHER
:
7468 case elfcpp::R_PPC64_REL16_HIGHERA
:
7469 case elfcpp::R_PPC64_REL16_HIGHEST
:
7470 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7471 case elfcpp::R_PPC64_PCREL34
:
7472 case elfcpp::R_PPC64_REL16_HIGHER34
:
7473 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7474 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7475 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7476 case elfcpp::R_PPC64_PCREL28
:
7477 ref
= Symbol::RELATIVE_REF
;
7480 case elfcpp::R_PPC64_REL24_NOTOC
:
7484 case elfcpp::R_POWERPC_REL24
:
7485 case elfcpp::R_PPC_PLTREL24
:
7486 case elfcpp::R_POWERPC_REL14
:
7487 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7488 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7489 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7492 case elfcpp::R_POWERPC_GOT16
:
7493 case elfcpp::R_POWERPC_GOT16_LO
:
7494 case elfcpp::R_POWERPC_GOT16_HI
:
7495 case elfcpp::R_POWERPC_GOT16_HA
:
7496 case elfcpp::R_PPC64_GOT16_DS
:
7497 case elfcpp::R_PPC64_GOT16_LO_DS
:
7498 case elfcpp::R_PPC64_GOT_PCREL34
:
7499 case elfcpp::R_PPC64_TOC16
:
7500 case elfcpp::R_PPC64_TOC16_LO
:
7501 case elfcpp::R_PPC64_TOC16_HI
:
7502 case elfcpp::R_PPC64_TOC16_HA
:
7503 case elfcpp::R_PPC64_TOC16_DS
:
7504 case elfcpp::R_PPC64_TOC16_LO_DS
:
7505 case elfcpp::R_POWERPC_PLT16_LO
:
7506 case elfcpp::R_POWERPC_PLT16_HI
:
7507 case elfcpp::R_POWERPC_PLT16_HA
:
7508 case elfcpp::R_PPC64_PLT16_LO_DS
:
7509 case elfcpp::R_PPC64_PLT_PCREL34
:
7510 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7511 ref
= Symbol::RELATIVE_REF
;
7514 case elfcpp::R_POWERPC_GOT_TPREL16
:
7515 case elfcpp::R_POWERPC_TLS
:
7516 case elfcpp::R_PPC64_TLSGD
:
7517 case elfcpp::R_PPC64_TLSLD
:
7518 case elfcpp::R_PPC64_TPREL34
:
7519 case elfcpp::R_PPC64_DTPREL34
:
7520 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7521 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7522 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7523 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7524 ref
= Symbol::TLS_REF
;
7527 case elfcpp::R_POWERPC_COPY
:
7528 case elfcpp::R_POWERPC_GLOB_DAT
:
7529 case elfcpp::R_POWERPC_JMP_SLOT
:
7530 case elfcpp::R_POWERPC_RELATIVE
:
7531 case elfcpp::R_POWERPC_DTPMOD
:
7533 // Not expected. We will give an error later.
7537 if (size
== 64 && target
->abiversion() < 2)
7538 ref
|= Symbol::FUNC_DESC_ABI
;
7542 // Report an unsupported relocation against a local symbol.
7544 template<int size
, bool big_endian
>
7546 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7547 Sized_relobj_file
<size
, big_endian
>* object
,
7548 unsigned int r_type
)
7550 gold_error(_("%s: unsupported reloc %u against local symbol"),
7551 object
->name().c_str(), r_type
);
7554 // We are about to emit a dynamic relocation of type R_TYPE. If the
7555 // dynamic linker does not support it, issue an error.
7557 template<int size
, bool big_endian
>
7559 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7560 unsigned int r_type
)
7562 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7564 // These are the relocation types supported by glibc for both 32-bit
7565 // and 64-bit powerpc.
7568 case elfcpp::R_POWERPC_NONE
:
7569 case elfcpp::R_POWERPC_RELATIVE
:
7570 case elfcpp::R_POWERPC_GLOB_DAT
:
7571 case elfcpp::R_POWERPC_DTPMOD
:
7572 case elfcpp::R_POWERPC_DTPREL
:
7573 case elfcpp::R_POWERPC_TPREL
:
7574 case elfcpp::R_POWERPC_JMP_SLOT
:
7575 case elfcpp::R_POWERPC_COPY
:
7576 case elfcpp::R_POWERPC_IRELATIVE
:
7577 case elfcpp::R_POWERPC_ADDR32
:
7578 case elfcpp::R_POWERPC_UADDR32
:
7579 case elfcpp::R_POWERPC_ADDR24
:
7580 case elfcpp::R_POWERPC_ADDR16
:
7581 case elfcpp::R_POWERPC_UADDR16
:
7582 case elfcpp::R_POWERPC_ADDR16_LO
:
7583 case elfcpp::R_POWERPC_ADDR16_HI
:
7584 case elfcpp::R_POWERPC_ADDR16_HA
:
7585 case elfcpp::R_POWERPC_ADDR14
:
7586 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7587 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7588 case elfcpp::R_POWERPC_REL32
:
7589 case elfcpp::R_POWERPC_TPREL16
:
7590 case elfcpp::R_POWERPC_TPREL16_LO
:
7591 case elfcpp::R_POWERPC_TPREL16_HI
:
7592 case elfcpp::R_POWERPC_TPREL16_HA
:
7603 // These are the relocation types supported only on 64-bit.
7604 case elfcpp::R_PPC64_ADDR64
:
7605 case elfcpp::R_PPC64_UADDR64
:
7606 case elfcpp::R_PPC64_JMP_IREL
:
7607 case elfcpp::R_PPC64_ADDR16_DS
:
7608 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7609 case elfcpp::R_PPC64_ADDR16_HIGH
:
7610 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7611 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7612 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7613 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7614 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7615 case elfcpp::R_PPC64_REL64
:
7616 case elfcpp::R_POWERPC_ADDR30
:
7617 case elfcpp::R_PPC64_TPREL16_DS
:
7618 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7619 case elfcpp::R_PPC64_TPREL16_HIGH
:
7620 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7621 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7622 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7623 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7624 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7635 // These are the relocation types supported only on 32-bit.
7636 // ??? glibc ld.so doesn't need to support these.
7637 case elfcpp::R_POWERPC_REL24
:
7638 case elfcpp::R_POWERPC_DTPREL16
:
7639 case elfcpp::R_POWERPC_DTPREL16_LO
:
7640 case elfcpp::R_POWERPC_DTPREL16_HI
:
7641 case elfcpp::R_POWERPC_DTPREL16_HA
:
7649 // This prevents us from issuing more than one error per reloc
7650 // section. But we can still wind up issuing more than one
7651 // error per object file.
7652 if (this->issued_non_pic_error_
)
7654 gold_assert(parameters
->options().output_is_position_independent());
7655 object
->error(_("requires unsupported dynamic reloc; "
7656 "recompile with -fPIC"));
7657 this->issued_non_pic_error_
= true;
7661 // Return whether we need to make a PLT entry for a relocation of the
7662 // given type against a STT_GNU_IFUNC symbol.
7664 template<int size
, bool big_endian
>
7666 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7667 Target_powerpc
<size
, big_endian
>* target
,
7668 Sized_relobj_file
<size
, big_endian
>* object
,
7669 unsigned int r_type
,
7672 // In non-pic code any reference will resolve to the plt call stub
7673 // for the ifunc symbol.
7674 if ((size
== 32 || target
->abiversion() >= 2)
7675 && !parameters
->options().output_is_position_independent())
7680 // Word size refs from data sections are OK, but don't need a PLT entry.
7681 case elfcpp::R_POWERPC_ADDR32
:
7682 case elfcpp::R_POWERPC_UADDR32
:
7687 case elfcpp::R_PPC64_ADDR64
:
7688 case elfcpp::R_PPC64_UADDR64
:
7693 // GOT refs are good, but also don't need a PLT entry.
7694 case elfcpp::R_POWERPC_GOT16
:
7695 case elfcpp::R_POWERPC_GOT16_LO
:
7696 case elfcpp::R_POWERPC_GOT16_HI
:
7697 case elfcpp::R_POWERPC_GOT16_HA
:
7698 case elfcpp::R_PPC64_GOT16_DS
:
7699 case elfcpp::R_PPC64_GOT16_LO_DS
:
7700 case elfcpp::R_PPC64_GOT_PCREL34
:
7703 // PLT relocs are OK and need a PLT entry.
7704 case elfcpp::R_POWERPC_PLT16_LO
:
7705 case elfcpp::R_POWERPC_PLT16_HI
:
7706 case elfcpp::R_POWERPC_PLT16_HA
:
7707 case elfcpp::R_PPC64_PLT16_LO_DS
:
7708 case elfcpp::R_POWERPC_PLTSEQ
:
7709 case elfcpp::R_POWERPC_PLTCALL
:
7710 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7711 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7712 case elfcpp::R_PPC64_PLT_PCREL34
:
7713 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7717 // Function calls are good, and these do need a PLT entry.
7718 case elfcpp::R_PPC64_REL24_NOTOC
:
7722 case elfcpp::R_POWERPC_ADDR24
:
7723 case elfcpp::R_POWERPC_ADDR14
:
7724 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7725 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7726 case elfcpp::R_POWERPC_REL24
:
7727 case elfcpp::R_PPC_PLTREL24
:
7728 case elfcpp::R_POWERPC_REL14
:
7729 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7730 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7737 // Anything else is a problem.
7738 // If we are building a static executable, the libc startup function
7739 // responsible for applying indirect function relocations is going
7740 // to complain about the reloc type.
7741 // If we are building a dynamic executable, we will have a text
7742 // relocation. The dynamic loader will set the text segment
7743 // writable and non-executable to apply text relocations. So we'll
7744 // segfault when trying to run the indirection function to resolve
7747 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7748 object
->name().c_str(), r_type
);
7752 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7756 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7758 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7759 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7760 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7761 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7762 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7763 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7764 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7765 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7766 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7767 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7768 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7769 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7770 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7771 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7772 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7773 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7774 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7775 /* Exclude lfqu by testing reloc. If relocs are ever
7776 defined for the reduced D field in psq_lu then those
7777 will need testing too. */
7778 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7779 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7780 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7782 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7783 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7784 /* Exclude stfqu. psq_stu as above for psq_lu. */
7785 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7786 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7787 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7788 && (insn
& 1) == 0));
7791 // Scan a relocation for a local symbol.
7793 template<int size
, bool big_endian
>
7795 Target_powerpc
<size
, big_endian
>::Scan::local(
7796 Symbol_table
* symtab
,
7798 Target_powerpc
<size
, big_endian
>* target
,
7799 Sized_relobj_file
<size
, big_endian
>* object
,
7800 unsigned int data_shndx
,
7801 Output_section
* output_section
,
7802 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7803 unsigned int r_type
,
7804 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7807 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7809 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7810 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7812 this->expect_tls_get_addr_call();
7813 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7814 if (tls_type
!= tls::TLSOPT_NONE
)
7815 this->skip_next_tls_get_addr_call();
7817 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7818 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7820 this->expect_tls_get_addr_call();
7821 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7822 if (tls_type
!= tls::TLSOPT_NONE
)
7823 this->skip_next_tls_get_addr_call();
7826 Powerpc_relobj
<size
, big_endian
>* ppc_object
7827 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7832 && data_shndx
== ppc_object
->opd_shndx()
7833 && r_type
== elfcpp::R_PPC64_ADDR64
)
7834 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7838 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7839 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7840 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7842 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7843 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7844 r_type
, r_sym
, reloc
.get_r_addend());
7845 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7850 case elfcpp::R_POWERPC_NONE
:
7851 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7852 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7853 case elfcpp::R_POWERPC_TLS
:
7854 case elfcpp::R_PPC64_ENTRY
:
7855 case elfcpp::R_POWERPC_PLTSEQ
:
7856 case elfcpp::R_POWERPC_PLTCALL
:
7857 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7858 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7859 case elfcpp::R_PPC64_PCREL_OPT
:
7860 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7861 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7862 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7863 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7864 case elfcpp::R_PPC64_REL16_HIGHER34
:
7865 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7866 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7867 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7868 case elfcpp::R_PPC64_D34
:
7869 case elfcpp::R_PPC64_D34_LO
:
7870 case elfcpp::R_PPC64_D34_HI30
:
7871 case elfcpp::R_PPC64_D34_HA30
:
7872 case elfcpp::R_PPC64_D28
:
7873 case elfcpp::R_PPC64_PCREL34
:
7874 case elfcpp::R_PPC64_PCREL28
:
7875 case elfcpp::R_PPC64_TPREL34
:
7876 case elfcpp::R_PPC64_DTPREL34
:
7879 case elfcpp::R_PPC64_TOC
:
7881 Output_data_got_powerpc
<size
, big_endian
>* got
7882 = target
->got_section(symtab
, layout
);
7883 if (parameters
->options().output_is_position_independent())
7885 Address off
= reloc
.get_r_offset();
7887 && target
->abiversion() < 2
7888 && data_shndx
== ppc_object
->opd_shndx()
7889 && ppc_object
->get_opd_discard(off
- 8))
7892 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7893 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7894 rela_dyn
->add_output_section_relative(got
->output_section(),
7895 elfcpp::R_POWERPC_RELATIVE
,
7897 object
, data_shndx
, off
,
7898 symobj
->toc_base_offset());
7903 case elfcpp::R_PPC64_ADDR64
:
7904 case elfcpp::R_PPC64_UADDR64
:
7905 case elfcpp::R_POWERPC_ADDR32
:
7906 case elfcpp::R_POWERPC_UADDR32
:
7907 case elfcpp::R_POWERPC_ADDR24
:
7908 case elfcpp::R_POWERPC_ADDR16
:
7909 case elfcpp::R_POWERPC_ADDR16_LO
:
7910 case elfcpp::R_POWERPC_ADDR16_HI
:
7911 case elfcpp::R_POWERPC_ADDR16_HA
:
7912 case elfcpp::R_POWERPC_UADDR16
:
7913 case elfcpp::R_PPC64_ADDR16_HIGH
:
7914 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7915 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7916 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7917 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7918 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7919 case elfcpp::R_PPC64_ADDR16_DS
:
7920 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7921 case elfcpp::R_POWERPC_ADDR14
:
7922 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7923 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7924 // If building a shared library (or a position-independent
7925 // executable), we need to create a dynamic relocation for
7927 if (parameters
->options().output_is_position_independent()
7928 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7930 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7932 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7933 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7934 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7936 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7937 : elfcpp::R_POWERPC_RELATIVE
);
7938 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7939 output_section
, data_shndx
,
7940 reloc
.get_r_offset(),
7941 reloc
.get_r_addend(), false);
7943 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7945 check_non_pic(object
, r_type
);
7946 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7947 data_shndx
, reloc
.get_r_offset(),
7948 reloc
.get_r_addend());
7952 gold_assert(lsym
.get_st_value() == 0);
7953 unsigned int shndx
= lsym
.get_st_shndx();
7955 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7958 object
->error(_("section symbol %u has bad shndx %u"),
7961 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7962 output_section
, data_shndx
,
7963 reloc
.get_r_offset());
7968 case elfcpp::R_PPC64_PLT_PCREL34
:
7969 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7970 case elfcpp::R_POWERPC_PLT16_LO
:
7971 case elfcpp::R_POWERPC_PLT16_HI
:
7972 case elfcpp::R_POWERPC_PLT16_HA
:
7973 case elfcpp::R_PPC64_PLT16_LO_DS
:
7976 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7977 target
->make_local_plt_entry(layout
, object
, r_sym
);
7981 case elfcpp::R_PPC64_REL24_NOTOC
:
7985 case elfcpp::R_POWERPC_REL24
:
7986 case elfcpp::R_PPC_PLTREL24
:
7987 case elfcpp::R_PPC_LOCAL24PC
:
7988 case elfcpp::R_POWERPC_REL14
:
7989 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7990 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7993 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7994 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7995 r_type
, r_sym
, reloc
.get_r_addend());
7999 case elfcpp::R_PPC64_TOCSAVE
:
8000 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8001 // caller has already saved r2 and thus a plt call stub need not
8004 && target
->mark_pltcall(ppc_object
, data_shndx
,
8005 reloc
.get_r_offset() - 4, symtab
))
8007 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8008 unsigned int shndx
= lsym
.get_st_shndx();
8010 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8012 object
->error(_("tocsave symbol %u has bad shndx %u"),
8015 target
->add_tocsave(ppc_object
, shndx
,
8016 lsym
.get_st_value() + reloc
.get_r_addend());
8020 case elfcpp::R_PPC64_REL64
:
8021 case elfcpp::R_POWERPC_REL32
:
8022 case elfcpp::R_POWERPC_REL16
:
8023 case elfcpp::R_POWERPC_REL16_LO
:
8024 case elfcpp::R_POWERPC_REL16_HI
:
8025 case elfcpp::R_POWERPC_REL16_HA
:
8026 case elfcpp::R_POWERPC_REL16DX_HA
:
8027 case elfcpp::R_PPC64_REL16_HIGH
:
8028 case elfcpp::R_PPC64_REL16_HIGHA
:
8029 case elfcpp::R_PPC64_REL16_HIGHER
:
8030 case elfcpp::R_PPC64_REL16_HIGHERA
:
8031 case elfcpp::R_PPC64_REL16_HIGHEST
:
8032 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8033 case elfcpp::R_POWERPC_SECTOFF
:
8034 case elfcpp::R_POWERPC_SECTOFF_LO
:
8035 case elfcpp::R_POWERPC_SECTOFF_HI
:
8036 case elfcpp::R_POWERPC_SECTOFF_HA
:
8037 case elfcpp::R_PPC64_SECTOFF_DS
:
8038 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8039 case elfcpp::R_POWERPC_TPREL16
:
8040 case elfcpp::R_POWERPC_TPREL16_LO
:
8041 case elfcpp::R_POWERPC_TPREL16_HI
:
8042 case elfcpp::R_POWERPC_TPREL16_HA
:
8043 case elfcpp::R_PPC64_TPREL16_DS
:
8044 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8045 case elfcpp::R_PPC64_TPREL16_HIGH
:
8046 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8047 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8048 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8049 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8050 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8051 case elfcpp::R_POWERPC_DTPREL16
:
8052 case elfcpp::R_POWERPC_DTPREL16_LO
:
8053 case elfcpp::R_POWERPC_DTPREL16_HI
:
8054 case elfcpp::R_POWERPC_DTPREL16_HA
:
8055 case elfcpp::R_PPC64_DTPREL16_DS
:
8056 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8057 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8058 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8059 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8060 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8061 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8062 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8063 case elfcpp::R_PPC64_TLSGD
:
8064 case elfcpp::R_PPC64_TLSLD
:
8065 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8068 case elfcpp::R_PPC64_GOT_PCREL34
:
8069 case elfcpp::R_POWERPC_GOT16
:
8070 case elfcpp::R_POWERPC_GOT16_LO
:
8071 case elfcpp::R_POWERPC_GOT16_HI
:
8072 case elfcpp::R_POWERPC_GOT16_HA
:
8073 case elfcpp::R_PPC64_GOT16_DS
:
8074 case elfcpp::R_PPC64_GOT16_LO_DS
:
8076 // The symbol requires a GOT entry.
8077 Output_data_got_powerpc
<size
, big_endian
>* got
8078 = target
->got_section(symtab
, layout
);
8079 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8081 if (!parameters
->options().output_is_position_independent())
8084 && (size
== 32 || target
->abiversion() >= 2))
8085 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8087 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8089 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8091 // If we are generating a shared object or a pie, this
8092 // symbol's GOT entry will be set by a dynamic relocation.
8094 off
= got
->add_constant(0);
8095 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8097 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8099 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8100 : elfcpp::R_POWERPC_RELATIVE
);
8101 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8102 got
, off
, 0, false);
8107 case elfcpp::R_PPC64_TOC16
:
8108 case elfcpp::R_PPC64_TOC16_LO
:
8109 case elfcpp::R_PPC64_TOC16_HI
:
8110 case elfcpp::R_PPC64_TOC16_HA
:
8111 case elfcpp::R_PPC64_TOC16_DS
:
8112 case elfcpp::R_PPC64_TOC16_LO_DS
:
8113 // We need a GOT section.
8114 target
->got_section(symtab
, layout
);
8117 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8118 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8119 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8120 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8121 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8123 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
8124 if (tls_type
== tls::TLSOPT_NONE
)
8126 Output_data_got_powerpc
<size
, big_endian
>* got
8127 = target
->got_section(symtab
, layout
);
8128 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8129 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8130 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8131 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8133 else if (tls_type
== tls::TLSOPT_TO_LE
)
8135 // no GOT relocs needed for Local Exec.
8142 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8143 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8144 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8145 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8146 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8148 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8149 if (tls_type
== tls::TLSOPT_NONE
)
8150 target
->tlsld_got_offset(symtab
, layout
, object
);
8151 else if (tls_type
== tls::TLSOPT_TO_LE
)
8153 // no GOT relocs needed for Local Exec.
8154 if (parameters
->options().emit_relocs())
8156 Output_section
* os
= layout
->tls_segment()->first_section();
8157 gold_assert(os
!= NULL
);
8158 os
->set_needs_symtab_index();
8166 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8167 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8168 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8169 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8170 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8172 Output_data_got_powerpc
<size
, big_endian
>* got
8173 = target
->got_section(symtab
, layout
);
8174 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8175 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8179 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8180 case elfcpp::R_POWERPC_GOT_TPREL16
:
8181 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8182 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8183 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8185 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8186 if (tls_type
== tls::TLSOPT_NONE
)
8188 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8189 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8191 Output_data_got_powerpc
<size
, big_endian
>* got
8192 = target
->got_section(symtab
, layout
);
8193 unsigned int off
= got
->add_constant(0);
8194 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8196 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8197 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8198 elfcpp::R_POWERPC_TPREL
,
8202 else if (tls_type
== tls::TLSOPT_TO_LE
)
8204 // no GOT relocs needed for Local Exec.
8212 unsupported_reloc_local(object
, r_type
);
8217 && parameters
->options().toc_optimize())
8219 if (data_shndx
== ppc_object
->toc_shndx())
8222 if (r_type
!= elfcpp::R_PPC64_ADDR64
8223 || (is_ifunc
&& target
->abiversion() < 2))
8225 else if (parameters
->options().output_is_position_independent())
8231 unsigned int shndx
= lsym
.get_st_shndx();
8232 if (shndx
>= elfcpp::SHN_LORESERVE
8233 && shndx
!= elfcpp::SHN_XINDEX
)
8238 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8241 enum {no_check
, check_lo
, check_ha
} insn_check
;
8245 insn_check
= no_check
;
8248 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8249 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8250 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8251 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8252 case elfcpp::R_POWERPC_GOT16_HA
:
8253 case elfcpp::R_PPC64_TOC16_HA
:
8254 insn_check
= check_ha
;
8257 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8258 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8259 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8260 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8261 case elfcpp::R_POWERPC_GOT16_LO
:
8262 case elfcpp::R_PPC64_GOT16_LO_DS
:
8263 case elfcpp::R_PPC64_TOC16_LO
:
8264 case elfcpp::R_PPC64_TOC16_LO_DS
:
8265 insn_check
= check_lo
;
8269 section_size_type slen
;
8270 const unsigned char* view
= NULL
;
8271 if (insn_check
!= no_check
)
8273 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8274 section_size_type off
=
8275 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8278 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8279 if (insn_check
== check_lo
8280 ? !ok_lo_toc_insn(insn
, r_type
)
8281 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8282 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8284 ppc_object
->set_no_toc_opt();
8285 gold_warning(_("%s: toc optimization is not supported "
8286 "for %#08x instruction"),
8287 ppc_object
->name().c_str(), insn
);
8296 case elfcpp::R_PPC64_TOC16
:
8297 case elfcpp::R_PPC64_TOC16_LO
:
8298 case elfcpp::R_PPC64_TOC16_HI
:
8299 case elfcpp::R_PPC64_TOC16_HA
:
8300 case elfcpp::R_PPC64_TOC16_DS
:
8301 case elfcpp::R_PPC64_TOC16_LO_DS
:
8302 unsigned int shndx
= lsym
.get_st_shndx();
8303 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8305 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8306 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8308 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8309 if (dst_off
< ppc_object
->section_size(shndx
))
8312 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8314 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8316 // Need to check that the insn is a ld
8318 view
= ppc_object
->section_contents(data_shndx
,
8321 section_size_type off
=
8322 (convert_to_section_size_type(reloc
.get_r_offset())
8323 + (big_endian
? -2 : 3));
8325 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8329 ppc_object
->set_no_toc_opt(dst_off
);
8340 case elfcpp::R_POWERPC_REL32
:
8341 if (ppc_object
->got2_shndx() != 0
8342 && parameters
->options().output_is_position_independent())
8344 unsigned int shndx
= lsym
.get_st_shndx();
8345 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8347 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8348 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8349 && (ppc_object
->section_flags(data_shndx
)
8350 & elfcpp::SHF_EXECINSTR
) != 0)
8351 gold_error(_("%s: unsupported -mbss-plt code"),
8352 ppc_object
->name().c_str());
8362 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8363 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8364 case elfcpp::R_POWERPC_GOT_TPREL16
:
8365 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8366 case elfcpp::R_POWERPC_GOT16
:
8367 case elfcpp::R_PPC64_GOT16_DS
:
8368 case elfcpp::R_PPC64_TOC16
:
8369 case elfcpp::R_PPC64_TOC16_DS
:
8370 ppc_object
->set_has_small_toc_reloc();
8378 case elfcpp::R_PPC64_TPREL16_DS
:
8379 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8380 case elfcpp::R_PPC64_TPREL16_HIGH
:
8381 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8382 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8383 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8384 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8385 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8386 case elfcpp::R_PPC64_TPREL34
:
8390 case elfcpp::R_POWERPC_TPREL16
:
8391 case elfcpp::R_POWERPC_TPREL16_LO
:
8392 case elfcpp::R_POWERPC_TPREL16_HI
:
8393 case elfcpp::R_POWERPC_TPREL16_HA
:
8394 layout
->set_has_static_tls();
8402 case elfcpp::R_POWERPC_TPREL16_HA
:
8403 if (target
->tprel_opt())
8405 section_size_type slen
;
8406 const unsigned char* view
= NULL
;
8407 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8408 section_size_type off
8409 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8412 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8413 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8414 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8415 target
->set_tprel_opt(false);
8420 case elfcpp::R_PPC64_TPREL16_HIGH
:
8421 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8422 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8423 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8424 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8425 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8429 case elfcpp::R_POWERPC_TPREL16_HI
:
8430 target
->set_tprel_opt(false);
8438 case elfcpp::R_PPC64_D34
:
8439 case elfcpp::R_PPC64_D34_LO
:
8440 case elfcpp::R_PPC64_D34_HI30
:
8441 case elfcpp::R_PPC64_D34_HA30
:
8442 case elfcpp::R_PPC64_D28
:
8443 case elfcpp::R_PPC64_PCREL34
:
8444 case elfcpp::R_PPC64_PCREL28
:
8445 case elfcpp::R_PPC64_TPREL34
:
8446 case elfcpp::R_PPC64_DTPREL34
:
8447 case elfcpp::R_PPC64_PLT_PCREL34
:
8448 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8449 case elfcpp::R_PPC64_GOT_PCREL34
:
8450 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8451 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8452 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8453 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8454 target
->set_power10_stubs();
8461 // Report an unsupported relocation against a global symbol.
8463 template<int size
, bool big_endian
>
8465 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8466 Sized_relobj_file
<size
, big_endian
>* object
,
8467 unsigned int r_type
,
8470 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8471 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8474 // Scan a relocation for a global symbol.
8476 template<int size
, bool big_endian
>
8478 Target_powerpc
<size
, big_endian
>::Scan::global(
8479 Symbol_table
* symtab
,
8481 Target_powerpc
<size
, big_endian
>* target
,
8482 Sized_relobj_file
<size
, big_endian
>* object
,
8483 unsigned int data_shndx
,
8484 Output_section
* output_section
,
8485 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8486 unsigned int r_type
,
8489 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8493 if (target
->replace_tls_get_addr(gsym
))
8494 // Change a __tls_get_addr reference to __tls_get_addr_opt
8495 // so dynamic relocs are emitted against the latter symbol.
8496 gsym
= target
->tls_get_addr_opt();
8498 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8499 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8501 this->expect_tls_get_addr_call();
8502 const bool final
= gsym
->final_value_is_known();
8503 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8504 if (tls_type
!= tls::TLSOPT_NONE
)
8505 this->skip_next_tls_get_addr_call();
8507 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8508 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8510 this->expect_tls_get_addr_call();
8511 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8512 if (tls_type
!= tls::TLSOPT_NONE
)
8513 this->skip_next_tls_get_addr_call();
8516 Powerpc_relobj
<size
, big_endian
>* ppc_object
8517 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8519 // A STT_GNU_IFUNC symbol may require a PLT entry.
8520 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8521 bool pushed_ifunc
= false;
8522 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8524 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8525 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8526 r_type
, r_sym
, reloc
.get_r_addend());
8527 target
->make_plt_entry(symtab
, layout
, gsym
);
8528 pushed_ifunc
= true;
8533 case elfcpp::R_POWERPC_NONE
:
8534 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8535 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8536 case elfcpp::R_PPC_LOCAL24PC
:
8537 case elfcpp::R_POWERPC_TLS
:
8538 case elfcpp::R_PPC64_ENTRY
:
8539 case elfcpp::R_POWERPC_PLTSEQ
:
8540 case elfcpp::R_POWERPC_PLTCALL
:
8541 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8542 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8543 case elfcpp::R_PPC64_PCREL_OPT
:
8544 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8545 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8546 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8547 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8548 case elfcpp::R_PPC64_REL16_HIGHER34
:
8549 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8550 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8551 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8552 case elfcpp::R_PPC64_D34
:
8553 case elfcpp::R_PPC64_D34_LO
:
8554 case elfcpp::R_PPC64_D34_HI30
:
8555 case elfcpp::R_PPC64_D34_HA30
:
8556 case elfcpp::R_PPC64_D28
:
8557 case elfcpp::R_PPC64_PCREL34
:
8558 case elfcpp::R_PPC64_PCREL28
:
8559 case elfcpp::R_PPC64_TPREL34
:
8560 case elfcpp::R_PPC64_DTPREL34
:
8563 case elfcpp::R_PPC64_TOC
:
8565 Output_data_got_powerpc
<size
, big_endian
>* got
8566 = target
->got_section(symtab
, layout
);
8567 if (parameters
->options().output_is_position_independent())
8569 Address off
= reloc
.get_r_offset();
8571 && data_shndx
== ppc_object
->opd_shndx()
8572 && ppc_object
->get_opd_discard(off
- 8))
8575 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8576 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8577 if (data_shndx
!= ppc_object
->opd_shndx())
8578 symobj
= static_cast
8579 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8580 rela_dyn
->add_output_section_relative(got
->output_section(),
8581 elfcpp::R_POWERPC_RELATIVE
,
8583 object
, data_shndx
, off
,
8584 symobj
->toc_base_offset());
8589 case elfcpp::R_PPC64_ADDR64
:
8591 && target
->abiversion() < 2
8592 && data_shndx
== ppc_object
->opd_shndx()
8593 && (gsym
->is_defined_in_discarded_section()
8594 || gsym
->object() != object
))
8596 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8600 case elfcpp::R_PPC64_UADDR64
:
8601 case elfcpp::R_POWERPC_ADDR32
:
8602 case elfcpp::R_POWERPC_UADDR32
:
8603 case elfcpp::R_POWERPC_ADDR24
:
8604 case elfcpp::R_POWERPC_ADDR16
:
8605 case elfcpp::R_POWERPC_ADDR16_LO
:
8606 case elfcpp::R_POWERPC_ADDR16_HI
:
8607 case elfcpp::R_POWERPC_ADDR16_HA
:
8608 case elfcpp::R_POWERPC_UADDR16
:
8609 case elfcpp::R_PPC64_ADDR16_HIGH
:
8610 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8611 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8612 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8613 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8614 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8615 case elfcpp::R_PPC64_ADDR16_DS
:
8616 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8617 case elfcpp::R_POWERPC_ADDR14
:
8618 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8619 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8621 // Make a PLT entry if necessary.
8622 if (gsym
->needs_plt_entry())
8624 // Since this is not a PC-relative relocation, we may be
8625 // taking the address of a function. In that case we need to
8626 // set the entry in the dynamic symbol table to the address of
8627 // the PLT call stub.
8628 bool need_ifunc_plt
= false;
8629 if ((size
== 32 || target
->abiversion() >= 2)
8630 && gsym
->is_from_dynobj()
8631 && !parameters
->options().output_is_position_independent())
8633 gsym
->set_needs_dynsym_value();
8634 need_ifunc_plt
= true;
8636 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8638 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8639 target
->push_branch(ppc_object
, data_shndx
,
8640 reloc
.get_r_offset(), r_type
, r_sym
,
8641 reloc
.get_r_addend());
8642 target
->make_plt_entry(symtab
, layout
, gsym
);
8645 // Make a dynamic relocation if necessary.
8646 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8647 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8649 if (!parameters
->options().output_is_position_independent()
8650 && gsym
->may_need_copy_reloc())
8652 target
->copy_reloc(symtab
, layout
, object
,
8653 data_shndx
, output_section
, gsym
, reloc
);
8655 else if ((((size
== 32
8656 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8658 && r_type
== elfcpp::R_PPC64_ADDR64
8659 && target
->abiversion() >= 2))
8660 && gsym
->can_use_relative_reloc(false)
8661 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8662 && parameters
->options().shared()))
8664 && r_type
== elfcpp::R_PPC64_ADDR64
8665 && target
->abiversion() < 2
8666 && (gsym
->can_use_relative_reloc(false)
8667 || data_shndx
== ppc_object
->opd_shndx())))
8669 Reloc_section
* rela_dyn
8670 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8671 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8672 : elfcpp::R_POWERPC_RELATIVE
);
8673 rela_dyn
->add_symbolless_global_addend(
8674 gsym
, dynrel
, output_section
, object
, data_shndx
,
8675 reloc
.get_r_offset(), reloc
.get_r_addend());
8679 Reloc_section
* rela_dyn
8680 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8681 check_non_pic(object
, r_type
);
8682 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8684 reloc
.get_r_offset(),
8685 reloc
.get_r_addend());
8688 && parameters
->options().toc_optimize()
8689 && data_shndx
== ppc_object
->toc_shndx())
8690 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8696 case elfcpp::R_PPC64_PLT_PCREL34
:
8697 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8698 case elfcpp::R_POWERPC_PLT16_LO
:
8699 case elfcpp::R_POWERPC_PLT16_HI
:
8700 case elfcpp::R_POWERPC_PLT16_HA
:
8701 case elfcpp::R_PPC64_PLT16_LO_DS
:
8703 target
->make_plt_entry(symtab
, layout
, gsym
);
8706 case elfcpp::R_PPC64_REL24_NOTOC
:
8710 case elfcpp::R_PPC_PLTREL24
:
8711 case elfcpp::R_POWERPC_REL24
:
8714 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8715 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8716 r_type
, r_sym
, reloc
.get_r_addend());
8717 if (gsym
->needs_plt_entry()
8718 || (!gsym
->final_value_is_known()
8719 && (gsym
->is_undefined()
8720 || gsym
->is_from_dynobj()
8721 || gsym
->is_preemptible())))
8722 target
->make_plt_entry(symtab
, layout
, gsym
);
8726 case elfcpp::R_PPC64_REL64
:
8727 case elfcpp::R_POWERPC_REL32
:
8728 // Make a dynamic relocation if necessary.
8729 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8731 if (!parameters
->options().output_is_position_independent()
8732 && gsym
->may_need_copy_reloc())
8734 target
->copy_reloc(symtab
, layout
, object
,
8735 data_shndx
, output_section
, gsym
,
8740 Reloc_section
* rela_dyn
8741 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8742 check_non_pic(object
, r_type
);
8743 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8744 data_shndx
, reloc
.get_r_offset(),
8745 reloc
.get_r_addend());
8750 case elfcpp::R_POWERPC_REL14
:
8751 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8752 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8755 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8756 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8757 r_type
, r_sym
, reloc
.get_r_addend());
8761 case elfcpp::R_PPC64_TOCSAVE
:
8762 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8763 // caller has already saved r2 and thus a plt call stub need not
8766 && target
->mark_pltcall(ppc_object
, data_shndx
,
8767 reloc
.get_r_offset() - 4, symtab
))
8769 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8771 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8773 object
->error(_("tocsave symbol %u has bad shndx %u"),
8777 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8778 target
->add_tocsave(ppc_object
, shndx
,
8779 sym
->value() + reloc
.get_r_addend());
8784 case elfcpp::R_POWERPC_REL16
:
8785 case elfcpp::R_POWERPC_REL16_LO
:
8786 case elfcpp::R_POWERPC_REL16_HI
:
8787 case elfcpp::R_POWERPC_REL16_HA
:
8788 case elfcpp::R_POWERPC_REL16DX_HA
:
8789 case elfcpp::R_PPC64_REL16_HIGH
:
8790 case elfcpp::R_PPC64_REL16_HIGHA
:
8791 case elfcpp::R_PPC64_REL16_HIGHER
:
8792 case elfcpp::R_PPC64_REL16_HIGHERA
:
8793 case elfcpp::R_PPC64_REL16_HIGHEST
:
8794 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8795 case elfcpp::R_POWERPC_SECTOFF
:
8796 case elfcpp::R_POWERPC_SECTOFF_LO
:
8797 case elfcpp::R_POWERPC_SECTOFF_HI
:
8798 case elfcpp::R_POWERPC_SECTOFF_HA
:
8799 case elfcpp::R_PPC64_SECTOFF_DS
:
8800 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8801 case elfcpp::R_POWERPC_TPREL16
:
8802 case elfcpp::R_POWERPC_TPREL16_LO
:
8803 case elfcpp::R_POWERPC_TPREL16_HI
:
8804 case elfcpp::R_POWERPC_TPREL16_HA
:
8805 case elfcpp::R_PPC64_TPREL16_DS
:
8806 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8807 case elfcpp::R_PPC64_TPREL16_HIGH
:
8808 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8809 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8810 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8811 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8812 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8813 case elfcpp::R_POWERPC_DTPREL16
:
8814 case elfcpp::R_POWERPC_DTPREL16_LO
:
8815 case elfcpp::R_POWERPC_DTPREL16_HI
:
8816 case elfcpp::R_POWERPC_DTPREL16_HA
:
8817 case elfcpp::R_PPC64_DTPREL16_DS
:
8818 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8819 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8820 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8821 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8822 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8823 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8824 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8825 case elfcpp::R_PPC64_TLSGD
:
8826 case elfcpp::R_PPC64_TLSLD
:
8827 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8830 case elfcpp::R_PPC64_GOT_PCREL34
:
8831 case elfcpp::R_POWERPC_GOT16
:
8832 case elfcpp::R_POWERPC_GOT16_LO
:
8833 case elfcpp::R_POWERPC_GOT16_HI
:
8834 case elfcpp::R_POWERPC_GOT16_HA
:
8835 case elfcpp::R_PPC64_GOT16_DS
:
8836 case elfcpp::R_PPC64_GOT16_LO_DS
:
8838 // The symbol requires a GOT entry.
8839 Output_data_got_powerpc
<size
, big_endian
>* got
;
8841 got
= target
->got_section(symtab
, layout
);
8842 if (gsym
->final_value_is_known())
8845 && (size
== 32 || target
->abiversion() >= 2))
8846 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8848 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8850 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8852 // If we are generating a shared object or a pie, this
8853 // symbol's GOT entry will be set by a dynamic relocation.
8854 unsigned int off
= got
->add_constant(0);
8855 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8857 Reloc_section
* rela_dyn
8858 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8860 if (gsym
->can_use_relative_reloc(false)
8862 || target
->abiversion() >= 2)
8863 && gsym
->visibility() == elfcpp::STV_PROTECTED
8864 && parameters
->options().shared()))
8866 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8867 : elfcpp::R_POWERPC_RELATIVE
);
8868 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8872 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8873 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8879 case elfcpp::R_PPC64_TOC16
:
8880 case elfcpp::R_PPC64_TOC16_LO
:
8881 case elfcpp::R_PPC64_TOC16_HI
:
8882 case elfcpp::R_PPC64_TOC16_HA
:
8883 case elfcpp::R_PPC64_TOC16_DS
:
8884 case elfcpp::R_PPC64_TOC16_LO_DS
:
8885 // We need a GOT section.
8886 target
->got_section(symtab
, layout
);
8889 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8890 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8891 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8892 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8893 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8895 const bool final
= gsym
->final_value_is_known();
8896 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8897 if (tls_type
== tls::TLSOPT_NONE
)
8899 Output_data_got_powerpc
<size
, big_endian
>* got
8900 = target
->got_section(symtab
, layout
);
8901 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8902 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8903 elfcpp::R_POWERPC_DTPMOD
,
8904 elfcpp::R_POWERPC_DTPREL
);
8906 else if (tls_type
== tls::TLSOPT_TO_IE
)
8908 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8910 Output_data_got_powerpc
<size
, big_endian
>* got
8911 = target
->got_section(symtab
, layout
);
8912 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8913 if (gsym
->is_undefined()
8914 || gsym
->is_from_dynobj())
8916 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8917 elfcpp::R_POWERPC_TPREL
);
8921 unsigned int off
= got
->add_constant(0);
8922 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8923 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8924 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8929 else if (tls_type
== tls::TLSOPT_TO_LE
)
8931 // no GOT relocs needed for Local Exec.
8938 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8939 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8940 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8941 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8942 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8944 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8945 if (tls_type
== tls::TLSOPT_NONE
)
8946 target
->tlsld_got_offset(symtab
, layout
, object
);
8947 else if (tls_type
== tls::TLSOPT_TO_LE
)
8949 // no GOT relocs needed for Local Exec.
8950 if (parameters
->options().emit_relocs())
8952 Output_section
* os
= layout
->tls_segment()->first_section();
8953 gold_assert(os
!= NULL
);
8954 os
->set_needs_symtab_index();
8962 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8963 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8964 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8965 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8966 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8968 Output_data_got_powerpc
<size
, big_endian
>* got
8969 = target
->got_section(symtab
, layout
);
8970 if (!gsym
->final_value_is_known()
8971 && (gsym
->is_from_dynobj()
8972 || gsym
->is_undefined()
8973 || gsym
->is_preemptible()))
8974 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8975 target
->rela_dyn_section(layout
),
8976 elfcpp::R_POWERPC_DTPREL
);
8978 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8982 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8983 case elfcpp::R_POWERPC_GOT_TPREL16
:
8984 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8985 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8986 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8988 const bool final
= gsym
->final_value_is_known();
8989 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8990 if (tls_type
== tls::TLSOPT_NONE
)
8992 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8994 Output_data_got_powerpc
<size
, big_endian
>* got
8995 = target
->got_section(symtab
, layout
);
8996 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8997 if (gsym
->is_undefined()
8998 || gsym
->is_from_dynobj())
9000 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9001 elfcpp::R_POWERPC_TPREL
);
9005 unsigned int off
= got
->add_constant(0);
9006 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9007 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9008 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9013 else if (tls_type
== tls::TLSOPT_TO_LE
)
9015 // no GOT relocs needed for Local Exec.
9023 unsupported_reloc_global(object
, r_type
, gsym
);
9028 && parameters
->options().toc_optimize())
9030 if (data_shndx
== ppc_object
->toc_shndx())
9033 if (r_type
!= elfcpp::R_PPC64_ADDR64
9034 || (is_ifunc
&& target
->abiversion() < 2))
9036 else if (parameters
->options().output_is_position_independent()
9037 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9040 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9043 enum {no_check
, check_lo
, check_ha
} insn_check
;
9047 insn_check
= no_check
;
9050 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9051 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9052 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9053 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9054 case elfcpp::R_POWERPC_GOT16_HA
:
9055 case elfcpp::R_PPC64_TOC16_HA
:
9056 insn_check
= check_ha
;
9059 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9060 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9061 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9062 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9063 case elfcpp::R_POWERPC_GOT16_LO
:
9064 case elfcpp::R_PPC64_GOT16_LO_DS
:
9065 case elfcpp::R_PPC64_TOC16_LO
:
9066 case elfcpp::R_PPC64_TOC16_LO_DS
:
9067 insn_check
= check_lo
;
9071 section_size_type slen
;
9072 const unsigned char* view
= NULL
;
9073 if (insn_check
!= no_check
)
9075 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9076 section_size_type off
=
9077 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9080 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9081 if (insn_check
== check_lo
9082 ? !ok_lo_toc_insn(insn
, r_type
)
9083 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9084 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9086 ppc_object
->set_no_toc_opt();
9087 gold_warning(_("%s: toc optimization is not supported "
9088 "for %#08x instruction"),
9089 ppc_object
->name().c_str(), insn
);
9098 case elfcpp::R_PPC64_TOC16
:
9099 case elfcpp::R_PPC64_TOC16_LO
:
9100 case elfcpp::R_PPC64_TOC16_HI
:
9101 case elfcpp::R_PPC64_TOC16_HA
:
9102 case elfcpp::R_PPC64_TOC16_DS
:
9103 case elfcpp::R_PPC64_TOC16_LO_DS
:
9104 if (gsym
->source() == Symbol::FROM_OBJECT
9105 && !gsym
->object()->is_dynamic())
9107 Powerpc_relobj
<size
, big_endian
>* sym_object
9108 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9110 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9111 if (shndx
== sym_object
->toc_shndx())
9113 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9114 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9115 if (dst_off
< sym_object
->section_size(shndx
))
9118 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9120 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9122 // Need to check that the insn is a ld
9124 view
= ppc_object
->section_contents(data_shndx
,
9127 section_size_type off
=
9128 (convert_to_section_size_type(reloc
.get_r_offset())
9129 + (big_endian
? -2 : 3));
9131 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9135 sym_object
->set_no_toc_opt(dst_off
);
9147 case elfcpp::R_PPC_LOCAL24PC
:
9148 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9149 gold_error(_("%s: unsupported -mbss-plt code"),
9150 ppc_object
->name().c_str());
9159 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9160 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9161 case elfcpp::R_POWERPC_GOT_TPREL16
:
9162 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9163 case elfcpp::R_POWERPC_GOT16
:
9164 case elfcpp::R_PPC64_GOT16_DS
:
9165 case elfcpp::R_PPC64_TOC16
:
9166 case elfcpp::R_PPC64_TOC16_DS
:
9167 ppc_object
->set_has_small_toc_reloc();
9175 case elfcpp::R_PPC64_TPREL16_DS
:
9176 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9177 case elfcpp::R_PPC64_TPREL16_HIGH
:
9178 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9179 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9180 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9181 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9182 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9183 case elfcpp::R_PPC64_TPREL34
:
9187 case elfcpp::R_POWERPC_TPREL16
:
9188 case elfcpp::R_POWERPC_TPREL16_LO
:
9189 case elfcpp::R_POWERPC_TPREL16_HI
:
9190 case elfcpp::R_POWERPC_TPREL16_HA
:
9191 layout
->set_has_static_tls();
9199 case elfcpp::R_POWERPC_TPREL16_HA
:
9200 if (target
->tprel_opt())
9202 section_size_type slen
;
9203 const unsigned char* view
= NULL
;
9204 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9205 section_size_type off
9206 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9209 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9210 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9211 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9212 target
->set_tprel_opt(false);
9217 case elfcpp::R_PPC64_TPREL16_HIGH
:
9218 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9219 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9220 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9221 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9222 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9226 case elfcpp::R_POWERPC_TPREL16_HI
:
9227 target
->set_tprel_opt(false);
9235 case elfcpp::R_PPC64_D34
:
9236 case elfcpp::R_PPC64_D34_LO
:
9237 case elfcpp::R_PPC64_D34_HI30
:
9238 case elfcpp::R_PPC64_D34_HA30
:
9239 case elfcpp::R_PPC64_D28
:
9240 case elfcpp::R_PPC64_PCREL34
:
9241 case elfcpp::R_PPC64_PCREL28
:
9242 case elfcpp::R_PPC64_TPREL34
:
9243 case elfcpp::R_PPC64_DTPREL34
:
9244 case elfcpp::R_PPC64_PLT_PCREL34
:
9245 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9246 case elfcpp::R_PPC64_GOT_PCREL34
:
9247 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9248 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9249 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9250 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9251 target
->set_power10_stubs();
9258 // Process relocations for gc.
9260 template<int size
, bool big_endian
>
9262 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9263 Symbol_table
* symtab
,
9265 Sized_relobj_file
<size
, big_endian
>* object
,
9266 unsigned int data_shndx
,
9268 const unsigned char* prelocs
,
9270 Output_section
* output_section
,
9271 bool needs_special_offset_handling
,
9272 size_t local_symbol_count
,
9273 const unsigned char* plocal_symbols
)
9275 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9276 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9279 Powerpc_relobj
<size
, big_endian
>* ppc_object
9280 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9282 ppc_object
->set_opd_valid();
9283 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9285 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9286 for (p
= ppc_object
->access_from_map()->begin();
9287 p
!= ppc_object
->access_from_map()->end();
9290 Address dst_off
= p
->first
;
9291 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9292 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9293 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9295 Relobj
* src_obj
= s
->first
;
9296 unsigned int src_indx
= s
->second
;
9297 symtab
->gc()->add_reference(src_obj
, src_indx
,
9298 ppc_object
, dst_indx
);
9302 ppc_object
->access_from_map()->clear();
9303 ppc_object
->process_gc_mark(symtab
);
9304 // Don't look at .opd relocs as .opd will reference everything.
9308 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9317 needs_special_offset_handling
,
9322 // Handle target specific gc actions when adding a gc reference from
9323 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9324 // and DST_OFF. For powerpc64, this adds a referenc to the code
9325 // section of a function descriptor.
9327 template<int size
, bool big_endian
>
9329 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9330 Symbol_table
* symtab
,
9332 unsigned int src_shndx
,
9334 unsigned int dst_shndx
,
9335 Address dst_off
) const
9337 if (size
!= 64 || dst_obj
->is_dynamic())
9340 Powerpc_relobj
<size
, big_endian
>* ppc_object
9341 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9342 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9344 if (ppc_object
->opd_valid())
9346 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9347 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9351 // If we haven't run scan_opd_relocs, we must delay
9352 // processing this function descriptor reference.
9353 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9358 // Add any special sections for this symbol to the gc work list.
9359 // For powerpc64, this adds the code section of a function
9362 template<int size
, bool big_endian
>
9364 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9365 Symbol_table
* symtab
,
9368 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9370 Powerpc_relobj
<size
, big_endian
>* ppc_object
9371 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9373 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9374 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9376 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9377 Address dst_off
= gsym
->value();
9378 if (ppc_object
->opd_valid())
9380 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9381 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9385 ppc_object
->add_gc_mark(dst_off
);
9390 // For a symbol location in .opd, set LOC to the location of the
9393 template<int size
, bool big_endian
>
9395 Target_powerpc
<size
, big_endian
>::do_function_location(
9396 Symbol_location
* loc
) const
9398 if (size
== 64 && loc
->shndx
!= 0)
9400 if (loc
->object
->is_dynamic())
9402 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9403 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9404 if (loc
->shndx
== ppc_object
->opd_shndx())
9407 Address off
= loc
->offset
- ppc_object
->opd_address();
9408 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9409 loc
->offset
= dest_off
;
9414 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9415 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9416 if (loc
->shndx
== ppc_object
->opd_shndx())
9419 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9420 loc
->offset
= dest_off
;
9426 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9427 // compiled with -fsplit-stack. The function calls non-split-stack
9428 // code. Change the function to ensure it has enough stack space to
9429 // call some random function.
9431 template<int size
, bool big_endian
>
9433 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9436 section_offset_type fnoffset
,
9437 section_size_type fnsize
,
9438 const unsigned char* prelocs
,
9440 unsigned char* view
,
9441 section_size_type view_size
,
9443 std::string
* to
) const
9445 // 32-bit not supported.
9449 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9450 prelocs
, reloc_count
, view
, view_size
,
9455 // The function always starts with
9456 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9457 // addis %r12,%r1,-allocate@ha
9458 // addi %r12,%r12,-allocate@l
9460 // but note that the addis or addi may be replaced with a nop
9462 unsigned char *entry
= view
+ fnoffset
;
9463 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9465 if ((insn
& 0xffff0000) == addis_2_12
)
9467 /* Skip ELFv2 global entry code. */
9469 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9472 unsigned char *pinsn
= entry
;
9474 const uint32_t ld_private_ss
= 0xe80d8fc0;
9475 if (insn
== ld_private_ss
)
9477 int32_t allocate
= 0;
9481 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9482 if ((insn
& 0xffff0000) == addis_12_1
)
9483 allocate
+= (insn
& 0xffff) << 16;
9484 else if ((insn
& 0xffff0000) == addi_12_1
9485 || (insn
& 0xffff0000) == addi_12_12
)
9486 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9487 else if (insn
!= nop
)
9490 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9492 int extra
= parameters
->options().split_stack_adjust_size();
9494 if (allocate
>= 0 || extra
< 0)
9496 object
->error(_("split-stack stack size overflow at "
9497 "section %u offset %0zx"),
9498 shndx
, static_cast<size_t>(fnoffset
));
9502 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9503 if (insn
!= addis_12_1
)
9505 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9507 insn
= addi_12_12
| (allocate
& 0xffff);
9508 if (insn
!= addi_12_12
)
9510 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9516 insn
= addi_12_1
| (allocate
& 0xffff);
9517 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9520 if (pinsn
!= entry
+ 12)
9521 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9529 if (!object
->has_no_split_stack())
9530 object
->error(_("failed to match split-stack sequence at "
9531 "section %u offset %0zx"),
9532 shndx
, static_cast<size_t>(fnoffset
));
9536 // Scan relocations for a section.
9538 template<int size
, bool big_endian
>
9540 Target_powerpc
<size
, big_endian
>::scan_relocs(
9541 Symbol_table
* symtab
,
9543 Sized_relobj_file
<size
, big_endian
>* object
,
9544 unsigned int data_shndx
,
9545 unsigned int sh_type
,
9546 const unsigned char* prelocs
,
9548 Output_section
* output_section
,
9549 bool needs_special_offset_handling
,
9550 size_t local_symbol_count
,
9551 const unsigned char* plocal_symbols
)
9553 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9554 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9557 if (!this->plt_localentry0_init_
)
9559 bool plt_localentry0
= false;
9561 && this->abiversion() >= 2)
9563 if (parameters
->options().user_set_plt_localentry())
9564 plt_localentry0
= parameters
->options().plt_localentry();
9566 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9567 gold_warning(_("--plt-localentry is especially dangerous without "
9568 "ld.so support to detect ABI violations"));
9570 this->plt_localentry0_
= plt_localentry0
;
9571 this->plt_localentry0_init_
= true;
9574 if (sh_type
== elfcpp::SHT_REL
)
9576 gold_error(_("%s: unsupported REL reloc section"),
9577 object
->name().c_str());
9581 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9590 needs_special_offset_handling
,
9595 // Functor class for processing the global symbol table.
9596 // Removes symbols defined on discarded opd entries.
9598 template<bool big_endian
>
9599 class Global_symbol_visitor_opd
9602 Global_symbol_visitor_opd()
9606 operator()(Sized_symbol
<64>* sym
)
9608 if (sym
->has_symtab_index()
9609 || sym
->source() != Symbol::FROM_OBJECT
9610 || !sym
->in_real_elf())
9613 if (sym
->object()->is_dynamic())
9616 Powerpc_relobj
<64, big_endian
>* symobj
9617 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9618 if (symobj
->opd_shndx() == 0)
9622 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9623 if (shndx
== symobj
->opd_shndx()
9624 && symobj
->get_opd_discard(sym
->value()))
9626 sym
->set_undefined();
9627 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9628 sym
->set_is_defined_in_discarded_section();
9629 sym
->set_symtab_index(-1U);
9634 template<int size
, bool big_endian
>
9636 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9638 Symbol_table
* symtab
)
9642 Output_data_save_res
<size
, big_endian
>* savres
9643 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9644 this->savres_section_
= savres
;
9645 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9646 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9647 savres
, ORDER_TEXT
, false);
9651 // Sort linker created .got section first (for the header), then input
9652 // sections belonging to files using small model code.
9654 template<bool big_endian
>
9655 class Sort_toc_sections
9659 operator()(const Output_section::Input_section
& is1
,
9660 const Output_section::Input_section
& is2
) const
9662 if (!is1
.is_input_section() && is2
.is_input_section())
9665 = (is1
.is_input_section()
9666 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9667 ->has_small_toc_reloc()));
9669 = (is2
.is_input_section()
9670 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9671 ->has_small_toc_reloc()));
9672 return small1
&& !small2
;
9676 // Finalize the sections.
9678 template<int size
, bool big_endian
>
9680 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9682 const Input_objects
* input_objects
,
9683 Symbol_table
* symtab
)
9685 if (parameters
->doing_static_link())
9687 // At least some versions of glibc elf-init.o have a strong
9688 // reference to __rela_iplt marker syms. A weak ref would be
9690 if (this->iplt_
!= NULL
)
9692 Reloc_section
* rel
= this->iplt_
->rel_plt();
9693 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9694 Symbol_table::PREDEFINED
, rel
, 0, 0,
9695 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9696 elfcpp::STV_HIDDEN
, 0, false, true);
9697 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9698 Symbol_table::PREDEFINED
, rel
, 0, 0,
9699 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9700 elfcpp::STV_HIDDEN
, 0, true, true);
9704 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9705 Symbol_table::PREDEFINED
, 0, 0,
9706 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9707 elfcpp::STV_HIDDEN
, 0, true, false);
9708 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9709 Symbol_table::PREDEFINED
, 0, 0,
9710 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9711 elfcpp::STV_HIDDEN
, 0, true, false);
9717 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9718 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9720 if (!parameters
->options().relocatable())
9722 this->define_save_restore_funcs(layout
, symtab
);
9724 // Annoyingly, we need to make these sections now whether or
9725 // not we need them. If we delay until do_relax then we
9726 // need to mess with the relaxation machinery checkpointing.
9727 this->got_section(symtab
, layout
);
9728 this->make_brlt_section(layout
);
9730 if (parameters
->options().toc_sort())
9732 Output_section
* os
= this->got_
->output_section();
9733 if (os
!= NULL
&& os
->input_sections().size() > 1)
9734 std::stable_sort(os
->input_sections().begin(),
9735 os
->input_sections().end(),
9736 Sort_toc_sections
<big_endian
>());
9741 // Fill in some more dynamic tags.
9742 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9745 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9747 : this->plt_
->rel_plt());
9748 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9749 this->rela_dyn_
, true, size
== 32);
9753 if (this->got_
!= NULL
)
9755 this->got_
->finalize_data_size();
9756 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9757 this->got_
, this->got_
->g_o_t());
9759 if (this->has_tls_get_addr_opt_
)
9760 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9764 if (this->glink_
!= NULL
)
9766 this->glink_
->finalize_data_size();
9767 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9769 (this->glink_
->pltresolve_size()
9772 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9773 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9774 ((this->has_localentry0_
9775 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9776 | (this->has_tls_get_addr_opt_
9777 ? elfcpp::PPC64_OPT_TLS
: 0)));
9781 // Emit any relocs we saved in an attempt to avoid generating COPY
9783 if (this->copy_relocs_
.any_saved_relocs())
9784 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9786 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9787 p
!= input_objects
->relobj_end();
9790 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9791 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9792 if (ppc_relobj
->attributes_section_data())
9793 this->merge_object_attributes(ppc_relobj
,
9794 ppc_relobj
->attributes_section_data());
9796 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9797 p
!= input_objects
->dynobj_end();
9800 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9801 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9802 if (ppc_dynobj
->attributes_section_data())
9803 this->merge_object_attributes(ppc_dynobj
,
9804 ppc_dynobj
->attributes_section_data());
9807 // Create a .gnu.attributes section if we have merged any attributes
9809 if (this->attributes_section_data_
!= NULL
9810 && this->attributes_section_data_
->size() != 0)
9812 Output_attributes_section_data
* attributes_section
9813 = new Output_attributes_section_data(*this->attributes_section_data_
);
9814 layout
->add_output_section_data(".gnu.attributes",
9815 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9816 attributes_section
, ORDER_INVALID
, false);
9820 // Merge object attributes from input file called NAME with those of the
9821 // output. The input object attributes are in the object pointed by PASD.
9823 template<int size
, bool big_endian
>
9825 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9827 const Attributes_section_data
* pasd
)
9829 // Return if there is no attributes section data.
9833 // Create output object attributes.
9834 if (this->attributes_section_data_
== NULL
)
9835 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9837 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9838 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9839 Object_attribute
* out_attr
9840 = this->attributes_section_data_
->known_attributes(vendor
);
9842 const char* name
= obj
->name().c_str();
9846 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9847 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9848 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9849 bool warn_only
= obj
->is_dynamic();
9850 if (in_fp
!= out_fp
)
9853 if ((in_fp
& 3) == 0)
9855 else if ((out_fp
& 3) == 0)
9859 out_fp
|= in_fp
& 3;
9860 out_attr
[tag
].set_int_value(out_fp
);
9861 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9862 this->last_fp_
= name
;
9865 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9867 err
= N_("%s uses hard float, %s uses soft float");
9868 first
= this->last_fp_
;
9871 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9873 err
= N_("%s uses hard float, %s uses soft float");
9875 second
= this->last_fp_
;
9877 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9879 err
= N_("%s uses double-precision hard float, "
9880 "%s uses single-precision hard float");
9881 first
= this->last_fp_
;
9884 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9886 err
= N_("%s uses double-precision hard float, "
9887 "%s uses single-precision hard float");
9889 second
= this->last_fp_
;
9892 if (err
|| (in_fp
& 0xc) == 0)
9894 else if ((out_fp
& 0xc) == 0)
9898 out_fp
|= in_fp
& 0xc;
9899 out_attr
[tag
].set_int_value(out_fp
);
9900 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9901 this->last_ld_
= name
;
9904 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9906 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9908 second
= this->last_ld_
;
9910 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9912 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9913 first
= this->last_ld_
;
9916 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9918 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9919 first
= this->last_ld_
;
9922 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9924 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9926 second
= this->last_ld_
;
9931 if (parameters
->options().warn_mismatch())
9934 gold_warning(_(err
), first
, second
);
9936 gold_error(_(err
), first
, second
);
9938 // Arrange for this attribute to be deleted. It's better to
9939 // say "don't know" about a file than to wrongly claim compliance.
9941 out_attr
[tag
].set_type(0);
9947 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9948 int in_vec
= in_attr
[tag
].int_value() & 3;
9949 int out_vec
= out_attr
[tag
].int_value() & 3;
9950 if (in_vec
!= out_vec
)
9955 else if (out_vec
== 0)
9958 out_attr
[tag
].set_int_value(out_vec
);
9959 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9960 this->last_vec_
= name
;
9962 // For now, allow generic to transition to AltiVec or SPE
9963 // without a warning. If GCC marked files with their stack
9964 // alignment and used don't-care markings for files which are
9965 // not affected by the vector ABI, we could warn about this
9967 else if (in_vec
== 1)
9969 else if (out_vec
== 1)
9972 out_attr
[tag
].set_int_value(out_vec
);
9973 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9974 this->last_vec_
= name
;
9976 else if (out_vec
< in_vec
)
9978 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9979 first
= this->last_vec_
;
9982 else if (out_vec
> in_vec
)
9984 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9986 second
= this->last_vec_
;
9990 if (parameters
->options().warn_mismatch())
9991 gold_error(_(err
), first
, second
);
9992 out_attr
[tag
].set_type(0);
9996 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9997 int in_struct
= in_attr
[tag
].int_value() & 3;
9998 int out_struct
= out_attr
[tag
].int_value() & 3;
9999 if (in_struct
!= out_struct
)
10002 if (in_struct
== 0 || in_struct
== 3)
10004 else if (out_struct
== 0)
10006 out_struct
= in_struct
;
10007 out_attr
[tag
].set_int_value(out_struct
);
10008 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10009 this->last_struct_
= name
;
10011 else if (out_struct
< in_struct
)
10013 err
= N_("%s uses r3/r4 for small structure returns, "
10015 first
= this->last_struct_
;
10018 else if (out_struct
> in_struct
)
10020 err
= N_("%s uses r3/r4 for small structure returns, "
10023 second
= this->last_struct_
;
10027 if (parameters
->options().warn_mismatch())
10028 gold_error(_(err
), first
, second
);
10029 out_attr
[tag
].set_type(0);
10034 // Merge Tag_compatibility attributes and any common GNU ones.
10035 this->attributes_section_data_
->merge(name
, pasd
);
10038 // Emit any saved relocs, and mark toc entries using any of these
10039 // relocs as not optimizable.
10041 template<int sh_type
, int size
, bool big_endian
>
10043 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10044 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10047 && parameters
->options().toc_optimize())
10049 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10050 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10051 p
!= this->entries_
.end();
10054 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10057 // If the symbol is no longer defined in a dynamic object,
10058 // then we emitted a COPY relocation. If it is still
10059 // dynamic then we'll need dynamic relocations and thus
10060 // can't optimize toc entries.
10061 if (entry
.sym_
->is_from_dynobj())
10063 Powerpc_relobj
<size
, big_endian
>* ppc_object
10064 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10065 if (entry
.shndx_
== ppc_object
->toc_shndx())
10066 ppc_object
->set_no_toc_opt(entry
.address_
);
10071 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10074 // Return the value to use for a branch relocation.
10076 template<int size
, bool big_endian
>
10078 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10079 const Symbol_table
* symtab
,
10080 const Sized_symbol
<size
>* gsym
,
10081 Powerpc_relobj
<size
, big_endian
>* object
,
10083 unsigned int *dest_shndx
)
10085 if (size
== 32 || this->abiversion() >= 2)
10086 gold_unreachable();
10089 // If the symbol is defined in an opd section, ie. is a function
10090 // descriptor, use the function descriptor code entry address
10091 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10093 && (gsym
->source() != Symbol::FROM_OBJECT
10094 || gsym
->object()->is_dynamic()))
10097 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10098 unsigned int shndx
= symobj
->opd_shndx();
10101 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10102 if (opd_addr
== invalid_address
)
10104 opd_addr
+= symobj
->output_section_address(shndx
);
10105 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10108 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10109 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10112 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10113 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10114 *dest_shndx
= folded
.second
;
10116 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10117 if (sec_addr
== invalid_address
)
10120 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10121 *value
= sec_addr
+ sec_off
;
10128 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10130 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10133 if (gsym
->is_from_dynobj()
10134 || gsym
->is_undefined()
10135 || gsym
->is_preemptible())
10138 if (gsym
->is_absolute())
10139 return !parameters
->options().output_is_position_independent();
10146 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10148 if (psymval
->is_ifunc_symbol())
10152 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10154 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10157 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10158 // pld ra,symbol@got@pcrel
10159 // load/store rt,0(ra)
10161 // pla ra,symbol@pcrel
10162 // load/store rt,0(ra)
10163 // may be translated to
10164 // pload/pstore rt,symbol@pcrel
10166 // This function returns true if the optimization is possible, placing
10167 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10169 // On entry to this function, the linker has already determined that
10170 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10171 // while *PINSN2 is the second instruction.
10174 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10176 uint32_t insn2
= *pinsn2
>> 32;
10179 // Check that regs match.
10180 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10183 switch ((insn2
>> 26) & 63)
10199 // These are the PMLS cases, where we just need to tack a prefix
10200 // on the insn. Check that the D field is zero.
10201 if ((insn2
& 0xffff) != 0)
10203 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10204 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10207 case 58: // lwa, ld
10208 if ((insn2
& 0xfffd) != 0)
10210 i1new
= ((1ULL << 58) | (1ULL << 52)
10211 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10212 | (insn2
& (31ULL << 21)));
10215 case 57: // lxsd, lxssp
10216 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10218 i1new
= ((1ULL << 58) | (1ULL << 52)
10219 | ((40ULL | (insn2
& 3)) << 26)
10220 | (insn2
& (31ULL << 21)));
10223 case 61: // stxsd, stxssp, lxv, stxv
10224 if ((insn2
& 3) == 0)
10226 else if ((insn2
& 3) >= 2)
10228 if ((insn2
& 0xfffc) != 0)
10230 i1new
= ((1ULL << 58) | (1ULL << 52)
10231 | ((44ULL | (insn2
& 3)) << 26)
10232 | (insn2
& (31ULL << 21)));
10236 if ((insn2
& 0xfff0) != 0)
10238 i1new
= ((1ULL << 58) | (1ULL << 52)
10239 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10240 | (insn2
& (31ULL << 21)));
10245 if ((insn2
& 0xffff) != 0)
10247 i1new
= ((1ULL << 58) | (1ULL << 52)
10248 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10251 case 62: // std, stq
10252 if ((insn2
& 0xfffd) != 0)
10254 i1new
= ((1ULL << 58) | (1ULL << 52)
10255 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10256 | (insn2
& (31ULL << 21)));
10261 *pinsn2
= (uint64_t) nop
<< 32;
10265 // Perform a relocation.
10267 template<int size
, bool big_endian
>
10269 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10270 const Relocate_info
<size
, big_endian
>* relinfo
,
10272 Target_powerpc
* target
,
10273 Output_section
* os
,
10275 const unsigned char* preloc
,
10276 const Sized_symbol
<size
>* gsym
,
10277 const Symbol_value
<size
>* psymval
,
10278 unsigned char* view
,
10280 section_size_type view_size
)
10282 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10283 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10284 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10289 if (target
->replace_tls_get_addr(gsym
))
10290 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10292 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10293 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10294 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10296 case Track_tls::NOT_EXPECTED
:
10297 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10298 _("__tls_get_addr call lacks marker reloc"));
10300 case Track_tls::EXPECTED
:
10301 // We have already complained.
10303 case Track_tls::SKIP
:
10304 if (is_plt16_reloc
<size
>(r_type
)
10305 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10306 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10308 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10309 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10311 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10313 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10314 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10316 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10317 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10319 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10320 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10321 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10324 case Track_tls::NORMAL
:
10328 // Offset from start of insn to d-field reloc.
10329 const int d_offset
= big_endian
? 2 : 0;
10331 Powerpc_relobj
<size
, big_endian
>* const object
10332 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10334 bool has_stub_value
= false;
10335 bool localentry0
= false;
10336 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10337 bool has_plt_offset
10339 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10340 : object
->local_has_plt_offset(r_sym
));
10342 && !is_plt16_reloc
<size
>(r_type
)
10343 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10344 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10345 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10346 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10347 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10348 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10349 && (!psymval
->is_ifunc_symbol()
10350 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10354 && target
->abiversion() >= 2
10355 && !parameters
->options().output_is_position_independent()
10356 && !is_branch_reloc
<size
>(r_type
))
10358 Address off
= target
->glink_section()->find_global_entry(gsym
);
10359 if (off
!= invalid_address
)
10361 value
= target
->glink_section()->global_entry_address() + off
;
10362 has_stub_value
= true;
10367 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10368 if (target
->stub_tables().size() == 1)
10369 stub_table
= target
->stub_tables()[0];
10370 if (stub_table
== NULL
10373 && !parameters
->options().output_is_position_independent()
10374 && !is_branch_reloc
<size
>(r_type
)))
10375 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10376 if (stub_table
== NULL
)
10378 // This is a ref from a data section to an ifunc symbol,
10379 // or a non-branch reloc for which we always want to use
10380 // one set of stubs for resolving function addresses.
10381 if (target
->stub_tables().size() != 0)
10382 stub_table
= target
->stub_tables()[0];
10384 if (stub_table
!= NULL
)
10386 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10388 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10389 rela
.get_r_addend());
10391 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10392 rela
.get_r_addend());
10395 value
= stub_table
->stub_address() + ent
->off_
;
10396 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10397 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10398 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10400 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10401 value
+= ent
->tocoff_
;
10404 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10406 if (!(target
->power10_stubs()
10407 && target
->power10_stubs_auto()))
10410 else if (size
== 64
10412 && relnum
< reloc_count
- 1)
10414 Reltype
next_rela(preloc
+ reloc_size
);
10415 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10416 == elfcpp::R_PPC64_TOCSAVE
10417 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
10420 localentry0
= ent
->localentry0_
;
10421 has_stub_value
= true;
10425 // We don't care too much about bogus debug references to
10426 // non-local functions, but otherwise there had better be a plt
10427 // call stub or global entry stub as appropriate.
10428 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10431 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10432 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10433 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10435 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10437 value
= target
->plt_off(gsym
, &plt
);
10439 value
= target
->plt_off(object
, r_sym
, &plt
);
10440 value
+= plt
->address();
10444 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10445 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10446 value
-= (target
->got_section()->output_section()->address()
10447 + object
->toc_base_offset());
10449 else if (parameters
->options().output_is_position_independent())
10451 if (rela
.get_r_addend() >= 32768)
10453 unsigned int got2
= object
->got2_shndx();
10454 value
-= (object
->get_output_section_offset(got2
)
10455 + object
->output_section(got2
)->address()
10456 + rela
.get_r_addend());
10459 value
-= (target
->got_section()->address()
10460 + target
->got_section()->g_o_t());
10463 else if (!has_plt_offset
10464 && (is_plt16_reloc
<size
>(r_type
)
10465 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10466 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10468 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10469 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10470 r_type
= elfcpp::R_POWERPC_NONE
;
10472 else if (!has_plt_offset
10473 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10474 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10476 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10477 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10478 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10479 r_type
= elfcpp::R_POWERPC_NONE
;
10481 else if (r_type
== elfcpp::R_POWERPC_GOT16
10482 || r_type
== elfcpp::R_POWERPC_GOT16_LO
10483 || r_type
== elfcpp::R_POWERPC_GOT16_HI
10484 || r_type
== elfcpp::R_POWERPC_GOT16_HA
10485 || r_type
== elfcpp::R_PPC64_GOT16_DS
10486 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10487 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10491 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10492 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10496 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10497 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10499 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10500 value
+= target
->got_section()->address();
10502 value
-= target
->got_section()->got_base_offset(object
);
10504 else if (r_type
== elfcpp::R_PPC64_TOC
)
10506 value
= (target
->got_section()->output_section()->address()
10507 + object
->toc_base_offset());
10509 else if (gsym
!= NULL
10510 && (r_type
== elfcpp::R_POWERPC_REL24
10511 || r_type
== elfcpp::R_PPC_PLTREL24
)
10516 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10517 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10518 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10519 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10521 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10522 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10523 if ((insn
& 1) != 0
10525 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10527 elfcpp::Swap
<32, big_endian
>::
10528 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10529 can_plt_call
= true;
10534 // If we don't have a branch and link followed by a nop,
10535 // we can't go via the plt because there is no place to
10536 // put a toc restoring instruction.
10537 // Unless we know we won't be returning.
10538 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10539 can_plt_call
= true;
10543 // g++ as of 20130507 emits self-calls without a
10544 // following nop. This is arguably wrong since we have
10545 // conflicting information. On the one hand a global
10546 // symbol and on the other a local call sequence, but
10547 // don't error for this special case.
10548 // It isn't possible to cheaply verify we have exactly
10549 // such a call. Allow all calls to the same section.
10551 Address code
= value
;
10552 if (gsym
->source() == Symbol::FROM_OBJECT
10553 && gsym
->object() == object
)
10555 unsigned int dest_shndx
= 0;
10556 if (target
->abiversion() < 2)
10558 Address addend
= rela
.get_r_addend();
10559 code
= psymval
->value(object
, addend
);
10560 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10561 &code
, &dest_shndx
);
10564 if (dest_shndx
== 0)
10565 dest_shndx
= gsym
->shndx(&is_ordinary
);
10566 ok
= dest_shndx
== relinfo
->data_shndx
;
10570 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10571 _("call lacks nop, can't restore toc; "
10572 "recompile with -fPIC"));
10578 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10579 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10580 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10581 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10582 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10584 // First instruction of a global dynamic sequence, arg setup insn.
10585 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10586 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10587 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10588 if (tls_type
== tls::TLSOPT_NONE
)
10589 got_type
= GOT_TYPE_TLSGD
;
10590 else if (tls_type
== tls::TLSOPT_TO_IE
)
10591 got_type
= GOT_TYPE_TPREL
;
10592 if (got_type
!= GOT_TYPE_STANDARD
)
10596 gold_assert(gsym
->has_got_offset(got_type
));
10597 value
= gsym
->got_offset(got_type
);
10601 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10602 value
= object
->local_got_offset(r_sym
, got_type
);
10604 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10605 value
+= target
->got_section()->address();
10607 value
-= target
->got_section()->got_base_offset(object
);
10609 if (tls_type
== tls::TLSOPT_TO_IE
)
10611 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10613 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10614 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10616 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10618 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10619 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10620 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10621 pinsn
& 0xffffffff);
10622 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10626 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10627 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10629 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10630 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10631 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10633 insn
|= 32 << 26; // lwz
10635 insn
|= 58 << 26; // ld
10636 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10638 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10639 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10642 else if (tls_type
== tls::TLSOPT_TO_LE
)
10644 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10646 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10647 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10649 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10650 // pla pcrel -> paddi r13
10651 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10652 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10653 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10654 pinsn
& 0xffffffff);
10655 r_type
= elfcpp::R_PPC64_TPREL34
;
10656 value
= psymval
->value(object
, rela
.get_r_addend());
10660 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10661 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10663 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10664 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10665 insn
&= (1 << 26) - (1 << 21); // extract rt
10669 insn
|= addis_0_13
;
10670 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10671 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10672 value
= psymval
->value(object
, rela
.get_r_addend());
10676 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10678 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10679 r_type
= elfcpp::R_POWERPC_NONE
;
10684 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10685 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10686 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10687 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10688 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10690 // First instruction of a local dynamic sequence, arg setup insn.
10691 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10692 if (tls_type
== tls::TLSOPT_NONE
)
10694 value
= target
->tlsld_got_offset();
10695 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10696 value
+= target
->got_section()->address();
10698 value
-= target
->got_section()->got_base_offset(object
);
10702 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10703 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10705 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10706 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10708 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10709 // pla pcrel -> paddi r13
10710 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10711 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10712 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10713 pinsn
& 0xffffffff);
10714 r_type
= elfcpp::R_PPC64_TPREL34
;
10715 value
= dtp_offset
;
10717 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10718 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10720 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10721 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10722 insn
&= (1 << 26) - (1 << 21); // extract rt
10726 insn
|= addis_0_13
;
10727 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10728 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10729 value
= dtp_offset
;
10733 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10735 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10736 r_type
= elfcpp::R_POWERPC_NONE
;
10740 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10741 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10742 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10743 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10744 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10746 // Accesses relative to a local dynamic sequence address,
10747 // no optimisation here.
10750 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10751 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10755 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10756 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10758 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10759 value
+= target
->got_section()->address();
10761 value
-= target
->got_section()->got_base_offset(object
);
10763 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10764 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10765 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10766 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10767 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10769 // First instruction of initial exec sequence.
10770 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10771 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10772 if (tls_type
== tls::TLSOPT_NONE
)
10776 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10777 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10781 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10782 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10784 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10785 value
+= target
->got_section()->address();
10787 value
-= target
->got_section()->got_base_offset(object
);
10791 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10792 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10794 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10795 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10797 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10798 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10799 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10800 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10801 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10802 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10803 pinsn
& 0xffffffff);
10804 r_type
= elfcpp::R_PPC64_TPREL34
;
10805 value
= psymval
->value(object
, rela
.get_r_addend());
10807 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10808 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10810 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10811 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10812 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10816 insn
|= addis_0_13
;
10817 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10818 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10819 value
= psymval
->value(object
, rela
.get_r_addend());
10823 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10825 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10826 r_type
= elfcpp::R_POWERPC_NONE
;
10830 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10831 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10833 // Second instruction of a global dynamic sequence,
10834 // the __tls_get_addr call
10835 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10836 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10837 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10838 if (tls_type
!= tls::TLSOPT_NONE
)
10840 if (tls_type
== tls::TLSOPT_TO_IE
)
10842 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10843 Insn insn
= add_3_3_13
;
10846 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10847 r_type
= elfcpp::R_POWERPC_NONE
;
10851 bool is_pcrel
= false;
10852 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10853 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10854 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10855 if (relnum
< reloc_count
- 1)
10857 Reltype
next_rela(preloc
+ reloc_size
);
10858 unsigned int r_type2
10859 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10860 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10861 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10862 && next_rela
.get_r_offset() == rela
.get_r_offset())
10865 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10868 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10869 r_type
= elfcpp::R_POWERPC_NONE
;
10873 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10874 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10876 value
= psymval
->value(object
, rela
.get_r_addend());
10879 this->skip_next_tls_get_addr_call();
10882 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10883 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10885 // Second instruction of a local dynamic sequence,
10886 // the __tls_get_addr call
10887 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10888 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10889 if (tls_type
== tls::TLSOPT_TO_LE
)
10891 bool is_pcrel
= false;
10892 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10893 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10894 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10895 if (relnum
< reloc_count
- 1)
10897 Reltype
next_rela(preloc
+ reloc_size
);
10898 unsigned int r_type2
10899 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10900 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10901 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10902 && next_rela
.get_r_offset() == rela
.get_r_offset())
10905 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10908 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10909 r_type
= elfcpp::R_POWERPC_NONE
;
10913 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10914 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10916 value
= dtp_offset
;
10918 this->skip_next_tls_get_addr_call();
10921 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10923 // Second instruction of an initial exec sequence
10924 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10925 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10926 if (tls_type
== tls::TLSOPT_TO_LE
)
10928 Address roff
= rela
.get_r_offset() & 3;
10929 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10930 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10931 unsigned int reg
= size
== 32 ? 2 : 13;
10932 insn
= at_tls_transform(insn
, reg
);
10933 gold_assert(insn
!= 0);
10936 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10937 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10939 value
= psymval
->value(object
, rela
.get_r_addend());
10941 else if (roff
== 1)
10943 // For pcrel IE to LE we already have the full offset
10944 // and thus don't need an addi here. A nop or mr will do.
10945 if ((insn
& (0x3f << 26)) == 14 << 26)
10947 // Extract regs from addi rt,ra,si.
10948 unsigned int rt
= (insn
>> 21) & 0x1f;
10949 unsigned int ra
= (insn
>> 16) & 0x1f;
10954 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
10955 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
10956 insn
|= (31u << 26) | (444u << 1);
10959 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10960 r_type
= elfcpp::R_POWERPC_NONE
;
10964 else if (!has_stub_value
)
10966 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
10967 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
10969 // PLTCALL without plt entry => convert to direct call
10970 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10971 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10972 insn
= (insn
& 1) | b
;
10973 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10975 r_type
= elfcpp::R_PPC_PLTREL24
;
10976 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10977 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
10979 r_type
= elfcpp::R_POWERPC_REL24
;
10981 Address addend
= 0;
10983 && (r_type
== elfcpp::R_PPC_PLTREL24
10984 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10985 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10986 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
10987 addend
= rela
.get_r_addend();
10988 value
= psymval
->value(object
, addend
);
10989 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
10991 if (target
->abiversion() >= 2)
10994 value
+= object
->ppc64_local_entry_offset(gsym
);
10996 value
+= object
->ppc64_local_entry_offset(r_sym
);
11000 unsigned int dest_shndx
;
11001 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11002 &value
, &dest_shndx
);
11005 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
11006 if (max_branch_offset
!= 0
11007 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
11009 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11011 ? object
->ppc64_needs_toc(gsym
)
11012 : object
->ppc64_needs_toc(r_sym
)))))
11014 Stub_table
<size
, big_endian
>* stub_table
11015 = object
->stub_table(relinfo
->data_shndx
);
11016 if (stub_table
!= NULL
)
11018 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11019 = stub_table
->find_long_branch_entry(object
, value
);
11022 if (ent
->save_res_
)
11023 value
= (value
- target
->savres_section()->address()
11024 + stub_table
->branch_size());
11027 value
= (stub_table
->stub_address()
11028 + stub_table
->plt_size()
11031 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11032 value
+= ent
->tocoff_
;
11034 has_stub_value
= true;
11042 case elfcpp::R_PPC64_REL24_NOTOC
:
11046 case elfcpp::R_PPC64_REL64
:
11047 case elfcpp::R_POWERPC_REL32
:
11048 case elfcpp::R_POWERPC_REL24
:
11049 case elfcpp::R_PPC_PLTREL24
:
11050 case elfcpp::R_PPC_LOCAL24PC
:
11051 case elfcpp::R_POWERPC_REL16
:
11052 case elfcpp::R_POWERPC_REL16_LO
:
11053 case elfcpp::R_POWERPC_REL16_HI
:
11054 case elfcpp::R_POWERPC_REL16_HA
:
11055 case elfcpp::R_POWERPC_REL16DX_HA
:
11056 case elfcpp::R_PPC64_REL16_HIGH
:
11057 case elfcpp::R_PPC64_REL16_HIGHA
:
11058 case elfcpp::R_PPC64_REL16_HIGHER
:
11059 case elfcpp::R_PPC64_REL16_HIGHERA
:
11060 case elfcpp::R_PPC64_REL16_HIGHEST
:
11061 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11062 case elfcpp::R_POWERPC_REL14
:
11063 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11064 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11065 case elfcpp::R_PPC64_PCREL34
:
11066 case elfcpp::R_PPC64_GOT_PCREL34
:
11067 case elfcpp::R_PPC64_PLT_PCREL34
:
11068 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11069 case elfcpp::R_PPC64_PCREL28
:
11070 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11071 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11072 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11073 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11074 case elfcpp::R_PPC64_REL16_HIGHER34
:
11075 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11076 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11077 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11081 case elfcpp::R_PPC64_TOC16
:
11082 case elfcpp::R_PPC64_TOC16_LO
:
11083 case elfcpp::R_PPC64_TOC16_HI
:
11084 case elfcpp::R_PPC64_TOC16_HA
:
11085 case elfcpp::R_PPC64_TOC16_DS
:
11086 case elfcpp::R_PPC64_TOC16_LO_DS
:
11087 // Subtract the TOC base address.
11088 value
-= (target
->got_section()->output_section()->address()
11089 + object
->toc_base_offset());
11092 case elfcpp::R_POWERPC_SECTOFF
:
11093 case elfcpp::R_POWERPC_SECTOFF_LO
:
11094 case elfcpp::R_POWERPC_SECTOFF_HI
:
11095 case elfcpp::R_POWERPC_SECTOFF_HA
:
11096 case elfcpp::R_PPC64_SECTOFF_DS
:
11097 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11099 value
-= os
->address();
11102 case elfcpp::R_PPC64_TPREL16_DS
:
11103 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11104 case elfcpp::R_PPC64_TPREL16_HIGH
:
11105 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11107 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11110 case elfcpp::R_POWERPC_TPREL16
:
11111 case elfcpp::R_POWERPC_TPREL16_LO
:
11112 case elfcpp::R_POWERPC_TPREL16_HI
:
11113 case elfcpp::R_POWERPC_TPREL16_HA
:
11114 case elfcpp::R_POWERPC_TPREL
:
11115 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11116 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11117 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11118 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11119 case elfcpp::R_PPC64_TPREL34
:
11120 // tls symbol values are relative to tls_segment()->vaddr()
11121 value
-= tp_offset
;
11124 case elfcpp::R_PPC64_DTPREL16_DS
:
11125 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11126 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11127 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11128 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11129 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11131 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11132 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11135 case elfcpp::R_POWERPC_DTPREL16
:
11136 case elfcpp::R_POWERPC_DTPREL16_LO
:
11137 case elfcpp::R_POWERPC_DTPREL16_HI
:
11138 case elfcpp::R_POWERPC_DTPREL16_HA
:
11139 case elfcpp::R_POWERPC_DTPREL
:
11140 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11141 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11142 case elfcpp::R_PPC64_DTPREL34
:
11143 // tls symbol values are relative to tls_segment()->vaddr()
11144 value
-= dtp_offset
;
11147 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11149 value
+= object
->ppc64_local_entry_offset(gsym
);
11151 value
+= object
->ppc64_local_entry_offset(r_sym
);
11158 Insn branch_bit
= 0;
11161 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11162 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11163 branch_bit
= 1 << 21;
11165 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11166 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11168 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11169 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11170 insn
&= ~(1 << 21);
11171 insn
|= branch_bit
;
11172 if (this->is_isa_v2
)
11174 // Set 'a' bit. This is 0b00010 in BO field for branch
11175 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11176 // for branch on CTR insns (BO == 1a00t or 1a01t).
11177 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11178 insn
|= 0x02 << 21;
11179 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11180 insn
|= 0x08 << 21;
11186 // Invert 'y' bit if not the default.
11187 if (static_cast<Signed_address
>(value
) < 0)
11190 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11194 case elfcpp::R_POWERPC_PLT16_HA
:
11196 && !parameters
->options().output_is_position_independent())
11198 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11199 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11201 // Convert addis to lis.
11202 if ((insn
& (0x3f << 26)) == 15u << 26
11203 && (insn
& (0x1f << 16)) != 0)
11205 insn
&= ~(0x1f << 16);
11206 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11216 ? relative_value_is_known(gsym
)
11217 : relative_value_is_known(psymval
))
11222 uint64_t pinsn
, pinsn2
;
11229 // Multi-instruction sequences that access the GOT/TOC can
11230 // be optimized, eg.
11231 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11232 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11234 // addis ra,r2,0; addi rb,ra,x@toc@l;
11235 // to nop; addi rb,r2,x@toc;
11236 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11237 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11238 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11239 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11240 case elfcpp::R_POWERPC_GOT16_HA
:
11241 case elfcpp::R_PPC64_TOC16_HA
:
11242 if (size
== 64 && parameters
->options().toc_optimize())
11244 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11245 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11246 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11247 && object
->make_toc_relative(target
, &value
))
11248 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11249 && object
->make_got_relative(target
, psymval
,
11250 rela
.get_r_addend(),
11253 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11254 == ((15u << 26) | (2 << 16)));
11256 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11257 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11258 && value
+ 0x8000 < 0x10000)
11260 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11266 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11267 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11268 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11269 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11270 case elfcpp::R_POWERPC_GOT16_LO
:
11271 case elfcpp::R_PPC64_GOT16_LO_DS
:
11272 case elfcpp::R_PPC64_TOC16_LO
:
11273 case elfcpp::R_PPC64_TOC16_LO_DS
:
11274 if (size
== 64 && parameters
->options().toc_optimize())
11276 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11277 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11278 bool changed
= false;
11279 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11280 && object
->make_toc_relative(target
, &value
))
11281 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11282 && object
->make_got_relative(target
, psymval
,
11283 rela
.get_r_addend(),
11286 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11287 insn
^= (14u << 26) ^ (58u << 26);
11288 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11291 if (ok_lo_toc_insn(insn
, r_type
)
11292 && value
+ 0x8000 < 0x10000)
11294 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11296 // Transform addic to addi when we change reg.
11297 insn
&= ~((0x3f << 26) | (0x1f << 16));
11298 insn
|= (14u << 26) | (2 << 16);
11302 insn
&= ~(0x1f << 16);
11308 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11312 case elfcpp::R_PPC64_GOT_PCREL34
:
11313 if (size
== 64 && parameters
->options().toc_optimize())
11315 iview
= reinterpret_cast<Insn
*>(view
);
11316 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11318 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11319 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11320 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11323 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11325 if (relval
+ (1ULL << 33) < 1ULL << 34)
11328 // Replace with paddi
11329 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11330 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11331 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11332 pinsn
& 0xffffffff);
11338 case elfcpp::R_PPC64_PCREL34
:
11341 iview
= reinterpret_cast<Insn
*>(view
);
11342 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11344 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11345 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11346 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11347 | (14ULL << 26) /* paddi */))
11351 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11352 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11353 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11354 if (relnum
>= reloc_count
- 1)
11357 Reltype
next_rela(preloc
+ reloc_size
);
11358 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11359 != elfcpp::R_PPC64_PCREL_OPT
)
11360 || next_rela
.get_r_offset() != rela
.get_r_offset())
11363 Address off
= next_rela
.get_r_addend();
11365 off
= 8; // zero means next insn.
11366 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11369 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11370 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11372 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11374 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11376 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11377 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11378 pinsn
& 0xffffffff);
11379 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11384 case elfcpp::R_POWERPC_TPREL16_HA
:
11385 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11387 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11388 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11393 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11395 // R_PPC_TLSGD, R_PPC_TLSLD
11398 case elfcpp::R_POWERPC_TPREL16_LO
:
11399 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11401 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11402 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11403 insn
&= ~(0x1f << 16);
11404 insn
|= (size
== 32 ? 2 : 13) << 16;
11405 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11409 case elfcpp::R_PPC64_ENTRY
:
11412 value
= (target
->got_section()->output_section()->address()
11413 + object
->toc_base_offset());
11414 if (value
+ 0x80008000 <= 0xffffffff
11415 && !parameters
->options().output_is_position_independent())
11417 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11418 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11419 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11421 if ((insn1
& ~0xfffc) == ld_2_12
11422 && insn2
== add_2_2_12
)
11424 insn1
= lis_2
+ ha(value
);
11425 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11426 insn2
= addi_2_2
+ l(value
);
11427 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11434 if (value
+ 0x80008000 <= 0xffffffff)
11436 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11437 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11438 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11440 if ((insn1
& ~0xfffc) == ld_2_12
11441 && insn2
== add_2_2_12
)
11443 insn1
= addis_2_12
+ ha(value
);
11444 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11445 insn2
= addi_2_2
+ l(value
);
11446 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11454 case elfcpp::R_POWERPC_REL16_LO
:
11455 // If we are generating a non-PIC executable, edit
11456 // 0: addis 2,12,.TOC.-0b@ha
11457 // addi 2,2,.TOC.-0b@l
11458 // used by ELFv2 global entry points to set up r2, to
11460 // addi 2,2,.TOC.@l
11461 // if .TOC. is in range. */
11463 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11466 && target
->abiversion() >= 2
11467 && !parameters
->options().output_is_position_independent()
11468 && rela
.get_r_addend() == d_offset
+ 4
11470 && strcmp(gsym
->name(), ".TOC.") == 0)
11472 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11473 Reltype
prev_rela(preloc
- reloc_size
);
11474 if ((prev_rela
.get_r_info()
11475 == elfcpp::elf_r_info
<size
>(r_sym
,
11476 elfcpp::R_POWERPC_REL16_HA
))
11477 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11478 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11480 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11481 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11482 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11484 if ((insn1
& 0xffff0000) == addis_2_12
11485 && (insn2
& 0xffff0000) == addi_2_2
)
11487 insn1
= lis_2
+ ha(value
+ address
- 4);
11488 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11489 insn2
= addi_2_2
+ l(value
+ address
- 4);
11490 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11493 relinfo
->rr
->set_strategy(relnum
- 1,
11494 Relocatable_relocs::RELOC_SPECIAL
);
11495 relinfo
->rr
->set_strategy(relnum
,
11496 Relocatable_relocs::RELOC_SPECIAL
);
11506 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11507 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11510 case elfcpp::R_POWERPC_ADDR32
:
11511 case elfcpp::R_POWERPC_UADDR32
:
11513 overflow
= Reloc::CHECK_BITFIELD
;
11516 case elfcpp::R_POWERPC_REL32
:
11517 case elfcpp::R_POWERPC_REL16DX_HA
:
11519 overflow
= Reloc::CHECK_SIGNED
;
11522 case elfcpp::R_POWERPC_UADDR16
:
11523 overflow
= Reloc::CHECK_BITFIELD
;
11526 case elfcpp::R_POWERPC_ADDR16
:
11527 // We really should have three separate relocations,
11528 // one for 16-bit data, one for insns with 16-bit signed fields,
11529 // and one for insns with 16-bit unsigned fields.
11530 overflow
= Reloc::CHECK_BITFIELD
;
11531 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11532 overflow
= Reloc::CHECK_LOW_INSN
;
11535 case elfcpp::R_POWERPC_ADDR16_HI
:
11536 case elfcpp::R_POWERPC_ADDR16_HA
:
11537 case elfcpp::R_POWERPC_GOT16_HI
:
11538 case elfcpp::R_POWERPC_GOT16_HA
:
11539 case elfcpp::R_POWERPC_PLT16_HI
:
11540 case elfcpp::R_POWERPC_PLT16_HA
:
11541 case elfcpp::R_POWERPC_SECTOFF_HI
:
11542 case elfcpp::R_POWERPC_SECTOFF_HA
:
11543 case elfcpp::R_PPC64_TOC16_HI
:
11544 case elfcpp::R_PPC64_TOC16_HA
:
11545 case elfcpp::R_PPC64_PLTGOT16_HI
:
11546 case elfcpp::R_PPC64_PLTGOT16_HA
:
11547 case elfcpp::R_POWERPC_TPREL16_HI
:
11548 case elfcpp::R_POWERPC_TPREL16_HA
:
11549 case elfcpp::R_POWERPC_DTPREL16_HI
:
11550 case elfcpp::R_POWERPC_DTPREL16_HA
:
11551 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11552 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11553 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11554 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11555 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11556 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11557 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11558 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11559 case elfcpp::R_POWERPC_REL16_HI
:
11560 case elfcpp::R_POWERPC_REL16_HA
:
11562 overflow
= Reloc::CHECK_HIGH_INSN
;
11565 case elfcpp::R_POWERPC_REL16
:
11566 case elfcpp::R_PPC64_TOC16
:
11567 case elfcpp::R_POWERPC_GOT16
:
11568 case elfcpp::R_POWERPC_SECTOFF
:
11569 case elfcpp::R_POWERPC_TPREL16
:
11570 case elfcpp::R_POWERPC_DTPREL16
:
11571 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11572 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11573 case elfcpp::R_POWERPC_GOT_TPREL16
:
11574 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11575 overflow
= Reloc::CHECK_LOW_INSN
;
11578 case elfcpp::R_PPC64_REL24_NOTOC
:
11582 case elfcpp::R_POWERPC_ADDR24
:
11583 case elfcpp::R_POWERPC_ADDR14
:
11584 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11585 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11586 case elfcpp::R_PPC64_ADDR16_DS
:
11587 case elfcpp::R_POWERPC_REL24
:
11588 case elfcpp::R_PPC_PLTREL24
:
11589 case elfcpp::R_PPC_LOCAL24PC
:
11590 case elfcpp::R_PPC64_TPREL16_DS
:
11591 case elfcpp::R_PPC64_DTPREL16_DS
:
11592 case elfcpp::R_PPC64_TOC16_DS
:
11593 case elfcpp::R_PPC64_GOT16_DS
:
11594 case elfcpp::R_PPC64_SECTOFF_DS
:
11595 case elfcpp::R_POWERPC_REL14
:
11596 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11597 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11598 case elfcpp::R_PPC64_D34
:
11599 case elfcpp::R_PPC64_PCREL34
:
11600 case elfcpp::R_PPC64_GOT_PCREL34
:
11601 case elfcpp::R_PPC64_PLT_PCREL34
:
11602 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11603 case elfcpp::R_PPC64_D28
:
11604 case elfcpp::R_PPC64_PCREL28
:
11605 case elfcpp::R_PPC64_TPREL34
:
11606 case elfcpp::R_PPC64_DTPREL34
:
11607 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11608 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11609 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11610 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11611 overflow
= Reloc::CHECK_SIGNED
;
11615 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11618 if (overflow
== Reloc::CHECK_LOW_INSN
11619 || overflow
== Reloc::CHECK_HIGH_INSN
)
11621 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11623 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11624 overflow
= Reloc::CHECK_BITFIELD
;
11625 else if (overflow
== Reloc::CHECK_LOW_INSN
11626 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11627 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11628 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11629 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11630 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11631 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11632 overflow
= Reloc::CHECK_UNSIGNED
;
11634 overflow
= Reloc::CHECK_SIGNED
;
11637 bool maybe_dq_reloc
= false;
11638 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11639 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11642 case elfcpp::R_POWERPC_NONE
:
11643 case elfcpp::R_POWERPC_TLS
:
11644 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11645 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11646 case elfcpp::R_POWERPC_PLTSEQ
:
11647 case elfcpp::R_POWERPC_PLTCALL
:
11648 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11649 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11650 case elfcpp::R_PPC64_PCREL_OPT
:
11653 case elfcpp::R_PPC64_ADDR64
:
11654 case elfcpp::R_PPC64_REL64
:
11655 case elfcpp::R_PPC64_TOC
:
11656 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11657 Reloc::addr64(view
, value
);
11660 case elfcpp::R_POWERPC_TPREL
:
11661 case elfcpp::R_POWERPC_DTPREL
:
11663 Reloc::addr64(view
, value
);
11665 status
= Reloc::addr32(view
, value
, overflow
);
11668 case elfcpp::R_PPC64_UADDR64
:
11669 Reloc::addr64_u(view
, value
);
11672 case elfcpp::R_POWERPC_ADDR32
:
11673 status
= Reloc::addr32(view
, value
, overflow
);
11676 case elfcpp::R_POWERPC_REL32
:
11677 case elfcpp::R_POWERPC_UADDR32
:
11678 status
= Reloc::addr32_u(view
, value
, overflow
);
11681 case elfcpp::R_PPC64_REL24_NOTOC
:
11683 goto unsupp
; // R_PPC_EMB_RELSDA
11685 case elfcpp::R_POWERPC_ADDR24
:
11686 case elfcpp::R_POWERPC_REL24
:
11687 case elfcpp::R_PPC_PLTREL24
:
11688 case elfcpp::R_PPC_LOCAL24PC
:
11689 status
= Reloc::addr24(view
, value
, overflow
);
11692 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11693 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11694 case elfcpp::R_POWERPC_GOT_TPREL16
:
11695 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11698 // On ppc64 these are all ds form
11699 maybe_dq_reloc
= true;
11703 case elfcpp::R_POWERPC_ADDR16
:
11704 case elfcpp::R_POWERPC_REL16
:
11705 case elfcpp::R_PPC64_TOC16
:
11706 case elfcpp::R_POWERPC_GOT16
:
11707 case elfcpp::R_POWERPC_SECTOFF
:
11708 case elfcpp::R_POWERPC_TPREL16
:
11709 case elfcpp::R_POWERPC_DTPREL16
:
11710 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11711 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11712 case elfcpp::R_POWERPC_ADDR16_LO
:
11713 case elfcpp::R_POWERPC_REL16_LO
:
11714 case elfcpp::R_PPC64_TOC16_LO
:
11715 case elfcpp::R_POWERPC_GOT16_LO
:
11716 case elfcpp::R_POWERPC_PLT16_LO
:
11717 case elfcpp::R_POWERPC_SECTOFF_LO
:
11718 case elfcpp::R_POWERPC_TPREL16_LO
:
11719 case elfcpp::R_POWERPC_DTPREL16_LO
:
11720 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11721 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11723 status
= Reloc::addr16(view
, value
, overflow
);
11725 maybe_dq_reloc
= true;
11728 case elfcpp::R_POWERPC_UADDR16
:
11729 status
= Reloc::addr16_u(view
, value
, overflow
);
11732 case elfcpp::R_PPC64_ADDR16_HIGH
:
11733 case elfcpp::R_PPC64_TPREL16_HIGH
:
11734 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11736 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11739 case elfcpp::R_POWERPC_ADDR16_HI
:
11740 case elfcpp::R_POWERPC_REL16_HI
:
11741 case elfcpp::R_PPC64_REL16_HIGH
:
11742 case elfcpp::R_PPC64_TOC16_HI
:
11743 case elfcpp::R_POWERPC_GOT16_HI
:
11744 case elfcpp::R_POWERPC_PLT16_HI
:
11745 case elfcpp::R_POWERPC_SECTOFF_HI
:
11746 case elfcpp::R_POWERPC_TPREL16_HI
:
11747 case elfcpp::R_POWERPC_DTPREL16_HI
:
11748 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11749 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11750 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11751 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11752 Reloc::addr16_hi(view
, value
);
11755 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11756 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11757 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11759 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11762 case elfcpp::R_POWERPC_ADDR16_HA
:
11763 case elfcpp::R_POWERPC_REL16_HA
:
11764 case elfcpp::R_PPC64_REL16_HIGHA
:
11765 case elfcpp::R_PPC64_TOC16_HA
:
11766 case elfcpp::R_POWERPC_GOT16_HA
:
11767 case elfcpp::R_POWERPC_PLT16_HA
:
11768 case elfcpp::R_POWERPC_SECTOFF_HA
:
11769 case elfcpp::R_POWERPC_TPREL16_HA
:
11770 case elfcpp::R_POWERPC_DTPREL16_HA
:
11771 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11772 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11773 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11774 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11775 Reloc::addr16_ha(view
, value
);
11778 case elfcpp::R_POWERPC_REL16DX_HA
:
11779 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11782 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11784 // R_PPC_EMB_NADDR16_LO
11787 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11788 case elfcpp::R_PPC64_REL16_HIGHER
:
11789 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11790 Reloc::addr16_hi2(view
, value
);
11793 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11795 // R_PPC_EMB_NADDR16_HI
11798 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11799 case elfcpp::R_PPC64_REL16_HIGHERA
:
11800 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11801 Reloc::addr16_ha2(view
, value
);
11804 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11806 // R_PPC_EMB_NADDR16_HA
11809 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11810 case elfcpp::R_PPC64_REL16_HIGHEST
:
11811 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11812 Reloc::addr16_hi3(view
, value
);
11815 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11817 // R_PPC_EMB_SDAI16
11820 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11821 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11822 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11823 Reloc::addr16_ha3(view
, value
);
11826 case elfcpp::R_PPC64_DTPREL16_DS
:
11827 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11829 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11832 case elfcpp::R_PPC64_TPREL16_DS
:
11833 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11835 // R_PPC_TLSGD, R_PPC_TLSLD
11838 case elfcpp::R_PPC64_ADDR16_DS
:
11839 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11840 case elfcpp::R_PPC64_TOC16_DS
:
11841 case elfcpp::R_PPC64_TOC16_LO_DS
:
11842 case elfcpp::R_PPC64_GOT16_DS
:
11843 case elfcpp::R_PPC64_GOT16_LO_DS
:
11844 case elfcpp::R_PPC64_PLT16_LO_DS
:
11845 case elfcpp::R_PPC64_SECTOFF_DS
:
11846 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11847 maybe_dq_reloc
= true;
11850 case elfcpp::R_POWERPC_ADDR14
:
11851 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11852 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11853 case elfcpp::R_POWERPC_REL14
:
11854 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11855 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11856 status
= Reloc::addr14(view
, value
, overflow
);
11859 case elfcpp::R_POWERPC_COPY
:
11860 case elfcpp::R_POWERPC_GLOB_DAT
:
11861 case elfcpp::R_POWERPC_JMP_SLOT
:
11862 case elfcpp::R_POWERPC_RELATIVE
:
11863 case elfcpp::R_POWERPC_DTPMOD
:
11864 case elfcpp::R_PPC64_JMP_IREL
:
11865 case elfcpp::R_POWERPC_IRELATIVE
:
11866 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11867 _("unexpected reloc %u in object file"),
11871 case elfcpp::R_PPC64_TOCSAVE
:
11877 Symbol_location loc
;
11878 loc
.object
= relinfo
->object
;
11879 loc
.shndx
= relinfo
->data_shndx
;
11880 loc
.offset
= rela
.get_r_offset();
11881 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11882 if (p
!= target
->tocsave_loc().end())
11884 // If we've generated plt calls using this tocsave, then
11885 // the nop needs to be changed to save r2.
11886 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11887 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11888 elfcpp::Swap
<32, big_endian
>::
11889 writeval(iview
, std_2_1
+ target
->stk_toc());
11894 case elfcpp::R_PPC_EMB_SDA2I16
:
11895 case elfcpp::R_PPC_EMB_SDA2REL
:
11898 // R_PPC64_TLSGD, R_PPC64_TLSLD
11901 case elfcpp::R_PPC64_D34
:
11902 case elfcpp::R_PPC64_D34_LO
:
11903 case elfcpp::R_PPC64_PCREL34
:
11904 case elfcpp::R_PPC64_GOT_PCREL34
:
11905 case elfcpp::R_PPC64_PLT_PCREL34
:
11906 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11907 case elfcpp::R_PPC64_TPREL34
:
11908 case elfcpp::R_PPC64_DTPREL34
:
11909 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11910 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11911 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11912 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11915 status
= Reloc::addr34(view
, value
, overflow
);
11918 case elfcpp::R_PPC64_D34_HI30
:
11921 Reloc::addr34_hi(view
, value
);
11924 case elfcpp::R_PPC64_D34_HA30
:
11927 Reloc::addr34_ha(view
, value
);
11930 case elfcpp::R_PPC64_D28
:
11931 case elfcpp::R_PPC64_PCREL28
:
11934 status
= Reloc::addr28(view
, value
, overflow
);
11937 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11938 case elfcpp::R_PPC64_REL16_HIGHER34
:
11941 Reloc::addr16_higher34(view
, value
);
11944 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11945 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11948 Reloc::addr16_highera34(view
, value
);
11951 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11952 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11955 Reloc::addr16_highest34(view
, value
);
11958 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
11959 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11962 Reloc::addr16_highesta34(view
, value
);
11965 case elfcpp::R_POWERPC_PLT32
:
11966 case elfcpp::R_POWERPC_PLTREL32
:
11967 case elfcpp::R_PPC_SDAREL16
:
11968 case elfcpp::R_POWERPC_ADDR30
:
11969 case elfcpp::R_PPC64_PLT64
:
11970 case elfcpp::R_PPC64_PLTREL64
:
11971 case elfcpp::R_PPC64_PLTGOT16
:
11972 case elfcpp::R_PPC64_PLTGOT16_LO
:
11973 case elfcpp::R_PPC64_PLTGOT16_HI
:
11974 case elfcpp::R_PPC64_PLTGOT16_HA
:
11975 case elfcpp::R_PPC64_PLTGOT16_DS
:
11976 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
11977 case elfcpp::R_PPC_TOC16
:
11980 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11981 _("unsupported reloc %u"),
11986 if (maybe_dq_reloc
)
11989 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11991 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
11992 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
11993 && (insn
& 3) == 1))
11994 status
= Reloc::addr16_dq(view
, value
, overflow
);
11995 else if (size
== 64
11996 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
11997 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
11998 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
11999 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12000 status
= Reloc::addr16_ds(view
, value
, overflow
);
12002 status
= Reloc::addr16(view
, value
, overflow
);
12005 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12008 && gsym
->is_undefined()
12009 && is_branch_reloc
<size
>(r_type
))))
12011 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12012 _("relocation overflow"));
12013 if (has_stub_value
)
12014 gold_info(_("try relinking with a smaller --stub-group-size"));
12020 // Relocate section data.
12022 template<int size
, bool big_endian
>
12024 Target_powerpc
<size
, big_endian
>::relocate_section(
12025 const Relocate_info
<size
, big_endian
>* relinfo
,
12026 unsigned int sh_type
,
12027 const unsigned char* prelocs
,
12028 size_t reloc_count
,
12029 Output_section
* output_section
,
12030 bool needs_special_offset_handling
,
12031 unsigned char* view
,
12033 section_size_type view_size
,
12034 const Reloc_symbol_changes
* reloc_symbol_changes
)
12036 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12037 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12038 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12039 Powerpc_comdat_behavior
;
12040 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12043 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12045 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12046 Powerpc_comdat_behavior
, Classify_reloc
>(
12052 needs_special_offset_handling
,
12056 reloc_symbol_changes
);
12059 template<int size
, bool big_endian
>
12060 class Powerpc_scan_relocatable_reloc
12063 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12064 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12065 static const int sh_type
= elfcpp::SHT_RELA
;
12067 // Return the symbol referred to by the relocation.
12068 static inline unsigned int
12069 get_r_sym(const Reltype
* reloc
)
12070 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12072 // Return the type of the relocation.
12073 static inline unsigned int
12074 get_r_type(const Reltype
* reloc
)
12075 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12077 // Return the strategy to use for a local symbol which is not a
12078 // section symbol, given the relocation type.
12079 inline Relocatable_relocs::Reloc_strategy
12080 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12082 if (r_type
== 0 && r_sym
== 0)
12083 return Relocatable_relocs::RELOC_DISCARD
;
12084 return Relocatable_relocs::RELOC_COPY
;
12087 // Return the strategy to use for a local symbol which is a section
12088 // symbol, given the relocation type.
12089 inline Relocatable_relocs::Reloc_strategy
12090 local_section_strategy(unsigned int, Relobj
*)
12092 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12095 // Return the strategy to use for a global symbol, given the
12096 // relocation type, the object, and the symbol index.
12097 inline Relocatable_relocs::Reloc_strategy
12098 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12101 && (r_type
== elfcpp::R_PPC_PLTREL24
12102 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12103 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12104 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12105 return Relocatable_relocs::RELOC_SPECIAL
;
12106 return Relocatable_relocs::RELOC_COPY
;
12110 // Scan the relocs during a relocatable link.
12112 template<int size
, bool big_endian
>
12114 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12115 Symbol_table
* symtab
,
12117 Sized_relobj_file
<size
, big_endian
>* object
,
12118 unsigned int data_shndx
,
12119 unsigned int sh_type
,
12120 const unsigned char* prelocs
,
12121 size_t reloc_count
,
12122 Output_section
* output_section
,
12123 bool needs_special_offset_handling
,
12124 size_t local_symbol_count
,
12125 const unsigned char* plocal_symbols
,
12126 Relocatable_relocs
* rr
)
12128 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12130 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12132 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12140 needs_special_offset_handling
,
12141 local_symbol_count
,
12146 // Scan the relocs for --emit-relocs.
12148 template<int size
, bool big_endian
>
12150 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12151 Symbol_table
* symtab
,
12153 Sized_relobj_file
<size
, big_endian
>* object
,
12154 unsigned int data_shndx
,
12155 unsigned int sh_type
,
12156 const unsigned char* prelocs
,
12157 size_t reloc_count
,
12158 Output_section
* output_section
,
12159 bool needs_special_offset_handling
,
12160 size_t local_symbol_count
,
12161 const unsigned char* plocal_syms
,
12162 Relocatable_relocs
* rr
)
12164 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12166 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12167 Emit_relocs_strategy
;
12169 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12171 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12179 needs_special_offset_handling
,
12180 local_symbol_count
,
12185 // Emit relocations for a section.
12186 // This is a modified version of the function by the same name in
12187 // target-reloc.h. Using relocate_special_relocatable for
12188 // R_PPC_PLTREL24 would require duplication of the entire body of the
12189 // loop, so we may as well duplicate the whole thing.
12191 template<int size
, bool big_endian
>
12193 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12194 const Relocate_info
<size
, big_endian
>* relinfo
,
12195 unsigned int sh_type
,
12196 const unsigned char* prelocs
,
12197 size_t reloc_count
,
12198 Output_section
* output_section
,
12199 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12201 Address view_address
,
12203 unsigned char* reloc_view
,
12204 section_size_type reloc_view_size
)
12206 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12208 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12209 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12210 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12211 // Offset from start of insn to d-field reloc.
12212 const int d_offset
= big_endian
? 2 : 0;
12214 Powerpc_relobj
<size
, big_endian
>* const object
12215 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12216 const unsigned int local_count
= object
->local_symbol_count();
12217 unsigned int got2_shndx
= object
->got2_shndx();
12218 Address got2_addend
= 0;
12219 if (got2_shndx
!= 0)
12221 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12222 gold_assert(got2_addend
!= invalid_address
);
12225 const bool relocatable
= parameters
->options().relocatable();
12227 unsigned char* pwrite
= reloc_view
;
12228 bool zap_next
= false;
12229 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12231 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12232 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12235 Reltype
reloc(prelocs
);
12236 Reltype_write
reloc_write(pwrite
);
12238 Address offset
= reloc
.get_r_offset();
12239 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12240 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12241 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12242 const unsigned int orig_r_sym
= r_sym
;
12243 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12244 = reloc
.get_r_addend();
12245 const Symbol
* gsym
= NULL
;
12249 // We could arrange to discard these and other relocs for
12250 // tls optimised sequences in the strategy methods, but for
12251 // now do as BFD ld does.
12252 r_type
= elfcpp::R_POWERPC_NONE
;
12256 // Get the new symbol index.
12257 Output_section
* os
= NULL
;
12258 if (r_sym
< local_count
)
12262 case Relocatable_relocs::RELOC_COPY
:
12263 case Relocatable_relocs::RELOC_SPECIAL
:
12266 r_sym
= object
->symtab_index(r_sym
);
12267 gold_assert(r_sym
!= -1U);
12271 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12273 // We are adjusting a section symbol. We need to find
12274 // the symbol table index of the section symbol for
12275 // the output section corresponding to input section
12276 // in which this symbol is defined.
12277 gold_assert(r_sym
< local_count
);
12279 unsigned int shndx
=
12280 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12281 gold_assert(is_ordinary
);
12282 os
= object
->output_section(shndx
);
12283 gold_assert(os
!= NULL
);
12284 gold_assert(os
->needs_symtab_index());
12285 r_sym
= os
->symtab_index();
12290 gold_unreachable();
12295 gsym
= object
->global_symbol(r_sym
);
12296 gold_assert(gsym
!= NULL
);
12297 if (gsym
->is_forwarder())
12298 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12300 gold_assert(gsym
->has_symtab_index());
12301 r_sym
= gsym
->symtab_index();
12304 // Get the new offset--the location in the output section where
12305 // this relocation should be applied.
12306 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12307 offset
+= offset_in_output_section
;
12310 section_offset_type sot_offset
=
12311 convert_types
<section_offset_type
, Address
>(offset
);
12312 section_offset_type new_sot_offset
=
12313 output_section
->output_offset(object
, relinfo
->data_shndx
,
12315 gold_assert(new_sot_offset
!= -1);
12316 offset
= new_sot_offset
;
12319 // In an object file, r_offset is an offset within the section.
12320 // In an executable or dynamic object, generated by
12321 // --emit-relocs, r_offset is an absolute address.
12324 offset
+= view_address
;
12325 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12326 offset
-= offset_in_output_section
;
12329 // Handle the reloc addend based on the strategy.
12330 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12332 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12334 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12335 addend
= psymval
->value(object
, addend
);
12336 // In a relocatable link, the symbol value is relative to
12337 // the start of the output section. For a non-relocatable
12338 // link, we need to adjust the addend.
12341 gold_assert(os
!= NULL
);
12342 addend
-= os
->address();
12345 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12349 if (addend
>= 32768)
12350 addend
+= got2_addend
;
12352 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12354 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12355 addend
-= d_offset
;
12357 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12359 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12360 addend
-= d_offset
+ 4;
12364 gold_unreachable();
12368 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12369 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12370 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12371 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12373 // First instruction of a global dynamic sequence,
12375 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12376 switch (this->optimize_tls_gd(final
))
12378 case tls::TLSOPT_TO_IE
:
12379 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12380 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12382 case tls::TLSOPT_TO_LE
:
12383 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12384 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12385 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12388 r_type
= elfcpp::R_POWERPC_NONE
;
12389 offset
-= d_offset
;
12396 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12397 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12398 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12399 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12401 // First instruction of a local dynamic sequence,
12403 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12405 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12406 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12408 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12409 const Output_section
* os
= relinfo
->layout
->tls_segment()
12411 gold_assert(os
!= NULL
);
12412 gold_assert(os
->needs_symtab_index());
12413 r_sym
= os
->symtab_index();
12414 addend
= dtp_offset
;
12418 r_type
= elfcpp::R_POWERPC_NONE
;
12419 offset
-= d_offset
;
12423 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12424 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12425 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12426 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12428 // First instruction of initial exec sequence.
12429 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12430 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12432 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12433 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12434 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12437 r_type
= elfcpp::R_POWERPC_NONE
;
12438 offset
-= d_offset
;
12442 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12443 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12445 // Second instruction of a global dynamic sequence,
12446 // the __tls_get_addr call
12447 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12448 switch (this->optimize_tls_gd(final
))
12450 case tls::TLSOPT_TO_IE
:
12451 r_type
= elfcpp::R_POWERPC_NONE
;
12454 case tls::TLSOPT_TO_LE
:
12455 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12456 offset
+= d_offset
;
12463 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12464 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12466 // Second instruction of a local dynamic sequence,
12467 // the __tls_get_addr call
12468 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12470 const Output_section
* os
= relinfo
->layout
->tls_segment()
12472 gold_assert(os
!= NULL
);
12473 gold_assert(os
->needs_symtab_index());
12474 r_sym
= os
->symtab_index();
12475 addend
= dtp_offset
;
12476 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12477 offset
+= d_offset
;
12481 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12483 // Second instruction of an initial exec sequence
12484 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12485 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12487 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12488 offset
+= d_offset
;
12493 reloc_write
.put_r_offset(offset
);
12494 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12495 reloc_write
.put_r_addend(addend
);
12497 pwrite
+= reloc_size
;
12500 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12501 == reloc_view_size
);
12504 // Return the value to use for a dynamic symbol which requires special
12505 // treatment. This is how we support equality comparisons of function
12506 // pointers across shared library boundaries, as described in the
12507 // processor specific ABI supplement.
12509 template<int size
, bool big_endian
>
12511 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12515 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12516 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12517 p
!= this->stub_tables_
.end();
12520 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12521 = (*p
)->find_plt_call_entry(gsym
);
12523 return (*p
)->stub_address() + ent
->off_
;
12526 else if (this->abiversion() >= 2)
12528 Address off
= this->glink_section()->find_global_entry(gsym
);
12529 if (off
!= invalid_address
)
12530 return this->glink_section()->global_entry_address() + off
;
12532 gold_unreachable();
12535 // Return the PLT address to use for a local symbol.
12536 template<int size
, bool big_endian
>
12538 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12539 const Relobj
* object
,
12540 unsigned int symndx
) const
12544 const Sized_relobj
<size
, big_endian
>* relobj
12545 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12546 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12547 p
!= this->stub_tables_
.end();
12550 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12551 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12553 return (*p
)->stub_address() + ent
->off_
;
12556 gold_unreachable();
12559 // Return the PLT address to use for a global symbol.
12560 template<int size
, bool big_endian
>
12562 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12563 const Symbol
* gsym
) const
12567 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12568 p
!= this->stub_tables_
.end();
12571 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12572 = (*p
)->find_plt_call_entry(gsym
);
12574 return (*p
)->stub_address() + ent
->off_
;
12577 else if (this->abiversion() >= 2)
12579 Address off
= this->glink_section()->find_global_entry(gsym
);
12580 if (off
!= invalid_address
)
12581 return this->glink_section()->global_entry_address() + off
;
12583 gold_unreachable();
12586 // Return the offset to use for the GOT_INDX'th got entry which is
12587 // for a local tls symbol specified by OBJECT, SYMNDX.
12588 template<int size
, bool big_endian
>
12590 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12591 const Relobj
* object
,
12592 unsigned int symndx
,
12593 unsigned int got_indx
) const
12595 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12596 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12597 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12599 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12600 got_type
<= GOT_TYPE_TPREL
;
12601 got_type
= Got_type(got_type
+ 1))
12602 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12604 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12605 if (got_type
== GOT_TYPE_TLSGD
)
12607 if (off
== got_indx
* (size
/ 8))
12609 if (got_type
== GOT_TYPE_TPREL
)
12612 return -dtp_offset
;
12616 gold_unreachable();
12619 // Return the offset to use for the GOT_INDX'th got entry which is
12620 // for global tls symbol GSYM.
12621 template<int size
, bool big_endian
>
12623 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12625 unsigned int got_indx
) const
12627 if (gsym
->type() == elfcpp::STT_TLS
)
12629 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12630 got_type
<= GOT_TYPE_TPREL
;
12631 got_type
= Got_type(got_type
+ 1))
12632 if (gsym
->has_got_offset(got_type
))
12634 unsigned int off
= gsym
->got_offset(got_type
);
12635 if (got_type
== GOT_TYPE_TLSGD
)
12637 if (off
== got_indx
* (size
/ 8))
12639 if (got_type
== GOT_TYPE_TPREL
)
12642 return -dtp_offset
;
12646 gold_unreachable();
12649 // The selector for powerpc object files.
12651 template<int size
, bool big_endian
>
12652 class Target_selector_powerpc
: public Target_selector
12655 Target_selector_powerpc()
12656 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12659 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12660 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12662 ? (big_endian
? "elf64ppc" : "elf64lppc")
12663 : (big_endian
? "elf32ppc" : "elf32lppc")))
12667 do_instantiate_target()
12668 { return new Target_powerpc
<size
, big_endian
>(); }
12671 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12672 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12673 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12674 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12676 // Instantiate these constants for -O0
12677 template<int size
, bool big_endian
>
12678 const typename Output_data_glink
<size
, big_endian
>::Address
12679 Output_data_glink
<size
, big_endian
>::invalid_address
;
12680 template<int size
, bool big_endian
>
12681 const typename Stub_table
<size
, big_endian
>::Address
12682 Stub_table
<size
, big_endian
>::invalid_address
;
12683 template<int size
, bool big_endian
>
12684 const typename Target_powerpc
<size
, big_endian
>::Address
12685 Target_powerpc
<size
, big_endian
>::invalid_address
;
12687 } // End anonymous namespace.