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 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 plt_thread_safe() const
1077 { return this->plt_thread_safe_
; }
1080 plt_localentry0() const
1081 { return this->plt_localentry0_
; }
1084 set_has_localentry0()
1086 this->has_localentry0_
= true;
1090 is_elfv2_localentry0(const Symbol
* gsym
) const
1093 && this->abiversion() >= 2
1094 && this->plt_localentry0()
1095 && gsym
->type() == elfcpp::STT_FUNC
1096 && gsym
->is_defined()
1097 && gsym
->nonvis() >> 3 == 0
1098 && !gsym
->non_zero_localentry());
1102 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1103 unsigned int r_sym
) const
1105 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1106 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1109 && this->abiversion() >= 2
1110 && this->plt_localentry0()
1111 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1113 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1115 if (!psymval
->is_ifunc_symbol()
1116 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1123 // Remember any symbols seen with non-zero localentry, even those
1124 // not providing a definition
1126 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1131 unsigned char st_other
= sym
.get_st_other();
1132 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1133 to
->set_non_zero_localentry();
1135 // We haven't resolved anything, continue normal processing.
1141 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1144 set_abiversion(int ver
)
1146 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1147 flags
&= ~elfcpp::EF_PPC64_ABI
;
1148 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1149 this->set_processor_specific_flags(flags
);
1153 tls_get_addr_opt() const
1154 { return this->tls_get_addr_opt_
; }
1157 tls_get_addr() const
1158 { return this->tls_get_addr_
; }
1160 // If optimizing __tls_get_addr calls, whether this is the
1161 // "__tls_get_addr" symbol.
1163 is_tls_get_addr_opt(const Symbol
* gsym
) const
1165 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1166 || gsym
== this->tls_get_addr_opt_
);
1170 replace_tls_get_addr(const Symbol
* gsym
) const
1171 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1174 set_has_tls_get_addr_opt()
1175 { this->has_tls_get_addr_opt_
= true; }
1177 // Offset to toc save stack slot
1180 { return this->abiversion() < 2 ? 40 : 24; }
1182 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1183 // so use the CR save slot. Used only by __tls_get_addr call stub,
1184 // relying on __tls_get_addr not saving CR itself.
1187 { return this->abiversion() < 2 ? 32 : 8; }
1189 // Merge object attributes from input object with those in the output.
1191 merge_object_attributes(const char*, const Attributes_section_data
*);
1207 : tls_get_addr_state_(NOT_EXPECTED
),
1208 relinfo_(NULL
), relnum_(0), r_offset_(0)
1213 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1220 if (this->relinfo_
!= NULL
)
1221 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1222 _("missing expected __tls_get_addr call"));
1226 expect_tls_get_addr_call(
1227 const Relocate_info
<size
, big_endian
>* relinfo
,
1231 this->tls_get_addr_state_
= EXPECTED
;
1232 this->relinfo_
= relinfo
;
1233 this->relnum_
= relnum
;
1234 this->r_offset_
= r_offset
;
1238 expect_tls_get_addr_call()
1239 { this->tls_get_addr_state_
= EXPECTED
; }
1242 skip_next_tls_get_addr_call()
1243 {this->tls_get_addr_state_
= SKIP
; }
1246 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1247 unsigned int r_type
, const Symbol
* gsym
)
1250 = ((r_type
== elfcpp::R_POWERPC_REL24
1251 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1252 || r_type
== elfcpp::R_PPC_PLTREL24
1253 || is_plt16_reloc
<size
>(r_type
)
1254 || r_type
== elfcpp::R_POWERPC_PLTSEQ
1255 || r_type
== elfcpp::R_POWERPC_PLTCALL
1256 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
1257 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
1259 && (gsym
== target
->tls_get_addr()
1260 || gsym
== target
->tls_get_addr_opt()));
1261 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1262 this->tls_get_addr_state_
= NOT_EXPECTED
;
1263 if (is_tls_call
&& last_tls
!= EXPECTED
)
1265 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1274 // What we're up to regarding calls to __tls_get_addr.
1275 // On powerpc, the branch and link insn making a call to
1276 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1277 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1278 // usual R_POWERPC_REL24 or R_PPC_PLTREL24 relocation on a call.
1279 // The marker relocation always comes first, and has the same
1280 // symbol as the reloc on the insn setting up the __tls_get_addr
1281 // argument. This ties the arg setup insn with the call insn,
1282 // allowing ld to safely optimize away the call. We check that
1283 // every call to __tls_get_addr has a marker relocation, and that
1284 // every marker relocation is on a call to __tls_get_addr.
1285 Tls_get_addr tls_get_addr_state_
;
1286 // Info about the last reloc for error message.
1287 const Relocate_info
<size
, big_endian
>* relinfo_
;
1292 // The class which scans relocations.
1293 class Scan
: protected Track_tls
1296 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1299 : Track_tls(), issued_non_pic_error_(false)
1303 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1306 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1307 Sized_relobj_file
<size
, big_endian
>* object
,
1308 unsigned int data_shndx
,
1309 Output_section
* output_section
,
1310 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1311 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1315 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1316 Sized_relobj_file
<size
, big_endian
>* object
,
1317 unsigned int data_shndx
,
1318 Output_section
* output_section
,
1319 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1323 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1325 Sized_relobj_file
<size
, big_endian
>* relobj
,
1328 const elfcpp::Rela
<size
, big_endian
>& ,
1329 unsigned int r_type
,
1330 const elfcpp::Sym
<size
, big_endian
>&)
1332 // PowerPC64 .opd is not folded, so any identical function text
1333 // may be folded and we'll still keep function addresses distinct.
1334 // That means no reloc is of concern here.
1337 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1338 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1339 if (ppcobj
->abiversion() == 1)
1342 // For 32-bit and ELFv2, conservatively assume anything but calls to
1343 // function code might be taking the address of the function.
1344 return !is_branch_reloc
<size
>(r_type
);
1348 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1350 Sized_relobj_file
<size
, big_endian
>* relobj
,
1353 const elfcpp::Rela
<size
, big_endian
>& ,
1354 unsigned int r_type
,
1360 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1361 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1362 if (ppcobj
->abiversion() == 1)
1365 return !is_branch_reloc
<size
>(r_type
);
1369 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1370 Sized_relobj_file
<size
, big_endian
>* object
,
1371 unsigned int r_type
, bool report_err
);
1375 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1376 unsigned int r_type
);
1379 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1380 unsigned int r_type
, Symbol
*);
1383 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1384 Target_powerpc
* target
);
1387 check_non_pic(Relobj
*, unsigned int r_type
);
1389 // Whether we have issued an error about a non-PIC compilation.
1390 bool issued_non_pic_error_
;
1394 symval_for_branch(const Symbol_table
* symtab
,
1395 const Sized_symbol
<size
>* gsym
,
1396 Powerpc_relobj
<size
, big_endian
>* object
,
1397 Address
*value
, unsigned int *dest_shndx
);
1399 // The class which implements relocation.
1400 class Relocate
: protected Track_tls
1403 // Use 'at' branch hints when true, 'y' when false.
1404 // FIXME maybe: set this with an option.
1405 static const bool is_isa_v2
= true;
1411 // Do a relocation. Return false if the caller should not issue
1412 // any warnings about this relocation.
1414 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1415 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1416 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1417 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1421 class Relocate_comdat_behavior
1424 // Decide what the linker should do for relocations that refer to
1425 // discarded comdat sections.
1426 inline Comdat_behavior
1427 get(const char* name
)
1429 gold::Default_comdat_behavior default_behavior
;
1430 Comdat_behavior ret
= default_behavior
.get(name
);
1431 if (ret
== CB_ERROR
)
1434 && (strcmp(name
, ".fixup") == 0
1435 || strcmp(name
, ".got2") == 0))
1438 && (strcmp(name
, ".opd") == 0
1439 || strcmp(name
, ".toc") == 0
1440 || strcmp(name
, ".toc1") == 0))
1447 // Optimize the TLS relocation type based on what we know about the
1448 // symbol. IS_FINAL is true if the final address of this symbol is
1449 // known at link time.
1451 tls::Tls_optimization
1452 optimize_tls_gd(bool is_final
)
1454 // If we are generating a shared library, then we can't do anything
1456 if (parameters
->options().shared()
1457 || !parameters
->options().tls_optimize())
1458 return tls::TLSOPT_NONE
;
1461 return tls::TLSOPT_TO_IE
;
1462 return tls::TLSOPT_TO_LE
;
1465 tls::Tls_optimization
1468 if (parameters
->options().shared()
1469 || !parameters
->options().tls_optimize())
1470 return tls::TLSOPT_NONE
;
1472 return tls::TLSOPT_TO_LE
;
1475 tls::Tls_optimization
1476 optimize_tls_ie(bool is_final
)
1479 || parameters
->options().shared()
1480 || !parameters
->options().tls_optimize())
1481 return tls::TLSOPT_NONE
;
1483 return tls::TLSOPT_TO_LE
;
1488 make_glink_section(Layout
*);
1490 // Create the PLT section.
1492 make_plt_section(Symbol_table
*, Layout
*);
1495 make_iplt_section(Symbol_table
*, Layout
*);
1498 make_lplt_section(Layout
*);
1501 make_brlt_section(Layout
*);
1503 // Create a PLT entry for a global symbol.
1505 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1507 // Create a PLT entry for a local IFUNC symbol.
1509 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1510 Sized_relobj_file
<size
, big_endian
>*,
1513 // Create a PLT entry for a local non-IFUNC symbol.
1515 make_local_plt_entry(Layout
*,
1516 Sized_relobj_file
<size
, big_endian
>*,
1520 // Create a GOT entry for local dynamic __tls_get_addr.
1522 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1523 Sized_relobj_file
<size
, big_endian
>* object
);
1526 tlsld_got_offset() const
1528 return this->tlsld_got_offset_
;
1531 // Get the dynamic reloc section, creating it if necessary.
1533 rela_dyn_section(Layout
*);
1535 // Similarly, but for ifunc symbols get the one for ifunc.
1537 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1539 // Copy a relocation against a global symbol.
1541 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1542 Sized_relobj_file
<size
, big_endian
>* object
,
1543 unsigned int shndx
, Output_section
* output_section
,
1544 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1546 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1547 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1548 symtab
->get_sized_symbol
<size
>(sym
),
1549 object
, shndx
, output_section
,
1550 r_type
, reloc
.get_r_offset(),
1551 reloc
.get_r_addend(),
1552 this->rela_dyn_section(layout
));
1555 // Look over all the input sections, deciding where to place stubs.
1557 group_sections(Layout
*, const Task
*, bool);
1559 // Sort output sections by address.
1560 struct Sort_sections
1563 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1564 { return sec1
->address() < sec2
->address(); }
1570 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1571 unsigned int data_shndx
,
1573 unsigned int r_type
,
1576 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1577 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1583 // Return whether this branch is going via a plt call stub, and if
1584 // so, mark it as having an R_PPC64_TOCSAVE.
1586 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1587 unsigned int shndx
, Address offset
,
1588 Target_powerpc
* target
, Symbol_table
* symtab
);
1590 // If this branch needs a plt call stub, or a long branch stub, make one.
1592 make_stub(Stub_table
<size
, big_endian
>*,
1593 Stub_table
<size
, big_endian
>*,
1594 Symbol_table
*) const;
1597 // The branch location..
1598 Powerpc_relobj
<size
, big_endian
>* object_
;
1599 unsigned int shndx_
;
1601 // ..and the branch type and destination.
1602 unsigned int r_type_
: 31;
1603 unsigned int tocsave_
: 1;
1604 unsigned int r_sym_
;
1608 // Information about this specific target which we pass to the
1609 // general Target structure.
1610 static Target::Target_info powerpc_info
;
1612 // The types of GOT entries needed for this platform.
1613 // These values are exposed to the ABI in an incremental link.
1614 // Do not renumber existing values without changing the version
1615 // number of the .gnu_incremental_inputs section.
1619 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1620 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1621 GOT_TYPE_TPREL
// entry for @got@tprel
1625 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1626 // The PLT section. This is a container for a table of addresses,
1627 // and their relocations. Each address in the PLT has a dynamic
1628 // relocation (R_*_JMP_SLOT) and each address will have a
1629 // corresponding entry in .glink for lazy resolution of the PLT.
1630 // ppc32 initialises the PLT to point at the .glink entry, while
1631 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1632 // linker adds a stub that loads the PLT entry into ctr then
1633 // branches to ctr. There may be more than one stub for each PLT
1634 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1635 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1636 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1637 // The IPLT section. Like plt_, this is a container for a table of
1638 // addresses and their relocations, specifically for STT_GNU_IFUNC
1639 // functions that resolve locally (STT_GNU_IFUNC functions that
1640 // don't resolve locally go in PLT). Unlike plt_, these have no
1641 // entry in .glink for lazy resolution, and the relocation section
1642 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1643 // the relocation section may contain relocations against
1644 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1645 // relocation section will appear at the end of other dynamic
1646 // relocations, so that ld.so applies these relocations after other
1647 // dynamic relocations. In a static executable, the relocation
1648 // section is emitted and marked with __rela_iplt_start and
1649 // __rela_iplt_end symbols.
1650 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1651 // A PLT style section for local, non-ifunc symbols
1652 Output_data_plt_powerpc
<size
, big_endian
>* lplt_
;
1653 // Section holding long branch destinations.
1654 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1655 // The .glink section.
1656 Output_data_glink
<size
, big_endian
>* glink_
;
1657 // The dynamic reloc section.
1658 Reloc_section
* rela_dyn_
;
1659 // Relocs saved to avoid a COPY reloc.
1660 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1661 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1662 unsigned int tlsld_got_offset_
;
1664 Stub_tables stub_tables_
;
1665 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1666 Branch_lookup_table branch_lookup_table_
;
1668 typedef std::vector
<Branch_info
> Branches
;
1669 Branches branch_info_
;
1670 Tocsave_loc tocsave_loc_
;
1672 bool plt_thread_safe_
;
1673 bool plt_localentry0_
;
1674 bool plt_localentry0_init_
;
1675 bool has_localentry0_
;
1676 bool has_tls_get_addr_opt_
;
1679 int relax_fail_count_
;
1680 int32_t stub_group_size_
;
1682 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1684 // The "__tls_get_addr" symbol, if present
1685 Symbol
* tls_get_addr_
;
1686 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1687 Symbol
* tls_get_addr_opt_
;
1689 // Attributes in output.
1690 Attributes_section_data
* attributes_section_data_
;
1692 // Last input file to change various attribute tags
1693 const char* last_fp_
;
1694 const char* last_ld_
;
1695 const char* last_vec_
;
1696 const char* last_struct_
;
1700 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1703 true, // is_big_endian
1704 elfcpp::EM_PPC
, // machine_code
1705 false, // has_make_symbol
1706 false, // has_resolve
1707 false, // has_code_fill
1708 true, // is_default_stack_executable
1709 false, // can_icf_inline_merge_sections
1711 "/usr/lib/ld.so.1", // dynamic_linker
1712 0x10000000, // default_text_segment_address
1713 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1714 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1715 false, // isolate_execinstr
1717 elfcpp::SHN_UNDEF
, // small_common_shndx
1718 elfcpp::SHN_UNDEF
, // large_common_shndx
1719 0, // small_common_section_flags
1720 0, // large_common_section_flags
1721 NULL
, // attributes_section
1722 NULL
, // attributes_vendor
1723 "_start", // entry_symbol_name
1724 32, // hash_entry_size
1725 elfcpp::SHT_PROGBITS
, // unwind_section_type
1729 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1732 false, // is_big_endian
1733 elfcpp::EM_PPC
, // machine_code
1734 false, // has_make_symbol
1735 false, // has_resolve
1736 false, // has_code_fill
1737 true, // is_default_stack_executable
1738 false, // can_icf_inline_merge_sections
1740 "/usr/lib/ld.so.1", // dynamic_linker
1741 0x10000000, // default_text_segment_address
1742 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1743 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1744 false, // isolate_execinstr
1746 elfcpp::SHN_UNDEF
, // small_common_shndx
1747 elfcpp::SHN_UNDEF
, // large_common_shndx
1748 0, // small_common_section_flags
1749 0, // large_common_section_flags
1750 NULL
, // attributes_section
1751 NULL
, // attributes_vendor
1752 "_start", // entry_symbol_name
1753 32, // hash_entry_size
1754 elfcpp::SHT_PROGBITS
, // unwind_section_type
1758 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1761 true, // is_big_endian
1762 elfcpp::EM_PPC64
, // machine_code
1763 false, // has_make_symbol
1764 true, // has_resolve
1765 false, // has_code_fill
1766 false, // is_default_stack_executable
1767 false, // can_icf_inline_merge_sections
1769 "/usr/lib/ld.so.1", // dynamic_linker
1770 0x10000000, // default_text_segment_address
1771 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1772 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1773 false, // isolate_execinstr
1775 elfcpp::SHN_UNDEF
, // small_common_shndx
1776 elfcpp::SHN_UNDEF
, // large_common_shndx
1777 0, // small_common_section_flags
1778 0, // large_common_section_flags
1779 NULL
, // attributes_section
1780 NULL
, // attributes_vendor
1781 "_start", // entry_symbol_name
1782 32, // hash_entry_size
1783 elfcpp::SHT_PROGBITS
, // unwind_section_type
1787 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1790 false, // is_big_endian
1791 elfcpp::EM_PPC64
, // machine_code
1792 false, // has_make_symbol
1793 true, // has_resolve
1794 false, // has_code_fill
1795 false, // is_default_stack_executable
1796 false, // can_icf_inline_merge_sections
1798 "/usr/lib/ld.so.1", // dynamic_linker
1799 0x10000000, // default_text_segment_address
1800 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1801 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1802 false, // isolate_execinstr
1804 elfcpp::SHN_UNDEF
, // small_common_shndx
1805 elfcpp::SHN_UNDEF
, // large_common_shndx
1806 0, // small_common_section_flags
1807 0, // large_common_section_flags
1808 NULL
, // attributes_section
1809 NULL
, // attributes_vendor
1810 "_start", // entry_symbol_name
1811 32, // hash_entry_size
1812 elfcpp::SHT_PROGBITS
, // unwind_section_type
1817 is_branch_reloc(unsigned int r_type
)
1819 return (r_type
== elfcpp::R_POWERPC_REL24
1820 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
1821 || r_type
== elfcpp::R_PPC_PLTREL24
1822 || r_type
== elfcpp::R_PPC_LOCAL24PC
1823 || r_type
== elfcpp::R_POWERPC_REL14
1824 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1825 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1826 || r_type
== elfcpp::R_POWERPC_ADDR24
1827 || r_type
== elfcpp::R_POWERPC_ADDR14
1828 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1829 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1832 // Reloc resolves to plt entry.
1835 is_plt16_reloc(unsigned int r_type
)
1837 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1838 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1839 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1840 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1843 // If INSN is an opcode that may be used with an @tls operand, return
1844 // the transformed insn for TLS optimisation, otherwise return 0. If
1845 // REG is non-zero only match an insn with RB or RA equal to REG.
1847 at_tls_transform(uint32_t insn
, unsigned int reg
)
1849 if ((insn
& (0x3f << 26)) != 31 << 26)
1853 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1854 rtra
= insn
& ((1 << 26) - (1 << 16));
1855 else if (((insn
>> 16) & 0x1f) == reg
)
1856 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1860 if ((insn
& (0x3ff << 1)) == 266 << 1)
1863 else if ((insn
& (0x1f << 1)) == 23 << 1
1864 && ((insn
& (0x1f << 6)) < 14 << 6
1865 || ((insn
& (0x1f << 6)) >= 16 << 6
1866 && (insn
& (0x1f << 6)) < 24 << 6)))
1867 // load and store indexed -> dform
1868 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1869 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1870 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1871 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1872 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1874 insn
= (58 << 26) | 2;
1882 template<int size
, bool big_endian
>
1883 class Powerpc_relocate_functions
1903 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1904 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1905 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1907 template<int valsize
>
1909 has_overflow_signed(Address value
)
1911 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1912 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1913 limit
<<= ((valsize
- 1) >> 1);
1914 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1915 return value
+ limit
> (limit
<< 1) - 1;
1918 template<int valsize
>
1920 has_overflow_unsigned(Address value
)
1922 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1923 limit
<<= ((valsize
- 1) >> 1);
1924 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1925 return value
> (limit
<< 1) - 1;
1928 template<int valsize
>
1930 has_overflow_bitfield(Address value
)
1932 return (has_overflow_unsigned
<valsize
>(value
)
1933 && has_overflow_signed
<valsize
>(value
));
1936 template<int valsize
>
1937 static inline Status
1938 overflowed(Address value
, Overflow_check overflow
)
1940 if (overflow
== CHECK_SIGNED
)
1942 if (has_overflow_signed
<valsize
>(value
))
1943 return STATUS_OVERFLOW
;
1945 else if (overflow
== CHECK_UNSIGNED
)
1947 if (has_overflow_unsigned
<valsize
>(value
))
1948 return STATUS_OVERFLOW
;
1950 else if (overflow
== CHECK_BITFIELD
)
1952 if (has_overflow_bitfield
<valsize
>(value
))
1953 return STATUS_OVERFLOW
;
1958 // Do a simple RELA relocation
1959 template<int fieldsize
, int valsize
>
1960 static inline Status
1961 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1963 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1964 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1965 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1966 return overflowed
<valsize
>(value
, overflow
);
1969 template<int fieldsize
, int valsize
>
1970 static inline Status
1971 rela(unsigned char* view
,
1972 unsigned int right_shift
,
1973 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1975 Overflow_check overflow
)
1977 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1978 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1979 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1980 Valtype reloc
= value
>> right_shift
;
1983 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1984 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1987 // Do a simple RELA relocation, unaligned.
1988 template<int fieldsize
, int valsize
>
1989 static inline Status
1990 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1992 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1993 return overflowed
<valsize
>(value
, overflow
);
1996 template<int fieldsize
, int valsize
>
1997 static inline Status
1998 rela_ua(unsigned char* view
,
1999 unsigned int right_shift
,
2000 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
2002 Overflow_check overflow
)
2004 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
2006 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
2007 Valtype reloc
= value
>> right_shift
;
2010 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
2011 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
2015 // R_PPC64_ADDR64: (Symbol + Addend)
2017 addr64(unsigned char* view
, Address value
)
2018 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
2020 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
2022 addr64_u(unsigned char* view
, Address value
)
2023 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
2025 // R_POWERPC_ADDR32: (Symbol + Addend)
2026 static inline Status
2027 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
2028 { return This::template rela
<32,32>(view
, value
, overflow
); }
2030 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
2031 static inline Status
2032 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2033 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
2035 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
2036 static inline Status
2037 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
2039 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
2041 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2042 stat
= STATUS_OVERFLOW
;
2046 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
2047 static inline Status
2048 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
2049 { return This::template rela
<16,16>(view
, value
, overflow
); }
2051 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
2052 static inline Status
2053 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
2054 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
2056 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
2057 static inline Status
2058 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
2060 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
2061 if ((value
& 3) != 0)
2062 stat
= STATUS_OVERFLOW
;
2066 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
2067 static inline Status
2068 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
2070 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
2071 if ((value
& 15) != 0)
2072 stat
= STATUS_OVERFLOW
;
2076 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2078 addr16_hi(unsigned char* view
, Address value
)
2079 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2081 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2083 addr16_ha(unsigned char* view
, Address value
)
2084 { This::addr16_hi(view
, value
+ 0x8000); }
2086 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2088 addr16_hi2(unsigned char* view
, Address value
)
2089 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2091 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2093 addr16_ha2(unsigned char* view
, Address value
)
2094 { This::addr16_hi2(view
, value
+ 0x8000); }
2096 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2098 addr16_hi3(unsigned char* view
, Address value
)
2099 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2101 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2103 addr16_ha3(unsigned char* view
, Address value
)
2104 { This::addr16_hi3(view
, value
+ 0x8000); }
2106 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2107 static inline Status
2108 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2110 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2111 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2112 stat
= STATUS_OVERFLOW
;
2116 // R_POWERPC_REL16DX_HA
2117 static inline Status
2118 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2120 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2121 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2122 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2124 value
= static_cast<SignedAddress
>(value
) >> 16;
2125 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2126 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2127 return overflowed
<16>(value
, overflow
);
2131 // Set ABI version for input and output.
2133 template<int size
, bool big_endian
>
2135 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2137 this->e_flags_
|= ver
;
2138 if (this->abiversion() != 0)
2140 Target_powerpc
<size
, big_endian
>* target
=
2141 static_cast<Target_powerpc
<size
, big_endian
>*>(
2142 parameters
->sized_target
<size
, big_endian
>());
2143 if (target
->abiversion() == 0)
2144 target
->set_abiversion(this->abiversion());
2145 else if (target
->abiversion() != this->abiversion())
2146 gold_error(_("%s: ABI version %d is not compatible "
2147 "with ABI version %d output"),
2148 this->name().c_str(),
2149 this->abiversion(), target
->abiversion());
2154 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2155 // relocatable object, if such sections exists.
2157 template<int size
, bool big_endian
>
2159 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2160 Read_symbols_data
* sd
)
2162 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2163 const unsigned char* namesu
= sd
->section_names
->data();
2164 const char* names
= reinterpret_cast<const char*>(namesu
);
2165 section_size_type names_size
= sd
->section_names_size
;
2166 const unsigned char* s
;
2168 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2169 size
== 32 ? ".got2" : ".opd",
2170 names
, names_size
, NULL
);
2173 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2174 this->special_
= ndx
;
2177 if (this->abiversion() == 0)
2178 this->set_abiversion(1);
2179 else if (this->abiversion() > 1)
2180 gold_error(_("%s: .opd invalid in abiv%d"),
2181 this->name().c_str(), this->abiversion());
2186 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2187 names
, names_size
, NULL
);
2190 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2191 this->relatoc_
= ndx
;
2192 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2193 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2196 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2199 // Examine .rela.opd to build info about function entry points.
2201 template<int size
, bool big_endian
>
2203 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2205 const unsigned char* prelocs
,
2206 const unsigned char* plocal_syms
)
2210 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2211 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2212 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2213 Address expected_off
= 0;
2214 bool regular
= true;
2215 unsigned int opd_ent_size
= 0;
2217 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2219 Reltype
reloc(prelocs
);
2220 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2221 = reloc
.get_r_info();
2222 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2223 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2225 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2226 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2229 if (r_sym
< this->local_symbol_count())
2231 typename
elfcpp::Sym
<size
, big_endian
>
2232 lsym(plocal_syms
+ r_sym
* sym_size
);
2233 shndx
= lsym
.get_st_shndx();
2234 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2235 value
= lsym
.get_st_value();
2238 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2240 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2241 value
+ reloc
.get_r_addend());
2244 expected_off
= reloc
.get_r_offset();
2245 opd_ent_size
= expected_off
;
2247 else if (expected_off
!= reloc
.get_r_offset())
2249 expected_off
+= opd_ent_size
;
2251 else if (r_type
== elfcpp::R_PPC64_TOC
)
2253 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2258 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2259 this->name().c_str(), r_type
);
2263 if (reloc_count
<= 2)
2264 opd_ent_size
= this->section_size(this->opd_shndx());
2265 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2269 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2270 this->name().c_str());
2276 // Returns true if a code sequence loading the TOC entry at VALUE
2277 // relative to the TOC pointer can be converted into code calculating
2278 // a TOC pointer relative offset.
2279 // If so, the TOC pointer relative offset is stored to VALUE.
2281 template<int size
, bool big_endian
>
2283 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2284 Target_powerpc
<size
, big_endian
>* target
,
2290 // With -mcmodel=medium code it is quite possible to have
2291 // toc-relative relocs referring to objects outside the TOC.
2292 // Don't try to look at a non-existent TOC.
2293 if (this->toc_shndx() == 0)
2296 // Convert VALUE back to an address by adding got_base (see below),
2297 // then to an offset in the TOC by subtracting the TOC output
2298 // section address and the TOC output offset. Since this TOC output
2299 // section and the got output section are one and the same, we can
2300 // omit adding and subtracting the output section address.
2301 Address off
= (*value
+ this->toc_base_offset()
2302 - this->output_section_offset(this->toc_shndx()));
2303 // Is this offset in the TOC? -mcmodel=medium code may be using
2304 // TOC relative access to variables outside the TOC. Those of
2305 // course can't be optimized. We also don't try to optimize code
2306 // that is using a different object's TOC.
2307 if (off
>= this->section_size(this->toc_shndx()))
2310 if (this->no_toc_opt(off
))
2313 section_size_type vlen
;
2314 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2315 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2317 Address got_base
= (target
->got_section()->output_section()->address()
2318 + this->toc_base_offset());
2320 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2327 // Perform the Sized_relobj_file method, then set up opd info from
2330 template<int size
, bool big_endian
>
2332 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2334 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2337 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2338 p
!= rd
->relocs
.end();
2341 if (p
->data_shndx
== this->opd_shndx())
2343 uint64_t opd_size
= this->section_size(this->opd_shndx());
2344 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2347 this->init_opd(opd_size
);
2348 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2349 rd
->local_symbols
->data());
2357 // Read the symbols then set up st_other vector.
2359 template<int size
, bool big_endian
>
2361 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2363 this->base_read_symbols(sd
);
2364 if (this->input_file()->format() != Input_file::FORMAT_ELF
)
2368 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2369 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2370 const unsigned int loccount
= this->do_local_symbol_count();
2373 this->st_other_
.resize(loccount
);
2374 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2375 off_t locsize
= loccount
* sym_size
;
2376 const unsigned int symtab_shndx
= this->symtab_shndx();
2377 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2378 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2379 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2380 locsize
, true, false);
2382 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2384 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2385 unsigned char st_other
= sym
.get_st_other();
2386 this->st_other_
[i
] = st_other
;
2387 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2389 if (this->abiversion() == 0)
2390 this->set_abiversion(2);
2391 else if (this->abiversion() < 2)
2392 gold_error(_("%s: local symbol %d has invalid st_other"
2393 " for ABI version 1"),
2394 this->name().c_str(), i
);
2400 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2401 const unsigned char* ps
= sd
->section_headers
->data() + shdr_size
;
2402 bool merge_attributes
= false;
2403 for (unsigned int i
= 1; i
< this->shnum(); ++i
, ps
+= shdr_size
)
2405 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2406 switch (shdr
.get_sh_type())
2408 case elfcpp::SHT_GNU_ATTRIBUTES
:
2410 gold_assert(this->attributes_section_data_
== NULL
);
2411 section_offset_type section_offset
= shdr
.get_sh_offset();
2412 section_size_type section_size
=
2413 convert_to_section_size_type(shdr
.get_sh_size());
2414 const unsigned char* view
=
2415 this->get_view(section_offset
, section_size
, true, false);
2416 this->attributes_section_data_
=
2417 new Attributes_section_data(view
, section_size
);
2421 case elfcpp::SHT_SYMTAB
:
2423 // Sometimes an object has no contents except the section
2424 // name string table and an empty symbol table with the
2425 // undefined symbol. We don't want to merge
2426 // processor-specific flags from such an object.
2427 const typename
elfcpp::Elf_types
<size
>::Elf_WXword sym_size
=
2428 elfcpp::Elf_sizes
<size
>::sym_size
;
2429 if (shdr
.get_sh_size() > sym_size
)
2430 merge_attributes
= true;
2434 case elfcpp::SHT_STRTAB
:
2438 merge_attributes
= true;
2443 if (!merge_attributes
)
2445 // Should rarely happen.
2446 delete this->attributes_section_data_
;
2447 this->attributes_section_data_
= NULL
;
2451 template<int size
, bool big_endian
>
2453 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2455 this->e_flags_
|= ver
;
2456 if (this->abiversion() != 0)
2458 Target_powerpc
<size
, big_endian
>* target
=
2459 static_cast<Target_powerpc
<size
, big_endian
>*>(
2460 parameters
->sized_target
<size
, big_endian
>());
2461 if (target
->abiversion() == 0)
2462 target
->set_abiversion(this->abiversion());
2463 else if (target
->abiversion() != this->abiversion())
2464 gold_error(_("%s: ABI version %d is not compatible "
2465 "with ABI version %d output"),
2466 this->name().c_str(),
2467 this->abiversion(), target
->abiversion());
2472 // Call Sized_dynobj::base_read_symbols to read the symbols then
2473 // read .opd from a dynamic object, filling in opd_ent_ vector,
2475 template<int size
, bool big_endian
>
2477 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2479 this->base_read_symbols(sd
);
2480 const size_t shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2481 const unsigned char* ps
=
2482 sd
->section_headers
->data() + shdr_size
* (this->shnum() - 1);
2483 for (unsigned int i
= this->shnum(); i
> 0; --i
, ps
-= shdr_size
)
2485 elfcpp::Shdr
<size
, big_endian
> shdr(ps
);
2486 if (shdr
.get_sh_type() == elfcpp::SHT_GNU_ATTRIBUTES
)
2488 section_offset_type section_offset
= shdr
.get_sh_offset();
2489 section_size_type section_size
=
2490 convert_to_section_size_type(shdr
.get_sh_size());
2491 const unsigned char* view
=
2492 this->get_view(section_offset
, section_size
, true, false);
2493 this->attributes_section_data_
=
2494 new Attributes_section_data(view
, section_size
);
2500 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2501 const unsigned char* namesu
= sd
->section_names
->data();
2502 const char* names
= reinterpret_cast<const char*>(namesu
);
2503 const unsigned char* s
= NULL
;
2504 const unsigned char* opd
;
2505 section_size_type opd_size
;
2507 // Find and read .opd section.
2510 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2511 sd
->section_names_size
,
2516 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2517 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2518 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2520 if (this->abiversion() == 0)
2521 this->set_abiversion(1);
2522 else if (this->abiversion() > 1)
2523 gold_error(_("%s: .opd invalid in abiv%d"),
2524 this->name().c_str(), this->abiversion());
2526 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2527 this->opd_address_
= shdr
.get_sh_addr();
2528 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2529 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2535 // Build set of executable sections.
2536 // Using a set is probably overkill. There is likely to be only
2537 // a few executable sections, typically .init, .text and .fini,
2538 // and they are generally grouped together.
2539 typedef std::set
<Sec_info
> Exec_sections
;
2540 Exec_sections exec_sections
;
2542 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2544 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2545 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2546 && ((shdr
.get_sh_flags()
2547 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2548 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2549 && shdr
.get_sh_size() != 0)
2551 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2552 shdr
.get_sh_size(), i
));
2555 if (exec_sections
.empty())
2558 // Look over the OPD entries. This is complicated by the fact
2559 // that some binaries will use two-word entries while others
2560 // will use the standard three-word entries. In most cases
2561 // the third word (the environment pointer for languages like
2562 // Pascal) is unused and will be zero. If the third word is
2563 // used it should not be pointing into executable sections,
2565 this->init_opd(opd_size
);
2566 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2568 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2569 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2570 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2572 // Chances are that this is the third word of an OPD entry.
2574 typename
Exec_sections::const_iterator e
2575 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2576 if (e
!= exec_sections
.begin())
2579 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2581 // We have an address in an executable section.
2582 // VAL ought to be the function entry, set it up.
2583 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2584 // Skip second word of OPD entry, the TOC pointer.
2588 // If we didn't match any executable sections, we likely
2589 // have a non-zero third word in the OPD entry.
2594 // Relocate sections.
2596 template<int size
, bool big_endian
>
2598 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2599 const Symbol_table
* symtab
, const Layout
* layout
,
2600 const unsigned char* pshdrs
, Output_file
* of
,
2601 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2603 unsigned int start
= 1;
2605 && this->relatoc_
!= 0
2606 && !parameters
->options().relocatable())
2608 // Relocate .toc first.
2609 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2610 this->relatoc_
, this->relatoc_
);
2611 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2612 1, this->relatoc_
- 1);
2613 start
= this->relatoc_
+ 1;
2615 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2616 start
, this->shnum() - 1);
2618 if (!parameters
->options().output_is_position_independent())
2620 Target_powerpc
<size
, big_endian
>* target
2621 = static_cast<Target_powerpc
<size
, big_endian
>*>(
2622 parameters
->sized_target
<size
, big_endian
>());
2623 if (target
->lplt_section() && target
->lplt_section()->data_size() != 0)
2625 const section_size_type offset
= target
->lplt_section()->offset();
2626 const section_size_type oview_size
2627 = convert_to_section_size_type(target
->lplt_section()->data_size());
2628 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2630 bool modified
= false;
2631 unsigned int nsyms
= this->local_symbol_count();
2632 for (unsigned int i
= 0; i
< nsyms
; i
++)
2633 if (this->local_has_plt_offset(i
))
2635 Address value
= this->local_symbol_value(i
, 0);
2637 value
+= ppc64_local_entry_offset(i
);
2638 size_t off
= this->local_plt_offset(i
);
2639 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ off
, value
);
2643 of
->write_output_view(offset
, oview_size
, oview
);
2648 // Set up some symbols.
2650 template<int size
, bool big_endian
>
2652 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2653 Symbol_table
* symtab
,
2658 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2659 // undefined when scanning relocs (and thus requires
2660 // non-relative dynamic relocs). The proper value will be
2662 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2663 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2665 Target_powerpc
<size
, big_endian
>* target
=
2666 static_cast<Target_powerpc
<size
, big_endian
>*>(
2667 parameters
->sized_target
<size
, big_endian
>());
2668 Output_data_got_powerpc
<size
, big_endian
>* got
2669 = target
->got_section(symtab
, layout
);
2670 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2671 Symbol_table::PREDEFINED
,
2675 elfcpp::STV_HIDDEN
, 0,
2679 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2680 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2681 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2683 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2685 = layout
->add_output_section_data(".sdata", 0,
2687 | elfcpp::SHF_WRITE
,
2688 sdata
, ORDER_SMALL_DATA
, false);
2689 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2690 Symbol_table::PREDEFINED
,
2691 os
, 32768, 0, elfcpp::STT_OBJECT
,
2692 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2698 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2699 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2700 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2702 Target_powerpc
<size
, big_endian
>* target
=
2703 static_cast<Target_powerpc
<size
, big_endian
>*>(
2704 parameters
->sized_target
<size
, big_endian
>());
2705 Output_data_got_powerpc
<size
, big_endian
>* got
2706 = target
->got_section(symtab
, layout
);
2707 symtab
->define_in_output_data(".TOC.", NULL
,
2708 Symbol_table::PREDEFINED
,
2712 elfcpp::STV_HIDDEN
, 0,
2717 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2718 if (parameters
->options().tls_get_addr_optimize()
2719 && this->tls_get_addr_
!= NULL
2720 && this->tls_get_addr_
->in_reg())
2721 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2722 if (this->tls_get_addr_opt_
!= NULL
)
2724 if (this->tls_get_addr_
->is_undefined()
2725 || this->tls_get_addr_
->is_from_dynobj())
2727 // Make it seem as if references to __tls_get_addr are
2728 // really to __tls_get_addr_opt, so the latter symbol is
2729 // made dynamic, not the former.
2730 this->tls_get_addr_
->clear_in_reg();
2731 this->tls_get_addr_opt_
->set_in_reg();
2733 // We have a non-dynamic definition for __tls_get_addr.
2734 // Make __tls_get_addr_opt the same, if it does not already have
2735 // a non-dynamic definition.
2736 else if (this->tls_get_addr_opt_
->is_undefined()
2737 || this->tls_get_addr_opt_
->is_from_dynobj())
2739 Sized_symbol
<size
>* from
2740 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2741 Sized_symbol
<size
>* to
2742 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2743 symtab
->clone
<size
>(to
, from
);
2748 // Set up PowerPC target specific relobj.
2750 template<int size
, bool big_endian
>
2752 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2753 const std::string
& name
,
2754 Input_file
* input_file
,
2755 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2757 int et
= ehdr
.get_e_type();
2758 // ET_EXEC files are valid input for --just-symbols/-R,
2759 // and we treat them as relocatable objects.
2760 if (et
== elfcpp::ET_REL
2761 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2763 Powerpc_relobj
<size
, big_endian
>* obj
=
2764 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2768 else if (et
== elfcpp::ET_DYN
)
2770 Powerpc_dynobj
<size
, big_endian
>* obj
=
2771 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2777 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2782 template<int size
, bool big_endian
>
2783 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2786 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2787 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2789 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2790 : Output_data_got
<size
, big_endian
>(),
2791 symtab_(symtab
), layout_(layout
),
2792 header_ent_cnt_(size
== 32 ? 3 : 1),
2793 header_index_(size
== 32 ? 0x2000 : 0)
2796 this->set_addralign(256);
2799 // Override all the Output_data_got methods we use so as to first call
2802 add_global(Symbol
* gsym
, unsigned int got_type
)
2804 this->reserve_ent();
2805 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2809 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2811 this->reserve_ent();
2812 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2816 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2817 { return this->add_global_plt(gsym
, got_type
); }
2820 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2821 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2823 this->reserve_ent();
2824 Output_data_got
<size
, big_endian
>::
2825 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2829 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2830 Output_data_reloc_generic
* rel_dyn
,
2831 unsigned int r_type_1
, unsigned int r_type_2
)
2833 if (gsym
->has_got_offset(got_type
))
2836 this->reserve_ent(2);
2837 Output_data_got
<size
, big_endian
>::
2838 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2842 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2844 this->reserve_ent();
2845 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2850 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2852 this->reserve_ent();
2853 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2858 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2859 { return this->add_local_plt(object
, sym_index
, got_type
); }
2862 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2863 unsigned int got_type
,
2864 Output_data_reloc_generic
* rel_dyn
,
2865 unsigned int r_type
)
2867 if (object
->local_has_got_offset(sym_index
, got_type
))
2870 this->reserve_ent(2);
2871 Output_data_got
<size
, big_endian
>::
2872 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2876 add_constant(Valtype constant
)
2878 this->reserve_ent();
2879 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2883 add_constant_pair(Valtype c1
, Valtype c2
)
2885 this->reserve_ent(2);
2886 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2889 // Offset of _GLOBAL_OFFSET_TABLE_.
2893 return this->got_offset(this->header_index_
);
2896 // Offset of base used to access the GOT/TOC.
2897 // The got/toc pointer reg will be set to this value.
2899 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2902 return this->g_o_t();
2904 return (this->output_section()->address()
2905 + object
->toc_base_offset()
2909 // Ensure our GOT has a header.
2911 set_final_data_size()
2913 if (this->header_ent_cnt_
!= 0)
2914 this->make_header();
2915 Output_data_got
<size
, big_endian
>::set_final_data_size();
2918 // First word of GOT header needs some values that are not
2919 // handled by Output_data_got so poke them in here.
2920 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2922 do_write(Output_file
* of
)
2925 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2926 val
= this->layout_
->dynamic_section()->address();
2928 val
= this->output_section()->address() + 0x8000;
2929 this->replace_constant(this->header_index_
, val
);
2930 Output_data_got
<size
, big_endian
>::do_write(of
);
2935 reserve_ent(unsigned int cnt
= 1)
2937 if (this->header_ent_cnt_
== 0)
2939 if (this->num_entries() + cnt
> this->header_index_
)
2940 this->make_header();
2946 this->header_ent_cnt_
= 0;
2947 this->header_index_
= this->num_entries();
2950 Output_data_got
<size
, big_endian
>::add_constant(0);
2951 Output_data_got
<size
, big_endian
>::add_constant(0);
2952 Output_data_got
<size
, big_endian
>::add_constant(0);
2954 // Define _GLOBAL_OFFSET_TABLE_ at the header
2955 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2958 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2959 sym
->set_value(this->g_o_t());
2962 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2963 Symbol_table::PREDEFINED
,
2964 this, this->g_o_t(), 0,
2967 elfcpp::STV_HIDDEN
, 0,
2971 Output_data_got
<size
, big_endian
>::add_constant(0);
2974 // Stashed pointers.
2975 Symbol_table
* symtab_
;
2979 unsigned int header_ent_cnt_
;
2980 // GOT header index.
2981 unsigned int header_index_
;
2984 // Get the GOT section, creating it if necessary.
2986 template<int size
, bool big_endian
>
2987 Output_data_got_powerpc
<size
, big_endian
>*
2988 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2991 if (this->got_
== NULL
)
2993 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2996 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2998 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2999 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3000 this->got_
, ORDER_DATA
, false);
3006 // Get the dynamic reloc section, creating it if necessary.
3008 template<int size
, bool big_endian
>
3009 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3010 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
3012 if (this->rela_dyn_
== NULL
)
3014 gold_assert(layout
!= NULL
);
3015 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
3016 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
3017 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
3018 ORDER_DYNAMIC_RELOCS
, false);
3020 return this->rela_dyn_
;
3023 // Similarly, but for ifunc symbols get the one for ifunc.
3025 template<int size
, bool big_endian
>
3026 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
3027 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
3032 return this->rela_dyn_section(layout
);
3034 if (this->iplt_
== NULL
)
3035 this->make_iplt_section(symtab
, layout
);
3036 return this->iplt_
->rel_plt();
3042 // Determine the stub group size. The group size is the absolute
3043 // value of the parameter --stub-group-size. If --stub-group-size
3044 // is passed a negative value, we restrict stubs to be always after
3045 // the stubbed branches.
3046 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
3047 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
3048 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
3049 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
3050 owner_(NULL
), output_section_(NULL
)
3054 // Return true iff input section can be handled by current stub
3057 can_add_to_stub_group(Output_section
* o
,
3058 const Output_section::Input_section
* i
,
3061 const Output_section::Input_section
*
3067 { return output_section_
; }
3070 set_output_and_owner(Output_section
* o
,
3071 const Output_section::Input_section
* i
)
3073 this->output_section_
= o
;
3082 // Adding group sections before the stubs.
3083 FINDING_STUB_SECTION
,
3084 // Adding group sections after the stubs.
3088 uint32_t stub_group_size_
;
3089 bool stubs_always_after_branch_
;
3090 bool suppress_size_errors_
;
3091 // True if a stub group can serve multiple output sections.
3094 // Current max size of group. Starts at stub_group_size_ but is
3095 // reduced to stub_group_size_/1024 on seeing a section with
3096 // external conditional branches.
3097 uint32_t group_size_
;
3098 uint64_t group_start_addr_
;
3099 // owner_ and output_section_ specify the section to which stubs are
3100 // attached. The stubs are placed at the end of this section.
3101 const Output_section::Input_section
* owner_
;
3102 Output_section
* output_section_
;
3105 // Return true iff input section can be handled by current stub
3106 // group. Sections are presented to this function in order,
3107 // so the first section is the head of the group.
3110 Stub_control::can_add_to_stub_group(Output_section
* o
,
3111 const Output_section::Input_section
* i
,
3114 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
3116 uint64_t start_addr
= o
->address();
3119 // .init and .fini sections are pasted together to form a single
3120 // function. We can't be adding stubs in the middle of the function.
3121 this_size
= o
->data_size();
3124 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
3125 this_size
= i
->data_size();
3128 uint64_t end_addr
= start_addr
+ this_size
;
3129 uint32_t group_size
= this->stub_group_size_
;
3131 this->group_size_
= group_size
= group_size
>> 10;
3133 if (this_size
> group_size
&& !this->suppress_size_errors_
)
3134 gold_warning(_("%s:%s exceeds group size"),
3135 i
->relobj()->name().c_str(),
3136 i
->relobj()->section_name(i
->shndx()).c_str());
3138 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
3139 has14
? " 14bit" : "",
3140 i
->relobj()->name().c_str(),
3141 i
->relobj()->section_name(i
->shndx()).c_str(),
3142 (long long) this_size
,
3143 (this->state_
== NO_GROUP
3145 : (long long) end_addr
- this->group_start_addr_
));
3147 if (this->state_
== NO_GROUP
)
3149 // Only here on very first use of Stub_control
3151 this->output_section_
= o
;
3152 this->state_
= FINDING_STUB_SECTION
;
3153 this->group_size_
= group_size
;
3154 this->group_start_addr_
= start_addr
;
3157 else if (!this->multi_os_
&& this->output_section_
!= o
)
3159 else if (this->state_
== HAS_STUB_SECTION
)
3161 // Can we add this section, which is after the stubs, to the
3163 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
3166 else if (this->state_
== FINDING_STUB_SECTION
)
3168 if ((whole_sec
&& this->output_section_
== o
)
3169 || end_addr
- this->group_start_addr_
<= this->group_size_
)
3171 // Stubs are added at the end of "owner_".
3173 this->output_section_
= o
;
3176 // The group before the stubs has reached maximum size.
3177 // Now see about adding sections after the stubs to the
3178 // group. If the current section has a 14-bit branch and
3179 // the group before the stubs exceeds group_size_ (because
3180 // they didn't have 14-bit branches), don't add sections
3181 // after the stubs: The size of stubs for such a large
3182 // group may exceed the reach of a 14-bit branch.
3183 if (!this->stubs_always_after_branch_
3184 && this_size
<= this->group_size_
3185 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3187 gold_debug(DEBUG_TARGET
, "adding after stubs");
3188 this->state_
= HAS_STUB_SECTION
;
3189 this->group_start_addr_
= start_addr
;
3196 gold_debug(DEBUG_TARGET
,
3197 !this->multi_os_
&& this->output_section_
!= o
3198 ? "nope, new output section\n"
3199 : "nope, didn't fit\n");
3201 // The section fails to fit in the current group. Set up a few
3202 // things for the next group. owner_ and output_section_ will be
3203 // set later after we've retrieved those values for the current
3205 this->state_
= FINDING_STUB_SECTION
;
3206 this->group_size_
= group_size
;
3207 this->group_start_addr_
= start_addr
;
3211 // Look over all the input sections, deciding where to place stubs.
3213 template<int size
, bool big_endian
>
3215 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3217 bool no_size_errors
)
3219 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3220 parameters
->options().stub_group_multi());
3222 // Group input sections and insert stub table
3223 Stub_table_owner
* table_owner
= NULL
;
3224 std::vector
<Stub_table_owner
*> tables
;
3225 Layout::Section_list section_list
;
3226 layout
->get_executable_sections(§ion_list
);
3227 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3228 for (Layout::Section_list::iterator o
= section_list
.begin();
3229 o
!= section_list
.end();
3232 typedef Output_section::Input_section_list Input_section_list
;
3233 for (Input_section_list::const_iterator i
3234 = (*o
)->input_sections().begin();
3235 i
!= (*o
)->input_sections().end();
3238 if (i
->is_input_section()
3239 || i
->is_relaxed_input_section())
3241 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3242 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3243 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3244 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3246 table_owner
->output_section
= stub_control
.output_section();
3247 table_owner
->owner
= stub_control
.owner();
3248 stub_control
.set_output_and_owner(*o
, &*i
);
3251 if (table_owner
== NULL
)
3253 table_owner
= new Stub_table_owner
;
3254 tables
.push_back(table_owner
);
3256 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3260 if (table_owner
!= NULL
)
3262 table_owner
->output_section
= stub_control
.output_section();
3263 table_owner
->owner
= stub_control
.owner();;
3265 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3269 Stub_table
<size
, big_endian
>* stub_table
;
3271 if ((*t
)->owner
->is_input_section())
3272 stub_table
= new Stub_table
<size
, big_endian
>(this,
3273 (*t
)->output_section
,
3275 this->stub_tables_
.size());
3276 else if ((*t
)->owner
->is_relaxed_input_section())
3277 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3278 (*t
)->owner
->relaxed_input_section());
3281 this->stub_tables_
.push_back(stub_table
);
3287 static unsigned long
3288 max_branch_delta (unsigned int r_type
)
3290 if (r_type
== elfcpp::R_POWERPC_REL14
3291 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3292 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3294 if (r_type
== elfcpp::R_POWERPC_REL24
3295 || (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
3296 || r_type
== elfcpp::R_PPC_PLTREL24
3297 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3302 // Return whether this branch is going via a plt call stub.
3304 template<int size
, bool big_endian
>
3306 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3307 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3310 Target_powerpc
* target
,
3311 Symbol_table
* symtab
)
3313 if (this->object_
!= ppc_object
3314 || this->shndx_
!= shndx
3315 || this->offset_
!= offset
)
3318 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3319 if (sym
!= NULL
&& sym
->is_forwarder())
3320 sym
= symtab
->resolve_forwards(sym
);
3321 if (target
->replace_tls_get_addr(sym
))
3322 sym
= target
->tls_get_addr_opt();
3323 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3325 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3326 && !target
->is_elfv2_localentry0(gsym
))
3327 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3328 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3336 // If this branch needs a plt call stub, or a long branch stub, make one.
3338 template<int size
, bool big_endian
>
3340 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3341 Stub_table
<size
, big_endian
>* stub_table
,
3342 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3343 Symbol_table
* symtab
) const
3345 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3346 Target_powerpc
<size
, big_endian
>* target
=
3347 static_cast<Target_powerpc
<size
, big_endian
>*>(
3348 parameters
->sized_target
<size
, big_endian
>());
3349 if (sym
!= NULL
&& sym
->is_forwarder())
3350 sym
= symtab
->resolve_forwards(sym
);
3351 if (target
->replace_tls_get_addr(sym
))
3352 sym
= target
->tls_get_addr_opt();
3353 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3357 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3358 : this->object_
->local_has_plt_offset(this->r_sym_
))
3362 && target
->abiversion() >= 2
3363 && !parameters
->options().output_is_position_independent()
3364 && !is_branch_reloc
<size
>(this->r_type_
))
3365 target
->glink_section()->add_global_entry(gsym
);
3368 if (stub_table
== NULL
3371 && !parameters
->options().output_is_position_independent()
3372 && !is_branch_reloc
<size
>(this->r_type_
)))
3373 stub_table
= this->object_
->stub_table(this->shndx_
);
3374 if (stub_table
== NULL
)
3376 // This is a ref from a data section to an ifunc symbol,
3377 // or a non-branch reloc for which we always want to use
3378 // one set of stubs for resolving function addresses.
3379 stub_table
= ifunc_stub_table
;
3381 gold_assert(stub_table
!= NULL
);
3382 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3383 if (from
!= invalid_address
)
3384 from
+= (this->object_
->output_section(this->shndx_
)->address()
3387 ok
= stub_table
->add_plt_call_entry(from
,
3388 this->object_
, gsym
,
3389 this->r_type_
, this->addend_
,
3392 ok
= stub_table
->add_plt_call_entry(from
,
3393 this->object_
, this->r_sym_
,
3394 this->r_type_
, this->addend_
,
3400 Address max_branch_offset
= max_branch_delta
<size
>(this->r_type_
);
3401 if (max_branch_offset
== 0)
3403 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3404 gold_assert(from
!= invalid_address
);
3405 from
+= (this->object_
->output_section(this->shndx_
)->address()
3410 switch (gsym
->source())
3412 case Symbol::FROM_OBJECT
:
3414 Object
* symobj
= gsym
->object();
3415 if (symobj
->is_dynamic()
3416 || symobj
->pluginobj() != NULL
)
3419 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3420 if (shndx
== elfcpp::SHN_UNDEF
)
3425 case Symbol::IS_UNDEFINED
:
3431 Symbol_table::Compute_final_value_status status
;
3432 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3433 if (status
!= Symbol_table::CFVS_OK
)
3436 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3440 const Symbol_value
<size
>* psymval
3441 = this->object_
->local_symbol(this->r_sym_
);
3442 Symbol_value
<size
> symval
;
3443 if (psymval
->is_section_symbol())
3444 symval
.set_is_section_symbol();
3445 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3446 typename
ObjType::Compute_final_local_value_status status
3447 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3449 if (status
!= ObjType::CFLV_OK
3450 || !symval
.has_output_value())
3452 to
= symval
.value(this->object_
, 0);
3454 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3456 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3457 to
+= this->addend_
;
3458 if (stub_table
== NULL
)
3459 stub_table
= this->object_
->stub_table(this->shndx_
);
3460 if (size
== 64 && target
->abiversion() < 2)
3462 unsigned int dest_shndx
;
3463 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3467 Address delta
= to
- from
;
3468 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
3470 && this->r_type_
== elfcpp::R_PPC64_REL24_NOTOC
3472 ? this->object_
->ppc64_needs_toc(gsym
)
3473 : this->object_
->ppc64_needs_toc(this->r_sym_
))))
3475 if (stub_table
== NULL
)
3477 gold_warning(_("%s:%s: branch in non-executable section,"
3478 " no long branch stub for you"),
3479 this->object_
->name().c_str(),
3480 this->object_
->section_name(this->shndx_
).c_str());
3483 bool save_res
= (size
== 64
3485 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3486 && gsym
->output_data() == target
->savres_section());
3487 ok
= stub_table
->add_long_branch_entry(this->object_
,
3489 from
, to
, save_res
);
3493 gold_debug(DEBUG_TARGET
,
3494 "branch at %s:%s+%#lx\n"
3495 "can't reach stub attached to %s:%s",
3496 this->object_
->name().c_str(),
3497 this->object_
->section_name(this->shndx_
).c_str(),
3498 (unsigned long) this->offset_
,
3499 stub_table
->relobj()->name().c_str(),
3500 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3505 // Relaxation hook. This is where we do stub generation.
3507 template<int size
, bool big_endian
>
3509 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3510 const Input_objects
*,
3511 Symbol_table
* symtab
,
3515 unsigned int prev_brlt_size
= 0;
3519 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3521 && this->abiversion() < 2
3523 && !parameters
->options().user_set_plt_thread_safe())
3525 static const char* const thread_starter
[] =
3529 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3531 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3532 "mq_notify", "create_timer",
3537 "GOMP_parallel_start",
3538 "GOMP_parallel_loop_static",
3539 "GOMP_parallel_loop_static_start",
3540 "GOMP_parallel_loop_dynamic",
3541 "GOMP_parallel_loop_dynamic_start",
3542 "GOMP_parallel_loop_guided",
3543 "GOMP_parallel_loop_guided_start",
3544 "GOMP_parallel_loop_runtime",
3545 "GOMP_parallel_loop_runtime_start",
3546 "GOMP_parallel_sections",
3547 "GOMP_parallel_sections_start",
3552 if (parameters
->options().shared())
3556 for (unsigned int i
= 0;
3557 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3560 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3561 thread_safe
= (sym
!= NULL
3563 && sym
->in_real_elf());
3569 this->plt_thread_safe_
= thread_safe
;
3574 this->stub_group_size_
= parameters
->options().stub_group_size();
3575 bool no_size_errors
= true;
3576 if (this->stub_group_size_
== 1)
3577 this->stub_group_size_
= 0x1c00000;
3578 else if (this->stub_group_size_
== -1)
3579 this->stub_group_size_
= -0x1e00000;
3581 no_size_errors
= false;
3582 this->group_sections(layout
, task
, no_size_errors
);
3584 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3586 this->branch_lookup_table_
.clear();
3587 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3588 p
!= this->stub_tables_
.end();
3591 (*p
)->clear_stubs(true);
3593 this->stub_tables_
.clear();
3594 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3595 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3596 program_name
, this->stub_group_size_
);
3597 this->group_sections(layout
, task
, true);
3600 // We need address of stub tables valid for make_stub.
3601 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3602 p
!= this->stub_tables_
.end();
3605 const Powerpc_relobj
<size
, big_endian
>* object
3606 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3607 Address off
= object
->get_output_section_offset((*p
)->shndx());
3608 gold_assert(off
!= invalid_address
);
3609 Output_section
* os
= (*p
)->output_section();
3610 (*p
)->set_address_and_size(os
, off
);
3615 // Clear plt call stubs, long branch stubs and branch lookup table.
3616 prev_brlt_size
= this->branch_lookup_table_
.size();
3617 this->branch_lookup_table_
.clear();
3618 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3619 p
!= this->stub_tables_
.end();
3622 (*p
)->clear_stubs(false);
3626 // Build all the stubs.
3627 this->relax_failed_
= false;
3628 Stub_table
<size
, big_endian
>* ifunc_stub_table
3629 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3630 Stub_table
<size
, big_endian
>* one_stub_table
3631 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3632 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3633 b
!= this->branch_info_
.end();
3636 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3637 && !this->relax_failed_
)
3639 this->relax_failed_
= true;
3640 this->relax_fail_count_
++;
3641 if (this->relax_fail_count_
< 3)
3645 bool do_resize
= false;
3646 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3647 p
!= this->stub_tables_
.end();
3649 if ((*p
)->need_resize())
3656 this->branch_lookup_table_
.clear();
3657 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3658 p
!= this->stub_tables_
.end();
3660 (*p
)->set_resizing(true);
3661 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3662 b
!= this->branch_info_
.end();
3665 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3666 && !this->relax_failed_
)
3668 this->relax_failed_
= true;
3669 this->relax_fail_count_
++;
3670 if (this->relax_fail_count_
< 3)
3674 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3675 p
!= this->stub_tables_
.end();
3677 (*p
)->set_resizing(false);
3680 // Did anything change size?
3681 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3682 bool again
= num_huge_branches
!= prev_brlt_size
;
3683 if (size
== 64 && num_huge_branches
!= 0)
3684 this->make_brlt_section(layout
);
3685 if (size
== 64 && again
)
3686 this->brlt_section_
->set_current_size(num_huge_branches
);
3688 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3689 p
!= this->stub_tables_
.rend();
3691 (*p
)->remove_eh_frame(layout
);
3693 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3694 p
!= this->stub_tables_
.end();
3696 (*p
)->add_eh_frame(layout
);
3698 typedef Unordered_set
<Output_section
*> Output_sections
;
3699 Output_sections os_need_update
;
3700 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3701 p
!= this->stub_tables_
.end();
3704 if ((*p
)->size_update())
3707 os_need_update
.insert((*p
)->output_section());
3711 // Set output section offsets for all input sections in an output
3712 // section that just changed size. Anything past the stubs will
3714 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3715 p
!= os_need_update
.end();
3718 Output_section
* os
= *p
;
3720 typedef Output_section::Input_section_list Input_section_list
;
3721 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3722 i
!= os
->input_sections().end();
3725 off
= align_address(off
, i
->addralign());
3726 if (i
->is_input_section() || i
->is_relaxed_input_section())
3727 i
->relobj()->set_section_offset(i
->shndx(), off
);
3728 if (i
->is_relaxed_input_section())
3730 Stub_table
<size
, big_endian
>* stub_table
3731 = static_cast<Stub_table
<size
, big_endian
>*>(
3732 i
->relaxed_input_section());
3733 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3734 off
+= stub_table_size
;
3735 // After a few iterations, set current stub table size
3736 // as min size threshold, so later stub tables can only
3739 stub_table
->set_min_size_threshold(stub_table_size
);
3742 off
+= i
->data_size();
3744 // If .branch_lt is part of this output section, then we have
3745 // just done the offset adjustment.
3746 os
->clear_section_offsets_need_adjustment();
3751 && num_huge_branches
!= 0
3752 && parameters
->options().output_is_position_independent())
3754 // Fill in the BRLT relocs.
3755 this->brlt_section_
->reset_brlt_sizes();
3756 for (typename
Branch_lookup_table::const_iterator p
3757 = this->branch_lookup_table_
.begin();
3758 p
!= this->branch_lookup_table_
.end();
3761 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3763 this->brlt_section_
->finalize_brlt_sizes();
3767 && (parameters
->options().user_set_emit_stub_syms()
3768 ? parameters
->options().emit_stub_syms()
3770 || parameters
->options().output_is_position_independent()
3771 || parameters
->options().emit_relocs())))
3773 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3774 p
!= this->stub_tables_
.end();
3776 (*p
)->define_stub_syms(symtab
);
3778 if (this->glink_
!= NULL
)
3780 int stub_size
= this->glink_
->pltresolve_size();
3781 Address value
= -stub_size
;
3787 this->define_local(symtab
, "__glink_PLTresolve",
3788 this->glink_
, value
, stub_size
);
3791 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3798 template<int size
, bool big_endian
>
3800 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3801 unsigned char* oview
,
3805 uint64_t address
= plt
->address();
3806 off_t len
= plt
->data_size();
3808 if (plt
== this->glink_
)
3810 // See Output_data_glink::do_write() for glink contents.
3813 gold_assert(parameters
->doing_static_link());
3814 // Static linking may need stubs, to support ifunc and long
3815 // branches. We need to create an output section for
3816 // .eh_frame early in the link process, to have a place to
3817 // attach stub .eh_frame info. We also need to have
3818 // registered a CIE that matches the stub CIE. Both of
3819 // these requirements are satisfied by creating an FDE and
3820 // CIE for .glink, even though static linking will leave
3821 // .glink zero length.
3822 // ??? Hopefully generating an FDE with a zero address range
3823 // won't confuse anything that consumes .eh_frame info.
3825 else if (size
== 64)
3827 // There is one word before __glink_PLTresolve
3831 else if (parameters
->options().output_is_position_independent())
3833 // There are two FDEs for a position independent glink.
3834 // The first covers the branch table, the second
3835 // __glink_PLTresolve at the end of glink.
3836 off_t resolve_size
= this->glink_
->pltresolve_size();
3837 if (oview
[9] == elfcpp::DW_CFA_nop
)
3838 len
-= resolve_size
;
3841 address
+= len
- resolve_size
;
3848 // Must be a stub table.
3849 const Stub_table
<size
, big_endian
>* stub_table
3850 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3851 uint64_t stub_address
= stub_table
->stub_address();
3852 len
-= stub_address
- address
;
3853 address
= stub_address
;
3856 *paddress
= address
;
3860 // A class to handle the PLT data.
3862 template<int size
, bool big_endian
>
3863 class Output_data_plt_powerpc
: public Output_section_data_build
3866 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3867 size
, big_endian
> Reloc_section
;
3869 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3870 Reloc_section
* plt_rel
,
3872 : Output_section_data_build(size
== 32 ? 4 : 8),
3878 // Add an entry to the PLT.
3883 add_ifunc_entry(Symbol
*);
3886 add_local_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3889 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3891 // Return the .rela.plt section data.
3898 // Return the number of PLT entries.
3902 if (this->current_data_size() == 0)
3904 return ((this->current_data_size() - this->first_plt_entry_offset())
3905 / this->plt_entry_size());
3910 do_adjust_output_section(Output_section
* os
)
3915 // Write to a map file.
3917 do_print_to_mapfile(Mapfile
* mapfile
) const
3918 { mapfile
->print_output_data(this, this->name_
); }
3921 // Return the offset of the first non-reserved PLT entry.
3923 first_plt_entry_offset() const
3925 // IPLT and LPLT have no reserved entry.
3926 if (this->name_
[3] == 'I' || this->name_
[3] == 'L')
3928 return this->targ_
->first_plt_entry_offset();
3931 // Return the size of each PLT entry.
3933 plt_entry_size() const
3935 return this->targ_
->plt_entry_size();
3938 // Write out the PLT data.
3940 do_write(Output_file
*);
3942 // The reloc section.
3943 Reloc_section
* rel_
;
3944 // Allows access to .glink for do_write.
3945 Target_powerpc
<size
, big_endian
>* targ_
;
3946 // What to report in map file.
3950 // Add an entry to the PLT.
3952 template<int size
, bool big_endian
>
3954 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3956 if (!gsym
->has_plt_offset())
3958 section_size_type off
= this->current_data_size();
3960 off
+= this->first_plt_entry_offset();
3961 gsym
->set_plt_offset(off
);
3962 gsym
->set_needs_dynsym_entry();
3963 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3964 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3965 off
+= this->plt_entry_size();
3966 this->set_current_data_size(off
);
3970 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3972 template<int size
, bool big_endian
>
3974 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3976 if (!gsym
->has_plt_offset())
3978 section_size_type off
= this->current_data_size();
3979 gsym
->set_plt_offset(off
);
3980 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3981 if (size
== 64 && this->targ_
->abiversion() < 2)
3982 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3983 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3984 off
+= this->plt_entry_size();
3985 this->set_current_data_size(off
);
3989 // Add an entry for a local symbol to the PLT.
3991 template<int size
, bool big_endian
>
3993 Output_data_plt_powerpc
<size
, big_endian
>::add_local_entry(
3994 Sized_relobj_file
<size
, big_endian
>* relobj
,
3995 unsigned int local_sym_index
)
3997 if (!relobj
->local_has_plt_offset(local_sym_index
))
3999 section_size_type off
= this->current_data_size();
4000 relobj
->set_local_plt_offset(local_sym_index
, off
);
4003 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4004 if (size
== 64 && this->targ_
->abiversion() < 2)
4005 dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
4006 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
,
4007 dynrel
, this, off
, 0);
4009 off
+= this->plt_entry_size();
4010 this->set_current_data_size(off
);
4014 // Add an entry for a local ifunc symbol to the IPLT.
4016 template<int size
, bool big_endian
>
4018 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
4019 Sized_relobj_file
<size
, big_endian
>* relobj
,
4020 unsigned int local_sym_index
)
4022 if (!relobj
->local_has_plt_offset(local_sym_index
))
4024 section_size_type off
= this->current_data_size();
4025 relobj
->set_local_plt_offset(local_sym_index
, off
);
4026 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4027 if (size
== 64 && this->targ_
->abiversion() < 2)
4028 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
4029 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
4031 off
+= this->plt_entry_size();
4032 this->set_current_data_size(off
);
4036 static const uint32_t add_0_11_11
= 0x7c0b5a14;
4037 static const uint32_t add_2_2_11
= 0x7c425a14;
4038 static const uint32_t add_2_2_12
= 0x7c426214;
4039 static const uint32_t add_3_3_2
= 0x7c631214;
4040 static const uint32_t add_3_3_13
= 0x7c636a14;
4041 static const uint32_t add_3_12_2
= 0x7c6c1214;
4042 static const uint32_t add_3_12_13
= 0x7c6c6a14;
4043 static const uint32_t add_11_0_11
= 0x7d605a14;
4044 static const uint32_t add_11_2_11
= 0x7d625a14;
4045 static const uint32_t add_11_11_2
= 0x7d6b1214;
4046 static const uint32_t add_12_11_12
= 0x7d8b6214;
4047 static const uint32_t addi_0_12
= 0x380c0000;
4048 static const uint32_t addi_2_2
= 0x38420000;
4049 static const uint32_t addi_3_3
= 0x38630000;
4050 static const uint32_t addi_11_11
= 0x396b0000;
4051 static const uint32_t addi_12_1
= 0x39810000;
4052 static const uint32_t addi_12_11
= 0x398b0000;
4053 static const uint32_t addi_12_12
= 0x398c0000;
4054 static const uint32_t addis_0_2
= 0x3c020000;
4055 static const uint32_t addis_0_13
= 0x3c0d0000;
4056 static const uint32_t addis_2_12
= 0x3c4c0000;
4057 static const uint32_t addis_11_2
= 0x3d620000;
4058 static const uint32_t addis_11_11
= 0x3d6b0000;
4059 static const uint32_t addis_11_30
= 0x3d7e0000;
4060 static const uint32_t addis_12_1
= 0x3d810000;
4061 static const uint32_t addis_12_2
= 0x3d820000;
4062 static const uint32_t addis_12_11
= 0x3d8b0000;
4063 static const uint32_t addis_12_12
= 0x3d8c0000;
4064 static const uint32_t b
= 0x48000000;
4065 static const uint32_t bcl_20_31
= 0x429f0005;
4066 static const uint32_t bctr
= 0x4e800420;
4067 static const uint32_t bctrl
= 0x4e800421;
4068 static const uint32_t beqlr
= 0x4d820020;
4069 static const uint32_t blr
= 0x4e800020;
4070 static const uint32_t bnectr_p4
= 0x4ce20420;
4071 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
4072 static const uint32_t cmpldi_2_0
= 0x28220000;
4073 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
4074 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
4075 static const uint32_t cror_15_15_15
= 0x4def7b82;
4076 static const uint32_t cror_31_31_31
= 0x4ffffb82;
4077 static const uint32_t ld_0_1
= 0xe8010000;
4078 static const uint32_t ld_0_12
= 0xe80c0000;
4079 static const uint32_t ld_2_1
= 0xe8410000;
4080 static const uint32_t ld_2_2
= 0xe8420000;
4081 static const uint32_t ld_2_11
= 0xe84b0000;
4082 static const uint32_t ld_2_12
= 0xe84c0000;
4083 static const uint32_t ld_11_1
= 0xe9610000;
4084 static const uint32_t ld_11_2
= 0xe9620000;
4085 static const uint32_t ld_11_3
= 0xe9630000;
4086 static const uint32_t ld_11_11
= 0xe96b0000;
4087 static const uint32_t ld_12_2
= 0xe9820000;
4088 static const uint32_t ld_12_3
= 0xe9830000;
4089 static const uint32_t ld_12_11
= 0xe98b0000;
4090 static const uint32_t ld_12_12
= 0xe98c0000;
4091 static const uint32_t ldx_12_11_12
= 0x7d8b602a;
4092 static const uint32_t lfd_0_1
= 0xc8010000;
4093 static const uint32_t li_0_0
= 0x38000000;
4094 static const uint32_t li_12_0
= 0x39800000;
4095 static const uint32_t lis_0
= 0x3c000000;
4096 static const uint32_t lis_2
= 0x3c400000;
4097 static const uint32_t lis_11
= 0x3d600000;
4098 static const uint32_t lis_12
= 0x3d800000;
4099 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
4100 static const uint32_t lwz_0_12
= 0x800c0000;
4101 static const uint32_t lwz_11_3
= 0x81630000;
4102 static const uint32_t lwz_11_11
= 0x816b0000;
4103 static const uint32_t lwz_11_30
= 0x817e0000;
4104 static const uint32_t lwz_12_3
= 0x81830000;
4105 static const uint32_t lwz_12_12
= 0x818c0000;
4106 static const uint32_t lwzu_0_12
= 0x840c0000;
4107 static const uint32_t mflr_0
= 0x7c0802a6;
4108 static const uint32_t mflr_11
= 0x7d6802a6;
4109 static const uint32_t mflr_12
= 0x7d8802a6;
4110 static const uint32_t mr_0_3
= 0x7c601b78;
4111 static const uint32_t mr_3_0
= 0x7c030378;
4112 static const uint32_t mtctr_0
= 0x7c0903a6;
4113 static const uint32_t mtctr_11
= 0x7d6903a6;
4114 static const uint32_t mtctr_12
= 0x7d8903a6;
4115 static const uint32_t mtlr_0
= 0x7c0803a6;
4116 static const uint32_t mtlr_11
= 0x7d6803a6;
4117 static const uint32_t mtlr_12
= 0x7d8803a6;
4118 static const uint32_t nop
= 0x60000000;
4119 static const uint32_t ori_0_0_0
= 0x60000000;
4120 static const uint32_t ori_12_12_0
= 0x618c0000;
4121 static const uint32_t oris_12_12_0
= 0x658c0000;
4122 static const uint32_t sldi_12_12_32
= 0x799c07c6;
4123 static const uint32_t srdi_0_0_2
= 0x7800f082;
4124 static const uint32_t std_0_1
= 0xf8010000;
4125 static const uint32_t std_0_12
= 0xf80c0000;
4126 static const uint32_t std_2_1
= 0xf8410000;
4127 static const uint32_t std_11_1
= 0xf9610000;
4128 static const uint32_t stfd_0_1
= 0xd8010000;
4129 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
4130 static const uint32_t sub_11_11_12
= 0x7d6c5850;
4131 static const uint32_t sub_12_12_11
= 0x7d8b6050;
4132 static const uint32_t xor_2_12_12
= 0x7d826278;
4133 static const uint32_t xor_11_12_12
= 0x7d8b6278;
4135 // Write out the PLT.
4137 template<int size
, bool big_endian
>
4139 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4141 if (size
== 32 && (this->name_
[3] != 'I' && this->name_
[3] != 'L'))
4143 const section_size_type offset
= this->offset();
4144 const section_size_type oview_size
4145 = convert_to_section_size_type(this->data_size());
4146 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4147 unsigned char* pov
= oview
;
4148 unsigned char* endpov
= oview
+ oview_size
;
4150 // The address of the .glink branch table
4151 const Output_data_glink
<size
, big_endian
>* glink
4152 = this->targ_
->glink_section();
4153 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
4155 while (pov
< endpov
)
4157 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
4162 of
->write_output_view(offset
, oview_size
, oview
);
4166 // Create the PLT section.
4168 template<int size
, bool big_endian
>
4170 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
4173 if (this->plt_
== NULL
)
4175 if (this->got_
== NULL
)
4176 this->got_section(symtab
, layout
);
4178 if (this->glink_
== NULL
)
4179 make_glink_section(layout
);
4181 // Ensure that .rela.dyn always appears before .rela.plt This is
4182 // necessary due to how, on PowerPC and some other targets, .rela.dyn
4183 // needs to include .rela.plt in its range.
4184 this->rela_dyn_section(layout
);
4186 Reloc_section
* plt_rel
= new Reloc_section(false);
4187 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
4188 elfcpp::SHF_ALLOC
, plt_rel
,
4189 ORDER_DYNAMIC_PLT_RELOCS
, false);
4191 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
4193 layout
->add_output_section_data(".plt",
4195 ? elfcpp::SHT_PROGBITS
4196 : elfcpp::SHT_NOBITS
),
4197 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4204 Output_section
* rela_plt_os
= plt_rel
->output_section();
4205 rela_plt_os
->set_info_section(this->plt_
->output_section());
4209 // Create the IPLT section.
4211 template<int size
, bool big_endian
>
4213 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
4216 if (this->iplt_
== NULL
)
4218 this->make_plt_section(symtab
, layout
);
4219 this->make_lplt_section(layout
);
4221 Reloc_section
* iplt_rel
= new Reloc_section(false);
4222 if (this->rela_dyn_
->output_section())
4223 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
4225 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
4227 if (this->plt_
->output_section())
4228 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
4232 // Create the LPLT section.
4234 template<int size
, bool big_endian
>
4236 Target_powerpc
<size
, big_endian
>::make_lplt_section(Layout
* layout
)
4238 if (this->lplt_
== NULL
)
4240 Reloc_section
* lplt_rel
= NULL
;
4241 if (parameters
->options().output_is_position_independent())
4243 lplt_rel
= new Reloc_section(false);
4244 this->rela_dyn_section(layout
);
4245 if (this->rela_dyn_
->output_section())
4246 this->rela_dyn_
->output_section()
4247 ->add_output_section_data(lplt_rel
);
4250 = new Output_data_plt_powerpc
<size
, big_endian
>(this, lplt_rel
,
4252 this->make_brlt_section(layout
);
4253 if (this->brlt_section_
&& this->brlt_section_
->output_section())
4254 this->brlt_section_
->output_section()
4255 ->add_output_section_data(this->lplt_
);
4257 layout
->add_output_section_data(".branch_lt",
4258 elfcpp::SHT_PROGBITS
,
4259 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4266 // A section for huge long branch addresses, similar to plt section.
4268 template<int size
, bool big_endian
>
4269 class Output_data_brlt_powerpc
: public Output_section_data_build
4272 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4273 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
4274 size
, big_endian
> Reloc_section
;
4276 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
4277 Reloc_section
* brlt_rel
)
4278 : Output_section_data_build(size
== 32 ? 4 : 8),
4286 this->reset_data_size();
4287 this->rel_
->reset_data_size();
4291 finalize_brlt_sizes()
4293 this->finalize_data_size();
4294 this->rel_
->finalize_data_size();
4297 // Add a reloc for an entry in the BRLT.
4299 add_reloc(Address to
, unsigned int off
)
4300 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4302 // Update section and reloc section size.
4304 set_current_size(unsigned int num_branches
)
4306 this->reset_address_and_file_offset();
4307 this->set_current_data_size(num_branches
* 16);
4308 this->finalize_data_size();
4309 Output_section
* os
= this->output_section();
4310 os
->set_section_offsets_need_adjustment();
4311 if (this->rel_
!= NULL
)
4313 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4314 this->rel_
->reset_address_and_file_offset();
4315 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4316 this->rel_
->finalize_data_size();
4317 Output_section
* os
= this->rel_
->output_section();
4318 os
->set_section_offsets_need_adjustment();
4324 do_adjust_output_section(Output_section
* os
)
4329 // Write to a map file.
4331 do_print_to_mapfile(Mapfile
* mapfile
) const
4332 { mapfile
->print_output_data(this, "** BRLT"); }
4335 // Write out the BRLT data.
4337 do_write(Output_file
*);
4339 // The reloc section.
4340 Reloc_section
* rel_
;
4341 Target_powerpc
<size
, big_endian
>* targ_
;
4344 // Make the branch lookup table section.
4346 template<int size
, bool big_endian
>
4348 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4350 if (size
== 64 && this->brlt_section_
== NULL
)
4352 Reloc_section
* brlt_rel
= NULL
;
4353 bool is_pic
= parameters
->options().output_is_position_independent();
4356 // When PIC we can't fill in .branch_lt but must initialise at
4357 // runtime via dynamic relocations.
4358 this->rela_dyn_section(layout
);
4359 brlt_rel
= new Reloc_section(false);
4360 if (this->rela_dyn_
->output_section())
4361 this->rela_dyn_
->output_section()
4362 ->add_output_section_data(brlt_rel
);
4365 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4366 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4367 this->plt_
->output_section()
4368 ->add_output_section_data(this->brlt_section_
);
4370 layout
->add_output_section_data(".branch_lt",
4371 elfcpp::SHT_PROGBITS
,
4372 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4373 this->brlt_section_
,
4379 // Write out .branch_lt when non-PIC.
4381 template<int size
, bool big_endian
>
4383 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4385 if (size
== 64 && !parameters
->options().output_is_position_independent())
4387 const section_size_type offset
= this->offset();
4388 const section_size_type oview_size
4389 = convert_to_section_size_type(this->data_size());
4390 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4392 this->targ_
->write_branch_lookup_table(oview
);
4393 of
->write_output_view(offset
, oview_size
, oview
);
4397 static inline uint32_t
4403 static inline uint32_t
4409 static inline uint32_t
4412 return hi(a
+ 0x8000);
4418 static const unsigned char eh_frame_cie
[12];
4422 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4425 'z', 'R', 0, // Augmentation string.
4426 4, // Code alignment.
4427 0x80 - size
/ 8 , // Data alignment.
4429 1, // Augmentation size.
4430 (elfcpp::DW_EH_PE_pcrel
4431 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4432 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4435 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4436 static const unsigned char glink_eh_frame_fde_64v1
[] =
4438 0, 0, 0, 0, // Replaced with offset to .glink.
4439 0, 0, 0, 0, // Replaced with size of .glink.
4440 0, // Augmentation size.
4441 elfcpp::DW_CFA_advance_loc
+ 1,
4442 elfcpp::DW_CFA_register
, 65, 12,
4443 elfcpp::DW_CFA_advance_loc
+ 5,
4444 elfcpp::DW_CFA_restore_extended
, 65
4447 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4448 static const unsigned char glink_eh_frame_fde_64v2
[] =
4450 0, 0, 0, 0, // Replaced with offset to .glink.
4451 0, 0, 0, 0, // Replaced with size of .glink.
4452 0, // Augmentation size.
4453 elfcpp::DW_CFA_advance_loc
+ 1,
4454 elfcpp::DW_CFA_register
, 65, 0,
4455 elfcpp::DW_CFA_advance_loc
+ 7,
4456 elfcpp::DW_CFA_restore_extended
, 65
4459 // Describe __glink_PLTresolve use of LR, 32-bit version.
4460 static const unsigned char glink_eh_frame_fde_32
[] =
4462 0, 0, 0, 0, // Replaced with offset to .glink.
4463 0, 0, 0, 0, // Replaced with size of .glink.
4464 0, // Augmentation size.
4465 elfcpp::DW_CFA_advance_loc
+ 2,
4466 elfcpp::DW_CFA_register
, 65, 0,
4467 elfcpp::DW_CFA_advance_loc
+ 4,
4468 elfcpp::DW_CFA_restore_extended
, 65
4471 static const unsigned char default_fde
[] =
4473 0, 0, 0, 0, // Replaced with offset to stubs.
4474 0, 0, 0, 0, // Replaced with size of stubs.
4475 0, // Augmentation size.
4476 elfcpp::DW_CFA_nop
, // Pad.
4481 template<bool big_endian
>
4483 write_insn(unsigned char* p
, uint32_t v
)
4485 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4489 static inline unsigned int
4492 if (!parameters
->options().user_set_plt_align())
4493 return size
== 64 ? 32 : 8;
4494 return 1 << parameters
->options().plt_align();
4497 // Stub_table holds information about plt and long branch stubs.
4498 // Stubs are built in an area following some input section determined
4499 // by group_sections(). This input section is converted to a relaxed
4500 // input section allowing it to be resized to accommodate the stubs
4502 template<int size
, bool big_endian
>
4503 class Stub_table
: public Output_relaxed_input_section
4508 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4509 : off_(off
), indx_(indx
), iter_(0), notoc_(0), r2save_(0), localentry0_(0)
4513 unsigned int indx_
: 28;
4514 unsigned int iter_
: 1;
4515 unsigned int notoc_
: 1;
4516 unsigned int r2save_
: 1;
4517 unsigned int localentry0_
: 1;
4519 struct Branch_stub_ent
4521 Branch_stub_ent(unsigned int off
, bool notoc
, bool save_res
)
4522 : off_(off
), iter_(false), notoc_(notoc
), save_res_(save_res
)
4530 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4531 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4533 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4534 Output_section
* output_section
,
4535 const Output_section::Input_section
* owner
,
4537 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4539 ->section_addralign(owner
->shndx())),
4540 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4541 orig_data_size_(owner
->current_data_size()),
4542 plt_size_(0), last_plt_size_(0),
4543 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4544 need_save_res_(false), need_resize_(false), resizing_(false),
4547 this->set_output_section(output_section
);
4549 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4550 new_relaxed
.push_back(this);
4551 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4554 // Add a plt call stub.
4556 add_plt_call_entry(Address
,
4557 const Sized_relobj_file
<size
, big_endian
>*,
4564 add_plt_call_entry(Address
,
4565 const Sized_relobj_file
<size
, big_endian
>*,
4571 // Find a given plt call stub.
4573 find_plt_call_entry(const Symbol
*) const;
4576 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4577 unsigned int) const;
4580 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4586 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4591 // Add a long branch stub.
4593 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4594 unsigned int, Address
, Address
, bool);
4596 const Branch_stub_ent
*
4597 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4601 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4603 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
4604 if (max_branch_offset
== 0)
4606 gold_assert(from
!= invalid_address
);
4607 Address loc
= off
+ this->stub_address();
4608 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4612 clear_stubs(bool all
)
4614 this->plt_call_stubs_
.clear();
4615 this->plt_size_
= 0;
4616 this->long_branch_stubs_
.clear();
4617 this->branch_size_
= 0;
4618 this->need_save_res_
= false;
4621 this->last_plt_size_
= 0;
4622 this->last_branch_size_
= 0;
4628 { return need_resize_
; }
4631 set_resizing(bool val
)
4633 this->resizing_
= val
;
4636 this->need_resize_
= false;
4637 this->plt_size_
= 0;
4638 this->branch_size_
= 0;
4639 this->need_save_res_
= false;
4644 set_address_and_size(const Output_section
* os
, Address off
)
4646 Address start_off
= off
;
4647 off
+= this->orig_data_size_
;
4648 Address my_size
= this->plt_size_
+ this->branch_size_
;
4649 if (this->need_save_res_
)
4650 my_size
+= this->targ_
->savres_section()->data_size();
4652 off
= align_address(off
, this->stub_align());
4653 // Include original section size and alignment padding in size
4654 my_size
+= off
- start_off
;
4655 // Ensure new size is always larger than min size
4656 // threshold. Alignment requirement is included in "my_size", so
4657 // increase "my_size" does not invalidate alignment.
4658 if (my_size
< this->min_size_threshold_
)
4659 my_size
= this->min_size_threshold_
;
4660 this->reset_address_and_file_offset();
4661 this->set_current_data_size(my_size
);
4662 this->set_address_and_file_offset(os
->address() + start_off
,
4663 os
->offset() + start_off
);
4668 stub_address() const
4670 return align_address(this->address() + this->orig_data_size_
,
4671 this->stub_align());
4677 return align_address(this->offset() + this->orig_data_size_
,
4678 this->stub_align());
4683 { return this->plt_size_
; }
4687 { return this->branch_size_
; }
4690 set_min_size_threshold(Address min_size
)
4691 { this->min_size_threshold_
= min_size
; }
4694 define_stub_syms(Symbol_table
*);
4699 Output_section
* os
= this->output_section();
4700 if (os
->addralign() < this->stub_align())
4702 os
->set_addralign(this->stub_align());
4703 // FIXME: get rid of the insane checkpointing.
4704 // We can't increase alignment of the input section to which
4705 // stubs are attached; The input section may be .init which
4706 // is pasted together with other .init sections to form a
4707 // function. Aligning might insert zero padding resulting in
4708 // sigill. However we do need to increase alignment of the
4709 // output section so that the align_address() on offset in
4710 // set_address_and_size() adds the same padding as the
4711 // align_address() on address in stub_address().
4712 // What's more, we need this alignment for the layout done in
4713 // relaxation_loop_body() so that the output section starts at
4714 // a suitably aligned address.
4715 os
->checkpoint_set_addralign(this->stub_align());
4717 if (this->last_plt_size_
!= this->plt_size_
4718 || this->last_branch_size_
!= this->branch_size_
)
4720 this->last_plt_size_
= this->plt_size_
;
4721 this->last_branch_size_
= this->branch_size_
;
4727 // Add .eh_frame info for this stub section.
4729 add_eh_frame(Layout
* layout
);
4731 // Remove .eh_frame info for this stub section.
4733 remove_eh_frame(Layout
* layout
);
4735 Target_powerpc
<size
, big_endian
>*
4741 class Plt_stub_key_hash
;
4742 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4743 Plt_stub_key_hash
> Plt_stub_entries
;
4744 class Branch_stub_key
;
4745 class Branch_stub_key_hash
;
4746 typedef Unordered_map
<Branch_stub_key
, Branch_stub_ent
,
4747 Branch_stub_key_hash
> Branch_stub_entries
;
4749 // Alignment of stub section.
4753 unsigned int min_align
= size
== 64 ? 32 : 16;
4754 unsigned int user_align
= 1 << parameters
->options().plt_align();
4755 return std::max(user_align
, min_align
);
4758 // Return the plt offset for the given call stub.
4760 plt_off(typename
Plt_stub_entries::const_iterator p
,
4761 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4763 const Symbol
* gsym
= p
->first
.sym_
;
4765 return this->targ_
->plt_off(gsym
, sec
);
4768 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4769 unsigned int local_sym_index
= p
->first
.locsym_
;
4770 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4774 // Size of a given plt call stub.
4776 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const;
4779 plt_call_align(unsigned int bytes
) const
4781 unsigned int align
= param_plt_align
<size
>();
4782 return (bytes
+ align
- 1) & -align
;
4785 // Return long branch stub size.
4787 branch_stub_size(typename
Branch_stub_entries::const_iterator p
,
4791 build_tls_opt_head(unsigned char** pp
,
4792 typename
Plt_stub_entries::const_iterator cs
);
4795 build_tls_opt_tail(unsigned char* p
,
4796 typename
Plt_stub_entries::const_iterator cs
);
4799 plt_error(const Plt_stub_key
& p
);
4803 do_write(Output_file
*);
4805 // Plt call stub keys.
4809 Plt_stub_key(const Symbol
* sym
)
4810 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4813 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4814 unsigned int locsym_index
)
4815 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4818 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4820 unsigned int r_type
,
4822 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4825 this->addend_
= addend
;
4826 else if (parameters
->options().output_is_position_independent()
4827 && (r_type
== elfcpp::R_PPC_PLTREL24
4828 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4830 this->addend_
= addend
;
4831 if (this->addend_
>= 32768)
4832 this->object_
= object
;
4836 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4837 unsigned int locsym_index
,
4838 unsigned int r_type
,
4840 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4843 this->addend_
= addend
;
4844 else if (parameters
->options().output_is_position_independent()
4845 && (r_type
== elfcpp::R_PPC_PLTREL24
4846 || r_type
== elfcpp::R_POWERPC_PLTCALL
))
4847 this->addend_
= addend
;
4850 bool operator==(const Plt_stub_key
& that
) const
4852 return (this->sym_
== that
.sym_
4853 && this->object_
== that
.object_
4854 && this->addend_
== that
.addend_
4855 && this->locsym_
== that
.locsym_
);
4859 const Sized_relobj_file
<size
, big_endian
>* object_
;
4860 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4861 unsigned int locsym_
;
4864 class Plt_stub_key_hash
4867 size_t operator()(const Plt_stub_key
& ent
) const
4869 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4870 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
4876 // Long branch stub keys.
4877 class Branch_stub_key
4880 Branch_stub_key(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
4881 : dest_(to
), toc_base_off_(0)
4884 toc_base_off_
= obj
->toc_base_offset();
4887 bool operator==(const Branch_stub_key
& that
) const
4889 return (this->dest_
== that
.dest_
4891 || this->toc_base_off_
== that
.toc_base_off_
));
4895 unsigned int toc_base_off_
;
4898 class Branch_stub_key_hash
4901 size_t operator()(const Branch_stub_key
& key
) const
4902 { return key
.dest_
^ key
.toc_base_off_
; }
4905 // In a sane world this would be a global.
4906 Target_powerpc
<size
, big_endian
>* targ_
;
4907 // Map sym/object/addend to stub offset.
4908 Plt_stub_entries plt_call_stubs_
;
4909 // Map destination address to stub offset.
4910 Branch_stub_entries long_branch_stubs_
;
4911 // size of input section
4912 section_size_type orig_data_size_
;
4914 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
4915 // Some rare cases cause (PR/20529) fluctuation in stub table
4916 // size, which leads to an endless relax loop. This is to be fixed
4917 // by, after the first few iterations, allowing only increase of
4918 // stub table size. This variable sets the minimal possible size of
4919 // a stub table, it is zero for the first few iterations, then
4920 // increases monotonically.
4921 Address min_size_threshold_
;
4922 // Set if this stub group needs a copy of out-of-line register
4923 // save/restore functions.
4924 bool need_save_res_
;
4925 // Set when notoc_/r2save_ changes after sizing a stub
4927 // Set when resizing stubs
4929 // Per stub table unique identifier.
4933 // Add a plt call stub, if we do not already have one for this
4934 // sym/object/addend combo.
4936 template<int size
, bool big_endian
>
4938 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4940 const Sized_relobj_file
<size
, big_endian
>* object
,
4942 unsigned int r_type
,
4946 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
4947 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
4948 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4949 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
4953 && this->targ_
->is_elfv2_localentry0(gsym
))
4955 p
.first
->second
.localentry0_
= 1;
4956 this->targ_
->set_has_localentry0();
4958 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
4960 if (!p
.second
&& !p
.first
->second
.notoc_
)
4961 this->need_resize_
= true;
4962 p
.first
->second
.notoc_
= 1;
4964 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
4966 if (!p
.second
&& !p
.first
->second
.r2save_
)
4967 this->need_resize_
= true;
4968 p
.first
->second
.r2save_
= 1;
4971 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
4973 if (this->resizing_
)
4975 p
.first
->second
.iter_
= 1;
4976 p
.first
->second
.off_
= this->plt_size_
;
4978 this->plt_size_
+= this->plt_call_size(p
.first
);
4979 if (this->targ_
->is_tls_get_addr_opt(gsym
))
4980 this->targ_
->set_has_tls_get_addr_opt();
4981 this->plt_size_
= this->plt_call_align(this->plt_size_
);
4983 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
4986 template<int size
, bool big_endian
>
4988 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4990 const Sized_relobj_file
<size
, big_endian
>* object
,
4991 unsigned int locsym_index
,
4992 unsigned int r_type
,
4996 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
4997 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
4998 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4999 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
5003 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
5005 p
.first
->second
.localentry0_
= 1;
5006 this->targ_
->set_has_localentry0();
5008 if (r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
5010 if (!p
.second
&& !p
.first
->second
.notoc_
)
5011 this->need_resize_
= true;
5012 p
.first
->second
.notoc_
= 1;
5014 else if (!tocsave
&& !p
.first
->second
.localentry0_
)
5016 if (!p
.second
&& !p
.first
->second
.r2save_
)
5017 this->need_resize_
= true;
5018 p
.first
->second
.r2save_
= 1;
5021 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5023 if (this->resizing_
)
5025 p
.first
->second
.iter_
= 1;
5026 p
.first
->second
.off_
= this->plt_size_
;
5028 this->plt_size_
+= this->plt_call_size(p
.first
);
5029 this->plt_size_
= this->plt_call_align(this->plt_size_
);
5031 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5034 // Find a plt call stub.
5036 template<int size
, bool big_endian
>
5037 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5038 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5039 const Sized_relobj_file
<size
, big_endian
>* object
,
5041 unsigned int r_type
,
5042 Address addend
) const
5044 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
5045 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5046 if (p
== this->plt_call_stubs_
.end())
5051 template<int size
, bool big_endian
>
5052 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5053 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
5055 Plt_stub_key
key(gsym
);
5056 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5057 if (p
== this->plt_call_stubs_
.end())
5062 template<int size
, bool big_endian
>
5063 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5064 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5065 const Sized_relobj_file
<size
, big_endian
>* object
,
5066 unsigned int locsym_index
,
5067 unsigned int r_type
,
5068 Address addend
) const
5070 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
5071 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5072 if (p
== this->plt_call_stubs_
.end())
5077 template<int size
, bool big_endian
>
5078 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
5079 Stub_table
<size
, big_endian
>::find_plt_call_entry(
5080 const Sized_relobj_file
<size
, big_endian
>* object
,
5081 unsigned int locsym_index
) const
5083 Plt_stub_key
key(object
, locsym_index
);
5084 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
5085 if (p
== this->plt_call_stubs_
.end())
5090 // Add a long branch stub if we don't already have one to given
5093 template<int size
, bool big_endian
>
5095 Stub_table
<size
, big_endian
>::add_long_branch_entry(
5096 const Powerpc_relobj
<size
, big_endian
>* object
,
5097 unsigned int r_type
,
5102 Branch_stub_key
key(object
, to
);
5103 bool notoc
= (size
== 64 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
);
5104 Branch_stub_ent
ent(this->branch_size_
, notoc
, save_res
);
5105 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
5106 = this->long_branch_stubs_
.insert(std::make_pair(key
, ent
));
5107 if (notoc
&& !p
.first
->second
.notoc_
)
5109 this->need_resize_
= true;
5110 p
.first
->second
.notoc_
= true;
5112 gold_assert(save_res
== p
.first
->second
.save_res_
);
5113 if (p
.second
|| (this->resizing_
&& !p
.first
->second
.iter_
))
5115 if (this->resizing_
)
5117 p
.first
->second
.iter_
= 1;
5118 p
.first
->second
.off_
= this->branch_size_
;
5121 this->need_save_res_
= true;
5124 bool need_lt
= false;
5125 unsigned int stub_size
= this->branch_stub_size(p
.first
, &need_lt
);
5126 this->branch_size_
+= stub_size
;
5127 if (size
== 64 && need_lt
)
5128 this->targ_
->add_branch_lookup_table(to
);
5131 return this->can_reach_stub(from
, p
.first
->second
.off_
, r_type
);
5134 // Find long branch stub offset.
5136 template<int size
, bool big_endian
>
5137 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
*
5138 Stub_table
<size
, big_endian
>::find_long_branch_entry(
5139 const Powerpc_relobj
<size
, big_endian
>* object
,
5142 Branch_stub_key
key(object
, to
);
5143 typename
Branch_stub_entries::const_iterator p
5144 = this->long_branch_stubs_
.find(key
);
5145 if (p
== this->long_branch_stubs_
.end())
5150 template<bool big_endian
>
5152 eh_advance (std::vector
<unsigned char>& fde
, unsigned int delta
)
5156 fde
.push_back(elfcpp::DW_CFA_advance_loc
+ delta
);
5157 else if (delta
< 256)
5159 fde
.push_back(elfcpp::DW_CFA_advance_loc1
);
5160 fde
.push_back(delta
);
5162 else if (delta
< 65536)
5164 fde
.resize(fde
.size() + 3);
5165 unsigned char *p
= &*fde
.end() - 3;
5166 *p
++ = elfcpp::DW_CFA_advance_loc2
;
5167 elfcpp::Swap
<16, big_endian
>::writeval(p
, delta
);
5171 fde
.resize(fde
.size() + 5);
5172 unsigned char *p
= &*fde
.end() - 5;
5173 *p
++ = elfcpp::DW_CFA_advance_loc4
;
5174 elfcpp::Swap
<32, big_endian
>::writeval(p
, delta
);
5178 template<typename T
>
5180 stub_sort(T s1
, T s2
)
5182 return s1
->second
.off_
< s2
->second
.off_
;
5185 // Add .eh_frame info for this stub section. Unlike other linker
5186 // generated .eh_frame this is added late in the link, because we
5187 // only want the .eh_frame info if this particular stub section is
5190 template<int size
, bool big_endian
>
5192 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5195 || !parameters
->options().ld_generated_unwind_info())
5198 // Since we add stub .eh_frame info late, it must be placed
5199 // after all other linker generated .eh_frame info so that
5200 // merge mapping need not be updated for input sections.
5201 // There is no provision to use a different CIE to that used
5203 if (!this->targ_
->has_glink())
5206 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5207 std::vector
<plt_iter
> calls
;
5208 if (!this->plt_call_stubs_
.empty())
5209 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5210 cs
!= this->plt_call_stubs_
.end();
5212 if ((this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
)
5213 && cs
->second
.r2save_
5214 && !cs
->second
.localentry0_
)
5215 || cs
->second
.notoc_
)
5216 calls
.push_back(cs
);
5217 if (calls
.size() > 1)
5218 std::stable_sort(calls
.begin(), calls
.end(),
5219 stub_sort
<plt_iter
>);
5221 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5222 std::vector
<branch_iter
> branches
;
5223 if (!this->long_branch_stubs_
.empty())
5224 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5225 bs
!= this->long_branch_stubs_
.end();
5227 if (bs
->second
.notoc_
)
5228 branches
.push_back(bs
);
5229 if (branches
.size() > 1)
5230 std::stable_sort(branches
.begin(), branches
.end(),
5231 stub_sort
<branch_iter
>);
5233 if (calls
.empty() && branches
.empty())
5236 unsigned int last_eh_loc
= 0;
5237 // offset pcrel sdata4, size udata4, and augmentation size byte.
5238 std::vector
<unsigned char> fde(9, 0);
5240 for (unsigned int i
= 0; i
< calls
.size(); i
++)
5242 plt_iter cs
= calls
[i
];
5243 unsigned int off
= cs
->second
.off_
;
5244 // The __tls_get_addr_opt call stub needs to describe where
5245 // it saves LR, to support exceptions that might be thrown
5246 // from __tls_get_addr, and to support asynchronous exceptions.
5247 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5250 if (cs
->second
.r2save_
5251 && !cs
->second
.localentry0_
)
5254 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5255 fde
.resize(fde
.size() + 6);
5256 unsigned char* p
= &*fde
.end() - 6;
5257 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
5259 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
5260 unsigned int delta
= this->plt_call_size(cs
) - 4 - 9 * 4;
5261 *p
++ = elfcpp::DW_CFA_advance_loc
+ delta
/ 4;
5262 *p
++ = elfcpp::DW_CFA_restore_extended
;
5264 last_eh_loc
= off
+ delta
;
5268 // notoc stubs also should describe LR changes, to support
5269 // asynchronous exceptions.
5270 off
+= (cs
->second
.r2save_
? 4 : 0) + 8;
5271 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5272 fde
.resize(fde
.size() + 6);
5273 unsigned char* p
= &*fde
.end() - 6;
5274 *p
++ = elfcpp::DW_CFA_register
;
5277 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5278 *p
++ = elfcpp::DW_CFA_restore_extended
;
5280 last_eh_loc
= off
+ 8;
5283 for (unsigned int i
= 0; i
< branches
.size(); i
++)
5285 branch_iter bs
= branches
[i
];
5286 unsigned int off
= bs
->second
.off_
+ 8;
5287 eh_advance
<big_endian
>(fde
, off
- last_eh_loc
);
5288 fde
.resize(fde
.size() + 6);
5289 unsigned char* p
= &*fde
.end() - 6;
5290 *p
++ = elfcpp::DW_CFA_register
;
5293 *p
++ = elfcpp::DW_CFA_advance_loc
+ 8 / 4;
5294 *p
++ = elfcpp::DW_CFA_restore_extended
;
5296 last_eh_loc
= off
+ 8;
5299 layout
->add_eh_frame_for_plt(this,
5300 Eh_cie
<size
>::eh_frame_cie
,
5301 sizeof (Eh_cie
<size
>::eh_frame_cie
),
5302 &*fde
.begin(), fde
.size());
5305 template<int size
, bool big_endian
>
5307 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
5310 && parameters
->options().ld_generated_unwind_info()
5311 && this->targ_
->has_glink())
5312 layout
->remove_eh_frame_for_plt(this,
5313 Eh_cie
<size
>::eh_frame_cie
,
5314 sizeof (Eh_cie
<size
>::eh_frame_cie
));
5317 // A class to handle .glink.
5319 template<int size
, bool big_endian
>
5320 class Output_data_glink
: public Output_section_data
5323 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5324 static const Address invalid_address
= static_cast<Address
>(0) - 1;
5326 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
5327 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
5328 end_branch_table_(), ge_size_(0)
5332 add_eh_frame(Layout
* layout
);
5335 add_global_entry(const Symbol
*);
5338 find_global_entry(const Symbol
*) const;
5341 global_entry_align(unsigned int off
) const
5343 unsigned int align
= param_plt_align
<size
>();
5344 return (off
+ align
- 1) & -align
;
5348 global_entry_off() const
5350 return this->global_entry_align(this->end_branch_table_
);
5354 global_entry_address() const
5356 gold_assert(this->is_data_size_valid());
5357 return this->address() + this->global_entry_off();
5361 pltresolve_size() const
5365 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
5370 // Write to a map file.
5372 do_print_to_mapfile(Mapfile
* mapfile
) const
5373 { mapfile
->print_output_data(this, _("** glink")); }
5377 set_final_data_size();
5381 do_write(Output_file
*);
5383 // Allows access to .got and .plt for do_write.
5384 Target_powerpc
<size
, big_endian
>* targ_
;
5386 // Map sym to stub offset.
5387 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
5388 Global_entry_stub_entries global_entry_stubs_
;
5390 unsigned int end_branch_table_
, ge_size_
;
5393 template<int size
, bool big_endian
>
5395 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
5397 if (!parameters
->options().ld_generated_unwind_info())
5402 if (this->targ_
->abiversion() < 2)
5403 layout
->add_eh_frame_for_plt(this,
5404 Eh_cie
<64>::eh_frame_cie
,
5405 sizeof (Eh_cie
<64>::eh_frame_cie
),
5406 glink_eh_frame_fde_64v1
,
5407 sizeof (glink_eh_frame_fde_64v1
));
5409 layout
->add_eh_frame_for_plt(this,
5410 Eh_cie
<64>::eh_frame_cie
,
5411 sizeof (Eh_cie
<64>::eh_frame_cie
),
5412 glink_eh_frame_fde_64v2
,
5413 sizeof (glink_eh_frame_fde_64v2
));
5417 // 32-bit .glink can use the default since the CIE return
5418 // address reg, LR, is valid.
5419 layout
->add_eh_frame_for_plt(this,
5420 Eh_cie
<32>::eh_frame_cie
,
5421 sizeof (Eh_cie
<32>::eh_frame_cie
),
5423 sizeof (default_fde
));
5424 // Except where LR is used in a PIC __glink_PLTresolve.
5425 if (parameters
->options().output_is_position_independent())
5426 layout
->add_eh_frame_for_plt(this,
5427 Eh_cie
<32>::eh_frame_cie
,
5428 sizeof (Eh_cie
<32>::eh_frame_cie
),
5429 glink_eh_frame_fde_32
,
5430 sizeof (glink_eh_frame_fde_32
));
5434 template<int size
, bool big_endian
>
5436 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5438 unsigned int off
= this->global_entry_align(this->ge_size_
);
5439 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5440 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5442 this->ge_size_
= off
+ 16;
5445 template<int size
, bool big_endian
>
5446 typename Output_data_glink
<size
, big_endian
>::Address
5447 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5449 typename
Global_entry_stub_entries::const_iterator p
5450 = this->global_entry_stubs_
.find(gsym
);
5451 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5454 template<int size
, bool big_endian
>
5456 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5458 unsigned int count
= this->targ_
->plt_entry_count();
5459 section_size_type total
= 0;
5465 // space for branch table
5466 total
+= 4 * (count
- 1);
5468 total
+= -total
& 15;
5469 total
+= this->pltresolve_size();
5473 total
+= this->pltresolve_size();
5475 // space for branch table
5477 if (this->targ_
->abiversion() < 2)
5481 total
+= 4 * (count
- 0x8000);
5485 this->end_branch_table_
= total
;
5486 total
= this->global_entry_align(total
);
5487 total
+= this->ge_size_
;
5489 this->set_data_size(total
);
5492 // Define symbols on stubs, identifying the stub.
5494 template<int size
, bool big_endian
>
5496 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5498 if (!this->plt_call_stubs_
.empty())
5500 // The key for the plt call stub hash table includes addresses,
5501 // therefore traversal order depends on those addresses, which
5502 // can change between runs if gold is a PIE. Unfortunately the
5503 // output .symtab ordering depends on the order in which symbols
5504 // are added to the linker symtab. We want reproducible output
5505 // so must sort the call stub symbols.
5506 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5507 std::vector
<plt_iter
> sorted
;
5508 sorted
.resize(this->plt_call_stubs_
.size());
5510 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5511 cs
!= this->plt_call_stubs_
.end();
5513 sorted
[cs
->second
.indx_
] = cs
;
5515 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5517 plt_iter cs
= sorted
[i
];
5520 if (cs
->first
.addend_
!= 0)
5521 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5524 if (cs
->first
.object_
)
5526 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5527 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5528 sprintf(obj
, "%x:", ppcobj
->uniq());
5531 const char *symname
;
5532 if (cs
->first
.sym_
== NULL
)
5534 sprintf(localname
, "%x", cs
->first
.locsym_
);
5535 symname
= localname
;
5537 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5538 symname
= this->targ_
->tls_get_addr_opt()->name();
5540 symname
= cs
->first
.sym_
->name();
5541 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5542 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5544 = this->stub_address() - this->address() + cs
->second
.off_
;
5545 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5546 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5550 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5551 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5552 bs
!= this->long_branch_stubs_
.end();
5555 if (bs
->second
.save_res_
)
5558 char* name
= new char[8 + 13 + 16 + 1];
5559 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5560 static_cast<unsigned long long>(bs
->first
.dest_
));
5561 Address value
= (this->stub_address() - this->address()
5562 + this->plt_size_
+ bs
->second
.off_
);
5563 bool need_lt
= false;
5564 unsigned int stub_size
= this->branch_stub_size(bs
, &need_lt
);
5565 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5569 // Emit the start of a __tls_get_addr_opt plt call stub.
5571 template<int size
, bool big_endian
>
5573 Stub_table
<size
, big_endian
>::build_tls_opt_head(
5575 typename
Plt_stub_entries::const_iterator cs
)
5577 if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5579 unsigned char* p
= *pp
;
5582 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5584 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5586 write_insn
<big_endian
>(p
, mr_0_3
);
5588 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5590 write_insn
<big_endian
>(p
, add_3_12_13
);
5592 write_insn
<big_endian
>(p
, beqlr
);
5594 write_insn
<big_endian
>(p
, mr_3_0
);
5596 if (cs
->second
.r2save_
&& !cs
->second
.localentry0_
)
5598 write_insn
<big_endian
>(p
, mflr_11
);
5600 write_insn
<big_endian
>(p
, (std_11_1
+ this->targ_
->stk_linker()));
5606 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5608 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5610 write_insn
<big_endian
>(p
, mr_0_3
);
5612 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5614 write_insn
<big_endian
>(p
, add_3_12_2
);
5616 write_insn
<big_endian
>(p
, beqlr
);
5618 write_insn
<big_endian
>(p
, mr_3_0
);
5620 write_insn
<big_endian
>(p
, nop
);
5629 // Emit the tail of a __tls_get_addr_opt plt call stub.
5631 template<int size
, bool big_endian
>
5633 Stub_table
<size
, big_endian
>::build_tls_opt_tail(
5635 typename
Plt_stub_entries::const_iterator cs
)
5638 && cs
->second
.r2save_
5639 && !cs
->second
.localentry0_
5640 && this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5642 write_insn
<big_endian
>(p
, bctrl
);
5644 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5646 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5648 write_insn
<big_endian
>(p
, mtlr_11
);
5650 write_insn
<big_endian
>(p
, blr
);
5656 // Gets the address of a label (1:) in r11 and builds an offset in r12,
5657 // then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
5662 // lis %r12,xxx-1b@highest
5663 // ori %r12,%r12,xxx-1b@higher
5664 // sldi %r12,%r12,32
5665 // oris %r12,%r12,xxx-1b@high
5666 // ori %r12,%r12,xxx-1b@l
5667 // add/ldx %r12,%r11,%r12
5669 template<bool big_endian
>
5670 static unsigned char*
5671 build_notoc_offset(unsigned char* p
, uint64_t off
, bool load
)
5673 write_insn
<big_endian
>(p
, mflr_12
);
5675 write_insn
<big_endian
>(p
, bcl_20_31
);
5677 write_insn
<big_endian
>(p
, mflr_11
);
5679 write_insn
<big_endian
>(p
, mtlr_12
);
5681 if (off
+ 0x8000 < 0x10000)
5684 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5686 write_insn
<big_endian
>(p
, addi_12_11
+ l(off
));
5688 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5690 write_insn
<big_endian
>(p
, addis_12_11
+ ha(off
));
5693 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5695 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
));
5699 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
5701 write_insn
<big_endian
>(p
, li_12_0
+ ((off
>> 32) & 0xffff));
5706 write_insn
<big_endian
>(p
, lis_12
+ ((off
>> 48) & 0xffff));
5708 if (((off
>> 32) & 0xffff) != 0)
5710 write_insn
<big_endian
>(p
, ori_12_12_0
+ ((off
>> 32) & 0xffff));
5714 if (((off
>> 32) & 0xffffffffULL
) != 0)
5716 write_insn
<big_endian
>(p
, sldi_12_12_32
);
5721 write_insn
<big_endian
>(p
, oris_12_12_0
+ hi(off
));
5726 write_insn
<big_endian
>(p
, ori_12_12_0
+ l(off
));
5730 write_insn
<big_endian
>(p
, ldx_12_11_12
);
5732 write_insn
<big_endian
>(p
, add_12_11_12
);
5738 // Size of a given plt call stub.
5740 template<int size
, bool big_endian
>
5742 Stub_table
<size
, big_endian
>::plt_call_size(
5743 typename
Plt_stub_entries::const_iterator p
) const
5747 const Symbol
* gsym
= p
->first
.sym_
;
5749 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
5752 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5753 uint64_t plt_addr
= this->plt_off(p
, &plt
);
5754 plt_addr
+= plt
->address();
5755 unsigned int bytes
= 0;
5756 const Symbol
* gsym
= p
->first
.sym_
;
5757 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5759 if (p
->second
.r2save_
&& !p
->second
.localentry0_
)
5765 if (p
->second
.r2save_
)
5768 if (p
->second
.notoc_
)
5770 uint64_t from
= this->stub_address() + p
->second
.off_
+ bytes
+ 2 * 4;
5773 uint64_t off
= plt_addr
- from
;
5774 if (off
+ 0x8000 < 0x10000)
5776 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5781 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
5782 && ((off
>> 32) & 0xffff) != 0)
5784 if (((off
>> 32) & 0xffffffffULL
) != 0)
5794 uint64_t got_addr
= this->targ_
->got_section()->output_section()->address();
5795 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5796 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
5797 got_addr
+= ppcobj
->toc_base_offset();
5798 uint64_t off
= plt_addr
- got_addr
;
5799 bytes
+= 3 * 4 + 4 * (ha(off
) != 0);
5800 if (this->targ_
->abiversion() < 2)
5802 bool static_chain
= parameters
->options().plt_static_chain();
5803 bool thread_safe
= this->targ_
->plt_thread_safe();
5807 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
5812 // Return long branch stub size.
5814 template<int size
, bool big_endian
>
5816 Stub_table
<size
, big_endian
>::branch_stub_size(
5817 typename
Branch_stub_entries::const_iterator p
,
5820 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
.off_
;
5823 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
5825 if (parameters
->options().output_is_position_independent())
5830 uint64_t off
= p
->first
.dest_
- loc
;
5831 if (p
->second
.notoc_
)
5834 if (off
+ 0x8000 < 0x10000)
5836 if (off
+ 0x80008000ULL
< 0x100000000ULL
)
5838 if (off
+ 24 + (1 << 25) < 2 << 25)
5842 unsigned int bytes
= 32;
5843 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
5844 && ((off
>> 32) & 0xffff) != 0)
5846 if (((off
>> 32) & 0xffffffffULL
) != 0)
5855 if (off
+ (1 << 25) < 2 << 25)
5861 template<int size
, bool big_endian
>
5863 Stub_table
<size
, big_endian
>::plt_error(const Plt_stub_key
& p
)
5866 gold_error(_("linkage table error against `%s'"),
5867 p
.sym_
->demangled_name().c_str());
5869 gold_error(_("linkage table error against `%s:[local %u]'"),
5870 p
.object_
->name().c_str(),
5874 // Write out plt and long branch stub code.
5876 template<int size
, bool big_endian
>
5878 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
5880 if (this->plt_call_stubs_
.empty()
5881 && this->long_branch_stubs_
.empty())
5884 const section_size_type start_off
= this->offset();
5885 const section_size_type off
= this->stub_offset();
5886 const section_size_type oview_size
=
5887 convert_to_section_size_type(this->data_size() - (off
- start_off
));
5888 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5893 const Output_data_got_powerpc
<size
, big_endian
>* got
5894 = this->targ_
->got_section();
5895 Address got_os_addr
= got
->output_section()->address();
5897 if (!this->plt_call_stubs_
.empty()
5898 && this->targ_
->abiversion() >= 2)
5900 // Write out plt call stubs for ELFv2.
5901 typename
Plt_stub_entries::const_iterator cs
;
5902 for (cs
= this->plt_call_stubs_
.begin();
5903 cs
!= this->plt_call_stubs_
.end();
5906 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5907 Address pltoff
= this->plt_off(cs
, &plt
);
5908 Address plt_addr
= pltoff
+ plt
->address();
5910 p
= oview
+ cs
->second
.off_
;
5911 this->build_tls_opt_head(&p
, cs
);
5912 if (cs
->second
.r2save_
)
5914 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
5917 if (cs
->second
.notoc_
)
5919 Address from
= this->stub_address() + (p
- oview
) + 8;
5920 Address off
= plt_addr
- from
;
5921 p
= build_notoc_offset
<big_endian
>(p
, off
, true);
5925 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5926 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5927 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
5928 Address off
= plt_addr
- got_addr
;
5930 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
5931 this->plt_error(cs
->first
);
5935 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
5937 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5942 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
5946 write_insn
<big_endian
>(p
, mtctr_12
);
5948 if (!this->build_tls_opt_tail(p
, cs
))
5949 write_insn
<big_endian
>(p
, bctr
);
5952 else if (!this->plt_call_stubs_
.empty())
5954 // Write out plt call stubs for ELFv1.
5955 typename
Plt_stub_entries::const_iterator cs
;
5956 for (cs
= this->plt_call_stubs_
.begin();
5957 cs
!= this->plt_call_stubs_
.end();
5960 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5961 Address pltoff
= this->plt_off(cs
, &plt
);
5962 Address plt_addr
= pltoff
+ plt
->address();
5963 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5964 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5965 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
5966 Address off
= plt_addr
- got_addr
;
5968 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0
5969 || cs
->second
.notoc_
)
5970 this->plt_error(cs
->first
);
5972 bool static_chain
= parameters
->options().plt_static_chain();
5973 bool thread_safe
= this->targ_
->plt_thread_safe();
5974 bool use_fake_dep
= false;
5975 Address cmp_branch_off
= 0;
5978 unsigned int pltindex
5979 = ((pltoff
- this->targ_
->first_plt_entry_offset())
5980 / this->targ_
->plt_entry_size());
5982 = (this->targ_
->glink_section()->pltresolve_size()
5984 if (pltindex
> 32768)
5985 glinkoff
+= (pltindex
- 32768) * 4;
5987 = this->targ_
->glink_section()->address() + glinkoff
;
5989 = (this->stub_address() + cs
->second
.off_
+ 20
5990 + 4 * cs
->second
.r2save_
5991 + 4 * (ha(off
) != 0)
5992 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
5993 + 4 * static_chain
);
5994 cmp_branch_off
= to
- from
;
5995 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
5998 p
= oview
+ cs
->second
.off_
;
5999 if (this->build_tls_opt_head(&p
, cs
))
6000 use_fake_dep
= thread_safe
;
6001 if (cs
->second
.r2save_
)
6003 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
6008 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
6010 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
6012 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6014 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
6018 write_insn
<big_endian
>(p
, mtctr_12
);
6022 write_insn
<big_endian
>(p
, xor_2_12_12
);
6024 write_insn
<big_endian
>(p
, add_11_11_2
);
6027 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
6031 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
6037 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
6039 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
6041 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
6045 write_insn
<big_endian
>(p
, mtctr_12
);
6049 write_insn
<big_endian
>(p
, xor_11_12_12
);
6051 write_insn
<big_endian
>(p
, add_2_2_11
);
6056 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
6059 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
6062 if (this->build_tls_opt_tail(p
, cs
))
6064 else if (thread_safe
&& !use_fake_dep
)
6066 write_insn
<big_endian
>(p
, cmpldi_2_0
);
6068 write_insn
<big_endian
>(p
, bnectr_p4
);
6070 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
6073 write_insn
<big_endian
>(p
, bctr
);
6077 // Write out long branch stubs.
6078 typename
Branch_stub_entries::const_iterator bs
;
6079 for (bs
= this->long_branch_stubs_
.begin();
6080 bs
!= this->long_branch_stubs_
.end();
6083 if (bs
->second
.save_res_
)
6085 Address off
= this->plt_size_
+ bs
->second
.off_
;
6087 Address loc
= this->stub_address() + off
;
6088 Address delta
= bs
->first
.dest_
- loc
;
6089 if (bs
->second
.notoc_
)
6091 unsigned char* startp
= p
;
6092 p
= build_notoc_offset
<big_endian
>(p
, off
, false);
6093 delta
-= p
- startp
;
6095 else if (delta
+ (1 << 25) >= 2 << 25)
6098 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
6099 gold_assert(brlt_addr
!= invalid_address
);
6100 brlt_addr
+= this->targ_
->brlt_section()->address();
6101 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
6102 Address brltoff
= brlt_addr
- got_addr
;
6103 if (ha(brltoff
) == 0)
6105 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
));
6110 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
));
6112 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
));
6116 if (delta
+ (1 << 25) < 2 << 25)
6117 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6120 write_insn
<big_endian
>(p
, mtctr_12
);
6122 write_insn
<big_endian
>(p
, bctr
);
6128 if (!this->plt_call_stubs_
.empty())
6130 // The address of _GLOBAL_OFFSET_TABLE_.
6131 Address g_o_t
= invalid_address
;
6133 // Write out plt call stubs.
6134 typename
Plt_stub_entries::const_iterator cs
;
6135 for (cs
= this->plt_call_stubs_
.begin();
6136 cs
!= this->plt_call_stubs_
.end();
6139 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
6140 Address plt_addr
= this->plt_off(cs
, &plt
);
6141 plt_addr
+= plt
->address();
6143 p
= oview
+ cs
->second
.off_
;
6144 this->build_tls_opt_head(&p
, cs
);
6145 if (parameters
->options().output_is_position_independent())
6148 const Powerpc_relobj
<size
, big_endian
>* ppcobj
6149 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
6150 (cs
->first
.object_
));
6151 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
6153 unsigned int got2
= ppcobj
->got2_shndx();
6154 got_addr
= ppcobj
->get_output_section_offset(got2
);
6155 gold_assert(got_addr
!= invalid_address
);
6156 got_addr
+= (ppcobj
->output_section(got2
)->address()
6157 + cs
->first
.addend_
);
6161 if (g_o_t
== invalid_address
)
6163 const Output_data_got_powerpc
<size
, big_endian
>* got
6164 = this->targ_
->got_section();
6165 g_o_t
= got
->address() + got
->g_o_t();
6170 Address off
= plt_addr
- got_addr
;
6172 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
6175 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
6177 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
6182 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
6184 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
6187 write_insn
<big_endian
>(p
, mtctr_11
);
6189 write_insn
<big_endian
>(p
, bctr
);
6193 // Write out long branch stubs.
6194 typename
Branch_stub_entries::const_iterator bs
;
6195 for (bs
= this->long_branch_stubs_
.begin();
6196 bs
!= this->long_branch_stubs_
.end();
6199 if (bs
->second
.save_res_
)
6201 Address off
= this->plt_size_
+ bs
->second
.off_
;
6203 Address loc
= this->stub_address() + off
;
6204 Address delta
= bs
->first
.dest_
- loc
;
6205 if (delta
+ (1 << 25) < 2 << 25)
6206 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
6207 else if (!parameters
->options().output_is_position_independent())
6209 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
6211 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
6216 write_insn
<big_endian
>(p
, mflr_0
);
6218 write_insn
<big_endian
>(p
, bcl_20_31
);
6220 write_insn
<big_endian
>(p
, mflr_12
);
6222 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
6224 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
6226 write_insn
<big_endian
>(p
, mtlr_0
);
6229 write_insn
<big_endian
>(p
, mtctr_12
);
6231 write_insn
<big_endian
>(p
, bctr
);
6234 if (this->need_save_res_
)
6236 p
= oview
+ this->plt_size_
+ this->branch_size_
;
6237 memcpy (p
, this->targ_
->savres_section()->contents(),
6238 this->targ_
->savres_section()->data_size());
6242 // Write out .glink.
6244 template<int size
, bool big_endian
>
6246 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
6248 const section_size_type off
= this->offset();
6249 const section_size_type oview_size
=
6250 convert_to_section_size_type(this->data_size());
6251 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6254 // The base address of the .plt section.
6255 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
6256 Address plt_base
= this->targ_
->plt_section()->address();
6260 if (this->end_branch_table_
!= 0)
6262 // Write pltresolve stub.
6264 Address after_bcl
= this->address() + 16;
6265 Address pltoff
= plt_base
- after_bcl
;
6267 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
6269 if (this->targ_
->abiversion() < 2)
6271 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
6272 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6273 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6274 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6275 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
6276 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6277 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6278 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
6279 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6280 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
6284 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
6285 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
6286 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
6287 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
6288 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
6289 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
6290 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
6291 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
6292 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
6293 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
6294 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
6295 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6296 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
6298 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
6299 gold_assert(p
== oview
+ this->pltresolve_size());
6301 // Write lazy link call stubs.
6303 while (p
< oview
+ this->end_branch_table_
)
6305 if (this->targ_
->abiversion() < 2)
6309 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
6313 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
6314 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
6317 uint32_t branch_off
= 8 - (p
- oview
);
6318 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
6323 Address plt_base
= this->targ_
->plt_section()->address();
6324 Address iplt_base
= invalid_address
;
6325 unsigned int global_entry_off
= this->global_entry_off();
6326 Address global_entry_base
= this->address() + global_entry_off
;
6327 typename
Global_entry_stub_entries::const_iterator ge
;
6328 for (ge
= this->global_entry_stubs_
.begin();
6329 ge
!= this->global_entry_stubs_
.end();
6332 p
= oview
+ global_entry_off
+ ge
->second
;
6333 Address plt_addr
= ge
->first
->plt_offset();
6334 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
6335 && ge
->first
->can_use_relative_reloc(false))
6337 if (iplt_base
== invalid_address
)
6338 iplt_base
= this->targ_
->iplt_section()->address();
6339 plt_addr
+= iplt_base
;
6342 plt_addr
+= plt_base
;
6343 Address my_addr
= global_entry_base
+ ge
->second
;
6344 Address off
= plt_addr
- my_addr
;
6346 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
6347 gold_error(_("linkage table error against `%s'"),
6348 ge
->first
->demangled_name().c_str());
6350 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
6351 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
6352 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
6353 write_insn
<big_endian
>(p
, bctr
);
6358 const Output_data_got_powerpc
<size
, big_endian
>* got
6359 = this->targ_
->got_section();
6360 // The address of _GLOBAL_OFFSET_TABLE_.
6361 Address g_o_t
= got
->address() + got
->g_o_t();
6363 // Write out pltresolve branch table.
6365 unsigned int the_end
= oview_size
- this->pltresolve_size();
6366 unsigned char* end_p
= oview
+ the_end
;
6367 while (p
< end_p
- 8 * 4)
6368 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
6370 write_insn
<big_endian
>(p
, nop
), p
+= 4;
6372 // Write out pltresolve call stub.
6373 end_p
= oview
+ oview_size
;
6374 if (parameters
->options().output_is_position_independent())
6376 Address res0_off
= 0;
6377 Address after_bcl_off
= the_end
+ 12;
6378 Address bcl_res0
= after_bcl_off
- res0_off
;
6380 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
6382 write_insn
<big_endian
>(p
, mflr_0
);
6384 write_insn
<big_endian
>(p
, bcl_20_31
);
6386 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
6388 write_insn
<big_endian
>(p
, mflr_12
);
6390 write_insn
<big_endian
>(p
, mtlr_0
);
6392 write_insn
<big_endian
>(p
, sub_11_11_12
);
6395 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
6397 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
6399 if (ha(got_bcl
) == ha(got_bcl
+ 4))
6401 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
6403 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
6407 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
6409 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6412 write_insn
<big_endian
>(p
, mtctr_0
);
6414 write_insn
<big_endian
>(p
, add_0_11_11
);
6416 write_insn
<big_endian
>(p
, add_11_0_11
);
6420 Address res0
= this->address();
6422 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
6424 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
6426 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6427 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
6429 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
6431 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
6433 write_insn
<big_endian
>(p
, mtctr_0
);
6435 write_insn
<big_endian
>(p
, add_0_11_11
);
6437 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
6438 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
6440 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
6442 write_insn
<big_endian
>(p
, add_11_0_11
);
6445 write_insn
<big_endian
>(p
, bctr
);
6449 write_insn
<big_endian
>(p
, nop
);
6454 of
->write_output_view(off
, oview_size
, oview
);
6458 // A class to handle linker generated save/restore functions.
6460 template<int size
, bool big_endian
>
6461 class Output_data_save_res
: public Output_section_data_build
6464 Output_data_save_res(Symbol_table
* symtab
);
6466 const unsigned char*
6473 // Write to a map file.
6475 do_print_to_mapfile(Mapfile
* mapfile
) const
6476 { mapfile
->print_output_data(this, _("** save/restore")); }
6479 do_write(Output_file
*);
6482 // The maximum size of save/restore contents.
6483 static const unsigned int savres_max
= 218*4;
6486 savres_define(Symbol_table
* symtab
,
6488 unsigned int lo
, unsigned int hi
,
6489 unsigned char* write_ent(unsigned char*, int),
6490 unsigned char* write_tail(unsigned char*, int));
6492 unsigned char *contents_
;
6495 template<bool big_endian
>
6496 static unsigned char*
6497 savegpr0(unsigned char* p
, int r
)
6499 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6500 write_insn
<big_endian
>(p
, insn
);
6504 template<bool big_endian
>
6505 static unsigned char*
6506 savegpr0_tail(unsigned char* p
, int r
)
6508 p
= savegpr0
<big_endian
>(p
, r
);
6509 uint32_t insn
= std_0_1
+ 16;
6510 write_insn
<big_endian
>(p
, insn
);
6512 write_insn
<big_endian
>(p
, blr
);
6516 template<bool big_endian
>
6517 static unsigned char*
6518 restgpr0(unsigned char* p
, int r
)
6520 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6521 write_insn
<big_endian
>(p
, insn
);
6525 template<bool big_endian
>
6526 static unsigned char*
6527 restgpr0_tail(unsigned char* p
, int r
)
6529 uint32_t insn
= ld_0_1
+ 16;
6530 write_insn
<big_endian
>(p
, insn
);
6532 p
= restgpr0
<big_endian
>(p
, r
);
6533 write_insn
<big_endian
>(p
, mtlr_0
);
6537 p
= restgpr0
<big_endian
>(p
, 30);
6538 p
= restgpr0
<big_endian
>(p
, 31);
6540 write_insn
<big_endian
>(p
, blr
);
6544 template<bool big_endian
>
6545 static unsigned char*
6546 savegpr1(unsigned char* p
, int r
)
6548 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6549 write_insn
<big_endian
>(p
, insn
);
6553 template<bool big_endian
>
6554 static unsigned char*
6555 savegpr1_tail(unsigned char* p
, int r
)
6557 p
= savegpr1
<big_endian
>(p
, r
);
6558 write_insn
<big_endian
>(p
, blr
);
6562 template<bool big_endian
>
6563 static unsigned char*
6564 restgpr1(unsigned char* p
, int r
)
6566 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6567 write_insn
<big_endian
>(p
, insn
);
6571 template<bool big_endian
>
6572 static unsigned char*
6573 restgpr1_tail(unsigned char* p
, int r
)
6575 p
= restgpr1
<big_endian
>(p
, r
);
6576 write_insn
<big_endian
>(p
, blr
);
6580 template<bool big_endian
>
6581 static unsigned char*
6582 savefpr(unsigned char* p
, int r
)
6584 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6585 write_insn
<big_endian
>(p
, insn
);
6589 template<bool big_endian
>
6590 static unsigned char*
6591 savefpr0_tail(unsigned char* p
, int r
)
6593 p
= savefpr
<big_endian
>(p
, r
);
6594 write_insn
<big_endian
>(p
, std_0_1
+ 16);
6596 write_insn
<big_endian
>(p
, blr
);
6600 template<bool big_endian
>
6601 static unsigned char*
6602 restfpr(unsigned char* p
, int r
)
6604 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
6605 write_insn
<big_endian
>(p
, insn
);
6609 template<bool big_endian
>
6610 static unsigned char*
6611 restfpr0_tail(unsigned char* p
, int r
)
6613 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
6615 p
= restfpr
<big_endian
>(p
, r
);
6616 write_insn
<big_endian
>(p
, mtlr_0
);
6620 p
= restfpr
<big_endian
>(p
, 30);
6621 p
= restfpr
<big_endian
>(p
, 31);
6623 write_insn
<big_endian
>(p
, blr
);
6627 template<bool big_endian
>
6628 static unsigned char*
6629 savefpr1_tail(unsigned char* p
, int r
)
6631 p
= savefpr
<big_endian
>(p
, r
);
6632 write_insn
<big_endian
>(p
, blr
);
6636 template<bool big_endian
>
6637 static unsigned char*
6638 restfpr1_tail(unsigned char* p
, int r
)
6640 p
= restfpr
<big_endian
>(p
, r
);
6641 write_insn
<big_endian
>(p
, blr
);
6645 template<bool big_endian
>
6646 static unsigned char*
6647 savevr(unsigned char* p
, int r
)
6649 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6650 write_insn
<big_endian
>(p
, insn
);
6652 insn
= stvx_0_12_0
+ (r
<< 21);
6653 write_insn
<big_endian
>(p
, insn
);
6657 template<bool big_endian
>
6658 static unsigned char*
6659 savevr_tail(unsigned char* p
, int r
)
6661 p
= savevr
<big_endian
>(p
, r
);
6662 write_insn
<big_endian
>(p
, blr
);
6666 template<bool big_endian
>
6667 static unsigned char*
6668 restvr(unsigned char* p
, int r
)
6670 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
6671 write_insn
<big_endian
>(p
, insn
);
6673 insn
= lvx_0_12_0
+ (r
<< 21);
6674 write_insn
<big_endian
>(p
, insn
);
6678 template<bool big_endian
>
6679 static unsigned char*
6680 restvr_tail(unsigned char* p
, int r
)
6682 p
= restvr
<big_endian
>(p
, r
);
6683 write_insn
<big_endian
>(p
, blr
);
6688 template<int size
, bool big_endian
>
6689 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
6690 Symbol_table
* symtab
)
6691 : Output_section_data_build(4),
6694 this->savres_define(symtab
,
6695 "_savegpr0_", 14, 31,
6696 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
6697 this->savres_define(symtab
,
6698 "_restgpr0_", 14, 29,
6699 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6700 this->savres_define(symtab
,
6701 "_restgpr0_", 30, 31,
6702 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6703 this->savres_define(symtab
,
6704 "_savegpr1_", 14, 31,
6705 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
6706 this->savres_define(symtab
,
6707 "_restgpr1_", 14, 31,
6708 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
6709 this->savres_define(symtab
,
6710 "_savefpr_", 14, 31,
6711 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
6712 this->savres_define(symtab
,
6713 "_restfpr_", 14, 29,
6714 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6715 this->savres_define(symtab
,
6716 "_restfpr_", 30, 31,
6717 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6718 this->savres_define(symtab
,
6720 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
6721 this->savres_define(symtab
,
6723 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
6724 this->savres_define(symtab
,
6726 savevr
<big_endian
>, savevr_tail
<big_endian
>);
6727 this->savres_define(symtab
,
6729 restvr
<big_endian
>, restvr_tail
<big_endian
>);
6732 template<int size
, bool big_endian
>
6734 Output_data_save_res
<size
, big_endian
>::savres_define(
6735 Symbol_table
* symtab
,
6737 unsigned int lo
, unsigned int hi
,
6738 unsigned char* write_ent(unsigned char*, int),
6739 unsigned char* write_tail(unsigned char*, int))
6741 size_t len
= strlen(name
);
6742 bool writing
= false;
6745 memcpy(sym
, name
, len
);
6748 for (unsigned int i
= lo
; i
<= hi
; i
++)
6750 sym
[len
+ 0] = i
/ 10 + '0';
6751 sym
[len
+ 1] = i
% 10 + '0';
6752 Symbol
* gsym
= symtab
->lookup(sym
);
6753 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
6754 writing
= writing
|| refd
;
6757 if (this->contents_
== NULL
)
6758 this->contents_
= new unsigned char[this->savres_max
];
6760 section_size_type value
= this->current_data_size();
6761 unsigned char* p
= this->contents_
+ value
;
6763 p
= write_ent(p
, i
);
6765 p
= write_tail(p
, i
);
6766 section_size_type cur_size
= p
- this->contents_
;
6767 this->set_current_data_size(cur_size
);
6769 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
6770 this, value
, cur_size
- value
,
6771 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
6772 elfcpp::STV_HIDDEN
, 0, false, false);
6777 // Write out save/restore.
6779 template<int size
, bool big_endian
>
6781 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
6783 const section_size_type off
= this->offset();
6784 const section_size_type oview_size
=
6785 convert_to_section_size_type(this->data_size());
6786 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6787 memcpy(oview
, this->contents_
, oview_size
);
6788 of
->write_output_view(off
, oview_size
, oview
);
6792 // Create the glink section.
6794 template<int size
, bool big_endian
>
6796 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
6798 if (this->glink_
== NULL
)
6800 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
6801 this->glink_
->add_eh_frame(layout
);
6802 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6803 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6804 this->glink_
, ORDER_TEXT
, false);
6808 // Create a PLT entry for a global symbol.
6810 template<int size
, bool big_endian
>
6812 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
6816 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
6817 && gsym
->can_use_relative_reloc(false))
6819 if (this->iplt_
== NULL
)
6820 this->make_iplt_section(symtab
, layout
);
6821 this->iplt_
->add_ifunc_entry(gsym
);
6825 if (this->plt_
== NULL
)
6826 this->make_plt_section(symtab
, layout
);
6827 this->plt_
->add_entry(gsym
);
6831 // Make a PLT entry for a local symbol.
6833 template<int size
, bool big_endian
>
6835 Target_powerpc
<size
, big_endian
>::make_local_plt_entry(
6837 Sized_relobj_file
<size
, big_endian
>* relobj
,
6840 if (this->lplt_
== NULL
)
6841 this->make_lplt_section(layout
);
6842 this->lplt_
->add_local_entry(relobj
, r_sym
);
6845 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
6847 template<int size
, bool big_endian
>
6849 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
6850 Symbol_table
* symtab
,
6852 Sized_relobj_file
<size
, big_endian
>* relobj
,
6855 if (this->iplt_
== NULL
)
6856 this->make_iplt_section(symtab
, layout
);
6857 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
6860 // Return the number of entries in the PLT.
6862 template<int size
, bool big_endian
>
6864 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
6866 if (this->plt_
== NULL
)
6868 return this->plt_
->entry_count();
6871 // Create a GOT entry for local dynamic __tls_get_addr calls.
6873 template<int size
, bool big_endian
>
6875 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
6876 Symbol_table
* symtab
,
6878 Sized_relobj_file
<size
, big_endian
>* object
)
6880 if (this->tlsld_got_offset_
== -1U)
6882 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
6883 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
6884 Output_data_got_powerpc
<size
, big_endian
>* got
6885 = this->got_section(symtab
, layout
);
6886 unsigned int got_offset
= got
->add_constant_pair(0, 0);
6887 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
6889 this->tlsld_got_offset_
= got_offset
;
6891 return this->tlsld_got_offset_
;
6894 // Get the Reference_flags for a particular relocation.
6896 template<int size
, bool big_endian
>
6898 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
6899 unsigned int r_type
,
6900 const Target_powerpc
* target
)
6906 case elfcpp::R_POWERPC_NONE
:
6907 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6908 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6909 case elfcpp::R_PPC64_TOC
:
6910 // No symbol reference.
6913 case elfcpp::R_PPC64_ADDR64
:
6914 case elfcpp::R_PPC64_UADDR64
:
6915 case elfcpp::R_POWERPC_ADDR32
:
6916 case elfcpp::R_POWERPC_UADDR32
:
6917 case elfcpp::R_POWERPC_ADDR16
:
6918 case elfcpp::R_POWERPC_UADDR16
:
6919 case elfcpp::R_POWERPC_ADDR16_LO
:
6920 case elfcpp::R_POWERPC_ADDR16_HI
:
6921 case elfcpp::R_POWERPC_ADDR16_HA
:
6922 ref
= Symbol::ABSOLUTE_REF
;
6925 case elfcpp::R_POWERPC_ADDR24
:
6926 case elfcpp::R_POWERPC_ADDR14
:
6927 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6928 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6929 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
6932 case elfcpp::R_PPC64_REL64
:
6933 case elfcpp::R_POWERPC_REL32
:
6934 case elfcpp::R_PPC_LOCAL24PC
:
6935 case elfcpp::R_POWERPC_REL16
:
6936 case elfcpp::R_POWERPC_REL16_LO
:
6937 case elfcpp::R_POWERPC_REL16_HI
:
6938 case elfcpp::R_POWERPC_REL16_HA
:
6939 case elfcpp::R_PPC64_REL16_HIGH
:
6940 case elfcpp::R_PPC64_REL16_HIGHA
:
6941 case elfcpp::R_PPC64_REL16_HIGHER
:
6942 case elfcpp::R_PPC64_REL16_HIGHERA
:
6943 case elfcpp::R_PPC64_REL16_HIGHEST
:
6944 case elfcpp::R_PPC64_REL16_HIGHESTA
:
6945 ref
= Symbol::RELATIVE_REF
;
6948 case elfcpp::R_PPC64_REL24_NOTOC
:
6952 case elfcpp::R_POWERPC_REL24
:
6953 case elfcpp::R_PPC_PLTREL24
:
6954 case elfcpp::R_POWERPC_REL14
:
6955 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6956 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6957 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
6960 case elfcpp::R_POWERPC_GOT16
:
6961 case elfcpp::R_POWERPC_GOT16_LO
:
6962 case elfcpp::R_POWERPC_GOT16_HI
:
6963 case elfcpp::R_POWERPC_GOT16_HA
:
6964 case elfcpp::R_PPC64_GOT16_DS
:
6965 case elfcpp::R_PPC64_GOT16_LO_DS
:
6966 case elfcpp::R_PPC64_TOC16
:
6967 case elfcpp::R_PPC64_TOC16_LO
:
6968 case elfcpp::R_PPC64_TOC16_HI
:
6969 case elfcpp::R_PPC64_TOC16_HA
:
6970 case elfcpp::R_PPC64_TOC16_DS
:
6971 case elfcpp::R_PPC64_TOC16_LO_DS
:
6972 case elfcpp::R_POWERPC_PLT16_LO
:
6973 case elfcpp::R_POWERPC_PLT16_HI
:
6974 case elfcpp::R_POWERPC_PLT16_HA
:
6975 case elfcpp::R_PPC64_PLT16_LO_DS
:
6976 ref
= Symbol::RELATIVE_REF
;
6979 case elfcpp::R_POWERPC_GOT_TPREL16
:
6980 case elfcpp::R_POWERPC_TLS
:
6981 ref
= Symbol::TLS_REF
;
6984 case elfcpp::R_POWERPC_COPY
:
6985 case elfcpp::R_POWERPC_GLOB_DAT
:
6986 case elfcpp::R_POWERPC_JMP_SLOT
:
6987 case elfcpp::R_POWERPC_RELATIVE
:
6988 case elfcpp::R_POWERPC_DTPMOD
:
6990 // Not expected. We will give an error later.
6994 if (size
== 64 && target
->abiversion() < 2)
6995 ref
|= Symbol::FUNC_DESC_ABI
;
6999 // Report an unsupported relocation against a local symbol.
7001 template<int size
, bool big_endian
>
7003 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
7004 Sized_relobj_file
<size
, big_endian
>* object
,
7005 unsigned int r_type
)
7007 gold_error(_("%s: unsupported reloc %u against local symbol"),
7008 object
->name().c_str(), r_type
);
7011 // We are about to emit a dynamic relocation of type R_TYPE. If the
7012 // dynamic linker does not support it, issue an error.
7014 template<int size
, bool big_endian
>
7016 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
7017 unsigned int r_type
)
7019 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
7021 // These are the relocation types supported by glibc for both 32-bit
7022 // and 64-bit powerpc.
7025 case elfcpp::R_POWERPC_NONE
:
7026 case elfcpp::R_POWERPC_RELATIVE
:
7027 case elfcpp::R_POWERPC_GLOB_DAT
:
7028 case elfcpp::R_POWERPC_DTPMOD
:
7029 case elfcpp::R_POWERPC_DTPREL
:
7030 case elfcpp::R_POWERPC_TPREL
:
7031 case elfcpp::R_POWERPC_JMP_SLOT
:
7032 case elfcpp::R_POWERPC_COPY
:
7033 case elfcpp::R_POWERPC_IRELATIVE
:
7034 case elfcpp::R_POWERPC_ADDR32
:
7035 case elfcpp::R_POWERPC_UADDR32
:
7036 case elfcpp::R_POWERPC_ADDR24
:
7037 case elfcpp::R_POWERPC_ADDR16
:
7038 case elfcpp::R_POWERPC_UADDR16
:
7039 case elfcpp::R_POWERPC_ADDR16_LO
:
7040 case elfcpp::R_POWERPC_ADDR16_HI
:
7041 case elfcpp::R_POWERPC_ADDR16_HA
:
7042 case elfcpp::R_POWERPC_ADDR14
:
7043 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7044 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7045 case elfcpp::R_POWERPC_REL32
:
7046 case elfcpp::R_POWERPC_REL24
:
7047 case elfcpp::R_POWERPC_TPREL16
:
7048 case elfcpp::R_POWERPC_TPREL16_LO
:
7049 case elfcpp::R_POWERPC_TPREL16_HI
:
7050 case elfcpp::R_POWERPC_TPREL16_HA
:
7061 // These are the relocation types supported only on 64-bit.
7062 case elfcpp::R_PPC64_ADDR64
:
7063 case elfcpp::R_PPC64_UADDR64
:
7064 case elfcpp::R_PPC64_JMP_IREL
:
7065 case elfcpp::R_PPC64_ADDR16_DS
:
7066 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7067 case elfcpp::R_PPC64_ADDR16_HIGH
:
7068 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7069 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7070 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7071 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7072 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7073 case elfcpp::R_PPC64_REL64
:
7074 case elfcpp::R_POWERPC_ADDR30
:
7075 case elfcpp::R_PPC64_TPREL16_DS
:
7076 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7077 case elfcpp::R_PPC64_TPREL16_HIGH
:
7078 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7079 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7080 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7081 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7082 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7093 // These are the relocation types supported only on 32-bit.
7094 // ??? glibc ld.so doesn't need to support these.
7095 case elfcpp::R_POWERPC_DTPREL16
:
7096 case elfcpp::R_POWERPC_DTPREL16_LO
:
7097 case elfcpp::R_POWERPC_DTPREL16_HI
:
7098 case elfcpp::R_POWERPC_DTPREL16_HA
:
7106 // This prevents us from issuing more than one error per reloc
7107 // section. But we can still wind up issuing more than one
7108 // error per object file.
7109 if (this->issued_non_pic_error_
)
7111 gold_assert(parameters
->options().output_is_position_independent());
7112 object
->error(_("requires unsupported dynamic reloc; "
7113 "recompile with -fPIC"));
7114 this->issued_non_pic_error_
= true;
7118 // Return whether we need to make a PLT entry for a relocation of the
7119 // given type against a STT_GNU_IFUNC symbol.
7121 template<int size
, bool big_endian
>
7123 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
7124 Target_powerpc
<size
, big_endian
>* target
,
7125 Sized_relobj_file
<size
, big_endian
>* object
,
7126 unsigned int r_type
,
7129 // In non-pic code any reference will resolve to the plt call stub
7130 // for the ifunc symbol.
7131 if ((size
== 32 || target
->abiversion() >= 2)
7132 && !parameters
->options().output_is_position_independent())
7137 // Word size refs from data sections are OK, but don't need a PLT entry.
7138 case elfcpp::R_POWERPC_ADDR32
:
7139 case elfcpp::R_POWERPC_UADDR32
:
7144 case elfcpp::R_PPC64_ADDR64
:
7145 case elfcpp::R_PPC64_UADDR64
:
7150 // GOT refs are good, but also don't need a PLT entry.
7151 case elfcpp::R_POWERPC_GOT16
:
7152 case elfcpp::R_POWERPC_GOT16_LO
:
7153 case elfcpp::R_POWERPC_GOT16_HI
:
7154 case elfcpp::R_POWERPC_GOT16_HA
:
7155 case elfcpp::R_PPC64_GOT16_DS
:
7156 case elfcpp::R_PPC64_GOT16_LO_DS
:
7159 // PLT relocs are OK and need a PLT entry.
7160 case elfcpp::R_POWERPC_PLT16_LO
:
7161 case elfcpp::R_POWERPC_PLT16_HI
:
7162 case elfcpp::R_POWERPC_PLT16_HA
:
7163 case elfcpp::R_PPC64_PLT16_LO_DS
:
7164 case elfcpp::R_POWERPC_PLTSEQ
:
7165 case elfcpp::R_POWERPC_PLTCALL
:
7166 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7167 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7171 // Function calls are good, and these do need a PLT entry.
7172 case elfcpp::R_PPC64_REL24_NOTOC
:
7176 case elfcpp::R_POWERPC_ADDR24
:
7177 case elfcpp::R_POWERPC_ADDR14
:
7178 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7179 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7180 case elfcpp::R_POWERPC_REL24
:
7181 case elfcpp::R_PPC_PLTREL24
:
7182 case elfcpp::R_POWERPC_REL14
:
7183 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7184 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7191 // Anything else is a problem.
7192 // If we are building a static executable, the libc startup function
7193 // responsible for applying indirect function relocations is going
7194 // to complain about the reloc type.
7195 // If we are building a dynamic executable, we will have a text
7196 // relocation. The dynamic loader will set the text segment
7197 // writable and non-executable to apply text relocations. So we'll
7198 // segfault when trying to run the indirection function to resolve
7201 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
7202 object
->name().c_str(), r_type
);
7206 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
7210 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
7212 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7213 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7214 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7215 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7216 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7217 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7218 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7219 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7220 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7221 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7222 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7223 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7224 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7225 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7226 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7227 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7228 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7229 /* Exclude lfqu by testing reloc. If relocs are ever
7230 defined for the reduced D field in psq_lu then those
7231 will need testing too. */
7232 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7233 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7234 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7236 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7237 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7238 /* Exclude stfqu. psq_stu as above for psq_lu. */
7239 && r_type
!= elfcpp::R_PPC64_TOC16_LO
7240 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
7241 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7242 && (insn
& 1) == 0));
7245 // Scan a relocation for a local symbol.
7247 template<int size
, bool big_endian
>
7249 Target_powerpc
<size
, big_endian
>::Scan::local(
7250 Symbol_table
* symtab
,
7252 Target_powerpc
<size
, big_endian
>* target
,
7253 Sized_relobj_file
<size
, big_endian
>* object
,
7254 unsigned int data_shndx
,
7255 Output_section
* output_section
,
7256 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7257 unsigned int r_type
,
7258 const elfcpp::Sym
<size
, big_endian
>& lsym
,
7261 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
7263 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7264 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7266 this->expect_tls_get_addr_call();
7267 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7268 if (tls_type
!= tls::TLSOPT_NONE
)
7269 this->skip_next_tls_get_addr_call();
7271 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7272 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7274 this->expect_tls_get_addr_call();
7275 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7276 if (tls_type
!= tls::TLSOPT_NONE
)
7277 this->skip_next_tls_get_addr_call();
7280 Powerpc_relobj
<size
, big_endian
>* ppc_object
7281 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7286 && data_shndx
== ppc_object
->opd_shndx()
7287 && r_type
== elfcpp::R_PPC64_ADDR64
)
7288 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7292 // A local STT_GNU_IFUNC symbol may require a PLT entry.
7293 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
7294 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7296 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7297 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7298 r_type
, r_sym
, reloc
.get_r_addend());
7299 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
7304 case elfcpp::R_POWERPC_NONE
:
7305 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7306 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7307 case elfcpp::R_POWERPC_TLS
:
7308 case elfcpp::R_PPC64_ENTRY
:
7309 case elfcpp::R_POWERPC_PLTSEQ
:
7310 case elfcpp::R_POWERPC_PLTCALL
:
7311 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7312 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7315 case elfcpp::R_PPC64_TOC
:
7317 Output_data_got_powerpc
<size
, big_endian
>* got
7318 = target
->got_section(symtab
, layout
);
7319 if (parameters
->options().output_is_position_independent())
7321 Address off
= reloc
.get_r_offset();
7323 && target
->abiversion() < 2
7324 && data_shndx
== ppc_object
->opd_shndx()
7325 && ppc_object
->get_opd_discard(off
- 8))
7328 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7329 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7330 rela_dyn
->add_output_section_relative(got
->output_section(),
7331 elfcpp::R_POWERPC_RELATIVE
,
7333 object
, data_shndx
, off
,
7334 symobj
->toc_base_offset());
7339 case elfcpp::R_PPC64_ADDR64
:
7340 case elfcpp::R_PPC64_UADDR64
:
7341 case elfcpp::R_POWERPC_ADDR32
:
7342 case elfcpp::R_POWERPC_UADDR32
:
7343 case elfcpp::R_POWERPC_ADDR24
:
7344 case elfcpp::R_POWERPC_ADDR16
:
7345 case elfcpp::R_POWERPC_ADDR16_LO
:
7346 case elfcpp::R_POWERPC_ADDR16_HI
:
7347 case elfcpp::R_POWERPC_ADDR16_HA
:
7348 case elfcpp::R_POWERPC_UADDR16
:
7349 case elfcpp::R_PPC64_ADDR16_HIGH
:
7350 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7351 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7352 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7353 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7354 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7355 case elfcpp::R_PPC64_ADDR16_DS
:
7356 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7357 case elfcpp::R_POWERPC_ADDR14
:
7358 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7359 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7360 // If building a shared library (or a position-independent
7361 // executable), we need to create a dynamic relocation for
7363 if (parameters
->options().output_is_position_independent()
7364 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7366 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7368 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7369 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7370 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
7372 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7373 : elfcpp::R_POWERPC_RELATIVE
);
7374 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7375 output_section
, data_shndx
,
7376 reloc
.get_r_offset(),
7377 reloc
.get_r_addend(), false);
7379 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
7381 check_non_pic(object
, r_type
);
7382 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
7383 data_shndx
, reloc
.get_r_offset(),
7384 reloc
.get_r_addend());
7388 gold_assert(lsym
.get_st_value() == 0);
7389 unsigned int shndx
= lsym
.get_st_shndx();
7391 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
7394 object
->error(_("section symbol %u has bad shndx %u"),
7397 rela_dyn
->add_local_section(object
, shndx
, r_type
,
7398 output_section
, data_shndx
,
7399 reloc
.get_r_offset());
7404 case elfcpp::R_POWERPC_PLT16_LO
:
7405 case elfcpp::R_POWERPC_PLT16_HI
:
7406 case elfcpp::R_POWERPC_PLT16_HA
:
7407 case elfcpp::R_PPC64_PLT16_LO_DS
:
7410 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7411 target
->make_local_plt_entry(layout
, object
, r_sym
);
7415 case elfcpp::R_PPC64_REL24_NOTOC
:
7419 case elfcpp::R_POWERPC_REL24
:
7420 case elfcpp::R_PPC_PLTREL24
:
7421 case elfcpp::R_PPC_LOCAL24PC
:
7422 case elfcpp::R_POWERPC_REL14
:
7423 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7424 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7427 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7428 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7429 r_type
, r_sym
, reloc
.get_r_addend());
7433 case elfcpp::R_PPC64_TOCSAVE
:
7434 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7435 // caller has already saved r2 and thus a plt call stub need not
7438 && target
->mark_pltcall(ppc_object
, data_shndx
,
7439 reloc
.get_r_offset() - 4, symtab
))
7441 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7442 unsigned int shndx
= lsym
.get_st_shndx();
7444 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7446 object
->error(_("tocsave symbol %u has bad shndx %u"),
7449 target
->add_tocsave(ppc_object
, shndx
,
7450 lsym
.get_st_value() + reloc
.get_r_addend());
7454 case elfcpp::R_PPC64_REL64
:
7455 case elfcpp::R_POWERPC_REL32
:
7456 case elfcpp::R_POWERPC_REL16
:
7457 case elfcpp::R_POWERPC_REL16_LO
:
7458 case elfcpp::R_POWERPC_REL16_HI
:
7459 case elfcpp::R_POWERPC_REL16_HA
:
7460 case elfcpp::R_POWERPC_REL16DX_HA
:
7461 case elfcpp::R_PPC64_REL16_HIGH
:
7462 case elfcpp::R_PPC64_REL16_HIGHA
:
7463 case elfcpp::R_PPC64_REL16_HIGHER
:
7464 case elfcpp::R_PPC64_REL16_HIGHERA
:
7465 case elfcpp::R_PPC64_REL16_HIGHEST
:
7466 case elfcpp::R_PPC64_REL16_HIGHESTA
:
7467 case elfcpp::R_POWERPC_SECTOFF
:
7468 case elfcpp::R_POWERPC_SECTOFF_LO
:
7469 case elfcpp::R_POWERPC_SECTOFF_HI
:
7470 case elfcpp::R_POWERPC_SECTOFF_HA
:
7471 case elfcpp::R_PPC64_SECTOFF_DS
:
7472 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7473 case elfcpp::R_POWERPC_TPREL16
:
7474 case elfcpp::R_POWERPC_TPREL16_LO
:
7475 case elfcpp::R_POWERPC_TPREL16_HI
:
7476 case elfcpp::R_POWERPC_TPREL16_HA
:
7477 case elfcpp::R_PPC64_TPREL16_DS
:
7478 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7479 case elfcpp::R_PPC64_TPREL16_HIGH
:
7480 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7481 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7482 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7483 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7484 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7485 case elfcpp::R_POWERPC_DTPREL16
:
7486 case elfcpp::R_POWERPC_DTPREL16_LO
:
7487 case elfcpp::R_POWERPC_DTPREL16_HI
:
7488 case elfcpp::R_POWERPC_DTPREL16_HA
:
7489 case elfcpp::R_PPC64_DTPREL16_DS
:
7490 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7491 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7492 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7493 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7494 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7495 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7496 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7497 case elfcpp::R_PPC64_TLSGD
:
7498 case elfcpp::R_PPC64_TLSLD
:
7499 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7502 case elfcpp::R_POWERPC_GOT16
:
7503 case elfcpp::R_POWERPC_GOT16_LO
:
7504 case elfcpp::R_POWERPC_GOT16_HI
:
7505 case elfcpp::R_POWERPC_GOT16_HA
:
7506 case elfcpp::R_PPC64_GOT16_DS
:
7507 case elfcpp::R_PPC64_GOT16_LO_DS
:
7509 // The symbol requires a GOT entry.
7510 Output_data_got_powerpc
<size
, big_endian
>* got
7511 = target
->got_section(symtab
, layout
);
7512 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7514 if (!parameters
->options().output_is_position_independent())
7517 && (size
== 32 || target
->abiversion() >= 2))
7518 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
7520 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
7522 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
7524 // If we are generating a shared object or a pie, this
7525 // symbol's GOT entry will be set by a dynamic relocation.
7527 off
= got
->add_constant(0);
7528 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
7530 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
7532 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7533 : elfcpp::R_POWERPC_RELATIVE
);
7534 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
7535 got
, off
, 0, false);
7540 case elfcpp::R_PPC64_TOC16
:
7541 case elfcpp::R_PPC64_TOC16_LO
:
7542 case elfcpp::R_PPC64_TOC16_HI
:
7543 case elfcpp::R_PPC64_TOC16_HA
:
7544 case elfcpp::R_PPC64_TOC16_DS
:
7545 case elfcpp::R_PPC64_TOC16_LO_DS
:
7546 // We need a GOT section.
7547 target
->got_section(symtab
, layout
);
7550 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7551 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7552 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7553 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7555 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
7556 if (tls_type
== tls::TLSOPT_NONE
)
7558 Output_data_got_powerpc
<size
, big_endian
>* got
7559 = target
->got_section(symtab
, layout
);
7560 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7561 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7562 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
7563 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
7565 else if (tls_type
== tls::TLSOPT_TO_LE
)
7567 // no GOT relocs needed for Local Exec.
7574 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7575 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7576 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7577 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7579 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7580 if (tls_type
== tls::TLSOPT_NONE
)
7581 target
->tlsld_got_offset(symtab
, layout
, object
);
7582 else if (tls_type
== tls::TLSOPT_TO_LE
)
7584 // no GOT relocs needed for Local Exec.
7585 if (parameters
->options().emit_relocs())
7587 Output_section
* os
= layout
->tls_segment()->first_section();
7588 gold_assert(os
!= NULL
);
7589 os
->set_needs_symtab_index();
7597 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7598 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7599 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7600 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7602 Output_data_got_powerpc
<size
, big_endian
>* got
7603 = target
->got_section(symtab
, layout
);
7604 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7605 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
7609 case elfcpp::R_POWERPC_GOT_TPREL16
:
7610 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7611 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7612 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7614 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
7615 if (tls_type
== tls::TLSOPT_NONE
)
7617 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7618 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
7620 Output_data_got_powerpc
<size
, big_endian
>* got
7621 = target
->got_section(symtab
, layout
);
7622 unsigned int off
= got
->add_constant(0);
7623 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
7625 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7626 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
7627 elfcpp::R_POWERPC_TPREL
,
7631 else if (tls_type
== tls::TLSOPT_TO_LE
)
7633 // no GOT relocs needed for Local Exec.
7641 unsupported_reloc_local(object
, r_type
);
7646 && parameters
->options().toc_optimize())
7648 if (data_shndx
== ppc_object
->toc_shndx())
7651 if (r_type
!= elfcpp::R_PPC64_ADDR64
7652 || (is_ifunc
&& target
->abiversion() < 2))
7654 else if (parameters
->options().output_is_position_independent())
7660 unsigned int shndx
= lsym
.get_st_shndx();
7661 if (shndx
>= elfcpp::SHN_LORESERVE
7662 && shndx
!= elfcpp::SHN_XINDEX
)
7667 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
7670 enum {no_check
, check_lo
, check_ha
} insn_check
;
7674 insn_check
= no_check
;
7677 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7678 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7679 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7680 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7681 case elfcpp::R_POWERPC_GOT16_HA
:
7682 case elfcpp::R_PPC64_TOC16_HA
:
7683 insn_check
= check_ha
;
7686 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7687 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7688 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7689 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7690 case elfcpp::R_POWERPC_GOT16_LO
:
7691 case elfcpp::R_PPC64_GOT16_LO_DS
:
7692 case elfcpp::R_PPC64_TOC16_LO
:
7693 case elfcpp::R_PPC64_TOC16_LO_DS
:
7694 insn_check
= check_lo
;
7698 section_size_type slen
;
7699 const unsigned char* view
= NULL
;
7700 if (insn_check
!= no_check
)
7702 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
7703 section_size_type off
=
7704 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
7707 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
7708 if (insn_check
== check_lo
7709 ? !ok_lo_toc_insn(insn
, r_type
)
7710 : ((insn
& ((0x3f << 26) | 0x1f << 16))
7711 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
7713 ppc_object
->set_no_toc_opt();
7714 gold_warning(_("%s: toc optimization is not supported "
7715 "for %#08x instruction"),
7716 ppc_object
->name().c_str(), insn
);
7725 case elfcpp::R_PPC64_TOC16
:
7726 case elfcpp::R_PPC64_TOC16_LO
:
7727 case elfcpp::R_PPC64_TOC16_HI
:
7728 case elfcpp::R_PPC64_TOC16_HA
:
7729 case elfcpp::R_PPC64_TOC16_DS
:
7730 case elfcpp::R_PPC64_TOC16_LO_DS
:
7731 unsigned int shndx
= lsym
.get_st_shndx();
7732 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7734 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7735 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
7737 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
7738 if (dst_off
< ppc_object
->section_size(shndx
))
7741 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
7743 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
7745 // Need to check that the insn is a ld
7747 view
= ppc_object
->section_contents(data_shndx
,
7750 section_size_type off
=
7751 (convert_to_section_size_type(reloc
.get_r_offset())
7752 + (big_endian
? -2 : 3));
7754 && (view
[off
] & (0x3f << 2)) == 58u << 2)
7758 ppc_object
->set_no_toc_opt(dst_off
);
7769 case elfcpp::R_POWERPC_REL32
:
7770 if (ppc_object
->got2_shndx() != 0
7771 && parameters
->options().output_is_position_independent())
7773 unsigned int shndx
= lsym
.get_st_shndx();
7774 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7776 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7777 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
7778 && (ppc_object
->section_flags(data_shndx
)
7779 & elfcpp::SHF_EXECINSTR
) != 0)
7780 gold_error(_("%s: unsupported -mbss-plt code"),
7781 ppc_object
->name().c_str());
7791 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7792 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7793 case elfcpp::R_POWERPC_GOT_TPREL16
:
7794 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7795 case elfcpp::R_POWERPC_GOT16
:
7796 case elfcpp::R_PPC64_GOT16_DS
:
7797 case elfcpp::R_PPC64_TOC16
:
7798 case elfcpp::R_PPC64_TOC16_DS
:
7799 ppc_object
->set_has_small_toc_reloc();
7805 // Report an unsupported relocation against a global symbol.
7807 template<int size
, bool big_endian
>
7809 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
7810 Sized_relobj_file
<size
, big_endian
>* object
,
7811 unsigned int r_type
,
7814 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
7815 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
7818 // Scan a relocation for a global symbol.
7820 template<int size
, bool big_endian
>
7822 Target_powerpc
<size
, big_endian
>::Scan::global(
7823 Symbol_table
* symtab
,
7825 Target_powerpc
<size
, big_endian
>* target
,
7826 Sized_relobj_file
<size
, big_endian
>* object
,
7827 unsigned int data_shndx
,
7828 Output_section
* output_section
,
7829 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7830 unsigned int r_type
,
7833 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
7837 if (target
->replace_tls_get_addr(gsym
))
7838 // Change a __tls_get_addr reference to __tls_get_addr_opt
7839 // so dynamic relocs are emitted against the latter symbol.
7840 gsym
= target
->tls_get_addr_opt();
7842 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7843 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7845 this->expect_tls_get_addr_call();
7846 const bool final
= gsym
->final_value_is_known();
7847 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7848 if (tls_type
!= tls::TLSOPT_NONE
)
7849 this->skip_next_tls_get_addr_call();
7851 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7852 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7854 this->expect_tls_get_addr_call();
7855 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7856 if (tls_type
!= tls::TLSOPT_NONE
)
7857 this->skip_next_tls_get_addr_call();
7860 Powerpc_relobj
<size
, big_endian
>* ppc_object
7861 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7863 // A STT_GNU_IFUNC symbol may require a PLT entry.
7864 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
7865 bool pushed_ifunc
= false;
7866 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7868 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7869 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7870 r_type
, r_sym
, reloc
.get_r_addend());
7871 target
->make_plt_entry(symtab
, layout
, gsym
);
7872 pushed_ifunc
= true;
7877 case elfcpp::R_POWERPC_NONE
:
7878 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7879 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7880 case elfcpp::R_PPC_LOCAL24PC
:
7881 case elfcpp::R_POWERPC_TLS
:
7882 case elfcpp::R_PPC64_ENTRY
:
7883 case elfcpp::R_POWERPC_PLTSEQ
:
7884 case elfcpp::R_POWERPC_PLTCALL
:
7885 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
7886 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
7889 case elfcpp::R_PPC64_TOC
:
7891 Output_data_got_powerpc
<size
, big_endian
>* got
7892 = target
->got_section(symtab
, layout
);
7893 if (parameters
->options().output_is_position_independent())
7895 Address off
= reloc
.get_r_offset();
7897 && data_shndx
== ppc_object
->opd_shndx()
7898 && ppc_object
->get_opd_discard(off
- 8))
7901 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7902 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7903 if (data_shndx
!= ppc_object
->opd_shndx())
7904 symobj
= static_cast
7905 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
7906 rela_dyn
->add_output_section_relative(got
->output_section(),
7907 elfcpp::R_POWERPC_RELATIVE
,
7909 object
, data_shndx
, off
,
7910 symobj
->toc_base_offset());
7915 case elfcpp::R_PPC64_ADDR64
:
7917 && target
->abiversion() < 2
7918 && data_shndx
== ppc_object
->opd_shndx()
7919 && (gsym
->is_defined_in_discarded_section()
7920 || gsym
->object() != object
))
7922 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7926 case elfcpp::R_PPC64_UADDR64
:
7927 case elfcpp::R_POWERPC_ADDR32
:
7928 case elfcpp::R_POWERPC_UADDR32
:
7929 case elfcpp::R_POWERPC_ADDR24
:
7930 case elfcpp::R_POWERPC_ADDR16
:
7931 case elfcpp::R_POWERPC_ADDR16_LO
:
7932 case elfcpp::R_POWERPC_ADDR16_HI
:
7933 case elfcpp::R_POWERPC_ADDR16_HA
:
7934 case elfcpp::R_POWERPC_UADDR16
:
7935 case elfcpp::R_PPC64_ADDR16_HIGH
:
7936 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7937 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7938 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7939 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7940 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7941 case elfcpp::R_PPC64_ADDR16_DS
:
7942 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7943 case elfcpp::R_POWERPC_ADDR14
:
7944 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7945 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7947 // Make a PLT entry if necessary.
7948 if (gsym
->needs_plt_entry())
7950 // Since this is not a PC-relative relocation, we may be
7951 // taking the address of a function. In that case we need to
7952 // set the entry in the dynamic symbol table to the address of
7953 // the PLT call stub.
7954 bool need_ifunc_plt
= false;
7955 if ((size
== 32 || target
->abiversion() >= 2)
7956 && gsym
->is_from_dynobj()
7957 && !parameters
->options().output_is_position_independent())
7959 gsym
->set_needs_dynsym_value();
7960 need_ifunc_plt
= true;
7962 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
7964 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7965 target
->push_branch(ppc_object
, data_shndx
,
7966 reloc
.get_r_offset(), r_type
, r_sym
,
7967 reloc
.get_r_addend());
7968 target
->make_plt_entry(symtab
, layout
, gsym
);
7971 // Make a dynamic relocation if necessary.
7972 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
7973 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7975 if (!parameters
->options().output_is_position_independent()
7976 && gsym
->may_need_copy_reloc())
7978 target
->copy_reloc(symtab
, layout
, object
,
7979 data_shndx
, output_section
, gsym
, reloc
);
7981 else if ((((size
== 32
7982 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7984 && r_type
== elfcpp::R_PPC64_ADDR64
7985 && target
->abiversion() >= 2))
7986 && gsym
->can_use_relative_reloc(false)
7987 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
7988 && parameters
->options().shared()))
7990 && r_type
== elfcpp::R_PPC64_ADDR64
7991 && target
->abiversion() < 2
7992 && (gsym
->can_use_relative_reloc(false)
7993 || data_shndx
== ppc_object
->opd_shndx())))
7995 Reloc_section
* rela_dyn
7996 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
7997 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7998 : elfcpp::R_POWERPC_RELATIVE
);
7999 rela_dyn
->add_symbolless_global_addend(
8000 gsym
, dynrel
, output_section
, object
, data_shndx
,
8001 reloc
.get_r_offset(), reloc
.get_r_addend());
8005 Reloc_section
* rela_dyn
8006 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8007 check_non_pic(object
, r_type
);
8008 rela_dyn
->add_global(gsym
, r_type
, output_section
,
8010 reloc
.get_r_offset(),
8011 reloc
.get_r_addend());
8014 && parameters
->options().toc_optimize()
8015 && data_shndx
== ppc_object
->toc_shndx())
8016 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8022 case elfcpp::R_POWERPC_PLT16_LO
:
8023 case elfcpp::R_POWERPC_PLT16_HI
:
8024 case elfcpp::R_POWERPC_PLT16_HA
:
8025 case elfcpp::R_PPC64_PLT16_LO_DS
:
8027 target
->make_plt_entry(symtab
, layout
, gsym
);
8030 case elfcpp::R_PPC64_REL24_NOTOC
:
8034 case elfcpp::R_PPC_PLTREL24
:
8035 case elfcpp::R_POWERPC_REL24
:
8038 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8039 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8040 r_type
, r_sym
, reloc
.get_r_addend());
8041 if (gsym
->needs_plt_entry()
8042 || (!gsym
->final_value_is_known()
8043 && (gsym
->is_undefined()
8044 || gsym
->is_from_dynobj()
8045 || gsym
->is_preemptible())))
8046 target
->make_plt_entry(symtab
, layout
, gsym
);
8050 case elfcpp::R_PPC64_REL64
:
8051 case elfcpp::R_POWERPC_REL32
:
8052 // Make a dynamic relocation if necessary.
8053 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
8055 if (!parameters
->options().output_is_position_independent()
8056 && gsym
->may_need_copy_reloc())
8058 target
->copy_reloc(symtab
, layout
, object
,
8059 data_shndx
, output_section
, gsym
,
8064 Reloc_section
* rela_dyn
8065 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8066 check_non_pic(object
, r_type
);
8067 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
8068 data_shndx
, reloc
.get_r_offset(),
8069 reloc
.get_r_addend());
8074 case elfcpp::R_POWERPC_REL14
:
8075 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8076 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8079 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8080 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
8081 r_type
, r_sym
, reloc
.get_r_addend());
8085 case elfcpp::R_PPC64_TOCSAVE
:
8086 // R_PPC64_TOCSAVE follows a call instruction to indicate the
8087 // caller has already saved r2 and thus a plt call stub need not
8090 && target
->mark_pltcall(ppc_object
, data_shndx
,
8091 reloc
.get_r_offset() - 4, symtab
))
8093 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
8095 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8097 object
->error(_("tocsave symbol %u has bad shndx %u"),
8101 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8102 target
->add_tocsave(ppc_object
, shndx
,
8103 sym
->value() + reloc
.get_r_addend());
8108 case elfcpp::R_POWERPC_REL16
:
8109 case elfcpp::R_POWERPC_REL16_LO
:
8110 case elfcpp::R_POWERPC_REL16_HI
:
8111 case elfcpp::R_POWERPC_REL16_HA
:
8112 case elfcpp::R_POWERPC_REL16DX_HA
:
8113 case elfcpp::R_PPC64_REL16_HIGH
:
8114 case elfcpp::R_PPC64_REL16_HIGHA
:
8115 case elfcpp::R_PPC64_REL16_HIGHER
:
8116 case elfcpp::R_PPC64_REL16_HIGHERA
:
8117 case elfcpp::R_PPC64_REL16_HIGHEST
:
8118 case elfcpp::R_PPC64_REL16_HIGHESTA
:
8119 case elfcpp::R_POWERPC_SECTOFF
:
8120 case elfcpp::R_POWERPC_SECTOFF_LO
:
8121 case elfcpp::R_POWERPC_SECTOFF_HI
:
8122 case elfcpp::R_POWERPC_SECTOFF_HA
:
8123 case elfcpp::R_PPC64_SECTOFF_DS
:
8124 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8125 case elfcpp::R_POWERPC_TPREL16
:
8126 case elfcpp::R_POWERPC_TPREL16_LO
:
8127 case elfcpp::R_POWERPC_TPREL16_HI
:
8128 case elfcpp::R_POWERPC_TPREL16_HA
:
8129 case elfcpp::R_PPC64_TPREL16_DS
:
8130 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8131 case elfcpp::R_PPC64_TPREL16_HIGH
:
8132 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8133 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8134 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8135 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8136 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8137 case elfcpp::R_POWERPC_DTPREL16
:
8138 case elfcpp::R_POWERPC_DTPREL16_LO
:
8139 case elfcpp::R_POWERPC_DTPREL16_HI
:
8140 case elfcpp::R_POWERPC_DTPREL16_HA
:
8141 case elfcpp::R_PPC64_DTPREL16_DS
:
8142 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8143 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8144 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8145 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8146 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8147 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8148 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8149 case elfcpp::R_PPC64_TLSGD
:
8150 case elfcpp::R_PPC64_TLSLD
:
8151 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8154 case elfcpp::R_POWERPC_GOT16
:
8155 case elfcpp::R_POWERPC_GOT16_LO
:
8156 case elfcpp::R_POWERPC_GOT16_HI
:
8157 case elfcpp::R_POWERPC_GOT16_HA
:
8158 case elfcpp::R_PPC64_GOT16_DS
:
8159 case elfcpp::R_PPC64_GOT16_LO_DS
:
8161 // The symbol requires a GOT entry.
8162 Output_data_got_powerpc
<size
, big_endian
>* got
;
8164 got
= target
->got_section(symtab
, layout
);
8165 if (gsym
->final_value_is_known())
8168 && (size
== 32 || target
->abiversion() >= 2))
8169 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
8171 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
8173 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
8175 // If we are generating a shared object or a pie, this
8176 // symbol's GOT entry will be set by a dynamic relocation.
8177 unsigned int off
= got
->add_constant(0);
8178 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
8180 Reloc_section
* rela_dyn
8181 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
8183 if (gsym
->can_use_relative_reloc(false)
8185 || target
->abiversion() >= 2)
8186 && gsym
->visibility() == elfcpp::STV_PROTECTED
8187 && parameters
->options().shared()))
8189 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
8190 : elfcpp::R_POWERPC_RELATIVE
);
8191 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
8195 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
8196 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
8202 case elfcpp::R_PPC64_TOC16
:
8203 case elfcpp::R_PPC64_TOC16_LO
:
8204 case elfcpp::R_PPC64_TOC16_HI
:
8205 case elfcpp::R_PPC64_TOC16_HA
:
8206 case elfcpp::R_PPC64_TOC16_DS
:
8207 case elfcpp::R_PPC64_TOC16_LO_DS
:
8208 // We need a GOT section.
8209 target
->got_section(symtab
, layout
);
8212 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8213 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8214 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8215 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8217 const bool final
= gsym
->final_value_is_known();
8218 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8219 if (tls_type
== tls::TLSOPT_NONE
)
8221 Output_data_got_powerpc
<size
, big_endian
>* got
8222 = target
->got_section(symtab
, layout
);
8223 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8224 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
8225 elfcpp::R_POWERPC_DTPMOD
,
8226 elfcpp::R_POWERPC_DTPREL
);
8228 else if (tls_type
== tls::TLSOPT_TO_IE
)
8230 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8232 Output_data_got_powerpc
<size
, big_endian
>* got
8233 = target
->got_section(symtab
, layout
);
8234 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8235 if (gsym
->is_undefined()
8236 || gsym
->is_from_dynobj())
8238 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8239 elfcpp::R_POWERPC_TPREL
);
8243 unsigned int off
= got
->add_constant(0);
8244 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8245 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8246 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8251 else if (tls_type
== tls::TLSOPT_TO_LE
)
8253 // no GOT relocs needed for Local Exec.
8260 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8261 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8262 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8263 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8265 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8266 if (tls_type
== tls::TLSOPT_NONE
)
8267 target
->tlsld_got_offset(symtab
, layout
, object
);
8268 else if (tls_type
== tls::TLSOPT_TO_LE
)
8270 // no GOT relocs needed for Local Exec.
8271 if (parameters
->options().emit_relocs())
8273 Output_section
* os
= layout
->tls_segment()->first_section();
8274 gold_assert(os
!= NULL
);
8275 os
->set_needs_symtab_index();
8283 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8284 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8285 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8286 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8288 Output_data_got_powerpc
<size
, big_endian
>* got
8289 = target
->got_section(symtab
, layout
);
8290 if (!gsym
->final_value_is_known()
8291 && (gsym
->is_from_dynobj()
8292 || gsym
->is_undefined()
8293 || gsym
->is_preemptible()))
8294 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
8295 target
->rela_dyn_section(layout
),
8296 elfcpp::R_POWERPC_DTPREL
);
8298 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
8302 case elfcpp::R_POWERPC_GOT_TPREL16
:
8303 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8304 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8305 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8307 const bool final
= gsym
->final_value_is_known();
8308 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8309 if (tls_type
== tls::TLSOPT_NONE
)
8311 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
8313 Output_data_got_powerpc
<size
, big_endian
>* got
8314 = target
->got_section(symtab
, layout
);
8315 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
8316 if (gsym
->is_undefined()
8317 || gsym
->is_from_dynobj())
8319 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
8320 elfcpp::R_POWERPC_TPREL
);
8324 unsigned int off
= got
->add_constant(0);
8325 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
8326 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
8327 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
8332 else if (tls_type
== tls::TLSOPT_TO_LE
)
8334 // no GOT relocs needed for Local Exec.
8342 unsupported_reloc_global(object
, r_type
, gsym
);
8347 && parameters
->options().toc_optimize())
8349 if (data_shndx
== ppc_object
->toc_shndx())
8352 if (r_type
!= elfcpp::R_PPC64_ADDR64
8353 || (is_ifunc
&& target
->abiversion() < 2))
8355 else if (parameters
->options().output_is_position_independent()
8356 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
8359 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
8362 enum {no_check
, check_lo
, check_ha
} insn_check
;
8366 insn_check
= no_check
;
8369 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8370 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8371 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8372 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8373 case elfcpp::R_POWERPC_GOT16_HA
:
8374 case elfcpp::R_PPC64_TOC16_HA
:
8375 insn_check
= check_ha
;
8378 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8379 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8380 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8381 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8382 case elfcpp::R_POWERPC_GOT16_LO
:
8383 case elfcpp::R_PPC64_GOT16_LO_DS
:
8384 case elfcpp::R_PPC64_TOC16_LO
:
8385 case elfcpp::R_PPC64_TOC16_LO_DS
:
8386 insn_check
= check_lo
;
8390 section_size_type slen
;
8391 const unsigned char* view
= NULL
;
8392 if (insn_check
!= no_check
)
8394 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
8395 section_size_type off
=
8396 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
8399 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
8400 if (insn_check
== check_lo
8401 ? !ok_lo_toc_insn(insn
, r_type
)
8402 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8403 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8405 ppc_object
->set_no_toc_opt();
8406 gold_warning(_("%s: toc optimization is not supported "
8407 "for %#08x instruction"),
8408 ppc_object
->name().c_str(), insn
);
8417 case elfcpp::R_PPC64_TOC16
:
8418 case elfcpp::R_PPC64_TOC16_LO
:
8419 case elfcpp::R_PPC64_TOC16_HI
:
8420 case elfcpp::R_PPC64_TOC16_HA
:
8421 case elfcpp::R_PPC64_TOC16_DS
:
8422 case elfcpp::R_PPC64_TOC16_LO_DS
:
8423 if (gsym
->source() == Symbol::FROM_OBJECT
8424 && !gsym
->object()->is_dynamic())
8426 Powerpc_relobj
<size
, big_endian
>* sym_object
8427 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8429 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
8430 if (shndx
== sym_object
->toc_shndx())
8432 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
8433 Address dst_off
= sym
->value() + reloc
.get_r_addend();
8434 if (dst_off
< sym_object
->section_size(shndx
))
8437 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
8439 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
8441 // Need to check that the insn is a ld
8443 view
= ppc_object
->section_contents(data_shndx
,
8446 section_size_type off
=
8447 (convert_to_section_size_type(reloc
.get_r_offset())
8448 + (big_endian
? -2 : 3));
8450 && (view
[off
] & (0x3f << 2)) == (58u << 2))
8454 sym_object
->set_no_toc_opt(dst_off
);
8466 case elfcpp::R_PPC_LOCAL24PC
:
8467 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
8468 gold_error(_("%s: unsupported -mbss-plt code"),
8469 ppc_object
->name().c_str());
8478 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8479 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8480 case elfcpp::R_POWERPC_GOT_TPREL16
:
8481 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8482 case elfcpp::R_POWERPC_GOT16
:
8483 case elfcpp::R_PPC64_GOT16_DS
:
8484 case elfcpp::R_PPC64_TOC16
:
8485 case elfcpp::R_PPC64_TOC16_DS
:
8486 ppc_object
->set_has_small_toc_reloc();
8492 // Process relocations for gc.
8494 template<int size
, bool big_endian
>
8496 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
8497 Symbol_table
* symtab
,
8499 Sized_relobj_file
<size
, big_endian
>* object
,
8500 unsigned int data_shndx
,
8502 const unsigned char* prelocs
,
8504 Output_section
* output_section
,
8505 bool needs_special_offset_handling
,
8506 size_t local_symbol_count
,
8507 const unsigned char* plocal_symbols
)
8509 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8510 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8513 Powerpc_relobj
<size
, big_endian
>* ppc_object
8514 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
8516 ppc_object
->set_opd_valid();
8517 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
8519 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
8520 for (p
= ppc_object
->access_from_map()->begin();
8521 p
!= ppc_object
->access_from_map()->end();
8524 Address dst_off
= p
->first
;
8525 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8526 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
8527 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
8529 Relobj
* src_obj
= s
->first
;
8530 unsigned int src_indx
= s
->second
;
8531 symtab
->gc()->add_reference(src_obj
, src_indx
,
8532 ppc_object
, dst_indx
);
8536 ppc_object
->access_from_map()->clear();
8537 ppc_object
->process_gc_mark(symtab
);
8538 // Don't look at .opd relocs as .opd will reference everything.
8542 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
8551 needs_special_offset_handling
,
8556 // Handle target specific gc actions when adding a gc reference from
8557 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
8558 // and DST_OFF. For powerpc64, this adds a referenc to the code
8559 // section of a function descriptor.
8561 template<int size
, bool big_endian
>
8563 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
8564 Symbol_table
* symtab
,
8566 unsigned int src_shndx
,
8568 unsigned int dst_shndx
,
8569 Address dst_off
) const
8571 if (size
!= 64 || dst_obj
->is_dynamic())
8574 Powerpc_relobj
<size
, big_endian
>* ppc_object
8575 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
8576 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
8578 if (ppc_object
->opd_valid())
8580 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
8581 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
8585 // If we haven't run scan_opd_relocs, we must delay
8586 // processing this function descriptor reference.
8587 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
8592 // Add any special sections for this symbol to the gc work list.
8593 // For powerpc64, this adds the code section of a function
8596 template<int size
, bool big_endian
>
8598 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
8599 Symbol_table
* symtab
,
8604 Powerpc_relobj
<size
, big_endian
>* ppc_object
8605 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
8607 unsigned int shndx
= sym
->shndx(&is_ordinary
);
8608 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
8610 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
8611 Address dst_off
= gsym
->value();
8612 if (ppc_object
->opd_valid())
8614 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
8615 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
8619 ppc_object
->add_gc_mark(dst_off
);
8624 // For a symbol location in .opd, set LOC to the location of the
8627 template<int size
, bool big_endian
>
8629 Target_powerpc
<size
, big_endian
>::do_function_location(
8630 Symbol_location
* loc
) const
8632 if (size
== 64 && loc
->shndx
!= 0)
8634 if (loc
->object
->is_dynamic())
8636 Powerpc_dynobj
<size
, big_endian
>* ppc_object
8637 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
8638 if (loc
->shndx
== ppc_object
->opd_shndx())
8641 Address off
= loc
->offset
- ppc_object
->opd_address();
8642 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
8643 loc
->offset
= dest_off
;
8648 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8649 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
8650 if (loc
->shndx
== ppc_object
->opd_shndx())
8653 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
8654 loc
->offset
= dest_off
;
8660 // FNOFFSET in section SHNDX in OBJECT is the start of a function
8661 // compiled with -fsplit-stack. The function calls non-split-stack
8662 // code. Change the function to ensure it has enough stack space to
8663 // call some random function.
8665 template<int size
, bool big_endian
>
8667 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
8670 section_offset_type fnoffset
,
8671 section_size_type fnsize
,
8672 const unsigned char* prelocs
,
8674 unsigned char* view
,
8675 section_size_type view_size
,
8677 std::string
* to
) const
8679 // 32-bit not supported.
8683 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
8684 prelocs
, reloc_count
, view
, view_size
,
8689 // The function always starts with
8690 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
8691 // addis %r12,%r1,-allocate@ha
8692 // addi %r12,%r12,-allocate@l
8694 // but note that the addis or addi may be replaced with a nop
8696 unsigned char *entry
= view
+ fnoffset
;
8697 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
8699 if ((insn
& 0xffff0000) == addis_2_12
)
8701 /* Skip ELFv2 global entry code. */
8703 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
8706 unsigned char *pinsn
= entry
;
8708 const uint32_t ld_private_ss
= 0xe80d8fc0;
8709 if (insn
== ld_private_ss
)
8711 int32_t allocate
= 0;
8715 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
8716 if ((insn
& 0xffff0000) == addis_12_1
)
8717 allocate
+= (insn
& 0xffff) << 16;
8718 else if ((insn
& 0xffff0000) == addi_12_1
8719 || (insn
& 0xffff0000) == addi_12_12
)
8720 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
8721 else if (insn
!= nop
)
8724 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
8726 int extra
= parameters
->options().split_stack_adjust_size();
8728 if (allocate
>= 0 || extra
< 0)
8730 object
->error(_("split-stack stack size overflow at "
8731 "section %u offset %0zx"),
8732 shndx
, static_cast<size_t>(fnoffset
));
8736 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
8737 if (insn
!= addis_12_1
)
8739 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
8741 insn
= addi_12_12
| (allocate
& 0xffff);
8742 if (insn
!= addi_12_12
)
8744 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
8750 insn
= addi_12_1
| (allocate
& 0xffff);
8751 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
8754 if (pinsn
!= entry
+ 12)
8755 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
8763 if (!object
->has_no_split_stack())
8764 object
->error(_("failed to match split-stack sequence at "
8765 "section %u offset %0zx"),
8766 shndx
, static_cast<size_t>(fnoffset
));
8770 // Scan relocations for a section.
8772 template<int size
, bool big_endian
>
8774 Target_powerpc
<size
, big_endian
>::scan_relocs(
8775 Symbol_table
* symtab
,
8777 Sized_relobj_file
<size
, big_endian
>* object
,
8778 unsigned int data_shndx
,
8779 unsigned int sh_type
,
8780 const unsigned char* prelocs
,
8782 Output_section
* output_section
,
8783 bool needs_special_offset_handling
,
8784 size_t local_symbol_count
,
8785 const unsigned char* plocal_symbols
)
8787 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8788 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8791 if (!this->plt_localentry0_init_
)
8793 bool plt_localentry0
= false;
8795 && this->abiversion() >= 2)
8797 if (parameters
->options().user_set_plt_localentry())
8798 plt_localentry0
= parameters
->options().plt_localentry();
8800 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
8801 gold_warning(_("--plt-localentry is especially dangerous without "
8802 "ld.so support to detect ABI violations"));
8804 this->plt_localentry0_
= plt_localentry0
;
8805 this->plt_localentry0_init_
= true;
8808 if (sh_type
== elfcpp::SHT_REL
)
8810 gold_error(_("%s: unsupported REL reloc section"),
8811 object
->name().c_str());
8815 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
8824 needs_special_offset_handling
,
8829 // Functor class for processing the global symbol table.
8830 // Removes symbols defined on discarded opd entries.
8832 template<bool big_endian
>
8833 class Global_symbol_visitor_opd
8836 Global_symbol_visitor_opd()
8840 operator()(Sized_symbol
<64>* sym
)
8842 if (sym
->has_symtab_index()
8843 || sym
->source() != Symbol::FROM_OBJECT
8844 || !sym
->in_real_elf())
8847 if (sym
->object()->is_dynamic())
8850 Powerpc_relobj
<64, big_endian
>* symobj
8851 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
8852 if (symobj
->opd_shndx() == 0)
8856 unsigned int shndx
= sym
->shndx(&is_ordinary
);
8857 if (shndx
== symobj
->opd_shndx()
8858 && symobj
->get_opd_discard(sym
->value()))
8860 sym
->set_undefined();
8861 sym
->set_visibility(elfcpp::STV_DEFAULT
);
8862 sym
->set_is_defined_in_discarded_section();
8863 sym
->set_symtab_index(-1U);
8868 template<int size
, bool big_endian
>
8870 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
8872 Symbol_table
* symtab
)
8876 Output_data_save_res
<size
, big_endian
>* savres
8877 = new Output_data_save_res
<size
, big_endian
>(symtab
);
8878 this->savres_section_
= savres
;
8879 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8880 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
8881 savres
, ORDER_TEXT
, false);
8885 // Sort linker created .got section first (for the header), then input
8886 // sections belonging to files using small model code.
8888 template<bool big_endian
>
8889 class Sort_toc_sections
8893 operator()(const Output_section::Input_section
& is1
,
8894 const Output_section::Input_section
& is2
) const
8896 if (!is1
.is_input_section() && is2
.is_input_section())
8899 = (is1
.is_input_section()
8900 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
8901 ->has_small_toc_reloc()));
8903 = (is2
.is_input_section()
8904 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
8905 ->has_small_toc_reloc()));
8906 return small1
&& !small2
;
8910 // Finalize the sections.
8912 template<int size
, bool big_endian
>
8914 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
8916 const Input_objects
* input_objects
,
8917 Symbol_table
* symtab
)
8919 if (parameters
->doing_static_link())
8921 // At least some versions of glibc elf-init.o have a strong
8922 // reference to __rela_iplt marker syms. A weak ref would be
8924 if (this->iplt_
!= NULL
)
8926 Reloc_section
* rel
= this->iplt_
->rel_plt();
8927 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
8928 Symbol_table::PREDEFINED
, rel
, 0, 0,
8929 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8930 elfcpp::STV_HIDDEN
, 0, false, true);
8931 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
8932 Symbol_table::PREDEFINED
, rel
, 0, 0,
8933 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8934 elfcpp::STV_HIDDEN
, 0, true, true);
8938 symtab
->define_as_constant("__rela_iplt_start", NULL
,
8939 Symbol_table::PREDEFINED
, 0, 0,
8940 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8941 elfcpp::STV_HIDDEN
, 0, true, false);
8942 symtab
->define_as_constant("__rela_iplt_end", NULL
,
8943 Symbol_table::PREDEFINED
, 0, 0,
8944 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8945 elfcpp::STV_HIDDEN
, 0, true, false);
8951 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
8952 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
8954 if (!parameters
->options().relocatable())
8956 this->define_save_restore_funcs(layout
, symtab
);
8958 // Annoyingly, we need to make these sections now whether or
8959 // not we need them. If we delay until do_relax then we
8960 // need to mess with the relaxation machinery checkpointing.
8961 this->got_section(symtab
, layout
);
8962 this->make_brlt_section(layout
);
8964 if (parameters
->options().toc_sort())
8966 Output_section
* os
= this->got_
->output_section();
8967 if (os
!= NULL
&& os
->input_sections().size() > 1)
8968 std::stable_sort(os
->input_sections().begin(),
8969 os
->input_sections().end(),
8970 Sort_toc_sections
<big_endian
>());
8975 // Fill in some more dynamic tags.
8976 Output_data_dynamic
* odyn
= layout
->dynamic_data();
8979 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8981 : this->plt_
->rel_plt());
8982 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
8983 this->rela_dyn_
, true, size
== 32);
8987 if (this->got_
!= NULL
)
8989 this->got_
->finalize_data_size();
8990 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
8991 this->got_
, this->got_
->g_o_t());
8993 if (this->has_tls_get_addr_opt_
)
8994 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
8998 if (this->glink_
!= NULL
)
9000 this->glink_
->finalize_data_size();
9001 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
9003 (this->glink_
->pltresolve_size()
9006 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
9007 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
9008 ((this->has_localentry0_
9009 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
9010 | (this->has_tls_get_addr_opt_
9011 ? elfcpp::PPC64_OPT_TLS
: 0)));
9015 // Emit any relocs we saved in an attempt to avoid generating COPY
9017 if (this->copy_relocs_
.any_saved_relocs())
9018 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
9020 for (Input_objects::Relobj_iterator p
= input_objects
->relobj_begin();
9021 p
!= input_objects
->relobj_end();
9024 Powerpc_relobj
<size
, big_endian
>* ppc_relobj
9025 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(*p
);
9026 if (ppc_relobj
->attributes_section_data())
9027 this->merge_object_attributes(ppc_relobj
->name().c_str(),
9028 ppc_relobj
->attributes_section_data());
9030 for (Input_objects::Dynobj_iterator p
= input_objects
->dynobj_begin();
9031 p
!= input_objects
->dynobj_end();
9034 Powerpc_dynobj
<size
, big_endian
>* ppc_dynobj
9035 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(*p
);
9036 if (ppc_dynobj
->attributes_section_data())
9037 this->merge_object_attributes(ppc_dynobj
->name().c_str(),
9038 ppc_dynobj
->attributes_section_data());
9041 // Create a .gnu.attributes section if we have merged any attributes
9043 if (this->attributes_section_data_
!= NULL
9044 && this->attributes_section_data_
->size() != 0)
9046 Output_attributes_section_data
* attributes_section
9047 = new Output_attributes_section_data(*this->attributes_section_data_
);
9048 layout
->add_output_section_data(".gnu.attributes",
9049 elfcpp::SHT_GNU_ATTRIBUTES
, 0,
9050 attributes_section
, ORDER_INVALID
, false);
9054 // Merge object attributes from input file called NAME with those of the
9055 // output. The input object attributes are in the object pointed by PASD.
9057 template<int size
, bool big_endian
>
9059 Target_powerpc
<size
, big_endian
>::merge_object_attributes(
9061 const Attributes_section_data
* pasd
)
9063 // Return if there is no attributes section data.
9067 // Create output object attributes.
9068 if (this->attributes_section_data_
== NULL
)
9069 this->attributes_section_data_
= new Attributes_section_data(NULL
, 0);
9071 const int vendor
= Object_attribute::OBJ_ATTR_GNU
;
9072 const Object_attribute
* in_attr
= pasd
->known_attributes(vendor
);
9073 Object_attribute
* out_attr
9074 = this->attributes_section_data_
->known_attributes(vendor
);
9079 int tag
= elfcpp::Tag_GNU_Power_ABI_FP
;
9080 int in_fp
= in_attr
[tag
].int_value() & 0xf;
9081 int out_fp
= out_attr
[tag
].int_value() & 0xf;
9082 if (in_fp
!= out_fp
)
9085 if ((in_fp
& 3) == 0)
9087 else if ((out_fp
& 3) == 0)
9089 out_fp
|= in_fp
& 3;
9090 out_attr
[tag
].set_int_value(out_fp
);
9091 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9092 this->last_fp_
= name
;
9094 else if ((out_fp
& 3) != 2 && (in_fp
& 3) == 2)
9096 err
= N_("%s uses hard float, %s uses soft float");
9097 first
= this->last_fp_
;
9100 else if ((out_fp
& 3) == 2 && (in_fp
& 3) != 2)
9102 err
= N_("%s uses hard float, %s uses soft float");
9104 second
= this->last_fp_
;
9106 else if ((out_fp
& 3) == 1 && (in_fp
& 3) == 3)
9108 err
= N_("%s uses double-precision hard float, "
9109 "%s uses single-precision hard float");
9110 first
= this->last_fp_
;
9113 else if ((out_fp
& 3) == 3 && (in_fp
& 3) == 1)
9115 err
= N_("%s uses double-precision hard float, "
9116 "%s uses single-precision hard float");
9118 second
= this->last_fp_
;
9121 if (err
|| (in_fp
& 0xc) == 0)
9123 else if ((out_fp
& 0xc) == 0)
9125 out_fp
|= in_fp
& 0xc;
9126 out_attr
[tag
].set_int_value(out_fp
);
9127 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9128 this->last_ld_
= name
;
9130 else if ((out_fp
& 0xc) != 2 * 4 && (in_fp
& 0xc) == 2 * 4)
9132 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9134 second
= this->last_ld_
;
9136 else if ((in_fp
& 0xc) != 2 * 4 && (out_fp
& 0xc) == 2 * 4)
9138 err
= N_("%s uses 64-bit long double, %s uses 128-bit long double");
9139 first
= this->last_ld_
;
9142 else if ((out_fp
& 0xc) == 1 * 4 && (in_fp
& 0xc) == 3 * 4)
9144 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9145 first
= this->last_ld_
;
9148 else if ((out_fp
& 0xc) == 3 * 4 && (in_fp
& 0xc) == 1 * 4)
9150 err
= N_("%s uses IBM long double, %s uses IEEE long double");
9152 second
= this->last_ld_
;
9157 if (parameters
->options().warn_mismatch())
9158 gold_error(_(err
), first
, second
);
9159 // Arrange for this attribute to be deleted. It's better to
9160 // say "don't know" about a file than to wrongly claim compliance.
9161 out_attr
[tag
].set_type(0);
9167 tag
= elfcpp::Tag_GNU_Power_ABI_Vector
;
9168 int in_vec
= in_attr
[tag
].int_value() & 3;
9169 int out_vec
= out_attr
[tag
].int_value() & 3;
9170 if (in_vec
!= out_vec
)
9175 else if (out_vec
== 0)
9178 out_attr
[tag
].set_int_value(out_vec
);
9179 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9180 this->last_vec_
= name
;
9182 // For now, allow generic to transition to AltiVec or SPE
9183 // without a warning. If GCC marked files with their stack
9184 // alignment and used don't-care markings for files which are
9185 // not affected by the vector ABI, we could warn about this
9187 else if (in_vec
== 1)
9189 else if (out_vec
== 1)
9192 out_attr
[tag
].set_int_value(out_vec
);
9193 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9194 this->last_vec_
= name
;
9196 else if (out_vec
< in_vec
)
9198 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9199 first
= this->last_vec_
;
9202 else if (out_vec
> in_vec
)
9204 err
= N_("%s uses AltiVec vector ABI, %s uses SPE vector ABI");
9206 second
= this->last_vec_
;
9210 if (parameters
->options().warn_mismatch())
9211 gold_error(_(err
), first
, second
);
9212 out_attr
[tag
].set_type(0);
9216 tag
= elfcpp::Tag_GNU_Power_ABI_Struct_Return
;
9217 int in_struct
= in_attr
[tag
].int_value() & 3;
9218 int out_struct
= out_attr
[tag
].int_value() & 3;
9219 if (in_struct
!= out_struct
)
9222 if (in_struct
== 0 || in_struct
== 3)
9224 else if (out_struct
== 0)
9226 out_struct
= in_struct
;
9227 out_attr
[tag
].set_int_value(out_struct
);
9228 out_attr
[tag
].set_type(Object_attribute::ATTR_TYPE_FLAG_INT_VAL
);
9229 this->last_struct_
= name
;
9231 else if (out_struct
< in_struct
)
9233 err
= N_("%s uses r3/r4 for small structure returns, "
9235 first
= this->last_struct_
;
9238 else if (out_struct
> in_struct
)
9240 err
= N_("%s uses r3/r4 for small structure returns, "
9243 second
= this->last_struct_
;
9247 if (parameters
->options().warn_mismatch())
9248 gold_error(_(err
), first
, second
);
9249 out_attr
[tag
].set_type(0);
9254 // Merge Tag_compatibility attributes and any common GNU ones.
9255 this->attributes_section_data_
->merge(name
, pasd
);
9258 // Emit any saved relocs, and mark toc entries using any of these
9259 // relocs as not optimizable.
9261 template<int sh_type
, int size
, bool big_endian
>
9263 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
9264 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
9267 && parameters
->options().toc_optimize())
9269 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
9270 Copy_reloc_entries::iterator p
= this->entries_
.begin();
9271 p
!= this->entries_
.end();
9274 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
9277 // If the symbol is no longer defined in a dynamic object,
9278 // then we emitted a COPY relocation. If it is still
9279 // dynamic then we'll need dynamic relocations and thus
9280 // can't optimize toc entries.
9281 if (entry
.sym_
->is_from_dynobj())
9283 Powerpc_relobj
<size
, big_endian
>* ppc_object
9284 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
9285 if (entry
.shndx_
== ppc_object
->toc_shndx())
9286 ppc_object
->set_no_toc_opt(entry
.address_
);
9291 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
9294 // Return the value to use for a branch relocation.
9296 template<int size
, bool big_endian
>
9298 Target_powerpc
<size
, big_endian
>::symval_for_branch(
9299 const Symbol_table
* symtab
,
9300 const Sized_symbol
<size
>* gsym
,
9301 Powerpc_relobj
<size
, big_endian
>* object
,
9303 unsigned int *dest_shndx
)
9305 if (size
== 32 || this->abiversion() >= 2)
9309 // If the symbol is defined in an opd section, ie. is a function
9310 // descriptor, use the function descriptor code entry address
9311 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
9313 && (gsym
->source() != Symbol::FROM_OBJECT
9314 || gsym
->object()->is_dynamic()))
9317 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
9318 unsigned int shndx
= symobj
->opd_shndx();
9321 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
9322 if (opd_addr
== invalid_address
)
9324 opd_addr
+= symobj
->output_section_address(shndx
);
9325 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
9328 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
9329 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
9332 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
9333 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
9334 *dest_shndx
= folded
.second
;
9336 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
9337 if (sec_addr
== invalid_address
)
9340 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
9341 *value
= sec_addr
+ sec_off
;
9346 // Perform a relocation.
9348 template<int size
, bool big_endian
>
9350 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
9351 const Relocate_info
<size
, big_endian
>* relinfo
,
9353 Target_powerpc
* target
,
9356 const unsigned char* preloc
,
9357 const Sized_symbol
<size
>* gsym
,
9358 const Symbol_value
<size
>* psymval
,
9359 unsigned char* view
,
9361 section_size_type view_size
)
9363 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
9364 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
9365 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9370 if (target
->replace_tls_get_addr(gsym
))
9371 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
9373 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
9374 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
9375 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
9377 case Track_tls::NOT_EXPECTED
:
9378 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9379 _("__tls_get_addr call lacks marker reloc"));
9381 case Track_tls::EXPECTED
:
9382 // We have already complained.
9384 case Track_tls::SKIP
:
9385 if (is_plt16_reloc
<size
>(r_type
)
9386 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9387 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
)
9389 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9390 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9392 else if (size
== 64 && r_type
== elfcpp::R_POWERPC_PLTCALL
)
9394 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9395 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, nop
);
9398 case Track_tls::NORMAL
:
9402 // Offset from start of insn to d-field reloc.
9403 const int d_offset
= big_endian
? 2 : 0;
9405 Powerpc_relobj
<size
, big_endian
>* const object
9406 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
9408 bool has_stub_value
= false;
9409 bool localentry0
= false;
9410 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
9413 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
9414 : object
->local_has_plt_offset(r_sym
));
9416 && !is_plt16_reloc
<size
>(r_type
)
9417 && r_type
!= elfcpp::R_POWERPC_PLTSEQ
9418 && r_type
!= elfcpp::R_POWERPC_PLTCALL
9419 && r_type
!= elfcpp::R_PPC64_PLTSEQ_NOTOC
9420 && r_type
!= elfcpp::R_PPC64_PLTCALL_NOTOC
9421 && (!psymval
->is_ifunc_symbol()
9422 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
9426 && target
->abiversion() >= 2
9427 && !parameters
->options().output_is_position_independent()
9428 && !is_branch_reloc
<size
>(r_type
))
9430 Address off
= target
->glink_section()->find_global_entry(gsym
);
9431 if (off
!= invalid_address
)
9433 value
= target
->glink_section()->global_entry_address() + off
;
9434 has_stub_value
= true;
9439 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
9440 if (target
->stub_tables().size() == 1)
9441 stub_table
= target
->stub_tables()[0];
9442 if (stub_table
== NULL
9445 && !parameters
->options().output_is_position_independent()
9446 && !is_branch_reloc
<size
>(r_type
)))
9447 stub_table
= object
->stub_table(relinfo
->data_shndx
);
9448 if (stub_table
== NULL
)
9450 // This is a ref from a data section to an ifunc symbol,
9451 // or a non-branch reloc for which we always want to use
9452 // one set of stubs for resolving function addresses.
9453 if (target
->stub_tables().size() != 0)
9454 stub_table
= target
->stub_tables()[0];
9456 if (stub_table
!= NULL
)
9458 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
9460 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
9461 rela
.get_r_addend());
9463 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
9464 rela
.get_r_addend());
9467 value
= stub_table
->stub_address() + ent
->off_
;
9468 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9469 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
9470 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
9473 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
)
9477 && relnum
< reloc_count
- 1)
9479 Reltype
next_rela(preloc
+ reloc_size
);
9480 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
9481 == elfcpp::R_PPC64_TOCSAVE
9482 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
9485 localentry0
= ent
->localentry0_
;
9486 has_stub_value
= true;
9490 // We don't care too much about bogus debug references to
9491 // non-local functions, but otherwise there had better be a plt
9492 // call stub or global entry stub as appropriate.
9493 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
9496 if (has_plt_offset
&& is_plt16_reloc
<size
>(r_type
))
9498 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
9500 value
= target
->plt_off(gsym
, &plt
);
9502 value
= target
->plt_off(object
, r_sym
, &plt
);
9503 value
+= plt
->address();
9506 value
-= (target
->got_section()->output_section()->address()
9507 + object
->toc_base_offset());
9508 else if (parameters
->options().output_is_position_independent())
9510 if (rela
.get_r_addend() >= 32768)
9512 unsigned int got2
= object
->got2_shndx();
9513 value
-= (object
->get_output_section_offset(got2
)
9514 + object
->output_section(got2
)->address()
9515 + rela
.get_r_addend());
9518 value
-= (target
->got_section()->address()
9519 + target
->got_section()->g_o_t());
9522 else if (!has_plt_offset
9523 && (is_plt16_reloc
<size
>(r_type
)
9524 || r_type
== elfcpp::R_POWERPC_PLTSEQ
9525 || r_type
== elfcpp::R_PPC64_PLTSEQ_NOTOC
))
9527 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9528 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9529 r_type
= elfcpp::R_POWERPC_NONE
;
9531 else if (r_type
== elfcpp::R_POWERPC_GOT16
9532 || r_type
== elfcpp::R_POWERPC_GOT16_LO
9533 || r_type
== elfcpp::R_POWERPC_GOT16_HI
9534 || r_type
== elfcpp::R_POWERPC_GOT16_HA
9535 || r_type
== elfcpp::R_PPC64_GOT16_DS
9536 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
9540 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
9541 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
9545 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
9546 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
9548 value
-= target
->got_section()->got_base_offset(object
);
9550 else if (r_type
== elfcpp::R_PPC64_TOC
)
9552 value
= (target
->got_section()->output_section()->address()
9553 + object
->toc_base_offset());
9555 else if (gsym
!= NULL
9556 && (r_type
== elfcpp::R_POWERPC_REL24
9557 || r_type
== elfcpp::R_PPC_PLTREL24
)
9562 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
9563 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
9564 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
9565 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
9567 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
9568 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
9571 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
9573 elfcpp::Swap
<32, big_endian
>::
9574 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
9575 can_plt_call
= true;
9580 // If we don't have a branch and link followed by a nop,
9581 // we can't go via the plt because there is no place to
9582 // put a toc restoring instruction.
9583 // Unless we know we won't be returning.
9584 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
9585 can_plt_call
= true;
9589 // g++ as of 20130507 emits self-calls without a
9590 // following nop. This is arguably wrong since we have
9591 // conflicting information. On the one hand a global
9592 // symbol and on the other a local call sequence, but
9593 // don't error for this special case.
9594 // It isn't possible to cheaply verify we have exactly
9595 // such a call. Allow all calls to the same section.
9597 Address code
= value
;
9598 if (gsym
->source() == Symbol::FROM_OBJECT
9599 && gsym
->object() == object
)
9601 unsigned int dest_shndx
= 0;
9602 if (target
->abiversion() < 2)
9604 Address addend
= rela
.get_r_addend();
9605 code
= psymval
->value(object
, addend
);
9606 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
9607 &code
, &dest_shndx
);
9610 if (dest_shndx
== 0)
9611 dest_shndx
= gsym
->shndx(&is_ordinary
);
9612 ok
= dest_shndx
== relinfo
->data_shndx
;
9616 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9617 _("call lacks nop, can't restore toc; "
9618 "recompile with -fPIC"));
9624 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
9625 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
9626 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
9627 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
9629 // First instruction of a global dynamic sequence, arg setup insn.
9630 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
9631 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9632 enum Got_type got_type
= GOT_TYPE_STANDARD
;
9633 if (tls_type
== tls::TLSOPT_NONE
)
9634 got_type
= GOT_TYPE_TLSGD
;
9635 else if (tls_type
== tls::TLSOPT_TO_IE
)
9636 got_type
= GOT_TYPE_TPREL
;
9637 if (got_type
!= GOT_TYPE_STANDARD
)
9641 gold_assert(gsym
->has_got_offset(got_type
));
9642 value
= gsym
->got_offset(got_type
);
9646 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
9647 value
= object
->local_got_offset(r_sym
, got_type
);
9649 value
-= target
->got_section()->got_base_offset(object
);
9651 if (tls_type
== tls::TLSOPT_TO_IE
)
9653 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
9654 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
9656 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9657 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9658 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
9660 insn
|= 32 << 26; // lwz
9662 insn
|= 58 << 26; // ld
9663 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9665 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
9666 - elfcpp::R_POWERPC_GOT_TLSGD16
);
9668 else if (tls_type
== tls::TLSOPT_TO_LE
)
9670 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
9671 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
9673 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9674 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9675 insn
&= (1 << 26) - (1 << 21); // extract rt
9680 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9681 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
9682 value
= psymval
->value(object
, rela
.get_r_addend());
9686 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9688 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9689 r_type
= elfcpp::R_POWERPC_NONE
;
9693 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
9694 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
9695 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
9696 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
9698 // First instruction of a local dynamic sequence, arg setup insn.
9699 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9700 if (tls_type
== tls::TLSOPT_NONE
)
9702 value
= target
->tlsld_got_offset();
9703 value
-= target
->got_section()->got_base_offset(object
);
9707 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
9708 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
9709 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
9711 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9712 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9713 insn
&= (1 << 26) - (1 << 21); // extract rt
9718 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9719 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
9724 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9726 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9727 r_type
= elfcpp::R_POWERPC_NONE
;
9731 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
9732 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
9733 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
9734 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
9736 // Accesses relative to a local dynamic sequence address,
9737 // no optimisation here.
9740 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
9741 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
9745 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
9746 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
9748 value
-= target
->got_section()->got_base_offset(object
);
9750 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
9751 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
9752 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
9753 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
9755 // First instruction of initial exec sequence.
9756 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
9757 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9758 if (tls_type
== tls::TLSOPT_NONE
)
9762 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
9763 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
9767 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
9768 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
9770 value
-= target
->got_section()->got_base_offset(object
);
9774 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
9775 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
9776 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
9778 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9779 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9780 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
9785 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9786 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
9787 value
= psymval
->value(object
, rela
.get_r_addend());
9791 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9793 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9794 r_type
= elfcpp::R_POWERPC_NONE
;
9798 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
9799 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
9801 // Second instruction of a global dynamic sequence,
9802 // the __tls_get_addr call
9803 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
9804 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
9805 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
9806 if (tls_type
!= tls::TLSOPT_NONE
)
9808 if (tls_type
== tls::TLSOPT_TO_IE
)
9810 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9811 Insn insn
= add_3_3_13
;
9814 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9815 r_type
= elfcpp::R_POWERPC_NONE
;
9819 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9820 Insn insn
= addi_3_3
;
9821 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9822 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
9824 value
= psymval
->value(object
, rela
.get_r_addend());
9826 this->skip_next_tls_get_addr_call();
9829 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
9830 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
9832 // Second instruction of a local dynamic sequence,
9833 // the __tls_get_addr call
9834 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
9835 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
9836 if (tls_type
== tls::TLSOPT_TO_LE
)
9838 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9839 Insn insn
= addi_3_3
;
9840 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9841 this->skip_next_tls_get_addr_call();
9842 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
9847 else if (r_type
== elfcpp::R_POWERPC_TLS
)
9849 // Second instruction of an initial exec sequence
9850 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
9851 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
9852 if (tls_type
== tls::TLSOPT_TO_LE
)
9854 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9855 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9856 unsigned int reg
= size
== 32 ? 2 : 13;
9857 insn
= at_tls_transform(insn
, reg
);
9858 gold_assert(insn
!= 0);
9859 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9860 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
9862 value
= psymval
->value(object
, rela
.get_r_addend());
9865 else if (!has_stub_value
)
9867 if (!has_plt_offset
&& (r_type
== elfcpp::R_POWERPC_PLTCALL
9868 || r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
))
9870 // PLTCALL without plt entry => convert to direct call
9871 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9872 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9873 insn
= (insn
& 1) | b
;
9874 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9876 r_type
= elfcpp::R_PPC_PLTREL24
;
9877 else if (r_type
== elfcpp::R_PPC64_PLTCALL_NOTOC
)
9878 r_type
= elfcpp::R_PPC64_REL24_NOTOC
;
9880 r_type
= elfcpp::R_POWERPC_REL24
;
9884 && (r_type
== elfcpp::R_PPC_PLTREL24
9885 || r_type
== elfcpp::R_POWERPC_PLT16_LO
9886 || r_type
== elfcpp::R_POWERPC_PLT16_HI
9887 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
9888 addend
= rela
.get_r_addend();
9889 value
= psymval
->value(object
, addend
);
9890 if (size
== 64 && is_branch_reloc
<size
>(r_type
))
9892 if (target
->abiversion() >= 2)
9895 value
+= object
->ppc64_local_entry_offset(gsym
);
9897 value
+= object
->ppc64_local_entry_offset(r_sym
);
9901 unsigned int dest_shndx
;
9902 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
9903 &value
, &dest_shndx
);
9906 Address max_branch_offset
= max_branch_delta
<size
>(r_type
);
9907 if (max_branch_offset
!= 0
9908 && (value
- address
+ max_branch_offset
>= 2 * max_branch_offset
9910 && r_type
== elfcpp::R_PPC64_REL24_NOTOC
9912 ? object
->ppc64_needs_toc(gsym
)
9913 : object
->ppc64_needs_toc(r_sym
)))))
9915 Stub_table
<size
, big_endian
>* stub_table
9916 = object
->stub_table(relinfo
->data_shndx
);
9917 if (stub_table
!= NULL
)
9919 const typename Stub_table
<size
, big_endian
>::Branch_stub_ent
* ent
9920 = stub_table
->find_long_branch_entry(object
, value
);
9924 value
= (value
- target
->savres_section()->address()
9925 + stub_table
->branch_size());
9927 value
= (stub_table
->stub_address() + stub_table
->plt_size()
9929 has_stub_value
= true;
9937 case elfcpp::R_PPC64_REL24_NOTOC
:
9941 case elfcpp::R_PPC64_REL64
:
9942 case elfcpp::R_POWERPC_REL32
:
9943 case elfcpp::R_POWERPC_REL24
:
9944 case elfcpp::R_PPC_PLTREL24
:
9945 case elfcpp::R_PPC_LOCAL24PC
:
9946 case elfcpp::R_POWERPC_REL16
:
9947 case elfcpp::R_POWERPC_REL16_LO
:
9948 case elfcpp::R_POWERPC_REL16_HI
:
9949 case elfcpp::R_POWERPC_REL16_HA
:
9950 case elfcpp::R_POWERPC_REL16DX_HA
:
9951 case elfcpp::R_PPC64_REL16_HIGH
:
9952 case elfcpp::R_PPC64_REL16_HIGHA
:
9953 case elfcpp::R_PPC64_REL16_HIGHER
:
9954 case elfcpp::R_PPC64_REL16_HIGHERA
:
9955 case elfcpp::R_PPC64_REL16_HIGHEST
:
9956 case elfcpp::R_PPC64_REL16_HIGHESTA
:
9957 case elfcpp::R_POWERPC_REL14
:
9958 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9959 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9963 case elfcpp::R_PPC64_TOC16
:
9964 case elfcpp::R_PPC64_TOC16_LO
:
9965 case elfcpp::R_PPC64_TOC16_HI
:
9966 case elfcpp::R_PPC64_TOC16_HA
:
9967 case elfcpp::R_PPC64_TOC16_DS
:
9968 case elfcpp::R_PPC64_TOC16_LO_DS
:
9969 // Subtract the TOC base address.
9970 value
-= (target
->got_section()->output_section()->address()
9971 + object
->toc_base_offset());
9974 case elfcpp::R_POWERPC_SECTOFF
:
9975 case elfcpp::R_POWERPC_SECTOFF_LO
:
9976 case elfcpp::R_POWERPC_SECTOFF_HI
:
9977 case elfcpp::R_POWERPC_SECTOFF_HA
:
9978 case elfcpp::R_PPC64_SECTOFF_DS
:
9979 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9981 value
-= os
->address();
9984 case elfcpp::R_PPC64_TPREL16_DS
:
9985 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9986 case elfcpp::R_PPC64_TPREL16_HIGH
:
9987 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9989 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
9992 case elfcpp::R_POWERPC_TPREL16
:
9993 case elfcpp::R_POWERPC_TPREL16_LO
:
9994 case elfcpp::R_POWERPC_TPREL16_HI
:
9995 case elfcpp::R_POWERPC_TPREL16_HA
:
9996 case elfcpp::R_POWERPC_TPREL
:
9997 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9998 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9999 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10000 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10001 // tls symbol values are relative to tls_segment()->vaddr()
10002 value
-= tp_offset
;
10005 case elfcpp::R_PPC64_DTPREL16_DS
:
10006 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10007 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10008 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10009 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10010 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10012 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
10013 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
10016 case elfcpp::R_POWERPC_DTPREL16
:
10017 case elfcpp::R_POWERPC_DTPREL16_LO
:
10018 case elfcpp::R_POWERPC_DTPREL16_HI
:
10019 case elfcpp::R_POWERPC_DTPREL16_HA
:
10020 case elfcpp::R_POWERPC_DTPREL
:
10021 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10022 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10023 // tls symbol values are relative to tls_segment()->vaddr()
10024 value
-= dtp_offset
;
10027 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10029 value
+= object
->ppc64_local_entry_offset(gsym
);
10031 value
+= object
->ppc64_local_entry_offset(r_sym
);
10038 Insn branch_bit
= 0;
10041 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10042 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10043 branch_bit
= 1 << 21;
10045 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10046 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10048 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10049 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10050 insn
&= ~(1 << 21);
10051 insn
|= branch_bit
;
10052 if (this->is_isa_v2
)
10054 // Set 'a' bit. This is 0b00010 in BO field for branch
10055 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
10056 // for branch on CTR insns (BO == 1a00t or 1a01t).
10057 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10058 insn
|= 0x02 << 21;
10059 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10060 insn
|= 0x08 << 21;
10066 // Invert 'y' bit if not the default.
10067 if (static_cast<Signed_address
>(value
) < 0)
10070 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10074 case elfcpp::R_POWERPC_PLT16_HA
:
10076 && !parameters
->options().output_is_position_independent())
10078 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10079 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10081 // Convert addis to lis.
10082 if ((insn
& (0x3f << 26)) == 15u << 26
10083 && (insn
& (0x1f << 16)) != 0)
10085 insn
&= ~(0x1f << 16);
10086 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10102 // Multi-instruction sequences that access the GOT/TOC can
10103 // be optimized, eg.
10104 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
10105 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
10107 // addis ra,r2,0; addi rb,ra,x@toc@l;
10108 // to nop; addi rb,r2,x@toc;
10109 // FIXME: the @got sequence shown above is not yet
10110 // optimized. Note that gcc as of 2017-01-07 doesn't use
10111 // the ELF @got relocs except for TLS, instead using the
10112 // PowerOpen variant of a compiler managed GOT (called TOC).
10113 // The PowerOpen TOC sequence equivalent to the first
10114 // example is optimized.
10115 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10116 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10117 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10118 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10119 case elfcpp::R_POWERPC_GOT16_HA
:
10120 case elfcpp::R_PPC64_TOC16_HA
:
10121 if (parameters
->options().toc_optimize())
10123 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10124 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10125 if (r_type
== elfcpp::R_PPC64_TOC16_HA
10126 && object
->make_toc_relative(target
, &value
))
10128 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
10129 == ((15u << 26) | (2 << 16)));
10131 if (((insn
& ((0x3f << 26) | 0x1f << 16))
10132 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
10133 && value
+ 0x8000 < 0x10000)
10135 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10141 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10142 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10143 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10144 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10145 case elfcpp::R_POWERPC_GOT16_LO
:
10146 case elfcpp::R_PPC64_GOT16_LO_DS
:
10147 case elfcpp::R_PPC64_TOC16_LO
:
10148 case elfcpp::R_PPC64_TOC16_LO_DS
:
10149 if (parameters
->options().toc_optimize())
10151 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10152 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10153 bool changed
= false;
10154 if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
10155 && object
->make_toc_relative(target
, &value
))
10157 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
10158 insn
^= (14u << 26) ^ (58u << 26);
10159 r_type
= elfcpp::R_PPC64_TOC16_LO
;
10162 if (ok_lo_toc_insn(insn
, r_type
)
10163 && value
+ 0x8000 < 0x10000)
10165 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
10167 // Transform addic to addi when we change reg.
10168 insn
&= ~((0x3f << 26) | (0x1f << 16));
10169 insn
|= (14u << 26) | (2 << 16);
10173 insn
&= ~(0x1f << 16);
10179 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10183 case elfcpp::R_POWERPC_TPREL16_HA
:
10184 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10186 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10187 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10188 if ((insn
& ((0x3f << 26) | 0x1f << 16))
10189 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
10193 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
10199 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10201 // R_PPC_TLSGD, R_PPC_TLSLD
10204 case elfcpp::R_POWERPC_TPREL16_LO
:
10205 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
10207 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10208 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10209 insn
&= ~(0x1f << 16);
10210 insn
|= (size
== 32 ? 2 : 13) << 16;
10211 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
10215 case elfcpp::R_PPC64_ENTRY
:
10216 value
= (target
->got_section()->output_section()->address()
10217 + object
->toc_base_offset());
10218 if (value
+ 0x80008000 <= 0xffffffff
10219 && !parameters
->options().output_is_position_independent())
10221 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10222 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10223 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10225 if ((insn1
& ~0xfffc) == ld_2_12
10226 && insn2
== add_2_2_12
)
10228 insn1
= lis_2
+ ha(value
);
10229 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10230 insn2
= addi_2_2
+ l(value
);
10231 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10238 if (value
+ 0x80008000 <= 0xffffffff)
10240 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10241 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10242 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
10244 if ((insn1
& ~0xfffc) == ld_2_12
10245 && insn2
== add_2_2_12
)
10247 insn1
= addis_2_12
+ ha(value
);
10248 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
10249 insn2
= addi_2_2
+ l(value
);
10250 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
10257 case elfcpp::R_POWERPC_REL16_LO
:
10258 // If we are generating a non-PIC executable, edit
10259 // 0: addis 2,12,.TOC.-0b@ha
10260 // addi 2,2,.TOC.-0b@l
10261 // used by ELFv2 global entry points to set up r2, to
10263 // addi 2,2,.TOC.@l
10264 // if .TOC. is in range. */
10265 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
10268 && target
->abiversion() >= 2
10269 && !parameters
->options().output_is_position_independent()
10270 && rela
.get_r_addend() == d_offset
+ 4
10272 && strcmp(gsym
->name(), ".TOC.") == 0)
10274 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10275 Reltype
prev_rela(preloc
- reloc_size
);
10276 if ((prev_rela
.get_r_info()
10277 == elfcpp::elf_r_info
<size
>(r_sym
,
10278 elfcpp::R_POWERPC_REL16_HA
))
10279 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
10280 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
10282 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10283 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
10284 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10286 if ((insn1
& 0xffff0000) == addis_2_12
10287 && (insn2
& 0xffff0000) == addi_2_2
)
10289 insn1
= lis_2
+ ha(value
+ address
- 4);
10290 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
10291 insn2
= addi_2_2
+ l(value
+ address
- 4);
10292 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
10295 relinfo
->rr
->set_strategy(relnum
- 1,
10296 Relocatable_relocs::RELOC_SPECIAL
);
10297 relinfo
->rr
->set_strategy(relnum
,
10298 Relocatable_relocs::RELOC_SPECIAL
);
10308 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
10309 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
10312 case elfcpp::R_POWERPC_ADDR32
:
10313 case elfcpp::R_POWERPC_UADDR32
:
10315 overflow
= Reloc::CHECK_BITFIELD
;
10318 case elfcpp::R_POWERPC_REL32
:
10319 case elfcpp::R_POWERPC_REL16DX_HA
:
10321 overflow
= Reloc::CHECK_SIGNED
;
10324 case elfcpp::R_POWERPC_UADDR16
:
10325 overflow
= Reloc::CHECK_BITFIELD
;
10328 case elfcpp::R_POWERPC_ADDR16
:
10329 // We really should have three separate relocations,
10330 // one for 16-bit data, one for insns with 16-bit signed fields,
10331 // and one for insns with 16-bit unsigned fields.
10332 overflow
= Reloc::CHECK_BITFIELD
;
10333 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
10334 overflow
= Reloc::CHECK_LOW_INSN
;
10337 case elfcpp::R_POWERPC_ADDR16_HI
:
10338 case elfcpp::R_POWERPC_ADDR16_HA
:
10339 case elfcpp::R_POWERPC_GOT16_HI
:
10340 case elfcpp::R_POWERPC_GOT16_HA
:
10341 case elfcpp::R_POWERPC_PLT16_HI
:
10342 case elfcpp::R_POWERPC_PLT16_HA
:
10343 case elfcpp::R_POWERPC_SECTOFF_HI
:
10344 case elfcpp::R_POWERPC_SECTOFF_HA
:
10345 case elfcpp::R_PPC64_TOC16_HI
:
10346 case elfcpp::R_PPC64_TOC16_HA
:
10347 case elfcpp::R_PPC64_PLTGOT16_HI
:
10348 case elfcpp::R_PPC64_PLTGOT16_HA
:
10349 case elfcpp::R_POWERPC_TPREL16_HI
:
10350 case elfcpp::R_POWERPC_TPREL16_HA
:
10351 case elfcpp::R_POWERPC_DTPREL16_HI
:
10352 case elfcpp::R_POWERPC_DTPREL16_HA
:
10353 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
10354 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10355 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
10356 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10357 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
10358 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10359 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
10360 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10361 case elfcpp::R_POWERPC_REL16_HI
:
10362 case elfcpp::R_POWERPC_REL16_HA
:
10364 overflow
= Reloc::CHECK_HIGH_INSN
;
10367 case elfcpp::R_POWERPC_REL16
:
10368 case elfcpp::R_PPC64_TOC16
:
10369 case elfcpp::R_POWERPC_GOT16
:
10370 case elfcpp::R_POWERPC_SECTOFF
:
10371 case elfcpp::R_POWERPC_TPREL16
:
10372 case elfcpp::R_POWERPC_DTPREL16
:
10373 case elfcpp::R_POWERPC_GOT_TLSGD16
:
10374 case elfcpp::R_POWERPC_GOT_TLSLD16
:
10375 case elfcpp::R_POWERPC_GOT_TPREL16
:
10376 case elfcpp::R_POWERPC_GOT_DTPREL16
:
10377 overflow
= Reloc::CHECK_LOW_INSN
;
10380 case elfcpp::R_PPC64_REL24_NOTOC
:
10384 case elfcpp::R_POWERPC_ADDR24
:
10385 case elfcpp::R_POWERPC_ADDR14
:
10386 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10387 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10388 case elfcpp::R_PPC64_ADDR16_DS
:
10389 case elfcpp::R_POWERPC_REL24
:
10390 case elfcpp::R_PPC_PLTREL24
:
10391 case elfcpp::R_PPC_LOCAL24PC
:
10392 case elfcpp::R_PPC64_TPREL16_DS
:
10393 case elfcpp::R_PPC64_DTPREL16_DS
:
10394 case elfcpp::R_PPC64_TOC16_DS
:
10395 case elfcpp::R_PPC64_GOT16_DS
:
10396 case elfcpp::R_PPC64_SECTOFF_DS
:
10397 case elfcpp::R_POWERPC_REL14
:
10398 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10399 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10400 overflow
= Reloc::CHECK_SIGNED
;
10404 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
10407 if (overflow
== Reloc::CHECK_LOW_INSN
10408 || overflow
== Reloc::CHECK_HIGH_INSN
)
10410 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10412 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
10413 overflow
= Reloc::CHECK_BITFIELD
;
10414 else if (overflow
== Reloc::CHECK_LOW_INSN
10415 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
10416 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
10417 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
10418 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
10419 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
10420 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
10421 overflow
= Reloc::CHECK_UNSIGNED
;
10423 overflow
= Reloc::CHECK_SIGNED
;
10426 bool maybe_dq_reloc
= false;
10427 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
10428 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
10431 case elfcpp::R_POWERPC_NONE
:
10432 case elfcpp::R_POWERPC_TLS
:
10433 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
10434 case elfcpp::R_POWERPC_GNU_VTENTRY
:
10435 case elfcpp::R_POWERPC_PLTSEQ
:
10436 case elfcpp::R_POWERPC_PLTCALL
:
10437 case elfcpp::R_PPC64_PLTSEQ_NOTOC
:
10438 case elfcpp::R_PPC64_PLTCALL_NOTOC
:
10441 case elfcpp::R_PPC64_ADDR64
:
10442 case elfcpp::R_PPC64_REL64
:
10443 case elfcpp::R_PPC64_TOC
:
10444 case elfcpp::R_PPC64_ADDR64_LOCAL
:
10445 Reloc::addr64(view
, value
);
10448 case elfcpp::R_POWERPC_TPREL
:
10449 case elfcpp::R_POWERPC_DTPREL
:
10451 Reloc::addr64(view
, value
);
10453 status
= Reloc::addr32(view
, value
, overflow
);
10456 case elfcpp::R_PPC64_UADDR64
:
10457 Reloc::addr64_u(view
, value
);
10460 case elfcpp::R_POWERPC_ADDR32
:
10461 status
= Reloc::addr32(view
, value
, overflow
);
10464 case elfcpp::R_POWERPC_REL32
:
10465 case elfcpp::R_POWERPC_UADDR32
:
10466 status
= Reloc::addr32_u(view
, value
, overflow
);
10469 case elfcpp::R_PPC64_REL24_NOTOC
:
10471 goto unsupp
; // R_PPC_EMB_RELSDA
10473 case elfcpp::R_POWERPC_ADDR24
:
10474 case elfcpp::R_POWERPC_REL24
:
10475 case elfcpp::R_PPC_PLTREL24
:
10476 case elfcpp::R_PPC_LOCAL24PC
:
10477 status
= Reloc::addr24(view
, value
, overflow
);
10480 case elfcpp::R_POWERPC_GOT_DTPREL16
:
10481 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
10482 case elfcpp::R_POWERPC_GOT_TPREL16
:
10483 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
10486 // On ppc64 these are all ds form
10487 maybe_dq_reloc
= true;
10491 case elfcpp::R_POWERPC_ADDR16
:
10492 case elfcpp::R_POWERPC_REL16
:
10493 case elfcpp::R_PPC64_TOC16
:
10494 case elfcpp::R_POWERPC_GOT16
:
10495 case elfcpp::R_POWERPC_SECTOFF
:
10496 case elfcpp::R_POWERPC_TPREL16
:
10497 case elfcpp::R_POWERPC_DTPREL16
:
10498 case elfcpp::R_POWERPC_GOT_TLSGD16
:
10499 case elfcpp::R_POWERPC_GOT_TLSLD16
:
10500 case elfcpp::R_POWERPC_ADDR16_LO
:
10501 case elfcpp::R_POWERPC_REL16_LO
:
10502 case elfcpp::R_PPC64_TOC16_LO
:
10503 case elfcpp::R_POWERPC_GOT16_LO
:
10504 case elfcpp::R_POWERPC_PLT16_LO
:
10505 case elfcpp::R_POWERPC_SECTOFF_LO
:
10506 case elfcpp::R_POWERPC_TPREL16_LO
:
10507 case elfcpp::R_POWERPC_DTPREL16_LO
:
10508 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
10509 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
10511 status
= Reloc::addr16(view
, value
, overflow
);
10513 maybe_dq_reloc
= true;
10516 case elfcpp::R_POWERPC_UADDR16
:
10517 status
= Reloc::addr16_u(view
, value
, overflow
);
10520 case elfcpp::R_PPC64_ADDR16_HIGH
:
10521 case elfcpp::R_PPC64_TPREL16_HIGH
:
10522 case elfcpp::R_PPC64_DTPREL16_HIGH
:
10524 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
10527 case elfcpp::R_POWERPC_ADDR16_HI
:
10528 case elfcpp::R_POWERPC_REL16_HI
:
10529 case elfcpp::R_PPC64_REL16_HIGH
:
10530 case elfcpp::R_PPC64_TOC16_HI
:
10531 case elfcpp::R_POWERPC_GOT16_HI
:
10532 case elfcpp::R_POWERPC_PLT16_HI
:
10533 case elfcpp::R_POWERPC_SECTOFF_HI
:
10534 case elfcpp::R_POWERPC_TPREL16_HI
:
10535 case elfcpp::R_POWERPC_DTPREL16_HI
:
10536 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
10537 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
10538 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
10539 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
10540 Reloc::addr16_hi(view
, value
);
10543 case elfcpp::R_PPC64_ADDR16_HIGHA
:
10544 case elfcpp::R_PPC64_TPREL16_HIGHA
:
10545 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
10547 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
10550 case elfcpp::R_POWERPC_ADDR16_HA
:
10551 case elfcpp::R_POWERPC_REL16_HA
:
10552 case elfcpp::R_PPC64_REL16_HIGHA
:
10553 case elfcpp::R_PPC64_TOC16_HA
:
10554 case elfcpp::R_POWERPC_GOT16_HA
:
10555 case elfcpp::R_POWERPC_PLT16_HA
:
10556 case elfcpp::R_POWERPC_SECTOFF_HA
:
10557 case elfcpp::R_POWERPC_TPREL16_HA
:
10558 case elfcpp::R_POWERPC_DTPREL16_HA
:
10559 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
10560 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
10561 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
10562 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
10563 Reloc::addr16_ha(view
, value
);
10566 case elfcpp::R_POWERPC_REL16DX_HA
:
10567 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
10570 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
10572 // R_PPC_EMB_NADDR16_LO
10575 case elfcpp::R_PPC64_ADDR16_HIGHER
:
10576 case elfcpp::R_PPC64_REL16_HIGHER
:
10577 case elfcpp::R_PPC64_TPREL16_HIGHER
:
10578 Reloc::addr16_hi2(view
, value
);
10581 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
10583 // R_PPC_EMB_NADDR16_HI
10586 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
10587 case elfcpp::R_PPC64_REL16_HIGHERA
:
10588 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
10589 Reloc::addr16_ha2(view
, value
);
10592 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
10594 // R_PPC_EMB_NADDR16_HA
10597 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
10598 case elfcpp::R_PPC64_REL16_HIGHEST
:
10599 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
10600 Reloc::addr16_hi3(view
, value
);
10603 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
10605 // R_PPC_EMB_SDAI16
10608 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
10609 case elfcpp::R_PPC64_REL16_HIGHESTA
:
10610 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
10611 Reloc::addr16_ha3(view
, value
);
10614 case elfcpp::R_PPC64_DTPREL16_DS
:
10615 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
10617 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
10620 case elfcpp::R_PPC64_TPREL16_DS
:
10621 case elfcpp::R_PPC64_TPREL16_LO_DS
:
10623 // R_PPC_TLSGD, R_PPC_TLSLD
10626 case elfcpp::R_PPC64_ADDR16_DS
:
10627 case elfcpp::R_PPC64_ADDR16_LO_DS
:
10628 case elfcpp::R_PPC64_TOC16_DS
:
10629 case elfcpp::R_PPC64_TOC16_LO_DS
:
10630 case elfcpp::R_PPC64_GOT16_DS
:
10631 case elfcpp::R_PPC64_GOT16_LO_DS
:
10632 case elfcpp::R_PPC64_PLT16_LO_DS
:
10633 case elfcpp::R_PPC64_SECTOFF_DS
:
10634 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
10635 maybe_dq_reloc
= true;
10638 case elfcpp::R_POWERPC_ADDR14
:
10639 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
10640 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
10641 case elfcpp::R_POWERPC_REL14
:
10642 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
10643 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
10644 status
= Reloc::addr14(view
, value
, overflow
);
10647 case elfcpp::R_POWERPC_COPY
:
10648 case elfcpp::R_POWERPC_GLOB_DAT
:
10649 case elfcpp::R_POWERPC_JMP_SLOT
:
10650 case elfcpp::R_POWERPC_RELATIVE
:
10651 case elfcpp::R_POWERPC_DTPMOD
:
10652 case elfcpp::R_PPC64_JMP_IREL
:
10653 case elfcpp::R_POWERPC_IRELATIVE
:
10654 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10655 _("unexpected reloc %u in object file"),
10659 case elfcpp::R_PPC64_TOCSAVE
:
10665 Symbol_location loc
;
10666 loc
.object
= relinfo
->object
;
10667 loc
.shndx
= relinfo
->data_shndx
;
10668 loc
.offset
= rela
.get_r_offset();
10669 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
10670 if (p
!= target
->tocsave_loc().end())
10672 // If we've generated plt calls using this tocsave, then
10673 // the nop needs to be changed to save r2.
10674 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
10675 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
10676 elfcpp::Swap
<32, big_endian
>::
10677 writeval(iview
, std_2_1
+ target
->stk_toc());
10682 case elfcpp::R_PPC_EMB_SDA2I16
:
10683 case elfcpp::R_PPC_EMB_SDA2REL
:
10686 // R_PPC64_TLSGD, R_PPC64_TLSLD
10689 case elfcpp::R_POWERPC_PLT32
:
10690 case elfcpp::R_POWERPC_PLTREL32
:
10691 case elfcpp::R_PPC_SDAREL16
:
10692 case elfcpp::R_POWERPC_ADDR30
:
10693 case elfcpp::R_PPC64_PLT64
:
10694 case elfcpp::R_PPC64_PLTREL64
:
10695 case elfcpp::R_PPC64_PLTGOT16
:
10696 case elfcpp::R_PPC64_PLTGOT16_LO
:
10697 case elfcpp::R_PPC64_PLTGOT16_HI
:
10698 case elfcpp::R_PPC64_PLTGOT16_HA
:
10699 case elfcpp::R_PPC64_PLTGOT16_DS
:
10700 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
10701 case elfcpp::R_PPC_TOC16
:
10704 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10705 _("unsupported reloc %u"),
10710 if (maybe_dq_reloc
)
10713 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
10715 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
10716 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
10717 && (insn
& 3) == 1))
10718 status
= Reloc::addr16_dq(view
, value
, overflow
);
10719 else if (size
== 64
10720 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
10721 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
10722 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
10723 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
10724 status
= Reloc::addr16_ds(view
, value
, overflow
);
10726 status
= Reloc::addr16(view
, value
, overflow
);
10729 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
10732 && gsym
->is_undefined()
10733 && is_branch_reloc
<size
>(r_type
))))
10735 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
10736 _("relocation overflow"));
10737 if (has_stub_value
)
10738 gold_info(_("try relinking with a smaller --stub-group-size"));
10744 // Relocate section data.
10746 template<int size
, bool big_endian
>
10748 Target_powerpc
<size
, big_endian
>::relocate_section(
10749 const Relocate_info
<size
, big_endian
>* relinfo
,
10750 unsigned int sh_type
,
10751 const unsigned char* prelocs
,
10752 size_t reloc_count
,
10753 Output_section
* output_section
,
10754 bool needs_special_offset_handling
,
10755 unsigned char* view
,
10757 section_size_type view_size
,
10758 const Reloc_symbol_changes
* reloc_symbol_changes
)
10760 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
10761 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
10762 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
10763 Powerpc_comdat_behavior
;
10764 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10767 gold_assert(sh_type
== elfcpp::SHT_RELA
);
10769 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
10770 Powerpc_comdat_behavior
, Classify_reloc
>(
10776 needs_special_offset_handling
,
10780 reloc_symbol_changes
);
10783 template<int size
, bool big_endian
>
10784 class Powerpc_scan_relocatable_reloc
10787 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10788 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10789 static const int sh_type
= elfcpp::SHT_RELA
;
10791 // Return the symbol referred to by the relocation.
10792 static inline unsigned int
10793 get_r_sym(const Reltype
* reloc
)
10794 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
10796 // Return the type of the relocation.
10797 static inline unsigned int
10798 get_r_type(const Reltype
* reloc
)
10799 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
10801 // Return the strategy to use for a local symbol which is not a
10802 // section symbol, given the relocation type.
10803 inline Relocatable_relocs::Reloc_strategy
10804 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
10806 if (r_type
== 0 && r_sym
== 0)
10807 return Relocatable_relocs::RELOC_DISCARD
;
10808 return Relocatable_relocs::RELOC_COPY
;
10811 // Return the strategy to use for a local symbol which is a section
10812 // symbol, given the relocation type.
10813 inline Relocatable_relocs::Reloc_strategy
10814 local_section_strategy(unsigned int, Relobj
*)
10816 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
10819 // Return the strategy to use for a global symbol, given the
10820 // relocation type, the object, and the symbol index.
10821 inline Relocatable_relocs::Reloc_strategy
10822 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
10825 && (r_type
== elfcpp::R_PPC_PLTREL24
10826 || r_type
== elfcpp::R_POWERPC_PLT16_LO
10827 || r_type
== elfcpp::R_POWERPC_PLT16_HI
10828 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
10829 return Relocatable_relocs::RELOC_SPECIAL
;
10830 return Relocatable_relocs::RELOC_COPY
;
10834 // Scan the relocs during a relocatable link.
10836 template<int size
, bool big_endian
>
10838 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
10839 Symbol_table
* symtab
,
10841 Sized_relobj_file
<size
, big_endian
>* object
,
10842 unsigned int data_shndx
,
10843 unsigned int sh_type
,
10844 const unsigned char* prelocs
,
10845 size_t reloc_count
,
10846 Output_section
* output_section
,
10847 bool needs_special_offset_handling
,
10848 size_t local_symbol_count
,
10849 const unsigned char* plocal_symbols
,
10850 Relocatable_relocs
* rr
)
10852 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
10854 gold_assert(sh_type
== elfcpp::SHT_RELA
);
10856 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
10864 needs_special_offset_handling
,
10865 local_symbol_count
,
10870 // Scan the relocs for --emit-relocs.
10872 template<int size
, bool big_endian
>
10874 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
10875 Symbol_table
* symtab
,
10877 Sized_relobj_file
<size
, big_endian
>* object
,
10878 unsigned int data_shndx
,
10879 unsigned int sh_type
,
10880 const unsigned char* prelocs
,
10881 size_t reloc_count
,
10882 Output_section
* output_section
,
10883 bool needs_special_offset_handling
,
10884 size_t local_symbol_count
,
10885 const unsigned char* plocal_syms
,
10886 Relocatable_relocs
* rr
)
10888 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
10890 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
10891 Emit_relocs_strategy
;
10893 gold_assert(sh_type
== elfcpp::SHT_RELA
);
10895 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
10903 needs_special_offset_handling
,
10904 local_symbol_count
,
10909 // Emit relocations for a section.
10910 // This is a modified version of the function by the same name in
10911 // target-reloc.h. Using relocate_special_relocatable for
10912 // R_PPC_PLTREL24 would require duplication of the entire body of the
10913 // loop, so we may as well duplicate the whole thing.
10915 template<int size
, bool big_endian
>
10917 Target_powerpc
<size
, big_endian
>::relocate_relocs(
10918 const Relocate_info
<size
, big_endian
>* relinfo
,
10919 unsigned int sh_type
,
10920 const unsigned char* prelocs
,
10921 size_t reloc_count
,
10922 Output_section
* output_section
,
10923 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
10925 Address view_address
,
10927 unsigned char* reloc_view
,
10928 section_size_type reloc_view_size
)
10930 gold_assert(sh_type
== elfcpp::SHT_RELA
);
10932 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
10933 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
10934 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
10935 // Offset from start of insn to d-field reloc.
10936 const int d_offset
= big_endian
? 2 : 0;
10938 Powerpc_relobj
<size
, big_endian
>* const object
10939 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
10940 const unsigned int local_count
= object
->local_symbol_count();
10941 unsigned int got2_shndx
= object
->got2_shndx();
10942 Address got2_addend
= 0;
10943 if (got2_shndx
!= 0)
10945 got2_addend
= object
->get_output_section_offset(got2_shndx
);
10946 gold_assert(got2_addend
!= invalid_address
);
10949 const bool relocatable
= parameters
->options().relocatable();
10951 unsigned char* pwrite
= reloc_view
;
10952 bool zap_next
= false;
10953 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
10955 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
10956 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
10959 Reltype
reloc(prelocs
);
10960 Reltype_write
reloc_write(pwrite
);
10962 Address offset
= reloc
.get_r_offset();
10963 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
10964 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
10965 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
10966 const unsigned int orig_r_sym
= r_sym
;
10967 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
10968 = reloc
.get_r_addend();
10969 const Symbol
* gsym
= NULL
;
10973 // We could arrange to discard these and other relocs for
10974 // tls optimised sequences in the strategy methods, but for
10975 // now do as BFD ld does.
10976 r_type
= elfcpp::R_POWERPC_NONE
;
10980 // Get the new symbol index.
10981 Output_section
* os
= NULL
;
10982 if (r_sym
< local_count
)
10986 case Relocatable_relocs::RELOC_COPY
:
10987 case Relocatable_relocs::RELOC_SPECIAL
:
10990 r_sym
= object
->symtab_index(r_sym
);
10991 gold_assert(r_sym
!= -1U);
10995 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
10997 // We are adjusting a section symbol. We need to find
10998 // the symbol table index of the section symbol for
10999 // the output section corresponding to input section
11000 // in which this symbol is defined.
11001 gold_assert(r_sym
< local_count
);
11003 unsigned int shndx
=
11004 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
11005 gold_assert(is_ordinary
);
11006 os
= object
->output_section(shndx
);
11007 gold_assert(os
!= NULL
);
11008 gold_assert(os
->needs_symtab_index());
11009 r_sym
= os
->symtab_index();
11014 gold_unreachable();
11019 gsym
= object
->global_symbol(r_sym
);
11020 gold_assert(gsym
!= NULL
);
11021 if (gsym
->is_forwarder())
11022 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
11024 gold_assert(gsym
->has_symtab_index());
11025 r_sym
= gsym
->symtab_index();
11028 // Get the new offset--the location in the output section where
11029 // this relocation should be applied.
11030 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11031 offset
+= offset_in_output_section
;
11034 section_offset_type sot_offset
=
11035 convert_types
<section_offset_type
, Address
>(offset
);
11036 section_offset_type new_sot_offset
=
11037 output_section
->output_offset(object
, relinfo
->data_shndx
,
11039 gold_assert(new_sot_offset
!= -1);
11040 offset
= new_sot_offset
;
11043 // In an object file, r_offset is an offset within the section.
11044 // In an executable or dynamic object, generated by
11045 // --emit-relocs, r_offset is an absolute address.
11048 offset
+= view_address
;
11049 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
11050 offset
-= offset_in_output_section
;
11053 // Handle the reloc addend based on the strategy.
11054 if (strategy
== Relocatable_relocs::RELOC_COPY
)
11056 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
11058 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
11059 addend
= psymval
->value(object
, addend
);
11060 // In a relocatable link, the symbol value is relative to
11061 // the start of the output section. For a non-relocatable
11062 // link, we need to adjust the addend.
11065 gold_assert(os
!= NULL
);
11066 addend
-= os
->address();
11069 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
11073 if (addend
>= 32768)
11074 addend
+= got2_addend
;
11076 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
11078 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
11079 addend
-= d_offset
;
11081 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
11083 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
11084 addend
-= d_offset
+ 4;
11088 gold_unreachable();
11092 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11093 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
11094 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
11095 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
11097 // First instruction of a global dynamic sequence,
11099 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11100 switch (this->optimize_tls_gd(final
))
11102 case tls::TLSOPT_TO_IE
:
11103 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
11104 - elfcpp::R_POWERPC_GOT_TLSGD16
);
11106 case tls::TLSOPT_TO_LE
:
11107 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
11108 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
11109 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11112 r_type
= elfcpp::R_POWERPC_NONE
;
11113 offset
-= d_offset
;
11120 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11121 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
11122 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
11123 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
11125 // First instruction of a local dynamic sequence,
11127 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11129 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
11130 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
11132 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11133 const Output_section
* os
= relinfo
->layout
->tls_segment()
11135 gold_assert(os
!= NULL
);
11136 gold_assert(os
->needs_symtab_index());
11137 r_sym
= os
->symtab_index();
11138 addend
= dtp_offset
;
11142 r_type
= elfcpp::R_POWERPC_NONE
;
11143 offset
-= d_offset
;
11147 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11148 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
11149 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
11150 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
11152 // First instruction of initial exec sequence.
11153 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11154 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11156 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
11157 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
11158 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
11161 r_type
= elfcpp::R_POWERPC_NONE
;
11162 offset
-= d_offset
;
11166 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
11167 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
11169 // Second instruction of a global dynamic sequence,
11170 // the __tls_get_addr call
11171 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11172 switch (this->optimize_tls_gd(final
))
11174 case tls::TLSOPT_TO_IE
:
11175 r_type
= elfcpp::R_POWERPC_NONE
;
11178 case tls::TLSOPT_TO_LE
:
11179 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11180 offset
+= d_offset
;
11187 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
11188 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
11190 // Second instruction of a local dynamic sequence,
11191 // the __tls_get_addr call
11192 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
11194 const Output_section
* os
= relinfo
->layout
->tls_segment()
11196 gold_assert(os
!= NULL
);
11197 gold_assert(os
->needs_symtab_index());
11198 r_sym
= os
->symtab_index();
11199 addend
= dtp_offset
;
11200 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11201 offset
+= d_offset
;
11205 else if (r_type
== elfcpp::R_POWERPC_TLS
)
11207 // Second instruction of an initial exec sequence
11208 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
11209 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
11211 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
11212 offset
+= d_offset
;
11217 reloc_write
.put_r_offset(offset
);
11218 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
11219 reloc_write
.put_r_addend(addend
);
11221 pwrite
+= reloc_size
;
11224 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
11225 == reloc_view_size
);
11228 // Return the value to use for a dynamic symbol which requires special
11229 // treatment. This is how we support equality comparisons of function
11230 // pointers across shared library boundaries, as described in the
11231 // processor specific ABI supplement.
11233 template<int size
, bool big_endian
>
11235 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
11239 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
11240 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11241 p
!= this->stub_tables_
.end();
11244 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11245 = (*p
)->find_plt_call_entry(gsym
);
11247 return (*p
)->stub_address() + ent
->off_
;
11250 else if (this->abiversion() >= 2)
11252 Address off
= this->glink_section()->find_global_entry(gsym
);
11253 if (off
!= invalid_address
)
11254 return this->glink_section()->global_entry_address() + off
;
11256 gold_unreachable();
11259 // Return the PLT address to use for a local symbol.
11260 template<int size
, bool big_endian
>
11262 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
11263 const Relobj
* object
,
11264 unsigned int symndx
) const
11268 const Sized_relobj
<size
, big_endian
>* relobj
11269 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
11270 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11271 p
!= this->stub_tables_
.end();
11274 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11275 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
11277 return (*p
)->stub_address() + ent
->off_
;
11280 gold_unreachable();
11283 // Return the PLT address to use for a global symbol.
11284 template<int size
, bool big_endian
>
11286 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
11287 const Symbol
* gsym
) const
11291 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
11292 p
!= this->stub_tables_
.end();
11295 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
11296 = (*p
)->find_plt_call_entry(gsym
);
11298 return (*p
)->stub_address() + ent
->off_
;
11301 else if (this->abiversion() >= 2)
11303 Address off
= this->glink_section()->find_global_entry(gsym
);
11304 if (off
!= invalid_address
)
11305 return this->glink_section()->global_entry_address() + off
;
11307 gold_unreachable();
11310 // Return the offset to use for the GOT_INDX'th got entry which is
11311 // for a local tls symbol specified by OBJECT, SYMNDX.
11312 template<int size
, bool big_endian
>
11314 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
11315 const Relobj
* object
,
11316 unsigned int symndx
,
11317 unsigned int got_indx
) const
11319 const Powerpc_relobj
<size
, big_endian
>* ppc_object
11320 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
11321 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
11323 for (Got_type got_type
= GOT_TYPE_TLSGD
;
11324 got_type
<= GOT_TYPE_TPREL
;
11325 got_type
= Got_type(got_type
+ 1))
11326 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
11328 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
11329 if (got_type
== GOT_TYPE_TLSGD
)
11331 if (off
== got_indx
* (size
/ 8))
11333 if (got_type
== GOT_TYPE_TPREL
)
11336 return -dtp_offset
;
11340 gold_unreachable();
11343 // Return the offset to use for the GOT_INDX'th got entry which is
11344 // for global tls symbol GSYM.
11345 template<int size
, bool big_endian
>
11347 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
11349 unsigned int got_indx
) const
11351 if (gsym
->type() == elfcpp::STT_TLS
)
11353 for (Got_type got_type
= GOT_TYPE_TLSGD
;
11354 got_type
<= GOT_TYPE_TPREL
;
11355 got_type
= Got_type(got_type
+ 1))
11356 if (gsym
->has_got_offset(got_type
))
11358 unsigned int off
= gsym
->got_offset(got_type
);
11359 if (got_type
== GOT_TYPE_TLSGD
)
11361 if (off
== got_indx
* (size
/ 8))
11363 if (got_type
== GOT_TYPE_TPREL
)
11366 return -dtp_offset
;
11370 gold_unreachable();
11373 // The selector for powerpc object files.
11375 template<int size
, bool big_endian
>
11376 class Target_selector_powerpc
: public Target_selector
11379 Target_selector_powerpc()
11380 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
11383 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
11384 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
11386 ? (big_endian
? "elf64ppc" : "elf64lppc")
11387 : (big_endian
? "elf32ppc" : "elf32lppc")))
11391 do_instantiate_target()
11392 { return new Target_powerpc
<size
, big_endian
>(); }
11395 Target_selector_powerpc
<32, true> target_selector_ppc32
;
11396 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
11397 Target_selector_powerpc
<64, true> target_selector_ppc64
;
11398 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
11400 // Instantiate these constants for -O0
11401 template<int size
, bool big_endian
>
11402 const typename Output_data_glink
<size
, big_endian
>::Address
11403 Output_data_glink
<size
, big_endian
>::invalid_address
;
11404 template<int size
, bool big_endian
>
11405 const typename Stub_table
<size
, big_endian
>::Address
11406 Stub_table
<size
, big_endian
>::invalid_address
;
11407 template<int size
, bool big_endian
>
11408 const typename Target_powerpc
<size
, big_endian
>::Address
11409 Target_powerpc
<size
, big_endian
>::invalid_address
;
11411 } // End anonymous namespace.