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
,
252 // Perform the Sized_relobj_file method, then set up opd info from
255 do_read_relocs(Read_relocs_data
*);
258 do_find_special_sections(Read_symbols_data
* sd
);
260 // Adjust this local symbol value. Return false if the symbol
261 // should be discarded from the output file.
263 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
265 if (size
== 64 && this->opd_shndx() != 0)
268 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
270 if (this->get_opd_discard(lv
->input_value()))
278 { return &this->access_from_map_
; }
280 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
281 // section at DST_OFF.
283 add_reference(Relobj
* src_obj
,
284 unsigned int src_indx
,
285 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
287 Section_id
src_id(src_obj
, src_indx
);
288 this->access_from_map_
[dst_off
].insert(src_id
);
291 // Add a reference to the code section specified by the .opd entry
294 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
296 size_t ndx
= this->opd_ent_ndx(dst_off
);
297 if (ndx
>= this->opd_ent_
.size())
298 this->opd_ent_
.resize(ndx
+ 1);
299 this->opd_ent_
[ndx
].gc_mark
= true;
303 process_gc_mark(Symbol_table
* symtab
)
305 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
306 if (this->opd_ent_
[i
].gc_mark
)
308 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
309 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
313 // Return offset in output GOT section that this object will use
314 // as a TOC pointer. Won't be just a constant with multi-toc support.
316 toc_base_offset() const
320 set_has_small_toc_reloc()
321 { has_small_toc_reloc_
= true; }
324 has_small_toc_reloc() const
325 { return has_small_toc_reloc_
; }
328 set_has_14bit_branch(unsigned int shndx
)
330 if (shndx
>= this->has14_
.size())
331 this->has14_
.resize(shndx
+ 1);
332 this->has14_
[shndx
] = true;
336 has_14bit_branch(unsigned int shndx
) const
337 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
340 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
342 if (shndx
>= this->stub_table_index_
.size())
343 this->stub_table_index_
.resize(shndx
+ 1, -1);
344 this->stub_table_index_
[shndx
] = stub_index
;
347 Stub_table
<size
, big_endian
>*
348 stub_table(unsigned int shndx
)
350 if (shndx
< this->stub_table_index_
.size())
352 Target_powerpc
<size
, big_endian
>* target
353 = static_cast<Target_powerpc
<size
, big_endian
>*>(
354 parameters
->sized_target
<size
, big_endian
>());
355 unsigned int indx
= this->stub_table_index_
[shndx
];
356 if (indx
< target
->stub_tables().size())
357 return target
->stub_tables()[indx
];
365 this->stub_table_index_
.clear();
370 { return this->uniq_
; }
374 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
376 // Set ABI version for input and output
378 set_abiversion(int ver
);
381 st_other (unsigned int symndx
) const
383 return this->st_other_
[symndx
];
387 ppc64_local_entry_offset(const Symbol
* sym
) const
388 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
391 ppc64_local_entry_offset(unsigned int symndx
) const
392 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
395 ppc64_needs_toc(const Symbol
* sym
) const
396 { return sym
->nonvis() > 1 << 3; }
399 ppc64_needs_toc(unsigned int symndx
) const
400 { return this->st_other_
[symndx
] > 1 << 5; }
402 // The contents of the .gnu.attributes section if there is one.
403 const Attributes_section_data
*
404 attributes_section_data() const
405 { return this->attributes_section_data_
; }
416 // Return index into opd_ent_ array for .opd entry at OFF.
417 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
418 // apart when the language doesn't use the last 8-byte word, the
419 // environment pointer. Thus dividing the entry section offset by
420 // 16 will give an index into opd_ent_ that works for either layout
421 // of .opd. (It leaves some elements of the vector unused when .opd
422 // entries are spaced 24 bytes apart, but we don't know the spacing
423 // until relocations are processed, and in any case it is possible
424 // for an object to have some entries spaced 16 bytes apart and
425 // others 24 bytes apart.)
427 opd_ent_ndx(size_t off
) const
430 // Per object unique identifier
433 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
434 unsigned int special_
;
436 // For 64-bit the .rela.toc and .toc section shdnx.
437 unsigned int relatoc_
;
440 // For 64-bit, whether this object uses small model relocs to access
442 bool has_small_toc_reloc_
;
444 // Set at the start of gc_process_relocs, when we know opd_ent_
445 // vector is valid. The flag could be made atomic and set in
446 // do_read_relocs with memory_order_release and then tested with
447 // memory_order_acquire, potentially resulting in fewer entries in
452 elfcpp::Elf_Word e_flags_
;
454 // For 64-bit, an array with one entry per 64-bit word in the .toc
455 // section, set if accesses using that word cannot be optimised.
456 std::vector
<bool> no_toc_opt_
;
458 // The first 8-byte word of an OPD entry gives the address of the
459 // entry point of the function. Relocatable object files have a
460 // relocation on this word. The following vector records the
461 // section and offset specified by these relocations.
462 std::vector
<Opd_ent
> opd_ent_
;
464 // References made to this object's .opd section when running
465 // gc_process_relocs for another object, before the opd_ent_ vector
466 // is valid for this object.
467 Access_from access_from_map_
;
469 // Whether input section has a 14-bit branch reloc.
470 std::vector
<bool> has14_
;
472 // The stub table to use for a given input section.
473 std::vector
<unsigned int> stub_table_index_
;
475 // ELF st_other field for local symbols.
476 std::vector
<unsigned char> st_other_
;
478 // Object attributes if there is a .gnu.attributes section.
479 Attributes_section_data
* attributes_section_data_
;
482 template<int size
, bool big_endian
>
483 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
486 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
488 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
489 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
490 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
491 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_(),
492 attributes_section_data_(NULL
)
494 this->set_abiversion(0);
498 { delete this->attributes_section_data_
; }
500 // Call Sized_dynobj::do_read_symbols to read the symbols then
501 // read .opd from a dynamic object, filling in opd_ent_ vector,
503 do_read_symbols(Read_symbols_data
*);
505 // The .opd section shndx.
509 return this->opd_shndx_
;
512 // The .opd section address.
516 return this->opd_address_
;
519 // Init OPD entry arrays.
521 init_opd(size_t opd_size
)
523 size_t count
= this->opd_ent_ndx(opd_size
);
524 this->opd_ent_
.resize(count
);
527 // Return section and offset of function entry for .opd + R_OFF.
529 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
531 size_t ndx
= this->opd_ent_ndx(r_off
);
532 gold_assert(ndx
< this->opd_ent_
.size());
533 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
535 *value
= this->opd_ent_
[ndx
].off
;
536 return this->opd_ent_
[ndx
].shndx
;
539 // Set section and offset of function entry for .opd + R_OFF.
541 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
543 size_t ndx
= this->opd_ent_ndx(r_off
);
544 gold_assert(ndx
< this->opd_ent_
.size());
545 this->opd_ent_
[ndx
].shndx
= shndx
;
546 this->opd_ent_
[ndx
].off
= value
;
551 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
553 // Set ABI version for input and output.
555 set_abiversion(int ver
);
557 // The contents of the .gnu.attributes section if there is one.
558 const Attributes_section_data
*
559 attributes_section_data() const
560 { return this->attributes_section_data_
; }
563 // Used to specify extent of executable sections.
566 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
567 : start(start_
), len(len_
), shndx(shndx_
)
571 operator<(const Sec_info
& that
) const
572 { return this->start
< that
.start
; }
585 // Return index into opd_ent_ array for .opd entry at OFF.
587 opd_ent_ndx(size_t off
) const
590 // For 64-bit the .opd section shndx and address.
591 unsigned int opd_shndx_
;
592 Address opd_address_
;
595 elfcpp::Elf_Word e_flags_
;
597 // The first 8-byte word of an OPD entry gives the address of the
598 // entry point of the function. Records the section and offset
599 // corresponding to the address. Note that in dynamic objects,
600 // offset is *not* relative to the section.
601 std::vector
<Opd_ent
> opd_ent_
;
603 // Object attributes if there is a .gnu.attributes section.
604 Attributes_section_data
* attributes_section_data_
;
607 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
608 // base class will emit.
610 template<int sh_type
, int size
, bool big_endian
>
611 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
614 Powerpc_copy_relocs()
615 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
618 // Emit any saved relocations which turn out to be needed. This is
619 // called after all the relocs have been scanned.
621 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
624 template<int size
, bool big_endian
>
625 class Target_powerpc
: public Sized_target
<size
, big_endian
>
629 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
630 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
631 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
632 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
633 static const Address invalid_address
= static_cast<Address
>(0) - 1;
634 // Offset of tp and dtp pointers from start of TLS block.
635 static const Address tp_offset
= 0x7000;
636 static const Address dtp_offset
= 0x8000;
639 : Sized_target
<size
, big_endian
>(&powerpc_info
),
640 got_(NULL
), plt_(NULL
), iplt_(NULL
), lplt_(NULL
), brlt_section_(NULL
),
641 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
642 tlsld_got_offset_(-1U),
643 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
644 powerxx_stubs_(false), plt_thread_safe_(false), plt_localentry0_(false),
645 plt_localentry0_init_(false), has_localentry0_(false),
646 has_tls_get_addr_opt_(false),
647 relax_failed_(false), relax_fail_count_(0),
648 stub_group_size_(0), savres_section_(0),
649 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
),
650 attributes_section_data_(NULL
),
651 last_fp_(NULL
), last_ld_(NULL
), last_vec_(NULL
), last_struct_(NULL
)
655 // Process the relocations to determine unreferenced sections for
656 // garbage collection.
658 gc_process_relocs(Symbol_table
* symtab
,
660 Sized_relobj_file
<size
, big_endian
>* object
,
661 unsigned int data_shndx
,
662 unsigned int sh_type
,
663 const unsigned char* prelocs
,
665 Output_section
* output_section
,
666 bool needs_special_offset_handling
,
667 size_t local_symbol_count
,
668 const unsigned char* plocal_symbols
);
670 // Scan the relocations to look for symbol adjustments.
672 scan_relocs(Symbol_table
* symtab
,
674 Sized_relobj_file
<size
, big_endian
>* object
,
675 unsigned int data_shndx
,
676 unsigned int sh_type
,
677 const unsigned char* prelocs
,
679 Output_section
* output_section
,
680 bool needs_special_offset_handling
,
681 size_t local_symbol_count
,
682 const unsigned char* plocal_symbols
);
684 // Map input .toc section to output .got section.
686 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
688 if (size
== 64 && strcmp(name
, ".toc") == 0)
696 // Provide linker defined save/restore functions.
698 define_save_restore_funcs(Layout
*, Symbol_table
*);
700 // No stubs unless a final link.
703 { return !parameters
->options().relocatable(); }
706 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
709 do_plt_fde_location(const Output_data
*, unsigned char*,
710 uint64_t*, off_t
*) const;
712 // Stash info about branches, for stub generation.
714 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
715 unsigned int data_shndx
, Address r_offset
,
716 unsigned int r_type
, unsigned int r_sym
, Address addend
)
718 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
719 this->branch_info_
.push_back(info
);
720 if (r_type
== elfcpp::R_POWERPC_REL14
721 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
722 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
723 ppc_object
->set_has_14bit_branch(data_shndx
);
726 // Return whether the last branch is a plt call, and if so, mark the
727 // branch as having an R_PPC64_TOCSAVE.
729 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
730 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
733 && !this->branch_info_
.empty()
734 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
735 r_offset
, this, symtab
));
738 // Say the given location, that of a nop in a function prologue with
739 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
740 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
742 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
743 unsigned int shndx
, Address offset
)
746 loc
.object
= ppc_object
;
749 this->tocsave_loc_
.insert(loc
);
756 return this->tocsave_loc_
;
760 do_define_standard_symbols(Symbol_table
*, Layout
*);
762 // Finalize the sections.
764 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
766 // Return the value to use for a dynamic which requires special
769 do_dynsym_value(const Symbol
*) const;
771 // Return the PLT address to use for a local symbol.
773 do_plt_address_for_local(const Relobj
*, unsigned int) const;
775 // Return the PLT address to use for a global symbol.
777 do_plt_address_for_global(const Symbol
*) const;
779 // Return the offset to use for the GOT_INDX'th got entry which is
780 // for a local tls symbol specified by OBJECT, SYMNDX.
782 do_tls_offset_for_local(const Relobj
* object
,
784 unsigned int got_indx
) const;
786 // Return the offset to use for the GOT_INDX'th got entry which is
787 // for global tls symbol GSYM.
789 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
792 do_function_location(Symbol_location
*) const;
795 do_can_check_for_function_pointers() const
798 // Adjust -fsplit-stack code which calls non-split-stack code.
800 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
801 section_offset_type fnoffset
, section_size_type fnsize
,
802 const unsigned char* prelocs
, size_t reloc_count
,
803 unsigned char* view
, section_size_type view_size
,
804 std::string
* from
, std::string
* to
) const;
806 // Relocate a section.
808 relocate_section(const Relocate_info
<size
, big_endian
>*,
809 unsigned int sh_type
,
810 const unsigned char* prelocs
,
812 Output_section
* output_section
,
813 bool needs_special_offset_handling
,
815 Address view_address
,
816 section_size_type view_size
,
817 const Reloc_symbol_changes
*);
819 // Scan the relocs during a relocatable link.
821 scan_relocatable_relocs(Symbol_table
* symtab
,
823 Sized_relobj_file
<size
, big_endian
>* object
,
824 unsigned int data_shndx
,
825 unsigned int sh_type
,
826 const unsigned char* prelocs
,
828 Output_section
* output_section
,
829 bool needs_special_offset_handling
,
830 size_t local_symbol_count
,
831 const unsigned char* plocal_symbols
,
832 Relocatable_relocs
*);
834 // Scan the relocs for --emit-relocs.
836 emit_relocs_scan(Symbol_table
* symtab
,
838 Sized_relobj_file
<size
, big_endian
>* object
,
839 unsigned int data_shndx
,
840 unsigned int sh_type
,
841 const unsigned char* prelocs
,
843 Output_section
* output_section
,
844 bool needs_special_offset_handling
,
845 size_t local_symbol_count
,
846 const unsigned char* plocal_syms
,
847 Relocatable_relocs
* rr
);
849 // Emit relocations for a section.
851 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
852 unsigned int sh_type
,
853 const unsigned char* prelocs
,
855 Output_section
* output_section
,
856 typename
elfcpp::Elf_types
<size
>::Elf_Off
857 offset_in_output_section
,
859 Address view_address
,
861 unsigned char* reloc_view
,
862 section_size_type reloc_view_size
);
864 // Return whether SYM is defined by the ABI.
866 do_is_defined_by_abi(const Symbol
* sym
) const
868 return strcmp(sym
->name(), "__tls_get_addr") == 0;
871 // Return the size of the GOT section.
875 gold_assert(this->got_
!= NULL
);
876 return this->got_
->data_size();
879 // Get the PLT section.
880 const Output_data_plt_powerpc
<size
, big_endian
>*
883 gold_assert(this->plt_
!= NULL
);
887 // Get the IPLT section.
888 const Output_data_plt_powerpc
<size
, big_endian
>*
891 gold_assert(this->iplt_
!= NULL
);
895 // Get the LPLT section.
896 const Output_data_plt_powerpc
<size
, big_endian
>*
902 // Return the plt offset and section for the given global sym.
904 plt_off(const Symbol
* gsym
,
905 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
907 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
908 && gsym
->can_use_relative_reloc(false))
909 *sec
= this->iplt_section();
911 *sec
= this->plt_section();
912 return gsym
->plt_offset();
915 // Return the plt offset and section for the given local sym.
917 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
918 unsigned int local_sym_index
,
919 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
921 const Symbol_value
<size
>* lsym
= relobj
->local_symbol(local_sym_index
);
922 if (lsym
->is_ifunc_symbol())
923 *sec
= this->iplt_section();
925 *sec
= this->lplt_section();
926 return relobj
->local_plt_offset(local_sym_index
);
929 // Get the .glink section.
930 const Output_data_glink
<size
, big_endian
>*
931 glink_section() const
933 gold_assert(this->glink_
!= NULL
);
937 Output_data_glink
<size
, big_endian
>*
940 gold_assert(this->glink_
!= NULL
);
944 bool has_glink() const
945 { return this->glink_
!= NULL
; }
947 // Get the GOT section.
948 const Output_data_got_powerpc
<size
, big_endian
>*
951 gold_assert(this->got_
!= NULL
);
955 // Get the GOT section, creating it if necessary.
956 Output_data_got_powerpc
<size
, big_endian
>*
957 got_section(Symbol_table
*, Layout
*);
960 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
961 const elfcpp::Ehdr
<size
, big_endian
>&);
963 // Return the number of entries in the GOT.
965 got_entry_count() const
967 if (this->got_
== NULL
)
969 return this->got_size() / (size
/ 8);
972 // Return the number of entries in the PLT.
974 plt_entry_count() const;
976 // Return the offset of the first non-reserved PLT entry.
978 first_plt_entry_offset() const
982 if (this->abiversion() >= 2)
987 // Return the size of each PLT entry.
989 plt_entry_size() const
993 if (this->abiversion() >= 2)
998 Output_data_save_res
<size
, big_endian
>*
999 savres_section() const
1001 return this->savres_section_
;
1004 // Add any special sections for this symbol to the gc work list.
1005 // For powerpc64, this adds the code section of a function
1008 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
1010 // Handle target specific gc actions when adding a gc reference from
1011 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
1012 // and DST_OFF. For powerpc64, this adds a referenc to the code
1013 // section of a function descriptor.
1015 do_gc_add_reference(Symbol_table
* symtab
,
1017 unsigned int src_shndx
,
1019 unsigned int dst_shndx
,
1020 Address dst_off
) const;
1022 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
1025 { return this->stub_tables_
; }
1027 const Output_data_brlt_powerpc
<size
, big_endian
>*
1028 brlt_section() const
1029 { return this->brlt_section_
; }
1032 add_branch_lookup_table(Address to
)
1034 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
1035 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
1039 find_branch_lookup_table(Address to
)
1041 typename
Branch_lookup_table::const_iterator p
1042 = this->branch_lookup_table_
.find(to
);
1043 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1047 write_branch_lookup_table(unsigned char *oview
)
1049 for (typename
Branch_lookup_table::const_iterator p
1050 = this->branch_lookup_table_
.begin();
1051 p
!= this->branch_lookup_table_
.end();
1054 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1058 // Wrapper used after relax to define a local symbol in output data,
1059 // from the end if value < 0.
1061 define_local(Symbol_table
* symtab
, const char* name
,
1062 Output_data
* od
, Address value
, unsigned int symsize
)
1065 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1066 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1067 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1068 static_cast<Signed_address
>(value
) < 0,
1070 // We are creating this symbol late, so need to fix up things
1071 // done early in Layout::finalize.
1072 sym
->set_dynsym_index(-1U);
1076 powerxx_stubs() const
1077 { return this->powerxx_stubs_
; }
1082 this->powerxx_stubs_
= true;
1086 plt_thread_safe() const
1087 { return this->plt_thread_safe_
; }
1090 plt_localentry0() const
1091 { return this->plt_localentry0_
; }
1094 set_has_localentry0()
1096 this->has_localentry0_
= true;
1100 is_elfv2_localentry0(const Symbol
* gsym
) const
1103 && this->abiversion() >= 2
1104 && this->plt_localentry0()
1105 && gsym
->type() == elfcpp::STT_FUNC
1106 && gsym
->is_defined()
1107 && gsym
->nonvis() >> 3 == 0
1108 && !gsym
->non_zero_localentry());
1112 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1113 unsigned int r_sym
) const
1115 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1116 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1119 && this->abiversion() >= 2
1120 && this->plt_localentry0()
1121 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1123 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1125 if (!psymval
->is_ifunc_symbol()
1126 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1133 // Remember any symbols seen with non-zero localentry, even those
1134 // not providing a definition
1136 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1141 unsigned char st_other
= sym
.get_st_other();
1142 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1143 to
->set_non_zero_localentry();
1145 // We haven't resolved anything, continue normal processing.
1151 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1154 set_abiversion(int ver
)
1156 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1157 flags
&= ~elfcpp::EF_PPC64_ABI
;
1158 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1159 this->set_processor_specific_flags(flags
);
1163 tls_get_addr_opt() const
1164 { return this->tls_get_addr_opt_
; }
1167 tls_get_addr() const
1168 { return this->tls_get_addr_
; }
1170 // If optimizing __tls_get_addr calls, whether this is the
1171 // "__tls_get_addr" symbol.
1173 is_tls_get_addr_opt(const Symbol
* gsym
) const
1175 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1176 || gsym
== this->tls_get_addr_opt_
);
1180 replace_tls_get_addr(const Symbol
* gsym
) const
1181 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1184 set_has_tls_get_addr_opt()
1185 { this->has_tls_get_addr_opt_
= true; }
1187 // Offset to toc save stack slot
1190 { return this->abiversion() < 2 ? 40 : 24; }
1192 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1193 // so use the CR save slot. Used only by __tls_get_addr call stub,
1194 // relying on __tls_get_addr not saving CR itself.
1197 { return this->abiversion() < 2 ? 32 : 8; }
1199 // Merge object attributes from input object with those in the output.
1201 merge_object_attributes(const char*, const Attributes_section_data
*);
1217 : tls_get_addr_state_(NOT_EXPECTED
),
1218 relinfo_(NULL
), relnum_(0), r_offset_(0)
1223 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1230 if (this->relinfo_
!= NULL
)
1231 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1232 _("missing expected __tls_get_addr call"));
1236 expect_tls_get_addr_call(
1237 const Relocate_info
<size
, big_endian
>* relinfo
,
1241 this->tls_get_addr_state_
= EXPECTED
;
1242 this->relinfo_
= relinfo
;
1243 this->relnum_
= relnum
;
1244 this->r_offset_
= r_offset
;
1248 expect_tls_get_addr_call()
1249 { this->tls_get_addr_state_
= EXPECTED
; }
1252 skip_next_tls_get_addr_call()
1253 {this->tls_get_addr_state_
= SKIP
; }
1256 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1257 unsigned int r_type
, const Symbol
* gsym
)
1260 = ((r_type
== elfcpp::R_POWERPC_REL24
1261 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1262 || r_type
== elfcpp::R_PPC_PLTREL24
1263 || is_plt16_reloc
<size
>(r_type
)
1264 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
1265 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
1266 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1267 || r_type
== elfcpp::R_POWERPC_PLTCALL
1268 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1269 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1271 && (gsym
== target
->tls_get_addr()
1272 || gsym
== target
->tls_get_addr_opt()));
1273 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1274 this->tls_get_addr_state_
= NOT_EXPECTED
;
1275 if (is_tls_call
&& last_tls
!= EXPECTED
)
1277 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1286 // What we're up to regarding calls to __tls_get_addr.
1287 // On powerpc, the branch and link insn making a call to
1288 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1289 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1290 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1291 // The marker relocation always comes first, and has the same
1292 // symbol as the reloc on the insn setting up the __tls_get_addr
1293 // argument. This ties the arg setup insn with the call insn,
1294 // allowing ld to safely optimize away the call. We check that
1295 // every call to __tls_get_addr has a marker relocation, and that
1296 // every marker relocation is on a call to __tls_get_addr.
1297 Tls_get_addr tls_get_addr_state_
;
1298 // Info about the last reloc for error message.
1299 const Relocate_info
<size
, big_endian
>* relinfo_
;
1304 // The class which scans relocations.
1305 class Scan
: protected Track_tls
1308 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1311 : Track_tls(), issued_non_pic_error_(false)
1315 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1318 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1319 Sized_relobj_file
<size
, big_endian
>* object
,
1320 unsigned int data_shndx
,
1321 Output_section
* output_section
,
1322 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1323 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1327 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1328 Sized_relobj_file
<size
, big_endian
>* object
,
1329 unsigned int data_shndx
,
1330 Output_section
* output_section
,
1331 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1335 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1337 Sized_relobj_file
<size
, big_endian
>* relobj
,
1340 const elfcpp::Rela
<size
, big_endian
>& ,
1341 unsigned int r_type
,
1342 const elfcpp::Sym
<size
, big_endian
>&)
1344 // PowerPC64 .opd is not folded, so any identical function text
1345 // may be folded and we'll still keep function addresses distinct.
1346 // That means no reloc is of concern here.
1349 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1350 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1351 if (ppcobj
->abiversion() == 1)
1354 // For 32-bit and ELFv2, conservatively assume anything but calls to
1355 // function code might be taking the address of the function.
1356 return !is_branch_reloc
<size
>(r_type
);
1360 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1362 Sized_relobj_file
<size
, big_endian
>* relobj
,
1365 const elfcpp::Rela
<size
, big_endian
>& ,
1366 unsigned int r_type
,
1372 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1373 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1374 if (ppcobj
->abiversion() == 1)
1377 return !is_branch_reloc
<size
>(r_type
);
1381 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1382 Sized_relobj_file
<size
, big_endian
>* object
,
1383 unsigned int r_type
, bool report_err
);
1387 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1388 unsigned int r_type
);
1391 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1392 unsigned int r_type
, Symbol
*);
1395 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1396 Target_powerpc
* target
);
1399 check_non_pic(Relobj
*, unsigned int r_type
);
1401 // Whether we have issued an error about a non-PIC compilation.
1402 bool issued_non_pic_error_
;
1406 symval_for_branch(const Symbol_table
* symtab
,
1407 const Sized_symbol
<size
>* gsym
,
1408 Powerpc_relobj
<size
, big_endian
>* object
,
1409 Address
*value
, unsigned int *dest_shndx
);
1411 // The class which implements relocation.
1412 class Relocate
: protected Track_tls
1415 // Use 'at' branch hints when true, 'y' when false.
1416 // FIXME maybe: set this with an option.
1417 static const bool is_isa_v2
= true;
1423 // Do a relocation. Return false if the caller should not issue
1424 // any warnings about this relocation.
1426 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1427 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1428 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1429 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1433 class Relocate_comdat_behavior
1436 // Decide what the linker should do for relocations that refer to
1437 // discarded comdat sections.
1438 inline Comdat_behavior
1439 get(const char* name
)
1441 gold::Default_comdat_behavior default_behavior
;
1442 Comdat_behavior ret
= default_behavior
.get(name
);
1443 if (ret
== CB_ERROR
)
1446 && (strcmp(name
, ".fixup") == 0
1447 || strcmp(name
, ".got2") == 0))
1450 && (strcmp(name
, ".opd") == 0
1451 || strcmp(name
, ".toc") == 0
1452 || strcmp(name
, ".toc1") == 0))
1459 // Optimize the TLS relocation type based on what we know about the
1460 // symbol. IS_FINAL is true if the final address of this symbol is
1461 // known at link time.
1463 tls::Tls_optimization
1464 optimize_tls_gd(bool is_final
)
1466 // If we are generating a shared library, then we can't do anything
1468 if (parameters
->options().shared()
1469 || !parameters
->options().tls_optimize())
1470 return tls::TLSOPT_NONE
;
1473 return tls::TLSOPT_TO_IE
;
1474 return tls::TLSOPT_TO_LE
;
1477 tls::Tls_optimization
1480 if (parameters
->options().shared()
1481 || !parameters
->options().tls_optimize())
1482 return tls::TLSOPT_NONE
;
1484 return tls::TLSOPT_TO_LE
;
1487 tls::Tls_optimization
1488 optimize_tls_ie(bool is_final
)
1491 || parameters
->options().shared()
1492 || !parameters
->options().tls_optimize())
1493 return tls::TLSOPT_NONE
;
1495 return tls::TLSOPT_TO_LE
;
1500 make_glink_section(Layout
*);
1502 // Create the PLT section.
1504 make_plt_section(Symbol_table
*, Layout
*);
1507 make_iplt_section(Symbol_table
*, Layout
*);
1510 make_lplt_section(Layout
*);
1513 make_brlt_section(Layout
*);
1515 // Create a PLT entry for a global symbol.
1517 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1519 // Create a PLT entry for a local IFUNC symbol.
1521 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1522 Sized_relobj_file
<size
, big_endian
>*,
1525 // Create a PLT entry for a local non-IFUNC symbol.
1527 make_local_plt_entry(Layout
*,
1528 Sized_relobj_file
<size
, big_endian
>*,
1532 // Create a GOT entry for local dynamic __tls_get_addr.
1534 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1535 Sized_relobj_file
<size
, big_endian
>* object
);
1538 tlsld_got_offset() const
1540 return this->tlsld_got_offset_
;
1543 // Get the dynamic reloc section, creating it if necessary.
1545 rela_dyn_section(Layout
*);
1547 // Similarly, but for ifunc symbols get the one for ifunc.
1549 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1551 // Copy a relocation against a global symbol.
1553 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1554 Sized_relobj_file
<size
, big_endian
>* object
,
1555 unsigned int shndx
, Output_section
* output_section
,
1556 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1558 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1559 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1560 symtab
->get_sized_symbol
<size
>(sym
),
1561 object
, shndx
, output_section
,
1562 r_type
, reloc
.get_r_offset(),
1563 reloc
.get_r_addend(),
1564 this->rela_dyn_section(layout
));
1567 // Look over all the input sections, deciding where to place stubs.
1569 group_sections(Layout
*, const Task
*, bool);
1571 // Sort output sections by address.
1572 struct Sort_sections
1575 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1576 { return sec1
->address() < sec2
->address(); }
1582 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1583 unsigned int data_shndx
,
1585 unsigned int r_type
,
1588 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1589 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1595 // Return whether this branch is going via a plt call stub, and if
1596 // so, mark it as having an R_PPC64_TOCSAVE.
1598 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1599 unsigned int shndx
, Address offset
,
1600 Target_powerpc
* target
, Symbol_table
* symtab
);
1602 // If this branch needs a plt call stub, or a long branch stub, make one.
1604 make_stub(Stub_table
<size
, big_endian
>*,
1605 Stub_table
<size
, big_endian
>*,
1606 Symbol_table
*) const;
1609 // The branch location..
1610 Powerpc_relobj
<size
, big_endian
>* object_
;
1611 unsigned int shndx_
;
1613 // ..and the branch type and destination.
1614 unsigned int r_type_
: 31;
1615 unsigned int tocsave_
: 1;
1616 unsigned int r_sym_
;
1620 // Information about this specific target which we pass to the
1621 // general Target structure.
1622 static Target::Target_info powerpc_info
;
1624 // The types of GOT entries needed for this platform.
1625 // These values are exposed to the ABI in an incremental link.
1626 // Do not renumber existing values without changing the version
1627 // number of the .gnu_incremental_inputs section.
1631 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1632 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1633 GOT_TYPE_TPREL
// entry for @got@tprel
1637 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1638 // The PLT section. This is a container for a table of addresses,
1639 // and their relocations. Each address in the PLT has a dynamic
1640 // relocation (R_*_JMP_SLOT) and each address will have a
1641 // corresponding entry in .glink for lazy resolution of the PLT.
1642 // ppc32 initialises the PLT to point at the .glink entry, while
1643 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1644 // linker adds a stub that loads the PLT entry into ctr then
1645 // branches to ctr. There may be more than one stub for each PLT
1646 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1647 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1648 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1649 // The IPLT section. Like plt_, this is a container for a table of
1650 // addresses and their relocations, specifically for STT_GNU_IFUNC
1651 // functions that resolve locally (STT_GNU_IFUNC functions that
1652 // don't resolve locally go in PLT). Unlike plt_, these have no
1653 // entry in .glink for lazy resolution, and the relocation section
1654 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1655 // the relocation section may contain relocations against
1656 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1657 // relocation section will appear at the end of other dynamic
1658 // relocations, so that ld.so applies these relocations after other
1659 // dynamic relocations. In a static executable, the relocation
1660 // section is emitted and marked with __rela_iplt_start and
1661 // __rela_iplt_end symbols.
1662 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1663 // A PLT style section for local, non-ifunc symbols
1664 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1665 // Section holding long branch destinations.
1666 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1667 // The .glink section.
1668 Output_data_glink
<size
, big_endian
>* glink_
;
1669 // The dynamic reloc section.
1670 Reloc_section
* rela_dyn_
;
1671 // Relocs saved to avoid a COPY reloc.
1672 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1673 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1674 unsigned int tlsld_got_offset_
;
1676 Stub_tables stub_tables_
;
1677 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1678 Branch_lookup_table branch_lookup_table_
;
1680 typedef std::vector
<Branch_info
> Branches
;
1681 Branches branch_info_
;
1682 Tocsave_loc tocsave_loc_
;
1684 bool powerxx_stubs_
;
1685 bool plt_thread_safe_
;
1686 bool plt_localentry0_
;
1687 bool plt_localentry0_init_
;
1688 bool has_localentry0_
;
1689 bool has_tls_get_addr_opt_
;
1692 int relax_fail_count_
;
1693 int32_t stub_group_size_
;
1695 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1697 // The "__tls_get_addr" symbol, if present
1698 Symbol
* tls_get_addr_
;
1699 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1700 Symbol
* tls_get_addr_opt_
;
1702 // Attributes in output.
1703 Attributes_section_data
* attributes_section_data_
;
1705 // Last input file to change various attribute tags
1706 const char* last_fp_
;
1707 const char* last_ld_
;
1708 const char* last_vec_
;
1709 const char* last_struct_
;
1713 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1716 true, // is_big_endian
1717 elfcpp::EM_PPC
, // machine_code
1718 false, // has_make_symbol
1719 false, // has_resolve
1720 false, // has_code_fill
1721 true, // is_default_stack_executable
1722 false, // can_icf_inline_merge_sections
1724 "/usr/lib/ld.so.1", // dynamic_linker
1725 0x10000000, // default_text_segment_address
1726 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1727 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1728 false, // isolate_execinstr
1730 elfcpp::SHN_UNDEF
, // small_common_shndx
1731 elfcpp::SHN_UNDEF
, // large_common_shndx
1732 0, // small_common_section_flags
1733 0, // large_common_section_flags
1734 NULL
, // attributes_section
1735 NULL
, // attributes_vendor
1736 "_start", // entry_symbol_name
1737 32, // hash_entry_size
1738 elfcpp::SHT_PROGBITS
, // unwind_section_type
1742 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1745 false, // is_big_endian
1746 elfcpp::EM_PPC
, // machine_code
1747 false, // has_make_symbol
1748 false, // has_resolve
1749 false, // has_code_fill
1750 true, // is_default_stack_executable
1751 false, // can_icf_inline_merge_sections
1753 "/usr/lib/ld.so.1", // dynamic_linker
1754 0x10000000, // default_text_segment_address
1755 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1756 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1757 false, // isolate_execinstr
1759 elfcpp::SHN_UNDEF
, // small_common_shndx
1760 elfcpp::SHN_UNDEF
, // large_common_shndx
1761 0, // small_common_section_flags
1762 0, // large_common_section_flags
1763 NULL
, // attributes_section
1764 NULL
, // attributes_vendor
1765 "_start", // entry_symbol_name
1766 32, // hash_entry_size
1767 elfcpp::SHT_PROGBITS
, // unwind_section_type
1771 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1774 true, // is_big_endian
1775 elfcpp::EM_PPC64
, // machine_code
1776 false, // has_make_symbol
1777 true, // has_resolve
1778 false, // has_code_fill
1779 false, // is_default_stack_executable
1780 false, // can_icf_inline_merge_sections
1782 "/usr/lib/ld.so.1", // dynamic_linker
1783 0x10000000, // default_text_segment_address
1784 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1785 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1786 false, // isolate_execinstr
1788 elfcpp::SHN_UNDEF
, // small_common_shndx
1789 elfcpp::SHN_UNDEF
, // large_common_shndx
1790 0, // small_common_section_flags
1791 0, // large_common_section_flags
1792 NULL
, // attributes_section
1793 NULL
, // attributes_vendor
1794 "_start", // entry_symbol_name
1795 32, // hash_entry_size
1796 elfcpp::SHT_PROGBITS
, // unwind_section_type
1800 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1803 false, // is_big_endian
1804 elfcpp::EM_PPC64
, // machine_code
1805 false, // has_make_symbol
1806 true, // has_resolve
1807 false, // has_code_fill
1808 false, // is_default_stack_executable
1809 false, // can_icf_inline_merge_sections
1811 "/usr/lib/ld.so.1", // dynamic_linker
1812 0x10000000, // default_text_segment_address
1813 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1814 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1815 false, // isolate_execinstr
1817 elfcpp::SHN_UNDEF
, // small_common_shndx
1818 elfcpp::SHN_UNDEF
, // large_common_shndx
1819 0, // small_common_section_flags
1820 0, // large_common_section_flags
1821 NULL
, // attributes_section
1822 NULL
, // attributes_vendor
1823 "_start", // entry_symbol_name
1824 32, // hash_entry_size
1825 elfcpp::SHT_PROGBITS
, // unwind_section_type
1830 is_branch_reloc(unsigned int r_type
)
1832 return (r_type
== elfcpp::R_POWERPC_REL24
1833 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1834 || r_type
== elfcpp::R_PPC_PLTREL24
1835 || r_type
== elfcpp::R_PPC_LOCAL24PC
1836 || r_type
== elfcpp::R_POWERPC_REL14
1837 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1838 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1839 || r_type
== elfcpp::R_POWERPC_ADDR24
1840 || r_type
== elfcpp::R_POWERPC_ADDR14
1841 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1842 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1845 // Reloc resolves to plt entry.
1848 is_plt16_reloc(unsigned int r_type
)
1850 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1851 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1852 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1853 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1856 // If INSN is an opcode that may be used with an @tls operand, return
1857 // the transformed insn for TLS optimisation, otherwise return 0. If
1858 // REG is non-zero only match an insn with RB or RA equal to REG.
1860 at_tls_transform(uint32_t insn
, unsigned int reg
)
1862 if ((insn
& (0x3f << 26)) != 31 << 26)
1866 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1867 rtra
= insn
& ((1 << 26) - (1 << 16));
1868 else if (((insn
>> 16) & 0x1f) == reg
)
1869 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1873 if ((insn
& (0x3ff << 1)) == 266 << 1)
1876 else if ((insn
& (0x1f << 1)) == 23 << 1
1877 && ((insn
& (0x1f << 6)) < 14 << 6
1878 || ((insn
& (0x1f << 6)) >= 16 << 6
1879 && (insn
& (0x1f << 6)) < 24 << 6)))
1880 // load and store indexed -> dform
1881 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1882 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1883 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1884 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1885 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1887 insn
= (58 << 26) | 2;
1895 template<int size
, bool big_endian
>
1896 class Powerpc_relocate_functions
1916 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1917 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1918 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1920 template<int valsize
>
1922 has_overflow_signed(Address value
)
1924 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1925 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1926 limit
<<= ((valsize
- 1) >> 1);
1927 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1928 return value
+ limit
> (limit
<< 1) - 1;
1931 template<int valsize
>
1933 has_overflow_unsigned(Address value
)
1935 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1936 limit
<<= ((valsize
- 1) >> 1);
1937 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1938 return value
> (limit
<< 1) - 1;
1941 template<int valsize
>
1943 has_overflow_bitfield(Address value
)
1945 return (has_overflow_unsigned
<valsize
>(value
)
1946 && has_overflow_signed
<valsize
>(value
));
1949 template<int valsize
>
1950 static inline Status
1951 overflowed(Address value
, Overflow_check overflow
)
1953 if (overflow
== CHECK_SIGNED
)
1955 if (has_overflow_signed
<valsize
>(value
))
1956 return STATUS_OVERFLOW
;
1958 else if (overflow
== CHECK_UNSIGNED
)
1960 if (has_overflow_unsigned
<valsize
>(value
))
1961 return STATUS_OVERFLOW
;
1963 else if (overflow
== CHECK_BITFIELD
)
1965 if (has_overflow_bitfield
<valsize
>(value
))
1966 return STATUS_OVERFLOW
;
1971 // Do a simple RELA relocation
1972 template<int fieldsize
, int valsize
>
1973 static inline Status
1974 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1976 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1977 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1978 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1979 return overflowed
<valsize
>(value
, overflow
);
1982 template<int fieldsize
, int valsize
>
1983 static inline Status
1984 rela(unsigned char* view
,
1985 unsigned int right_shift
,
1986 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1988 Overflow_check overflow
)
1990 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1991 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1992 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1993 Valtype reloc
= value
>> right_shift
;
1996 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1997 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
2000 // Do a simple RELA relocation, unaligned.
2001 template<int fieldsize
, int valsize
>
2002 static inline Status
2003 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
2005 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
2006 return overflowed
<valsize
>(value
, overflow
);
2009 template<int fieldsize
, int valsize
>
2010 static inline Status
2011 rela_ua(unsigned char* view
,
2012 unsigned int right_shift
,
2013 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2015 Overflow_check overflow
)
2017 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2019 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2020 Valtype reloc
= value
>> right_shift
;
2023 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2024 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
2028 // R_PPC64_ADDR64: (Symbol + Addend)
2030 addr64(unsigned char* view
, Address value
)
2031 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2033 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2035 addr64_u(unsigned char* view
, Address value
)
2036 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2038 // R_POWERPC_ADDR32: (Symbol + Addend)
2039 static inline Status
2040 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2041 { return This::template rela
<32,32>(view
, value
, overflow
); }
2043 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2044 static inline Status
2045 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2046 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2048 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2049 static inline Status
2050 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2052 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2054 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2055 stat
= STATUS_OVERFLOW
;
2059 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2060 static inline Status
2061 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2062 { return This::template rela
<16,16>(view
, value
, overflow
); }
2064 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2065 static inline Status
2066 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2067 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2069 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2070 static inline Status
2071 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2073 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2074 if ((value
& 3) != 0)
2075 stat
= STATUS_OVERFLOW
;
2079 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2080 static inline Status
2081 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2083 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2084 if ((value
& 15) != 0)
2085 stat
= STATUS_OVERFLOW
;
2089 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2091 addr16_hi(unsigned char* view
, Address value
)
2092 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2094 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2096 addr16_ha(unsigned char* view
, Address value
)
2097 { This::addr16_hi(view
, value
+ 0x8000); }
2099 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2101 addr16_hi2(unsigned char* view
, Address value
)
2102 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2104 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2106 addr16_ha2(unsigned char* view
, Address value
)
2107 { This::addr16_hi2(view
, value
+ 0x8000); }
2109 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2111 addr16_hi3(unsigned char* view
, Address value
)
2112 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2114 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2116 addr16_ha3(unsigned char* view
, Address value
)
2117 { This::addr16_hi3(view
, value
+ 0x8000); }
2119 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2120 static inline Status
2121 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2123 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2124 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2125 stat
= STATUS_OVERFLOW
;
2129 // R_POWERPC_REL16DX_HA
2130 static inline Status
2131 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2133 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2134 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2135 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2137 value
= static_cast<SignedAddress
>(value
) >> 16;
2138 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2139 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2140 return overflowed
<16>(value
, overflow
);
2144 static inline Status
2145 addr34(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2147 Status stat
= This::template rela
<32,18>(view
, 16, 0x3ffff,
2149 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2155 addr34_hi(unsigned char *view
, uint64_t value
)
2156 { This::addr34(view
, value
>> 34, CHECK_NONE
);}
2160 addr34_ha(unsigned char *view
, uint64_t value
)
2161 { This::addr34_hi(view
, value
+ (1ULL << 33));}
2164 static inline Status
2165 addr28(unsigned char *view
, uint64_t value
, Overflow_check overflow
)
2167 Status stat
= This::template rela
<32,12>(view
, 16, 0xfff,
2169 This::rela
<32,16>(view
+ 4, 0, 0xffff, value
, CHECK_NONE
);
2173 // R_PPC64_ADDR16_HIGHER34
2175 addr16_higher34(unsigned char* view
, uint64_t value
)
2176 { This::addr16(view
, value
>> 34, CHECK_NONE
); }
2178 // R_PPC64_ADDR16_HIGHERA34
2180 addr16_highera34(unsigned char* view
, uint64_t value
)
2181 { This::addr16_higher34(view
, value
+ (1ULL << 33)); }
2183 // R_PPC64_ADDR16_HIGHEST34
2185 addr16_highest34(unsigned char* view
, uint64_t value
)
2186 { This::addr16(view
, value
>> 50, CHECK_NONE
); }
2188 // R_PPC64_ADDR16_HIGHESTA34
2190 addr16_highesta34(unsigned char* view
, uint64_t value
)
2191 { This::addr16_highest34(view
, value
+ (1ULL << 33)); }
2194 // Set ABI version for input and output.
2196 template<int size
, bool big_endian
>
2198 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2200 this->e_flags_
|= ver
;
2201 if (this->abiversion() != 0)
2203 Target_powerpc
<size
, big_endian
>* target
=
2204 static_cast<Target_powerpc
<size
, big_endian
>*>(
2205 parameters
->sized_target
<size
, big_endian
>());
2206 if (target
->abiversion() == 0)
2207 target
->set_abiversion(this->abiversion());
2208 else if (target
->abiversion() != this->abiversion())
2209 gold_error(_("%s: ABI version %d is not compatible "
2210 "with ABI version %d output"),
2211 this->name().c_str(),
2212 this->abiversion(), target
->abiversion());
2217 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2218 // relocatable object, if such sections exists.
2220 template<int size
, bool big_endian
>
2222 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2223 Read_symbols_data
* sd
)
2225 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2226 const unsigned char* namesu
= sd
->section_names
->data();
2227 const char* names
= reinterpret_cast<const char*>(namesu
);
2228 section_size_type names_size
= sd
->section_names_size
;
2229 const unsigned char* s
;
2231 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2232 size
== 32 ? ".got2" : ".opd",
2233 names
, names_size
, NULL
);
2236 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2237 this->special_
= ndx
;
2240 if (this->abiversion() == 0)
2241 this->set_abiversion(1);
2242 else if (this->abiversion() > 1)
2243 gold_error(_("%s: .opd invalid in abiv%d"),
2244 this->name().c_str(), this->abiversion());
2249 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2250 names
, names_size
, NULL
);
2253 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2254 this->relatoc_
= ndx
;
2255 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2256 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2259 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2262 // Examine .rela.opd to build info about function entry points.
2264 template<int size
, bool big_endian
>
2266 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2268 const unsigned char* prelocs
,
2269 const unsigned char* plocal_syms
)
2273 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2274 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2275 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2276 Address expected_off
= 0;
2277 bool regular
= true;
2278 unsigned int opd_ent_size
= 0;
2280 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2282 Reltype
reloc(prelocs
);
2283 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2284 = reloc
.get_r_info();
2285 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2286 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2288 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2289 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2292 if (r_sym
< this->local_symbol_count())
2294 typename
elfcpp::Sym
<size
, big_endian
>
2295 lsym(plocal_syms
+ r_sym
* sym_size
);
2296 shndx
= lsym
.get_st_shndx();
2297 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2298 value
= lsym
.get_st_value();
2301 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2303 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2304 value
+ reloc
.get_r_addend());
2307 expected_off
= reloc
.get_r_offset();
2308 opd_ent_size
= expected_off
;
2310 else if (expected_off
!= reloc
.get_r_offset())
2312 expected_off
+= opd_ent_size
;
2314 else if (r_type
== elfcpp::R_PPC64_TOC
)
2316 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2321 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2322 this->name().c_str(), r_type
);
2326 if (reloc_count
<= 2)
2327 opd_ent_size
= this->section_size(this->opd_shndx());
2328 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2332 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2333 this->name().c_str());
2339 // Returns true if a code sequence loading the TOC entry at VALUE
2340 // relative to the TOC pointer can be converted into code calculating
2341 // a TOC pointer relative offset.
2342 // If so, the TOC pointer relative offset is stored to VALUE.
2344 template<int size
, bool big_endian
>
2346 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2347 Target_powerpc
<size
, big_endian
>* target
,
2353 // With -mcmodel=medium code it is quite possible to have
2354 // toc-relative relocs referring to objects outside the TOC.
2355 // Don't try to look at a non-existent TOC.
2356 if (this->toc_shndx() == 0)
2359 // Convert VALUE back to an address by adding got_base (see below),
2360 // then to an offset in the TOC by subtracting the TOC output
2361 // section address and the TOC output offset. Since this TOC output
2362 // section and the got output section are one and the same, we can
2363 // omit adding and subtracting the output section address.
2364 Address off
= (*value
+ this->toc_base_offset()
2365 - this->output_section_offset(this->toc_shndx()));
2366 // Is this offset in the TOC? -mcmodel=medium code may be using
2367 // TOC relative access to variables outside the TOC. Those of
2368 // course can't be optimized. We also don't try to optimize code
2369 // that is using a different object's TOC.
2370 if (off
>= this->section_size(this->toc_shndx()))
2373 if (this->no_toc_opt(off
))
2376 section_size_type vlen
;
2377 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2378 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2380 Address got_base
= (target
->got_section()->output_section()->address()
2381 + this->toc_base_offset());
2383 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2390 // Perform the Sized_relobj_file method, then set up opd info from
2393 template<int size
, bool big_endian
>
2395 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2397 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2400 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2401 p
!= rd
->relocs
.end();
2404 if (p
->data_shndx
== this->opd_shndx())
2406 uint64_t opd_size
= this->section_size(this->opd_shndx());
2407 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2410 this->init_opd(opd_size
);
2411 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2412 rd
->local_symbols
->data());
2420 // Read the symbols then set up st_other vector.
2422 template<int size
, bool big_endian
>
2424 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2426 this->base_read_symbols(sd
);
2427 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2431 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2432 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2433 const unsigned int loccount
= this->do_local_symbol_count();
2436 this->st_other_
.resize(loccount
);
2437 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2438 off_t locsize
= loccount
* sym_size
;
2439 const unsigned int symtab_shndx
= this->symtab_shndx();
2440 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2441 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2442 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2443 locsize
, true, false);
2445 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2447 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2448 unsigned char st_other
= sym
.get_st_other();
2449 this->st_other_
[i
] = st_other
;
2450 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2452 if (this->abiversion() == 0)
2453 this->set_abiversion(2);
2454 else if (this->abiversion() < 2)
2455 gold_error(_("%s: local symbol %d has invalid st_other"
2456 " for ABI version 1"),
2457 this->name().c_str(), i
);
2463 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2464 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2465 bool merge_attributes
= false;
2466 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2468 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2469 switch (shdr
.get_sh_type())
2471 case elfcpp::SHT_GNU_ATTRIBUTES
:
2473 gold_assert(this->attributes_section_data_
== NULL
);
2474 section_offset_type section_offset
= shdr
.get_sh_offset();
2475 section_size_type section_size
=
2476 convert_to_section_size_type(shdr
.get_sh_size());
2477 const unsigned char* view
=
2478 this->get_view(section_offset
, section_size
, true, false);
2479 this->attributes_section_data_
=
2480 new Attributes_section_data(view
, section_size
);
2484 case elfcpp::SHT_SYMTAB
:
2486 // Sometimes an object has no contents except the section
2487 // name string table and an empty symbol table with the
2488 // undefined symbol. We don't want to merge
2489 // processor-specific flags from such an object.
2490 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2491 elfcpp::Elf_sizes
<size
>::sym_size
;
2492 if (shdr
.get_sh_size() > sym_size
)
2493 merge_attributes
= true;
2497 case elfcpp::SHT_STRTAB
:
2501 merge_attributes
= true;
2506 if (!merge_attributes
)
2508 // Should rarely happen.
2509 delete this->attributes_section_data_
;
2510 this->attributes_section_data_
= NULL
;
2514 template<int size
, bool big_endian
>
2516 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2518 this->e_flags_
|= ver
;
2519 if (this->abiversion() != 0)
2521 Target_powerpc
<size
, big_endian
>* target
=
2522 static_cast<Target_powerpc
<size
, big_endian
>*>(
2523 parameters
->sized_target
<size
, big_endian
>());
2524 if (target
->abiversion() == 0)
2525 target
->set_abiversion(this->abiversion());
2526 else if (target
->abiversion() != this->abiversion())
2527 gold_error(_("%s: ABI version %d is not compatible "
2528 "with ABI version %d output"),
2529 this->name().c_str(),
2530 this->abiversion(), target
->abiversion());
2535 // Call Sized_dynobj::base_read_symbols to read the symbols then
2536 // read .opd from a dynamic object, filling in opd_ent_ vector,
2538 template<int size
, bool big_endian
>
2540 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2542 this->base_read_symbols(sd
);
2543 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2544 const unsigned char* ps
=
2545 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2546 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2548 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2549 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2551 section_offset_type section_offset
= shdr
.get_sh_offset();
2552 section_size_type section_size
=
2553 convert_to_section_size_type(shdr
.get_sh_size());
2554 const unsigned char* view
=
2555 this->get_view(section_offset
, section_size
, true, false);
2556 this->attributes_section_data_
=
2557 new Attributes_section_data(view
, section_size
);
2563 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2564 const unsigned char* namesu
= sd
->section_names
->data();
2565 const char* names
= reinterpret_cast<const char*>(namesu
);
2566 const unsigned char* s
= NULL
;
2567 const unsigned char* opd
;
2568 section_size_type opd_size
;
2570 // Find and read .opd section.
2573 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2574 sd
->section_names_size
,
2579 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2580 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2581 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2583 if (this->abiversion() == 0)
2584 this->set_abiversion(1);
2585 else if (this->abiversion() > 1)
2586 gold_error(_("%s: .opd invalid in abiv%d"),
2587 this->name().c_str(), this->abiversion());
2589 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2590 this->opd_address_
= shdr
.get_sh_addr();
2591 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2592 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2598 // Build set of executable sections.
2599 // Using a set is probably overkill. There is likely to be only
2600 // a few executable sections, typically .init, .text and .fini,
2601 // and they are generally grouped together.
2602 typedef std::set
<Sec_info
> Exec_sections
;
2603 Exec_sections exec_sections
;
2605 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2607 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2608 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2609 && ((shdr
.get_sh_flags()
2610 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2611 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2612 && shdr
.get_sh_size() != 0)
2614 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2615 shdr
.get_sh_size(), i
));
2618 if (exec_sections
.empty())
2621 // Look over the OPD entries. This is complicated by the fact
2622 // that some binaries will use two-word entries while others
2623 // will use the standard three-word entries. In most cases
2624 // the third word (the environment pointer for languages like
2625 // Pascal) is unused and will be zero. If the third word is
2626 // used it should not be pointing into executable sections,
2628 this->init_opd(opd_size
);
2629 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2631 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2632 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2633 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2635 // Chances are that this is the third word of an OPD entry.
2637 typename
Exec_sections::const_iterator e
2638 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2639 if (e
!= exec_sections
.begin())
2642 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2644 // We have an address in an executable section.
2645 // VAL ought to be the function entry, set it up.
2646 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2647 // Skip second word of OPD entry, the TOC pointer.
2651 // If we didn't match any executable sections, we likely
2652 // have a non-zero third word in the OPD entry.
2657 // Relocate sections.
2659 template<int size
, bool big_endian
>
2661 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2662 const Symbol_table
* symtab
, const Layout
* layout
,
2663 const unsigned char* pshdrs
, Output_file
* of
,
2664 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2666 unsigned int start
= 1;
2668 && this->relatoc_
!= 0
2669 && !parameters
->options().relocatable())
2671 // Relocate .toc first.
2672 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2673 this->relatoc_
, this->relatoc_
);
2674 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2675 1, this->relatoc_
- 1);
2676 start
= this->relatoc_
+ 1;
2678 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2679 start
, this->shnum() - 1);
2681 if (!parameters
->options().output_is_position_independent())
2683 Target_powerpc
<size
, big_endian
>* target
2684 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2685 parameters
->sized_target
<size
, big_endian
>());
2686 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2688 const section_size_type offset
= target
->lplt_section()->offset();
2689 const section_size_type oview_size
2690 = convert_to_section_size_type(target
->lplt_section()->data_size());
2691 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2693 bool modified
= false;
2694 unsigned int nsyms
= this->local_symbol_count();
2695 for (unsigned int i
= 0; i
< nsyms
; i
++)
2696 if (this->local_has_plt_offset(i
))
2698 Address value
= this->local_symbol_value(i
, 0);
2700 value
+= ppc64_local_entry_offset(i
);
2701 size_t off
= this->local_plt_offset(i
);
2702 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2706 of
->write_output_view(offset
, oview_size
, oview
);
2711 // Set up some symbols.
2713 template<int size
, bool big_endian
>
2715 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2716 Symbol_table
* symtab
,
2721 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2722 // undefined when scanning relocs (and thus requires
2723 // non-relative dynamic relocs). The proper value will be
2725 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2726 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2728 Target_powerpc
<size
, big_endian
>* target
=
2729 static_cast<Target_powerpc
<size
, big_endian
>*>(
2730 parameters
->sized_target
<size
, big_endian
>());
2731 Output_data_got_powerpc
<size
, big_endian
>* got
2732 = target
->got_section(symtab
, layout
);
2733 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2734 Symbol_table::PREDEFINED
,
2738 elfcpp::STV_HIDDEN
, 0,
2742 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2743 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2744 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2746 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2748 = layout
->add_output_section_data(".sdata", 0,
2750 | elfcpp::SHF_WRITE
,
2751 sdata
, ORDER_SMALL_DATA
, false);
2752 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2753 Symbol_table::PREDEFINED
,
2754 os
, 32768, 0, elfcpp::STT_OBJECT
,
2755 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2761 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2762 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2763 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2765 Target_powerpc
<size
, big_endian
>* target
=
2766 static_cast<Target_powerpc
<size
, big_endian
>*>(
2767 parameters
->sized_target
<size
, big_endian
>());
2768 Output_data_got_powerpc
<size
, big_endian
>* got
2769 = target
->got_section(symtab
, layout
);
2770 symtab
->define_in_output_data(".TOC.", NULL
,
2771 Symbol_table::PREDEFINED
,
2775 elfcpp::STV_HIDDEN
, 0,
2780 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2781 if (parameters
->options().tls_get_addr_optimize()
2782 && this->tls_get_addr_
!= NULL
2783 && this->tls_get_addr_
->in_reg())
2784 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2785 if (this->tls_get_addr_opt_
!= NULL
)
2787 if (this->tls_get_addr_
->is_undefined()
2788 || this->tls_get_addr_
->is_from_dynobj())
2790 // Make it seem as if references to __tls_get_addr are
2791 // really to __tls_get_addr_opt, so the latter symbol is
2792 // made dynamic, not the former.
2793 this->tls_get_addr_
->clear_in_reg();
2794 this->tls_get_addr_opt_
->set_in_reg();
2796 // We have a non-dynamic definition for __tls_get_addr.
2797 // Make __tls_get_addr_opt the same, if it does not already have
2798 // a non-dynamic definition.
2799 else if (this->tls_get_addr_opt_
->is_undefined()
2800 || this->tls_get_addr_opt_
->is_from_dynobj())
2802 Sized_symbol
<size
>* from
2803 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2804 Sized_symbol
<size
>* to
2805 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2806 symtab
->clone
<size
>(to
, from
);
2811 // Set up PowerPC target specific relobj.
2813 template<int size
, bool big_endian
>
2815 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2816 const std::string
& name
,
2817 Input_file
* input_file
,
2818 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2820 int et
= ehdr
.get_e_type();
2821 // ET_EXEC files are valid input for --just-symbols/-R,
2822 // and we treat them as relocatable objects.
2823 if (et
== elfcpp::ET_REL
2824 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2826 Powerpc_relobj
<size
, big_endian
>* obj
=
2827 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2831 else if (et
== elfcpp::ET_DYN
)
2833 Powerpc_dynobj
<size
, big_endian
>* obj
=
2834 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2840 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2845 template<int size
, bool big_endian
>
2846 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2849 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2850 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2852 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2853 : Output_data_got
<size
, big_endian
>(),
2854 symtab_(symtab
), layout_(layout
),
2855 header_ent_cnt_(size
== 32 ? 3 : 1),
2856 header_index_(size
== 32 ? 0x2000 : 0)
2859 this->set_addralign(256);
2862 // Override all the Output_data_got methods we use so as to first call
2865 add_global(Symbol
* gsym
, unsigned int got_type
)
2867 this->reserve_ent();
2868 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2872 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2874 this->reserve_ent();
2875 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2879 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2880 { return this->add_global_plt(gsym
, got_type
); }
2883 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2884 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2886 this->reserve_ent();
2887 Output_data_got
<size
, big_endian
>::
2888 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2892 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2893 Output_data_reloc_generic
* rel_dyn
,
2894 unsigned int r_type_1
, unsigned int r_type_2
)
2896 if (gsym
->has_got_offset(got_type
))
2899 this->reserve_ent(2);
2900 Output_data_got
<size
, big_endian
>::
2901 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2905 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2907 this->reserve_ent();
2908 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2913 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2915 this->reserve_ent();
2916 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2921 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2922 { return this->add_local_plt(object
, sym_index
, got_type
); }
2925 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2926 unsigned int got_type
,
2927 Output_data_reloc_generic
* rel_dyn
,
2928 unsigned int r_type
)
2930 if (object
->local_has_got_offset(sym_index
, got_type
))
2933 this->reserve_ent(2);
2934 Output_data_got
<size
, big_endian
>::
2935 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2939 add_constant(Valtype constant
)
2941 this->reserve_ent();
2942 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2946 add_constant_pair(Valtype c1
, Valtype c2
)
2948 this->reserve_ent(2);
2949 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2952 // Offset of _GLOBAL_OFFSET_TABLE_.
2956 return this->got_offset(this->header_index_
);
2959 // Offset of base used to access the GOT/TOC.
2960 // The got/toc pointer reg will be set to this value.
2962 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2965 return this->g_o_t();
2967 return (this->output_section()->address()
2968 + object
->toc_base_offset()
2972 // Ensure our GOT has a header.
2974 set_final_data_size()
2976 if (this->header_ent_cnt_
!= 0)
2977 this->make_header();
2978 Output_data_got
<size
, big_endian
>::set_final_data_size();
2981 // First word of GOT header needs some values that are not
2982 // handled by Output_data_got so poke them in here.
2983 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2985 do_write(Output_file
* of
)
2988 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2989 val
= this->layout_
->dynamic_section()->address();
2991 val
= this->output_section()->address() + 0x8000;
2992 this->replace_constant(this->header_index_
, val
);
2993 Output_data_got
<size
, big_endian
>::do_write(of
);
2998 reserve_ent(unsigned int cnt
= 1)
3000 if (this->header_ent_cnt_
== 0)
3002 if (this->num_entries() + cnt
> this->header_index_
)
3003 this->make_header();
3009 this->header_ent_cnt_
= 0;
3010 this->header_index_
= this->num_entries();
3013 Output_data_got
<size
, big_endian
>::add_constant(0);
3014 Output_data_got
<size
, big_endian
>::add_constant(0);
3015 Output_data_got
<size
, big_endian
>::add_constant(0);
3017 // Define _GLOBAL_OFFSET_TABLE_ at the header
3018 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
3021 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
3022 sym
->set_value(this->g_o_t());
3025 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
3026 Symbol_table::PREDEFINED
,
3027 this, this->g_o_t(), 0,
3030 elfcpp::STV_HIDDEN
, 0,
3034 Output_data_got
<size
, big_endian
>::add_constant(0);
3037 // Stashed pointers.
3038 Symbol_table
* symtab_
;
3042 unsigned int header_ent_cnt_
;
3043 // GOT header index.
3044 unsigned int header_index_
;
3047 // Get the GOT section, creating it if necessary.
3049 template<int size
, bool big_endian
>
3050 Output_data_got_powerpc
<size
, big_endian
>*
3051 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
3054 if (this->got_
== NULL
)
3056 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
3059 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
3061 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
3062 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3063 this->got_
, ORDER_DATA
, false);
3069 // Get the dynamic reloc section, creating it if necessary.
3071 template<int size
, bool big_endian
>
3072 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3073 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3075 if (this->rela_dyn_
== NULL
)
3077 gold_assert(layout
!= NULL
);
3078 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3079 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3080 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3081 ORDER_DYNAMIC_RELOCS
, false);
3083 return this->rela_dyn_
;
3086 // Similarly, but for ifunc symbols get the one for ifunc.
3088 template<int size
, bool big_endian
>
3089 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3090 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3095 return this->rela_dyn_section(layout
);
3097 if (this->iplt_
== NULL
)
3098 this->make_iplt_section(symtab
, layout
);
3099 return this->iplt_
->rel_plt();
3105 // Determine the stub group size. The group size is the absolute
3106 // value of the parameter --stub-group-size. If --stub-group-size
3107 // is passed a negative value, we restrict stubs to be always after
3108 // the stubbed branches.
3109 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3110 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3111 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3112 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3113 owner_(NULL
), output_section_(NULL
)
3117 // Return true iff input section can be handled by current stub
3120 can_add_to_stub_group(Output_section
* o
,
3121 const Output_section::Input_section
* i
,
3124 const Output_section::Input_section
*
3130 { return output_section_
; }
3133 set_output_and_owner(Output_section
* o
,
3134 const Output_section::Input_section
* i
)
3136 this->output_section_
= o
;
3145 // Adding group sections before the stubs.
3146 FINDING_STUB_SECTION
,
3147 // Adding group sections after the stubs.
3151 uint32_t stub_group_size_
;
3152 bool stubs_always_after_branch_
;
3153 bool suppress_size_errors_
;
3154 // True if a stub group can serve multiple output sections.
3157 // Current max size of group. Starts at stub_group_size_ but is
3158 // reduced to stub_group_size_/1024 on seeing a section with
3159 // external conditional branches.
3160 uint32_t group_size_
;
3161 uint64_t group_start_addr_
;
3162 // owner_ and output_section_ specify the section to which stubs are
3163 // attached. The stubs are placed at the end of this section.
3164 const Output_section::Input_section
* owner_
;
3165 Output_section
* output_section_
;
3168 // Return true iff input section can be handled by current stub
3169 // group. Sections are presented to this function in order,
3170 // so the first section is the head of the group.
3173 Stub_control::can_add_to_stub_group(Output_section
* o
,
3174 const Output_section::Input_section
* i
,
3177 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3179 uint64_t start_addr
= o
->address();
3182 // .init and .fini sections are pasted together to form a single
3183 // function. We can't be adding stubs in the middle of the function.
3184 this_size
= o
->data_size();
3187 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3188 this_size
= i
->data_size();
3191 uint64_t end_addr
= start_addr
+ this_size
;
3192 uint32_t group_size
= this->stub_group_size_
;
3194 this->group_size_
= group_size
= group_size
>> 10;
3196 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3197 gold_warning(_("%s:%s exceeds group size"),
3198 i
->relobj()->name().c_str(),
3199 i
->relobj()->section_name(i
->shndx()).c_str());
3201 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3202 has14
? " 14bit" : "",
3203 i
->relobj()->name().c_str(),
3204 i
->relobj()->section_name(i
->shndx()).c_str(),
3205 (long long) this_size
,
3206 (this->state_
== NO_GROUP
3208 : (long long) end_addr
- this->group_start_addr_
));
3210 if (this->state_
== NO_GROUP
)
3212 // Only here on very first use of Stub_control
3214 this->output_section_
= o
;
3215 this->state_
= FINDING_STUB_SECTION
;
3216 this->group_size_
= group_size
;
3217 this->group_start_addr_
= start_addr
;
3220 else if (!this->multi_os_
&& this->output_section_
!= o
)
3222 else if (this->state_
== HAS_STUB_SECTION
)
3224 // Can we add this section, which is after the stubs, to the
3226 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3229 else if (this->state_
== FINDING_STUB_SECTION
)
3231 if ((whole_sec
&& this->output_section_
== o
)
3232 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3234 // Stubs are added at the end of "owner_".
3236 this->output_section_
= o
;
3239 // The group before the stubs has reached maximum size.
3240 // Now see about adding sections after the stubs to the
3241 // group. If the current section has a 14-bit branch and
3242 // the group before the stubs exceeds group_size_ (because
3243 // they didn't have 14-bit branches), don't add sections
3244 // after the stubs: The size of stubs for such a large
3245 // group may exceed the reach of a 14-bit branch.
3246 if (!this->stubs_always_after_branch_
3247 && this_size
<= this->group_size_
3248 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3250 gold_debug(DEBUG_TARGET
, "adding after stubs");
3251 this->state_
= HAS_STUB_SECTION
;
3252 this->group_start_addr_
= start_addr
;
3259 gold_debug(DEBUG_TARGET
,
3260 !this->multi_os_
&& this->output_section_
!= o
3261 ? "nope, new output section\n"
3262 : "nope, didn't fit\n");
3264 // The section fails to fit in the current group. Set up a few
3265 // things for the next group. owner_ and output_section_ will be
3266 // set later after we've retrieved those values for the current
3268 this->state_
= FINDING_STUB_SECTION
;
3269 this->group_size_
= group_size
;
3270 this->group_start_addr_
= start_addr
;
3274 // Look over all the input sections, deciding where to place stubs.
3276 template<int size
, bool big_endian
>
3278 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3280 bool no_size_errors
)
3282 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3283 parameters
->options().stub_group_multi());
3285 // Group input sections and insert stub table
3286 Stub_table_owner
* table_owner
= NULL
;
3287 std::vector
<Stub_table_owner
*> tables
;
3288 Layout::Section_list section_list
;
3289 layout
->get_executable_sections(§ion_list
);
3290 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3291 for (Layout::Section_list::iterator o
= section_list
.begin();
3292 o
!= section_list
.end();
3295 typedef Output_section::Input_section_list Input_section_list
;
3296 for (Input_section_list::const_iterator i
3297 = (*o
)->input_sections().begin();
3298 i
!= (*o
)->input_sections().end();
3301 if (i
->is_input_section()
3302 || i
->is_relaxed_input_section())
3304 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3305 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3306 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3307 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3309 table_owner
->output_section
= stub_control
.output_section();
3310 table_owner
->owner
= stub_control
.owner();
3311 stub_control
.set_output_and_owner(*o
, &*i
);
3314 if (table_owner
== NULL
)
3316 table_owner
= new Stub_table_owner
;
3317 tables
.push_back(table_owner
);
3319 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3323 if (table_owner
!= NULL
)
3325 table_owner
->output_section
= stub_control
.output_section();
3326 table_owner
->owner
= stub_control
.owner();;
3328 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3332 Stub_table
<size
, big_endian
>* stub_table
;
3334 if ((*t
)->owner
->is_input_section())
3335 stub_table
= new Stub_table
<size
, big_endian
>(this,
3336 (*t
)->output_section
,
3338 this->stub_tables_
.size());
3339 else if ((*t
)->owner
->is_relaxed_input_section())
3340 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3341 (*t
)->owner
->relaxed_input_section());
3344 this->stub_tables_
.push_back(stub_table
);
3350 static unsigned long
3351 max_branch_delta (unsigned int r_type
)
3353 if (r_type
== elfcpp::R_POWERPC_REL14
3354 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3355 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3357 if (r_type
== elfcpp::R_POWERPC_REL24
3358 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3359 || r_type
== elfcpp::R_PPC_PLTREL24
3360 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3365 // Return whether this branch is going via a plt call stub.
3367 template<int size
, bool big_endian
>
3369 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3370 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3373 Target_powerpc
* target
,
3374 Symbol_table
* symtab
)
3376 if (this->object_
!= ppc_object
3377 || this->shndx_
!= shndx
3378 || this->offset_
!= offset
)
3381 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3382 if (sym
!= NULL
&& sym
->is_forwarder())
3383 sym
= symtab
->resolve_forwards(sym
);
3384 if (target
->replace_tls_get_addr(sym
))
3385 sym
= target
->tls_get_addr_opt();
3386 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3388 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3389 && !target
->is_elfv2_localentry0(gsym
))
3390 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3391 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3399 // If this branch needs a plt call stub, or a long branch stub, make one.
3401 template<int size
, bool big_endian
>
3403 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3404 Stub_table
<size
, big_endian
>* stub_table
,
3405 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3406 Symbol_table
* symtab
) const
3408 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3409 Target_powerpc
<size
, big_endian
>* target
=
3410 static_cast<Target_powerpc
<size
, big_endian
>*>(
3411 parameters
->sized_target
<size
, big_endian
>());
3412 if (sym
!= NULL
&& sym
->is_forwarder())
3413 sym
= symtab
->resolve_forwards(sym
);
3414 if (target
->replace_tls_get_addr(sym
))
3415 sym
= target
->tls_get_addr_opt();
3416 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3420 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3421 : this->object_
->local_has_plt_offset(this->r_sym_
))
3425 && target
->abiversion() >= 2
3426 && !parameters
->options().output_is_position_independent()
3427 && !is_branch_reloc
<size
>(this->r_type_
))
3428 target
->glink_section()->add_global_entry(gsym
);
3431 if (stub_table
== NULL
3434 && !parameters
->options().output_is_position_independent()
3435 && !is_branch_reloc
<size
>(this->r_type_
)))
3436 stub_table
= this->object_
->stub_table(this->shndx_
);
3437 if (stub_table
== NULL
)
3439 // This is a ref from a data section to an ifunc symbol,
3440 // or a non-branch reloc for which we always want to use
3441 // one set of stubs for resolving function addresses.
3442 stub_table
= ifunc_stub_table
;
3444 gold_assert(stub_table
!= NULL
);
3445 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3446 if (from
!= invalid_address
)
3447 from
+= (this->object_
->output_section(this->shndx_
)->address()
3450 ok
= stub_table
->add_plt_call_entry(from
,
3451 this->object_
, gsym
,
3452 this->r_type_
, this->addend_
,
3455 ok
= stub_table
->add_plt_call_entry(from
,
3456 this->object_
, this->r_sym_
,
3457 this->r_type_
, this->addend_
,
3463 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3464 if (max_branch_offset
== 0)
3466 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3467 gold_assert(from
!= invalid_address
);
3468 from
+= (this->object_
->output_section(this->shndx_
)->address()
3473 switch (gsym
->source())
3475 case Symbol::FROM_OBJECT
:
3477 Object
* symobj
= gsym
->object();
3478 if (symobj
->is_dynamic()
3479 || symobj
->pluginobj() != NULL
)
3482 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3483 if (shndx
== elfcpp::SHN_UNDEF
)
3488 case Symbol::IS_UNDEFINED
:
3494 Symbol_table::Compute_final_value_status status
;
3495 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3496 if (status
!= Symbol_table::CFVS_OK
)
3499 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3503 const Symbol_value
<size
>* psymval
3504 = this->object_
->local_symbol(this->r_sym_
);
3505 Symbol_value
<size
> symval
;
3506 if (psymval
->is_section_symbol())
3507 symval
.set_is_section_symbol();
3508 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3509 typename
ObjType::Compute_final_local_value_status status
3510 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3512 if (status
!= ObjType::CFLV_OK
3513 || !symval
.has_output_value())
3515 to
= symval
.value(this->object_
, 0);
3517 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3519 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3520 to
+= this->addend_
;
3521 if (stub_table
== NULL
)
3522 stub_table
= this->object_
->stub_table(this->shndx_
);
3523 if (size
== 64 && target
->abiversion() < 2)
3525 unsigned int dest_shndx
;
3526 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3530 Address delta
= to
- from
;
3531 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3533 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3535 ? this->object_
->ppc64_needs_toc(gsym
)
3536 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3538 if (stub_table
== NULL
)
3540 gold_warning(_("%s:%s: branch in non-executable section,"
3541 " no long branch stub for you"),
3542 this->object_
->name().c_str(),
3543 this->object_
->section_name(this->shndx_
).c_str());
3546 bool save_res
= (size
== 64
3548 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3549 && gsym
->output_data() == target
->savres_section());
3550 ok
= stub_table
->add_long_branch_entry(this->object_
,
3552 from
, to
, save_res
);
3556 gold_debug(DEBUG_TARGET
,
3557 "branch at %s:%s+%#lx\n"
3558 "can't reach stub attached to %s:%s",
3559 this->object_
->name().c_str(),
3560 this->object_
->section_name(this->shndx_
).c_str(),
3561 (unsigned long) this->offset_
,
3562 stub_table
->relobj()->name().c_str(),
3563 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3568 // Relaxation hook. This is where we do stub generation.
3570 template<int size
, bool big_endian
>
3572 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3573 const Input_objects
*,
3574 Symbol_table
* symtab
,
3578 unsigned int prev_brlt_size
= 0;
3582 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3584 && this->abiversion() < 2
3586 && !parameters
->options().user_set_plt_thread_safe())
3588 static const char* const thread_starter
[] =
3592 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3594 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3595 "mq_notify", "create_timer",
3600 "GOMP_parallel_start",
3601 "GOMP_parallel_loop_static",
3602 "GOMP_parallel_loop_static_start",
3603 "GOMP_parallel_loop_dynamic",
3604 "GOMP_parallel_loop_dynamic_start",
3605 "GOMP_parallel_loop_guided",
3606 "GOMP_parallel_loop_guided_start",
3607 "GOMP_parallel_loop_runtime",
3608 "GOMP_parallel_loop_runtime_start",
3609 "GOMP_parallel_sections",
3610 "GOMP_parallel_sections_start",
3615 if (parameters
->options().shared())
3619 for (unsigned int i
= 0;
3620 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3623 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3624 thread_safe
= (sym
!= NULL
3626 && sym
->in_real_elf());
3632 this->plt_thread_safe_
= thread_safe
;
3637 this->stub_group_size_
= parameters
->options().stub_group_size();
3638 bool no_size_errors
= true;
3639 if (this->stub_group_size_
== 1)
3640 this->stub_group_size_
= 0x1c00000;
3641 else if (this->stub_group_size_
== -1)
3642 this->stub_group_size_
= -0x1e00000;
3644 no_size_errors
= false;
3645 this->group_sections(layout
, task
, no_size_errors
);
3647 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3649 this->branch_lookup_table_
.clear();
3650 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3651 p
!= this->stub_tables_
.end();
3654 (*p
)->clear_stubs(true);
3656 this->stub_tables_
.clear();
3657 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3658 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3659 program_name
, this->stub_group_size_
);
3660 this->group_sections(layout
, task
, true);
3663 // We need address of stub tables valid for make_stub.
3664 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3665 p
!= this->stub_tables_
.end();
3668 const Powerpc_relobj
<size
, big_endian
>* object
3669 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3670 Address off
= object
->get_output_section_offset((*p
)->shndx());
3671 gold_assert(off
!= invalid_address
);
3672 Output_section
* os
= (*p
)->output_section();
3673 (*p
)->set_address_and_size(os
, off
);
3678 // Clear plt call stubs, long branch stubs and branch lookup table.
3679 prev_brlt_size
= this->branch_lookup_table_
.size();
3680 this->branch_lookup_table_
.clear();
3681 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3682 p
!= this->stub_tables_
.end();
3685 (*p
)->clear_stubs(false);
3689 // Build all the stubs.
3690 this->relax_failed_
= false;
3691 Stub_table
<size
, big_endian
>* ifunc_stub_table
3692 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3693 Stub_table
<size
, big_endian
>* one_stub_table
3694 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3695 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3696 b
!= this->branch_info_
.end();
3699 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3700 && !this->relax_failed_
)
3702 this->relax_failed_
= true;
3703 this->relax_fail_count_
++;
3704 if (this->relax_fail_count_
< 3)
3708 bool do_resize
= false;
3709 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3710 p
!= this->stub_tables_
.end();
3712 if ((*p
)->need_resize())
3719 this->branch_lookup_table_
.clear();
3720 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3721 p
!= this->stub_tables_
.end();
3723 (*p
)->set_resizing(true);
3724 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3725 b
!= this->branch_info_
.end();
3728 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3729 && !this->relax_failed_
)
3731 this->relax_failed_
= true;
3732 this->relax_fail_count_
++;
3733 if (this->relax_fail_count_
< 3)
3737 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3738 p
!= this->stub_tables_
.end();
3740 (*p
)->set_resizing(false);
3743 // Did anything change size?
3744 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3745 bool again
= num_huge_branches
!= prev_brlt_size
;
3746 if (size
== 64 && num_huge_branches
!= 0)
3747 this->make_brlt_section(layout
);
3748 if (size
== 64 && again
)
3749 this->brlt_section_
->set_current_size(num_huge_branches
);
3751 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3752 p
!= this->stub_tables_
.rend();
3754 (*p
)->remove_eh_frame(layout
);
3756 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3757 p
!= this->stub_tables_
.end();
3759 (*p
)->add_eh_frame(layout
);
3761 typedef Unordered_set
<Output_section
*> Output_sections
;
3762 Output_sections os_need_update
;
3763 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3764 p
!= this->stub_tables_
.end();
3767 if ((*p
)->size_update())
3770 os_need_update
.insert((*p
)->output_section());
3774 // Set output section offsets for all input sections in an output
3775 // section that just changed size. Anything past the stubs will
3777 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3778 p
!= os_need_update
.end();
3781 Output_section
* os
= *p
;
3783 typedef Output_section::Input_section_list Input_section_list
;
3784 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3785 i
!= os
->input_sections().end();
3788 off
= align_address(off
, i
->addralign());
3789 if (i
->is_input_section() || i
->is_relaxed_input_section())
3790 i
->relobj()->set_section_offset(i
->shndx(), off
);
3791 if (i
->is_relaxed_input_section())
3793 Stub_table
<size
, big_endian
>* stub_table
3794 = static_cast<Stub_table
<size
, big_endian
>*>(
3795 i
->relaxed_input_section());
3796 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3797 off
+= stub_table_size
;
3798 // After a few iterations, set current stub table size
3799 // as min size threshold, so later stub tables can only
3802 stub_table
->set_min_size_threshold(stub_table_size
);
3805 off
+= i
->data_size();
3807 // If .branch_lt is part of this output section, then we have
3808 // just done the offset adjustment.
3809 os
->clear_section_offsets_need_adjustment();
3814 && num_huge_branches
!= 0
3815 && parameters
->options().output_is_position_independent())
3817 // Fill in the BRLT relocs.
3818 this->brlt_section_
->reset_brlt_sizes();
3819 for (typename
Branch_lookup_table::const_iterator p
3820 = this->branch_lookup_table_
.begin();
3821 p
!= this->branch_lookup_table_
.end();
3824 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3826 this->brlt_section_
->finalize_brlt_sizes();
3830 && (parameters
->options().user_set_emit_stub_syms()
3831 ? parameters
->options().emit_stub_syms()
3833 || parameters
->options().output_is_position_independent()
3834 || parameters
->options().emit_relocs())))
3836 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3837 p
!= this->stub_tables_
.end();
3839 (*p
)->define_stub_syms(symtab
);
3841 if (this->glink_
!= NULL
)
3843 int stub_size
= this->glink_
->pltresolve_size();
3844 Address value
= -stub_size
;
3850 this->define_local(symtab
, "__glink_PLTresolve",
3851 this->glink_
, value
, stub_size
);
3854 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3861 template<int size
, bool big_endian
>
3863 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3864 unsigned char* oview
,
3868 uint64_t address
= plt
->address();
3869 off_t len
= plt
->data_size();
3871 if (plt
== this->glink_
)
3873 // See Output_data_glink::do_write() for glink contents.
3876 gold_assert(parameters
->doing_static_link());
3877 // Static linking may need stubs, to support ifunc and long
3878 // branches. We need to create an output section for
3879 // .eh_frame early in the link process, to have a place to
3880 // attach stub .eh_frame info. We also need to have
3881 // registered a CIE that matches the stub CIE. Both of
3882 // these requirements are satisfied by creating an FDE and
3883 // CIE for .glink, even though static linking will leave
3884 // .glink zero length.
3885 // ??? Hopefully generating an FDE with a zero address range
3886 // won't confuse anything that consumes .eh_frame info.
3888 else if (size
== 64)
3890 // There is one word before __glink_PLTresolve
3894 else if (parameters
->options().output_is_position_independent())
3896 // There are two FDEs for a position independent glink.
3897 // The first covers the branch table, the second
3898 // __glink_PLTresolve at the end of glink.
3899 off_t resolve_size
= this->glink_
->pltresolve_size();
3900 if (oview
[9] == elfcpp::DW_CFA_nop
)
3901 len
-= resolve_size
;
3904 address
+= len
- resolve_size
;
3911 // Must be a stub table.
3912 const Stub_table
<size
, big_endian
>* stub_table
3913 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3914 uint64_t stub_address
= stub_table
->stub_address();
3915 len
-= stub_address
- address
;
3916 address
= stub_address
;
3919 *paddress
= address
;
3923 // A class to handle the PLT data.
3925 template<int size
, bool big_endian
>
3926 class Output_data_plt_powerpc
: public Output_section_data_build
3929 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3930 size
, big_endian
> Reloc_section
;
3932 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3933 Reloc_section
* plt_rel
,
3935 : Output_section_data_build(size
== 32 ? 4 : 8),
3941 // Add an entry to the PLT.
3946 add_ifunc_entry(Symbol
*);
3949 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3952 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3954 // Return the .rela.plt section data.
3961 // Return the number of PLT entries.
3965 if (this->current_data_size() == 0)
3967 return ((this->current_data_size() - this->first_plt_entry_offset())
3968 / this->plt_entry_size());
3973 do_adjust_output_section(Output_section
* os
)
3978 // Write to a map file.
3980 do_print_to_mapfile(Mapfile
* mapfile
) const
3981 { mapfile
->print_output_data(this, this->name_
); }
3984 // Return the offset of the first non-reserved PLT entry.
3986 first_plt_entry_offset() const
3988 // IPLT and LPLT have no reserved entry.
3989 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
3991 return this->targ_
->first_plt_entry_offset();
3994 // Return the size of each PLT entry.
3996 plt_entry_size() const
3998 return this->targ_
->plt_entry_size();
4001 // Write out the PLT data.
4003 do_write(Output_file
*);
4005 // The reloc section.
4006 Reloc_section
* rel_
;
4007 // Allows access to .glink for do_write.
4008 Target_powerpc
<size
, big_endian
>* targ_
;
4009 // What to report in map file.
4013 // Add an entry to the PLT.
4015 template<int size
, bool big_endian
>
4017 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
4019 if (!gsym
->has_plt_offset())
4021 section_size_type off
= this->current_data_size();
4023 off
+= this->first_plt_entry_offset();
4024 gsym
->set_plt_offset(off
);
4025 gsym
->set_needs_dynsym_entry();
4026 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4027 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
4028 off
+= this->plt_entry_size();
4029 this->set_current_data_size(off
);
4033 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
4035 template<int size
, bool big_endian
>
4037 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
4039 if (!gsym
->has_plt_offset())
4041 section_size_type off
= this->current_data_size();
4042 gsym
->set_plt_offset(off
);
4043 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4044 if (size
== 64 && this->targ_
->abiversion() < 2)
4045 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4046 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
4047 off
+= this->plt_entry_size();
4048 this->set_current_data_size(off
);
4052 // Add an entry for a local symbol to the PLT.
4054 template<int size
, bool big_endian
>
4056 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
4057 Sized_relobj_file
<size
, big_endian
>* relobj
,
4058 unsigned int local_sym_index
)
4060 if (!relobj
->local_has_plt_offset(local_sym_index
))
4062 section_size_type off
= this->current_data_size();
4063 relobj
->set_local_plt_offset(local_sym_index
, off
);
4066 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4067 if (size
== 64 && this->targ_
->abiversion() < 2)
4068 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4069 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4070 dynrel
, this, off
, 0);
4072 off
+= this->plt_entry_size();
4073 this->set_current_data_size(off
);
4077 // Add an entry for a local ifunc symbol to the IPLT.
4079 template<int size
, bool big_endian
>
4081 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4082 Sized_relobj_file
<size
, big_endian
>* relobj
,
4083 unsigned int local_sym_index
)
4085 if (!relobj
->local_has_plt_offset(local_sym_index
))
4087 section_size_type off
= this->current_data_size();
4088 relobj
->set_local_plt_offset(local_sym_index
, off
);
4089 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4090 if (size
== 64 && this->targ_
->abiversion() < 2)
4091 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4092 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4094 off
+= this->plt_entry_size();
4095 this->set_current_data_size(off
);
4099 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4100 static const uint32_t add_2_2_11
= 0x7c425a14;
4101 static const uint32_t add_2_2_12
= 0x7c426214;
4102 static const uint32_t add_3_3_2
= 0x7c631214;
4103 static const uint32_t add_3_3_13
= 0x7c636a14;
4104 static const uint32_t add_3_12_2
= 0x7c6c1214;
4105 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4106 static const uint32_t add_11_0_11
= 0x7d605a14;
4107 static const uint32_t add_11_2_11
= 0x7d625a14;
4108 static const uint32_t add_11_11_2
= 0x7d6b1214;
4109 static const uint32_t add_12_11_12
= 0x7d8b6214;
4110 static const uint32_t addi_0_12
= 0x380c0000;
4111 static const uint32_t addi_2_2
= 0x38420000;
4112 static const uint32_t addi_3_3
= 0x38630000;
4113 static const uint32_t addi_11_11
= 0x396b0000;
4114 static const uint32_t addi_12_1
= 0x39810000;
4115 static const uint32_t addi_12_11
= 0x398b0000;
4116 static const uint32_t addi_12_12
= 0x398c0000;
4117 static const uint32_t addis_0_2
= 0x3c020000;
4118 static const uint32_t addis_0_13
= 0x3c0d0000;
4119 static const uint32_t addis_2_12
= 0x3c4c0000;
4120 static const uint32_t addis_11_2
= 0x3d620000;
4121 static const uint32_t addis_11_11
= 0x3d6b0000;
4122 static const uint32_t addis_11_30
= 0x3d7e0000;
4123 static const uint32_t addis_12_1
= 0x3d810000;
4124 static const uint32_t addis_12_2
= 0x3d820000;
4125 static const uint32_t addis_12_11
= 0x3d8b0000;
4126 static const uint32_t addis_12_12
= 0x3d8c0000;
4127 static const uint32_t b
= 0x48000000;
4128 static const uint32_t bcl_20_31
= 0x429f0005;
4129 static const uint32_t bctr
= 0x4e800420;
4130 static const uint32_t bctrl
= 0x4e800421;
4131 static const uint32_t beqlr
= 0x4d820020;
4132 static const uint32_t blr
= 0x4e800020;
4133 static const uint32_t bnectr_p4
= 0x4ce20420;
4134 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4135 static const uint32_t cmpldi_2_0
= 0x28220000;
4136 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4137 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4138 static const uint32_t cror_15_15_15
= 0x4def7b82;
4139 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4140 static const uint32_t ld_0_1
= 0xe8010000;
4141 static const uint32_t ld_0_12
= 0xe80c0000;
4142 static const uint32_t ld_2_1
= 0xe8410000;
4143 static const uint32_t ld_2_2
= 0xe8420000;
4144 static const uint32_t ld_2_11
= 0xe84b0000;
4145 static const uint32_t ld_2_12
= 0xe84c0000;
4146 static const uint32_t ld_11_1
= 0xe9610000;
4147 static const uint32_t ld_11_2
= 0xe9620000;
4148 static const uint32_t ld_11_3
= 0xe9630000;
4149 static const uint32_t ld_11_11
= 0xe96b0000;
4150 static const uint32_t ld_12_2
= 0xe9820000;
4151 static const uint32_t ld_12_3
= 0xe9830000;
4152 static const uint32_t ld_12_11
= 0xe98b0000;
4153 static const uint32_t ld_12_12
= 0xe98c0000;
4154 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4155 static const uint32_t lfd_0_1
= 0xc8010000;
4156 static const uint32_t li_0_0
= 0x38000000;
4157 static const uint32_t li_11_0
= 0x39600000;
4158 static const uint32_t li_12_0
= 0x39800000;
4159 static const uint32_t lis_0
= 0x3c000000;
4160 static const uint32_t lis_2
= 0x3c400000;
4161 static const uint32_t lis_11
= 0x3d600000;
4162 static const uint32_t lis_12
= 0x3d800000;
4163 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4164 static const uint32_t lwz_0_12
= 0x800c0000;
4165 static const uint32_t lwz_11_3
= 0x81630000;
4166 static const uint32_t lwz_11_11
= 0x816b0000;
4167 static const uint32_t lwz_11_30
= 0x817e0000;
4168 static const uint32_t lwz_12_3
= 0x81830000;
4169 static const uint32_t lwz_12_12
= 0x818c0000;
4170 static const uint32_t lwzu_0_12
= 0x840c0000;
4171 static const uint32_t mflr_0
= 0x7c0802a6;
4172 static const uint32_t mflr_11
= 0x7d6802a6;
4173 static const uint32_t mflr_12
= 0x7d8802a6;
4174 static const uint32_t mr_0_3
= 0x7c601b78;
4175 static const uint32_t mr_3_0
= 0x7c030378;
4176 static const uint32_t mtctr_0
= 0x7c0903a6;
4177 static const uint32_t mtctr_11
= 0x7d6903a6;
4178 static const uint32_t mtctr_12
= 0x7d8903a6;
4179 static const uint32_t mtlr_0
= 0x7c0803a6;
4180 static const uint32_t mtlr_11
= 0x7d6803a6;
4181 static const uint32_t mtlr_12
= 0x7d8803a6;
4182 static const uint32_t nop
= 0x60000000;
4183 static const uint32_t ori_0_0_0
= 0x60000000;
4184 static const uint32_t ori_11_11_0
= 0x616b0000;
4185 static const uint32_t ori_12_12_0
= 0x618c0000;
4186 static const uint32_t oris_12_12_0
= 0x658c0000;
4187 static const uint32_t sldi_11_11_34
= 0x796b1746;
4188 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4189 static const uint32_t srdi_0_0_2
= 0x7800f082;
4190 static const uint32_t std_0_1
= 0xf8010000;
4191 static const uint32_t std_0_12
= 0xf80c0000;
4192 static const uint32_t std_2_1
= 0xf8410000;
4193 static const uint32_t std_11_1
= 0xf9610000;
4194 static const uint32_t stfd_0_1
= 0xd8010000;
4195 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4196 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4197 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4198 static const uint32_t xor_2_12_12
= 0x7d826278;
4199 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4201 static const uint64_t paddi_12_pc
= 0x0610000039800000ULL
;
4202 static const uint64_t pld_12_pc
= 0x04100000e5800000ULL
;
4203 static const uint64_t pnop
= 0x0700000000000000ULL
;
4205 // Write out the PLT.
4207 template<int size
, bool big_endian
>
4209 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4211 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4213 const section_size_type offset
= this->offset();
4214 const section_size_type oview_size
4215 = convert_to_section_size_type(this->data_size());
4216 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4217 unsigned char* pov
= oview
;
4218 unsigned char* endpov
= oview
+ oview_size
;
4220 // The address of the .glink branch table
4221 const Output_data_glink
<size
, big_endian
>* glink
4222 = this->targ_
->glink_section();
4223 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4225 while (pov
< endpov
)
4227 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4232 of
->write_output_view(offset
, oview_size
, oview
);
4236 // Create the PLT section.
4238 template<int size
, bool big_endian
>
4240 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4243 if (this->plt_
== NULL
)
4245 if (this->got_
== NULL
)
4246 this->got_section(symtab
, layout
);
4248 if (this->glink_
== NULL
)
4249 make_glink_section(layout
);
4251 // Ensure that .rela.dyn always appears before .rela.plt This is
4252 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4253 // needs to include .rela.plt in its range.
4254 this->rela_dyn_section(layout
);
4256 Reloc_section
* plt_rel
= new Reloc_section(false);
4257 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4258 elfcpp::SHF_ALLOC
, plt_rel
,
4259 ORDER_DYNAMIC_PLT_RELOCS
, false);
4261 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4263 layout
->add_output_section_data(".plt",
4265 ? elfcpp::SHT_PROGBITS
4266 : elfcpp::SHT_NOBITS
),
4267 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4274 Output_section
* rela_plt_os
= plt_rel
->output_section();
4275 rela_plt_os
->set_info_section(this->plt_
->output_section());
4279 // Create the IPLT section.
4281 template<int size
, bool big_endian
>
4283 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4286 if (this->iplt_
== NULL
)
4288 this->make_plt_section(symtab
, layout
);
4289 this->make_lplt_section(layout
);
4291 Reloc_section
* iplt_rel
= new Reloc_section(false);
4292 if (this->rela_dyn_
->output_section())
4293 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4295 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4297 if (this->plt_
->output_section())
4298 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4302 // Create the LPLT section.
4304 template<int size
, bool big_endian
>
4306 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4308 if (this->lplt_
== NULL
)
4310 Reloc_section
* lplt_rel
= NULL
;
4311 if (parameters
->options().output_is_position_independent())
4313 lplt_rel
= new Reloc_section(false);
4314 this->rela_dyn_section(layout
);
4315 if (this->rela_dyn_
->output_section())
4316 this->rela_dyn_
->output_section()
4317 ->add_output_section_data(lplt_rel
);
4320 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4322 this->make_brlt_section(layout
);
4323 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4324 this->brlt_section_
->output_section()
4325 ->add_output_section_data(this->lplt_
);
4327 layout
->add_output_section_data(".branch_lt",
4328 elfcpp::SHT_PROGBITS
,
4329 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4336 // A section for huge long branch addresses, similar to plt section.
4338 template<int size
, bool big_endian
>
4339 class Output_data_brlt_powerpc
: public Output_section_data_build
4342 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4343 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4344 size
, big_endian
> Reloc_section
;
4346 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4347 Reloc_section
* brlt_rel
)
4348 : Output_section_data_build(size
== 32 ? 4 : 8),
4356 this->reset_data_size();
4357 this->rel_
->reset_data_size();
4361 finalize_brlt_sizes()
4363 this->finalize_data_size();
4364 this->rel_
->finalize_data_size();
4367 // Add a reloc for an entry in the BRLT.
4369 add_reloc(Address to
, unsigned int off
)
4370 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4372 // Update section and reloc section size.
4374 set_current_size(unsigned int num_branches
)
4376 this->reset_address_and_file_offset();
4377 this->set_current_data_size(num_branches
* 16);
4378 this->finalize_data_size();
4379 Output_section
* os
= this->output_section();
4380 os
->set_section_offsets_need_adjustment();
4381 if (this->rel_
!= NULL
)
4383 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4384 this->rel_
->reset_address_and_file_offset();
4385 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4386 this->rel_
->finalize_data_size();
4387 Output_section
* os
= this->rel_
->output_section();
4388 os
->set_section_offsets_need_adjustment();
4394 do_adjust_output_section(Output_section
* os
)
4399 // Write to a map file.
4401 do_print_to_mapfile(Mapfile
* mapfile
) const
4402 { mapfile
->print_output_data(this, "** BRLT"); }
4405 // Write out the BRLT data.
4407 do_write(Output_file
*);
4409 // The reloc section.
4410 Reloc_section
* rel_
;
4411 Target_powerpc
<size
, big_endian
>* targ_
;
4414 // Make the branch lookup table section.
4416 template<int size
, bool big_endian
>
4418 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4420 if (size
== 64 && this->brlt_section_
== NULL
)
4422 Reloc_section
* brlt_rel
= NULL
;
4423 bool is_pic
= parameters
->options().output_is_position_independent();
4426 // When PIC we can't fill in .branch_lt but must initialise at
4427 // runtime via dynamic relocations.
4428 this->rela_dyn_section(layout
);
4429 brlt_rel
= new Reloc_section(false);
4430 if (this->rela_dyn_
->output_section())
4431 this->rela_dyn_
->output_section()
4432 ->add_output_section_data(brlt_rel
);
4435 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4436 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4437 this->plt_
->output_section()
4438 ->add_output_section_data(this->brlt_section_
);
4440 layout
->add_output_section_data(".branch_lt",
4441 elfcpp::SHT_PROGBITS
,
4442 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4443 this->brlt_section_
,
4449 // Write out .branch_lt when non-PIC.
4451 template<int size
, bool big_endian
>
4453 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4455 if (size
== 64 && !parameters
->options().output_is_position_independent())
4457 const section_size_type offset
= this->offset();
4458 const section_size_type oview_size
4459 = convert_to_section_size_type(this->data_size());
4460 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4462 this->targ_
->write_branch_lookup_table(oview
);
4463 of
->write_output_view(offset
, oview_size
, oview
);
4467 static inline uint32_t
4473 static inline uint32_t
4479 static inline uint32_t
4482 return hi(a
+ 0x8000);
4485 static inline uint64_t
4488 return ((v
& 0x3ffff0000ULL
) << 16) | (v
& 0xffff);
4491 static inline uint64_t
4494 return (v
+ (1ULL << 33)) >> 34;
4500 static const unsigned char eh_frame_cie
[12];
4504 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4507 'z', 'R', 0, // Augmentation string.
4508 4, // Code alignment.
4509 0x80 - size
/ 8 , // Data alignment.
4511 1, // Augmentation size.
4512 (elfcpp::DW_EH_PE_pcrel
4513 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4514 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4517 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4518 static const unsigned char glink_eh_frame_fde_64v1
[] =
4520 0, 0, 0, 0, // Replaced with offset to .glink.
4521 0, 0, 0, 0, // Replaced with size of .glink.
4522 0, // Augmentation size.
4523 elfcpp::DW_CFA_advance_loc
+ 1,
4524 elfcpp::DW_CFA_register
, 65, 12,
4525 elfcpp::DW_CFA_advance_loc
+ 5,
4526 elfcpp::DW_CFA_restore_extended
, 65
4529 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4530 static const unsigned char glink_eh_frame_fde_64v2
[] =
4532 0, 0, 0, 0, // Replaced with offset to .glink.
4533 0, 0, 0, 0, // Replaced with size of .glink.
4534 0, // Augmentation size.
4535 elfcpp::DW_CFA_advance_loc
+ 1,
4536 elfcpp::DW_CFA_register
, 65, 0,
4537 elfcpp::DW_CFA_advance_loc
+ 7,
4538 elfcpp::DW_CFA_restore_extended
, 65
4541 // Describe __glink_PLTresolve use of LR, 32-bit version.
4542 static const unsigned char glink_eh_frame_fde_32
[] =
4544 0, 0, 0, 0, // Replaced with offset to .glink.
4545 0, 0, 0, 0, // Replaced with size of .glink.
4546 0, // Augmentation size.
4547 elfcpp::DW_CFA_advance_loc
+ 2,
4548 elfcpp::DW_CFA_register
, 65, 0,
4549 elfcpp::DW_CFA_advance_loc
+ 4,
4550 elfcpp::DW_CFA_restore_extended
, 65
4553 static const unsigned char default_fde
[] =
4555 0, 0, 0, 0, // Replaced with offset to stubs.
4556 0, 0, 0, 0, // Replaced with size of stubs.
4557 0, // Augmentation size.
4558 elfcpp::DW_CFA_nop
, // Pad.
4563 template<bool big_endian
>
4565 write_insn(unsigned char* p
, uint32_t v
)
4567 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4571 static inline unsigned int
4574 if (!parameters
->options().user_set_plt_align())
4575 return size
== 64 ? 32 : 8;
4576 return 1 << parameters
->options().plt_align();
4579 // Stub_table holds information about plt and long branch stubs.
4580 // Stubs are built in an area following some input section determined
4581 // by group_sections(). This input section is converted to a relaxed
4582 // input section allowing it to be resized to accommodate the stubs
4584 template<int size
, bool big_endian
>
4585 class Stub_table
: public Output_relaxed_input_section
4590 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4591 : off_(off
), indx_(indx
), iter_(0), notoc_(0), r2save_(0), localentry0_(0)
4595 unsigned int indx_
: 28;
4596 unsigned int iter_
: 1;
4597 unsigned int notoc_
: 1;
4598 unsigned int r2save_
: 1;
4599 unsigned int localentry0_
: 1;
4601 struct Branch_stub_ent
4603 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4604 : off_(off
), iter_(false), notoc_(notoc
), save_res_(save_res
)
4612 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4613 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4615 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4616 Output_section
* output_section
,
4617 const Output_section::Input_section
* owner
,
4619 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4621 ->section_addralign(owner
->shndx())),
4622 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4623 orig_data_size_(owner
->current_data_size()),
4624 plt_size_(0), last_plt_size_(0),
4625 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4626 need_save_res_(false), need_resize_(false), resizing_(false),
4629 this->set_output_section(output_section
);
4631 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4632 new_relaxed
.push_back(this);
4633 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4636 // Add a plt call stub.
4638 add_plt_call_entry(Address
,
4639 const Sized_relobj_file
<size
, big_endian
>*,
4646 add_plt_call_entry(Address
,
4647 const Sized_relobj_file
<size
, big_endian
>*,
4653 // Find a given plt call stub.
4655 find_plt_call_entry(const Symbol
*) const;
4658 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4659 unsigned int) const;
4662 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4668 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4673 // Add a long branch stub.
4675 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4676 unsigned int, Address
, Address
, bool);
4678 const Branch_stub_ent
*
4679 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4683 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4685 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4686 if (max_branch_offset
== 0)
4688 gold_assert(from
!= invalid_address
);
4689 Address loc
= off
+ this->stub_address();
4690 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4694 clear_stubs(bool all
)
4696 this->plt_call_stubs_
.clear();
4697 this->plt_size_
= 0;
4698 this->long_branch_stubs_
.clear();
4699 this->branch_size_
= 0;
4700 this->need_save_res_
= false;
4703 this->last_plt_size_
= 0;
4704 this->last_branch_size_
= 0;
4710 { return need_resize_
; }
4713 set_resizing(bool val
)
4715 this->resizing_
= val
;
4718 this->need_resize_
= false;
4719 this->plt_size_
= 0;
4720 this->branch_size_
= 0;
4721 this->need_save_res_
= false;
4726 set_address_and_size(const Output_section
* os
, Address off
)
4728 Address start_off
= off
;
4729 off
+= this->orig_data_size_
;
4730 Address my_size
= this->plt_size_
+ this->branch_size_
;
4731 if (this->need_save_res_
)
4732 my_size
+= this->targ_
->savres_section()->data_size();
4734 off
= align_address(off
, this->stub_align());
4735 // Include original section size and alignment padding in size
4736 my_size
+= off
- start_off
;
4737 // Ensure new size is always larger than min size
4738 // threshold. Alignment requirement is included in "my_size", so
4739 // increase "my_size" does not invalidate alignment.
4740 if (my_size
< this->min_size_threshold_
)
4741 my_size
= this->min_size_threshold_
;
4742 this->reset_address_and_file_offset();
4743 this->set_current_data_size(my_size
);
4744 this->set_address_and_file_offset(os
->address() + start_off
,
4745 os
->offset() + start_off
);
4750 stub_address() const
4752 return align_address(this->address() + this->orig_data_size_
,
4753 this->stub_align());
4759 return align_address(this->offset() + this->orig_data_size_
,
4760 this->stub_align());
4765 { return this->plt_size_
; }
4769 { return this->branch_size_
; }
4772 set_min_size_threshold(Address min_size
)
4773 { this->min_size_threshold_
= min_size
; }
4776 define_stub_syms(Symbol_table
*);
4781 Output_section
* os
= this->output_section();
4782 if (os
->addralign() < this->stub_align())
4784 os
->set_addralign(this->stub_align());
4785 // FIXME: get rid of the insane checkpointing.
4786 // We can't increase alignment of the input section to which
4787 // stubs are attached; The input section may be .init which
4788 // is pasted together with other .init sections to form a
4789 // function. Aligning might insert zero padding resulting in
4790 // sigill. However we do need to increase alignment of the
4791 // output section so that the align_address() on offset in
4792 // set_address_and_size() adds the same padding as the
4793 // align_address() on address in stub_address().
4794 // What's more, we need this alignment for the layout done in
4795 // relaxation_loop_body() so that the output section starts at
4796 // a suitably aligned address.
4797 os
->checkpoint_set_addralign(this->stub_align());
4799 if (this->last_plt_size_
!= this->plt_size_
4800 || this->last_branch_size_
!= this->branch_size_
)
4802 this->last_plt_size_
= this->plt_size_
;
4803 this->last_branch_size_
= this->branch_size_
;
4809 // Add .eh_frame info for this stub section.
4811 add_eh_frame(Layout
* layout
);
4813 // Remove .eh_frame info for this stub section.
4815 remove_eh_frame(Layout
* layout
);
4817 Target_powerpc
<size
, big_endian
>*
4823 class Plt_stub_key_hash
;
4824 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4825 Plt_stub_key_hash
> Plt_stub_entries
;
4826 class Branch_stub_key
;
4827 class Branch_stub_key_hash
;
4828 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4829 Branch_stub_key_hash
> Branch_stub_entries
;
4831 // Alignment of stub section.
4835 unsigned int min_align
= size
== 64 ? 32 : 16;
4836 unsigned int user_align
= 1 << parameters
->options().plt_align();
4837 return std::max(user_align
, min_align
);
4840 // Return the plt offset for the given call stub.
4842 plt_off(typename
Plt_stub_entries::const_iterator p
,
4843 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4845 const Symbol
* gsym
= p
->first
.sym_
;
4847 return this->targ_
->plt_off(gsym
, sec
);
4850 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4851 unsigned int local_sym_index
= p
->first
.locsym_
;
4852 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4856 // Size of a given plt call stub.
4858 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const;
4861 plt_call_align(unsigned int bytes
) const
4863 unsigned int align
= param_plt_align
<size
>();
4864 return (bytes
+ align
- 1) & -align
;
4867 // Return long branch stub size.
4869 branch_stub_size(typename
Branch_stub_entries::const_iterator p
,
4873 build_tls_opt_head(unsigned char** pp
,
4874 typename
Plt_stub_entries::const_iterator cs
);
4877 build_tls_opt_tail(unsigned char* p
,
4878 typename
Plt_stub_entries::const_iterator cs
);
4881 plt_error(const Plt_stub_key
& p
);
4885 do_write(Output_file
*);
4887 // Plt call stub keys.
4891 Plt_stub_key(const Symbol
* sym
)
4892 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4895 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4896 unsigned int locsym_index
)
4897 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4900 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4902 unsigned int r_type
,
4904 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4907 this->addend_
= addend
;
4908 else if (parameters
->options().output_is_position_independent()
4909 && (r_type
== elfcpp::R_PPC_PLTREL24
4910 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4912 this->addend_
= addend
;
4913 if (this->addend_
>= 32768)
4914 this->object_
= object
;
4918 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4919 unsigned int locsym_index
,
4920 unsigned int r_type
,
4922 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4925 this->addend_
= addend
;
4926 else if (parameters
->options().output_is_position_independent()
4927 && (r_type
== elfcpp::R_PPC_PLTREL24
4928 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4929 this->addend_
= addend
;
4932 bool operator==(const Plt_stub_key
& that
) const
4934 return (this->sym_
== that
.sym_
4935 && this->object_
== that
.object_
4936 && this->addend_
== that
.addend_
4937 && this->locsym_
== that
.locsym_
);
4941 const Sized_relobj_file
<size
, big_endian
>* object_
;
4942 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4943 unsigned int locsym_
;
4946 class Plt_stub_key_hash
4949 size_t operator()(const Plt_stub_key
& ent
) const
4951 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4952 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
4958 // Long branch stub keys.
4959 class Branch_stub_key
4962 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
4963 : dest_(to
), toc_base_off_(0)
4966 toc_base_off_
= obj
->toc_base_offset();
4969 bool operator==(const Branch_stub_key
& that
) const
4971 return (this->dest_
== that
.dest_
4973 || this->toc_base_off_
== that
.toc_base_off_
));
4977 unsigned int toc_base_off_
;
4980 class Branch_stub_key_hash
4983 size_t operator()(const Branch_stub_key
& key
) const
4984 { return key
.dest_
^ key
.toc_base_off_
; }
4987 // In a sane world this would be a global.
4988 Target_powerpc
<size
, big_endian
>* targ_
;
4989 // Map sym/object/addend to stub offset.
4990 Plt_stub_entries plt_call_stubs_
;
4991 // Map destination address to stub offset.
4992 Branch_stub_entries long_branch_stubs_
;
4993 // size of input section
4994 section_size_type orig_data_size_
;
4996 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
4997 // Some rare cases cause (PR/20529) fluctuation in stub table
4998 // size, which leads to an endless relax loop. This is to be fixed
4999 // by, after the first few iterations, allowing only increase of
5000 // stub table size. This variable sets the minimal possible size of
5001 // a stub table, it is zero for the first few iterations, then
5002 // increases monotonically.
5003 Address min_size_threshold_
;
5004 // Set if this stub group needs a copy of out-of-line register
5005 // save/restore functions.
5006 bool need_save_res_
;
5007 // Set when notoc_/r2save_ changes after sizing a stub
5009 // Set when resizing stubs
5011 // Per stub table unique identifier.
5015 // Add a plt call stub, if we do not already have one for this
5016 // sym/object/addend combo.
5018 template<int size
, bool big_endian
>
5020 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5022 const Sized_relobj_file
<size
, big_endian
>* object
,
5024 unsigned int r_type
,
5028 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5029 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5030 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5031 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5035 && this->targ_
->is_elfv2_localentry0(gsym
))
5037 p
.first
->second
.localentry0_
= 1;
5038 this->targ_
->set_has_localentry0();
5040 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5042 if (!p
.second
&& !p
.first
->second
.notoc_
5043 && !this->targ_
->powerxx_stubs())
5044 this->need_resize_
= true;
5045 p
.first
->second
.notoc_
= 1;
5047 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
5049 if (!p
.second
&& !p
.first
->second
.r2save_
)
5050 this->need_resize_
= true;
5051 p
.first
->second
.r2save_
= 1;
5054 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5056 if (this->resizing_
)
5058 p
.first
->second
.iter_
= 1;
5059 p
.first
->second
.off_
= this->plt_size_
;
5061 this->plt_size_
+= this->plt_call_size(p
.first
);
5062 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5063 this->targ_
->set_has_tls_get_addr_opt();
5064 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5066 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5069 template<int size
, bool big_endian
>
5071 Stub_table
<size
, big_endian
>::add_plt_call_entry(
5073 const Sized_relobj_file
<size
, big_endian
>* object
,
5074 unsigned int locsym_index
,
5075 unsigned int r_type
,
5079 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5080 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
5081 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
5082 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5086 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5088 p
.first
->second
.localentry0_
= 1;
5089 this->targ_
->set_has_localentry0();
5091 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5093 if (!p
.second
&& !p
.first
->second
.notoc_
5094 && !this->targ_
->powerxx_stubs())
5095 this->need_resize_
= true;
5096 p
.first
->second
.notoc_
= 1;
5098 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
5100 if (!p
.second
&& !p
.first
->second
.r2save_
)
5101 this->need_resize_
= true;
5102 p
.first
->second
.r2save_
= 1;
5105 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5107 if (this->resizing_
)
5109 p
.first
->second
.iter_
= 1;
5110 p
.first
->second
.off_
= this->plt_size_
;
5112 this->plt_size_
+= this->plt_call_size(p
.first
);
5113 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5115 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5118 // Find a plt call stub.
5120 template<int size
, bool big_endian
>
5121 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5122 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5123 const Sized_relobj_file
<size
, big_endian
>* object
,
5125 unsigned int r_type
,
5126 Address addend
) const
5128 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5129 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5130 if (p
== this->plt_call_stubs_
.end())
5135 template<int size
, bool big_endian
>
5136 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5137 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5139 Plt_stub_key
key(gsym
);
5140 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5141 if (p
== this->plt_call_stubs_
.end())
5146 template<int size
, bool big_endian
>
5147 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5148 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5149 const Sized_relobj_file
<size
, big_endian
>* object
,
5150 unsigned int locsym_index
,
5151 unsigned int r_type
,
5152 Address addend
) const
5154 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5155 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5156 if (p
== this->plt_call_stubs_
.end())
5161 template<int size
, bool big_endian
>
5162 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5163 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5164 const Sized_relobj_file
<size
, big_endian
>* object
,
5165 unsigned int locsym_index
) const
5167 Plt_stub_key
key(object
, locsym_index
);
5168 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5169 if (p
== this->plt_call_stubs_
.end())
5174 // Add a long branch stub if we don't already have one to given
5177 template<int size
, bool big_endian
>
5179 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5180 const Powerpc_relobj
<size
, big_endian
>* object
,
5181 unsigned int r_type
,
5186 Branch_stub_key
key(object
, to
);
5187 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5188 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5189 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5190 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5191 if (notoc
&& !p
.first
->second
.notoc_
)
5193 this->need_resize_
= true;
5194 p
.first
->second
.notoc_
= true;
5196 gold_assert(save_res
== p
.first
->second
.save_res_
);
5197 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5199 if (this->resizing_
)
5201 p
.first
->second
.iter_
= 1;
5202 p
.first
->second
.off_
= this->branch_size_
;
5205 this->need_save_res_
= true;
5208 bool need_lt
= false;
5209 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5210 this->branch_size_
+= stub_size
;
5211 if (size
== 64 && need_lt
)
5212 this->targ_
->add_branch_lookup_table(to
);
5215 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5218 // Find long branch stub offset.
5220 template<int size
, bool big_endian
>
5221 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5222 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5223 const Powerpc_relobj
<size
, big_endian
>* object
,
5226 Branch_stub_key
key(object
, to
);
5227 typename
Branch_stub_entries::const_iterator p
5228 = this->long_branch_stubs_
.find(key
);
5229 if (p
== this->long_branch_stubs_
.end())
5234 template<bool big_endian
>
5236 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5240 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5241 else if (delta
< 256)
5243 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5244 fde
.push_back(delta
);
5246 else if (delta
< 65536)
5248 fde
.resize(fde
.size() + 3);
5249 unsigned char *p
= &*fde
.end() - 3;
5250 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5251 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5255 fde
.resize(fde
.size() + 5);
5256 unsigned char *p
= &*fde
.end() - 5;
5257 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5258 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5262 template<typename T
>
5264 stub_sort(T s1
, T s2
)
5266 return s1
->second
.off_
< s2
->second
.off_
;
5269 // Add .eh_frame info for this stub section. Unlike other linker
5270 // generated .eh_frame this is added late in the link, because we
5271 // only want the .eh_frame info if this particular stub section is
5274 template<int size
, bool big_endian
>
5276 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5279 || !parameters
->options().ld_generated_unwind_info())
5282 // Since we add stub .eh_frame info late, it must be placed
5283 // after all other linker generated .eh_frame info so that
5284 // merge mapping need not be updated for input sections.
5285 // There is no provision to use a different CIE to that used
5287 if (!this->targ_
->has_glink())
5290 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5291 std::vector
<plt_iter
> calls
;
5292 if (!this->plt_call_stubs_
.empty())
5293 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5294 cs
!= this->plt_call_stubs_
.end();
5296 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5297 && cs
->second
.r2save_
5298 && !cs
->second
.localentry0_
)
5299 || (cs
->second
.notoc_
5300 && !this->targ_
->powerxx_stubs()))
5301 calls
.push_back(cs
);
5302 if (calls
.size() > 1)
5303 std::stable_sort(calls
.begin(), calls
.end(),
5304 stub_sort
<plt_iter
>);
5306 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5307 std::vector
<branch_iter
> branches
;
5308 if (!this->long_branch_stubs_
.empty()
5309 && !this->targ_
->powerxx_stubs())
5310 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5311 bs
!= this->long_branch_stubs_
.end();
5313 if (bs
->second
.notoc_
)
5314 branches
.push_back(bs
);
5315 if (branches
.size() > 1)
5316 std::stable_sort(branches
.begin(), branches
.end(),
5317 stub_sort
<branch_iter
>);
5319 if (calls
.empty() && branches
.empty())
5322 unsigned int last_eh_loc
= 0;
5323 // offset pcrel sdata4, size udata4, and augmentation size byte.
5324 std::vector
<unsigned char> fde(9, 0);
5326 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5328 plt_iter cs
= calls
[i
];
5329 unsigned int off
= cs
->second
.off_
;
5330 // The __tls_get_addr_opt call stub needs to describe where
5331 // it saves LR, to support exceptions that might be thrown
5332 // from __tls_get_addr, and to support asynchronous exceptions.
5333 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5336 if (cs
->second
.r2save_
5337 && !cs
->second
.localentry0_
)
5340 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5341 fde
.resize(fde
.size() + 6);
5342 unsigned char* p
= &*fde
.end() - 6;
5343 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5345 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5346 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5347 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5348 *p
++ = elfcpp::DW_CFA_restore_extended
;
5350 last_eh_loc
= off
+ delta
;
5354 // notoc stubs also should describe LR changes, to support
5355 // asynchronous exceptions.
5356 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5357 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5358 fde
.resize(fde
.size() + 6);
5359 unsigned char* p
= &*fde
.end() - 6;
5360 *p
++ = elfcpp::DW_CFA_register
;
5363 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5364 *p
++ = elfcpp::DW_CFA_restore_extended
;
5366 last_eh_loc
= off
+ 8;
5369 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5371 branch_iter bs
= branches
[i
];
5372 unsigned int off
= bs
->second
.off_
+ 8;
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_register
;
5379 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5380 *p
++ = elfcpp::DW_CFA_restore_extended
;
5382 last_eh_loc
= off
+ 8;
5385 layout
->add_eh_frame_for_plt(this,
5386 Eh_cie
<size
>::eh_frame_cie
,
5387 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5388 &*fde
.begin(), fde
.size());
5391 template<int size
, bool big_endian
>
5393 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5396 && parameters
->options().ld_generated_unwind_info()
5397 && this->targ_
->has_glink())
5398 layout
->remove_eh_frame_for_plt(this,
5399 Eh_cie
<size
>::eh_frame_cie
,
5400 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5403 // A class to handle .glink.
5405 template<int size
, bool big_endian
>
5406 class Output_data_glink
: public Output_section_data
5409 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5410 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5412 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5413 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5414 end_branch_table_(), ge_size_(0)
5418 add_eh_frame(Layout
* layout
);
5421 add_global_entry(const Symbol
*);
5424 find_global_entry(const Symbol
*) const;
5427 global_entry_align(unsigned int off
) const
5429 unsigned int align
= param_plt_align
<size
>();
5430 return (off
+ align
- 1) & -align
;
5434 global_entry_off() const
5436 return this->global_entry_align(this->end_branch_table_
);
5440 global_entry_address() const
5442 gold_assert(this->is_data_size_valid());
5443 return this->address() + this->global_entry_off();
5447 pltresolve_size() const
5451 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
5456 // Write to a map file.
5458 do_print_to_mapfile(Mapfile
* mapfile
) const
5459 { mapfile
->print_output_data(this, _("** glink")); }
5463 set_final_data_size();
5467 do_write(Output_file
*);
5469 // Allows access to .got and .plt for do_write.
5470 Target_powerpc
<size
, big_endian
>* targ_
;
5472 // Map sym to stub offset.
5473 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5474 Global_entry_stub_entries global_entry_stubs_
;
5476 unsigned int end_branch_table_
, ge_size_
;
5479 template<int size
, bool big_endian
>
5481 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5483 if (!parameters
->options().ld_generated_unwind_info())
5488 if (this->targ_
->abiversion() < 2)
5489 layout
->add_eh_frame_for_plt(this,
5490 Eh_cie
<64>::eh_frame_cie
,
5491 sizeof (Eh_cie
<64>::eh_frame_cie
),
5492 glink_eh_frame_fde_64v1
,
5493 sizeof (glink_eh_frame_fde_64v1
));
5495 layout
->add_eh_frame_for_plt(this,
5496 Eh_cie
<64>::eh_frame_cie
,
5497 sizeof (Eh_cie
<64>::eh_frame_cie
),
5498 glink_eh_frame_fde_64v2
,
5499 sizeof (glink_eh_frame_fde_64v2
));
5503 // 32-bit .glink can use the default since the CIE return
5504 // address reg, LR, is valid.
5505 layout
->add_eh_frame_for_plt(this,
5506 Eh_cie
<32>::eh_frame_cie
,
5507 sizeof (Eh_cie
<32>::eh_frame_cie
),
5509 sizeof (default_fde
));
5510 // Except where LR is used in a PIC __glink_PLTresolve.
5511 if (parameters
->options().output_is_position_independent())
5512 layout
->add_eh_frame_for_plt(this,
5513 Eh_cie
<32>::eh_frame_cie
,
5514 sizeof (Eh_cie
<32>::eh_frame_cie
),
5515 glink_eh_frame_fde_32
,
5516 sizeof (glink_eh_frame_fde_32
));
5520 template<int size
, bool big_endian
>
5522 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5524 unsigned int off
= this->global_entry_align(this->ge_size_
);
5525 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5526 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5528 this->ge_size_
= off
+ 16;
5531 template<int size
, bool big_endian
>
5532 typename Output_data_glink
<size
, big_endian
>::Address
5533 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5535 typename
Global_entry_stub_entries::const_iterator p
5536 = this->global_entry_stubs_
.find(gsym
);
5537 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5540 template<int size
, bool big_endian
>
5542 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5544 unsigned int count
= this->targ_
->plt_entry_count();
5545 section_size_type total
= 0;
5551 // space for branch table
5552 total
+= 4 * (count
- 1);
5554 total
+= -total
& 15;
5555 total
+= this->pltresolve_size();
5559 total
+= this->pltresolve_size();
5561 // space for branch table
5563 if (this->targ_
->abiversion() < 2)
5567 total
+= 4 * (count
- 0x8000);
5571 this->end_branch_table_
= total
;
5572 total
= this->global_entry_align(total
);
5573 total
+= this->ge_size_
;
5575 this->set_data_size(total
);
5578 // Define symbols on stubs, identifying the stub.
5580 template<int size
, bool big_endian
>
5582 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5584 if (!this->plt_call_stubs_
.empty())
5586 // The key for the plt call stub hash table includes addresses,
5587 // therefore traversal order depends on those addresses, which
5588 // can change between runs if gold is a PIE. Unfortunately the
5589 // output .symtab ordering depends on the order in which symbols
5590 // are added to the linker symtab. We want reproducible output
5591 // so must sort the call stub symbols.
5592 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5593 std::vector
<plt_iter
> sorted
;
5594 sorted
.resize(this->plt_call_stubs_
.size());
5596 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5597 cs
!= this->plt_call_stubs_
.end();
5599 sorted
[cs
->second
.indx_
] = cs
;
5601 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5603 plt_iter cs
= sorted
[i
];
5606 if (cs
->first
.addend_
!= 0)
5607 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5610 if (cs
->first
.object_
)
5612 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5613 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5614 sprintf(obj
, "%x:", ppcobj
->uniq());
5617 const char *symname
;
5618 if (cs
->first
.sym_
== NULL
)
5620 sprintf(localname
, "%x", cs
->first
.locsym_
);
5621 symname
= localname
;
5623 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5624 symname
= this->targ_
->tls_get_addr_opt()->name();
5626 symname
= cs
->first
.sym_
->name();
5627 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5628 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5630 = this->stub_address() - this->address() + cs
->second
.off_
;
5631 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5632 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5636 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5637 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5638 bs
!= this->long_branch_stubs_
.end();
5641 if (bs
->second
.save_res_
)
5644 char* name
= new char[8 + 13 + 16 + 1];
5645 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5646 static_cast<unsigned long long>(bs
->first
.dest_
));
5647 Address value
= (this->stub_address() - this->address()
5648 + this->plt_size_
+ bs
->second
.off_
);
5649 bool need_lt
= false;
5650 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5651 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5655 // Emit the start of a __tls_get_addr_opt plt call stub.
5657 template<int size
, bool big_endian
>
5659 Stub_table
<size
, big_endian
>::build_tls_opt_head(
5661 typename
Plt_stub_entries::const_iterator cs
)
5663 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5665 unsigned char* p
= *pp
;
5668 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5670 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5672 write_insn
<big_endian
>(p
, mr_0_3
);
5674 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5676 write_insn
<big_endian
>(p
, add_3_12_13
);
5678 write_insn
<big_endian
>(p
, beqlr
);
5680 write_insn
<big_endian
>(p
, mr_3_0
);
5682 if (cs
->second
.r2save_
&& !cs
->second
.localentry0_
)
5684 write_insn
<big_endian
>(p
, mflr_11
);
5686 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5692 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5694 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5696 write_insn
<big_endian
>(p
, mr_0_3
);
5698 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5700 write_insn
<big_endian
>(p
, add_3_12_2
);
5702 write_insn
<big_endian
>(p
, beqlr
);
5704 write_insn
<big_endian
>(p
, mr_3_0
);
5706 write_insn
<big_endian
>(p
, nop
);
5715 // Emit the tail of a __tls_get_addr_opt plt call stub.
5717 template<int size
, bool big_endian
>
5719 Stub_table
<size
, big_endian
>::build_tls_opt_tail(
5721 typename
Plt_stub_entries::const_iterator cs
)
5724 && cs
->second
.r2save_
5725 && !cs
->second
.localentry0_
5726 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5728 write_insn
<big_endian
>(p
, bctrl
);
5730 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5732 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5734 write_insn
<big_endian
>(p
, mtlr_11
);
5736 write_insn
<big_endian
>(p
, blr
);
5742 // Emit pc-relative plt call stub code.
5744 template<bool big_endian
>
5745 static unsigned char*
5746 build_powerxx_offset(unsigned char* p
, uint64_t off
, uint64_t odd
, bool load
)
5749 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5754 write_insn
<big_endian
>(p
, nop
);
5762 write_insn
<big_endian
>(p
, insn
>> 32);
5764 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5766 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5769 write_insn
<big_endian
>(p
, li_11_0
| (ha34(off
) & 0xffff));
5773 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5776 insn
= paddi_12_pc
| d34(off
);
5777 write_insn
<big_endian
>(p
, insn
>> 32);
5779 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5783 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5787 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5789 write_insn
<big_endian
>(p
, add_12_11_12
);
5794 write_insn
<big_endian
>(p
, lis_11
| ((ha34(off
) >> 16) & 0x3fff));
5796 write_insn
<big_endian
>(p
, ori_11_11_0
| (ha34(off
) & 0xffff));
5800 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5803 insn
= paddi_12_pc
| d34(off
);
5804 write_insn
<big_endian
>(p
, insn
>> 32);
5806 write_insn
<big_endian
>(p
, insn
& 0xffffffff);
5810 write_insn
<big_endian
>(p
, sldi_11_11_34
);
5814 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5816 write_insn
<big_endian
>(p
, add_12_11_12
);
5822 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5823 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5828 // lis %r12,xxx-1b@highest
5829 // ori %r12,%r12,xxx-1b@higher
5830 // sldi %r12,%r12,32
5831 // oris %r12,%r12,xxx-1b@high
5832 // ori %r12,%r12,xxx-1b@l
5833 // add/ldx %r12,%r11,%r12
5835 template<bool big_endian
>
5836 static unsigned char*
5837 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5839 write_insn
<big_endian
>(p
, mflr_12
);
5841 write_insn
<big_endian
>(p
, bcl_20_31
);
5843 write_insn
<big_endian
>(p
, mflr_11
);
5845 write_insn
<big_endian
>(p
, mtlr_12
);
5847 if (off
+ 0x8000 < 0x10000)
5850 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5852 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5854 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5856 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5859 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5861 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5865 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5867 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5872 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5874 if (((off
>> 32) & 0xffff) != 0)
5876 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5880 if (((off
>> 32) & 0xffffffffULL
) != 0)
5882 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5887 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5892 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5896 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5898 write_insn
<big_endian
>(p
, add_12_11_12
);
5904 // Size of a given plt call stub.
5906 template<int size
, bool big_endian
>
5908 Stub_table
<size
, big_endian
>::plt_call_size(
5909 typename
Plt_stub_entries::const_iterator p
) const
5913 const Symbol
* gsym
= p
->first
.sym_
;
5915 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
5918 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5919 uint64_t plt_addr
= this->plt_off(p
, &plt
);
5920 plt_addr
+= plt
->address();
5921 unsigned int bytes
= 0;
5922 const Symbol
* gsym
= p
->first
.sym_
;
5923 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5925 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
5931 if (p
->second
.r2save_
)
5934 if (this->targ_
->powerxx_stubs())
5936 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
;
5939 uint64_t odd
= from
& 4;
5940 uint64_t off
= plt_addr
- from
;
5941 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
5942 bytes
+= odd
+ 4 * 4;
5943 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
5950 if (p
->second
.notoc_
)
5952 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
5955 uint64_t off
= plt_addr
- from
;
5956 if (off
+ 0x8000 < 0x10000)
5958 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5963 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
5964 && ((off
>> 32) & 0xffff) != 0)
5966 if (((off
>> 32) & 0xffffffffULL
) != 0)
5976 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
5977 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5978 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
5979 got_addr
+= ppcobj
->toc_base_offset();
5980 uint64_t off
= plt_addr
- got_addr
;
5981 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
5982 if (this->targ_
->abiversion() < 2)
5984 bool static_chain
= parameters
->options().plt_static_chain();
5985 bool thread_safe
= this->targ_
->plt_thread_safe();
5989 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
5994 // Return long branch stub size.
5996 template<int size
, bool big_endian
>
5998 Stub_table
<size
, big_endian
>::branch_stub_size(
5999 typename
Branch_stub_entries::const_iterator p
,
6002 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
6005 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
6007 if (parameters
->options().output_is_position_independent())
6012 uint64_t off
= p
->first
.dest_
- loc
;
6013 if (p
->second
.notoc_
)
6015 if (this->targ_
->powerxx_stubs())
6017 Address odd
= loc
& 4;
6018 if (off
+ (1 << 25) < 2 << 25)
6020 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
6022 if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
6027 if (off
+ 0x8000 < 0x10000)
6029 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
6031 if (off
+ 24 + (1 << 25) < 2 << 25)
6035 unsigned int bytes
= 32;
6036 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
6037 && ((off
>> 32) & 0xffff) != 0)
6039 if (((off
>> 32) & 0xffffffffULL
) != 0)
6048 if (off
+ (1 << 25) < 2 << 25)
6050 if (!this->targ_
->powerxx_stubs())
6055 template<int size
, bool big_endian
>
6057 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
6060 gold_error(_("linkage table error against `%s'"),
6061 p
.sym_
->demangled_name().c_str());
6063 gold_error(_("linkage table error against `%s:[local %u]'"),
6064 p
.object_
->name().c_str(),
6068 // Write out plt and long branch stub code.
6070 template<int size
, bool big_endian
>
6072 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
6074 if (this->plt_call_stubs_
.empty()
6075 && this->long_branch_stubs_
.empty())
6078 const section_size_type start_off
= this->offset();
6079 const section_size_type off
= this->stub_offset();
6080 const section_size_type oview_size
=
6081 convert_to_section_size_type(this->data_size() - (off
- start_off
));
6082 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6086 && this->targ_
->powerxx_stubs())
6088 if (!this->plt_call_stubs_
.empty())
6090 // Write out plt call stubs.
6091 typename
Plt_stub_entries::const_iterator cs
;
6092 for (cs
= this->plt_call_stubs_
.begin();
6093 cs
!= this->plt_call_stubs_
.end();
6096 p
= oview
+ cs
->second
.off_
;
6097 this->build_tls_opt_head(&p
, cs
);
6098 if (cs
->second
.r2save_
)
6100 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6103 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6104 Address pltoff
= this->plt_off(cs
, &plt
);
6105 Address plt_addr
= pltoff
+ plt
->address();
6106 Address from
= this->stub_address() + (p
- oview
);
6107 Address delta
= plt_addr
- from
;
6108 p
= build_powerxx_offset
<big_endian
>(p
, delta
, from
& 4, true);
6109 write_insn
<big_endian
>(p
, mtctr_12
);
6111 if (!this->build_tls_opt_tail(p
, cs
))
6112 write_insn
<big_endian
>(p
, bctr
);
6116 // Write out long branch stubs.
6117 typename
Branch_stub_entries::const_iterator bs
;
6118 for (bs
= this->long_branch_stubs_
.begin();
6119 bs
!= this->long_branch_stubs_
.end();
6122 if (bs
->second
.save_res_
)
6124 Address off
= this->plt_size_
+ bs
->second
.off_
;
6126 Address loc
= this->stub_address() + off
;
6127 Address delta
= bs
->first
.dest_
- loc
;
6128 if (bs
->second
.notoc_
|| delta
+ (1 << 25) >= 2 << 25)
6130 unsigned char* startp
= p
;
6131 p
= build_powerxx_offset
<big_endian
>(p
, delta
, loc
& 4, false);
6132 delta
-= p
- startp
;
6134 if (delta
+ (1 << 25) < 2 << 25)
6135 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6138 write_insn
<big_endian
>(p
, mtctr_12
);
6140 write_insn
<big_endian
>(p
, bctr
);
6144 else if (size
== 64)
6146 const Output_data_got_powerpc
<size
, big_endian
>* got
6147 = this->targ_
->got_section();
6148 Address got_os_addr
= got
->output_section()->address();
6150 if (!this->plt_call_stubs_
.empty()
6151 && this->targ_
->abiversion() >= 2)
6153 // Write out plt call stubs for ELFv2.
6154 typename
Plt_stub_entries::const_iterator cs
;
6155 for (cs
= this->plt_call_stubs_
.begin();
6156 cs
!= this->plt_call_stubs_
.end();
6159 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6160 Address pltoff
= this->plt_off(cs
, &plt
);
6161 Address plt_addr
= pltoff
+ plt
->address();
6163 p
= oview
+ cs
->second
.off_
;
6164 this->build_tls_opt_head(&p
, cs
);
6165 if (cs
->second
.r2save_
)
6167 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6170 if (cs
->second
.notoc_
)
6172 Address from
= this->stub_address() + (p
- oview
) + 8;
6173 Address off
= plt_addr
- from
;
6174 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
6178 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6179 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6180 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6181 Address off
= plt_addr
- got_addr
;
6183 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6184 this->plt_error(cs
->first
);
6188 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
6190 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
6195 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6199 write_insn
<big_endian
>(p
, mtctr_12
);
6201 if (!this->build_tls_opt_tail(p
, cs
))
6202 write_insn
<big_endian
>(p
, bctr
);
6205 else if (!this->plt_call_stubs_
.empty())
6207 // Write out plt call stubs for ELFv1.
6208 typename
Plt_stub_entries::const_iterator cs
;
6209 for (cs
= this->plt_call_stubs_
.begin();
6210 cs
!= this->plt_call_stubs_
.end();
6213 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6214 Address pltoff
= this->plt_off(cs
, &plt
);
6215 Address plt_addr
= pltoff
+ plt
->address();
6216 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
6217 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
6218 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
6219 Address off
= plt_addr
- got_addr
;
6221 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
6222 || cs
->second
.notoc_
)
6223 this->plt_error(cs
->first
);
6225 bool static_chain
= parameters
->options().plt_static_chain();
6226 bool thread_safe
= this->targ_
->plt_thread_safe();
6227 bool use_fake_dep
= false;
6228 Address cmp_branch_off
= 0;
6231 unsigned int pltindex
6232 = ((pltoff
- this->targ_
->first_plt_entry_offset())
6233 / this->targ_
->plt_entry_size());
6235 = (this->targ_
->glink_section()->pltresolve_size()
6237 if (pltindex
> 32768)
6238 glinkoff
+= (pltindex
- 32768) * 4;
6240 = this->targ_
->glink_section()->address() + glinkoff
;
6242 = (this->stub_address() + cs
->second
.off_
+ 20
6243 + 4 * cs
->second
.r2save_
6244 + 4 * (ha(off
) != 0)
6245 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6246 + 4 * static_chain
);
6247 cmp_branch_off
= to
- from
;
6248 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
6251 p
= oview
+ cs
->second
.off_
;
6252 if (this->build_tls_opt_head(&p
, cs
))
6253 use_fake_dep
= thread_safe
;
6254 if (cs
->second
.r2save_
)
6256 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6261 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6263 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6265 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6267 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6271 write_insn
<big_endian
>(p
, mtctr_12
);
6275 write_insn
<big_endian
>(p
, xor_2_12_12
);
6277 write_insn
<big_endian
>(p
, add_11_11_2
);
6280 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6284 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6290 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6292 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6294 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6298 write_insn
<big_endian
>(p
, mtctr_12
);
6302 write_insn
<big_endian
>(p
, xor_11_12_12
);
6304 write_insn
<big_endian
>(p
, add_2_2_11
);
6309 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6312 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6315 if (this->build_tls_opt_tail(p
, cs
))
6317 else if (thread_safe
&& !use_fake_dep
)
6319 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6321 write_insn
<big_endian
>(p
, bnectr_p4
);
6323 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6326 write_insn
<big_endian
>(p
, bctr
);
6330 // Write out long branch stubs.
6331 typename
Branch_stub_entries::const_iterator bs
;
6332 for (bs
= this->long_branch_stubs_
.begin();
6333 bs
!= this->long_branch_stubs_
.end();
6336 if (bs
->second
.save_res_
)
6338 Address off
= this->plt_size_
+ bs
->second
.off_
;
6340 Address loc
= this->stub_address() + off
;
6341 Address delta
= bs
->first
.dest_
- loc
;
6342 if (bs
->second
.notoc_
)
6344 unsigned char* startp
= p
;
6345 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6346 delta
-= p
- startp
;
6348 else if (delta
+ (1 << 25) >= 2 << 25)
6351 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6352 gold_assert(brlt_addr
!= invalid_address
);
6353 brlt_addr
+= this->targ_
->brlt_section()->address();
6354 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6355 Address brltoff
= brlt_addr
- got_addr
;
6356 if (ha(brltoff
) == 0)
6358 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6363 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6365 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6369 if (delta
+ (1 << 25) < 2 << 25)
6370 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6373 write_insn
<big_endian
>(p
, mtctr_12
);
6375 write_insn
<big_endian
>(p
, bctr
);
6381 if (!this->plt_call_stubs_
.empty())
6383 // The address of _GLOBAL_OFFSET_TABLE_.
6384 Address g_o_t
= invalid_address
;
6386 // Write out plt call stubs.
6387 typename
Plt_stub_entries::const_iterator cs
;
6388 for (cs
= this->plt_call_stubs_
.begin();
6389 cs
!= this->plt_call_stubs_
.end();
6392 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6393 Address plt_addr
= this->plt_off(cs
, &plt
);
6394 plt_addr
+= plt
->address();
6396 p
= oview
+ cs
->second
.off_
;
6397 this->build_tls_opt_head(&p
, cs
);
6398 if (parameters
->options().output_is_position_independent())
6401 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6402 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6403 (cs
->first
.object_
));
6404 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6406 unsigned int got2
= ppcobj
->got2_shndx();
6407 got_addr
= ppcobj
->get_output_section_offset(got2
);
6408 gold_assert(got_addr
!= invalid_address
);
6409 got_addr
+= (ppcobj
->output_section(got2
)->address()
6410 + cs
->first
.addend_
);
6414 if (g_o_t
== invalid_address
)
6416 const Output_data_got_powerpc
<size
, big_endian
>* got
6417 = this->targ_
->got_section();
6418 g_o_t
= got
->address() + got
->g_o_t();
6423 Address off
= plt_addr
- got_addr
;
6425 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6428 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6430 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6435 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6437 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6440 write_insn
<big_endian
>(p
, mtctr_11
);
6442 write_insn
<big_endian
>(p
, bctr
);
6446 // Write out long branch stubs.
6447 typename
Branch_stub_entries::const_iterator bs
;
6448 for (bs
= this->long_branch_stubs_
.begin();
6449 bs
!= this->long_branch_stubs_
.end();
6452 if (bs
->second
.save_res_
)
6454 Address off
= this->plt_size_
+ bs
->second
.off_
;
6456 Address loc
= this->stub_address() + off
;
6457 Address delta
= bs
->first
.dest_
- loc
;
6458 if (delta
+ (1 << 25) < 2 << 25)
6459 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6460 else if (!parameters
->options().output_is_position_independent())
6462 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6464 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6469 write_insn
<big_endian
>(p
, mflr_0
);
6471 write_insn
<big_endian
>(p
, bcl_20_31
);
6473 write_insn
<big_endian
>(p
, mflr_12
);
6475 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6477 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6479 write_insn
<big_endian
>(p
, mtlr_0
);
6482 write_insn
<big_endian
>(p
, mtctr_12
);
6484 write_insn
<big_endian
>(p
, bctr
);
6487 if (this->need_save_res_
)
6489 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6490 memcpy (p
, this->targ_
->savres_section()->contents(),
6491 this->targ_
->savres_section()->data_size());
6495 // Write out .glink.
6497 template<int size
, bool big_endian
>
6499 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6501 const section_size_type off
= this->offset();
6502 const section_size_type oview_size
=
6503 convert_to_section_size_type(this->data_size());
6504 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6507 // The base address of the .plt section.
6508 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6509 Address plt_base
= this->targ_
->plt_section()->address();
6513 if (this->end_branch_table_
!= 0)
6515 // Write pltresolve stub.
6517 Address after_bcl
= this->address() + 16;
6518 Address pltoff
= plt_base
- after_bcl
;
6520 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6522 if (this->targ_
->abiversion() < 2)
6524 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6525 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6526 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6527 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6528 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6529 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6530 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6531 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6532 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6533 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6537 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6538 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6539 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6540 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6541 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6542 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6543 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6544 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6545 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
6546 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6547 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6548 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6549 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6551 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6552 gold_assert(p
== oview
+ this->pltresolve_size());
6554 // Write lazy link call stubs.
6556 while (p
< oview
+ this->end_branch_table_
)
6558 if (this->targ_
->abiversion() < 2)
6562 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6566 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6567 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6570 uint32_t branch_off
= 8 - (p
- oview
);
6571 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6576 Address plt_base
= this->targ_
->plt_section()->address();
6577 Address iplt_base
= invalid_address
;
6578 unsigned int global_entry_off
= this->global_entry_off();
6579 Address global_entry_base
= this->address() + global_entry_off
;
6580 typename
Global_entry_stub_entries::const_iterator ge
;
6581 for (ge
= this->global_entry_stubs_
.begin();
6582 ge
!= this->global_entry_stubs_
.end();
6585 p
= oview
+ global_entry_off
+ ge
->second
;
6586 Address plt_addr
= ge
->first
->plt_offset();
6587 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6588 && ge
->first
->can_use_relative_reloc(false))
6590 if (iplt_base
== invalid_address
)
6591 iplt_base
= this->targ_
->iplt_section()->address();
6592 plt_addr
+= iplt_base
;
6595 plt_addr
+= plt_base
;
6596 Address my_addr
= global_entry_base
+ ge
->second
;
6597 Address off
= plt_addr
- my_addr
;
6599 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6600 gold_error(_("linkage table error against `%s'"),
6601 ge
->first
->demangled_name().c_str());
6603 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6604 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6605 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6606 write_insn
<big_endian
>(p
, bctr
);
6611 const Output_data_got_powerpc
<size
, big_endian
>* got
6612 = this->targ_
->got_section();
6613 // The address of _GLOBAL_OFFSET_TABLE_.
6614 Address g_o_t
= got
->address() + got
->g_o_t();
6616 // Write out pltresolve branch table.
6618 unsigned int the_end
= oview_size
- this->pltresolve_size();
6619 unsigned char* end_p
= oview
+ the_end
;
6620 while (p
< end_p
- 8 * 4)
6621 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6623 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6625 // Write out pltresolve call stub.
6626 end_p
= oview
+ oview_size
;
6627 if (parameters
->options().output_is_position_independent())
6629 Address res0_off
= 0;
6630 Address after_bcl_off
= the_end
+ 12;
6631 Address bcl_res0
= after_bcl_off
- res0_off
;
6633 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6635 write_insn
<big_endian
>(p
, mflr_0
);
6637 write_insn
<big_endian
>(p
, bcl_20_31
);
6639 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6641 write_insn
<big_endian
>(p
, mflr_12
);
6643 write_insn
<big_endian
>(p
, mtlr_0
);
6645 write_insn
<big_endian
>(p
, sub_11_11_12
);
6648 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6650 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6652 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6654 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6656 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6660 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6662 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6665 write_insn
<big_endian
>(p
, mtctr_0
);
6667 write_insn
<big_endian
>(p
, add_0_11_11
);
6669 write_insn
<big_endian
>(p
, add_11_0_11
);
6673 Address res0
= this->address();
6675 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6677 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6679 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6680 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6682 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6684 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6686 write_insn
<big_endian
>(p
, mtctr_0
);
6688 write_insn
<big_endian
>(p
, add_0_11_11
);
6690 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6691 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6693 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6695 write_insn
<big_endian
>(p
, add_11_0_11
);
6698 write_insn
<big_endian
>(p
, bctr
);
6702 write_insn
<big_endian
>(p
, nop
);
6707 of
->write_output_view(off
, oview_size
, oview
);
6711 // A class to handle linker generated save/restore functions.
6713 template<int size
, bool big_endian
>
6714 class Output_data_save_res
: public Output_section_data_build
6717 Output_data_save_res(Symbol_table
* symtab
);
6719 const unsigned char*
6726 // Write to a map file.
6728 do_print_to_mapfile(Mapfile
* mapfile
) const
6729 { mapfile
->print_output_data(this, _("** save/restore")); }
6732 do_write(Output_file
*);
6735 // The maximum size of save/restore contents.
6736 static const unsigned int savres_max
= 218*4;
6739 savres_define(Symbol_table
* symtab
,
6741 unsigned int lo
, unsigned int hi
,
6742 unsigned char* write_ent(unsigned char*, int),
6743 unsigned char* write_tail(unsigned char*, int));
6745 unsigned char *contents_
;
6748 template<bool big_endian
>
6749 static unsigned char*
6750 savegpr0(unsigned char* p
, int r
)
6752 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6753 write_insn
<big_endian
>(p
, insn
);
6757 template<bool big_endian
>
6758 static unsigned char*
6759 savegpr0_tail(unsigned char* p
, int r
)
6761 p
= savegpr0
<big_endian
>(p
, r
);
6762 uint32_t insn
= std_0_1
+ 16;
6763 write_insn
<big_endian
>(p
, insn
);
6765 write_insn
<big_endian
>(p
, blr
);
6769 template<bool big_endian
>
6770 static unsigned char*
6771 restgpr0(unsigned char* p
, int r
)
6773 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6774 write_insn
<big_endian
>(p
, insn
);
6778 template<bool big_endian
>
6779 static unsigned char*
6780 restgpr0_tail(unsigned char* p
, int r
)
6782 uint32_t insn
= ld_0_1
+ 16;
6783 write_insn
<big_endian
>(p
, insn
);
6785 p
= restgpr0
<big_endian
>(p
, r
);
6786 write_insn
<big_endian
>(p
, mtlr_0
);
6790 p
= restgpr0
<big_endian
>(p
, 30);
6791 p
= restgpr0
<big_endian
>(p
, 31);
6793 write_insn
<big_endian
>(p
, blr
);
6797 template<bool big_endian
>
6798 static unsigned char*
6799 savegpr1(unsigned char* p
, int r
)
6801 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6802 write_insn
<big_endian
>(p
, insn
);
6806 template<bool big_endian
>
6807 static unsigned char*
6808 savegpr1_tail(unsigned char* p
, int r
)
6810 p
= savegpr1
<big_endian
>(p
, r
);
6811 write_insn
<big_endian
>(p
, blr
);
6815 template<bool big_endian
>
6816 static unsigned char*
6817 restgpr1(unsigned char* p
, int r
)
6819 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6820 write_insn
<big_endian
>(p
, insn
);
6824 template<bool big_endian
>
6825 static unsigned char*
6826 restgpr1_tail(unsigned char* p
, int r
)
6828 p
= restgpr1
<big_endian
>(p
, r
);
6829 write_insn
<big_endian
>(p
, blr
);
6833 template<bool big_endian
>
6834 static unsigned char*
6835 savefpr(unsigned char* p
, int r
)
6837 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6838 write_insn
<big_endian
>(p
, insn
);
6842 template<bool big_endian
>
6843 static unsigned char*
6844 savefpr0_tail(unsigned char* p
, int r
)
6846 p
= savefpr
<big_endian
>(p
, r
);
6847 write_insn
<big_endian
>(p
, std_0_1
+ 16);
6849 write_insn
<big_endian
>(p
, blr
);
6853 template<bool big_endian
>
6854 static unsigned char*
6855 restfpr(unsigned char* p
, int r
)
6857 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6858 write_insn
<big_endian
>(p
, insn
);
6862 template<bool big_endian
>
6863 static unsigned char*
6864 restfpr0_tail(unsigned char* p
, int r
)
6866 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
6868 p
= restfpr
<big_endian
>(p
, r
);
6869 write_insn
<big_endian
>(p
, mtlr_0
);
6873 p
= restfpr
<big_endian
>(p
, 30);
6874 p
= restfpr
<big_endian
>(p
, 31);
6876 write_insn
<big_endian
>(p
, blr
);
6880 template<bool big_endian
>
6881 static unsigned char*
6882 savefpr1_tail(unsigned char* p
, int r
)
6884 p
= savefpr
<big_endian
>(p
, r
);
6885 write_insn
<big_endian
>(p
, blr
);
6889 template<bool big_endian
>
6890 static unsigned char*
6891 restfpr1_tail(unsigned char* p
, int r
)
6893 p
= restfpr
<big_endian
>(p
, r
);
6894 write_insn
<big_endian
>(p
, blr
);
6898 template<bool big_endian
>
6899 static unsigned char*
6900 savevr(unsigned char* p
, int r
)
6902 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6903 write_insn
<big_endian
>(p
, insn
);
6905 insn
= stvx_0_12_0
+ (r
<< 21);
6906 write_insn
<big_endian
>(p
, insn
);
6910 template<bool big_endian
>
6911 static unsigned char*
6912 savevr_tail(unsigned char* p
, int r
)
6914 p
= savevr
<big_endian
>(p
, r
);
6915 write_insn
<big_endian
>(p
, blr
);
6919 template<bool big_endian
>
6920 static unsigned char*
6921 restvr(unsigned char* p
, int r
)
6923 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6924 write_insn
<big_endian
>(p
, insn
);
6926 insn
= lvx_0_12_0
+ (r
<< 21);
6927 write_insn
<big_endian
>(p
, insn
);
6931 template<bool big_endian
>
6932 static unsigned char*
6933 restvr_tail(unsigned char* p
, int r
)
6935 p
= restvr
<big_endian
>(p
, r
);
6936 write_insn
<big_endian
>(p
, blr
);
6941 template<int size
, bool big_endian
>
6942 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
6943 Symbol_table
* symtab
)
6944 : Output_section_data_build(4),
6947 this->savres_define(symtab
,
6948 "_savegpr0_", 14, 31,
6949 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
6950 this->savres_define(symtab
,
6951 "_restgpr0_", 14, 29,
6952 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6953 this->savres_define(symtab
,
6954 "_restgpr0_", 30, 31,
6955 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6956 this->savres_define(symtab
,
6957 "_savegpr1_", 14, 31,
6958 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
6959 this->savres_define(symtab
,
6960 "_restgpr1_", 14, 31,
6961 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
6962 this->savres_define(symtab
,
6963 "_savefpr_", 14, 31,
6964 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
6965 this->savres_define(symtab
,
6966 "_restfpr_", 14, 29,
6967 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6968 this->savres_define(symtab
,
6969 "_restfpr_", 30, 31,
6970 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6971 this->savres_define(symtab
,
6973 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
6974 this->savres_define(symtab
,
6976 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
6977 this->savres_define(symtab
,
6979 savevr
<big_endian
>, savevr_tail
<big_endian
>);
6980 this->savres_define(symtab
,
6982 restvr
<big_endian
>, restvr_tail
<big_endian
>);
6985 template<int size
, bool big_endian
>
6987 Output_data_save_res
<size
, big_endian
>::savres_define(
6988 Symbol_table
* symtab
,
6990 unsigned int lo
, unsigned int hi
,
6991 unsigned char* write_ent(unsigned char*, int),
6992 unsigned char* write_tail(unsigned char*, int))
6994 size_t len
= strlen(name
);
6995 bool writing
= false;
6998 memcpy(sym
, name
, len
);
7001 for (unsigned int i
= lo
; i
<= hi
; i
++)
7003 sym
[len
+ 0] = i
/ 10 + '0';
7004 sym
[len
+ 1] = i
% 10 + '0';
7005 Symbol
* gsym
= symtab
->lookup(sym
);
7006 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
7007 writing
= writing
|| refd
;
7010 if (this->contents_
== NULL
)
7011 this->contents_
= new unsigned char[this->savres_max
];
7013 section_size_type value
= this->current_data_size();
7014 unsigned char* p
= this->contents_
+ value
;
7016 p
= write_ent(p
, i
);
7018 p
= write_tail(p
, i
);
7019 section_size_type cur_size
= p
- this->contents_
;
7020 this->set_current_data_size(cur_size
);
7022 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
7023 this, value
, cur_size
- value
,
7024 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
7025 elfcpp::STV_HIDDEN
, 0, false, false);
7030 // Write out save/restore.
7032 template<int size
, bool big_endian
>
7034 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
7036 const section_size_type off
= this->offset();
7037 const section_size_type oview_size
=
7038 convert_to_section_size_type(this->data_size());
7039 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
7040 memcpy(oview
, this->contents_
, oview_size
);
7041 of
->write_output_view(off
, oview_size
, oview
);
7045 // Create the glink section.
7047 template<int size
, bool big_endian
>
7049 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
7051 if (this->glink_
== NULL
)
7053 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
7054 this->glink_
->add_eh_frame(layout
);
7055 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
7056 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
7057 this->glink_
, ORDER_TEXT
, false);
7061 // Create a PLT entry for a global symbol.
7063 template<int size
, bool big_endian
>
7065 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
7069 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
7070 && gsym
->can_use_relative_reloc(false))
7072 if (this->iplt_
== NULL
)
7073 this->make_iplt_section(symtab
, layout
);
7074 this->iplt_
->add_ifunc_entry(gsym
);
7078 if (this->plt_
== NULL
)
7079 this->make_plt_section(symtab
, layout
);
7080 this->plt_
->add_entry(gsym
);
7084 // Make a PLT entry for a local symbol.
7086 template<int size
, bool big_endian
>
7088 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
7090 Sized_relobj_file
<size
, big_endian
>* relobj
,
7093 if (this->lplt_
== NULL
)
7094 this->make_lplt_section(layout
);
7095 this->lplt_
->add_local_entry(relobj
, r_sym
);
7098 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
7100 template<int size
, bool big_endian
>
7102 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
7103 Symbol_table
* symtab
,
7105 Sized_relobj_file
<size
, big_endian
>* relobj
,
7108 if (this->iplt_
== NULL
)
7109 this->make_iplt_section(symtab
, layout
);
7110 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
7113 // Return the number of entries in the PLT.
7115 template<int size
, bool big_endian
>
7117 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
7119 if (this->plt_
== NULL
)
7121 return this->plt_
->entry_count();
7124 // Create a GOT entry for local dynamic __tls_get_addr calls.
7126 template<int size
, bool big_endian
>
7128 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
7129 Symbol_table
* symtab
,
7131 Sized_relobj_file
<size
, big_endian
>* object
)
7133 if (this->tlsld_got_offset_
== -1U)
7135 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
7136 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
7137 Output_data_got_powerpc
<size
, big_endian
>* got
7138 = this->got_section(symtab
, layout
);
7139 unsigned int got_offset
= got
->add_constant_pair(0, 0);
7140 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
7142 this->tlsld_got_offset_
= got_offset
;
7144 return this->tlsld_got_offset_
;
7147 // Get the Reference_flags for a particular relocation.
7149 template<int size
, bool big_endian
>
7151 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
7152 unsigned int r_type
,
7153 const Target_powerpc
* target
)
7159 case elfcpp::R_POWERPC_NONE
:
7160 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7161 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7162 case elfcpp::R_PPC64_TOC
:
7163 // No symbol reference.
7166 case elfcpp::R_PPC64_ADDR64
:
7167 case elfcpp::R_PPC64_UADDR64
:
7168 case elfcpp::R_POWERPC_ADDR32
:
7169 case elfcpp::R_POWERPC_UADDR32
:
7170 case elfcpp::R_POWERPC_ADDR16
:
7171 case elfcpp::R_POWERPC_UADDR16
:
7172 case elfcpp::R_POWERPC_ADDR16_LO
:
7173 case elfcpp::R_POWERPC_ADDR16_HI
:
7174 case elfcpp::R_POWERPC_ADDR16_HA
:
7175 ref
= Symbol::ABSOLUTE_REF
;
7178 case elfcpp::R_POWERPC_ADDR24
:
7179 case elfcpp::R_POWERPC_ADDR14
:
7180 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7181 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7182 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
7185 case elfcpp::R_PPC64_REL64
:
7186 case elfcpp::R_POWERPC_REL32
:
7187 case elfcpp::R_PPC_LOCAL24PC
:
7188 case elfcpp::R_POWERPC_REL16
:
7189 case elfcpp::R_POWERPC_REL16_LO
:
7190 case elfcpp::R_POWERPC_REL16_HI
:
7191 case elfcpp::R_POWERPC_REL16_HA
:
7192 case elfcpp::R_PPC64_REL16_HIGH
:
7193 case elfcpp::R_PPC64_REL16_HIGHA
:
7194 case elfcpp::R_PPC64_REL16_HIGHER
:
7195 case elfcpp::R_PPC64_REL16_HIGHERA
:
7196 case elfcpp::R_PPC64_REL16_HIGHEST
:
7197 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7198 case elfcpp::R_PPC64_PCREL34
:
7199 case elfcpp::R_PPC64_REL16_HIGHER34
:
7200 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7201 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7202 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7203 case elfcpp::R_PPC64_PCREL28
:
7204 ref
= Symbol::RELATIVE_REF
;
7207 case elfcpp::R_PPC64_REL24_NOTOC
:
7211 case elfcpp::R_POWERPC_REL24
:
7212 case elfcpp::R_PPC_PLTREL24
:
7213 case elfcpp::R_POWERPC_REL14
:
7214 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7215 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7216 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
7219 case elfcpp::R_POWERPC_GOT16
:
7220 case elfcpp::R_POWERPC_GOT16_LO
:
7221 case elfcpp::R_POWERPC_GOT16_HI
:
7222 case elfcpp::R_POWERPC_GOT16_HA
:
7223 case elfcpp::R_PPC64_GOT16_DS
:
7224 case elfcpp::R_PPC64_GOT16_LO_DS
:
7225 case elfcpp::R_PPC64_GOT_PCREL34
:
7226 case elfcpp::R_PPC64_TOC16
:
7227 case elfcpp::R_PPC64_TOC16_LO
:
7228 case elfcpp::R_PPC64_TOC16_HI
:
7229 case elfcpp::R_PPC64_TOC16_HA
:
7230 case elfcpp::R_PPC64_TOC16_DS
:
7231 case elfcpp::R_PPC64_TOC16_LO_DS
:
7232 case elfcpp::R_POWERPC_PLT16_LO
:
7233 case elfcpp::R_POWERPC_PLT16_HI
:
7234 case elfcpp::R_POWERPC_PLT16_HA
:
7235 case elfcpp::R_PPC64_PLT16_LO_DS
:
7236 case elfcpp::R_PPC64_PLT_PCREL34
:
7237 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7238 ref
= Symbol::RELATIVE_REF
;
7241 case elfcpp::R_POWERPC_GOT_TPREL16
:
7242 case elfcpp::R_POWERPC_TLS
:
7243 ref
= Symbol::TLS_REF
;
7246 case elfcpp::R_POWERPC_COPY
:
7247 case elfcpp::R_POWERPC_GLOB_DAT
:
7248 case elfcpp::R_POWERPC_JMP_SLOT
:
7249 case elfcpp::R_POWERPC_RELATIVE
:
7250 case elfcpp::R_POWERPC_DTPMOD
:
7252 // Not expected. We will give an error later.
7256 if (size
== 64 && target
->abiversion() < 2)
7257 ref
|= Symbol::FUNC_DESC_ABI
;
7261 // Report an unsupported relocation against a local symbol.
7263 template<int size
, bool big_endian
>
7265 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7266 Sized_relobj_file
<size
, big_endian
>* object
,
7267 unsigned int r_type
)
7269 gold_error(_("%s: unsupported reloc %u against local symbol"),
7270 object
->name().c_str(), r_type
);
7273 // We are about to emit a dynamic relocation of type R_TYPE. If the
7274 // dynamic linker does not support it, issue an error.
7276 template<int size
, bool big_endian
>
7278 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7279 unsigned int r_type
)
7281 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7283 // These are the relocation types supported by glibc for both 32-bit
7284 // and 64-bit powerpc.
7287 case elfcpp::R_POWERPC_NONE
:
7288 case elfcpp::R_POWERPC_RELATIVE
:
7289 case elfcpp::R_POWERPC_GLOB_DAT
:
7290 case elfcpp::R_POWERPC_DTPMOD
:
7291 case elfcpp::R_POWERPC_DTPREL
:
7292 case elfcpp::R_POWERPC_TPREL
:
7293 case elfcpp::R_POWERPC_JMP_SLOT
:
7294 case elfcpp::R_POWERPC_COPY
:
7295 case elfcpp::R_POWERPC_IRELATIVE
:
7296 case elfcpp::R_POWERPC_ADDR32
:
7297 case elfcpp::R_POWERPC_UADDR32
:
7298 case elfcpp::R_POWERPC_ADDR24
:
7299 case elfcpp::R_POWERPC_ADDR16
:
7300 case elfcpp::R_POWERPC_UADDR16
:
7301 case elfcpp::R_POWERPC_ADDR16_LO
:
7302 case elfcpp::R_POWERPC_ADDR16_HI
:
7303 case elfcpp::R_POWERPC_ADDR16_HA
:
7304 case elfcpp::R_POWERPC_ADDR14
:
7305 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7306 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7307 case elfcpp::R_POWERPC_REL32
:
7308 case elfcpp::R_POWERPC_REL24
:
7309 case elfcpp::R_POWERPC_TPREL16
:
7310 case elfcpp::R_POWERPC_TPREL16_LO
:
7311 case elfcpp::R_POWERPC_TPREL16_HI
:
7312 case elfcpp::R_POWERPC_TPREL16_HA
:
7323 // These are the relocation types supported only on 64-bit.
7324 case elfcpp::R_PPC64_ADDR64
:
7325 case elfcpp::R_PPC64_UADDR64
:
7326 case elfcpp::R_PPC64_JMP_IREL
:
7327 case elfcpp::R_PPC64_ADDR16_DS
:
7328 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7329 case elfcpp::R_PPC64_ADDR16_HIGH
:
7330 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7331 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7332 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7333 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7334 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7335 case elfcpp::R_PPC64_REL64
:
7336 case elfcpp::R_POWERPC_ADDR30
:
7337 case elfcpp::R_PPC64_TPREL16_DS
:
7338 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7339 case elfcpp::R_PPC64_TPREL16_HIGH
:
7340 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7341 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7342 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7343 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7344 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7355 // These are the relocation types supported only on 32-bit.
7356 // ??? glibc ld.so doesn't need to support these.
7357 case elfcpp::R_POWERPC_DTPREL16
:
7358 case elfcpp::R_POWERPC_DTPREL16_LO
:
7359 case elfcpp::R_POWERPC_DTPREL16_HI
:
7360 case elfcpp::R_POWERPC_DTPREL16_HA
:
7368 // This prevents us from issuing more than one error per reloc
7369 // section. But we can still wind up issuing more than one
7370 // error per object file.
7371 if (this->issued_non_pic_error_
)
7373 gold_assert(parameters
->options().output_is_position_independent());
7374 object
->error(_("requires unsupported dynamic reloc; "
7375 "recompile with -fPIC"));
7376 this->issued_non_pic_error_
= true;
7380 // Return whether we need to make a PLT entry for a relocation of the
7381 // given type against a STT_GNU_IFUNC symbol.
7383 template<int size
, bool big_endian
>
7385 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7386 Target_powerpc
<size
, big_endian
>* target
,
7387 Sized_relobj_file
<size
, big_endian
>* object
,
7388 unsigned int r_type
,
7391 // In non-pic code any reference will resolve to the plt call stub
7392 // for the ifunc symbol.
7393 if ((size
== 32 || target
->abiversion() >= 2)
7394 && !parameters
->options().output_is_position_independent())
7399 // Word size refs from data sections are OK, but don't need a PLT entry.
7400 case elfcpp::R_POWERPC_ADDR32
:
7401 case elfcpp::R_POWERPC_UADDR32
:
7406 case elfcpp::R_PPC64_ADDR64
:
7407 case elfcpp::R_PPC64_UADDR64
:
7412 // GOT refs are good, but also don't need a PLT entry.
7413 case elfcpp::R_POWERPC_GOT16
:
7414 case elfcpp::R_POWERPC_GOT16_LO
:
7415 case elfcpp::R_POWERPC_GOT16_HI
:
7416 case elfcpp::R_POWERPC_GOT16_HA
:
7417 case elfcpp::R_PPC64_GOT16_DS
:
7418 case elfcpp::R_PPC64_GOT16_LO_DS
:
7419 case elfcpp::R_PPC64_GOT_PCREL34
:
7422 // PLT relocs are OK and need a PLT entry.
7423 case elfcpp::R_POWERPC_PLT16_LO
:
7424 case elfcpp::R_POWERPC_PLT16_HI
:
7425 case elfcpp::R_POWERPC_PLT16_HA
:
7426 case elfcpp::R_PPC64_PLT16_LO_DS
:
7427 case elfcpp::R_POWERPC_PLTSEQ
:
7428 case elfcpp::R_POWERPC_PLTCALL
:
7429 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7430 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7431 case elfcpp::R_PPC64_PLT_PCREL34
:
7432 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7436 // Function calls are good, and these do need a PLT entry.
7437 case elfcpp::R_PPC64_REL24_NOTOC
:
7441 case elfcpp::R_POWERPC_ADDR24
:
7442 case elfcpp::R_POWERPC_ADDR14
:
7443 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7444 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7445 case elfcpp::R_POWERPC_REL24
:
7446 case elfcpp::R_PPC_PLTREL24
:
7447 case elfcpp::R_POWERPC_REL14
:
7448 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7449 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7456 // Anything else is a problem.
7457 // If we are building a static executable, the libc startup function
7458 // responsible for applying indirect function relocations is going
7459 // to complain about the reloc type.
7460 // If we are building a dynamic executable, we will have a text
7461 // relocation. The dynamic loader will set the text segment
7462 // writable and non-executable to apply text relocations. So we'll
7463 // segfault when trying to run the indirection function to resolve
7466 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7467 object
->name().c_str(), r_type
);
7471 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7475 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7477 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7478 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7479 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7480 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7481 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7482 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7483 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7484 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7485 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7486 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7487 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7488 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7489 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7490 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7491 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7492 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7493 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7494 /* Exclude lfqu by testing reloc. If relocs are ever
7495 defined for the reduced D field in psq_lu then those
7496 will need testing too. */
7497 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7498 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7499 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7501 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7502 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7503 /* Exclude stfqu. psq_stu as above for psq_lu. */
7504 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7505 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7506 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7507 && (insn
& 1) == 0));
7510 // Scan a relocation for a local symbol.
7512 template<int size
, bool big_endian
>
7514 Target_powerpc
<size
, big_endian
>::Scan::local(
7515 Symbol_table
* symtab
,
7517 Target_powerpc
<size
, big_endian
>* target
,
7518 Sized_relobj_file
<size
, big_endian
>* object
,
7519 unsigned int data_shndx
,
7520 Output_section
* output_section
,
7521 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7522 unsigned int r_type
,
7523 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7526 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7528 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7529 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7531 this->expect_tls_get_addr_call();
7532 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7533 if (tls_type
!= tls::TLSOPT_NONE
)
7534 this->skip_next_tls_get_addr_call();
7536 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7537 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7539 this->expect_tls_get_addr_call();
7540 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7541 if (tls_type
!= tls::TLSOPT_NONE
)
7542 this->skip_next_tls_get_addr_call();
7545 Powerpc_relobj
<size
, big_endian
>* ppc_object
7546 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7551 && data_shndx
== ppc_object
->opd_shndx()
7552 && r_type
== elfcpp::R_PPC64_ADDR64
)
7553 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7557 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7558 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7559 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7561 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7562 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7563 r_type
, r_sym
, reloc
.get_r_addend());
7564 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7569 case elfcpp::R_POWERPC_NONE
:
7570 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7571 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7572 case elfcpp::R_POWERPC_TLS
:
7573 case elfcpp::R_PPC64_ENTRY
:
7574 case elfcpp::R_POWERPC_PLTSEQ
:
7575 case elfcpp::R_POWERPC_PLTCALL
:
7576 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7577 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7578 case elfcpp::R_PPC64_PCREL_OPT
:
7579 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
7580 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
7581 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
7582 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
7583 case elfcpp::R_PPC64_REL16_HIGHER34
:
7584 case elfcpp::R_PPC64_REL16_HIGHERA34
:
7585 case elfcpp::R_PPC64_REL16_HIGHEST34
:
7586 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
7589 case elfcpp::R_PPC64_D34
:
7590 case elfcpp::R_PPC64_D34_LO
:
7591 case elfcpp::R_PPC64_D34_HI30
:
7592 case elfcpp::R_PPC64_D34_HA30
:
7593 case elfcpp::R_PPC64_D28
:
7594 case elfcpp::R_PPC64_PCREL34
:
7595 case elfcpp::R_PPC64_PCREL28
:
7596 target
->set_powerxx_stubs();
7599 case elfcpp::R_PPC64_TOC
:
7601 Output_data_got_powerpc
<size
, big_endian
>* got
7602 = target
->got_section(symtab
, layout
);
7603 if (parameters
->options().output_is_position_independent())
7605 Address off
= reloc
.get_r_offset();
7607 && target
->abiversion() < 2
7608 && data_shndx
== ppc_object
->opd_shndx()
7609 && ppc_object
->get_opd_discard(off
- 8))
7612 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7613 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7614 rela_dyn
->add_output_section_relative(got
->output_section(),
7615 elfcpp::R_POWERPC_RELATIVE
,
7617 object
, data_shndx
, off
,
7618 symobj
->toc_base_offset());
7623 case elfcpp::R_PPC64_ADDR64
:
7624 case elfcpp::R_PPC64_UADDR64
:
7625 case elfcpp::R_POWERPC_ADDR32
:
7626 case elfcpp::R_POWERPC_UADDR32
:
7627 case elfcpp::R_POWERPC_ADDR24
:
7628 case elfcpp::R_POWERPC_ADDR16
:
7629 case elfcpp::R_POWERPC_ADDR16_LO
:
7630 case elfcpp::R_POWERPC_ADDR16_HI
:
7631 case elfcpp::R_POWERPC_ADDR16_HA
:
7632 case elfcpp::R_POWERPC_UADDR16
:
7633 case elfcpp::R_PPC64_ADDR16_HIGH
:
7634 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7635 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7636 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7637 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7638 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7639 case elfcpp::R_PPC64_ADDR16_DS
:
7640 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7641 case elfcpp::R_POWERPC_ADDR14
:
7642 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7643 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7644 // If building a shared library (or a position-independent
7645 // executable), we need to create a dynamic relocation for
7647 if (parameters
->options().output_is_position_independent()
7648 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7650 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7652 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7653 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7654 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7656 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7657 : elfcpp::R_POWERPC_RELATIVE
);
7658 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7659 output_section
, data_shndx
,
7660 reloc
.get_r_offset(),
7661 reloc
.get_r_addend(), false);
7663 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7665 check_non_pic(object
, r_type
);
7666 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7667 data_shndx
, reloc
.get_r_offset(),
7668 reloc
.get_r_addend());
7672 gold_assert(lsym
.get_st_value() == 0);
7673 unsigned int shndx
= lsym
.get_st_shndx();
7675 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7678 object
->error(_("section symbol %u has bad shndx %u"),
7681 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7682 output_section
, data_shndx
,
7683 reloc
.get_r_offset());
7688 case elfcpp::R_PPC64_PLT_PCREL34
:
7689 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
7690 target
->set_powerxx_stubs();
7692 case elfcpp::R_POWERPC_PLT16_LO
:
7693 case elfcpp::R_POWERPC_PLT16_HI
:
7694 case elfcpp::R_POWERPC_PLT16_HA
:
7695 case elfcpp::R_PPC64_PLT16_LO_DS
:
7698 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7699 target
->make_local_plt_entry(layout
, object
, r_sym
);
7703 case elfcpp::R_PPC64_REL24_NOTOC
:
7707 case elfcpp::R_POWERPC_REL24
:
7708 case elfcpp::R_PPC_PLTREL24
:
7709 case elfcpp::R_PPC_LOCAL24PC
:
7710 case elfcpp::R_POWERPC_REL14
:
7711 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7712 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7715 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7716 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7717 r_type
, r_sym
, reloc
.get_r_addend());
7721 case elfcpp::R_PPC64_TOCSAVE
:
7722 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7723 // caller has already saved r2 and thus a plt call stub need not
7726 && target
->mark_pltcall(ppc_object
, data_shndx
,
7727 reloc
.get_r_offset() - 4, symtab
))
7729 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7730 unsigned int shndx
= lsym
.get_st_shndx();
7732 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7734 object
->error(_("tocsave symbol %u has bad shndx %u"),
7737 target
->add_tocsave(ppc_object
, shndx
,
7738 lsym
.get_st_value() + reloc
.get_r_addend());
7742 case elfcpp::R_PPC64_REL64
:
7743 case elfcpp::R_POWERPC_REL32
:
7744 case elfcpp::R_POWERPC_REL16
:
7745 case elfcpp::R_POWERPC_REL16_LO
:
7746 case elfcpp::R_POWERPC_REL16_HI
:
7747 case elfcpp::R_POWERPC_REL16_HA
:
7748 case elfcpp::R_POWERPC_REL16DX_HA
:
7749 case elfcpp::R_PPC64_REL16_HIGH
:
7750 case elfcpp::R_PPC64_REL16_HIGHA
:
7751 case elfcpp::R_PPC64_REL16_HIGHER
:
7752 case elfcpp::R_PPC64_REL16_HIGHERA
:
7753 case elfcpp::R_PPC64_REL16_HIGHEST
:
7754 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7755 case elfcpp::R_POWERPC_SECTOFF
:
7756 case elfcpp::R_POWERPC_SECTOFF_LO
:
7757 case elfcpp::R_POWERPC_SECTOFF_HI
:
7758 case elfcpp::R_POWERPC_SECTOFF_HA
:
7759 case elfcpp::R_PPC64_SECTOFF_DS
:
7760 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7761 case elfcpp::R_POWERPC_TPREL16
:
7762 case elfcpp::R_POWERPC_TPREL16_LO
:
7763 case elfcpp::R_POWERPC_TPREL16_HI
:
7764 case elfcpp::R_POWERPC_TPREL16_HA
:
7765 case elfcpp::R_PPC64_TPREL16_DS
:
7766 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7767 case elfcpp::R_PPC64_TPREL16_HIGH
:
7768 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7769 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7770 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7771 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7772 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7773 case elfcpp::R_POWERPC_DTPREL16
:
7774 case elfcpp::R_POWERPC_DTPREL16_LO
:
7775 case elfcpp::R_POWERPC_DTPREL16_HI
:
7776 case elfcpp::R_POWERPC_DTPREL16_HA
:
7777 case elfcpp::R_PPC64_DTPREL16_DS
:
7778 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7779 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7780 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7781 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7782 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7783 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7784 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7785 case elfcpp::R_PPC64_TLSGD
:
7786 case elfcpp::R_PPC64_TLSLD
:
7787 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7790 case elfcpp::R_PPC64_GOT_PCREL34
:
7791 target
->set_powerxx_stubs();
7793 case elfcpp::R_POWERPC_GOT16
:
7794 case elfcpp::R_POWERPC_GOT16_LO
:
7795 case elfcpp::R_POWERPC_GOT16_HI
:
7796 case elfcpp::R_POWERPC_GOT16_HA
:
7797 case elfcpp::R_PPC64_GOT16_DS
:
7798 case elfcpp::R_PPC64_GOT16_LO_DS
:
7800 // The symbol requires a GOT entry.
7801 Output_data_got_powerpc
<size
, big_endian
>* got
7802 = target
->got_section(symtab
, layout
);
7803 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7805 if (!parameters
->options().output_is_position_independent())
7808 && (size
== 32 || target
->abiversion() >= 2))
7809 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
7811 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
7813 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
7815 // If we are generating a shared object or a pie, this
7816 // symbol's GOT entry will be set by a dynamic relocation.
7818 off
= got
->add_constant(0);
7819 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
7821 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7823 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7824 : elfcpp::R_POWERPC_RELATIVE
);
7825 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7826 got
, off
, 0, false);
7831 case elfcpp::R_PPC64_TOC16
:
7832 case elfcpp::R_PPC64_TOC16_LO
:
7833 case elfcpp::R_PPC64_TOC16_HI
:
7834 case elfcpp::R_PPC64_TOC16_HA
:
7835 case elfcpp::R_PPC64_TOC16_DS
:
7836 case elfcpp::R_PPC64_TOC16_LO_DS
:
7837 // We need a GOT section.
7838 target
->got_section(symtab
, layout
);
7841 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7842 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7843 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7844 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7846 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7847 if (tls_type
== tls::TLSOPT_NONE
)
7849 Output_data_got_powerpc
<size
, big_endian
>* got
7850 = target
->got_section(symtab
, layout
);
7851 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7852 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7853 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
7854 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
7856 else if (tls_type
== tls::TLSOPT_TO_LE
)
7858 // no GOT relocs needed for Local Exec.
7865 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7866 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7867 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7868 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7870 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7871 if (tls_type
== tls::TLSOPT_NONE
)
7872 target
->tlsld_got_offset(symtab
, layout
, object
);
7873 else if (tls_type
== tls::TLSOPT_TO_LE
)
7875 // no GOT relocs needed for Local Exec.
7876 if (parameters
->options().emit_relocs())
7878 Output_section
* os
= layout
->tls_segment()->first_section();
7879 gold_assert(os
!= NULL
);
7880 os
->set_needs_symtab_index();
7888 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7889 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7890 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7891 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7893 Output_data_got_powerpc
<size
, big_endian
>* got
7894 = target
->got_section(symtab
, layout
);
7895 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7896 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
7900 case elfcpp::R_POWERPC_GOT_TPREL16
:
7901 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7902 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7903 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7905 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
7906 if (tls_type
== tls::TLSOPT_NONE
)
7908 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7909 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
7911 Output_data_got_powerpc
<size
, big_endian
>* got
7912 = target
->got_section(symtab
, layout
);
7913 unsigned int off
= got
->add_constant(0);
7914 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
7916 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7917 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
7918 elfcpp::R_POWERPC_TPREL
,
7922 else if (tls_type
== tls::TLSOPT_TO_LE
)
7924 // no GOT relocs needed for Local Exec.
7932 unsupported_reloc_local(object
, r_type
);
7937 && parameters
->options().toc_optimize())
7939 if (data_shndx
== ppc_object
->toc_shndx())
7942 if (r_type
!= elfcpp::R_PPC64_ADDR64
7943 || (is_ifunc
&& target
->abiversion() < 2))
7945 else if (parameters
->options().output_is_position_independent())
7951 unsigned int shndx
= lsym
.get_st_shndx();
7952 if (shndx
>= elfcpp::SHN_LORESERVE
7953 && shndx
!= elfcpp::SHN_XINDEX
)
7958 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
7961 enum {no_check
, check_lo
, check_ha
} insn_check
;
7965 insn_check
= no_check
;
7968 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7969 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7970 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7971 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7972 case elfcpp::R_POWERPC_GOT16_HA
:
7973 case elfcpp::R_PPC64_TOC16_HA
:
7974 insn_check
= check_ha
;
7977 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7978 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7979 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7980 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7981 case elfcpp::R_POWERPC_GOT16_LO
:
7982 case elfcpp::R_PPC64_GOT16_LO_DS
:
7983 case elfcpp::R_PPC64_TOC16_LO
:
7984 case elfcpp::R_PPC64_TOC16_LO_DS
:
7985 insn_check
= check_lo
;
7989 section_size_type slen
;
7990 const unsigned char* view
= NULL
;
7991 if (insn_check
!= no_check
)
7993 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
7994 section_size_type off
=
7995 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
7998 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
7999 if (insn_check
== check_lo
8000 ? !ok_lo_toc_insn(insn
, r_type
)
8001 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8002 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8004 ppc_object
->set_no_toc_opt();
8005 gold_warning(_("%s: toc optimization is not supported "
8006 "for %#08x instruction"),
8007 ppc_object
->name().c_str(), insn
);
8016 case elfcpp::R_PPC64_TOC16
:
8017 case elfcpp::R_PPC64_TOC16_LO
:
8018 case elfcpp::R_PPC64_TOC16_HI
:
8019 case elfcpp::R_PPC64_TOC16_HA
:
8020 case elfcpp::R_PPC64_TOC16_DS
:
8021 case elfcpp::R_PPC64_TOC16_LO_DS
:
8022 unsigned int shndx
= lsym
.get_st_shndx();
8023 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8025 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8026 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
8028 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
8029 if (dst_off
< ppc_object
->section_size(shndx
))
8032 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8034 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8036 // Need to check that the insn is a ld
8038 view
= ppc_object
->section_contents(data_shndx
,
8041 section_size_type off
=
8042 (convert_to_section_size_type(reloc
.get_r_offset())
8043 + (big_endian
? -2 : 3));
8045 && (view
[off
] & (0x3f << 2)) == 58u << 2)
8049 ppc_object
->set_no_toc_opt(dst_off
);
8060 case elfcpp::R_POWERPC_REL32
:
8061 if (ppc_object
->got2_shndx() != 0
8062 && parameters
->options().output_is_position_independent())
8064 unsigned int shndx
= lsym
.get_st_shndx();
8065 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8067 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
8068 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
8069 && (ppc_object
->section_flags(data_shndx
)
8070 & elfcpp::SHF_EXECINSTR
) != 0)
8071 gold_error(_("%s: unsupported -mbss-plt code"),
8072 ppc_object
->name().c_str());
8082 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8083 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8084 case elfcpp::R_POWERPC_GOT_TPREL16
:
8085 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8086 case elfcpp::R_POWERPC_GOT16
:
8087 case elfcpp::R_PPC64_GOT16_DS
:
8088 case elfcpp::R_PPC64_TOC16
:
8089 case elfcpp::R_PPC64_TOC16_DS
:
8090 ppc_object
->set_has_small_toc_reloc();
8096 // Report an unsupported relocation against a global symbol.
8098 template<int size
, bool big_endian
>
8100 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
8101 Sized_relobj_file
<size
, big_endian
>* object
,
8102 unsigned int r_type
,
8105 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
8106 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
8109 // Scan a relocation for a global symbol.
8111 template<int size
, bool big_endian
>
8113 Target_powerpc
<size
, big_endian
>::Scan::global(
8114 Symbol_table
* symtab
,
8116 Target_powerpc
<size
, big_endian
>* target
,
8117 Sized_relobj_file
<size
, big_endian
>* object
,
8118 unsigned int data_shndx
,
8119 Output_section
* output_section
,
8120 const elfcpp::Rela
<size
, big_endian
>& reloc
,
8121 unsigned int r_type
,
8124 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
8128 if (target
->replace_tls_get_addr(gsym
))
8129 // Change a __tls_get_addr reference to __tls_get_addr_opt
8130 // so dynamic relocs are emitted against the latter symbol.
8131 gsym
= target
->tls_get_addr_opt();
8133 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8134 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8136 this->expect_tls_get_addr_call();
8137 const bool final
= gsym
->final_value_is_known();
8138 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8139 if (tls_type
!= tls::TLSOPT_NONE
)
8140 this->skip_next_tls_get_addr_call();
8142 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8143 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8145 this->expect_tls_get_addr_call();
8146 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8147 if (tls_type
!= tls::TLSOPT_NONE
)
8148 this->skip_next_tls_get_addr_call();
8151 Powerpc_relobj
<size
, big_endian
>* ppc_object
8152 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8154 // A STT_GNU_IFUNC symbol may require a PLT entry.
8155 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
8156 bool pushed_ifunc
= false;
8157 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
8159 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8160 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8161 r_type
, r_sym
, reloc
.get_r_addend());
8162 target
->make_plt_entry(symtab
, layout
, gsym
);
8163 pushed_ifunc
= true;
8168 case elfcpp::R_POWERPC_NONE
:
8169 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
8170 case elfcpp::R_POWERPC_GNU_VTENTRY
:
8171 case elfcpp::R_PPC_LOCAL24PC
:
8172 case elfcpp::R_POWERPC_TLS
:
8173 case elfcpp::R_PPC64_ENTRY
:
8174 case elfcpp::R_POWERPC_PLTSEQ
:
8175 case elfcpp::R_POWERPC_PLTCALL
:
8176 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
8177 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
8178 case elfcpp::R_PPC64_PCREL_OPT
:
8179 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
8180 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
8181 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
8182 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
8183 case elfcpp::R_PPC64_REL16_HIGHER34
:
8184 case elfcpp::R_PPC64_REL16_HIGHERA34
:
8185 case elfcpp::R_PPC64_REL16_HIGHEST34
:
8186 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
8189 case elfcpp::R_PPC64_D34
:
8190 case elfcpp::R_PPC64_D34_LO
:
8191 case elfcpp::R_PPC64_D34_HI30
:
8192 case elfcpp::R_PPC64_D34_HA30
:
8193 case elfcpp::R_PPC64_D28
:
8194 case elfcpp::R_PPC64_PCREL34
:
8195 case elfcpp::R_PPC64_PCREL28
:
8196 target
->set_powerxx_stubs();
8199 case elfcpp::R_PPC64_TOC
:
8201 Output_data_got_powerpc
<size
, big_endian
>* got
8202 = target
->got_section(symtab
, layout
);
8203 if (parameters
->options().output_is_position_independent())
8205 Address off
= reloc
.get_r_offset();
8207 && data_shndx
== ppc_object
->opd_shndx()
8208 && ppc_object
->get_opd_discard(off
- 8))
8211 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8212 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
8213 if (data_shndx
!= ppc_object
->opd_shndx())
8214 symobj
= static_cast
8215 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8216 rela_dyn
->add_output_section_relative(got
->output_section(),
8217 elfcpp::R_POWERPC_RELATIVE
,
8219 object
, data_shndx
, off
,
8220 symobj
->toc_base_offset());
8225 case elfcpp::R_PPC64_ADDR64
:
8227 && target
->abiversion() < 2
8228 && data_shndx
== ppc_object
->opd_shndx()
8229 && (gsym
->is_defined_in_discarded_section()
8230 || gsym
->object() != object
))
8232 ppc_object
->set_opd_discard(reloc
.get_r_offset());
8236 case elfcpp::R_PPC64_UADDR64
:
8237 case elfcpp::R_POWERPC_ADDR32
:
8238 case elfcpp::R_POWERPC_UADDR32
:
8239 case elfcpp::R_POWERPC_ADDR24
:
8240 case elfcpp::R_POWERPC_ADDR16
:
8241 case elfcpp::R_POWERPC_ADDR16_LO
:
8242 case elfcpp::R_POWERPC_ADDR16_HI
:
8243 case elfcpp::R_POWERPC_ADDR16_HA
:
8244 case elfcpp::R_POWERPC_UADDR16
:
8245 case elfcpp::R_PPC64_ADDR16_HIGH
:
8246 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8247 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8248 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8249 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8250 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8251 case elfcpp::R_PPC64_ADDR16_DS
:
8252 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8253 case elfcpp::R_POWERPC_ADDR14
:
8254 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8255 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8257 // Make a PLT entry if necessary.
8258 if (gsym
->needs_plt_entry())
8260 // Since this is not a PC-relative relocation, we may be
8261 // taking the address of a function. In that case we need to
8262 // set the entry in the dynamic symbol table to the address of
8263 // the PLT call stub.
8264 bool need_ifunc_plt
= false;
8265 if ((size
== 32 || target
->abiversion() >= 2)
8266 && gsym
->is_from_dynobj()
8267 && !parameters
->options().output_is_position_independent())
8269 gsym
->set_needs_dynsym_value();
8270 need_ifunc_plt
= true;
8272 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
8274 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8275 target
->push_branch(ppc_object
, data_shndx
,
8276 reloc
.get_r_offset(), r_type
, r_sym
,
8277 reloc
.get_r_addend());
8278 target
->make_plt_entry(symtab
, layout
, gsym
);
8281 // Make a dynamic relocation if necessary.
8282 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
8283 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
8285 if (!parameters
->options().output_is_position_independent()
8286 && gsym
->may_need_copy_reloc())
8288 target
->copy_reloc(symtab
, layout
, object
,
8289 data_shndx
, output_section
, gsym
, reloc
);
8291 else if ((((size
== 32
8292 && r_type
== elfcpp::R_POWERPC_ADDR32
)
8294 && r_type
== elfcpp::R_PPC64_ADDR64
8295 && target
->abiversion() >= 2))
8296 && gsym
->can_use_relative_reloc(false)
8297 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
8298 && parameters
->options().shared()))
8300 && r_type
== elfcpp::R_PPC64_ADDR64
8301 && target
->abiversion() < 2
8302 && (gsym
->can_use_relative_reloc(false)
8303 || data_shndx
== ppc_object
->opd_shndx())))
8305 Reloc_section
* rela_dyn
8306 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8307 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8308 : elfcpp::R_POWERPC_RELATIVE
);
8309 rela_dyn
->add_symbolless_global_addend(
8310 gsym
, dynrel
, output_section
, object
, data_shndx
,
8311 reloc
.get_r_offset(), reloc
.get_r_addend());
8315 Reloc_section
* rela_dyn
8316 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8317 check_non_pic(object
, r_type
);
8318 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8320 reloc
.get_r_offset(),
8321 reloc
.get_r_addend());
8324 && parameters
->options().toc_optimize()
8325 && data_shndx
== ppc_object
->toc_shndx())
8326 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8332 case elfcpp::R_PPC64_PLT_PCREL34
:
8333 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
8334 target
->set_powerxx_stubs();
8336 case elfcpp::R_POWERPC_PLT16_LO
:
8337 case elfcpp::R_POWERPC_PLT16_HI
:
8338 case elfcpp::R_POWERPC_PLT16_HA
:
8339 case elfcpp::R_PPC64_PLT16_LO_DS
:
8341 target
->make_plt_entry(symtab
, layout
, gsym
);
8344 case elfcpp::R_PPC64_REL24_NOTOC
:
8348 case elfcpp::R_PPC_PLTREL24
:
8349 case elfcpp::R_POWERPC_REL24
:
8352 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8353 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8354 r_type
, r_sym
, reloc
.get_r_addend());
8355 if (gsym
->needs_plt_entry()
8356 || (!gsym
->final_value_is_known()
8357 && (gsym
->is_undefined()
8358 || gsym
->is_from_dynobj()
8359 || gsym
->is_preemptible())))
8360 target
->make_plt_entry(symtab
, layout
, gsym
);
8364 case elfcpp::R_PPC64_REL64
:
8365 case elfcpp::R_POWERPC_REL32
:
8366 // Make a dynamic relocation if necessary.
8367 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8369 if (!parameters
->options().output_is_position_independent()
8370 && gsym
->may_need_copy_reloc())
8372 target
->copy_reloc(symtab
, layout
, object
,
8373 data_shndx
, output_section
, gsym
,
8378 Reloc_section
* rela_dyn
8379 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8380 check_non_pic(object
, r_type
);
8381 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8382 data_shndx
, reloc
.get_r_offset(),
8383 reloc
.get_r_addend());
8388 case elfcpp::R_POWERPC_REL14
:
8389 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8390 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8393 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8394 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8395 r_type
, r_sym
, reloc
.get_r_addend());
8399 case elfcpp::R_PPC64_TOCSAVE
:
8400 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8401 // caller has already saved r2 and thus a plt call stub need not
8404 && target
->mark_pltcall(ppc_object
, data_shndx
,
8405 reloc
.get_r_offset() - 4, symtab
))
8407 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8409 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8411 object
->error(_("tocsave symbol %u has bad shndx %u"),
8415 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8416 target
->add_tocsave(ppc_object
, shndx
,
8417 sym
->value() + reloc
.get_r_addend());
8422 case elfcpp::R_POWERPC_REL16
:
8423 case elfcpp::R_POWERPC_REL16_LO
:
8424 case elfcpp::R_POWERPC_REL16_HI
:
8425 case elfcpp::R_POWERPC_REL16_HA
:
8426 case elfcpp::R_POWERPC_REL16DX_HA
:
8427 case elfcpp::R_PPC64_REL16_HIGH
:
8428 case elfcpp::R_PPC64_REL16_HIGHA
:
8429 case elfcpp::R_PPC64_REL16_HIGHER
:
8430 case elfcpp::R_PPC64_REL16_HIGHERA
:
8431 case elfcpp::R_PPC64_REL16_HIGHEST
:
8432 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8433 case elfcpp::R_POWERPC_SECTOFF
:
8434 case elfcpp::R_POWERPC_SECTOFF_LO
:
8435 case elfcpp::R_POWERPC_SECTOFF_HI
:
8436 case elfcpp::R_POWERPC_SECTOFF_HA
:
8437 case elfcpp::R_PPC64_SECTOFF_DS
:
8438 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8439 case elfcpp::R_POWERPC_TPREL16
:
8440 case elfcpp::R_POWERPC_TPREL16_LO
:
8441 case elfcpp::R_POWERPC_TPREL16_HI
:
8442 case elfcpp::R_POWERPC_TPREL16_HA
:
8443 case elfcpp::R_PPC64_TPREL16_DS
:
8444 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8445 case elfcpp::R_PPC64_TPREL16_HIGH
:
8446 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8447 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8448 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8449 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8450 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8451 case elfcpp::R_POWERPC_DTPREL16
:
8452 case elfcpp::R_POWERPC_DTPREL16_LO
:
8453 case elfcpp::R_POWERPC_DTPREL16_HI
:
8454 case elfcpp::R_POWERPC_DTPREL16_HA
:
8455 case elfcpp::R_PPC64_DTPREL16_DS
:
8456 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8457 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8458 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8459 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8460 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8461 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8462 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8463 case elfcpp::R_PPC64_TLSGD
:
8464 case elfcpp::R_PPC64_TLSLD
:
8465 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8468 case elfcpp::R_PPC64_GOT_PCREL34
:
8469 target
->set_powerxx_stubs();
8471 case elfcpp::R_POWERPC_GOT16
:
8472 case elfcpp::R_POWERPC_GOT16_LO
:
8473 case elfcpp::R_POWERPC_GOT16_HI
:
8474 case elfcpp::R_POWERPC_GOT16_HA
:
8475 case elfcpp::R_PPC64_GOT16_DS
:
8476 case elfcpp::R_PPC64_GOT16_LO_DS
:
8478 // The symbol requires a GOT entry.
8479 Output_data_got_powerpc
<size
, big_endian
>* got
;
8481 got
= target
->got_section(symtab
, layout
);
8482 if (gsym
->final_value_is_known())
8485 && (size
== 32 || target
->abiversion() >= 2))
8486 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8488 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8490 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8492 // If we are generating a shared object or a pie, this
8493 // symbol's GOT entry will be set by a dynamic relocation.
8494 unsigned int off
= got
->add_constant(0);
8495 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8497 Reloc_section
* rela_dyn
8498 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8500 if (gsym
->can_use_relative_reloc(false)
8502 || target
->abiversion() >= 2)
8503 && gsym
->visibility() == elfcpp::STV_PROTECTED
8504 && parameters
->options().shared()))
8506 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8507 : elfcpp::R_POWERPC_RELATIVE
);
8508 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8512 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8513 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8519 case elfcpp::R_PPC64_TOC16
:
8520 case elfcpp::R_PPC64_TOC16_LO
:
8521 case elfcpp::R_PPC64_TOC16_HI
:
8522 case elfcpp::R_PPC64_TOC16_HA
:
8523 case elfcpp::R_PPC64_TOC16_DS
:
8524 case elfcpp::R_PPC64_TOC16_LO_DS
:
8525 // We need a GOT section.
8526 target
->got_section(symtab
, layout
);
8529 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8530 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8531 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8532 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8534 const bool final
= gsym
->final_value_is_known();
8535 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8536 if (tls_type
== tls::TLSOPT_NONE
)
8538 Output_data_got_powerpc
<size
, big_endian
>* got
8539 = target
->got_section(symtab
, layout
);
8540 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8541 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8542 elfcpp::R_POWERPC_DTPMOD
,
8543 elfcpp::R_POWERPC_DTPREL
);
8545 else if (tls_type
== tls::TLSOPT_TO_IE
)
8547 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8549 Output_data_got_powerpc
<size
, big_endian
>* got
8550 = target
->got_section(symtab
, layout
);
8551 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8552 if (gsym
->is_undefined()
8553 || gsym
->is_from_dynobj())
8555 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8556 elfcpp::R_POWERPC_TPREL
);
8560 unsigned int off
= got
->add_constant(0);
8561 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8562 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8563 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8568 else if (tls_type
== tls::TLSOPT_TO_LE
)
8570 // no GOT relocs needed for Local Exec.
8577 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8578 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8579 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8580 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8582 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8583 if (tls_type
== tls::TLSOPT_NONE
)
8584 target
->tlsld_got_offset(symtab
, layout
, object
);
8585 else if (tls_type
== tls::TLSOPT_TO_LE
)
8587 // no GOT relocs needed for Local Exec.
8588 if (parameters
->options().emit_relocs())
8590 Output_section
* os
= layout
->tls_segment()->first_section();
8591 gold_assert(os
!= NULL
);
8592 os
->set_needs_symtab_index();
8600 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8601 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8602 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8603 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8605 Output_data_got_powerpc
<size
, big_endian
>* got
8606 = target
->got_section(symtab
, layout
);
8607 if (!gsym
->final_value_is_known()
8608 && (gsym
->is_from_dynobj()
8609 || gsym
->is_undefined()
8610 || gsym
->is_preemptible()))
8611 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8612 target
->rela_dyn_section(layout
),
8613 elfcpp::R_POWERPC_DTPREL
);
8615 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8619 case elfcpp::R_POWERPC_GOT_TPREL16
:
8620 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8621 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8622 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8624 const bool final
= gsym
->final_value_is_known();
8625 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8626 if (tls_type
== tls::TLSOPT_NONE
)
8628 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8630 Output_data_got_powerpc
<size
, big_endian
>* got
8631 = target
->got_section(symtab
, layout
);
8632 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8633 if (gsym
->is_undefined()
8634 || gsym
->is_from_dynobj())
8636 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8637 elfcpp::R_POWERPC_TPREL
);
8641 unsigned int off
= got
->add_constant(0);
8642 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8643 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8644 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8649 else if (tls_type
== tls::TLSOPT_TO_LE
)
8651 // no GOT relocs needed for Local Exec.
8659 unsupported_reloc_global(object
, r_type
, gsym
);
8664 && parameters
->options().toc_optimize())
8666 if (data_shndx
== ppc_object
->toc_shndx())
8669 if (r_type
!= elfcpp::R_PPC64_ADDR64
8670 || (is_ifunc
&& target
->abiversion() < 2))
8672 else if (parameters
->options().output_is_position_independent()
8673 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
8676 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8679 enum {no_check
, check_lo
, check_ha
} insn_check
;
8683 insn_check
= no_check
;
8686 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8687 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8688 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8689 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8690 case elfcpp::R_POWERPC_GOT16_HA
:
8691 case elfcpp::R_PPC64_TOC16_HA
:
8692 insn_check
= check_ha
;
8695 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8696 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8697 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8698 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8699 case elfcpp::R_POWERPC_GOT16_LO
:
8700 case elfcpp::R_PPC64_GOT16_LO_DS
:
8701 case elfcpp::R_PPC64_TOC16_LO
:
8702 case elfcpp::R_PPC64_TOC16_LO_DS
:
8703 insn_check
= check_lo
;
8707 section_size_type slen
;
8708 const unsigned char* view
= NULL
;
8709 if (insn_check
!= no_check
)
8711 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8712 section_size_type off
=
8713 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8716 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8717 if (insn_check
== check_lo
8718 ? !ok_lo_toc_insn(insn
, r_type
)
8719 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8720 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8722 ppc_object
->set_no_toc_opt();
8723 gold_warning(_("%s: toc optimization is not supported "
8724 "for %#08x instruction"),
8725 ppc_object
->name().c_str(), insn
);
8734 case elfcpp::R_PPC64_TOC16
:
8735 case elfcpp::R_PPC64_TOC16_LO
:
8736 case elfcpp::R_PPC64_TOC16_HI
:
8737 case elfcpp::R_PPC64_TOC16_HA
:
8738 case elfcpp::R_PPC64_TOC16_DS
:
8739 case elfcpp::R_PPC64_TOC16_LO_DS
:
8740 if (gsym
->source() == Symbol::FROM_OBJECT
8741 && !gsym
->object()->is_dynamic())
8743 Powerpc_relobj
<size
, big_endian
>* sym_object
8744 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8746 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8747 if (shndx
== sym_object
->toc_shndx())
8749 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8750 Address dst_off
= sym
->value() + reloc
.get_r_addend();
8751 if (dst_off
< sym_object
->section_size(shndx
))
8754 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8756 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8758 // Need to check that the insn is a ld
8760 view
= ppc_object
->section_contents(data_shndx
,
8763 section_size_type off
=
8764 (convert_to_section_size_type(reloc
.get_r_offset())
8765 + (big_endian
? -2 : 3));
8767 && (view
[off
] & (0x3f << 2)) == (58u << 2))
8771 sym_object
->set_no_toc_opt(dst_off
);
8783 case elfcpp::R_PPC_LOCAL24PC
:
8784 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
8785 gold_error(_("%s: unsupported -mbss-plt code"),
8786 ppc_object
->name().c_str());
8795 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8796 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8797 case elfcpp::R_POWERPC_GOT_TPREL16
:
8798 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8799 case elfcpp::R_POWERPC_GOT16
:
8800 case elfcpp::R_PPC64_GOT16_DS
:
8801 case elfcpp::R_PPC64_TOC16
:
8802 case elfcpp::R_PPC64_TOC16_DS
:
8803 ppc_object
->set_has_small_toc_reloc();
8809 // Process relocations for gc.
8811 template<int size
, bool big_endian
>
8813 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
8814 Symbol_table
* symtab
,
8816 Sized_relobj_file
<size
, big_endian
>* object
,
8817 unsigned int data_shndx
,
8819 const unsigned char* prelocs
,
8821 Output_section
* output_section
,
8822 bool needs_special_offset_handling
,
8823 size_t local_symbol_count
,
8824 const unsigned char* plocal_symbols
)
8826 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8827 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8830 Powerpc_relobj
<size
, big_endian
>* ppc_object
8831 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8833 ppc_object
->set_opd_valid();
8834 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
8836 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
8837 for (p
= ppc_object
->access_from_map()->begin();
8838 p
!= ppc_object
->access_from_map()->end();
8841 Address dst_off
= p
->first
;
8842 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8843 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
8844 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
8846 Relobj
* src_obj
= s
->first
;
8847 unsigned int src_indx
= s
->second
;
8848 symtab
->gc()->add_reference(src_obj
, src_indx
,
8849 ppc_object
, dst_indx
);
8853 ppc_object
->access_from_map()->clear();
8854 ppc_object
->process_gc_mark(symtab
);
8855 // Don't look at .opd relocs as .opd will reference everything.
8859 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
8868 needs_special_offset_handling
,
8873 // Handle target specific gc actions when adding a gc reference from
8874 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
8875 // and DST_OFF. For powerpc64, this adds a referenc to the code
8876 // section of a function descriptor.
8878 template<int size
, bool big_endian
>
8880 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
8881 Symbol_table
* symtab
,
8883 unsigned int src_shndx
,
8885 unsigned int dst_shndx
,
8886 Address dst_off
) const
8888 if (size
!= 64 || dst_obj
->is_dynamic())
8891 Powerpc_relobj
<size
, big_endian
>* ppc_object
8892 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
8893 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
8895 if (ppc_object
->opd_valid())
8897 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
8898 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
8902 // If we haven't run scan_opd_relocs, we must delay
8903 // processing this function descriptor reference.
8904 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
8909 // Add any special sections for this symbol to the gc work list.
8910 // For powerpc64, this adds the code section of a function
8913 template<int size
, bool big_endian
>
8915 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
8916 Symbol_table
* symtab
,
8921 Powerpc_relobj
<size
, big_endian
>* ppc_object
8922 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
8924 unsigned int shndx
= sym
->shndx(&is_ordinary
);
8925 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
8927 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
8928 Address dst_off
= gsym
->value();
8929 if (ppc_object
->opd_valid())
8931 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8932 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
8936 ppc_object
->add_gc_mark(dst_off
);
8941 // For a symbol location in .opd, set LOC to the location of the
8944 template<int size
, bool big_endian
>
8946 Target_powerpc
<size
, big_endian
>::do_function_location(
8947 Symbol_location
* loc
) const
8949 if (size
== 64 && loc
->shndx
!= 0)
8951 if (loc
->object
->is_dynamic())
8953 Powerpc_dynobj
<size
, big_endian
>* ppc_object
8954 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
8955 if (loc
->shndx
== ppc_object
->opd_shndx())
8958 Address off
= loc
->offset
- ppc_object
->opd_address();
8959 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
8960 loc
->offset
= dest_off
;
8965 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8966 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
8967 if (loc
->shndx
== ppc_object
->opd_shndx())
8970 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
8971 loc
->offset
= dest_off
;
8977 // FNOFFSET in section SHNDX in OBJECT is the start of a function
8978 // compiled with -fsplit-stack. The function calls non-split-stack
8979 // code. Change the function to ensure it has enough stack space to
8980 // call some random function.
8982 template<int size
, bool big_endian
>
8984 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
8987 section_offset_type fnoffset
,
8988 section_size_type fnsize
,
8989 const unsigned char* prelocs
,
8991 unsigned char* view
,
8992 section_size_type view_size
,
8994 std::string
* to
) const
8996 // 32-bit not supported.
9000 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
9001 prelocs
, reloc_count
, view
, view_size
,
9006 // The function always starts with
9007 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
9008 // addis %r12,%r1,-allocate@ha
9009 // addi %r12,%r12,-allocate@l
9011 // but note that the addis or addi may be replaced with a nop
9013 unsigned char *entry
= view
+ fnoffset
;
9014 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9016 if ((insn
& 0xffff0000) == addis_2_12
)
9018 /* Skip ELFv2 global entry code. */
9020 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
9023 unsigned char *pinsn
= entry
;
9025 const uint32_t ld_private_ss
= 0xe80d8fc0;
9026 if (insn
== ld_private_ss
)
9028 int32_t allocate
= 0;
9032 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
9033 if ((insn
& 0xffff0000) == addis_12_1
)
9034 allocate
+= (insn
& 0xffff) << 16;
9035 else if ((insn
& 0xffff0000) == addi_12_1
9036 || (insn
& 0xffff0000) == addi_12_12
)
9037 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
9038 else if (insn
!= nop
)
9041 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
9043 int extra
= parameters
->options().split_stack_adjust_size();
9045 if (allocate
>= 0 || extra
< 0)
9047 object
->error(_("split-stack stack size overflow at "
9048 "section %u offset %0zx"),
9049 shndx
, static_cast<size_t>(fnoffset
));
9053 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
9054 if (insn
!= addis_12_1
)
9056 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9058 insn
= addi_12_12
| (allocate
& 0xffff);
9059 if (insn
!= addi_12_12
)
9061 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9067 insn
= addi_12_1
| (allocate
& 0xffff);
9068 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
9071 if (pinsn
!= entry
+ 12)
9072 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
9080 if (!object
->has_no_split_stack())
9081 object
->error(_("failed to match split-stack sequence at "
9082 "section %u offset %0zx"),
9083 shndx
, static_cast<size_t>(fnoffset
));
9087 // Scan relocations for a section.
9089 template<int size
, bool big_endian
>
9091 Target_powerpc
<size
, big_endian
>::scan_relocs(
9092 Symbol_table
* symtab
,
9094 Sized_relobj_file
<size
, big_endian
>* object
,
9095 unsigned int data_shndx
,
9096 unsigned int sh_type
,
9097 const unsigned char* prelocs
,
9099 Output_section
* output_section
,
9100 bool needs_special_offset_handling
,
9101 size_t local_symbol_count
,
9102 const unsigned char* plocal_symbols
)
9104 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9105 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9108 if (!this->plt_localentry0_init_
)
9110 bool plt_localentry0
= false;
9112 && this->abiversion() >= 2)
9114 if (parameters
->options().user_set_plt_localentry())
9115 plt_localentry0
= parameters
->options().plt_localentry();
9117 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
9118 gold_warning(_("--plt-localentry is especially dangerous without "
9119 "ld.so support to detect ABI violations"));
9121 this->plt_localentry0_
= plt_localentry0
;
9122 this->plt_localentry0_init_
= true;
9125 if (sh_type
== elfcpp::SHT_REL
)
9127 gold_error(_("%s: unsupported REL reloc section"),
9128 object
->name().c_str());
9132 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
9141 needs_special_offset_handling
,
9146 // Functor class for processing the global symbol table.
9147 // Removes symbols defined on discarded opd entries.
9149 template<bool big_endian
>
9150 class Global_symbol_visitor_opd
9153 Global_symbol_visitor_opd()
9157 operator()(Sized_symbol
<64>* sym
)
9159 if (sym
->has_symtab_index()
9160 || sym
->source() != Symbol::FROM_OBJECT
9161 || !sym
->in_real_elf())
9164 if (sym
->object()->is_dynamic())
9167 Powerpc_relobj
<64, big_endian
>* symobj
9168 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
9169 if (symobj
->opd_shndx() == 0)
9173 unsigned int shndx
= sym
->shndx(&is_ordinary
);
9174 if (shndx
== symobj
->opd_shndx()
9175 && symobj
->get_opd_discard(sym
->value()))
9177 sym
->set_undefined();
9178 sym
->set_visibility(elfcpp::STV_DEFAULT
);
9179 sym
->set_is_defined_in_discarded_section();
9180 sym
->set_symtab_index(-1U);
9185 template<int size
, bool big_endian
>
9187 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
9189 Symbol_table
* symtab
)
9193 Output_data_save_res
<size
, big_endian
>* savres
9194 = new Output_data_save_res
<size
, big_endian
>(symtab
);
9195 this->savres_section_
= savres
;
9196 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
9197 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
9198 savres
, ORDER_TEXT
, false);
9202 // Sort linker created .got section first (for the header), then input
9203 // sections belonging to files using small model code.
9205 template<bool big_endian
>
9206 class Sort_toc_sections
9210 operator()(const Output_section::Input_section
& is1
,
9211 const Output_section::Input_section
& is2
) const
9213 if (!is1
.is_input_section() && is2
.is_input_section())
9216 = (is1
.is_input_section()
9217 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
9218 ->has_small_toc_reloc()));
9220 = (is2
.is_input_section()
9221 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
9222 ->has_small_toc_reloc()));
9223 return small1
&& !small2
;
9227 // Finalize the sections.
9229 template<int size
, bool big_endian
>
9231 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
9233 const Input_objects
* input_objects
,
9234 Symbol_table
* symtab
)
9236 if (parameters
->doing_static_link())
9238 // At least some versions of glibc elf-init.o have a strong
9239 // reference to __rela_iplt marker syms. A weak ref would be
9241 if (this->iplt_
!= NULL
)
9243 Reloc_section
* rel
= this->iplt_
->rel_plt();
9244 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
9245 Symbol_table::PREDEFINED
, rel
, 0, 0,
9246 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9247 elfcpp::STV_HIDDEN
, 0, false, true);
9248 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
9249 Symbol_table::PREDEFINED
, rel
, 0, 0,
9250 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9251 elfcpp::STV_HIDDEN
, 0, true, true);
9255 symtab
->define_as_constant("__rela_iplt_start", NULL
,
9256 Symbol_table::PREDEFINED
, 0, 0,
9257 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9258 elfcpp::STV_HIDDEN
, 0, true, false);
9259 symtab
->define_as_constant("__rela_iplt_end", NULL
,
9260 Symbol_table::PREDEFINED
, 0, 0,
9261 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
9262 elfcpp::STV_HIDDEN
, 0, true, false);
9268 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
9269 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
9271 if (!parameters
->options().relocatable())
9273 this->define_save_restore_funcs(layout
, symtab
);
9275 // Annoyingly, we need to make these sections now whether or
9276 // not we need them. If we delay until do_relax then we
9277 // need to mess with the relaxation machinery checkpointing.
9278 this->got_section(symtab
, layout
);
9279 this->make_brlt_section(layout
);
9281 if (parameters
->options().toc_sort())
9283 Output_section
* os
= this->got_
->output_section();
9284 if (os
!= NULL
&& os
->input_sections().size() > 1)
9285 std::stable_sort(os
->input_sections().begin(),
9286 os
->input_sections().end(),
9287 Sort_toc_sections
<big_endian
>());
9292 // Fill in some more dynamic tags.
9293 Output_data_dynamic
* odyn
= layout
->dynamic_data();
9296 const Reloc_section
* rel_plt
= (this->plt_
== NULL
9298 : this->plt_
->rel_plt());
9299 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
9300 this->rela_dyn_
, true, size
== 32);
9304 if (this->got_
!= NULL
)
9306 this->got_
->finalize_data_size();
9307 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
9308 this->got_
, this->got_
->g_o_t());
9310 if (this->has_tls_get_addr_opt_
)
9311 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
9315 if (this->glink_
!= NULL
)
9317 this->glink_
->finalize_data_size();
9318 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9320 (this->glink_
->pltresolve_size()
9323 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9324 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9325 ((this->has_localentry0_
9326 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9327 | (this->has_tls_get_addr_opt_
9328 ? elfcpp::PPC64_OPT_TLS
: 0)));
9332 // Emit any relocs we saved in an attempt to avoid generating COPY
9334 if (this->copy_relocs_
.any_saved_relocs())
9335 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9337 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9338 p
!= input_objects
->relobj_end();
9341 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9342 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9343 if (ppc_relobj
->attributes_section_data())
9344 this->merge_object_attributes(ppc_relobj
->name().c_str(),
9345 ppc_relobj
->attributes_section_data());
9347 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9348 p
!= input_objects
->dynobj_end();
9351 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9352 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9353 if (ppc_dynobj
->attributes_section_data())
9354 this->merge_object_attributes(ppc_dynobj
->name().c_str(),
9355 ppc_dynobj
->attributes_section_data());
9358 // Create a .gnu.attributes section if we have merged any attributes
9360 if (this->attributes_section_data_
!= NULL
9361 && this->attributes_section_data_
->size() != 0)
9363 Output_attributes_section_data
* attributes_section
9364 = new Output_attributes_section_data(*this->attributes_section_data_
);
9365 layout
->add_output_section_data(".gnu.attributes",
9366 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9367 attributes_section
, ORDER_INVALID
, false);
9371 // Merge object attributes from input file called NAME with those of the
9372 // output. The input object attributes are in the object pointed by PASD.
9374 template<int size
, bool big_endian
>
9376 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9378 const Attributes_section_data
* pasd
)
9380 // Return if there is no attributes section data.
9384 // Create output object attributes.
9385 if (this->attributes_section_data_
== NULL
)
9386 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9388 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9389 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9390 Object_attribute
* out_attr
9391 = this->attributes_section_data_
->known_attributes(vendor
);
9396 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9397 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9398 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9399 if (in_fp
!= out_fp
)
9402 if ((in_fp
& 3) == 0)
9404 else if ((out_fp
& 3) == 0)
9406 out_fp
|= in_fp
& 3;
9407 out_attr
[tag
].set_int_value(out_fp
);
9408 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9409 this->last_fp_
= name
;
9411 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9413 err
= N_("%s uses hard float, %s uses soft float");
9414 first
= this->last_fp_
;
9417 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9419 err
= N_("%s uses hard float, %s uses soft float");
9421 second
= this->last_fp_
;
9423 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9425 err
= N_("%s uses double-precision hard float, "
9426 "%s uses single-precision hard float");
9427 first
= this->last_fp_
;
9430 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9432 err
= N_("%s uses double-precision hard float, "
9433 "%s uses single-precision hard float");
9435 second
= this->last_fp_
;
9438 if (err
|| (in_fp
& 0xc) == 0)
9440 else if ((out_fp
& 0xc) == 0)
9442 out_fp
|= in_fp
& 0xc;
9443 out_attr
[tag
].set_int_value(out_fp
);
9444 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9445 this->last_ld_
= name
;
9447 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9449 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9451 second
= this->last_ld_
;
9453 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9455 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9456 first
= this->last_ld_
;
9459 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9461 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9462 first
= this->last_ld_
;
9465 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9467 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9469 second
= this->last_ld_
;
9474 if (parameters
->options().warn_mismatch())
9475 gold_error(_(err
), first
, second
);
9476 // Arrange for this attribute to be deleted. It's better to
9477 // say "don't know" about a file than to wrongly claim compliance.
9478 out_attr
[tag
].set_type(0);
9484 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9485 int in_vec
= in_attr
[tag
].int_value() & 3;
9486 int out_vec
= out_attr
[tag
].int_value() & 3;
9487 if (in_vec
!= out_vec
)
9492 else if (out_vec
== 0)
9495 out_attr
[tag
].set_int_value(out_vec
);
9496 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9497 this->last_vec_
= name
;
9499 // For now, allow generic to transition to AltiVec or SPE
9500 // without a warning. If GCC marked files with their stack
9501 // alignment and used don't-care markings for files which are
9502 // not affected by the vector ABI, we could warn about this
9504 else if (in_vec
== 1)
9506 else if (out_vec
== 1)
9509 out_attr
[tag
].set_int_value(out_vec
);
9510 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9511 this->last_vec_
= name
;
9513 else if (out_vec
< in_vec
)
9515 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9516 first
= this->last_vec_
;
9519 else if (out_vec
> in_vec
)
9521 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9523 second
= this->last_vec_
;
9527 if (parameters
->options().warn_mismatch())
9528 gold_error(_(err
), first
, second
);
9529 out_attr
[tag
].set_type(0);
9533 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9534 int in_struct
= in_attr
[tag
].int_value() & 3;
9535 int out_struct
= out_attr
[tag
].int_value() & 3;
9536 if (in_struct
!= out_struct
)
9539 if (in_struct
== 0 || in_struct
== 3)
9541 else if (out_struct
== 0)
9543 out_struct
= in_struct
;
9544 out_attr
[tag
].set_int_value(out_struct
);
9545 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9546 this->last_struct_
= name
;
9548 else if (out_struct
< in_struct
)
9550 err
= N_("%s uses r3/r4 for small structure returns, "
9552 first
= this->last_struct_
;
9555 else if (out_struct
> in_struct
)
9557 err
= N_("%s uses r3/r4 for small structure returns, "
9560 second
= this->last_struct_
;
9564 if (parameters
->options().warn_mismatch())
9565 gold_error(_(err
), first
, second
);
9566 out_attr
[tag
].set_type(0);
9571 // Merge Tag_compatibility attributes and any common GNU ones.
9572 this->attributes_section_data_
->merge(name
, pasd
);
9575 // Emit any saved relocs, and mark toc entries using any of these
9576 // relocs as not optimizable.
9578 template<int sh_type
, int size
, bool big_endian
>
9580 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
9581 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
9584 && parameters
->options().toc_optimize())
9586 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
9587 Copy_reloc_entries::iterator p
= this->entries_
.begin();
9588 p
!= this->entries_
.end();
9591 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
9594 // If the symbol is no longer defined in a dynamic object,
9595 // then we emitted a COPY relocation. If it is still
9596 // dynamic then we'll need dynamic relocations and thus
9597 // can't optimize toc entries.
9598 if (entry
.sym_
->is_from_dynobj())
9600 Powerpc_relobj
<size
, big_endian
>* ppc_object
9601 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
9602 if (entry
.shndx_
== ppc_object
->toc_shndx())
9603 ppc_object
->set_no_toc_opt(entry
.address_
);
9608 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
9611 // Return the value to use for a branch relocation.
9613 template<int size
, bool big_endian
>
9615 Target_powerpc
<size
, big_endian
>::symval_for_branch(
9616 const Symbol_table
* symtab
,
9617 const Sized_symbol
<size
>* gsym
,
9618 Powerpc_relobj
<size
, big_endian
>* object
,
9620 unsigned int *dest_shndx
)
9622 if (size
== 32 || this->abiversion() >= 2)
9626 // If the symbol is defined in an opd section, ie. is a function
9627 // descriptor, use the function descriptor code entry address
9628 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
9630 && (gsym
->source() != Symbol::FROM_OBJECT
9631 || gsym
->object()->is_dynamic()))
9634 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9635 unsigned int shndx
= symobj
->opd_shndx();
9638 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
9639 if (opd_addr
== invalid_address
)
9641 opd_addr
+= symobj
->output_section_address(shndx
);
9642 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
9645 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
9646 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
9649 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
9650 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
9651 *dest_shndx
= folded
.second
;
9653 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
9654 if (sec_addr
== invalid_address
)
9657 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
9658 *value
= sec_addr
+ sec_off
;
9663 // Perform a relocation.
9665 template<int size
, bool big_endian
>
9667 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
9668 const Relocate_info
<size
, big_endian
>* relinfo
,
9670 Target_powerpc
* target
,
9673 const unsigned char* preloc
,
9674 const Sized_symbol
<size
>* gsym
,
9675 const Symbol_value
<size
>* psymval
,
9676 unsigned char* view
,
9678 section_size_type view_size
)
9680 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
9681 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
9682 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9687 if (target
->replace_tls_get_addr(gsym
))
9688 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
9690 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
9691 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
9692 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
9694 case Track_tls::NOT_EXPECTED
:
9695 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9696 _("__tls_get_addr call lacks marker reloc"));
9698 case Track_tls::EXPECTED
:
9699 // We have already complained.
9701 case Track_tls::SKIP
:
9702 if (is_plt16_reloc
<size
>(r_type
)
9703 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9704 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
9706 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9707 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9709 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
9711 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9712 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
9714 else if (size
== 64 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
9715 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9717 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9718 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
9719 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
9722 case Track_tls::NORMAL
:
9726 // Offset from start of insn to d-field reloc.
9727 const int d_offset
= big_endian
? 2 : 0;
9729 Powerpc_relobj
<size
, big_endian
>* const object
9730 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
9732 bool has_stub_value
= false;
9733 bool localentry0
= false;
9734 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
9737 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
9738 : object
->local_has_plt_offset(r_sym
));
9740 && !is_plt16_reloc
<size
>(r_type
)
9741 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34
9742 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
9743 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
9744 && r_type
!= elfcpp::R_POWERPC_PLTCALL
9745 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
9746 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
9747 && (!psymval
->is_ifunc_symbol()
9748 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
9752 && target
->abiversion() >= 2
9753 && !parameters
->options().output_is_position_independent()
9754 && !is_branch_reloc
<size
>(r_type
))
9756 Address off
= target
->glink_section()->find_global_entry(gsym
);
9757 if (off
!= invalid_address
)
9759 value
= target
->glink_section()->global_entry_address() + off
;
9760 has_stub_value
= true;
9765 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
9766 if (target
->stub_tables().size() == 1)
9767 stub_table
= target
->stub_tables()[0];
9768 if (stub_table
== NULL
9771 && !parameters
->options().output_is_position_independent()
9772 && !is_branch_reloc
<size
>(r_type
)))
9773 stub_table
= object
->stub_table(relinfo
->data_shndx
);
9774 if (stub_table
== NULL
)
9776 // This is a ref from a data section to an ifunc symbol,
9777 // or a non-branch reloc for which we always want to use
9778 // one set of stubs for resolving function addresses.
9779 if (target
->stub_tables().size() != 0)
9780 stub_table
= target
->stub_tables()[0];
9782 if (stub_table
!= NULL
)
9784 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
9786 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
9787 rela
.get_r_addend());
9789 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
9790 rela
.get_r_addend());
9793 value
= stub_table
->stub_address() + ent
->off_
;
9794 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9795 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
9796 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
9799 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
9803 && relnum
< reloc_count
- 1)
9805 Reltype
next_rela(preloc
+ reloc_size
);
9806 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
9807 == elfcpp::R_PPC64_TOCSAVE
9808 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
9811 localentry0
= ent
->localentry0_
;
9812 has_stub_value
= true;
9816 // We don't care too much about bogus debug references to
9817 // non-local functions, but otherwise there had better be a plt
9818 // call stub or global entry stub as appropriate.
9819 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
9822 if (has_plt_offset
&& (is_plt16_reloc
<size
>(r_type
)
9823 || r_type
== elfcpp::R_PPC64_PLT_PCREL34
9824 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9826 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
9828 value
= target
->plt_off(gsym
, &plt
);
9830 value
= target
->plt_off(object
, r_sym
, &plt
);
9831 value
+= plt
->address();
9835 if (r_type
!= elfcpp::R_PPC64_PLT_PCREL34
9836 && r_type
!= elfcpp::R_PPC64_PLT_PCREL34_NOTOC
)
9837 value
-= (target
->got_section()->output_section()->address()
9838 + object
->toc_base_offset());
9840 else if (parameters
->options().output_is_position_independent())
9842 if (rela
.get_r_addend() >= 32768)
9844 unsigned int got2
= object
->got2_shndx();
9845 value
-= (object
->get_output_section_offset(got2
)
9846 + object
->output_section(got2
)->address()
9847 + rela
.get_r_addend());
9850 value
-= (target
->got_section()->address()
9851 + target
->got_section()->g_o_t());
9854 else if (!has_plt_offset
9855 && (is_plt16_reloc
<size
>(r_type
)
9856 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9857 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
9859 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9860 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9861 r_type
= elfcpp::R_POWERPC_NONE
;
9863 else if (!has_plt_offset
9864 && (r_type
== elfcpp::R_PPC64_PLT_PCREL34
9865 || r_type
== elfcpp::R_PPC64_PLT_PCREL34_NOTOC
))
9867 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9868 elfcpp::Swap
<32, big_endian
>::writeval(iview
, pnop
>> 32);
9869 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, pnop
& 0xffffffff);
9870 r_type
= elfcpp::R_POWERPC_NONE
;
9872 else if (r_type
== elfcpp::R_POWERPC_GOT16
9873 || r_type
== elfcpp::R_POWERPC_GOT16_LO
9874 || r_type
== elfcpp::R_POWERPC_GOT16_HI
9875 || r_type
== elfcpp::R_POWERPC_GOT16_HA
9876 || r_type
== elfcpp::R_PPC64_GOT16_DS
9877 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
9878 || r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
9882 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
9883 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
9887 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
9888 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
9890 if (r_type
== elfcpp::R_PPC64_GOT_PCREL34
)
9891 value
+= target
->got_section()->address();
9893 value
-= target
->got_section()->got_base_offset(object
);
9895 else if (r_type
== elfcpp::R_PPC64_TOC
)
9897 value
= (target
->got_section()->output_section()->address()
9898 + object
->toc_base_offset());
9900 else if (gsym
!= NULL
9901 && (r_type
== elfcpp::R_POWERPC_REL24
9902 || r_type
== elfcpp::R_PPC_PLTREL24
)
9907 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
9908 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
9909 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
9910 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
9912 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
9913 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
9916 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
9918 elfcpp::Swap
<32, big_endian
>::
9919 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
9920 can_plt_call
= true;
9925 // If we don't have a branch and link followed by a nop,
9926 // we can't go via the plt because there is no place to
9927 // put a toc restoring instruction.
9928 // Unless we know we won't be returning.
9929 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
9930 can_plt_call
= true;
9934 // g++ as of 20130507 emits self-calls without a
9935 // following nop. This is arguably wrong since we have
9936 // conflicting information. On the one hand a global
9937 // symbol and on the other a local call sequence, but
9938 // don't error for this special case.
9939 // It isn't possible to cheaply verify we have exactly
9940 // such a call. Allow all calls to the same section.
9942 Address code
= value
;
9943 if (gsym
->source() == Symbol::FROM_OBJECT
9944 && gsym
->object() == object
)
9946 unsigned int dest_shndx
= 0;
9947 if (target
->abiversion() < 2)
9949 Address addend
= rela
.get_r_addend();
9950 code
= psymval
->value(object
, addend
);
9951 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
9952 &code
, &dest_shndx
);
9955 if (dest_shndx
== 0)
9956 dest_shndx
= gsym
->shndx(&is_ordinary
);
9957 ok
= dest_shndx
== relinfo
->data_shndx
;
9961 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9962 _("call lacks nop, can't restore toc; "
9963 "recompile with -fPIC"));
9969 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
9970 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
9971 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
9972 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
9974 // First instruction of a global dynamic sequence, arg setup insn.
9975 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
9976 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9977 enum Got_type got_type
= GOT_TYPE_STANDARD
;
9978 if (tls_type
== tls::TLSOPT_NONE
)
9979 got_type
= GOT_TYPE_TLSGD
;
9980 else if (tls_type
== tls::TLSOPT_TO_IE
)
9981 got_type
= GOT_TYPE_TPREL
;
9982 if (got_type
!= GOT_TYPE_STANDARD
)
9986 gold_assert(gsym
->has_got_offset(got_type
));
9987 value
= gsym
->got_offset(got_type
);
9991 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
9992 value
= object
->local_got_offset(r_sym
, got_type
);
9994 value
-= target
->got_section()->got_base_offset(object
);
9996 if (tls_type
== tls::TLSOPT_TO_IE
)
9998 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
9999 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10001 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10002 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10003 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
10005 insn
|= 32 << 26; // lwz
10007 insn
|= 58 << 26; // ld
10008 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10010 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10011 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10013 else if (tls_type
== tls::TLSOPT_TO_LE
)
10015 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10016 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10018 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10019 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10020 insn
&= (1 << 26) - (1 << 21); // extract rt
10024 insn
|= addis_0_13
;
10025 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10026 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10027 value
= psymval
->value(object
, rela
.get_r_addend());
10031 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10033 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10034 r_type
= elfcpp::R_POWERPC_NONE
;
10038 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10039 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10040 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10041 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
10043 // First instruction of a local dynamic sequence, arg setup insn.
10044 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10045 if (tls_type
== tls::TLSOPT_NONE
)
10047 value
= target
->tlsld_got_offset();
10048 value
-= target
->got_section()->got_base_offset(object
);
10052 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10053 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10054 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10056 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10057 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10058 insn
&= (1 << 26) - (1 << 21); // extract rt
10062 insn
|= addis_0_13
;
10063 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10064 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10065 value
= dtp_offset
;
10069 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10071 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10072 r_type
= elfcpp::R_POWERPC_NONE
;
10076 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
10077 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
10078 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
10079 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
10081 // Accesses relative to a local dynamic sequence address,
10082 // no optimisation here.
10085 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
10086 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
10090 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
10091 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
10093 value
-= target
->got_section()->got_base_offset(object
);
10095 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10096 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10097 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10098 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
10100 // First instruction of initial exec sequence.
10101 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10102 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10103 if (tls_type
== tls::TLSOPT_NONE
)
10107 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
10108 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
10112 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
10113 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
10115 value
-= target
->got_section()->got_base_offset(object
);
10119 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
10120 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10121 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10123 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10124 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10125 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
10129 insn
|= addis_0_13
;
10130 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10131 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10132 value
= psymval
->value(object
, rela
.get_r_addend());
10136 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10138 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10139 r_type
= elfcpp::R_POWERPC_NONE
;
10143 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10144 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10146 // Second instruction of a global dynamic sequence,
10147 // the __tls_get_addr call
10148 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10149 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10150 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
10151 if (tls_type
!= tls::TLSOPT_NONE
)
10153 if (tls_type
== tls::TLSOPT_TO_IE
)
10155 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10156 Insn insn
= add_3_3_13
;
10159 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10160 r_type
= elfcpp::R_POWERPC_NONE
;
10164 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10165 Insn insn
= addi_3_3
;
10166 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10167 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10169 value
= psymval
->value(object
, rela
.get_r_addend());
10171 this->skip_next_tls_get_addr_call();
10174 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10175 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10177 // Second instruction of a local dynamic sequence,
10178 // the __tls_get_addr call
10179 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
10180 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
10181 if (tls_type
== tls::TLSOPT_TO_LE
)
10183 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10184 Insn insn
= addi_3_3
;
10185 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10186 this->skip_next_tls_get_addr_call();
10187 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10189 value
= dtp_offset
;
10192 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10194 // Second instruction of an initial exec sequence
10195 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10196 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
10197 if (tls_type
== tls::TLSOPT_TO_LE
)
10199 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10200 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10201 unsigned int reg
= size
== 32 ? 2 : 13;
10202 insn
= at_tls_transform(insn
, reg
);
10203 gold_assert(insn
!= 0);
10204 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10205 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10207 value
= psymval
->value(object
, rela
.get_r_addend());
10210 else if (!has_stub_value
)
10212 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
10213 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
10215 // PLTCALL without plt entry => convert to direct call
10216 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10217 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10218 insn
= (insn
& 1) | b
;
10219 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10221 r_type
= elfcpp::R_PPC_PLTREL24
;
10222 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
10223 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
10225 r_type
= elfcpp::R_POWERPC_REL24
;
10227 Address addend
= 0;
10229 && (r_type
== elfcpp::R_PPC_PLTREL24
10230 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10231 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10232 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
10233 addend
= rela
.get_r_addend();
10234 value
= psymval
->value(object
, addend
);
10235 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
10237 if (target
->abiversion() >= 2)
10240 value
+= object
->ppc64_local_entry_offset(gsym
);
10242 value
+= object
->ppc64_local_entry_offset(r_sym
);
10246 unsigned int dest_shndx
;
10247 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
10248 &value
, &dest_shndx
);
10251 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
10252 if (max_branch_offset
!= 0
10253 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
10255 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
10257 ? object
->ppc64_needs_toc(gsym
)
10258 : object
->ppc64_needs_toc(r_sym
)))))
10260 Stub_table
<size
, big_endian
>* stub_table
10261 = object
->stub_table(relinfo
->data_shndx
);
10262 if (stub_table
!= NULL
)
10264 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
10265 = stub_table
->find_long_branch_entry(object
, value
);
10268 if (ent
->save_res_
)
10269 value
= (value
- target
->savres_section()->address()
10270 + stub_table
->branch_size());
10272 value
= (stub_table
->stub_address() + stub_table
->plt_size()
10274 has_stub_value
= true;
10282 case elfcpp::R_PPC64_REL24_NOTOC
:
10286 case elfcpp::R_PPC64_REL64
:
10287 case elfcpp::R_POWERPC_REL32
:
10288 case elfcpp::R_POWERPC_REL24
:
10289 case elfcpp::R_PPC_PLTREL24
:
10290 case elfcpp::R_PPC_LOCAL24PC
:
10291 case elfcpp::R_POWERPC_REL16
:
10292 case elfcpp::R_POWERPC_REL16_LO
:
10293 case elfcpp::R_POWERPC_REL16_HI
:
10294 case elfcpp::R_POWERPC_REL16_HA
:
10295 case elfcpp::R_POWERPC_REL16DX_HA
:
10296 case elfcpp::R_PPC64_REL16_HIGH
:
10297 case elfcpp::R_PPC64_REL16_HIGHA
:
10298 case elfcpp::R_PPC64_REL16_HIGHER
:
10299 case elfcpp::R_PPC64_REL16_HIGHERA
:
10300 case elfcpp::R_PPC64_REL16_HIGHEST
:
10301 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10302 case elfcpp::R_POWERPC_REL14
:
10303 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10304 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10305 case elfcpp::R_PPC64_PCREL34
:
10306 case elfcpp::R_PPC64_GOT_PCREL34
:
10307 case elfcpp::R_PPC64_PLT_PCREL34
:
10308 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
10309 case elfcpp::R_PPC64_PCREL28
:
10310 case elfcpp::R_PPC64_REL16_HIGHER34
:
10311 case elfcpp::R_PPC64_REL16_HIGHERA34
:
10312 case elfcpp::R_PPC64_REL16_HIGHEST34
:
10313 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
10317 case elfcpp::R_PPC64_TOC16
:
10318 case elfcpp::R_PPC64_TOC16_LO
:
10319 case elfcpp::R_PPC64_TOC16_HI
:
10320 case elfcpp::R_PPC64_TOC16_HA
:
10321 case elfcpp::R_PPC64_TOC16_DS
:
10322 case elfcpp::R_PPC64_TOC16_LO_DS
:
10323 // Subtract the TOC base address.
10324 value
-= (target
->got_section()->output_section()->address()
10325 + object
->toc_base_offset());
10328 case elfcpp::R_POWERPC_SECTOFF
:
10329 case elfcpp::R_POWERPC_SECTOFF_LO
:
10330 case elfcpp::R_POWERPC_SECTOFF_HI
:
10331 case elfcpp::R_POWERPC_SECTOFF_HA
:
10332 case elfcpp::R_PPC64_SECTOFF_DS
:
10333 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
10335 value
-= os
->address();
10338 case elfcpp::R_PPC64_TPREL16_DS
:
10339 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10340 case elfcpp::R_PPC64_TPREL16_HIGH
:
10341 case elfcpp::R_PPC64_TPREL16_HIGHA
:
10343 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
10346 case elfcpp::R_POWERPC_TPREL16
:
10347 case elfcpp::R_POWERPC_TPREL16_LO
:
10348 case elfcpp::R_POWERPC_TPREL16_HI
:
10349 case elfcpp::R_POWERPC_TPREL16_HA
:
10350 case elfcpp::R_POWERPC_TPREL
:
10351 case elfcpp::R_PPC64_TPREL16_HIGHER
:
10352 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
10353 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10354 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10355 // tls symbol values are relative to tls_segment()->vaddr()
10356 value
-= tp_offset
;
10359 case elfcpp::R_PPC64_DTPREL16_DS
:
10360 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10361 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10362 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10363 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10364 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10366 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
10367 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
10370 case elfcpp::R_POWERPC_DTPREL16
:
10371 case elfcpp::R_POWERPC_DTPREL16_LO
:
10372 case elfcpp::R_POWERPC_DTPREL16_HI
:
10373 case elfcpp::R_POWERPC_DTPREL16_HA
:
10374 case elfcpp::R_POWERPC_DTPREL
:
10375 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10376 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10377 // tls symbol values are relative to tls_segment()->vaddr()
10378 value
-= dtp_offset
;
10381 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10383 value
+= object
->ppc64_local_entry_offset(gsym
);
10385 value
+= object
->ppc64_local_entry_offset(r_sym
);
10392 Insn branch_bit
= 0;
10395 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10396 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10397 branch_bit
= 1 << 21;
10399 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10400 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10402 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10403 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10404 insn
&= ~(1 << 21);
10405 insn
|= branch_bit
;
10406 if (this->is_isa_v2
)
10408 // Set 'a' bit. This is 0b00010 in BO field for branch
10409 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
10410 // for branch on CTR insns (BO == 1a00t or 1a01t).
10411 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10412 insn
|= 0x02 << 21;
10413 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10414 insn
|= 0x08 << 21;
10420 // Invert 'y' bit if not the default.
10421 if (static_cast<Signed_address
>(value
) < 0)
10424 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10428 case elfcpp::R_POWERPC_PLT16_HA
:
10430 && !parameters
->options().output_is_position_independent())
10432 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10433 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10435 // Convert addis to lis.
10436 if ((insn
& (0x3f << 26)) == 15u << 26
10437 && (insn
& (0x1f << 16)) != 0)
10439 insn
&= ~(0x1f << 16);
10440 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10456 // Multi-instruction sequences that access the GOT/TOC can
10457 // be optimized, eg.
10458 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
10459 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
10461 // addis ra,r2,0; addi rb,ra,x@toc@l;
10462 // to nop; addi rb,r2,x@toc;
10463 // FIXME: the @got sequence shown above is not yet
10464 // optimized. Note that gcc as of 2017-01-07 doesn't use
10465 // the ELF @got relocs except for TLS, instead using the
10466 // PowerOpen variant of a compiler managed GOT (called TOC).
10467 // The PowerOpen TOC sequence equivalent to the first
10468 // example is optimized.
10469 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10470 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10471 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10472 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10473 case elfcpp::R_POWERPC_GOT16_HA
:
10474 case elfcpp::R_PPC64_TOC16_HA
:
10475 if (parameters
->options().toc_optimize())
10477 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10478 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10479 if (r_type
== elfcpp::R_PPC64_TOC16_HA
10480 && object
->make_toc_relative(target
, &value
))
10482 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
10483 == ((15u << 26) | (2 << 16)));
10485 if (((insn
& ((0x3f << 26) | 0x1f << 16))
10486 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
10487 && value
+ 0x8000 < 0x10000)
10489 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10495 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10496 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10497 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10498 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10499 case elfcpp::R_POWERPC_GOT16_LO
:
10500 case elfcpp::R_PPC64_GOT16_LO_DS
:
10501 case elfcpp::R_PPC64_TOC16_LO
:
10502 case elfcpp::R_PPC64_TOC16_LO_DS
:
10503 if (parameters
->options().toc_optimize())
10505 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10506 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10507 bool changed
= false;
10508 if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
10509 && object
->make_toc_relative(target
, &value
))
10511 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
10512 insn
^= (14u << 26) ^ (58u << 26);
10513 r_type
= elfcpp::R_PPC64_TOC16_LO
;
10516 if (ok_lo_toc_insn(insn
, r_type
)
10517 && value
+ 0x8000 < 0x10000)
10519 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
10521 // Transform addic to addi when we change reg.
10522 insn
&= ~((0x3f << 26) | (0x1f << 16));
10523 insn
|= (14u << 26) | (2 << 16);
10527 insn
&= ~(0x1f << 16);
10533 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10537 case elfcpp::R_POWERPC_TPREL16_HA
:
10538 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10540 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10541 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10542 if ((insn
& ((0x3f << 26) | 0x1f << 16))
10543 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
10547 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10553 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10555 // R_PPC_TLSGD, R_PPC_TLSLD
10558 case elfcpp::R_POWERPC_TPREL16_LO
:
10559 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10561 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10562 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10563 insn
&= ~(0x1f << 16);
10564 insn
|= (size
== 32 ? 2 : 13) << 16;
10565 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10569 case elfcpp::R_PPC64_ENTRY
:
10570 value
= (target
->got_section()->output_section()->address()
10571 + object
->toc_base_offset());
10572 if (value
+ 0x80008000 <= 0xffffffff
10573 && !parameters
->options().output_is_position_independent())
10575 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10576 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10577 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10579 if ((insn1
& ~0xfffc) == ld_2_12
10580 && insn2
== add_2_2_12
)
10582 insn1
= lis_2
+ ha(value
);
10583 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10584 insn2
= addi_2_2
+ l(value
);
10585 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10592 if (value
+ 0x80008000 <= 0xffffffff)
10594 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10595 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10596 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10598 if ((insn1
& ~0xfffc) == ld_2_12
10599 && insn2
== add_2_2_12
)
10601 insn1
= addis_2_12
+ ha(value
);
10602 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10603 insn2
= addi_2_2
+ l(value
);
10604 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10611 case elfcpp::R_POWERPC_REL16_LO
:
10612 // If we are generating a non-PIC executable, edit
10613 // 0: addis 2,12,.TOC.-0b@ha
10614 // addi 2,2,.TOC.-0b@l
10615 // used by ELFv2 global entry points to set up r2, to
10617 // addi 2,2,.TOC.@l
10618 // if .TOC. is in range. */
10619 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
10622 && target
->abiversion() >= 2
10623 && !parameters
->options().output_is_position_independent()
10624 && rela
.get_r_addend() == d_offset
+ 4
10626 && strcmp(gsym
->name(), ".TOC.") == 0)
10628 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10629 Reltype
prev_rela(preloc
- reloc_size
);
10630 if ((prev_rela
.get_r_info()
10631 == elfcpp::elf_r_info
<size
>(r_sym
,
10632 elfcpp::R_POWERPC_REL16_HA
))
10633 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
10634 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
10636 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10637 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
10638 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10640 if ((insn1
& 0xffff0000) == addis_2_12
10641 && (insn2
& 0xffff0000) == addi_2_2
)
10643 insn1
= lis_2
+ ha(value
+ address
- 4);
10644 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
10645 insn2
= addi_2_2
+ l(value
+ address
- 4);
10646 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
10649 relinfo
->rr
->set_strategy(relnum
- 1,
10650 Relocatable_relocs::RELOC_SPECIAL
);
10651 relinfo
->rr
->set_strategy(relnum
,
10652 Relocatable_relocs::RELOC_SPECIAL
);
10662 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
10663 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
10666 case elfcpp::R_POWERPC_ADDR32
:
10667 case elfcpp::R_POWERPC_UADDR32
:
10669 overflow
= Reloc::CHECK_BITFIELD
;
10672 case elfcpp::R_POWERPC_REL32
:
10673 case elfcpp::R_POWERPC_REL16DX_HA
:
10675 overflow
= Reloc::CHECK_SIGNED
;
10678 case elfcpp::R_POWERPC_UADDR16
:
10679 overflow
= Reloc::CHECK_BITFIELD
;
10682 case elfcpp::R_POWERPC_ADDR16
:
10683 // We really should have three separate relocations,
10684 // one for 16-bit data, one for insns with 16-bit signed fields,
10685 // and one for insns with 16-bit unsigned fields.
10686 overflow
= Reloc::CHECK_BITFIELD
;
10687 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
10688 overflow
= Reloc::CHECK_LOW_INSN
;
10691 case elfcpp::R_POWERPC_ADDR16_HI
:
10692 case elfcpp::R_POWERPC_ADDR16_HA
:
10693 case elfcpp::R_POWERPC_GOT16_HI
:
10694 case elfcpp::R_POWERPC_GOT16_HA
:
10695 case elfcpp::R_POWERPC_PLT16_HI
:
10696 case elfcpp::R_POWERPC_PLT16_HA
:
10697 case elfcpp::R_POWERPC_SECTOFF_HI
:
10698 case elfcpp::R_POWERPC_SECTOFF_HA
:
10699 case elfcpp::R_PPC64_TOC16_HI
:
10700 case elfcpp::R_PPC64_TOC16_HA
:
10701 case elfcpp::R_PPC64_PLTGOT16_HI
:
10702 case elfcpp::R_PPC64_PLTGOT16_HA
:
10703 case elfcpp::R_POWERPC_TPREL16_HI
:
10704 case elfcpp::R_POWERPC_TPREL16_HA
:
10705 case elfcpp::R_POWERPC_DTPREL16_HI
:
10706 case elfcpp::R_POWERPC_DTPREL16_HA
:
10707 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
10708 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10709 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
10710 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10711 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
10712 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10713 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
10714 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10715 case elfcpp::R_POWERPC_REL16_HI
:
10716 case elfcpp::R_POWERPC_REL16_HA
:
10718 overflow
= Reloc::CHECK_HIGH_INSN
;
10721 case elfcpp::R_POWERPC_REL16
:
10722 case elfcpp::R_PPC64_TOC16
:
10723 case elfcpp::R_POWERPC_GOT16
:
10724 case elfcpp::R_POWERPC_SECTOFF
:
10725 case elfcpp::R_POWERPC_TPREL16
:
10726 case elfcpp::R_POWERPC_DTPREL16
:
10727 case elfcpp::R_POWERPC_GOT_TLSGD16
:
10728 case elfcpp::R_POWERPC_GOT_TLSLD16
:
10729 case elfcpp::R_POWERPC_GOT_TPREL16
:
10730 case elfcpp::R_POWERPC_GOT_DTPREL16
:
10731 overflow
= Reloc::CHECK_LOW_INSN
;
10734 case elfcpp::R_PPC64_REL24_NOTOC
:
10738 case elfcpp::R_POWERPC_ADDR24
:
10739 case elfcpp::R_POWERPC_ADDR14
:
10740 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10741 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10742 case elfcpp::R_PPC64_ADDR16_DS
:
10743 case elfcpp::R_POWERPC_REL24
:
10744 case elfcpp::R_PPC_PLTREL24
:
10745 case elfcpp::R_PPC_LOCAL24PC
:
10746 case elfcpp::R_PPC64_TPREL16_DS
:
10747 case elfcpp::R_PPC64_DTPREL16_DS
:
10748 case elfcpp::R_PPC64_TOC16_DS
:
10749 case elfcpp::R_PPC64_GOT16_DS
:
10750 case elfcpp::R_PPC64_SECTOFF_DS
:
10751 case elfcpp::R_POWERPC_REL14
:
10752 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10753 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10754 case elfcpp::R_PPC64_D34
:
10755 case elfcpp::R_PPC64_PCREL34
:
10756 case elfcpp::R_PPC64_GOT_PCREL34
:
10757 case elfcpp::R_PPC64_PLT_PCREL34
:
10758 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
10759 case elfcpp::R_PPC64_D28
:
10760 case elfcpp::R_PPC64_PCREL28
:
10761 overflow
= Reloc::CHECK_SIGNED
;
10765 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10768 if (overflow
== Reloc::CHECK_LOW_INSN
10769 || overflow
== Reloc::CHECK_HIGH_INSN
)
10771 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10773 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
10774 overflow
= Reloc::CHECK_BITFIELD
;
10775 else if (overflow
== Reloc::CHECK_LOW_INSN
10776 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
10777 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
10778 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
10779 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
10780 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
10781 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
10782 overflow
= Reloc::CHECK_UNSIGNED
;
10784 overflow
= Reloc::CHECK_SIGNED
;
10787 bool maybe_dq_reloc
= false;
10788 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
10789 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
10792 case elfcpp::R_POWERPC_NONE
:
10793 case elfcpp::R_POWERPC_TLS
:
10794 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
10795 case elfcpp::R_POWERPC_GNU_VTENTRY
:
10796 case elfcpp::R_POWERPC_PLTSEQ
:
10797 case elfcpp::R_POWERPC_PLTCALL
:
10798 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
10799 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
10800 case elfcpp::R_PPC64_PCREL_OPT
:
10803 case elfcpp::R_PPC64_ADDR64
:
10804 case elfcpp::R_PPC64_REL64
:
10805 case elfcpp::R_PPC64_TOC
:
10806 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10807 Reloc::addr64(view
, value
);
10810 case elfcpp::R_POWERPC_TPREL
:
10811 case elfcpp::R_POWERPC_DTPREL
:
10813 Reloc::addr64(view
, value
);
10815 status
= Reloc::addr32(view
, value
, overflow
);
10818 case elfcpp::R_PPC64_UADDR64
:
10819 Reloc::addr64_u(view
, value
);
10822 case elfcpp::R_POWERPC_ADDR32
:
10823 status
= Reloc::addr32(view
, value
, overflow
);
10826 case elfcpp::R_POWERPC_REL32
:
10827 case elfcpp::R_POWERPC_UADDR32
:
10828 status
= Reloc::addr32_u(view
, value
, overflow
);
10831 case elfcpp::R_PPC64_REL24_NOTOC
:
10833 goto unsupp
; // R_PPC_EMB_RELSDA
10835 case elfcpp::R_POWERPC_ADDR24
:
10836 case elfcpp::R_POWERPC_REL24
:
10837 case elfcpp::R_PPC_PLTREL24
:
10838 case elfcpp::R_PPC_LOCAL24PC
:
10839 status
= Reloc::addr24(view
, value
, overflow
);
10842 case elfcpp::R_POWERPC_GOT_DTPREL16
:
10843 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10844 case elfcpp::R_POWERPC_GOT_TPREL16
:
10845 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10848 // On ppc64 these are all ds form
10849 maybe_dq_reloc
= true;
10853 case elfcpp::R_POWERPC_ADDR16
:
10854 case elfcpp::R_POWERPC_REL16
:
10855 case elfcpp::R_PPC64_TOC16
:
10856 case elfcpp::R_POWERPC_GOT16
:
10857 case elfcpp::R_POWERPC_SECTOFF
:
10858 case elfcpp::R_POWERPC_TPREL16
:
10859 case elfcpp::R_POWERPC_DTPREL16
:
10860 case elfcpp::R_POWERPC_GOT_TLSGD16
:
10861 case elfcpp::R_POWERPC_GOT_TLSLD16
:
10862 case elfcpp::R_POWERPC_ADDR16_LO
:
10863 case elfcpp::R_POWERPC_REL16_LO
:
10864 case elfcpp::R_PPC64_TOC16_LO
:
10865 case elfcpp::R_POWERPC_GOT16_LO
:
10866 case elfcpp::R_POWERPC_PLT16_LO
:
10867 case elfcpp::R_POWERPC_SECTOFF_LO
:
10868 case elfcpp::R_POWERPC_TPREL16_LO
:
10869 case elfcpp::R_POWERPC_DTPREL16_LO
:
10870 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10871 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10873 status
= Reloc::addr16(view
, value
, overflow
);
10875 maybe_dq_reloc
= true;
10878 case elfcpp::R_POWERPC_UADDR16
:
10879 status
= Reloc::addr16_u(view
, value
, overflow
);
10882 case elfcpp::R_PPC64_ADDR16_HIGH
:
10883 case elfcpp::R_PPC64_TPREL16_HIGH
:
10884 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10886 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
10889 case elfcpp::R_POWERPC_ADDR16_HI
:
10890 case elfcpp::R_POWERPC_REL16_HI
:
10891 case elfcpp::R_PPC64_REL16_HIGH
:
10892 case elfcpp::R_PPC64_TOC16_HI
:
10893 case elfcpp::R_POWERPC_GOT16_HI
:
10894 case elfcpp::R_POWERPC_PLT16_HI
:
10895 case elfcpp::R_POWERPC_SECTOFF_HI
:
10896 case elfcpp::R_POWERPC_TPREL16_HI
:
10897 case elfcpp::R_POWERPC_DTPREL16_HI
:
10898 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
10899 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
10900 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
10901 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
10902 Reloc::addr16_hi(view
, value
);
10905 case elfcpp::R_PPC64_ADDR16_HIGHA
:
10906 case elfcpp::R_PPC64_TPREL16_HIGHA
:
10907 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10909 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
10912 case elfcpp::R_POWERPC_ADDR16_HA
:
10913 case elfcpp::R_POWERPC_REL16_HA
:
10914 case elfcpp::R_PPC64_REL16_HIGHA
:
10915 case elfcpp::R_PPC64_TOC16_HA
:
10916 case elfcpp::R_POWERPC_GOT16_HA
:
10917 case elfcpp::R_POWERPC_PLT16_HA
:
10918 case elfcpp::R_POWERPC_SECTOFF_HA
:
10919 case elfcpp::R_POWERPC_TPREL16_HA
:
10920 case elfcpp::R_POWERPC_DTPREL16_HA
:
10921 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10922 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10923 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10924 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10925 Reloc::addr16_ha(view
, value
);
10928 case elfcpp::R_POWERPC_REL16DX_HA
:
10929 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
10932 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10934 // R_PPC_EMB_NADDR16_LO
10937 case elfcpp::R_PPC64_ADDR16_HIGHER
:
10938 case elfcpp::R_PPC64_REL16_HIGHER
:
10939 case elfcpp::R_PPC64_TPREL16_HIGHER
:
10940 Reloc::addr16_hi2(view
, value
);
10943 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10945 // R_PPC_EMB_NADDR16_HI
10948 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
10949 case elfcpp::R_PPC64_REL16_HIGHERA
:
10950 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
10951 Reloc::addr16_ha2(view
, value
);
10954 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10956 // R_PPC_EMB_NADDR16_HA
10959 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
10960 case elfcpp::R_PPC64_REL16_HIGHEST
:
10961 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10962 Reloc::addr16_hi3(view
, value
);
10965 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10967 // R_PPC_EMB_SDAI16
10970 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
10971 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10972 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10973 Reloc::addr16_ha3(view
, value
);
10976 case elfcpp::R_PPC64_DTPREL16_DS
:
10977 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10979 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
10982 case elfcpp::R_PPC64_TPREL16_DS
:
10983 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10985 // R_PPC_TLSGD, R_PPC_TLSLD
10988 case elfcpp::R_PPC64_ADDR16_DS
:
10989 case elfcpp::R_PPC64_ADDR16_LO_DS
:
10990 case elfcpp::R_PPC64_TOC16_DS
:
10991 case elfcpp::R_PPC64_TOC16_LO_DS
:
10992 case elfcpp::R_PPC64_GOT16_DS
:
10993 case elfcpp::R_PPC64_GOT16_LO_DS
:
10994 case elfcpp::R_PPC64_PLT16_LO_DS
:
10995 case elfcpp::R_PPC64_SECTOFF_DS
:
10996 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
10997 maybe_dq_reloc
= true;
11000 case elfcpp::R_POWERPC_ADDR14
:
11001 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
11002 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
11003 case elfcpp::R_POWERPC_REL14
:
11004 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
11005 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
11006 status
= Reloc::addr14(view
, value
, overflow
);
11009 case elfcpp::R_POWERPC_COPY
:
11010 case elfcpp::R_POWERPC_GLOB_DAT
:
11011 case elfcpp::R_POWERPC_JMP_SLOT
:
11012 case elfcpp::R_POWERPC_RELATIVE
:
11013 case elfcpp::R_POWERPC_DTPMOD
:
11014 case elfcpp::R_PPC64_JMP_IREL
:
11015 case elfcpp::R_POWERPC_IRELATIVE
:
11016 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11017 _("unexpected reloc %u in object file"),
11021 case elfcpp::R_PPC64_TOCSAVE
:
11027 Symbol_location loc
;
11028 loc
.object
= relinfo
->object
;
11029 loc
.shndx
= relinfo
->data_shndx
;
11030 loc
.offset
= rela
.get_r_offset();
11031 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
11032 if (p
!= target
->tocsave_loc().end())
11034 // If we've generated plt calls using this tocsave, then
11035 // the nop needs to be changed to save r2.
11036 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
11037 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
11038 elfcpp::Swap
<32, big_endian
>::
11039 writeval(iview
, std_2_1
+ target
->stk_toc());
11044 case elfcpp::R_PPC_EMB_SDA2I16
:
11045 case elfcpp::R_PPC_EMB_SDA2REL
:
11048 // R_PPC64_TLSGD, R_PPC64_TLSLD
11051 case elfcpp::R_PPC64_D34
:
11052 case elfcpp::R_PPC64_D34_LO
:
11053 case elfcpp::R_PPC64_PCREL34
:
11054 case elfcpp::R_PPC64_GOT_PCREL34
:
11055 case elfcpp::R_PPC64_PLT_PCREL34
:
11056 case elfcpp::R_PPC64_PLT_PCREL34_NOTOC
:
11059 status
= Reloc::addr34(view
, value
, overflow
);
11062 case elfcpp::R_PPC64_D34_HI30
:
11065 Reloc::addr34_hi(view
, value
);
11068 case elfcpp::R_PPC64_D34_HA30
:
11071 Reloc::addr34_ha(view
, value
);
11074 case elfcpp::R_PPC64_D28
:
11075 case elfcpp::R_PPC64_PCREL28
:
11078 status
= Reloc::addr28(view
, value
, overflow
);
11081 case elfcpp::R_PPC64_ADDR16_HIGHER34
:
11082 case elfcpp::R_PPC64_REL16_HIGHER34
:
11085 Reloc::addr16_higher34(view
, value
);
11088 case elfcpp::R_PPC64_ADDR16_HIGHERA34
:
11089 case elfcpp::R_PPC64_REL16_HIGHERA34
:
11092 Reloc::addr16_highera34(view
, value
);
11095 case elfcpp::R_PPC64_ADDR16_HIGHEST34
:
11096 case elfcpp::R_PPC64_REL16_HIGHEST34
:
11099 Reloc::addr16_highest34(view
, value
);
11102 case elfcpp::R_PPC64_ADDR16_HIGHESTA34
:
11103 case elfcpp::R_PPC64_REL16_HIGHESTA34
:
11106 Reloc::addr16_highesta34(view
, value
);
11109 case elfcpp::R_POWERPC_PLT32
:
11110 case elfcpp::R_POWERPC_PLTREL32
:
11111 case elfcpp::R_PPC_SDAREL16
:
11112 case elfcpp::R_POWERPC_ADDR30
:
11113 case elfcpp::R_PPC64_PLT64
:
11114 case elfcpp::R_PPC64_PLTREL64
:
11115 case elfcpp::R_PPC64_PLTGOT16
:
11116 case elfcpp::R_PPC64_PLTGOT16_LO
:
11117 case elfcpp::R_PPC64_PLTGOT16_HI
:
11118 case elfcpp::R_PPC64_PLTGOT16_HA
:
11119 case elfcpp::R_PPC64_PLTGOT16_DS
:
11120 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
11121 case elfcpp::R_PPC_TOC16
:
11124 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11125 _("unsupported reloc %u"),
11130 if (maybe_dq_reloc
)
11133 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
11135 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
11136 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
11137 && (insn
& 3) == 1))
11138 status
= Reloc::addr16_dq(view
, value
, overflow
);
11139 else if (size
== 64
11140 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
11141 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
11142 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
11143 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
11144 status
= Reloc::addr16_ds(view
, value
, overflow
);
11146 status
= Reloc::addr16(view
, value
, overflow
);
11149 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
11152 && gsym
->is_undefined()
11153 && is_branch_reloc
<size
>(r_type
))))
11155 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
11156 _("relocation overflow"));
11157 if (has_stub_value
)
11158 gold_info(_("try relinking with a smaller --stub-group-size"));
11164 // Relocate section data.
11166 template<int size
, bool big_endian
>
11168 Target_powerpc
<size
, big_endian
>::relocate_section(
11169 const Relocate_info
<size
, big_endian
>* relinfo
,
11170 unsigned int sh_type
,
11171 const unsigned char* prelocs
,
11172 size_t reloc_count
,
11173 Output_section
* output_section
,
11174 bool needs_special_offset_handling
,
11175 unsigned char* view
,
11177 section_size_type view_size
,
11178 const Reloc_symbol_changes
* reloc_symbol_changes
)
11180 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
11181 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
11182 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
11183 Powerpc_comdat_behavior
;
11184 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11187 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11189 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
11190 Powerpc_comdat_behavior
, Classify_reloc
>(
11196 needs_special_offset_handling
,
11200 reloc_symbol_changes
);
11203 template<int size
, bool big_endian
>
11204 class Powerpc_scan_relocatable_reloc
11207 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11208 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11209 static const int sh_type
= elfcpp::SHT_RELA
;
11211 // Return the symbol referred to by the relocation.
11212 static inline unsigned int
11213 get_r_sym(const Reltype
* reloc
)
11214 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
11216 // Return the type of the relocation.
11217 static inline unsigned int
11218 get_r_type(const Reltype
* reloc
)
11219 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
11221 // Return the strategy to use for a local symbol which is not a
11222 // section symbol, given the relocation type.
11223 inline Relocatable_relocs::Reloc_strategy
11224 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
11226 if (r_type
== 0 && r_sym
== 0)
11227 return Relocatable_relocs::RELOC_DISCARD
;
11228 return Relocatable_relocs::RELOC_COPY
;
11231 // Return the strategy to use for a local symbol which is a section
11232 // symbol, given the relocation type.
11233 inline Relocatable_relocs::Reloc_strategy
11234 local_section_strategy(unsigned int, Relobj
*)
11236 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
11239 // Return the strategy to use for a global symbol, given the
11240 // relocation type, the object, and the symbol index.
11241 inline Relocatable_relocs::Reloc_strategy
11242 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
11245 && (r_type
== elfcpp::R_PPC_PLTREL24
11246 || r_type
== elfcpp::R_POWERPC_PLT16_LO
11247 || r_type
== elfcpp::R_POWERPC_PLT16_HI
11248 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
11249 return Relocatable_relocs::RELOC_SPECIAL
;
11250 return Relocatable_relocs::RELOC_COPY
;
11254 // Scan the relocs during a relocatable link.
11256 template<int size
, bool big_endian
>
11258 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
11259 Symbol_table
* symtab
,
11261 Sized_relobj_file
<size
, big_endian
>* object
,
11262 unsigned int data_shndx
,
11263 unsigned int sh_type
,
11264 const unsigned char* prelocs
,
11265 size_t reloc_count
,
11266 Output_section
* output_section
,
11267 bool needs_special_offset_handling
,
11268 size_t local_symbol_count
,
11269 const unsigned char* plocal_symbols
,
11270 Relocatable_relocs
* rr
)
11272 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
11274 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11276 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
11284 needs_special_offset_handling
,
11285 local_symbol_count
,
11290 // Scan the relocs for --emit-relocs.
11292 template<int size
, bool big_endian
>
11294 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
11295 Symbol_table
* symtab
,
11297 Sized_relobj_file
<size
, big_endian
>* object
,
11298 unsigned int data_shndx
,
11299 unsigned int sh_type
,
11300 const unsigned char* prelocs
,
11301 size_t reloc_count
,
11302 Output_section
* output_section
,
11303 bool needs_special_offset_handling
,
11304 size_t local_symbol_count
,
11305 const unsigned char* plocal_syms
,
11306 Relocatable_relocs
* rr
)
11308 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
11310 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
11311 Emit_relocs_strategy
;
11313 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11315 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
11323 needs_special_offset_handling
,
11324 local_symbol_count
,
11329 // Emit relocations for a section.
11330 // This is a modified version of the function by the same name in
11331 // target-reloc.h. Using relocate_special_relocatable for
11332 // R_PPC_PLTREL24 would require duplication of the entire body of the
11333 // loop, so we may as well duplicate the whole thing.
11335 template<int size
, bool big_endian
>
11337 Target_powerpc
<size
, big_endian
>::relocate_relocs(
11338 const Relocate_info
<size
, big_endian
>* relinfo
,
11339 unsigned int sh_type
,
11340 const unsigned char* prelocs
,
11341 size_t reloc_count
,
11342 Output_section
* output_section
,
11343 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
11345 Address view_address
,
11347 unsigned char* reloc_view
,
11348 section_size_type reloc_view_size
)
11350 gold_assert(sh_type
== elfcpp::SHT_RELA
);
11352 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
11353 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
11354 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
11355 // Offset from start of insn to d-field reloc.
11356 const int d_offset
= big_endian
? 2 : 0;
11358 Powerpc_relobj
<size
, big_endian
>* const object
11359 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
11360 const unsigned int local_count
= object
->local_symbol_count();
11361 unsigned int got2_shndx
= object
->got2_shndx();
11362 Address got2_addend
= 0;
11363 if (got2_shndx
!= 0)
11365 got2_addend
= object
->get_output_section_offset(got2_shndx
);
11366 gold_assert(got2_addend
!= invalid_address
);
11369 const bool relocatable
= parameters
->options().relocatable();
11371 unsigned char* pwrite
= reloc_view
;
11372 bool zap_next
= false;
11373 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
11375 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
11376 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
11379 Reltype
reloc(prelocs
);
11380 Reltype_write
reloc_write(pwrite
);
11382 Address offset
= reloc
.get_r_offset();
11383 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
11384 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
11385 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
11386 const unsigned int orig_r_sym
= r_sym
;
11387 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
11388 = reloc
.get_r_addend();
11389 const Symbol
* gsym
= NULL
;
11393 // We could arrange to discard these and other relocs for
11394 // tls optimised sequences in the strategy methods, but for
11395 // now do as BFD ld does.
11396 r_type
= elfcpp::R_POWERPC_NONE
;
11400 // Get the new symbol index.
11401 Output_section
* os
= NULL
;
11402 if (r_sym
< local_count
)
11406 case Relocatable_relocs::RELOC_COPY
:
11407 case Relocatable_relocs::RELOC_SPECIAL
:
11410 r_sym
= object
->symtab_index(r_sym
);
11411 gold_assert(r_sym
!= -1U);
11415 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
11417 // We are adjusting a section symbol. We need to find
11418 // the symbol table index of the section symbol for
11419 // the output section corresponding to input section
11420 // in which this symbol is defined.
11421 gold_assert(r_sym
< local_count
);
11423 unsigned int shndx
=
11424 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
11425 gold_assert(is_ordinary
);
11426 os
= object
->output_section(shndx
);
11427 gold_assert(os
!= NULL
);
11428 gold_assert(os
->needs_symtab_index());
11429 r_sym
= os
->symtab_index();
11434 gold_unreachable();
11439 gsym
= object
->global_symbol(r_sym
);
11440 gold_assert(gsym
!= NULL
);
11441 if (gsym
->is_forwarder())
11442 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
11444 gold_assert(gsym
->has_symtab_index());
11445 r_sym
= gsym
->symtab_index();
11448 // Get the new offset--the location in the output section where
11449 // this relocation should be applied.
11450 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11451 offset
+= offset_in_output_section
;
11454 section_offset_type sot_offset
=
11455 convert_types
<section_offset_type
, Address
>(offset
);
11456 section_offset_type new_sot_offset
=
11457 output_section
->output_offset(object
, relinfo
->data_shndx
,
11459 gold_assert(new_sot_offset
!= -1);
11460 offset
= new_sot_offset
;
11463 // In an object file, r_offset is an offset within the section.
11464 // In an executable or dynamic object, generated by
11465 // --emit-relocs, r_offset is an absolute address.
11468 offset
+= view_address
;
11469 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11470 offset
-= offset_in_output_section
;
11473 // Handle the reloc addend based on the strategy.
11474 if (strategy
== Relocatable_relocs::RELOC_COPY
)
11476 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
11478 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
11479 addend
= psymval
->value(object
, addend
);
11480 // In a relocatable link, the symbol value is relative to
11481 // the start of the output section. For a non-relocatable
11482 // link, we need to adjust the addend.
11485 gold_assert(os
!= NULL
);
11486 addend
-= os
->address();
11489 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
11493 if (addend
>= 32768)
11494 addend
+= got2_addend
;
11496 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
11498 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
11499 addend
-= d_offset
;
11501 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
11503 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
11504 addend
-= d_offset
+ 4;
11508 gold_unreachable();
11512 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11513 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
11514 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
11515 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
11517 // First instruction of a global dynamic sequence,
11519 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11520 switch (this->optimize_tls_gd(final
))
11522 case tls::TLSOPT_TO_IE
:
11523 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11524 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11526 case tls::TLSOPT_TO_LE
:
11527 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11528 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11529 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11532 r_type
= elfcpp::R_POWERPC_NONE
;
11533 offset
-= d_offset
;
11540 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11541 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11542 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11543 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
11545 // First instruction of a local dynamic sequence,
11547 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11549 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11550 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11552 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11553 const Output_section
* os
= relinfo
->layout
->tls_segment()
11555 gold_assert(os
!= NULL
);
11556 gold_assert(os
->needs_symtab_index());
11557 r_sym
= os
->symtab_index();
11558 addend
= dtp_offset
;
11562 r_type
= elfcpp::R_POWERPC_NONE
;
11563 offset
-= d_offset
;
11567 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11568 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11569 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11570 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
11572 // First instruction of initial exec sequence.
11573 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11574 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11576 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11577 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11578 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11581 r_type
= elfcpp::R_POWERPC_NONE
;
11582 offset
-= d_offset
;
11586 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11587 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11589 // Second instruction of a global dynamic sequence,
11590 // the __tls_get_addr call
11591 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11592 switch (this->optimize_tls_gd(final
))
11594 case tls::TLSOPT_TO_IE
:
11595 r_type
= elfcpp::R_POWERPC_NONE
;
11598 case tls::TLSOPT_TO_LE
:
11599 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11600 offset
+= d_offset
;
11607 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11608 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11610 // Second instruction of a local dynamic sequence,
11611 // the __tls_get_addr call
11612 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11614 const Output_section
* os
= relinfo
->layout
->tls_segment()
11616 gold_assert(os
!= NULL
);
11617 gold_assert(os
->needs_symtab_index());
11618 r_sym
= os
->symtab_index();
11619 addend
= dtp_offset
;
11620 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11621 offset
+= d_offset
;
11625 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11627 // Second instruction of an initial exec sequence
11628 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11629 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11631 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11632 offset
+= d_offset
;
11637 reloc_write
.put_r_offset(offset
);
11638 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
11639 reloc_write
.put_r_addend(addend
);
11641 pwrite
+= reloc_size
;
11644 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
11645 == reloc_view_size
);
11648 // Return the value to use for a dynamic symbol which requires special
11649 // treatment. This is how we support equality comparisons of function
11650 // pointers across shared library boundaries, as described in the
11651 // processor specific ABI supplement.
11653 template<int size
, bool big_endian
>
11655 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
11659 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
11660 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11661 p
!= this->stub_tables_
.end();
11664 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11665 = (*p
)->find_plt_call_entry(gsym
);
11667 return (*p
)->stub_address() + ent
->off_
;
11670 else if (this->abiversion() >= 2)
11672 Address off
= this->glink_section()->find_global_entry(gsym
);
11673 if (off
!= invalid_address
)
11674 return this->glink_section()->global_entry_address() + off
;
11676 gold_unreachable();
11679 // Return the PLT address to use for a local symbol.
11680 template<int size
, bool big_endian
>
11682 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
11683 const Relobj
* object
,
11684 unsigned int symndx
) const
11688 const Sized_relobj
<size
, big_endian
>* relobj
11689 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
11690 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11691 p
!= this->stub_tables_
.end();
11694 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11695 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
11697 return (*p
)->stub_address() + ent
->off_
;
11700 gold_unreachable();
11703 // Return the PLT address to use for a global symbol.
11704 template<int size
, bool big_endian
>
11706 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
11707 const Symbol
* gsym
) const
11711 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11712 p
!= this->stub_tables_
.end();
11715 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11716 = (*p
)->find_plt_call_entry(gsym
);
11718 return (*p
)->stub_address() + ent
->off_
;
11721 else if (this->abiversion() >= 2)
11723 Address off
= this->glink_section()->find_global_entry(gsym
);
11724 if (off
!= invalid_address
)
11725 return this->glink_section()->global_entry_address() + off
;
11727 gold_unreachable();
11730 // Return the offset to use for the GOT_INDX'th got entry which is
11731 // for a local tls symbol specified by OBJECT, SYMNDX.
11732 template<int size
, bool big_endian
>
11734 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
11735 const Relobj
* object
,
11736 unsigned int symndx
,
11737 unsigned int got_indx
) const
11739 const Powerpc_relobj
<size
, big_endian
>* ppc_object
11740 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
11741 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
11743 for (Got_type got_type
= GOT_TYPE_TLSGD
;
11744 got_type
<= GOT_TYPE_TPREL
;
11745 got_type
= Got_type(got_type
+ 1))
11746 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
11748 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
11749 if (got_type
== GOT_TYPE_TLSGD
)
11751 if (off
== got_indx
* (size
/ 8))
11753 if (got_type
== GOT_TYPE_TPREL
)
11756 return -dtp_offset
;
11760 gold_unreachable();
11763 // Return the offset to use for the GOT_INDX'th got entry which is
11764 // for global tls symbol GSYM.
11765 template<int size
, bool big_endian
>
11767 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
11769 unsigned int got_indx
) const
11771 if (gsym
->type() == elfcpp::STT_TLS
)
11773 for (Got_type got_type
= GOT_TYPE_TLSGD
;
11774 got_type
<= GOT_TYPE_TPREL
;
11775 got_type
= Got_type(got_type
+ 1))
11776 if (gsym
->has_got_offset(got_type
))
11778 unsigned int off
= gsym
->got_offset(got_type
);
11779 if (got_type
== GOT_TYPE_TLSGD
)
11781 if (off
== got_indx
* (size
/ 8))
11783 if (got_type
== GOT_TYPE_TPREL
)
11786 return -dtp_offset
;
11790 gold_unreachable();
11793 // The selector for powerpc object files.
11795 template<int size
, bool big_endian
>
11796 class Target_selector_powerpc
: public Target_selector
11799 Target_selector_powerpc()
11800 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
11803 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
11804 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
11806 ? (big_endian
? "elf64ppc" : "elf64lppc")
11807 : (big_endian
? "elf32ppc" : "elf32lppc")))
11811 do_instantiate_target()
11812 { return new Target_powerpc
<size
, big_endian
>(); }
11815 Target_selector_powerpc
<32, true> target_selector_ppc32
;
11816 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
11817 Target_selector_powerpc
<64, true> target_selector_ppc64
;
11818 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
11820 // Instantiate these constants for -O0
11821 template<int size
, bool big_endian
>
11822 const typename Output_data_glink
<size
, big_endian
>::Address
11823 Output_data_glink
<size
, big_endian
>::invalid_address
;
11824 template<int size
, bool big_endian
>
11825 const typename Stub_table
<size
, big_endian
>::Address
11826 Stub_table
<size
, big_endian
>::invalid_address
;
11827 template<int size
, bool big_endian
>
11828 const typename Target_powerpc
<size
, big_endian
>::Address
11829 Target_powerpc
<size
, big_endian
>::invalid_address
;
11831 } // End anonymous namespace.