1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2021 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 no_tls_marker_(false), tls_marker_(false), tls_opt_error_(false),
105 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
106 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
107 attributes_section_data_(NULL
)
109 this->set_abiversion(0);
113 { delete this->attributes_section_data_
; }
115 // Read the symbols then set up st_other vector.
117 do_read_symbols(Read_symbols_data
*);
119 // Arrange to always relocate .toc first.
121 do_relocate_sections(
122 const Symbol_table
* symtab
, const Layout
* layout
,
123 const unsigned char* pshdrs
, Output_file
* of
,
124 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
126 // The .toc section index.
133 // Mark .toc entry at OFF as not optimizable.
135 set_no_toc_opt(Address off
)
137 if (this->no_toc_opt_
.empty())
138 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
141 if (off
< this->no_toc_opt_
.size())
142 this->no_toc_opt_
[off
] = true;
145 // Mark the entire .toc as not optimizable.
149 this->no_toc_opt_
.resize(1);
150 this->no_toc_opt_
[0] = true;
153 // Return true if code using the .toc entry at OFF should not be edited.
155 no_toc_opt(Address off
) const
157 if (this->no_toc_opt_
.empty())
160 if (off
>= this->no_toc_opt_
.size())
162 return this->no_toc_opt_
[off
];
168 if (!this->no_tls_marker_
&& this->tls_marker_
)
169 this->tls_opt_error_
= true;
170 this->no_tls_marker_
= true;
174 no_tls_marker() const
175 { return this->no_tls_marker_
; }
179 { this->tls_marker_
= true; }
183 { return this->tls_marker_
; }
186 tls_opt_error() const
187 { return this->tls_opt_error_
; }
189 // The .got2 section shndx.
194 return this->special_
;
199 // The .opd section shndx.
206 return this->special_
;
209 // Init OPD entry arrays.
211 init_opd(size_t opd_size
)
213 size_t count
= this->opd_ent_ndx(opd_size
);
214 this->opd_ent_
.resize(count
);
217 // Return section and offset of function entry for .opd + R_OFF.
219 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
221 size_t ndx
= this->opd_ent_ndx(r_off
);
222 gold_assert(ndx
< this->opd_ent_
.size());
223 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
225 *value
= this->opd_ent_
[ndx
].off
;
226 return this->opd_ent_
[ndx
].shndx
;
229 // Set section and offset of function entry for .opd + R_OFF.
231 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
233 size_t ndx
= this->opd_ent_ndx(r_off
);
234 gold_assert(ndx
< this->opd_ent_
.size());
235 this->opd_ent_
[ndx
].shndx
= shndx
;
236 this->opd_ent_
[ndx
].off
= value
;
239 // Return discard flag for .opd + R_OFF.
241 get_opd_discard(Address r_off
) const
243 size_t ndx
= this->opd_ent_ndx(r_off
);
244 gold_assert(ndx
< this->opd_ent_
.size());
245 return this->opd_ent_
[ndx
].discard
;
248 // Set discard flag for .opd + R_OFF.
250 set_opd_discard(Address r_off
)
252 size_t ndx
= this->opd_ent_ndx(r_off
);
253 gold_assert(ndx
< this->opd_ent_
.size());
254 this->opd_ent_
[ndx
].discard
= true;
259 { return this->opd_valid_
; }
263 { this->opd_valid_
= true; }
265 // Examine .rela.opd to build info about function entry points.
267 scan_opd_relocs(size_t reloc_count
,
268 const unsigned char* prelocs
,
269 const unsigned char* plocal_syms
);
271 // Returns true if a code sequence loading a TOC entry can be
272 // converted into code calculating a TOC pointer relative offset.
274 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
278 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
279 const Symbol_value
<size
>* psymval
,
283 // Perform the Sized_relobj_file method, then set up opd info from
286 do_read_relocs(Read_relocs_data
*);
289 do_find_special_sections(Read_symbols_data
* sd
);
291 // Adjust this local symbol value. Return false if the symbol
292 // should be discarded from the output file.
294 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
296 if (size
== 64 && this->opd_shndx() != 0)
299 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
301 if (this->get_opd_discard(lv
->input_value()))
309 { return &this->access_from_map_
; }
311 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
312 // section at DST_OFF.
314 add_reference(Relobj
* src_obj
,
315 unsigned int src_indx
,
316 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
318 Section_id
src_id(src_obj
, src_indx
);
319 this->access_from_map_
[dst_off
].insert(src_id
);
322 // Add a reference to the code section specified by the .opd entry
325 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
327 size_t ndx
= this->opd_ent_ndx(dst_off
);
328 if (ndx
>= this->opd_ent_
.size())
329 this->opd_ent_
.resize(ndx
+ 1);
330 this->opd_ent_
[ndx
].gc_mark
= true;
334 process_gc_mark(Symbol_table
* symtab
)
336 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
337 if (this->opd_ent_
[i
].gc_mark
)
339 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
340 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
344 // Return offset in output GOT section that this object will use
345 // as a TOC pointer. Won't be just a constant with multi-toc support.
347 toc_base_offset() const
351 set_has_small_toc_reloc()
352 { has_small_toc_reloc_
= true; }
355 has_small_toc_reloc() const
356 { return has_small_toc_reloc_
; }
359 set_has_14bit_branch(unsigned int shndx
)
361 if (shndx
>= this->has14_
.size())
362 this->has14_
.resize(shndx
+ 1);
363 this->has14_
[shndx
] = true;
367 has_14bit_branch(unsigned int shndx
) const
368 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
371 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
373 if (shndx
>= this->stub_table_index_
.size())
374 this->stub_table_index_
.resize(shndx
+ 1, -1);
375 this->stub_table_index_
[shndx
] = stub_index
;
378 Stub_table
<size
, big_endian
>*
379 stub_table(unsigned int shndx
)
381 if (shndx
< this->stub_table_index_
.size())
383 Target_powerpc
<size
, big_endian
>* target
384 = static_cast<Target_powerpc
<size
, big_endian
>*>(
385 parameters
->sized_target
<size
, big_endian
>());
386 unsigned int indx
= this->stub_table_index_
[shndx
];
387 if (indx
< target
->stub_tables().size())
388 return target
->stub_tables()[indx
];
396 this->stub_table_index_
.clear();
401 { return this->uniq_
; }
405 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
407 // Set ABI version for input and output
409 set_abiversion(int ver
);
412 st_other (unsigned int symndx
) const
414 return this->st_other_
[symndx
];
418 ppc64_local_entry_offset(const Symbol
* sym
) const
419 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
422 ppc64_local_entry_offset(unsigned int symndx
) const
423 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
426 ppc64_needs_toc(const Symbol
* sym
) const
427 { return sym
->nonvis() > 1 << 3; }
430 ppc64_needs_toc(unsigned int symndx
) const
431 { return this->st_other_
[symndx
] > 1 << 5; }
433 // The contents of the .gnu.attributes section if there is one.
434 const Attributes_section_data
*
435 attributes_section_data() const
436 { return this->attributes_section_data_
; }
447 // Return index into opd_ent_ array for .opd entry at OFF.
448 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
449 // apart when the language doesn't use the last 8-byte word, the
450 // environment pointer. Thus dividing the entry section offset by
451 // 16 will give an index into opd_ent_ that works for either layout
452 // of .opd. (It leaves some elements of the vector unused when .opd
453 // entries are spaced 24 bytes apart, but we don't know the spacing
454 // until relocations are processed, and in any case it is possible
455 // for an object to have some entries spaced 16 bytes apart and
456 // others 24 bytes apart.)
458 opd_ent_ndx(size_t off
) const
461 // Per object unique identifier
464 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
465 unsigned int special_
;
467 // For 64-bit the .rela.toc and .toc section shdnx.
468 unsigned int relatoc_
;
471 // For 64-bit, whether this object uses small model relocs to access
473 bool has_small_toc_reloc_
;
475 // Set at the start of gc_process_relocs, when we know opd_ent_
476 // vector is valid. The flag could be made atomic and set in
477 // do_read_relocs with memory_order_release and then tested with
478 // memory_order_acquire, potentially resulting in fewer entries in
482 // Set when finding a __tls_get_addr call without marker relocs.
483 // Such a call disables GD and LD tls optimisations for the object file.
486 // Set when finding a __tls_get_addr call with marker relocs, or
487 // when finding a relocation that needs __tls_get_addr calls with
491 // Set when seeing a __tls_get_addr call without marker relocs after
492 // seeing some __tls_get_addr calls with marker relocs.
496 elfcpp::Elf_Word e_flags_
;
498 // For 64-bit, an array with one entry per 64-bit word in the .toc
499 // section, set if accesses using that word cannot be optimised.
500 std::vector
<bool> no_toc_opt_
;
502 // The first 8-byte word of an OPD entry gives the address of the
503 // entry point of the function. Relocatable object files have a
504 // relocation on this word. The following vector records the
505 // section and offset specified by these relocations.
506 std::vector
<Opd_ent
> opd_ent_
;
508 // References made to this object's .opd section when running
509 // gc_process_relocs for another object, before the opd_ent_ vector
510 // is valid for this object.
511 Access_from access_from_map_
;
513 // Whether input section has a 14-bit branch reloc.
514 std::vector
<bool> has14_
;
516 // The stub table to use for a given input section.
517 std::vector
<unsigned int> stub_table_index_
;
519 // ELF st_other field for local symbols.
520 std::vector
<unsigned char> st_other_
;
522 // Object attributes if there is a .gnu.attributes section.
523 Attributes_section_data
* attributes_section_data_
;
526 template<int size
, bool big_endian
>
527 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
530 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
532 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
533 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
534 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
535 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
536 attributes_section_data_(NULL
)
538 this->set_abiversion(0);
542 { delete this->attributes_section_data_
; }
544 // Call Sized_dynobj::do_read_symbols to read the symbols then
545 // read .opd from a dynamic object, filling in opd_ent_ vector,
547 do_read_symbols(Read_symbols_data
*);
549 // The .opd section shndx.
553 return this->opd_shndx_
;
556 // The .opd section address.
560 return this->opd_address_
;
563 // Init OPD entry arrays.
565 init_opd(size_t opd_size
)
567 size_t count
= this->opd_ent_ndx(opd_size
);
568 this->opd_ent_
.resize(count
);
571 // Return section and offset of function entry for .opd + R_OFF.
573 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
575 size_t ndx
= this->opd_ent_ndx(r_off
);
576 gold_assert(ndx
< this->opd_ent_
.size());
577 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
579 *value
= this->opd_ent_
[ndx
].off
;
580 return this->opd_ent_
[ndx
].shndx
;
583 // Set section and offset of function entry for .opd + R_OFF.
585 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
587 size_t ndx
= this->opd_ent_ndx(r_off
);
588 gold_assert(ndx
< this->opd_ent_
.size());
589 this->opd_ent_
[ndx
].shndx
= shndx
;
590 this->opd_ent_
[ndx
].off
= value
;
595 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
597 // Set ABI version for input and output.
599 set_abiversion(int ver
);
601 // The contents of the .gnu.attributes section if there is one.
602 const Attributes_section_data
*
603 attributes_section_data() const
604 { return this->attributes_section_data_
; }
607 // Used to specify extent of executable sections.
610 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
611 : start(start_
), len(len_
), shndx(shndx_
)
615 operator<(const Sec_info
& that
) const
616 { return this->start
< that
.start
; }
629 // Return index into opd_ent_ array for .opd entry at OFF.
631 opd_ent_ndx(size_t off
) const
634 // For 64-bit the .opd section shndx and address.
635 unsigned int opd_shndx_
;
636 Address opd_address_
;
639 elfcpp::Elf_Word e_flags_
;
641 // The first 8-byte word of an OPD entry gives the address of the
642 // entry point of the function. Records the section and offset
643 // corresponding to the address. Note that in dynamic objects,
644 // offset is *not* relative to the section.
645 std::vector
<Opd_ent
> opd_ent_
;
647 // Object attributes if there is a .gnu.attributes section.
648 Attributes_section_data
* attributes_section_data_
;
651 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
652 // base class will emit.
654 template<int sh_type
, int size
, bool big_endian
>
655 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
658 Powerpc_copy_relocs()
659 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
662 // Emit any saved relocations which turn out to be needed. This is
663 // called after all the relocs have been scanned.
665 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
668 template<int size
, bool big_endian
>
669 class Target_powerpc
: public Sized_target
<size
, big_endian
>
673 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
674 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
675 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
676 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
677 static const Address invalid_address
= static_cast<Address
>(0) - 1;
678 // Offset of tp and dtp pointers from start of TLS block.
679 static const Address tp_offset
= 0x7000;
680 static const Address dtp_offset
= 0x8000;
683 : Sized_target
<size
, big_endian
>(&powerpc_info
),
684 got_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
), brlt_section_(NULL
),
685 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
686 tlsld_got_offset_(-1U),
687 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
688 power10_relocs_(false), plt_thread_safe_(false), plt_localentry0_(false),
689 plt_localentry0_init_(false), has_localentry0_(false),
690 has_tls_get_addr_opt_(false), no_tprel_opt_(false),
691 relax_failed_(false), relax_fail_count_(0),
692 stub_group_size_(0), savres_section_(0),
693 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
694 attributes_section_data_(NULL
),
695 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
699 // Process the relocations to determine unreferenced sections for
700 // garbage collection.
702 gc_process_relocs(Symbol_table
* symtab
,
704 Sized_relobj_file
<size
, big_endian
>* object
,
705 unsigned int data_shndx
,
706 unsigned int sh_type
,
707 const unsigned char* prelocs
,
709 Output_section
* output_section
,
710 bool needs_special_offset_handling
,
711 size_t local_symbol_count
,
712 const unsigned char* plocal_symbols
);
714 // Scan the relocations to look for symbol adjustments.
716 scan_relocs(Symbol_table
* symtab
,
718 Sized_relobj_file
<size
, big_endian
>* object
,
719 unsigned int data_shndx
,
720 unsigned int sh_type
,
721 const unsigned char* prelocs
,
723 Output_section
* output_section
,
724 bool needs_special_offset_handling
,
725 size_t local_symbol_count
,
726 const unsigned char* plocal_symbols
);
728 // Map input .toc section to output .got section.
730 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
732 if (size
== 64 && strcmp(name
, ".toc") == 0)
740 // Provide linker defined save/restore functions.
742 define_save_restore_funcs(Layout
*, Symbol_table
*);
744 // No stubs unless a final link.
747 { return !parameters
->options().relocatable(); }
750 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
753 do_plt_fde_location(const Output_data
*, unsigned char*,
754 uint64_t*, off_t
*) const;
756 // Stash info about branches, for stub generation.
758 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
759 unsigned int data_shndx
, Address r_offset
,
760 unsigned int r_type
, unsigned int r_sym
, Address addend
)
762 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
763 this->branch_info_
.push_back(info
);
764 if (r_type
== elfcpp::R_POWERPC_REL14
765 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
766 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
767 ppc_object
->set_has_14bit_branch(data_shndx
);
770 // Return whether the last branch is a plt call, and if so, mark the
771 // branch as having an R_PPC64_TOCSAVE.
773 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
774 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
777 && !this->branch_info_
.empty()
778 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
779 r_offset
, this, symtab
));
782 // Say the given location, that of a nop in a function prologue with
783 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
784 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
786 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
787 unsigned int shndx
, Address offset
)
790 loc
.object
= ppc_object
;
793 this->tocsave_loc_
.insert(loc
);
800 return &this->tocsave_loc_
;
804 do_define_standard_symbols(Symbol_table
*, Layout
*);
806 // Finalize the sections.
808 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
810 // Return the value to use for a dynamic which requires special
813 do_dynsym_value(const Symbol
*) const;
815 // Return the PLT address to use for a local symbol.
817 do_plt_address_for_local(const Relobj
*, unsigned int) const;
819 // Return the PLT address to use for a global symbol.
821 do_plt_address_for_global(const Symbol
*) const;
823 // Return the offset to use for the GOT_INDX'th got entry which is
824 // for a local tls symbol specified by OBJECT, SYMNDX.
826 do_tls_offset_for_local(const Relobj
* object
,
828 unsigned int got_indx
) const;
830 // Return the offset to use for the GOT_INDX'th got entry which is
831 // for global tls symbol GSYM.
833 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
836 do_function_location(Symbol_location
*) const;
839 do_can_check_for_function_pointers() const
842 // Adjust -fsplit-stack code which calls non-split-stack code.
844 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
845 section_offset_type fnoffset
, section_size_type fnsize
,
846 const unsigned char* prelocs
, size_t reloc_count
,
847 unsigned char* view
, section_size_type view_size
,
848 std::string
* from
, std::string
* to
) const;
850 // Relocate a section.
852 relocate_section(const Relocate_info
<size
, big_endian
>*,
853 unsigned int sh_type
,
854 const unsigned char* prelocs
,
856 Output_section
* output_section
,
857 bool needs_special_offset_handling
,
859 Address view_address
,
860 section_size_type view_size
,
861 const Reloc_symbol_changes
*);
863 // Scan the relocs during a relocatable link.
865 scan_relocatable_relocs(Symbol_table
* symtab
,
867 Sized_relobj_file
<size
, big_endian
>* object
,
868 unsigned int data_shndx
,
869 unsigned int sh_type
,
870 const unsigned char* prelocs
,
872 Output_section
* output_section
,
873 bool needs_special_offset_handling
,
874 size_t local_symbol_count
,
875 const unsigned char* plocal_symbols
,
876 Relocatable_relocs
*);
878 // Scan the relocs for --emit-relocs.
880 emit_relocs_scan(Symbol_table
* symtab
,
882 Sized_relobj_file
<size
, big_endian
>* object
,
883 unsigned int data_shndx
,
884 unsigned int sh_type
,
885 const unsigned char* prelocs
,
887 Output_section
* output_section
,
888 bool needs_special_offset_handling
,
889 size_t local_symbol_count
,
890 const unsigned char* plocal_syms
,
891 Relocatable_relocs
* rr
);
893 // Emit relocations for a section.
895 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
896 unsigned int sh_type
,
897 const unsigned char* prelocs
,
899 Output_section
* output_section
,
900 typename
elfcpp::Elf_types
<size
>::Elf_Off
901 offset_in_output_section
,
903 Address view_address
,
905 unsigned char* reloc_view
,
906 section_size_type reloc_view_size
);
908 // Return whether SYM is defined by the ABI.
910 do_is_defined_by_abi(const Symbol
* sym
) const
912 return strcmp(sym
->name(), "__tls_get_addr") == 0;
915 // Return the size of the GOT section.
919 gold_assert(this->got_
!= NULL
);
920 return this->got_
->data_size();
923 // Get the PLT section.
924 const Output_data_plt_powerpc
<size
, big_endian
>*
927 gold_assert(this->plt_
!= NULL
);
931 // Get the IPLT section.
932 const Output_data_plt_powerpc
<size
, big_endian
>*
935 gold_assert(this->iplt_
!= NULL
);
939 // Get the LPLT section.
940 const Output_data_plt_powerpc
<size
, big_endian
>*
946 // Return the plt offset and section for the given global sym.
948 plt_off(const Symbol
* gsym
,
949 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
951 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
952 && gsym
->can_use_relative_reloc(false))
953 *sec
= this->iplt_section();
955 *sec
= this->plt_section();
956 return gsym
->plt_offset();
959 // Return the plt offset and section for the given local sym.
961 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
962 unsigned int local_sym_index
,
963 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
965 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
966 if (lsym
->is_ifunc_symbol())
967 *sec
= this->iplt_section();
969 *sec
= this->lplt_section();
970 return relobj
->local_plt_offset(local_sym_index
);
973 // Get the .glink section.
974 const Output_data_glink
<size
, big_endian
>*
975 glink_section() const
977 gold_assert(this->glink_
!= NULL
);
981 Output_data_glink
<size
, big_endian
>*
984 gold_assert(this->glink_
!= NULL
);
988 bool has_glink() const
989 { return this->glink_
!= NULL
; }
991 // Get the GOT section.
992 const Output_data_got_powerpc
<size
, big_endian
>*
995 gold_assert(this->got_
!= NULL
);
999 // Get the GOT section, creating it if necessary.
1000 Output_data_got_powerpc
<size
, big_endian
>*
1001 got_section(Symbol_table
*, Layout
*);
1004 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
1005 const elfcpp::Ehdr
<size
, big_endian
>&);
1007 // Return the number of entries in the GOT.
1009 got_entry_count() const
1011 if (this->got_
== NULL
)
1013 return this->got_size() / (size
/ 8);
1016 // Return the number of entries in the PLT.
1018 plt_entry_count() const;
1020 // Return the offset of the first non-reserved PLT entry.
1022 first_plt_entry_offset() const
1026 if (this->abiversion() >= 2)
1031 // Return the size of each PLT entry.
1033 plt_entry_size() const
1037 if (this->abiversion() >= 2)
1042 Output_data_save_res
<size
, big_endian
>*
1043 savres_section() const
1045 return this->savres_section_
;
1048 // Add any special sections for this symbol to the gc work list.
1049 // For powerpc64, this adds the code section of a function
1052 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1054 // Handle target specific gc actions when adding a gc reference from
1055 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1056 // and DST_OFF. For powerpc64, this adds a referenc to the code
1057 // section of a function descriptor.
1059 do_gc_add_reference(Symbol_table
* symtab
,
1061 unsigned int src_shndx
,
1063 unsigned int dst_shndx
,
1064 Address dst_off
) const;
1066 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1069 { return this->stub_tables_
; }
1071 const Output_data_brlt_powerpc
<size
, big_endian
>*
1072 brlt_section() const
1073 { return this->brlt_section_
; }
1076 add_branch_lookup_table(Address to
)
1078 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1079 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1083 find_branch_lookup_table(Address to
)
1085 typename
Branch_lookup_table::const_iterator p
1086 = this->branch_lookup_table_
.find(to
);
1087 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1091 write_branch_lookup_table(unsigned char *oview
)
1093 for (typename
Branch_lookup_table::const_iterator p
1094 = this->branch_lookup_table_
.begin();
1095 p
!= this->branch_lookup_table_
.end();
1098 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1102 // Wrapper used after relax to define a local symbol in output data,
1103 // from the end if value < 0.
1105 define_local(Symbol_table
* symtab
, const char* name
,
1106 Output_data
* od
, Address value
, unsigned int symsize
)
1109 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1110 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1111 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1112 static_cast<Signed_address
>(value
) < 0,
1114 // We are creating this symbol late, so need to fix up things
1115 // done early in Layout::finalize.
1116 sym
->set_dynsym_index(-1U);
1120 set_power10_relocs()
1122 this->power10_relocs_
= true;
1126 power10_stubs() const
1128 return (this->power10_relocs_
1129 && (parameters
->options().power10_stubs_enum()
1130 != General_options::POWER10_STUBS_NO
));
1134 power10_stubs_auto() const
1136 return (parameters
->options().power10_stubs_enum()
1137 == General_options::POWER10_STUBS_AUTO
);
1141 plt_thread_safe() const
1142 { return this->plt_thread_safe_
; }
1145 plt_localentry0() const
1146 { return this->plt_localentry0_
; }
1149 has_localentry0() const
1150 { return this->has_localentry0_
; }
1153 set_has_localentry0()
1155 this->has_localentry0_
= true;
1159 is_elfv2_localentry0(const Symbol
* gsym
) const
1162 && this->abiversion() >= 2
1163 && this->plt_localentry0()
1164 && gsym
->type() == elfcpp::STT_FUNC
1165 && gsym
->is_defined()
1166 && gsym
->nonvis() >> 3 == 0
1167 && !gsym
->non_zero_localentry());
1171 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1172 unsigned int r_sym
) const
1174 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1175 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1178 && this->abiversion() >= 2
1179 && this->plt_localentry0()
1180 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1182 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1184 if (!psymval
->is_ifunc_symbol()
1185 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1194 { return !this->no_tprel_opt_
&& parameters
->options().tls_optimize(); }
1198 { this->no_tprel_opt_
= true; }
1200 // Remember any symbols seen with non-zero localentry, even those
1201 // not providing a definition
1203 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1208 unsigned char st_other
= sym
.get_st_other();
1209 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1210 to
->set_non_zero_localentry();
1212 // We haven't resolved anything, continue normal processing.
1218 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1221 set_abiversion(int ver
)
1223 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1224 flags
&= ~elfcpp::EF_PPC64_ABI
;
1225 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1226 this->set_processor_specific_flags(flags
);
1230 tls_get_addr_opt() const
1231 { return this->tls_get_addr_opt_
; }
1234 tls_get_addr() const
1235 { return this->tls_get_addr_
; }
1237 // If optimizing __tls_get_addr calls, whether this is the
1238 // "__tls_get_addr" symbol.
1240 is_tls_get_addr_opt(const Symbol
* gsym
) const
1242 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1243 || gsym
== this->tls_get_addr_opt_
);
1247 replace_tls_get_addr(const Symbol
* gsym
) const
1248 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1251 set_has_tls_get_addr_opt()
1252 { this->has_tls_get_addr_opt_
= true; }
1254 // Offset to toc save stack slot
1257 { return this->abiversion() < 2 ? 40 : 24; }
1259 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1260 // so use the CR save slot. Used only by __tls_get_addr call stub,
1261 // relying on __tls_get_addr not saving CR itself.
1264 { return this->abiversion() < 2 ? 32 : 8; }
1266 // Merge object attributes from input object with those in the output.
1268 merge_object_attributes(const Object
*, const Attributes_section_data
*);
1284 : tls_get_addr_state_(NOT_EXPECTED
),
1285 relinfo_(NULL
), relnum_(0), r_offset_(0)
1290 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1297 if (this->relinfo_
!= NULL
)
1298 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1299 _("missing expected __tls_get_addr call"));
1303 expect_tls_get_addr_call(
1304 const Relocate_info
<size
, big_endian
>* relinfo
,
1308 this->tls_get_addr_state_
= EXPECTED
;
1309 this->relinfo_
= relinfo
;
1310 this->relnum_
= relnum
;
1311 this->r_offset_
= r_offset
;
1315 expect_tls_get_addr_call()
1316 { this->tls_get_addr_state_
= EXPECTED
; }
1319 skip_next_tls_get_addr_call()
1320 {this->tls_get_addr_state_
= SKIP
; }
1323 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1324 unsigned int r_type
, const Symbol
* gsym
)
1327 = ((r_type
== elfcpp::R_POWERPC_REL24
1328 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1329 || r_type
== elfcpp::R_PPC_PLTREL24
1330 || is_plt16_reloc
<size
>(r_type
)
1331 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1332 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1333 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1334 || r_type
== elfcpp::R_POWERPC_PLTCALL
1335 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1336 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1338 && (gsym
== target
->tls_get_addr()
1339 || gsym
== target
->tls_get_addr_opt()));
1340 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1341 this->tls_get_addr_state_
= NOT_EXPECTED
;
1342 if (is_tls_call
&& last_tls
!= EXPECTED
)
1344 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1353 // What we're up to regarding calls to __tls_get_addr.
1354 // On powerpc, the branch and link insn making a call to
1355 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1356 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1357 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1358 // The marker relocation always comes first, and has the same
1359 // symbol as the reloc on the insn setting up the __tls_get_addr
1360 // argument. This ties the arg setup insn with the call insn,
1361 // allowing ld to safely optimize away the call. We check that
1362 // every call to __tls_get_addr has a marker relocation, and that
1363 // every marker relocation is on a call to __tls_get_addr.
1364 Tls_get_addr tls_get_addr_state_
;
1365 // Info about the last reloc for error message.
1366 const Relocate_info
<size
, big_endian
>* relinfo_
;
1371 // The class which scans relocations.
1372 class Scan
: protected Track_tls
1375 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1378 : Track_tls(), issued_non_pic_error_(false)
1382 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1385 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1386 Sized_relobj_file
<size
, big_endian
>* object
,
1387 unsigned int data_shndx
,
1388 Output_section
* output_section
,
1389 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1390 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1394 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1395 Sized_relobj_file
<size
, big_endian
>* object
,
1396 unsigned int data_shndx
,
1397 Output_section
* output_section
,
1398 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1402 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1404 Sized_relobj_file
<size
, big_endian
>* relobj
,
1407 const elfcpp::Rela
<size
, big_endian
>& ,
1408 unsigned int r_type
,
1409 const elfcpp::Sym
<size
, big_endian
>&)
1411 // PowerPC64 .opd is not folded, so any identical function text
1412 // may be folded and we'll still keep function addresses distinct.
1413 // That means no reloc is of concern here.
1416 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1417 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1418 if (ppcobj
->abiversion() == 1)
1421 // For 32-bit and ELFv2, conservatively assume anything but calls to
1422 // function code might be taking the address of the function.
1423 return !is_branch_reloc
<size
>(r_type
);
1427 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1429 Sized_relobj_file
<size
, big_endian
>* relobj
,
1432 const elfcpp::Rela
<size
, big_endian
>& ,
1433 unsigned int r_type
,
1439 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1440 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1441 if (ppcobj
->abiversion() == 1)
1444 return !is_branch_reloc
<size
>(r_type
);
1448 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1449 Sized_relobj_file
<size
, big_endian
>* object
,
1450 unsigned int r_type
, bool report_err
);
1454 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1455 unsigned int r_type
);
1458 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1459 unsigned int r_type
, Symbol
*);
1462 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1463 Target_powerpc
* target
);
1466 check_non_pic(Relobj
*, unsigned int r_type
);
1468 // Whether we have issued an error about a non-PIC compilation.
1469 bool issued_non_pic_error_
;
1473 symval_for_branch(const Symbol_table
* symtab
,
1474 const Sized_symbol
<size
>* gsym
,
1475 Powerpc_relobj
<size
, big_endian
>* object
,
1476 Address
*value
, unsigned int *dest_shndx
);
1478 // The class which implements relocation.
1479 class Relocate
: protected Track_tls
1482 // Use 'at' branch hints when true, 'y' when false.
1483 // FIXME maybe: set this with an option.
1484 static const bool is_isa_v2
= true;
1490 // Do a relocation. Return false if the caller should not issue
1491 // any warnings about this relocation.
1493 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1494 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1495 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1496 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1500 class Relocate_comdat_behavior
1503 // Decide what the linker should do for relocations that refer to
1504 // discarded comdat sections.
1505 inline Comdat_behavior
1506 get(const char* name
)
1508 gold::Default_comdat_behavior default_behavior
;
1509 Comdat_behavior ret
= default_behavior
.get(name
);
1510 if (ret
== CB_ERROR
)
1513 && (strcmp(name
, ".fixup") == 0
1514 || strcmp(name
, ".got2") == 0))
1517 && (strcmp(name
, ".opd") == 0
1518 || strcmp(name
, ".toc") == 0
1519 || strcmp(name
, ".toc1") == 0))
1526 // Optimize the TLS relocation type based on what we know about the
1527 // symbol. IS_FINAL is true if the final address of this symbol is
1528 // known at link time.
1530 tls::Tls_optimization
1531 optimize_tls_gd(bool is_final
)
1533 // If we are generating a shared library, then we can't do anything
1535 if (parameters
->options().shared()
1536 || !parameters
->options().tls_optimize())
1537 return tls::TLSOPT_NONE
;
1540 return tls::TLSOPT_TO_IE
;
1541 return tls::TLSOPT_TO_LE
;
1544 tls::Tls_optimization
1547 if (parameters
->options().shared()
1548 || !parameters
->options().tls_optimize())
1549 return tls::TLSOPT_NONE
;
1551 return tls::TLSOPT_TO_LE
;
1554 tls::Tls_optimization
1555 optimize_tls_ie(bool is_final
)
1558 || parameters
->options().shared()
1559 || !parameters
->options().tls_optimize())
1560 return tls::TLSOPT_NONE
;
1562 return tls::TLSOPT_TO_LE
;
1567 make_glink_section(Layout
*);
1569 // Create the PLT section.
1571 make_plt_section(Symbol_table
*, Layout
*);
1574 make_iplt_section(Symbol_table
*, Layout
*);
1577 make_lplt_section(Layout
*);
1580 make_brlt_section(Layout
*);
1582 // Create a PLT entry for a global symbol.
1584 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1586 // Create a PLT entry for a local IFUNC symbol.
1588 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1589 Sized_relobj_file
<size
, big_endian
>*,
1592 // Create a PLT entry for a local non-IFUNC symbol.
1594 make_local_plt_entry(Layout
*,
1595 Sized_relobj_file
<size
, big_endian
>*,
1599 // Create a GOT entry for local dynamic __tls_get_addr.
1601 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1602 Sized_relobj_file
<size
, big_endian
>* object
);
1605 tlsld_got_offset() const
1607 return this->tlsld_got_offset_
;
1610 // Get the dynamic reloc section, creating it if necessary.
1612 rela_dyn_section(Layout
*);
1614 // Similarly, but for ifunc symbols get the one for ifunc.
1616 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1618 // Copy a relocation against a global symbol.
1620 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1621 Sized_relobj_file
<size
, big_endian
>* object
,
1622 unsigned int shndx
, Output_section
* output_section
,
1623 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1625 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1626 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1627 symtab
->get_sized_symbol
<size
>(sym
),
1628 object
, shndx
, output_section
,
1629 r_type
, reloc
.get_r_offset(),
1630 reloc
.get_r_addend(),
1631 this->rela_dyn_section(layout
));
1634 // Look over all the input sections, deciding where to place stubs.
1636 group_sections(Layout
*, const Task
*, bool);
1638 // Sort output sections by address.
1639 struct Sort_sections
1642 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1643 { return sec1
->address() < sec2
->address(); }
1649 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1650 unsigned int data_shndx
,
1652 unsigned int r_type
,
1655 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1656 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1662 // Return whether this branch is going via a plt call stub, and if
1663 // so, mark it as having an R_PPC64_TOCSAVE.
1665 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1666 unsigned int shndx
, Address offset
,
1667 Target_powerpc
* target
, Symbol_table
* symtab
);
1669 // If this branch needs a plt call stub, or a long branch stub, make one.
1671 make_stub(Stub_table
<size
, big_endian
>*,
1672 Stub_table
<size
, big_endian
>*,
1673 Symbol_table
*) const;
1676 // The branch location..
1677 Powerpc_relobj
<size
, big_endian
>* object_
;
1678 unsigned int shndx_
;
1680 // ..and the branch type and destination.
1681 unsigned int r_type_
: 31;
1682 unsigned int tocsave_
: 1;
1683 unsigned int r_sym_
;
1687 // Information about this specific target which we pass to the
1688 // general Target structure.
1689 static Target::Target_info powerpc_info
;
1691 // The types of GOT entries needed for this platform.
1692 // These values are exposed to the ABI in an incremental link.
1693 // Do not renumber existing values without changing the version
1694 // number of the .gnu_incremental_inputs section.
1698 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1699 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1700 GOT_TYPE_TPREL
// entry for @got@tprel
1704 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1705 // The PLT section. This is a container for a table of addresses,
1706 // and their relocations. Each address in the PLT has a dynamic
1707 // relocation (R_*_JMP_SLOT) and each address will have a
1708 // corresponding entry in .glink for lazy resolution of the PLT.
1709 // ppc32 initialises the PLT to point at the .glink entry, while
1710 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1711 // linker adds a stub that loads the PLT entry into ctr then
1712 // branches to ctr. There may be more than one stub for each PLT
1713 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1714 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1715 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1716 // The IPLT section. Like plt_, this is a container for a table of
1717 // addresses and their relocations, specifically for STT_GNU_IFUNC
1718 // functions that resolve locally (STT_GNU_IFUNC functions that
1719 // don't resolve locally go in PLT). Unlike plt_, these have no
1720 // entry in .glink for lazy resolution, and the relocation section
1721 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1722 // the relocation section may contain relocations against
1723 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1724 // relocation section will appear at the end of other dynamic
1725 // relocations, so that ld.so applies these relocations after other
1726 // dynamic relocations. In a static executable, the relocation
1727 // section is emitted and marked with __rela_iplt_start and
1728 // __rela_iplt_end symbols.
1729 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1730 // A PLT style section for local, non-ifunc symbols
1731 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1732 // Section holding long branch destinations.
1733 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1734 // The .glink section.
1735 Output_data_glink
<size
, big_endian
>* glink_
;
1736 // The dynamic reloc section.
1737 Reloc_section
* rela_dyn_
;
1738 // Relocs saved to avoid a COPY reloc.
1739 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1740 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1741 unsigned int tlsld_got_offset_
;
1743 Stub_tables stub_tables_
;
1744 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1745 Branch_lookup_table branch_lookup_table_
;
1747 typedef std::vector
<Branch_info
> Branches
;
1748 Branches branch_info_
;
1749 Tocsave_loc tocsave_loc_
;
1751 bool power10_relocs_
;
1752 bool plt_thread_safe_
;
1753 bool plt_localentry0_
;
1754 bool plt_localentry0_init_
;
1755 bool has_localentry0_
;
1756 bool has_tls_get_addr_opt_
;
1760 int relax_fail_count_
;
1761 int32_t stub_group_size_
;
1763 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1765 // The "__tls_get_addr" symbol, if present
1766 Symbol
* tls_get_addr_
;
1767 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1768 Symbol
* tls_get_addr_opt_
;
1770 // Attributes in output.
1771 Attributes_section_data
* attributes_section_data_
;
1773 // Last input file to change various attribute tags
1774 const char* last_fp_
;
1775 const char* last_ld_
;
1776 const char* last_vec_
;
1777 const char* last_struct_
;
1781 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1784 true, // is_big_endian
1785 elfcpp::EM_PPC
, // machine_code
1786 false, // has_make_symbol
1787 false, // has_resolve
1788 false, // has_code_fill
1789 true, // is_default_stack_executable
1790 false, // can_icf_inline_merge_sections
1792 "/usr/lib/ld.so.1", // dynamic_linker
1793 0x10000000, // default_text_segment_address
1794 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1795 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1796 false, // isolate_execinstr
1798 elfcpp::SHN_UNDEF
, // small_common_shndx
1799 elfcpp::SHN_UNDEF
, // large_common_shndx
1800 0, // small_common_section_flags
1801 0, // large_common_section_flags
1802 NULL
, // attributes_section
1803 NULL
, // attributes_vendor
1804 "_start", // entry_symbol_name
1805 32, // hash_entry_size
1806 elfcpp::SHT_PROGBITS
, // unwind_section_type
1810 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1813 false, // is_big_endian
1814 elfcpp::EM_PPC
, // machine_code
1815 false, // has_make_symbol
1816 false, // has_resolve
1817 false, // has_code_fill
1818 true, // is_default_stack_executable
1819 false, // can_icf_inline_merge_sections
1821 "/usr/lib/ld.so.1", // dynamic_linker
1822 0x10000000, // default_text_segment_address
1823 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1824 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1825 false, // isolate_execinstr
1827 elfcpp::SHN_UNDEF
, // small_common_shndx
1828 elfcpp::SHN_UNDEF
, // large_common_shndx
1829 0, // small_common_section_flags
1830 0, // large_common_section_flags
1831 NULL
, // attributes_section
1832 NULL
, // attributes_vendor
1833 "_start", // entry_symbol_name
1834 32, // hash_entry_size
1835 elfcpp::SHT_PROGBITS
, // unwind_section_type
1839 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1842 true, // is_big_endian
1843 elfcpp::EM_PPC64
, // machine_code
1844 false, // has_make_symbol
1845 true, // has_resolve
1846 false, // has_code_fill
1847 false, // is_default_stack_executable
1848 false, // can_icf_inline_merge_sections
1850 "/usr/lib/ld.so.1", // dynamic_linker
1851 0x10000000, // default_text_segment_address
1852 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1853 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1854 false, // isolate_execinstr
1856 elfcpp::SHN_UNDEF
, // small_common_shndx
1857 elfcpp::SHN_UNDEF
, // large_common_shndx
1858 0, // small_common_section_flags
1859 0, // large_common_section_flags
1860 NULL
, // attributes_section
1861 NULL
, // attributes_vendor
1862 "_start", // entry_symbol_name
1863 32, // hash_entry_size
1864 elfcpp::SHT_PROGBITS
, // unwind_section_type
1868 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1871 false, // is_big_endian
1872 elfcpp::EM_PPC64
, // machine_code
1873 false, // has_make_symbol
1874 true, // has_resolve
1875 false, // has_code_fill
1876 false, // is_default_stack_executable
1877 false, // can_icf_inline_merge_sections
1879 "/usr/lib/ld.so.1", // dynamic_linker
1880 0x10000000, // default_text_segment_address
1881 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1882 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1883 false, // isolate_execinstr
1885 elfcpp::SHN_UNDEF
, // small_common_shndx
1886 elfcpp::SHN_UNDEF
, // large_common_shndx
1887 0, // small_common_section_flags
1888 0, // large_common_section_flags
1889 NULL
, // attributes_section
1890 NULL
, // attributes_vendor
1891 "_start", // entry_symbol_name
1892 32, // hash_entry_size
1893 elfcpp::SHT_PROGBITS
, // unwind_section_type
1898 is_branch_reloc(unsigned int r_type
)
1900 return (r_type
== elfcpp::R_POWERPC_REL24
1901 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1902 || r_type
== elfcpp::R_PPC_PLTREL24
1903 || r_type
== elfcpp::R_PPC_LOCAL24PC
1904 || r_type
== elfcpp::R_POWERPC_REL14
1905 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1906 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1907 || r_type
== elfcpp::R_POWERPC_ADDR24
1908 || r_type
== elfcpp::R_POWERPC_ADDR14
1909 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1910 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1913 // Reloc resolves to plt entry.
1916 is_plt16_reloc(unsigned int r_type
)
1918 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1919 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1920 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1921 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1924 // GOT_TYPE_STANDARD (ie. not TLS) GOT relocs
1926 is_got_reloc(unsigned int r_type
)
1928 return (r_type
== elfcpp::R_POWERPC_GOT16
1929 || r_type
== elfcpp::R_POWERPC_GOT16_LO
1930 || r_type
== elfcpp::R_POWERPC_GOT16_HI
1931 || r_type
== elfcpp::R_POWERPC_GOT16_HA
1932 || r_type
== elfcpp::R_PPC64_GOT16_DS
1933 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
1934 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
);
1937 // If INSN is an opcode that may be used with an @tls operand, return
1938 // the transformed insn for TLS optimisation, otherwise return 0. If
1939 // REG is non-zero only match an insn with RB or RA equal to REG.
1941 at_tls_transform(uint32_t insn
, unsigned int reg
)
1943 if ((insn
& (0x3f << 26)) != 31 << 26)
1947 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1948 rtra
= insn
& ((1 << 26) - (1 << 16));
1949 else if (((insn
>> 16) & 0x1f) == reg
)
1950 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1954 if ((insn
& (0x3ff << 1)) == 266 << 1)
1957 else if ((insn
& (0x1f << 1)) == 23 << 1
1958 && ((insn
& (0x1f << 6)) < 14 << 6
1959 || ((insn
& (0x1f << 6)) >= 16 << 6
1960 && (insn
& (0x1f << 6)) < 24 << 6)))
1961 // load and store indexed -> dform
1962 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1963 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1964 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1965 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1966 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1968 insn
= (58 << 26) | 2;
1976 template<int size
, bool big_endian
>
1977 class Powerpc_relocate_functions
1997 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1998 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1999 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
2001 template<int valsize
>
2003 has_overflow_signed(Address value
)
2005 // limit = 1 << (valsize - 1) without shift count exceeding size of type
2006 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2007 limit
<<= ((valsize
- 1) >> 1);
2008 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2009 return value
+ limit
> (limit
<< 1) - 1;
2012 template<int valsize
>
2014 has_overflow_unsigned(Address value
)
2016 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
2017 limit
<<= ((valsize
- 1) >> 1);
2018 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
2019 return value
> (limit
<< 1) - 1;
2022 template<int valsize
>
2024 has_overflow_bitfield(Address value
)
2026 return (has_overflow_unsigned
<valsize
>(value
)
2027 && has_overflow_signed
<valsize
>(value
));
2030 template<int valsize
>
2031 static inline Status
2032 overflowed(Address value
, Overflow_check overflow
)
2034 if (overflow
== CHECK_SIGNED
)
2036 if (has_overflow_signed
<valsize
>(value
))
2037 return STATUS_OVERFLOW
;
2039 else if (overflow
== CHECK_UNSIGNED
)
2041 if (has_overflow_unsigned
<valsize
>(value
))
2042 return STATUS_OVERFLOW
;
2044 else if (overflow
== CHECK_BITFIELD
)
2046 if (has_overflow_bitfield
<valsize
>(value
))
2047 return STATUS_OVERFLOW
;
2052 // Do a simple RELA relocation
2053 template<int fieldsize
, int valsize
>
2054 static inline Status
2055 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
2057 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2058 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2059 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
2060 return overflowed
<valsize
>(value
, overflow
);
2063 template<int fieldsize
, int valsize
>
2064 static inline Status
2065 rela(unsigned char* view
,
2066 unsigned int right_shift
,
2067 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2069 Overflow_check overflow
)
2071 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
2072 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2073 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
2074 if (overflow
== CHECK_SIGNED
)
2075 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2077 value
= value
>> right_shift
;
2078 Valtype reloc
= value
;
2081 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2082 return overflowed
<valsize
>(value
, overflow
);
2085 // Do a simple RELA relocation, unaligned.
2086 template<int fieldsize
, int valsize
>
2087 static inline Status
2088 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2090 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2091 return overflowed
<valsize
>(value
, overflow
);
2094 template<int fieldsize
, int valsize
>
2095 static inline Status
2096 rela_ua(unsigned char* view
,
2097 unsigned int right_shift
,
2098 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2100 Overflow_check overflow
)
2102 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2104 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2105 if (overflow
== CHECK_SIGNED
)
2106 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2108 value
= value
>> right_shift
;
2109 Valtype reloc
= value
;
2112 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2113 return overflowed
<valsize
>(value
, overflow
);
2117 // R_PPC64_ADDR64: (Symbol + Addend)
2119 addr64(unsigned char* view
, Address value
)
2120 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2122 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2124 addr64_u(unsigned char* view
, Address value
)
2125 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2127 // R_POWERPC_ADDR32: (Symbol + Addend)
2128 static inline Status
2129 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2130 { return This::template rela
<32,32>(view
, value
, overflow
); }
2132 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2133 static inline Status
2134 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2135 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2137 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2138 static inline Status
2139 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2141 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2143 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2144 stat
= STATUS_OVERFLOW
;
2148 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2149 static inline Status
2150 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2151 { return This::template rela
<16,16>(view
, value
, overflow
); }
2153 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2154 static inline Status
2155 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2156 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2158 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2159 static inline Status
2160 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2162 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2163 if ((value
& 3) != 0)
2164 stat
= STATUS_OVERFLOW
;
2168 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2169 static inline Status
2170 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2172 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2173 if ((value
& 15) != 0)
2174 stat
= STATUS_OVERFLOW
;
2178 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2180 addr16_hi(unsigned char* view
, Address value
)
2181 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2183 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2185 addr16_ha(unsigned char* view
, Address value
)
2186 { This::addr16_hi(view
, value
+ 0x8000); }
2188 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2190 addr16_hi2(unsigned char* view
, Address value
)
2191 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2193 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2195 addr16_ha2(unsigned char* view
, Address value
)
2196 { This::addr16_hi2(view
, value
+ 0x8000); }
2198 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2200 addr16_hi3(unsigned char* view
, Address value
)
2201 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2203 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2205 addr16_ha3(unsigned char* view
, Address value
)
2206 { This::addr16_hi3(view
, value
+ 0x8000); }
2208 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2209 static inline Status
2210 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2212 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2213 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2214 stat
= STATUS_OVERFLOW
;
2218 // R_POWERPC_REL16DX_HA
2219 static inline Status
2220 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2222 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2223 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2224 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2226 value
= static_cast<SignedAddress
>(value
) >> 16;
2227 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2228 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2229 return overflowed
<16>(value
, overflow
);
2233 static inline Status
2234 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2236 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2238 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2244 addr34_hi(unsigned char *view
, uint64_t value
)
2245 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2249 addr34_ha(unsigned char *view
, uint64_t value
)
2250 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2253 static inline Status
2254 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2256 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2258 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2262 // R_PPC64_ADDR16_HIGHER34
2264 addr16_higher34(unsigned char* view
, uint64_t value
)
2265 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2267 // R_PPC64_ADDR16_HIGHERA34
2269 addr16_highera34(unsigned char* view
, uint64_t value
)
2270 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2272 // R_PPC64_ADDR16_HIGHEST34
2274 addr16_highest34(unsigned char* view
, uint64_t value
)
2275 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2277 // R_PPC64_ADDR16_HIGHESTA34
2279 addr16_highesta34(unsigned char* view
, uint64_t value
)
2280 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2283 // Set ABI version for input and output.
2285 template<int size
, bool big_endian
>
2287 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2289 this->e_flags_
|= ver
;
2290 if (this->abiversion() != 0)
2292 Target_powerpc
<size
, big_endian
>* target
=
2293 static_cast<Target_powerpc
<size
, big_endian
>*>(
2294 parameters
->sized_target
<size
, big_endian
>());
2295 if (target
->abiversion() == 0)
2296 target
->set_abiversion(this->abiversion());
2297 else if (target
->abiversion() != this->abiversion())
2298 gold_error(_("%s: ABI version %d is not compatible "
2299 "with ABI version %d output"),
2300 this->name().c_str(),
2301 this->abiversion(), target
->abiversion());
2306 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2307 // relocatable object, if such sections exists.
2309 template<int size
, bool big_endian
>
2311 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2312 Read_symbols_data
* sd
)
2314 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2315 const unsigned char* namesu
= sd
->section_names
->data();
2316 const char* names
= reinterpret_cast<const char*>(namesu
);
2317 section_size_type names_size
= sd
->section_names_size
;
2318 const unsigned char* s
;
2320 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2321 size
== 32 ? ".got2" : ".opd",
2322 names
, names_size
, NULL
);
2325 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2326 this->special_
= ndx
;
2329 if (this->abiversion() == 0)
2330 this->set_abiversion(1);
2331 else if (this->abiversion() > 1)
2332 gold_error(_("%s: .opd invalid in abiv%d"),
2333 this->name().c_str(), this->abiversion());
2338 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2339 names
, names_size
, NULL
);
2342 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2343 this->relatoc_
= ndx
;
2344 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2345 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2348 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2351 // Examine .rela.opd to build info about function entry points.
2353 template<int size
, bool big_endian
>
2355 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2357 const unsigned char* prelocs
,
2358 const unsigned char* plocal_syms
)
2362 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2363 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2364 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2365 Address expected_off
= 0;
2366 bool regular
= true;
2367 unsigned int opd_ent_size
= 0;
2369 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2371 Reltype
reloc(prelocs
);
2372 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2373 = reloc
.get_r_info();
2374 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2375 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2377 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2378 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2381 if (r_sym
< this->local_symbol_count())
2383 typename
elfcpp::Sym
<size
, big_endian
>
2384 lsym(plocal_syms
+ r_sym
* sym_size
);
2385 shndx
= lsym
.get_st_shndx();
2386 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2387 value
= lsym
.get_st_value();
2390 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2392 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2393 value
+ reloc
.get_r_addend());
2396 expected_off
= reloc
.get_r_offset();
2397 opd_ent_size
= expected_off
;
2399 else if (expected_off
!= reloc
.get_r_offset())
2401 expected_off
+= opd_ent_size
;
2403 else if (r_type
== elfcpp::R_PPC64_TOC
)
2405 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2410 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2411 this->name().c_str(), r_type
);
2415 if (reloc_count
<= 2)
2416 opd_ent_size
= this->section_size(this->opd_shndx());
2417 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2421 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2422 this->name().c_str());
2428 // Returns true if a code sequence loading the TOC entry at VALUE
2429 // relative to the TOC pointer can be converted into code calculating
2430 // a TOC pointer relative offset.
2431 // If so, the TOC pointer relative offset is stored to VALUE.
2433 template<int size
, bool big_endian
>
2435 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2436 Target_powerpc
<size
, big_endian
>* target
,
2442 // With -mcmodel=medium code it is quite possible to have
2443 // toc-relative relocs referring to objects outside the TOC.
2444 // Don't try to look at a non-existent TOC.
2445 if (this->toc_shndx() == 0)
2448 // Convert VALUE back to an address by adding got_base (see below),
2449 // then to an offset in the TOC by subtracting the TOC output
2450 // section address and the TOC output offset. Since this TOC output
2451 // section and the got output section are one and the same, we can
2452 // omit adding and subtracting the output section address.
2453 Address off
= (*value
+ this->toc_base_offset()
2454 - this->output_section_offset(this->toc_shndx()));
2455 // Is this offset in the TOC? -mcmodel=medium code may be using
2456 // TOC relative access to variables outside the TOC. Those of
2457 // course can't be optimized. We also don't try to optimize code
2458 // that is using a different object's TOC.
2459 if (off
>= this->section_size(this->toc_shndx()))
2462 if (this->no_toc_opt(off
))
2465 section_size_type vlen
;
2466 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2467 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2469 Address got_base
= (target
->got_section()->output_section()->address()
2470 + this->toc_base_offset());
2472 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2479 template<int size
, bool big_endian
>
2481 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2482 Target_powerpc
<size
, big_endian
>* target
,
2483 const Symbol_value
<size
>* psymval
,
2487 Address addr
= psymval
->value(this, addend
);
2488 Address got_base
= (target
->got_section()->output_section()->address()
2489 + this->toc_base_offset());
2491 if (addr
+ 0x80008000 > 0xffffffff)
2498 // Perform the Sized_relobj_file method, then set up opd info from
2501 template<int size
, bool big_endian
>
2503 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2505 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2508 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2509 p
!= rd
->relocs
.end();
2512 if (p
->data_shndx
== this->opd_shndx())
2514 uint64_t opd_size
= this->section_size(this->opd_shndx());
2515 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2518 this->init_opd(opd_size
);
2519 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2520 rd
->local_symbols
->data());
2528 // Read the symbols then set up st_other vector.
2530 template<int size
, bool big_endian
>
2532 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2534 this->base_read_symbols(sd
);
2535 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2539 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2540 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2541 const unsigned int loccount
= this->do_local_symbol_count();
2544 this->st_other_
.resize(loccount
);
2545 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2546 off_t locsize
= loccount
* sym_size
;
2547 const unsigned int symtab_shndx
= this->symtab_shndx();
2548 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2549 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2550 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2551 locsize
, true, false);
2553 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2555 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2556 unsigned char st_other
= sym
.get_st_other();
2557 this->st_other_
[i
] = st_other
;
2558 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2560 if (this->abiversion() == 0)
2561 this->set_abiversion(2);
2562 else if (this->abiversion() < 2)
2563 gold_error(_("%s: local symbol %d has invalid st_other"
2564 " for ABI version 1"),
2565 this->name().c_str(), i
);
2571 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2572 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2573 bool merge_attributes
= false;
2574 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2576 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2577 switch (shdr
.get_sh_type())
2579 case elfcpp::SHT_GNU_ATTRIBUTES
:
2581 gold_assert(this->attributes_section_data_
== NULL
);
2582 section_offset_type section_offset
= shdr
.get_sh_offset();
2583 section_size_type section_size
=
2584 convert_to_section_size_type(shdr
.get_sh_size());
2585 const unsigned char* view
=
2586 this->get_view(section_offset
, section_size
, true, false);
2587 this->attributes_section_data_
=
2588 new Attributes_section_data(view
, section_size
);
2592 case elfcpp::SHT_SYMTAB
:
2594 // Sometimes an object has no contents except the section
2595 // name string table and an empty symbol table with the
2596 // undefined symbol. We don't want to merge
2597 // processor-specific flags from such an object.
2598 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2599 elfcpp::Elf_sizes
<size
>::sym_size
;
2600 if (shdr
.get_sh_size() > sym_size
)
2601 merge_attributes
= true;
2605 case elfcpp::SHT_STRTAB
:
2609 merge_attributes
= true;
2614 if (!merge_attributes
)
2616 // Should rarely happen.
2617 delete this->attributes_section_data_
;
2618 this->attributes_section_data_
= NULL
;
2622 template<int size
, bool big_endian
>
2624 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2626 this->e_flags_
|= ver
;
2627 if (this->abiversion() != 0)
2629 Target_powerpc
<size
, big_endian
>* target
=
2630 static_cast<Target_powerpc
<size
, big_endian
>*>(
2631 parameters
->sized_target
<size
, big_endian
>());
2632 if (target
->abiversion() == 0)
2633 target
->set_abiversion(this->abiversion());
2634 else if (target
->abiversion() != this->abiversion())
2635 gold_error(_("%s: ABI version %d is not compatible "
2636 "with ABI version %d output"),
2637 this->name().c_str(),
2638 this->abiversion(), target
->abiversion());
2643 // Call Sized_dynobj::base_read_symbols to read the symbols then
2644 // read .opd from a dynamic object, filling in opd_ent_ vector,
2646 template<int size
, bool big_endian
>
2648 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2650 this->base_read_symbols(sd
);
2651 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2652 const unsigned char* ps
=
2653 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2654 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2656 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2657 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2659 section_offset_type section_offset
= shdr
.get_sh_offset();
2660 section_size_type section_size
=
2661 convert_to_section_size_type(shdr
.get_sh_size());
2662 const unsigned char* view
=
2663 this->get_view(section_offset
, section_size
, true, false);
2664 this->attributes_section_data_
=
2665 new Attributes_section_data(view
, section_size
);
2671 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2672 const unsigned char* namesu
= sd
->section_names
->data();
2673 const char* names
= reinterpret_cast<const char*>(namesu
);
2674 const unsigned char* s
= NULL
;
2675 const unsigned char* opd
;
2676 section_size_type opd_size
;
2678 // Find and read .opd section.
2681 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2682 sd
->section_names_size
,
2687 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2688 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2689 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2691 if (this->abiversion() == 0)
2692 this->set_abiversion(1);
2693 else if (this->abiversion() > 1)
2694 gold_error(_("%s: .opd invalid in abiv%d"),
2695 this->name().c_str(), this->abiversion());
2697 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2698 this->opd_address_
= shdr
.get_sh_addr();
2699 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2700 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2706 // Build set of executable sections.
2707 // Using a set is probably overkill. There is likely to be only
2708 // a few executable sections, typically .init, .text and .fini,
2709 // and they are generally grouped together.
2710 typedef std::set
<Sec_info
> Exec_sections
;
2711 Exec_sections exec_sections
;
2713 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2715 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2716 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2717 && ((shdr
.get_sh_flags()
2718 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2719 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2720 && shdr
.get_sh_size() != 0)
2722 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2723 shdr
.get_sh_size(), i
));
2726 if (exec_sections
.empty())
2729 // Look over the OPD entries. This is complicated by the fact
2730 // that some binaries will use two-word entries while others
2731 // will use the standard three-word entries. In most cases
2732 // the third word (the environment pointer for languages like
2733 // Pascal) is unused and will be zero. If the third word is
2734 // used it should not be pointing into executable sections,
2736 this->init_opd(opd_size
);
2737 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2739 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2740 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2741 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2743 // Chances are that this is the third word of an OPD entry.
2745 typename
Exec_sections::const_iterator e
2746 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2747 if (e
!= exec_sections
.begin())
2750 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2752 // We have an address in an executable section.
2753 // VAL ought to be the function entry, set it up.
2754 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2755 // Skip second word of OPD entry, the TOC pointer.
2759 // If we didn't match any executable sections, we likely
2760 // have a non-zero third word in the OPD entry.
2765 // Relocate sections.
2767 template<int size
, bool big_endian
>
2769 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2770 const Symbol_table
* symtab
, const Layout
* layout
,
2771 const unsigned char* pshdrs
, Output_file
* of
,
2772 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2774 unsigned int start
= 1;
2776 && this->relatoc_
!= 0
2777 && !parameters
->options().relocatable())
2779 // Relocate .toc first.
2780 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2781 this->relatoc_
, this->relatoc_
);
2782 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2783 1, this->relatoc_
- 1);
2784 start
= this->relatoc_
+ 1;
2786 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2787 start
, this->shnum() - 1);
2789 if (!parameters
->options().output_is_position_independent())
2791 Target_powerpc
<size
, big_endian
>* target
2792 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2793 parameters
->sized_target
<size
, big_endian
>());
2794 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2796 const section_size_type offset
= target
->lplt_section()->offset();
2797 const section_size_type oview_size
2798 = convert_to_section_size_type(target
->lplt_section()->data_size());
2799 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2801 bool modified
= false;
2802 unsigned int nsyms
= this->local_symbol_count();
2803 for (unsigned int i
= 0; i
< nsyms
; i
++)
2804 if (this->local_has_plt_offset(i
))
2806 Address value
= this->local_symbol_value(i
, 0);
2807 size_t off
= this->local_plt_offset(i
);
2808 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2812 of
->write_output_view(offset
, oview_size
, oview
);
2817 // Set up some symbols.
2819 template<int size
, bool big_endian
>
2821 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2822 Symbol_table
* symtab
,
2827 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2828 // undefined when scanning relocs (and thus requires
2829 // non-relative dynamic relocs). The proper value will be
2831 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2832 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2834 Target_powerpc
<size
, big_endian
>* target
=
2835 static_cast<Target_powerpc
<size
, big_endian
>*>(
2836 parameters
->sized_target
<size
, big_endian
>());
2837 Output_data_got_powerpc
<size
, big_endian
>* got
2838 = target
->got_section(symtab
, layout
);
2839 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2840 Symbol_table::PREDEFINED
,
2844 elfcpp::STV_HIDDEN
, 0,
2848 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2849 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2850 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2852 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2854 = layout
->add_output_section_data(".sdata", 0,
2856 | elfcpp::SHF_WRITE
,
2857 sdata
, ORDER_SMALL_DATA
, false);
2858 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2859 Symbol_table::PREDEFINED
,
2860 os
, 32768, 0, elfcpp::STT_OBJECT
,
2861 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2867 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2868 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2869 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2871 Target_powerpc
<size
, big_endian
>* target
=
2872 static_cast<Target_powerpc
<size
, big_endian
>*>(
2873 parameters
->sized_target
<size
, big_endian
>());
2874 Output_data_got_powerpc
<size
, big_endian
>* got
2875 = target
->got_section(symtab
, layout
);
2876 symtab
->define_in_output_data(".TOC.", NULL
,
2877 Symbol_table::PREDEFINED
,
2881 elfcpp::STV_HIDDEN
, 0,
2886 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2887 if (parameters
->options().tls_get_addr_optimize()
2888 && this->tls_get_addr_
!= NULL
2889 && this->tls_get_addr_
->in_reg())
2890 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2891 if (this->tls_get_addr_opt_
!= NULL
)
2893 if (this->tls_get_addr_
->is_undefined()
2894 || this->tls_get_addr_
->is_from_dynobj())
2896 // Make it seem as if references to __tls_get_addr are
2897 // really to __tls_get_addr_opt, so the latter symbol is
2898 // made dynamic, not the former.
2899 this->tls_get_addr_
->clear_in_reg();
2900 this->tls_get_addr_opt_
->set_in_reg();
2902 // We have a non-dynamic definition for __tls_get_addr.
2903 // Make __tls_get_addr_opt the same, if it does not already have
2904 // a non-dynamic definition.
2905 else if (this->tls_get_addr_opt_
->is_undefined()
2906 || this->tls_get_addr_opt_
->is_from_dynobj())
2908 Sized_symbol
<size
>* from
2909 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2910 Sized_symbol
<size
>* to
2911 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2912 symtab
->clone
<size
>(to
, from
);
2917 // Set up PowerPC target specific relobj.
2919 template<int size
, bool big_endian
>
2921 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2922 const std::string
& name
,
2923 Input_file
* input_file
,
2924 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2926 int et
= ehdr
.get_e_type();
2927 // ET_EXEC files are valid input for --just-symbols/-R,
2928 // and we treat them as relocatable objects.
2929 if (et
== elfcpp::ET_REL
2930 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2932 Powerpc_relobj
<size
, big_endian
>* obj
=
2933 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2937 else if (et
== elfcpp::ET_DYN
)
2939 Powerpc_dynobj
<size
, big_endian
>* obj
=
2940 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2946 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2951 template<int size
, bool big_endian
>
2952 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2955 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2956 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2958 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2959 : Output_data_got
<size
, big_endian
>(),
2960 symtab_(symtab
), layout_(layout
),
2961 header_ent_cnt_(size
== 32 ? 3 : 1),
2962 header_index_(size
== 32 ? 0x2000 : 0)
2965 this->set_addralign(256);
2968 // Override all the Output_data_got methods we use so as to first call
2971 add_global(Symbol
* gsym
, unsigned int got_type
)
2973 this->reserve_ent();
2974 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2978 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2980 this->reserve_ent();
2981 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2985 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2986 { return this->add_global_plt(gsym
, got_type
); }
2989 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2990 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2992 this->reserve_ent();
2993 Output_data_got
<size
, big_endian
>::
2994 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2998 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2999 Output_data_reloc_generic
* rel_dyn
,
3000 unsigned int r_type_1
, unsigned int r_type_2
)
3002 if (gsym
->has_got_offset(got_type
))
3005 this->reserve_ent(2);
3006 Output_data_got
<size
, big_endian
>::
3007 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
3011 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
3013 this->reserve_ent();
3014 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
3019 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
3021 this->reserve_ent();
3022 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
3027 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
3028 { return this->add_local_plt(object
, sym_index
, got_type
); }
3031 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
3032 unsigned int got_type
,
3033 Output_data_reloc_generic
* rel_dyn
,
3034 unsigned int r_type
)
3036 if (object
->local_has_got_offset(sym_index
, got_type
))
3039 this->reserve_ent(2);
3040 Output_data_got
<size
, big_endian
>::
3041 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
3045 add_constant(Valtype constant
)
3047 this->reserve_ent();
3048 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
3052 add_constant_pair(Valtype c1
, Valtype c2
)
3054 this->reserve_ent(2);
3055 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
3058 // Offset of _GLOBAL_OFFSET_TABLE_.
3062 return this->got_offset(this->header_index_
);
3065 // Offset of base used to access the GOT/TOC.
3066 // The got/toc pointer reg will be set to this value.
3068 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
3071 return this->g_o_t();
3073 return (this->output_section()->address()
3074 + object
->toc_base_offset()
3078 // Ensure our GOT has a header.
3080 set_final_data_size()
3082 if (this->header_ent_cnt_
!= 0)
3083 this->make_header();
3084 Output_data_got
<size
, big_endian
>::set_final_data_size();
3087 // First word of GOT header needs some values that are not
3088 // handled by Output_data_got so poke them in here.
3089 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3091 do_write(Output_file
* of
)
3094 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3095 val
= this->layout_
->dynamic_section()->address();
3097 val
= this->output_section()->address() + 0x8000;
3098 this->replace_constant(this->header_index_
, val
);
3099 Output_data_got
<size
, big_endian
>::do_write(of
);
3104 reserve_ent(unsigned int cnt
= 1)
3106 if (this->header_ent_cnt_
== 0)
3108 if (this->num_entries() + cnt
> this->header_index_
)
3109 this->make_header();
3115 this->header_ent_cnt_
= 0;
3116 this->header_index_
= this->num_entries();
3119 Output_data_got
<size
, big_endian
>::add_constant(0);
3120 Output_data_got
<size
, big_endian
>::add_constant(0);
3121 Output_data_got
<size
, big_endian
>::add_constant(0);
3123 // Define _GLOBAL_OFFSET_TABLE_ at the header
3124 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3127 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3128 sym
->set_value(this->g_o_t());
3131 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3132 Symbol_table::PREDEFINED
,
3133 this, this->g_o_t(), 0,
3136 elfcpp::STV_HIDDEN
, 0,
3140 Output_data_got
<size
, big_endian
>::add_constant(0);
3143 // Stashed pointers.
3144 Symbol_table
* symtab_
;
3148 unsigned int header_ent_cnt_
;
3149 // GOT header index.
3150 unsigned int header_index_
;
3153 // Get the GOT section, creating it if necessary.
3155 template<int size
, bool big_endian
>
3156 Output_data_got_powerpc
<size
, big_endian
>*
3157 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3160 if (this->got_
== NULL
)
3162 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3165 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3167 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3168 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3169 this->got_
, ORDER_DATA
, false);
3175 // Get the dynamic reloc section, creating it if necessary.
3177 template<int size
, bool big_endian
>
3178 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3179 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3181 if (this->rela_dyn_
== NULL
)
3183 gold_assert(layout
!= NULL
);
3184 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3185 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3186 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3187 ORDER_DYNAMIC_RELOCS
, false);
3189 return this->rela_dyn_
;
3192 // Similarly, but for ifunc symbols get the one for ifunc.
3194 template<int size
, bool big_endian
>
3195 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3196 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3201 return this->rela_dyn_section(layout
);
3203 if (this->iplt_
== NULL
)
3204 this->make_iplt_section(symtab
, layout
);
3205 return this->iplt_
->rel_plt();
3211 // Determine the stub group size. The group size is the absolute
3212 // value of the parameter --stub-group-size. If --stub-group-size
3213 // is passed a negative value, we restrict stubs to be always after
3214 // the stubbed branches.
3215 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3216 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3217 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3218 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3219 owner_(NULL
), output_section_(NULL
)
3223 // Return true iff input section can be handled by current stub
3226 can_add_to_stub_group(Output_section
* o
,
3227 const Output_section::Input_section
* i
,
3230 const Output_section::Input_section
*
3236 { return output_section_
; }
3239 set_output_and_owner(Output_section
* o
,
3240 const Output_section::Input_section
* i
)
3242 this->output_section_
= o
;
3251 // Adding group sections before the stubs.
3252 FINDING_STUB_SECTION
,
3253 // Adding group sections after the stubs.
3257 uint32_t stub_group_size_
;
3258 bool stubs_always_after_branch_
;
3259 bool suppress_size_errors_
;
3260 // True if a stub group can serve multiple output sections.
3263 // Current max size of group. Starts at stub_group_size_ but is
3264 // reduced to stub_group_size_/1024 on seeing a section with
3265 // external conditional branches.
3266 uint32_t group_size_
;
3267 uint64_t group_start_addr_
;
3268 // owner_ and output_section_ specify the section to which stubs are
3269 // attached. The stubs are placed at the end of this section.
3270 const Output_section::Input_section
* owner_
;
3271 Output_section
* output_section_
;
3274 // Return true iff input section can be handled by current stub
3275 // group. Sections are presented to this function in order,
3276 // so the first section is the head of the group.
3279 Stub_control::can_add_to_stub_group(Output_section
* o
,
3280 const Output_section::Input_section
* i
,
3283 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3285 uint64_t start_addr
= o
->address();
3288 // .init and .fini sections are pasted together to form a single
3289 // function. We can't be adding stubs in the middle of the function.
3290 this_size
= o
->data_size();
3293 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3294 this_size
= i
->data_size();
3297 uint64_t end_addr
= start_addr
+ this_size
;
3298 uint32_t group_size
= this->stub_group_size_
;
3300 this->group_size_
= group_size
= group_size
>> 10;
3302 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3303 gold_warning(_("%s:%s exceeds group size"),
3304 i
->relobj()->name().c_str(),
3305 i
->relobj()->section_name(i
->shndx()).c_str());
3307 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3308 has14
? " 14bit" : "",
3309 i
->relobj()->name().c_str(),
3310 i
->relobj()->section_name(i
->shndx()).c_str(),
3311 (long long) this_size
,
3312 (this->state_
== NO_GROUP
3314 : (long long) end_addr
- this->group_start_addr_
));
3316 if (this->state_
== NO_GROUP
)
3318 // Only here on very first use of Stub_control
3320 this->output_section_
= o
;
3321 this->state_
= FINDING_STUB_SECTION
;
3322 this->group_size_
= group_size
;
3323 this->group_start_addr_
= start_addr
;
3326 else if (!this->multi_os_
&& this->output_section_
!= o
)
3328 else if (this->state_
== HAS_STUB_SECTION
)
3330 // Can we add this section, which is after the stubs, to the
3332 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3335 else if (this->state_
== FINDING_STUB_SECTION
)
3337 if ((whole_sec
&& this->output_section_
== o
)
3338 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3340 // Stubs are added at the end of "owner_".
3342 this->output_section_
= o
;
3345 // The group before the stubs has reached maximum size.
3346 // Now see about adding sections after the stubs to the
3347 // group. If the current section has a 14-bit branch and
3348 // the group before the stubs exceeds group_size_ (because
3349 // they didn't have 14-bit branches), don't add sections
3350 // after the stubs: The size of stubs for such a large
3351 // group may exceed the reach of a 14-bit branch.
3352 if (!this->stubs_always_after_branch_
3353 && this_size
<= this->group_size_
3354 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3356 gold_debug(DEBUG_TARGET
, "adding after stubs");
3357 this->state_
= HAS_STUB_SECTION
;
3358 this->group_start_addr_
= start_addr
;
3365 gold_debug(DEBUG_TARGET
,
3366 !this->multi_os_
&& this->output_section_
!= o
3367 ? "nope, new output section\n"
3368 : "nope, didn't fit\n");
3370 // The section fails to fit in the current group. Set up a few
3371 // things for the next group. owner_ and output_section_ will be
3372 // set later after we've retrieved those values for the current
3374 this->state_
= FINDING_STUB_SECTION
;
3375 this->group_size_
= group_size
;
3376 this->group_start_addr_
= start_addr
;
3380 // Look over all the input sections, deciding where to place stubs.
3382 template<int size
, bool big_endian
>
3384 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3386 bool no_size_errors
)
3388 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3389 parameters
->options().stub_group_multi());
3391 // Group input sections and insert stub table
3392 Stub_table_owner
* table_owner
= NULL
;
3393 std::vector
<Stub_table_owner
*> tables
;
3394 Layout::Section_list section_list
;
3395 layout
->get_executable_sections(§ion_list
);
3396 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3397 for (Layout::Section_list::iterator o
= section_list
.begin();
3398 o
!= section_list
.end();
3401 typedef Output_section::Input_section_list Input_section_list
;
3402 for (Input_section_list::const_iterator i
3403 = (*o
)->input_sections().begin();
3404 i
!= (*o
)->input_sections().end();
3407 if (i
->is_input_section()
3408 || i
->is_relaxed_input_section())
3410 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3411 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3412 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3413 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3415 table_owner
->output_section
= stub_control
.output_section();
3416 table_owner
->owner
= stub_control
.owner();
3417 stub_control
.set_output_and_owner(*o
, &*i
);
3420 if (table_owner
== NULL
)
3422 table_owner
= new Stub_table_owner
;
3423 tables
.push_back(table_owner
);
3425 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3429 if (table_owner
!= NULL
)
3431 table_owner
->output_section
= stub_control
.output_section();
3432 table_owner
->owner
= stub_control
.owner();;
3434 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3438 Stub_table
<size
, big_endian
>* stub_table
;
3440 if ((*t
)->owner
->is_input_section())
3441 stub_table
= new Stub_table
<size
, big_endian
>(this,
3442 (*t
)->output_section
,
3444 this->stub_tables_
.size());
3445 else if ((*t
)->owner
->is_relaxed_input_section())
3446 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3447 (*t
)->owner
->relaxed_input_section());
3450 this->stub_tables_
.push_back(stub_table
);
3456 static unsigned long
3457 max_branch_delta (unsigned int r_type
)
3459 if (r_type
== elfcpp::R_POWERPC_REL14
3460 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3461 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3463 if (r_type
== elfcpp::R_POWERPC_REL24
3464 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3465 || r_type
== elfcpp::R_PPC_PLTREL24
3466 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3471 // Return whether this branch is going via a plt call stub.
3473 template<int size
, bool big_endian
>
3475 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3476 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3479 Target_powerpc
* target
,
3480 Symbol_table
* symtab
)
3482 if (this->object_
!= ppc_object
3483 || this->shndx_
!= shndx
3484 || this->offset_
!= offset
)
3487 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3488 if (sym
!= NULL
&& sym
->is_forwarder())
3489 sym
= symtab
->resolve_forwards(sym
);
3490 if (target
->replace_tls_get_addr(sym
))
3491 sym
= target
->tls_get_addr_opt();
3492 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3494 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3495 && !target
->is_elfv2_localentry0(gsym
))
3496 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3497 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3505 // If this branch needs a plt call stub, or a long branch stub, make one.
3507 template<int size
, bool big_endian
>
3509 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3510 Stub_table
<size
, big_endian
>* stub_table
,
3511 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3512 Symbol_table
* symtab
) const
3514 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3515 Target_powerpc
<size
, big_endian
>* target
=
3516 static_cast<Target_powerpc
<size
, big_endian
>*>(
3517 parameters
->sized_target
<size
, big_endian
>());
3518 if (sym
!= NULL
&& sym
->is_forwarder())
3519 sym
= symtab
->resolve_forwards(sym
);
3520 if (target
->replace_tls_get_addr(sym
))
3521 sym
= target
->tls_get_addr_opt();
3522 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3526 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3527 : this->object_
->local_has_plt_offset(this->r_sym_
))
3531 && target
->abiversion() >= 2
3532 && !parameters
->options().output_is_position_independent()
3533 && !is_branch_reloc
<size
>(this->r_type_
))
3534 target
->glink_section()->add_global_entry(gsym
);
3537 if (stub_table
== NULL
3540 && !parameters
->options().output_is_position_independent()
3541 && !is_branch_reloc
<size
>(this->r_type_
)))
3542 stub_table
= this->object_
->stub_table(this->shndx_
);
3543 if (stub_table
== NULL
)
3545 // This is a ref from a data section to an ifunc symbol,
3546 // or a non-branch reloc for which we always want to use
3547 // one set of stubs for resolving function addresses.
3548 stub_table
= ifunc_stub_table
;
3550 gold_assert(stub_table
!= NULL
);
3551 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3552 if (from
!= invalid_address
)
3553 from
+= (this->object_
->output_section(this->shndx_
)->address()
3556 ok
= stub_table
->add_plt_call_entry(from
,
3557 this->object_
, gsym
,
3558 this->r_type_
, this->addend_
,
3561 ok
= stub_table
->add_plt_call_entry(from
,
3562 this->object_
, this->r_sym_
,
3563 this->r_type_
, this->addend_
,
3569 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3570 if (max_branch_offset
== 0)
3572 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3573 gold_assert(from
!= invalid_address
);
3574 from
+= (this->object_
->output_section(this->shndx_
)->address()
3577 unsigned int other
= 0;
3580 switch (gsym
->source())
3582 case Symbol::FROM_OBJECT
:
3584 Object
* symobj
= gsym
->object();
3585 if (symobj
->is_dynamic()
3586 || symobj
->pluginobj() != NULL
)
3589 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3590 if (shndx
== elfcpp::SHN_UNDEF
)
3595 case Symbol::IS_UNDEFINED
:
3601 Symbol_table::Compute_final_value_status status
;
3602 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3603 if (status
!= Symbol_table::CFVS_OK
)
3606 other
= gsym
->nonvis() >> 3;
3610 const Symbol_value
<size
>* psymval
3611 = this->object_
->local_symbol(this->r_sym_
);
3612 Symbol_value
<size
> symval
;
3613 if (psymval
->is_section_symbol())
3614 symval
.set_is_section_symbol();
3615 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3616 typename
ObjType::Compute_final_local_value_status status
3617 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3619 if (status
!= ObjType::CFLV_OK
3620 || !symval
.has_output_value())
3622 to
= symval
.value(this->object_
, 0);
3624 other
= this->object_
->st_other(this->r_sym_
) >> 5;
3626 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3627 to
+= this->addend_
;
3628 if (stub_table
== NULL
)
3629 stub_table
= this->object_
->stub_table(this->shndx_
);
3630 if (size
== 64 && target
->abiversion() < 2)
3632 unsigned int dest_shndx
;
3633 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3637 unsigned int local_ent
= 0;
3639 && this->r_type_
!= elfcpp::R_PPC64_REL24_NOTOC
)
3640 local_ent
= elfcpp::ppc64_decode_local_entry(other
);
3641 Address delta
= to
+ local_ent
- from
;
3642 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3644 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3646 ? this->object_
->ppc64_needs_toc(gsym
)
3647 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3649 if (stub_table
== NULL
)
3651 gold_warning(_("%s:%s: branch in non-executable section,"
3652 " no long branch stub for you"),
3653 this->object_
->name().c_str(),
3654 this->object_
->section_name(this->shndx_
).c_str());
3657 bool save_res
= (size
== 64
3659 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3660 && gsym
->output_data() == target
->savres_section());
3661 ok
= stub_table
->add_long_branch_entry(this->object_
,
3663 from
, to
, other
, save_res
);
3667 gold_debug(DEBUG_TARGET
,
3668 "branch at %s:%s+%#lx\n"
3669 "can't reach stub attached to %s:%s",
3670 this->object_
->name().c_str(),
3671 this->object_
->section_name(this->shndx_
).c_str(),
3672 (unsigned long) this->offset_
,
3673 stub_table
->relobj()->name().c_str(),
3674 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3679 // Relaxation hook. This is where we do stub generation.
3681 template<int size
, bool big_endian
>
3683 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3684 const Input_objects
*,
3685 Symbol_table
* symtab
,
3689 unsigned int prev_brlt_size
= 0;
3693 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3695 && this->abiversion() < 2
3697 && !parameters
->options().user_set_plt_thread_safe())
3699 static const char* const thread_starter
[] =
3703 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3705 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3706 "mq_notify", "create_timer",
3711 "GOMP_parallel_start",
3712 "GOMP_parallel_loop_static",
3713 "GOMP_parallel_loop_static_start",
3714 "GOMP_parallel_loop_dynamic",
3715 "GOMP_parallel_loop_dynamic_start",
3716 "GOMP_parallel_loop_guided",
3717 "GOMP_parallel_loop_guided_start",
3718 "GOMP_parallel_loop_runtime",
3719 "GOMP_parallel_loop_runtime_start",
3720 "GOMP_parallel_sections",
3721 "GOMP_parallel_sections_start",
3726 if (parameters
->options().shared())
3730 for (unsigned int i
= 0;
3731 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3734 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3735 thread_safe
= (sym
!= NULL
3737 && sym
->in_real_elf());
3743 this->plt_thread_safe_
= thread_safe
;
3748 this->stub_group_size_
= parameters
->options().stub_group_size();
3749 bool no_size_errors
= true;
3750 if (this->stub_group_size_
== 1)
3751 this->stub_group_size_
= 0x1c00000;
3752 else if (this->stub_group_size_
== -1)
3753 this->stub_group_size_
= -0x1e00000;
3755 no_size_errors
= false;
3756 this->group_sections(layout
, task
, no_size_errors
);
3758 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3760 this->branch_lookup_table_
.clear();
3761 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3762 p
!= this->stub_tables_
.end();
3765 (*p
)->clear_stubs(true);
3767 this->stub_tables_
.clear();
3768 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3769 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3770 program_name
, this->stub_group_size_
);
3771 this->group_sections(layout
, task
, true);
3774 // We need address of stub tables valid for make_stub.
3775 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3776 p
!= this->stub_tables_
.end();
3779 const Powerpc_relobj
<size
, big_endian
>* object
3780 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3781 Address off
= object
->get_output_section_offset((*p
)->shndx());
3782 gold_assert(off
!= invalid_address
);
3783 Output_section
* os
= (*p
)->output_section();
3784 (*p
)->set_address_and_size(os
, off
);
3789 // Clear plt call stubs, long branch stubs and branch lookup table.
3790 prev_brlt_size
= this->branch_lookup_table_
.size();
3791 this->branch_lookup_table_
.clear();
3792 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3793 p
!= this->stub_tables_
.end();
3796 (*p
)->clear_stubs(false);
3800 // Build all the stubs.
3801 this->relax_failed_
= false;
3802 Stub_table
<size
, big_endian
>* ifunc_stub_table
3803 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3804 Stub_table
<size
, big_endian
>* one_stub_table
3805 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3806 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3807 b
!= this->branch_info_
.end();
3810 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3811 && !this->relax_failed_
)
3813 this->relax_failed_
= true;
3814 this->relax_fail_count_
++;
3815 if (this->relax_fail_count_
< 3)
3819 bool do_resize
= false;
3820 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3821 p
!= this->stub_tables_
.end();
3823 if ((*p
)->need_resize())
3830 this->branch_lookup_table_
.clear();
3831 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3832 p
!= this->stub_tables_
.end();
3834 (*p
)->set_resizing(true);
3835 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3836 b
!= this->branch_info_
.end();
3839 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3840 && !this->relax_failed_
)
3842 this->relax_failed_
= true;
3843 this->relax_fail_count_
++;
3844 if (this->relax_fail_count_
< 3)
3848 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3849 p
!= this->stub_tables_
.end();
3851 (*p
)->set_resizing(false);
3854 // Did anything change size?
3855 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3856 bool again
= num_huge_branches
!= prev_brlt_size
;
3857 if (size
== 64 && num_huge_branches
!= 0)
3858 this->make_brlt_section(layout
);
3859 if (size
== 64 && again
)
3860 this->brlt_section_
->set_current_size(num_huge_branches
);
3862 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3863 p
!= this->stub_tables_
.rend();
3865 (*p
)->remove_eh_frame(layout
);
3867 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3868 p
!= this->stub_tables_
.end();
3870 (*p
)->add_eh_frame(layout
);
3872 typedef Unordered_set
<Output_section
*> Output_sections
;
3873 Output_sections os_need_update
;
3874 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3875 p
!= this->stub_tables_
.end();
3878 if ((*p
)->size_update())
3881 os_need_update
.insert((*p
)->output_section());
3885 // Set output section offsets for all input sections in an output
3886 // section that just changed size. Anything past the stubs will
3888 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3889 p
!= os_need_update
.end();
3892 Output_section
* os
= *p
;
3894 typedef Output_section::Input_section_list Input_section_list
;
3895 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3896 i
!= os
->input_sections().end();
3899 off
= align_address(off
, i
->addralign());
3900 if (i
->is_input_section() || i
->is_relaxed_input_section())
3901 i
->relobj()->set_section_offset(i
->shndx(), off
);
3902 if (i
->is_relaxed_input_section())
3904 Stub_table
<size
, big_endian
>* stub_table
3905 = static_cast<Stub_table
<size
, big_endian
>*>(
3906 i
->relaxed_input_section());
3907 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3908 off
+= stub_table_size
;
3909 // After a few iterations, set current stub table size
3910 // as min size threshold, so later stub tables can only
3913 stub_table
->set_min_size_threshold(stub_table_size
);
3916 off
+= i
->data_size();
3918 // If .branch_lt is part of this output section, then we have
3919 // just done the offset adjustment.
3920 os
->clear_section_offsets_need_adjustment();
3925 && num_huge_branches
!= 0
3926 && parameters
->options().output_is_position_independent())
3928 // Fill in the BRLT relocs.
3929 this->brlt_section_
->reset_brlt_sizes();
3930 for (typename
Branch_lookup_table::const_iterator p
3931 = this->branch_lookup_table_
.begin();
3932 p
!= this->branch_lookup_table_
.end();
3935 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3937 this->brlt_section_
->finalize_brlt_sizes();
3941 && (parameters
->options().user_set_emit_stub_syms()
3942 ? parameters
->options().emit_stub_syms()
3944 || parameters
->options().output_is_position_independent()
3945 || parameters
->options().emit_relocs())))
3947 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3948 p
!= this->stub_tables_
.end();
3950 (*p
)->define_stub_syms(symtab
);
3952 if (this->glink_
!= NULL
)
3954 int stub_size
= this->glink_
->pltresolve_size();
3955 Address value
= -stub_size
;
3961 this->define_local(symtab
, "__glink_PLTresolve",
3962 this->glink_
, value
, stub_size
);
3965 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3972 template<int size
, bool big_endian
>
3974 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3975 unsigned char* oview
,
3979 uint64_t address
= plt
->address();
3980 off_t len
= plt
->data_size();
3982 if (plt
== this->glink_
)
3984 // See Output_data_glink::do_write() for glink contents.
3987 // Static linking may need stubs, to support ifunc and long
3988 // branches. We need to create an output section for
3989 // .eh_frame early in the link process, to have a place to
3990 // attach stub .eh_frame info. We also need to have
3991 // registered a CIE that matches the stub CIE. Both of
3992 // these requirements are satisfied by creating an FDE and
3993 // CIE for .glink, even though static linking will leave
3994 // .glink zero length.
3995 // ??? Hopefully generating an FDE with a zero address range
3996 // won't confuse anything that consumes .eh_frame info.
3998 else if (size
== 64)
4000 // There is one word before __glink_PLTresolve
4004 else if (parameters
->options().output_is_position_independent())
4006 // There are two FDEs for a position independent glink.
4007 // The first covers the branch table, the second
4008 // __glink_PLTresolve at the end of glink.
4009 off_t resolve_size
= this->glink_
->pltresolve_size();
4010 if (oview
[9] == elfcpp::DW_CFA_nop
)
4011 len
-= resolve_size
;
4014 address
+= len
- resolve_size
;
4021 // Must be a stub table.
4022 const Stub_table
<size
, big_endian
>* stub_table
4023 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
4024 uint64_t stub_address
= stub_table
->stub_address();
4025 len
-= stub_address
- address
;
4026 address
= stub_address
;
4029 *paddress
= address
;
4033 // A class to handle the PLT data.
4035 template<int size
, bool big_endian
>
4036 class Output_data_plt_powerpc
: public Output_section_data_build
4039 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4040 size
, big_endian
> Reloc_section
;
4042 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4043 Reloc_section
* plt_rel
,
4045 : Output_section_data_build(size
== 32 ? 4 : 8),
4051 // Add an entry to the PLT.
4056 add_ifunc_entry(Symbol
*);
4059 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4062 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
4064 // Return the .rela.plt section data.
4071 // Return the number of PLT entries.
4075 if (this->current_data_size() == 0)
4077 return ((this->current_data_size() - this->first_plt_entry_offset())
4078 / this->plt_entry_size());
4083 do_adjust_output_section(Output_section
* os
)
4088 // Write to a map file.
4090 do_print_to_mapfile(Mapfile
* mapfile
) const
4091 { mapfile
->print_output_data(this, this->name_
); }
4094 // Return the offset of the first non-reserved PLT entry.
4096 first_plt_entry_offset() const
4098 // IPLT and LPLT have no reserved entry.
4099 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4101 return this->targ_
->first_plt_entry_offset();
4104 // Return the size of each PLT entry.
4106 plt_entry_size() const
4108 return this->targ_
->plt_entry_size();
4111 // Write out the PLT data.
4113 do_write(Output_file
*);
4115 // The reloc section.
4116 Reloc_section
* rel_
;
4117 // Allows access to .glink for do_write.
4118 Target_powerpc
<size
, big_endian
>* targ_
;
4119 // What to report in map file.
4123 // Add an entry to the PLT.
4125 template<int size
, bool big_endian
>
4127 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4129 if (!gsym
->has_plt_offset())
4131 section_size_type off
= this->current_data_size();
4133 off
+= this->first_plt_entry_offset();
4134 gsym
->set_plt_offset(off
);
4135 gsym
->set_needs_dynsym_entry();
4136 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4137 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4138 off
+= this->plt_entry_size();
4139 this->set_current_data_size(off
);
4143 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4145 template<int size
, bool big_endian
>
4147 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4149 if (!gsym
->has_plt_offset())
4151 section_size_type off
= this->current_data_size();
4152 gsym
->set_plt_offset(off
);
4153 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4154 if (size
== 64 && this->targ_
->abiversion() < 2)
4155 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4156 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4157 off
+= this->plt_entry_size();
4158 this->set_current_data_size(off
);
4162 // Add an entry for a local symbol to the PLT.
4164 template<int size
, bool big_endian
>
4166 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4167 Sized_relobj_file
<size
, big_endian
>* relobj
,
4168 unsigned int local_sym_index
)
4170 if (!relobj
->local_has_plt_offset(local_sym_index
))
4172 section_size_type off
= this->current_data_size();
4173 relobj
->set_local_plt_offset(local_sym_index
, off
);
4176 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4177 if (size
== 64 && this->targ_
->abiversion() < 2)
4178 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4179 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4180 dynrel
, this, off
, 0);
4182 off
+= this->plt_entry_size();
4183 this->set_current_data_size(off
);
4187 // Add an entry for a local ifunc symbol to the IPLT.
4189 template<int size
, bool big_endian
>
4191 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4192 Sized_relobj_file
<size
, big_endian
>* relobj
,
4193 unsigned int local_sym_index
)
4195 if (!relobj
->local_has_plt_offset(local_sym_index
))
4197 section_size_type off
= this->current_data_size();
4198 relobj
->set_local_plt_offset(local_sym_index
, off
);
4199 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4200 if (size
== 64 && this->targ_
->abiversion() < 2)
4201 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4202 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4204 off
+= this->plt_entry_size();
4205 this->set_current_data_size(off
);
4209 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4210 static const uint32_t add_2_2_11
= 0x7c425a14;
4211 static const uint32_t add_2_2_12
= 0x7c426214;
4212 static const uint32_t add_3_3_2
= 0x7c631214;
4213 static const uint32_t add_3_3_13
= 0x7c636a14;
4214 static const uint32_t add_3_12_2
= 0x7c6c1214;
4215 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4216 static const uint32_t add_11_0_11
= 0x7d605a14;
4217 static const uint32_t add_11_2_11
= 0x7d625a14;
4218 static const uint32_t add_11_11_2
= 0x7d6b1214;
4219 static const uint32_t add_12_11_12
= 0x7d8b6214;
4220 static const uint32_t addi_0_12
= 0x380c0000;
4221 static const uint32_t addi_2_2
= 0x38420000;
4222 static const uint32_t addi_3_3
= 0x38630000;
4223 static const uint32_t addi_11_11
= 0x396b0000;
4224 static const uint32_t addi_12_1
= 0x39810000;
4225 static const uint32_t addi_12_11
= 0x398b0000;
4226 static const uint32_t addi_12_12
= 0x398c0000;
4227 static const uint32_t addis_0_2
= 0x3c020000;
4228 static const uint32_t addis_0_13
= 0x3c0d0000;
4229 static const uint32_t addis_2_12
= 0x3c4c0000;
4230 static const uint32_t addis_11_2
= 0x3d620000;
4231 static const uint32_t addis_11_11
= 0x3d6b0000;
4232 static const uint32_t addis_11_30
= 0x3d7e0000;
4233 static const uint32_t addis_12_1
= 0x3d810000;
4234 static const uint32_t addis_12_2
= 0x3d820000;
4235 static const uint32_t addis_12_11
= 0x3d8b0000;
4236 static const uint32_t addis_12_12
= 0x3d8c0000;
4237 static const uint32_t b
= 0x48000000;
4238 static const uint32_t bcl_20_31
= 0x429f0005;
4239 static const uint32_t bctr
= 0x4e800420;
4240 static const uint32_t bctrl
= 0x4e800421;
4241 static const uint32_t beqlr
= 0x4d820020;
4242 static const uint32_t blr
= 0x4e800020;
4243 static const uint32_t bnectr_p4
= 0x4ce20420;
4244 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4245 static const uint32_t cmpldi_2_0
= 0x28220000;
4246 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4247 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4248 static const uint32_t cror_15_15_15
= 0x4def7b82;
4249 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4250 static const uint32_t ld_0_1
= 0xe8010000;
4251 static const uint32_t ld_0_11
= 0xe80b0000;
4252 static const uint32_t ld_0_12
= 0xe80c0000;
4253 static const uint32_t ld_2_1
= 0xe8410000;
4254 static const uint32_t ld_2_2
= 0xe8420000;
4255 static const uint32_t ld_2_11
= 0xe84b0000;
4256 static const uint32_t ld_2_12
= 0xe84c0000;
4257 static const uint32_t ld_11_1
= 0xe9610000;
4258 static const uint32_t ld_11_2
= 0xe9620000;
4259 static const uint32_t ld_11_3
= 0xe9630000;
4260 static const uint32_t ld_11_11
= 0xe96b0000;
4261 static const uint32_t ld_12_2
= 0xe9820000;
4262 static const uint32_t ld_12_3
= 0xe9830000;
4263 static const uint32_t ld_12_11
= 0xe98b0000;
4264 static const uint32_t ld_12_12
= 0xe98c0000;
4265 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4266 static const uint32_t lfd_0_1
= 0xc8010000;
4267 static const uint32_t li_0_0
= 0x38000000;
4268 static const uint32_t li_11_0
= 0x39600000;
4269 static const uint32_t li_12_0
= 0x39800000;
4270 static const uint32_t lis_0
= 0x3c000000;
4271 static const uint32_t lis_2
= 0x3c400000;
4272 static const uint32_t lis_11
= 0x3d600000;
4273 static const uint32_t lis_12
= 0x3d800000;
4274 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4275 static const uint32_t lwz_0_12
= 0x800c0000;
4276 static const uint32_t lwz_11_3
= 0x81630000;
4277 static const uint32_t lwz_11_11
= 0x816b0000;
4278 static const uint32_t lwz_11_30
= 0x817e0000;
4279 static const uint32_t lwz_12_3
= 0x81830000;
4280 static const uint32_t lwz_12_12
= 0x818c0000;
4281 static const uint32_t lwzu_0_12
= 0x840c0000;
4282 static const uint32_t mflr_0
= 0x7c0802a6;
4283 static const uint32_t mflr_11
= 0x7d6802a6;
4284 static const uint32_t mflr_12
= 0x7d8802a6;
4285 static const uint32_t mr_0_3
= 0x7c601b78;
4286 static const uint32_t mr_3_0
= 0x7c030378;
4287 static const uint32_t mtctr_0
= 0x7c0903a6;
4288 static const uint32_t mtctr_11
= 0x7d6903a6;
4289 static const uint32_t mtctr_12
= 0x7d8903a6;
4290 static const uint32_t mtlr_0
= 0x7c0803a6;
4291 static const uint32_t mtlr_11
= 0x7d6803a6;
4292 static const uint32_t mtlr_12
= 0x7d8803a6;
4293 static const uint32_t nop
= 0x60000000;
4294 static const uint32_t ori_0_0_0
= 0x60000000;
4295 static const uint32_t ori_11_11_0
= 0x616b0000;
4296 static const uint32_t ori_12_12_0
= 0x618c0000;
4297 static const uint32_t oris_12_12_0
= 0x658c0000;
4298 static const uint32_t sldi_11_11_34
= 0x796b1746;
4299 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4300 static const uint32_t srdi_0_0_2
= 0x7800f082;
4301 static const uint32_t std_0_1
= 0xf8010000;
4302 static const uint32_t std_0_12
= 0xf80c0000;
4303 static const uint32_t std_2_1
= 0xf8410000;
4304 static const uint32_t std_11_1
= 0xf9610000;
4305 static const uint32_t stfd_0_1
= 0xd8010000;
4306 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4307 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4308 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4309 static const uint32_t xor_2_12_12
= 0x7d826278;
4310 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4312 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4313 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4314 static const uint64_t pnop
= 0x0700000000000000ULL
;
4316 // Write out the PLT.
4318 template<int size
, bool big_endian
>
4320 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4322 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4324 const section_size_type offset
= this->offset();
4325 const section_size_type oview_size
4326 = convert_to_section_size_type(this->data_size());
4327 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4328 unsigned char* pov
= oview
;
4329 unsigned char* endpov
= oview
+ oview_size
;
4331 // The address of the .glink branch table
4332 const Output_data_glink
<size
, big_endian
>* glink
4333 = this->targ_
->glink_section();
4334 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4336 while (pov
< endpov
)
4338 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4343 of
->write_output_view(offset
, oview_size
, oview
);
4347 // Create the PLT section.
4349 template<int size
, bool big_endian
>
4351 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4354 if (this->plt_
== NULL
)
4356 if (this->got_
== NULL
)
4357 this->got_section(symtab
, layout
);
4359 if (this->glink_
== NULL
)
4360 make_glink_section(layout
);
4362 // Ensure that .rela.dyn always appears before .rela.plt This is
4363 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4364 // needs to include .rela.plt in its range.
4365 this->rela_dyn_section(layout
);
4367 Reloc_section
* plt_rel
= new Reloc_section(false);
4368 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4369 elfcpp::SHF_ALLOC
, plt_rel
,
4370 ORDER_DYNAMIC_PLT_RELOCS
, false);
4372 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4374 layout
->add_output_section_data(".plt",
4376 ? elfcpp::SHT_PROGBITS
4377 : elfcpp::SHT_NOBITS
),
4378 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4385 Output_section
* rela_plt_os
= plt_rel
->output_section();
4386 rela_plt_os
->set_info_section(this->plt_
->output_section());
4390 // Create the IPLT section.
4392 template<int size
, bool big_endian
>
4394 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4397 if (this->iplt_
== NULL
)
4399 this->make_plt_section(symtab
, layout
);
4400 this->make_lplt_section(layout
);
4402 Reloc_section
* iplt_rel
= new Reloc_section(false);
4403 if (this->rela_dyn_
->output_section())
4404 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4406 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4408 if (this->plt_
->output_section())
4409 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4413 // Create the LPLT section.
4415 template<int size
, bool big_endian
>
4417 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4419 if (this->lplt_
== NULL
)
4421 Reloc_section
* lplt_rel
= NULL
;
4422 if (parameters
->options().output_is_position_independent())
4424 lplt_rel
= new Reloc_section(false);
4425 this->rela_dyn_section(layout
);
4426 if (this->rela_dyn_
->output_section())
4427 this->rela_dyn_
->output_section()
4428 ->add_output_section_data(lplt_rel
);
4431 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4433 this->make_brlt_section(layout
);
4434 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4435 this->brlt_section_
->output_section()
4436 ->add_output_section_data(this->lplt_
);
4438 layout
->add_output_section_data(".branch_lt",
4439 elfcpp::SHT_PROGBITS
,
4440 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4447 // A section for huge long branch addresses, similar to plt section.
4449 template<int size
, bool big_endian
>
4450 class Output_data_brlt_powerpc
: public Output_section_data_build
4453 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4454 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4455 size
, big_endian
> Reloc_section
;
4457 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4458 Reloc_section
* brlt_rel
)
4459 : Output_section_data_build(size
== 32 ? 4 : 8),
4467 this->reset_data_size();
4468 this->rel_
->reset_data_size();
4472 finalize_brlt_sizes()
4474 this->finalize_data_size();
4475 this->rel_
->finalize_data_size();
4478 // Add a reloc for an entry in the BRLT.
4480 add_reloc(Address to
, unsigned int off
)
4481 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4483 // Update section and reloc section size.
4485 set_current_size(unsigned int num_branches
)
4487 this->reset_address_and_file_offset();
4488 this->set_current_data_size(num_branches
* 16);
4489 this->finalize_data_size();
4490 Output_section
* os
= this->output_section();
4491 os
->set_section_offsets_need_adjustment();
4492 if (this->rel_
!= NULL
)
4494 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4495 this->rel_
->reset_address_and_file_offset();
4496 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4497 this->rel_
->finalize_data_size();
4498 Output_section
* os
= this->rel_
->output_section();
4499 os
->set_section_offsets_need_adjustment();
4505 do_adjust_output_section(Output_section
* os
)
4510 // Write to a map file.
4512 do_print_to_mapfile(Mapfile
* mapfile
) const
4513 { mapfile
->print_output_data(this, "** BRLT"); }
4516 // Write out the BRLT data.
4518 do_write(Output_file
*);
4520 // The reloc section.
4521 Reloc_section
* rel_
;
4522 Target_powerpc
<size
, big_endian
>* targ_
;
4525 // Make the branch lookup table section.
4527 template<int size
, bool big_endian
>
4529 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4531 if (size
== 64 && this->brlt_section_
== NULL
)
4533 Reloc_section
* brlt_rel
= NULL
;
4534 bool is_pic
= parameters
->options().output_is_position_independent();
4537 // When PIC we can't fill in .branch_lt but must initialise at
4538 // runtime via dynamic relocations.
4539 this->rela_dyn_section(layout
);
4540 brlt_rel
= new Reloc_section(false);
4541 if (this->rela_dyn_
->output_section())
4542 this->rela_dyn_
->output_section()
4543 ->add_output_section_data(brlt_rel
);
4546 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4547 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4548 this->plt_
->output_section()
4549 ->add_output_section_data(this->brlt_section_
);
4551 layout
->add_output_section_data(".branch_lt",
4552 elfcpp::SHT_PROGBITS
,
4553 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4554 this->brlt_section_
,
4560 // Write out .branch_lt when non-PIC.
4562 template<int size
, bool big_endian
>
4564 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4566 if (size
== 64 && !parameters
->options().output_is_position_independent())
4568 const section_size_type offset
= this->offset();
4569 const section_size_type oview_size
4570 = convert_to_section_size_type(this->data_size());
4571 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4573 this->targ_
->write_branch_lookup_table(oview
);
4574 of
->write_output_view(offset
, oview_size
, oview
);
4578 static inline uint32_t
4584 static inline uint32_t
4590 static inline uint32_t
4593 return hi(a
+ 0x8000);
4596 static inline uint64_t
4599 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4602 static inline uint64_t
4605 return (v
+ (1ULL << 33)) >> 34;
4611 static const unsigned char eh_frame_cie
[12];
4615 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4618 'z', 'R', 0, // Augmentation string.
4619 4, // Code alignment.
4620 0x80 - size
/ 8 , // Data alignment.
4622 1, // Augmentation size.
4623 (elfcpp::DW_EH_PE_pcrel
4624 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4625 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4628 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4629 static const unsigned char glink_eh_frame_fde_64v1
[] =
4631 0, 0, 0, 0, // Replaced with offset to .glink.
4632 0, 0, 0, 0, // Replaced with size of .glink.
4633 0, // Augmentation size.
4634 elfcpp::DW_CFA_advance_loc
+ 2,
4635 elfcpp::DW_CFA_register
, 65, 12,
4636 elfcpp::DW_CFA_advance_loc
+ 4,
4637 elfcpp::DW_CFA_restore_extended
, 65
4640 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4641 static const unsigned char glink_eh_frame_fde_64v2
[] =
4643 0, 0, 0, 0, // Replaced with offset to .glink.
4644 0, 0, 0, 0, // Replaced with size of .glink.
4645 0, // Augmentation size.
4646 elfcpp::DW_CFA_advance_loc
+ 2,
4647 elfcpp::DW_CFA_register
, 65, 0,
4648 elfcpp::DW_CFA_advance_loc
+ 2,
4649 elfcpp::DW_CFA_restore_extended
, 65
4652 static const unsigned char glink_eh_frame_fde_64v2_localentry0
[] =
4654 0, 0, 0, 0, // Replaced with offset to .glink.
4655 0, 0, 0, 0, // Replaced with size of .glink.
4656 0, // Augmentation size.
4657 elfcpp::DW_CFA_advance_loc
+ 3,
4658 elfcpp::DW_CFA_register
, 65, 0,
4659 elfcpp::DW_CFA_advance_loc
+ 2,
4660 elfcpp::DW_CFA_restore_extended
, 65
4663 // Describe __glink_PLTresolve use of LR, 32-bit version.
4664 static const unsigned char glink_eh_frame_fde_32
[] =
4666 0, 0, 0, 0, // Replaced with offset to .glink.
4667 0, 0, 0, 0, // Replaced with size of .glink.
4668 0, // Augmentation size.
4669 elfcpp::DW_CFA_advance_loc
+ 2,
4670 elfcpp::DW_CFA_register
, 65, 0,
4671 elfcpp::DW_CFA_advance_loc
+ 4,
4672 elfcpp::DW_CFA_restore_extended
, 65
4675 static const unsigned char default_fde
[] =
4677 0, 0, 0, 0, // Replaced with offset to stubs.
4678 0, 0, 0, 0, // Replaced with size of stubs.
4679 0, // Augmentation size.
4680 elfcpp::DW_CFA_nop
, // Pad.
4685 template<bool big_endian
>
4687 write_insn(unsigned char* p
, uint32_t v
)
4689 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4693 static inline unsigned int
4696 if (!parameters
->options().user_set_plt_align())
4697 return size
== 64 ? 32 : 8;
4698 return 1 << parameters
->options().plt_align();
4701 // Stub_table holds information about plt and long branch stubs.
4702 // Stubs are built in an area following some input section determined
4703 // by group_sections(). This input section is converted to a relaxed
4704 // input section allowing it to be resized to accommodate the stubs
4706 template<int size
, bool big_endian
>
4707 class Stub_table
: public Output_relaxed_input_section
4712 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4713 : off_(off
), indx_(indx
), iter_(0), notoc_(0), toc_(0),
4714 r2save_(0), localentry0_(0), tocoff_(0)
4719 unsigned int iter_
: 1;
4720 unsigned int notoc_
: 1;
4721 unsigned int toc_
: 1;
4722 unsigned int r2save_
: 1;
4723 unsigned int localentry0_
: 1;
4724 unsigned int tocoff_
: 8;
4726 struct Branch_stub_ent
4728 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4729 : off_(off
), iter_(0), notoc_(notoc
), toc_(0), save_res_(save_res
),
4730 other_(0), tocoff_(0)
4734 unsigned int iter_
: 1;
4735 unsigned int notoc_
: 1;
4736 unsigned int toc_
: 1;
4737 unsigned int save_res_
: 1;
4738 unsigned int other_
: 3;
4739 unsigned int tocoff_
: 8;
4741 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4742 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4744 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4745 Output_section
* output_section
,
4746 const Output_section::Input_section
* owner
,
4748 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4750 ->section_addralign(owner
->shndx())),
4751 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4752 orig_data_size_(owner
->current_data_size()),
4753 plt_size_(0), last_plt_size_(0),
4754 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4755 need_save_res_(false), need_resize_(false), resizing_(false),
4758 this->set_output_section(output_section
);
4760 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4761 new_relaxed
.push_back(this);
4762 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4765 // Add a plt call stub.
4767 add_plt_call_entry(Address
,
4768 const Sized_relobj_file
<size
, big_endian
>*,
4775 add_plt_call_entry(Address
,
4776 const Sized_relobj_file
<size
, big_endian
>*,
4782 // Find a given plt call stub.
4784 find_plt_call_entry(const Symbol
*) const;
4787 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4788 unsigned int) const;
4791 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4797 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4802 // Add a long branch stub.
4804 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4805 unsigned int, Address
, Address
, unsigned int, bool);
4807 const Branch_stub_ent
*
4808 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4812 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4814 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4815 if (max_branch_offset
== 0)
4817 gold_assert(from
!= invalid_address
);
4818 Address loc
= off
+ this->stub_address();
4819 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4823 clear_stubs(bool all
)
4825 this->plt_call_stubs_
.clear();
4826 this->plt_size_
= 0;
4827 this->long_branch_stubs_
.clear();
4828 this->branch_size_
= 0;
4829 this->need_save_res_
= false;
4832 this->last_plt_size_
= 0;
4833 this->last_branch_size_
= 0;
4839 { return need_resize_
; }
4842 set_resizing(bool val
)
4844 this->resizing_
= val
;
4847 this->need_resize_
= false;
4848 this->plt_size_
= 0;
4849 this->branch_size_
= 0;
4850 this->need_save_res_
= false;
4855 set_address_and_size(const Output_section
* os
, Address off
)
4857 Address start_off
= off
;
4858 off
+= this->orig_data_size_
;
4859 Address my_size
= this->plt_size_
+ this->branch_size_
;
4860 if (this->need_save_res_
)
4861 my_size
+= this->targ_
->savres_section()->data_size();
4863 off
= align_address(off
, this->stub_align());
4864 // Include original section size and alignment padding in size
4865 my_size
+= off
- start_off
;
4866 // Ensure new size is always larger than min size
4867 // threshold. Alignment requirement is included in "my_size", so
4868 // increase "my_size" does not invalidate alignment.
4869 if (my_size
< this->min_size_threshold_
)
4870 my_size
= this->min_size_threshold_
;
4871 this->reset_address_and_file_offset();
4872 this->set_current_data_size(my_size
);
4873 this->set_address_and_file_offset(os
->address() + start_off
,
4874 os
->offset() + start_off
);
4879 stub_address() const
4881 return align_address(this->address() + this->orig_data_size_
,
4882 this->stub_align());
4888 return align_address(this->offset() + this->orig_data_size_
,
4889 this->stub_align());
4894 { return this->plt_size_
; }
4898 { return this->branch_size_
; }
4901 set_min_size_threshold(Address min_size
)
4902 { this->min_size_threshold_
= min_size
; }
4905 define_stub_syms(Symbol_table
*);
4910 Output_section
* os
= this->output_section();
4911 if (os
->addralign() < this->stub_align())
4913 os
->set_addralign(this->stub_align());
4914 // FIXME: get rid of the insane checkpointing.
4915 // We can't increase alignment of the input section to which
4916 // stubs are attached; The input section may be .init which
4917 // is pasted together with other .init sections to form a
4918 // function. Aligning might insert zero padding resulting in
4919 // sigill. However we do need to increase alignment of the
4920 // output section so that the align_address() on offset in
4921 // set_address_and_size() adds the same padding as the
4922 // align_address() on address in stub_address().
4923 // What's more, we need this alignment for the layout done in
4924 // relaxation_loop_body() so that the output section starts at
4925 // a suitably aligned address.
4926 os
->checkpoint_set_addralign(this->stub_align());
4928 if (this->last_plt_size_
!= this->plt_size_
4929 || this->last_branch_size_
!= this->branch_size_
)
4931 this->last_plt_size_
= this->plt_size_
;
4932 this->last_branch_size_
= this->branch_size_
;
4938 // Add .eh_frame info for this stub section.
4940 add_eh_frame(Layout
* layout
);
4942 // Remove .eh_frame info for this stub section.
4944 remove_eh_frame(Layout
* layout
);
4946 Target_powerpc
<size
, big_endian
>*
4952 class Plt_stub_key_hash
;
4953 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4954 Plt_stub_key_hash
> Plt_stub_entries
;
4955 class Branch_stub_key
;
4956 class Branch_stub_key_hash
;
4957 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4958 Branch_stub_key_hash
> Branch_stub_entries
;
4960 // Alignment of stub section.
4964 unsigned int min_align
= size
== 64 ? 32 : 16;
4965 unsigned int user_align
= 1 << parameters
->options().plt_align();
4966 return std::max(user_align
, min_align
);
4969 // Return the plt offset for the given call stub.
4971 plt_off(typename
Plt_stub_entries::const_iterator p
,
4972 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4974 const Symbol
* gsym
= p
->first
.sym_
;
4976 return this->targ_
->plt_off(gsym
, sec
);
4979 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4980 unsigned int local_sym_index
= p
->first
.locsym_
;
4981 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4985 // Size of a given plt call stub.
4987 plt_call_size(typename
Plt_stub_entries::iterator p
) const;
4990 plt_call_align(unsigned int bytes
) const
4992 unsigned int align
= param_plt_align
<size
>();
4993 return (bytes
+ align
- 1) & -align
;
4996 // Return long branch stub size.
4998 branch_stub_size(typename
Branch_stub_entries::iterator p
,
5002 build_tls_opt_head(unsigned char** pp
, bool save_lr
);
5005 build_tls_opt_tail(unsigned char* p
);
5008 plt_error(const Plt_stub_key
& p
);
5012 do_write(Output_file
*);
5014 // Plt call stub keys.
5018 Plt_stub_key(const Symbol
* sym
)
5019 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5022 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5023 unsigned int locsym_index
)
5024 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5027 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5029 unsigned int r_type
,
5031 : sym_(sym
), object_(0), addend_(0), locsym_(0)
5034 this->addend_
= addend
;
5035 else if (parameters
->options().output_is_position_independent()
5036 && (r_type
== elfcpp::R_PPC_PLTREL24
5037 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5039 this->addend_
= addend
;
5040 if (this->addend_
>= 32768)
5041 this->object_
= object
;
5045 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
5046 unsigned int locsym_index
,
5047 unsigned int r_type
,
5049 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
5052 this->addend_
= addend
;
5053 else if (parameters
->options().output_is_position_independent()
5054 && (r_type
== elfcpp::R_PPC_PLTREL24
5055 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
5056 this->addend_
= addend
;
5059 bool operator==(const Plt_stub_key
& that
) const
5061 return (this->sym_
== that
.sym_
5062 && this->object_
== that
.object_
5063 && this->addend_
== that
.addend_
5064 && this->locsym_
== that
.locsym_
);
5068 const Sized_relobj_file
<size
, big_endian
>* object_
;
5069 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
5070 unsigned int locsym_
;
5073 class Plt_stub_key_hash
5076 size_t operator()(const Plt_stub_key
& ent
) const
5078 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
5079 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
5085 // Long branch stub keys.
5086 class Branch_stub_key
5089 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
5090 : dest_(to
), toc_base_off_(0)
5093 toc_base_off_
= obj
->toc_base_offset();
5096 bool operator==(const Branch_stub_key
& that
) const
5098 return (this->dest_
== that
.dest_
5100 || this->toc_base_off_
== that
.toc_base_off_
));
5104 unsigned int toc_base_off_
;
5107 class Branch_stub_key_hash
5110 size_t operator()(const Branch_stub_key
& key
) const
5111 { return key
.dest_
^ key
.toc_base_off_
; }
5114 // In a sane world this would be a global.
5115 Target_powerpc
<size
, big_endian
>* targ_
;
5116 // Map sym/object/addend to stub offset.
5117 Plt_stub_entries plt_call_stubs_
;
5118 // Map destination address to stub offset.
5119 Branch_stub_entries long_branch_stubs_
;
5120 // size of input section
5121 section_size_type orig_data_size_
;
5123 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5124 // Some rare cases cause (PR/20529) fluctuation in stub table
5125 // size, which leads to an endless relax loop. This is to be fixed
5126 // by, after the first few iterations, allowing only increase of
5127 // stub table size. This variable sets the minimal possible size of
5128 // a stub table, it is zero for the first few iterations, then
5129 // increases monotonically.
5130 Address min_size_threshold_
;
5131 // Set if this stub group needs a copy of out-of-line register
5132 // save/restore functions.
5133 bool need_save_res_
;
5134 // Set when notoc_/r2save_ changes after sizing a stub
5136 // Set when resizing stubs
5138 // Per stub table unique identifier.
5142 // Add a plt call stub, if we do not already have one for this
5143 // sym/object/addend combo.
5145 template<int size
, bool big_endian
>
5147 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5149 const Sized_relobj_file
<size
, big_endian
>* object
,
5151 unsigned int r_type
,
5155 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5156 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5157 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5158 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5162 && this->targ_
->is_elfv2_localentry0(gsym
))
5164 p
.first
->second
.localentry0_
= 1;
5165 this->targ_
->set_has_localentry0();
5167 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5169 if (!p
.second
&& !p
.first
->second
.notoc_
5170 && (!this->targ_
->power10_stubs()
5171 || this->targ_
->power10_stubs_auto()))
5172 this->need_resize_
= true;
5173 p
.first
->second
.notoc_
= 1;
5177 if (!p
.second
&& !p
.first
->second
.toc_
)
5178 this->need_resize_
= true;
5179 p
.first
->second
.toc_
= 1;
5180 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5182 if (!p
.second
&& !p
.first
->second
.r2save_
)
5183 this->need_resize_
= true;
5184 p
.first
->second
.r2save_
= 1;
5188 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5190 if (this->resizing_
)
5192 p
.first
->second
.iter_
= 1;
5193 p
.first
->second
.off_
= this->plt_size_
;
5195 this->plt_size_
+= this->plt_call_size(p
.first
);
5196 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5197 this->targ_
->set_has_tls_get_addr_opt();
5198 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5200 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5203 template<int size
, bool big_endian
>
5205 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5207 const Sized_relobj_file
<size
, big_endian
>* object
,
5208 unsigned int locsym_index
,
5209 unsigned int r_type
,
5213 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5214 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5215 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5216 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5220 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5222 p
.first
->second
.localentry0_
= 1;
5223 this->targ_
->set_has_localentry0();
5225 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5227 if (!p
.second
&& !p
.first
->second
.notoc_
5228 && (!this->targ_
->power10_stubs()
5229 || this->targ_
->power10_stubs_auto()))
5230 this->need_resize_
= true;
5231 p
.first
->second
.notoc_
= 1;
5235 if (!p
.second
&& !p
.first
->second
.toc_
)
5236 this->need_resize_
= true;
5237 p
.first
->second
.toc_
= 1;
5238 if (!tocsave
&& !p
.first
->second
.localentry0_
)
5240 if (!p
.second
&& !p
.first
->second
.r2save_
)
5241 this->need_resize_
= true;
5242 p
.first
->second
.r2save_
= 1;
5246 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5248 if (this->resizing_
)
5250 p
.first
->second
.iter_
= 1;
5251 p
.first
->second
.off_
= this->plt_size_
;
5253 this->plt_size_
+= this->plt_call_size(p
.first
);
5254 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5256 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5259 // Find a plt call stub.
5261 template<int size
, bool big_endian
>
5262 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5263 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5264 const Sized_relobj_file
<size
, big_endian
>* object
,
5266 unsigned int r_type
,
5267 Address addend
) const
5269 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5270 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5271 if (p
== this->plt_call_stubs_
.end())
5276 template<int size
, bool big_endian
>
5277 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5278 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5280 Plt_stub_key
key(gsym
);
5281 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5282 if (p
== this->plt_call_stubs_
.end())
5287 template<int size
, bool big_endian
>
5288 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5289 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5290 const Sized_relobj_file
<size
, big_endian
>* object
,
5291 unsigned int locsym_index
,
5292 unsigned int r_type
,
5293 Address addend
) const
5295 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5296 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5297 if (p
== this->plt_call_stubs_
.end())
5302 template<int size
, bool big_endian
>
5303 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5304 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5305 const Sized_relobj_file
<size
, big_endian
>* object
,
5306 unsigned int locsym_index
) const
5308 Plt_stub_key
key(object
, locsym_index
);
5309 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5310 if (p
== this->plt_call_stubs_
.end())
5315 // Add a long branch stub if we don't already have one to given
5318 template<int size
, bool big_endian
>
5320 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5321 const Powerpc_relobj
<size
, big_endian
>* object
,
5322 unsigned int r_type
,
5328 Branch_stub_key
key(object
, to
);
5329 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5330 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5331 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5332 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5335 if (!p
.second
&& !p
.first
->second
.notoc_
)
5336 this->need_resize_
= true;
5337 p
.first
->second
.notoc_
= true;
5341 if (!p
.second
&& !p
.first
->second
.toc_
)
5342 this->need_resize_
= true;
5343 p
.first
->second
.toc_
= true;
5345 if (size
== 64 && p
.first
->second
.other_
== 0)
5346 p
.first
->second
.other_
= other
;
5347 gold_assert(save_res
== p
.first
->second
.save_res_
);
5348 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5350 if (this->resizing_
)
5352 p
.first
->second
.iter_
= 1;
5353 p
.first
->second
.off_
= this->branch_size_
;
5356 this->need_save_res_
= true;
5359 bool need_lt
= false;
5360 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5361 this->branch_size_
+= stub_size
;
5362 if (size
== 64 && need_lt
)
5363 this->targ_
->add_branch_lookup_table(to
);
5366 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5369 // Find long branch stub offset.
5371 template<int size
, bool big_endian
>
5372 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5373 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5374 const Powerpc_relobj
<size
, big_endian
>* object
,
5377 Branch_stub_key
key(object
, to
);
5378 typename
Branch_stub_entries::const_iterator p
5379 = this->long_branch_stubs_
.find(key
);
5380 if (p
== this->long_branch_stubs_
.end())
5385 template<bool big_endian
>
5387 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5391 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5392 else if (delta
< 256)
5394 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5395 fde
.push_back(delta
);
5397 else if (delta
< 65536)
5399 fde
.resize(fde
.size() + 3);
5400 unsigned char *p
= &*fde
.end() - 3;
5401 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5402 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5406 fde
.resize(fde
.size() + 5);
5407 unsigned char *p
= &*fde
.end() - 5;
5408 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5409 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5413 template<typename T
>
5415 stub_sort(T s1
, T s2
)
5417 return s1
->second
.off_
< s2
->second
.off_
;
5420 // Add .eh_frame info for this stub section. Unlike other linker
5421 // generated .eh_frame this is added late in the link, because we
5422 // only want the .eh_frame info if this particular stub section is
5425 template<int size
, bool big_endian
>
5427 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5430 || !parameters
->options().ld_generated_unwind_info())
5433 // Since we add stub .eh_frame info late, it must be placed
5434 // after all other linker generated .eh_frame info so that
5435 // merge mapping need not be updated for input sections.
5436 // There is no provision to use a different CIE to that used
5438 if (!this->targ_
->has_glink())
5441 typedef typename
Plt_stub_entries::iterator plt_iter
;
5442 std::vector
<plt_iter
> calls
;
5443 if (!this->plt_call_stubs_
.empty())
5444 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5445 cs
!= this->plt_call_stubs_
.end();
5447 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5448 && cs
->second
.r2save_
5449 && !cs
->second
.localentry0_
)
5450 || (cs
->second
.notoc_
5451 && !this->targ_
->power10_stubs()))
5452 calls
.push_back(cs
);
5453 if (calls
.size() > 1)
5454 std::stable_sort(calls
.begin(), calls
.end(),
5455 stub_sort
<plt_iter
>);
5457 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5458 std::vector
<branch_iter
> branches
;
5459 if (!this->long_branch_stubs_
.empty()
5460 && !this->targ_
->power10_stubs())
5461 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5462 bs
!= this->long_branch_stubs_
.end();
5464 if (bs
->second
.notoc_
)
5465 branches
.push_back(bs
);
5466 if (branches
.size() > 1)
5467 std::stable_sort(branches
.begin(), branches
.end(),
5468 stub_sort
<branch_iter
>);
5470 if (calls
.empty() && branches
.empty())
5473 unsigned int last_eh_loc
= 0;
5474 // offset pcrel sdata4, size udata4, and augmentation size byte.
5475 std::vector
<unsigned char> fde(9, 0);
5477 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5479 plt_iter cs
= calls
[i
];
5480 unsigned int off
= cs
->second
.off_
;
5481 // The __tls_get_addr_opt call stub needs to describe where
5482 // it saves LR, to support exceptions that might be thrown
5483 // from __tls_get_addr, and to support asynchronous exceptions.
5484 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5487 if (cs
->second
.r2save_
5488 && !cs
->second
.localentry0_
)
5491 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5492 fde
.resize(fde
.size() + 6);
5493 unsigned char* p
= &*fde
.end() - 6;
5494 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5496 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5497 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5498 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5499 *p
++ = elfcpp::DW_CFA_restore_extended
;
5501 last_eh_loc
= off
+ delta
;
5505 // notoc stubs also should describe LR changes, to support
5506 // asynchronous exceptions.
5507 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5508 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5509 fde
.resize(fde
.size() + 6);
5510 unsigned char* p
= &*fde
.end() - 6;
5511 *p
++ = elfcpp::DW_CFA_register
;
5514 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5515 *p
++ = elfcpp::DW_CFA_restore_extended
;
5517 last_eh_loc
= off
+ 8;
5520 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5522 branch_iter bs
= branches
[i
];
5523 unsigned int off
= bs
->second
.off_
+ 8;
5524 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5525 fde
.resize(fde
.size() + 6);
5526 unsigned char* p
= &*fde
.end() - 6;
5527 *p
++ = elfcpp::DW_CFA_register
;
5530 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5531 *p
++ = elfcpp::DW_CFA_restore_extended
;
5533 last_eh_loc
= off
+ 8;
5536 layout
->add_eh_frame_for_plt(this,
5537 Eh_cie
<size
>::eh_frame_cie
,
5538 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5539 &*fde
.begin(), fde
.size());
5542 template<int size
, bool big_endian
>
5544 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5547 && parameters
->options().ld_generated_unwind_info()
5548 && this->targ_
->has_glink())
5549 layout
->remove_eh_frame_for_plt(this,
5550 Eh_cie
<size
>::eh_frame_cie
,
5551 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5554 // A class to handle .glink.
5556 template<int size
, bool big_endian
>
5557 class Output_data_glink
: public Output_section_data
5560 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5561 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5563 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5564 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5565 end_branch_table_(), ge_size_(0)
5569 add_eh_frame(Layout
* layout
);
5572 add_global_entry(const Symbol
*);
5575 find_global_entry(const Symbol
*) const;
5578 global_entry_align(unsigned int off
) const
5580 unsigned int align
= param_plt_align
<size
>();
5581 return (off
+ align
- 1) & -align
;
5585 global_entry_off() const
5587 return this->global_entry_align(this->end_branch_table_
);
5591 global_entry_address() const
5593 gold_assert(this->is_data_size_valid());
5594 return this->address() + this->global_entry_off();
5598 pltresolve_size() const
5602 + (this->targ_
->abiversion() < 2 ? 11 * 4
5603 : this->targ_
->has_localentry0() ? 14 * 4 : 13 * 4));
5608 // Write to a map file.
5610 do_print_to_mapfile(Mapfile
* mapfile
) const
5611 { mapfile
->print_output_data(this, _("** glink")); }
5615 set_final_data_size();
5619 do_write(Output_file
*);
5621 // Allows access to .got and .plt for do_write.
5622 Target_powerpc
<size
, big_endian
>* targ_
;
5624 // Map sym to stub offset.
5625 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5626 Global_entry_stub_entries global_entry_stubs_
;
5628 unsigned int end_branch_table_
, ge_size_
;
5631 template<int size
, bool big_endian
>
5633 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5635 if (!parameters
->options().ld_generated_unwind_info())
5640 if (this->targ_
->abiversion() < 2)
5641 layout
->add_eh_frame_for_plt(this,
5642 Eh_cie
<64>::eh_frame_cie
,
5643 sizeof (Eh_cie
<64>::eh_frame_cie
),
5644 glink_eh_frame_fde_64v1
,
5645 sizeof (glink_eh_frame_fde_64v1
));
5646 else if (this->targ_
->has_localentry0())
5647 layout
->add_eh_frame_for_plt(this,
5648 Eh_cie
<64>::eh_frame_cie
,
5649 sizeof (Eh_cie
<64>::eh_frame_cie
),
5650 glink_eh_frame_fde_64v2_localentry0
,
5651 sizeof (glink_eh_frame_fde_64v2
));
5653 layout
->add_eh_frame_for_plt(this,
5654 Eh_cie
<64>::eh_frame_cie
,
5655 sizeof (Eh_cie
<64>::eh_frame_cie
),
5656 glink_eh_frame_fde_64v2
,
5657 sizeof (glink_eh_frame_fde_64v2
));
5661 // 32-bit .glink can use the default since the CIE return
5662 // address reg, LR, is valid.
5663 layout
->add_eh_frame_for_plt(this,
5664 Eh_cie
<32>::eh_frame_cie
,
5665 sizeof (Eh_cie
<32>::eh_frame_cie
),
5667 sizeof (default_fde
));
5668 // Except where LR is used in a PIC __glink_PLTresolve.
5669 if (parameters
->options().output_is_position_independent())
5670 layout
->add_eh_frame_for_plt(this,
5671 Eh_cie
<32>::eh_frame_cie
,
5672 sizeof (Eh_cie
<32>::eh_frame_cie
),
5673 glink_eh_frame_fde_32
,
5674 sizeof (glink_eh_frame_fde_32
));
5678 template<int size
, bool big_endian
>
5680 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5682 unsigned int off
= this->global_entry_align(this->ge_size_
);
5683 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5684 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5686 this->ge_size_
= off
+ 16;
5689 template<int size
, bool big_endian
>
5690 typename Output_data_glink
<size
, big_endian
>::Address
5691 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5693 typename
Global_entry_stub_entries::const_iterator p
5694 = this->global_entry_stubs_
.find(gsym
);
5695 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5698 template<int size
, bool big_endian
>
5700 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5702 unsigned int count
= this->targ_
->plt_entry_count();
5703 section_size_type total
= 0;
5709 // space for branch table
5710 total
+= 4 * (count
- 1);
5712 total
+= -total
& 15;
5713 total
+= this->pltresolve_size();
5717 total
+= this->pltresolve_size();
5719 // space for branch table
5721 if (this->targ_
->abiversion() < 2)
5725 total
+= 4 * (count
- 0x8000);
5729 this->end_branch_table_
= total
;
5730 total
= this->global_entry_align(total
);
5731 total
+= this->ge_size_
;
5733 this->set_data_size(total
);
5736 // Define symbols on stubs, identifying the stub.
5738 template<int size
, bool big_endian
>
5740 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5742 if (!this->plt_call_stubs_
.empty())
5744 // The key for the plt call stub hash table includes addresses,
5745 // therefore traversal order depends on those addresses, which
5746 // can change between runs if gold is a PIE. Unfortunately the
5747 // output .symtab ordering depends on the order in which symbols
5748 // are added to the linker symtab. We want reproducible output
5749 // so must sort the call stub symbols.
5750 typedef typename
Plt_stub_entries::iterator plt_iter
;
5751 std::vector
<plt_iter
> sorted
;
5752 sorted
.resize(this->plt_call_stubs_
.size());
5754 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5755 cs
!= this->plt_call_stubs_
.end();
5757 sorted
[cs
->second
.indx_
] = cs
;
5759 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5761 plt_iter cs
= sorted
[i
];
5764 if (cs
->first
.addend_
!= 0)
5765 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5768 if (cs
->first
.object_
)
5770 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5771 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5772 sprintf(obj
, "%x:", ppcobj
->uniq());
5775 const char *symname
;
5776 if (cs
->first
.sym_
== NULL
)
5778 sprintf(localname
, "%x", cs
->first
.locsym_
);
5779 symname
= localname
;
5781 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5782 symname
= this->targ_
->tls_get_addr_opt()->name();
5784 symname
= cs
->first
.sym_
->name();
5785 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5786 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5788 = this->stub_address() - this->address() + cs
->second
.off_
;
5789 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5790 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5794 typedef typename
Branch_stub_entries::iterator branch_iter
;
5795 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5796 bs
!= this->long_branch_stubs_
.end();
5799 if (bs
->second
.save_res_
)
5802 char* name
= new char[8 + 13 + 16 + 1];
5803 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5804 static_cast<unsigned long long>(bs
->first
.dest_
));
5805 Address value
= (this->stub_address() - this->address()
5806 + this->plt_size_
+ bs
->second
.off_
);
5807 bool need_lt
= false;
5808 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5809 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5813 // Emit the start of a __tls_get_addr_opt plt call stub.
5815 template<int size
, bool big_endian
>
5817 Stub_table
<size
, big_endian
>::build_tls_opt_head(unsigned char** pp
,
5820 unsigned char* p
= *pp
;
5823 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5825 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5827 write_insn
<big_endian
>(p
, mr_0_3
);
5829 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5831 write_insn
<big_endian
>(p
, add_3_12_13
);
5833 write_insn
<big_endian
>(p
, beqlr
);
5835 write_insn
<big_endian
>(p
, mr_3_0
);
5839 write_insn
<big_endian
>(p
, mflr_11
);
5841 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5847 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5849 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5851 write_insn
<big_endian
>(p
, mr_0_3
);
5853 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5855 write_insn
<big_endian
>(p
, add_3_12_2
);
5857 write_insn
<big_endian
>(p
, beqlr
);
5859 write_insn
<big_endian
>(p
, mr_3_0
);
5861 write_insn
<big_endian
>(p
, nop
);
5867 // Emit the tail of a __tls_get_addr_opt plt call stub.
5869 template<int size
, bool big_endian
>
5871 Stub_table
<size
, big_endian
>::build_tls_opt_tail(unsigned char* p
)
5873 write_insn
<big_endian
>(p
, bctrl
);
5875 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5877 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5879 write_insn
<big_endian
>(p
, mtlr_11
);
5881 write_insn
<big_endian
>(p
, blr
);
5884 // Emit pc-relative plt call stub code.
5886 template<bool big_endian
>
5887 static unsigned char*
5888 build_power10_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5891 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5896 write_insn
<big_endian
>(p
, nop
);
5904 write_insn
<big_endian
>(p
, insn
>> 32);
5906 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5908 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5911 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5915 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5918 insn
= paddi_12_pc
| d34(off
);
5919 write_insn
<big_endian
>(p
, insn
>> 32);
5921 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5925 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5929 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5931 write_insn
<big_endian
>(p
, add_12_11_12
);
5936 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5938 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5942 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5945 insn
= paddi_12_pc
| d34(off
);
5946 write_insn
<big_endian
>(p
, insn
>> 32);
5948 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5952 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5956 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5958 write_insn
<big_endian
>(p
, add_12_11_12
);
5964 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5965 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5970 // lis %r12,xxx-1b@highest
5971 // ori %r12,%r12,xxx-1b@higher
5972 // sldi %r12,%r12,32
5973 // oris %r12,%r12,xxx-1b@high
5974 // ori %r12,%r12,xxx-1b@l
5975 // add/ldx %r12,%r11,%r12
5977 template<bool big_endian
>
5978 static unsigned char*
5979 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5981 write_insn
<big_endian
>(p
, mflr_12
);
5983 write_insn
<big_endian
>(p
, bcl_20_31
);
5985 write_insn
<big_endian
>(p
, mflr_11
);
5987 write_insn
<big_endian
>(p
, mtlr_12
);
5989 if (off
+ 0x8000 < 0x10000)
5992 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5994 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5996 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5998 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
6001 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6003 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
6007 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
6009 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
6014 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
6016 if (((off
>> 32) & 0xffff) != 0)
6018 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
6022 if (((off
>> 32) & 0xffffffffULL
) != 0)
6024 write_insn
<big_endian
>(p
, sldi_12_12_32
);
6029 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
6034 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
6038 write_insn
<big_endian
>(p
, ldx_12_11_12
);
6040 write_insn
<big_endian
>(p
, add_12_11_12
);
6046 // Size of a given plt call stub.
6048 template<int size
, bool big_endian
>
6050 Stub_table
<size
, big_endian
>::plt_call_size(
6051 typename
Plt_stub_entries::iterator p
) const
6055 const Symbol
* gsym
= p
->first
.sym_
;
6057 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
6060 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6061 uint64_t plt_addr
= this->plt_off(p
, &plt
);
6062 plt_addr
+= plt
->address();
6063 if (this->targ_
->power10_stubs()
6064 && this->targ_
->power10_stubs_auto())
6066 unsigned int bytes
= 0;
6067 if (p
->second
.notoc_
)
6069 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6071 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6072 uint64_t odd
= from
& 4;
6073 uint64_t off
= plt_addr
- from
;
6074 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6075 bytes
+= odd
+ 4 * 4;
6076 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6080 bytes
= this->plt_call_align(bytes
);
6082 unsigned int tail
= 0;
6085 p
->second
.tocoff_
= bytes
;
6086 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6089 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6095 if (p
->second
.r2save_
)
6098 = this->targ_
->got_section()->output_section()->address();
6099 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6100 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6101 got_addr
+= ppcobj
->toc_base_offset();
6102 uint64_t off
= plt_addr
- got_addr
;
6103 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6105 return bytes
+ tail
;
6109 unsigned int bytes
= 0;
6110 unsigned int tail
= 0;
6111 if (this->targ_
->is_tls_get_addr_opt(p
->first
.sym_
))
6114 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
6121 if (p
->second
.r2save_
)
6124 if (this->targ_
->power10_stubs())
6126 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
6127 uint64_t odd
= from
& 4;
6128 uint64_t off
= plt_addr
- from
;
6129 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6130 bytes
+= odd
+ 4 * 4;
6131 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6135 return bytes
+ tail
;
6138 if (p
->second
.notoc_
)
6140 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
6141 uint64_t off
= plt_addr
- from
;
6142 if (off
+ 0x8000 < 0x10000)
6144 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6149 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6150 && ((off
>> 32) & 0xffff) != 0)
6152 if (((off
>> 32) & 0xffffffffULL
) != 0)
6159 return bytes
+ tail
;
6162 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6163 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6164 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6165 got_addr
+= ppcobj
->toc_base_offset();
6166 uint64_t off
= plt_addr
- got_addr
;
6167 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6168 if (this->targ_
->abiversion() < 2)
6170 bool static_chain
= parameters
->options().plt_static_chain();
6171 bool thread_safe
= this->targ_
->plt_thread_safe();
6175 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6177 return bytes
+ tail
;
6181 // Return long branch stub size.
6183 template<int size
, bool big_endian
>
6185 Stub_table
<size
, big_endian
>::branch_stub_size(
6186 typename
Branch_stub_entries::iterator p
,
6189 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6192 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6194 if (parameters
->options().output_is_position_independent())
6199 uint64_t off
= p
->first
.dest_
- loc
;
6200 unsigned int bytes
= 0;
6201 if (p
->second
.notoc_
)
6203 if (this->targ_
->power10_stubs())
6205 Address odd
= loc
& 4;
6206 if (off
+ (1 << 25) < 2 << 25)
6208 else if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6210 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6214 if (!(p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6216 p
->second
.tocoff_
= bytes
;
6221 if (off
+ 0x8000 < 0x10000)
6223 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6225 if (off
+ 24 + (1 << 25) < 2 << 25)
6231 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6232 && ((off
>> 32) & 0xffff) != 0)
6234 if (((off
>> 32) & 0xffffffffULL
) != 0)
6244 off
+= elfcpp::ppc64_decode_local_entry(p
->second
.other_
);
6245 if (off
+ (1 << 25) < 2 << 25)
6247 if (!this->targ_
->power10_stubs()
6248 || (p
->second
.toc_
&& this->targ_
->power10_stubs_auto()))
6253 template<int size
, bool big_endian
>
6255 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6258 gold_error(_("linkage table error against `%s'"),
6259 p
.sym_
->demangled_name().c_str());
6261 gold_error(_("linkage table error against `%s:[local %u]'"),
6262 p
.object_
->name().c_str(),
6266 // Write out plt and long branch stub code.
6268 template<int size
, bool big_endian
>
6270 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6272 if (this->plt_call_stubs_
.empty()
6273 && this->long_branch_stubs_
.empty())
6276 const section_size_type start_off
= this->offset();
6277 const section_size_type off
= this->stub_offset();
6278 const section_size_type oview_size
=
6279 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6280 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6284 && this->targ_
->power10_stubs())
6286 const Output_data_got_powerpc
<size
, big_endian
>* got
6287 = this->targ_
->got_section();
6288 Address got_os_addr
= got
->output_section()->address();
6290 if (!this->plt_call_stubs_
.empty())
6292 // Write out plt call stubs.
6293 typename
Plt_stub_entries::const_iterator cs
;
6294 for (cs
= this->plt_call_stubs_
.begin();
6295 cs
!= this->plt_call_stubs_
.end();
6298 p
= oview
+ cs
->second
.off_
;
6299 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6300 Address pltoff
= this->plt_off(cs
, &plt
);
6301 Address plt_addr
= pltoff
+ plt
->address();
6302 if (this->targ_
->power10_stubs_auto())
6304 if (cs
->second
.notoc_
)
6306 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6307 this->build_tls_opt_head(&p
, false);
6308 Address from
= this->stub_address() + (p
- oview
);
6309 Address delta
= plt_addr
- from
;
6310 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4,
6312 write_insn
<big_endian
>(p
, mtctr_12
);
6314 write_insn
<big_endian
>(p
, bctr
);
6316 p
= oview
+ this->plt_call_align(p
- oview
);
6318 if (cs
->second
.toc_
)
6320 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6323 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6324 this->build_tls_opt_head(&p
, save_lr
);
6326 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6327 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(
6329 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6330 Address off
= plt_addr
- got_addr
;
6332 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6333 this->plt_error(cs
->first
);
6335 if (cs
->second
.r2save_
)
6337 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6342 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6344 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6349 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6352 write_insn
<big_endian
>(p
, mtctr_12
);
6354 if (cs
->second
.r2save_
6355 && !cs
->second
.localentry0_
6356 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6357 this->build_tls_opt_tail(p
);
6359 write_insn
<big_endian
>(p
, bctr
);
6364 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6367 = cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6368 this->build_tls_opt_head(&p
, save_lr
);
6370 if (cs
->second
.r2save_
)
6372 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6375 Address from
= this->stub_address() + (p
- oview
);
6376 Address delta
= plt_addr
- from
;
6377 p
= build_power10_offset
<big_endian
>(p
, delta
, from
& 4, true);
6378 write_insn
<big_endian
>(p
, mtctr_12
);
6380 if (cs
->second
.r2save_
6381 && !cs
->second
.localentry0_
6382 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6383 this->build_tls_opt_tail(p
);
6385 write_insn
<big_endian
>(p
, bctr
);
6390 // Write out long branch stubs.
6391 typename
Branch_stub_entries::const_iterator bs
;
6392 for (bs
= this->long_branch_stubs_
.begin();
6393 bs
!= this->long_branch_stubs_
.end();
6396 if (bs
->second
.save_res_
)
6398 Address off
= this->plt_size_
+ bs
->second
.off_
;
6400 Address loc
= this->stub_address() + off
;
6401 Address delta
= bs
->first
.dest_
- loc
;
6402 if (this->targ_
->power10_stubs_auto())
6404 if (bs
->second
.notoc_
)
6406 unsigned char* startp
= p
;
6407 p
= build_power10_offset
<big_endian
>(p
, delta
,
6409 delta
-= p
- startp
;
6411 if (delta
+ (1 << 25) < 2 << 25)
6412 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6415 write_insn
<big_endian
>(p
, mtctr_12
);
6417 write_insn
<big_endian
>(p
, bctr
);
6420 delta
-= p
- startp
;
6422 if (bs
->second
.toc_
)
6424 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6425 if (delta
+ (1 << 25) >= 2 << 25)
6428 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6429 gold_assert(brlt_addr
!= invalid_address
);
6430 brlt_addr
+= this->targ_
->brlt_section()->address();
6431 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6432 Address brltoff
= brlt_addr
- got_addr
;
6433 if (ha(brltoff
) == 0)
6435 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6440 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6442 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6446 if (delta
+ (1 << 25) < 2 << 25)
6447 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6450 write_insn
<big_endian
>(p
, mtctr_12
);
6452 write_insn
<big_endian
>(p
, bctr
);
6458 if (!bs
->second
.notoc_
)
6459 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6460 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6462 unsigned char* startp
= p
;
6463 p
= build_power10_offset
<big_endian
>(p
, delta
,
6465 delta
-= p
- startp
;
6467 if (delta
+ (1 << 25) < 2 << 25)
6468 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6471 write_insn
<big_endian
>(p
, mtctr_12
);
6473 write_insn
<big_endian
>(p
, bctr
);
6478 else if (size
== 64)
6480 const Output_data_got_powerpc
<size
, big_endian
>* got
6481 = this->targ_
->got_section();
6482 Address got_os_addr
= got
->output_section()->address();
6484 if (!this->plt_call_stubs_
.empty()
6485 && this->targ_
->abiversion() >= 2)
6487 // Write out plt call stubs for ELFv2.
6488 typename
Plt_stub_entries::const_iterator cs
;
6489 for (cs
= this->plt_call_stubs_
.begin();
6490 cs
!= this->plt_call_stubs_
.end();
6493 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6494 Address pltoff
= this->plt_off(cs
, &plt
);
6495 Address plt_addr
= pltoff
+ plt
->address();
6497 p
= oview
+ cs
->second
.off_
;
6498 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6500 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6501 this->build_tls_opt_head(&p
, save_lr
);
6503 if (cs
->second
.r2save_
)
6505 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6508 if (cs
->second
.notoc_
)
6510 Address from
= this->stub_address() + (p
- oview
) + 8;
6511 Address off
= plt_addr
- from
;
6512 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6516 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6517 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6518 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6519 Address off
= plt_addr
- got_addr
;
6521 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6522 this->plt_error(cs
->first
);
6526 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6528 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6533 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6537 write_insn
<big_endian
>(p
, mtctr_12
);
6539 if (cs
->second
.r2save_
6540 && !cs
->second
.localentry0_
6541 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6542 this->build_tls_opt_tail(p
);
6544 write_insn
<big_endian
>(p
, bctr
);
6547 else if (!this->plt_call_stubs_
.empty())
6549 // Write out plt call stubs for ELFv1.
6550 typename
Plt_stub_entries::const_iterator cs
;
6551 for (cs
= this->plt_call_stubs_
.begin();
6552 cs
!= this->plt_call_stubs_
.end();
6555 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6556 Address pltoff
= this->plt_off(cs
, &plt
);
6557 Address plt_addr
= pltoff
+ plt
->address();
6558 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6559 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6560 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6561 Address off
= plt_addr
- got_addr
;
6563 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6564 || cs
->second
.notoc_
)
6565 this->plt_error(cs
->first
);
6567 bool static_chain
= parameters
->options().plt_static_chain();
6568 bool thread_safe
= this->targ_
->plt_thread_safe();
6569 bool use_fake_dep
= false;
6570 Address cmp_branch_off
= 0;
6573 unsigned int pltindex
6574 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6575 / this->targ_
->plt_entry_size());
6577 = (this->targ_
->glink_section()->pltresolve_size()
6579 if (pltindex
> 32768)
6580 glinkoff
+= (pltindex
- 32768) * 4;
6582 = this->targ_
->glink_section()->address() + glinkoff
;
6584 = (this->stub_address() + cs
->second
.off_
+ 20
6585 + 4 * cs
->second
.r2save_
6586 + 4 * (ha(off
) != 0)
6587 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6588 + 4 * static_chain
);
6589 cmp_branch_off
= to
- from
;
6590 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6593 p
= oview
+ cs
->second
.off_
;
6594 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6596 bool save_lr
= cs
->second
.r2save_
&& !cs
->second
.localentry0_
;
6597 this->build_tls_opt_head(&p
, save_lr
);
6598 use_fake_dep
= thread_safe
;
6600 if (cs
->second
.r2save_
)
6602 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6607 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6609 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6611 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6613 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6617 write_insn
<big_endian
>(p
, mtctr_12
);
6621 write_insn
<big_endian
>(p
, xor_2_12_12
);
6623 write_insn
<big_endian
>(p
, add_11_11_2
);
6626 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6630 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6636 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6638 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6640 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6644 write_insn
<big_endian
>(p
, mtctr_12
);
6648 write_insn
<big_endian
>(p
, xor_11_12_12
);
6650 write_insn
<big_endian
>(p
, add_2_2_11
);
6655 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6658 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6661 if (cs
->second
.r2save_
6662 && !cs
->second
.localentry0_
6663 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6664 this->build_tls_opt_tail(p
);
6665 else if (thread_safe
&& !use_fake_dep
)
6667 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6669 write_insn
<big_endian
>(p
, bnectr_p4
);
6671 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6674 write_insn
<big_endian
>(p
, bctr
);
6678 // Write out long branch stubs.
6679 typename
Branch_stub_entries::const_iterator bs
;
6680 for (bs
= this->long_branch_stubs_
.begin();
6681 bs
!= this->long_branch_stubs_
.end();
6684 if (bs
->second
.save_res_
)
6686 Address off
= this->plt_size_
+ bs
->second
.off_
;
6688 Address loc
= this->stub_address() + off
;
6689 Address delta
= bs
->first
.dest_
- loc
;
6690 if (!bs
->second
.notoc_
)
6691 delta
+= elfcpp::ppc64_decode_local_entry(bs
->second
.other_
);
6692 if (bs
->second
.notoc_
)
6694 unsigned char* startp
= p
;
6695 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6696 delta
-= p
- startp
;
6698 else if (delta
+ (1 << 25) >= 2 << 25)
6701 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6702 gold_assert(brlt_addr
!= invalid_address
);
6703 brlt_addr
+= this->targ_
->brlt_section()->address();
6704 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6705 Address brltoff
= brlt_addr
- got_addr
;
6706 if (ha(brltoff
) == 0)
6708 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6713 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6715 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6719 if (delta
+ (1 << 25) < 2 << 25)
6720 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6723 write_insn
<big_endian
>(p
, mtctr_12
);
6725 write_insn
<big_endian
>(p
, bctr
);
6731 if (!this->plt_call_stubs_
.empty())
6733 // The address of _GLOBAL_OFFSET_TABLE_.
6734 Address g_o_t
= invalid_address
;
6736 // Write out plt call stubs.
6737 typename
Plt_stub_entries::const_iterator cs
;
6738 for (cs
= this->plt_call_stubs_
.begin();
6739 cs
!= this->plt_call_stubs_
.end();
6742 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6743 Address plt_addr
= this->plt_off(cs
, &plt
);
6744 plt_addr
+= plt
->address();
6746 p
= oview
+ cs
->second
.off_
;
6747 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
6748 this->build_tls_opt_head(&p
, false);
6749 if (parameters
->options().output_is_position_independent())
6752 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6753 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6754 (cs
->first
.object_
));
6755 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6757 unsigned int got2
= ppcobj
->got2_shndx();
6758 got_addr
= ppcobj
->get_output_section_offset(got2
);
6759 gold_assert(got_addr
!= invalid_address
);
6760 got_addr
+= (ppcobj
->output_section(got2
)->address()
6761 + cs
->first
.addend_
);
6765 if (g_o_t
== invalid_address
)
6767 const Output_data_got_powerpc
<size
, big_endian
>* got
6768 = this->targ_
->got_section();
6769 g_o_t
= got
->address() + got
->g_o_t();
6774 Address off
= plt_addr
- got_addr
;
6776 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6779 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6781 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6786 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6788 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6791 write_insn
<big_endian
>(p
, mtctr_11
);
6793 write_insn
<big_endian
>(p
, bctr
);
6797 // Write out long branch stubs.
6798 typename
Branch_stub_entries::const_iterator bs
;
6799 for (bs
= this->long_branch_stubs_
.begin();
6800 bs
!= this->long_branch_stubs_
.end();
6803 if (bs
->second
.save_res_
)
6805 Address off
= this->plt_size_
+ bs
->second
.off_
;
6807 Address loc
= this->stub_address() + off
;
6808 Address delta
= bs
->first
.dest_
- loc
;
6809 if (delta
+ (1 << 25) < 2 << 25)
6810 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6811 else if (!parameters
->options().output_is_position_independent())
6813 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6815 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6820 write_insn
<big_endian
>(p
, mflr_0
);
6822 write_insn
<big_endian
>(p
, bcl_20_31
);
6824 write_insn
<big_endian
>(p
, mflr_12
);
6826 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6828 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6830 write_insn
<big_endian
>(p
, mtlr_0
);
6833 write_insn
<big_endian
>(p
, mtctr_12
);
6835 write_insn
<big_endian
>(p
, bctr
);
6838 if (this->need_save_res_
)
6840 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6841 memcpy (p
, this->targ_
->savres_section()->contents(),
6842 this->targ_
->savres_section()->data_size());
6846 // Write out .glink.
6848 template<int size
, bool big_endian
>
6850 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6852 const section_size_type off
= this->offset();
6853 const section_size_type oview_size
=
6854 convert_to_section_size_type(this->data_size());
6855 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6858 // The base address of the .plt section.
6859 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6860 Address plt_base
= this->targ_
->plt_section()->address();
6864 if (this->end_branch_table_
!= 0)
6866 // Write pltresolve stub.
6868 Address after_bcl
= this->address() + 16;
6869 Address pltoff
= plt_base
- after_bcl
;
6871 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6873 if (this->targ_
->abiversion() < 2)
6875 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6876 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6877 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6878 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6879 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6880 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6881 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6882 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6883 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6884 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6888 if (this->targ_
->has_localentry0())
6890 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6892 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6893 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6894 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6895 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6896 if (this->targ_
->has_localentry0())
6898 write_insn
<big_endian
>(p
, ld_0_11
+ l(-20)), p
+= 4;
6902 write_insn
<big_endian
>(p
, ld_0_11
+ l(-16)), p
+= 4;
6904 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6905 write_insn
<big_endian
>(p
, add_11_0_11
), p
+= 4;
6906 write_insn
<big_endian
>(p
, addi_0_12
+ l(-44)), p
+= 4;
6907 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6908 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6909 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6910 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6912 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6913 gold_assert(p
== oview
+ this->pltresolve_size());
6915 // Write lazy link call stubs.
6917 while (p
< oview
+ this->end_branch_table_
)
6919 if (this->targ_
->abiversion() < 2)
6923 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6927 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6928 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6931 uint32_t branch_off
= 8 - (p
- oview
);
6932 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6937 Address plt_base
= this->targ_
->plt_section()->address();
6938 Address iplt_base
= invalid_address
;
6939 unsigned int global_entry_off
= this->global_entry_off();
6940 Address global_entry_base
= this->address() + global_entry_off
;
6941 typename
Global_entry_stub_entries::const_iterator ge
;
6942 for (ge
= this->global_entry_stubs_
.begin();
6943 ge
!= this->global_entry_stubs_
.end();
6946 p
= oview
+ global_entry_off
+ ge
->second
;
6947 Address plt_addr
= ge
->first
->plt_offset();
6948 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6949 && ge
->first
->can_use_relative_reloc(false))
6951 if (iplt_base
== invalid_address
)
6952 iplt_base
= this->targ_
->iplt_section()->address();
6953 plt_addr
+= iplt_base
;
6956 plt_addr
+= plt_base
;
6957 Address my_addr
= global_entry_base
+ ge
->second
;
6958 Address off
= plt_addr
- my_addr
;
6960 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6961 gold_error(_("linkage table error against `%s'"),
6962 ge
->first
->demangled_name().c_str());
6964 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6965 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6966 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6967 write_insn
<big_endian
>(p
, bctr
);
6972 const Output_data_got_powerpc
<size
, big_endian
>* got
6973 = this->targ_
->got_section();
6974 // The address of _GLOBAL_OFFSET_TABLE_.
6975 Address g_o_t
= got
->address() + got
->g_o_t();
6977 // Write out pltresolve branch table.
6979 unsigned int the_end
= oview_size
- this->pltresolve_size();
6980 unsigned char* end_p
= oview
+ the_end
;
6981 while (p
< end_p
- 8 * 4)
6982 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6984 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6986 // Write out pltresolve call stub.
6987 end_p
= oview
+ oview_size
;
6988 if (parameters
->options().output_is_position_independent())
6990 Address res0_off
= 0;
6991 Address after_bcl_off
= the_end
+ 12;
6992 Address bcl_res0
= after_bcl_off
- res0_off
;
6994 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6996 write_insn
<big_endian
>(p
, mflr_0
);
6998 write_insn
<big_endian
>(p
, bcl_20_31
);
7000 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
7002 write_insn
<big_endian
>(p
, mflr_12
);
7004 write_insn
<big_endian
>(p
, mtlr_0
);
7006 write_insn
<big_endian
>(p
, sub_11_11_12
);
7009 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
7011 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
7013 if (ha(got_bcl
) == ha(got_bcl
+ 4))
7015 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
7017 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
7021 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
7023 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7026 write_insn
<big_endian
>(p
, mtctr_0
);
7028 write_insn
<big_endian
>(p
, add_0_11_11
);
7030 write_insn
<big_endian
>(p
, add_11_0_11
);
7034 Address res0
= this->address();
7036 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
7038 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
7040 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7041 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
7043 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
7045 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
7047 write_insn
<big_endian
>(p
, mtctr_0
);
7049 write_insn
<big_endian
>(p
, add_0_11_11
);
7051 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
7052 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
7054 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
7056 write_insn
<big_endian
>(p
, add_11_0_11
);
7059 write_insn
<big_endian
>(p
, bctr
);
7063 write_insn
<big_endian
>(p
, nop
);
7068 of
->write_output_view(off
, oview_size
, oview
);
7072 // A class to handle linker generated save/restore functions.
7074 template<int size
, bool big_endian
>
7075 class Output_data_save_res
: public Output_section_data_build
7078 Output_data_save_res(Symbol_table
* symtab
);
7080 const unsigned char*
7087 // Write to a map file.
7089 do_print_to_mapfile(Mapfile
* mapfile
) const
7090 { mapfile
->print_output_data(this, _("** save/restore")); }
7093 do_write(Output_file
*);
7096 // The maximum size of save/restore contents.
7097 static const unsigned int savres_max
= 218*4;
7100 savres_define(Symbol_table
* symtab
,
7102 unsigned int lo
, unsigned int hi
,
7103 unsigned char* write_ent(unsigned char*, int),
7104 unsigned char* write_tail(unsigned char*, int));
7106 unsigned char *contents_
;
7109 template<bool big_endian
>
7110 static unsigned char*
7111 savegpr0(unsigned char* p
, int r
)
7113 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7114 write_insn
<big_endian
>(p
, insn
);
7118 template<bool big_endian
>
7119 static unsigned char*
7120 savegpr0_tail(unsigned char* p
, int r
)
7122 p
= savegpr0
<big_endian
>(p
, r
);
7123 uint32_t insn
= std_0_1
+ 16;
7124 write_insn
<big_endian
>(p
, insn
);
7126 write_insn
<big_endian
>(p
, blr
);
7130 template<bool big_endian
>
7131 static unsigned char*
7132 restgpr0(unsigned char* p
, int r
)
7134 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7135 write_insn
<big_endian
>(p
, insn
);
7139 template<bool big_endian
>
7140 static unsigned char*
7141 restgpr0_tail(unsigned char* p
, int r
)
7143 uint32_t insn
= ld_0_1
+ 16;
7144 write_insn
<big_endian
>(p
, insn
);
7146 p
= restgpr0
<big_endian
>(p
, r
);
7147 write_insn
<big_endian
>(p
, mtlr_0
);
7151 p
= restgpr0
<big_endian
>(p
, 30);
7152 p
= restgpr0
<big_endian
>(p
, 31);
7154 write_insn
<big_endian
>(p
, blr
);
7158 template<bool big_endian
>
7159 static unsigned char*
7160 savegpr1(unsigned char* p
, int r
)
7162 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7163 write_insn
<big_endian
>(p
, insn
);
7167 template<bool big_endian
>
7168 static unsigned char*
7169 savegpr1_tail(unsigned char* p
, int r
)
7171 p
= savegpr1
<big_endian
>(p
, r
);
7172 write_insn
<big_endian
>(p
, blr
);
7176 template<bool big_endian
>
7177 static unsigned char*
7178 restgpr1(unsigned char* p
, int r
)
7180 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7181 write_insn
<big_endian
>(p
, insn
);
7185 template<bool big_endian
>
7186 static unsigned char*
7187 restgpr1_tail(unsigned char* p
, int r
)
7189 p
= restgpr1
<big_endian
>(p
, r
);
7190 write_insn
<big_endian
>(p
, blr
);
7194 template<bool big_endian
>
7195 static unsigned char*
7196 savefpr(unsigned char* p
, int r
)
7198 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7199 write_insn
<big_endian
>(p
, insn
);
7203 template<bool big_endian
>
7204 static unsigned char*
7205 savefpr0_tail(unsigned char* p
, int r
)
7207 p
= savefpr
<big_endian
>(p
, r
);
7208 write_insn
<big_endian
>(p
, std_0_1
+ 16);
7210 write_insn
<big_endian
>(p
, blr
);
7214 template<bool big_endian
>
7215 static unsigned char*
7216 restfpr(unsigned char* p
, int r
)
7218 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
7219 write_insn
<big_endian
>(p
, insn
);
7223 template<bool big_endian
>
7224 static unsigned char*
7225 restfpr0_tail(unsigned char* p
, int r
)
7227 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
7229 p
= restfpr
<big_endian
>(p
, r
);
7230 write_insn
<big_endian
>(p
, mtlr_0
);
7234 p
= restfpr
<big_endian
>(p
, 30);
7235 p
= restfpr
<big_endian
>(p
, 31);
7237 write_insn
<big_endian
>(p
, blr
);
7241 template<bool big_endian
>
7242 static unsigned char*
7243 savefpr1_tail(unsigned char* p
, int r
)
7245 p
= savefpr
<big_endian
>(p
, r
);
7246 write_insn
<big_endian
>(p
, blr
);
7250 template<bool big_endian
>
7251 static unsigned char*
7252 restfpr1_tail(unsigned char* p
, int r
)
7254 p
= restfpr
<big_endian
>(p
, r
);
7255 write_insn
<big_endian
>(p
, blr
);
7259 template<bool big_endian
>
7260 static unsigned char*
7261 savevr(unsigned char* p
, int r
)
7263 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7264 write_insn
<big_endian
>(p
, insn
);
7266 insn
= stvx_0_12_0
+ (r
<< 21);
7267 write_insn
<big_endian
>(p
, insn
);
7271 template<bool big_endian
>
7272 static unsigned char*
7273 savevr_tail(unsigned char* p
, int r
)
7275 p
= savevr
<big_endian
>(p
, r
);
7276 write_insn
<big_endian
>(p
, blr
);
7280 template<bool big_endian
>
7281 static unsigned char*
7282 restvr(unsigned char* p
, int r
)
7284 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
7285 write_insn
<big_endian
>(p
, insn
);
7287 insn
= lvx_0_12_0
+ (r
<< 21);
7288 write_insn
<big_endian
>(p
, insn
);
7292 template<bool big_endian
>
7293 static unsigned char*
7294 restvr_tail(unsigned char* p
, int r
)
7296 p
= restvr
<big_endian
>(p
, r
);
7297 write_insn
<big_endian
>(p
, blr
);
7302 template<int size
, bool big_endian
>
7303 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
7304 Symbol_table
* symtab
)
7305 : Output_section_data_build(4),
7308 this->savres_define(symtab
,
7309 "_savegpr0_", 14, 31,
7310 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
7311 this->savres_define(symtab
,
7312 "_restgpr0_", 14, 29,
7313 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7314 this->savres_define(symtab
,
7315 "_restgpr0_", 30, 31,
7316 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
7317 this->savres_define(symtab
,
7318 "_savegpr1_", 14, 31,
7319 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
7320 this->savres_define(symtab
,
7321 "_restgpr1_", 14, 31,
7322 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
7323 this->savres_define(symtab
,
7324 "_savefpr_", 14, 31,
7325 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
7326 this->savres_define(symtab
,
7327 "_restfpr_", 14, 29,
7328 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7329 this->savres_define(symtab
,
7330 "_restfpr_", 30, 31,
7331 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7332 this->savres_define(symtab
,
7334 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7335 this->savres_define(symtab
,
7337 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7338 this->savres_define(symtab
,
7340 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7341 this->savres_define(symtab
,
7343 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7346 template<int size
, bool big_endian
>
7348 Output_data_save_res
<size
, big_endian
>::savres_define(
7349 Symbol_table
* symtab
,
7351 unsigned int lo
, unsigned int hi
,
7352 unsigned char* write_ent(unsigned char*, int),
7353 unsigned char* write_tail(unsigned char*, int))
7355 size_t len
= strlen(name
);
7356 bool writing
= false;
7359 memcpy(sym
, name
, len
);
7362 for (unsigned int i
= lo
; i
<= hi
; i
++)
7364 sym
[len
+ 0] = i
/ 10 + '0';
7365 sym
[len
+ 1] = i
% 10 + '0';
7366 Symbol
* gsym
= symtab
->lookup(sym
);
7367 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7368 writing
= writing
|| refd
;
7371 if (this->contents_
== NULL
)
7372 this->contents_
= new unsigned char[this->savres_max
];
7374 section_size_type value
= this->current_data_size();
7375 unsigned char* p
= this->contents_
+ value
;
7377 p
= write_ent(p
, i
);
7379 p
= write_tail(p
, i
);
7380 section_size_type cur_size
= p
- this->contents_
;
7381 this->set_current_data_size(cur_size
);
7383 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7384 this, value
, cur_size
- value
,
7385 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7386 elfcpp::STV_HIDDEN
, 0, false, false);
7391 // Write out save/restore.
7393 template<int size
, bool big_endian
>
7395 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7397 const section_size_type off
= this->offset();
7398 const section_size_type oview_size
=
7399 convert_to_section_size_type(this->data_size());
7400 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7401 memcpy(oview
, this->contents_
, oview_size
);
7402 of
->write_output_view(off
, oview_size
, oview
);
7406 // Create the glink section.
7408 template<int size
, bool big_endian
>
7410 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7412 if (this->glink_
== NULL
)
7414 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7415 this->glink_
->add_eh_frame(layout
);
7416 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7417 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7418 this->glink_
, ORDER_TEXT
, false);
7422 // Create a PLT entry for a global symbol.
7424 template<int size
, bool big_endian
>
7426 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7430 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7431 && gsym
->can_use_relative_reloc(false))
7433 if (this->iplt_
== NULL
)
7434 this->make_iplt_section(symtab
, layout
);
7435 this->iplt_
->add_ifunc_entry(gsym
);
7439 if (this->plt_
== NULL
)
7440 this->make_plt_section(symtab
, layout
);
7441 this->plt_
->add_entry(gsym
);
7445 // Make a PLT entry for a local symbol.
7447 template<int size
, bool big_endian
>
7449 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7451 Sized_relobj_file
<size
, big_endian
>* relobj
,
7454 if (this->lplt_
== NULL
)
7455 this->make_lplt_section(layout
);
7456 this->lplt_
->add_local_entry(relobj
, r_sym
);
7459 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7461 template<int size
, bool big_endian
>
7463 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7464 Symbol_table
* symtab
,
7466 Sized_relobj_file
<size
, big_endian
>* relobj
,
7469 if (this->iplt_
== NULL
)
7470 this->make_iplt_section(symtab
, layout
);
7471 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7474 // Return the number of entries in the PLT.
7476 template<int size
, bool big_endian
>
7478 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7480 if (this->plt_
== NULL
)
7482 return this->plt_
->entry_count();
7485 // Create a GOT entry for local dynamic __tls_get_addr calls.
7487 template<int size
, bool big_endian
>
7489 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7490 Symbol_table
* symtab
,
7492 Sized_relobj_file
<size
, big_endian
>* object
)
7494 if (this->tlsld_got_offset_
== -1U)
7496 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7497 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7498 Output_data_got_powerpc
<size
, big_endian
>* got
7499 = this->got_section(symtab
, layout
);
7500 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7501 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7503 this->tlsld_got_offset_
= got_offset
;
7505 return this->tlsld_got_offset_
;
7508 // Get the Reference_flags for a particular relocation.
7510 template<int size
, bool big_endian
>
7512 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7513 unsigned int r_type
,
7514 const Target_powerpc
* target
)
7520 case elfcpp::R_POWERPC_NONE
:
7521 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7522 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7523 case elfcpp::R_PPC64_TOC
:
7524 // No symbol reference.
7527 case elfcpp::R_PPC64_ADDR64
:
7528 case elfcpp::R_PPC64_UADDR64
:
7529 case elfcpp::R_POWERPC_ADDR32
:
7530 case elfcpp::R_POWERPC_UADDR32
:
7531 case elfcpp::R_POWERPC_ADDR16
:
7532 case elfcpp::R_POWERPC_UADDR16
:
7533 case elfcpp::R_POWERPC_ADDR16_LO
:
7534 case elfcpp::R_POWERPC_ADDR16_HI
:
7535 case elfcpp::R_POWERPC_ADDR16_HA
:
7536 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7537 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7538 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7539 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7540 case elfcpp::R_PPC64_D34
:
7541 case elfcpp::R_PPC64_D34_LO
:
7542 case elfcpp::R_PPC64_D34_HI30
:
7543 case elfcpp::R_PPC64_D34_HA30
:
7544 case elfcpp::R_PPC64_D28
:
7545 ref
= Symbol::ABSOLUTE_REF
;
7548 case elfcpp::R_POWERPC_ADDR24
:
7549 case elfcpp::R_POWERPC_ADDR14
:
7550 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7551 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7552 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7555 case elfcpp::R_PPC64_REL64
:
7556 case elfcpp::R_POWERPC_REL32
:
7557 case elfcpp::R_PPC_LOCAL24PC
:
7558 case elfcpp::R_POWERPC_REL16
:
7559 case elfcpp::R_POWERPC_REL16_LO
:
7560 case elfcpp::R_POWERPC_REL16_HI
:
7561 case elfcpp::R_POWERPC_REL16_HA
:
7562 case elfcpp::R_PPC64_REL16_HIGH
:
7563 case elfcpp::R_PPC64_REL16_HIGHA
:
7564 case elfcpp::R_PPC64_REL16_HIGHER
:
7565 case elfcpp::R_PPC64_REL16_HIGHERA
:
7566 case elfcpp::R_PPC64_REL16_HIGHEST
:
7567 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7568 case elfcpp::R_PPC64_PCREL34
:
7569 case elfcpp::R_PPC64_REL16_HIGHER34
:
7570 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7571 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7572 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7573 case elfcpp::R_PPC64_PCREL28
:
7574 ref
= Symbol::RELATIVE_REF
;
7577 case elfcpp::R_PPC64_REL24_NOTOC
:
7581 case elfcpp::R_POWERPC_REL24
:
7582 case elfcpp::R_PPC_PLTREL24
:
7583 case elfcpp::R_POWERPC_REL14
:
7584 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7585 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7586 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7589 case elfcpp::R_POWERPC_GOT16
:
7590 case elfcpp::R_POWERPC_GOT16_LO
:
7591 case elfcpp::R_POWERPC_GOT16_HI
:
7592 case elfcpp::R_POWERPC_GOT16_HA
:
7593 case elfcpp::R_PPC64_GOT16_DS
:
7594 case elfcpp::R_PPC64_GOT16_LO_DS
:
7595 case elfcpp::R_PPC64_GOT_PCREL34
:
7596 case elfcpp::R_PPC64_TOC16
:
7597 case elfcpp::R_PPC64_TOC16_LO
:
7598 case elfcpp::R_PPC64_TOC16_HI
:
7599 case elfcpp::R_PPC64_TOC16_HA
:
7600 case elfcpp::R_PPC64_TOC16_DS
:
7601 case elfcpp::R_PPC64_TOC16_LO_DS
:
7602 case elfcpp::R_POWERPC_PLT16_LO
:
7603 case elfcpp::R_POWERPC_PLT16_HI
:
7604 case elfcpp::R_POWERPC_PLT16_HA
:
7605 case elfcpp::R_PPC64_PLT16_LO_DS
:
7606 case elfcpp::R_PPC64_PLT_PCREL34
:
7607 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7608 ref
= Symbol::RELATIVE_REF
;
7611 case elfcpp::R_POWERPC_GOT_TPREL16
:
7612 case elfcpp::R_POWERPC_TLS
:
7613 case elfcpp::R_PPC64_TLSGD
:
7614 case elfcpp::R_PPC64_TLSLD
:
7615 case elfcpp::R_PPC64_TPREL34
:
7616 case elfcpp::R_PPC64_DTPREL34
:
7617 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
7618 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
7619 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
7620 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
7621 ref
= Symbol::TLS_REF
;
7624 case elfcpp::R_POWERPC_COPY
:
7625 case elfcpp::R_POWERPC_GLOB_DAT
:
7626 case elfcpp::R_POWERPC_JMP_SLOT
:
7627 case elfcpp::R_POWERPC_RELATIVE
:
7628 case elfcpp::R_POWERPC_DTPMOD
:
7630 // Not expected. We will give an error later.
7634 if (size
== 64 && target
->abiversion() < 2)
7635 ref
|= Symbol::FUNC_DESC_ABI
;
7639 // Report an unsupported relocation against a local symbol.
7641 template<int size
, bool big_endian
>
7643 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7644 Sized_relobj_file
<size
, big_endian
>* object
,
7645 unsigned int r_type
)
7647 gold_error(_("%s: unsupported reloc %u against local symbol"),
7648 object
->name().c_str(), r_type
);
7651 // We are about to emit a dynamic relocation of type R_TYPE. If the
7652 // dynamic linker does not support it, issue an error.
7654 template<int size
, bool big_endian
>
7656 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7657 unsigned int r_type
)
7659 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7661 // These are the relocation types supported by glibc for both 32-bit
7662 // and 64-bit powerpc.
7665 case elfcpp::R_POWERPC_NONE
:
7666 case elfcpp::R_POWERPC_RELATIVE
:
7667 case elfcpp::R_POWERPC_GLOB_DAT
:
7668 case elfcpp::R_POWERPC_DTPMOD
:
7669 case elfcpp::R_POWERPC_DTPREL
:
7670 case elfcpp::R_POWERPC_TPREL
:
7671 case elfcpp::R_POWERPC_JMP_SLOT
:
7672 case elfcpp::R_POWERPC_COPY
:
7673 case elfcpp::R_POWERPC_IRELATIVE
:
7674 case elfcpp::R_POWERPC_ADDR32
:
7675 case elfcpp::R_POWERPC_UADDR32
:
7676 case elfcpp::R_POWERPC_ADDR24
:
7677 case elfcpp::R_POWERPC_ADDR16
:
7678 case elfcpp::R_POWERPC_UADDR16
:
7679 case elfcpp::R_POWERPC_ADDR16_LO
:
7680 case elfcpp::R_POWERPC_ADDR16_HI
:
7681 case elfcpp::R_POWERPC_ADDR16_HA
:
7682 case elfcpp::R_POWERPC_ADDR14
:
7683 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7684 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7685 case elfcpp::R_POWERPC_REL32
:
7686 case elfcpp::R_POWERPC_TPREL16
:
7687 case elfcpp::R_POWERPC_TPREL16_LO
:
7688 case elfcpp::R_POWERPC_TPREL16_HI
:
7689 case elfcpp::R_POWERPC_TPREL16_HA
:
7700 // These are the relocation types supported only on 64-bit.
7701 case elfcpp::R_PPC64_ADDR64
:
7702 case elfcpp::R_PPC64_UADDR64
:
7703 case elfcpp::R_PPC64_JMP_IREL
:
7704 case elfcpp::R_PPC64_ADDR16_DS
:
7705 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7706 case elfcpp::R_PPC64_ADDR16_HIGH
:
7707 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7708 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7709 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7710 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7711 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7712 case elfcpp::R_PPC64_REL64
:
7713 case elfcpp::R_POWERPC_ADDR30
:
7714 case elfcpp::R_PPC64_TPREL16_DS
:
7715 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7716 case elfcpp::R_PPC64_TPREL16_HIGH
:
7717 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7718 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7719 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7720 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7721 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7732 // These are the relocation types supported only on 32-bit.
7733 // ??? glibc ld.so doesn't need to support these.
7734 case elfcpp::R_POWERPC_REL24
:
7735 case elfcpp::R_POWERPC_DTPREL16
:
7736 case elfcpp::R_POWERPC_DTPREL16_LO
:
7737 case elfcpp::R_POWERPC_DTPREL16_HI
:
7738 case elfcpp::R_POWERPC_DTPREL16_HA
:
7746 // This prevents us from issuing more than one error per reloc
7747 // section. But we can still wind up issuing more than one
7748 // error per object file.
7749 if (this->issued_non_pic_error_
)
7751 gold_assert(parameters
->options().output_is_position_independent());
7752 object
->error(_("requires unsupported dynamic reloc; "
7753 "recompile with -fPIC"));
7754 this->issued_non_pic_error_
= true;
7758 // Return whether we need to make a PLT entry for a relocation of the
7759 // given type against a STT_GNU_IFUNC symbol.
7761 template<int size
, bool big_endian
>
7763 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7764 Target_powerpc
<size
, big_endian
>* target
,
7765 Sized_relobj_file
<size
, big_endian
>* object
,
7766 unsigned int r_type
,
7769 // In non-pic code any reference will resolve to the plt call stub
7770 // for the ifunc symbol.
7771 if ((size
== 32 || target
->abiversion() >= 2)
7772 && !parameters
->options().output_is_position_independent())
7777 // Word size refs from data sections are OK, but don't need a PLT entry.
7778 case elfcpp::R_POWERPC_ADDR32
:
7779 case elfcpp::R_POWERPC_UADDR32
:
7784 case elfcpp::R_PPC64_ADDR64
:
7785 case elfcpp::R_PPC64_UADDR64
:
7790 // GOT refs are good, but also don't need a PLT entry.
7791 case elfcpp::R_POWERPC_GOT16
:
7792 case elfcpp::R_POWERPC_GOT16_LO
:
7793 case elfcpp::R_POWERPC_GOT16_HI
:
7794 case elfcpp::R_POWERPC_GOT16_HA
:
7795 case elfcpp::R_PPC64_GOT16_DS
:
7796 case elfcpp::R_PPC64_GOT16_LO_DS
:
7797 case elfcpp::R_PPC64_GOT_PCREL34
:
7800 // PLT relocs are OK and need a PLT entry.
7801 case elfcpp::R_POWERPC_PLT16_LO
:
7802 case elfcpp::R_POWERPC_PLT16_HI
:
7803 case elfcpp::R_POWERPC_PLT16_HA
:
7804 case elfcpp::R_PPC64_PLT16_LO_DS
:
7805 case elfcpp::R_POWERPC_PLTSEQ
:
7806 case elfcpp::R_POWERPC_PLTCALL
:
7807 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7808 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7809 case elfcpp::R_PPC64_PLT_PCREL34
:
7810 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7814 // Function calls are good, and these do need a PLT entry.
7815 case elfcpp::R_PPC64_REL24_NOTOC
:
7819 case elfcpp::R_POWERPC_ADDR24
:
7820 case elfcpp::R_POWERPC_ADDR14
:
7821 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7822 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7823 case elfcpp::R_POWERPC_REL24
:
7824 case elfcpp::R_PPC_PLTREL24
:
7825 case elfcpp::R_POWERPC_REL14
:
7826 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7827 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7834 // Anything else is a problem.
7835 // If we are building a static executable, the libc startup function
7836 // responsible for applying indirect function relocations is going
7837 // to complain about the reloc type.
7838 // If we are building a dynamic executable, we will have a text
7839 // relocation. The dynamic loader will set the text segment
7840 // writable and non-executable to apply text relocations. So we'll
7841 // segfault when trying to run the indirection function to resolve
7844 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7845 object
->name().c_str(), r_type
);
7849 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7853 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7855 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7856 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7857 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7858 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7859 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7860 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7861 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7862 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7863 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7864 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7865 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7866 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7867 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7868 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7869 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7870 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7871 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7872 /* Exclude lfqu by testing reloc. If relocs are ever
7873 defined for the reduced D field in psq_lu then those
7874 will need testing too. */
7875 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7876 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7877 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7879 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7880 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7881 /* Exclude stfqu. psq_stu as above for psq_lu. */
7882 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7883 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7884 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7885 && (insn
& 1) == 0));
7888 // Scan a relocation for a local symbol.
7890 template<int size
, bool big_endian
>
7892 Target_powerpc
<size
, big_endian
>::Scan::local(
7893 Symbol_table
* symtab
,
7895 Target_powerpc
<size
, big_endian
>* target
,
7896 Sized_relobj_file
<size
, big_endian
>* object
,
7897 unsigned int data_shndx
,
7898 Output_section
* output_section
,
7899 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7900 unsigned int r_type
,
7901 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7904 Powerpc_relobj
<size
, big_endian
>* ppc_object
7905 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7907 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
))
7909 case Track_tls::NOT_EXPECTED
:
7910 ppc_object
->set_no_tls_marker();
7916 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7917 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7919 this->expect_tls_get_addr_call();
7920 if (!ppc_object
->no_tls_marker())
7922 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7923 if (tls_type
!= tls::TLSOPT_NONE
)
7925 this->skip_next_tls_get_addr_call();
7926 ppc_object
->set_tls_marker();
7930 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7931 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7933 this->expect_tls_get_addr_call();
7934 if (!ppc_object
->no_tls_marker())
7936 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7937 if (tls_type
!= tls::TLSOPT_NONE
)
7939 this->skip_next_tls_get_addr_call();
7940 ppc_object
->set_tls_marker();
7948 && data_shndx
== ppc_object
->opd_shndx()
7949 && r_type
== elfcpp::R_PPC64_ADDR64
)
7950 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7954 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7955 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7956 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7958 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7959 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7960 r_type
, r_sym
, reloc
.get_r_addend());
7961 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7966 case elfcpp::R_POWERPC_NONE
:
7967 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7968 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7969 case elfcpp::R_POWERPC_TLS
:
7970 case elfcpp::R_PPC64_ENTRY
:
7971 case elfcpp::R_POWERPC_PLTSEQ
:
7972 case elfcpp::R_POWERPC_PLTCALL
:
7973 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7974 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7975 case elfcpp::R_PPC64_PCREL_OPT
:
7976 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7977 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7978 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7979 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7980 case elfcpp::R_PPC64_REL16_HIGHER34
:
7981 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7982 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7983 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7984 case elfcpp::R_PPC64_D34
:
7985 case elfcpp::R_PPC64_D34_LO
:
7986 case elfcpp::R_PPC64_D34_HI30
:
7987 case elfcpp::R_PPC64_D34_HA30
:
7988 case elfcpp::R_PPC64_D28
:
7989 case elfcpp::R_PPC64_PCREL34
:
7990 case elfcpp::R_PPC64_PCREL28
:
7991 case elfcpp::R_PPC64_TPREL34
:
7992 case elfcpp::R_PPC64_DTPREL34
:
7995 case elfcpp::R_PPC64_TOC
:
7997 Output_data_got_powerpc
<size
, big_endian
>* got
7998 = target
->got_section(symtab
, layout
);
7999 if (parameters
->options().output_is_position_independent())
8001 Address off
= reloc
.get_r_offset();
8003 && target
->abiversion() < 2
8004 && data_shndx
== ppc_object
->opd_shndx()
8005 && ppc_object
->get_opd_discard(off
- 8))
8008 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8009 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8010 rela_dyn
->add_output_section_relative(got
->output_section(),
8011 elfcpp::R_POWERPC_RELATIVE
,
8013 object
, data_shndx
, off
,
8014 symobj
->toc_base_offset());
8019 case elfcpp::R_PPC64_ADDR64
:
8020 case elfcpp::R_PPC64_UADDR64
:
8021 case elfcpp::R_POWERPC_ADDR32
:
8022 case elfcpp::R_POWERPC_UADDR32
:
8023 case elfcpp::R_POWERPC_ADDR24
:
8024 case elfcpp::R_POWERPC_ADDR16
:
8025 case elfcpp::R_POWERPC_ADDR16_LO
:
8026 case elfcpp::R_POWERPC_ADDR16_HI
:
8027 case elfcpp::R_POWERPC_ADDR16_HA
:
8028 case elfcpp::R_POWERPC_UADDR16
:
8029 case elfcpp::R_PPC64_ADDR16_HIGH
:
8030 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8031 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8032 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8033 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8034 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8035 case elfcpp::R_PPC64_ADDR16_DS
:
8036 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8037 case elfcpp::R_POWERPC_ADDR14
:
8038 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8039 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8040 // If building a shared library (or a position-independent
8041 // executable), we need to create a dynamic relocation for
8043 if (parameters
->options().output_is_position_independent()
8044 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8046 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8048 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8049 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8050 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
8052 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8053 : elfcpp::R_POWERPC_RELATIVE
);
8054 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8055 output_section
, data_shndx
,
8056 reloc
.get_r_offset(),
8057 reloc
.get_r_addend(), false);
8059 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
8061 check_non_pic(object
, r_type
);
8062 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
8063 data_shndx
, reloc
.get_r_offset(),
8064 reloc
.get_r_addend());
8068 gold_assert(lsym
.get_st_value() == 0);
8069 unsigned int shndx
= lsym
.get_st_shndx();
8071 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
8074 object
->error(_("section symbol %u has bad shndx %u"),
8077 rela_dyn
->add_local_section(object
, shndx
, r_type
,
8078 output_section
, data_shndx
,
8079 reloc
.get_r_offset());
8084 case elfcpp::R_PPC64_PLT_PCREL34
:
8085 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8086 case elfcpp::R_POWERPC_PLT16_LO
:
8087 case elfcpp::R_POWERPC_PLT16_HI
:
8088 case elfcpp::R_POWERPC_PLT16_HA
:
8089 case elfcpp::R_PPC64_PLT16_LO_DS
:
8092 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8093 target
->make_local_plt_entry(layout
, object
, r_sym
);
8097 case elfcpp::R_PPC64_REL24_NOTOC
:
8101 case elfcpp::R_POWERPC_REL24
:
8102 case elfcpp::R_PPC_PLTREL24
:
8103 case elfcpp::R_PPC_LOCAL24PC
:
8104 case elfcpp::R_POWERPC_REL14
:
8105 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8106 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8109 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8110 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8111 r_type
, r_sym
, reloc
.get_r_addend());
8115 case elfcpp::R_PPC64_TOCSAVE
:
8116 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8117 // caller has already saved r2 and thus a plt call stub need not
8120 && target
->mark_pltcall(ppc_object
, data_shndx
,
8121 reloc
.get_r_offset() - 4, symtab
))
8123 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8124 unsigned int shndx
= lsym
.get_st_shndx();
8126 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8128 object
->error(_("tocsave symbol %u has bad shndx %u"),
8131 target
->add_tocsave(ppc_object
, shndx
,
8132 lsym
.get_st_value() + reloc
.get_r_addend());
8136 case elfcpp::R_PPC64_REL64
:
8137 case elfcpp::R_POWERPC_REL32
:
8138 case elfcpp::R_POWERPC_REL16
:
8139 case elfcpp::R_POWERPC_REL16_LO
:
8140 case elfcpp::R_POWERPC_REL16_HI
:
8141 case elfcpp::R_POWERPC_REL16_HA
:
8142 case elfcpp::R_POWERPC_REL16DX_HA
:
8143 case elfcpp::R_PPC64_REL16_HIGH
:
8144 case elfcpp::R_PPC64_REL16_HIGHA
:
8145 case elfcpp::R_PPC64_REL16_HIGHER
:
8146 case elfcpp::R_PPC64_REL16_HIGHERA
:
8147 case elfcpp::R_PPC64_REL16_HIGHEST
:
8148 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8149 case elfcpp::R_POWERPC_SECTOFF
:
8150 case elfcpp::R_POWERPC_SECTOFF_LO
:
8151 case elfcpp::R_POWERPC_SECTOFF_HI
:
8152 case elfcpp::R_POWERPC_SECTOFF_HA
:
8153 case elfcpp::R_PPC64_SECTOFF_DS
:
8154 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8155 case elfcpp::R_POWERPC_TPREL16
:
8156 case elfcpp::R_POWERPC_TPREL16_LO
:
8157 case elfcpp::R_POWERPC_TPREL16_HI
:
8158 case elfcpp::R_POWERPC_TPREL16_HA
:
8159 case elfcpp::R_PPC64_TPREL16_DS
:
8160 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8161 case elfcpp::R_PPC64_TPREL16_HIGH
:
8162 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8163 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8164 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8165 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8166 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8167 case elfcpp::R_POWERPC_DTPREL16
:
8168 case elfcpp::R_POWERPC_DTPREL16_LO
:
8169 case elfcpp::R_POWERPC_DTPREL16_HI
:
8170 case elfcpp::R_POWERPC_DTPREL16_HA
:
8171 case elfcpp::R_PPC64_DTPREL16_DS
:
8172 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8173 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8174 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8175 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8176 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8177 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8178 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8179 case elfcpp::R_PPC64_TLSGD
:
8180 case elfcpp::R_PPC64_TLSLD
:
8181 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8184 case elfcpp::R_PPC64_GOT_PCREL34
:
8185 case elfcpp::R_POWERPC_GOT16
:
8186 case elfcpp::R_POWERPC_GOT16_LO
:
8187 case elfcpp::R_POWERPC_GOT16_HI
:
8188 case elfcpp::R_POWERPC_GOT16_HA
:
8189 case elfcpp::R_PPC64_GOT16_DS
:
8190 case elfcpp::R_PPC64_GOT16_LO_DS
:
8192 // The symbol requires a GOT entry.
8193 Output_data_got_powerpc
<size
, big_endian
>* got
8194 = target
->got_section(symtab
, layout
);
8195 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8197 if (!parameters
->options().output_is_position_independent())
8200 && (size
== 32 || target
->abiversion() >= 2))
8201 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
8203 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
8205 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
8207 // If we are generating a shared object or a pie, this
8208 // symbol's GOT entry will be set by a dynamic relocation.
8210 off
= got
->add_constant(0);
8211 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
8213 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
8215 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8216 : elfcpp::R_POWERPC_RELATIVE
);
8217 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
8218 got
, off
, 0, false);
8223 case elfcpp::R_PPC64_TOC16
:
8224 case elfcpp::R_PPC64_TOC16_LO
:
8225 case elfcpp::R_PPC64_TOC16_HI
:
8226 case elfcpp::R_PPC64_TOC16_HA
:
8227 case elfcpp::R_PPC64_TOC16_DS
:
8228 case elfcpp::R_PPC64_TOC16_LO_DS
:
8229 // We need a GOT section.
8230 target
->got_section(symtab
, layout
);
8233 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8234 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8235 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8236 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8237 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8239 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
8240 if (!ppc_object
->no_tls_marker())
8241 tls_type
= target
->optimize_tls_gd(true);
8242 if (tls_type
== tls::TLSOPT_NONE
)
8244 Output_data_got_powerpc
<size
, big_endian
>* got
8245 = target
->got_section(symtab
, layout
);
8246 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8247 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8248 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
8249 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
8251 else if (tls_type
== tls::TLSOPT_TO_LE
)
8253 // no GOT relocs needed for Local Exec.
8254 ppc_object
->set_tls_marker();
8261 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8262 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8263 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8264 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8265 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8267 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
8268 if (!ppc_object
->no_tls_marker())
8269 tls_type
= target
->optimize_tls_ld();
8270 if (tls_type
== tls::TLSOPT_NONE
)
8271 target
->tlsld_got_offset(symtab
, layout
, object
);
8272 else if (tls_type
== tls::TLSOPT_TO_LE
)
8274 // no GOT relocs needed for Local Exec.
8275 if (parameters
->options().emit_relocs())
8277 Output_section
* os
= layout
->tls_segment()->first_section();
8278 gold_assert(os
!= NULL
);
8279 os
->set_needs_symtab_index();
8281 ppc_object
->set_tls_marker();
8288 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8289 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8290 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8291 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8292 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8294 Output_data_got_powerpc
<size
, big_endian
>* got
8295 = target
->got_section(symtab
, layout
);
8296 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8297 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
8301 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8302 case elfcpp::R_POWERPC_GOT_TPREL16
:
8303 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8304 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8305 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8307 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
8308 if (tls_type
== tls::TLSOPT_NONE
)
8310 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8311 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
8313 Output_data_got_powerpc
<size
, big_endian
>* got
8314 = target
->got_section(symtab
, layout
);
8315 unsigned int off
= got
->add_constant(0);
8316 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
8318 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8319 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
8320 elfcpp::R_POWERPC_TPREL
,
8324 else if (tls_type
== tls::TLSOPT_TO_LE
)
8326 // no GOT relocs needed for Local Exec.
8334 unsupported_reloc_local(object
, r_type
);
8339 && parameters
->options().toc_optimize())
8341 if (data_shndx
== ppc_object
->toc_shndx())
8344 if (r_type
!= elfcpp::R_PPC64_ADDR64
8345 || (is_ifunc
&& target
->abiversion() < 2))
8347 else if (parameters
->options().output_is_position_independent())
8353 unsigned int shndx
= lsym
.get_st_shndx();
8354 if (shndx
>= elfcpp::SHN_LORESERVE
8355 && shndx
!= elfcpp::SHN_XINDEX
)
8360 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8363 enum {no_check
, check_lo
, check_ha
} insn_check
;
8367 insn_check
= no_check
;
8370 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8371 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8372 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8373 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8374 case elfcpp::R_POWERPC_GOT16_HA
:
8375 case elfcpp::R_PPC64_TOC16_HA
:
8376 insn_check
= check_ha
;
8379 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8380 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8381 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8382 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8383 case elfcpp::R_POWERPC_GOT16_LO
:
8384 case elfcpp::R_PPC64_GOT16_LO_DS
:
8385 case elfcpp::R_PPC64_TOC16_LO
:
8386 case elfcpp::R_PPC64_TOC16_LO_DS
:
8387 insn_check
= check_lo
;
8391 section_size_type slen
;
8392 const unsigned char* view
= NULL
;
8393 if (insn_check
!= no_check
)
8395 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8396 section_size_type off
=
8397 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8400 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8401 if (insn_check
== check_lo
8402 ? !ok_lo_toc_insn(insn
, r_type
)
8403 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8404 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8406 ppc_object
->set_no_toc_opt();
8407 gold_warning(_("%s: toc optimization is not supported "
8408 "for %#08x instruction"),
8409 ppc_object
->name().c_str(), insn
);
8418 case elfcpp::R_PPC64_TOC16
:
8419 case elfcpp::R_PPC64_TOC16_LO
:
8420 case elfcpp::R_PPC64_TOC16_HI
:
8421 case elfcpp::R_PPC64_TOC16_HA
:
8422 case elfcpp::R_PPC64_TOC16_DS
:
8423 case elfcpp::R_PPC64_TOC16_LO_DS
:
8424 unsigned int shndx
= lsym
.get_st_shndx();
8425 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8427 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8428 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8430 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8431 if (dst_off
< ppc_object
->section_size(shndx
))
8434 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8436 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8438 // Need to check that the insn is a ld
8440 view
= ppc_object
->section_contents(data_shndx
,
8443 section_size_type off
=
8444 (convert_to_section_size_type(reloc
.get_r_offset())
8445 + (big_endian
? -2 : 3));
8447 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8451 ppc_object
->set_no_toc_opt(dst_off
);
8462 case elfcpp::R_POWERPC_REL32
:
8463 if (ppc_object
->got2_shndx() != 0
8464 && parameters
->options().output_is_position_independent())
8466 unsigned int shndx
= lsym
.get_st_shndx();
8467 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8469 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8470 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8471 && (ppc_object
->section_flags(data_shndx
)
8472 & elfcpp::SHF_EXECINSTR
) != 0)
8473 gold_error(_("%s: unsupported -mbss-plt code"),
8474 ppc_object
->name().c_str());
8484 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8485 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8486 case elfcpp::R_POWERPC_GOT_TPREL16
:
8487 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8488 case elfcpp::R_POWERPC_GOT16
:
8489 case elfcpp::R_PPC64_GOT16_DS
:
8490 case elfcpp::R_PPC64_TOC16
:
8491 case elfcpp::R_PPC64_TOC16_DS
:
8492 ppc_object
->set_has_small_toc_reloc();
8500 case elfcpp::R_PPC64_TPREL16_DS
:
8501 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8502 case elfcpp::R_PPC64_TPREL16_HIGH
:
8503 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8504 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8505 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8506 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8507 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8508 case elfcpp::R_PPC64_TPREL34
:
8512 case elfcpp::R_POWERPC_TPREL16
:
8513 case elfcpp::R_POWERPC_TPREL16_LO
:
8514 case elfcpp::R_POWERPC_TPREL16_HI
:
8515 case elfcpp::R_POWERPC_TPREL16_HA
:
8516 layout
->set_has_static_tls();
8524 case elfcpp::R_POWERPC_TPREL16_HA
:
8525 if (target
->tprel_opt())
8527 section_size_type slen
;
8528 const unsigned char* view
= NULL
;
8529 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8530 section_size_type off
8531 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8534 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8535 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8536 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
8537 target
->set_no_tprel_opt();
8542 case elfcpp::R_PPC64_TPREL16_HIGH
:
8543 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8544 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8545 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8546 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8547 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8551 case elfcpp::R_POWERPC_TPREL16_HI
:
8552 target
->set_no_tprel_opt();
8560 case elfcpp::R_PPC64_D34
:
8561 case elfcpp::R_PPC64_D34_LO
:
8562 case elfcpp::R_PPC64_D34_HI30
:
8563 case elfcpp::R_PPC64_D34_HA30
:
8564 case elfcpp::R_PPC64_D28
:
8565 case elfcpp::R_PPC64_PCREL34
:
8566 case elfcpp::R_PPC64_PCREL28
:
8567 case elfcpp::R_PPC64_TPREL34
:
8568 case elfcpp::R_PPC64_DTPREL34
:
8569 case elfcpp::R_PPC64_PLT_PCREL34
:
8570 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8571 case elfcpp::R_PPC64_GOT_PCREL34
:
8572 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
8573 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
8574 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
8575 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
8576 target
->set_power10_relocs();
8583 // Report an unsupported relocation against a global symbol.
8585 template<int size
, bool big_endian
>
8587 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8588 Sized_relobj_file
<size
, big_endian
>* object
,
8589 unsigned int r_type
,
8592 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8593 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8596 // Scan a relocation for a global symbol.
8598 template<int size
, bool big_endian
>
8600 Target_powerpc
<size
, big_endian
>::Scan::global(
8601 Symbol_table
* symtab
,
8603 Target_powerpc
<size
, big_endian
>* target
,
8604 Sized_relobj_file
<size
, big_endian
>* object
,
8605 unsigned int data_shndx
,
8606 Output_section
* output_section
,
8607 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8608 unsigned int r_type
,
8611 Powerpc_relobj
<size
, big_endian
>* ppc_object
8612 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8614 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8616 case Track_tls::NOT_EXPECTED
:
8617 ppc_object
->set_no_tls_marker();
8619 case Track_tls::SKIP
:
8625 if (target
->replace_tls_get_addr(gsym
))
8626 // Change a __tls_get_addr reference to __tls_get_addr_opt
8627 // so dynamic relocs are emitted against the latter symbol.
8628 gsym
= target
->tls_get_addr_opt();
8630 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8631 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8633 this->expect_tls_get_addr_call();
8634 if (!ppc_object
->no_tls_marker())
8636 bool final
= gsym
->final_value_is_known();
8637 tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8638 if (tls_type
!= tls::TLSOPT_NONE
)
8640 this->skip_next_tls_get_addr_call();
8641 ppc_object
->set_tls_marker();
8645 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8646 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8648 this->expect_tls_get_addr_call();
8649 if (!ppc_object
->no_tls_marker())
8651 tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8652 if (tls_type
!= tls::TLSOPT_NONE
)
8654 this->skip_next_tls_get_addr_call();
8655 ppc_object
->set_tls_marker();
8660 // A STT_GNU_IFUNC symbol may require a PLT entry.
8661 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8662 bool pushed_ifunc
= false;
8663 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8665 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8666 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8667 r_type
, r_sym
, reloc
.get_r_addend());
8668 target
->make_plt_entry(symtab
, layout
, gsym
);
8669 pushed_ifunc
= true;
8674 case elfcpp::R_POWERPC_NONE
:
8675 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8676 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8677 case elfcpp::R_PPC_LOCAL24PC
:
8678 case elfcpp::R_POWERPC_TLS
:
8679 case elfcpp::R_PPC64_ENTRY
:
8680 case elfcpp::R_POWERPC_PLTSEQ
:
8681 case elfcpp::R_POWERPC_PLTCALL
:
8682 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8683 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8684 case elfcpp::R_PPC64_PCREL_OPT
:
8685 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8686 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8687 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8688 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8689 case elfcpp::R_PPC64_REL16_HIGHER34
:
8690 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8691 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8692 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8693 case elfcpp::R_PPC64_D34
:
8694 case elfcpp::R_PPC64_D34_LO
:
8695 case elfcpp::R_PPC64_D34_HI30
:
8696 case elfcpp::R_PPC64_D34_HA30
:
8697 case elfcpp::R_PPC64_D28
:
8698 case elfcpp::R_PPC64_PCREL34
:
8699 case elfcpp::R_PPC64_PCREL28
:
8700 case elfcpp::R_PPC64_TPREL34
:
8701 case elfcpp::R_PPC64_DTPREL34
:
8704 case elfcpp::R_PPC64_TOC
:
8706 Output_data_got_powerpc
<size
, big_endian
>* got
8707 = target
->got_section(symtab
, layout
);
8708 if (parameters
->options().output_is_position_independent())
8710 Address off
= reloc
.get_r_offset();
8712 && data_shndx
== ppc_object
->opd_shndx()
8713 && ppc_object
->get_opd_discard(off
- 8))
8716 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8717 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8718 if (data_shndx
!= ppc_object
->opd_shndx())
8719 symobj
= static_cast
8720 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8721 rela_dyn
->add_output_section_relative(got
->output_section(),
8722 elfcpp::R_POWERPC_RELATIVE
,
8724 object
, data_shndx
, off
,
8725 symobj
->toc_base_offset());
8730 case elfcpp::R_PPC64_ADDR64
:
8732 && target
->abiversion() < 2
8733 && data_shndx
== ppc_object
->opd_shndx()
8734 && (gsym
->is_defined_in_discarded_section()
8735 || gsym
->object() != object
))
8737 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8741 case elfcpp::R_PPC64_UADDR64
:
8742 case elfcpp::R_POWERPC_ADDR32
:
8743 case elfcpp::R_POWERPC_UADDR32
:
8744 case elfcpp::R_POWERPC_ADDR24
:
8745 case elfcpp::R_POWERPC_ADDR16
:
8746 case elfcpp::R_POWERPC_ADDR16_LO
:
8747 case elfcpp::R_POWERPC_ADDR16_HI
:
8748 case elfcpp::R_POWERPC_ADDR16_HA
:
8749 case elfcpp::R_POWERPC_UADDR16
:
8750 case elfcpp::R_PPC64_ADDR16_HIGH
:
8751 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8752 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8753 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8754 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8755 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8756 case elfcpp::R_PPC64_ADDR16_DS
:
8757 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8758 case elfcpp::R_POWERPC_ADDR14
:
8759 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8760 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8762 // Make a PLT entry if necessary.
8763 if (gsym
->needs_plt_entry())
8765 // Since this is not a PC-relative relocation, we may be
8766 // taking the address of a function. In that case we need to
8767 // set the entry in the dynamic symbol table to the address of
8768 // the PLT call stub.
8769 bool need_ifunc_plt
= false;
8770 if ((size
== 32 || target
->abiversion() >= 2)
8771 && gsym
->is_from_dynobj()
8772 && !parameters
->options().output_is_position_independent())
8774 gsym
->set_needs_dynsym_value();
8775 need_ifunc_plt
= true;
8777 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8779 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8780 target
->push_branch(ppc_object
, data_shndx
,
8781 reloc
.get_r_offset(), r_type
, r_sym
,
8782 reloc
.get_r_addend());
8783 target
->make_plt_entry(symtab
, layout
, gsym
);
8786 // Make a dynamic relocation if necessary.
8787 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8788 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8790 if (!parameters
->options().output_is_position_independent()
8791 && gsym
->may_need_copy_reloc())
8793 target
->copy_reloc(symtab
, layout
, object
,
8794 data_shndx
, output_section
, gsym
, reloc
);
8796 else if ((((size
== 32
8797 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8799 && r_type
== elfcpp::R_PPC64_ADDR64
8800 && target
->abiversion() >= 2))
8801 && gsym
->can_use_relative_reloc(false)
8802 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8803 && parameters
->options().shared()))
8805 && r_type
== elfcpp::R_PPC64_ADDR64
8806 && target
->abiversion() < 2
8807 && (gsym
->can_use_relative_reloc(false)
8808 || data_shndx
== ppc_object
->opd_shndx())))
8810 Reloc_section
* rela_dyn
8811 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8812 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8813 : elfcpp::R_POWERPC_RELATIVE
);
8814 rela_dyn
->add_symbolless_global_addend(
8815 gsym
, dynrel
, output_section
, object
, data_shndx
,
8816 reloc
.get_r_offset(), reloc
.get_r_addend());
8820 Reloc_section
* rela_dyn
8821 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8822 check_non_pic(object
, r_type
);
8823 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8825 reloc
.get_r_offset(),
8826 reloc
.get_r_addend());
8829 && parameters
->options().toc_optimize()
8830 && data_shndx
== ppc_object
->toc_shndx())
8831 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8837 case elfcpp::R_PPC64_PLT_PCREL34
:
8838 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8839 case elfcpp::R_POWERPC_PLT16_LO
:
8840 case elfcpp::R_POWERPC_PLT16_HI
:
8841 case elfcpp::R_POWERPC_PLT16_HA
:
8842 case elfcpp::R_PPC64_PLT16_LO_DS
:
8844 target
->make_plt_entry(symtab
, layout
, gsym
);
8847 case elfcpp::R_PPC64_REL24_NOTOC
:
8851 case elfcpp::R_PPC_PLTREL24
:
8852 case elfcpp::R_POWERPC_REL24
:
8855 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8856 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8857 r_type
, r_sym
, reloc
.get_r_addend());
8858 if (gsym
->needs_plt_entry()
8859 || (!gsym
->final_value_is_known()
8860 && (gsym
->is_undefined()
8861 || gsym
->is_from_dynobj()
8862 || gsym
->is_preemptible())))
8863 target
->make_plt_entry(symtab
, layout
, gsym
);
8867 case elfcpp::R_PPC64_REL64
:
8868 case elfcpp::R_POWERPC_REL32
:
8869 // Make a dynamic relocation if necessary.
8870 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8872 if (!parameters
->options().output_is_position_independent()
8873 && gsym
->may_need_copy_reloc())
8875 target
->copy_reloc(symtab
, layout
, object
,
8876 data_shndx
, output_section
, gsym
,
8881 Reloc_section
* rela_dyn
8882 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8883 check_non_pic(object
, r_type
);
8884 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8885 data_shndx
, reloc
.get_r_offset(),
8886 reloc
.get_r_addend());
8891 case elfcpp::R_POWERPC_REL14
:
8892 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8893 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8896 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8897 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8898 r_type
, r_sym
, reloc
.get_r_addend());
8902 case elfcpp::R_PPC64_TOCSAVE
:
8903 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8904 // caller has already saved r2 and thus a plt call stub need not
8907 && target
->mark_pltcall(ppc_object
, data_shndx
,
8908 reloc
.get_r_offset() - 4, symtab
))
8910 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8912 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8914 object
->error(_("tocsave symbol %u has bad shndx %u"),
8918 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8919 target
->add_tocsave(ppc_object
, shndx
,
8920 sym
->value() + reloc
.get_r_addend());
8925 case elfcpp::R_POWERPC_REL16
:
8926 case elfcpp::R_POWERPC_REL16_LO
:
8927 case elfcpp::R_POWERPC_REL16_HI
:
8928 case elfcpp::R_POWERPC_REL16_HA
:
8929 case elfcpp::R_POWERPC_REL16DX_HA
:
8930 case elfcpp::R_PPC64_REL16_HIGH
:
8931 case elfcpp::R_PPC64_REL16_HIGHA
:
8932 case elfcpp::R_PPC64_REL16_HIGHER
:
8933 case elfcpp::R_PPC64_REL16_HIGHERA
:
8934 case elfcpp::R_PPC64_REL16_HIGHEST
:
8935 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8936 case elfcpp::R_POWERPC_SECTOFF
:
8937 case elfcpp::R_POWERPC_SECTOFF_LO
:
8938 case elfcpp::R_POWERPC_SECTOFF_HI
:
8939 case elfcpp::R_POWERPC_SECTOFF_HA
:
8940 case elfcpp::R_PPC64_SECTOFF_DS
:
8941 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8942 case elfcpp::R_POWERPC_TPREL16
:
8943 case elfcpp::R_POWERPC_TPREL16_LO
:
8944 case elfcpp::R_POWERPC_TPREL16_HI
:
8945 case elfcpp::R_POWERPC_TPREL16_HA
:
8946 case elfcpp::R_PPC64_TPREL16_DS
:
8947 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8948 case elfcpp::R_PPC64_TPREL16_HIGH
:
8949 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8950 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8951 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8952 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8953 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8954 case elfcpp::R_POWERPC_DTPREL16
:
8955 case elfcpp::R_POWERPC_DTPREL16_LO
:
8956 case elfcpp::R_POWERPC_DTPREL16_HI
:
8957 case elfcpp::R_POWERPC_DTPREL16_HA
:
8958 case elfcpp::R_PPC64_DTPREL16_DS
:
8959 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8960 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8961 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8962 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8963 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8964 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8965 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8966 case elfcpp::R_PPC64_TLSGD
:
8967 case elfcpp::R_PPC64_TLSLD
:
8968 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8971 case elfcpp::R_PPC64_GOT_PCREL34
:
8972 case elfcpp::R_POWERPC_GOT16
:
8973 case elfcpp::R_POWERPC_GOT16_LO
:
8974 case elfcpp::R_POWERPC_GOT16_HI
:
8975 case elfcpp::R_POWERPC_GOT16_HA
:
8976 case elfcpp::R_PPC64_GOT16_DS
:
8977 case elfcpp::R_PPC64_GOT16_LO_DS
:
8979 // The symbol requires a GOT entry.
8980 Output_data_got_powerpc
<size
, big_endian
>* got
;
8982 got
= target
->got_section(symtab
, layout
);
8983 if (gsym
->final_value_is_known())
8986 && (size
== 32 || target
->abiversion() >= 2))
8987 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8989 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8991 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8993 // If we are generating a shared object or a pie, this
8994 // symbol's GOT entry will be set by a dynamic relocation.
8995 unsigned int off
= got
->add_constant(0);
8996 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8998 Reloc_section
* rela_dyn
8999 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
9001 if (gsym
->can_use_relative_reloc(false)
9003 || target
->abiversion() >= 2)
9004 && gsym
->visibility() == elfcpp::STV_PROTECTED
9005 && parameters
->options().shared()))
9007 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
9008 : elfcpp::R_POWERPC_RELATIVE
);
9009 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
9013 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
9014 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
9020 case elfcpp::R_PPC64_TOC16
:
9021 case elfcpp::R_PPC64_TOC16_LO
:
9022 case elfcpp::R_PPC64_TOC16_HI
:
9023 case elfcpp::R_PPC64_TOC16_HA
:
9024 case elfcpp::R_PPC64_TOC16_DS
:
9025 case elfcpp::R_PPC64_TOC16_LO_DS
:
9026 // We need a GOT section.
9027 target
->got_section(symtab
, layout
);
9030 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9031 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9032 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9033 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9034 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9036 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
9037 if (!ppc_object
->no_tls_marker())
9039 bool final
= gsym
->final_value_is_known();
9040 tls_type
= target
->optimize_tls_gd(final
);
9042 if (tls_type
== tls::TLSOPT_NONE
)
9044 Output_data_got_powerpc
<size
, big_endian
>* got
9045 = target
->got_section(symtab
, layout
);
9046 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9047 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
9048 elfcpp::R_POWERPC_DTPMOD
,
9049 elfcpp::R_POWERPC_DTPREL
);
9051 else if (tls_type
== tls::TLSOPT_TO_IE
)
9053 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
9055 Output_data_got_powerpc
<size
, big_endian
>* got
9056 = target
->got_section(symtab
, layout
);
9057 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9058 if (gsym
->is_undefined()
9059 || gsym
->is_from_dynobj())
9061 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9062 elfcpp::R_POWERPC_TPREL
);
9066 unsigned int off
= got
->add_constant(0);
9067 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9068 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9069 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9073 ppc_object
->set_tls_marker();
9075 else if (tls_type
== tls::TLSOPT_TO_LE
)
9077 // no GOT relocs needed for Local Exec.
9078 ppc_object
->set_tls_marker();
9085 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9086 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9087 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9088 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9089 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9091 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
9092 if (!ppc_object
->no_tls_marker())
9093 tls_type
= target
->optimize_tls_ld();
9094 if (tls_type
== tls::TLSOPT_NONE
)
9095 target
->tlsld_got_offset(symtab
, layout
, object
);
9096 else if (tls_type
== tls::TLSOPT_TO_LE
)
9098 // no GOT relocs needed for Local Exec.
9099 if (parameters
->options().emit_relocs())
9101 Output_section
* os
= layout
->tls_segment()->first_section();
9102 gold_assert(os
!= NULL
);
9103 os
->set_needs_symtab_index();
9105 ppc_object
->set_tls_marker();
9112 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9113 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9114 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9115 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9116 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9118 Output_data_got_powerpc
<size
, big_endian
>* got
9119 = target
->got_section(symtab
, layout
);
9120 if (!gsym
->final_value_is_known()
9121 && (gsym
->is_from_dynobj()
9122 || gsym
->is_undefined()
9123 || gsym
->is_preemptible()))
9124 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
9125 target
->rela_dyn_section(layout
),
9126 elfcpp::R_POWERPC_DTPREL
);
9128 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
9132 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9133 case elfcpp::R_POWERPC_GOT_TPREL16
:
9134 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9135 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9136 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9138 bool final
= gsym
->final_value_is_known();
9139 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9140 if (tls_type
== tls::TLSOPT_NONE
)
9142 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
9144 Output_data_got_powerpc
<size
, big_endian
>* got
9145 = target
->got_section(symtab
, layout
);
9146 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
9147 if (gsym
->is_undefined()
9148 || gsym
->is_from_dynobj())
9150 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
9151 elfcpp::R_POWERPC_TPREL
);
9155 unsigned int off
= got
->add_constant(0);
9156 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
9157 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
9158 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
9163 else if (tls_type
== tls::TLSOPT_TO_LE
)
9165 // no GOT relocs needed for Local Exec.
9173 unsupported_reloc_global(object
, r_type
, gsym
);
9178 && parameters
->options().toc_optimize())
9180 if (data_shndx
== ppc_object
->toc_shndx())
9183 if (r_type
!= elfcpp::R_PPC64_ADDR64
9184 || (is_ifunc
&& target
->abiversion() < 2))
9186 else if (parameters
->options().output_is_position_independent()
9187 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
9190 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
9193 enum {no_check
, check_lo
, check_ha
} insn_check
;
9197 insn_check
= no_check
;
9200 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9201 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9202 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9203 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9204 case elfcpp::R_POWERPC_GOT16_HA
:
9205 case elfcpp::R_PPC64_TOC16_HA
:
9206 insn_check
= check_ha
;
9209 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9210 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9211 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9212 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9213 case elfcpp::R_POWERPC_GOT16_LO
:
9214 case elfcpp::R_PPC64_GOT16_LO_DS
:
9215 case elfcpp::R_PPC64_TOC16_LO
:
9216 case elfcpp::R_PPC64_TOC16_LO_DS
:
9217 insn_check
= check_lo
;
9221 section_size_type slen
;
9222 const unsigned char* view
= NULL
;
9223 if (insn_check
!= no_check
)
9225 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9226 section_size_type off
=
9227 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9230 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9231 if (insn_check
== check_lo
9232 ? !ok_lo_toc_insn(insn
, r_type
)
9233 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9234 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9236 ppc_object
->set_no_toc_opt();
9237 gold_warning(_("%s: toc optimization is not supported "
9238 "for %#08x instruction"),
9239 ppc_object
->name().c_str(), insn
);
9248 case elfcpp::R_PPC64_TOC16
:
9249 case elfcpp::R_PPC64_TOC16_LO
:
9250 case elfcpp::R_PPC64_TOC16_HI
:
9251 case elfcpp::R_PPC64_TOC16_HA
:
9252 case elfcpp::R_PPC64_TOC16_DS
:
9253 case elfcpp::R_PPC64_TOC16_LO_DS
:
9254 if (gsym
->source() == Symbol::FROM_OBJECT
9255 && !gsym
->object()->is_dynamic())
9257 Powerpc_relobj
<size
, big_endian
>* sym_object
9258 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9260 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
9261 if (shndx
== sym_object
->toc_shndx())
9263 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
9264 Address dst_off
= sym
->value() + reloc
.get_r_addend();
9265 if (dst_off
< sym_object
->section_size(shndx
))
9268 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
9270 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
9272 // Need to check that the insn is a ld
9274 view
= ppc_object
->section_contents(data_shndx
,
9277 section_size_type off
=
9278 (convert_to_section_size_type(reloc
.get_r_offset())
9279 + (big_endian
? -2 : 3));
9281 && (view
[off
] & (0x3f << 2)) == (58u << 2))
9285 sym_object
->set_no_toc_opt(dst_off
);
9297 case elfcpp::R_PPC_LOCAL24PC
:
9298 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
9299 gold_error(_("%s: unsupported -mbss-plt code"),
9300 ppc_object
->name().c_str());
9309 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9310 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9311 case elfcpp::R_POWERPC_GOT_TPREL16
:
9312 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9313 case elfcpp::R_POWERPC_GOT16
:
9314 case elfcpp::R_PPC64_GOT16_DS
:
9315 case elfcpp::R_PPC64_TOC16
:
9316 case elfcpp::R_PPC64_TOC16_DS
:
9317 ppc_object
->set_has_small_toc_reloc();
9325 case elfcpp::R_PPC64_TPREL16_DS
:
9326 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9327 case elfcpp::R_PPC64_TPREL16_HIGH
:
9328 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9329 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9330 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9331 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9332 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9333 case elfcpp::R_PPC64_TPREL34
:
9337 case elfcpp::R_POWERPC_TPREL16
:
9338 case elfcpp::R_POWERPC_TPREL16_LO
:
9339 case elfcpp::R_POWERPC_TPREL16_HI
:
9340 case elfcpp::R_POWERPC_TPREL16_HA
:
9341 layout
->set_has_static_tls();
9349 case elfcpp::R_POWERPC_TPREL16_HA
:
9350 if (target
->tprel_opt())
9352 section_size_type slen
;
9353 const unsigned char* view
= NULL
;
9354 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
9355 section_size_type off
9356 = convert_to_section_size_type(reloc
.get_r_offset()) & -4;
9359 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
9360 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9361 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9362 target
->set_no_tprel_opt();
9367 case elfcpp::R_PPC64_TPREL16_HIGH
:
9368 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9369 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9370 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9371 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9372 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9376 case elfcpp::R_POWERPC_TPREL16_HI
:
9377 target
->set_no_tprel_opt();
9385 case elfcpp::R_PPC64_D34
:
9386 case elfcpp::R_PPC64_D34_LO
:
9387 case elfcpp::R_PPC64_D34_HI30
:
9388 case elfcpp::R_PPC64_D34_HA30
:
9389 case elfcpp::R_PPC64_D28
:
9390 case elfcpp::R_PPC64_PCREL34
:
9391 case elfcpp::R_PPC64_PCREL28
:
9392 case elfcpp::R_PPC64_TPREL34
:
9393 case elfcpp::R_PPC64_DTPREL34
:
9394 case elfcpp::R_PPC64_PLT_PCREL34
:
9395 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
9396 case elfcpp::R_PPC64_GOT_PCREL34
:
9397 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
9398 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
9399 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
9400 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
9401 target
->set_power10_relocs();
9408 // Process relocations for gc.
9410 template<int size
, bool big_endian
>
9412 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
9413 Symbol_table
* symtab
,
9415 Sized_relobj_file
<size
, big_endian
>* object
,
9416 unsigned int data_shndx
,
9418 const unsigned char* prelocs
,
9420 Output_section
* output_section
,
9421 bool needs_special_offset_handling
,
9422 size_t local_symbol_count
,
9423 const unsigned char* plocal_symbols
)
9425 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9426 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9429 Powerpc_relobj
<size
, big_endian
>* ppc_object
9430 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
9432 ppc_object
->set_opd_valid();
9433 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
9435 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
9436 for (p
= ppc_object
->access_from_map()->begin();
9437 p
!= ppc_object
->access_from_map()->end();
9440 Address dst_off
= p
->first
;
9441 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9442 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
9443 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
9445 Relobj
* src_obj
= s
->first
;
9446 unsigned int src_indx
= s
->second
;
9447 symtab
->gc()->add_reference(src_obj
, src_indx
,
9448 ppc_object
, dst_indx
);
9452 ppc_object
->access_from_map()->clear();
9453 ppc_object
->process_gc_mark(symtab
);
9454 // Don't look at .opd relocs as .opd will reference everything.
9458 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9467 needs_special_offset_handling
,
9472 // Handle target specific gc actions when adding a gc reference from
9473 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9474 // and DST_OFF. For powerpc64, this adds a referenc to the code
9475 // section of a function descriptor.
9477 template<int size
, bool big_endian
>
9479 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9480 Symbol_table
* symtab
,
9482 unsigned int src_shndx
,
9484 unsigned int dst_shndx
,
9485 Address dst_off
) const
9487 if (size
!= 64 || dst_obj
->is_dynamic())
9490 Powerpc_relobj
<size
, big_endian
>* ppc_object
9491 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9492 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9494 if (ppc_object
->opd_valid())
9496 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9497 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9501 // If we haven't run scan_opd_relocs, we must delay
9502 // processing this function descriptor reference.
9503 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9508 // Add any special sections for this symbol to the gc work list.
9509 // For powerpc64, this adds the code section of a function
9512 template<int size
, bool big_endian
>
9514 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9515 Symbol_table
* symtab
,
9518 if (size
== 64 && sym
->object()->pluginobj() == NULL
)
9520 Powerpc_relobj
<size
, big_endian
>* ppc_object
9521 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9523 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9524 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9526 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9527 Address dst_off
= gsym
->value();
9528 if (ppc_object
->opd_valid())
9530 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9531 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9535 ppc_object
->add_gc_mark(dst_off
);
9540 // For a symbol location in .opd, set LOC to the location of the
9543 template<int size
, bool big_endian
>
9545 Target_powerpc
<size
, big_endian
>::do_function_location(
9546 Symbol_location
* loc
) const
9548 if (size
== 64 && loc
->shndx
!= 0)
9550 if (loc
->object
->is_dynamic())
9552 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9553 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9554 if (loc
->shndx
== ppc_object
->opd_shndx())
9557 Address off
= loc
->offset
- ppc_object
->opd_address();
9558 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9559 loc
->offset
= dest_off
;
9564 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9565 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9566 if (loc
->shndx
== ppc_object
->opd_shndx())
9569 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9570 loc
->offset
= dest_off
;
9576 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9577 // compiled with -fsplit-stack. The function calls non-split-stack
9578 // code. Change the function to ensure it has enough stack space to
9579 // call some random function.
9581 template<int size
, bool big_endian
>
9583 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9586 section_offset_type fnoffset
,
9587 section_size_type fnsize
,
9588 const unsigned char* prelocs
,
9590 unsigned char* view
,
9591 section_size_type view_size
,
9593 std::string
* to
) const
9595 // 32-bit not supported.
9599 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9600 prelocs
, reloc_count
, view
, view_size
,
9605 // The function always starts with
9606 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9607 // addis %r12,%r1,-allocate@ha
9608 // addi %r12,%r12,-allocate@l
9610 // but note that the addis or addi may be replaced with a nop
9612 unsigned char *entry
= view
+ fnoffset
;
9613 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9615 if ((insn
& 0xffff0000) == addis_2_12
)
9617 /* Skip ELFv2 global entry code. */
9619 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9622 unsigned char *pinsn
= entry
;
9624 const uint32_t ld_private_ss
= 0xe80d8fc0;
9625 if (insn
== ld_private_ss
)
9627 int32_t allocate
= 0;
9631 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9632 if ((insn
& 0xffff0000) == addis_12_1
)
9633 allocate
+= (insn
& 0xffff) << 16;
9634 else if ((insn
& 0xffff0000) == addi_12_1
9635 || (insn
& 0xffff0000) == addi_12_12
)
9636 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9637 else if (insn
!= nop
)
9640 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9642 int extra
= parameters
->options().split_stack_adjust_size();
9644 if (allocate
>= 0 || extra
< 0)
9646 object
->error(_("split-stack stack size overflow at "
9647 "section %u offset %0zx"),
9648 shndx
, static_cast<size_t>(fnoffset
));
9652 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9653 if (insn
!= addis_12_1
)
9655 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9657 insn
= addi_12_12
| (allocate
& 0xffff);
9658 if (insn
!= addi_12_12
)
9660 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9666 insn
= addi_12_1
| (allocate
& 0xffff);
9667 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9670 if (pinsn
!= entry
+ 12)
9671 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9679 if (!object
->has_no_split_stack())
9680 object
->error(_("failed to match split-stack sequence at "
9681 "section %u offset %0zx"),
9682 shndx
, static_cast<size_t>(fnoffset
));
9686 // Scan relocations for a section.
9688 template<int size
, bool big_endian
>
9690 Target_powerpc
<size
, big_endian
>::scan_relocs(
9691 Symbol_table
* symtab
,
9693 Sized_relobj_file
<size
, big_endian
>* object
,
9694 unsigned int data_shndx
,
9695 unsigned int sh_type
,
9696 const unsigned char* prelocs
,
9698 Output_section
* output_section
,
9699 bool needs_special_offset_handling
,
9700 size_t local_symbol_count
,
9701 const unsigned char* plocal_symbols
)
9703 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9704 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9707 if (!this->plt_localentry0_init_
)
9709 bool plt_localentry0
= false;
9711 && this->abiversion() >= 2)
9713 if (parameters
->options().user_set_plt_localentry())
9714 plt_localentry0
= parameters
->options().plt_localentry();
9716 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9717 gold_warning(_("--plt-localentry is especially dangerous without "
9718 "ld.so support to detect ABI violations"));
9720 this->plt_localentry0_
= plt_localentry0
;
9721 this->plt_localentry0_init_
= true;
9724 if (sh_type
== elfcpp::SHT_REL
)
9726 gold_error(_("%s: unsupported REL reloc section"),
9727 object
->name().c_str());
9731 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9740 needs_special_offset_handling
,
9744 if (this->plt_localentry0_
&& this->power10_relocs_
)
9746 gold_warning(_("--plt-localentry is incompatible with "
9747 "power10 pc-relative code"));
9748 this->plt_localentry0_
= false;
9752 // Functor class for processing the global symbol table.
9753 // Removes symbols defined on discarded opd entries.
9755 template<bool big_endian
>
9756 class Global_symbol_visitor_opd
9759 Global_symbol_visitor_opd()
9763 operator()(Sized_symbol
<64>* sym
)
9765 if (sym
->has_symtab_index()
9766 || sym
->source() != Symbol::FROM_OBJECT
9767 || !sym
->in_real_elf())
9770 if (sym
->object()->is_dynamic())
9773 Powerpc_relobj
<64, big_endian
>* symobj
9774 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9775 if (symobj
->opd_shndx() == 0)
9779 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9780 if (shndx
== symobj
->opd_shndx()
9781 && symobj
->get_opd_discard(sym
->value()))
9783 sym
->set_undefined();
9784 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9785 sym
->set_is_defined_in_discarded_section();
9786 sym
->set_symtab_index(-1U);
9791 template<int size
, bool big_endian
>
9793 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9795 Symbol_table
* symtab
)
9799 Output_data_save_res
<size
, big_endian
>* savres
9800 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9801 this->savres_section_
= savres
;
9802 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9803 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9804 savres
, ORDER_TEXT
, false);
9808 // Sort linker created .got section first (for the header), then input
9809 // sections belonging to files using small model code.
9811 template<bool big_endian
>
9812 class Sort_toc_sections
9816 operator()(const Output_section::Input_section
& is1
,
9817 const Output_section::Input_section
& is2
) const
9819 if (!is1
.is_input_section() && is2
.is_input_section())
9822 = (is1
.is_input_section()
9823 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9824 ->has_small_toc_reloc()));
9826 = (is2
.is_input_section()
9827 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9828 ->has_small_toc_reloc()));
9829 return small1
&& !small2
;
9833 // Finalize the sections.
9835 template<int size
, bool big_endian
>
9837 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9839 const Input_objects
* input_objects
,
9840 Symbol_table
* symtab
)
9842 if (parameters
->doing_static_link())
9844 // At least some versions of glibc elf-init.o have a strong
9845 // reference to __rela_iplt marker syms. A weak ref would be
9847 if (this->iplt_
!= NULL
)
9849 Reloc_section
* rel
= this->iplt_
->rel_plt();
9850 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9851 Symbol_table::PREDEFINED
, rel
, 0, 0,
9852 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9853 elfcpp::STV_HIDDEN
, 0, false, true);
9854 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9855 Symbol_table::PREDEFINED
, rel
, 0, 0,
9856 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9857 elfcpp::STV_HIDDEN
, 0, true, true);
9861 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9862 Symbol_table::PREDEFINED
, 0, 0,
9863 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9864 elfcpp::STV_HIDDEN
, 0, true, false);
9865 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9866 Symbol_table::PREDEFINED
, 0, 0,
9867 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9868 elfcpp::STV_HIDDEN
, 0, true, false);
9874 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9875 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9877 if (!parameters
->options().relocatable())
9879 this->define_save_restore_funcs(layout
, symtab
);
9881 // Annoyingly, we need to make these sections now whether or
9882 // not we need them. If we delay until do_relax then we
9883 // need to mess with the relaxation machinery checkpointing.
9884 this->got_section(symtab
, layout
);
9885 this->make_brlt_section(layout
);
9887 if (parameters
->options().toc_sort())
9889 Output_section
* os
= this->got_
->output_section();
9890 if (os
!= NULL
&& os
->input_sections().size() > 1)
9891 std::stable_sort(os
->input_sections().begin(),
9892 os
->input_sections().end(),
9893 Sort_toc_sections
<big_endian
>());
9898 // Fill in some more dynamic tags.
9899 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9902 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9904 : this->plt_
->rel_plt());
9905 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9906 this->rela_dyn_
, true, size
== 32);
9910 if (this->got_
!= NULL
)
9912 this->got_
->finalize_data_size();
9913 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9914 this->got_
, this->got_
->g_o_t());
9916 if (this->has_tls_get_addr_opt_
)
9917 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9921 if (this->glink_
!= NULL
)
9923 this->glink_
->finalize_data_size();
9924 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9926 (this->glink_
->pltresolve_size()
9929 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9930 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9931 ((this->has_localentry0_
9932 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9933 | (this->has_tls_get_addr_opt_
9934 ? elfcpp::PPC64_OPT_TLS
: 0)));
9938 // Emit any relocs we saved in an attempt to avoid generating COPY
9940 if (this->copy_relocs_
.any_saved_relocs())
9941 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9943 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9944 p
!= input_objects
->relobj_end();
9947 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9948 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9949 if (ppc_relobj
->attributes_section_data())
9950 this->merge_object_attributes(ppc_relobj
,
9951 ppc_relobj
->attributes_section_data());
9953 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9954 p
!= input_objects
->dynobj_end();
9957 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9958 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9959 if (ppc_dynobj
->attributes_section_data())
9960 this->merge_object_attributes(ppc_dynobj
,
9961 ppc_dynobj
->attributes_section_data());
9964 // Create a .gnu.attributes section if we have merged any attributes
9966 if (this->attributes_section_data_
!= NULL
9967 && this->attributes_section_data_
->size() != 0)
9969 Output_attributes_section_data
* attributes_section
9970 = new Output_attributes_section_data(*this->attributes_section_data_
);
9971 layout
->add_output_section_data(".gnu.attributes",
9972 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9973 attributes_section
, ORDER_INVALID
, false);
9977 // Merge object attributes from input file called NAME with those of the
9978 // output. The input object attributes are in the object pointed by PASD.
9980 template<int size
, bool big_endian
>
9982 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9984 const Attributes_section_data
* pasd
)
9986 // Return if there is no attributes section data.
9990 // Create output object attributes.
9991 if (this->attributes_section_data_
== NULL
)
9992 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9994 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9995 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9996 Object_attribute
* out_attr
9997 = this->attributes_section_data_
->known_attributes(vendor
);
9999 const char* name
= obj
->name().c_str();
10002 const char* second
;
10003 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
10004 int in_fp
= in_attr
[tag
].int_value() & 0xf;
10005 int out_fp
= out_attr
[tag
].int_value() & 0xf;
10006 bool warn_only
= obj
->is_dynamic();
10007 if (in_fp
!= out_fp
)
10010 if ((in_fp
& 3) == 0)
10012 else if ((out_fp
& 3) == 0)
10016 out_fp
|= in_fp
& 3;
10017 out_attr
[tag
].set_int_value(out_fp
);
10018 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10019 this->last_fp_
= name
;
10022 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
10024 err
= N_("%s uses hard float, %s uses soft float");
10025 first
= this->last_fp_
;
10028 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
10030 err
= N_("%s uses hard float, %s uses soft float");
10032 second
= this->last_fp_
;
10034 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
10036 err
= N_("%s uses double-precision hard float, "
10037 "%s uses single-precision hard float");
10038 first
= this->last_fp_
;
10041 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
10043 err
= N_("%s uses double-precision hard float, "
10044 "%s uses single-precision hard float");
10046 second
= this->last_fp_
;
10049 if (err
|| (in_fp
& 0xc) == 0)
10051 else if ((out_fp
& 0xc) == 0)
10055 out_fp
|= in_fp
& 0xc;
10056 out_attr
[tag
].set_int_value(out_fp
);
10057 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10058 this->last_ld_
= name
;
10061 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
10063 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10065 second
= this->last_ld_
;
10067 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
10069 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
10070 first
= this->last_ld_
;
10073 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
10075 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10076 first
= this->last_ld_
;
10079 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
10081 err
= N_("%s uses IBM long double, %s uses IEEE long double");
10083 second
= this->last_ld_
;
10088 if (parameters
->options().warn_mismatch())
10091 gold_warning(_(err
), first
, second
);
10093 gold_error(_(err
), first
, second
);
10095 // Arrange for this attribute to be deleted. It's better to
10096 // say "don't know" about a file than to wrongly claim compliance.
10098 out_attr
[tag
].set_type(0);
10104 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
10105 int in_vec
= in_attr
[tag
].int_value() & 3;
10106 int out_vec
= out_attr
[tag
].int_value() & 3;
10107 if (in_vec
!= out_vec
)
10112 else if (out_vec
== 0)
10115 out_attr
[tag
].set_int_value(out_vec
);
10116 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10117 this->last_vec_
= name
;
10119 // For now, allow generic to transition to AltiVec or SPE
10120 // without a warning. If GCC marked files with their stack
10121 // alignment and used don't-care markings for files which are
10122 // not affected by the vector ABI, we could warn about this
10124 else if (in_vec
== 1)
10126 else if (out_vec
== 1)
10129 out_attr
[tag
].set_int_value(out_vec
);
10130 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10131 this->last_vec_
= name
;
10133 else if (out_vec
< in_vec
)
10135 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10136 first
= this->last_vec_
;
10139 else if (out_vec
> in_vec
)
10141 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
10143 second
= this->last_vec_
;
10147 if (parameters
->options().warn_mismatch())
10148 gold_error(_(err
), first
, second
);
10149 out_attr
[tag
].set_type(0);
10153 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
10154 int in_struct
= in_attr
[tag
].int_value() & 3;
10155 int out_struct
= out_attr
[tag
].int_value() & 3;
10156 if (in_struct
!= out_struct
)
10159 if (in_struct
== 0 || in_struct
== 3)
10161 else if (out_struct
== 0)
10163 out_struct
= in_struct
;
10164 out_attr
[tag
].set_int_value(out_struct
);
10165 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
10166 this->last_struct_
= name
;
10168 else if (out_struct
< in_struct
)
10170 err
= N_("%s uses r3/r4 for small structure returns, "
10172 first
= this->last_struct_
;
10175 else if (out_struct
> in_struct
)
10177 err
= N_("%s uses r3/r4 for small structure returns, "
10180 second
= this->last_struct_
;
10184 if (parameters
->options().warn_mismatch())
10185 gold_error(_(err
), first
, second
);
10186 out_attr
[tag
].set_type(0);
10191 // Merge Tag_compatibility attributes and any common GNU ones.
10192 this->attributes_section_data_
->merge(name
, pasd
);
10195 // Emit any saved relocs, and mark toc entries using any of these
10196 // relocs as not optimizable.
10198 template<int sh_type
, int size
, bool big_endian
>
10200 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
10201 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
10204 && parameters
->options().toc_optimize())
10206 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
10207 Copy_reloc_entries::iterator p
= this->entries_
.begin();
10208 p
!= this->entries_
.end();
10211 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
10214 // If the symbol is no longer defined in a dynamic object,
10215 // then we emitted a COPY relocation. If it is still
10216 // dynamic then we'll need dynamic relocations and thus
10217 // can't optimize toc entries.
10218 if (entry
.sym_
->is_from_dynobj())
10220 Powerpc_relobj
<size
, big_endian
>* ppc_object
10221 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
10222 if (entry
.shndx_
== ppc_object
->toc_shndx())
10223 ppc_object
->set_no_toc_opt(entry
.address_
);
10228 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
10231 // Return the value to use for a branch relocation.
10233 template<int size
, bool big_endian
>
10235 Target_powerpc
<size
, big_endian
>::symval_for_branch(
10236 const Symbol_table
* symtab
,
10237 const Sized_symbol
<size
>* gsym
,
10238 Powerpc_relobj
<size
, big_endian
>* object
,
10240 unsigned int *dest_shndx
)
10242 if (size
== 32 || this->abiversion() >= 2)
10243 gold_unreachable();
10246 // If the symbol is defined in an opd section, ie. is a function
10247 // descriptor, use the function descriptor code entry address
10248 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
10250 && (gsym
->source() != Symbol::FROM_OBJECT
10251 || gsym
->object()->is_dynamic()))
10254 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
10255 unsigned int shndx
= symobj
->opd_shndx();
10258 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
10259 if (opd_addr
== invalid_address
)
10261 opd_addr
+= symobj
->output_section_address(shndx
);
10262 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
10265 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
10266 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
10269 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
10270 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
10271 *dest_shndx
= folded
.second
;
10273 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
10274 if (sec_addr
== invalid_address
)
10277 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
10278 *value
= sec_addr
+ sec_off
;
10285 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
10287 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
10290 if (gsym
->is_from_dynobj()
10291 || gsym
->is_undefined()
10292 || gsym
->is_preemptible())
10295 if (gsym
->is_absolute())
10296 return !parameters
->options().output_is_position_independent();
10303 relative_value_is_known(const Symbol_value
<size
>* psymval
)
10305 if (psymval
->is_ifunc_symbol())
10309 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
10311 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
10314 // PCREL_OPT in one instance flags to the linker that a pair of insns:
10315 // pld ra,symbol@got@pcrel
10316 // load/store rt,0(ra)
10318 // pla ra,symbol@pcrel
10319 // load/store rt,0(ra)
10320 // may be translated to
10321 // pload/pstore rt,symbol@pcrel
10323 // This function returns true if the optimization is possible, placing
10324 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
10326 // On entry to this function, the linker has already determined that
10327 // the pld can be replaced with pla: *PINSN1 is that pla insn,
10328 // while *PINSN2 is the second instruction.
10331 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
10333 uint32_t insn2
= *pinsn2
>> 32;
10336 // Check that regs match.
10337 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
10340 switch ((insn2
>> 26) & 63)
10356 // These are the PMLS cases, where we just need to tack a prefix
10357 // on the insn. Check that the D field is zero.
10358 if ((insn2
& 0xffff) != 0)
10360 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10361 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10364 case 58: // lwa, ld
10365 if ((insn2
& 0xfffd) != 0)
10367 i1new
= ((1ULL << 58) | (1ULL << 52)
10368 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
10369 | (insn2
& (31ULL << 21)));
10372 case 57: // lxsd, lxssp
10373 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
10375 i1new
= ((1ULL << 58) | (1ULL << 52)
10376 | ((40ULL | (insn2
& 3)) << 26)
10377 | (insn2
& (31ULL << 21)));
10380 case 61: // stxsd, stxssp, lxv, stxv
10381 if ((insn2
& 3) == 0)
10383 else if ((insn2
& 3) >= 2)
10385 if ((insn2
& 0xfffc) != 0)
10387 i1new
= ((1ULL << 58) | (1ULL << 52)
10388 | ((44ULL | (insn2
& 3)) << 26)
10389 | (insn2
& (31ULL << 21)));
10393 if ((insn2
& 0xfff0) != 0)
10395 i1new
= ((1ULL << 58) | (1ULL << 52)
10396 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
10397 | (insn2
& (31ULL << 21)));
10402 if ((insn2
& 0xffff) != 0)
10404 i1new
= ((1ULL << 58) | (1ULL << 52)
10405 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
10408 case 62: // std, stq
10409 if ((insn2
& 0xfffd) != 0)
10411 i1new
= ((1ULL << 58) | (1ULL << 52)
10412 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
10413 | (insn2
& (31ULL << 21)));
10418 *pinsn2
= (uint64_t) nop
<< 32;
10422 // Perform a relocation.
10424 template<int size
, bool big_endian
>
10426 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
10427 const Relocate_info
<size
, big_endian
>* relinfo
,
10429 Target_powerpc
* target
,
10430 Output_section
* os
,
10432 const unsigned char* preloc
,
10433 const Sized_symbol
<size
>* gsym
,
10434 const Symbol_value
<size
>* psymval
,
10435 unsigned char* view
,
10437 section_size_type view_size
)
10439 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
10440 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
10441 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10446 if (target
->replace_tls_get_addr(gsym
))
10447 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
10449 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
10450 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
10451 Powerpc_relobj
<size
, big_endian
>* const object
10452 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10453 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
10455 case Track_tls::NOT_EXPECTED
:
10456 if (!parameters
->options().shared()
10457 && parameters
->options().tls_optimize())
10459 // It is a hard error to see a __tls_get_addr call without
10460 // marker relocs after seeing calls with marker relocs in the
10461 // same object file, because dynamic relocation accounting
10463 if (object
->tls_opt_error())
10464 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10465 _("__tls_get_addr call lacks marker reloc"));
10467 gold_warning_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10468 _("__tls_get_addr call lacks marker reloc"));
10471 case Track_tls::EXPECTED
:
10472 // We have already complained.
10474 case Track_tls::SKIP
:
10475 if (is_plt16_reloc
<size
>(r_type
)
10476 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10477 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
10479 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10480 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10482 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
10484 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10485 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
10487 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10488 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10490 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10491 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10492 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10495 case Track_tls::NORMAL
:
10499 // Offset from start of insn to d-field reloc.
10500 const int d_offset
= big_endian
? 2 : 0;
10503 bool has_stub_value
= false;
10504 bool localentry0
= false;
10505 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10506 bool has_plt_offset
10508 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10509 : object
->local_has_plt_offset(r_sym
));
10511 && !is_got_reloc(r_type
)
10512 && !is_plt16_reloc
<size
>(r_type
)
10513 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10514 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10515 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10516 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10517 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10518 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10519 && (!psymval
->is_ifunc_symbol()
10520 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10524 && target
->abiversion() >= 2
10525 && !parameters
->options().output_is_position_independent()
10526 && !is_branch_reloc
<size
>(r_type
))
10528 Address off
= target
->glink_section()->find_global_entry(gsym
);
10529 if (off
!= invalid_address
)
10531 value
= target
->glink_section()->global_entry_address() + off
;
10532 has_stub_value
= true;
10537 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10538 if (target
->stub_tables().size() == 1)
10539 stub_table
= target
->stub_tables()[0];
10540 if (stub_table
== NULL
10543 && !parameters
->options().output_is_position_independent()
10544 && !is_branch_reloc
<size
>(r_type
)))
10545 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10546 if (stub_table
== NULL
)
10548 // This is a ref from a data section to an ifunc symbol,
10549 // or a non-branch reloc for which we always want to use
10550 // one set of stubs for resolving function addresses.
10551 if (target
->stub_tables().size() != 0)
10552 stub_table
= target
->stub_tables()[0];
10554 if (stub_table
!= NULL
)
10556 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10558 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10559 rela
.get_r_addend());
10561 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10562 rela
.get_r_addend());
10565 value
= stub_table
->stub_address() + ent
->off_
;
10566 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10567 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10568 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10570 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
10571 value
+= ent
->tocoff_
;
10575 && target
->is_tls_get_addr_opt(gsym
)))
10577 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10579 if (!(target
->power10_stubs()
10580 && target
->power10_stubs_auto()))
10583 else if (relnum
< reloc_count
- 1)
10585 Reltype
next_rela(preloc
+ reloc_size
);
10586 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10587 == elfcpp::R_PPC64_TOCSAVE
10588 && (next_rela
.get_r_offset()
10589 == rela
.get_r_offset() + 4))
10593 localentry0
= ent
->localentry0_
;
10594 has_stub_value
= true;
10598 // We don't care too much about bogus debug references to
10599 // non-local functions, but otherwise there had better be a plt
10600 // call stub or global entry stub as appropriate.
10601 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10604 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10605 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10606 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10608 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10610 value
= target
->plt_off(gsym
, &plt
);
10612 value
= target
->plt_off(object
, r_sym
, &plt
);
10613 value
+= plt
->address();
10617 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10618 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10619 value
-= (target
->got_section()->output_section()->address()
10620 + object
->toc_base_offset());
10622 else if (parameters
->options().output_is_position_independent())
10624 if (rela
.get_r_addend() >= 32768)
10626 unsigned int got2
= object
->got2_shndx();
10627 value
-= (object
->get_output_section_offset(got2
)
10628 + object
->output_section(got2
)->address()
10629 + rela
.get_r_addend());
10632 value
-= (target
->got_section()->address()
10633 + target
->got_section()->g_o_t());
10636 else if (!has_plt_offset
10637 && (is_plt16_reloc
<size
>(r_type
)
10638 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10639 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10641 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10642 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10643 r_type
= elfcpp::R_POWERPC_NONE
;
10645 else if (!has_plt_offset
10646 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10647 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10649 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10650 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10651 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10652 r_type
= elfcpp::R_POWERPC_NONE
;
10654 else if (is_got_reloc(r_type
))
10658 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10659 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10663 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10664 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10666 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10667 value
+= target
->got_section()->address();
10669 value
-= target
->got_section()->got_base_offset(object
);
10671 else if (r_type
== elfcpp::R_PPC64_TOC
)
10673 value
= (target
->got_section()->output_section()->address()
10674 + object
->toc_base_offset());
10676 else if (gsym
!= NULL
10677 && (r_type
== elfcpp::R_POWERPC_REL24
10678 || r_type
== elfcpp::R_PPC_PLTREL24
)
10683 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10684 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10685 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10686 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10688 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10689 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10690 if ((insn
& 1) != 0
10692 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10694 elfcpp::Swap
<32, big_endian
>::
10695 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10696 can_plt_call
= true;
10701 // If we don't have a branch and link followed by a nop,
10702 // we can't go via the plt because there is no place to
10703 // put a toc restoring instruction.
10704 // Unless we know we won't be returning.
10705 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10706 can_plt_call
= true;
10710 // g++ as of 20130507 emits self-calls without a
10711 // following nop. This is arguably wrong since we have
10712 // conflicting information. On the one hand a global
10713 // symbol and on the other a local call sequence, but
10714 // don't error for this special case.
10715 // It isn't possible to cheaply verify we have exactly
10716 // such a call. Allow all calls to the same section.
10718 Address code
= value
;
10719 if (gsym
->source() == Symbol::FROM_OBJECT
10720 && gsym
->object() == object
)
10722 unsigned int dest_shndx
= 0;
10723 if (target
->abiversion() < 2)
10725 Address addend
= rela
.get_r_addend();
10726 code
= psymval
->value(object
, addend
);
10727 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10728 &code
, &dest_shndx
);
10731 if (dest_shndx
== 0)
10732 dest_shndx
= gsym
->shndx(&is_ordinary
);
10733 ok
= dest_shndx
== relinfo
->data_shndx
;
10737 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10738 _("call lacks nop, can't restore toc; "
10739 "recompile with -fPIC"));
10745 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10746 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10747 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10748 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10749 || r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10751 // First instruction of a global dynamic sequence, arg setup insn.
10752 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
10753 if (!object
->no_tls_marker())
10755 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10756 tls_type
= target
->optimize_tls_gd(final
);
10758 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10759 if (tls_type
== tls::TLSOPT_NONE
)
10760 got_type
= GOT_TYPE_TLSGD
;
10761 else if (tls_type
== tls::TLSOPT_TO_IE
)
10762 got_type
= GOT_TYPE_TPREL
;
10763 if (got_type
!= GOT_TYPE_STANDARD
)
10767 gold_assert(gsym
->has_got_offset(got_type
));
10768 value
= gsym
->got_offset(got_type
);
10772 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10773 value
= object
->local_got_offset(r_sym
, got_type
);
10775 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10776 value
+= target
->got_section()->address();
10778 value
-= target
->got_section()->got_base_offset(object
);
10780 if (tls_type
== tls::TLSOPT_TO_IE
)
10782 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10784 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10785 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10787 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10789 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10790 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10791 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10792 pinsn
& 0xffffffff);
10793 r_type
= elfcpp::R_PPC64_GOT_TPREL_PCREL34
;
10797 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10798 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10800 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10801 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10802 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10804 insn
|= 32 << 26; // lwz
10806 insn
|= 58 << 26; // ld
10807 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10809 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10810 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10813 else if (tls_type
== tls::TLSOPT_TO_LE
)
10815 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD_PCREL34
)
10817 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10818 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10820 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10821 // pla pcrel -> paddi r13
10822 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10823 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10824 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10825 pinsn
& 0xffffffff);
10826 r_type
= elfcpp::R_PPC64_TPREL34
;
10827 value
= psymval
->value(object
, rela
.get_r_addend());
10831 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10832 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10834 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10835 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10836 insn
&= (1 << 26) - (1 << 21); // extract rt
10840 insn
|= addis_0_13
;
10841 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10842 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10843 value
= psymval
->value(object
, rela
.get_r_addend());
10847 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10849 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10850 r_type
= elfcpp::R_POWERPC_NONE
;
10855 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10856 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10857 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10858 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10859 || r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10861 // First instruction of a local dynamic sequence, arg setup insn.
10862 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
10863 if (!object
->no_tls_marker())
10864 tls_type
= target
->optimize_tls_ld();
10865 if (tls_type
== tls::TLSOPT_NONE
)
10867 value
= target
->tlsld_got_offset();
10868 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10869 value
+= target
->got_section()->address();
10871 value
-= target
->got_section()->got_base_offset(object
);
10875 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10876 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD_PCREL34
)
10878 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10879 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10881 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10882 // pla pcrel -> paddi r13
10883 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10884 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10885 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10886 pinsn
& 0xffffffff);
10887 r_type
= elfcpp::R_PPC64_TPREL34
;
10888 value
= dtp_offset
;
10890 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10891 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10893 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10894 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10895 insn
&= (1 << 26) - (1 << 21); // extract rt
10899 insn
|= addis_0_13
;
10900 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10901 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10902 value
= dtp_offset
;
10906 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10908 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10909 r_type
= elfcpp::R_POWERPC_NONE
;
10913 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10914 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10915 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10916 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10917 || r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10919 // Accesses relative to a local dynamic sequence address,
10920 // no optimisation here.
10923 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10924 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10928 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10929 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10931 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL_PCREL34
)
10932 value
+= target
->got_section()->address();
10934 value
-= target
->got_section()->got_base_offset(object
);
10936 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10937 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10938 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10939 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10940 || r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10942 // First instruction of initial exec sequence.
10943 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10944 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10945 if (tls_type
== tls::TLSOPT_NONE
)
10949 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10950 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10954 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10955 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10957 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10958 value
+= target
->got_section()->address();
10960 value
-= target
->got_section()->got_base_offset(object
);
10964 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10965 if (r_type
== elfcpp::R_PPC64_GOT_TPREL_PCREL34
)
10967 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10968 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10970 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10971 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10972 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10973 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10974 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10975 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10976 pinsn
& 0xffffffff);
10977 r_type
= elfcpp::R_PPC64_TPREL34
;
10978 value
= psymval
->value(object
, rela
.get_r_addend());
10980 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10981 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10983 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10984 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10985 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10989 insn
|= addis_0_13
;
10990 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10991 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10992 value
= psymval
->value(object
, rela
.get_r_addend());
10996 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10998 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10999 r_type
= elfcpp::R_POWERPC_NONE
;
11003 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11004 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11006 // Second instruction of a global dynamic sequence,
11007 // the __tls_get_addr call
11008 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11009 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
11010 if (!object
->no_tls_marker())
11012 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11013 tls_type
= target
->optimize_tls_gd(final
);
11015 if (tls_type
!= tls::TLSOPT_NONE
)
11017 if (tls_type
== tls::TLSOPT_TO_IE
)
11019 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11020 Insn insn
= add_3_3_13
;
11023 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11024 r_type
= elfcpp::R_POWERPC_NONE
;
11028 bool is_pcrel
= false;
11029 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11030 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11031 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11032 if (relnum
< reloc_count
- 1)
11034 Reltype
next_rela(preloc
+ reloc_size
);
11035 unsigned int r_type2
11036 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11037 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11038 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11039 && next_rela
.get_r_offset() == rela
.get_r_offset())
11042 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11045 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11046 r_type
= elfcpp::R_POWERPC_NONE
;
11050 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11051 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11053 value
= psymval
->value(object
, rela
.get_r_addend());
11056 this->skip_next_tls_get_addr_call();
11059 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11060 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11062 // Second instruction of a local dynamic sequence,
11063 // the __tls_get_addr call
11064 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
11065 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
11066 if (!object
->no_tls_marker())
11067 tls_type
= target
->optimize_tls_ld();
11068 if (tls_type
== tls::TLSOPT_TO_LE
)
11070 bool is_pcrel
= false;
11071 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11072 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11073 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11074 if (relnum
< reloc_count
- 1)
11076 Reltype
next_rela(preloc
+ reloc_size
);
11077 unsigned int r_type2
11078 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
11079 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
11080 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11081 && next_rela
.get_r_offset() == rela
.get_r_offset())
11084 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11087 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11088 r_type
= elfcpp::R_POWERPC_NONE
;
11092 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
11093 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11095 value
= dtp_offset
;
11097 this->skip_next_tls_get_addr_call();
11100 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11102 // Second instruction of an initial exec sequence
11103 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11104 tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
11105 if (tls_type
== tls::TLSOPT_TO_LE
)
11107 Address roff
= rela
.get_r_offset() & 3;
11108 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
11109 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11110 unsigned int reg
= size
== 32 ? 2 : 13;
11111 insn
= at_tls_transform(insn
, reg
);
11112 gold_assert(insn
!= 0);
11115 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11116 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11118 value
= psymval
->value(object
, rela
.get_r_addend());
11120 else if (roff
== 1)
11122 // For pcrel IE to LE we already have the full offset
11123 // and thus don't need an addi here. A nop or mr will do.
11124 if ((insn
& (0x3f << 26)) == 14 << 26)
11126 // Extract regs from addi rt,ra,si.
11127 unsigned int rt
= (insn
>> 21) & 0x1f;
11128 unsigned int ra
= (insn
>> 16) & 0x1f;
11133 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
11134 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
11135 insn
|= (31u << 26) | (444u << 1);
11138 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11139 r_type
= elfcpp::R_POWERPC_NONE
;
11143 else if (!has_stub_value
)
11145 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
11146 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
11148 // PLTCALL without plt entry => convert to direct call
11149 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11150 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11151 insn
= (insn
& 1) | b
;
11152 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11154 r_type
= elfcpp::R_PPC_PLTREL24
;
11155 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
11156 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
11158 r_type
= elfcpp::R_POWERPC_REL24
;
11160 Address addend
= 0;
11162 && (r_type
== elfcpp::R_PPC_PLTREL24
11163 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11164 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11165 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
11166 addend
= rela
.get_r_addend();
11167 value
= psymval
->value(object
, addend
);
11168 unsigned int local_ent
= 0;
11169 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
11171 if (target
->abiversion() >= 2)
11174 local_ent
= object
->ppc64_local_entry_offset(gsym
);
11176 local_ent
= object
->ppc64_local_entry_offset(r_sym
);
11180 unsigned int dest_shndx
;
11181 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
11182 &value
, &dest_shndx
);
11185 Address max_branch
= max_branch_delta
<size
>(r_type
);
11186 if (max_branch
!= 0
11187 && (value
+ local_ent
- address
+ max_branch
>= 2 * max_branch
11189 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
11191 ? object
->ppc64_needs_toc(gsym
)
11192 : object
->ppc64_needs_toc(r_sym
)))))
11194 Stub_table
<size
, big_endian
>* stub_table
11195 = object
->stub_table(relinfo
->data_shndx
);
11196 if (stub_table
!= NULL
)
11198 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
11199 = stub_table
->find_long_branch_entry(object
, value
);
11202 if (ent
->save_res_
)
11203 value
= (value
- target
->savres_section()->address()
11204 + stub_table
->branch_size());
11207 value
= (stub_table
->stub_address()
11208 + stub_table
->plt_size()
11211 && r_type
!= elfcpp::R_PPC64_REL24_NOTOC
)
11212 value
+= ent
->tocoff_
;
11214 has_stub_value
= true;
11218 if (!has_stub_value
)
11219 value
+= local_ent
;
11224 case elfcpp::R_PPC64_REL24_NOTOC
:
11228 case elfcpp::R_PPC64_REL64
:
11229 case elfcpp::R_POWERPC_REL32
:
11230 case elfcpp::R_POWERPC_REL24
:
11231 case elfcpp::R_PPC_PLTREL24
:
11232 case elfcpp::R_PPC_LOCAL24PC
:
11233 case elfcpp::R_POWERPC_REL16
:
11234 case elfcpp::R_POWERPC_REL16_LO
:
11235 case elfcpp::R_POWERPC_REL16_HI
:
11236 case elfcpp::R_POWERPC_REL16_HA
:
11237 case elfcpp::R_POWERPC_REL16DX_HA
:
11238 case elfcpp::R_PPC64_REL16_HIGH
:
11239 case elfcpp::R_PPC64_REL16_HIGHA
:
11240 case elfcpp::R_PPC64_REL16_HIGHER
:
11241 case elfcpp::R_PPC64_REL16_HIGHERA
:
11242 case elfcpp::R_PPC64_REL16_HIGHEST
:
11243 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11244 case elfcpp::R_POWERPC_REL14
:
11245 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11246 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11247 case elfcpp::R_PPC64_PCREL34
:
11248 case elfcpp::R_PPC64_GOT_PCREL34
:
11249 case elfcpp::R_PPC64_PLT_PCREL34
:
11250 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11251 case elfcpp::R_PPC64_PCREL28
:
11252 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11253 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11254 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11255 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11256 case elfcpp::R_PPC64_REL16_HIGHER34
:
11257 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11258 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11259 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11263 case elfcpp::R_PPC64_TOC16
:
11264 case elfcpp::R_PPC64_TOC16_LO
:
11265 case elfcpp::R_PPC64_TOC16_HI
:
11266 case elfcpp::R_PPC64_TOC16_HA
:
11267 case elfcpp::R_PPC64_TOC16_DS
:
11268 case elfcpp::R_PPC64_TOC16_LO_DS
:
11269 // Subtract the TOC base address.
11270 value
-= (target
->got_section()->output_section()->address()
11271 + object
->toc_base_offset());
11274 case elfcpp::R_POWERPC_SECTOFF
:
11275 case elfcpp::R_POWERPC_SECTOFF_LO
:
11276 case elfcpp::R_POWERPC_SECTOFF_HI
:
11277 case elfcpp::R_POWERPC_SECTOFF_HA
:
11278 case elfcpp::R_PPC64_SECTOFF_DS
:
11279 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11281 value
-= os
->address();
11284 case elfcpp::R_PPC64_TPREL16_DS
:
11285 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11286 case elfcpp::R_PPC64_TPREL16_HIGH
:
11287 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11289 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
11292 case elfcpp::R_POWERPC_TPREL16
:
11293 case elfcpp::R_POWERPC_TPREL16_LO
:
11294 case elfcpp::R_POWERPC_TPREL16_HI
:
11295 case elfcpp::R_POWERPC_TPREL16_HA
:
11296 case elfcpp::R_POWERPC_TPREL
:
11297 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11298 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11299 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11300 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11301 case elfcpp::R_PPC64_TPREL34
:
11302 // tls symbol values are relative to tls_segment()->vaddr()
11303 value
-= tp_offset
;
11306 case elfcpp::R_PPC64_DTPREL16_DS
:
11307 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11308 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11309 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11310 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11311 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11313 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
11314 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
11317 case elfcpp::R_POWERPC_DTPREL16
:
11318 case elfcpp::R_POWERPC_DTPREL16_LO
:
11319 case elfcpp::R_POWERPC_DTPREL16_HI
:
11320 case elfcpp::R_POWERPC_DTPREL16_HA
:
11321 case elfcpp::R_POWERPC_DTPREL
:
11322 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11323 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11324 case elfcpp::R_PPC64_DTPREL34
:
11325 // tls symbol values are relative to tls_segment()->vaddr()
11326 value
-= dtp_offset
;
11329 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11331 value
+= object
->ppc64_local_entry_offset(gsym
);
11333 value
+= object
->ppc64_local_entry_offset(r_sym
);
11340 Insn branch_bit
= 0;
11343 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11344 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11345 branch_bit
= 1 << 21;
11347 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11348 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11350 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11351 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11352 insn
&= ~(1 << 21);
11353 insn
|= branch_bit
;
11354 if (this->is_isa_v2
)
11356 // Set 'a' bit. This is 0b00010 in BO field for branch
11357 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
11358 // for branch on CTR insns (BO == 1a00t or 1a01t).
11359 if ((insn
& (0x14 << 21)) == (0x04 << 21))
11360 insn
|= 0x02 << 21;
11361 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
11362 insn
|= 0x08 << 21;
11368 // Invert 'y' bit if not the default.
11369 if (static_cast<Signed_address
>(value
) < 0)
11372 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11376 case elfcpp::R_POWERPC_PLT16_HA
:
11378 && !parameters
->options().output_is_position_independent())
11380 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11381 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11383 // Convert addis to lis.
11384 if ((insn
& (0x3f << 26)) == 15u << 26
11385 && (insn
& (0x1f << 16)) != 0)
11387 insn
&= ~(0x1f << 16);
11388 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11398 ? relative_value_is_known(gsym
)
11399 : relative_value_is_known(psymval
))
11404 uint64_t pinsn
, pinsn2
;
11411 // Multi-instruction sequences that access the GOT/TOC can
11412 // be optimized, eg.
11413 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
11414 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
11416 // addis ra,r2,0; addi rb,ra,x@toc@l;
11417 // to nop; addi rb,r2,x@toc;
11418 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11419 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11420 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11421 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11422 case elfcpp::R_POWERPC_GOT16_HA
:
11423 case elfcpp::R_PPC64_TOC16_HA
:
11424 if (size
== 64 && parameters
->options().toc_optimize())
11426 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11427 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11428 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
11429 && object
->make_toc_relative(target
, &value
))
11430 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
11431 && object
->make_got_relative(target
, psymval
,
11432 rela
.get_r_addend(),
11435 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
11436 == ((15u << 26) | (2 << 16)));
11438 if (((insn
& ((0x3f << 26) | 0x1f << 16))
11439 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
11440 && value
+ 0x8000 < 0x10000)
11442 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11448 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11449 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11450 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11451 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11452 case elfcpp::R_POWERPC_GOT16_LO
:
11453 case elfcpp::R_PPC64_GOT16_LO_DS
:
11454 case elfcpp::R_PPC64_TOC16_LO
:
11455 case elfcpp::R_PPC64_TOC16_LO_DS
:
11456 if (size
== 64 && parameters
->options().toc_optimize())
11458 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11459 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11460 bool changed
= false;
11461 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
11462 && object
->make_toc_relative(target
, &value
))
11463 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
11464 && object
->make_got_relative(target
, psymval
,
11465 rela
.get_r_addend(),
11468 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
11469 insn
^= (14u << 26) ^ (58u << 26);
11470 r_type
= elfcpp::R_PPC64_TOC16_LO
;
11473 if (ok_lo_toc_insn(insn
, r_type
)
11474 && value
+ 0x8000 < 0x10000)
11476 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
11478 // Transform addic to addi when we change reg.
11479 insn
&= ~((0x3f << 26) | (0x1f << 16));
11480 insn
|= (14u << 26) | (2 << 16);
11484 insn
&= ~(0x1f << 16);
11490 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11494 case elfcpp::R_PPC64_GOT_PCREL34
:
11495 if (size
== 64 && parameters
->options().toc_optimize())
11497 iview
= reinterpret_cast<Insn
*>(view
);
11498 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11500 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11501 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11502 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
11505 Address relval
= psymval
->value(object
, rela
.get_r_addend());
11507 if (relval
+ (1ULL << 33) < 1ULL << 34)
11510 // Replace with paddi
11511 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
11512 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11513 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11514 pinsn
& 0xffffffff);
11520 case elfcpp::R_PPC64_PCREL34
:
11523 iview
= reinterpret_cast<Insn
*>(view
);
11524 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11526 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11527 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11528 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11529 | (14ULL << 26) /* paddi */))
11533 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11534 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11535 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11536 if (relnum
>= reloc_count
- 1)
11539 Reltype
next_rela(preloc
+ reloc_size
);
11540 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11541 != elfcpp::R_PPC64_PCREL_OPT
)
11542 || next_rela
.get_r_offset() != rela
.get_r_offset())
11545 Address off
= next_rela
.get_r_addend();
11547 off
= 8; // zero means next insn.
11548 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11551 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11552 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11554 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11556 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11558 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11559 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11560 pinsn
& 0xffffffff);
11561 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11566 case elfcpp::R_POWERPC_TPREL16_HA
:
11567 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11569 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11570 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11575 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11577 // R_PPC_TLSGD, R_PPC_TLSLD
11580 case elfcpp::R_POWERPC_TPREL16_LO
:
11581 if (target
->tprel_opt() && value
+ 0x8000 < 0x10000)
11583 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11584 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11585 insn
&= ~(0x1f << 16);
11586 insn
|= (size
== 32 ? 2 : 13) << 16;
11587 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11591 case elfcpp::R_PPC64_ENTRY
:
11594 value
= (target
->got_section()->output_section()->address()
11595 + object
->toc_base_offset());
11596 if (value
+ 0x80008000 <= 0xffffffff
11597 && !parameters
->options().output_is_position_independent())
11599 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11600 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11601 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11603 if ((insn1
& ~0xfffc) == ld_2_12
11604 && insn2
== add_2_2_12
)
11606 insn1
= lis_2
+ ha(value
);
11607 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11608 insn2
= addi_2_2
+ l(value
);
11609 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11616 if (value
+ 0x80008000 <= 0xffffffff)
11618 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11619 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11620 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11622 if ((insn1
& ~0xfffc) == ld_2_12
11623 && insn2
== add_2_2_12
)
11625 insn1
= addis_2_12
+ ha(value
);
11626 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11627 insn2
= addi_2_2
+ l(value
);
11628 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11636 case elfcpp::R_POWERPC_REL16_LO
:
11637 // If we are generating a non-PIC executable, edit
11638 // 0: addis 2,12,.TOC.-0b@ha
11639 // addi 2,2,.TOC.-0b@l
11640 // used by ELFv2 global entry points to set up r2, to
11642 // addi 2,2,.TOC.@l
11643 // if .TOC. is in range. */
11645 && value
+ address
- 4 + 0x80008000 <= 0xffffffff
11648 && target
->abiversion() >= 2
11649 && !parameters
->options().output_is_position_independent()
11650 && rela
.get_r_addend() == d_offset
+ 4
11652 && strcmp(gsym
->name(), ".TOC.") == 0)
11654 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11655 Reltype
prev_rela(preloc
- reloc_size
);
11656 if ((prev_rela
.get_r_info()
11657 == elfcpp::elf_r_info
<size
>(r_sym
,
11658 elfcpp::R_POWERPC_REL16_HA
))
11659 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11660 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11662 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11663 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11664 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11666 if ((insn1
& 0xffff0000) == addis_2_12
11667 && (insn2
& 0xffff0000) == addi_2_2
)
11669 insn1
= lis_2
+ ha(value
+ address
- 4);
11670 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11671 insn2
= addi_2_2
+ l(value
+ address
- 4);
11672 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11675 relinfo
->rr
->set_strategy(relnum
- 1,
11676 Relocatable_relocs::RELOC_SPECIAL
);
11677 relinfo
->rr
->set_strategy(relnum
,
11678 Relocatable_relocs::RELOC_SPECIAL
);
11688 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11689 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11692 case elfcpp::R_POWERPC_ADDR32
:
11693 case elfcpp::R_POWERPC_UADDR32
:
11695 overflow
= Reloc::CHECK_BITFIELD
;
11698 case elfcpp::R_POWERPC_REL32
:
11699 case elfcpp::R_POWERPC_REL16DX_HA
:
11701 overflow
= Reloc::CHECK_SIGNED
;
11704 case elfcpp::R_POWERPC_UADDR16
:
11705 overflow
= Reloc::CHECK_BITFIELD
;
11708 case elfcpp::R_POWERPC_ADDR16
:
11709 // We really should have three separate relocations,
11710 // one for 16-bit data, one for insns with 16-bit signed fields,
11711 // and one for insns with 16-bit unsigned fields.
11712 overflow
= Reloc::CHECK_BITFIELD
;
11713 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11714 overflow
= Reloc::CHECK_LOW_INSN
;
11717 case elfcpp::R_POWERPC_ADDR16_HI
:
11718 case elfcpp::R_POWERPC_ADDR16_HA
:
11719 case elfcpp::R_POWERPC_GOT16_HI
:
11720 case elfcpp::R_POWERPC_GOT16_HA
:
11721 case elfcpp::R_POWERPC_PLT16_HI
:
11722 case elfcpp::R_POWERPC_PLT16_HA
:
11723 case elfcpp::R_POWERPC_SECTOFF_HI
:
11724 case elfcpp::R_POWERPC_SECTOFF_HA
:
11725 case elfcpp::R_PPC64_TOC16_HI
:
11726 case elfcpp::R_PPC64_TOC16_HA
:
11727 case elfcpp::R_PPC64_PLTGOT16_HI
:
11728 case elfcpp::R_PPC64_PLTGOT16_HA
:
11729 case elfcpp::R_POWERPC_TPREL16_HI
:
11730 case elfcpp::R_POWERPC_TPREL16_HA
:
11731 case elfcpp::R_POWERPC_DTPREL16_HI
:
11732 case elfcpp::R_POWERPC_DTPREL16_HA
:
11733 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11734 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11735 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11736 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11737 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11738 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11739 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11740 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11741 case elfcpp::R_POWERPC_REL16_HI
:
11742 case elfcpp::R_POWERPC_REL16_HA
:
11744 overflow
= Reloc::CHECK_HIGH_INSN
;
11747 case elfcpp::R_POWERPC_REL16
:
11748 case elfcpp::R_PPC64_TOC16
:
11749 case elfcpp::R_POWERPC_GOT16
:
11750 case elfcpp::R_POWERPC_SECTOFF
:
11751 case elfcpp::R_POWERPC_TPREL16
:
11752 case elfcpp::R_POWERPC_DTPREL16
:
11753 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11754 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11755 case elfcpp::R_POWERPC_GOT_TPREL16
:
11756 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11757 overflow
= Reloc::CHECK_LOW_INSN
;
11760 case elfcpp::R_PPC64_REL24_NOTOC
:
11764 case elfcpp::R_POWERPC_ADDR24
:
11765 case elfcpp::R_POWERPC_ADDR14
:
11766 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11767 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11768 case elfcpp::R_PPC64_ADDR16_DS
:
11769 case elfcpp::R_POWERPC_REL24
:
11770 case elfcpp::R_PPC_PLTREL24
:
11771 case elfcpp::R_PPC_LOCAL24PC
:
11772 case elfcpp::R_PPC64_TPREL16_DS
:
11773 case elfcpp::R_PPC64_DTPREL16_DS
:
11774 case elfcpp::R_PPC64_TOC16_DS
:
11775 case elfcpp::R_PPC64_GOT16_DS
:
11776 case elfcpp::R_PPC64_SECTOFF_DS
:
11777 case elfcpp::R_POWERPC_REL14
:
11778 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11779 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11780 case elfcpp::R_PPC64_D34
:
11781 case elfcpp::R_PPC64_PCREL34
:
11782 case elfcpp::R_PPC64_GOT_PCREL34
:
11783 case elfcpp::R_PPC64_PLT_PCREL34
:
11784 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11785 case elfcpp::R_PPC64_D28
:
11786 case elfcpp::R_PPC64_PCREL28
:
11787 case elfcpp::R_PPC64_TPREL34
:
11788 case elfcpp::R_PPC64_DTPREL34
:
11789 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
11790 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
11791 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
11792 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
11793 overflow
= Reloc::CHECK_SIGNED
;
11797 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11800 if (overflow
== Reloc::CHECK_LOW_INSN
11801 || overflow
== Reloc::CHECK_HIGH_INSN
)
11803 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11805 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11806 overflow
= Reloc::CHECK_BITFIELD
;
11807 else if (overflow
== Reloc::CHECK_LOW_INSN
11808 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11809 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11810 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11811 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11812 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11813 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11814 overflow
= Reloc::CHECK_UNSIGNED
;
11816 overflow
= Reloc::CHECK_SIGNED
;
11819 bool maybe_dq_reloc
= false;
11820 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11821 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11824 case elfcpp::R_POWERPC_NONE
:
11825 case elfcpp::R_POWERPC_TLS
:
11826 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11827 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11828 case elfcpp::R_POWERPC_PLTSEQ
:
11829 case elfcpp::R_POWERPC_PLTCALL
:
11830 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11831 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11832 case elfcpp::R_PPC64_PCREL_OPT
:
11835 case elfcpp::R_PPC64_ADDR64
:
11836 case elfcpp::R_PPC64_REL64
:
11837 case elfcpp::R_PPC64_TOC
:
11838 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11839 Reloc::addr64(view
, value
);
11842 case elfcpp::R_POWERPC_TPREL
:
11843 case elfcpp::R_POWERPC_DTPREL
:
11845 Reloc::addr64(view
, value
);
11847 status
= Reloc::addr32(view
, value
, overflow
);
11850 case elfcpp::R_PPC64_UADDR64
:
11851 Reloc::addr64_u(view
, value
);
11854 case elfcpp::R_POWERPC_ADDR32
:
11855 status
= Reloc::addr32(view
, value
, overflow
);
11858 case elfcpp::R_POWERPC_REL32
:
11859 case elfcpp::R_POWERPC_UADDR32
:
11860 status
= Reloc::addr32_u(view
, value
, overflow
);
11863 case elfcpp::R_PPC64_REL24_NOTOC
:
11865 goto unsupp
; // R_PPC_EMB_RELSDA
11867 case elfcpp::R_POWERPC_ADDR24
:
11868 case elfcpp::R_POWERPC_REL24
:
11869 case elfcpp::R_PPC_PLTREL24
:
11870 case elfcpp::R_PPC_LOCAL24PC
:
11871 status
= Reloc::addr24(view
, value
, overflow
);
11874 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11875 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11876 case elfcpp::R_POWERPC_GOT_TPREL16
:
11877 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11880 // On ppc64 these are all ds form
11881 maybe_dq_reloc
= true;
11885 case elfcpp::R_POWERPC_ADDR16
:
11886 case elfcpp::R_POWERPC_REL16
:
11887 case elfcpp::R_PPC64_TOC16
:
11888 case elfcpp::R_POWERPC_GOT16
:
11889 case elfcpp::R_POWERPC_SECTOFF
:
11890 case elfcpp::R_POWERPC_TPREL16
:
11891 case elfcpp::R_POWERPC_DTPREL16
:
11892 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11893 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11894 case elfcpp::R_POWERPC_ADDR16_LO
:
11895 case elfcpp::R_POWERPC_REL16_LO
:
11896 case elfcpp::R_PPC64_TOC16_LO
:
11897 case elfcpp::R_POWERPC_GOT16_LO
:
11898 case elfcpp::R_POWERPC_PLT16_LO
:
11899 case elfcpp::R_POWERPC_SECTOFF_LO
:
11900 case elfcpp::R_POWERPC_TPREL16_LO
:
11901 case elfcpp::R_POWERPC_DTPREL16_LO
:
11902 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11903 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11905 status
= Reloc::addr16(view
, value
, overflow
);
11907 maybe_dq_reloc
= true;
11910 case elfcpp::R_POWERPC_UADDR16
:
11911 status
= Reloc::addr16_u(view
, value
, overflow
);
11914 case elfcpp::R_PPC64_ADDR16_HIGH
:
11915 case elfcpp::R_PPC64_TPREL16_HIGH
:
11916 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11918 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11921 case elfcpp::R_POWERPC_ADDR16_HI
:
11922 case elfcpp::R_POWERPC_REL16_HI
:
11923 case elfcpp::R_PPC64_REL16_HIGH
:
11924 case elfcpp::R_PPC64_TOC16_HI
:
11925 case elfcpp::R_POWERPC_GOT16_HI
:
11926 case elfcpp::R_POWERPC_PLT16_HI
:
11927 case elfcpp::R_POWERPC_SECTOFF_HI
:
11928 case elfcpp::R_POWERPC_TPREL16_HI
:
11929 case elfcpp::R_POWERPC_DTPREL16_HI
:
11930 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11931 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11932 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11933 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11934 Reloc::addr16_hi(view
, value
);
11937 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11938 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11939 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11941 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11944 case elfcpp::R_POWERPC_ADDR16_HA
:
11945 case elfcpp::R_POWERPC_REL16_HA
:
11946 case elfcpp::R_PPC64_REL16_HIGHA
:
11947 case elfcpp::R_PPC64_TOC16_HA
:
11948 case elfcpp::R_POWERPC_GOT16_HA
:
11949 case elfcpp::R_POWERPC_PLT16_HA
:
11950 case elfcpp::R_POWERPC_SECTOFF_HA
:
11951 case elfcpp::R_POWERPC_TPREL16_HA
:
11952 case elfcpp::R_POWERPC_DTPREL16_HA
:
11953 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11954 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11955 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11956 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11957 Reloc::addr16_ha(view
, value
);
11960 case elfcpp::R_POWERPC_REL16DX_HA
:
11961 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11964 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11966 // R_PPC_EMB_NADDR16_LO
11969 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11970 case elfcpp::R_PPC64_REL16_HIGHER
:
11971 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11972 Reloc::addr16_hi2(view
, value
);
11975 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11977 // R_PPC_EMB_NADDR16_HI
11980 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11981 case elfcpp::R_PPC64_REL16_HIGHERA
:
11982 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11983 Reloc::addr16_ha2(view
, value
);
11986 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11988 // R_PPC_EMB_NADDR16_HA
11991 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11992 case elfcpp::R_PPC64_REL16_HIGHEST
:
11993 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11994 Reloc::addr16_hi3(view
, value
);
11997 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11999 // R_PPC_EMB_SDAI16
12002 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
12003 case elfcpp::R_PPC64_REL16_HIGHESTA
:
12004 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
12005 Reloc::addr16_ha3(view
, value
);
12008 case elfcpp::R_PPC64_DTPREL16_DS
:
12009 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
12011 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
12014 case elfcpp::R_PPC64_TPREL16_DS
:
12015 case elfcpp::R_PPC64_TPREL16_LO_DS
:
12017 // R_PPC_TLSGD, R_PPC_TLSLD
12020 case elfcpp::R_PPC64_ADDR16_DS
:
12021 case elfcpp::R_PPC64_ADDR16_LO_DS
:
12022 case elfcpp::R_PPC64_TOC16_DS
:
12023 case elfcpp::R_PPC64_TOC16_LO_DS
:
12024 case elfcpp::R_PPC64_GOT16_DS
:
12025 case elfcpp::R_PPC64_GOT16_LO_DS
:
12026 case elfcpp::R_PPC64_PLT16_LO_DS
:
12027 case elfcpp::R_PPC64_SECTOFF_DS
:
12028 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
12029 maybe_dq_reloc
= true;
12032 case elfcpp::R_POWERPC_ADDR14
:
12033 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
12034 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
12035 case elfcpp::R_POWERPC_REL14
:
12036 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
12037 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
12038 status
= Reloc::addr14(view
, value
, overflow
);
12041 case elfcpp::R_POWERPC_COPY
:
12042 case elfcpp::R_POWERPC_GLOB_DAT
:
12043 case elfcpp::R_POWERPC_JMP_SLOT
:
12044 case elfcpp::R_POWERPC_RELATIVE
:
12045 case elfcpp::R_POWERPC_DTPMOD
:
12046 case elfcpp::R_PPC64_JMP_IREL
:
12047 case elfcpp::R_POWERPC_IRELATIVE
:
12048 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12049 _("unexpected reloc %u in object file"),
12053 case elfcpp::R_PPC64_TOCSAVE
:
12059 Symbol_location loc
;
12060 loc
.object
= relinfo
->object
;
12061 loc
.shndx
= relinfo
->data_shndx
;
12062 loc
.offset
= rela
.get_r_offset();
12063 const Tocsave_loc
*tocsave
= target
->tocsave_loc();
12064 if (tocsave
->find(loc
) != tocsave
->end())
12066 // If we've generated plt calls using this tocsave, then
12067 // the nop needs to be changed to save r2.
12068 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
12069 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
12070 elfcpp::Swap
<32, big_endian
>::
12071 writeval(iview
, std_2_1
+ target
->stk_toc());
12076 case elfcpp::R_PPC_EMB_SDA2I16
:
12077 case elfcpp::R_PPC_EMB_SDA2REL
:
12080 // R_PPC64_TLSGD, R_PPC64_TLSLD
12083 case elfcpp::R_PPC64_D34
:
12084 case elfcpp::R_PPC64_D34_LO
:
12085 case elfcpp::R_PPC64_PCREL34
:
12086 case elfcpp::R_PPC64_GOT_PCREL34
:
12087 case elfcpp::R_PPC64_PLT_PCREL34
:
12088 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
12089 case elfcpp::R_PPC64_TPREL34
:
12090 case elfcpp::R_PPC64_DTPREL34
:
12091 case elfcpp::R_PPC64_GOT_TLSGD_PCREL34
:
12092 case elfcpp::R_PPC64_GOT_TLSLD_PCREL34
:
12093 case elfcpp::R_PPC64_GOT_TPREL_PCREL34
:
12094 case elfcpp::R_PPC64_GOT_DTPREL_PCREL34
:
12097 status
= Reloc::addr34(view
, value
, overflow
);
12100 case elfcpp::R_PPC64_D34_HI30
:
12103 Reloc::addr34_hi(view
, value
);
12106 case elfcpp::R_PPC64_D34_HA30
:
12109 Reloc::addr34_ha(view
, value
);
12112 case elfcpp::R_PPC64_D28
:
12113 case elfcpp::R_PPC64_PCREL28
:
12116 status
= Reloc::addr28(view
, value
, overflow
);
12119 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
12120 case elfcpp::R_PPC64_REL16_HIGHER34
:
12123 Reloc::addr16_higher34(view
, value
);
12126 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
12127 case elfcpp::R_PPC64_REL16_HIGHERA34
:
12130 Reloc::addr16_highera34(view
, value
);
12133 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
12134 case elfcpp::R_PPC64_REL16_HIGHEST34
:
12137 Reloc::addr16_highest34(view
, value
);
12140 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
12141 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
12144 Reloc::addr16_highesta34(view
, value
);
12147 case elfcpp::R_POWERPC_PLT32
:
12148 case elfcpp::R_POWERPC_PLTREL32
:
12149 case elfcpp::R_PPC_SDAREL16
:
12150 case elfcpp::R_POWERPC_ADDR30
:
12151 case elfcpp::R_PPC64_PLT64
:
12152 case elfcpp::R_PPC64_PLTREL64
:
12153 case elfcpp::R_PPC64_PLTGOT16
:
12154 case elfcpp::R_PPC64_PLTGOT16_LO
:
12155 case elfcpp::R_PPC64_PLTGOT16_HI
:
12156 case elfcpp::R_PPC64_PLTGOT16_HA
:
12157 case elfcpp::R_PPC64_PLTGOT16_DS
:
12158 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
12159 case elfcpp::R_PPC_TOC16
:
12162 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12163 _("unsupported reloc %u"),
12168 if (maybe_dq_reloc
)
12171 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
12173 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
12174 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
12175 && (insn
& 3) == 1))
12176 status
= Reloc::addr16_dq(view
, value
, overflow
);
12177 else if (size
== 64
12178 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
12179 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
12180 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
12181 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
12182 status
= Reloc::addr16_ds(view
, value
, overflow
);
12184 status
= Reloc::addr16(view
, value
, overflow
);
12187 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
12190 && gsym
->is_undefined()
12191 && is_branch_reloc
<size
>(r_type
))))
12193 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
12194 _("relocation overflow"));
12195 if (has_stub_value
)
12196 gold_info(_("try relinking with a smaller --stub-group-size"));
12202 // Relocate section data.
12204 template<int size
, bool big_endian
>
12206 Target_powerpc
<size
, big_endian
>::relocate_section(
12207 const Relocate_info
<size
, big_endian
>* relinfo
,
12208 unsigned int sh_type
,
12209 const unsigned char* prelocs
,
12210 size_t reloc_count
,
12211 Output_section
* output_section
,
12212 bool needs_special_offset_handling
,
12213 unsigned char* view
,
12215 section_size_type view_size
,
12216 const Reloc_symbol_changes
* reloc_symbol_changes
)
12218 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
12219 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
12220 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
12221 Powerpc_comdat_behavior
;
12222 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12225 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12227 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
12228 Powerpc_comdat_behavior
, Classify_reloc
>(
12234 needs_special_offset_handling
,
12238 reloc_symbol_changes
);
12241 template<int size
, bool big_endian
>
12242 class Powerpc_scan_relocatable_reloc
12245 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12246 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12247 static const int sh_type
= elfcpp::SHT_RELA
;
12249 // Return the symbol referred to by the relocation.
12250 static inline unsigned int
12251 get_r_sym(const Reltype
* reloc
)
12252 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
12254 // Return the type of the relocation.
12255 static inline unsigned int
12256 get_r_type(const Reltype
* reloc
)
12257 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
12259 // Return the strategy to use for a local symbol which is not a
12260 // section symbol, given the relocation type.
12261 inline Relocatable_relocs::Reloc_strategy
12262 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
12264 if (r_type
== 0 && r_sym
== 0)
12265 return Relocatable_relocs::RELOC_DISCARD
;
12266 return Relocatable_relocs::RELOC_COPY
;
12269 // Return the strategy to use for a local symbol which is a section
12270 // symbol, given the relocation type.
12271 inline Relocatable_relocs::Reloc_strategy
12272 local_section_strategy(unsigned int, Relobj
*)
12274 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
12277 // Return the strategy to use for a global symbol, given the
12278 // relocation type, the object, and the symbol index.
12279 inline Relocatable_relocs::Reloc_strategy
12280 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
12283 && (r_type
== elfcpp::R_PPC_PLTREL24
12284 || r_type
== elfcpp::R_POWERPC_PLT16_LO
12285 || r_type
== elfcpp::R_POWERPC_PLT16_HI
12286 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
12287 return Relocatable_relocs::RELOC_SPECIAL
;
12288 return Relocatable_relocs::RELOC_COPY
;
12292 // Scan the relocs during a relocatable link.
12294 template<int size
, bool big_endian
>
12296 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
12297 Symbol_table
* symtab
,
12299 Sized_relobj_file
<size
, big_endian
>* object
,
12300 unsigned int data_shndx
,
12301 unsigned int sh_type
,
12302 const unsigned char* prelocs
,
12303 size_t reloc_count
,
12304 Output_section
* output_section
,
12305 bool needs_special_offset_handling
,
12306 size_t local_symbol_count
,
12307 const unsigned char* plocal_symbols
,
12308 Relocatable_relocs
* rr
)
12310 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
12312 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12314 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
12322 needs_special_offset_handling
,
12323 local_symbol_count
,
12328 // Scan the relocs for --emit-relocs.
12330 template<int size
, bool big_endian
>
12332 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
12333 Symbol_table
* symtab
,
12335 Sized_relobj_file
<size
, big_endian
>* object
,
12336 unsigned int data_shndx
,
12337 unsigned int sh_type
,
12338 const unsigned char* prelocs
,
12339 size_t reloc_count
,
12340 Output_section
* output_section
,
12341 bool needs_special_offset_handling
,
12342 size_t local_symbol_count
,
12343 const unsigned char* plocal_syms
,
12344 Relocatable_relocs
* rr
)
12346 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
12348 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
12349 Emit_relocs_strategy
;
12351 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12353 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
12361 needs_special_offset_handling
,
12362 local_symbol_count
,
12367 // Emit relocations for a section.
12368 // This is a modified version of the function by the same name in
12369 // target-reloc.h. Using relocate_special_relocatable for
12370 // R_PPC_PLTREL24 would require duplication of the entire body of the
12371 // loop, so we may as well duplicate the whole thing.
12373 template<int size
, bool big_endian
>
12375 Target_powerpc
<size
, big_endian
>::relocate_relocs(
12376 const Relocate_info
<size
, big_endian
>* relinfo
,
12377 unsigned int sh_type
,
12378 const unsigned char* prelocs
,
12379 size_t reloc_count
,
12380 Output_section
* output_section
,
12381 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
12383 Address view_address
,
12385 unsigned char* reloc_view
,
12386 section_size_type reloc_view_size
)
12388 gold_assert(sh_type
== elfcpp::SHT_RELA
);
12390 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
12391 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
12392 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
12393 // Offset from start of insn to d-field reloc.
12394 const int d_offset
= big_endian
? 2 : 0;
12396 Powerpc_relobj
<size
, big_endian
>* const object
12397 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
12398 const unsigned int local_count
= object
->local_symbol_count();
12399 unsigned int got2_shndx
= object
->got2_shndx();
12400 Address got2_addend
= 0;
12401 if (got2_shndx
!= 0)
12403 got2_addend
= object
->get_output_section_offset(got2_shndx
);
12404 gold_assert(got2_addend
!= invalid_address
);
12407 const bool relocatable
= parameters
->options().relocatable();
12409 unsigned char* pwrite
= reloc_view
;
12410 bool zap_next
= false;
12411 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
12413 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
12414 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
12417 Reltype
reloc(prelocs
);
12418 Reltype_write
reloc_write(pwrite
);
12420 Address offset
= reloc
.get_r_offset();
12421 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
12422 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
12423 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
12424 const unsigned int orig_r_sym
= r_sym
;
12425 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
12426 = reloc
.get_r_addend();
12427 const Symbol
* gsym
= NULL
;
12431 // We could arrange to discard these and other relocs for
12432 // tls optimised sequences in the strategy methods, but for
12433 // now do as BFD ld does.
12434 r_type
= elfcpp::R_POWERPC_NONE
;
12438 // Get the new symbol index.
12439 Output_section
* os
= NULL
;
12440 if (r_sym
< local_count
)
12444 case Relocatable_relocs::RELOC_COPY
:
12445 case Relocatable_relocs::RELOC_SPECIAL
:
12448 r_sym
= object
->symtab_index(r_sym
);
12449 gold_assert(r_sym
!= -1U);
12453 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
12455 // We are adjusting a section symbol. We need to find
12456 // the symbol table index of the section symbol for
12457 // the output section corresponding to input section
12458 // in which this symbol is defined.
12459 gold_assert(r_sym
< local_count
);
12461 unsigned int shndx
=
12462 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
12463 gold_assert(is_ordinary
);
12464 os
= object
->output_section(shndx
);
12465 gold_assert(os
!= NULL
);
12466 gold_assert(os
->needs_symtab_index());
12467 r_sym
= os
->symtab_index();
12472 gold_unreachable();
12477 gsym
= object
->global_symbol(r_sym
);
12478 gold_assert(gsym
!= NULL
);
12479 if (gsym
->is_forwarder())
12480 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
12482 gold_assert(gsym
->has_symtab_index());
12483 r_sym
= gsym
->symtab_index();
12486 // Get the new offset--the location in the output section where
12487 // this relocation should be applied.
12488 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12489 offset
+= offset_in_output_section
;
12492 section_offset_type sot_offset
=
12493 convert_types
<section_offset_type
, Address
>(offset
);
12494 section_offset_type new_sot_offset
=
12495 output_section
->output_offset(object
, relinfo
->data_shndx
,
12497 gold_assert(new_sot_offset
!= -1);
12498 offset
= new_sot_offset
;
12501 // In an object file, r_offset is an offset within the section.
12502 // In an executable or dynamic object, generated by
12503 // --emit-relocs, r_offset is an absolute address.
12506 offset
+= view_address
;
12507 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
12508 offset
-= offset_in_output_section
;
12511 // Handle the reloc addend based on the strategy.
12512 if (strategy
== Relocatable_relocs::RELOC_COPY
)
12514 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12516 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12517 addend
= psymval
->value(object
, addend
);
12518 // In a relocatable link, the symbol value is relative to
12519 // the start of the output section. For a non-relocatable
12520 // link, we need to adjust the addend.
12523 gold_assert(os
!= NULL
);
12524 addend
-= os
->address();
12527 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12531 if (addend
>= 32768)
12532 addend
+= got2_addend
;
12534 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12536 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12537 addend
-= d_offset
;
12539 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12541 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12542 addend
-= d_offset
+ 4;
12546 gold_unreachable();
12550 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12551 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12552 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12553 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12555 // First instruction of a global dynamic sequence,
12557 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
12558 if (!object
->no_tls_marker())
12560 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12561 tls_type
= this->optimize_tls_gd(final
);
12565 case tls::TLSOPT_TO_IE
:
12566 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12567 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12569 case tls::TLSOPT_TO_LE
:
12570 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12571 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12572 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12575 r_type
= elfcpp::R_POWERPC_NONE
;
12576 offset
-= d_offset
;
12583 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12584 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12585 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12586 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12588 // First instruction of a local dynamic sequence,
12590 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
12591 if (!object
->no_tls_marker())
12592 tls_type
= this->optimize_tls_ld();
12593 if (tls_type
== tls::TLSOPT_TO_LE
)
12595 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12596 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12598 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12599 const Output_section
* os
= relinfo
->layout
->tls_segment()
12601 gold_assert(os
!= NULL
);
12602 gold_assert(os
->needs_symtab_index());
12603 r_sym
= os
->symtab_index();
12604 addend
= dtp_offset
;
12608 r_type
= elfcpp::R_POWERPC_NONE
;
12609 offset
-= d_offset
;
12613 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12614 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12615 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12616 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12618 // First instruction of initial exec sequence.
12619 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12620 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12622 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12623 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12624 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12627 r_type
= elfcpp::R_POWERPC_NONE
;
12628 offset
-= d_offset
;
12632 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12633 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12635 // Second instruction of a global dynamic sequence,
12636 // the __tls_get_addr call
12637 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
12638 if (!object
->no_tls_marker())
12640 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12641 tls_type
= this->optimize_tls_gd(final
);
12645 case tls::TLSOPT_TO_IE
:
12646 r_type
= elfcpp::R_POWERPC_NONE
;
12649 case tls::TLSOPT_TO_LE
:
12650 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12651 offset
+= d_offset
;
12658 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12659 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12661 // Second instruction of a local dynamic sequence,
12662 // the __tls_get_addr call
12663 tls::Tls_optimization tls_type
= tls::TLSOPT_NONE
;
12664 if (!object
->no_tls_marker())
12665 tls_type
= this->optimize_tls_ld();
12666 if (tls_type
== tls::TLSOPT_TO_LE
)
12668 const Output_section
* os
= relinfo
->layout
->tls_segment()
12670 gold_assert(os
!= NULL
);
12671 gold_assert(os
->needs_symtab_index());
12672 r_sym
= os
->symtab_index();
12673 addend
= dtp_offset
;
12674 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12675 offset
+= d_offset
;
12679 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12681 // Second instruction of an initial exec sequence
12682 bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12683 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12685 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12686 offset
+= d_offset
;
12691 reloc_write
.put_r_offset(offset
);
12692 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12693 reloc_write
.put_r_addend(addend
);
12695 pwrite
+= reloc_size
;
12698 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12699 == reloc_view_size
);
12702 // Return the value to use for a dynamic symbol which requires special
12703 // treatment. This is how we support equality comparisons of function
12704 // pointers across shared library boundaries, as described in the
12705 // processor specific ABI supplement.
12707 template<int size
, bool big_endian
>
12709 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12713 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12714 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12715 p
!= this->stub_tables_
.end();
12718 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12719 = (*p
)->find_plt_call_entry(gsym
);
12721 return (*p
)->stub_address() + ent
->off_
;
12724 else if (this->abiversion() >= 2)
12726 Address off
= this->glink_section()->find_global_entry(gsym
);
12727 if (off
!= invalid_address
)
12728 return this->glink_section()->global_entry_address() + off
;
12730 gold_unreachable();
12733 // Return the PLT address to use for a local symbol.
12734 template<int size
, bool big_endian
>
12736 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12737 const Relobj
* object
,
12738 unsigned int symndx
) const
12742 const Sized_relobj
<size
, big_endian
>* relobj
12743 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12744 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12745 p
!= this->stub_tables_
.end();
12748 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12749 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12751 return (*p
)->stub_address() + ent
->off_
;
12754 gold_unreachable();
12757 // Return the PLT address to use for a global symbol.
12758 template<int size
, bool big_endian
>
12760 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12761 const Symbol
* gsym
) const
12765 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12766 p
!= this->stub_tables_
.end();
12769 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12770 = (*p
)->find_plt_call_entry(gsym
);
12772 return (*p
)->stub_address() + ent
->off_
;
12775 else if (this->abiversion() >= 2)
12777 Address off
= this->glink_section()->find_global_entry(gsym
);
12778 if (off
!= invalid_address
)
12779 return this->glink_section()->global_entry_address() + off
;
12781 gold_unreachable();
12784 // Return the offset to use for the GOT_INDX'th got entry which is
12785 // for a local tls symbol specified by OBJECT, SYMNDX.
12786 template<int size
, bool big_endian
>
12788 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12789 const Relobj
* object
,
12790 unsigned int symndx
,
12791 unsigned int got_indx
) const
12793 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12794 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12795 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12797 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12798 got_type
<= GOT_TYPE_TPREL
;
12799 got_type
= Got_type(got_type
+ 1))
12800 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12802 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12803 if (got_type
== GOT_TYPE_TLSGD
)
12805 if (off
== got_indx
* (size
/ 8))
12807 if (got_type
== GOT_TYPE_TPREL
)
12810 return -dtp_offset
;
12814 gold_unreachable();
12817 // Return the offset to use for the GOT_INDX'th got entry which is
12818 // for global tls symbol GSYM.
12819 template<int size
, bool big_endian
>
12821 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12823 unsigned int got_indx
) const
12825 if (gsym
->type() == elfcpp::STT_TLS
)
12827 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12828 got_type
<= GOT_TYPE_TPREL
;
12829 got_type
= Got_type(got_type
+ 1))
12830 if (gsym
->has_got_offset(got_type
))
12832 unsigned int off
= gsym
->got_offset(got_type
);
12833 if (got_type
== GOT_TYPE_TLSGD
)
12835 if (off
== got_indx
* (size
/ 8))
12837 if (got_type
== GOT_TYPE_TPREL
)
12840 return -dtp_offset
;
12844 gold_unreachable();
12847 // The selector for powerpc object files.
12849 template<int size
, bool big_endian
>
12850 class Target_selector_powerpc
: public Target_selector
12853 Target_selector_powerpc()
12854 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12857 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12858 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12860 ? (big_endian
? "elf64ppc" : "elf64lppc")
12861 : (big_endian
? "elf32ppc" : "elf32lppc")))
12865 do_instantiate_target()
12866 { return new Target_powerpc
<size
, big_endian
>(); }
12869 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12870 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12871 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12872 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12874 // Instantiate these constants for -O0
12875 template<int size
, bool big_endian
>
12876 const typename Output_data_glink
<size
, big_endian
>::Address
12877 Output_data_glink
<size
, big_endian
>::invalid_address
;
12878 template<int size
, bool big_endian
>
12879 const typename Stub_table
<size
, big_endian
>::Address
12880 Stub_table
<size
, big_endian
>::invalid_address
;
12881 template<int size
, bool big_endian
>
12882 const typename Target_powerpc
<size
, big_endian
>::Address
12883 Target_powerpc
<size
, big_endian
>::invalid_address
;
12885 } // End anonymous namespace.