1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2020 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
44 #include "attributes.h"
51 template<int size
, bool big_endian
>
52 class Output_data_plt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_brlt_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_got_powerpc
;
60 template<int size
, bool big_endian
>
61 class Output_data_glink
;
63 template<int size
, bool big_endian
>
66 template<int size
, bool big_endian
>
67 class Output_data_save_res
;
69 template<int size
, bool big_endian
>
72 struct Stub_table_owner
75 : output_section(NULL
), owner(NULL
)
78 Output_section
* output_section
;
79 const Output_section::Input_section
* owner
;
83 inline bool is_branch_reloc(unsigned int);
86 inline bool is_plt16_reloc(unsigned int);
88 // Counter incremented on every Powerpc_relobj constructed.
89 static uint32_t object_id
= 0;
91 template<int size
, bool big_endian
>
92 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
95 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
96 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
97 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
99 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
100 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
101 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
102 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
103 has_small_toc_reloc_(false), opd_valid_(false),
104 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
105 access_from_map_(), has14_(), stub_table_index_(), st_other_(),
106 attributes_section_data_(NULL
)
108 this->set_abiversion(0);
112 { delete this->attributes_section_data_
; }
114 // Read the symbols then set up st_other vector.
116 do_read_symbols(Read_symbols_data
*);
118 // Arrange to always relocate .toc first.
120 do_relocate_sections(
121 const Symbol_table
* symtab
, const Layout
* layout
,
122 const unsigned char* pshdrs
, Output_file
* of
,
123 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
125 // The .toc section index.
132 // Mark .toc entry at OFF as not optimizable.
134 set_no_toc_opt(Address off
)
136 if (this->no_toc_opt_
.empty())
137 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
140 if (off
< this->no_toc_opt_
.size())
141 this->no_toc_opt_
[off
] = true;
144 // Mark the entire .toc as not optimizable.
148 this->no_toc_opt_
.resize(1);
149 this->no_toc_opt_
[0] = true;
152 // Return true if code using the .toc entry at OFF should not be edited.
154 no_toc_opt(Address off
) const
156 if (this->no_toc_opt_
.empty())
159 if (off
>= this->no_toc_opt_
.size())
161 return this->no_toc_opt_
[off
];
164 // The .got2 section shndx.
169 return this->special_
;
174 // The .opd section shndx.
181 return this->special_
;
184 // Init OPD entry arrays.
186 init_opd(size_t opd_size
)
188 size_t count
= this->opd_ent_ndx(opd_size
);
189 this->opd_ent_
.resize(count
);
192 // Return section and offset of function entry for .opd + R_OFF.
194 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
196 size_t ndx
= this->opd_ent_ndx(r_off
);
197 gold_assert(ndx
< this->opd_ent_
.size());
198 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
200 *value
= this->opd_ent_
[ndx
].off
;
201 return this->opd_ent_
[ndx
].shndx
;
204 // Set section and offset of function entry for .opd + R_OFF.
206 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
208 size_t ndx
= this->opd_ent_ndx(r_off
);
209 gold_assert(ndx
< this->opd_ent_
.size());
210 this->opd_ent_
[ndx
].shndx
= shndx
;
211 this->opd_ent_
[ndx
].off
= value
;
214 // Return discard flag for .opd + R_OFF.
216 get_opd_discard(Address r_off
) const
218 size_t ndx
= this->opd_ent_ndx(r_off
);
219 gold_assert(ndx
< this->opd_ent_
.size());
220 return this->opd_ent_
[ndx
].discard
;
223 // Set discard flag for .opd + R_OFF.
225 set_opd_discard(Address r_off
)
227 size_t ndx
= this->opd_ent_ndx(r_off
);
228 gold_assert(ndx
< this->opd_ent_
.size());
229 this->opd_ent_
[ndx
].discard
= true;
234 { return this->opd_valid_
; }
238 { this->opd_valid_
= true; }
240 // Examine .rela.opd to build info about function entry points.
242 scan_opd_relocs(size_t reloc_count
,
243 const unsigned char* prelocs
,
244 const unsigned char* plocal_syms
);
246 // Returns true if a code sequence loading a TOC entry can be
247 // converted into code calculating a TOC pointer relative offset.
249 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
253 make_got_relative(Target_powerpc
<size
, big_endian
>* target
,
254 const Symbol_value
<size
>* psymval
,
258 // Perform the Sized_relobj_file method, then set up opd info from
261 do_read_relocs(Read_relocs_data
*);
264 do_find_special_sections(Read_symbols_data
* sd
);
266 // Adjust this local symbol value. Return false if the symbol
267 // should be discarded from the output file.
269 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
271 if (size
== 64 && this->opd_shndx() != 0)
274 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
276 if (this->get_opd_discard(lv
->input_value()))
284 { return &this->access_from_map_
; }
286 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
287 // section at DST_OFF.
289 add_reference(Relobj
* src_obj
,
290 unsigned int src_indx
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
293 Section_id
src_id(src_obj
, src_indx
);
294 this->access_from_map_
[dst_off
].insert(src_id
);
297 // Add a reference to the code section specified by the .opd entry
300 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
302 size_t ndx
= this->opd_ent_ndx(dst_off
);
303 if (ndx
>= this->opd_ent_
.size())
304 this->opd_ent_
.resize(ndx
+ 1);
305 this->opd_ent_
[ndx
].gc_mark
= true;
309 process_gc_mark(Symbol_table
* symtab
)
311 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
312 if (this->opd_ent_
[i
].gc_mark
)
314 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
315 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
319 // Return offset in output GOT section that this object will use
320 // as a TOC pointer. Won't be just a constant with multi-toc support.
322 toc_base_offset() const
326 set_has_small_toc_reloc()
327 { has_small_toc_reloc_
= true; }
330 has_small_toc_reloc() const
331 { return has_small_toc_reloc_
; }
334 set_has_14bit_branch(unsigned int shndx
)
336 if (shndx
>= this->has14_
.size())
337 this->has14_
.resize(shndx
+ 1);
338 this->has14_
[shndx
] = true;
342 has_14bit_branch(unsigned int shndx
) const
343 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
346 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
348 if (shndx
>= this->stub_table_index_
.size())
349 this->stub_table_index_
.resize(shndx
+ 1, -1);
350 this->stub_table_index_
[shndx
] = stub_index
;
353 Stub_table
<size
, big_endian
>*
354 stub_table(unsigned int shndx
)
356 if (shndx
< this->stub_table_index_
.size())
358 Target_powerpc
<size
, big_endian
>* target
359 = static_cast<Target_powerpc
<size
, big_endian
>*>(
360 parameters
->sized_target
<size
, big_endian
>());
361 unsigned int indx
= this->stub_table_index_
[shndx
];
362 if (indx
< target
->stub_tables().size())
363 return target
->stub_tables()[indx
];
371 this->stub_table_index_
.clear();
376 { return this->uniq_
; }
380 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
382 // Set ABI version for input and output
384 set_abiversion(int ver
);
387 st_other (unsigned int symndx
) const
389 return this->st_other_
[symndx
];
393 ppc64_local_entry_offset(const Symbol
* sym
) const
394 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
397 ppc64_local_entry_offset(unsigned int symndx
) const
398 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
401 ppc64_needs_toc(const Symbol
* sym
) const
402 { return sym
->nonvis() > 1 << 3; }
405 ppc64_needs_toc(unsigned int symndx
) const
406 { return this->st_other_
[symndx
] > 1 << 5; }
408 // The contents of the .gnu.attributes section if there is one.
409 const Attributes_section_data
*
410 attributes_section_data() const
411 { return this->attributes_section_data_
; }
422 // Return index into opd_ent_ array for .opd entry at OFF.
423 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
424 // apart when the language doesn't use the last 8-byte word, the
425 // environment pointer. Thus dividing the entry section offset by
426 // 16 will give an index into opd_ent_ that works for either layout
427 // of .opd. (It leaves some elements of the vector unused when .opd
428 // entries are spaced 24 bytes apart, but we don't know the spacing
429 // until relocations are processed, and in any case it is possible
430 // for an object to have some entries spaced 16 bytes apart and
431 // others 24 bytes apart.)
433 opd_ent_ndx(size_t off
) const
436 // Per object unique identifier
439 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
440 unsigned int special_
;
442 // For 64-bit the .rela.toc and .toc section shdnx.
443 unsigned int relatoc_
;
446 // For 64-bit, whether this object uses small model relocs to access
448 bool has_small_toc_reloc_
;
450 // Set at the start of gc_process_relocs, when we know opd_ent_
451 // vector is valid. The flag could be made atomic and set in
452 // do_read_relocs with memory_order_release and then tested with
453 // memory_order_acquire, potentially resulting in fewer entries in
458 elfcpp::Elf_Word e_flags_
;
460 // For 64-bit, an array with one entry per 64-bit word in the .toc
461 // section, set if accesses using that word cannot be optimised.
462 std::vector
<bool> no_toc_opt_
;
464 // The first 8-byte word of an OPD entry gives the address of the
465 // entry point of the function. Relocatable object files have a
466 // relocation on this word. The following vector records the
467 // section and offset specified by these relocations.
468 std::vector
<Opd_ent
> opd_ent_
;
470 // References made to this object's .opd section when running
471 // gc_process_relocs for another object, before the opd_ent_ vector
472 // is valid for this object.
473 Access_from access_from_map_
;
475 // Whether input section has a 14-bit branch reloc.
476 std::vector
<bool> has14_
;
478 // The stub table to use for a given input section.
479 std::vector
<unsigned int> stub_table_index_
;
481 // ELF st_other field for local symbols.
482 std::vector
<unsigned char> st_other_
;
484 // Object attributes if there is a .gnu.attributes section.
485 Attributes_section_data
* attributes_section_data_
;
488 template<int size
, bool big_endian
>
489 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
492 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
494 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
495 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
496 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
497 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
498 attributes_section_data_(NULL
)
500 this->set_abiversion(0);
504 { delete this->attributes_section_data_
; }
506 // Call Sized_dynobj::do_read_symbols to read the symbols then
507 // read .opd from a dynamic object, filling in opd_ent_ vector,
509 do_read_symbols(Read_symbols_data
*);
511 // The .opd section shndx.
515 return this->opd_shndx_
;
518 // The .opd section address.
522 return this->opd_address_
;
525 // Init OPD entry arrays.
527 init_opd(size_t opd_size
)
529 size_t count
= this->opd_ent_ndx(opd_size
);
530 this->opd_ent_
.resize(count
);
533 // Return section and offset of function entry for .opd + R_OFF.
535 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
537 size_t ndx
= this->opd_ent_ndx(r_off
);
538 gold_assert(ndx
< this->opd_ent_
.size());
539 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
541 *value
= this->opd_ent_
[ndx
].off
;
542 return this->opd_ent_
[ndx
].shndx
;
545 // Set section and offset of function entry for .opd + R_OFF.
547 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
549 size_t ndx
= this->opd_ent_ndx(r_off
);
550 gold_assert(ndx
< this->opd_ent_
.size());
551 this->opd_ent_
[ndx
].shndx
= shndx
;
552 this->opd_ent_
[ndx
].off
= value
;
557 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
559 // Set ABI version for input and output.
561 set_abiversion(int ver
);
563 // The contents of the .gnu.attributes section if there is one.
564 const Attributes_section_data
*
565 attributes_section_data() const
566 { return this->attributes_section_data_
; }
569 // Used to specify extent of executable sections.
572 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
573 : start(start_
), len(len_
), shndx(shndx_
)
577 operator<(const Sec_info
& that
) const
578 { return this->start
< that
.start
; }
591 // Return index into opd_ent_ array for .opd entry at OFF.
593 opd_ent_ndx(size_t off
) const
596 // For 64-bit the .opd section shndx and address.
597 unsigned int opd_shndx_
;
598 Address opd_address_
;
601 elfcpp::Elf_Word e_flags_
;
603 // The first 8-byte word of an OPD entry gives the address of the
604 // entry point of the function. Records the section and offset
605 // corresponding to the address. Note that in dynamic objects,
606 // offset is *not* relative to the section.
607 std::vector
<Opd_ent
> opd_ent_
;
609 // Object attributes if there is a .gnu.attributes section.
610 Attributes_section_data
* attributes_section_data_
;
613 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
614 // base class will emit.
616 template<int sh_type
, int size
, bool big_endian
>
617 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
620 Powerpc_copy_relocs()
621 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
624 // Emit any saved relocations which turn out to be needed. This is
625 // called after all the relocs have been scanned.
627 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
630 template<int size
, bool big_endian
>
631 class Target_powerpc
: public Sized_target
<size
, big_endian
>
635 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
636 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
637 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
638 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
639 static const Address invalid_address
= static_cast<Address
>(0) - 1;
640 // Offset of tp and dtp pointers from start of TLS block.
641 static const Address tp_offset
= 0x7000;
642 static const Address dtp_offset
= 0x8000;
645 : Sized_target
<size
, big_endian
>(&powerpc_info
),
646 got_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
), brlt_section_(NULL
),
647 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
648 tlsld_got_offset_(-1U),
649 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
650 powerxx_stubs_(false), plt_thread_safe_(false), plt_localentry0_(false),
651 plt_localentry0_init_(false), has_localentry0_(false),
652 has_tls_get_addr_opt_(false),
653 relax_failed_(false), relax_fail_count_(0),
654 stub_group_size_(0), savres_section_(0),
655 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
656 attributes_section_data_(NULL
),
657 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
661 // Process the relocations to determine unreferenced sections for
662 // garbage collection.
664 gc_process_relocs(Symbol_table
* symtab
,
666 Sized_relobj_file
<size
, big_endian
>* object
,
667 unsigned int data_shndx
,
668 unsigned int sh_type
,
669 const unsigned char* prelocs
,
671 Output_section
* output_section
,
672 bool needs_special_offset_handling
,
673 size_t local_symbol_count
,
674 const unsigned char* plocal_symbols
);
676 // Scan the relocations to look for symbol adjustments.
678 scan_relocs(Symbol_table
* symtab
,
680 Sized_relobj_file
<size
, big_endian
>* object
,
681 unsigned int data_shndx
,
682 unsigned int sh_type
,
683 const unsigned char* prelocs
,
685 Output_section
* output_section
,
686 bool needs_special_offset_handling
,
687 size_t local_symbol_count
,
688 const unsigned char* plocal_symbols
);
690 // Map input .toc section to output .got section.
692 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
694 if (size
== 64 && strcmp(name
, ".toc") == 0)
702 // Provide linker defined save/restore functions.
704 define_save_restore_funcs(Layout
*, Symbol_table
*);
706 // No stubs unless a final link.
709 { return !parameters
->options().relocatable(); }
712 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
715 do_plt_fde_location(const Output_data
*, unsigned char*,
716 uint64_t*, off_t
*) const;
718 // Stash info about branches, for stub generation.
720 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
721 unsigned int data_shndx
, Address r_offset
,
722 unsigned int r_type
, unsigned int r_sym
, Address addend
)
724 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
725 this->branch_info_
.push_back(info
);
726 if (r_type
== elfcpp::R_POWERPC_REL14
727 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
728 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
729 ppc_object
->set_has_14bit_branch(data_shndx
);
732 // Return whether the last branch is a plt call, and if so, mark the
733 // branch as having an R_PPC64_TOCSAVE.
735 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
736 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
739 && !this->branch_info_
.empty()
740 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
741 r_offset
, this, symtab
));
744 // Say the given location, that of a nop in a function prologue with
745 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
746 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
748 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
749 unsigned int shndx
, Address offset
)
752 loc
.object
= ppc_object
;
755 this->tocsave_loc_
.insert(loc
);
762 return this->tocsave_loc_
;
766 do_define_standard_symbols(Symbol_table
*, Layout
*);
768 // Finalize the sections.
770 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
772 // Return the value to use for a dynamic which requires special
775 do_dynsym_value(const Symbol
*) const;
777 // Return the PLT address to use for a local symbol.
779 do_plt_address_for_local(const Relobj
*, unsigned int) const;
781 // Return the PLT address to use for a global symbol.
783 do_plt_address_for_global(const Symbol
*) const;
785 // Return the offset to use for the GOT_INDX'th got entry which is
786 // for a local tls symbol specified by OBJECT, SYMNDX.
788 do_tls_offset_for_local(const Relobj
* object
,
790 unsigned int got_indx
) const;
792 // Return the offset to use for the GOT_INDX'th got entry which is
793 // for global tls symbol GSYM.
795 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
798 do_function_location(Symbol_location
*) const;
801 do_can_check_for_function_pointers() const
804 // Adjust -fsplit-stack code which calls non-split-stack code.
806 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
807 section_offset_type fnoffset
, section_size_type fnsize
,
808 const unsigned char* prelocs
, size_t reloc_count
,
809 unsigned char* view
, section_size_type view_size
,
810 std::string
* from
, std::string
* to
) const;
812 // Relocate a section.
814 relocate_section(const Relocate_info
<size
, big_endian
>*,
815 unsigned int sh_type
,
816 const unsigned char* prelocs
,
818 Output_section
* output_section
,
819 bool needs_special_offset_handling
,
821 Address view_address
,
822 section_size_type view_size
,
823 const Reloc_symbol_changes
*);
825 // Scan the relocs during a relocatable link.
827 scan_relocatable_relocs(Symbol_table
* symtab
,
829 Sized_relobj_file
<size
, big_endian
>* object
,
830 unsigned int data_shndx
,
831 unsigned int sh_type
,
832 const unsigned char* prelocs
,
834 Output_section
* output_section
,
835 bool needs_special_offset_handling
,
836 size_t local_symbol_count
,
837 const unsigned char* plocal_symbols
,
838 Relocatable_relocs
*);
840 // Scan the relocs for --emit-relocs.
842 emit_relocs_scan(Symbol_table
* symtab
,
844 Sized_relobj_file
<size
, big_endian
>* object
,
845 unsigned int data_shndx
,
846 unsigned int sh_type
,
847 const unsigned char* prelocs
,
849 Output_section
* output_section
,
850 bool needs_special_offset_handling
,
851 size_t local_symbol_count
,
852 const unsigned char* plocal_syms
,
853 Relocatable_relocs
* rr
);
855 // Emit relocations for a section.
857 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
858 unsigned int sh_type
,
859 const unsigned char* prelocs
,
861 Output_section
* output_section
,
862 typename
elfcpp::Elf_types
<size
>::Elf_Off
863 offset_in_output_section
,
865 Address view_address
,
867 unsigned char* reloc_view
,
868 section_size_type reloc_view_size
);
870 // Return whether SYM is defined by the ABI.
872 do_is_defined_by_abi(const Symbol
* sym
) const
874 return strcmp(sym
->name(), "__tls_get_addr") == 0;
877 // Return the size of the GOT section.
881 gold_assert(this->got_
!= NULL
);
882 return this->got_
->data_size();
885 // Get the PLT section.
886 const Output_data_plt_powerpc
<size
, big_endian
>*
889 gold_assert(this->plt_
!= NULL
);
893 // Get the IPLT section.
894 const Output_data_plt_powerpc
<size
, big_endian
>*
897 gold_assert(this->iplt_
!= NULL
);
901 // Get the LPLT section.
902 const Output_data_plt_powerpc
<size
, big_endian
>*
908 // Return the plt offset and section for the given global sym.
910 plt_off(const Symbol
* gsym
,
911 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
913 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
914 && gsym
->can_use_relative_reloc(false))
915 *sec
= this->iplt_section();
917 *sec
= this->plt_section();
918 return gsym
->plt_offset();
921 // Return the plt offset and section for the given local sym.
923 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
924 unsigned int local_sym_index
,
925 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
927 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
928 if (lsym
->is_ifunc_symbol())
929 *sec
= this->iplt_section();
931 *sec
= this->lplt_section();
932 return relobj
->local_plt_offset(local_sym_index
);
935 // Get the .glink section.
936 const Output_data_glink
<size
, big_endian
>*
937 glink_section() const
939 gold_assert(this->glink_
!= NULL
);
943 Output_data_glink
<size
, big_endian
>*
946 gold_assert(this->glink_
!= NULL
);
950 bool has_glink() const
951 { return this->glink_
!= NULL
; }
953 // Get the GOT section.
954 const Output_data_got_powerpc
<size
, big_endian
>*
957 gold_assert(this->got_
!= NULL
);
961 // Get the GOT section, creating it if necessary.
962 Output_data_got_powerpc
<size
, big_endian
>*
963 got_section(Symbol_table
*, Layout
*);
966 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
967 const elfcpp::Ehdr
<size
, big_endian
>&);
969 // Return the number of entries in the GOT.
971 got_entry_count() const
973 if (this->got_
== NULL
)
975 return this->got_size() / (size
/ 8);
978 // Return the number of entries in the PLT.
980 plt_entry_count() const;
982 // Return the offset of the first non-reserved PLT entry.
984 first_plt_entry_offset() const
988 if (this->abiversion() >= 2)
993 // Return the size of each PLT entry.
995 plt_entry_size() const
999 if (this->abiversion() >= 2)
1004 Output_data_save_res
<size
, big_endian
>*
1005 savres_section() const
1007 return this->savres_section_
;
1010 // Add any special sections for this symbol to the gc work list.
1011 // For powerpc64, this adds the code section of a function
1014 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1016 // Handle target specific gc actions when adding a gc reference from
1017 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1018 // and DST_OFF. For powerpc64, this adds a referenc to the code
1019 // section of a function descriptor.
1021 do_gc_add_reference(Symbol_table
* symtab
,
1023 unsigned int src_shndx
,
1025 unsigned int dst_shndx
,
1026 Address dst_off
) const;
1028 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1031 { return this->stub_tables_
; }
1033 const Output_data_brlt_powerpc
<size
, big_endian
>*
1034 brlt_section() const
1035 { return this->brlt_section_
; }
1038 add_branch_lookup_table(Address to
)
1040 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1041 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1045 find_branch_lookup_table(Address to
)
1047 typename
Branch_lookup_table::const_iterator p
1048 = this->branch_lookup_table_
.find(to
);
1049 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1053 write_branch_lookup_table(unsigned char *oview
)
1055 for (typename
Branch_lookup_table::const_iterator p
1056 = this->branch_lookup_table_
.begin();
1057 p
!= this->branch_lookup_table_
.end();
1060 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1064 // Wrapper used after relax to define a local symbol in output data,
1065 // from the end if value < 0.
1067 define_local(Symbol_table
* symtab
, const char* name
,
1068 Output_data
* od
, Address value
, unsigned int symsize
)
1071 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1072 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1073 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1074 static_cast<Signed_address
>(value
) < 0,
1076 // We are creating this symbol late, so need to fix up things
1077 // done early in Layout::finalize.
1078 sym
->set_dynsym_index(-1U);
1082 powerxx_stubs() const
1083 { return this->powerxx_stubs_
; }
1088 this->powerxx_stubs_
= true;
1092 plt_thread_safe() const
1093 { return this->plt_thread_safe_
; }
1096 plt_localentry0() const
1097 { return this->plt_localentry0_
; }
1100 set_has_localentry0()
1102 this->has_localentry0_
= true;
1106 is_elfv2_localentry0(const Symbol
* gsym
) const
1109 && this->abiversion() >= 2
1110 && this->plt_localentry0()
1111 && gsym
->type() == elfcpp::STT_FUNC
1112 && gsym
->is_defined()
1113 && gsym
->nonvis() >> 3 == 0
1114 && !gsym
->non_zero_localentry());
1118 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1119 unsigned int r_sym
) const
1121 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1122 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1125 && this->abiversion() >= 2
1126 && this->plt_localentry0()
1127 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1129 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1131 if (!psymval
->is_ifunc_symbol()
1132 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1139 // Remember any symbols seen with non-zero localentry, even those
1140 // not providing a definition
1142 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1147 unsigned char st_other
= sym
.get_st_other();
1148 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1149 to
->set_non_zero_localentry();
1151 // We haven't resolved anything, continue normal processing.
1157 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1160 set_abiversion(int ver
)
1162 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1163 flags
&= ~elfcpp::EF_PPC64_ABI
;
1164 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1165 this->set_processor_specific_flags(flags
);
1169 tls_get_addr_opt() const
1170 { return this->tls_get_addr_opt_
; }
1173 tls_get_addr() const
1174 { return this->tls_get_addr_
; }
1176 // If optimizing __tls_get_addr calls, whether this is the
1177 // "__tls_get_addr" symbol.
1179 is_tls_get_addr_opt(const Symbol
* gsym
) const
1181 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1182 || gsym
== this->tls_get_addr_opt_
);
1186 replace_tls_get_addr(const Symbol
* gsym
) const
1187 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1190 set_has_tls_get_addr_opt()
1191 { this->has_tls_get_addr_opt_
= true; }
1193 // Offset to toc save stack slot
1196 { return this->abiversion() < 2 ? 40 : 24; }
1198 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1199 // so use the CR save slot. Used only by __tls_get_addr call stub,
1200 // relying on __tls_get_addr not saving CR itself.
1203 { return this->abiversion() < 2 ? 32 : 8; }
1205 // Merge object attributes from input object with those in the output.
1207 merge_object_attributes(const char*, const Attributes_section_data
*);
1223 : tls_get_addr_state_(NOT_EXPECTED
),
1224 relinfo_(NULL
), relnum_(0), r_offset_(0)
1229 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1236 if (this->relinfo_
!= NULL
)
1237 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1238 _("missing expected __tls_get_addr call"));
1242 expect_tls_get_addr_call(
1243 const Relocate_info
<size
, big_endian
>* relinfo
,
1247 this->tls_get_addr_state_
= EXPECTED
;
1248 this->relinfo_
= relinfo
;
1249 this->relnum_
= relnum
;
1250 this->r_offset_
= r_offset
;
1254 expect_tls_get_addr_call()
1255 { this->tls_get_addr_state_
= EXPECTED
; }
1258 skip_next_tls_get_addr_call()
1259 {this->tls_get_addr_state_
= SKIP
; }
1262 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1263 unsigned int r_type
, const Symbol
* gsym
)
1266 = ((r_type
== elfcpp::R_POWERPC_REL24
1267 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1268 || r_type
== elfcpp::R_PPC_PLTREL24
1269 || is_plt16_reloc
<size
>(r_type
)
1270 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1271 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1272 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1273 || r_type
== elfcpp::R_POWERPC_PLTCALL
1274 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1275 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1277 && (gsym
== target
->tls_get_addr()
1278 || gsym
== target
->tls_get_addr_opt()));
1279 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1280 this->tls_get_addr_state_
= NOT_EXPECTED
;
1281 if (is_tls_call
&& last_tls
!= EXPECTED
)
1283 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1292 // What we're up to regarding calls to __tls_get_addr.
1293 // On powerpc, the branch and link insn making a call to
1294 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1295 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1296 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1297 // The marker relocation always comes first, and has the same
1298 // symbol as the reloc on the insn setting up the __tls_get_addr
1299 // argument. This ties the arg setup insn with the call insn,
1300 // allowing ld to safely optimize away the call. We check that
1301 // every call to __tls_get_addr has a marker relocation, and that
1302 // every marker relocation is on a call to __tls_get_addr.
1303 Tls_get_addr tls_get_addr_state_
;
1304 // Info about the last reloc for error message.
1305 const Relocate_info
<size
, big_endian
>* relinfo_
;
1310 // The class which scans relocations.
1311 class Scan
: protected Track_tls
1314 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1317 : Track_tls(), issued_non_pic_error_(false)
1321 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1324 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1325 Sized_relobj_file
<size
, big_endian
>* object
,
1326 unsigned int data_shndx
,
1327 Output_section
* output_section
,
1328 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1329 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1333 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1334 Sized_relobj_file
<size
, big_endian
>* object
,
1335 unsigned int data_shndx
,
1336 Output_section
* output_section
,
1337 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1341 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1343 Sized_relobj_file
<size
, big_endian
>* relobj
,
1346 const elfcpp::Rela
<size
, big_endian
>& ,
1347 unsigned int r_type
,
1348 const elfcpp::Sym
<size
, big_endian
>&)
1350 // PowerPC64 .opd is not folded, so any identical function text
1351 // may be folded and we'll still keep function addresses distinct.
1352 // That means no reloc is of concern here.
1355 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1356 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1357 if (ppcobj
->abiversion() == 1)
1360 // For 32-bit and ELFv2, conservatively assume anything but calls to
1361 // function code might be taking the address of the function.
1362 return !is_branch_reloc
<size
>(r_type
);
1366 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1368 Sized_relobj_file
<size
, big_endian
>* relobj
,
1371 const elfcpp::Rela
<size
, big_endian
>& ,
1372 unsigned int r_type
,
1378 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1379 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1380 if (ppcobj
->abiversion() == 1)
1383 return !is_branch_reloc
<size
>(r_type
);
1387 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1388 Sized_relobj_file
<size
, big_endian
>* object
,
1389 unsigned int r_type
, bool report_err
);
1393 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1394 unsigned int r_type
);
1397 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1398 unsigned int r_type
, Symbol
*);
1401 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1402 Target_powerpc
* target
);
1405 check_non_pic(Relobj
*, unsigned int r_type
);
1407 // Whether we have issued an error about a non-PIC compilation.
1408 bool issued_non_pic_error_
;
1412 symval_for_branch(const Symbol_table
* symtab
,
1413 const Sized_symbol
<size
>* gsym
,
1414 Powerpc_relobj
<size
, big_endian
>* object
,
1415 Address
*value
, unsigned int *dest_shndx
);
1417 // The class which implements relocation.
1418 class Relocate
: protected Track_tls
1421 // Use 'at' branch hints when true, 'y' when false.
1422 // FIXME maybe: set this with an option.
1423 static const bool is_isa_v2
= true;
1429 // Do a relocation. Return false if the caller should not issue
1430 // any warnings about this relocation.
1432 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1433 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1434 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1435 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1439 class Relocate_comdat_behavior
1442 // Decide what the linker should do for relocations that refer to
1443 // discarded comdat sections.
1444 inline Comdat_behavior
1445 get(const char* name
)
1447 gold::Default_comdat_behavior default_behavior
;
1448 Comdat_behavior ret
= default_behavior
.get(name
);
1449 if (ret
== CB_ERROR
)
1452 && (strcmp(name
, ".fixup") == 0
1453 || strcmp(name
, ".got2") == 0))
1456 && (strcmp(name
, ".opd") == 0
1457 || strcmp(name
, ".toc") == 0
1458 || strcmp(name
, ".toc1") == 0))
1465 // Optimize the TLS relocation type based on what we know about the
1466 // symbol. IS_FINAL is true if the final address of this symbol is
1467 // known at link time.
1469 tls::Tls_optimization
1470 optimize_tls_gd(bool is_final
)
1472 // If we are generating a shared library, then we can't do anything
1474 if (parameters
->options().shared()
1475 || !parameters
->options().tls_optimize())
1476 return tls::TLSOPT_NONE
;
1479 return tls::TLSOPT_TO_IE
;
1480 return tls::TLSOPT_TO_LE
;
1483 tls::Tls_optimization
1486 if (parameters
->options().shared()
1487 || !parameters
->options().tls_optimize())
1488 return tls::TLSOPT_NONE
;
1490 return tls::TLSOPT_TO_LE
;
1493 tls::Tls_optimization
1494 optimize_tls_ie(bool is_final
)
1497 || parameters
->options().shared()
1498 || !parameters
->options().tls_optimize())
1499 return tls::TLSOPT_NONE
;
1501 return tls::TLSOPT_TO_LE
;
1506 make_glink_section(Layout
*);
1508 // Create the PLT section.
1510 make_plt_section(Symbol_table
*, Layout
*);
1513 make_iplt_section(Symbol_table
*, Layout
*);
1516 make_lplt_section(Layout
*);
1519 make_brlt_section(Layout
*);
1521 // Create a PLT entry for a global symbol.
1523 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1525 // Create a PLT entry for a local IFUNC symbol.
1527 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1528 Sized_relobj_file
<size
, big_endian
>*,
1531 // Create a PLT entry for a local non-IFUNC symbol.
1533 make_local_plt_entry(Layout
*,
1534 Sized_relobj_file
<size
, big_endian
>*,
1538 // Create a GOT entry for local dynamic __tls_get_addr.
1540 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1541 Sized_relobj_file
<size
, big_endian
>* object
);
1544 tlsld_got_offset() const
1546 return this->tlsld_got_offset_
;
1549 // Get the dynamic reloc section, creating it if necessary.
1551 rela_dyn_section(Layout
*);
1553 // Similarly, but for ifunc symbols get the one for ifunc.
1555 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1557 // Copy a relocation against a global symbol.
1559 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1560 Sized_relobj_file
<size
, big_endian
>* object
,
1561 unsigned int shndx
, Output_section
* output_section
,
1562 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1564 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1565 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1566 symtab
->get_sized_symbol
<size
>(sym
),
1567 object
, shndx
, output_section
,
1568 r_type
, reloc
.get_r_offset(),
1569 reloc
.get_r_addend(),
1570 this->rela_dyn_section(layout
));
1573 // Look over all the input sections, deciding where to place stubs.
1575 group_sections(Layout
*, const Task
*, bool);
1577 // Sort output sections by address.
1578 struct Sort_sections
1581 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1582 { return sec1
->address() < sec2
->address(); }
1588 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1589 unsigned int data_shndx
,
1591 unsigned int r_type
,
1594 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1595 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1601 // Return whether this branch is going via a plt call stub, and if
1602 // so, mark it as having an R_PPC64_TOCSAVE.
1604 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1605 unsigned int shndx
, Address offset
,
1606 Target_powerpc
* target
, Symbol_table
* symtab
);
1608 // If this branch needs a plt call stub, or a long branch stub, make one.
1610 make_stub(Stub_table
<size
, big_endian
>*,
1611 Stub_table
<size
, big_endian
>*,
1612 Symbol_table
*) const;
1615 // The branch location..
1616 Powerpc_relobj
<size
, big_endian
>* object_
;
1617 unsigned int shndx_
;
1619 // ..and the branch type and destination.
1620 unsigned int r_type_
: 31;
1621 unsigned int tocsave_
: 1;
1622 unsigned int r_sym_
;
1626 // Information about this specific target which we pass to the
1627 // general Target structure.
1628 static Target::Target_info powerpc_info
;
1630 // The types of GOT entries needed for this platform.
1631 // These values are exposed to the ABI in an incremental link.
1632 // Do not renumber existing values without changing the version
1633 // number of the .gnu_incremental_inputs section.
1637 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1638 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1639 GOT_TYPE_TPREL
// entry for @got@tprel
1643 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1644 // The PLT section. This is a container for a table of addresses,
1645 // and their relocations. Each address in the PLT has a dynamic
1646 // relocation (R_*_JMP_SLOT) and each address will have a
1647 // corresponding entry in .glink for lazy resolution of the PLT.
1648 // ppc32 initialises the PLT to point at the .glink entry, while
1649 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1650 // linker adds a stub that loads the PLT entry into ctr then
1651 // branches to ctr. There may be more than one stub for each PLT
1652 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1653 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1654 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1655 // The IPLT section. Like plt_, this is a container for a table of
1656 // addresses and their relocations, specifically for STT_GNU_IFUNC
1657 // functions that resolve locally (STT_GNU_IFUNC functions that
1658 // don't resolve locally go in PLT). Unlike plt_, these have no
1659 // entry in .glink for lazy resolution, and the relocation section
1660 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1661 // the relocation section may contain relocations against
1662 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1663 // relocation section will appear at the end of other dynamic
1664 // relocations, so that ld.so applies these relocations after other
1665 // dynamic relocations. In a static executable, the relocation
1666 // section is emitted and marked with __rela_iplt_start and
1667 // __rela_iplt_end symbols.
1668 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1669 // A PLT style section for local, non-ifunc symbols
1670 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1671 // Section holding long branch destinations.
1672 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1673 // The .glink section.
1674 Output_data_glink
<size
, big_endian
>* glink_
;
1675 // The dynamic reloc section.
1676 Reloc_section
* rela_dyn_
;
1677 // Relocs saved to avoid a COPY reloc.
1678 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1679 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1680 unsigned int tlsld_got_offset_
;
1682 Stub_tables stub_tables_
;
1683 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1684 Branch_lookup_table branch_lookup_table_
;
1686 typedef std::vector
<Branch_info
> Branches
;
1687 Branches branch_info_
;
1688 Tocsave_loc tocsave_loc_
;
1690 bool powerxx_stubs_
;
1691 bool plt_thread_safe_
;
1692 bool plt_localentry0_
;
1693 bool plt_localentry0_init_
;
1694 bool has_localentry0_
;
1695 bool has_tls_get_addr_opt_
;
1698 int relax_fail_count_
;
1699 int32_t stub_group_size_
;
1701 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1703 // The "__tls_get_addr" symbol, if present
1704 Symbol
* tls_get_addr_
;
1705 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1706 Symbol
* tls_get_addr_opt_
;
1708 // Attributes in output.
1709 Attributes_section_data
* attributes_section_data_
;
1711 // Last input file to change various attribute tags
1712 const char* last_fp_
;
1713 const char* last_ld_
;
1714 const char* last_vec_
;
1715 const char* last_struct_
;
1719 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1722 true, // is_big_endian
1723 elfcpp::EM_PPC
, // machine_code
1724 false, // has_make_symbol
1725 false, // has_resolve
1726 false, // has_code_fill
1727 true, // is_default_stack_executable
1728 false, // can_icf_inline_merge_sections
1730 "/usr/lib/ld.so.1", // dynamic_linker
1731 0x10000000, // default_text_segment_address
1732 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1733 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1734 false, // isolate_execinstr
1736 elfcpp::SHN_UNDEF
, // small_common_shndx
1737 elfcpp::SHN_UNDEF
, // large_common_shndx
1738 0, // small_common_section_flags
1739 0, // large_common_section_flags
1740 NULL
, // attributes_section
1741 NULL
, // attributes_vendor
1742 "_start", // entry_symbol_name
1743 32, // hash_entry_size
1744 elfcpp::SHT_PROGBITS
, // unwind_section_type
1748 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1751 false, // is_big_endian
1752 elfcpp::EM_PPC
, // machine_code
1753 false, // has_make_symbol
1754 false, // has_resolve
1755 false, // has_code_fill
1756 true, // is_default_stack_executable
1757 false, // can_icf_inline_merge_sections
1759 "/usr/lib/ld.so.1", // dynamic_linker
1760 0x10000000, // default_text_segment_address
1761 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1762 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1763 false, // isolate_execinstr
1765 elfcpp::SHN_UNDEF
, // small_common_shndx
1766 elfcpp::SHN_UNDEF
, // large_common_shndx
1767 0, // small_common_section_flags
1768 0, // large_common_section_flags
1769 NULL
, // attributes_section
1770 NULL
, // attributes_vendor
1771 "_start", // entry_symbol_name
1772 32, // hash_entry_size
1773 elfcpp::SHT_PROGBITS
, // unwind_section_type
1777 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1780 true, // is_big_endian
1781 elfcpp::EM_PPC64
, // machine_code
1782 false, // has_make_symbol
1783 true, // has_resolve
1784 false, // has_code_fill
1785 false, // is_default_stack_executable
1786 false, // can_icf_inline_merge_sections
1788 "/usr/lib/ld.so.1", // dynamic_linker
1789 0x10000000, // default_text_segment_address
1790 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1791 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1792 false, // isolate_execinstr
1794 elfcpp::SHN_UNDEF
, // small_common_shndx
1795 elfcpp::SHN_UNDEF
, // large_common_shndx
1796 0, // small_common_section_flags
1797 0, // large_common_section_flags
1798 NULL
, // attributes_section
1799 NULL
, // attributes_vendor
1800 "_start", // entry_symbol_name
1801 32, // hash_entry_size
1802 elfcpp::SHT_PROGBITS
, // unwind_section_type
1806 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1809 false, // is_big_endian
1810 elfcpp::EM_PPC64
, // machine_code
1811 false, // has_make_symbol
1812 true, // has_resolve
1813 false, // has_code_fill
1814 false, // is_default_stack_executable
1815 false, // can_icf_inline_merge_sections
1817 "/usr/lib/ld.so.1", // dynamic_linker
1818 0x10000000, // default_text_segment_address
1819 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1820 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1821 false, // isolate_execinstr
1823 elfcpp::SHN_UNDEF
, // small_common_shndx
1824 elfcpp::SHN_UNDEF
, // large_common_shndx
1825 0, // small_common_section_flags
1826 0, // large_common_section_flags
1827 NULL
, // attributes_section
1828 NULL
, // attributes_vendor
1829 "_start", // entry_symbol_name
1830 32, // hash_entry_size
1831 elfcpp::SHT_PROGBITS
, // unwind_section_type
1836 is_branch_reloc(unsigned int r_type
)
1838 return (r_type
== elfcpp::R_POWERPC_REL24
1839 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1840 || r_type
== elfcpp::R_PPC_PLTREL24
1841 || r_type
== elfcpp::R_PPC_LOCAL24PC
1842 || r_type
== elfcpp::R_POWERPC_REL14
1843 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1844 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1845 || r_type
== elfcpp::R_POWERPC_ADDR24
1846 || r_type
== elfcpp::R_POWERPC_ADDR14
1847 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1848 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1851 // Reloc resolves to plt entry.
1854 is_plt16_reloc(unsigned int r_type
)
1856 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1857 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1858 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1859 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1862 // If INSN is an opcode that may be used with an @tls operand, return
1863 // the transformed insn for TLS optimisation, otherwise return 0. If
1864 // REG is non-zero only match an insn with RB or RA equal to REG.
1866 at_tls_transform(uint32_t insn
, unsigned int reg
)
1868 if ((insn
& (0x3f << 26)) != 31 << 26)
1872 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1873 rtra
= insn
& ((1 << 26) - (1 << 16));
1874 else if (((insn
>> 16) & 0x1f) == reg
)
1875 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1879 if ((insn
& (0x3ff << 1)) == 266 << 1)
1882 else if ((insn
& (0x1f << 1)) == 23 << 1
1883 && ((insn
& (0x1f << 6)) < 14 << 6
1884 || ((insn
& (0x1f << 6)) >= 16 << 6
1885 && (insn
& (0x1f << 6)) < 24 << 6)))
1886 // load and store indexed -> dform
1887 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1888 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1889 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1890 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1891 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1893 insn
= (58 << 26) | 2;
1901 template<int size
, bool big_endian
>
1902 class Powerpc_relocate_functions
1922 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1923 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1924 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1926 template<int valsize
>
1928 has_overflow_signed(Address value
)
1930 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1931 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1932 limit
<<= ((valsize
- 1) >> 1);
1933 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1934 return value
+ limit
> (limit
<< 1) - 1;
1937 template<int valsize
>
1939 has_overflow_unsigned(Address value
)
1941 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1942 limit
<<= ((valsize
- 1) >> 1);
1943 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1944 return value
> (limit
<< 1) - 1;
1947 template<int valsize
>
1949 has_overflow_bitfield(Address value
)
1951 return (has_overflow_unsigned
<valsize
>(value
)
1952 && has_overflow_signed
<valsize
>(value
));
1955 template<int valsize
>
1956 static inline Status
1957 overflowed(Address value
, Overflow_check overflow
)
1959 if (overflow
== CHECK_SIGNED
)
1961 if (has_overflow_signed
<valsize
>(value
))
1962 return STATUS_OVERFLOW
;
1964 else if (overflow
== CHECK_UNSIGNED
)
1966 if (has_overflow_unsigned
<valsize
>(value
))
1967 return STATUS_OVERFLOW
;
1969 else if (overflow
== CHECK_BITFIELD
)
1971 if (has_overflow_bitfield
<valsize
>(value
))
1972 return STATUS_OVERFLOW
;
1977 // Do a simple RELA relocation
1978 template<int fieldsize
, int valsize
>
1979 static inline Status
1980 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1982 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1983 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1984 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1985 return overflowed
<valsize
>(value
, overflow
);
1988 template<int fieldsize
, int valsize
>
1989 static inline Status
1990 rela(unsigned char* view
,
1991 unsigned int right_shift
,
1992 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1994 Overflow_check overflow
)
1996 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1997 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1998 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1999 if (overflow
== CHECK_SIGNED
)
2000 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2002 value
= value
>> right_shift
;
2003 Valtype reloc
= value
;
2006 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
2007 return overflowed
<valsize
>(value
, overflow
);
2010 // Do a simple RELA relocation, unaligned.
2011 template<int fieldsize
, int valsize
>
2012 static inline Status
2013 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2015 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2016 return overflowed
<valsize
>(value
, overflow
);
2019 template<int fieldsize
, int valsize
>
2020 static inline Status
2021 rela_ua(unsigned char* view
,
2022 unsigned int right_shift
,
2023 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2025 Overflow_check overflow
)
2027 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2029 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2030 if (overflow
== CHECK_SIGNED
)
2031 value
= static_cast<SignedAddress
>(value
) >> right_shift
;
2033 value
= value
>> right_shift
;
2034 Valtype reloc
= value
;
2037 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2038 return overflowed
<valsize
>(value
, overflow
);
2042 // R_PPC64_ADDR64: (Symbol + Addend)
2044 addr64(unsigned char* view
, Address value
)
2045 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2047 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2049 addr64_u(unsigned char* view
, Address value
)
2050 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2052 // R_POWERPC_ADDR32: (Symbol + Addend)
2053 static inline Status
2054 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2055 { return This::template rela
<32,32>(view
, value
, overflow
); }
2057 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2058 static inline Status
2059 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2060 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2062 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2063 static inline Status
2064 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2066 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2068 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2069 stat
= STATUS_OVERFLOW
;
2073 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2074 static inline Status
2075 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2076 { return This::template rela
<16,16>(view
, value
, overflow
); }
2078 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2079 static inline Status
2080 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2081 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2083 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2084 static inline Status
2085 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2087 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2088 if ((value
& 3) != 0)
2089 stat
= STATUS_OVERFLOW
;
2093 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2094 static inline Status
2095 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2097 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2098 if ((value
& 15) != 0)
2099 stat
= STATUS_OVERFLOW
;
2103 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2105 addr16_hi(unsigned char* view
, Address value
)
2106 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2108 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2110 addr16_ha(unsigned char* view
, Address value
)
2111 { This::addr16_hi(view
, value
+ 0x8000); }
2113 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2115 addr16_hi2(unsigned char* view
, Address value
)
2116 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2118 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2120 addr16_ha2(unsigned char* view
, Address value
)
2121 { This::addr16_hi2(view
, value
+ 0x8000); }
2123 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2125 addr16_hi3(unsigned char* view
, Address value
)
2126 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2128 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2130 addr16_ha3(unsigned char* view
, Address value
)
2131 { This::addr16_hi3(view
, value
+ 0x8000); }
2133 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2134 static inline Status
2135 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2137 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2138 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2139 stat
= STATUS_OVERFLOW
;
2143 // R_POWERPC_REL16DX_HA
2144 static inline Status
2145 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2147 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2148 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2149 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2151 value
= static_cast<SignedAddress
>(value
) >> 16;
2152 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2153 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2154 return overflowed
<16>(value
, overflow
);
2158 static inline Status
2159 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2161 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2163 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2169 addr34_hi(unsigned char *view
, uint64_t value
)
2170 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2174 addr34_ha(unsigned char *view
, uint64_t value
)
2175 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2178 static inline Status
2179 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2181 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2183 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2187 // R_PPC64_ADDR16_HIGHER34
2189 addr16_higher34(unsigned char* view
, uint64_t value
)
2190 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2192 // R_PPC64_ADDR16_HIGHERA34
2194 addr16_highera34(unsigned char* view
, uint64_t value
)
2195 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2197 // R_PPC64_ADDR16_HIGHEST34
2199 addr16_highest34(unsigned char* view
, uint64_t value
)
2200 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2202 // R_PPC64_ADDR16_HIGHESTA34
2204 addr16_highesta34(unsigned char* view
, uint64_t value
)
2205 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2208 // Set ABI version for input and output.
2210 template<int size
, bool big_endian
>
2212 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2214 this->e_flags_
|= ver
;
2215 if (this->abiversion() != 0)
2217 Target_powerpc
<size
, big_endian
>* target
=
2218 static_cast<Target_powerpc
<size
, big_endian
>*>(
2219 parameters
->sized_target
<size
, big_endian
>());
2220 if (target
->abiversion() == 0)
2221 target
->set_abiversion(this->abiversion());
2222 else if (target
->abiversion() != this->abiversion())
2223 gold_error(_("%s: ABI version %d is not compatible "
2224 "with ABI version %d output"),
2225 this->name().c_str(),
2226 this->abiversion(), target
->abiversion());
2231 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2232 // relocatable object, if such sections exists.
2234 template<int size
, bool big_endian
>
2236 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2237 Read_symbols_data
* sd
)
2239 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2240 const unsigned char* namesu
= sd
->section_names
->data();
2241 const char* names
= reinterpret_cast<const char*>(namesu
);
2242 section_size_type names_size
= sd
->section_names_size
;
2243 const unsigned char* s
;
2245 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2246 size
== 32 ? ".got2" : ".opd",
2247 names
, names_size
, NULL
);
2250 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2251 this->special_
= ndx
;
2254 if (this->abiversion() == 0)
2255 this->set_abiversion(1);
2256 else if (this->abiversion() > 1)
2257 gold_error(_("%s: .opd invalid in abiv%d"),
2258 this->name().c_str(), this->abiversion());
2263 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2264 names
, names_size
, NULL
);
2267 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2268 this->relatoc_
= ndx
;
2269 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2270 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2273 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2276 // Examine .rela.opd to build info about function entry points.
2278 template<int size
, bool big_endian
>
2280 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2282 const unsigned char* prelocs
,
2283 const unsigned char* plocal_syms
)
2287 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2288 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2289 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2290 Address expected_off
= 0;
2291 bool regular
= true;
2292 unsigned int opd_ent_size
= 0;
2294 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2296 Reltype
reloc(prelocs
);
2297 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2298 = reloc
.get_r_info();
2299 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2300 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2302 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2303 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2306 if (r_sym
< this->local_symbol_count())
2308 typename
elfcpp::Sym
<size
, big_endian
>
2309 lsym(plocal_syms
+ r_sym
* sym_size
);
2310 shndx
= lsym
.get_st_shndx();
2311 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2312 value
= lsym
.get_st_value();
2315 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2317 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2318 value
+ reloc
.get_r_addend());
2321 expected_off
= reloc
.get_r_offset();
2322 opd_ent_size
= expected_off
;
2324 else if (expected_off
!= reloc
.get_r_offset())
2326 expected_off
+= opd_ent_size
;
2328 else if (r_type
== elfcpp::R_PPC64_TOC
)
2330 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2335 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2336 this->name().c_str(), r_type
);
2340 if (reloc_count
<= 2)
2341 opd_ent_size
= this->section_size(this->opd_shndx());
2342 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2346 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2347 this->name().c_str());
2353 // Returns true if a code sequence loading the TOC entry at VALUE
2354 // relative to the TOC pointer can be converted into code calculating
2355 // a TOC pointer relative offset.
2356 // If so, the TOC pointer relative offset is stored to VALUE.
2358 template<int size
, bool big_endian
>
2360 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2361 Target_powerpc
<size
, big_endian
>* target
,
2367 // With -mcmodel=medium code it is quite possible to have
2368 // toc-relative relocs referring to objects outside the TOC.
2369 // Don't try to look at a non-existent TOC.
2370 if (this->toc_shndx() == 0)
2373 // Convert VALUE back to an address by adding got_base (see below),
2374 // then to an offset in the TOC by subtracting the TOC output
2375 // section address and the TOC output offset. Since this TOC output
2376 // section and the got output section are one and the same, we can
2377 // omit adding and subtracting the output section address.
2378 Address off
= (*value
+ this->toc_base_offset()
2379 - this->output_section_offset(this->toc_shndx()));
2380 // Is this offset in the TOC? -mcmodel=medium code may be using
2381 // TOC relative access to variables outside the TOC. Those of
2382 // course can't be optimized. We also don't try to optimize code
2383 // that is using a different object's TOC.
2384 if (off
>= this->section_size(this->toc_shndx()))
2387 if (this->no_toc_opt(off
))
2390 section_size_type vlen
;
2391 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2392 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2394 Address got_base
= (target
->got_section()->output_section()->address()
2395 + this->toc_base_offset());
2397 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2404 template<int size
, bool big_endian
>
2406 Powerpc_relobj
<size
, big_endian
>::make_got_relative(
2407 Target_powerpc
<size
, big_endian
>* target
,
2408 const Symbol_value
<size
>* psymval
,
2412 Address addr
= psymval
->value(this, addend
);
2413 Address got_base
= (target
->got_section()->output_section()->address()
2414 + this->toc_base_offset());
2416 if (addr
+ 0x80008000 > 0xffffffff)
2423 // Perform the Sized_relobj_file method, then set up opd info from
2426 template<int size
, bool big_endian
>
2428 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2430 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2433 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2434 p
!= rd
->relocs
.end();
2437 if (p
->data_shndx
== this->opd_shndx())
2439 uint64_t opd_size
= this->section_size(this->opd_shndx());
2440 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2443 this->init_opd(opd_size
);
2444 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2445 rd
->local_symbols
->data());
2453 // Read the symbols then set up st_other vector.
2455 template<int size
, bool big_endian
>
2457 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2459 this->base_read_symbols(sd
);
2460 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2464 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2465 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2466 const unsigned int loccount
= this->do_local_symbol_count();
2469 this->st_other_
.resize(loccount
);
2470 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2471 off_t locsize
= loccount
* sym_size
;
2472 const unsigned int symtab_shndx
= this->symtab_shndx();
2473 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2474 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2475 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2476 locsize
, true, false);
2478 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2480 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2481 unsigned char st_other
= sym
.get_st_other();
2482 this->st_other_
[i
] = st_other
;
2483 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2485 if (this->abiversion() == 0)
2486 this->set_abiversion(2);
2487 else if (this->abiversion() < 2)
2488 gold_error(_("%s: local symbol %d has invalid st_other"
2489 " for ABI version 1"),
2490 this->name().c_str(), i
);
2496 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2497 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2498 bool merge_attributes
= false;
2499 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2501 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2502 switch (shdr
.get_sh_type())
2504 case elfcpp::SHT_GNU_ATTRIBUTES
:
2506 gold_assert(this->attributes_section_data_
== NULL
);
2507 section_offset_type section_offset
= shdr
.get_sh_offset();
2508 section_size_type section_size
=
2509 convert_to_section_size_type(shdr
.get_sh_size());
2510 const unsigned char* view
=
2511 this->get_view(section_offset
, section_size
, true, false);
2512 this->attributes_section_data_
=
2513 new Attributes_section_data(view
, section_size
);
2517 case elfcpp::SHT_SYMTAB
:
2519 // Sometimes an object has no contents except the section
2520 // name string table and an empty symbol table with the
2521 // undefined symbol. We don't want to merge
2522 // processor-specific flags from such an object.
2523 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2524 elfcpp::Elf_sizes
<size
>::sym_size
;
2525 if (shdr
.get_sh_size() > sym_size
)
2526 merge_attributes
= true;
2530 case elfcpp::SHT_STRTAB
:
2534 merge_attributes
= true;
2539 if (!merge_attributes
)
2541 // Should rarely happen.
2542 delete this->attributes_section_data_
;
2543 this->attributes_section_data_
= NULL
;
2547 template<int size
, bool big_endian
>
2549 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2551 this->e_flags_
|= ver
;
2552 if (this->abiversion() != 0)
2554 Target_powerpc
<size
, big_endian
>* target
=
2555 static_cast<Target_powerpc
<size
, big_endian
>*>(
2556 parameters
->sized_target
<size
, big_endian
>());
2557 if (target
->abiversion() == 0)
2558 target
->set_abiversion(this->abiversion());
2559 else if (target
->abiversion() != this->abiversion())
2560 gold_error(_("%s: ABI version %d is not compatible "
2561 "with ABI version %d output"),
2562 this->name().c_str(),
2563 this->abiversion(), target
->abiversion());
2568 // Call Sized_dynobj::base_read_symbols to read the symbols then
2569 // read .opd from a dynamic object, filling in opd_ent_ vector,
2571 template<int size
, bool big_endian
>
2573 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2575 this->base_read_symbols(sd
);
2576 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2577 const unsigned char* ps
=
2578 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2579 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2581 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2582 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2584 section_offset_type section_offset
= shdr
.get_sh_offset();
2585 section_size_type section_size
=
2586 convert_to_section_size_type(shdr
.get_sh_size());
2587 const unsigned char* view
=
2588 this->get_view(section_offset
, section_size
, true, false);
2589 this->attributes_section_data_
=
2590 new Attributes_section_data(view
, section_size
);
2596 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2597 const unsigned char* namesu
= sd
->section_names
->data();
2598 const char* names
= reinterpret_cast<const char*>(namesu
);
2599 const unsigned char* s
= NULL
;
2600 const unsigned char* opd
;
2601 section_size_type opd_size
;
2603 // Find and read .opd section.
2606 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2607 sd
->section_names_size
,
2612 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2613 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2614 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2616 if (this->abiversion() == 0)
2617 this->set_abiversion(1);
2618 else if (this->abiversion() > 1)
2619 gold_error(_("%s: .opd invalid in abiv%d"),
2620 this->name().c_str(), this->abiversion());
2622 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2623 this->opd_address_
= shdr
.get_sh_addr();
2624 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2625 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2631 // Build set of executable sections.
2632 // Using a set is probably overkill. There is likely to be only
2633 // a few executable sections, typically .init, .text and .fini,
2634 // and they are generally grouped together.
2635 typedef std::set
<Sec_info
> Exec_sections
;
2636 Exec_sections exec_sections
;
2638 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2640 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2641 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2642 && ((shdr
.get_sh_flags()
2643 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2644 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2645 && shdr
.get_sh_size() != 0)
2647 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2648 shdr
.get_sh_size(), i
));
2651 if (exec_sections
.empty())
2654 // Look over the OPD entries. This is complicated by the fact
2655 // that some binaries will use two-word entries while others
2656 // will use the standard three-word entries. In most cases
2657 // the third word (the environment pointer for languages like
2658 // Pascal) is unused and will be zero. If the third word is
2659 // used it should not be pointing into executable sections,
2661 this->init_opd(opd_size
);
2662 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2664 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2665 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2666 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2668 // Chances are that this is the third word of an OPD entry.
2670 typename
Exec_sections::const_iterator e
2671 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2672 if (e
!= exec_sections
.begin())
2675 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2677 // We have an address in an executable section.
2678 // VAL ought to be the function entry, set it up.
2679 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2680 // Skip second word of OPD entry, the TOC pointer.
2684 // If we didn't match any executable sections, we likely
2685 // have a non-zero third word in the OPD entry.
2690 // Relocate sections.
2692 template<int size
, bool big_endian
>
2694 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2695 const Symbol_table
* symtab
, const Layout
* layout
,
2696 const unsigned char* pshdrs
, Output_file
* of
,
2697 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2699 unsigned int start
= 1;
2701 && this->relatoc_
!= 0
2702 && !parameters
->options().relocatable())
2704 // Relocate .toc first.
2705 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2706 this->relatoc_
, this->relatoc_
);
2707 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2708 1, this->relatoc_
- 1);
2709 start
= this->relatoc_
+ 1;
2711 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2712 start
, this->shnum() - 1);
2714 if (!parameters
->options().output_is_position_independent())
2716 Target_powerpc
<size
, big_endian
>* target
2717 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2718 parameters
->sized_target
<size
, big_endian
>());
2719 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2721 const section_size_type offset
= target
->lplt_section()->offset();
2722 const section_size_type oview_size
2723 = convert_to_section_size_type(target
->lplt_section()->data_size());
2724 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2726 bool modified
= false;
2727 unsigned int nsyms
= this->local_symbol_count();
2728 for (unsigned int i
= 0; i
< nsyms
; i
++)
2729 if (this->local_has_plt_offset(i
))
2731 Address value
= this->local_symbol_value(i
, 0);
2733 value
+= ppc64_local_entry_offset(i
);
2734 size_t off
= this->local_plt_offset(i
);
2735 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2739 of
->write_output_view(offset
, oview_size
, oview
);
2744 // Set up some symbols.
2746 template<int size
, bool big_endian
>
2748 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2749 Symbol_table
* symtab
,
2754 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2755 // undefined when scanning relocs (and thus requires
2756 // non-relative dynamic relocs). The proper value will be
2758 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2759 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2761 Target_powerpc
<size
, big_endian
>* target
=
2762 static_cast<Target_powerpc
<size
, big_endian
>*>(
2763 parameters
->sized_target
<size
, big_endian
>());
2764 Output_data_got_powerpc
<size
, big_endian
>* got
2765 = target
->got_section(symtab
, layout
);
2766 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2767 Symbol_table::PREDEFINED
,
2771 elfcpp::STV_HIDDEN
, 0,
2775 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2776 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2777 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2779 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2781 = layout
->add_output_section_data(".sdata", 0,
2783 | elfcpp::SHF_WRITE
,
2784 sdata
, ORDER_SMALL_DATA
, false);
2785 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2786 Symbol_table::PREDEFINED
,
2787 os
, 32768, 0, elfcpp::STT_OBJECT
,
2788 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2794 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2795 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2796 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2798 Target_powerpc
<size
, big_endian
>* target
=
2799 static_cast<Target_powerpc
<size
, big_endian
>*>(
2800 parameters
->sized_target
<size
, big_endian
>());
2801 Output_data_got_powerpc
<size
, big_endian
>* got
2802 = target
->got_section(symtab
, layout
);
2803 symtab
->define_in_output_data(".TOC.", NULL
,
2804 Symbol_table::PREDEFINED
,
2808 elfcpp::STV_HIDDEN
, 0,
2813 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2814 if (parameters
->options().tls_get_addr_optimize()
2815 && this->tls_get_addr_
!= NULL
2816 && this->tls_get_addr_
->in_reg())
2817 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2818 if (this->tls_get_addr_opt_
!= NULL
)
2820 if (this->tls_get_addr_
->is_undefined()
2821 || this->tls_get_addr_
->is_from_dynobj())
2823 // Make it seem as if references to __tls_get_addr are
2824 // really to __tls_get_addr_opt, so the latter symbol is
2825 // made dynamic, not the former.
2826 this->tls_get_addr_
->clear_in_reg();
2827 this->tls_get_addr_opt_
->set_in_reg();
2829 // We have a non-dynamic definition for __tls_get_addr.
2830 // Make __tls_get_addr_opt the same, if it does not already have
2831 // a non-dynamic definition.
2832 else if (this->tls_get_addr_opt_
->is_undefined()
2833 || this->tls_get_addr_opt_
->is_from_dynobj())
2835 Sized_symbol
<size
>* from
2836 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2837 Sized_symbol
<size
>* to
2838 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2839 symtab
->clone
<size
>(to
, from
);
2844 // Set up PowerPC target specific relobj.
2846 template<int size
, bool big_endian
>
2848 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2849 const std::string
& name
,
2850 Input_file
* input_file
,
2851 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2853 int et
= ehdr
.get_e_type();
2854 // ET_EXEC files are valid input for --just-symbols/-R,
2855 // and we treat them as relocatable objects.
2856 if (et
== elfcpp::ET_REL
2857 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2859 Powerpc_relobj
<size
, big_endian
>* obj
=
2860 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2864 else if (et
== elfcpp::ET_DYN
)
2866 Powerpc_dynobj
<size
, big_endian
>* obj
=
2867 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2873 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2878 template<int size
, bool big_endian
>
2879 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2882 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2883 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2885 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2886 : Output_data_got
<size
, big_endian
>(),
2887 symtab_(symtab
), layout_(layout
),
2888 header_ent_cnt_(size
== 32 ? 3 : 1),
2889 header_index_(size
== 32 ? 0x2000 : 0)
2892 this->set_addralign(256);
2895 // Override all the Output_data_got methods we use so as to first call
2898 add_global(Symbol
* gsym
, unsigned int got_type
)
2900 this->reserve_ent();
2901 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2905 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2907 this->reserve_ent();
2908 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2912 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2913 { return this->add_global_plt(gsym
, got_type
); }
2916 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2917 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2919 this->reserve_ent();
2920 Output_data_got
<size
, big_endian
>::
2921 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2925 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2926 Output_data_reloc_generic
* rel_dyn
,
2927 unsigned int r_type_1
, unsigned int r_type_2
)
2929 if (gsym
->has_got_offset(got_type
))
2932 this->reserve_ent(2);
2933 Output_data_got
<size
, big_endian
>::
2934 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2938 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2940 this->reserve_ent();
2941 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2946 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2948 this->reserve_ent();
2949 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2954 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2955 { return this->add_local_plt(object
, sym_index
, got_type
); }
2958 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2959 unsigned int got_type
,
2960 Output_data_reloc_generic
* rel_dyn
,
2961 unsigned int r_type
)
2963 if (object
->local_has_got_offset(sym_index
, got_type
))
2966 this->reserve_ent(2);
2967 Output_data_got
<size
, big_endian
>::
2968 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2972 add_constant(Valtype constant
)
2974 this->reserve_ent();
2975 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2979 add_constant_pair(Valtype c1
, Valtype c2
)
2981 this->reserve_ent(2);
2982 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2985 // Offset of _GLOBAL_OFFSET_TABLE_.
2989 return this->got_offset(this->header_index_
);
2992 // Offset of base used to access the GOT/TOC.
2993 // The got/toc pointer reg will be set to this value.
2995 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2998 return this->g_o_t();
3000 return (this->output_section()->address()
3001 + object
->toc_base_offset()
3005 // Ensure our GOT has a header.
3007 set_final_data_size()
3009 if (this->header_ent_cnt_
!= 0)
3010 this->make_header();
3011 Output_data_got
<size
, big_endian
>::set_final_data_size();
3014 // First word of GOT header needs some values that are not
3015 // handled by Output_data_got so poke them in here.
3016 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
3018 do_write(Output_file
* of
)
3021 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
3022 val
= this->layout_
->dynamic_section()->address();
3024 val
= this->output_section()->address() + 0x8000;
3025 this->replace_constant(this->header_index_
, val
);
3026 Output_data_got
<size
, big_endian
>::do_write(of
);
3031 reserve_ent(unsigned int cnt
= 1)
3033 if (this->header_ent_cnt_
== 0)
3035 if (this->num_entries() + cnt
> this->header_index_
)
3036 this->make_header();
3042 this->header_ent_cnt_
= 0;
3043 this->header_index_
= this->num_entries();
3046 Output_data_got
<size
, big_endian
>::add_constant(0);
3047 Output_data_got
<size
, big_endian
>::add_constant(0);
3048 Output_data_got
<size
, big_endian
>::add_constant(0);
3050 // Define _GLOBAL_OFFSET_TABLE_ at the header
3051 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3054 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3055 sym
->set_value(this->g_o_t());
3058 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3059 Symbol_table::PREDEFINED
,
3060 this, this->g_o_t(), 0,
3063 elfcpp::STV_HIDDEN
, 0,
3067 Output_data_got
<size
, big_endian
>::add_constant(0);
3070 // Stashed pointers.
3071 Symbol_table
* symtab_
;
3075 unsigned int header_ent_cnt_
;
3076 // GOT header index.
3077 unsigned int header_index_
;
3080 // Get the GOT section, creating it if necessary.
3082 template<int size
, bool big_endian
>
3083 Output_data_got_powerpc
<size
, big_endian
>*
3084 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3087 if (this->got_
== NULL
)
3089 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3092 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3094 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3095 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3096 this->got_
, ORDER_DATA
, false);
3102 // Get the dynamic reloc section, creating it if necessary.
3104 template<int size
, bool big_endian
>
3105 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3106 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3108 if (this->rela_dyn_
== NULL
)
3110 gold_assert(layout
!= NULL
);
3111 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3112 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3113 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3114 ORDER_DYNAMIC_RELOCS
, false);
3116 return this->rela_dyn_
;
3119 // Similarly, but for ifunc symbols get the one for ifunc.
3121 template<int size
, bool big_endian
>
3122 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3123 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3128 return this->rela_dyn_section(layout
);
3130 if (this->iplt_
== NULL
)
3131 this->make_iplt_section(symtab
, layout
);
3132 return this->iplt_
->rel_plt();
3138 // Determine the stub group size. The group size is the absolute
3139 // value of the parameter --stub-group-size. If --stub-group-size
3140 // is passed a negative value, we restrict stubs to be always after
3141 // the stubbed branches.
3142 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3143 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3144 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3145 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3146 owner_(NULL
), output_section_(NULL
)
3150 // Return true iff input section can be handled by current stub
3153 can_add_to_stub_group(Output_section
* o
,
3154 const Output_section::Input_section
* i
,
3157 const Output_section::Input_section
*
3163 { return output_section_
; }
3166 set_output_and_owner(Output_section
* o
,
3167 const Output_section::Input_section
* i
)
3169 this->output_section_
= o
;
3178 // Adding group sections before the stubs.
3179 FINDING_STUB_SECTION
,
3180 // Adding group sections after the stubs.
3184 uint32_t stub_group_size_
;
3185 bool stubs_always_after_branch_
;
3186 bool suppress_size_errors_
;
3187 // True if a stub group can serve multiple output sections.
3190 // Current max size of group. Starts at stub_group_size_ but is
3191 // reduced to stub_group_size_/1024 on seeing a section with
3192 // external conditional branches.
3193 uint32_t group_size_
;
3194 uint64_t group_start_addr_
;
3195 // owner_ and output_section_ specify the section to which stubs are
3196 // attached. The stubs are placed at the end of this section.
3197 const Output_section::Input_section
* owner_
;
3198 Output_section
* output_section_
;
3201 // Return true iff input section can be handled by current stub
3202 // group. Sections are presented to this function in order,
3203 // so the first section is the head of the group.
3206 Stub_control::can_add_to_stub_group(Output_section
* o
,
3207 const Output_section::Input_section
* i
,
3210 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3212 uint64_t start_addr
= o
->address();
3215 // .init and .fini sections are pasted together to form a single
3216 // function. We can't be adding stubs in the middle of the function.
3217 this_size
= o
->data_size();
3220 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3221 this_size
= i
->data_size();
3224 uint64_t end_addr
= start_addr
+ this_size
;
3225 uint32_t group_size
= this->stub_group_size_
;
3227 this->group_size_
= group_size
= group_size
>> 10;
3229 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3230 gold_warning(_("%s:%s exceeds group size"),
3231 i
->relobj()->name().c_str(),
3232 i
->relobj()->section_name(i
->shndx()).c_str());
3234 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3235 has14
? " 14bit" : "",
3236 i
->relobj()->name().c_str(),
3237 i
->relobj()->section_name(i
->shndx()).c_str(),
3238 (long long) this_size
,
3239 (this->state_
== NO_GROUP
3241 : (long long) end_addr
- this->group_start_addr_
));
3243 if (this->state_
== NO_GROUP
)
3245 // Only here on very first use of Stub_control
3247 this->output_section_
= o
;
3248 this->state_
= FINDING_STUB_SECTION
;
3249 this->group_size_
= group_size
;
3250 this->group_start_addr_
= start_addr
;
3253 else if (!this->multi_os_
&& this->output_section_
!= o
)
3255 else if (this->state_
== HAS_STUB_SECTION
)
3257 // Can we add this section, which is after the stubs, to the
3259 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3262 else if (this->state_
== FINDING_STUB_SECTION
)
3264 if ((whole_sec
&& this->output_section_
== o
)
3265 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3267 // Stubs are added at the end of "owner_".
3269 this->output_section_
= o
;
3272 // The group before the stubs has reached maximum size.
3273 // Now see about adding sections after the stubs to the
3274 // group. If the current section has a 14-bit branch and
3275 // the group before the stubs exceeds group_size_ (because
3276 // they didn't have 14-bit branches), don't add sections
3277 // after the stubs: The size of stubs for such a large
3278 // group may exceed the reach of a 14-bit branch.
3279 if (!this->stubs_always_after_branch_
3280 && this_size
<= this->group_size_
3281 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3283 gold_debug(DEBUG_TARGET
, "adding after stubs");
3284 this->state_
= HAS_STUB_SECTION
;
3285 this->group_start_addr_
= start_addr
;
3292 gold_debug(DEBUG_TARGET
,
3293 !this->multi_os_
&& this->output_section_
!= o
3294 ? "nope, new output section\n"
3295 : "nope, didn't fit\n");
3297 // The section fails to fit in the current group. Set up a few
3298 // things for the next group. owner_ and output_section_ will be
3299 // set later after we've retrieved those values for the current
3301 this->state_
= FINDING_STUB_SECTION
;
3302 this->group_size_
= group_size
;
3303 this->group_start_addr_
= start_addr
;
3307 // Look over all the input sections, deciding where to place stubs.
3309 template<int size
, bool big_endian
>
3311 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3313 bool no_size_errors
)
3315 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3316 parameters
->options().stub_group_multi());
3318 // Group input sections and insert stub table
3319 Stub_table_owner
* table_owner
= NULL
;
3320 std::vector
<Stub_table_owner
*> tables
;
3321 Layout::Section_list section_list
;
3322 layout
->get_executable_sections(§ion_list
);
3323 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3324 for (Layout::Section_list::iterator o
= section_list
.begin();
3325 o
!= section_list
.end();
3328 typedef Output_section::Input_section_list Input_section_list
;
3329 for (Input_section_list::const_iterator i
3330 = (*o
)->input_sections().begin();
3331 i
!= (*o
)->input_sections().end();
3334 if (i
->is_input_section()
3335 || i
->is_relaxed_input_section())
3337 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3338 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3339 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3340 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3342 table_owner
->output_section
= stub_control
.output_section();
3343 table_owner
->owner
= stub_control
.owner();
3344 stub_control
.set_output_and_owner(*o
, &*i
);
3347 if (table_owner
== NULL
)
3349 table_owner
= new Stub_table_owner
;
3350 tables
.push_back(table_owner
);
3352 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3356 if (table_owner
!= NULL
)
3358 table_owner
->output_section
= stub_control
.output_section();
3359 table_owner
->owner
= stub_control
.owner();;
3361 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3365 Stub_table
<size
, big_endian
>* stub_table
;
3367 if ((*t
)->owner
->is_input_section())
3368 stub_table
= new Stub_table
<size
, big_endian
>(this,
3369 (*t
)->output_section
,
3371 this->stub_tables_
.size());
3372 else if ((*t
)->owner
->is_relaxed_input_section())
3373 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3374 (*t
)->owner
->relaxed_input_section());
3377 this->stub_tables_
.push_back(stub_table
);
3383 static unsigned long
3384 max_branch_delta (unsigned int r_type
)
3386 if (r_type
== elfcpp::R_POWERPC_REL14
3387 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3388 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3390 if (r_type
== elfcpp::R_POWERPC_REL24
3391 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3392 || r_type
== elfcpp::R_PPC_PLTREL24
3393 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3398 // Return whether this branch is going via a plt call stub.
3400 template<int size
, bool big_endian
>
3402 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3403 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3406 Target_powerpc
* target
,
3407 Symbol_table
* symtab
)
3409 if (this->object_
!= ppc_object
3410 || this->shndx_
!= shndx
3411 || this->offset_
!= offset
)
3414 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3415 if (sym
!= NULL
&& sym
->is_forwarder())
3416 sym
= symtab
->resolve_forwards(sym
);
3417 if (target
->replace_tls_get_addr(sym
))
3418 sym
= target
->tls_get_addr_opt();
3419 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3421 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3422 && !target
->is_elfv2_localentry0(gsym
))
3423 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3424 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3432 // If this branch needs a plt call stub, or a long branch stub, make one.
3434 template<int size
, bool big_endian
>
3436 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3437 Stub_table
<size
, big_endian
>* stub_table
,
3438 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3439 Symbol_table
* symtab
) const
3441 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3442 Target_powerpc
<size
, big_endian
>* target
=
3443 static_cast<Target_powerpc
<size
, big_endian
>*>(
3444 parameters
->sized_target
<size
, big_endian
>());
3445 if (sym
!= NULL
&& sym
->is_forwarder())
3446 sym
= symtab
->resolve_forwards(sym
);
3447 if (target
->replace_tls_get_addr(sym
))
3448 sym
= target
->tls_get_addr_opt();
3449 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3453 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3454 : this->object_
->local_has_plt_offset(this->r_sym_
))
3458 && target
->abiversion() >= 2
3459 && !parameters
->options().output_is_position_independent()
3460 && !is_branch_reloc
<size
>(this->r_type_
))
3461 target
->glink_section()->add_global_entry(gsym
);
3464 if (stub_table
== NULL
3467 && !parameters
->options().output_is_position_independent()
3468 && !is_branch_reloc
<size
>(this->r_type_
)))
3469 stub_table
= this->object_
->stub_table(this->shndx_
);
3470 if (stub_table
== NULL
)
3472 // This is a ref from a data section to an ifunc symbol,
3473 // or a non-branch reloc for which we always want to use
3474 // one set of stubs for resolving function addresses.
3475 stub_table
= ifunc_stub_table
;
3477 gold_assert(stub_table
!= NULL
);
3478 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3479 if (from
!= invalid_address
)
3480 from
+= (this->object_
->output_section(this->shndx_
)->address()
3483 ok
= stub_table
->add_plt_call_entry(from
,
3484 this->object_
, gsym
,
3485 this->r_type_
, this->addend_
,
3488 ok
= stub_table
->add_plt_call_entry(from
,
3489 this->object_
, this->r_sym_
,
3490 this->r_type_
, this->addend_
,
3496 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3497 if (max_branch_offset
== 0)
3499 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3500 gold_assert(from
!= invalid_address
);
3501 from
+= (this->object_
->output_section(this->shndx_
)->address()
3506 switch (gsym
->source())
3508 case Symbol::FROM_OBJECT
:
3510 Object
* symobj
= gsym
->object();
3511 if (symobj
->is_dynamic()
3512 || symobj
->pluginobj() != NULL
)
3515 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3516 if (shndx
== elfcpp::SHN_UNDEF
)
3521 case Symbol::IS_UNDEFINED
:
3527 Symbol_table::Compute_final_value_status status
;
3528 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3529 if (status
!= Symbol_table::CFVS_OK
)
3532 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3536 const Symbol_value
<size
>* psymval
3537 = this->object_
->local_symbol(this->r_sym_
);
3538 Symbol_value
<size
> symval
;
3539 if (psymval
->is_section_symbol())
3540 symval
.set_is_section_symbol();
3541 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3542 typename
ObjType::Compute_final_local_value_status status
3543 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3545 if (status
!= ObjType::CFLV_OK
3546 || !symval
.has_output_value())
3548 to
= symval
.value(this->object_
, 0);
3550 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3552 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3553 to
+= this->addend_
;
3554 if (stub_table
== NULL
)
3555 stub_table
= this->object_
->stub_table(this->shndx_
);
3556 if (size
== 64 && target
->abiversion() < 2)
3558 unsigned int dest_shndx
;
3559 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3563 Address delta
= to
- from
;
3564 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3566 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3568 ? this->object_
->ppc64_needs_toc(gsym
)
3569 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3571 if (stub_table
== NULL
)
3573 gold_warning(_("%s:%s: branch in non-executable section,"
3574 " no long branch stub for you"),
3575 this->object_
->name().c_str(),
3576 this->object_
->section_name(this->shndx_
).c_str());
3579 bool save_res
= (size
== 64
3581 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3582 && gsym
->output_data() == target
->savres_section());
3583 ok
= stub_table
->add_long_branch_entry(this->object_
,
3585 from
, to
, save_res
);
3589 gold_debug(DEBUG_TARGET
,
3590 "branch at %s:%s+%#lx\n"
3591 "can't reach stub attached to %s:%s",
3592 this->object_
->name().c_str(),
3593 this->object_
->section_name(this->shndx_
).c_str(),
3594 (unsigned long) this->offset_
,
3595 stub_table
->relobj()->name().c_str(),
3596 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3601 // Relaxation hook. This is where we do stub generation.
3603 template<int size
, bool big_endian
>
3605 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3606 const Input_objects
*,
3607 Symbol_table
* symtab
,
3611 unsigned int prev_brlt_size
= 0;
3615 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3617 && this->abiversion() < 2
3619 && !parameters
->options().user_set_plt_thread_safe())
3621 static const char* const thread_starter
[] =
3625 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3627 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3628 "mq_notify", "create_timer",
3633 "GOMP_parallel_start",
3634 "GOMP_parallel_loop_static",
3635 "GOMP_parallel_loop_static_start",
3636 "GOMP_parallel_loop_dynamic",
3637 "GOMP_parallel_loop_dynamic_start",
3638 "GOMP_parallel_loop_guided",
3639 "GOMP_parallel_loop_guided_start",
3640 "GOMP_parallel_loop_runtime",
3641 "GOMP_parallel_loop_runtime_start",
3642 "GOMP_parallel_sections",
3643 "GOMP_parallel_sections_start",
3648 if (parameters
->options().shared())
3652 for (unsigned int i
= 0;
3653 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3656 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3657 thread_safe
= (sym
!= NULL
3659 && sym
->in_real_elf());
3665 this->plt_thread_safe_
= thread_safe
;
3670 this->stub_group_size_
= parameters
->options().stub_group_size();
3671 bool no_size_errors
= true;
3672 if (this->stub_group_size_
== 1)
3673 this->stub_group_size_
= 0x1c00000;
3674 else if (this->stub_group_size_
== -1)
3675 this->stub_group_size_
= -0x1e00000;
3677 no_size_errors
= false;
3678 this->group_sections(layout
, task
, no_size_errors
);
3680 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3682 this->branch_lookup_table_
.clear();
3683 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3684 p
!= this->stub_tables_
.end();
3687 (*p
)->clear_stubs(true);
3689 this->stub_tables_
.clear();
3690 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3691 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3692 program_name
, this->stub_group_size_
);
3693 this->group_sections(layout
, task
, true);
3696 // We need address of stub tables valid for make_stub.
3697 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3698 p
!= this->stub_tables_
.end();
3701 const Powerpc_relobj
<size
, big_endian
>* object
3702 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3703 Address off
= object
->get_output_section_offset((*p
)->shndx());
3704 gold_assert(off
!= invalid_address
);
3705 Output_section
* os
= (*p
)->output_section();
3706 (*p
)->set_address_and_size(os
, off
);
3711 // Clear plt call stubs, long branch stubs and branch lookup table.
3712 prev_brlt_size
= this->branch_lookup_table_
.size();
3713 this->branch_lookup_table_
.clear();
3714 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3715 p
!= this->stub_tables_
.end();
3718 (*p
)->clear_stubs(false);
3722 // Build all the stubs.
3723 this->relax_failed_
= false;
3724 Stub_table
<size
, big_endian
>* ifunc_stub_table
3725 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3726 Stub_table
<size
, big_endian
>* one_stub_table
3727 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3728 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3729 b
!= this->branch_info_
.end();
3732 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3733 && !this->relax_failed_
)
3735 this->relax_failed_
= true;
3736 this->relax_fail_count_
++;
3737 if (this->relax_fail_count_
< 3)
3741 bool do_resize
= false;
3742 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3743 p
!= this->stub_tables_
.end();
3745 if ((*p
)->need_resize())
3752 this->branch_lookup_table_
.clear();
3753 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3754 p
!= this->stub_tables_
.end();
3756 (*p
)->set_resizing(true);
3757 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3758 b
!= this->branch_info_
.end();
3761 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3762 && !this->relax_failed_
)
3764 this->relax_failed_
= true;
3765 this->relax_fail_count_
++;
3766 if (this->relax_fail_count_
< 3)
3770 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3771 p
!= this->stub_tables_
.end();
3773 (*p
)->set_resizing(false);
3776 // Did anything change size?
3777 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3778 bool again
= num_huge_branches
!= prev_brlt_size
;
3779 if (size
== 64 && num_huge_branches
!= 0)
3780 this->make_brlt_section(layout
);
3781 if (size
== 64 && again
)
3782 this->brlt_section_
->set_current_size(num_huge_branches
);
3784 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3785 p
!= this->stub_tables_
.rend();
3787 (*p
)->remove_eh_frame(layout
);
3789 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3790 p
!= this->stub_tables_
.end();
3792 (*p
)->add_eh_frame(layout
);
3794 typedef Unordered_set
<Output_section
*> Output_sections
;
3795 Output_sections os_need_update
;
3796 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3797 p
!= this->stub_tables_
.end();
3800 if ((*p
)->size_update())
3803 os_need_update
.insert((*p
)->output_section());
3807 // Set output section offsets for all input sections in an output
3808 // section that just changed size. Anything past the stubs will
3810 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3811 p
!= os_need_update
.end();
3814 Output_section
* os
= *p
;
3816 typedef Output_section::Input_section_list Input_section_list
;
3817 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3818 i
!= os
->input_sections().end();
3821 off
= align_address(off
, i
->addralign());
3822 if (i
->is_input_section() || i
->is_relaxed_input_section())
3823 i
->relobj()->set_section_offset(i
->shndx(), off
);
3824 if (i
->is_relaxed_input_section())
3826 Stub_table
<size
, big_endian
>* stub_table
3827 = static_cast<Stub_table
<size
, big_endian
>*>(
3828 i
->relaxed_input_section());
3829 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3830 off
+= stub_table_size
;
3831 // After a few iterations, set current stub table size
3832 // as min size threshold, so later stub tables can only
3835 stub_table
->set_min_size_threshold(stub_table_size
);
3838 off
+= i
->data_size();
3840 // If .branch_lt is part of this output section, then we have
3841 // just done the offset adjustment.
3842 os
->clear_section_offsets_need_adjustment();
3847 && num_huge_branches
!= 0
3848 && parameters
->options().output_is_position_independent())
3850 // Fill in the BRLT relocs.
3851 this->brlt_section_
->reset_brlt_sizes();
3852 for (typename
Branch_lookup_table::const_iterator p
3853 = this->branch_lookup_table_
.begin();
3854 p
!= this->branch_lookup_table_
.end();
3857 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3859 this->brlt_section_
->finalize_brlt_sizes();
3863 && (parameters
->options().user_set_emit_stub_syms()
3864 ? parameters
->options().emit_stub_syms()
3866 || parameters
->options().output_is_position_independent()
3867 || parameters
->options().emit_relocs())))
3869 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3870 p
!= this->stub_tables_
.end();
3872 (*p
)->define_stub_syms(symtab
);
3874 if (this->glink_
!= NULL
)
3876 int stub_size
= this->glink_
->pltresolve_size();
3877 Address value
= -stub_size
;
3883 this->define_local(symtab
, "__glink_PLTresolve",
3884 this->glink_
, value
, stub_size
);
3887 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3894 template<int size
, bool big_endian
>
3896 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3897 unsigned char* oview
,
3901 uint64_t address
= plt
->address();
3902 off_t len
= plt
->data_size();
3904 if (plt
== this->glink_
)
3906 // See Output_data_glink::do_write() for glink contents.
3909 gold_assert(parameters
->doing_static_link());
3910 // Static linking may need stubs, to support ifunc and long
3911 // branches. We need to create an output section for
3912 // .eh_frame early in the link process, to have a place to
3913 // attach stub .eh_frame info. We also need to have
3914 // registered a CIE that matches the stub CIE. Both of
3915 // these requirements are satisfied by creating an FDE and
3916 // CIE for .glink, even though static linking will leave
3917 // .glink zero length.
3918 // ??? Hopefully generating an FDE with a zero address range
3919 // won't confuse anything that consumes .eh_frame info.
3921 else if (size
== 64)
3923 // There is one word before __glink_PLTresolve
3927 else if (parameters
->options().output_is_position_independent())
3929 // There are two FDEs for a position independent glink.
3930 // The first covers the branch table, the second
3931 // __glink_PLTresolve at the end of glink.
3932 off_t resolve_size
= this->glink_
->pltresolve_size();
3933 if (oview
[9] == elfcpp::DW_CFA_nop
)
3934 len
-= resolve_size
;
3937 address
+= len
- resolve_size
;
3944 // Must be a stub table.
3945 const Stub_table
<size
, big_endian
>* stub_table
3946 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3947 uint64_t stub_address
= stub_table
->stub_address();
3948 len
-= stub_address
- address
;
3949 address
= stub_address
;
3952 *paddress
= address
;
3956 // A class to handle the PLT data.
3958 template<int size
, bool big_endian
>
3959 class Output_data_plt_powerpc
: public Output_section_data_build
3962 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3963 size
, big_endian
> Reloc_section
;
3965 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3966 Reloc_section
* plt_rel
,
3968 : Output_section_data_build(size
== 32 ? 4 : 8),
3974 // Add an entry to the PLT.
3979 add_ifunc_entry(Symbol
*);
3982 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3985 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3987 // Return the .rela.plt section data.
3994 // Return the number of PLT entries.
3998 if (this->current_data_size() == 0)
4000 return ((this->current_data_size() - this->first_plt_entry_offset())
4001 / this->plt_entry_size());
4006 do_adjust_output_section(Output_section
* os
)
4011 // Write to a map file.
4013 do_print_to_mapfile(Mapfile
* mapfile
) const
4014 { mapfile
->print_output_data(this, this->name_
); }
4017 // Return the offset of the first non-reserved PLT entry.
4019 first_plt_entry_offset() const
4021 // IPLT and LPLT have no reserved entry.
4022 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
4024 return this->targ_
->first_plt_entry_offset();
4027 // Return the size of each PLT entry.
4029 plt_entry_size() const
4031 return this->targ_
->plt_entry_size();
4034 // Write out the PLT data.
4036 do_write(Output_file
*);
4038 // The reloc section.
4039 Reloc_section
* rel_
;
4040 // Allows access to .glink for do_write.
4041 Target_powerpc
<size
, big_endian
>* targ_
;
4042 // What to report in map file.
4046 // Add an entry to the PLT.
4048 template<int size
, bool big_endian
>
4050 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4052 if (!gsym
->has_plt_offset())
4054 section_size_type off
= this->current_data_size();
4056 off
+= this->first_plt_entry_offset();
4057 gsym
->set_plt_offset(off
);
4058 gsym
->set_needs_dynsym_entry();
4059 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4060 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4061 off
+= this->plt_entry_size();
4062 this->set_current_data_size(off
);
4066 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4068 template<int size
, bool big_endian
>
4070 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4072 if (!gsym
->has_plt_offset())
4074 section_size_type off
= this->current_data_size();
4075 gsym
->set_plt_offset(off
);
4076 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4077 if (size
== 64 && this->targ_
->abiversion() < 2)
4078 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4079 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4080 off
+= this->plt_entry_size();
4081 this->set_current_data_size(off
);
4085 // Add an entry for a local symbol to the PLT.
4087 template<int size
, bool big_endian
>
4089 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4090 Sized_relobj_file
<size
, big_endian
>* relobj
,
4091 unsigned int local_sym_index
)
4093 if (!relobj
->local_has_plt_offset(local_sym_index
))
4095 section_size_type off
= this->current_data_size();
4096 relobj
->set_local_plt_offset(local_sym_index
, off
);
4099 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4100 if (size
== 64 && this->targ_
->abiversion() < 2)
4101 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4102 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4103 dynrel
, this, off
, 0);
4105 off
+= this->plt_entry_size();
4106 this->set_current_data_size(off
);
4110 // Add an entry for a local ifunc symbol to the IPLT.
4112 template<int size
, bool big_endian
>
4114 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4115 Sized_relobj_file
<size
, big_endian
>* relobj
,
4116 unsigned int local_sym_index
)
4118 if (!relobj
->local_has_plt_offset(local_sym_index
))
4120 section_size_type off
= this->current_data_size();
4121 relobj
->set_local_plt_offset(local_sym_index
, off
);
4122 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4123 if (size
== 64 && this->targ_
->abiversion() < 2)
4124 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4125 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4127 off
+= this->plt_entry_size();
4128 this->set_current_data_size(off
);
4132 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4133 static const uint32_t add_2_2_11
= 0x7c425a14;
4134 static const uint32_t add_2_2_12
= 0x7c426214;
4135 static const uint32_t add_3_3_2
= 0x7c631214;
4136 static const uint32_t add_3_3_13
= 0x7c636a14;
4137 static const uint32_t add_3_12_2
= 0x7c6c1214;
4138 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4139 static const uint32_t add_11_0_11
= 0x7d605a14;
4140 static const uint32_t add_11_2_11
= 0x7d625a14;
4141 static const uint32_t add_11_11_2
= 0x7d6b1214;
4142 static const uint32_t add_12_11_12
= 0x7d8b6214;
4143 static const uint32_t addi_0_12
= 0x380c0000;
4144 static const uint32_t addi_2_2
= 0x38420000;
4145 static const uint32_t addi_3_3
= 0x38630000;
4146 static const uint32_t addi_11_11
= 0x396b0000;
4147 static const uint32_t addi_12_1
= 0x39810000;
4148 static const uint32_t addi_12_11
= 0x398b0000;
4149 static const uint32_t addi_12_12
= 0x398c0000;
4150 static const uint32_t addis_0_2
= 0x3c020000;
4151 static const uint32_t addis_0_13
= 0x3c0d0000;
4152 static const uint32_t addis_2_12
= 0x3c4c0000;
4153 static const uint32_t addis_11_2
= 0x3d620000;
4154 static const uint32_t addis_11_11
= 0x3d6b0000;
4155 static const uint32_t addis_11_30
= 0x3d7e0000;
4156 static const uint32_t addis_12_1
= 0x3d810000;
4157 static const uint32_t addis_12_2
= 0x3d820000;
4158 static const uint32_t addis_12_11
= 0x3d8b0000;
4159 static const uint32_t addis_12_12
= 0x3d8c0000;
4160 static const uint32_t b
= 0x48000000;
4161 static const uint32_t bcl_20_31
= 0x429f0005;
4162 static const uint32_t bctr
= 0x4e800420;
4163 static const uint32_t bctrl
= 0x4e800421;
4164 static const uint32_t beqlr
= 0x4d820020;
4165 static const uint32_t blr
= 0x4e800020;
4166 static const uint32_t bnectr_p4
= 0x4ce20420;
4167 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4168 static const uint32_t cmpldi_2_0
= 0x28220000;
4169 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4170 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4171 static const uint32_t cror_15_15_15
= 0x4def7b82;
4172 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4173 static const uint32_t ld_0_1
= 0xe8010000;
4174 static const uint32_t ld_0_12
= 0xe80c0000;
4175 static const uint32_t ld_2_1
= 0xe8410000;
4176 static const uint32_t ld_2_2
= 0xe8420000;
4177 static const uint32_t ld_2_11
= 0xe84b0000;
4178 static const uint32_t ld_2_12
= 0xe84c0000;
4179 static const uint32_t ld_11_1
= 0xe9610000;
4180 static const uint32_t ld_11_2
= 0xe9620000;
4181 static const uint32_t ld_11_3
= 0xe9630000;
4182 static const uint32_t ld_11_11
= 0xe96b0000;
4183 static const uint32_t ld_12_2
= 0xe9820000;
4184 static const uint32_t ld_12_3
= 0xe9830000;
4185 static const uint32_t ld_12_11
= 0xe98b0000;
4186 static const uint32_t ld_12_12
= 0xe98c0000;
4187 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4188 static const uint32_t lfd_0_1
= 0xc8010000;
4189 static const uint32_t li_0_0
= 0x38000000;
4190 static const uint32_t li_11_0
= 0x39600000;
4191 static const uint32_t li_12_0
= 0x39800000;
4192 static const uint32_t lis_0
= 0x3c000000;
4193 static const uint32_t lis_2
= 0x3c400000;
4194 static const uint32_t lis_11
= 0x3d600000;
4195 static const uint32_t lis_12
= 0x3d800000;
4196 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4197 static const uint32_t lwz_0_12
= 0x800c0000;
4198 static const uint32_t lwz_11_3
= 0x81630000;
4199 static const uint32_t lwz_11_11
= 0x816b0000;
4200 static const uint32_t lwz_11_30
= 0x817e0000;
4201 static const uint32_t lwz_12_3
= 0x81830000;
4202 static const uint32_t lwz_12_12
= 0x818c0000;
4203 static const uint32_t lwzu_0_12
= 0x840c0000;
4204 static const uint32_t mflr_0
= 0x7c0802a6;
4205 static const uint32_t mflr_11
= 0x7d6802a6;
4206 static const uint32_t mflr_12
= 0x7d8802a6;
4207 static const uint32_t mr_0_3
= 0x7c601b78;
4208 static const uint32_t mr_3_0
= 0x7c030378;
4209 static const uint32_t mtctr_0
= 0x7c0903a6;
4210 static const uint32_t mtctr_11
= 0x7d6903a6;
4211 static const uint32_t mtctr_12
= 0x7d8903a6;
4212 static const uint32_t mtlr_0
= 0x7c0803a6;
4213 static const uint32_t mtlr_11
= 0x7d6803a6;
4214 static const uint32_t mtlr_12
= 0x7d8803a6;
4215 static const uint32_t nop
= 0x60000000;
4216 static const uint32_t ori_0_0_0
= 0x60000000;
4217 static const uint32_t ori_11_11_0
= 0x616b0000;
4218 static const uint32_t ori_12_12_0
= 0x618c0000;
4219 static const uint32_t oris_12_12_0
= 0x658c0000;
4220 static const uint32_t sldi_11_11_34
= 0x796b1746;
4221 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4222 static const uint32_t srdi_0_0_2
= 0x7800f082;
4223 static const uint32_t std_0_1
= 0xf8010000;
4224 static const uint32_t std_0_12
= 0xf80c0000;
4225 static const uint32_t std_2_1
= 0xf8410000;
4226 static const uint32_t std_11_1
= 0xf9610000;
4227 static const uint32_t stfd_0_1
= 0xd8010000;
4228 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4229 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4230 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4231 static const uint32_t xor_2_12_12
= 0x7d826278;
4232 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4234 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4235 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4236 static const uint64_t pnop
= 0x0700000000000000ULL
;
4238 // Write out the PLT.
4240 template<int size
, bool big_endian
>
4242 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4244 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4246 const section_size_type offset
= this->offset();
4247 const section_size_type oview_size
4248 = convert_to_section_size_type(this->data_size());
4249 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4250 unsigned char* pov
= oview
;
4251 unsigned char* endpov
= oview
+ oview_size
;
4253 // The address of the .glink branch table
4254 const Output_data_glink
<size
, big_endian
>* glink
4255 = this->targ_
->glink_section();
4256 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4258 while (pov
< endpov
)
4260 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4265 of
->write_output_view(offset
, oview_size
, oview
);
4269 // Create the PLT section.
4271 template<int size
, bool big_endian
>
4273 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4276 if (this->plt_
== NULL
)
4278 if (this->got_
== NULL
)
4279 this->got_section(symtab
, layout
);
4281 if (this->glink_
== NULL
)
4282 make_glink_section(layout
);
4284 // Ensure that .rela.dyn always appears before .rela.plt This is
4285 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4286 // needs to include .rela.plt in its range.
4287 this->rela_dyn_section(layout
);
4289 Reloc_section
* plt_rel
= new Reloc_section(false);
4290 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4291 elfcpp::SHF_ALLOC
, plt_rel
,
4292 ORDER_DYNAMIC_PLT_RELOCS
, false);
4294 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4296 layout
->add_output_section_data(".plt",
4298 ? elfcpp::SHT_PROGBITS
4299 : elfcpp::SHT_NOBITS
),
4300 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4307 Output_section
* rela_plt_os
= plt_rel
->output_section();
4308 rela_plt_os
->set_info_section(this->plt_
->output_section());
4312 // Create the IPLT section.
4314 template<int size
, bool big_endian
>
4316 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4319 if (this->iplt_
== NULL
)
4321 this->make_plt_section(symtab
, layout
);
4322 this->make_lplt_section(layout
);
4324 Reloc_section
* iplt_rel
= new Reloc_section(false);
4325 if (this->rela_dyn_
->output_section())
4326 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4328 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4330 if (this->plt_
->output_section())
4331 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4335 // Create the LPLT section.
4337 template<int size
, bool big_endian
>
4339 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4341 if (this->lplt_
== NULL
)
4343 Reloc_section
* lplt_rel
= NULL
;
4344 if (parameters
->options().output_is_position_independent())
4346 lplt_rel
= new Reloc_section(false);
4347 this->rela_dyn_section(layout
);
4348 if (this->rela_dyn_
->output_section())
4349 this->rela_dyn_
->output_section()
4350 ->add_output_section_data(lplt_rel
);
4353 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4355 this->make_brlt_section(layout
);
4356 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4357 this->brlt_section_
->output_section()
4358 ->add_output_section_data(this->lplt_
);
4360 layout
->add_output_section_data(".branch_lt",
4361 elfcpp::SHT_PROGBITS
,
4362 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4369 // A section for huge long branch addresses, similar to plt section.
4371 template<int size
, bool big_endian
>
4372 class Output_data_brlt_powerpc
: public Output_section_data_build
4375 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4376 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4377 size
, big_endian
> Reloc_section
;
4379 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4380 Reloc_section
* brlt_rel
)
4381 : Output_section_data_build(size
== 32 ? 4 : 8),
4389 this->reset_data_size();
4390 this->rel_
->reset_data_size();
4394 finalize_brlt_sizes()
4396 this->finalize_data_size();
4397 this->rel_
->finalize_data_size();
4400 // Add a reloc for an entry in the BRLT.
4402 add_reloc(Address to
, unsigned int off
)
4403 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4405 // Update section and reloc section size.
4407 set_current_size(unsigned int num_branches
)
4409 this->reset_address_and_file_offset();
4410 this->set_current_data_size(num_branches
* 16);
4411 this->finalize_data_size();
4412 Output_section
* os
= this->output_section();
4413 os
->set_section_offsets_need_adjustment();
4414 if (this->rel_
!= NULL
)
4416 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4417 this->rel_
->reset_address_and_file_offset();
4418 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4419 this->rel_
->finalize_data_size();
4420 Output_section
* os
= this->rel_
->output_section();
4421 os
->set_section_offsets_need_adjustment();
4427 do_adjust_output_section(Output_section
* os
)
4432 // Write to a map file.
4434 do_print_to_mapfile(Mapfile
* mapfile
) const
4435 { mapfile
->print_output_data(this, "** BRLT"); }
4438 // Write out the BRLT data.
4440 do_write(Output_file
*);
4442 // The reloc section.
4443 Reloc_section
* rel_
;
4444 Target_powerpc
<size
, big_endian
>* targ_
;
4447 // Make the branch lookup table section.
4449 template<int size
, bool big_endian
>
4451 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4453 if (size
== 64 && this->brlt_section_
== NULL
)
4455 Reloc_section
* brlt_rel
= NULL
;
4456 bool is_pic
= parameters
->options().output_is_position_independent();
4459 // When PIC we can't fill in .branch_lt but must initialise at
4460 // runtime via dynamic relocations.
4461 this->rela_dyn_section(layout
);
4462 brlt_rel
= new Reloc_section(false);
4463 if (this->rela_dyn_
->output_section())
4464 this->rela_dyn_
->output_section()
4465 ->add_output_section_data(brlt_rel
);
4468 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4469 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4470 this->plt_
->output_section()
4471 ->add_output_section_data(this->brlt_section_
);
4473 layout
->add_output_section_data(".branch_lt",
4474 elfcpp::SHT_PROGBITS
,
4475 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4476 this->brlt_section_
,
4482 // Write out .branch_lt when non-PIC.
4484 template<int size
, bool big_endian
>
4486 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4488 if (size
== 64 && !parameters
->options().output_is_position_independent())
4490 const section_size_type offset
= this->offset();
4491 const section_size_type oview_size
4492 = convert_to_section_size_type(this->data_size());
4493 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4495 this->targ_
->write_branch_lookup_table(oview
);
4496 of
->write_output_view(offset
, oview_size
, oview
);
4500 static inline uint32_t
4506 static inline uint32_t
4512 static inline uint32_t
4515 return hi(a
+ 0x8000);
4518 static inline uint64_t
4521 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4524 static inline uint64_t
4527 return (v
+ (1ULL << 33)) >> 34;
4533 static const unsigned char eh_frame_cie
[12];
4537 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4540 'z', 'R', 0, // Augmentation string.
4541 4, // Code alignment.
4542 0x80 - size
/ 8 , // Data alignment.
4544 1, // Augmentation size.
4545 (elfcpp::DW_EH_PE_pcrel
4546 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4547 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4550 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4551 static const unsigned char glink_eh_frame_fde_64v1
[] =
4553 0, 0, 0, 0, // Replaced with offset to .glink.
4554 0, 0, 0, 0, // Replaced with size of .glink.
4555 0, // Augmentation size.
4556 elfcpp::DW_CFA_advance_loc
+ 1,
4557 elfcpp::DW_CFA_register
, 65, 12,
4558 elfcpp::DW_CFA_advance_loc
+ 5,
4559 elfcpp::DW_CFA_restore_extended
, 65
4562 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4563 static const unsigned char glink_eh_frame_fde_64v2
[] =
4565 0, 0, 0, 0, // Replaced with offset to .glink.
4566 0, 0, 0, 0, // Replaced with size of .glink.
4567 0, // Augmentation size.
4568 elfcpp::DW_CFA_advance_loc
+ 1,
4569 elfcpp::DW_CFA_register
, 65, 0,
4570 elfcpp::DW_CFA_advance_loc
+ 7,
4571 elfcpp::DW_CFA_restore_extended
, 65
4574 // Describe __glink_PLTresolve use of LR, 32-bit version.
4575 static const unsigned char glink_eh_frame_fde_32
[] =
4577 0, 0, 0, 0, // Replaced with offset to .glink.
4578 0, 0, 0, 0, // Replaced with size of .glink.
4579 0, // Augmentation size.
4580 elfcpp::DW_CFA_advance_loc
+ 2,
4581 elfcpp::DW_CFA_register
, 65, 0,
4582 elfcpp::DW_CFA_advance_loc
+ 4,
4583 elfcpp::DW_CFA_restore_extended
, 65
4586 static const unsigned char default_fde
[] =
4588 0, 0, 0, 0, // Replaced with offset to stubs.
4589 0, 0, 0, 0, // Replaced with size of stubs.
4590 0, // Augmentation size.
4591 elfcpp::DW_CFA_nop
, // Pad.
4596 template<bool big_endian
>
4598 write_insn(unsigned char* p
, uint32_t v
)
4600 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4604 static inline unsigned int
4607 if (!parameters
->options().user_set_plt_align())
4608 return size
== 64 ? 32 : 8;
4609 return 1 << parameters
->options().plt_align();
4612 // Stub_table holds information about plt and long branch stubs.
4613 // Stubs are built in an area following some input section determined
4614 // by group_sections(). This input section is converted to a relaxed
4615 // input section allowing it to be resized to accommodate the stubs
4617 template<int size
, bool big_endian
>
4618 class Stub_table
: public Output_relaxed_input_section
4623 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4624 : off_(off
), indx_(indx
), iter_(0), notoc_(0), r2save_(0), localentry0_(0)
4628 unsigned int indx_
: 28;
4629 unsigned int iter_
: 1;
4630 unsigned int notoc_
: 1;
4631 unsigned int r2save_
: 1;
4632 unsigned int localentry0_
: 1;
4634 struct Branch_stub_ent
4636 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4637 : off_(off
), iter_(false), notoc_(notoc
), save_res_(save_res
)
4645 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4646 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4648 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4649 Output_section
* output_section
,
4650 const Output_section::Input_section
* owner
,
4652 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4654 ->section_addralign(owner
->shndx())),
4655 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4656 orig_data_size_(owner
->current_data_size()),
4657 plt_size_(0), last_plt_size_(0),
4658 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4659 need_save_res_(false), need_resize_(false), resizing_(false),
4662 this->set_output_section(output_section
);
4664 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4665 new_relaxed
.push_back(this);
4666 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4669 // Add a plt call stub.
4671 add_plt_call_entry(Address
,
4672 const Sized_relobj_file
<size
, big_endian
>*,
4679 add_plt_call_entry(Address
,
4680 const Sized_relobj_file
<size
, big_endian
>*,
4686 // Find a given plt call stub.
4688 find_plt_call_entry(const Symbol
*) const;
4691 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4692 unsigned int) const;
4695 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4701 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4706 // Add a long branch stub.
4708 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4709 unsigned int, Address
, Address
, bool);
4711 const Branch_stub_ent
*
4712 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4716 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4718 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4719 if (max_branch_offset
== 0)
4721 gold_assert(from
!= invalid_address
);
4722 Address loc
= off
+ this->stub_address();
4723 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4727 clear_stubs(bool all
)
4729 this->plt_call_stubs_
.clear();
4730 this->plt_size_
= 0;
4731 this->long_branch_stubs_
.clear();
4732 this->branch_size_
= 0;
4733 this->need_save_res_
= false;
4736 this->last_plt_size_
= 0;
4737 this->last_branch_size_
= 0;
4743 { return need_resize_
; }
4746 set_resizing(bool val
)
4748 this->resizing_
= val
;
4751 this->need_resize_
= false;
4752 this->plt_size_
= 0;
4753 this->branch_size_
= 0;
4754 this->need_save_res_
= false;
4759 set_address_and_size(const Output_section
* os
, Address off
)
4761 Address start_off
= off
;
4762 off
+= this->orig_data_size_
;
4763 Address my_size
= this->plt_size_
+ this->branch_size_
;
4764 if (this->need_save_res_
)
4765 my_size
+= this->targ_
->savres_section()->data_size();
4767 off
= align_address(off
, this->stub_align());
4768 // Include original section size and alignment padding in size
4769 my_size
+= off
- start_off
;
4770 // Ensure new size is always larger than min size
4771 // threshold. Alignment requirement is included in "my_size", so
4772 // increase "my_size" does not invalidate alignment.
4773 if (my_size
< this->min_size_threshold_
)
4774 my_size
= this->min_size_threshold_
;
4775 this->reset_address_and_file_offset();
4776 this->set_current_data_size(my_size
);
4777 this->set_address_and_file_offset(os
->address() + start_off
,
4778 os
->offset() + start_off
);
4783 stub_address() const
4785 return align_address(this->address() + this->orig_data_size_
,
4786 this->stub_align());
4792 return align_address(this->offset() + this->orig_data_size_
,
4793 this->stub_align());
4798 { return this->plt_size_
; }
4802 { return this->branch_size_
; }
4805 set_min_size_threshold(Address min_size
)
4806 { this->min_size_threshold_
= min_size
; }
4809 define_stub_syms(Symbol_table
*);
4814 Output_section
* os
= this->output_section();
4815 if (os
->addralign() < this->stub_align())
4817 os
->set_addralign(this->stub_align());
4818 // FIXME: get rid of the insane checkpointing.
4819 // We can't increase alignment of the input section to which
4820 // stubs are attached; The input section may be .init which
4821 // is pasted together with other .init sections to form a
4822 // function. Aligning might insert zero padding resulting in
4823 // sigill. However we do need to increase alignment of the
4824 // output section so that the align_address() on offset in
4825 // set_address_and_size() adds the same padding as the
4826 // align_address() on address in stub_address().
4827 // What's more, we need this alignment for the layout done in
4828 // relaxation_loop_body() so that the output section starts at
4829 // a suitably aligned address.
4830 os
->checkpoint_set_addralign(this->stub_align());
4832 if (this->last_plt_size_
!= this->plt_size_
4833 || this->last_branch_size_
!= this->branch_size_
)
4835 this->last_plt_size_
= this->plt_size_
;
4836 this->last_branch_size_
= this->branch_size_
;
4842 // Add .eh_frame info for this stub section.
4844 add_eh_frame(Layout
* layout
);
4846 // Remove .eh_frame info for this stub section.
4848 remove_eh_frame(Layout
* layout
);
4850 Target_powerpc
<size
, big_endian
>*
4856 class Plt_stub_key_hash
;
4857 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4858 Plt_stub_key_hash
> Plt_stub_entries
;
4859 class Branch_stub_key
;
4860 class Branch_stub_key_hash
;
4861 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4862 Branch_stub_key_hash
> Branch_stub_entries
;
4864 // Alignment of stub section.
4868 unsigned int min_align
= size
== 64 ? 32 : 16;
4869 unsigned int user_align
= 1 << parameters
->options().plt_align();
4870 return std::max(user_align
, min_align
);
4873 // Return the plt offset for the given call stub.
4875 plt_off(typename
Plt_stub_entries::const_iterator p
,
4876 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4878 const Symbol
* gsym
= p
->first
.sym_
;
4880 return this->targ_
->plt_off(gsym
, sec
);
4883 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4884 unsigned int local_sym_index
= p
->first
.locsym_
;
4885 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4889 // Size of a given plt call stub.
4891 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const;
4894 plt_call_align(unsigned int bytes
) const
4896 unsigned int align
= param_plt_align
<size
>();
4897 return (bytes
+ align
- 1) & -align
;
4900 // Return long branch stub size.
4902 branch_stub_size(typename
Branch_stub_entries::const_iterator p
,
4906 build_tls_opt_head(unsigned char** pp
,
4907 typename
Plt_stub_entries::const_iterator cs
);
4910 build_tls_opt_tail(unsigned char* p
,
4911 typename
Plt_stub_entries::const_iterator cs
);
4914 plt_error(const Plt_stub_key
& p
);
4918 do_write(Output_file
*);
4920 // Plt call stub keys.
4924 Plt_stub_key(const Symbol
* sym
)
4925 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4928 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4929 unsigned int locsym_index
)
4930 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4933 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4935 unsigned int r_type
,
4937 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4940 this->addend_
= addend
;
4941 else if (parameters
->options().output_is_position_independent()
4942 && (r_type
== elfcpp::R_PPC_PLTREL24
4943 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4945 this->addend_
= addend
;
4946 if (this->addend_
>= 32768)
4947 this->object_
= object
;
4951 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4952 unsigned int locsym_index
,
4953 unsigned int r_type
,
4955 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4958 this->addend_
= addend
;
4959 else if (parameters
->options().output_is_position_independent()
4960 && (r_type
== elfcpp::R_PPC_PLTREL24
4961 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4962 this->addend_
= addend
;
4965 bool operator==(const Plt_stub_key
& that
) const
4967 return (this->sym_
== that
.sym_
4968 && this->object_
== that
.object_
4969 && this->addend_
== that
.addend_
4970 && this->locsym_
== that
.locsym_
);
4974 const Sized_relobj_file
<size
, big_endian
>* object_
;
4975 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4976 unsigned int locsym_
;
4979 class Plt_stub_key_hash
4982 size_t operator()(const Plt_stub_key
& ent
) const
4984 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4985 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
4991 // Long branch stub keys.
4992 class Branch_stub_key
4995 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
4996 : dest_(to
), toc_base_off_(0)
4999 toc_base_off_
= obj
->toc_base_offset();
5002 bool operator==(const Branch_stub_key
& that
) const
5004 return (this->dest_
== that
.dest_
5006 || this->toc_base_off_
== that
.toc_base_off_
));
5010 unsigned int toc_base_off_
;
5013 class Branch_stub_key_hash
5016 size_t operator()(const Branch_stub_key
& key
) const
5017 { return key
.dest_
^ key
.toc_base_off_
; }
5020 // In a sane world this would be a global.
5021 Target_powerpc
<size
, big_endian
>* targ_
;
5022 // Map sym/object/addend to stub offset.
5023 Plt_stub_entries plt_call_stubs_
;
5024 // Map destination address to stub offset.
5025 Branch_stub_entries long_branch_stubs_
;
5026 // size of input section
5027 section_size_type orig_data_size_
;
5029 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
5030 // Some rare cases cause (PR/20529) fluctuation in stub table
5031 // size, which leads to an endless relax loop. This is to be fixed
5032 // by, after the first few iterations, allowing only increase of
5033 // stub table size. This variable sets the minimal possible size of
5034 // a stub table, it is zero for the first few iterations, then
5035 // increases monotonically.
5036 Address min_size_threshold_
;
5037 // Set if this stub group needs a copy of out-of-line register
5038 // save/restore functions.
5039 bool need_save_res_
;
5040 // Set when notoc_/r2save_ changes after sizing a stub
5042 // Set when resizing stubs
5044 // Per stub table unique identifier.
5048 // Add a plt call stub, if we do not already have one for this
5049 // sym/object/addend combo.
5051 template<int size
, bool big_endian
>
5053 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5055 const Sized_relobj_file
<size
, big_endian
>* object
,
5057 unsigned int r_type
,
5061 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5062 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5063 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5064 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5068 && this->targ_
->is_elfv2_localentry0(gsym
))
5070 p
.first
->second
.localentry0_
= 1;
5071 this->targ_
->set_has_localentry0();
5073 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5075 if (!p
.second
&& !p
.first
->second
.notoc_
5076 && !this->targ_
->powerxx_stubs())
5077 this->need_resize_
= true;
5078 p
.first
->second
.notoc_
= 1;
5080 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
5082 if (!p
.second
&& !p
.first
->second
.r2save_
)
5083 this->need_resize_
= true;
5084 p
.first
->second
.r2save_
= 1;
5087 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5089 if (this->resizing_
)
5091 p
.first
->second
.iter_
= 1;
5092 p
.first
->second
.off_
= this->plt_size_
;
5094 this->plt_size_
+= this->plt_call_size(p
.first
);
5095 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5096 this->targ_
->set_has_tls_get_addr_opt();
5097 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5099 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5102 template<int size
, bool big_endian
>
5104 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5106 const Sized_relobj_file
<size
, big_endian
>* object
,
5107 unsigned int locsym_index
,
5108 unsigned int r_type
,
5112 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5113 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5114 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5115 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5119 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5121 p
.first
->second
.localentry0_
= 1;
5122 this->targ_
->set_has_localentry0();
5124 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5126 if (!p
.second
&& !p
.first
->second
.notoc_
5127 && !this->targ_
->powerxx_stubs())
5128 this->need_resize_
= true;
5129 p
.first
->second
.notoc_
= 1;
5131 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
5133 if (!p
.second
&& !p
.first
->second
.r2save_
)
5134 this->need_resize_
= true;
5135 p
.first
->second
.r2save_
= 1;
5138 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5140 if (this->resizing_
)
5142 p
.first
->second
.iter_
= 1;
5143 p
.first
->second
.off_
= this->plt_size_
;
5145 this->plt_size_
+= this->plt_call_size(p
.first
);
5146 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5148 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5151 // Find a plt call stub.
5153 template<int size
, bool big_endian
>
5154 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5155 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5156 const Sized_relobj_file
<size
, big_endian
>* object
,
5158 unsigned int r_type
,
5159 Address addend
) const
5161 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5162 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5163 if (p
== this->plt_call_stubs_
.end())
5168 template<int size
, bool big_endian
>
5169 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5170 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5172 Plt_stub_key
key(gsym
);
5173 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5174 if (p
== this->plt_call_stubs_
.end())
5179 template<int size
, bool big_endian
>
5180 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5181 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5182 const Sized_relobj_file
<size
, big_endian
>* object
,
5183 unsigned int locsym_index
,
5184 unsigned int r_type
,
5185 Address addend
) const
5187 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5188 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5189 if (p
== this->plt_call_stubs_
.end())
5194 template<int size
, bool big_endian
>
5195 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5196 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5197 const Sized_relobj_file
<size
, big_endian
>* object
,
5198 unsigned int locsym_index
) const
5200 Plt_stub_key
key(object
, locsym_index
);
5201 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5202 if (p
== this->plt_call_stubs_
.end())
5207 // Add a long branch stub if we don't already have one to given
5210 template<int size
, bool big_endian
>
5212 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5213 const Powerpc_relobj
<size
, big_endian
>* object
,
5214 unsigned int r_type
,
5219 Branch_stub_key
key(object
, to
);
5220 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5221 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5222 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5223 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5224 if (notoc
&& !p
.first
->second
.notoc_
)
5226 this->need_resize_
= true;
5227 p
.first
->second
.notoc_
= true;
5229 gold_assert(save_res
== p
.first
->second
.save_res_
);
5230 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5232 if (this->resizing_
)
5234 p
.first
->second
.iter_
= 1;
5235 p
.first
->second
.off_
= this->branch_size_
;
5238 this->need_save_res_
= true;
5241 bool need_lt
= false;
5242 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5243 this->branch_size_
+= stub_size
;
5244 if (size
== 64 && need_lt
)
5245 this->targ_
->add_branch_lookup_table(to
);
5248 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5251 // Find long branch stub offset.
5253 template<int size
, bool big_endian
>
5254 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5255 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5256 const Powerpc_relobj
<size
, big_endian
>* object
,
5259 Branch_stub_key
key(object
, to
);
5260 typename
Branch_stub_entries::const_iterator p
5261 = this->long_branch_stubs_
.find(key
);
5262 if (p
== this->long_branch_stubs_
.end())
5267 template<bool big_endian
>
5269 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5273 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5274 else if (delta
< 256)
5276 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5277 fde
.push_back(delta
);
5279 else if (delta
< 65536)
5281 fde
.resize(fde
.size() + 3);
5282 unsigned char *p
= &*fde
.end() - 3;
5283 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5284 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5288 fde
.resize(fde
.size() + 5);
5289 unsigned char *p
= &*fde
.end() - 5;
5290 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5291 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5295 template<typename T
>
5297 stub_sort(T s1
, T s2
)
5299 return s1
->second
.off_
< s2
->second
.off_
;
5302 // Add .eh_frame info for this stub section. Unlike other linker
5303 // generated .eh_frame this is added late in the link, because we
5304 // only want the .eh_frame info if this particular stub section is
5307 template<int size
, bool big_endian
>
5309 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5312 || !parameters
->options().ld_generated_unwind_info())
5315 // Since we add stub .eh_frame info late, it must be placed
5316 // after all other linker generated .eh_frame info so that
5317 // merge mapping need not be updated for input sections.
5318 // There is no provision to use a different CIE to that used
5320 if (!this->targ_
->has_glink())
5323 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5324 std::vector
<plt_iter
> calls
;
5325 if (!this->plt_call_stubs_
.empty())
5326 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5327 cs
!= this->plt_call_stubs_
.end();
5329 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5330 && cs
->second
.r2save_
5331 && !cs
->second
.localentry0_
)
5332 || (cs
->second
.notoc_
5333 && !this->targ_
->powerxx_stubs()))
5334 calls
.push_back(cs
);
5335 if (calls
.size() > 1)
5336 std::stable_sort(calls
.begin(), calls
.end(),
5337 stub_sort
<plt_iter
>);
5339 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5340 std::vector
<branch_iter
> branches
;
5341 if (!this->long_branch_stubs_
.empty()
5342 && !this->targ_
->powerxx_stubs())
5343 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5344 bs
!= this->long_branch_stubs_
.end();
5346 if (bs
->second
.notoc_
)
5347 branches
.push_back(bs
);
5348 if (branches
.size() > 1)
5349 std::stable_sort(branches
.begin(), branches
.end(),
5350 stub_sort
<branch_iter
>);
5352 if (calls
.empty() && branches
.empty())
5355 unsigned int last_eh_loc
= 0;
5356 // offset pcrel sdata4, size udata4, and augmentation size byte.
5357 std::vector
<unsigned char> fde(9, 0);
5359 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5361 plt_iter cs
= calls
[i
];
5362 unsigned int off
= cs
->second
.off_
;
5363 // The __tls_get_addr_opt call stub needs to describe where
5364 // it saves LR, to support exceptions that might be thrown
5365 // from __tls_get_addr, and to support asynchronous exceptions.
5366 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5369 if (cs
->second
.r2save_
5370 && !cs
->second
.localentry0_
)
5373 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5374 fde
.resize(fde
.size() + 6);
5375 unsigned char* p
= &*fde
.end() - 6;
5376 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5378 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5379 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5380 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5381 *p
++ = elfcpp::DW_CFA_restore_extended
;
5383 last_eh_loc
= off
+ delta
;
5387 // notoc stubs also should describe LR changes, to support
5388 // asynchronous exceptions.
5389 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5390 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5391 fde
.resize(fde
.size() + 6);
5392 unsigned char* p
= &*fde
.end() - 6;
5393 *p
++ = elfcpp::DW_CFA_register
;
5396 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5397 *p
++ = elfcpp::DW_CFA_restore_extended
;
5399 last_eh_loc
= off
+ 8;
5402 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5404 branch_iter bs
= branches
[i
];
5405 unsigned int off
= bs
->second
.off_
+ 8;
5406 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5407 fde
.resize(fde
.size() + 6);
5408 unsigned char* p
= &*fde
.end() - 6;
5409 *p
++ = elfcpp::DW_CFA_register
;
5412 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5413 *p
++ = elfcpp::DW_CFA_restore_extended
;
5415 last_eh_loc
= off
+ 8;
5418 layout
->add_eh_frame_for_plt(this,
5419 Eh_cie
<size
>::eh_frame_cie
,
5420 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5421 &*fde
.begin(), fde
.size());
5424 template<int size
, bool big_endian
>
5426 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5429 && parameters
->options().ld_generated_unwind_info()
5430 && this->targ_
->has_glink())
5431 layout
->remove_eh_frame_for_plt(this,
5432 Eh_cie
<size
>::eh_frame_cie
,
5433 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5436 // A class to handle .glink.
5438 template<int size
, bool big_endian
>
5439 class Output_data_glink
: public Output_section_data
5442 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5443 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5445 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5446 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5447 end_branch_table_(), ge_size_(0)
5451 add_eh_frame(Layout
* layout
);
5454 add_global_entry(const Symbol
*);
5457 find_global_entry(const Symbol
*) const;
5460 global_entry_align(unsigned int off
) const
5462 unsigned int align
= param_plt_align
<size
>();
5463 return (off
+ align
- 1) & -align
;
5467 global_entry_off() const
5469 return this->global_entry_align(this->end_branch_table_
);
5473 global_entry_address() const
5475 gold_assert(this->is_data_size_valid());
5476 return this->address() + this->global_entry_off();
5480 pltresolve_size() const
5484 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
5489 // Write to a map file.
5491 do_print_to_mapfile(Mapfile
* mapfile
) const
5492 { mapfile
->print_output_data(this, _("** glink")); }
5496 set_final_data_size();
5500 do_write(Output_file
*);
5502 // Allows access to .got and .plt for do_write.
5503 Target_powerpc
<size
, big_endian
>* targ_
;
5505 // Map sym to stub offset.
5506 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5507 Global_entry_stub_entries global_entry_stubs_
;
5509 unsigned int end_branch_table_
, ge_size_
;
5512 template<int size
, bool big_endian
>
5514 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5516 if (!parameters
->options().ld_generated_unwind_info())
5521 if (this->targ_
->abiversion() < 2)
5522 layout
->add_eh_frame_for_plt(this,
5523 Eh_cie
<64>::eh_frame_cie
,
5524 sizeof (Eh_cie
<64>::eh_frame_cie
),
5525 glink_eh_frame_fde_64v1
,
5526 sizeof (glink_eh_frame_fde_64v1
));
5528 layout
->add_eh_frame_for_plt(this,
5529 Eh_cie
<64>::eh_frame_cie
,
5530 sizeof (Eh_cie
<64>::eh_frame_cie
),
5531 glink_eh_frame_fde_64v2
,
5532 sizeof (glink_eh_frame_fde_64v2
));
5536 // 32-bit .glink can use the default since the CIE return
5537 // address reg, LR, is valid.
5538 layout
->add_eh_frame_for_plt(this,
5539 Eh_cie
<32>::eh_frame_cie
,
5540 sizeof (Eh_cie
<32>::eh_frame_cie
),
5542 sizeof (default_fde
));
5543 // Except where LR is used in a PIC __glink_PLTresolve.
5544 if (parameters
->options().output_is_position_independent())
5545 layout
->add_eh_frame_for_plt(this,
5546 Eh_cie
<32>::eh_frame_cie
,
5547 sizeof (Eh_cie
<32>::eh_frame_cie
),
5548 glink_eh_frame_fde_32
,
5549 sizeof (glink_eh_frame_fde_32
));
5553 template<int size
, bool big_endian
>
5555 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5557 unsigned int off
= this->global_entry_align(this->ge_size_
);
5558 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5559 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5561 this->ge_size_
= off
+ 16;
5564 template<int size
, bool big_endian
>
5565 typename Output_data_glink
<size
, big_endian
>::Address
5566 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5568 typename
Global_entry_stub_entries::const_iterator p
5569 = this->global_entry_stubs_
.find(gsym
);
5570 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5573 template<int size
, bool big_endian
>
5575 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5577 unsigned int count
= this->targ_
->plt_entry_count();
5578 section_size_type total
= 0;
5584 // space for branch table
5585 total
+= 4 * (count
- 1);
5587 total
+= -total
& 15;
5588 total
+= this->pltresolve_size();
5592 total
+= this->pltresolve_size();
5594 // space for branch table
5596 if (this->targ_
->abiversion() < 2)
5600 total
+= 4 * (count
- 0x8000);
5604 this->end_branch_table_
= total
;
5605 total
= this->global_entry_align(total
);
5606 total
+= this->ge_size_
;
5608 this->set_data_size(total
);
5611 // Define symbols on stubs, identifying the stub.
5613 template<int size
, bool big_endian
>
5615 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5617 if (!this->plt_call_stubs_
.empty())
5619 // The key for the plt call stub hash table includes addresses,
5620 // therefore traversal order depends on those addresses, which
5621 // can change between runs if gold is a PIE. Unfortunately the
5622 // output .symtab ordering depends on the order in which symbols
5623 // are added to the linker symtab. We want reproducible output
5624 // so must sort the call stub symbols.
5625 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5626 std::vector
<plt_iter
> sorted
;
5627 sorted
.resize(this->plt_call_stubs_
.size());
5629 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5630 cs
!= this->plt_call_stubs_
.end();
5632 sorted
[cs
->second
.indx_
] = cs
;
5634 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5636 plt_iter cs
= sorted
[i
];
5639 if (cs
->first
.addend_
!= 0)
5640 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5643 if (cs
->first
.object_
)
5645 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5646 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5647 sprintf(obj
, "%x:", ppcobj
->uniq());
5650 const char *symname
;
5651 if (cs
->first
.sym_
== NULL
)
5653 sprintf(localname
, "%x", cs
->first
.locsym_
);
5654 symname
= localname
;
5656 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5657 symname
= this->targ_
->tls_get_addr_opt()->name();
5659 symname
= cs
->first
.sym_
->name();
5660 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5661 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5663 = this->stub_address() - this->address() + cs
->second
.off_
;
5664 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5665 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5669 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5670 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5671 bs
!= this->long_branch_stubs_
.end();
5674 if (bs
->second
.save_res_
)
5677 char* name
= new char[8 + 13 + 16 + 1];
5678 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5679 static_cast<unsigned long long>(bs
->first
.dest_
));
5680 Address value
= (this->stub_address() - this->address()
5681 + this->plt_size_
+ bs
->second
.off_
);
5682 bool need_lt
= false;
5683 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5684 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5688 // Emit the start of a __tls_get_addr_opt plt call stub.
5690 template<int size
, bool big_endian
>
5692 Stub_table
<size
, big_endian
>::build_tls_opt_head(
5694 typename
Plt_stub_entries::const_iterator cs
)
5696 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5698 unsigned char* p
= *pp
;
5701 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5703 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5705 write_insn
<big_endian
>(p
, mr_0_3
);
5707 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5709 write_insn
<big_endian
>(p
, add_3_12_13
);
5711 write_insn
<big_endian
>(p
, beqlr
);
5713 write_insn
<big_endian
>(p
, mr_3_0
);
5715 if (cs
->second
.r2save_
&& !cs
->second
.localentry0_
)
5717 write_insn
<big_endian
>(p
, mflr_11
);
5719 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5725 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5727 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5729 write_insn
<big_endian
>(p
, mr_0_3
);
5731 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5733 write_insn
<big_endian
>(p
, add_3_12_2
);
5735 write_insn
<big_endian
>(p
, beqlr
);
5737 write_insn
<big_endian
>(p
, mr_3_0
);
5739 write_insn
<big_endian
>(p
, nop
);
5748 // Emit the tail of a __tls_get_addr_opt plt call stub.
5750 template<int size
, bool big_endian
>
5752 Stub_table
<size
, big_endian
>::build_tls_opt_tail(
5754 typename
Plt_stub_entries::const_iterator cs
)
5757 && cs
->second
.r2save_
5758 && !cs
->second
.localentry0_
5759 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5761 write_insn
<big_endian
>(p
, bctrl
);
5763 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5765 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5767 write_insn
<big_endian
>(p
, mtlr_11
);
5769 write_insn
<big_endian
>(p
, blr
);
5775 // Emit pc-relative plt call stub code.
5777 template<bool big_endian
>
5778 static unsigned char*
5779 build_powerxx_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5782 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5787 write_insn
<big_endian
>(p
, nop
);
5795 write_insn
<big_endian
>(p
, insn
>> 32);
5797 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5799 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5802 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5806 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5809 insn
= paddi_12_pc
| d34(off
);
5810 write_insn
<big_endian
>(p
, insn
>> 32);
5812 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5816 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5820 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5822 write_insn
<big_endian
>(p
, add_12_11_12
);
5827 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5829 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5833 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5836 insn
= paddi_12_pc
| d34(off
);
5837 write_insn
<big_endian
>(p
, insn
>> 32);
5839 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5843 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5847 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5849 write_insn
<big_endian
>(p
, add_12_11_12
);
5855 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5856 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5861 // lis %r12,xxx-1b@highest
5862 // ori %r12,%r12,xxx-1b@higher
5863 // sldi %r12,%r12,32
5864 // oris %r12,%r12,xxx-1b@high
5865 // ori %r12,%r12,xxx-1b@l
5866 // add/ldx %r12,%r11,%r12
5868 template<bool big_endian
>
5869 static unsigned char*
5870 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5872 write_insn
<big_endian
>(p
, mflr_12
);
5874 write_insn
<big_endian
>(p
, bcl_20_31
);
5876 write_insn
<big_endian
>(p
, mflr_11
);
5878 write_insn
<big_endian
>(p
, mtlr_12
);
5880 if (off
+ 0x8000 < 0x10000)
5883 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5885 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5887 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5889 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5892 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5894 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5898 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5900 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5905 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5907 if (((off
>> 32) & 0xffff) != 0)
5909 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5913 if (((off
>> 32) & 0xffffffffULL
) != 0)
5915 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5920 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5925 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5929 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5931 write_insn
<big_endian
>(p
, add_12_11_12
);
5937 // Size of a given plt call stub.
5939 template<int size
, bool big_endian
>
5941 Stub_table
<size
, big_endian
>::plt_call_size(
5942 typename
Plt_stub_entries::const_iterator p
) const
5946 const Symbol
* gsym
= p
->first
.sym_
;
5948 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
5951 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5952 uint64_t plt_addr
= this->plt_off(p
, &plt
);
5953 plt_addr
+= plt
->address();
5954 unsigned int bytes
= 0;
5955 const Symbol
* gsym
= p
->first
.sym_
;
5956 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5958 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
5964 if (p
->second
.r2save_
)
5967 if (this->targ_
->powerxx_stubs())
5969 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
5972 uint64_t odd
= from
& 4;
5973 uint64_t off
= plt_addr
- from
;
5974 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5975 bytes
+= odd
+ 4 * 4;
5976 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5983 if (p
->second
.notoc_
)
5985 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
5988 uint64_t off
= plt_addr
- from
;
5989 if (off
+ 0x8000 < 0x10000)
5991 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5996 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
5997 && ((off
>> 32) & 0xffff) != 0)
5999 if (((off
>> 32) & 0xffffffffULL
) != 0)
6009 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
6010 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6011 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
6012 got_addr
+= ppcobj
->toc_base_offset();
6013 uint64_t off
= plt_addr
- got_addr
;
6014 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
6015 if (this->targ_
->abiversion() < 2)
6017 bool static_chain
= parameters
->options().plt_static_chain();
6018 bool thread_safe
= this->targ_
->plt_thread_safe();
6022 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
6027 // Return long branch stub size.
6029 template<int size
, bool big_endian
>
6031 Stub_table
<size
, big_endian
>::branch_stub_size(
6032 typename
Branch_stub_entries::const_iterator p
,
6035 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6038 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6040 if (parameters
->options().output_is_position_independent())
6045 uint64_t off
= p
->first
.dest_
- loc
;
6046 if (p
->second
.notoc_
)
6048 if (this->targ_
->powerxx_stubs())
6050 Address odd
= loc
& 4;
6051 if (off
+ (1 << 25) < 2 << 25)
6053 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6055 if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6060 if (off
+ 0x8000 < 0x10000)
6062 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6064 if (off
+ 24 + (1 << 25) < 2 << 25)
6068 unsigned int bytes
= 32;
6069 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6070 && ((off
>> 32) & 0xffff) != 0)
6072 if (((off
>> 32) & 0xffffffffULL
) != 0)
6081 if (off
+ (1 << 25) < 2 << 25)
6083 if (!this->targ_
->powerxx_stubs())
6088 template<int size
, bool big_endian
>
6090 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6093 gold_error(_("linkage table error against `%s'"),
6094 p
.sym_
->demangled_name().c_str());
6096 gold_error(_("linkage table error against `%s:[local %u]'"),
6097 p
.object_
->name().c_str(),
6101 // Write out plt and long branch stub code.
6103 template<int size
, bool big_endian
>
6105 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6107 if (this->plt_call_stubs_
.empty()
6108 && this->long_branch_stubs_
.empty())
6111 const section_size_type start_off
= this->offset();
6112 const section_size_type off
= this->stub_offset();
6113 const section_size_type oview_size
=
6114 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6115 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6119 && this->targ_
->powerxx_stubs())
6121 if (!this->plt_call_stubs_
.empty())
6123 // Write out plt call stubs.
6124 typename
Plt_stub_entries::const_iterator cs
;
6125 for (cs
= this->plt_call_stubs_
.begin();
6126 cs
!= this->plt_call_stubs_
.end();
6129 p
= oview
+ cs
->second
.off_
;
6130 this->build_tls_opt_head(&p
, cs
);
6131 if (cs
->second
.r2save_
)
6133 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6136 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6137 Address pltoff
= this->plt_off(cs
, &plt
);
6138 Address plt_addr
= pltoff
+ plt
->address();
6139 Address from
= this->stub_address() + (p
- oview
);
6140 Address delta
= plt_addr
- from
;
6141 p
= build_powerxx_offset
<big_endian
>(p
, delta
, from
& 4, true);
6142 write_insn
<big_endian
>(p
, mtctr_12
);
6144 if (!this->build_tls_opt_tail(p
, cs
))
6145 write_insn
<big_endian
>(p
, bctr
);
6149 // Write out long branch stubs.
6150 typename
Branch_stub_entries::const_iterator bs
;
6151 for (bs
= this->long_branch_stubs_
.begin();
6152 bs
!= this->long_branch_stubs_
.end();
6155 if (bs
->second
.save_res_
)
6157 Address off
= this->plt_size_
+ bs
->second
.off_
;
6159 Address loc
= this->stub_address() + off
;
6160 Address delta
= bs
->first
.dest_
- loc
;
6161 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6163 unsigned char* startp
= p
;
6164 p
= build_powerxx_offset
<big_endian
>(p
, delta
, loc
& 4, false);
6165 delta
-= p
- startp
;
6167 if (delta
+ (1 << 25) < 2 << 25)
6168 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6171 write_insn
<big_endian
>(p
, mtctr_12
);
6173 write_insn
<big_endian
>(p
, bctr
);
6177 else if (size
== 64)
6179 const Output_data_got_powerpc
<size
, big_endian
>* got
6180 = this->targ_
->got_section();
6181 Address got_os_addr
= got
->output_section()->address();
6183 if (!this->plt_call_stubs_
.empty()
6184 && this->targ_
->abiversion() >= 2)
6186 // Write out plt call stubs for ELFv2.
6187 typename
Plt_stub_entries::const_iterator cs
;
6188 for (cs
= this->plt_call_stubs_
.begin();
6189 cs
!= this->plt_call_stubs_
.end();
6192 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6193 Address pltoff
= this->plt_off(cs
, &plt
);
6194 Address plt_addr
= pltoff
+ plt
->address();
6196 p
= oview
+ cs
->second
.off_
;
6197 this->build_tls_opt_head(&p
, cs
);
6198 if (cs
->second
.r2save_
)
6200 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6203 if (cs
->second
.notoc_
)
6205 Address from
= this->stub_address() + (p
- oview
) + 8;
6206 Address off
= plt_addr
- from
;
6207 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6211 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6212 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6213 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6214 Address off
= plt_addr
- got_addr
;
6216 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6217 this->plt_error(cs
->first
);
6221 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6223 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6228 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6232 write_insn
<big_endian
>(p
, mtctr_12
);
6234 if (!this->build_tls_opt_tail(p
, cs
))
6235 write_insn
<big_endian
>(p
, bctr
);
6238 else if (!this->plt_call_stubs_
.empty())
6240 // Write out plt call stubs for ELFv1.
6241 typename
Plt_stub_entries::const_iterator cs
;
6242 for (cs
= this->plt_call_stubs_
.begin();
6243 cs
!= this->plt_call_stubs_
.end();
6246 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6247 Address pltoff
= this->plt_off(cs
, &plt
);
6248 Address plt_addr
= pltoff
+ plt
->address();
6249 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6250 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6251 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6252 Address off
= plt_addr
- got_addr
;
6254 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6255 || cs
->second
.notoc_
)
6256 this->plt_error(cs
->first
);
6258 bool static_chain
= parameters
->options().plt_static_chain();
6259 bool thread_safe
= this->targ_
->plt_thread_safe();
6260 bool use_fake_dep
= false;
6261 Address cmp_branch_off
= 0;
6264 unsigned int pltindex
6265 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6266 / this->targ_
->plt_entry_size());
6268 = (this->targ_
->glink_section()->pltresolve_size()
6270 if (pltindex
> 32768)
6271 glinkoff
+= (pltindex
- 32768) * 4;
6273 = this->targ_
->glink_section()->address() + glinkoff
;
6275 = (this->stub_address() + cs
->second
.off_
+ 20
6276 + 4 * cs
->second
.r2save_
6277 + 4 * (ha(off
) != 0)
6278 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6279 + 4 * static_chain
);
6280 cmp_branch_off
= to
- from
;
6281 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6284 p
= oview
+ cs
->second
.off_
;
6285 if (this->build_tls_opt_head(&p
, cs
))
6286 use_fake_dep
= thread_safe
;
6287 if (cs
->second
.r2save_
)
6289 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6294 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6296 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6298 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6300 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6304 write_insn
<big_endian
>(p
, mtctr_12
);
6308 write_insn
<big_endian
>(p
, xor_2_12_12
);
6310 write_insn
<big_endian
>(p
, add_11_11_2
);
6313 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6317 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6323 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6325 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6327 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6331 write_insn
<big_endian
>(p
, mtctr_12
);
6335 write_insn
<big_endian
>(p
, xor_11_12_12
);
6337 write_insn
<big_endian
>(p
, add_2_2_11
);
6342 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6345 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6348 if (this->build_tls_opt_tail(p
, cs
))
6350 else if (thread_safe
&& !use_fake_dep
)
6352 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6354 write_insn
<big_endian
>(p
, bnectr_p4
);
6356 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6359 write_insn
<big_endian
>(p
, bctr
);
6363 // Write out long branch stubs.
6364 typename
Branch_stub_entries::const_iterator bs
;
6365 for (bs
= this->long_branch_stubs_
.begin();
6366 bs
!= this->long_branch_stubs_
.end();
6369 if (bs
->second
.save_res_
)
6371 Address off
= this->plt_size_
+ bs
->second
.off_
;
6373 Address loc
= this->stub_address() + off
;
6374 Address delta
= bs
->first
.dest_
- loc
;
6375 if (bs
->second
.notoc_
)
6377 unsigned char* startp
= p
;
6378 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6379 delta
-= p
- startp
;
6381 else if (delta
+ (1 << 25) >= 2 << 25)
6384 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6385 gold_assert(brlt_addr
!= invalid_address
);
6386 brlt_addr
+= this->targ_
->brlt_section()->address();
6387 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6388 Address brltoff
= brlt_addr
- got_addr
;
6389 if (ha(brltoff
) == 0)
6391 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6396 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6398 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6402 if (delta
+ (1 << 25) < 2 << 25)
6403 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6406 write_insn
<big_endian
>(p
, mtctr_12
);
6408 write_insn
<big_endian
>(p
, bctr
);
6414 if (!this->plt_call_stubs_
.empty())
6416 // The address of _GLOBAL_OFFSET_TABLE_.
6417 Address g_o_t
= invalid_address
;
6419 // Write out plt call stubs.
6420 typename
Plt_stub_entries::const_iterator cs
;
6421 for (cs
= this->plt_call_stubs_
.begin();
6422 cs
!= this->plt_call_stubs_
.end();
6425 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6426 Address plt_addr
= this->plt_off(cs
, &plt
);
6427 plt_addr
+= plt
->address();
6429 p
= oview
+ cs
->second
.off_
;
6430 this->build_tls_opt_head(&p
, cs
);
6431 if (parameters
->options().output_is_position_independent())
6434 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6435 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6436 (cs
->first
.object_
));
6437 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6439 unsigned int got2
= ppcobj
->got2_shndx();
6440 got_addr
= ppcobj
->get_output_section_offset(got2
);
6441 gold_assert(got_addr
!= invalid_address
);
6442 got_addr
+= (ppcobj
->output_section(got2
)->address()
6443 + cs
->first
.addend_
);
6447 if (g_o_t
== invalid_address
)
6449 const Output_data_got_powerpc
<size
, big_endian
>* got
6450 = this->targ_
->got_section();
6451 g_o_t
= got
->address() + got
->g_o_t();
6456 Address off
= plt_addr
- got_addr
;
6458 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6461 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6463 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6468 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6470 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6473 write_insn
<big_endian
>(p
, mtctr_11
);
6475 write_insn
<big_endian
>(p
, bctr
);
6479 // Write out long branch stubs.
6480 typename
Branch_stub_entries::const_iterator bs
;
6481 for (bs
= this->long_branch_stubs_
.begin();
6482 bs
!= this->long_branch_stubs_
.end();
6485 if (bs
->second
.save_res_
)
6487 Address off
= this->plt_size_
+ bs
->second
.off_
;
6489 Address loc
= this->stub_address() + off
;
6490 Address delta
= bs
->first
.dest_
- loc
;
6491 if (delta
+ (1 << 25) < 2 << 25)
6492 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6493 else if (!parameters
->options().output_is_position_independent())
6495 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6497 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6502 write_insn
<big_endian
>(p
, mflr_0
);
6504 write_insn
<big_endian
>(p
, bcl_20_31
);
6506 write_insn
<big_endian
>(p
, mflr_12
);
6508 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6510 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6512 write_insn
<big_endian
>(p
, mtlr_0
);
6515 write_insn
<big_endian
>(p
, mtctr_12
);
6517 write_insn
<big_endian
>(p
, bctr
);
6520 if (this->need_save_res_
)
6522 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6523 memcpy (p
, this->targ_
->savres_section()->contents(),
6524 this->targ_
->savres_section()->data_size());
6528 // Write out .glink.
6530 template<int size
, bool big_endian
>
6532 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6534 const section_size_type off
= this->offset();
6535 const section_size_type oview_size
=
6536 convert_to_section_size_type(this->data_size());
6537 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6540 // The base address of the .plt section.
6541 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6542 Address plt_base
= this->targ_
->plt_section()->address();
6546 if (this->end_branch_table_
!= 0)
6548 // Write pltresolve stub.
6550 Address after_bcl
= this->address() + 16;
6551 Address pltoff
= plt_base
- after_bcl
;
6553 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6555 if (this->targ_
->abiversion() < 2)
6557 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6558 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6559 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6560 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6561 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6562 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6563 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6564 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6565 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6566 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6570 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6571 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6572 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6573 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6574 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6575 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6576 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6577 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6578 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
6579 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6580 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6581 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6582 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6584 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6585 gold_assert(p
== oview
+ this->pltresolve_size());
6587 // Write lazy link call stubs.
6589 while (p
< oview
+ this->end_branch_table_
)
6591 if (this->targ_
->abiversion() < 2)
6595 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6599 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6600 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6603 uint32_t branch_off
= 8 - (p
- oview
);
6604 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6609 Address plt_base
= this->targ_
->plt_section()->address();
6610 Address iplt_base
= invalid_address
;
6611 unsigned int global_entry_off
= this->global_entry_off();
6612 Address global_entry_base
= this->address() + global_entry_off
;
6613 typename
Global_entry_stub_entries::const_iterator ge
;
6614 for (ge
= this->global_entry_stubs_
.begin();
6615 ge
!= this->global_entry_stubs_
.end();
6618 p
= oview
+ global_entry_off
+ ge
->second
;
6619 Address plt_addr
= ge
->first
->plt_offset();
6620 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6621 && ge
->first
->can_use_relative_reloc(false))
6623 if (iplt_base
== invalid_address
)
6624 iplt_base
= this->targ_
->iplt_section()->address();
6625 plt_addr
+= iplt_base
;
6628 plt_addr
+= plt_base
;
6629 Address my_addr
= global_entry_base
+ ge
->second
;
6630 Address off
= plt_addr
- my_addr
;
6632 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6633 gold_error(_("linkage table error against `%s'"),
6634 ge
->first
->demangled_name().c_str());
6636 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6637 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6638 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6639 write_insn
<big_endian
>(p
, bctr
);
6644 const Output_data_got_powerpc
<size
, big_endian
>* got
6645 = this->targ_
->got_section();
6646 // The address of _GLOBAL_OFFSET_TABLE_.
6647 Address g_o_t
= got
->address() + got
->g_o_t();
6649 // Write out pltresolve branch table.
6651 unsigned int the_end
= oview_size
- this->pltresolve_size();
6652 unsigned char* end_p
= oview
+ the_end
;
6653 while (p
< end_p
- 8 * 4)
6654 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6656 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6658 // Write out pltresolve call stub.
6659 end_p
= oview
+ oview_size
;
6660 if (parameters
->options().output_is_position_independent())
6662 Address res0_off
= 0;
6663 Address after_bcl_off
= the_end
+ 12;
6664 Address bcl_res0
= after_bcl_off
- res0_off
;
6666 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6668 write_insn
<big_endian
>(p
, mflr_0
);
6670 write_insn
<big_endian
>(p
, bcl_20_31
);
6672 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6674 write_insn
<big_endian
>(p
, mflr_12
);
6676 write_insn
<big_endian
>(p
, mtlr_0
);
6678 write_insn
<big_endian
>(p
, sub_11_11_12
);
6681 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6683 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6685 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6687 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6689 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6693 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6695 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6698 write_insn
<big_endian
>(p
, mtctr_0
);
6700 write_insn
<big_endian
>(p
, add_0_11_11
);
6702 write_insn
<big_endian
>(p
, add_11_0_11
);
6706 Address res0
= this->address();
6708 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6710 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6712 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6713 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6715 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6717 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6719 write_insn
<big_endian
>(p
, mtctr_0
);
6721 write_insn
<big_endian
>(p
, add_0_11_11
);
6723 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6724 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6726 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6728 write_insn
<big_endian
>(p
, add_11_0_11
);
6731 write_insn
<big_endian
>(p
, bctr
);
6735 write_insn
<big_endian
>(p
, nop
);
6740 of
->write_output_view(off
, oview_size
, oview
);
6744 // A class to handle linker generated save/restore functions.
6746 template<int size
, bool big_endian
>
6747 class Output_data_save_res
: public Output_section_data_build
6750 Output_data_save_res(Symbol_table
* symtab
);
6752 const unsigned char*
6759 // Write to a map file.
6761 do_print_to_mapfile(Mapfile
* mapfile
) const
6762 { mapfile
->print_output_data(this, _("** save/restore")); }
6765 do_write(Output_file
*);
6768 // The maximum size of save/restore contents.
6769 static const unsigned int savres_max
= 218*4;
6772 savres_define(Symbol_table
* symtab
,
6774 unsigned int lo
, unsigned int hi
,
6775 unsigned char* write_ent(unsigned char*, int),
6776 unsigned char* write_tail(unsigned char*, int));
6778 unsigned char *contents_
;
6781 template<bool big_endian
>
6782 static unsigned char*
6783 savegpr0(unsigned char* p
, int r
)
6785 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6786 write_insn
<big_endian
>(p
, insn
);
6790 template<bool big_endian
>
6791 static unsigned char*
6792 savegpr0_tail(unsigned char* p
, int r
)
6794 p
= savegpr0
<big_endian
>(p
, r
);
6795 uint32_t insn
= std_0_1
+ 16;
6796 write_insn
<big_endian
>(p
, insn
);
6798 write_insn
<big_endian
>(p
, blr
);
6802 template<bool big_endian
>
6803 static unsigned char*
6804 restgpr0(unsigned char* p
, int r
)
6806 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6807 write_insn
<big_endian
>(p
, insn
);
6811 template<bool big_endian
>
6812 static unsigned char*
6813 restgpr0_tail(unsigned char* p
, int r
)
6815 uint32_t insn
= ld_0_1
+ 16;
6816 write_insn
<big_endian
>(p
, insn
);
6818 p
= restgpr0
<big_endian
>(p
, r
);
6819 write_insn
<big_endian
>(p
, mtlr_0
);
6823 p
= restgpr0
<big_endian
>(p
, 30);
6824 p
= restgpr0
<big_endian
>(p
, 31);
6826 write_insn
<big_endian
>(p
, blr
);
6830 template<bool big_endian
>
6831 static unsigned char*
6832 savegpr1(unsigned char* p
, int r
)
6834 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6835 write_insn
<big_endian
>(p
, insn
);
6839 template<bool big_endian
>
6840 static unsigned char*
6841 savegpr1_tail(unsigned char* p
, int r
)
6843 p
= savegpr1
<big_endian
>(p
, r
);
6844 write_insn
<big_endian
>(p
, blr
);
6848 template<bool big_endian
>
6849 static unsigned char*
6850 restgpr1(unsigned char* p
, int r
)
6852 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6853 write_insn
<big_endian
>(p
, insn
);
6857 template<bool big_endian
>
6858 static unsigned char*
6859 restgpr1_tail(unsigned char* p
, int r
)
6861 p
= restgpr1
<big_endian
>(p
, r
);
6862 write_insn
<big_endian
>(p
, blr
);
6866 template<bool big_endian
>
6867 static unsigned char*
6868 savefpr(unsigned char* p
, int r
)
6870 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6871 write_insn
<big_endian
>(p
, insn
);
6875 template<bool big_endian
>
6876 static unsigned char*
6877 savefpr0_tail(unsigned char* p
, int r
)
6879 p
= savefpr
<big_endian
>(p
, r
);
6880 write_insn
<big_endian
>(p
, std_0_1
+ 16);
6882 write_insn
<big_endian
>(p
, blr
);
6886 template<bool big_endian
>
6887 static unsigned char*
6888 restfpr(unsigned char* p
, int r
)
6890 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6891 write_insn
<big_endian
>(p
, insn
);
6895 template<bool big_endian
>
6896 static unsigned char*
6897 restfpr0_tail(unsigned char* p
, int r
)
6899 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
6901 p
= restfpr
<big_endian
>(p
, r
);
6902 write_insn
<big_endian
>(p
, mtlr_0
);
6906 p
= restfpr
<big_endian
>(p
, 30);
6907 p
= restfpr
<big_endian
>(p
, 31);
6909 write_insn
<big_endian
>(p
, blr
);
6913 template<bool big_endian
>
6914 static unsigned char*
6915 savefpr1_tail(unsigned char* p
, int r
)
6917 p
= savefpr
<big_endian
>(p
, r
);
6918 write_insn
<big_endian
>(p
, blr
);
6922 template<bool big_endian
>
6923 static unsigned char*
6924 restfpr1_tail(unsigned char* p
, int r
)
6926 p
= restfpr
<big_endian
>(p
, r
);
6927 write_insn
<big_endian
>(p
, blr
);
6931 template<bool big_endian
>
6932 static unsigned char*
6933 savevr(unsigned char* p
, int r
)
6935 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6936 write_insn
<big_endian
>(p
, insn
);
6938 insn
= stvx_0_12_0
+ (r
<< 21);
6939 write_insn
<big_endian
>(p
, insn
);
6943 template<bool big_endian
>
6944 static unsigned char*
6945 savevr_tail(unsigned char* p
, int r
)
6947 p
= savevr
<big_endian
>(p
, r
);
6948 write_insn
<big_endian
>(p
, blr
);
6952 template<bool big_endian
>
6953 static unsigned char*
6954 restvr(unsigned char* p
, int r
)
6956 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6957 write_insn
<big_endian
>(p
, insn
);
6959 insn
= lvx_0_12_0
+ (r
<< 21);
6960 write_insn
<big_endian
>(p
, insn
);
6964 template<bool big_endian
>
6965 static unsigned char*
6966 restvr_tail(unsigned char* p
, int r
)
6968 p
= restvr
<big_endian
>(p
, r
);
6969 write_insn
<big_endian
>(p
, blr
);
6974 template<int size
, bool big_endian
>
6975 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
6976 Symbol_table
* symtab
)
6977 : Output_section_data_build(4),
6980 this->savres_define(symtab
,
6981 "_savegpr0_", 14, 31,
6982 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
6983 this->savres_define(symtab
,
6984 "_restgpr0_", 14, 29,
6985 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6986 this->savres_define(symtab
,
6987 "_restgpr0_", 30, 31,
6988 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6989 this->savres_define(symtab
,
6990 "_savegpr1_", 14, 31,
6991 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
6992 this->savres_define(symtab
,
6993 "_restgpr1_", 14, 31,
6994 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
6995 this->savres_define(symtab
,
6996 "_savefpr_", 14, 31,
6997 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
6998 this->savres_define(symtab
,
6999 "_restfpr_", 14, 29,
7000 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7001 this->savres_define(symtab
,
7002 "_restfpr_", 30, 31,
7003 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
7004 this->savres_define(symtab
,
7006 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
7007 this->savres_define(symtab
,
7009 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
7010 this->savres_define(symtab
,
7012 savevr
<big_endian
>, savevr_tail
<big_endian
>);
7013 this->savres_define(symtab
,
7015 restvr
<big_endian
>, restvr_tail
<big_endian
>);
7018 template<int size
, bool big_endian
>
7020 Output_data_save_res
<size
, big_endian
>::savres_define(
7021 Symbol_table
* symtab
,
7023 unsigned int lo
, unsigned int hi
,
7024 unsigned char* write_ent(unsigned char*, int),
7025 unsigned char* write_tail(unsigned char*, int))
7027 size_t len
= strlen(name
);
7028 bool writing
= false;
7031 memcpy(sym
, name
, len
);
7034 for (unsigned int i
= lo
; i
<= hi
; i
++)
7036 sym
[len
+ 0] = i
/ 10 + '0';
7037 sym
[len
+ 1] = i
% 10 + '0';
7038 Symbol
* gsym
= symtab
->lookup(sym
);
7039 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7040 writing
= writing
|| refd
;
7043 if (this->contents_
== NULL
)
7044 this->contents_
= new unsigned char[this->savres_max
];
7046 section_size_type value
= this->current_data_size();
7047 unsigned char* p
= this->contents_
+ value
;
7049 p
= write_ent(p
, i
);
7051 p
= write_tail(p
, i
);
7052 section_size_type cur_size
= p
- this->contents_
;
7053 this->set_current_data_size(cur_size
);
7055 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7056 this, value
, cur_size
- value
,
7057 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7058 elfcpp::STV_HIDDEN
, 0, false, false);
7063 // Write out save/restore.
7065 template<int size
, bool big_endian
>
7067 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7069 const section_size_type off
= this->offset();
7070 const section_size_type oview_size
=
7071 convert_to_section_size_type(this->data_size());
7072 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7073 memcpy(oview
, this->contents_
, oview_size
);
7074 of
->write_output_view(off
, oview_size
, oview
);
7078 // Create the glink section.
7080 template<int size
, bool big_endian
>
7082 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7084 if (this->glink_
== NULL
)
7086 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7087 this->glink_
->add_eh_frame(layout
);
7088 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7089 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7090 this->glink_
, ORDER_TEXT
, false);
7094 // Create a PLT entry for a global symbol.
7096 template<int size
, bool big_endian
>
7098 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7102 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7103 && gsym
->can_use_relative_reloc(false))
7105 if (this->iplt_
== NULL
)
7106 this->make_iplt_section(symtab
, layout
);
7107 this->iplt_
->add_ifunc_entry(gsym
);
7111 if (this->plt_
== NULL
)
7112 this->make_plt_section(symtab
, layout
);
7113 this->plt_
->add_entry(gsym
);
7117 // Make a PLT entry for a local symbol.
7119 template<int size
, bool big_endian
>
7121 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7123 Sized_relobj_file
<size
, big_endian
>* relobj
,
7126 if (this->lplt_
== NULL
)
7127 this->make_lplt_section(layout
);
7128 this->lplt_
->add_local_entry(relobj
, r_sym
);
7131 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7133 template<int size
, bool big_endian
>
7135 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7136 Symbol_table
* symtab
,
7138 Sized_relobj_file
<size
, big_endian
>* relobj
,
7141 if (this->iplt_
== NULL
)
7142 this->make_iplt_section(symtab
, layout
);
7143 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7146 // Return the number of entries in the PLT.
7148 template<int size
, bool big_endian
>
7150 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7152 if (this->plt_
== NULL
)
7154 return this->plt_
->entry_count();
7157 // Create a GOT entry for local dynamic __tls_get_addr calls.
7159 template<int size
, bool big_endian
>
7161 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7162 Symbol_table
* symtab
,
7164 Sized_relobj_file
<size
, big_endian
>* object
)
7166 if (this->tlsld_got_offset_
== -1U)
7168 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7169 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7170 Output_data_got_powerpc
<size
, big_endian
>* got
7171 = this->got_section(symtab
, layout
);
7172 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7173 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7175 this->tlsld_got_offset_
= got_offset
;
7177 return this->tlsld_got_offset_
;
7180 // Get the Reference_flags for a particular relocation.
7182 template<int size
, bool big_endian
>
7184 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7185 unsigned int r_type
,
7186 const Target_powerpc
* target
)
7192 case elfcpp::R_POWERPC_NONE
:
7193 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7194 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7195 case elfcpp::R_PPC64_TOC
:
7196 // No symbol reference.
7199 case elfcpp::R_PPC64_ADDR64
:
7200 case elfcpp::R_PPC64_UADDR64
:
7201 case elfcpp::R_POWERPC_ADDR32
:
7202 case elfcpp::R_POWERPC_UADDR32
:
7203 case elfcpp::R_POWERPC_ADDR16
:
7204 case elfcpp::R_POWERPC_UADDR16
:
7205 case elfcpp::R_POWERPC_ADDR16_LO
:
7206 case elfcpp::R_POWERPC_ADDR16_HI
:
7207 case elfcpp::R_POWERPC_ADDR16_HA
:
7208 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7209 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7210 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7211 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7212 case elfcpp::R_PPC64_D34
:
7213 case elfcpp::R_PPC64_D34_LO
:
7214 case elfcpp::R_PPC64_D34_HI30
:
7215 case elfcpp::R_PPC64_D34_HA30
:
7216 case elfcpp::R_PPC64_D28
:
7217 ref
= Symbol::ABSOLUTE_REF
;
7220 case elfcpp::R_POWERPC_ADDR24
:
7221 case elfcpp::R_POWERPC_ADDR14
:
7222 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7223 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7224 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7227 case elfcpp::R_PPC64_REL64
:
7228 case elfcpp::R_POWERPC_REL32
:
7229 case elfcpp::R_PPC_LOCAL24PC
:
7230 case elfcpp::R_POWERPC_REL16
:
7231 case elfcpp::R_POWERPC_REL16_LO
:
7232 case elfcpp::R_POWERPC_REL16_HI
:
7233 case elfcpp::R_POWERPC_REL16_HA
:
7234 case elfcpp::R_PPC64_REL16_HIGH
:
7235 case elfcpp::R_PPC64_REL16_HIGHA
:
7236 case elfcpp::R_PPC64_REL16_HIGHER
:
7237 case elfcpp::R_PPC64_REL16_HIGHERA
:
7238 case elfcpp::R_PPC64_REL16_HIGHEST
:
7239 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7240 case elfcpp::R_PPC64_PCREL34
:
7241 case elfcpp::R_PPC64_REL16_HIGHER34
:
7242 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7243 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7244 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7245 case elfcpp::R_PPC64_PCREL28
:
7246 ref
= Symbol::RELATIVE_REF
;
7249 case elfcpp::R_PPC64_REL24_NOTOC
:
7253 case elfcpp::R_POWERPC_REL24
:
7254 case elfcpp::R_PPC_PLTREL24
:
7255 case elfcpp::R_POWERPC_REL14
:
7256 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7257 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7258 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7261 case elfcpp::R_POWERPC_GOT16
:
7262 case elfcpp::R_POWERPC_GOT16_LO
:
7263 case elfcpp::R_POWERPC_GOT16_HI
:
7264 case elfcpp::R_POWERPC_GOT16_HA
:
7265 case elfcpp::R_PPC64_GOT16_DS
:
7266 case elfcpp::R_PPC64_GOT16_LO_DS
:
7267 case elfcpp::R_PPC64_GOT_PCREL34
:
7268 case elfcpp::R_PPC64_TOC16
:
7269 case elfcpp::R_PPC64_TOC16_LO
:
7270 case elfcpp::R_PPC64_TOC16_HI
:
7271 case elfcpp::R_PPC64_TOC16_HA
:
7272 case elfcpp::R_PPC64_TOC16_DS
:
7273 case elfcpp::R_PPC64_TOC16_LO_DS
:
7274 case elfcpp::R_POWERPC_PLT16_LO
:
7275 case elfcpp::R_POWERPC_PLT16_HI
:
7276 case elfcpp::R_POWERPC_PLT16_HA
:
7277 case elfcpp::R_PPC64_PLT16_LO_DS
:
7278 case elfcpp::R_PPC64_PLT_PCREL34
:
7279 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7280 ref
= Symbol::RELATIVE_REF
;
7283 case elfcpp::R_POWERPC_GOT_TPREL16
:
7284 case elfcpp::R_POWERPC_TLS
:
7285 case elfcpp::R_PPC64_TLSGD
:
7286 case elfcpp::R_PPC64_TLSLD
:
7287 case elfcpp::R_PPC64_TPREL34
:
7288 case elfcpp::R_PPC64_DTPREL34
:
7289 case elfcpp::R_PPC64_GOT_TLSGD34
:
7290 case elfcpp::R_PPC64_GOT_TLSLD34
:
7291 case elfcpp::R_PPC64_GOT_TPREL34
:
7292 case elfcpp::R_PPC64_GOT_DTPREL34
:
7293 ref
= Symbol::TLS_REF
;
7296 case elfcpp::R_POWERPC_COPY
:
7297 case elfcpp::R_POWERPC_GLOB_DAT
:
7298 case elfcpp::R_POWERPC_JMP_SLOT
:
7299 case elfcpp::R_POWERPC_RELATIVE
:
7300 case elfcpp::R_POWERPC_DTPMOD
:
7302 // Not expected. We will give an error later.
7306 if (size
== 64 && target
->abiversion() < 2)
7307 ref
|= Symbol::FUNC_DESC_ABI
;
7311 // Report an unsupported relocation against a local symbol.
7313 template<int size
, bool big_endian
>
7315 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7316 Sized_relobj_file
<size
, big_endian
>* object
,
7317 unsigned int r_type
)
7319 gold_error(_("%s: unsupported reloc %u against local symbol"),
7320 object
->name().c_str(), r_type
);
7323 // We are about to emit a dynamic relocation of type R_TYPE. If the
7324 // dynamic linker does not support it, issue an error.
7326 template<int size
, bool big_endian
>
7328 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7329 unsigned int r_type
)
7331 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7333 // These are the relocation types supported by glibc for both 32-bit
7334 // and 64-bit powerpc.
7337 case elfcpp::R_POWERPC_NONE
:
7338 case elfcpp::R_POWERPC_RELATIVE
:
7339 case elfcpp::R_POWERPC_GLOB_DAT
:
7340 case elfcpp::R_POWERPC_DTPMOD
:
7341 case elfcpp::R_POWERPC_DTPREL
:
7342 case elfcpp::R_POWERPC_TPREL
:
7343 case elfcpp::R_POWERPC_JMP_SLOT
:
7344 case elfcpp::R_POWERPC_COPY
:
7345 case elfcpp::R_POWERPC_IRELATIVE
:
7346 case elfcpp::R_POWERPC_ADDR32
:
7347 case elfcpp::R_POWERPC_UADDR32
:
7348 case elfcpp::R_POWERPC_ADDR24
:
7349 case elfcpp::R_POWERPC_ADDR16
:
7350 case elfcpp::R_POWERPC_UADDR16
:
7351 case elfcpp::R_POWERPC_ADDR16_LO
:
7352 case elfcpp::R_POWERPC_ADDR16_HI
:
7353 case elfcpp::R_POWERPC_ADDR16_HA
:
7354 case elfcpp::R_POWERPC_ADDR14
:
7355 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7356 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7357 case elfcpp::R_POWERPC_REL32
:
7358 case elfcpp::R_POWERPC_TPREL16
:
7359 case elfcpp::R_POWERPC_TPREL16_LO
:
7360 case elfcpp::R_POWERPC_TPREL16_HI
:
7361 case elfcpp::R_POWERPC_TPREL16_HA
:
7372 // These are the relocation types supported only on 64-bit.
7373 case elfcpp::R_PPC64_ADDR64
:
7374 case elfcpp::R_PPC64_UADDR64
:
7375 case elfcpp::R_PPC64_JMP_IREL
:
7376 case elfcpp::R_PPC64_ADDR16_DS
:
7377 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7378 case elfcpp::R_PPC64_ADDR16_HIGH
:
7379 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7380 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7381 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7382 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7383 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7384 case elfcpp::R_PPC64_REL64
:
7385 case elfcpp::R_POWERPC_ADDR30
:
7386 case elfcpp::R_PPC64_TPREL16_DS
:
7387 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7388 case elfcpp::R_PPC64_TPREL16_HIGH
:
7389 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7390 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7391 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7392 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7393 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7404 // These are the relocation types supported only on 32-bit.
7405 // ??? glibc ld.so doesn't need to support these.
7406 case elfcpp::R_POWERPC_REL24
:
7407 case elfcpp::R_POWERPC_DTPREL16
:
7408 case elfcpp::R_POWERPC_DTPREL16_LO
:
7409 case elfcpp::R_POWERPC_DTPREL16_HI
:
7410 case elfcpp::R_POWERPC_DTPREL16_HA
:
7418 // This prevents us from issuing more than one error per reloc
7419 // section. But we can still wind up issuing more than one
7420 // error per object file.
7421 if (this->issued_non_pic_error_
)
7423 gold_assert(parameters
->options().output_is_position_independent());
7424 object
->error(_("requires unsupported dynamic reloc; "
7425 "recompile with -fPIC"));
7426 this->issued_non_pic_error_
= true;
7430 // Return whether we need to make a PLT entry for a relocation of the
7431 // given type against a STT_GNU_IFUNC symbol.
7433 template<int size
, bool big_endian
>
7435 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7436 Target_powerpc
<size
, big_endian
>* target
,
7437 Sized_relobj_file
<size
, big_endian
>* object
,
7438 unsigned int r_type
,
7441 // In non-pic code any reference will resolve to the plt call stub
7442 // for the ifunc symbol.
7443 if ((size
== 32 || target
->abiversion() >= 2)
7444 && !parameters
->options().output_is_position_independent())
7449 // Word size refs from data sections are OK, but don't need a PLT entry.
7450 case elfcpp::R_POWERPC_ADDR32
:
7451 case elfcpp::R_POWERPC_UADDR32
:
7456 case elfcpp::R_PPC64_ADDR64
:
7457 case elfcpp::R_PPC64_UADDR64
:
7462 // GOT refs are good, but also don't need a PLT entry.
7463 case elfcpp::R_POWERPC_GOT16
:
7464 case elfcpp::R_POWERPC_GOT16_LO
:
7465 case elfcpp::R_POWERPC_GOT16_HI
:
7466 case elfcpp::R_POWERPC_GOT16_HA
:
7467 case elfcpp::R_PPC64_GOT16_DS
:
7468 case elfcpp::R_PPC64_GOT16_LO_DS
:
7469 case elfcpp::R_PPC64_GOT_PCREL34
:
7472 // PLT relocs are OK and need a PLT entry.
7473 case elfcpp::R_POWERPC_PLT16_LO
:
7474 case elfcpp::R_POWERPC_PLT16_HI
:
7475 case elfcpp::R_POWERPC_PLT16_HA
:
7476 case elfcpp::R_PPC64_PLT16_LO_DS
:
7477 case elfcpp::R_POWERPC_PLTSEQ
:
7478 case elfcpp::R_POWERPC_PLTCALL
:
7479 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7480 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7481 case elfcpp::R_PPC64_PLT_PCREL34
:
7482 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7486 // Function calls are good, and these do need a PLT entry.
7487 case elfcpp::R_PPC64_REL24_NOTOC
:
7491 case elfcpp::R_POWERPC_ADDR24
:
7492 case elfcpp::R_POWERPC_ADDR14
:
7493 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7494 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7495 case elfcpp::R_POWERPC_REL24
:
7496 case elfcpp::R_PPC_PLTREL24
:
7497 case elfcpp::R_POWERPC_REL14
:
7498 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7499 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7506 // Anything else is a problem.
7507 // If we are building a static executable, the libc startup function
7508 // responsible for applying indirect function relocations is going
7509 // to complain about the reloc type.
7510 // If we are building a dynamic executable, we will have a text
7511 // relocation. The dynamic loader will set the text segment
7512 // writable and non-executable to apply text relocations. So we'll
7513 // segfault when trying to run the indirection function to resolve
7516 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7517 object
->name().c_str(), r_type
);
7521 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7525 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7527 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7528 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7529 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7530 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7531 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7532 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7533 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7534 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7535 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7536 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7537 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7538 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7539 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7540 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7541 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7542 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7543 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7544 /* Exclude lfqu by testing reloc. If relocs are ever
7545 defined for the reduced D field in psq_lu then those
7546 will need testing too. */
7547 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7548 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7549 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7551 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7552 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7553 /* Exclude stfqu. psq_stu as above for psq_lu. */
7554 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7555 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7556 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7557 && (insn
& 1) == 0));
7560 // Scan a relocation for a local symbol.
7562 template<int size
, bool big_endian
>
7564 Target_powerpc
<size
, big_endian
>::Scan::local(
7565 Symbol_table
* symtab
,
7567 Target_powerpc
<size
, big_endian
>* target
,
7568 Sized_relobj_file
<size
, big_endian
>* object
,
7569 unsigned int data_shndx
,
7570 Output_section
* output_section
,
7571 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7572 unsigned int r_type
,
7573 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7576 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7578 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7579 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7581 this->expect_tls_get_addr_call();
7582 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7583 if (tls_type
!= tls::TLSOPT_NONE
)
7584 this->skip_next_tls_get_addr_call();
7586 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7587 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7589 this->expect_tls_get_addr_call();
7590 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7591 if (tls_type
!= tls::TLSOPT_NONE
)
7592 this->skip_next_tls_get_addr_call();
7595 Powerpc_relobj
<size
, big_endian
>* ppc_object
7596 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7601 && data_shndx
== ppc_object
->opd_shndx()
7602 && r_type
== elfcpp::R_PPC64_ADDR64
)
7603 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7607 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7608 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7609 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7611 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7612 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7613 r_type
, r_sym
, reloc
.get_r_addend());
7614 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7619 case elfcpp::R_POWERPC_NONE
:
7620 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7621 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7622 case elfcpp::R_POWERPC_TLS
:
7623 case elfcpp::R_PPC64_ENTRY
:
7624 case elfcpp::R_POWERPC_PLTSEQ
:
7625 case elfcpp::R_POWERPC_PLTCALL
:
7626 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7627 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7628 case elfcpp::R_PPC64_PCREL_OPT
:
7629 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7630 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7631 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7632 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7633 case elfcpp::R_PPC64_REL16_HIGHER34
:
7634 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7635 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7636 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7637 case elfcpp::R_PPC64_D34
:
7638 case elfcpp::R_PPC64_D34_LO
:
7639 case elfcpp::R_PPC64_D34_HI30
:
7640 case elfcpp::R_PPC64_D34_HA30
:
7641 case elfcpp::R_PPC64_D28
:
7642 case elfcpp::R_PPC64_PCREL34
:
7643 case elfcpp::R_PPC64_PCREL28
:
7644 case elfcpp::R_PPC64_TPREL34
:
7645 case elfcpp::R_PPC64_DTPREL34
:
7648 case elfcpp::R_PPC64_TOC
:
7650 Output_data_got_powerpc
<size
, big_endian
>* got
7651 = target
->got_section(symtab
, layout
);
7652 if (parameters
->options().output_is_position_independent())
7654 Address off
= reloc
.get_r_offset();
7656 && target
->abiversion() < 2
7657 && data_shndx
== ppc_object
->opd_shndx()
7658 && ppc_object
->get_opd_discard(off
- 8))
7661 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7662 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7663 rela_dyn
->add_output_section_relative(got
->output_section(),
7664 elfcpp::R_POWERPC_RELATIVE
,
7666 object
, data_shndx
, off
,
7667 symobj
->toc_base_offset());
7672 case elfcpp::R_PPC64_ADDR64
:
7673 case elfcpp::R_PPC64_UADDR64
:
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_ADDR16_LO
:
7679 case elfcpp::R_POWERPC_ADDR16_HI
:
7680 case elfcpp::R_POWERPC_ADDR16_HA
:
7681 case elfcpp::R_POWERPC_UADDR16
:
7682 case elfcpp::R_PPC64_ADDR16_HIGH
:
7683 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7684 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7685 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7686 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7687 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7688 case elfcpp::R_PPC64_ADDR16_DS
:
7689 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7690 case elfcpp::R_POWERPC_ADDR14
:
7691 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7692 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7693 // If building a shared library (or a position-independent
7694 // executable), we need to create a dynamic relocation for
7696 if (parameters
->options().output_is_position_independent()
7697 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7699 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7701 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7702 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7703 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7705 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7706 : elfcpp::R_POWERPC_RELATIVE
);
7707 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7708 output_section
, data_shndx
,
7709 reloc
.get_r_offset(),
7710 reloc
.get_r_addend(), false);
7712 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7714 check_non_pic(object
, r_type
);
7715 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7716 data_shndx
, reloc
.get_r_offset(),
7717 reloc
.get_r_addend());
7721 gold_assert(lsym
.get_st_value() == 0);
7722 unsigned int shndx
= lsym
.get_st_shndx();
7724 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7727 object
->error(_("section symbol %u has bad shndx %u"),
7730 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7731 output_section
, data_shndx
,
7732 reloc
.get_r_offset());
7737 case elfcpp::R_PPC64_PLT_PCREL34
:
7738 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7739 case elfcpp::R_POWERPC_PLT16_LO
:
7740 case elfcpp::R_POWERPC_PLT16_HI
:
7741 case elfcpp::R_POWERPC_PLT16_HA
:
7742 case elfcpp::R_PPC64_PLT16_LO_DS
:
7745 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7746 target
->make_local_plt_entry(layout
, object
, r_sym
);
7750 case elfcpp::R_PPC64_REL24_NOTOC
:
7754 case elfcpp::R_POWERPC_REL24
:
7755 case elfcpp::R_PPC_PLTREL24
:
7756 case elfcpp::R_PPC_LOCAL24PC
:
7757 case elfcpp::R_POWERPC_REL14
:
7758 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7759 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7762 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7763 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7764 r_type
, r_sym
, reloc
.get_r_addend());
7768 case elfcpp::R_PPC64_TOCSAVE
:
7769 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7770 // caller has already saved r2 and thus a plt call stub need not
7773 && target
->mark_pltcall(ppc_object
, data_shndx
,
7774 reloc
.get_r_offset() - 4, symtab
))
7776 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7777 unsigned int shndx
= lsym
.get_st_shndx();
7779 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7781 object
->error(_("tocsave symbol %u has bad shndx %u"),
7784 target
->add_tocsave(ppc_object
, shndx
,
7785 lsym
.get_st_value() + reloc
.get_r_addend());
7789 case elfcpp::R_PPC64_REL64
:
7790 case elfcpp::R_POWERPC_REL32
:
7791 case elfcpp::R_POWERPC_REL16
:
7792 case elfcpp::R_POWERPC_REL16_LO
:
7793 case elfcpp::R_POWERPC_REL16_HI
:
7794 case elfcpp::R_POWERPC_REL16_HA
:
7795 case elfcpp::R_POWERPC_REL16DX_HA
:
7796 case elfcpp::R_PPC64_REL16_HIGH
:
7797 case elfcpp::R_PPC64_REL16_HIGHA
:
7798 case elfcpp::R_PPC64_REL16_HIGHER
:
7799 case elfcpp::R_PPC64_REL16_HIGHERA
:
7800 case elfcpp::R_PPC64_REL16_HIGHEST
:
7801 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7802 case elfcpp::R_POWERPC_SECTOFF
:
7803 case elfcpp::R_POWERPC_SECTOFF_LO
:
7804 case elfcpp::R_POWERPC_SECTOFF_HI
:
7805 case elfcpp::R_POWERPC_SECTOFF_HA
:
7806 case elfcpp::R_PPC64_SECTOFF_DS
:
7807 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7808 case elfcpp::R_POWERPC_TPREL16
:
7809 case elfcpp::R_POWERPC_TPREL16_LO
:
7810 case elfcpp::R_POWERPC_TPREL16_HI
:
7811 case elfcpp::R_POWERPC_TPREL16_HA
:
7812 case elfcpp::R_PPC64_TPREL16_DS
:
7813 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7814 case elfcpp::R_PPC64_TPREL16_HIGH
:
7815 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7816 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7817 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7818 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7819 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7820 case elfcpp::R_POWERPC_DTPREL16
:
7821 case elfcpp::R_POWERPC_DTPREL16_LO
:
7822 case elfcpp::R_POWERPC_DTPREL16_HI
:
7823 case elfcpp::R_POWERPC_DTPREL16_HA
:
7824 case elfcpp::R_PPC64_DTPREL16_DS
:
7825 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7826 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7827 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7828 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7829 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7830 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7831 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7832 case elfcpp::R_PPC64_TLSGD
:
7833 case elfcpp::R_PPC64_TLSLD
:
7834 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7837 case elfcpp::R_PPC64_GOT_PCREL34
:
7838 case elfcpp::R_POWERPC_GOT16
:
7839 case elfcpp::R_POWERPC_GOT16_LO
:
7840 case elfcpp::R_POWERPC_GOT16_HI
:
7841 case elfcpp::R_POWERPC_GOT16_HA
:
7842 case elfcpp::R_PPC64_GOT16_DS
:
7843 case elfcpp::R_PPC64_GOT16_LO_DS
:
7845 // The symbol requires a GOT entry.
7846 Output_data_got_powerpc
<size
, big_endian
>* got
7847 = target
->got_section(symtab
, layout
);
7848 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7850 if (!parameters
->options().output_is_position_independent())
7853 && (size
== 32 || target
->abiversion() >= 2))
7854 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
7856 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
7858 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
7860 // If we are generating a shared object or a pie, this
7861 // symbol's GOT entry will be set by a dynamic relocation.
7863 off
= got
->add_constant(0);
7864 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
7866 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7868 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7869 : elfcpp::R_POWERPC_RELATIVE
);
7870 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7871 got
, off
, 0, false);
7876 case elfcpp::R_PPC64_TOC16
:
7877 case elfcpp::R_PPC64_TOC16_LO
:
7878 case elfcpp::R_PPC64_TOC16_HI
:
7879 case elfcpp::R_PPC64_TOC16_HA
:
7880 case elfcpp::R_PPC64_TOC16_DS
:
7881 case elfcpp::R_PPC64_TOC16_LO_DS
:
7882 // We need a GOT section.
7883 target
->got_section(symtab
, layout
);
7886 case elfcpp::R_PPC64_GOT_TLSGD34
:
7887 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7888 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7889 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7890 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7892 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7893 if (tls_type
== tls::TLSOPT_NONE
)
7895 Output_data_got_powerpc
<size
, big_endian
>* got
7896 = target
->got_section(symtab
, layout
);
7897 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7898 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7899 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
7900 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
7902 else if (tls_type
== tls::TLSOPT_TO_LE
)
7904 // no GOT relocs needed for Local Exec.
7911 case elfcpp::R_PPC64_GOT_TLSLD34
:
7912 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7913 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7914 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7915 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7917 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7918 if (tls_type
== tls::TLSOPT_NONE
)
7919 target
->tlsld_got_offset(symtab
, layout
, object
);
7920 else if (tls_type
== tls::TLSOPT_TO_LE
)
7922 // no GOT relocs needed for Local Exec.
7923 if (parameters
->options().emit_relocs())
7925 Output_section
* os
= layout
->tls_segment()->first_section();
7926 gold_assert(os
!= NULL
);
7927 os
->set_needs_symtab_index();
7935 case elfcpp::R_PPC64_GOT_DTPREL34
:
7936 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7937 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7938 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7939 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7941 Output_data_got_powerpc
<size
, big_endian
>* got
7942 = target
->got_section(symtab
, layout
);
7943 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7944 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
7948 case elfcpp::R_PPC64_GOT_TPREL34
:
7949 case elfcpp::R_POWERPC_GOT_TPREL16
:
7950 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7951 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7952 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7954 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
7955 if (tls_type
== tls::TLSOPT_NONE
)
7957 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7958 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
7960 Output_data_got_powerpc
<size
, big_endian
>* got
7961 = target
->got_section(symtab
, layout
);
7962 unsigned int off
= got
->add_constant(0);
7963 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
7965 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7966 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
7967 elfcpp::R_POWERPC_TPREL
,
7971 else if (tls_type
== tls::TLSOPT_TO_LE
)
7973 // no GOT relocs needed for Local Exec.
7981 unsupported_reloc_local(object
, r_type
);
7986 && parameters
->options().toc_optimize())
7988 if (data_shndx
== ppc_object
->toc_shndx())
7991 if (r_type
!= elfcpp::R_PPC64_ADDR64
7992 || (is_ifunc
&& target
->abiversion() < 2))
7994 else if (parameters
->options().output_is_position_independent())
8000 unsigned int shndx
= lsym
.get_st_shndx();
8001 if (shndx
>= elfcpp::SHN_LORESERVE
8002 && shndx
!= elfcpp::SHN_XINDEX
)
8007 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8010 enum {no_check
, check_lo
, check_ha
} insn_check
;
8014 insn_check
= no_check
;
8017 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8018 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8019 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8020 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8021 case elfcpp::R_POWERPC_GOT16_HA
:
8022 case elfcpp::R_PPC64_TOC16_HA
:
8023 insn_check
= check_ha
;
8026 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8027 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8028 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8029 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8030 case elfcpp::R_POWERPC_GOT16_LO
:
8031 case elfcpp::R_PPC64_GOT16_LO_DS
:
8032 case elfcpp::R_PPC64_TOC16_LO
:
8033 case elfcpp::R_PPC64_TOC16_LO_DS
:
8034 insn_check
= check_lo
;
8038 section_size_type slen
;
8039 const unsigned char* view
= NULL
;
8040 if (insn_check
!= no_check
)
8042 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8043 section_size_type off
=
8044 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8047 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8048 if (insn_check
== check_lo
8049 ? !ok_lo_toc_insn(insn
, r_type
)
8050 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8051 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8053 ppc_object
->set_no_toc_opt();
8054 gold_warning(_("%s: toc optimization is not supported "
8055 "for %#08x instruction"),
8056 ppc_object
->name().c_str(), insn
);
8065 case elfcpp::R_PPC64_TOC16
:
8066 case elfcpp::R_PPC64_TOC16_LO
:
8067 case elfcpp::R_PPC64_TOC16_HI
:
8068 case elfcpp::R_PPC64_TOC16_HA
:
8069 case elfcpp::R_PPC64_TOC16_DS
:
8070 case elfcpp::R_PPC64_TOC16_LO_DS
:
8071 unsigned int shndx
= lsym
.get_st_shndx();
8072 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8074 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8075 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8077 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8078 if (dst_off
< ppc_object
->section_size(shndx
))
8081 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8083 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8085 // Need to check that the insn is a ld
8087 view
= ppc_object
->section_contents(data_shndx
,
8090 section_size_type off
=
8091 (convert_to_section_size_type(reloc
.get_r_offset())
8092 + (big_endian
? -2 : 3));
8094 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8098 ppc_object
->set_no_toc_opt(dst_off
);
8109 case elfcpp::R_POWERPC_REL32
:
8110 if (ppc_object
->got2_shndx() != 0
8111 && parameters
->options().output_is_position_independent())
8113 unsigned int shndx
= lsym
.get_st_shndx();
8114 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8116 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8117 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8118 && (ppc_object
->section_flags(data_shndx
)
8119 & elfcpp::SHF_EXECINSTR
) != 0)
8120 gold_error(_("%s: unsupported -mbss-plt code"),
8121 ppc_object
->name().c_str());
8131 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8132 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8133 case elfcpp::R_POWERPC_GOT_TPREL16
:
8134 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8135 case elfcpp::R_POWERPC_GOT16
:
8136 case elfcpp::R_PPC64_GOT16_DS
:
8137 case elfcpp::R_PPC64_TOC16
:
8138 case elfcpp::R_PPC64_TOC16_DS
:
8139 ppc_object
->set_has_small_toc_reloc();
8147 case elfcpp::R_POWERPC_TPREL16
:
8148 case elfcpp::R_POWERPC_TPREL16_LO
:
8149 case elfcpp::R_POWERPC_TPREL16_HI
:
8150 case elfcpp::R_POWERPC_TPREL16_HA
:
8151 case elfcpp::R_PPC64_TPREL16_DS
:
8152 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8153 case elfcpp::R_PPC64_TPREL16_HIGH
:
8154 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8155 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8156 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8157 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8158 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8159 case elfcpp::R_PPC64_TPREL34
:
8160 layout
->set_has_static_tls();
8168 case elfcpp::R_PPC64_D34
:
8169 case elfcpp::R_PPC64_D34_LO
:
8170 case elfcpp::R_PPC64_D34_HI30
:
8171 case elfcpp::R_PPC64_D34_HA30
:
8172 case elfcpp::R_PPC64_D28
:
8173 case elfcpp::R_PPC64_PCREL34
:
8174 case elfcpp::R_PPC64_PCREL28
:
8175 case elfcpp::R_PPC64_TPREL34
:
8176 case elfcpp::R_PPC64_DTPREL34
:
8177 case elfcpp::R_PPC64_PLT_PCREL34
:
8178 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8179 case elfcpp::R_PPC64_GOT_PCREL34
:
8180 case elfcpp::R_PPC64_GOT_TLSGD34
:
8181 case elfcpp::R_PPC64_GOT_TLSLD34
:
8182 case elfcpp::R_PPC64_GOT_DTPREL34
:
8183 case elfcpp::R_PPC64_GOT_TPREL34
:
8184 target
->set_powerxx_stubs();
8191 // Report an unsupported relocation against a global symbol.
8193 template<int size
, bool big_endian
>
8195 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8196 Sized_relobj_file
<size
, big_endian
>* object
,
8197 unsigned int r_type
,
8200 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8201 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8204 // Scan a relocation for a global symbol.
8206 template<int size
, bool big_endian
>
8208 Target_powerpc
<size
, big_endian
>::Scan::global(
8209 Symbol_table
* symtab
,
8211 Target_powerpc
<size
, big_endian
>* target
,
8212 Sized_relobj_file
<size
, big_endian
>* object
,
8213 unsigned int data_shndx
,
8214 Output_section
* output_section
,
8215 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8216 unsigned int r_type
,
8219 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8223 if (target
->replace_tls_get_addr(gsym
))
8224 // Change a __tls_get_addr reference to __tls_get_addr_opt
8225 // so dynamic relocs are emitted against the latter symbol.
8226 gsym
= target
->tls_get_addr_opt();
8228 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8229 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8231 this->expect_tls_get_addr_call();
8232 const bool final
= gsym
->final_value_is_known();
8233 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8234 if (tls_type
!= tls::TLSOPT_NONE
)
8235 this->skip_next_tls_get_addr_call();
8237 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8238 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8240 this->expect_tls_get_addr_call();
8241 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8242 if (tls_type
!= tls::TLSOPT_NONE
)
8243 this->skip_next_tls_get_addr_call();
8246 Powerpc_relobj
<size
, big_endian
>* ppc_object
8247 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8249 // A STT_GNU_IFUNC symbol may require a PLT entry.
8250 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8251 bool pushed_ifunc
= false;
8252 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8254 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8255 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8256 r_type
, r_sym
, reloc
.get_r_addend());
8257 target
->make_plt_entry(symtab
, layout
, gsym
);
8258 pushed_ifunc
= true;
8263 case elfcpp::R_POWERPC_NONE
:
8264 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8265 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8266 case elfcpp::R_PPC_LOCAL24PC
:
8267 case elfcpp::R_POWERPC_TLS
:
8268 case elfcpp::R_PPC64_ENTRY
:
8269 case elfcpp::R_POWERPC_PLTSEQ
:
8270 case elfcpp::R_POWERPC_PLTCALL
:
8271 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8272 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8273 case elfcpp::R_PPC64_PCREL_OPT
:
8274 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8275 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8276 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8277 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8278 case elfcpp::R_PPC64_REL16_HIGHER34
:
8279 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8280 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8281 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8282 case elfcpp::R_PPC64_D34
:
8283 case elfcpp::R_PPC64_D34_LO
:
8284 case elfcpp::R_PPC64_D34_HI30
:
8285 case elfcpp::R_PPC64_D34_HA30
:
8286 case elfcpp::R_PPC64_D28
:
8287 case elfcpp::R_PPC64_PCREL34
:
8288 case elfcpp::R_PPC64_PCREL28
:
8289 case elfcpp::R_PPC64_TPREL34
:
8290 case elfcpp::R_PPC64_DTPREL34
:
8293 case elfcpp::R_PPC64_TOC
:
8295 Output_data_got_powerpc
<size
, big_endian
>* got
8296 = target
->got_section(symtab
, layout
);
8297 if (parameters
->options().output_is_position_independent())
8299 Address off
= reloc
.get_r_offset();
8301 && data_shndx
== ppc_object
->opd_shndx()
8302 && ppc_object
->get_opd_discard(off
- 8))
8305 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8306 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8307 if (data_shndx
!= ppc_object
->opd_shndx())
8308 symobj
= static_cast
8309 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8310 rela_dyn
->add_output_section_relative(got
->output_section(),
8311 elfcpp::R_POWERPC_RELATIVE
,
8313 object
, data_shndx
, off
,
8314 symobj
->toc_base_offset());
8319 case elfcpp::R_PPC64_ADDR64
:
8321 && target
->abiversion() < 2
8322 && data_shndx
== ppc_object
->opd_shndx()
8323 && (gsym
->is_defined_in_discarded_section()
8324 || gsym
->object() != object
))
8326 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8330 case elfcpp::R_PPC64_UADDR64
:
8331 case elfcpp::R_POWERPC_ADDR32
:
8332 case elfcpp::R_POWERPC_UADDR32
:
8333 case elfcpp::R_POWERPC_ADDR24
:
8334 case elfcpp::R_POWERPC_ADDR16
:
8335 case elfcpp::R_POWERPC_ADDR16_LO
:
8336 case elfcpp::R_POWERPC_ADDR16_HI
:
8337 case elfcpp::R_POWERPC_ADDR16_HA
:
8338 case elfcpp::R_POWERPC_UADDR16
:
8339 case elfcpp::R_PPC64_ADDR16_HIGH
:
8340 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8341 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8342 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8343 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8344 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8345 case elfcpp::R_PPC64_ADDR16_DS
:
8346 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8347 case elfcpp::R_POWERPC_ADDR14
:
8348 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8349 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8351 // Make a PLT entry if necessary.
8352 if (gsym
->needs_plt_entry())
8354 // Since this is not a PC-relative relocation, we may be
8355 // taking the address of a function. In that case we need to
8356 // set the entry in the dynamic symbol table to the address of
8357 // the PLT call stub.
8358 bool need_ifunc_plt
= false;
8359 if ((size
== 32 || target
->abiversion() >= 2)
8360 && gsym
->is_from_dynobj()
8361 && !parameters
->options().output_is_position_independent())
8363 gsym
->set_needs_dynsym_value();
8364 need_ifunc_plt
= true;
8366 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8368 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8369 target
->push_branch(ppc_object
, data_shndx
,
8370 reloc
.get_r_offset(), r_type
, r_sym
,
8371 reloc
.get_r_addend());
8372 target
->make_plt_entry(symtab
, layout
, gsym
);
8375 // Make a dynamic relocation if necessary.
8376 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8377 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8379 if (!parameters
->options().output_is_position_independent()
8380 && gsym
->may_need_copy_reloc())
8382 target
->copy_reloc(symtab
, layout
, object
,
8383 data_shndx
, output_section
, gsym
, reloc
);
8385 else if ((((size
== 32
8386 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8388 && r_type
== elfcpp::R_PPC64_ADDR64
8389 && target
->abiversion() >= 2))
8390 && gsym
->can_use_relative_reloc(false)
8391 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8392 && parameters
->options().shared()))
8394 && r_type
== elfcpp::R_PPC64_ADDR64
8395 && target
->abiversion() < 2
8396 && (gsym
->can_use_relative_reloc(false)
8397 || data_shndx
== ppc_object
->opd_shndx())))
8399 Reloc_section
* rela_dyn
8400 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8401 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8402 : elfcpp::R_POWERPC_RELATIVE
);
8403 rela_dyn
->add_symbolless_global_addend(
8404 gsym
, dynrel
, output_section
, object
, data_shndx
,
8405 reloc
.get_r_offset(), reloc
.get_r_addend());
8409 Reloc_section
* rela_dyn
8410 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8411 check_non_pic(object
, r_type
);
8412 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8414 reloc
.get_r_offset(),
8415 reloc
.get_r_addend());
8418 && parameters
->options().toc_optimize()
8419 && data_shndx
== ppc_object
->toc_shndx())
8420 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8426 case elfcpp::R_PPC64_PLT_PCREL34
:
8427 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8428 case elfcpp::R_POWERPC_PLT16_LO
:
8429 case elfcpp::R_POWERPC_PLT16_HI
:
8430 case elfcpp::R_POWERPC_PLT16_HA
:
8431 case elfcpp::R_PPC64_PLT16_LO_DS
:
8433 target
->make_plt_entry(symtab
, layout
, gsym
);
8436 case elfcpp::R_PPC64_REL24_NOTOC
:
8440 case elfcpp::R_PPC_PLTREL24
:
8441 case elfcpp::R_POWERPC_REL24
:
8444 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8445 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8446 r_type
, r_sym
, reloc
.get_r_addend());
8447 if (gsym
->needs_plt_entry()
8448 || (!gsym
->final_value_is_known()
8449 && (gsym
->is_undefined()
8450 || gsym
->is_from_dynobj()
8451 || gsym
->is_preemptible())))
8452 target
->make_plt_entry(symtab
, layout
, gsym
);
8456 case elfcpp::R_PPC64_REL64
:
8457 case elfcpp::R_POWERPC_REL32
:
8458 // Make a dynamic relocation if necessary.
8459 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8461 if (!parameters
->options().output_is_position_independent()
8462 && gsym
->may_need_copy_reloc())
8464 target
->copy_reloc(symtab
, layout
, object
,
8465 data_shndx
, output_section
, gsym
,
8470 Reloc_section
* rela_dyn
8471 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8472 check_non_pic(object
, r_type
);
8473 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8474 data_shndx
, reloc
.get_r_offset(),
8475 reloc
.get_r_addend());
8480 case elfcpp::R_POWERPC_REL14
:
8481 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8482 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8485 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8486 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8487 r_type
, r_sym
, reloc
.get_r_addend());
8491 case elfcpp::R_PPC64_TOCSAVE
:
8492 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8493 // caller has already saved r2 and thus a plt call stub need not
8496 && target
->mark_pltcall(ppc_object
, data_shndx
,
8497 reloc
.get_r_offset() - 4, symtab
))
8499 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8501 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8503 object
->error(_("tocsave symbol %u has bad shndx %u"),
8507 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8508 target
->add_tocsave(ppc_object
, shndx
,
8509 sym
->value() + reloc
.get_r_addend());
8514 case elfcpp::R_POWERPC_REL16
:
8515 case elfcpp::R_POWERPC_REL16_LO
:
8516 case elfcpp::R_POWERPC_REL16_HI
:
8517 case elfcpp::R_POWERPC_REL16_HA
:
8518 case elfcpp::R_POWERPC_REL16DX_HA
:
8519 case elfcpp::R_PPC64_REL16_HIGH
:
8520 case elfcpp::R_PPC64_REL16_HIGHA
:
8521 case elfcpp::R_PPC64_REL16_HIGHER
:
8522 case elfcpp::R_PPC64_REL16_HIGHERA
:
8523 case elfcpp::R_PPC64_REL16_HIGHEST
:
8524 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8525 case elfcpp::R_POWERPC_SECTOFF
:
8526 case elfcpp::R_POWERPC_SECTOFF_LO
:
8527 case elfcpp::R_POWERPC_SECTOFF_HI
:
8528 case elfcpp::R_POWERPC_SECTOFF_HA
:
8529 case elfcpp::R_PPC64_SECTOFF_DS
:
8530 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8531 case elfcpp::R_POWERPC_TPREL16
:
8532 case elfcpp::R_POWERPC_TPREL16_LO
:
8533 case elfcpp::R_POWERPC_TPREL16_HI
:
8534 case elfcpp::R_POWERPC_TPREL16_HA
:
8535 case elfcpp::R_PPC64_TPREL16_DS
:
8536 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8537 case elfcpp::R_PPC64_TPREL16_HIGH
:
8538 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8539 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8540 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8541 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8542 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8543 case elfcpp::R_POWERPC_DTPREL16
:
8544 case elfcpp::R_POWERPC_DTPREL16_LO
:
8545 case elfcpp::R_POWERPC_DTPREL16_HI
:
8546 case elfcpp::R_POWERPC_DTPREL16_HA
:
8547 case elfcpp::R_PPC64_DTPREL16_DS
:
8548 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8549 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8550 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8551 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8552 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8553 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8554 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8555 case elfcpp::R_PPC64_TLSGD
:
8556 case elfcpp::R_PPC64_TLSLD
:
8557 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8560 case elfcpp::R_PPC64_GOT_PCREL34
:
8561 case elfcpp::R_POWERPC_GOT16
:
8562 case elfcpp::R_POWERPC_GOT16_LO
:
8563 case elfcpp::R_POWERPC_GOT16_HI
:
8564 case elfcpp::R_POWERPC_GOT16_HA
:
8565 case elfcpp::R_PPC64_GOT16_DS
:
8566 case elfcpp::R_PPC64_GOT16_LO_DS
:
8568 // The symbol requires a GOT entry.
8569 Output_data_got_powerpc
<size
, big_endian
>* got
;
8571 got
= target
->got_section(symtab
, layout
);
8572 if (gsym
->final_value_is_known())
8575 && (size
== 32 || target
->abiversion() >= 2))
8576 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8578 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8580 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8582 // If we are generating a shared object or a pie, this
8583 // symbol's GOT entry will be set by a dynamic relocation.
8584 unsigned int off
= got
->add_constant(0);
8585 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8587 Reloc_section
* rela_dyn
8588 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8590 if (gsym
->can_use_relative_reloc(false)
8592 || target
->abiversion() >= 2)
8593 && gsym
->visibility() == elfcpp::STV_PROTECTED
8594 && parameters
->options().shared()))
8596 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8597 : elfcpp::R_POWERPC_RELATIVE
);
8598 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8602 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8603 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8609 case elfcpp::R_PPC64_TOC16
:
8610 case elfcpp::R_PPC64_TOC16_LO
:
8611 case elfcpp::R_PPC64_TOC16_HI
:
8612 case elfcpp::R_PPC64_TOC16_HA
:
8613 case elfcpp::R_PPC64_TOC16_DS
:
8614 case elfcpp::R_PPC64_TOC16_LO_DS
:
8615 // We need a GOT section.
8616 target
->got_section(symtab
, layout
);
8619 case elfcpp::R_PPC64_GOT_TLSGD34
:
8620 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8621 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8622 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8623 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8625 const bool final
= gsym
->final_value_is_known();
8626 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8627 if (tls_type
== tls::TLSOPT_NONE
)
8629 Output_data_got_powerpc
<size
, big_endian
>* got
8630 = target
->got_section(symtab
, layout
);
8631 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8632 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8633 elfcpp::R_POWERPC_DTPMOD
,
8634 elfcpp::R_POWERPC_DTPREL
);
8636 else if (tls_type
== tls::TLSOPT_TO_IE
)
8638 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8640 Output_data_got_powerpc
<size
, big_endian
>* got
8641 = target
->got_section(symtab
, layout
);
8642 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8643 if (gsym
->is_undefined()
8644 || gsym
->is_from_dynobj())
8646 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8647 elfcpp::R_POWERPC_TPREL
);
8651 unsigned int off
= got
->add_constant(0);
8652 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8653 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8654 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8659 else if (tls_type
== tls::TLSOPT_TO_LE
)
8661 // no GOT relocs needed for Local Exec.
8668 case elfcpp::R_PPC64_GOT_TLSLD34
:
8669 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8670 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8671 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8672 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8674 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8675 if (tls_type
== tls::TLSOPT_NONE
)
8676 target
->tlsld_got_offset(symtab
, layout
, object
);
8677 else if (tls_type
== tls::TLSOPT_TO_LE
)
8679 // no GOT relocs needed for Local Exec.
8680 if (parameters
->options().emit_relocs())
8682 Output_section
* os
= layout
->tls_segment()->first_section();
8683 gold_assert(os
!= NULL
);
8684 os
->set_needs_symtab_index();
8692 case elfcpp::R_PPC64_GOT_DTPREL34
:
8693 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8694 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8695 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8696 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8698 Output_data_got_powerpc
<size
, big_endian
>* got
8699 = target
->got_section(symtab
, layout
);
8700 if (!gsym
->final_value_is_known()
8701 && (gsym
->is_from_dynobj()
8702 || gsym
->is_undefined()
8703 || gsym
->is_preemptible()))
8704 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8705 target
->rela_dyn_section(layout
),
8706 elfcpp::R_POWERPC_DTPREL
);
8708 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8712 case elfcpp::R_PPC64_GOT_TPREL34
:
8713 case elfcpp::R_POWERPC_GOT_TPREL16
:
8714 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8715 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8716 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8718 const bool final
= gsym
->final_value_is_known();
8719 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8720 if (tls_type
== tls::TLSOPT_NONE
)
8722 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8724 Output_data_got_powerpc
<size
, big_endian
>* got
8725 = target
->got_section(symtab
, layout
);
8726 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8727 if (gsym
->is_undefined()
8728 || gsym
->is_from_dynobj())
8730 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8731 elfcpp::R_POWERPC_TPREL
);
8735 unsigned int off
= got
->add_constant(0);
8736 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8737 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8738 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8743 else if (tls_type
== tls::TLSOPT_TO_LE
)
8745 // no GOT relocs needed for Local Exec.
8753 unsupported_reloc_global(object
, r_type
, gsym
);
8758 && parameters
->options().toc_optimize())
8760 if (data_shndx
== ppc_object
->toc_shndx())
8763 if (r_type
!= elfcpp::R_PPC64_ADDR64
8764 || (is_ifunc
&& target
->abiversion() < 2))
8766 else if (parameters
->options().output_is_position_independent()
8767 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
8770 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8773 enum {no_check
, check_lo
, check_ha
} insn_check
;
8777 insn_check
= no_check
;
8780 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8781 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8782 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8783 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8784 case elfcpp::R_POWERPC_GOT16_HA
:
8785 case elfcpp::R_PPC64_TOC16_HA
:
8786 insn_check
= check_ha
;
8789 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8790 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8791 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8792 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8793 case elfcpp::R_POWERPC_GOT16_LO
:
8794 case elfcpp::R_PPC64_GOT16_LO_DS
:
8795 case elfcpp::R_PPC64_TOC16_LO
:
8796 case elfcpp::R_PPC64_TOC16_LO_DS
:
8797 insn_check
= check_lo
;
8801 section_size_type slen
;
8802 const unsigned char* view
= NULL
;
8803 if (insn_check
!= no_check
)
8805 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8806 section_size_type off
=
8807 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8810 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8811 if (insn_check
== check_lo
8812 ? !ok_lo_toc_insn(insn
, r_type
)
8813 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8814 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8816 ppc_object
->set_no_toc_opt();
8817 gold_warning(_("%s: toc optimization is not supported "
8818 "for %#08x instruction"),
8819 ppc_object
->name().c_str(), insn
);
8828 case elfcpp::R_PPC64_TOC16
:
8829 case elfcpp::R_PPC64_TOC16_LO
:
8830 case elfcpp::R_PPC64_TOC16_HI
:
8831 case elfcpp::R_PPC64_TOC16_HA
:
8832 case elfcpp::R_PPC64_TOC16_DS
:
8833 case elfcpp::R_PPC64_TOC16_LO_DS
:
8834 if (gsym
->source() == Symbol::FROM_OBJECT
8835 && !gsym
->object()->is_dynamic())
8837 Powerpc_relobj
<size
, big_endian
>* sym_object
8838 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8840 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8841 if (shndx
== sym_object
->toc_shndx())
8843 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8844 Address dst_off
= sym
->value() + reloc
.get_r_addend();
8845 if (dst_off
< sym_object
->section_size(shndx
))
8848 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8850 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8852 // Need to check that the insn is a ld
8854 view
= ppc_object
->section_contents(data_shndx
,
8857 section_size_type off
=
8858 (convert_to_section_size_type(reloc
.get_r_offset())
8859 + (big_endian
? -2 : 3));
8861 && (view
[off
] & (0x3f << 2)) == (58u << 2))
8865 sym_object
->set_no_toc_opt(dst_off
);
8877 case elfcpp::R_PPC_LOCAL24PC
:
8878 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
8879 gold_error(_("%s: unsupported -mbss-plt code"),
8880 ppc_object
->name().c_str());
8889 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8890 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8891 case elfcpp::R_POWERPC_GOT_TPREL16
:
8892 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8893 case elfcpp::R_POWERPC_GOT16
:
8894 case elfcpp::R_PPC64_GOT16_DS
:
8895 case elfcpp::R_PPC64_TOC16
:
8896 case elfcpp::R_PPC64_TOC16_DS
:
8897 ppc_object
->set_has_small_toc_reloc();
8905 case elfcpp::R_POWERPC_TPREL16
:
8906 case elfcpp::R_POWERPC_TPREL16_LO
:
8907 case elfcpp::R_POWERPC_TPREL16_HI
:
8908 case elfcpp::R_POWERPC_TPREL16_HA
:
8909 case elfcpp::R_PPC64_TPREL16_DS
:
8910 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8911 case elfcpp::R_PPC64_TPREL16_HIGH
:
8912 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8913 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8914 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8915 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8916 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8917 case elfcpp::R_PPC64_TPREL34
:
8918 layout
->set_has_static_tls();
8926 case elfcpp::R_PPC64_D34
:
8927 case elfcpp::R_PPC64_D34_LO
:
8928 case elfcpp::R_PPC64_D34_HI30
:
8929 case elfcpp::R_PPC64_D34_HA30
:
8930 case elfcpp::R_PPC64_D28
:
8931 case elfcpp::R_PPC64_PCREL34
:
8932 case elfcpp::R_PPC64_PCREL28
:
8933 case elfcpp::R_PPC64_TPREL34
:
8934 case elfcpp::R_PPC64_DTPREL34
:
8935 case elfcpp::R_PPC64_PLT_PCREL34
:
8936 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8937 case elfcpp::R_PPC64_GOT_PCREL34
:
8938 case elfcpp::R_PPC64_GOT_TLSGD34
:
8939 case elfcpp::R_PPC64_GOT_TLSLD34
:
8940 case elfcpp::R_PPC64_GOT_DTPREL34
:
8941 case elfcpp::R_PPC64_GOT_TPREL34
:
8942 target
->set_powerxx_stubs();
8949 // Process relocations for gc.
8951 template<int size
, bool big_endian
>
8953 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
8954 Symbol_table
* symtab
,
8956 Sized_relobj_file
<size
, big_endian
>* object
,
8957 unsigned int data_shndx
,
8959 const unsigned char* prelocs
,
8961 Output_section
* output_section
,
8962 bool needs_special_offset_handling
,
8963 size_t local_symbol_count
,
8964 const unsigned char* plocal_symbols
)
8966 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8967 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8970 Powerpc_relobj
<size
, big_endian
>* ppc_object
8971 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8973 ppc_object
->set_opd_valid();
8974 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
8976 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
8977 for (p
= ppc_object
->access_from_map()->begin();
8978 p
!= ppc_object
->access_from_map()->end();
8981 Address dst_off
= p
->first
;
8982 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8983 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
8984 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
8986 Relobj
* src_obj
= s
->first
;
8987 unsigned int src_indx
= s
->second
;
8988 symtab
->gc()->add_reference(src_obj
, src_indx
,
8989 ppc_object
, dst_indx
);
8993 ppc_object
->access_from_map()->clear();
8994 ppc_object
->process_gc_mark(symtab
);
8995 // Don't look at .opd relocs as .opd will reference everything.
8999 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9008 needs_special_offset_handling
,
9013 // Handle target specific gc actions when adding a gc reference from
9014 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
9015 // and DST_OFF. For powerpc64, this adds a referenc to the code
9016 // section of a function descriptor.
9018 template<int size
, bool big_endian
>
9020 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
9021 Symbol_table
* symtab
,
9023 unsigned int src_shndx
,
9025 unsigned int dst_shndx
,
9026 Address dst_off
) const
9028 if (size
!= 64 || dst_obj
->is_dynamic())
9031 Powerpc_relobj
<size
, big_endian
>* ppc_object
9032 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
9033 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
9035 if (ppc_object
->opd_valid())
9037 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
9038 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
9042 // If we haven't run scan_opd_relocs, we must delay
9043 // processing this function descriptor reference.
9044 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
9049 // Add any special sections for this symbol to the gc work list.
9050 // For powerpc64, this adds the code section of a function
9053 template<int size
, bool big_endian
>
9055 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
9056 Symbol_table
* symtab
,
9061 Powerpc_relobj
<size
, big_endian
>* ppc_object
9062 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
9064 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9065 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
9067 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
9068 Address dst_off
= gsym
->value();
9069 if (ppc_object
->opd_valid())
9071 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
9072 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
9076 ppc_object
->add_gc_mark(dst_off
);
9081 // For a symbol location in .opd, set LOC to the location of the
9084 template<int size
, bool big_endian
>
9086 Target_powerpc
<size
, big_endian
>::do_function_location(
9087 Symbol_location
* loc
) const
9089 if (size
== 64 && loc
->shndx
!= 0)
9091 if (loc
->object
->is_dynamic())
9093 Powerpc_dynobj
<size
, big_endian
>* ppc_object
9094 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
9095 if (loc
->shndx
== ppc_object
->opd_shndx())
9098 Address off
= loc
->offset
- ppc_object
->opd_address();
9099 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
9100 loc
->offset
= dest_off
;
9105 const Powerpc_relobj
<size
, big_endian
>* ppc_object
9106 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9107 if (loc
->shndx
== ppc_object
->opd_shndx())
9110 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9111 loc
->offset
= dest_off
;
9117 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9118 // compiled with -fsplit-stack. The function calls non-split-stack
9119 // code. Change the function to ensure it has enough stack space to
9120 // call some random function.
9122 template<int size
, bool big_endian
>
9124 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9127 section_offset_type fnoffset
,
9128 section_size_type fnsize
,
9129 const unsigned char* prelocs
,
9131 unsigned char* view
,
9132 section_size_type view_size
,
9134 std::string
* to
) const
9136 // 32-bit not supported.
9140 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9141 prelocs
, reloc_count
, view
, view_size
,
9146 // The function always starts with
9147 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9148 // addis %r12,%r1,-allocate@ha
9149 // addi %r12,%r12,-allocate@l
9151 // but note that the addis or addi may be replaced with a nop
9153 unsigned char *entry
= view
+ fnoffset
;
9154 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9156 if ((insn
& 0xffff0000) == addis_2_12
)
9158 /* Skip ELFv2 global entry code. */
9160 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9163 unsigned char *pinsn
= entry
;
9165 const uint32_t ld_private_ss
= 0xe80d8fc0;
9166 if (insn
== ld_private_ss
)
9168 int32_t allocate
= 0;
9172 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9173 if ((insn
& 0xffff0000) == addis_12_1
)
9174 allocate
+= (insn
& 0xffff) << 16;
9175 else if ((insn
& 0xffff0000) == addi_12_1
9176 || (insn
& 0xffff0000) == addi_12_12
)
9177 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9178 else if (insn
!= nop
)
9181 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9183 int extra
= parameters
->options().split_stack_adjust_size();
9185 if (allocate
>= 0 || extra
< 0)
9187 object
->error(_("split-stack stack size overflow at "
9188 "section %u offset %0zx"),
9189 shndx
, static_cast<size_t>(fnoffset
));
9193 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9194 if (insn
!= addis_12_1
)
9196 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9198 insn
= addi_12_12
| (allocate
& 0xffff);
9199 if (insn
!= addi_12_12
)
9201 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9207 insn
= addi_12_1
| (allocate
& 0xffff);
9208 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9211 if (pinsn
!= entry
+ 12)
9212 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9220 if (!object
->has_no_split_stack())
9221 object
->error(_("failed to match split-stack sequence at "
9222 "section %u offset %0zx"),
9223 shndx
, static_cast<size_t>(fnoffset
));
9227 // Scan relocations for a section.
9229 template<int size
, bool big_endian
>
9231 Target_powerpc
<size
, big_endian
>::scan_relocs(
9232 Symbol_table
* symtab
,
9234 Sized_relobj_file
<size
, big_endian
>* object
,
9235 unsigned int data_shndx
,
9236 unsigned int sh_type
,
9237 const unsigned char* prelocs
,
9239 Output_section
* output_section
,
9240 bool needs_special_offset_handling
,
9241 size_t local_symbol_count
,
9242 const unsigned char* plocal_symbols
)
9244 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9245 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9248 if (!this->plt_localentry0_init_
)
9250 bool plt_localentry0
= false;
9252 && this->abiversion() >= 2)
9254 if (parameters
->options().user_set_plt_localentry())
9255 plt_localentry0
= parameters
->options().plt_localentry();
9257 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9258 gold_warning(_("--plt-localentry is especially dangerous without "
9259 "ld.so support to detect ABI violations"));
9261 this->plt_localentry0_
= plt_localentry0
;
9262 this->plt_localentry0_init_
= true;
9265 if (sh_type
== elfcpp::SHT_REL
)
9267 gold_error(_("%s: unsupported REL reloc section"),
9268 object
->name().c_str());
9272 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9281 needs_special_offset_handling
,
9286 // Functor class for processing the global symbol table.
9287 // Removes symbols defined on discarded opd entries.
9289 template<bool big_endian
>
9290 class Global_symbol_visitor_opd
9293 Global_symbol_visitor_opd()
9297 operator()(Sized_symbol
<64>* sym
)
9299 if (sym
->has_symtab_index()
9300 || sym
->source() != Symbol::FROM_OBJECT
9301 || !sym
->in_real_elf())
9304 if (sym
->object()->is_dynamic())
9307 Powerpc_relobj
<64, big_endian
>* symobj
9308 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9309 if (symobj
->opd_shndx() == 0)
9313 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9314 if (shndx
== symobj
->opd_shndx()
9315 && symobj
->get_opd_discard(sym
->value()))
9317 sym
->set_undefined();
9318 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9319 sym
->set_is_defined_in_discarded_section();
9320 sym
->set_symtab_index(-1U);
9325 template<int size
, bool big_endian
>
9327 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9329 Symbol_table
* symtab
)
9333 Output_data_save_res
<size
, big_endian
>* savres
9334 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9335 this->savres_section_
= savres
;
9336 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9337 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9338 savres
, ORDER_TEXT
, false);
9342 // Sort linker created .got section first (for the header), then input
9343 // sections belonging to files using small model code.
9345 template<bool big_endian
>
9346 class Sort_toc_sections
9350 operator()(const Output_section::Input_section
& is1
,
9351 const Output_section::Input_section
& is2
) const
9353 if (!is1
.is_input_section() && is2
.is_input_section())
9356 = (is1
.is_input_section()
9357 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9358 ->has_small_toc_reloc()));
9360 = (is2
.is_input_section()
9361 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9362 ->has_small_toc_reloc()));
9363 return small1
&& !small2
;
9367 // Finalize the sections.
9369 template<int size
, bool big_endian
>
9371 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9373 const Input_objects
* input_objects
,
9374 Symbol_table
* symtab
)
9376 if (parameters
->doing_static_link())
9378 // At least some versions of glibc elf-init.o have a strong
9379 // reference to __rela_iplt marker syms. A weak ref would be
9381 if (this->iplt_
!= NULL
)
9383 Reloc_section
* rel
= this->iplt_
->rel_plt();
9384 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9385 Symbol_table::PREDEFINED
, rel
, 0, 0,
9386 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9387 elfcpp::STV_HIDDEN
, 0, false, true);
9388 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9389 Symbol_table::PREDEFINED
, rel
, 0, 0,
9390 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9391 elfcpp::STV_HIDDEN
, 0, true, true);
9395 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9396 Symbol_table::PREDEFINED
, 0, 0,
9397 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9398 elfcpp::STV_HIDDEN
, 0, true, false);
9399 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9400 Symbol_table::PREDEFINED
, 0, 0,
9401 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9402 elfcpp::STV_HIDDEN
, 0, true, false);
9408 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9409 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9411 if (!parameters
->options().relocatable())
9413 this->define_save_restore_funcs(layout
, symtab
);
9415 // Annoyingly, we need to make these sections now whether or
9416 // not we need them. If we delay until do_relax then we
9417 // need to mess with the relaxation machinery checkpointing.
9418 this->got_section(symtab
, layout
);
9419 this->make_brlt_section(layout
);
9421 if (parameters
->options().toc_sort())
9423 Output_section
* os
= this->got_
->output_section();
9424 if (os
!= NULL
&& os
->input_sections().size() > 1)
9425 std::stable_sort(os
->input_sections().begin(),
9426 os
->input_sections().end(),
9427 Sort_toc_sections
<big_endian
>());
9432 // Fill in some more dynamic tags.
9433 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9436 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9438 : this->plt_
->rel_plt());
9439 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9440 this->rela_dyn_
, true, size
== 32);
9444 if (this->got_
!= NULL
)
9446 this->got_
->finalize_data_size();
9447 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9448 this->got_
, this->got_
->g_o_t());
9450 if (this->has_tls_get_addr_opt_
)
9451 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9455 if (this->glink_
!= NULL
)
9457 this->glink_
->finalize_data_size();
9458 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9460 (this->glink_
->pltresolve_size()
9463 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9464 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9465 ((this->has_localentry0_
9466 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9467 | (this->has_tls_get_addr_opt_
9468 ? elfcpp::PPC64_OPT_TLS
: 0)));
9472 // Emit any relocs we saved in an attempt to avoid generating COPY
9474 if (this->copy_relocs_
.any_saved_relocs())
9475 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9477 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9478 p
!= input_objects
->relobj_end();
9481 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9482 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9483 if (ppc_relobj
->attributes_section_data())
9484 this->merge_object_attributes(ppc_relobj
->name().c_str(),
9485 ppc_relobj
->attributes_section_data());
9487 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9488 p
!= input_objects
->dynobj_end();
9491 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9492 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9493 if (ppc_dynobj
->attributes_section_data())
9494 this->merge_object_attributes(ppc_dynobj
->name().c_str(),
9495 ppc_dynobj
->attributes_section_data());
9498 // Create a .gnu.attributes section if we have merged any attributes
9500 if (this->attributes_section_data_
!= NULL
9501 && this->attributes_section_data_
->size() != 0)
9503 Output_attributes_section_data
* attributes_section
9504 = new Output_attributes_section_data(*this->attributes_section_data_
);
9505 layout
->add_output_section_data(".gnu.attributes",
9506 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9507 attributes_section
, ORDER_INVALID
, false);
9511 // Merge object attributes from input file called NAME with those of the
9512 // output. The input object attributes are in the object pointed by PASD.
9514 template<int size
, bool big_endian
>
9516 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9518 const Attributes_section_data
* pasd
)
9520 // Return if there is no attributes section data.
9524 // Create output object attributes.
9525 if (this->attributes_section_data_
== NULL
)
9526 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9528 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9529 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9530 Object_attribute
* out_attr
9531 = this->attributes_section_data_
->known_attributes(vendor
);
9536 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9537 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9538 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9539 if (in_fp
!= out_fp
)
9542 if ((in_fp
& 3) == 0)
9544 else if ((out_fp
& 3) == 0)
9546 out_fp
|= in_fp
& 3;
9547 out_attr
[tag
].set_int_value(out_fp
);
9548 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9549 this->last_fp_
= name
;
9551 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9553 err
= N_("%s uses hard float, %s uses soft float");
9554 first
= this->last_fp_
;
9557 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9559 err
= N_("%s uses hard float, %s uses soft float");
9561 second
= this->last_fp_
;
9563 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9565 err
= N_("%s uses double-precision hard float, "
9566 "%s uses single-precision hard float");
9567 first
= this->last_fp_
;
9570 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9572 err
= N_("%s uses double-precision hard float, "
9573 "%s uses single-precision hard float");
9575 second
= this->last_fp_
;
9578 if (err
|| (in_fp
& 0xc) == 0)
9580 else if ((out_fp
& 0xc) == 0)
9582 out_fp
|= in_fp
& 0xc;
9583 out_attr
[tag
].set_int_value(out_fp
);
9584 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9585 this->last_ld_
= name
;
9587 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9589 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9591 second
= this->last_ld_
;
9593 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9595 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9596 first
= this->last_ld_
;
9599 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9601 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9602 first
= this->last_ld_
;
9605 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9607 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9609 second
= this->last_ld_
;
9614 if (parameters
->options().warn_mismatch())
9615 gold_error(_(err
), first
, second
);
9616 // Arrange for this attribute to be deleted. It's better to
9617 // say "don't know" about a file than to wrongly claim compliance.
9618 out_attr
[tag
].set_type(0);
9624 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9625 int in_vec
= in_attr
[tag
].int_value() & 3;
9626 int out_vec
= out_attr
[tag
].int_value() & 3;
9627 if (in_vec
!= out_vec
)
9632 else if (out_vec
== 0)
9635 out_attr
[tag
].set_int_value(out_vec
);
9636 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9637 this->last_vec_
= name
;
9639 // For now, allow generic to transition to AltiVec or SPE
9640 // without a warning. If GCC marked files with their stack
9641 // alignment and used don't-care markings for files which are
9642 // not affected by the vector ABI, we could warn about this
9644 else if (in_vec
== 1)
9646 else if (out_vec
== 1)
9649 out_attr
[tag
].set_int_value(out_vec
);
9650 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9651 this->last_vec_
= name
;
9653 else if (out_vec
< in_vec
)
9655 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9656 first
= this->last_vec_
;
9659 else if (out_vec
> in_vec
)
9661 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9663 second
= this->last_vec_
;
9667 if (parameters
->options().warn_mismatch())
9668 gold_error(_(err
), first
, second
);
9669 out_attr
[tag
].set_type(0);
9673 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9674 int in_struct
= in_attr
[tag
].int_value() & 3;
9675 int out_struct
= out_attr
[tag
].int_value() & 3;
9676 if (in_struct
!= out_struct
)
9679 if (in_struct
== 0 || in_struct
== 3)
9681 else if (out_struct
== 0)
9683 out_struct
= in_struct
;
9684 out_attr
[tag
].set_int_value(out_struct
);
9685 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9686 this->last_struct_
= name
;
9688 else if (out_struct
< in_struct
)
9690 err
= N_("%s uses r3/r4 for small structure returns, "
9692 first
= this->last_struct_
;
9695 else if (out_struct
> in_struct
)
9697 err
= N_("%s uses r3/r4 for small structure returns, "
9700 second
= this->last_struct_
;
9704 if (parameters
->options().warn_mismatch())
9705 gold_error(_(err
), first
, second
);
9706 out_attr
[tag
].set_type(0);
9711 // Merge Tag_compatibility attributes and any common GNU ones.
9712 this->attributes_section_data_
->merge(name
, pasd
);
9715 // Emit any saved relocs, and mark toc entries using any of these
9716 // relocs as not optimizable.
9718 template<int sh_type
, int size
, bool big_endian
>
9720 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
9721 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
9724 && parameters
->options().toc_optimize())
9726 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
9727 Copy_reloc_entries::iterator p
= this->entries_
.begin();
9728 p
!= this->entries_
.end();
9731 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
9734 // If the symbol is no longer defined in a dynamic object,
9735 // then we emitted a COPY relocation. If it is still
9736 // dynamic then we'll need dynamic relocations and thus
9737 // can't optimize toc entries.
9738 if (entry
.sym_
->is_from_dynobj())
9740 Powerpc_relobj
<size
, big_endian
>* ppc_object
9741 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
9742 if (entry
.shndx_
== ppc_object
->toc_shndx())
9743 ppc_object
->set_no_toc_opt(entry
.address_
);
9748 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
9751 // Return the value to use for a branch relocation.
9753 template<int size
, bool big_endian
>
9755 Target_powerpc
<size
, big_endian
>::symval_for_branch(
9756 const Symbol_table
* symtab
,
9757 const Sized_symbol
<size
>* gsym
,
9758 Powerpc_relobj
<size
, big_endian
>* object
,
9760 unsigned int *dest_shndx
)
9762 if (size
== 32 || this->abiversion() >= 2)
9766 // If the symbol is defined in an opd section, ie. is a function
9767 // descriptor, use the function descriptor code entry address
9768 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
9770 && (gsym
->source() != Symbol::FROM_OBJECT
9771 || gsym
->object()->is_dynamic()))
9774 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9775 unsigned int shndx
= symobj
->opd_shndx();
9778 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
9779 if (opd_addr
== invalid_address
)
9781 opd_addr
+= symobj
->output_section_address(shndx
);
9782 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
9785 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
9786 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
9789 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
9790 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
9791 *dest_shndx
= folded
.second
;
9793 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
9794 if (sec_addr
== invalid_address
)
9797 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
9798 *value
= sec_addr
+ sec_off
;
9805 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
9807 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
9810 if (gsym
->is_from_dynobj()
9811 || gsym
->is_undefined()
9812 || gsym
->is_preemptible())
9815 if (gsym
->is_absolute())
9816 return !parameters
->options().output_is_position_independent();
9823 relative_value_is_known(const Symbol_value
<size
>* psymval
)
9825 if (psymval
->is_ifunc_symbol())
9829 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
9831 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
9834 // PCREL_OPT in one instance flags to the linker that a pair of insns:
9835 // pld ra,symbol@got@pcrel
9836 // load/store rt,0(ra)
9838 // pla ra,symbol@pcrel
9839 // load/store rt,0(ra)
9840 // may be translated to
9841 // pload/pstore rt,symbol@pcrel
9843 // This function returns true if the optimization is possible, placing
9844 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
9846 // On entry to this function, the linker has already determined that
9847 // the pld can be replaced with pla: *PINSN1 is that pla insn,
9848 // while *PINSN2 is the second instruction.
9851 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
9853 uint32_t insn2
= *pinsn2
>> 32;
9856 // Check that regs match.
9857 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
9860 switch ((insn2
>> 26) & 63)
9876 // These are the PMLS cases, where we just need to tack a prefix
9877 // on the insn. Check that the D field is zero.
9878 if ((insn2
& 0xffff) != 0)
9880 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
9881 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
9885 if ((insn2
& 0xfffd) != 0)
9887 i1new
= ((1ULL << 58) | (1ULL << 52)
9888 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
9889 | (insn2
& (31ULL << 21)));
9892 case 57: // lxsd, lxssp
9893 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
9895 i1new
= ((1ULL << 58) | (1ULL << 52)
9896 | ((40ULL | (insn2
& 3)) << 26)
9897 | (insn2
& (31ULL << 21)));
9900 case 61: // stxsd, stxssp, lxv, stxv
9901 if ((insn2
& 3) == 0)
9903 else if ((insn2
& 3) >= 2)
9905 if ((insn2
& 0xfffc) != 0)
9907 i1new
= ((1ULL << 58) | (1ULL << 52)
9908 | ((44ULL | (insn2
& 3)) << 26)
9909 | (insn2
& (31ULL << 21)));
9913 if ((insn2
& 0xfff0) != 0)
9915 i1new
= ((1ULL << 58) | (1ULL << 52)
9916 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
9917 | (insn2
& (31ULL << 21)));
9922 if ((insn2
& 0xffff) != 0)
9924 i1new
= ((1ULL << 58) | (1ULL << 52)
9925 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
9928 case 62: // std, stq
9929 if ((insn2
& 0xfffd) != 0)
9931 i1new
= ((1ULL << 58) | (1ULL << 52)
9932 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
9933 | (insn2
& (31ULL << 21)));
9938 *pinsn2
= (uint64_t) nop
<< 32;
9942 // Perform a relocation.
9944 template<int size
, bool big_endian
>
9946 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
9947 const Relocate_info
<size
, big_endian
>* relinfo
,
9949 Target_powerpc
* target
,
9952 const unsigned char* preloc
,
9953 const Sized_symbol
<size
>* gsym
,
9954 const Symbol_value
<size
>* psymval
,
9955 unsigned char* view
,
9957 section_size_type view_size
)
9959 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
9960 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
9961 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9966 if (target
->replace_tls_get_addr(gsym
))
9967 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
9969 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
9970 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
9971 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
9973 case Track_tls::NOT_EXPECTED
:
9974 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9975 _("__tls_get_addr call lacks marker reloc"));
9977 case Track_tls::EXPECTED
:
9978 // We have already complained.
9980 case Track_tls::SKIP
:
9981 if (is_plt16_reloc
<size
>(r_type
)
9982 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9983 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
9985 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9986 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9988 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
9990 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9991 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
9993 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
9994 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9996 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9997 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
9998 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10001 case Track_tls::NORMAL
:
10005 // Offset from start of insn to d-field reloc.
10006 const int d_offset
= big_endian
? 2 : 0;
10008 Powerpc_relobj
<size
, big_endian
>* const object
10009 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10011 bool has_stub_value
= false;
10012 bool localentry0
= false;
10013 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
10014 bool has_plt_offset
10016 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
10017 : object
->local_has_plt_offset(r_sym
));
10019 && !is_plt16_reloc
<size
>(r_type
)
10020 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10021 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
10022 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
10023 && r_type
!= elfcpp::R_POWERPC_PLTCALL
10024 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
10025 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
10026 && (!psymval
->is_ifunc_symbol()
10027 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
10031 && target
->abiversion() >= 2
10032 && !parameters
->options().output_is_position_independent()
10033 && !is_branch_reloc
<size
>(r_type
))
10035 Address off
= target
->glink_section()->find_global_entry(gsym
);
10036 if (off
!= invalid_address
)
10038 value
= target
->glink_section()->global_entry_address() + off
;
10039 has_stub_value
= true;
10044 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
10045 if (target
->stub_tables().size() == 1)
10046 stub_table
= target
->stub_tables()[0];
10047 if (stub_table
== NULL
10050 && !parameters
->options().output_is_position_independent()
10051 && !is_branch_reloc
<size
>(r_type
)))
10052 stub_table
= object
->stub_table(relinfo
->data_shndx
);
10053 if (stub_table
== NULL
)
10055 // This is a ref from a data section to an ifunc symbol,
10056 // or a non-branch reloc for which we always want to use
10057 // one set of stubs for resolving function addresses.
10058 if (target
->stub_tables().size() != 0)
10059 stub_table
= target
->stub_tables()[0];
10061 if (stub_table
!= NULL
)
10063 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
10065 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
10066 rela
.get_r_addend());
10068 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
10069 rela
.get_r_addend());
10072 value
= stub_table
->stub_address() + ent
->off_
;
10073 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10074 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10075 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10078 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
10080 else if (size
== 64
10082 && relnum
< reloc_count
- 1)
10084 Reltype
next_rela(preloc
+ reloc_size
);
10085 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10086 == elfcpp::R_PPC64_TOCSAVE
10087 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
10090 localentry0
= ent
->localentry0_
;
10091 has_stub_value
= true;
10095 // We don't care too much about bogus debug references to
10096 // non-local functions, but otherwise there had better be a plt
10097 // call stub or global entry stub as appropriate.
10098 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
10101 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
10102 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
10103 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10105 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10107 value
= target
->plt_off(gsym
, &plt
);
10109 value
= target
->plt_off(object
, r_sym
, &plt
);
10110 value
+= plt
->address();
10114 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10115 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10116 value
-= (target
->got_section()->output_section()->address()
10117 + object
->toc_base_offset());
10119 else if (parameters
->options().output_is_position_independent())
10121 if (rela
.get_r_addend() >= 32768)
10123 unsigned int got2
= object
->got2_shndx();
10124 value
-= (object
->get_output_section_offset(got2
)
10125 + object
->output_section(got2
)->address()
10126 + rela
.get_r_addend());
10129 value
-= (target
->got_section()->address()
10130 + target
->got_section()->g_o_t());
10133 else if (!has_plt_offset
10134 && (is_plt16_reloc
<size
>(r_type
)
10135 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10136 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10138 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10139 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10140 r_type
= elfcpp::R_POWERPC_NONE
;
10142 else if (!has_plt_offset
10143 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10144 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10146 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10147 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10148 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10149 r_type
= elfcpp::R_POWERPC_NONE
;
10151 else if (r_type
== elfcpp::R_POWERPC_GOT16
10152 || r_type
== elfcpp::R_POWERPC_GOT16_LO
10153 || r_type
== elfcpp::R_POWERPC_GOT16_HI
10154 || r_type
== elfcpp::R_POWERPC_GOT16_HA
10155 || r_type
== elfcpp::R_PPC64_GOT16_DS
10156 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10157 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10161 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10162 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10166 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10167 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10169 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10170 value
+= target
->got_section()->address();
10172 value
-= target
->got_section()->got_base_offset(object
);
10174 else if (r_type
== elfcpp::R_PPC64_TOC
)
10176 value
= (target
->got_section()->output_section()->address()
10177 + object
->toc_base_offset());
10179 else if (gsym
!= NULL
10180 && (r_type
== elfcpp::R_POWERPC_REL24
10181 || r_type
== elfcpp::R_PPC_PLTREL24
)
10186 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10187 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10188 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10189 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10191 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10192 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10193 if ((insn
& 1) != 0
10195 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10197 elfcpp::Swap
<32, big_endian
>::
10198 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10199 can_plt_call
= true;
10204 // If we don't have a branch and link followed by a nop,
10205 // we can't go via the plt because there is no place to
10206 // put a toc restoring instruction.
10207 // Unless we know we won't be returning.
10208 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10209 can_plt_call
= true;
10213 // g++ as of 20130507 emits self-calls without a
10214 // following nop. This is arguably wrong since we have
10215 // conflicting information. On the one hand a global
10216 // symbol and on the other a local call sequence, but
10217 // don't error for this special case.
10218 // It isn't possible to cheaply verify we have exactly
10219 // such a call. Allow all calls to the same section.
10221 Address code
= value
;
10222 if (gsym
->source() == Symbol::FROM_OBJECT
10223 && gsym
->object() == object
)
10225 unsigned int dest_shndx
= 0;
10226 if (target
->abiversion() < 2)
10228 Address addend
= rela
.get_r_addend();
10229 code
= psymval
->value(object
, addend
);
10230 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10231 &code
, &dest_shndx
);
10234 if (dest_shndx
== 0)
10235 dest_shndx
= gsym
->shndx(&is_ordinary
);
10236 ok
= dest_shndx
== relinfo
->data_shndx
;
10240 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10241 _("call lacks nop, can't restore toc; "
10242 "recompile with -fPIC"));
10248 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10249 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10250 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10251 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
10252 || r_type
== elfcpp::R_PPC64_GOT_TLSGD34
)
10254 // First instruction of a global dynamic sequence, arg setup insn.
10255 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10256 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10257 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10258 if (tls_type
== tls::TLSOPT_NONE
)
10259 got_type
= GOT_TYPE_TLSGD
;
10260 else if (tls_type
== tls::TLSOPT_TO_IE
)
10261 got_type
= GOT_TYPE_TPREL
;
10262 if (got_type
!= GOT_TYPE_STANDARD
)
10266 gold_assert(gsym
->has_got_offset(got_type
));
10267 value
= gsym
->got_offset(got_type
);
10271 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10272 value
= object
->local_got_offset(r_sym
, got_type
);
10274 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD34
)
10275 value
+= target
->got_section()->address();
10277 value
-= target
->got_section()->got_base_offset(object
);
10279 if (tls_type
== tls::TLSOPT_TO_IE
)
10281 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD34
)
10283 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10284 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10286 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10288 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
10289 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10290 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10291 pinsn
& 0xffffffff);
10292 r_type
= elfcpp::R_PPC64_GOT_TPREL34
;
10296 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10297 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10299 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10300 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10301 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10303 insn
|= 32 << 26; // lwz
10305 insn
|= 58 << 26; // ld
10306 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10308 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10309 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10312 else if (tls_type
== tls::TLSOPT_TO_LE
)
10314 if (r_type
== elfcpp::R_PPC64_GOT_TLSGD34
)
10316 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10317 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10319 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10320 // pla pcrel -> paddi r13
10321 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10322 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10323 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10324 pinsn
& 0xffffffff);
10325 r_type
= elfcpp::R_PPC64_TPREL34
;
10326 value
= psymval
->value(object
, rela
.get_r_addend());
10330 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10331 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10333 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10334 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10335 insn
&= (1 << 26) - (1 << 21); // extract rt
10339 insn
|= addis_0_13
;
10340 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10341 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10342 value
= psymval
->value(object
, rela
.get_r_addend());
10346 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10348 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10349 r_type
= elfcpp::R_POWERPC_NONE
;
10354 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10355 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10356 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10357 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
10358 || r_type
== elfcpp::R_PPC64_GOT_TLSLD34
)
10360 // First instruction of a local dynamic sequence, arg setup insn.
10361 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10362 if (tls_type
== tls::TLSOPT_NONE
)
10364 value
= target
->tlsld_got_offset();
10365 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD34
)
10366 value
+= target
->got_section()->address();
10368 value
-= target
->got_section()->got_base_offset(object
);
10372 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10373 if (r_type
== elfcpp::R_PPC64_GOT_TLSLD34
)
10375 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10376 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10378 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10379 // pla pcrel -> paddi r13
10380 pinsn
+= (-1ULL << 52) + (13ULL << 16);
10381 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10382 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10383 pinsn
& 0xffffffff);
10384 r_type
= elfcpp::R_PPC64_TPREL34
;
10385 value
= dtp_offset
;
10387 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10388 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10390 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10391 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10392 insn
&= (1 << 26) - (1 << 21); // extract rt
10396 insn
|= addis_0_13
;
10397 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10398 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10399 value
= dtp_offset
;
10403 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10405 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10406 r_type
= elfcpp::R_POWERPC_NONE
;
10410 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10411 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10412 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10413 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
10414 || r_type
== elfcpp::R_PPC64_GOT_DTPREL34
)
10416 // Accesses relative to a local dynamic sequence address,
10417 // no optimisation here.
10420 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10421 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10425 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10426 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10428 if (r_type
== elfcpp::R_PPC64_GOT_DTPREL34
)
10429 value
+= target
->got_section()->address();
10431 value
-= target
->got_section()->got_base_offset(object
);
10433 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10434 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10435 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10436 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
10437 || r_type
== elfcpp::R_PPC64_GOT_TPREL34
)
10439 // First instruction of initial exec sequence.
10440 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10441 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10442 if (tls_type
== tls::TLSOPT_NONE
)
10446 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10447 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10451 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10452 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10454 if (r_type
== elfcpp::R_PPC64_GOT_TPREL34
)
10455 value
+= target
->got_section()->address();
10457 value
-= target
->got_section()->got_base_offset(object
);
10461 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10462 if (r_type
== elfcpp::R_PPC64_GOT_TPREL34
)
10464 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10465 uint64_t pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10467 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10468 // pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel
10469 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
10470 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
10471 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10472 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10473 pinsn
& 0xffffffff);
10474 r_type
= elfcpp::R_PPC64_TPREL34
;
10475 value
= psymval
->value(object
, rela
.get_r_addend());
10477 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10478 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10480 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10481 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10482 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10486 insn
|= addis_0_13
;
10487 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10488 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10489 value
= psymval
->value(object
, rela
.get_r_addend());
10493 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10495 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10496 r_type
= elfcpp::R_POWERPC_NONE
;
10500 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10501 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10503 // Second instruction of a global dynamic sequence,
10504 // the __tls_get_addr call
10505 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10506 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10507 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10508 if (tls_type
!= tls::TLSOPT_NONE
)
10510 if (tls_type
== tls::TLSOPT_TO_IE
)
10512 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10513 Insn insn
= add_3_3_13
;
10516 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10517 r_type
= elfcpp::R_POWERPC_NONE
;
10521 bool is_pcrel
= false;
10522 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10523 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10524 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10525 if (relnum
< reloc_count
- 1)
10527 Reltype
next_rela(preloc
+ reloc_size
);
10528 unsigned int r_type2
10529 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10530 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10531 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10532 && next_rela
.get_r_offset() == rela
.get_r_offset())
10535 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10538 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10539 r_type
= elfcpp::R_POWERPC_NONE
;
10543 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10544 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10546 value
= psymval
->value(object
, rela
.get_r_addend());
10549 this->skip_next_tls_get_addr_call();
10552 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10553 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10555 // Second instruction of a local dynamic sequence,
10556 // the __tls_get_addr call
10557 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10558 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10559 if (tls_type
== tls::TLSOPT_TO_LE
)
10561 bool is_pcrel
= false;
10562 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10563 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10564 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10565 if (relnum
< reloc_count
- 1)
10567 Reltype
next_rela(preloc
+ reloc_size
);
10568 unsigned int r_type2
10569 = elfcpp::elf_r_type
<size
>(next_rela
.get_r_info());
10570 if ((r_type2
== elfcpp::R_PPC64_REL24_NOTOC
10571 || r_type2
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10572 && next_rela
.get_r_offset() == rela
.get_r_offset())
10575 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10578 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10579 r_type
= elfcpp::R_POWERPC_NONE
;
10583 elfcpp::Swap
<32, big_endian
>::writeval(iview
, addi_3_3
);
10584 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10586 value
= dtp_offset
;
10588 this->skip_next_tls_get_addr_call();
10591 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10593 // Second instruction of an initial exec sequence
10594 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10595 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10596 if (tls_type
== tls::TLSOPT_TO_LE
)
10598 Address roff
= rela
.get_r_offset() & 3;
10599 Insn
* iview
= reinterpret_cast<Insn
*>(view
- roff
);
10600 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10601 unsigned int reg
= size
== 32 ? 2 : 13;
10602 insn
= at_tls_transform(insn
, reg
);
10603 gold_assert(insn
!= 0);
10606 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10607 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10609 value
= psymval
->value(object
, rela
.get_r_addend());
10611 else if (roff
== 1)
10613 // For pcrel IE to LE we already have the full offset
10614 // and thus don't need an addi here. A nop or mr will do.
10615 if ((insn
& (0x3f << 26)) == 14 << 26)
10617 // Extract regs from addi rt,ra,si.
10618 unsigned int rt
= (insn
>> 21) & 0x1f;
10619 unsigned int ra
= (insn
>> 16) & 0x1f;
10624 // Build or ra,rs,rb with rb==rs, ie. mr ra,rs.
10625 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
10626 insn
|= (31u << 26) | (444u << 1);
10629 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10630 r_type
= elfcpp::R_POWERPC_NONE
;
10634 else if (!has_stub_value
)
10636 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
10637 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
10639 // PLTCALL without plt entry => convert to direct call
10640 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10641 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10642 insn
= (insn
& 1) | b
;
10643 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10645 r_type
= elfcpp::R_PPC_PLTREL24
;
10646 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10647 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
10649 r_type
= elfcpp::R_POWERPC_REL24
;
10651 Address addend
= 0;
10653 && (r_type
== elfcpp::R_PPC_PLTREL24
10654 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10655 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10656 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
10657 addend
= rela
.get_r_addend();
10658 value
= psymval
->value(object
, addend
);
10659 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
10661 if (target
->abiversion() >= 2)
10664 value
+= object
->ppc64_local_entry_offset(gsym
);
10666 value
+= object
->ppc64_local_entry_offset(r_sym
);
10670 unsigned int dest_shndx
;
10671 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10672 &value
, &dest_shndx
);
10675 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
10676 if (max_branch_offset
!= 0
10677 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
10679 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
10681 ? object
->ppc64_needs_toc(gsym
)
10682 : object
->ppc64_needs_toc(r_sym
)))))
10684 Stub_table
<size
, big_endian
>* stub_table
10685 = object
->stub_table(relinfo
->data_shndx
);
10686 if (stub_table
!= NULL
)
10688 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
10689 = stub_table
->find_long_branch_entry(object
, value
);
10692 if (ent
->save_res_
)
10693 value
= (value
- target
->savres_section()->address()
10694 + stub_table
->branch_size());
10696 value
= (stub_table
->stub_address() + stub_table
->plt_size()
10698 has_stub_value
= true;
10706 case elfcpp::R_PPC64_REL24_NOTOC
:
10710 case elfcpp::R_PPC64_REL64
:
10711 case elfcpp::R_POWERPC_REL32
:
10712 case elfcpp::R_POWERPC_REL24
:
10713 case elfcpp::R_PPC_PLTREL24
:
10714 case elfcpp::R_PPC_LOCAL24PC
:
10715 case elfcpp::R_POWERPC_REL16
:
10716 case elfcpp::R_POWERPC_REL16_LO
:
10717 case elfcpp::R_POWERPC_REL16_HI
:
10718 case elfcpp::R_POWERPC_REL16_HA
:
10719 case elfcpp::R_POWERPC_REL16DX_HA
:
10720 case elfcpp::R_PPC64_REL16_HIGH
:
10721 case elfcpp::R_PPC64_REL16_HIGHA
:
10722 case elfcpp::R_PPC64_REL16_HIGHER
:
10723 case elfcpp::R_PPC64_REL16_HIGHERA
:
10724 case elfcpp::R_PPC64_REL16_HIGHEST
:
10725 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10726 case elfcpp::R_POWERPC_REL14
:
10727 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10728 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10729 case elfcpp::R_PPC64_PCREL34
:
10730 case elfcpp::R_PPC64_GOT_PCREL34
:
10731 case elfcpp::R_PPC64_PLT_PCREL34
:
10732 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
10733 case elfcpp::R_PPC64_PCREL28
:
10734 case elfcpp::R_PPC64_GOT_TLSGD34
:
10735 case elfcpp::R_PPC64_GOT_TLSLD34
:
10736 case elfcpp::R_PPC64_GOT_TPREL34
:
10737 case elfcpp::R_PPC64_GOT_DTPREL34
:
10738 case elfcpp::R_PPC64_REL16_HIGHER34
:
10739 case elfcpp::R_PPC64_REL16_HIGHERA34
:
10740 case elfcpp::R_PPC64_REL16_HIGHEST34
:
10741 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
10745 case elfcpp::R_PPC64_TOC16
:
10746 case elfcpp::R_PPC64_TOC16_LO
:
10747 case elfcpp::R_PPC64_TOC16_HI
:
10748 case elfcpp::R_PPC64_TOC16_HA
:
10749 case elfcpp::R_PPC64_TOC16_DS
:
10750 case elfcpp::R_PPC64_TOC16_LO_DS
:
10751 // Subtract the TOC base address.
10752 value
-= (target
->got_section()->output_section()->address()
10753 + object
->toc_base_offset());
10756 case elfcpp::R_POWERPC_SECTOFF
:
10757 case elfcpp::R_POWERPC_SECTOFF_LO
:
10758 case elfcpp::R_POWERPC_SECTOFF_HI
:
10759 case elfcpp::R_POWERPC_SECTOFF_HA
:
10760 case elfcpp::R_PPC64_SECTOFF_DS
:
10761 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
10763 value
-= os
->address();
10766 case elfcpp::R_PPC64_TPREL16_DS
:
10767 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10768 case elfcpp::R_PPC64_TPREL16_HIGH
:
10769 case elfcpp::R_PPC64_TPREL16_HIGHA
:
10771 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
10774 case elfcpp::R_POWERPC_TPREL16
:
10775 case elfcpp::R_POWERPC_TPREL16_LO
:
10776 case elfcpp::R_POWERPC_TPREL16_HI
:
10777 case elfcpp::R_POWERPC_TPREL16_HA
:
10778 case elfcpp::R_POWERPC_TPREL
:
10779 case elfcpp::R_PPC64_TPREL16_HIGHER
:
10780 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
10781 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10782 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10783 case elfcpp::R_PPC64_TPREL34
:
10784 // tls symbol values are relative to tls_segment()->vaddr()
10785 value
-= tp_offset
;
10788 case elfcpp::R_PPC64_DTPREL16_DS
:
10789 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10790 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10791 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10792 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10793 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10795 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
10796 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
10799 case elfcpp::R_POWERPC_DTPREL16
:
10800 case elfcpp::R_POWERPC_DTPREL16_LO
:
10801 case elfcpp::R_POWERPC_DTPREL16_HI
:
10802 case elfcpp::R_POWERPC_DTPREL16_HA
:
10803 case elfcpp::R_POWERPC_DTPREL
:
10804 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10805 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10806 case elfcpp::R_PPC64_DTPREL34
:
10807 // tls symbol values are relative to tls_segment()->vaddr()
10808 value
-= dtp_offset
;
10811 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10813 value
+= object
->ppc64_local_entry_offset(gsym
);
10815 value
+= object
->ppc64_local_entry_offset(r_sym
);
10822 Insn branch_bit
= 0;
10825 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10826 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10827 branch_bit
= 1 << 21;
10829 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10830 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10832 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10833 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10834 insn
&= ~(1 << 21);
10835 insn
|= branch_bit
;
10836 if (this->is_isa_v2
)
10838 // Set 'a' bit. This is 0b00010 in BO field for branch
10839 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
10840 // for branch on CTR insns (BO == 1a00t or 1a01t).
10841 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10842 insn
|= 0x02 << 21;
10843 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10844 insn
|= 0x08 << 21;
10850 // Invert 'y' bit if not the default.
10851 if (static_cast<Signed_address
>(value
) < 0)
10854 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10858 case elfcpp::R_POWERPC_PLT16_HA
:
10860 && !parameters
->options().output_is_position_independent())
10862 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10863 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10865 // Convert addis to lis.
10866 if ((insn
& (0x3f << 26)) == 15u << 26
10867 && (insn
& (0x1f << 16)) != 0)
10869 insn
&= ~(0x1f << 16);
10870 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10881 ? relative_value_is_known(gsym
)
10882 : relative_value_is_known(psymval
)))
10887 uint64_t pinsn
, pinsn2
;
10894 // Multi-instruction sequences that access the GOT/TOC can
10895 // be optimized, eg.
10896 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
10897 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
10899 // addis ra,r2,0; addi rb,ra,x@toc@l;
10900 // to nop; addi rb,r2,x@toc;
10901 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10902 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10903 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10904 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10905 case elfcpp::R_POWERPC_GOT16_HA
:
10906 case elfcpp::R_PPC64_TOC16_HA
:
10907 if (parameters
->options().toc_optimize())
10909 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10910 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10911 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
10912 && object
->make_toc_relative(target
, &value
))
10913 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
10914 && object
->make_got_relative(target
, psymval
,
10915 rela
.get_r_addend(),
10918 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
10919 == ((15u << 26) | (2 << 16)));
10921 if (((insn
& ((0x3f << 26) | 0x1f << 16))
10922 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
10923 && value
+ 0x8000 < 0x10000)
10925 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10931 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10932 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10933 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10934 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10935 case elfcpp::R_POWERPC_GOT16_LO
:
10936 case elfcpp::R_PPC64_GOT16_LO_DS
:
10937 case elfcpp::R_PPC64_TOC16_LO
:
10938 case elfcpp::R_PPC64_TOC16_LO_DS
:
10939 if (parameters
->options().toc_optimize())
10941 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10942 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10943 bool changed
= false;
10944 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
10945 && object
->make_toc_relative(target
, &value
))
10946 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10947 && object
->make_got_relative(target
, psymval
,
10948 rela
.get_r_addend(),
10951 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
10952 insn
^= (14u << 26) ^ (58u << 26);
10953 r_type
= elfcpp::R_PPC64_TOC16_LO
;
10956 if (ok_lo_toc_insn(insn
, r_type
)
10957 && value
+ 0x8000 < 0x10000)
10959 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
10961 // Transform addic to addi when we change reg.
10962 insn
&= ~((0x3f << 26) | (0x1f << 16));
10963 insn
|= (14u << 26) | (2 << 16);
10967 insn
&= ~(0x1f << 16);
10973 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10977 case elfcpp::R_PPC64_GOT_PCREL34
:
10978 if (parameters
->options().toc_optimize())
10980 iview
= reinterpret_cast<Insn
*>(view
);
10981 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10983 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10984 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
10985 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
10988 Address relval
= psymval
->value(object
, rela
.get_r_addend());
10990 if (relval
+ (1ULL << 33) < 1ULL << 34)
10993 // Replace with paddi
10994 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
10995 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10996 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10997 pinsn
& 0xffffffff);
11003 case elfcpp::R_PPC64_PCREL34
:
11005 iview
= reinterpret_cast<Insn
*>(view
);
11006 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11008 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11009 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
11010 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
11011 | (14ULL << 26) /* paddi */))
11015 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11016 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
11017 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
11018 if (relnum
>= reloc_count
- 1)
11021 Reltype
next_rela(preloc
+ reloc_size
);
11022 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
11023 != elfcpp::R_PPC64_PCREL_OPT
)
11024 || next_rela
.get_r_offset() != rela
.get_r_offset())
11027 Address off
= next_rela
.get_r_addend();
11029 off
= 8; // zero means next insn.
11030 if (off
+ rela
.get_r_offset() + 4 > view_size
)
11033 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
11034 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
11036 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
11038 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
11040 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
11041 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
11042 pinsn
& 0xffffffff);
11043 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
11048 case elfcpp::R_POWERPC_TPREL16_HA
:
11049 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
11051 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11052 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11053 if ((insn
& ((0x3f << 26) | 0x1f << 16))
11054 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
11058 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
11064 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11066 // R_PPC_TLSGD, R_PPC_TLSLD
11069 case elfcpp::R_POWERPC_TPREL16_LO
:
11070 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
11072 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11073 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11074 insn
&= ~(0x1f << 16);
11075 insn
|= (size
== 32 ? 2 : 13) << 16;
11076 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
11080 case elfcpp::R_PPC64_ENTRY
:
11081 value
= (target
->got_section()->output_section()->address()
11082 + object
->toc_base_offset());
11083 if (value
+ 0x80008000 <= 0xffffffff
11084 && !parameters
->options().output_is_position_independent())
11086 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11087 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11088 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11090 if ((insn1
& ~0xfffc) == ld_2_12
11091 && insn2
== add_2_2_12
)
11093 insn1
= lis_2
+ ha(value
);
11094 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11095 insn2
= addi_2_2
+ l(value
);
11096 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11103 if (value
+ 0x80008000 <= 0xffffffff)
11105 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11106 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11107 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
11109 if ((insn1
& ~0xfffc) == ld_2_12
11110 && insn2
== add_2_2_12
)
11112 insn1
= addis_2_12
+ ha(value
);
11113 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
11114 insn2
= addi_2_2
+ l(value
);
11115 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
11122 case elfcpp::R_POWERPC_REL16_LO
:
11123 // If we are generating a non-PIC executable, edit
11124 // 0: addis 2,12,.TOC.-0b@ha
11125 // addi 2,2,.TOC.-0b@l
11126 // used by ELFv2 global entry points to set up r2, to
11128 // addi 2,2,.TOC.@l
11129 // if .TOC. is in range. */
11130 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
11133 && target
->abiversion() >= 2
11134 && !parameters
->options().output_is_position_independent()
11135 && rela
.get_r_addend() == d_offset
+ 4
11137 && strcmp(gsym
->name(), ".TOC.") == 0)
11139 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11140 Reltype
prev_rela(preloc
- reloc_size
);
11141 if ((prev_rela
.get_r_info()
11142 == elfcpp::elf_r_info
<size
>(r_sym
,
11143 elfcpp::R_POWERPC_REL16_HA
))
11144 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
11145 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
11147 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11148 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
11149 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11151 if ((insn1
& 0xffff0000) == addis_2_12
11152 && (insn2
& 0xffff0000) == addi_2_2
)
11154 insn1
= lis_2
+ ha(value
+ address
- 4);
11155 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
11156 insn2
= addi_2_2
+ l(value
+ address
- 4);
11157 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
11160 relinfo
->rr
->set_strategy(relnum
- 1,
11161 Relocatable_relocs::RELOC_SPECIAL
);
11162 relinfo
->rr
->set_strategy(relnum
,
11163 Relocatable_relocs::RELOC_SPECIAL
);
11173 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
11174 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
11177 case elfcpp::R_POWERPC_ADDR32
:
11178 case elfcpp::R_POWERPC_UADDR32
:
11180 overflow
= Reloc::CHECK_BITFIELD
;
11183 case elfcpp::R_POWERPC_REL32
:
11184 case elfcpp::R_POWERPC_REL16DX_HA
:
11186 overflow
= Reloc::CHECK_SIGNED
;
11189 case elfcpp::R_POWERPC_UADDR16
:
11190 overflow
= Reloc::CHECK_BITFIELD
;
11193 case elfcpp::R_POWERPC_ADDR16
:
11194 // We really should have three separate relocations,
11195 // one for 16-bit data, one for insns with 16-bit signed fields,
11196 // and one for insns with 16-bit unsigned fields.
11197 overflow
= Reloc::CHECK_BITFIELD
;
11198 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
11199 overflow
= Reloc::CHECK_LOW_INSN
;
11202 case elfcpp::R_POWERPC_ADDR16_HI
:
11203 case elfcpp::R_POWERPC_ADDR16_HA
:
11204 case elfcpp::R_POWERPC_GOT16_HI
:
11205 case elfcpp::R_POWERPC_GOT16_HA
:
11206 case elfcpp::R_POWERPC_PLT16_HI
:
11207 case elfcpp::R_POWERPC_PLT16_HA
:
11208 case elfcpp::R_POWERPC_SECTOFF_HI
:
11209 case elfcpp::R_POWERPC_SECTOFF_HA
:
11210 case elfcpp::R_PPC64_TOC16_HI
:
11211 case elfcpp::R_PPC64_TOC16_HA
:
11212 case elfcpp::R_PPC64_PLTGOT16_HI
:
11213 case elfcpp::R_PPC64_PLTGOT16_HA
:
11214 case elfcpp::R_POWERPC_TPREL16_HI
:
11215 case elfcpp::R_POWERPC_TPREL16_HA
:
11216 case elfcpp::R_POWERPC_DTPREL16_HI
:
11217 case elfcpp::R_POWERPC_DTPREL16_HA
:
11218 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11219 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11220 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11221 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11222 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11223 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11224 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11225 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11226 case elfcpp::R_POWERPC_REL16_HI
:
11227 case elfcpp::R_POWERPC_REL16_HA
:
11229 overflow
= Reloc::CHECK_HIGH_INSN
;
11232 case elfcpp::R_POWERPC_REL16
:
11233 case elfcpp::R_PPC64_TOC16
:
11234 case elfcpp::R_POWERPC_GOT16
:
11235 case elfcpp::R_POWERPC_SECTOFF
:
11236 case elfcpp::R_POWERPC_TPREL16
:
11237 case elfcpp::R_POWERPC_DTPREL16
:
11238 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11239 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11240 case elfcpp::R_POWERPC_GOT_TPREL16
:
11241 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11242 overflow
= Reloc::CHECK_LOW_INSN
;
11245 case elfcpp::R_PPC64_REL24_NOTOC
:
11249 case elfcpp::R_POWERPC_ADDR24
:
11250 case elfcpp::R_POWERPC_ADDR14
:
11251 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11252 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11253 case elfcpp::R_PPC64_ADDR16_DS
:
11254 case elfcpp::R_POWERPC_REL24
:
11255 case elfcpp::R_PPC_PLTREL24
:
11256 case elfcpp::R_PPC_LOCAL24PC
:
11257 case elfcpp::R_PPC64_TPREL16_DS
:
11258 case elfcpp::R_PPC64_DTPREL16_DS
:
11259 case elfcpp::R_PPC64_TOC16_DS
:
11260 case elfcpp::R_PPC64_GOT16_DS
:
11261 case elfcpp::R_PPC64_SECTOFF_DS
:
11262 case elfcpp::R_POWERPC_REL14
:
11263 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11264 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11265 case elfcpp::R_PPC64_D34
:
11266 case elfcpp::R_PPC64_PCREL34
:
11267 case elfcpp::R_PPC64_GOT_PCREL34
:
11268 case elfcpp::R_PPC64_PLT_PCREL34
:
11269 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11270 case elfcpp::R_PPC64_D28
:
11271 case elfcpp::R_PPC64_PCREL28
:
11272 case elfcpp::R_PPC64_TPREL34
:
11273 case elfcpp::R_PPC64_DTPREL34
:
11274 case elfcpp::R_PPC64_GOT_TLSGD34
:
11275 case elfcpp::R_PPC64_GOT_TLSLD34
:
11276 case elfcpp::R_PPC64_GOT_TPREL34
:
11277 case elfcpp::R_PPC64_GOT_DTPREL34
:
11278 overflow
= Reloc::CHECK_SIGNED
;
11282 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11285 if (overflow
== Reloc::CHECK_LOW_INSN
11286 || overflow
== Reloc::CHECK_HIGH_INSN
)
11288 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11290 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11291 overflow
= Reloc::CHECK_BITFIELD
;
11292 else if (overflow
== Reloc::CHECK_LOW_INSN
11293 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11294 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11295 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11296 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11297 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11298 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11299 overflow
= Reloc::CHECK_UNSIGNED
;
11301 overflow
= Reloc::CHECK_SIGNED
;
11304 bool maybe_dq_reloc
= false;
11305 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11306 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11309 case elfcpp::R_POWERPC_NONE
:
11310 case elfcpp::R_POWERPC_TLS
:
11311 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11312 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11313 case elfcpp::R_POWERPC_PLTSEQ
:
11314 case elfcpp::R_POWERPC_PLTCALL
:
11315 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11316 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11317 case elfcpp::R_PPC64_PCREL_OPT
:
11320 case elfcpp::R_PPC64_ADDR64
:
11321 case elfcpp::R_PPC64_REL64
:
11322 case elfcpp::R_PPC64_TOC
:
11323 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11324 Reloc::addr64(view
, value
);
11327 case elfcpp::R_POWERPC_TPREL
:
11328 case elfcpp::R_POWERPC_DTPREL
:
11330 Reloc::addr64(view
, value
);
11332 status
= Reloc::addr32(view
, value
, overflow
);
11335 case elfcpp::R_PPC64_UADDR64
:
11336 Reloc::addr64_u(view
, value
);
11339 case elfcpp::R_POWERPC_ADDR32
:
11340 status
= Reloc::addr32(view
, value
, overflow
);
11343 case elfcpp::R_POWERPC_REL32
:
11344 case elfcpp::R_POWERPC_UADDR32
:
11345 status
= Reloc::addr32_u(view
, value
, overflow
);
11348 case elfcpp::R_PPC64_REL24_NOTOC
:
11350 goto unsupp
; // R_PPC_EMB_RELSDA
11352 case elfcpp::R_POWERPC_ADDR24
:
11353 case elfcpp::R_POWERPC_REL24
:
11354 case elfcpp::R_PPC_PLTREL24
:
11355 case elfcpp::R_PPC_LOCAL24PC
:
11356 status
= Reloc::addr24(view
, value
, overflow
);
11359 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11360 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11361 case elfcpp::R_POWERPC_GOT_TPREL16
:
11362 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11365 // On ppc64 these are all ds form
11366 maybe_dq_reloc
= true;
11370 case elfcpp::R_POWERPC_ADDR16
:
11371 case elfcpp::R_POWERPC_REL16
:
11372 case elfcpp::R_PPC64_TOC16
:
11373 case elfcpp::R_POWERPC_GOT16
:
11374 case elfcpp::R_POWERPC_SECTOFF
:
11375 case elfcpp::R_POWERPC_TPREL16
:
11376 case elfcpp::R_POWERPC_DTPREL16
:
11377 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11378 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11379 case elfcpp::R_POWERPC_ADDR16_LO
:
11380 case elfcpp::R_POWERPC_REL16_LO
:
11381 case elfcpp::R_PPC64_TOC16_LO
:
11382 case elfcpp::R_POWERPC_GOT16_LO
:
11383 case elfcpp::R_POWERPC_PLT16_LO
:
11384 case elfcpp::R_POWERPC_SECTOFF_LO
:
11385 case elfcpp::R_POWERPC_TPREL16_LO
:
11386 case elfcpp::R_POWERPC_DTPREL16_LO
:
11387 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11388 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11390 status
= Reloc::addr16(view
, value
, overflow
);
11392 maybe_dq_reloc
= true;
11395 case elfcpp::R_POWERPC_UADDR16
:
11396 status
= Reloc::addr16_u(view
, value
, overflow
);
11399 case elfcpp::R_PPC64_ADDR16_HIGH
:
11400 case elfcpp::R_PPC64_TPREL16_HIGH
:
11401 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11403 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11406 case elfcpp::R_POWERPC_ADDR16_HI
:
11407 case elfcpp::R_POWERPC_REL16_HI
:
11408 case elfcpp::R_PPC64_REL16_HIGH
:
11409 case elfcpp::R_PPC64_TOC16_HI
:
11410 case elfcpp::R_POWERPC_GOT16_HI
:
11411 case elfcpp::R_POWERPC_PLT16_HI
:
11412 case elfcpp::R_POWERPC_SECTOFF_HI
:
11413 case elfcpp::R_POWERPC_TPREL16_HI
:
11414 case elfcpp::R_POWERPC_DTPREL16_HI
:
11415 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11416 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11417 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11418 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11419 Reloc::addr16_hi(view
, value
);
11422 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11423 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11424 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11426 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11429 case elfcpp::R_POWERPC_ADDR16_HA
:
11430 case elfcpp::R_POWERPC_REL16_HA
:
11431 case elfcpp::R_PPC64_REL16_HIGHA
:
11432 case elfcpp::R_PPC64_TOC16_HA
:
11433 case elfcpp::R_POWERPC_GOT16_HA
:
11434 case elfcpp::R_POWERPC_PLT16_HA
:
11435 case elfcpp::R_POWERPC_SECTOFF_HA
:
11436 case elfcpp::R_POWERPC_TPREL16_HA
:
11437 case elfcpp::R_POWERPC_DTPREL16_HA
:
11438 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11439 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11440 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11441 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11442 Reloc::addr16_ha(view
, value
);
11445 case elfcpp::R_POWERPC_REL16DX_HA
:
11446 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11449 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11451 // R_PPC_EMB_NADDR16_LO
11454 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11455 case elfcpp::R_PPC64_REL16_HIGHER
:
11456 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11457 Reloc::addr16_hi2(view
, value
);
11460 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11462 // R_PPC_EMB_NADDR16_HI
11465 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11466 case elfcpp::R_PPC64_REL16_HIGHERA
:
11467 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11468 Reloc::addr16_ha2(view
, value
);
11471 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11473 // R_PPC_EMB_NADDR16_HA
11476 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11477 case elfcpp::R_PPC64_REL16_HIGHEST
:
11478 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11479 Reloc::addr16_hi3(view
, value
);
11482 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11484 // R_PPC_EMB_SDAI16
11487 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11488 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11489 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11490 Reloc::addr16_ha3(view
, value
);
11493 case elfcpp::R_PPC64_DTPREL16_DS
:
11494 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11496 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11499 case elfcpp::R_PPC64_TPREL16_DS
:
11500 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11502 // R_PPC_TLSGD, R_PPC_TLSLD
11505 case elfcpp::R_PPC64_ADDR16_DS
:
11506 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11507 case elfcpp::R_PPC64_TOC16_DS
:
11508 case elfcpp::R_PPC64_TOC16_LO_DS
:
11509 case elfcpp::R_PPC64_GOT16_DS
:
11510 case elfcpp::R_PPC64_GOT16_LO_DS
:
11511 case elfcpp::R_PPC64_PLT16_LO_DS
:
11512 case elfcpp::R_PPC64_SECTOFF_DS
:
11513 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11514 maybe_dq_reloc
= true;
11517 case elfcpp::R_POWERPC_ADDR14
:
11518 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11519 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11520 case elfcpp::R_POWERPC_REL14
:
11521 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11522 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11523 status
= Reloc::addr14(view
, value
, overflow
);
11526 case elfcpp::R_POWERPC_COPY
:
11527 case elfcpp::R_POWERPC_GLOB_DAT
:
11528 case elfcpp::R_POWERPC_JMP_SLOT
:
11529 case elfcpp::R_POWERPC_RELATIVE
:
11530 case elfcpp::R_POWERPC_DTPMOD
:
11531 case elfcpp::R_PPC64_JMP_IREL
:
11532 case elfcpp::R_POWERPC_IRELATIVE
:
11533 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11534 _("unexpected reloc %u in object file"),
11538 case elfcpp::R_PPC64_TOCSAVE
:
11544 Symbol_location loc
;
11545 loc
.object
= relinfo
->object
;
11546 loc
.shndx
= relinfo
->data_shndx
;
11547 loc
.offset
= rela
.get_r_offset();
11548 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11549 if (p
!= target
->tocsave_loc().end())
11551 // If we've generated plt calls using this tocsave, then
11552 // the nop needs to be changed to save r2.
11553 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11554 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11555 elfcpp::Swap
<32, big_endian
>::
11556 writeval(iview
, std_2_1
+ target
->stk_toc());
11561 case elfcpp::R_PPC_EMB_SDA2I16
:
11562 case elfcpp::R_PPC_EMB_SDA2REL
:
11565 // R_PPC64_TLSGD, R_PPC64_TLSLD
11568 case elfcpp::R_PPC64_D34
:
11569 case elfcpp::R_PPC64_D34_LO
:
11570 case elfcpp::R_PPC64_PCREL34
:
11571 case elfcpp::R_PPC64_GOT_PCREL34
:
11572 case elfcpp::R_PPC64_PLT_PCREL34
:
11573 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11574 case elfcpp::R_PPC64_TPREL34
:
11575 case elfcpp::R_PPC64_DTPREL34
:
11576 case elfcpp::R_PPC64_GOT_TLSGD34
:
11577 case elfcpp::R_PPC64_GOT_TLSLD34
:
11578 case elfcpp::R_PPC64_GOT_TPREL34
:
11579 case elfcpp::R_PPC64_GOT_DTPREL34
:
11582 status
= Reloc::addr34(view
, value
, overflow
);
11585 case elfcpp::R_PPC64_D34_HI30
:
11588 Reloc::addr34_hi(view
, value
);
11591 case elfcpp::R_PPC64_D34_HA30
:
11594 Reloc::addr34_ha(view
, value
);
11597 case elfcpp::R_PPC64_D28
:
11598 case elfcpp::R_PPC64_PCREL28
:
11601 status
= Reloc::addr28(view
, value
, overflow
);
11604 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11605 case elfcpp::R_PPC64_REL16_HIGHER34
:
11608 Reloc::addr16_higher34(view
, value
);
11611 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11612 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11615 Reloc::addr16_highera34(view
, value
);
11618 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11619 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11622 Reloc::addr16_highest34(view
, value
);
11625 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
11626 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11629 Reloc::addr16_highesta34(view
, value
);
11632 case elfcpp::R_POWERPC_PLT32
:
11633 case elfcpp::R_POWERPC_PLTREL32
:
11634 case elfcpp::R_PPC_SDAREL16
:
11635 case elfcpp::R_POWERPC_ADDR30
:
11636 case elfcpp::R_PPC64_PLT64
:
11637 case elfcpp::R_PPC64_PLTREL64
:
11638 case elfcpp::R_PPC64_PLTGOT16
:
11639 case elfcpp::R_PPC64_PLTGOT16_LO
:
11640 case elfcpp::R_PPC64_PLTGOT16_HI
:
11641 case elfcpp::R_PPC64_PLTGOT16_HA
:
11642 case elfcpp::R_PPC64_PLTGOT16_DS
:
11643 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
11644 case elfcpp::R_PPC_TOC16
:
11647 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11648 _("unsupported reloc %u"),
11653 if (maybe_dq_reloc
)
11656 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11658 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
11659 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
11660 && (insn
& 3) == 1))
11661 status
= Reloc::addr16_dq(view
, value
, overflow
);
11662 else if (size
== 64
11663 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
11664 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
11665 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
11666 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
11667 status
= Reloc::addr16_ds(view
, value
, overflow
);
11669 status
= Reloc::addr16(view
, value
, overflow
);
11672 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
11675 && gsym
->is_undefined()
11676 && is_branch_reloc
<size
>(r_type
))))
11678 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11679 _("relocation overflow"));
11680 if (has_stub_value
)
11681 gold_info(_("try relinking with a smaller --stub-group-size"));
11687 // Relocate section data.
11689 template<int size
, bool big_endian
>
11691 Target_powerpc
<size
, big_endian
>::relocate_section(
11692 const Relocate_info
<size
, big_endian
>* relinfo
,
11693 unsigned int sh_type
,
11694 const unsigned char* prelocs
,
11695 size_t reloc_count
,
11696 Output_section
* output_section
,
11697 bool needs_special_offset_handling
,
11698 unsigned char* view
,
11700 section_size_type view_size
,
11701 const Reloc_symbol_changes
* reloc_symbol_changes
)
11703 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
11704 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
11705 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
11706 Powerpc_comdat_behavior
;
11707 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11710 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11712 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
11713 Powerpc_comdat_behavior
, Classify_reloc
>(
11719 needs_special_offset_handling
,
11723 reloc_symbol_changes
);
11726 template<int size
, bool big_endian
>
11727 class Powerpc_scan_relocatable_reloc
11730 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11731 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11732 static const int sh_type
= elfcpp::SHT_RELA
;
11734 // Return the symbol referred to by the relocation.
11735 static inline unsigned int
11736 get_r_sym(const Reltype
* reloc
)
11737 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
11739 // Return the type of the relocation.
11740 static inline unsigned int
11741 get_r_type(const Reltype
* reloc
)
11742 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
11744 // Return the strategy to use for a local symbol which is not a
11745 // section symbol, given the relocation type.
11746 inline Relocatable_relocs::Reloc_strategy
11747 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
11749 if (r_type
== 0 && r_sym
== 0)
11750 return Relocatable_relocs::RELOC_DISCARD
;
11751 return Relocatable_relocs::RELOC_COPY
;
11754 // Return the strategy to use for a local symbol which is a section
11755 // symbol, given the relocation type.
11756 inline Relocatable_relocs::Reloc_strategy
11757 local_section_strategy(unsigned int, Relobj
*)
11759 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
11762 // Return the strategy to use for a global symbol, given the
11763 // relocation type, the object, and the symbol index.
11764 inline Relocatable_relocs::Reloc_strategy
11765 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
11768 && (r_type
== elfcpp::R_PPC_PLTREL24
11769 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11770 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11771 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
11772 return Relocatable_relocs::RELOC_SPECIAL
;
11773 return Relocatable_relocs::RELOC_COPY
;
11777 // Scan the relocs during a relocatable link.
11779 template<int size
, bool big_endian
>
11781 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
11782 Symbol_table
* symtab
,
11784 Sized_relobj_file
<size
, big_endian
>* object
,
11785 unsigned int data_shndx
,
11786 unsigned int sh_type
,
11787 const unsigned char* prelocs
,
11788 size_t reloc_count
,
11789 Output_section
* output_section
,
11790 bool needs_special_offset_handling
,
11791 size_t local_symbol_count
,
11792 const unsigned char* plocal_symbols
,
11793 Relocatable_relocs
* rr
)
11795 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
11797 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11799 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
11807 needs_special_offset_handling
,
11808 local_symbol_count
,
11813 // Scan the relocs for --emit-relocs.
11815 template<int size
, bool big_endian
>
11817 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
11818 Symbol_table
* symtab
,
11820 Sized_relobj_file
<size
, big_endian
>* object
,
11821 unsigned int data_shndx
,
11822 unsigned int sh_type
,
11823 const unsigned char* prelocs
,
11824 size_t reloc_count
,
11825 Output_section
* output_section
,
11826 bool needs_special_offset_handling
,
11827 size_t local_symbol_count
,
11828 const unsigned char* plocal_syms
,
11829 Relocatable_relocs
* rr
)
11831 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11833 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
11834 Emit_relocs_strategy
;
11836 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11838 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
11846 needs_special_offset_handling
,
11847 local_symbol_count
,
11852 // Emit relocations for a section.
11853 // This is a modified version of the function by the same name in
11854 // target-reloc.h. Using relocate_special_relocatable for
11855 // R_PPC_PLTREL24 would require duplication of the entire body of the
11856 // loop, so we may as well duplicate the whole thing.
11858 template<int size
, bool big_endian
>
11860 Target_powerpc
<size
, big_endian
>::relocate_relocs(
11861 const Relocate_info
<size
, big_endian
>* relinfo
,
11862 unsigned int sh_type
,
11863 const unsigned char* prelocs
,
11864 size_t reloc_count
,
11865 Output_section
* output_section
,
11866 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
11868 Address view_address
,
11870 unsigned char* reloc_view
,
11871 section_size_type reloc_view_size
)
11873 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11875 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11876 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
11877 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11878 // Offset from start of insn to d-field reloc.
11879 const int d_offset
= big_endian
? 2 : 0;
11881 Powerpc_relobj
<size
, big_endian
>* const object
11882 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
11883 const unsigned int local_count
= object
->local_symbol_count();
11884 unsigned int got2_shndx
= object
->got2_shndx();
11885 Address got2_addend
= 0;
11886 if (got2_shndx
!= 0)
11888 got2_addend
= object
->get_output_section_offset(got2_shndx
);
11889 gold_assert(got2_addend
!= invalid_address
);
11892 const bool relocatable
= parameters
->options().relocatable();
11894 unsigned char* pwrite
= reloc_view
;
11895 bool zap_next
= false;
11896 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
11898 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
11899 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
11902 Reltype
reloc(prelocs
);
11903 Reltype_write
reloc_write(pwrite
);
11905 Address offset
= reloc
.get_r_offset();
11906 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
11907 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
11908 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
11909 const unsigned int orig_r_sym
= r_sym
;
11910 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
11911 = reloc
.get_r_addend();
11912 const Symbol
* gsym
= NULL
;
11916 // We could arrange to discard these and other relocs for
11917 // tls optimised sequences in the strategy methods, but for
11918 // now do as BFD ld does.
11919 r_type
= elfcpp::R_POWERPC_NONE
;
11923 // Get the new symbol index.
11924 Output_section
* os
= NULL
;
11925 if (r_sym
< local_count
)
11929 case Relocatable_relocs::RELOC_COPY
:
11930 case Relocatable_relocs::RELOC_SPECIAL
:
11933 r_sym
= object
->symtab_index(r_sym
);
11934 gold_assert(r_sym
!= -1U);
11938 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
11940 // We are adjusting a section symbol. We need to find
11941 // the symbol table index of the section symbol for
11942 // the output section corresponding to input section
11943 // in which this symbol is defined.
11944 gold_assert(r_sym
< local_count
);
11946 unsigned int shndx
=
11947 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
11948 gold_assert(is_ordinary
);
11949 os
= object
->output_section(shndx
);
11950 gold_assert(os
!= NULL
);
11951 gold_assert(os
->needs_symtab_index());
11952 r_sym
= os
->symtab_index();
11957 gold_unreachable();
11962 gsym
= object
->global_symbol(r_sym
);
11963 gold_assert(gsym
!= NULL
);
11964 if (gsym
->is_forwarder())
11965 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
11967 gold_assert(gsym
->has_symtab_index());
11968 r_sym
= gsym
->symtab_index();
11971 // Get the new offset--the location in the output section where
11972 // this relocation should be applied.
11973 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11974 offset
+= offset_in_output_section
;
11977 section_offset_type sot_offset
=
11978 convert_types
<section_offset_type
, Address
>(offset
);
11979 section_offset_type new_sot_offset
=
11980 output_section
->output_offset(object
, relinfo
->data_shndx
,
11982 gold_assert(new_sot_offset
!= -1);
11983 offset
= new_sot_offset
;
11986 // In an object file, r_offset is an offset within the section.
11987 // In an executable or dynamic object, generated by
11988 // --emit-relocs, r_offset is an absolute address.
11991 offset
+= view_address
;
11992 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11993 offset
-= offset_in_output_section
;
11996 // Handle the reloc addend based on the strategy.
11997 if (strategy
== Relocatable_relocs::RELOC_COPY
)
11999 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
12001 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
12002 addend
= psymval
->value(object
, addend
);
12003 // In a relocatable link, the symbol value is relative to
12004 // the start of the output section. For a non-relocatable
12005 // link, we need to adjust the addend.
12008 gold_assert(os
!= NULL
);
12009 addend
-= os
->address();
12012 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
12016 if (addend
>= 32768)
12017 addend
+= got2_addend
;
12019 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
12021 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
12022 addend
-= d_offset
;
12024 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
12026 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
12027 addend
-= d_offset
+ 4;
12031 gold_unreachable();
12035 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12036 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
12037 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
12038 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
12040 // First instruction of a global dynamic sequence,
12042 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12043 switch (this->optimize_tls_gd(final
))
12045 case tls::TLSOPT_TO_IE
:
12046 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
12047 - elfcpp::R_POWERPC_GOT_TLSGD16
);
12049 case tls::TLSOPT_TO_LE
:
12050 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
12051 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
12052 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12055 r_type
= elfcpp::R_POWERPC_NONE
;
12056 offset
-= d_offset
;
12063 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12064 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
12065 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
12066 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
12068 // First instruction of a local dynamic sequence,
12070 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12072 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
12073 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
12075 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12076 const Output_section
* os
= relinfo
->layout
->tls_segment()
12078 gold_assert(os
!= NULL
);
12079 gold_assert(os
->needs_symtab_index());
12080 r_sym
= os
->symtab_index();
12081 addend
= dtp_offset
;
12085 r_type
= elfcpp::R_POWERPC_NONE
;
12086 offset
-= d_offset
;
12090 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12091 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
12092 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
12093 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
12095 // First instruction of initial exec sequence.
12096 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12097 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12099 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
12100 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
12101 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
12104 r_type
= elfcpp::R_POWERPC_NONE
;
12105 offset
-= d_offset
;
12109 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
12110 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
12112 // Second instruction of a global dynamic sequence,
12113 // the __tls_get_addr call
12114 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12115 switch (this->optimize_tls_gd(final
))
12117 case tls::TLSOPT_TO_IE
:
12118 r_type
= elfcpp::R_POWERPC_NONE
;
12121 case tls::TLSOPT_TO_LE
:
12122 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12123 offset
+= d_offset
;
12130 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
12131 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
12133 // Second instruction of a local dynamic sequence,
12134 // the __tls_get_addr call
12135 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
12137 const Output_section
* os
= relinfo
->layout
->tls_segment()
12139 gold_assert(os
!= NULL
);
12140 gold_assert(os
->needs_symtab_index());
12141 r_sym
= os
->symtab_index();
12142 addend
= dtp_offset
;
12143 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12144 offset
+= d_offset
;
12148 else if (r_type
== elfcpp::R_POWERPC_TLS
)
12150 // Second instruction of an initial exec sequence
12151 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
12152 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
12154 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
12155 offset
+= d_offset
;
12160 reloc_write
.put_r_offset(offset
);
12161 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
12162 reloc_write
.put_r_addend(addend
);
12164 pwrite
+= reloc_size
;
12167 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
12168 == reloc_view_size
);
12171 // Return the value to use for a dynamic symbol which requires special
12172 // treatment. This is how we support equality comparisons of function
12173 // pointers across shared library boundaries, as described in the
12174 // processor specific ABI supplement.
12176 template<int size
, bool big_endian
>
12178 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
12182 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
12183 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12184 p
!= this->stub_tables_
.end();
12187 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12188 = (*p
)->find_plt_call_entry(gsym
);
12190 return (*p
)->stub_address() + ent
->off_
;
12193 else if (this->abiversion() >= 2)
12195 Address off
= this->glink_section()->find_global_entry(gsym
);
12196 if (off
!= invalid_address
)
12197 return this->glink_section()->global_entry_address() + off
;
12199 gold_unreachable();
12202 // Return the PLT address to use for a local symbol.
12203 template<int size
, bool big_endian
>
12205 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
12206 const Relobj
* object
,
12207 unsigned int symndx
) const
12211 const Sized_relobj
<size
, big_endian
>* relobj
12212 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
12213 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12214 p
!= this->stub_tables_
.end();
12217 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12218 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
12220 return (*p
)->stub_address() + ent
->off_
;
12223 gold_unreachable();
12226 // Return the PLT address to use for a global symbol.
12227 template<int size
, bool big_endian
>
12229 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
12230 const Symbol
* gsym
) const
12234 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
12235 p
!= this->stub_tables_
.end();
12238 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
12239 = (*p
)->find_plt_call_entry(gsym
);
12241 return (*p
)->stub_address() + ent
->off_
;
12244 else if (this->abiversion() >= 2)
12246 Address off
= this->glink_section()->find_global_entry(gsym
);
12247 if (off
!= invalid_address
)
12248 return this->glink_section()->global_entry_address() + off
;
12250 gold_unreachable();
12253 // Return the offset to use for the GOT_INDX'th got entry which is
12254 // for a local tls symbol specified by OBJECT, SYMNDX.
12255 template<int size
, bool big_endian
>
12257 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
12258 const Relobj
* object
,
12259 unsigned int symndx
,
12260 unsigned int got_indx
) const
12262 const Powerpc_relobj
<size
, big_endian
>* ppc_object
12263 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
12264 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
12266 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12267 got_type
<= GOT_TYPE_TPREL
;
12268 got_type
= Got_type(got_type
+ 1))
12269 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12271 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12272 if (got_type
== GOT_TYPE_TLSGD
)
12274 if (off
== got_indx
* (size
/ 8))
12276 if (got_type
== GOT_TYPE_TPREL
)
12279 return -dtp_offset
;
12283 gold_unreachable();
12286 // Return the offset to use for the GOT_INDX'th got entry which is
12287 // for global tls symbol GSYM.
12288 template<int size
, bool big_endian
>
12290 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12292 unsigned int got_indx
) const
12294 if (gsym
->type() == elfcpp::STT_TLS
)
12296 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12297 got_type
<= GOT_TYPE_TPREL
;
12298 got_type
= Got_type(got_type
+ 1))
12299 if (gsym
->has_got_offset(got_type
))
12301 unsigned int off
= gsym
->got_offset(got_type
);
12302 if (got_type
== GOT_TYPE_TLSGD
)
12304 if (off
== got_indx
* (size
/ 8))
12306 if (got_type
== GOT_TYPE_TPREL
)
12309 return -dtp_offset
;
12313 gold_unreachable();
12316 // The selector for powerpc object files.
12318 template<int size
, bool big_endian
>
12319 class Target_selector_powerpc
: public Target_selector
12322 Target_selector_powerpc()
12323 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12326 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12327 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12329 ? (big_endian
? "elf64ppc" : "elf64lppc")
12330 : (big_endian
? "elf32ppc" : "elf32lppc")))
12334 do_instantiate_target()
12335 { return new Target_powerpc
<size
, big_endian
>(); }
12338 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12339 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12340 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12341 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12343 // Instantiate these constants for -O0
12344 template<int size
, bool big_endian
>
12345 const typename Output_data_glink
<size
, big_endian
>::Address
12346 Output_data_glink
<size
, big_endian
>::invalid_address
;
12347 template<int size
, bool big_endian
>
12348 const typename Stub_table
<size
, big_endian
>::Address
12349 Stub_table
<size
, big_endian
>::invalid_address
;
12350 template<int size
, bool big_endian
>
12351 const typename Target_powerpc
<size
, big_endian
>::Address
12352 Target_powerpc
<size
, big_endian
>::invalid_address
;
12354 } // End anonymous namespace.