1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2019 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 ref
= Symbol::ABSOLUTE_REF
;
7211 case elfcpp::R_POWERPC_ADDR24
:
7212 case elfcpp::R_POWERPC_ADDR14
:
7213 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7214 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7215 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7218 case elfcpp::R_PPC64_REL64
:
7219 case elfcpp::R_POWERPC_REL32
:
7220 case elfcpp::R_PPC_LOCAL24PC
:
7221 case elfcpp::R_POWERPC_REL16
:
7222 case elfcpp::R_POWERPC_REL16_LO
:
7223 case elfcpp::R_POWERPC_REL16_HI
:
7224 case elfcpp::R_POWERPC_REL16_HA
:
7225 case elfcpp::R_PPC64_REL16_HIGH
:
7226 case elfcpp::R_PPC64_REL16_HIGHA
:
7227 case elfcpp::R_PPC64_REL16_HIGHER
:
7228 case elfcpp::R_PPC64_REL16_HIGHERA
:
7229 case elfcpp::R_PPC64_REL16_HIGHEST
:
7230 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7231 case elfcpp::R_PPC64_PCREL34
:
7232 case elfcpp::R_PPC64_REL16_HIGHER34
:
7233 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7234 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7235 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7236 case elfcpp::R_PPC64_PCREL28
:
7237 ref
= Symbol::RELATIVE_REF
;
7240 case elfcpp::R_PPC64_REL24_NOTOC
:
7244 case elfcpp::R_POWERPC_REL24
:
7245 case elfcpp::R_PPC_PLTREL24
:
7246 case elfcpp::R_POWERPC_REL14
:
7247 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7248 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7249 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7252 case elfcpp::R_POWERPC_GOT16
:
7253 case elfcpp::R_POWERPC_GOT16_LO
:
7254 case elfcpp::R_POWERPC_GOT16_HI
:
7255 case elfcpp::R_POWERPC_GOT16_HA
:
7256 case elfcpp::R_PPC64_GOT16_DS
:
7257 case elfcpp::R_PPC64_GOT16_LO_DS
:
7258 case elfcpp::R_PPC64_GOT_PCREL34
:
7259 case elfcpp::R_PPC64_TOC16
:
7260 case elfcpp::R_PPC64_TOC16_LO
:
7261 case elfcpp::R_PPC64_TOC16_HI
:
7262 case elfcpp::R_PPC64_TOC16_HA
:
7263 case elfcpp::R_PPC64_TOC16_DS
:
7264 case elfcpp::R_PPC64_TOC16_LO_DS
:
7265 case elfcpp::R_POWERPC_PLT16_LO
:
7266 case elfcpp::R_POWERPC_PLT16_HI
:
7267 case elfcpp::R_POWERPC_PLT16_HA
:
7268 case elfcpp::R_PPC64_PLT16_LO_DS
:
7269 case elfcpp::R_PPC64_PLT_PCREL34
:
7270 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7271 ref
= Symbol::RELATIVE_REF
;
7274 case elfcpp::R_POWERPC_GOT_TPREL16
:
7275 case elfcpp::R_POWERPC_TLS
:
7276 ref
= Symbol::TLS_REF
;
7279 case elfcpp::R_POWERPC_COPY
:
7280 case elfcpp::R_POWERPC_GLOB_DAT
:
7281 case elfcpp::R_POWERPC_JMP_SLOT
:
7282 case elfcpp::R_POWERPC_RELATIVE
:
7283 case elfcpp::R_POWERPC_DTPMOD
:
7285 // Not expected. We will give an error later.
7289 if (size
== 64 && target
->abiversion() < 2)
7290 ref
|= Symbol::FUNC_DESC_ABI
;
7294 // Report an unsupported relocation against a local symbol.
7296 template<int size
, bool big_endian
>
7298 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7299 Sized_relobj_file
<size
, big_endian
>* object
,
7300 unsigned int r_type
)
7302 gold_error(_("%s: unsupported reloc %u against local symbol"),
7303 object
->name().c_str(), r_type
);
7306 // We are about to emit a dynamic relocation of type R_TYPE. If the
7307 // dynamic linker does not support it, issue an error.
7309 template<int size
, bool big_endian
>
7311 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7312 unsigned int r_type
)
7314 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7316 // These are the relocation types supported by glibc for both 32-bit
7317 // and 64-bit powerpc.
7320 case elfcpp::R_POWERPC_NONE
:
7321 case elfcpp::R_POWERPC_RELATIVE
:
7322 case elfcpp::R_POWERPC_GLOB_DAT
:
7323 case elfcpp::R_POWERPC_DTPMOD
:
7324 case elfcpp::R_POWERPC_DTPREL
:
7325 case elfcpp::R_POWERPC_TPREL
:
7326 case elfcpp::R_POWERPC_JMP_SLOT
:
7327 case elfcpp::R_POWERPC_COPY
:
7328 case elfcpp::R_POWERPC_IRELATIVE
:
7329 case elfcpp::R_POWERPC_ADDR32
:
7330 case elfcpp::R_POWERPC_UADDR32
:
7331 case elfcpp::R_POWERPC_ADDR24
:
7332 case elfcpp::R_POWERPC_ADDR16
:
7333 case elfcpp::R_POWERPC_UADDR16
:
7334 case elfcpp::R_POWERPC_ADDR16_LO
:
7335 case elfcpp::R_POWERPC_ADDR16_HI
:
7336 case elfcpp::R_POWERPC_ADDR16_HA
:
7337 case elfcpp::R_POWERPC_ADDR14
:
7338 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7339 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7340 case elfcpp::R_POWERPC_REL32
:
7341 case elfcpp::R_POWERPC_REL24
:
7342 case elfcpp::R_POWERPC_TPREL16
:
7343 case elfcpp::R_POWERPC_TPREL16_LO
:
7344 case elfcpp::R_POWERPC_TPREL16_HI
:
7345 case elfcpp::R_POWERPC_TPREL16_HA
:
7356 // These are the relocation types supported only on 64-bit.
7357 case elfcpp::R_PPC64_ADDR64
:
7358 case elfcpp::R_PPC64_UADDR64
:
7359 case elfcpp::R_PPC64_JMP_IREL
:
7360 case elfcpp::R_PPC64_ADDR16_DS
:
7361 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7362 case elfcpp::R_PPC64_ADDR16_HIGH
:
7363 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7364 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7365 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7366 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7367 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7368 case elfcpp::R_PPC64_REL64
:
7369 case elfcpp::R_POWERPC_ADDR30
:
7370 case elfcpp::R_PPC64_TPREL16_DS
:
7371 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7372 case elfcpp::R_PPC64_TPREL16_HIGH
:
7373 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7374 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7375 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7376 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7377 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7388 // These are the relocation types supported only on 32-bit.
7389 // ??? glibc ld.so doesn't need to support these.
7390 case elfcpp::R_POWERPC_DTPREL16
:
7391 case elfcpp::R_POWERPC_DTPREL16_LO
:
7392 case elfcpp::R_POWERPC_DTPREL16_HI
:
7393 case elfcpp::R_POWERPC_DTPREL16_HA
:
7401 // This prevents us from issuing more than one error per reloc
7402 // section. But we can still wind up issuing more than one
7403 // error per object file.
7404 if (this->issued_non_pic_error_
)
7406 gold_assert(parameters
->options().output_is_position_independent());
7407 object
->error(_("requires unsupported dynamic reloc; "
7408 "recompile with -fPIC"));
7409 this->issued_non_pic_error_
= true;
7413 // Return whether we need to make a PLT entry for a relocation of the
7414 // given type against a STT_GNU_IFUNC symbol.
7416 template<int size
, bool big_endian
>
7418 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7419 Target_powerpc
<size
, big_endian
>* target
,
7420 Sized_relobj_file
<size
, big_endian
>* object
,
7421 unsigned int r_type
,
7424 // In non-pic code any reference will resolve to the plt call stub
7425 // for the ifunc symbol.
7426 if ((size
== 32 || target
->abiversion() >= 2)
7427 && !parameters
->options().output_is_position_independent())
7432 // Word size refs from data sections are OK, but don't need a PLT entry.
7433 case elfcpp::R_POWERPC_ADDR32
:
7434 case elfcpp::R_POWERPC_UADDR32
:
7439 case elfcpp::R_PPC64_ADDR64
:
7440 case elfcpp::R_PPC64_UADDR64
:
7445 // GOT refs are good, but also don't need a PLT entry.
7446 case elfcpp::R_POWERPC_GOT16
:
7447 case elfcpp::R_POWERPC_GOT16_LO
:
7448 case elfcpp::R_POWERPC_GOT16_HI
:
7449 case elfcpp::R_POWERPC_GOT16_HA
:
7450 case elfcpp::R_PPC64_GOT16_DS
:
7451 case elfcpp::R_PPC64_GOT16_LO_DS
:
7452 case elfcpp::R_PPC64_GOT_PCREL34
:
7455 // PLT relocs are OK and need a PLT entry.
7456 case elfcpp::R_POWERPC_PLT16_LO
:
7457 case elfcpp::R_POWERPC_PLT16_HI
:
7458 case elfcpp::R_POWERPC_PLT16_HA
:
7459 case elfcpp::R_PPC64_PLT16_LO_DS
:
7460 case elfcpp::R_POWERPC_PLTSEQ
:
7461 case elfcpp::R_POWERPC_PLTCALL
:
7462 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7463 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7464 case elfcpp::R_PPC64_PLT_PCREL34
:
7465 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7469 // Function calls are good, and these do need a PLT entry.
7470 case elfcpp::R_PPC64_REL24_NOTOC
:
7474 case elfcpp::R_POWERPC_ADDR24
:
7475 case elfcpp::R_POWERPC_ADDR14
:
7476 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7477 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7478 case elfcpp::R_POWERPC_REL24
:
7479 case elfcpp::R_PPC_PLTREL24
:
7480 case elfcpp::R_POWERPC_REL14
:
7481 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7482 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7489 // Anything else is a problem.
7490 // If we are building a static executable, the libc startup function
7491 // responsible for applying indirect function relocations is going
7492 // to complain about the reloc type.
7493 // If we are building a dynamic executable, we will have a text
7494 // relocation. The dynamic loader will set the text segment
7495 // writable and non-executable to apply text relocations. So we'll
7496 // segfault when trying to run the indirection function to resolve
7499 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7500 object
->name().c_str(), r_type
);
7504 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7508 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7510 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7511 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7512 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7513 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7514 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7515 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7516 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7517 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7518 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7519 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7520 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7521 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7522 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7523 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7524 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7525 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7526 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7527 /* Exclude lfqu by testing reloc. If relocs are ever
7528 defined for the reduced D field in psq_lu then those
7529 will need testing too. */
7530 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7531 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7532 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7534 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7535 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7536 /* Exclude stfqu. psq_stu as above for psq_lu. */
7537 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7538 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7539 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7540 && (insn
& 1) == 0));
7543 // Scan a relocation for a local symbol.
7545 template<int size
, bool big_endian
>
7547 Target_powerpc
<size
, big_endian
>::Scan::local(
7548 Symbol_table
* symtab
,
7550 Target_powerpc
<size
, big_endian
>* target
,
7551 Sized_relobj_file
<size
, big_endian
>* object
,
7552 unsigned int data_shndx
,
7553 Output_section
* output_section
,
7554 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7555 unsigned int r_type
,
7556 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7559 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7561 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7562 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7564 this->expect_tls_get_addr_call();
7565 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7566 if (tls_type
!= tls::TLSOPT_NONE
)
7567 this->skip_next_tls_get_addr_call();
7569 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7570 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7572 this->expect_tls_get_addr_call();
7573 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7574 if (tls_type
!= tls::TLSOPT_NONE
)
7575 this->skip_next_tls_get_addr_call();
7578 Powerpc_relobj
<size
, big_endian
>* ppc_object
7579 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7584 && data_shndx
== ppc_object
->opd_shndx()
7585 && r_type
== elfcpp::R_PPC64_ADDR64
)
7586 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7590 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7591 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7592 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7594 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7595 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7596 r_type
, r_sym
, reloc
.get_r_addend());
7597 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7602 case elfcpp::R_POWERPC_NONE
:
7603 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7604 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7605 case elfcpp::R_POWERPC_TLS
:
7606 case elfcpp::R_PPC64_ENTRY
:
7607 case elfcpp::R_POWERPC_PLTSEQ
:
7608 case elfcpp::R_POWERPC_PLTCALL
:
7609 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7610 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7611 case elfcpp::R_PPC64_PCREL_OPT
:
7612 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7613 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7614 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7615 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7616 case elfcpp::R_PPC64_REL16_HIGHER34
:
7617 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7618 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7619 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7622 case elfcpp::R_PPC64_D34
:
7623 case elfcpp::R_PPC64_D34_LO
:
7624 case elfcpp::R_PPC64_D34_HI30
:
7625 case elfcpp::R_PPC64_D34_HA30
:
7626 case elfcpp::R_PPC64_D28
:
7627 case elfcpp::R_PPC64_PCREL34
:
7628 case elfcpp::R_PPC64_PCREL28
:
7629 target
->set_powerxx_stubs();
7632 case elfcpp::R_PPC64_TOC
:
7634 Output_data_got_powerpc
<size
, big_endian
>* got
7635 = target
->got_section(symtab
, layout
);
7636 if (parameters
->options().output_is_position_independent())
7638 Address off
= reloc
.get_r_offset();
7640 && target
->abiversion() < 2
7641 && data_shndx
== ppc_object
->opd_shndx()
7642 && ppc_object
->get_opd_discard(off
- 8))
7645 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7646 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7647 rela_dyn
->add_output_section_relative(got
->output_section(),
7648 elfcpp::R_POWERPC_RELATIVE
,
7650 object
, data_shndx
, off
,
7651 symobj
->toc_base_offset());
7656 case elfcpp::R_PPC64_ADDR64
:
7657 case elfcpp::R_PPC64_UADDR64
:
7658 case elfcpp::R_POWERPC_ADDR32
:
7659 case elfcpp::R_POWERPC_UADDR32
:
7660 case elfcpp::R_POWERPC_ADDR24
:
7661 case elfcpp::R_POWERPC_ADDR16
:
7662 case elfcpp::R_POWERPC_ADDR16_LO
:
7663 case elfcpp::R_POWERPC_ADDR16_HI
:
7664 case elfcpp::R_POWERPC_ADDR16_HA
:
7665 case elfcpp::R_POWERPC_UADDR16
:
7666 case elfcpp::R_PPC64_ADDR16_HIGH
:
7667 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7668 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7669 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7670 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7671 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7672 case elfcpp::R_PPC64_ADDR16_DS
:
7673 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7674 case elfcpp::R_POWERPC_ADDR14
:
7675 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7676 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7677 // If building a shared library (or a position-independent
7678 // executable), we need to create a dynamic relocation for
7680 if (parameters
->options().output_is_position_independent()
7681 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7683 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7685 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7686 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7687 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7689 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7690 : elfcpp::R_POWERPC_RELATIVE
);
7691 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7692 output_section
, data_shndx
,
7693 reloc
.get_r_offset(),
7694 reloc
.get_r_addend(), false);
7696 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7698 check_non_pic(object
, r_type
);
7699 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7700 data_shndx
, reloc
.get_r_offset(),
7701 reloc
.get_r_addend());
7705 gold_assert(lsym
.get_st_value() == 0);
7706 unsigned int shndx
= lsym
.get_st_shndx();
7708 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7711 object
->error(_("section symbol %u has bad shndx %u"),
7714 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7715 output_section
, data_shndx
,
7716 reloc
.get_r_offset());
7721 case elfcpp::R_PPC64_PLT_PCREL34
:
7722 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7723 target
->set_powerxx_stubs();
7725 case elfcpp::R_POWERPC_PLT16_LO
:
7726 case elfcpp::R_POWERPC_PLT16_HI
:
7727 case elfcpp::R_POWERPC_PLT16_HA
:
7728 case elfcpp::R_PPC64_PLT16_LO_DS
:
7731 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7732 target
->make_local_plt_entry(layout
, object
, r_sym
);
7736 case elfcpp::R_PPC64_REL24_NOTOC
:
7740 case elfcpp::R_POWERPC_REL24
:
7741 case elfcpp::R_PPC_PLTREL24
:
7742 case elfcpp::R_PPC_LOCAL24PC
:
7743 case elfcpp::R_POWERPC_REL14
:
7744 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7745 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7748 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7749 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7750 r_type
, r_sym
, reloc
.get_r_addend());
7754 case elfcpp::R_PPC64_TOCSAVE
:
7755 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7756 // caller has already saved r2 and thus a plt call stub need not
7759 && target
->mark_pltcall(ppc_object
, data_shndx
,
7760 reloc
.get_r_offset() - 4, symtab
))
7762 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7763 unsigned int shndx
= lsym
.get_st_shndx();
7765 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7767 object
->error(_("tocsave symbol %u has bad shndx %u"),
7770 target
->add_tocsave(ppc_object
, shndx
,
7771 lsym
.get_st_value() + reloc
.get_r_addend());
7775 case elfcpp::R_PPC64_REL64
:
7776 case elfcpp::R_POWERPC_REL32
:
7777 case elfcpp::R_POWERPC_REL16
:
7778 case elfcpp::R_POWERPC_REL16_LO
:
7779 case elfcpp::R_POWERPC_REL16_HI
:
7780 case elfcpp::R_POWERPC_REL16_HA
:
7781 case elfcpp::R_POWERPC_REL16DX_HA
:
7782 case elfcpp::R_PPC64_REL16_HIGH
:
7783 case elfcpp::R_PPC64_REL16_HIGHA
:
7784 case elfcpp::R_PPC64_REL16_HIGHER
:
7785 case elfcpp::R_PPC64_REL16_HIGHERA
:
7786 case elfcpp::R_PPC64_REL16_HIGHEST
:
7787 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7788 case elfcpp::R_POWERPC_SECTOFF
:
7789 case elfcpp::R_POWERPC_SECTOFF_LO
:
7790 case elfcpp::R_POWERPC_SECTOFF_HI
:
7791 case elfcpp::R_POWERPC_SECTOFF_HA
:
7792 case elfcpp::R_PPC64_SECTOFF_DS
:
7793 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7794 case elfcpp::R_POWERPC_TPREL16
:
7795 case elfcpp::R_POWERPC_TPREL16_LO
:
7796 case elfcpp::R_POWERPC_TPREL16_HI
:
7797 case elfcpp::R_POWERPC_TPREL16_HA
:
7798 case elfcpp::R_PPC64_TPREL16_DS
:
7799 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7800 case elfcpp::R_PPC64_TPREL16_HIGH
:
7801 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7802 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7803 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7804 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7805 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7806 case elfcpp::R_POWERPC_DTPREL16
:
7807 case elfcpp::R_POWERPC_DTPREL16_LO
:
7808 case elfcpp::R_POWERPC_DTPREL16_HI
:
7809 case elfcpp::R_POWERPC_DTPREL16_HA
:
7810 case elfcpp::R_PPC64_DTPREL16_DS
:
7811 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7812 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7813 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7814 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7815 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7816 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7817 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7818 case elfcpp::R_PPC64_TLSGD
:
7819 case elfcpp::R_PPC64_TLSLD
:
7820 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7823 case elfcpp::R_PPC64_GOT_PCREL34
:
7824 target
->set_powerxx_stubs();
7826 case elfcpp::R_POWERPC_GOT16
:
7827 case elfcpp::R_POWERPC_GOT16_LO
:
7828 case elfcpp::R_POWERPC_GOT16_HI
:
7829 case elfcpp::R_POWERPC_GOT16_HA
:
7830 case elfcpp::R_PPC64_GOT16_DS
:
7831 case elfcpp::R_PPC64_GOT16_LO_DS
:
7833 // The symbol requires a GOT entry.
7834 Output_data_got_powerpc
<size
, big_endian
>* got
7835 = target
->got_section(symtab
, layout
);
7836 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7838 if (!parameters
->options().output_is_position_independent())
7841 && (size
== 32 || target
->abiversion() >= 2))
7842 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
7844 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
7846 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
7848 // If we are generating a shared object or a pie, this
7849 // symbol's GOT entry will be set by a dynamic relocation.
7851 off
= got
->add_constant(0);
7852 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
7854 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7856 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7857 : elfcpp::R_POWERPC_RELATIVE
);
7858 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7859 got
, off
, 0, false);
7864 case elfcpp::R_PPC64_TOC16
:
7865 case elfcpp::R_PPC64_TOC16_LO
:
7866 case elfcpp::R_PPC64_TOC16_HI
:
7867 case elfcpp::R_PPC64_TOC16_HA
:
7868 case elfcpp::R_PPC64_TOC16_DS
:
7869 case elfcpp::R_PPC64_TOC16_LO_DS
:
7870 // We need a GOT section.
7871 target
->got_section(symtab
, layout
);
7874 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7875 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7876 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7877 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7879 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7880 if (tls_type
== tls::TLSOPT_NONE
)
7882 Output_data_got_powerpc
<size
, big_endian
>* got
7883 = target
->got_section(symtab
, layout
);
7884 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7885 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7886 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
7887 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
7889 else if (tls_type
== tls::TLSOPT_TO_LE
)
7891 // no GOT relocs needed for Local Exec.
7898 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7899 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7900 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7901 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7903 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7904 if (tls_type
== tls::TLSOPT_NONE
)
7905 target
->tlsld_got_offset(symtab
, layout
, object
);
7906 else if (tls_type
== tls::TLSOPT_TO_LE
)
7908 // no GOT relocs needed for Local Exec.
7909 if (parameters
->options().emit_relocs())
7911 Output_section
* os
= layout
->tls_segment()->first_section();
7912 gold_assert(os
!= NULL
);
7913 os
->set_needs_symtab_index();
7921 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7922 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7923 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7924 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7926 Output_data_got_powerpc
<size
, big_endian
>* got
7927 = target
->got_section(symtab
, layout
);
7928 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7929 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
7933 case elfcpp::R_POWERPC_GOT_TPREL16
:
7934 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7935 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7936 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7938 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
7939 if (tls_type
== tls::TLSOPT_NONE
)
7941 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7942 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
7944 Output_data_got_powerpc
<size
, big_endian
>* got
7945 = target
->got_section(symtab
, layout
);
7946 unsigned int off
= got
->add_constant(0);
7947 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
7949 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7950 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
7951 elfcpp::R_POWERPC_TPREL
,
7955 else if (tls_type
== tls::TLSOPT_TO_LE
)
7957 // no GOT relocs needed for Local Exec.
7965 unsupported_reloc_local(object
, r_type
);
7970 && parameters
->options().toc_optimize())
7972 if (data_shndx
== ppc_object
->toc_shndx())
7975 if (r_type
!= elfcpp::R_PPC64_ADDR64
7976 || (is_ifunc
&& target
->abiversion() < 2))
7978 else if (parameters
->options().output_is_position_independent())
7984 unsigned int shndx
= lsym
.get_st_shndx();
7985 if (shndx
>= elfcpp::SHN_LORESERVE
7986 && shndx
!= elfcpp::SHN_XINDEX
)
7991 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
7994 enum {no_check
, check_lo
, check_ha
} insn_check
;
7998 insn_check
= no_check
;
8001 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8002 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8003 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8004 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8005 case elfcpp::R_POWERPC_GOT16_HA
:
8006 case elfcpp::R_PPC64_TOC16_HA
:
8007 insn_check
= check_ha
;
8010 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8011 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8012 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8013 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8014 case elfcpp::R_POWERPC_GOT16_LO
:
8015 case elfcpp::R_PPC64_GOT16_LO_DS
:
8016 case elfcpp::R_PPC64_TOC16_LO
:
8017 case elfcpp::R_PPC64_TOC16_LO_DS
:
8018 insn_check
= check_lo
;
8022 section_size_type slen
;
8023 const unsigned char* view
= NULL
;
8024 if (insn_check
!= no_check
)
8026 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8027 section_size_type off
=
8028 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8031 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8032 if (insn_check
== check_lo
8033 ? !ok_lo_toc_insn(insn
, r_type
)
8034 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8035 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8037 ppc_object
->set_no_toc_opt();
8038 gold_warning(_("%s: toc optimization is not supported "
8039 "for %#08x instruction"),
8040 ppc_object
->name().c_str(), insn
);
8049 case elfcpp::R_PPC64_TOC16
:
8050 case elfcpp::R_PPC64_TOC16_LO
:
8051 case elfcpp::R_PPC64_TOC16_HI
:
8052 case elfcpp::R_PPC64_TOC16_HA
:
8053 case elfcpp::R_PPC64_TOC16_DS
:
8054 case elfcpp::R_PPC64_TOC16_LO_DS
:
8055 unsigned int shndx
= lsym
.get_st_shndx();
8056 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8058 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8059 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8061 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8062 if (dst_off
< ppc_object
->section_size(shndx
))
8065 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8067 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8069 // Need to check that the insn is a ld
8071 view
= ppc_object
->section_contents(data_shndx
,
8074 section_size_type off
=
8075 (convert_to_section_size_type(reloc
.get_r_offset())
8076 + (big_endian
? -2 : 3));
8078 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8082 ppc_object
->set_no_toc_opt(dst_off
);
8093 case elfcpp::R_POWERPC_REL32
:
8094 if (ppc_object
->got2_shndx() != 0
8095 && parameters
->options().output_is_position_independent())
8097 unsigned int shndx
= lsym
.get_st_shndx();
8098 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8100 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8101 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8102 && (ppc_object
->section_flags(data_shndx
)
8103 & elfcpp::SHF_EXECINSTR
) != 0)
8104 gold_error(_("%s: unsupported -mbss-plt code"),
8105 ppc_object
->name().c_str());
8115 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8116 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8117 case elfcpp::R_POWERPC_GOT_TPREL16
:
8118 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8119 case elfcpp::R_POWERPC_GOT16
:
8120 case elfcpp::R_PPC64_GOT16_DS
:
8121 case elfcpp::R_PPC64_TOC16
:
8122 case elfcpp::R_PPC64_TOC16_DS
:
8123 ppc_object
->set_has_small_toc_reloc();
8129 // Report an unsupported relocation against a global symbol.
8131 template<int size
, bool big_endian
>
8133 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8134 Sized_relobj_file
<size
, big_endian
>* object
,
8135 unsigned int r_type
,
8138 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8139 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8142 // Scan a relocation for a global symbol.
8144 template<int size
, bool big_endian
>
8146 Target_powerpc
<size
, big_endian
>::Scan::global(
8147 Symbol_table
* symtab
,
8149 Target_powerpc
<size
, big_endian
>* target
,
8150 Sized_relobj_file
<size
, big_endian
>* object
,
8151 unsigned int data_shndx
,
8152 Output_section
* output_section
,
8153 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8154 unsigned int r_type
,
8157 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8161 if (target
->replace_tls_get_addr(gsym
))
8162 // Change a __tls_get_addr reference to __tls_get_addr_opt
8163 // so dynamic relocs are emitted against the latter symbol.
8164 gsym
= target
->tls_get_addr_opt();
8166 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8167 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8169 this->expect_tls_get_addr_call();
8170 const bool final
= gsym
->final_value_is_known();
8171 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8172 if (tls_type
!= tls::TLSOPT_NONE
)
8173 this->skip_next_tls_get_addr_call();
8175 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8176 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8178 this->expect_tls_get_addr_call();
8179 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8180 if (tls_type
!= tls::TLSOPT_NONE
)
8181 this->skip_next_tls_get_addr_call();
8184 Powerpc_relobj
<size
, big_endian
>* ppc_object
8185 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8187 // A STT_GNU_IFUNC symbol may require a PLT entry.
8188 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8189 bool pushed_ifunc
= false;
8190 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8192 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8193 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8194 r_type
, r_sym
, reloc
.get_r_addend());
8195 target
->make_plt_entry(symtab
, layout
, gsym
);
8196 pushed_ifunc
= true;
8201 case elfcpp::R_POWERPC_NONE
:
8202 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8203 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8204 case elfcpp::R_PPC_LOCAL24PC
:
8205 case elfcpp::R_POWERPC_TLS
:
8206 case elfcpp::R_PPC64_ENTRY
:
8207 case elfcpp::R_POWERPC_PLTSEQ
:
8208 case elfcpp::R_POWERPC_PLTCALL
:
8209 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8210 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8211 case elfcpp::R_PPC64_PCREL_OPT
:
8212 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8213 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8214 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8215 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8216 case elfcpp::R_PPC64_REL16_HIGHER34
:
8217 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8218 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8219 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8222 case elfcpp::R_PPC64_D34
:
8223 case elfcpp::R_PPC64_D34_LO
:
8224 case elfcpp::R_PPC64_D34_HI30
:
8225 case elfcpp::R_PPC64_D34_HA30
:
8226 case elfcpp::R_PPC64_D28
:
8227 case elfcpp::R_PPC64_PCREL34
:
8228 case elfcpp::R_PPC64_PCREL28
:
8229 target
->set_powerxx_stubs();
8232 case elfcpp::R_PPC64_TOC
:
8234 Output_data_got_powerpc
<size
, big_endian
>* got
8235 = target
->got_section(symtab
, layout
);
8236 if (parameters
->options().output_is_position_independent())
8238 Address off
= reloc
.get_r_offset();
8240 && data_shndx
== ppc_object
->opd_shndx()
8241 && ppc_object
->get_opd_discard(off
- 8))
8244 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8245 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8246 if (data_shndx
!= ppc_object
->opd_shndx())
8247 symobj
= static_cast
8248 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8249 rela_dyn
->add_output_section_relative(got
->output_section(),
8250 elfcpp::R_POWERPC_RELATIVE
,
8252 object
, data_shndx
, off
,
8253 symobj
->toc_base_offset());
8258 case elfcpp::R_PPC64_ADDR64
:
8260 && target
->abiversion() < 2
8261 && data_shndx
== ppc_object
->opd_shndx()
8262 && (gsym
->is_defined_in_discarded_section()
8263 || gsym
->object() != object
))
8265 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8269 case elfcpp::R_PPC64_UADDR64
:
8270 case elfcpp::R_POWERPC_ADDR32
:
8271 case elfcpp::R_POWERPC_UADDR32
:
8272 case elfcpp::R_POWERPC_ADDR24
:
8273 case elfcpp::R_POWERPC_ADDR16
:
8274 case elfcpp::R_POWERPC_ADDR16_LO
:
8275 case elfcpp::R_POWERPC_ADDR16_HI
:
8276 case elfcpp::R_POWERPC_ADDR16_HA
:
8277 case elfcpp::R_POWERPC_UADDR16
:
8278 case elfcpp::R_PPC64_ADDR16_HIGH
:
8279 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8280 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8281 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8282 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8283 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8284 case elfcpp::R_PPC64_ADDR16_DS
:
8285 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8286 case elfcpp::R_POWERPC_ADDR14
:
8287 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8288 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8290 // Make a PLT entry if necessary.
8291 if (gsym
->needs_plt_entry())
8293 // Since this is not a PC-relative relocation, we may be
8294 // taking the address of a function. In that case we need to
8295 // set the entry in the dynamic symbol table to the address of
8296 // the PLT call stub.
8297 bool need_ifunc_plt
= false;
8298 if ((size
== 32 || target
->abiversion() >= 2)
8299 && gsym
->is_from_dynobj()
8300 && !parameters
->options().output_is_position_independent())
8302 gsym
->set_needs_dynsym_value();
8303 need_ifunc_plt
= true;
8305 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8307 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8308 target
->push_branch(ppc_object
, data_shndx
,
8309 reloc
.get_r_offset(), r_type
, r_sym
,
8310 reloc
.get_r_addend());
8311 target
->make_plt_entry(symtab
, layout
, gsym
);
8314 // Make a dynamic relocation if necessary.
8315 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8316 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8318 if (!parameters
->options().output_is_position_independent()
8319 && gsym
->may_need_copy_reloc())
8321 target
->copy_reloc(symtab
, layout
, object
,
8322 data_shndx
, output_section
, gsym
, reloc
);
8324 else if ((((size
== 32
8325 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8327 && r_type
== elfcpp::R_PPC64_ADDR64
8328 && target
->abiversion() >= 2))
8329 && gsym
->can_use_relative_reloc(false)
8330 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8331 && parameters
->options().shared()))
8333 && r_type
== elfcpp::R_PPC64_ADDR64
8334 && target
->abiversion() < 2
8335 && (gsym
->can_use_relative_reloc(false)
8336 || data_shndx
== ppc_object
->opd_shndx())))
8338 Reloc_section
* rela_dyn
8339 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8340 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8341 : elfcpp::R_POWERPC_RELATIVE
);
8342 rela_dyn
->add_symbolless_global_addend(
8343 gsym
, dynrel
, output_section
, object
, data_shndx
,
8344 reloc
.get_r_offset(), reloc
.get_r_addend());
8348 Reloc_section
* rela_dyn
8349 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8350 check_non_pic(object
, r_type
);
8351 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8353 reloc
.get_r_offset(),
8354 reloc
.get_r_addend());
8357 && parameters
->options().toc_optimize()
8358 && data_shndx
== ppc_object
->toc_shndx())
8359 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8365 case elfcpp::R_PPC64_PLT_PCREL34
:
8366 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8367 target
->set_powerxx_stubs();
8369 case elfcpp::R_POWERPC_PLT16_LO
:
8370 case elfcpp::R_POWERPC_PLT16_HI
:
8371 case elfcpp::R_POWERPC_PLT16_HA
:
8372 case elfcpp::R_PPC64_PLT16_LO_DS
:
8374 target
->make_plt_entry(symtab
, layout
, gsym
);
8377 case elfcpp::R_PPC64_REL24_NOTOC
:
8381 case elfcpp::R_PPC_PLTREL24
:
8382 case elfcpp::R_POWERPC_REL24
:
8385 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8386 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8387 r_type
, r_sym
, reloc
.get_r_addend());
8388 if (gsym
->needs_plt_entry()
8389 || (!gsym
->final_value_is_known()
8390 && (gsym
->is_undefined()
8391 || gsym
->is_from_dynobj()
8392 || gsym
->is_preemptible())))
8393 target
->make_plt_entry(symtab
, layout
, gsym
);
8397 case elfcpp::R_PPC64_REL64
:
8398 case elfcpp::R_POWERPC_REL32
:
8399 // Make a dynamic relocation if necessary.
8400 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8402 if (!parameters
->options().output_is_position_independent()
8403 && gsym
->may_need_copy_reloc())
8405 target
->copy_reloc(symtab
, layout
, object
,
8406 data_shndx
, output_section
, gsym
,
8411 Reloc_section
* rela_dyn
8412 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8413 check_non_pic(object
, r_type
);
8414 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8415 data_shndx
, reloc
.get_r_offset(),
8416 reloc
.get_r_addend());
8421 case elfcpp::R_POWERPC_REL14
:
8422 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8423 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8426 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8427 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8428 r_type
, r_sym
, reloc
.get_r_addend());
8432 case elfcpp::R_PPC64_TOCSAVE
:
8433 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8434 // caller has already saved r2 and thus a plt call stub need not
8437 && target
->mark_pltcall(ppc_object
, data_shndx
,
8438 reloc
.get_r_offset() - 4, symtab
))
8440 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8442 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8444 object
->error(_("tocsave symbol %u has bad shndx %u"),
8448 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8449 target
->add_tocsave(ppc_object
, shndx
,
8450 sym
->value() + reloc
.get_r_addend());
8455 case elfcpp::R_POWERPC_REL16
:
8456 case elfcpp::R_POWERPC_REL16_LO
:
8457 case elfcpp::R_POWERPC_REL16_HI
:
8458 case elfcpp::R_POWERPC_REL16_HA
:
8459 case elfcpp::R_POWERPC_REL16DX_HA
:
8460 case elfcpp::R_PPC64_REL16_HIGH
:
8461 case elfcpp::R_PPC64_REL16_HIGHA
:
8462 case elfcpp::R_PPC64_REL16_HIGHER
:
8463 case elfcpp::R_PPC64_REL16_HIGHERA
:
8464 case elfcpp::R_PPC64_REL16_HIGHEST
:
8465 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8466 case elfcpp::R_POWERPC_SECTOFF
:
8467 case elfcpp::R_POWERPC_SECTOFF_LO
:
8468 case elfcpp::R_POWERPC_SECTOFF_HI
:
8469 case elfcpp::R_POWERPC_SECTOFF_HA
:
8470 case elfcpp::R_PPC64_SECTOFF_DS
:
8471 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8472 case elfcpp::R_POWERPC_TPREL16
:
8473 case elfcpp::R_POWERPC_TPREL16_LO
:
8474 case elfcpp::R_POWERPC_TPREL16_HI
:
8475 case elfcpp::R_POWERPC_TPREL16_HA
:
8476 case elfcpp::R_PPC64_TPREL16_DS
:
8477 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8478 case elfcpp::R_PPC64_TPREL16_HIGH
:
8479 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8480 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8481 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8482 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8483 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8484 case elfcpp::R_POWERPC_DTPREL16
:
8485 case elfcpp::R_POWERPC_DTPREL16_LO
:
8486 case elfcpp::R_POWERPC_DTPREL16_HI
:
8487 case elfcpp::R_POWERPC_DTPREL16_HA
:
8488 case elfcpp::R_PPC64_DTPREL16_DS
:
8489 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8490 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8491 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8492 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8493 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8494 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8495 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8496 case elfcpp::R_PPC64_TLSGD
:
8497 case elfcpp::R_PPC64_TLSLD
:
8498 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8501 case elfcpp::R_PPC64_GOT_PCREL34
:
8502 target
->set_powerxx_stubs();
8504 case elfcpp::R_POWERPC_GOT16
:
8505 case elfcpp::R_POWERPC_GOT16_LO
:
8506 case elfcpp::R_POWERPC_GOT16_HI
:
8507 case elfcpp::R_POWERPC_GOT16_HA
:
8508 case elfcpp::R_PPC64_GOT16_DS
:
8509 case elfcpp::R_PPC64_GOT16_LO_DS
:
8511 // The symbol requires a GOT entry.
8512 Output_data_got_powerpc
<size
, big_endian
>* got
;
8514 got
= target
->got_section(symtab
, layout
);
8515 if (gsym
->final_value_is_known())
8518 && (size
== 32 || target
->abiversion() >= 2))
8519 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8521 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8523 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8525 // If we are generating a shared object or a pie, this
8526 // symbol's GOT entry will be set by a dynamic relocation.
8527 unsigned int off
= got
->add_constant(0);
8528 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8530 Reloc_section
* rela_dyn
8531 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8533 if (gsym
->can_use_relative_reloc(false)
8535 || target
->abiversion() >= 2)
8536 && gsym
->visibility() == elfcpp::STV_PROTECTED
8537 && parameters
->options().shared()))
8539 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8540 : elfcpp::R_POWERPC_RELATIVE
);
8541 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8545 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8546 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8552 case elfcpp::R_PPC64_TOC16
:
8553 case elfcpp::R_PPC64_TOC16_LO
:
8554 case elfcpp::R_PPC64_TOC16_HI
:
8555 case elfcpp::R_PPC64_TOC16_HA
:
8556 case elfcpp::R_PPC64_TOC16_DS
:
8557 case elfcpp::R_PPC64_TOC16_LO_DS
:
8558 // We need a GOT section.
8559 target
->got_section(symtab
, layout
);
8562 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8563 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8564 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8565 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8567 const bool final
= gsym
->final_value_is_known();
8568 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8569 if (tls_type
== tls::TLSOPT_NONE
)
8571 Output_data_got_powerpc
<size
, big_endian
>* got
8572 = target
->got_section(symtab
, layout
);
8573 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8574 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8575 elfcpp::R_POWERPC_DTPMOD
,
8576 elfcpp::R_POWERPC_DTPREL
);
8578 else if (tls_type
== tls::TLSOPT_TO_IE
)
8580 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8582 Output_data_got_powerpc
<size
, big_endian
>* got
8583 = target
->got_section(symtab
, layout
);
8584 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8585 if (gsym
->is_undefined()
8586 || gsym
->is_from_dynobj())
8588 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8589 elfcpp::R_POWERPC_TPREL
);
8593 unsigned int off
= got
->add_constant(0);
8594 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8595 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8596 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8601 else if (tls_type
== tls::TLSOPT_TO_LE
)
8603 // no GOT relocs needed for Local Exec.
8610 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8611 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8612 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8613 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8615 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8616 if (tls_type
== tls::TLSOPT_NONE
)
8617 target
->tlsld_got_offset(symtab
, layout
, object
);
8618 else if (tls_type
== tls::TLSOPT_TO_LE
)
8620 // no GOT relocs needed for Local Exec.
8621 if (parameters
->options().emit_relocs())
8623 Output_section
* os
= layout
->tls_segment()->first_section();
8624 gold_assert(os
!= NULL
);
8625 os
->set_needs_symtab_index();
8633 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8634 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8635 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8636 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8638 Output_data_got_powerpc
<size
, big_endian
>* got
8639 = target
->got_section(symtab
, layout
);
8640 if (!gsym
->final_value_is_known()
8641 && (gsym
->is_from_dynobj()
8642 || gsym
->is_undefined()
8643 || gsym
->is_preemptible()))
8644 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8645 target
->rela_dyn_section(layout
),
8646 elfcpp::R_POWERPC_DTPREL
);
8648 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8652 case elfcpp::R_POWERPC_GOT_TPREL16
:
8653 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8654 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8655 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8657 const bool final
= gsym
->final_value_is_known();
8658 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8659 if (tls_type
== tls::TLSOPT_NONE
)
8661 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8663 Output_data_got_powerpc
<size
, big_endian
>* got
8664 = target
->got_section(symtab
, layout
);
8665 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8666 if (gsym
->is_undefined()
8667 || gsym
->is_from_dynobj())
8669 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8670 elfcpp::R_POWERPC_TPREL
);
8674 unsigned int off
= got
->add_constant(0);
8675 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8676 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8677 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8682 else if (tls_type
== tls::TLSOPT_TO_LE
)
8684 // no GOT relocs needed for Local Exec.
8692 unsupported_reloc_global(object
, r_type
, gsym
);
8697 && parameters
->options().toc_optimize())
8699 if (data_shndx
== ppc_object
->toc_shndx())
8702 if (r_type
!= elfcpp::R_PPC64_ADDR64
8703 || (is_ifunc
&& target
->abiversion() < 2))
8705 else if (parameters
->options().output_is_position_independent()
8706 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
8709 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8712 enum {no_check
, check_lo
, check_ha
} insn_check
;
8716 insn_check
= no_check
;
8719 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8720 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8721 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8722 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8723 case elfcpp::R_POWERPC_GOT16_HA
:
8724 case elfcpp::R_PPC64_TOC16_HA
:
8725 insn_check
= check_ha
;
8728 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8729 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8730 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8731 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8732 case elfcpp::R_POWERPC_GOT16_LO
:
8733 case elfcpp::R_PPC64_GOT16_LO_DS
:
8734 case elfcpp::R_PPC64_TOC16_LO
:
8735 case elfcpp::R_PPC64_TOC16_LO_DS
:
8736 insn_check
= check_lo
;
8740 section_size_type slen
;
8741 const unsigned char* view
= NULL
;
8742 if (insn_check
!= no_check
)
8744 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8745 section_size_type off
=
8746 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8749 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8750 if (insn_check
== check_lo
8751 ? !ok_lo_toc_insn(insn
, r_type
)
8752 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8753 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8755 ppc_object
->set_no_toc_opt();
8756 gold_warning(_("%s: toc optimization is not supported "
8757 "for %#08x instruction"),
8758 ppc_object
->name().c_str(), insn
);
8767 case elfcpp::R_PPC64_TOC16
:
8768 case elfcpp::R_PPC64_TOC16_LO
:
8769 case elfcpp::R_PPC64_TOC16_HI
:
8770 case elfcpp::R_PPC64_TOC16_HA
:
8771 case elfcpp::R_PPC64_TOC16_DS
:
8772 case elfcpp::R_PPC64_TOC16_LO_DS
:
8773 if (gsym
->source() == Symbol::FROM_OBJECT
8774 && !gsym
->object()->is_dynamic())
8776 Powerpc_relobj
<size
, big_endian
>* sym_object
8777 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8779 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8780 if (shndx
== sym_object
->toc_shndx())
8782 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8783 Address dst_off
= sym
->value() + reloc
.get_r_addend();
8784 if (dst_off
< sym_object
->section_size(shndx
))
8787 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8789 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8791 // Need to check that the insn is a ld
8793 view
= ppc_object
->section_contents(data_shndx
,
8796 section_size_type off
=
8797 (convert_to_section_size_type(reloc
.get_r_offset())
8798 + (big_endian
? -2 : 3));
8800 && (view
[off
] & (0x3f << 2)) == (58u << 2))
8804 sym_object
->set_no_toc_opt(dst_off
);
8816 case elfcpp::R_PPC_LOCAL24PC
:
8817 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
8818 gold_error(_("%s: unsupported -mbss-plt code"),
8819 ppc_object
->name().c_str());
8828 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8829 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8830 case elfcpp::R_POWERPC_GOT_TPREL16
:
8831 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8832 case elfcpp::R_POWERPC_GOT16
:
8833 case elfcpp::R_PPC64_GOT16_DS
:
8834 case elfcpp::R_PPC64_TOC16
:
8835 case elfcpp::R_PPC64_TOC16_DS
:
8836 ppc_object
->set_has_small_toc_reloc();
8842 // Process relocations for gc.
8844 template<int size
, bool big_endian
>
8846 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
8847 Symbol_table
* symtab
,
8849 Sized_relobj_file
<size
, big_endian
>* object
,
8850 unsigned int data_shndx
,
8852 const unsigned char* prelocs
,
8854 Output_section
* output_section
,
8855 bool needs_special_offset_handling
,
8856 size_t local_symbol_count
,
8857 const unsigned char* plocal_symbols
)
8859 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8860 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8863 Powerpc_relobj
<size
, big_endian
>* ppc_object
8864 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8866 ppc_object
->set_opd_valid();
8867 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
8869 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
8870 for (p
= ppc_object
->access_from_map()->begin();
8871 p
!= ppc_object
->access_from_map()->end();
8874 Address dst_off
= p
->first
;
8875 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8876 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
8877 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
8879 Relobj
* src_obj
= s
->first
;
8880 unsigned int src_indx
= s
->second
;
8881 symtab
->gc()->add_reference(src_obj
, src_indx
,
8882 ppc_object
, dst_indx
);
8886 ppc_object
->access_from_map()->clear();
8887 ppc_object
->process_gc_mark(symtab
);
8888 // Don't look at .opd relocs as .opd will reference everything.
8892 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
8901 needs_special_offset_handling
,
8906 // Handle target specific gc actions when adding a gc reference from
8907 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
8908 // and DST_OFF. For powerpc64, this adds a referenc to the code
8909 // section of a function descriptor.
8911 template<int size
, bool big_endian
>
8913 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
8914 Symbol_table
* symtab
,
8916 unsigned int src_shndx
,
8918 unsigned int dst_shndx
,
8919 Address dst_off
) const
8921 if (size
!= 64 || dst_obj
->is_dynamic())
8924 Powerpc_relobj
<size
, big_endian
>* ppc_object
8925 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
8926 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
8928 if (ppc_object
->opd_valid())
8930 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
8931 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
8935 // If we haven't run scan_opd_relocs, we must delay
8936 // processing this function descriptor reference.
8937 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
8942 // Add any special sections for this symbol to the gc work list.
8943 // For powerpc64, this adds the code section of a function
8946 template<int size
, bool big_endian
>
8948 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
8949 Symbol_table
* symtab
,
8954 Powerpc_relobj
<size
, big_endian
>* ppc_object
8955 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
8957 unsigned int shndx
= sym
->shndx(&is_ordinary
);
8958 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
8960 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
8961 Address dst_off
= gsym
->value();
8962 if (ppc_object
->opd_valid())
8964 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8965 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
8969 ppc_object
->add_gc_mark(dst_off
);
8974 // For a symbol location in .opd, set LOC to the location of the
8977 template<int size
, bool big_endian
>
8979 Target_powerpc
<size
, big_endian
>::do_function_location(
8980 Symbol_location
* loc
) const
8982 if (size
== 64 && loc
->shndx
!= 0)
8984 if (loc
->object
->is_dynamic())
8986 Powerpc_dynobj
<size
, big_endian
>* ppc_object
8987 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
8988 if (loc
->shndx
== ppc_object
->opd_shndx())
8991 Address off
= loc
->offset
- ppc_object
->opd_address();
8992 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
8993 loc
->offset
= dest_off
;
8998 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8999 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
9000 if (loc
->shndx
== ppc_object
->opd_shndx())
9003 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
9004 loc
->offset
= dest_off
;
9010 // FNOFFSET in section SHNDX in OBJECT is the start of a function
9011 // compiled with -fsplit-stack. The function calls non-split-stack
9012 // code. Change the function to ensure it has enough stack space to
9013 // call some random function.
9015 template<int size
, bool big_endian
>
9017 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
9020 section_offset_type fnoffset
,
9021 section_size_type fnsize
,
9022 const unsigned char* prelocs
,
9024 unsigned char* view
,
9025 section_size_type view_size
,
9027 std::string
* to
) const
9029 // 32-bit not supported.
9033 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9034 prelocs
, reloc_count
, view
, view_size
,
9039 // The function always starts with
9040 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9041 // addis %r12,%r1,-allocate@ha
9042 // addi %r12,%r12,-allocate@l
9044 // but note that the addis or addi may be replaced with a nop
9046 unsigned char *entry
= view
+ fnoffset
;
9047 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9049 if ((insn
& 0xffff0000) == addis_2_12
)
9051 /* Skip ELFv2 global entry code. */
9053 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9056 unsigned char *pinsn
= entry
;
9058 const uint32_t ld_private_ss
= 0xe80d8fc0;
9059 if (insn
== ld_private_ss
)
9061 int32_t allocate
= 0;
9065 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9066 if ((insn
& 0xffff0000) == addis_12_1
)
9067 allocate
+= (insn
& 0xffff) << 16;
9068 else if ((insn
& 0xffff0000) == addi_12_1
9069 || (insn
& 0xffff0000) == addi_12_12
)
9070 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9071 else if (insn
!= nop
)
9074 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9076 int extra
= parameters
->options().split_stack_adjust_size();
9078 if (allocate
>= 0 || extra
< 0)
9080 object
->error(_("split-stack stack size overflow at "
9081 "section %u offset %0zx"),
9082 shndx
, static_cast<size_t>(fnoffset
));
9086 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9087 if (insn
!= addis_12_1
)
9089 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9091 insn
= addi_12_12
| (allocate
& 0xffff);
9092 if (insn
!= addi_12_12
)
9094 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9100 insn
= addi_12_1
| (allocate
& 0xffff);
9101 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9104 if (pinsn
!= entry
+ 12)
9105 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9113 if (!object
->has_no_split_stack())
9114 object
->error(_("failed to match split-stack sequence at "
9115 "section %u offset %0zx"),
9116 shndx
, static_cast<size_t>(fnoffset
));
9120 // Scan relocations for a section.
9122 template<int size
, bool big_endian
>
9124 Target_powerpc
<size
, big_endian
>::scan_relocs(
9125 Symbol_table
* symtab
,
9127 Sized_relobj_file
<size
, big_endian
>* object
,
9128 unsigned int data_shndx
,
9129 unsigned int sh_type
,
9130 const unsigned char* prelocs
,
9132 Output_section
* output_section
,
9133 bool needs_special_offset_handling
,
9134 size_t local_symbol_count
,
9135 const unsigned char* plocal_symbols
)
9137 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9138 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9141 if (!this->plt_localentry0_init_
)
9143 bool plt_localentry0
= false;
9145 && this->abiversion() >= 2)
9147 if (parameters
->options().user_set_plt_localentry())
9148 plt_localentry0
= parameters
->options().plt_localentry();
9150 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9151 gold_warning(_("--plt-localentry is especially dangerous without "
9152 "ld.so support to detect ABI violations"));
9154 this->plt_localentry0_
= plt_localentry0
;
9155 this->plt_localentry0_init_
= true;
9158 if (sh_type
== elfcpp::SHT_REL
)
9160 gold_error(_("%s: unsupported REL reloc section"),
9161 object
->name().c_str());
9165 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9174 needs_special_offset_handling
,
9179 // Functor class for processing the global symbol table.
9180 // Removes symbols defined on discarded opd entries.
9182 template<bool big_endian
>
9183 class Global_symbol_visitor_opd
9186 Global_symbol_visitor_opd()
9190 operator()(Sized_symbol
<64>* sym
)
9192 if (sym
->has_symtab_index()
9193 || sym
->source() != Symbol::FROM_OBJECT
9194 || !sym
->in_real_elf())
9197 if (sym
->object()->is_dynamic())
9200 Powerpc_relobj
<64, big_endian
>* symobj
9201 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9202 if (symobj
->opd_shndx() == 0)
9206 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9207 if (shndx
== symobj
->opd_shndx()
9208 && symobj
->get_opd_discard(sym
->value()))
9210 sym
->set_undefined();
9211 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9212 sym
->set_is_defined_in_discarded_section();
9213 sym
->set_symtab_index(-1U);
9218 template<int size
, bool big_endian
>
9220 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9222 Symbol_table
* symtab
)
9226 Output_data_save_res
<size
, big_endian
>* savres
9227 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9228 this->savres_section_
= savres
;
9229 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9230 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9231 savres
, ORDER_TEXT
, false);
9235 // Sort linker created .got section first (for the header), then input
9236 // sections belonging to files using small model code.
9238 template<bool big_endian
>
9239 class Sort_toc_sections
9243 operator()(const Output_section::Input_section
& is1
,
9244 const Output_section::Input_section
& is2
) const
9246 if (!is1
.is_input_section() && is2
.is_input_section())
9249 = (is1
.is_input_section()
9250 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9251 ->has_small_toc_reloc()));
9253 = (is2
.is_input_section()
9254 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9255 ->has_small_toc_reloc()));
9256 return small1
&& !small2
;
9260 // Finalize the sections.
9262 template<int size
, bool big_endian
>
9264 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9266 const Input_objects
* input_objects
,
9267 Symbol_table
* symtab
)
9269 if (parameters
->doing_static_link())
9271 // At least some versions of glibc elf-init.o have a strong
9272 // reference to __rela_iplt marker syms. A weak ref would be
9274 if (this->iplt_
!= NULL
)
9276 Reloc_section
* rel
= this->iplt_
->rel_plt();
9277 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9278 Symbol_table::PREDEFINED
, rel
, 0, 0,
9279 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9280 elfcpp::STV_HIDDEN
, 0, false, true);
9281 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9282 Symbol_table::PREDEFINED
, rel
, 0, 0,
9283 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9284 elfcpp::STV_HIDDEN
, 0, true, true);
9288 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9289 Symbol_table::PREDEFINED
, 0, 0,
9290 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9291 elfcpp::STV_HIDDEN
, 0, true, false);
9292 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9293 Symbol_table::PREDEFINED
, 0, 0,
9294 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9295 elfcpp::STV_HIDDEN
, 0, true, false);
9301 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9302 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9304 if (!parameters
->options().relocatable())
9306 this->define_save_restore_funcs(layout
, symtab
);
9308 // Annoyingly, we need to make these sections now whether or
9309 // not we need them. If we delay until do_relax then we
9310 // need to mess with the relaxation machinery checkpointing.
9311 this->got_section(symtab
, layout
);
9312 this->make_brlt_section(layout
);
9314 if (parameters
->options().toc_sort())
9316 Output_section
* os
= this->got_
->output_section();
9317 if (os
!= NULL
&& os
->input_sections().size() > 1)
9318 std::stable_sort(os
->input_sections().begin(),
9319 os
->input_sections().end(),
9320 Sort_toc_sections
<big_endian
>());
9325 // Fill in some more dynamic tags.
9326 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9329 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9331 : this->plt_
->rel_plt());
9332 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9333 this->rela_dyn_
, true, size
== 32);
9337 if (this->got_
!= NULL
)
9339 this->got_
->finalize_data_size();
9340 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9341 this->got_
, this->got_
->g_o_t());
9343 if (this->has_tls_get_addr_opt_
)
9344 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9348 if (this->glink_
!= NULL
)
9350 this->glink_
->finalize_data_size();
9351 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9353 (this->glink_
->pltresolve_size()
9356 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9357 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9358 ((this->has_localentry0_
9359 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9360 | (this->has_tls_get_addr_opt_
9361 ? elfcpp::PPC64_OPT_TLS
: 0)));
9365 // Emit any relocs we saved in an attempt to avoid generating COPY
9367 if (this->copy_relocs_
.any_saved_relocs())
9368 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9370 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9371 p
!= input_objects
->relobj_end();
9374 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9375 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9376 if (ppc_relobj
->attributes_section_data())
9377 this->merge_object_attributes(ppc_relobj
->name().c_str(),
9378 ppc_relobj
->attributes_section_data());
9380 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9381 p
!= input_objects
->dynobj_end();
9384 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9385 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9386 if (ppc_dynobj
->attributes_section_data())
9387 this->merge_object_attributes(ppc_dynobj
->name().c_str(),
9388 ppc_dynobj
->attributes_section_data());
9391 // Create a .gnu.attributes section if we have merged any attributes
9393 if (this->attributes_section_data_
!= NULL
9394 && this->attributes_section_data_
->size() != 0)
9396 Output_attributes_section_data
* attributes_section
9397 = new Output_attributes_section_data(*this->attributes_section_data_
);
9398 layout
->add_output_section_data(".gnu.attributes",
9399 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9400 attributes_section
, ORDER_INVALID
, false);
9404 // Merge object attributes from input file called NAME with those of the
9405 // output. The input object attributes are in the object pointed by PASD.
9407 template<int size
, bool big_endian
>
9409 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9411 const Attributes_section_data
* pasd
)
9413 // Return if there is no attributes section data.
9417 // Create output object attributes.
9418 if (this->attributes_section_data_
== NULL
)
9419 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9421 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9422 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9423 Object_attribute
* out_attr
9424 = this->attributes_section_data_
->known_attributes(vendor
);
9429 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9430 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9431 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9432 if (in_fp
!= out_fp
)
9435 if ((in_fp
& 3) == 0)
9437 else if ((out_fp
& 3) == 0)
9439 out_fp
|= in_fp
& 3;
9440 out_attr
[tag
].set_int_value(out_fp
);
9441 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9442 this->last_fp_
= name
;
9444 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9446 err
= N_("%s uses hard float, %s uses soft float");
9447 first
= this->last_fp_
;
9450 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9452 err
= N_("%s uses hard float, %s uses soft float");
9454 second
= this->last_fp_
;
9456 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9458 err
= N_("%s uses double-precision hard float, "
9459 "%s uses single-precision hard float");
9460 first
= this->last_fp_
;
9463 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9465 err
= N_("%s uses double-precision hard float, "
9466 "%s uses single-precision hard float");
9468 second
= this->last_fp_
;
9471 if (err
|| (in_fp
& 0xc) == 0)
9473 else if ((out_fp
& 0xc) == 0)
9475 out_fp
|= in_fp
& 0xc;
9476 out_attr
[tag
].set_int_value(out_fp
);
9477 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9478 this->last_ld_
= name
;
9480 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9482 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9484 second
= this->last_ld_
;
9486 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9488 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9489 first
= this->last_ld_
;
9492 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9494 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9495 first
= this->last_ld_
;
9498 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9500 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9502 second
= this->last_ld_
;
9507 if (parameters
->options().warn_mismatch())
9508 gold_error(_(err
), first
, second
);
9509 // Arrange for this attribute to be deleted. It's better to
9510 // say "don't know" about a file than to wrongly claim compliance.
9511 out_attr
[tag
].set_type(0);
9517 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9518 int in_vec
= in_attr
[tag
].int_value() & 3;
9519 int out_vec
= out_attr
[tag
].int_value() & 3;
9520 if (in_vec
!= out_vec
)
9525 else if (out_vec
== 0)
9528 out_attr
[tag
].set_int_value(out_vec
);
9529 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9530 this->last_vec_
= name
;
9532 // For now, allow generic to transition to AltiVec or SPE
9533 // without a warning. If GCC marked files with their stack
9534 // alignment and used don't-care markings for files which are
9535 // not affected by the vector ABI, we could warn about this
9537 else if (in_vec
== 1)
9539 else if (out_vec
== 1)
9542 out_attr
[tag
].set_int_value(out_vec
);
9543 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9544 this->last_vec_
= name
;
9546 else if (out_vec
< in_vec
)
9548 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9549 first
= this->last_vec_
;
9552 else if (out_vec
> in_vec
)
9554 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9556 second
= this->last_vec_
;
9560 if (parameters
->options().warn_mismatch())
9561 gold_error(_(err
), first
, second
);
9562 out_attr
[tag
].set_type(0);
9566 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9567 int in_struct
= in_attr
[tag
].int_value() & 3;
9568 int out_struct
= out_attr
[tag
].int_value() & 3;
9569 if (in_struct
!= out_struct
)
9572 if (in_struct
== 0 || in_struct
== 3)
9574 else if (out_struct
== 0)
9576 out_struct
= in_struct
;
9577 out_attr
[tag
].set_int_value(out_struct
);
9578 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9579 this->last_struct_
= name
;
9581 else if (out_struct
< in_struct
)
9583 err
= N_("%s uses r3/r4 for small structure returns, "
9585 first
= this->last_struct_
;
9588 else if (out_struct
> in_struct
)
9590 err
= N_("%s uses r3/r4 for small structure returns, "
9593 second
= this->last_struct_
;
9597 if (parameters
->options().warn_mismatch())
9598 gold_error(_(err
), first
, second
);
9599 out_attr
[tag
].set_type(0);
9604 // Merge Tag_compatibility attributes and any common GNU ones.
9605 this->attributes_section_data_
->merge(name
, pasd
);
9608 // Emit any saved relocs, and mark toc entries using any of these
9609 // relocs as not optimizable.
9611 template<int sh_type
, int size
, bool big_endian
>
9613 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
9614 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
9617 && parameters
->options().toc_optimize())
9619 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
9620 Copy_reloc_entries::iterator p
= this->entries_
.begin();
9621 p
!= this->entries_
.end();
9624 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
9627 // If the symbol is no longer defined in a dynamic object,
9628 // then we emitted a COPY relocation. If it is still
9629 // dynamic then we'll need dynamic relocations and thus
9630 // can't optimize toc entries.
9631 if (entry
.sym_
->is_from_dynobj())
9633 Powerpc_relobj
<size
, big_endian
>* ppc_object
9634 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
9635 if (entry
.shndx_
== ppc_object
->toc_shndx())
9636 ppc_object
->set_no_toc_opt(entry
.address_
);
9641 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
9644 // Return the value to use for a branch relocation.
9646 template<int size
, bool big_endian
>
9648 Target_powerpc
<size
, big_endian
>::symval_for_branch(
9649 const Symbol_table
* symtab
,
9650 const Sized_symbol
<size
>* gsym
,
9651 Powerpc_relobj
<size
, big_endian
>* object
,
9653 unsigned int *dest_shndx
)
9655 if (size
== 32 || this->abiversion() >= 2)
9659 // If the symbol is defined in an opd section, ie. is a function
9660 // descriptor, use the function descriptor code entry address
9661 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
9663 && (gsym
->source() != Symbol::FROM_OBJECT
9664 || gsym
->object()->is_dynamic()))
9667 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9668 unsigned int shndx
= symobj
->opd_shndx();
9671 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
9672 if (opd_addr
== invalid_address
)
9674 opd_addr
+= symobj
->output_section_address(shndx
);
9675 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
9678 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
9679 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
9682 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
9683 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
9684 *dest_shndx
= folded
.second
;
9686 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
9687 if (sec_addr
== invalid_address
)
9690 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
9691 *value
= sec_addr
+ sec_off
;
9698 relative_value_is_known(const Sized_symbol
<size
>* gsym
)
9700 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
9703 if (gsym
->is_from_dynobj()
9704 || gsym
->is_undefined()
9705 || gsym
->is_preemptible())
9708 if (gsym
->is_absolute())
9709 return !parameters
->options().output_is_position_independent();
9716 relative_value_is_known(const Symbol_value
<size
>* psymval
)
9718 if (psymval
->is_ifunc_symbol())
9722 unsigned int shndx
= psymval
->input_shndx(&is_ordinary
);
9724 return is_ordinary
&& shndx
!= elfcpp::SHN_UNDEF
;
9727 // PCREL_OPT in one instance flags to the linker that a pair of insns:
9728 // pld ra,symbol@got@pcrel
9729 // load/store rt,0(ra)
9731 // pla ra,symbol@pcrel
9732 // load/store rt,0(ra)
9733 // may be translated to
9734 // pload/pstore rt,symbol@pcrel
9736 // This function returns true if the optimization is possible, placing
9737 // the prefix insn in *PINSN1 and a NOP in *PINSN2.
9739 // On entry to this function, the linker has already determined that
9740 // the pld can be replaced with pla: *PINSN1 is that pla insn,
9741 // while *PINSN2 is the second instruction.
9744 xlate_pcrel_opt(uint64_t *pinsn1
, uint64_t *pinsn2
)
9746 uint32_t insn2
= *pinsn2
>> 32;
9749 // Check that regs match.
9750 if (((insn2
>> 16) & 31) != ((*pinsn1
>> 21) & 31))
9753 switch ((insn2
>> 26) & 63)
9769 // These are the PMLS cases, where we just need to tack a prefix
9770 // on the insn. Check that the D field is zero.
9771 if ((insn2
& 0xffff) != 0)
9773 i1new
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
9774 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
9778 if ((insn2
& 0xfffd) != 0)
9780 i1new
= ((1ULL << 58) | (1ULL << 52)
9781 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
9782 | (insn2
& (31ULL << 21)));
9785 case 57: // lxsd, lxssp
9786 if ((insn2
& 0xfffc) != 0 || (insn2
& 3) < 2)
9788 i1new
= ((1ULL << 58) | (1ULL << 52)
9789 | ((40ULL | (insn2
& 3)) << 26)
9790 | (insn2
& (31ULL << 21)));
9793 case 61: // stxsd, stxssp, lxv, stxv
9794 if ((insn2
& 3) == 0)
9796 else if ((insn2
& 3) >= 2)
9798 if ((insn2
& 0xfffc) != 0)
9800 i1new
= ((1ULL << 58) | (1ULL << 52)
9801 | ((44ULL | (insn2
& 3)) << 26)
9802 | (insn2
& (31ULL << 21)));
9806 if ((insn2
& 0xfff0) != 0)
9808 i1new
= ((1ULL << 58) | (1ULL << 52)
9809 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
9810 | (insn2
& (31ULL << 21)));
9815 if ((insn2
& 0xffff) != 0)
9817 i1new
= ((1ULL << 58) | (1ULL << 52)
9818 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
9821 case 62: // std, stq
9822 if ((insn2
& 0xfffd) != 0)
9824 i1new
= ((1ULL << 58) | (1ULL << 52)
9825 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
9826 | (insn2
& (31ULL << 21)));
9831 *pinsn2
= (uint64_t) nop
<< 32;
9835 // Perform a relocation.
9837 template<int size
, bool big_endian
>
9839 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
9840 const Relocate_info
<size
, big_endian
>* relinfo
,
9842 Target_powerpc
* target
,
9845 const unsigned char* preloc
,
9846 const Sized_symbol
<size
>* gsym
,
9847 const Symbol_value
<size
>* psymval
,
9848 unsigned char* view
,
9850 section_size_type view_size
)
9852 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
9853 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
9854 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9859 if (target
->replace_tls_get_addr(gsym
))
9860 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
9862 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
9863 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
9864 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
9866 case Track_tls::NOT_EXPECTED
:
9867 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9868 _("__tls_get_addr call lacks marker reloc"));
9870 case Track_tls::EXPECTED
:
9871 // We have already complained.
9873 case Track_tls::SKIP
:
9874 if (is_plt16_reloc
<size
>(r_type
)
9875 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9876 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
9878 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9879 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9881 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
9883 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9884 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
9886 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
9887 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9889 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9890 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
9891 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
9894 case Track_tls::NORMAL
:
9898 // Offset from start of insn to d-field reloc.
9899 const int d_offset
= big_endian
? 2 : 0;
9901 Powerpc_relobj
<size
, big_endian
>* const object
9902 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
9904 bool has_stub_value
= false;
9905 bool localentry0
= false;
9906 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
9909 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
9910 : object
->local_has_plt_offset(r_sym
));
9912 && !is_plt16_reloc
<size
>(r_type
)
9913 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
9914 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
9915 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
9916 && r_type
!= elfcpp::R_POWERPC_PLTCALL
9917 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
9918 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
9919 && (!psymval
->is_ifunc_symbol()
9920 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
9924 && target
->abiversion() >= 2
9925 && !parameters
->options().output_is_position_independent()
9926 && !is_branch_reloc
<size
>(r_type
))
9928 Address off
= target
->glink_section()->find_global_entry(gsym
);
9929 if (off
!= invalid_address
)
9931 value
= target
->glink_section()->global_entry_address() + off
;
9932 has_stub_value
= true;
9937 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
9938 if (target
->stub_tables().size() == 1)
9939 stub_table
= target
->stub_tables()[0];
9940 if (stub_table
== NULL
9943 && !parameters
->options().output_is_position_independent()
9944 && !is_branch_reloc
<size
>(r_type
)))
9945 stub_table
= object
->stub_table(relinfo
->data_shndx
);
9946 if (stub_table
== NULL
)
9948 // This is a ref from a data section to an ifunc symbol,
9949 // or a non-branch reloc for which we always want to use
9950 // one set of stubs for resolving function addresses.
9951 if (target
->stub_tables().size() != 0)
9952 stub_table
= target
->stub_tables()[0];
9954 if (stub_table
!= NULL
)
9956 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
9958 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
9959 rela
.get_r_addend());
9961 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
9962 rela
.get_r_addend());
9965 value
= stub_table
->stub_address() + ent
->off_
;
9966 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9967 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
9968 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
9971 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
9975 && relnum
< reloc_count
- 1)
9977 Reltype
next_rela(preloc
+ reloc_size
);
9978 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
9979 == elfcpp::R_PPC64_TOCSAVE
9980 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
9983 localentry0
= ent
->localentry0_
;
9984 has_stub_value
= true;
9988 // We don't care too much about bogus debug references to
9989 // non-local functions, but otherwise there had better be a plt
9990 // call stub or global entry stub as appropriate.
9991 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
9994 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
9995 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
9996 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9998 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
10000 value
= target
->plt_off(gsym
, &plt
);
10002 value
= target
->plt_off(object
, r_sym
, &plt
);
10003 value
+= plt
->address();
10007 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
10008 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
10009 value
-= (target
->got_section()->output_section()->address()
10010 + object
->toc_base_offset());
10012 else if (parameters
->options().output_is_position_independent())
10014 if (rela
.get_r_addend() >= 32768)
10016 unsigned int got2
= object
->got2_shndx();
10017 value
-= (object
->get_output_section_offset(got2
)
10018 + object
->output_section(got2
)->address()
10019 + rela
.get_r_addend());
10022 value
-= (target
->got_section()->address()
10023 + target
->got_section()->g_o_t());
10026 else if (!has_plt_offset
10027 && (is_plt16_reloc
<size
>(r_type
)
10028 || r_type
== elfcpp::R_POWERPC_PLTSEQ
10029 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
10031 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10032 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10033 r_type
= elfcpp::R_POWERPC_NONE
;
10035 else if (!has_plt_offset
10036 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
10037 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
10039 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10040 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
10041 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
10042 r_type
= elfcpp::R_POWERPC_NONE
;
10044 else if (r_type
== elfcpp::R_POWERPC_GOT16
10045 || r_type
== elfcpp::R_POWERPC_GOT16_LO
10046 || r_type
== elfcpp::R_POWERPC_GOT16_HI
10047 || r_type
== elfcpp::R_POWERPC_GOT16_HA
10048 || r_type
== elfcpp::R_PPC64_GOT16_DS
10049 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10050 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10054 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
10055 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
10059 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
10060 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
10062 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
10063 value
+= target
->got_section()->address();
10065 value
-= target
->got_section()->got_base_offset(object
);
10067 else if (r_type
== elfcpp::R_PPC64_TOC
)
10069 value
= (target
->got_section()->output_section()->address()
10070 + object
->toc_base_offset());
10072 else if (gsym
!= NULL
10073 && (r_type
== elfcpp::R_POWERPC_REL24
10074 || r_type
== elfcpp::R_PPC_PLTREL24
)
10079 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
10080 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
10081 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
10082 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
10084 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
10085 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
10086 if ((insn
& 1) != 0
10088 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
10090 elfcpp::Swap
<32, big_endian
>::
10091 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
10092 can_plt_call
= true;
10097 // If we don't have a branch and link followed by a nop,
10098 // we can't go via the plt because there is no place to
10099 // put a toc restoring instruction.
10100 // Unless we know we won't be returning.
10101 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
10102 can_plt_call
= true;
10106 // g++ as of 20130507 emits self-calls without a
10107 // following nop. This is arguably wrong since we have
10108 // conflicting information. On the one hand a global
10109 // symbol and on the other a local call sequence, but
10110 // don't error for this special case.
10111 // It isn't possible to cheaply verify we have exactly
10112 // such a call. Allow all calls to the same section.
10114 Address code
= value
;
10115 if (gsym
->source() == Symbol::FROM_OBJECT
10116 && gsym
->object() == object
)
10118 unsigned int dest_shndx
= 0;
10119 if (target
->abiversion() < 2)
10121 Address addend
= rela
.get_r_addend();
10122 code
= psymval
->value(object
, addend
);
10123 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10124 &code
, &dest_shndx
);
10127 if (dest_shndx
== 0)
10128 dest_shndx
= gsym
->shndx(&is_ordinary
);
10129 ok
= dest_shndx
== relinfo
->data_shndx
;
10133 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10134 _("call lacks nop, can't restore toc; "
10135 "recompile with -fPIC"));
10141 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10142 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10143 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10144 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
10146 // First instruction of a global dynamic sequence, arg setup insn.
10147 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10148 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10149 enum Got_type got_type
= GOT_TYPE_STANDARD
;
10150 if (tls_type
== tls::TLSOPT_NONE
)
10151 got_type
= GOT_TYPE_TLSGD
;
10152 else if (tls_type
== tls::TLSOPT_TO_IE
)
10153 got_type
= GOT_TYPE_TPREL
;
10154 if (got_type
!= GOT_TYPE_STANDARD
)
10158 gold_assert(gsym
->has_got_offset(got_type
));
10159 value
= gsym
->got_offset(got_type
);
10163 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
10164 value
= object
->local_got_offset(r_sym
, got_type
);
10166 value
-= target
->got_section()->got_base_offset(object
);
10168 if (tls_type
== tls::TLSOPT_TO_IE
)
10170 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10171 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10173 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10174 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10175 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10177 insn
|= 32 << 26; // lwz
10179 insn
|= 58 << 26; // ld
10180 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10182 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10183 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10185 else if (tls_type
== tls::TLSOPT_TO_LE
)
10187 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10188 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10190 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10191 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10192 insn
&= (1 << 26) - (1 << 21); // extract rt
10196 insn
|= addis_0_13
;
10197 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10198 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10199 value
= psymval
->value(object
, rela
.get_r_addend());
10203 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10205 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10206 r_type
= elfcpp::R_POWERPC_NONE
;
10210 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10211 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10212 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10213 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
10215 // First instruction of a local dynamic sequence, arg setup insn.
10216 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10217 if (tls_type
== tls::TLSOPT_NONE
)
10219 value
= target
->tlsld_got_offset();
10220 value
-= target
->got_section()->got_base_offset(object
);
10224 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10225 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10226 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10228 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10229 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10230 insn
&= (1 << 26) - (1 << 21); // extract rt
10234 insn
|= addis_0_13
;
10235 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10236 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10237 value
= dtp_offset
;
10241 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10243 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10244 r_type
= elfcpp::R_POWERPC_NONE
;
10248 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10249 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10250 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10251 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
10253 // Accesses relative to a local dynamic sequence address,
10254 // no optimisation here.
10257 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10258 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10262 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10263 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10265 value
-= target
->got_section()->got_base_offset(object
);
10267 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10268 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10269 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10270 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
10272 // First instruction of initial exec sequence.
10273 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10274 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10275 if (tls_type
== tls::TLSOPT_NONE
)
10279 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10280 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10284 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10285 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10287 value
-= target
->got_section()->got_base_offset(object
);
10291 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10292 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10293 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10295 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10296 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10297 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10301 insn
|= addis_0_13
;
10302 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10303 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10304 value
= psymval
->value(object
, rela
.get_r_addend());
10308 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10310 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10311 r_type
= elfcpp::R_POWERPC_NONE
;
10315 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10316 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10318 // Second instruction of a global dynamic sequence,
10319 // the __tls_get_addr call
10320 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10321 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10322 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10323 if (tls_type
!= tls::TLSOPT_NONE
)
10325 if (tls_type
== tls::TLSOPT_TO_IE
)
10327 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10328 Insn insn
= add_3_3_13
;
10331 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10332 r_type
= elfcpp::R_POWERPC_NONE
;
10336 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10337 Insn insn
= addi_3_3
;
10338 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10339 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10341 value
= psymval
->value(object
, rela
.get_r_addend());
10343 this->skip_next_tls_get_addr_call();
10346 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10347 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10349 // Second instruction of a local dynamic sequence,
10350 // the __tls_get_addr call
10351 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10352 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10353 if (tls_type
== tls::TLSOPT_TO_LE
)
10355 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10356 Insn insn
= addi_3_3
;
10357 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10358 this->skip_next_tls_get_addr_call();
10359 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10361 value
= dtp_offset
;
10364 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10366 // Second instruction of an initial exec sequence
10367 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10368 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10369 if (tls_type
== tls::TLSOPT_TO_LE
)
10371 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10372 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10373 unsigned int reg
= size
== 32 ? 2 : 13;
10374 insn
= at_tls_transform(insn
, reg
);
10375 gold_assert(insn
!= 0);
10376 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10377 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10379 value
= psymval
->value(object
, rela
.get_r_addend());
10382 else if (!has_stub_value
)
10384 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
10385 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
10387 // PLTCALL without plt entry => convert to direct call
10388 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10389 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10390 insn
= (insn
& 1) | b
;
10391 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10393 r_type
= elfcpp::R_PPC_PLTREL24
;
10394 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10395 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
10397 r_type
= elfcpp::R_POWERPC_REL24
;
10399 Address addend
= 0;
10401 && (r_type
== elfcpp::R_PPC_PLTREL24
10402 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10403 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10404 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
10405 addend
= rela
.get_r_addend();
10406 value
= psymval
->value(object
, addend
);
10407 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
10409 if (target
->abiversion() >= 2)
10412 value
+= object
->ppc64_local_entry_offset(gsym
);
10414 value
+= object
->ppc64_local_entry_offset(r_sym
);
10418 unsigned int dest_shndx
;
10419 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10420 &value
, &dest_shndx
);
10423 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
10424 if (max_branch_offset
!= 0
10425 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
10427 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
10429 ? object
->ppc64_needs_toc(gsym
)
10430 : object
->ppc64_needs_toc(r_sym
)))))
10432 Stub_table
<size
, big_endian
>* stub_table
10433 = object
->stub_table(relinfo
->data_shndx
);
10434 if (stub_table
!= NULL
)
10436 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
10437 = stub_table
->find_long_branch_entry(object
, value
);
10440 if (ent
->save_res_
)
10441 value
= (value
- target
->savres_section()->address()
10442 + stub_table
->branch_size());
10444 value
= (stub_table
->stub_address() + stub_table
->plt_size()
10446 has_stub_value
= true;
10454 case elfcpp::R_PPC64_REL24_NOTOC
:
10458 case elfcpp::R_PPC64_REL64
:
10459 case elfcpp::R_POWERPC_REL32
:
10460 case elfcpp::R_POWERPC_REL24
:
10461 case elfcpp::R_PPC_PLTREL24
:
10462 case elfcpp::R_PPC_LOCAL24PC
:
10463 case elfcpp::R_POWERPC_REL16
:
10464 case elfcpp::R_POWERPC_REL16_LO
:
10465 case elfcpp::R_POWERPC_REL16_HI
:
10466 case elfcpp::R_POWERPC_REL16_HA
:
10467 case elfcpp::R_POWERPC_REL16DX_HA
:
10468 case elfcpp::R_PPC64_REL16_HIGH
:
10469 case elfcpp::R_PPC64_REL16_HIGHA
:
10470 case elfcpp::R_PPC64_REL16_HIGHER
:
10471 case elfcpp::R_PPC64_REL16_HIGHERA
:
10472 case elfcpp::R_PPC64_REL16_HIGHEST
:
10473 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10474 case elfcpp::R_POWERPC_REL14
:
10475 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10476 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10477 case elfcpp::R_PPC64_PCREL34
:
10478 case elfcpp::R_PPC64_GOT_PCREL34
:
10479 case elfcpp::R_PPC64_PLT_PCREL34
:
10480 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
10481 case elfcpp::R_PPC64_PCREL28
:
10482 case elfcpp::R_PPC64_REL16_HIGHER34
:
10483 case elfcpp::R_PPC64_REL16_HIGHERA34
:
10484 case elfcpp::R_PPC64_REL16_HIGHEST34
:
10485 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
10489 case elfcpp::R_PPC64_TOC16
:
10490 case elfcpp::R_PPC64_TOC16_LO
:
10491 case elfcpp::R_PPC64_TOC16_HI
:
10492 case elfcpp::R_PPC64_TOC16_HA
:
10493 case elfcpp::R_PPC64_TOC16_DS
:
10494 case elfcpp::R_PPC64_TOC16_LO_DS
:
10495 // Subtract the TOC base address.
10496 value
-= (target
->got_section()->output_section()->address()
10497 + object
->toc_base_offset());
10500 case elfcpp::R_POWERPC_SECTOFF
:
10501 case elfcpp::R_POWERPC_SECTOFF_LO
:
10502 case elfcpp::R_POWERPC_SECTOFF_HI
:
10503 case elfcpp::R_POWERPC_SECTOFF_HA
:
10504 case elfcpp::R_PPC64_SECTOFF_DS
:
10505 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
10507 value
-= os
->address();
10510 case elfcpp::R_PPC64_TPREL16_DS
:
10511 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10512 case elfcpp::R_PPC64_TPREL16_HIGH
:
10513 case elfcpp::R_PPC64_TPREL16_HIGHA
:
10515 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
10518 case elfcpp::R_POWERPC_TPREL16
:
10519 case elfcpp::R_POWERPC_TPREL16_LO
:
10520 case elfcpp::R_POWERPC_TPREL16_HI
:
10521 case elfcpp::R_POWERPC_TPREL16_HA
:
10522 case elfcpp::R_POWERPC_TPREL
:
10523 case elfcpp::R_PPC64_TPREL16_HIGHER
:
10524 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
10525 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10526 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10527 // tls symbol values are relative to tls_segment()->vaddr()
10528 value
-= tp_offset
;
10531 case elfcpp::R_PPC64_DTPREL16_DS
:
10532 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10533 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10534 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10535 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10536 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10538 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
10539 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
10542 case elfcpp::R_POWERPC_DTPREL16
:
10543 case elfcpp::R_POWERPC_DTPREL16_LO
:
10544 case elfcpp::R_POWERPC_DTPREL16_HI
:
10545 case elfcpp::R_POWERPC_DTPREL16_HA
:
10546 case elfcpp::R_POWERPC_DTPREL
:
10547 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10548 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10549 // tls symbol values are relative to tls_segment()->vaddr()
10550 value
-= dtp_offset
;
10553 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10555 value
+= object
->ppc64_local_entry_offset(gsym
);
10557 value
+= object
->ppc64_local_entry_offset(r_sym
);
10564 Insn branch_bit
= 0;
10567 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10568 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10569 branch_bit
= 1 << 21;
10571 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10572 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10574 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10575 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10576 insn
&= ~(1 << 21);
10577 insn
|= branch_bit
;
10578 if (this->is_isa_v2
)
10580 // Set 'a' bit. This is 0b00010 in BO field for branch
10581 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
10582 // for branch on CTR insns (BO == 1a00t or 1a01t).
10583 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10584 insn
|= 0x02 << 21;
10585 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10586 insn
|= 0x08 << 21;
10592 // Invert 'y' bit if not the default.
10593 if (static_cast<Signed_address
>(value
) < 0)
10596 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10600 case elfcpp::R_POWERPC_PLT16_HA
:
10602 && !parameters
->options().output_is_position_independent())
10604 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10605 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10607 // Convert addis to lis.
10608 if ((insn
& (0x3f << 26)) == 15u << 26
10609 && (insn
& (0x1f << 16)) != 0)
10611 insn
&= ~(0x1f << 16);
10612 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10623 ? relative_value_is_known(gsym
)
10624 : relative_value_is_known(psymval
)))
10629 uint64_t pinsn
, pinsn2
;
10636 // Multi-instruction sequences that access the GOT/TOC can
10637 // be optimized, eg.
10638 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
10639 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
10641 // addis ra,r2,0; addi rb,ra,x@toc@l;
10642 // to nop; addi rb,r2,x@toc;
10643 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10644 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10645 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10646 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10647 case elfcpp::R_POWERPC_GOT16_HA
:
10648 case elfcpp::R_PPC64_TOC16_HA
:
10649 if (parameters
->options().toc_optimize())
10651 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10652 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10653 if ((r_type
== elfcpp::R_PPC64_TOC16_HA
10654 && object
->make_toc_relative(target
, &value
))
10655 || (r_type
== elfcpp::R_POWERPC_GOT16_HA
10656 && object
->make_got_relative(target
, psymval
,
10657 rela
.get_r_addend(),
10660 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
10661 == ((15u << 26) | (2 << 16)));
10663 if (((insn
& ((0x3f << 26) | 0x1f << 16))
10664 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
10665 && value
+ 0x8000 < 0x10000)
10667 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10673 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10674 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10675 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10676 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10677 case elfcpp::R_POWERPC_GOT16_LO
:
10678 case elfcpp::R_PPC64_GOT16_LO_DS
:
10679 case elfcpp::R_PPC64_TOC16_LO
:
10680 case elfcpp::R_PPC64_TOC16_LO_DS
:
10681 if (parameters
->options().toc_optimize())
10683 iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10684 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10685 bool changed
= false;
10686 if ((r_type
== elfcpp::R_PPC64_TOC16_LO_DS
10687 && object
->make_toc_relative(target
, &value
))
10688 || (r_type
== elfcpp::R_PPC64_GOT16_LO_DS
10689 && object
->make_got_relative(target
, psymval
,
10690 rela
.get_r_addend(),
10693 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
10694 insn
^= (14u << 26) ^ (58u << 26);
10695 r_type
= elfcpp::R_PPC64_TOC16_LO
;
10698 if (ok_lo_toc_insn(insn
, r_type
)
10699 && value
+ 0x8000 < 0x10000)
10701 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
10703 // Transform addic to addi when we change reg.
10704 insn
&= ~((0x3f << 26) | (0x1f << 16));
10705 insn
|= (14u << 26) | (2 << 16);
10709 insn
&= ~(0x1f << 16);
10715 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10719 case elfcpp::R_PPC64_GOT_PCREL34
:
10720 if (parameters
->options().toc_optimize())
10722 iview
= reinterpret_cast<Insn
*>(view
);
10723 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10725 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10726 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
10727 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
10730 Address relval
= psymval
->value(object
, rela
.get_r_addend());
10732 if (relval
+ (1ULL << 33) < 1ULL << 34)
10735 // Replace with paddi
10736 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
10737 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10738 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10739 pinsn
& 0xffffffff);
10745 case elfcpp::R_PPC64_PCREL34
:
10747 iview
= reinterpret_cast<Insn
*>(view
);
10748 pinsn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10750 pinsn
|= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10751 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
10752 != ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
10753 | (14ULL << 26) /* paddi */))
10757 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10758 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
10759 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
10760 if (relnum
>= reloc_count
- 1)
10763 Reltype
next_rela(preloc
+ reloc_size
);
10764 if ((elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
10765 != elfcpp::R_PPC64_PCREL_OPT
)
10766 || next_rela
.get_r_offset() != rela
.get_r_offset())
10769 Address off
= next_rela
.get_r_addend();
10771 off
= 8; // zero means next insn.
10772 if (off
+ rela
.get_r_offset() + 4 > view_size
)
10775 iview2
= reinterpret_cast<Insn
*>(view
+ off
);
10776 pinsn2
= elfcpp::Swap
<32, big_endian
>::readval(iview2
);
10778 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
10780 if (xlate_pcrel_opt(&pinsn
, &pinsn2
))
10782 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pinsn
>> 32);
10783 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1,
10784 pinsn
& 0xffffffff);
10785 elfcpp::Swap
<32, big_endian
>::writeval(iview2
, pinsn2
>> 32);
10790 case elfcpp::R_POWERPC_TPREL16_HA
:
10791 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10793 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10794 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10795 if ((insn
& ((0x3f << 26) | 0x1f << 16))
10796 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
10800 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10806 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10808 // R_PPC_TLSGD, R_PPC_TLSLD
10811 case elfcpp::R_POWERPC_TPREL16_LO
:
10812 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10814 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10815 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10816 insn
&= ~(0x1f << 16);
10817 insn
|= (size
== 32 ? 2 : 13) << 16;
10818 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10822 case elfcpp::R_PPC64_ENTRY
:
10823 value
= (target
->got_section()->output_section()->address()
10824 + object
->toc_base_offset());
10825 if (value
+ 0x80008000 <= 0xffffffff
10826 && !parameters
->options().output_is_position_independent())
10828 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10829 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10830 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10832 if ((insn1
& ~0xfffc) == ld_2_12
10833 && insn2
== add_2_2_12
)
10835 insn1
= lis_2
+ ha(value
);
10836 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10837 insn2
= addi_2_2
+ l(value
);
10838 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10845 if (value
+ 0x80008000 <= 0xffffffff)
10847 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10848 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10849 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10851 if ((insn1
& ~0xfffc) == ld_2_12
10852 && insn2
== add_2_2_12
)
10854 insn1
= addis_2_12
+ ha(value
);
10855 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10856 insn2
= addi_2_2
+ l(value
);
10857 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10864 case elfcpp::R_POWERPC_REL16_LO
:
10865 // If we are generating a non-PIC executable, edit
10866 // 0: addis 2,12,.TOC.-0b@ha
10867 // addi 2,2,.TOC.-0b@l
10868 // used by ELFv2 global entry points to set up r2, to
10870 // addi 2,2,.TOC.@l
10871 // if .TOC. is in range. */
10872 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
10875 && target
->abiversion() >= 2
10876 && !parameters
->options().output_is_position_independent()
10877 && rela
.get_r_addend() == d_offset
+ 4
10879 && strcmp(gsym
->name(), ".TOC.") == 0)
10881 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10882 Reltype
prev_rela(preloc
- reloc_size
);
10883 if ((prev_rela
.get_r_info()
10884 == elfcpp::elf_r_info
<size
>(r_sym
,
10885 elfcpp::R_POWERPC_REL16_HA
))
10886 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
10887 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
10889 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10890 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
10891 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10893 if ((insn1
& 0xffff0000) == addis_2_12
10894 && (insn2
& 0xffff0000) == addi_2_2
)
10896 insn1
= lis_2
+ ha(value
+ address
- 4);
10897 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
10898 insn2
= addi_2_2
+ l(value
+ address
- 4);
10899 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
10902 relinfo
->rr
->set_strategy(relnum
- 1,
10903 Relocatable_relocs::RELOC_SPECIAL
);
10904 relinfo
->rr
->set_strategy(relnum
,
10905 Relocatable_relocs::RELOC_SPECIAL
);
10915 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
10916 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
10919 case elfcpp::R_POWERPC_ADDR32
:
10920 case elfcpp::R_POWERPC_UADDR32
:
10922 overflow
= Reloc::CHECK_BITFIELD
;
10925 case elfcpp::R_POWERPC_REL32
:
10926 case elfcpp::R_POWERPC_REL16DX_HA
:
10928 overflow
= Reloc::CHECK_SIGNED
;
10931 case elfcpp::R_POWERPC_UADDR16
:
10932 overflow
= Reloc::CHECK_BITFIELD
;
10935 case elfcpp::R_POWERPC_ADDR16
:
10936 // We really should have three separate relocations,
10937 // one for 16-bit data, one for insns with 16-bit signed fields,
10938 // and one for insns with 16-bit unsigned fields.
10939 overflow
= Reloc::CHECK_BITFIELD
;
10940 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
10941 overflow
= Reloc::CHECK_LOW_INSN
;
10944 case elfcpp::R_POWERPC_ADDR16_HI
:
10945 case elfcpp::R_POWERPC_ADDR16_HA
:
10946 case elfcpp::R_POWERPC_GOT16_HI
:
10947 case elfcpp::R_POWERPC_GOT16_HA
:
10948 case elfcpp::R_POWERPC_PLT16_HI
:
10949 case elfcpp::R_POWERPC_PLT16_HA
:
10950 case elfcpp::R_POWERPC_SECTOFF_HI
:
10951 case elfcpp::R_POWERPC_SECTOFF_HA
:
10952 case elfcpp::R_PPC64_TOC16_HI
:
10953 case elfcpp::R_PPC64_TOC16_HA
:
10954 case elfcpp::R_PPC64_PLTGOT16_HI
:
10955 case elfcpp::R_PPC64_PLTGOT16_HA
:
10956 case elfcpp::R_POWERPC_TPREL16_HI
:
10957 case elfcpp::R_POWERPC_TPREL16_HA
:
10958 case elfcpp::R_POWERPC_DTPREL16_HI
:
10959 case elfcpp::R_POWERPC_DTPREL16_HA
:
10960 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
10961 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10962 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
10963 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10964 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
10965 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10966 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
10967 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10968 case elfcpp::R_POWERPC_REL16_HI
:
10969 case elfcpp::R_POWERPC_REL16_HA
:
10971 overflow
= Reloc::CHECK_HIGH_INSN
;
10974 case elfcpp::R_POWERPC_REL16
:
10975 case elfcpp::R_PPC64_TOC16
:
10976 case elfcpp::R_POWERPC_GOT16
:
10977 case elfcpp::R_POWERPC_SECTOFF
:
10978 case elfcpp::R_POWERPC_TPREL16
:
10979 case elfcpp::R_POWERPC_DTPREL16
:
10980 case elfcpp::R_POWERPC_GOT_TLSGD16
:
10981 case elfcpp::R_POWERPC_GOT_TLSLD16
:
10982 case elfcpp::R_POWERPC_GOT_TPREL16
:
10983 case elfcpp::R_POWERPC_GOT_DTPREL16
:
10984 overflow
= Reloc::CHECK_LOW_INSN
;
10987 case elfcpp::R_PPC64_REL24_NOTOC
:
10991 case elfcpp::R_POWERPC_ADDR24
:
10992 case elfcpp::R_POWERPC_ADDR14
:
10993 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10994 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10995 case elfcpp::R_PPC64_ADDR16_DS
:
10996 case elfcpp::R_POWERPC_REL24
:
10997 case elfcpp::R_PPC_PLTREL24
:
10998 case elfcpp::R_PPC_LOCAL24PC
:
10999 case elfcpp::R_PPC64_TPREL16_DS
:
11000 case elfcpp::R_PPC64_DTPREL16_DS
:
11001 case elfcpp::R_PPC64_TOC16_DS
:
11002 case elfcpp::R_PPC64_GOT16_DS
:
11003 case elfcpp::R_PPC64_SECTOFF_DS
:
11004 case elfcpp::R_POWERPC_REL14
:
11005 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11006 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11007 case elfcpp::R_PPC64_D34
:
11008 case elfcpp::R_PPC64_PCREL34
:
11009 case elfcpp::R_PPC64_GOT_PCREL34
:
11010 case elfcpp::R_PPC64_PLT_PCREL34
:
11011 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11012 case elfcpp::R_PPC64_D28
:
11013 case elfcpp::R_PPC64_PCREL28
:
11014 overflow
= Reloc::CHECK_SIGNED
;
11018 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
11021 if (overflow
== Reloc::CHECK_LOW_INSN
11022 || overflow
== Reloc::CHECK_HIGH_INSN
)
11024 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11026 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
11027 overflow
= Reloc::CHECK_BITFIELD
;
11028 else if (overflow
== Reloc::CHECK_LOW_INSN
11029 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
11030 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
11031 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
11032 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
11033 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
11034 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
11035 overflow
= Reloc::CHECK_UNSIGNED
;
11037 overflow
= Reloc::CHECK_SIGNED
;
11040 bool maybe_dq_reloc
= false;
11041 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
11042 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
11045 case elfcpp::R_POWERPC_NONE
:
11046 case elfcpp::R_POWERPC_TLS
:
11047 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
11048 case elfcpp::R_POWERPC_GNU_VTENTRY
:
11049 case elfcpp::R_POWERPC_PLTSEQ
:
11050 case elfcpp::R_POWERPC_PLTCALL
:
11051 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
11052 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
11053 case elfcpp::R_PPC64_PCREL_OPT
:
11056 case elfcpp::R_PPC64_ADDR64
:
11057 case elfcpp::R_PPC64_REL64
:
11058 case elfcpp::R_PPC64_TOC
:
11059 case elfcpp::R_PPC64_ADDR64_LOCAL
:
11060 Reloc::addr64(view
, value
);
11063 case elfcpp::R_POWERPC_TPREL
:
11064 case elfcpp::R_POWERPC_DTPREL
:
11066 Reloc::addr64(view
, value
);
11068 status
= Reloc::addr32(view
, value
, overflow
);
11071 case elfcpp::R_PPC64_UADDR64
:
11072 Reloc::addr64_u(view
, value
);
11075 case elfcpp::R_POWERPC_ADDR32
:
11076 status
= Reloc::addr32(view
, value
, overflow
);
11079 case elfcpp::R_POWERPC_REL32
:
11080 case elfcpp::R_POWERPC_UADDR32
:
11081 status
= Reloc::addr32_u(view
, value
, overflow
);
11084 case elfcpp::R_PPC64_REL24_NOTOC
:
11086 goto unsupp
; // R_PPC_EMB_RELSDA
11088 case elfcpp::R_POWERPC_ADDR24
:
11089 case elfcpp::R_POWERPC_REL24
:
11090 case elfcpp::R_PPC_PLTREL24
:
11091 case elfcpp::R_PPC_LOCAL24PC
:
11092 status
= Reloc::addr24(view
, value
, overflow
);
11095 case elfcpp::R_POWERPC_GOT_DTPREL16
:
11096 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
11097 case elfcpp::R_POWERPC_GOT_TPREL16
:
11098 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
11101 // On ppc64 these are all ds form
11102 maybe_dq_reloc
= true;
11106 case elfcpp::R_POWERPC_ADDR16
:
11107 case elfcpp::R_POWERPC_REL16
:
11108 case elfcpp::R_PPC64_TOC16
:
11109 case elfcpp::R_POWERPC_GOT16
:
11110 case elfcpp::R_POWERPC_SECTOFF
:
11111 case elfcpp::R_POWERPC_TPREL16
:
11112 case elfcpp::R_POWERPC_DTPREL16
:
11113 case elfcpp::R_POWERPC_GOT_TLSGD16
:
11114 case elfcpp::R_POWERPC_GOT_TLSLD16
:
11115 case elfcpp::R_POWERPC_ADDR16_LO
:
11116 case elfcpp::R_POWERPC_REL16_LO
:
11117 case elfcpp::R_PPC64_TOC16_LO
:
11118 case elfcpp::R_POWERPC_GOT16_LO
:
11119 case elfcpp::R_POWERPC_PLT16_LO
:
11120 case elfcpp::R_POWERPC_SECTOFF_LO
:
11121 case elfcpp::R_POWERPC_TPREL16_LO
:
11122 case elfcpp::R_POWERPC_DTPREL16_LO
:
11123 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
11124 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
11126 status
= Reloc::addr16(view
, value
, overflow
);
11128 maybe_dq_reloc
= true;
11131 case elfcpp::R_POWERPC_UADDR16
:
11132 status
= Reloc::addr16_u(view
, value
, overflow
);
11135 case elfcpp::R_PPC64_ADDR16_HIGH
:
11136 case elfcpp::R_PPC64_TPREL16_HIGH
:
11137 case elfcpp::R_PPC64_DTPREL16_HIGH
:
11139 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
11142 case elfcpp::R_POWERPC_ADDR16_HI
:
11143 case elfcpp::R_POWERPC_REL16_HI
:
11144 case elfcpp::R_PPC64_REL16_HIGH
:
11145 case elfcpp::R_PPC64_TOC16_HI
:
11146 case elfcpp::R_POWERPC_GOT16_HI
:
11147 case elfcpp::R_POWERPC_PLT16_HI
:
11148 case elfcpp::R_POWERPC_SECTOFF_HI
:
11149 case elfcpp::R_POWERPC_TPREL16_HI
:
11150 case elfcpp::R_POWERPC_DTPREL16_HI
:
11151 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
11152 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
11153 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
11154 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
11155 Reloc::addr16_hi(view
, value
);
11158 case elfcpp::R_PPC64_ADDR16_HIGHA
:
11159 case elfcpp::R_PPC64_TPREL16_HIGHA
:
11160 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
11162 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
11165 case elfcpp::R_POWERPC_ADDR16_HA
:
11166 case elfcpp::R_POWERPC_REL16_HA
:
11167 case elfcpp::R_PPC64_REL16_HIGHA
:
11168 case elfcpp::R_PPC64_TOC16_HA
:
11169 case elfcpp::R_POWERPC_GOT16_HA
:
11170 case elfcpp::R_POWERPC_PLT16_HA
:
11171 case elfcpp::R_POWERPC_SECTOFF_HA
:
11172 case elfcpp::R_POWERPC_TPREL16_HA
:
11173 case elfcpp::R_POWERPC_DTPREL16_HA
:
11174 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
11175 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
11176 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
11177 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
11178 Reloc::addr16_ha(view
, value
);
11181 case elfcpp::R_POWERPC_REL16DX_HA
:
11182 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
11185 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
11187 // R_PPC_EMB_NADDR16_LO
11190 case elfcpp::R_PPC64_ADDR16_HIGHER
:
11191 case elfcpp::R_PPC64_REL16_HIGHER
:
11192 case elfcpp::R_PPC64_TPREL16_HIGHER
:
11193 Reloc::addr16_hi2(view
, value
);
11196 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
11198 // R_PPC_EMB_NADDR16_HI
11201 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
11202 case elfcpp::R_PPC64_REL16_HIGHERA
:
11203 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
11204 Reloc::addr16_ha2(view
, value
);
11207 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
11209 // R_PPC_EMB_NADDR16_HA
11212 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
11213 case elfcpp::R_PPC64_REL16_HIGHEST
:
11214 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
11215 Reloc::addr16_hi3(view
, value
);
11218 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
11220 // R_PPC_EMB_SDAI16
11223 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
11224 case elfcpp::R_PPC64_REL16_HIGHESTA
:
11225 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
11226 Reloc::addr16_ha3(view
, value
);
11229 case elfcpp::R_PPC64_DTPREL16_DS
:
11230 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
11232 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
11235 case elfcpp::R_PPC64_TPREL16_DS
:
11236 case elfcpp::R_PPC64_TPREL16_LO_DS
:
11238 // R_PPC_TLSGD, R_PPC_TLSLD
11241 case elfcpp::R_PPC64_ADDR16_DS
:
11242 case elfcpp::R_PPC64_ADDR16_LO_DS
:
11243 case elfcpp::R_PPC64_TOC16_DS
:
11244 case elfcpp::R_PPC64_TOC16_LO_DS
:
11245 case elfcpp::R_PPC64_GOT16_DS
:
11246 case elfcpp::R_PPC64_GOT16_LO_DS
:
11247 case elfcpp::R_PPC64_PLT16_LO_DS
:
11248 case elfcpp::R_PPC64_SECTOFF_DS
:
11249 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
11250 maybe_dq_reloc
= true;
11253 case elfcpp::R_POWERPC_ADDR14
:
11254 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11255 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11256 case elfcpp::R_POWERPC_REL14
:
11257 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11258 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11259 status
= Reloc::addr14(view
, value
, overflow
);
11262 case elfcpp::R_POWERPC_COPY
:
11263 case elfcpp::R_POWERPC_GLOB_DAT
:
11264 case elfcpp::R_POWERPC_JMP_SLOT
:
11265 case elfcpp::R_POWERPC_RELATIVE
:
11266 case elfcpp::R_POWERPC_DTPMOD
:
11267 case elfcpp::R_PPC64_JMP_IREL
:
11268 case elfcpp::R_POWERPC_IRELATIVE
:
11269 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11270 _("unexpected reloc %u in object file"),
11274 case elfcpp::R_PPC64_TOCSAVE
:
11280 Symbol_location loc
;
11281 loc
.object
= relinfo
->object
;
11282 loc
.shndx
= relinfo
->data_shndx
;
11283 loc
.offset
= rela
.get_r_offset();
11284 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11285 if (p
!= target
->tocsave_loc().end())
11287 // If we've generated plt calls using this tocsave, then
11288 // the nop needs to be changed to save r2.
11289 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11290 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11291 elfcpp::Swap
<32, big_endian
>::
11292 writeval(iview
, std_2_1
+ target
->stk_toc());
11297 case elfcpp::R_PPC_EMB_SDA2I16
:
11298 case elfcpp::R_PPC_EMB_SDA2REL
:
11301 // R_PPC64_TLSGD, R_PPC64_TLSLD
11304 case elfcpp::R_PPC64_D34
:
11305 case elfcpp::R_PPC64_D34_LO
:
11306 case elfcpp::R_PPC64_PCREL34
:
11307 case elfcpp::R_PPC64_GOT_PCREL34
:
11308 case elfcpp::R_PPC64_PLT_PCREL34
:
11309 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11312 status
= Reloc::addr34(view
, value
, overflow
);
11315 case elfcpp::R_PPC64_D34_HI30
:
11318 Reloc::addr34_hi(view
, value
);
11321 case elfcpp::R_PPC64_D34_HA30
:
11324 Reloc::addr34_ha(view
, value
);
11327 case elfcpp::R_PPC64_D28
:
11328 case elfcpp::R_PPC64_PCREL28
:
11331 status
= Reloc::addr28(view
, value
, overflow
);
11334 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11335 case elfcpp::R_PPC64_REL16_HIGHER34
:
11338 Reloc::addr16_higher34(view
, value
);
11341 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11342 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11345 Reloc::addr16_highera34(view
, value
);
11348 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11349 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11352 Reloc::addr16_highest34(view
, value
);
11355 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
11356 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11359 Reloc::addr16_highesta34(view
, value
);
11362 case elfcpp::R_POWERPC_PLT32
:
11363 case elfcpp::R_POWERPC_PLTREL32
:
11364 case elfcpp::R_PPC_SDAREL16
:
11365 case elfcpp::R_POWERPC_ADDR30
:
11366 case elfcpp::R_PPC64_PLT64
:
11367 case elfcpp::R_PPC64_PLTREL64
:
11368 case elfcpp::R_PPC64_PLTGOT16
:
11369 case elfcpp::R_PPC64_PLTGOT16_LO
:
11370 case elfcpp::R_PPC64_PLTGOT16_HI
:
11371 case elfcpp::R_PPC64_PLTGOT16_HA
:
11372 case elfcpp::R_PPC64_PLTGOT16_DS
:
11373 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
11374 case elfcpp::R_PPC_TOC16
:
11377 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11378 _("unsupported reloc %u"),
11383 if (maybe_dq_reloc
)
11386 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11388 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
11389 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
11390 && (insn
& 3) == 1))
11391 status
= Reloc::addr16_dq(view
, value
, overflow
);
11392 else if (size
== 64
11393 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
11394 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
11395 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
11396 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
11397 status
= Reloc::addr16_ds(view
, value
, overflow
);
11399 status
= Reloc::addr16(view
, value
, overflow
);
11402 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
11405 && gsym
->is_undefined()
11406 && is_branch_reloc
<size
>(r_type
))))
11408 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11409 _("relocation overflow"));
11410 if (has_stub_value
)
11411 gold_info(_("try relinking with a smaller --stub-group-size"));
11417 // Relocate section data.
11419 template<int size
, bool big_endian
>
11421 Target_powerpc
<size
, big_endian
>::relocate_section(
11422 const Relocate_info
<size
, big_endian
>* relinfo
,
11423 unsigned int sh_type
,
11424 const unsigned char* prelocs
,
11425 size_t reloc_count
,
11426 Output_section
* output_section
,
11427 bool needs_special_offset_handling
,
11428 unsigned char* view
,
11430 section_size_type view_size
,
11431 const Reloc_symbol_changes
* reloc_symbol_changes
)
11433 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
11434 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
11435 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
11436 Powerpc_comdat_behavior
;
11437 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11440 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11442 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
11443 Powerpc_comdat_behavior
, Classify_reloc
>(
11449 needs_special_offset_handling
,
11453 reloc_symbol_changes
);
11456 template<int size
, bool big_endian
>
11457 class Powerpc_scan_relocatable_reloc
11460 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11461 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11462 static const int sh_type
= elfcpp::SHT_RELA
;
11464 // Return the symbol referred to by the relocation.
11465 static inline unsigned int
11466 get_r_sym(const Reltype
* reloc
)
11467 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
11469 // Return the type of the relocation.
11470 static inline unsigned int
11471 get_r_type(const Reltype
* reloc
)
11472 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
11474 // Return the strategy to use for a local symbol which is not a
11475 // section symbol, given the relocation type.
11476 inline Relocatable_relocs::Reloc_strategy
11477 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
11479 if (r_type
== 0 && r_sym
== 0)
11480 return Relocatable_relocs::RELOC_DISCARD
;
11481 return Relocatable_relocs::RELOC_COPY
;
11484 // Return the strategy to use for a local symbol which is a section
11485 // symbol, given the relocation type.
11486 inline Relocatable_relocs::Reloc_strategy
11487 local_section_strategy(unsigned int, Relobj
*)
11489 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
11492 // Return the strategy to use for a global symbol, given the
11493 // relocation type, the object, and the symbol index.
11494 inline Relocatable_relocs::Reloc_strategy
11495 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
11498 && (r_type
== elfcpp::R_PPC_PLTREL24
11499 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11500 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11501 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
11502 return Relocatable_relocs::RELOC_SPECIAL
;
11503 return Relocatable_relocs::RELOC_COPY
;
11507 // Scan the relocs during a relocatable link.
11509 template<int size
, bool big_endian
>
11511 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
11512 Symbol_table
* symtab
,
11514 Sized_relobj_file
<size
, big_endian
>* object
,
11515 unsigned int data_shndx
,
11516 unsigned int sh_type
,
11517 const unsigned char* prelocs
,
11518 size_t reloc_count
,
11519 Output_section
* output_section
,
11520 bool needs_special_offset_handling
,
11521 size_t local_symbol_count
,
11522 const unsigned char* plocal_symbols
,
11523 Relocatable_relocs
* rr
)
11525 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
11527 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11529 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
11537 needs_special_offset_handling
,
11538 local_symbol_count
,
11543 // Scan the relocs for --emit-relocs.
11545 template<int size
, bool big_endian
>
11547 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
11548 Symbol_table
* symtab
,
11550 Sized_relobj_file
<size
, big_endian
>* object
,
11551 unsigned int data_shndx
,
11552 unsigned int sh_type
,
11553 const unsigned char* prelocs
,
11554 size_t reloc_count
,
11555 Output_section
* output_section
,
11556 bool needs_special_offset_handling
,
11557 size_t local_symbol_count
,
11558 const unsigned char* plocal_syms
,
11559 Relocatable_relocs
* rr
)
11561 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11563 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
11564 Emit_relocs_strategy
;
11566 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11568 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
11576 needs_special_offset_handling
,
11577 local_symbol_count
,
11582 // Emit relocations for a section.
11583 // This is a modified version of the function by the same name in
11584 // target-reloc.h. Using relocate_special_relocatable for
11585 // R_PPC_PLTREL24 would require duplication of the entire body of the
11586 // loop, so we may as well duplicate the whole thing.
11588 template<int size
, bool big_endian
>
11590 Target_powerpc
<size
, big_endian
>::relocate_relocs(
11591 const Relocate_info
<size
, big_endian
>* relinfo
,
11592 unsigned int sh_type
,
11593 const unsigned char* prelocs
,
11594 size_t reloc_count
,
11595 Output_section
* output_section
,
11596 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
11598 Address view_address
,
11600 unsigned char* reloc_view
,
11601 section_size_type reloc_view_size
)
11603 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11605 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11606 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
11607 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11608 // Offset from start of insn to d-field reloc.
11609 const int d_offset
= big_endian
? 2 : 0;
11611 Powerpc_relobj
<size
, big_endian
>* const object
11612 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
11613 const unsigned int local_count
= object
->local_symbol_count();
11614 unsigned int got2_shndx
= object
->got2_shndx();
11615 Address got2_addend
= 0;
11616 if (got2_shndx
!= 0)
11618 got2_addend
= object
->get_output_section_offset(got2_shndx
);
11619 gold_assert(got2_addend
!= invalid_address
);
11622 const bool relocatable
= parameters
->options().relocatable();
11624 unsigned char* pwrite
= reloc_view
;
11625 bool zap_next
= false;
11626 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
11628 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
11629 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
11632 Reltype
reloc(prelocs
);
11633 Reltype_write
reloc_write(pwrite
);
11635 Address offset
= reloc
.get_r_offset();
11636 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
11637 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
11638 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
11639 const unsigned int orig_r_sym
= r_sym
;
11640 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
11641 = reloc
.get_r_addend();
11642 const Symbol
* gsym
= NULL
;
11646 // We could arrange to discard these and other relocs for
11647 // tls optimised sequences in the strategy methods, but for
11648 // now do as BFD ld does.
11649 r_type
= elfcpp::R_POWERPC_NONE
;
11653 // Get the new symbol index.
11654 Output_section
* os
= NULL
;
11655 if (r_sym
< local_count
)
11659 case Relocatable_relocs::RELOC_COPY
:
11660 case Relocatable_relocs::RELOC_SPECIAL
:
11663 r_sym
= object
->symtab_index(r_sym
);
11664 gold_assert(r_sym
!= -1U);
11668 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
11670 // We are adjusting a section symbol. We need to find
11671 // the symbol table index of the section symbol for
11672 // the output section corresponding to input section
11673 // in which this symbol is defined.
11674 gold_assert(r_sym
< local_count
);
11676 unsigned int shndx
=
11677 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
11678 gold_assert(is_ordinary
);
11679 os
= object
->output_section(shndx
);
11680 gold_assert(os
!= NULL
);
11681 gold_assert(os
->needs_symtab_index());
11682 r_sym
= os
->symtab_index();
11687 gold_unreachable();
11692 gsym
= object
->global_symbol(r_sym
);
11693 gold_assert(gsym
!= NULL
);
11694 if (gsym
->is_forwarder())
11695 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
11697 gold_assert(gsym
->has_symtab_index());
11698 r_sym
= gsym
->symtab_index();
11701 // Get the new offset--the location in the output section where
11702 // this relocation should be applied.
11703 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11704 offset
+= offset_in_output_section
;
11707 section_offset_type sot_offset
=
11708 convert_types
<section_offset_type
, Address
>(offset
);
11709 section_offset_type new_sot_offset
=
11710 output_section
->output_offset(object
, relinfo
->data_shndx
,
11712 gold_assert(new_sot_offset
!= -1);
11713 offset
= new_sot_offset
;
11716 // In an object file, r_offset is an offset within the section.
11717 // In an executable or dynamic object, generated by
11718 // --emit-relocs, r_offset is an absolute address.
11721 offset
+= view_address
;
11722 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11723 offset
-= offset_in_output_section
;
11726 // Handle the reloc addend based on the strategy.
11727 if (strategy
== Relocatable_relocs::RELOC_COPY
)
11729 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
11731 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
11732 addend
= psymval
->value(object
, addend
);
11733 // In a relocatable link, the symbol value is relative to
11734 // the start of the output section. For a non-relocatable
11735 // link, we need to adjust the addend.
11738 gold_assert(os
!= NULL
);
11739 addend
-= os
->address();
11742 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
11746 if (addend
>= 32768)
11747 addend
+= got2_addend
;
11749 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
11751 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
11752 addend
-= d_offset
;
11754 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
11756 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
11757 addend
-= d_offset
+ 4;
11761 gold_unreachable();
11765 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11766 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
11767 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
11768 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
11770 // First instruction of a global dynamic sequence,
11772 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11773 switch (this->optimize_tls_gd(final
))
11775 case tls::TLSOPT_TO_IE
:
11776 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11777 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11779 case tls::TLSOPT_TO_LE
:
11780 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11781 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11782 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11785 r_type
= elfcpp::R_POWERPC_NONE
;
11786 offset
-= d_offset
;
11793 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11794 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11795 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11796 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
11798 // First instruction of a local dynamic sequence,
11800 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11802 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11803 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11805 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11806 const Output_section
* os
= relinfo
->layout
->tls_segment()
11808 gold_assert(os
!= NULL
);
11809 gold_assert(os
->needs_symtab_index());
11810 r_sym
= os
->symtab_index();
11811 addend
= dtp_offset
;
11815 r_type
= elfcpp::R_POWERPC_NONE
;
11816 offset
-= d_offset
;
11820 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11821 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11822 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11823 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
11825 // First instruction of initial exec sequence.
11826 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11827 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11829 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11830 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11831 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11834 r_type
= elfcpp::R_POWERPC_NONE
;
11835 offset
-= d_offset
;
11839 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11840 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11842 // Second instruction of a global dynamic sequence,
11843 // the __tls_get_addr call
11844 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11845 switch (this->optimize_tls_gd(final
))
11847 case tls::TLSOPT_TO_IE
:
11848 r_type
= elfcpp::R_POWERPC_NONE
;
11851 case tls::TLSOPT_TO_LE
:
11852 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11853 offset
+= d_offset
;
11860 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11861 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11863 // Second instruction of a local dynamic sequence,
11864 // the __tls_get_addr call
11865 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11867 const Output_section
* os
= relinfo
->layout
->tls_segment()
11869 gold_assert(os
!= NULL
);
11870 gold_assert(os
->needs_symtab_index());
11871 r_sym
= os
->symtab_index();
11872 addend
= dtp_offset
;
11873 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11874 offset
+= d_offset
;
11878 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11880 // Second instruction of an initial exec sequence
11881 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11882 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11884 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11885 offset
+= d_offset
;
11890 reloc_write
.put_r_offset(offset
);
11891 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
11892 reloc_write
.put_r_addend(addend
);
11894 pwrite
+= reloc_size
;
11897 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
11898 == reloc_view_size
);
11901 // Return the value to use for a dynamic symbol which requires special
11902 // treatment. This is how we support equality comparisons of function
11903 // pointers across shared library boundaries, as described in the
11904 // processor specific ABI supplement.
11906 template<int size
, bool big_endian
>
11908 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
11912 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
11913 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11914 p
!= this->stub_tables_
.end();
11917 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11918 = (*p
)->find_plt_call_entry(gsym
);
11920 return (*p
)->stub_address() + ent
->off_
;
11923 else if (this->abiversion() >= 2)
11925 Address off
= this->glink_section()->find_global_entry(gsym
);
11926 if (off
!= invalid_address
)
11927 return this->glink_section()->global_entry_address() + off
;
11929 gold_unreachable();
11932 // Return the PLT address to use for a local symbol.
11933 template<int size
, bool big_endian
>
11935 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
11936 const Relobj
* object
,
11937 unsigned int symndx
) const
11941 const Sized_relobj
<size
, big_endian
>* relobj
11942 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
11943 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11944 p
!= this->stub_tables_
.end();
11947 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11948 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
11950 return (*p
)->stub_address() + ent
->off_
;
11953 gold_unreachable();
11956 // Return the PLT address to use for a global symbol.
11957 template<int size
, bool big_endian
>
11959 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
11960 const Symbol
* gsym
) const
11964 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11965 p
!= this->stub_tables_
.end();
11968 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11969 = (*p
)->find_plt_call_entry(gsym
);
11971 return (*p
)->stub_address() + ent
->off_
;
11974 else if (this->abiversion() >= 2)
11976 Address off
= this->glink_section()->find_global_entry(gsym
);
11977 if (off
!= invalid_address
)
11978 return this->glink_section()->global_entry_address() + off
;
11980 gold_unreachable();
11983 // Return the offset to use for the GOT_INDX'th got entry which is
11984 // for a local tls symbol specified by OBJECT, SYMNDX.
11985 template<int size
, bool big_endian
>
11987 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
11988 const Relobj
* object
,
11989 unsigned int symndx
,
11990 unsigned int got_indx
) const
11992 const Powerpc_relobj
<size
, big_endian
>* ppc_object
11993 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
11994 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
11996 for (Got_type got_type
= GOT_TYPE_TLSGD
;
11997 got_type
<= GOT_TYPE_TPREL
;
11998 got_type
= Got_type(got_type
+ 1))
11999 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
12001 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
12002 if (got_type
== GOT_TYPE_TLSGD
)
12004 if (off
== got_indx
* (size
/ 8))
12006 if (got_type
== GOT_TYPE_TPREL
)
12009 return -dtp_offset
;
12013 gold_unreachable();
12016 // Return the offset to use for the GOT_INDX'th got entry which is
12017 // for global tls symbol GSYM.
12018 template<int size
, bool big_endian
>
12020 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
12022 unsigned int got_indx
) const
12024 if (gsym
->type() == elfcpp::STT_TLS
)
12026 for (Got_type got_type
= GOT_TYPE_TLSGD
;
12027 got_type
<= GOT_TYPE_TPREL
;
12028 got_type
= Got_type(got_type
+ 1))
12029 if (gsym
->has_got_offset(got_type
))
12031 unsigned int off
= gsym
->got_offset(got_type
);
12032 if (got_type
== GOT_TYPE_TLSGD
)
12034 if (off
== got_indx
* (size
/ 8))
12036 if (got_type
== GOT_TYPE_TPREL
)
12039 return -dtp_offset
;
12043 gold_unreachable();
12046 // The selector for powerpc object files.
12048 template<int size
, bool big_endian
>
12049 class Target_selector_powerpc
: public Target_selector
12052 Target_selector_powerpc()
12053 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
12056 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
12057 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
12059 ? (big_endian
? "elf64ppc" : "elf64lppc")
12060 : (big_endian
? "elf32ppc" : "elf32lppc")))
12064 do_instantiate_target()
12065 { return new Target_powerpc
<size
, big_endian
>(); }
12068 Target_selector_powerpc
<32, true> target_selector_ppc32
;
12069 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
12070 Target_selector_powerpc
<64, true> target_selector_ppc64
;
12071 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
12073 // Instantiate these constants for -O0
12074 template<int size
, bool big_endian
>
12075 const typename Output_data_glink
<size
, big_endian
>::Address
12076 Output_data_glink
<size
, big_endian
>::invalid_address
;
12077 template<int size
, bool big_endian
>
12078 const typename Stub_table
<size
, big_endian
>::Address
12079 Stub_table
<size
, big_endian
>::invalid_address
;
12080 template<int size
, bool big_endian
>
12081 const typename Target_powerpc
<size
, big_endian
>::Address
12082 Target_powerpc
<size
, big_endian
>::invalid_address
;
12084 } // End anonymous namespace.