1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2018 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"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_brlt_powerpc
;
56 template<int size
, bool big_endian
>
57 class Output_data_got_powerpc
;
59 template<int size
, bool big_endian
>
60 class Output_data_glink
;
62 template<int size
, bool big_endian
>
65 template<int size
, bool big_endian
>
66 class Output_data_save_res
;
68 template<int size
, bool big_endian
>
71 struct Stub_table_owner
74 : output_section(NULL
), owner(NULL
)
77 Output_section
* output_section
;
78 const Output_section::Input_section
* owner
;
82 is_branch_reloc(unsigned int r_type
);
84 // Counter incremented on every Powerpc_relobj constructed.
85 static uint32_t object_id
= 0;
87 template<int size
, bool big_endian
>
88 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
91 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
92 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
93 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
95 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
96 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
97 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
98 uniq_(object_id
++), special_(0), relatoc_(0), toc_(0),
99 has_small_toc_reloc_(false), opd_valid_(false),
100 e_flags_(ehdr
.get_e_flags()), no_toc_opt_(), opd_ent_(),
101 access_from_map_(), has14_(), stub_table_index_(), st_other_()
103 this->set_abiversion(0);
109 // Read the symbols then set up st_other vector.
111 do_read_symbols(Read_symbols_data
*);
113 // Arrange to always relocate .toc first.
115 do_relocate_sections(
116 const Symbol_table
* symtab
, const Layout
* layout
,
117 const unsigned char* pshdrs
, Output_file
* of
,
118 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
);
120 // The .toc section index.
127 // Mark .toc entry at OFF as not optimizable.
129 set_no_toc_opt(Address off
)
131 if (this->no_toc_opt_
.empty())
132 this->no_toc_opt_
.resize(this->section_size(this->toc_shndx())
135 if (off
< this->no_toc_opt_
.size())
136 this->no_toc_opt_
[off
] = true;
139 // Mark the entire .toc as not optimizable.
143 this->no_toc_opt_
.resize(1);
144 this->no_toc_opt_
[0] = true;
147 // Return true if code using the .toc entry at OFF should not be edited.
149 no_toc_opt(Address off
) const
151 if (this->no_toc_opt_
.empty())
154 if (off
>= this->no_toc_opt_
.size())
156 return this->no_toc_opt_
[off
];
159 // The .got2 section shndx.
164 return this->special_
;
169 // The .opd section shndx.
176 return this->special_
;
179 // Init OPD entry arrays.
181 init_opd(size_t opd_size
)
183 size_t count
= this->opd_ent_ndx(opd_size
);
184 this->opd_ent_
.resize(count
);
187 // Return section and offset of function entry for .opd + R_OFF.
189 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
191 size_t ndx
= this->opd_ent_ndx(r_off
);
192 gold_assert(ndx
< this->opd_ent_
.size());
193 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
195 *value
= this->opd_ent_
[ndx
].off
;
196 return this->opd_ent_
[ndx
].shndx
;
199 // Set section and offset of function entry for .opd + R_OFF.
201 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
203 size_t ndx
= this->opd_ent_ndx(r_off
);
204 gold_assert(ndx
< this->opd_ent_
.size());
205 this->opd_ent_
[ndx
].shndx
= shndx
;
206 this->opd_ent_
[ndx
].off
= value
;
209 // Return discard flag for .opd + R_OFF.
211 get_opd_discard(Address r_off
) const
213 size_t ndx
= this->opd_ent_ndx(r_off
);
214 gold_assert(ndx
< this->opd_ent_
.size());
215 return this->opd_ent_
[ndx
].discard
;
218 // Set discard flag for .opd + R_OFF.
220 set_opd_discard(Address r_off
)
222 size_t ndx
= this->opd_ent_ndx(r_off
);
223 gold_assert(ndx
< this->opd_ent_
.size());
224 this->opd_ent_
[ndx
].discard
= true;
229 { return this->opd_valid_
; }
233 { this->opd_valid_
= true; }
235 // Examine .rela.opd to build info about function entry points.
237 scan_opd_relocs(size_t reloc_count
,
238 const unsigned char* prelocs
,
239 const unsigned char* plocal_syms
);
241 // Returns true if a code sequence loading a TOC entry can be
242 // converted into code calculating a TOC pointer relative offset.
244 make_toc_relative(Target_powerpc
<size
, big_endian
>* target
,
247 // Perform the Sized_relobj_file method, then set up opd info from
250 do_read_relocs(Read_relocs_data
*);
253 do_find_special_sections(Read_symbols_data
* sd
);
255 // Adjust this local symbol value. Return false if the symbol
256 // should be discarded from the output file.
258 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
260 if (size
== 64 && this->opd_shndx() != 0)
263 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
265 if (this->get_opd_discard(lv
->input_value()))
273 { return &this->access_from_map_
; }
275 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
276 // section at DST_OFF.
278 add_reference(Relobj
* src_obj
,
279 unsigned int src_indx
,
280 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
282 Section_id
src_id(src_obj
, src_indx
);
283 this->access_from_map_
[dst_off
].insert(src_id
);
286 // Add a reference to the code section specified by the .opd entry
289 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
291 size_t ndx
= this->opd_ent_ndx(dst_off
);
292 if (ndx
>= this->opd_ent_
.size())
293 this->opd_ent_
.resize(ndx
+ 1);
294 this->opd_ent_
[ndx
].gc_mark
= true;
298 process_gc_mark(Symbol_table
* symtab
)
300 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
301 if (this->opd_ent_
[i
].gc_mark
)
303 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
304 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
308 // Return offset in output GOT section that this object will use
309 // as a TOC pointer. Won't be just a constant with multi-toc support.
311 toc_base_offset() const
315 set_has_small_toc_reloc()
316 { has_small_toc_reloc_
= true; }
319 has_small_toc_reloc() const
320 { return has_small_toc_reloc_
; }
323 set_has_14bit_branch(unsigned int shndx
)
325 if (shndx
>= this->has14_
.size())
326 this->has14_
.resize(shndx
+ 1);
327 this->has14_
[shndx
] = true;
331 has_14bit_branch(unsigned int shndx
) const
332 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
335 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
337 if (shndx
>= this->stub_table_index_
.size())
338 this->stub_table_index_
.resize(shndx
+ 1, -1);
339 this->stub_table_index_
[shndx
] = stub_index
;
342 Stub_table
<size
, big_endian
>*
343 stub_table(unsigned int shndx
)
345 if (shndx
< this->stub_table_index_
.size())
347 Target_powerpc
<size
, big_endian
>* target
348 = static_cast<Target_powerpc
<size
, big_endian
>*>(
349 parameters
->sized_target
<size
, big_endian
>());
350 unsigned int indx
= this->stub_table_index_
[shndx
];
351 if (indx
< target
->stub_tables().size())
352 return target
->stub_tables()[indx
];
360 this->stub_table_index_
.clear();
365 { return this->uniq_
; }
369 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
371 // Set ABI version for input and output
373 set_abiversion(int ver
);
376 st_other (unsigned int symndx
) const
378 return this->st_other_
[symndx
];
382 ppc64_local_entry_offset(const Symbol
* sym
) const
383 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
386 ppc64_local_entry_offset(unsigned int symndx
) const
387 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
398 // Return index into opd_ent_ array for .opd entry at OFF.
399 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
400 // apart when the language doesn't use the last 8-byte word, the
401 // environment pointer. Thus dividing the entry section offset by
402 // 16 will give an index into opd_ent_ that works for either layout
403 // of .opd. (It leaves some elements of the vector unused when .opd
404 // entries are spaced 24 bytes apart, but we don't know the spacing
405 // until relocations are processed, and in any case it is possible
406 // for an object to have some entries spaced 16 bytes apart and
407 // others 24 bytes apart.)
409 opd_ent_ndx(size_t off
) const
412 // Per object unique identifier
415 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
416 unsigned int special_
;
418 // For 64-bit the .rela.toc and .toc section shdnx.
419 unsigned int relatoc_
;
422 // For 64-bit, whether this object uses small model relocs to access
424 bool has_small_toc_reloc_
;
426 // Set at the start of gc_process_relocs, when we know opd_ent_
427 // vector is valid. The flag could be made atomic and set in
428 // do_read_relocs with memory_order_release and then tested with
429 // memory_order_acquire, potentially resulting in fewer entries in
434 elfcpp::Elf_Word e_flags_
;
436 // For 64-bit, an array with one entry per 64-bit word in the .toc
437 // section, set if accesses using that word cannot be optimised.
438 std::vector
<bool> no_toc_opt_
;
440 // The first 8-byte word of an OPD entry gives the address of the
441 // entry point of the function. Relocatable object files have a
442 // relocation on this word. The following vector records the
443 // section and offset specified by these relocations.
444 std::vector
<Opd_ent
> opd_ent_
;
446 // References made to this object's .opd section when running
447 // gc_process_relocs for another object, before the opd_ent_ vector
448 // is valid for this object.
449 Access_from access_from_map_
;
451 // Whether input section has a 14-bit branch reloc.
452 std::vector
<bool> has14_
;
454 // The stub table to use for a given input section.
455 std::vector
<unsigned int> stub_table_index_
;
457 // ELF st_other field for local symbols.
458 std::vector
<unsigned char> st_other_
;
461 template<int size
, bool big_endian
>
462 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
465 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
467 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
468 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
469 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
470 opd_shndx_(0), e_flags_(ehdr
.get_e_flags()), opd_ent_()
472 this->set_abiversion(0);
478 // Call Sized_dynobj::do_read_symbols to read the symbols then
479 // read .opd from a dynamic object, filling in opd_ent_ vector,
481 do_read_symbols(Read_symbols_data
*);
483 // The .opd section shndx.
487 return this->opd_shndx_
;
490 // The .opd section address.
494 return this->opd_address_
;
497 // Init OPD entry arrays.
499 init_opd(size_t opd_size
)
501 size_t count
= this->opd_ent_ndx(opd_size
);
502 this->opd_ent_
.resize(count
);
505 // Return section and offset of function entry for .opd + R_OFF.
507 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
509 size_t ndx
= this->opd_ent_ndx(r_off
);
510 gold_assert(ndx
< this->opd_ent_
.size());
511 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
513 *value
= this->opd_ent_
[ndx
].off
;
514 return this->opd_ent_
[ndx
].shndx
;
517 // Set section and offset of function entry for .opd + R_OFF.
519 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
521 size_t ndx
= this->opd_ent_ndx(r_off
);
522 gold_assert(ndx
< this->opd_ent_
.size());
523 this->opd_ent_
[ndx
].shndx
= shndx
;
524 this->opd_ent_
[ndx
].off
= value
;
529 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
531 // Set ABI version for input and output.
533 set_abiversion(int ver
);
536 // Used to specify extent of executable sections.
539 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
540 : start(start_
), len(len_
), shndx(shndx_
)
544 operator<(const Sec_info
& that
) const
545 { return this->start
< that
.start
; }
558 // Return index into opd_ent_ array for .opd entry at OFF.
560 opd_ent_ndx(size_t off
) const
563 // For 64-bit the .opd section shndx and address.
564 unsigned int opd_shndx_
;
565 Address opd_address_
;
568 elfcpp::Elf_Word e_flags_
;
570 // The first 8-byte word of an OPD entry gives the address of the
571 // entry point of the function. Records the section and offset
572 // corresponding to the address. Note that in dynamic objects,
573 // offset is *not* relative to the section.
574 std::vector
<Opd_ent
> opd_ent_
;
577 // Powerpc_copy_relocs class. Needed to peek at dynamic relocs the
578 // base class will emit.
580 template<int sh_type
, int size
, bool big_endian
>
581 class Powerpc_copy_relocs
: public Copy_relocs
<sh_type
, size
, big_endian
>
584 Powerpc_copy_relocs()
585 : Copy_relocs
<sh_type
, size
, big_endian
>(elfcpp::R_POWERPC_COPY
)
588 // Emit any saved relocations which turn out to be needed. This is
589 // called after all the relocs have been scanned.
591 emit(Output_data_reloc
<sh_type
, true, size
, big_endian
>*);
594 template<int size
, bool big_endian
>
595 class Target_powerpc
: public Sized_target
<size
, big_endian
>
599 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
600 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
601 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
602 typedef Unordered_set
<Symbol_location
, Symbol_location_hash
> Tocsave_loc
;
603 static const Address invalid_address
= static_cast<Address
>(0) - 1;
604 // Offset of tp and dtp pointers from start of TLS block.
605 static const Address tp_offset
= 0x7000;
606 static const Address dtp_offset
= 0x8000;
609 : Sized_target
<size
, big_endian
>(&powerpc_info
),
610 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
611 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(),
612 tlsld_got_offset_(-1U),
613 stub_tables_(), branch_lookup_table_(), branch_info_(), tocsave_loc_(),
614 plt_thread_safe_(false), plt_localentry0_(false),
615 plt_localentry0_init_(false), has_localentry0_(false),
616 has_tls_get_addr_opt_(false),
617 relax_failed_(false), relax_fail_count_(0),
618 stub_group_size_(0), savres_section_(0),
619 tls_get_addr_(NULL
), tls_get_addr_opt_(NULL
)
623 // Process the relocations to determine unreferenced sections for
624 // garbage collection.
626 gc_process_relocs(Symbol_table
* symtab
,
628 Sized_relobj_file
<size
, big_endian
>* object
,
629 unsigned int data_shndx
,
630 unsigned int sh_type
,
631 const unsigned char* prelocs
,
633 Output_section
* output_section
,
634 bool needs_special_offset_handling
,
635 size_t local_symbol_count
,
636 const unsigned char* plocal_symbols
);
638 // Scan the relocations to look for symbol adjustments.
640 scan_relocs(Symbol_table
* symtab
,
642 Sized_relobj_file
<size
, big_endian
>* object
,
643 unsigned int data_shndx
,
644 unsigned int sh_type
,
645 const unsigned char* prelocs
,
647 Output_section
* output_section
,
648 bool needs_special_offset_handling
,
649 size_t local_symbol_count
,
650 const unsigned char* plocal_symbols
);
652 // Map input .toc section to output .got section.
654 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
656 if (size
== 64 && strcmp(name
, ".toc") == 0)
664 // Provide linker defined save/restore functions.
666 define_save_restore_funcs(Layout
*, Symbol_table
*);
668 // No stubs unless a final link.
671 { return !parameters
->options().relocatable(); }
674 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
677 do_plt_fde_location(const Output_data
*, unsigned char*,
678 uint64_t*, off_t
*) const;
680 // Stash info about branches, for stub generation.
682 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
683 unsigned int data_shndx
, Address r_offset
,
684 unsigned int r_type
, unsigned int r_sym
, Address addend
)
686 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
687 this->branch_info_
.push_back(info
);
688 if (r_type
== elfcpp::R_POWERPC_REL14
689 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
690 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
691 ppc_object
->set_has_14bit_branch(data_shndx
);
694 // Return whether the last branch is a plt call, and if so, mark the
695 // branch as having an R_PPC64_TOCSAVE.
697 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
698 unsigned int data_shndx
, Address r_offset
, Symbol_table
* symtab
)
701 && !this->branch_info_
.empty()
702 && this->branch_info_
.back().mark_pltcall(ppc_object
, data_shndx
,
703 r_offset
, this, symtab
));
706 // Say the given location, that of a nop in a function prologue with
707 // an R_PPC64_TOCSAVE reloc, will be used to save r2.
708 // R_PPC64_TOCSAVE relocs on nops following calls point at this nop.
710 add_tocsave(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
711 unsigned int shndx
, Address offset
)
714 loc
.object
= ppc_object
;
717 this->tocsave_loc_
.insert(loc
);
724 return this->tocsave_loc_
;
728 do_define_standard_symbols(Symbol_table
*, Layout
*);
730 // Finalize the sections.
732 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
734 // Return the value to use for a dynamic which requires special
737 do_dynsym_value(const Symbol
*) const;
739 // Return the PLT address to use for a local symbol.
741 do_plt_address_for_local(const Relobj
*, unsigned int) const;
743 // Return the PLT address to use for a global symbol.
745 do_plt_address_for_global(const Symbol
*) const;
747 // Return the offset to use for the GOT_INDX'th got entry which is
748 // for a local tls symbol specified by OBJECT, SYMNDX.
750 do_tls_offset_for_local(const Relobj
* object
,
752 unsigned int got_indx
) const;
754 // Return the offset to use for the GOT_INDX'th got entry which is
755 // for global tls symbol GSYM.
757 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
760 do_function_location(Symbol_location
*) const;
763 do_can_check_for_function_pointers() const
766 // Adjust -fsplit-stack code which calls non-split-stack code.
768 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
769 section_offset_type fnoffset
, section_size_type fnsize
,
770 const unsigned char* prelocs
, size_t reloc_count
,
771 unsigned char* view
, section_size_type view_size
,
772 std::string
* from
, std::string
* to
) const;
774 // Relocate a section.
776 relocate_section(const Relocate_info
<size
, big_endian
>*,
777 unsigned int sh_type
,
778 const unsigned char* prelocs
,
780 Output_section
* output_section
,
781 bool needs_special_offset_handling
,
783 Address view_address
,
784 section_size_type view_size
,
785 const Reloc_symbol_changes
*);
787 // Scan the relocs during a relocatable link.
789 scan_relocatable_relocs(Symbol_table
* symtab
,
791 Sized_relobj_file
<size
, big_endian
>* object
,
792 unsigned int data_shndx
,
793 unsigned int sh_type
,
794 const unsigned char* prelocs
,
796 Output_section
* output_section
,
797 bool needs_special_offset_handling
,
798 size_t local_symbol_count
,
799 const unsigned char* plocal_symbols
,
800 Relocatable_relocs
*);
802 // Scan the relocs for --emit-relocs.
804 emit_relocs_scan(Symbol_table
* symtab
,
806 Sized_relobj_file
<size
, big_endian
>* object
,
807 unsigned int data_shndx
,
808 unsigned int sh_type
,
809 const unsigned char* prelocs
,
811 Output_section
* output_section
,
812 bool needs_special_offset_handling
,
813 size_t local_symbol_count
,
814 const unsigned char* plocal_syms
,
815 Relocatable_relocs
* rr
);
817 // Emit relocations for a section.
819 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
820 unsigned int sh_type
,
821 const unsigned char* prelocs
,
823 Output_section
* output_section
,
824 typename
elfcpp::Elf_types
<size
>::Elf_Off
825 offset_in_output_section
,
827 Address view_address
,
829 unsigned char* reloc_view
,
830 section_size_type reloc_view_size
);
832 // Return whether SYM is defined by the ABI.
834 do_is_defined_by_abi(const Symbol
* sym
) const
836 return strcmp(sym
->name(), "__tls_get_addr") == 0;
839 // Return the size of the GOT section.
843 gold_assert(this->got_
!= NULL
);
844 return this->got_
->data_size();
847 // Get the PLT section.
848 const Output_data_plt_powerpc
<size
, big_endian
>*
851 gold_assert(this->plt_
!= NULL
);
855 // Get the IPLT section.
856 const Output_data_plt_powerpc
<size
, big_endian
>*
859 gold_assert(this->iplt_
!= NULL
);
863 // Return the plt offset and section for the given global sym.
865 plt_off(const Symbol
* gsym
,
866 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
868 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
869 && gsym
->can_use_relative_reloc(false))
870 *sec
= this->iplt_section();
872 *sec
= this->plt_section();
873 return gsym
->plt_offset();
876 // Return the plt offset and section for the given local sym.
878 plt_off(const Sized_relobj_file
<size
, big_endian
>* relobj
,
879 unsigned int local_sym_index
,
880 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
882 *sec
= this->iplt_section();
883 return relobj
->local_plt_offset(local_sym_index
);
886 // Get the .glink section.
887 const Output_data_glink
<size
, big_endian
>*
888 glink_section() const
890 gold_assert(this->glink_
!= NULL
);
894 Output_data_glink
<size
, big_endian
>*
897 gold_assert(this->glink_
!= NULL
);
901 bool has_glink() const
902 { return this->glink_
!= NULL
; }
904 // Get the GOT section.
905 const Output_data_got_powerpc
<size
, big_endian
>*
908 gold_assert(this->got_
!= NULL
);
912 // Get the GOT section, creating it if necessary.
913 Output_data_got_powerpc
<size
, big_endian
>*
914 got_section(Symbol_table
*, Layout
*);
917 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
918 const elfcpp::Ehdr
<size
, big_endian
>&);
920 // Return the number of entries in the GOT.
922 got_entry_count() const
924 if (this->got_
== NULL
)
926 return this->got_size() / (size
/ 8);
929 // Return the number of entries in the PLT.
931 plt_entry_count() const;
933 // Return the offset of the first non-reserved PLT entry.
935 first_plt_entry_offset() const
939 if (this->abiversion() >= 2)
944 // Return the size of each PLT entry.
946 plt_entry_size() const
950 if (this->abiversion() >= 2)
955 Output_data_save_res
<size
, big_endian
>*
956 savres_section() const
958 return this->savres_section_
;
961 // Add any special sections for this symbol to the gc work list.
962 // For powerpc64, this adds the code section of a function
965 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
967 // Handle target specific gc actions when adding a gc reference from
968 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
969 // and DST_OFF. For powerpc64, this adds a referenc to the code
970 // section of a function descriptor.
972 do_gc_add_reference(Symbol_table
* symtab
,
974 unsigned int src_shndx
,
976 unsigned int dst_shndx
,
977 Address dst_off
) const;
979 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
982 { return this->stub_tables_
; }
984 const Output_data_brlt_powerpc
<size
, big_endian
>*
986 { return this->brlt_section_
; }
989 add_branch_lookup_table(Address to
)
991 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
992 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
996 find_branch_lookup_table(Address to
)
998 typename
Branch_lookup_table::const_iterator p
999 = this->branch_lookup_table_
.find(to
);
1000 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
1004 write_branch_lookup_table(unsigned char *oview
)
1006 for (typename
Branch_lookup_table::const_iterator p
1007 = this->branch_lookup_table_
.begin();
1008 p
!= this->branch_lookup_table_
.end();
1011 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
1015 // Wrapper used after relax to define a local symbol in output data,
1016 // from the end if value < 0.
1018 define_local(Symbol_table
* symtab
, const char* name
,
1019 Output_data
* od
, Address value
, unsigned int symsize
)
1022 = symtab
->define_in_output_data(name
, NULL
, Symbol_table::PREDEFINED
,
1023 od
, value
, symsize
, elfcpp::STT_NOTYPE
,
1024 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
, 0,
1025 static_cast<Signed_address
>(value
) < 0,
1027 // We are creating this symbol late, so need to fix up things
1028 // done early in Layout::finalize.
1029 sym
->set_dynsym_index(-1U);
1033 plt_thread_safe() const
1034 { return this->plt_thread_safe_
; }
1037 plt_localentry0() const
1038 { return this->plt_localentry0_
; }
1041 set_has_localentry0()
1043 this->has_localentry0_
= true;
1047 is_elfv2_localentry0(const Symbol
* gsym
) const
1050 && this->abiversion() >= 2
1051 && this->plt_localentry0()
1052 && gsym
->type() == elfcpp::STT_FUNC
1053 && gsym
->is_defined()
1054 && gsym
->nonvis() >> 3 == 0
1055 && !gsym
->non_zero_localentry());
1059 is_elfv2_localentry0(const Sized_relobj_file
<size
, big_endian
>* object
,
1060 unsigned int r_sym
) const
1062 const Powerpc_relobj
<size
, big_endian
>* ppc_object
1063 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
1066 && this->abiversion() >= 2
1067 && this->plt_localentry0()
1068 && ppc_object
->st_other(r_sym
) >> 5 == 0)
1070 const Symbol_value
<size
>* psymval
= object
->local_symbol(r_sym
);
1072 if (!psymval
->is_ifunc_symbol()
1073 && psymval
->input_shndx(&is_ordinary
) != elfcpp::SHN_UNDEF
1080 // Remember any symbols seen with non-zero localentry, even those
1081 // not providing a definition
1083 resolve(Symbol
* to
, const elfcpp::Sym
<size
, big_endian
>& sym
, Object
*,
1088 unsigned char st_other
= sym
.get_st_other();
1089 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1090 to
->set_non_zero_localentry();
1092 // We haven't resolved anything, continue normal processing.
1098 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
1101 set_abiversion(int ver
)
1103 elfcpp::Elf_Word flags
= this->processor_specific_flags();
1104 flags
&= ~elfcpp::EF_PPC64_ABI
;
1105 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
1106 this->set_processor_specific_flags(flags
);
1110 tls_get_addr_opt() const
1111 { return this->tls_get_addr_opt_
; }
1114 tls_get_addr() const
1115 { return this->tls_get_addr_
; }
1117 // If optimizing __tls_get_addr calls, whether this is the
1118 // "__tls_get_addr" symbol.
1120 is_tls_get_addr_opt(const Symbol
* gsym
) const
1122 return this->tls_get_addr_opt_
&& (gsym
== this->tls_get_addr_
1123 || gsym
== this->tls_get_addr_opt_
);
1127 replace_tls_get_addr(const Symbol
* gsym
) const
1128 { return this->tls_get_addr_opt_
&& gsym
== this->tls_get_addr_
; }
1131 set_has_tls_get_addr_opt()
1132 { this->has_tls_get_addr_opt_
= true; }
1134 // Offset to toc save stack slot
1137 { return this->abiversion() < 2 ? 40 : 24; }
1139 // Offset to linker save stack slot. ELFv2 doesn't have a linker word,
1140 // so use the CR save slot. Used only by __tls_get_addr call stub,
1141 // relying on __tls_get_addr not saving CR itself.
1144 { return this->abiversion() < 2 ? 32 : 8; }
1160 : tls_get_addr_state_(NOT_EXPECTED
),
1161 relinfo_(NULL
), relnum_(0), r_offset_(0)
1166 if (this->tls_get_addr_state_
!= NOT_EXPECTED
)
1173 if (this->relinfo_
!= NULL
)
1174 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
1175 _("missing expected __tls_get_addr call"));
1179 expect_tls_get_addr_call(
1180 const Relocate_info
<size
, big_endian
>* relinfo
,
1184 this->tls_get_addr_state_
= EXPECTED
;
1185 this->relinfo_
= relinfo
;
1186 this->relnum_
= relnum
;
1187 this->r_offset_
= r_offset
;
1191 expect_tls_get_addr_call()
1192 { this->tls_get_addr_state_
= EXPECTED
; }
1195 skip_next_tls_get_addr_call()
1196 {this->tls_get_addr_state_
= SKIP
; }
1199 maybe_skip_tls_get_addr_call(Target_powerpc
<size
, big_endian
>* target
,
1200 unsigned int r_type
, const Symbol
* gsym
)
1202 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
1203 || r_type
== elfcpp::R_PPC_PLTREL24
)
1205 && (gsym
== target
->tls_get_addr()
1206 || gsym
== target
->tls_get_addr_opt()));
1207 Tls_get_addr last_tls
= this->tls_get_addr_state_
;
1208 this->tls_get_addr_state_
= NOT_EXPECTED
;
1209 if (is_tls_call
&& last_tls
!= EXPECTED
)
1211 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
1220 // What we're up to regarding calls to __tls_get_addr.
1221 // On powerpc, the branch and link insn making a call to
1222 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
1223 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
1224 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
1225 // The marker relocation always comes first, and has the same
1226 // symbol as the reloc on the insn setting up the __tls_get_addr
1227 // argument. This ties the arg setup insn with the call insn,
1228 // allowing ld to safely optimize away the call. We check that
1229 // every call to __tls_get_addr has a marker relocation, and that
1230 // every marker relocation is on a call to __tls_get_addr.
1231 Tls_get_addr tls_get_addr_state_
;
1232 // Info about the last reloc for error message.
1233 const Relocate_info
<size
, big_endian
>* relinfo_
;
1238 // The class which scans relocations.
1239 class Scan
: protected Track_tls
1242 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1245 : Track_tls(), issued_non_pic_error_(false)
1249 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
1252 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1253 Sized_relobj_file
<size
, big_endian
>* object
,
1254 unsigned int data_shndx
,
1255 Output_section
* output_section
,
1256 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1257 const elfcpp::Sym
<size
, big_endian
>& lsym
,
1261 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
1262 Sized_relobj_file
<size
, big_endian
>* object
,
1263 unsigned int data_shndx
,
1264 Output_section
* output_section
,
1265 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1269 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1271 Sized_relobj_file
<size
, big_endian
>* relobj
,
1274 const elfcpp::Rela
<size
, big_endian
>& ,
1275 unsigned int r_type
,
1276 const elfcpp::Sym
<size
, big_endian
>&)
1278 // PowerPC64 .opd is not folded, so any identical function text
1279 // may be folded and we'll still keep function addresses distinct.
1280 // That means no reloc is of concern here.
1283 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1284 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1285 if (ppcobj
->abiversion() == 1)
1288 // For 32-bit and ELFv2, conservatively assume anything but calls to
1289 // function code might be taking the address of the function.
1290 return !is_branch_reloc(r_type
);
1294 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1296 Sized_relobj_file
<size
, big_endian
>* relobj
,
1299 const elfcpp::Rela
<size
, big_endian
>& ,
1300 unsigned int r_type
,
1306 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1307 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1308 if (ppcobj
->abiversion() == 1)
1311 return !is_branch_reloc(r_type
);
1315 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1316 Sized_relobj_file
<size
, big_endian
>* object
,
1317 unsigned int r_type
, bool report_err
);
1321 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1322 unsigned int r_type
);
1325 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1326 unsigned int r_type
, Symbol
*);
1329 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1330 Target_powerpc
* target
);
1333 check_non_pic(Relobj
*, unsigned int r_type
);
1335 // Whether we have issued an error about a non-PIC compilation.
1336 bool issued_non_pic_error_
;
1340 symval_for_branch(const Symbol_table
* symtab
,
1341 const Sized_symbol
<size
>* gsym
,
1342 Powerpc_relobj
<size
, big_endian
>* object
,
1343 Address
*value
, unsigned int *dest_shndx
);
1345 // The class which implements relocation.
1346 class Relocate
: protected Track_tls
1349 // Use 'at' branch hints when true, 'y' when false.
1350 // FIXME maybe: set this with an option.
1351 static const bool is_isa_v2
= true;
1357 // Do a relocation. Return false if the caller should not issue
1358 // any warnings about this relocation.
1360 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1361 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1362 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1363 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1367 class Relocate_comdat_behavior
1370 // Decide what the linker should do for relocations that refer to
1371 // discarded comdat sections.
1372 inline Comdat_behavior
1373 get(const char* name
)
1375 gold::Default_comdat_behavior default_behavior
;
1376 Comdat_behavior ret
= default_behavior
.get(name
);
1377 if (ret
== CB_ERROR
)
1380 && (strcmp(name
, ".fixup") == 0
1381 || strcmp(name
, ".got2") == 0))
1384 && (strcmp(name
, ".opd") == 0
1385 || strcmp(name
, ".toc") == 0
1386 || strcmp(name
, ".toc1") == 0))
1393 // Optimize the TLS relocation type based on what we know about the
1394 // symbol. IS_FINAL is true if the final address of this symbol is
1395 // known at link time.
1397 tls::Tls_optimization
1398 optimize_tls_gd(bool is_final
)
1400 // If we are generating a shared library, then we can't do anything
1402 if (parameters
->options().shared()
1403 || !parameters
->options().tls_optimize())
1404 return tls::TLSOPT_NONE
;
1407 return tls::TLSOPT_TO_IE
;
1408 return tls::TLSOPT_TO_LE
;
1411 tls::Tls_optimization
1414 if (parameters
->options().shared()
1415 || !parameters
->options().tls_optimize())
1416 return tls::TLSOPT_NONE
;
1418 return tls::TLSOPT_TO_LE
;
1421 tls::Tls_optimization
1422 optimize_tls_ie(bool is_final
)
1425 || parameters
->options().shared()
1426 || !parameters
->options().tls_optimize())
1427 return tls::TLSOPT_NONE
;
1429 return tls::TLSOPT_TO_LE
;
1434 make_glink_section(Layout
*);
1436 // Create the PLT section.
1438 make_plt_section(Symbol_table
*, Layout
*);
1441 make_iplt_section(Symbol_table
*, Layout
*);
1444 make_brlt_section(Layout
*);
1446 // Create a PLT entry for a global symbol.
1448 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1450 // Create a PLT entry for a local IFUNC symbol.
1452 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1453 Sized_relobj_file
<size
, big_endian
>*,
1457 // Create a GOT entry for local dynamic __tls_get_addr.
1459 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1460 Sized_relobj_file
<size
, big_endian
>* object
);
1463 tlsld_got_offset() const
1465 return this->tlsld_got_offset_
;
1468 // Get the dynamic reloc section, creating it if necessary.
1470 rela_dyn_section(Layout
*);
1472 // Similarly, but for ifunc symbols get the one for ifunc.
1474 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1476 // Copy a relocation against a global symbol.
1478 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1479 Sized_relobj_file
<size
, big_endian
>* object
,
1480 unsigned int shndx
, Output_section
* output_section
,
1481 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1483 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1484 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1485 symtab
->get_sized_symbol
<size
>(sym
),
1486 object
, shndx
, output_section
,
1487 r_type
, reloc
.get_r_offset(),
1488 reloc
.get_r_addend(),
1489 this->rela_dyn_section(layout
));
1492 // Look over all the input sections, deciding where to place stubs.
1494 group_sections(Layout
*, const Task
*, bool);
1496 // Sort output sections by address.
1497 struct Sort_sections
1500 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1501 { return sec1
->address() < sec2
->address(); }
1507 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1508 unsigned int data_shndx
,
1510 unsigned int r_type
,
1513 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1514 r_type_(r_type
), tocsave_ (0), r_sym_(r_sym
), addend_(addend
)
1520 // Return whether this branch is going via a plt call stub, and if
1521 // so, mark it as having an R_PPC64_TOCSAVE.
1523 mark_pltcall(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1524 unsigned int shndx
, Address offset
,
1525 Target_powerpc
* target
, Symbol_table
* symtab
);
1527 // If this branch needs a plt call stub, or a long branch stub, make one.
1529 make_stub(Stub_table
<size
, big_endian
>*,
1530 Stub_table
<size
, big_endian
>*,
1531 Symbol_table
*) const;
1534 // The branch location..
1535 Powerpc_relobj
<size
, big_endian
>* object_
;
1536 unsigned int shndx_
;
1538 // ..and the branch type and destination.
1539 unsigned int r_type_
: 31;
1540 unsigned int tocsave_
: 1;
1541 unsigned int r_sym_
;
1545 // Information about this specific target which we pass to the
1546 // general Target structure.
1547 static Target::Target_info powerpc_info
;
1549 // The types of GOT entries needed for this platform.
1550 // These values are exposed to the ABI in an incremental link.
1551 // Do not renumber existing values without changing the version
1552 // number of the .gnu_incremental_inputs section.
1556 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1557 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1558 GOT_TYPE_TPREL
// entry for @got@tprel
1562 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1563 // The PLT section. This is a container for a table of addresses,
1564 // and their relocations. Each address in the PLT has a dynamic
1565 // relocation (R_*_JMP_SLOT) and each address will have a
1566 // corresponding entry in .glink for lazy resolution of the PLT.
1567 // ppc32 initialises the PLT to point at the .glink entry, while
1568 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1569 // linker adds a stub that loads the PLT entry into ctr then
1570 // branches to ctr. There may be more than one stub for each PLT
1571 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1572 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1573 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1574 // The IPLT section. Like plt_, this is a container for a table of
1575 // addresses and their relocations, specifically for STT_GNU_IFUNC
1576 // functions that resolve locally (STT_GNU_IFUNC functions that
1577 // don't resolve locally go in PLT). Unlike plt_, these have no
1578 // entry in .glink for lazy resolution, and the relocation section
1579 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1580 // the relocation section may contain relocations against
1581 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1582 // relocation section will appear at the end of other dynamic
1583 // relocations, so that ld.so applies these relocations after other
1584 // dynamic relocations. In a static executable, the relocation
1585 // section is emitted and marked with __rela_iplt_start and
1586 // __rela_iplt_end symbols.
1587 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1588 // Section holding long branch destinations.
1589 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1590 // The .glink section.
1591 Output_data_glink
<size
, big_endian
>* glink_
;
1592 // The dynamic reloc section.
1593 Reloc_section
* rela_dyn_
;
1594 // Relocs saved to avoid a COPY reloc.
1595 Powerpc_copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1596 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1597 unsigned int tlsld_got_offset_
;
1599 Stub_tables stub_tables_
;
1600 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1601 Branch_lookup_table branch_lookup_table_
;
1603 typedef std::vector
<Branch_info
> Branches
;
1604 Branches branch_info_
;
1605 Tocsave_loc tocsave_loc_
;
1607 bool plt_thread_safe_
;
1608 bool plt_localentry0_
;
1609 bool plt_localentry0_init_
;
1610 bool has_localentry0_
;
1611 bool has_tls_get_addr_opt_
;
1614 int relax_fail_count_
;
1615 int32_t stub_group_size_
;
1617 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1619 // The "__tls_get_addr" symbol, if present
1620 Symbol
* tls_get_addr_
;
1621 // If optimizing __tls_get_addr calls, the "__tls_get_addr_opt" symbol.
1622 Symbol
* tls_get_addr_opt_
;
1626 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1629 true, // is_big_endian
1630 elfcpp::EM_PPC
, // machine_code
1631 false, // has_make_symbol
1632 false, // has_resolve
1633 false, // has_code_fill
1634 true, // is_default_stack_executable
1635 false, // can_icf_inline_merge_sections
1637 "/usr/lib/ld.so.1", // dynamic_linker
1638 0x10000000, // default_text_segment_address
1639 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1640 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1641 false, // isolate_execinstr
1643 elfcpp::SHN_UNDEF
, // small_common_shndx
1644 elfcpp::SHN_UNDEF
, // large_common_shndx
1645 0, // small_common_section_flags
1646 0, // large_common_section_flags
1647 NULL
, // attributes_section
1648 NULL
, // attributes_vendor
1649 "_start", // entry_symbol_name
1650 32, // hash_entry_size
1651 elfcpp::SHT_PROGBITS
, // unwind_section_type
1655 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1658 false, // is_big_endian
1659 elfcpp::EM_PPC
, // machine_code
1660 false, // has_make_symbol
1661 false, // has_resolve
1662 false, // has_code_fill
1663 true, // is_default_stack_executable
1664 false, // can_icf_inline_merge_sections
1666 "/usr/lib/ld.so.1", // dynamic_linker
1667 0x10000000, // default_text_segment_address
1668 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1669 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1670 false, // isolate_execinstr
1672 elfcpp::SHN_UNDEF
, // small_common_shndx
1673 elfcpp::SHN_UNDEF
, // large_common_shndx
1674 0, // small_common_section_flags
1675 0, // large_common_section_flags
1676 NULL
, // attributes_section
1677 NULL
, // attributes_vendor
1678 "_start", // entry_symbol_name
1679 32, // hash_entry_size
1680 elfcpp::SHT_PROGBITS
, // unwind_section_type
1684 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1687 true, // is_big_endian
1688 elfcpp::EM_PPC64
, // machine_code
1689 false, // has_make_symbol
1690 true, // has_resolve
1691 false, // has_code_fill
1692 false, // is_default_stack_executable
1693 false, // can_icf_inline_merge_sections
1695 "/usr/lib/ld.so.1", // dynamic_linker
1696 0x10000000, // default_text_segment_address
1697 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1698 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1699 false, // isolate_execinstr
1701 elfcpp::SHN_UNDEF
, // small_common_shndx
1702 elfcpp::SHN_UNDEF
, // large_common_shndx
1703 0, // small_common_section_flags
1704 0, // large_common_section_flags
1705 NULL
, // attributes_section
1706 NULL
, // attributes_vendor
1707 "_start", // entry_symbol_name
1708 32, // hash_entry_size
1709 elfcpp::SHT_PROGBITS
, // unwind_section_type
1713 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1716 false, // is_big_endian
1717 elfcpp::EM_PPC64
, // machine_code
1718 false, // has_make_symbol
1719 true, // has_resolve
1720 false, // has_code_fill
1721 false, // is_default_stack_executable
1722 false, // can_icf_inline_merge_sections
1724 "/usr/lib/ld.so.1", // dynamic_linker
1725 0x10000000, // default_text_segment_address
1726 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1727 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1728 false, // isolate_execinstr
1730 elfcpp::SHN_UNDEF
, // small_common_shndx
1731 elfcpp::SHN_UNDEF
, // large_common_shndx
1732 0, // small_common_section_flags
1733 0, // large_common_section_flags
1734 NULL
, // attributes_section
1735 NULL
, // attributes_vendor
1736 "_start", // entry_symbol_name
1737 32, // hash_entry_size
1738 elfcpp::SHT_PROGBITS
, // unwind_section_type
1742 is_branch_reloc(unsigned int r_type
)
1744 return (r_type
== elfcpp::R_POWERPC_REL24
1745 || r_type
== elfcpp::R_PPC_PLTREL24
1746 || r_type
== elfcpp::R_PPC_LOCAL24PC
1747 || r_type
== elfcpp::R_POWERPC_REL14
1748 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1749 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1750 || r_type
== elfcpp::R_POWERPC_ADDR24
1751 || r_type
== elfcpp::R_POWERPC_ADDR14
1752 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1753 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1756 // Reloc resolves to plt entry.
1759 is_plt16_reloc(unsigned int r_type
)
1761 return (r_type
== elfcpp::R_POWERPC_PLT16_LO
1762 || r_type
== elfcpp::R_POWERPC_PLT16_HI
1763 || r_type
== elfcpp::R_POWERPC_PLT16_HA
1764 || (size
== 64 && r_type
== elfcpp::R_PPC64_PLT16_LO_DS
));
1767 // If INSN is an opcode that may be used with an @tls operand, return
1768 // the transformed insn for TLS optimisation, otherwise return 0. If
1769 // REG is non-zero only match an insn with RB or RA equal to REG.
1771 at_tls_transform(uint32_t insn
, unsigned int reg
)
1773 if ((insn
& (0x3f << 26)) != 31 << 26)
1777 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1778 rtra
= insn
& ((1 << 26) - (1 << 16));
1779 else if (((insn
>> 16) & 0x1f) == reg
)
1780 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1784 if ((insn
& (0x3ff << 1)) == 266 << 1)
1787 else if ((insn
& (0x1f << 1)) == 23 << 1
1788 && ((insn
& (0x1f << 6)) < 14 << 6
1789 || ((insn
& (0x1f << 6)) >= 16 << 6
1790 && (insn
& (0x1f << 6)) < 24 << 6)))
1791 // load and store indexed -> dform
1792 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1793 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1794 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1795 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1796 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1798 insn
= (58 << 26) | 2;
1806 template<int size
, bool big_endian
>
1807 class Powerpc_relocate_functions
1827 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1828 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1829 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1831 template<int valsize
>
1833 has_overflow_signed(Address value
)
1835 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1836 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1837 limit
<<= ((valsize
- 1) >> 1);
1838 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1839 return value
+ limit
> (limit
<< 1) - 1;
1842 template<int valsize
>
1844 has_overflow_unsigned(Address value
)
1846 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1847 limit
<<= ((valsize
- 1) >> 1);
1848 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1849 return value
> (limit
<< 1) - 1;
1852 template<int valsize
>
1854 has_overflow_bitfield(Address value
)
1856 return (has_overflow_unsigned
<valsize
>(value
)
1857 && has_overflow_signed
<valsize
>(value
));
1860 template<int valsize
>
1861 static inline Status
1862 overflowed(Address value
, Overflow_check overflow
)
1864 if (overflow
== CHECK_SIGNED
)
1866 if (has_overflow_signed
<valsize
>(value
))
1867 return STATUS_OVERFLOW
;
1869 else if (overflow
== CHECK_UNSIGNED
)
1871 if (has_overflow_unsigned
<valsize
>(value
))
1872 return STATUS_OVERFLOW
;
1874 else if (overflow
== CHECK_BITFIELD
)
1876 if (has_overflow_bitfield
<valsize
>(value
))
1877 return STATUS_OVERFLOW
;
1882 // Do a simple RELA relocation
1883 template<int fieldsize
, int valsize
>
1884 static inline Status
1885 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1887 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1888 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1889 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1890 return overflowed
<valsize
>(value
, overflow
);
1893 template<int fieldsize
, int valsize
>
1894 static inline Status
1895 rela(unsigned char* view
,
1896 unsigned int right_shift
,
1897 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1899 Overflow_check overflow
)
1901 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1902 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1903 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1904 Valtype reloc
= value
>> right_shift
;
1907 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1908 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1911 // Do a simple RELA relocation, unaligned.
1912 template<int fieldsize
, int valsize
>
1913 static inline Status
1914 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1916 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1917 return overflowed
<valsize
>(value
, overflow
);
1920 template<int fieldsize
, int valsize
>
1921 static inline Status
1922 rela_ua(unsigned char* view
,
1923 unsigned int right_shift
,
1924 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1926 Overflow_check overflow
)
1928 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
1930 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
1931 Valtype reloc
= value
>> right_shift
;
1934 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
1935 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1939 // R_PPC64_ADDR64: (Symbol + Addend)
1941 addr64(unsigned char* view
, Address value
)
1942 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
1944 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1946 addr64_u(unsigned char* view
, Address value
)
1947 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
1949 // R_POWERPC_ADDR32: (Symbol + Addend)
1950 static inline Status
1951 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1952 { return This::template rela
<32,32>(view
, value
, overflow
); }
1954 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1955 static inline Status
1956 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1957 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
1959 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1960 static inline Status
1961 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1963 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
1965 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1966 stat
= STATUS_OVERFLOW
;
1970 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1971 static inline Status
1972 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1973 { return This::template rela
<16,16>(view
, value
, overflow
); }
1975 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1976 static inline Status
1977 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1978 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
1980 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1981 static inline Status
1982 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1984 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
1985 if ((value
& 3) != 0)
1986 stat
= STATUS_OVERFLOW
;
1990 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
1991 static inline Status
1992 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
1994 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
1995 if ((value
& 15) != 0)
1996 stat
= STATUS_OVERFLOW
;
2000 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
2002 addr16_hi(unsigned char* view
, Address value
)
2003 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
2005 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
2007 addr16_ha(unsigned char* view
, Address value
)
2008 { This::addr16_hi(view
, value
+ 0x8000); }
2010 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
2012 addr16_hi2(unsigned char* view
, Address value
)
2013 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
2015 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
2017 addr16_ha2(unsigned char* view
, Address value
)
2018 { This::addr16_hi2(view
, value
+ 0x8000); }
2020 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
2022 addr16_hi3(unsigned char* view
, Address value
)
2023 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
2025 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
2027 addr16_ha3(unsigned char* view
, Address value
)
2028 { This::addr16_hi3(view
, value
+ 0x8000); }
2030 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
2031 static inline Status
2032 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
2034 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
2035 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
2036 stat
= STATUS_OVERFLOW
;
2040 // R_POWERPC_REL16DX_HA
2041 static inline Status
2042 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
2044 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
2045 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
2046 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
2048 value
= static_cast<SignedAddress
>(value
) >> 16;
2049 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2050 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
2051 return overflowed
<16>(value
, overflow
);
2055 // Set ABI version for input and output.
2057 template<int size
, bool big_endian
>
2059 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
2061 this->e_flags_
|= ver
;
2062 if (this->abiversion() != 0)
2064 Target_powerpc
<size
, big_endian
>* target
=
2065 static_cast<Target_powerpc
<size
, big_endian
>*>(
2066 parameters
->sized_target
<size
, big_endian
>());
2067 if (target
->abiversion() == 0)
2068 target
->set_abiversion(this->abiversion());
2069 else if (target
->abiversion() != this->abiversion())
2070 gold_error(_("%s: ABI version %d is not compatible "
2071 "with ABI version %d output"),
2072 this->name().c_str(),
2073 this->abiversion(), target
->abiversion());
2078 // Stash away the index of .got2, .opd, .rela.toc, and .toc in a
2079 // relocatable object, if such sections exists.
2081 template<int size
, bool big_endian
>
2083 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
2084 Read_symbols_data
* sd
)
2086 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2087 const unsigned char* namesu
= sd
->section_names
->data();
2088 const char* names
= reinterpret_cast<const char*>(namesu
);
2089 section_size_type names_size
= sd
->section_names_size
;
2090 const unsigned char* s
;
2092 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
2093 size
== 32 ? ".got2" : ".opd",
2094 names
, names_size
, NULL
);
2097 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2098 this->special_
= ndx
;
2101 if (this->abiversion() == 0)
2102 this->set_abiversion(1);
2103 else if (this->abiversion() > 1)
2104 gold_error(_("%s: .opd invalid in abiv%d"),
2105 this->name().c_str(), this->abiversion());
2110 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".rela.toc",
2111 names
, names_size
, NULL
);
2114 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
2115 this->relatoc_
= ndx
;
2116 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2117 this->toc_
= this->adjust_shndx(shdr
.get_sh_info());
2120 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
2123 // Examine .rela.opd to build info about function entry points.
2125 template<int size
, bool big_endian
>
2127 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
2129 const unsigned char* prelocs
,
2130 const unsigned char* plocal_syms
)
2134 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
2135 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
2136 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2137 Address expected_off
= 0;
2138 bool regular
= true;
2139 unsigned int opd_ent_size
= 0;
2141 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
2143 Reltype
reloc(prelocs
);
2144 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
2145 = reloc
.get_r_info();
2146 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
2147 if (r_type
== elfcpp::R_PPC64_ADDR64
)
2149 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
2150 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
2153 if (r_sym
< this->local_symbol_count())
2155 typename
elfcpp::Sym
<size
, big_endian
>
2156 lsym(plocal_syms
+ r_sym
* sym_size
);
2157 shndx
= lsym
.get_st_shndx();
2158 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2159 value
= lsym
.get_st_value();
2162 shndx
= this->symbol_section_and_value(r_sym
, &value
,
2164 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
2165 value
+ reloc
.get_r_addend());
2168 expected_off
= reloc
.get_r_offset();
2169 opd_ent_size
= expected_off
;
2171 else if (expected_off
!= reloc
.get_r_offset())
2173 expected_off
+= opd_ent_size
;
2175 else if (r_type
== elfcpp::R_PPC64_TOC
)
2177 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
2182 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
2183 this->name().c_str(), r_type
);
2187 if (reloc_count
<= 2)
2188 opd_ent_size
= this->section_size(this->opd_shndx());
2189 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
2193 gold_warning(_("%s: .opd is not a regular array of opd entries"),
2194 this->name().c_str());
2200 // Returns true if a code sequence loading the TOC entry at VALUE
2201 // relative to the TOC pointer can be converted into code calculating
2202 // a TOC pointer relative offset.
2203 // If so, the TOC pointer relative offset is stored to VALUE.
2205 template<int size
, bool big_endian
>
2207 Powerpc_relobj
<size
, big_endian
>::make_toc_relative(
2208 Target_powerpc
<size
, big_endian
>* target
,
2214 // With -mcmodel=medium code it is quite possible to have
2215 // toc-relative relocs referring to objects outside the TOC.
2216 // Don't try to look at a non-existent TOC.
2217 if (this->toc_shndx() == 0)
2220 // Convert VALUE back to an address by adding got_base (see below),
2221 // then to an offset in the TOC by subtracting the TOC output
2222 // section address and the TOC output offset. Since this TOC output
2223 // section and the got output section are one and the same, we can
2224 // omit adding and subtracting the output section address.
2225 Address off
= (*value
+ this->toc_base_offset()
2226 - this->output_section_offset(this->toc_shndx()));
2227 // Is this offset in the TOC? -mcmodel=medium code may be using
2228 // TOC relative access to variables outside the TOC. Those of
2229 // course can't be optimized. We also don't try to optimize code
2230 // that is using a different object's TOC.
2231 if (off
>= this->section_size(this->toc_shndx()))
2234 if (this->no_toc_opt(off
))
2237 section_size_type vlen
;
2238 unsigned char* view
= this->get_output_view(this->toc_shndx(), &vlen
);
2239 Address addr
= elfcpp::Swap
<size
, big_endian
>::readval(view
+ off
);
2241 Address got_base
= (target
->got_section()->output_section()->address()
2242 + this->toc_base_offset());
2244 if (addr
+ (uint64_t) 0x80008000 >= (uint64_t) 1 << 32)
2251 // Perform the Sized_relobj_file method, then set up opd info from
2254 template<int size
, bool big_endian
>
2256 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
2258 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
2261 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
2262 p
!= rd
->relocs
.end();
2265 if (p
->data_shndx
== this->opd_shndx())
2267 uint64_t opd_size
= this->section_size(this->opd_shndx());
2268 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
2271 this->init_opd(opd_size
);
2272 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
2273 rd
->local_symbols
->data());
2281 // Read the symbols then set up st_other vector.
2283 template<int size
, bool big_endian
>
2285 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2287 this->base_read_symbols(sd
);
2290 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2291 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2292 const unsigned int loccount
= this->do_local_symbol_count();
2295 this->st_other_
.resize(loccount
);
2296 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2297 off_t locsize
= loccount
* sym_size
;
2298 const unsigned int symtab_shndx
= this->symtab_shndx();
2299 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
2300 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
2301 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
2302 locsize
, true, false);
2304 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
2306 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
2307 unsigned char st_other
= sym
.get_st_other();
2308 this->st_other_
[i
] = st_other
;
2309 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
2311 if (this->abiversion() == 0)
2312 this->set_abiversion(2);
2313 else if (this->abiversion() < 2)
2314 gold_error(_("%s: local symbol %d has invalid st_other"
2315 " for ABI version 1"),
2316 this->name().c_str(), i
);
2323 template<int size
, bool big_endian
>
2325 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
2327 this->e_flags_
|= ver
;
2328 if (this->abiversion() != 0)
2330 Target_powerpc
<size
, big_endian
>* target
=
2331 static_cast<Target_powerpc
<size
, big_endian
>*>(
2332 parameters
->sized_target
<size
, big_endian
>());
2333 if (target
->abiversion() == 0)
2334 target
->set_abiversion(this->abiversion());
2335 else if (target
->abiversion() != this->abiversion())
2336 gold_error(_("%s: ABI version %d is not compatible "
2337 "with ABI version %d output"),
2338 this->name().c_str(),
2339 this->abiversion(), target
->abiversion());
2344 // Call Sized_dynobj::base_read_symbols to read the symbols then
2345 // read .opd from a dynamic object, filling in opd_ent_ vector,
2347 template<int size
, bool big_endian
>
2349 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
2351 this->base_read_symbols(sd
);
2354 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
2355 const unsigned char* const pshdrs
= sd
->section_headers
->data();
2356 const unsigned char* namesu
= sd
->section_names
->data();
2357 const char* names
= reinterpret_cast<const char*>(namesu
);
2358 const unsigned char* s
= NULL
;
2359 const unsigned char* opd
;
2360 section_size_type opd_size
;
2362 // Find and read .opd section.
2365 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
2366 sd
->section_names_size
,
2371 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2372 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2373 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2375 if (this->abiversion() == 0)
2376 this->set_abiversion(1);
2377 else if (this->abiversion() > 1)
2378 gold_error(_("%s: .opd invalid in abiv%d"),
2379 this->name().c_str(), this->abiversion());
2381 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2382 this->opd_address_
= shdr
.get_sh_addr();
2383 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2384 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2390 // Build set of executable sections.
2391 // Using a set is probably overkill. There is likely to be only
2392 // a few executable sections, typically .init, .text and .fini,
2393 // and they are generally grouped together.
2394 typedef std::set
<Sec_info
> Exec_sections
;
2395 Exec_sections exec_sections
;
2397 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2399 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2400 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2401 && ((shdr
.get_sh_flags()
2402 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2403 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2404 && shdr
.get_sh_size() != 0)
2406 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2407 shdr
.get_sh_size(), i
));
2410 if (exec_sections
.empty())
2413 // Look over the OPD entries. This is complicated by the fact
2414 // that some binaries will use two-word entries while others
2415 // will use the standard three-word entries. In most cases
2416 // the third word (the environment pointer for languages like
2417 // Pascal) is unused and will be zero. If the third word is
2418 // used it should not be pointing into executable sections,
2420 this->init_opd(opd_size
);
2421 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2423 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2424 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2425 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2427 // Chances are that this is the third word of an OPD entry.
2429 typename
Exec_sections::const_iterator e
2430 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2431 if (e
!= exec_sections
.begin())
2434 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2436 // We have an address in an executable section.
2437 // VAL ought to be the function entry, set it up.
2438 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2439 // Skip second word of OPD entry, the TOC pointer.
2443 // If we didn't match any executable sections, we likely
2444 // have a non-zero third word in the OPD entry.
2449 // Relocate sections.
2451 template<int size
, bool big_endian
>
2453 Powerpc_relobj
<size
, big_endian
>::do_relocate_sections(
2454 const Symbol_table
* symtab
, const Layout
* layout
,
2455 const unsigned char* pshdrs
, Output_file
* of
,
2456 typename Sized_relobj_file
<size
, big_endian
>::Views
* pviews
)
2458 unsigned int start
= 1;
2460 && this->relatoc_
!= 0
2461 && !parameters
->options().relocatable())
2463 // Relocate .toc first.
2464 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2465 this->relatoc_
, this->relatoc_
);
2466 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2467 1, this->relatoc_
- 1);
2468 start
= this->relatoc_
+ 1;
2470 this->relocate_section_range(symtab
, layout
, pshdrs
, of
, pviews
,
2471 start
, this->shnum() - 1);
2474 // Set up some symbols.
2476 template<int size
, bool big_endian
>
2478 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2479 Symbol_table
* symtab
,
2484 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2485 // undefined when scanning relocs (and thus requires
2486 // non-relative dynamic relocs). The proper value will be
2488 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2489 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2491 Target_powerpc
<size
, big_endian
>* target
=
2492 static_cast<Target_powerpc
<size
, big_endian
>*>(
2493 parameters
->sized_target
<size
, big_endian
>());
2494 Output_data_got_powerpc
<size
, big_endian
>* got
2495 = target
->got_section(symtab
, layout
);
2496 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2497 Symbol_table::PREDEFINED
,
2501 elfcpp::STV_HIDDEN
, 0,
2505 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2506 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2507 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2509 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2511 = layout
->add_output_section_data(".sdata", 0,
2513 | elfcpp::SHF_WRITE
,
2514 sdata
, ORDER_SMALL_DATA
, false);
2515 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2516 Symbol_table::PREDEFINED
,
2517 os
, 32768, 0, elfcpp::STT_OBJECT
,
2518 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2524 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2525 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2526 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2528 Target_powerpc
<size
, big_endian
>* target
=
2529 static_cast<Target_powerpc
<size
, big_endian
>*>(
2530 parameters
->sized_target
<size
, big_endian
>());
2531 Output_data_got_powerpc
<size
, big_endian
>* got
2532 = target
->got_section(symtab
, layout
);
2533 symtab
->define_in_output_data(".TOC.", NULL
,
2534 Symbol_table::PREDEFINED
,
2538 elfcpp::STV_HIDDEN
, 0,
2543 this->tls_get_addr_
= symtab
->lookup("__tls_get_addr");
2544 if (parameters
->options().tls_get_addr_optimize()
2545 && this->tls_get_addr_
!= NULL
2546 && this->tls_get_addr_
->in_reg())
2547 this->tls_get_addr_opt_
= symtab
->lookup("__tls_get_addr_opt");
2548 if (this->tls_get_addr_opt_
!= NULL
)
2550 if (this->tls_get_addr_
->is_undefined()
2551 || this->tls_get_addr_
->is_from_dynobj())
2553 // Make it seem as if references to __tls_get_addr are
2554 // really to __tls_get_addr_opt, so the latter symbol is
2555 // made dynamic, not the former.
2556 this->tls_get_addr_
->clear_in_reg();
2557 this->tls_get_addr_opt_
->set_in_reg();
2559 // We have a non-dynamic definition for __tls_get_addr.
2560 // Make __tls_get_addr_opt the same, if it does not already have
2561 // a non-dynamic definition.
2562 else if (this->tls_get_addr_opt_
->is_undefined()
2563 || this->tls_get_addr_opt_
->is_from_dynobj())
2565 Sized_symbol
<size
>* from
2566 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_
);
2567 Sized_symbol
<size
>* to
2568 = static_cast<Sized_symbol
<size
>*>(this->tls_get_addr_opt_
);
2569 symtab
->clone
<size
>(to
, from
);
2574 // Set up PowerPC target specific relobj.
2576 template<int size
, bool big_endian
>
2578 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2579 const std::string
& name
,
2580 Input_file
* input_file
,
2581 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2583 int et
= ehdr
.get_e_type();
2584 // ET_EXEC files are valid input for --just-symbols/-R,
2585 // and we treat them as relocatable objects.
2586 if (et
== elfcpp::ET_REL
2587 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2589 Powerpc_relobj
<size
, big_endian
>* obj
=
2590 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2594 else if (et
== elfcpp::ET_DYN
)
2596 Powerpc_dynobj
<size
, big_endian
>* obj
=
2597 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2603 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2608 template<int size
, bool big_endian
>
2609 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2612 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2613 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2615 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2616 : Output_data_got
<size
, big_endian
>(),
2617 symtab_(symtab
), layout_(layout
),
2618 header_ent_cnt_(size
== 32 ? 3 : 1),
2619 header_index_(size
== 32 ? 0x2000 : 0)
2622 this->set_addralign(256);
2625 // Override all the Output_data_got methods we use so as to first call
2628 add_global(Symbol
* gsym
, unsigned int got_type
)
2630 this->reserve_ent();
2631 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2635 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2637 this->reserve_ent();
2638 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2642 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2643 { return this->add_global_plt(gsym
, got_type
); }
2646 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2647 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2649 this->reserve_ent();
2650 Output_data_got
<size
, big_endian
>::
2651 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2655 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2656 Output_data_reloc_generic
* rel_dyn
,
2657 unsigned int r_type_1
, unsigned int r_type_2
)
2659 if (gsym
->has_got_offset(got_type
))
2662 this->reserve_ent(2);
2663 Output_data_got
<size
, big_endian
>::
2664 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2668 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2670 this->reserve_ent();
2671 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2676 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2678 this->reserve_ent();
2679 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2684 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2685 { return this->add_local_plt(object
, sym_index
, got_type
); }
2688 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2689 unsigned int got_type
,
2690 Output_data_reloc_generic
* rel_dyn
,
2691 unsigned int r_type
)
2693 if (object
->local_has_got_offset(sym_index
, got_type
))
2696 this->reserve_ent(2);
2697 Output_data_got
<size
, big_endian
>::
2698 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2702 add_constant(Valtype constant
)
2704 this->reserve_ent();
2705 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2709 add_constant_pair(Valtype c1
, Valtype c2
)
2711 this->reserve_ent(2);
2712 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2715 // Offset of _GLOBAL_OFFSET_TABLE_.
2719 return this->got_offset(this->header_index_
);
2722 // Offset of base used to access the GOT/TOC.
2723 // The got/toc pointer reg will be set to this value.
2725 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2728 return this->g_o_t();
2730 return (this->output_section()->address()
2731 + object
->toc_base_offset()
2735 // Ensure our GOT has a header.
2737 set_final_data_size()
2739 if (this->header_ent_cnt_
!= 0)
2740 this->make_header();
2741 Output_data_got
<size
, big_endian
>::set_final_data_size();
2744 // First word of GOT header needs some values that are not
2745 // handled by Output_data_got so poke them in here.
2746 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2748 do_write(Output_file
* of
)
2751 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2752 val
= this->layout_
->dynamic_section()->address();
2754 val
= this->output_section()->address() + 0x8000;
2755 this->replace_constant(this->header_index_
, val
);
2756 Output_data_got
<size
, big_endian
>::do_write(of
);
2761 reserve_ent(unsigned int cnt
= 1)
2763 if (this->header_ent_cnt_
== 0)
2765 if (this->num_entries() + cnt
> this->header_index_
)
2766 this->make_header();
2772 this->header_ent_cnt_
= 0;
2773 this->header_index_
= this->num_entries();
2776 Output_data_got
<size
, big_endian
>::add_constant(0);
2777 Output_data_got
<size
, big_endian
>::add_constant(0);
2778 Output_data_got
<size
, big_endian
>::add_constant(0);
2780 // Define _GLOBAL_OFFSET_TABLE_ at the header
2781 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2784 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2785 sym
->set_value(this->g_o_t());
2788 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2789 Symbol_table::PREDEFINED
,
2790 this, this->g_o_t(), 0,
2793 elfcpp::STV_HIDDEN
, 0,
2797 Output_data_got
<size
, big_endian
>::add_constant(0);
2800 // Stashed pointers.
2801 Symbol_table
* symtab_
;
2805 unsigned int header_ent_cnt_
;
2806 // GOT header index.
2807 unsigned int header_index_
;
2810 // Get the GOT section, creating it if necessary.
2812 template<int size
, bool big_endian
>
2813 Output_data_got_powerpc
<size
, big_endian
>*
2814 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2817 if (this->got_
== NULL
)
2819 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2822 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2824 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2825 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2826 this->got_
, ORDER_DATA
, false);
2832 // Get the dynamic reloc section, creating it if necessary.
2834 template<int size
, bool big_endian
>
2835 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2836 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2838 if (this->rela_dyn_
== NULL
)
2840 gold_assert(layout
!= NULL
);
2841 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2842 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2843 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2844 ORDER_DYNAMIC_RELOCS
, false);
2846 return this->rela_dyn_
;
2849 // Similarly, but for ifunc symbols get the one for ifunc.
2851 template<int size
, bool big_endian
>
2852 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2853 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2858 return this->rela_dyn_section(layout
);
2860 if (this->iplt_
== NULL
)
2861 this->make_iplt_section(symtab
, layout
);
2862 return this->iplt_
->rel_plt();
2868 // Determine the stub group size. The group size is the absolute
2869 // value of the parameter --stub-group-size. If --stub-group-size
2870 // is passed a negative value, we restrict stubs to be always after
2871 // the stubbed branches.
2872 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
2873 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
2874 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
2875 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
2876 owner_(NULL
), output_section_(NULL
)
2880 // Return true iff input section can be handled by current stub
2883 can_add_to_stub_group(Output_section
* o
,
2884 const Output_section::Input_section
* i
,
2887 const Output_section::Input_section
*
2893 { return output_section_
; }
2896 set_output_and_owner(Output_section
* o
,
2897 const Output_section::Input_section
* i
)
2899 this->output_section_
= o
;
2908 // Adding group sections before the stubs.
2909 FINDING_STUB_SECTION
,
2910 // Adding group sections after the stubs.
2914 uint32_t stub_group_size_
;
2915 bool stubs_always_after_branch_
;
2916 bool suppress_size_errors_
;
2917 // True if a stub group can serve multiple output sections.
2920 // Current max size of group. Starts at stub_group_size_ but is
2921 // reduced to stub_group_size_/1024 on seeing a section with
2922 // external conditional branches.
2923 uint32_t group_size_
;
2924 uint64_t group_start_addr_
;
2925 // owner_ and output_section_ specify the section to which stubs are
2926 // attached. The stubs are placed at the end of this section.
2927 const Output_section::Input_section
* owner_
;
2928 Output_section
* output_section_
;
2931 // Return true iff input section can be handled by current stub
2932 // group. Sections are presented to this function in order,
2933 // so the first section is the head of the group.
2936 Stub_control::can_add_to_stub_group(Output_section
* o
,
2937 const Output_section::Input_section
* i
,
2940 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2942 uint64_t start_addr
= o
->address();
2945 // .init and .fini sections are pasted together to form a single
2946 // function. We can't be adding stubs in the middle of the function.
2947 this_size
= o
->data_size();
2950 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2951 this_size
= i
->data_size();
2954 uint64_t end_addr
= start_addr
+ this_size
;
2955 uint32_t group_size
= this->stub_group_size_
;
2957 this->group_size_
= group_size
= group_size
>> 10;
2959 if (this_size
> group_size
&& !this->suppress_size_errors_
)
2960 gold_warning(_("%s:%s exceeds group size"),
2961 i
->relobj()->name().c_str(),
2962 i
->relobj()->section_name(i
->shndx()).c_str());
2964 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
2965 has14
? " 14bit" : "",
2966 i
->relobj()->name().c_str(),
2967 i
->relobj()->section_name(i
->shndx()).c_str(),
2968 (long long) this_size
,
2969 (this->state_
== NO_GROUP
2971 : (long long) end_addr
- this->group_start_addr_
));
2973 if (this->state_
== NO_GROUP
)
2975 // Only here on very first use of Stub_control
2977 this->output_section_
= o
;
2978 this->state_
= FINDING_STUB_SECTION
;
2979 this->group_size_
= group_size
;
2980 this->group_start_addr_
= start_addr
;
2983 else if (!this->multi_os_
&& this->output_section_
!= o
)
2985 else if (this->state_
== HAS_STUB_SECTION
)
2987 // Can we add this section, which is after the stubs, to the
2989 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
2992 else if (this->state_
== FINDING_STUB_SECTION
)
2994 if ((whole_sec
&& this->output_section_
== o
)
2995 || end_addr
- this->group_start_addr_
<= this->group_size_
)
2997 // Stubs are added at the end of "owner_".
2999 this->output_section_
= o
;
3002 // The group before the stubs has reached maximum size.
3003 // Now see about adding sections after the stubs to the
3004 // group. If the current section has a 14-bit branch and
3005 // the group before the stubs exceeds group_size_ (because
3006 // they didn't have 14-bit branches), don't add sections
3007 // after the stubs: The size of stubs for such a large
3008 // group may exceed the reach of a 14-bit branch.
3009 if (!this->stubs_always_after_branch_
3010 && this_size
<= this->group_size_
3011 && start_addr
- this->group_start_addr_
<= this->group_size_
)
3013 gold_debug(DEBUG_TARGET
, "adding after stubs");
3014 this->state_
= HAS_STUB_SECTION
;
3015 this->group_start_addr_
= start_addr
;
3022 gold_debug(DEBUG_TARGET
,
3023 !this->multi_os_
&& this->output_section_
!= o
3024 ? "nope, new output section\n"
3025 : "nope, didn't fit\n");
3027 // The section fails to fit in the current group. Set up a few
3028 // things for the next group. owner_ and output_section_ will be
3029 // set later after we've retrieved those values for the current
3031 this->state_
= FINDING_STUB_SECTION
;
3032 this->group_size_
= group_size
;
3033 this->group_start_addr_
= start_addr
;
3037 // Look over all the input sections, deciding where to place stubs.
3039 template<int size
, bool big_endian
>
3041 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
3043 bool no_size_errors
)
3045 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
3046 parameters
->options().stub_group_multi());
3048 // Group input sections and insert stub table
3049 Stub_table_owner
* table_owner
= NULL
;
3050 std::vector
<Stub_table_owner
*> tables
;
3051 Layout::Section_list section_list
;
3052 layout
->get_executable_sections(§ion_list
);
3053 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
3054 for (Layout::Section_list::iterator o
= section_list
.begin();
3055 o
!= section_list
.end();
3058 typedef Output_section::Input_section_list Input_section_list
;
3059 for (Input_section_list::const_iterator i
3060 = (*o
)->input_sections().begin();
3061 i
!= (*o
)->input_sections().end();
3064 if (i
->is_input_section()
3065 || i
->is_relaxed_input_section())
3067 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3068 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
3069 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
3070 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
3072 table_owner
->output_section
= stub_control
.output_section();
3073 table_owner
->owner
= stub_control
.owner();
3074 stub_control
.set_output_and_owner(*o
, &*i
);
3077 if (table_owner
== NULL
)
3079 table_owner
= new Stub_table_owner
;
3080 tables
.push_back(table_owner
);
3082 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
3086 if (table_owner
!= NULL
)
3088 table_owner
->output_section
= stub_control
.output_section();
3089 table_owner
->owner
= stub_control
.owner();;
3091 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
3095 Stub_table
<size
, big_endian
>* stub_table
;
3097 if ((*t
)->owner
->is_input_section())
3098 stub_table
= new Stub_table
<size
, big_endian
>(this,
3099 (*t
)->output_section
,
3101 this->stub_tables_
.size());
3102 else if ((*t
)->owner
->is_relaxed_input_section())
3103 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
3104 (*t
)->owner
->relaxed_input_section());
3107 this->stub_tables_
.push_back(stub_table
);
3112 static unsigned long
3113 max_branch_delta (unsigned int r_type
)
3115 if (r_type
== elfcpp::R_POWERPC_REL14
3116 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
3117 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
3119 if (r_type
== elfcpp::R_POWERPC_REL24
3120 || r_type
== elfcpp::R_PPC_PLTREL24
3121 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
3126 // Return whether this branch is going via a plt call stub.
3128 template<int size
, bool big_endian
>
3130 Target_powerpc
<size
, big_endian
>::Branch_info::mark_pltcall(
3131 Powerpc_relobj
<size
, big_endian
>* ppc_object
,
3134 Target_powerpc
* target
,
3135 Symbol_table
* symtab
)
3137 if (this->object_
!= ppc_object
3138 || this->shndx_
!= shndx
3139 || this->offset_
!= offset
)
3142 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3143 if (sym
!= NULL
&& sym
->is_forwarder())
3144 sym
= symtab
->resolve_forwards(sym
);
3145 if (target
->replace_tls_get_addr(sym
))
3146 sym
= target
->tls_get_addr_opt();
3147 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3149 ? (gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3150 && !target
->is_elfv2_localentry0(gsym
))
3151 : (this->object_
->local_has_plt_offset(this->r_sym_
)
3152 && !target
->is_elfv2_localentry0(this->object_
, this->r_sym_
)))
3160 // If this branch needs a plt call stub, or a long branch stub, make one.
3162 template<int size
, bool big_endian
>
3164 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
3165 Stub_table
<size
, big_endian
>* stub_table
,
3166 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
3167 Symbol_table
* symtab
) const
3169 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
3170 Target_powerpc
<size
, big_endian
>* target
=
3171 static_cast<Target_powerpc
<size
, big_endian
>*>(
3172 parameters
->sized_target
<size
, big_endian
>());
3173 if (sym
!= NULL
&& sym
->is_forwarder())
3174 sym
= symtab
->resolve_forwards(sym
);
3175 if (target
->replace_tls_get_addr(sym
))
3176 sym
= target
->tls_get_addr_opt();
3177 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
3181 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
3182 : this->object_
->local_has_plt_offset(this->r_sym_
))
3186 && target
->abiversion() >= 2
3187 && !parameters
->options().output_is_position_independent()
3188 && !is_branch_reloc(this->r_type_
))
3189 target
->glink_section()->add_global_entry(gsym
);
3192 if (stub_table
== NULL
3195 && !parameters
->options().output_is_position_independent()
3196 && !is_branch_reloc(this->r_type_
)))
3197 stub_table
= this->object_
->stub_table(this->shndx_
);
3198 if (stub_table
== NULL
)
3200 // This is a ref from a data section to an ifunc symbol,
3201 // or a non-branch reloc for which we always want to use
3202 // one set of stubs for resolving function addresses.
3203 stub_table
= ifunc_stub_table
;
3205 gold_assert(stub_table
!= NULL
);
3206 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3207 if (from
!= invalid_address
)
3208 from
+= (this->object_
->output_section(this->shndx_
)->address()
3211 ok
= stub_table
->add_plt_call_entry(from
,
3212 this->object_
, gsym
,
3213 this->r_type_
, this->addend_
,
3216 ok
= stub_table
->add_plt_call_entry(from
,
3217 this->object_
, this->r_sym_
,
3218 this->r_type_
, this->addend_
,
3224 Address max_branch_offset
= max_branch_delta(this->r_type_
);
3225 if (max_branch_offset
== 0)
3227 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
3228 gold_assert(from
!= invalid_address
);
3229 from
+= (this->object_
->output_section(this->shndx_
)->address()
3234 switch (gsym
->source())
3236 case Symbol::FROM_OBJECT
:
3238 Object
* symobj
= gsym
->object();
3239 if (symobj
->is_dynamic()
3240 || symobj
->pluginobj() != NULL
)
3243 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
3244 if (shndx
== elfcpp::SHN_UNDEF
)
3249 case Symbol::IS_UNDEFINED
:
3255 Symbol_table::Compute_final_value_status status
;
3256 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
3257 if (status
!= Symbol_table::CFVS_OK
)
3260 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
3264 const Symbol_value
<size
>* psymval
3265 = this->object_
->local_symbol(this->r_sym_
);
3266 Symbol_value
<size
> symval
;
3267 if (psymval
->is_section_symbol())
3268 symval
.set_is_section_symbol();
3269 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
3270 typename
ObjType::Compute_final_local_value_status status
3271 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
3273 if (status
!= ObjType::CFLV_OK
3274 || !symval
.has_output_value())
3276 to
= symval
.value(this->object_
, 0);
3278 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
3280 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
3281 to
+= this->addend_
;
3282 if (stub_table
== NULL
)
3283 stub_table
= this->object_
->stub_table(this->shndx_
);
3284 if (size
== 64 && target
->abiversion() < 2)
3286 unsigned int dest_shndx
;
3287 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
3291 Address delta
= to
- from
;
3292 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
3294 if (stub_table
== NULL
)
3296 gold_warning(_("%s:%s: branch in non-executable section,"
3297 " no long branch stub for you"),
3298 this->object_
->name().c_str(),
3299 this->object_
->section_name(this->shndx_
).c_str());
3302 bool save_res
= (size
== 64
3304 && gsym
->source() == Symbol::IN_OUTPUT_DATA
3305 && gsym
->output_data() == target
->savres_section());
3306 ok
= stub_table
->add_long_branch_entry(this->object_
,
3308 from
, to
, save_res
);
3312 gold_debug(DEBUG_TARGET
,
3313 "branch at %s:%s+%#lx\n"
3314 "can't reach stub attached to %s:%s",
3315 this->object_
->name().c_str(),
3316 this->object_
->section_name(this->shndx_
).c_str(),
3317 (unsigned long) this->offset_
,
3318 stub_table
->relobj()->name().c_str(),
3319 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
3324 // Relaxation hook. This is where we do stub generation.
3326 template<int size
, bool big_endian
>
3328 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
3329 const Input_objects
*,
3330 Symbol_table
* symtab
,
3334 unsigned int prev_brlt_size
= 0;
3338 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
3340 && this->abiversion() < 2
3342 && !parameters
->options().user_set_plt_thread_safe())
3344 static const char* const thread_starter
[] =
3348 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
3350 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
3351 "mq_notify", "create_timer",
3356 "GOMP_parallel_start",
3357 "GOMP_parallel_loop_static",
3358 "GOMP_parallel_loop_static_start",
3359 "GOMP_parallel_loop_dynamic",
3360 "GOMP_parallel_loop_dynamic_start",
3361 "GOMP_parallel_loop_guided",
3362 "GOMP_parallel_loop_guided_start",
3363 "GOMP_parallel_loop_runtime",
3364 "GOMP_parallel_loop_runtime_start",
3365 "GOMP_parallel_sections",
3366 "GOMP_parallel_sections_start",
3371 if (parameters
->options().shared())
3375 for (unsigned int i
= 0;
3376 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
3379 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
3380 thread_safe
= (sym
!= NULL
3382 && sym
->in_real_elf());
3388 this->plt_thread_safe_
= thread_safe
;
3393 this->stub_group_size_
= parameters
->options().stub_group_size();
3394 bool no_size_errors
= true;
3395 if (this->stub_group_size_
== 1)
3396 this->stub_group_size_
= 0x1c00000;
3397 else if (this->stub_group_size_
== -1)
3398 this->stub_group_size_
= -0x1e00000;
3400 no_size_errors
= false;
3401 this->group_sections(layout
, task
, no_size_errors
);
3403 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
3405 this->branch_lookup_table_
.clear();
3406 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3407 p
!= this->stub_tables_
.end();
3410 (*p
)->clear_stubs(true);
3412 this->stub_tables_
.clear();
3413 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
3414 gold_info(_("%s: stub group size is too large; retrying with %#x"),
3415 program_name
, this->stub_group_size_
);
3416 this->group_sections(layout
, task
, true);
3419 // We need address of stub tables valid for make_stub.
3420 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3421 p
!= this->stub_tables_
.end();
3424 const Powerpc_relobj
<size
, big_endian
>* object
3425 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
3426 Address off
= object
->get_output_section_offset((*p
)->shndx());
3427 gold_assert(off
!= invalid_address
);
3428 Output_section
* os
= (*p
)->output_section();
3429 (*p
)->set_address_and_size(os
, off
);
3434 // Clear plt call stubs, long branch stubs and branch lookup table.
3435 prev_brlt_size
= this->branch_lookup_table_
.size();
3436 this->branch_lookup_table_
.clear();
3437 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3438 p
!= this->stub_tables_
.end();
3441 (*p
)->clear_stubs(false);
3445 // Build all the stubs.
3446 this->relax_failed_
= false;
3447 Stub_table
<size
, big_endian
>* ifunc_stub_table
3448 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
3449 Stub_table
<size
, big_endian
>* one_stub_table
3450 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
3451 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
3452 b
!= this->branch_info_
.end();
3455 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
3456 && !this->relax_failed_
)
3458 this->relax_failed_
= true;
3459 this->relax_fail_count_
++;
3460 if (this->relax_fail_count_
< 3)
3465 // Did anything change size?
3466 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
3467 bool again
= num_huge_branches
!= prev_brlt_size
;
3468 if (size
== 64 && num_huge_branches
!= 0)
3469 this->make_brlt_section(layout
);
3470 if (size
== 64 && again
)
3471 this->brlt_section_
->set_current_size(num_huge_branches
);
3473 for (typename
Stub_tables::reverse_iterator p
= this->stub_tables_
.rbegin();
3474 p
!= this->stub_tables_
.rend();
3476 (*p
)->remove_eh_frame(layout
);
3478 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3479 p
!= this->stub_tables_
.end();
3481 (*p
)->add_eh_frame(layout
);
3483 typedef Unordered_set
<Output_section
*> Output_sections
;
3484 Output_sections os_need_update
;
3485 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3486 p
!= this->stub_tables_
.end();
3489 if ((*p
)->size_update())
3492 os_need_update
.insert((*p
)->output_section());
3496 // Set output section offsets for all input sections in an output
3497 // section that just changed size. Anything past the stubs will
3499 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3500 p
!= os_need_update
.end();
3503 Output_section
* os
= *p
;
3505 typedef Output_section::Input_section_list Input_section_list
;
3506 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3507 i
!= os
->input_sections().end();
3510 off
= align_address(off
, i
->addralign());
3511 if (i
->is_input_section() || i
->is_relaxed_input_section())
3512 i
->relobj()->set_section_offset(i
->shndx(), off
);
3513 if (i
->is_relaxed_input_section())
3515 Stub_table
<size
, big_endian
>* stub_table
3516 = static_cast<Stub_table
<size
, big_endian
>*>(
3517 i
->relaxed_input_section());
3518 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3519 off
+= stub_table_size
;
3520 // After a few iterations, set current stub table size
3521 // as min size threshold, so later stub tables can only
3524 stub_table
->set_min_size_threshold(stub_table_size
);
3527 off
+= i
->data_size();
3529 // If .branch_lt is part of this output section, then we have
3530 // just done the offset adjustment.
3531 os
->clear_section_offsets_need_adjustment();
3536 && num_huge_branches
!= 0
3537 && parameters
->options().output_is_position_independent())
3539 // Fill in the BRLT relocs.
3540 this->brlt_section_
->reset_brlt_sizes();
3541 for (typename
Branch_lookup_table::const_iterator p
3542 = this->branch_lookup_table_
.begin();
3543 p
!= this->branch_lookup_table_
.end();
3546 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3548 this->brlt_section_
->finalize_brlt_sizes();
3552 && (parameters
->options().user_set_emit_stub_syms()
3553 ? parameters
->options().emit_stub_syms()
3555 || parameters
->options().output_is_position_independent()
3556 || parameters
->options().emit_relocs())))
3558 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3559 p
!= this->stub_tables_
.end();
3561 (*p
)->define_stub_syms(symtab
);
3563 if (this->glink_
!= NULL
)
3565 int stub_size
= this->glink_
->pltresolve_size();
3566 Address value
= -stub_size
;
3572 this->define_local(symtab
, "__glink_PLTresolve",
3573 this->glink_
, value
, stub_size
);
3576 this->define_local(symtab
, "__glink", this->glink_
, 0, 0);
3583 template<int size
, bool big_endian
>
3585 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3586 unsigned char* oview
,
3590 uint64_t address
= plt
->address();
3591 off_t len
= plt
->data_size();
3593 if (plt
== this->glink_
)
3595 // See Output_data_glink::do_write() for glink contents.
3598 gold_assert(parameters
->doing_static_link());
3599 // Static linking may need stubs, to support ifunc and long
3600 // branches. We need to create an output section for
3601 // .eh_frame early in the link process, to have a place to
3602 // attach stub .eh_frame info. We also need to have
3603 // registered a CIE that matches the stub CIE. Both of
3604 // these requirements are satisfied by creating an FDE and
3605 // CIE for .glink, even though static linking will leave
3606 // .glink zero length.
3607 // ??? Hopefully generating an FDE with a zero address range
3608 // won't confuse anything that consumes .eh_frame info.
3610 else if (size
== 64)
3612 // There is one word before __glink_PLTresolve
3616 else if (parameters
->options().output_is_position_independent())
3618 // There are two FDEs for a position independent glink.
3619 // The first covers the branch table, the second
3620 // __glink_PLTresolve at the end of glink.
3621 off_t resolve_size
= this->glink_
->pltresolve_size();
3622 if (oview
[9] == elfcpp::DW_CFA_nop
)
3623 len
-= resolve_size
;
3626 address
+= len
- resolve_size
;
3633 // Must be a stub table.
3634 const Stub_table
<size
, big_endian
>* stub_table
3635 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3636 uint64_t stub_address
= stub_table
->stub_address();
3637 len
-= stub_address
- address
;
3638 address
= stub_address
;
3641 *paddress
= address
;
3645 // A class to handle the PLT data.
3647 template<int size
, bool big_endian
>
3648 class Output_data_plt_powerpc
: public Output_section_data_build
3651 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3652 size
, big_endian
> Reloc_section
;
3654 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3655 Reloc_section
* plt_rel
,
3657 : Output_section_data_build(size
== 32 ? 4 : 8),
3663 // Add an entry to the PLT.
3668 add_ifunc_entry(Symbol
*);
3671 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3673 // Return the .rela.plt section data.
3680 // Return the number of PLT entries.
3684 if (this->current_data_size() == 0)
3686 return ((this->current_data_size() - this->first_plt_entry_offset())
3687 / this->plt_entry_size());
3692 do_adjust_output_section(Output_section
* os
)
3697 // Write to a map file.
3699 do_print_to_mapfile(Mapfile
* mapfile
) const
3700 { mapfile
->print_output_data(this, this->name_
); }
3703 // Return the offset of the first non-reserved PLT entry.
3705 first_plt_entry_offset() const
3707 // IPLT has no reserved entry.
3708 if (this->name_
[3] == 'I')
3710 return this->targ_
->first_plt_entry_offset();
3713 // Return the size of each PLT entry.
3715 plt_entry_size() const
3717 return this->targ_
->plt_entry_size();
3720 // Write out the PLT data.
3722 do_write(Output_file
*);
3724 // The reloc section.
3725 Reloc_section
* rel_
;
3726 // Allows access to .glink for do_write.
3727 Target_powerpc
<size
, big_endian
>* targ_
;
3728 // What to report in map file.
3732 // Add an entry to the PLT.
3734 template<int size
, bool big_endian
>
3736 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3738 if (!gsym
->has_plt_offset())
3740 section_size_type off
= this->current_data_size();
3742 off
+= this->first_plt_entry_offset();
3743 gsym
->set_plt_offset(off
);
3744 gsym
->set_needs_dynsym_entry();
3745 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3746 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3747 off
+= this->plt_entry_size();
3748 this->set_current_data_size(off
);
3752 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3754 template<int size
, bool big_endian
>
3756 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3758 if (!gsym
->has_plt_offset())
3760 section_size_type off
= this->current_data_size();
3761 gsym
->set_plt_offset(off
);
3762 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3763 if (size
== 64 && this->targ_
->abiversion() < 2)
3764 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3765 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3766 off
+= this->plt_entry_size();
3767 this->set_current_data_size(off
);
3771 // Add an entry for a local ifunc symbol to the IPLT.
3773 template<int size
, bool big_endian
>
3775 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3776 Sized_relobj_file
<size
, big_endian
>* relobj
,
3777 unsigned int local_sym_index
)
3779 if (!relobj
->local_has_plt_offset(local_sym_index
))
3781 section_size_type off
= this->current_data_size();
3782 relobj
->set_local_plt_offset(local_sym_index
, off
);
3783 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3784 if (size
== 64 && this->targ_
->abiversion() < 2)
3785 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3786 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3788 off
+= this->plt_entry_size();
3789 this->set_current_data_size(off
);
3793 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3794 static const uint32_t add_2_2_11
= 0x7c425a14;
3795 static const uint32_t add_2_2_12
= 0x7c426214;
3796 static const uint32_t add_3_3_2
= 0x7c631214;
3797 static const uint32_t add_3_3_13
= 0x7c636a14;
3798 static const uint32_t add_3_12_2
= 0x7c6c1214;
3799 static const uint32_t add_3_12_13
= 0x7c6c6a14;
3800 static const uint32_t add_11_0_11
= 0x7d605a14;
3801 static const uint32_t add_11_2_11
= 0x7d625a14;
3802 static const uint32_t add_11_11_2
= 0x7d6b1214;
3803 static const uint32_t addi_0_12
= 0x380c0000;
3804 static const uint32_t addi_2_2
= 0x38420000;
3805 static const uint32_t addi_3_3
= 0x38630000;
3806 static const uint32_t addi_11_11
= 0x396b0000;
3807 static const uint32_t addi_12_1
= 0x39810000;
3808 static const uint32_t addi_12_12
= 0x398c0000;
3809 static const uint32_t addis_0_2
= 0x3c020000;
3810 static const uint32_t addis_0_13
= 0x3c0d0000;
3811 static const uint32_t addis_2_12
= 0x3c4c0000;
3812 static const uint32_t addis_11_2
= 0x3d620000;
3813 static const uint32_t addis_11_11
= 0x3d6b0000;
3814 static const uint32_t addis_11_30
= 0x3d7e0000;
3815 static const uint32_t addis_12_1
= 0x3d810000;
3816 static const uint32_t addis_12_2
= 0x3d820000;
3817 static const uint32_t addis_12_12
= 0x3d8c0000;
3818 static const uint32_t b
= 0x48000000;
3819 static const uint32_t bcl_20_31
= 0x429f0005;
3820 static const uint32_t bctr
= 0x4e800420;
3821 static const uint32_t bctrl
= 0x4e800421;
3822 static const uint32_t beqlr
= 0x4d820020;
3823 static const uint32_t blr
= 0x4e800020;
3824 static const uint32_t bnectr_p4
= 0x4ce20420;
3825 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
3826 static const uint32_t cmpldi_2_0
= 0x28220000;
3827 static const uint32_t cmpdi_11_0
= 0x2c2b0000;
3828 static const uint32_t cmpwi_11_0
= 0x2c0b0000;
3829 static const uint32_t cror_15_15_15
= 0x4def7b82;
3830 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3831 static const uint32_t ld_0_1
= 0xe8010000;
3832 static const uint32_t ld_0_12
= 0xe80c0000;
3833 static const uint32_t ld_2_1
= 0xe8410000;
3834 static const uint32_t ld_2_2
= 0xe8420000;
3835 static const uint32_t ld_2_11
= 0xe84b0000;
3836 static const uint32_t ld_2_12
= 0xe84c0000;
3837 static const uint32_t ld_11_1
= 0xe9610000;
3838 static const uint32_t ld_11_2
= 0xe9620000;
3839 static const uint32_t ld_11_3
= 0xe9630000;
3840 static const uint32_t ld_11_11
= 0xe96b0000;
3841 static const uint32_t ld_12_2
= 0xe9820000;
3842 static const uint32_t ld_12_3
= 0xe9830000;
3843 static const uint32_t ld_12_11
= 0xe98b0000;
3844 static const uint32_t ld_12_12
= 0xe98c0000;
3845 static const uint32_t lfd_0_1
= 0xc8010000;
3846 static const uint32_t li_0_0
= 0x38000000;
3847 static const uint32_t li_12_0
= 0x39800000;
3848 static const uint32_t lis_0
= 0x3c000000;
3849 static const uint32_t lis_2
= 0x3c400000;
3850 static const uint32_t lis_11
= 0x3d600000;
3851 static const uint32_t lis_12
= 0x3d800000;
3852 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3853 static const uint32_t lwz_0_12
= 0x800c0000;
3854 static const uint32_t lwz_11_3
= 0x81630000;
3855 static const uint32_t lwz_11_11
= 0x816b0000;
3856 static const uint32_t lwz_11_30
= 0x817e0000;
3857 static const uint32_t lwz_12_3
= 0x81830000;
3858 static const uint32_t lwz_12_12
= 0x818c0000;
3859 static const uint32_t lwzu_0_12
= 0x840c0000;
3860 static const uint32_t mflr_0
= 0x7c0802a6;
3861 static const uint32_t mflr_11
= 0x7d6802a6;
3862 static const uint32_t mflr_12
= 0x7d8802a6;
3863 static const uint32_t mr_0_3
= 0x7c601b78;
3864 static const uint32_t mr_3_0
= 0x7c030378;
3865 static const uint32_t mtctr_0
= 0x7c0903a6;
3866 static const uint32_t mtctr_11
= 0x7d6903a6;
3867 static const uint32_t mtctr_12
= 0x7d8903a6;
3868 static const uint32_t mtlr_0
= 0x7c0803a6;
3869 static const uint32_t mtlr_11
= 0x7d6803a6;
3870 static const uint32_t mtlr_12
= 0x7d8803a6;
3871 static const uint32_t nop
= 0x60000000;
3872 static const uint32_t ori_0_0_0
= 0x60000000;
3873 static const uint32_t srdi_0_0_2
= 0x7800f082;
3874 static const uint32_t std_0_1
= 0xf8010000;
3875 static const uint32_t std_0_12
= 0xf80c0000;
3876 static const uint32_t std_2_1
= 0xf8410000;
3877 static const uint32_t std_11_1
= 0xf9610000;
3878 static const uint32_t stfd_0_1
= 0xd8010000;
3879 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3880 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3881 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3882 static const uint32_t xor_2_12_12
= 0x7d826278;
3883 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3885 // Write out the PLT.
3887 template<int size
, bool big_endian
>
3889 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3891 if (size
== 32 && this->name_
[3] != 'I')
3893 const section_size_type offset
= this->offset();
3894 const section_size_type oview_size
3895 = convert_to_section_size_type(this->data_size());
3896 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3897 unsigned char* pov
= oview
;
3898 unsigned char* endpov
= oview
+ oview_size
;
3900 // The address of the .glink branch table
3901 const Output_data_glink
<size
, big_endian
>* glink
3902 = this->targ_
->glink_section();
3903 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3905 while (pov
< endpov
)
3907 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3912 of
->write_output_view(offset
, oview_size
, oview
);
3916 // Create the PLT section.
3918 template<int size
, bool big_endian
>
3920 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3923 if (this->plt_
== NULL
)
3925 if (this->got_
== NULL
)
3926 this->got_section(symtab
, layout
);
3928 if (this->glink_
== NULL
)
3929 make_glink_section(layout
);
3931 // Ensure that .rela.dyn always appears before .rela.plt This is
3932 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3933 // needs to include .rela.plt in its range.
3934 this->rela_dyn_section(layout
);
3936 Reloc_section
* plt_rel
= new Reloc_section(false);
3937 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3938 elfcpp::SHF_ALLOC
, plt_rel
,
3939 ORDER_DYNAMIC_PLT_RELOCS
, false);
3941 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3943 layout
->add_output_section_data(".plt",
3945 ? elfcpp::SHT_PROGBITS
3946 : elfcpp::SHT_NOBITS
),
3947 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3954 Output_section
* rela_plt_os
= plt_rel
->output_section();
3955 rela_plt_os
->set_info_section(this->plt_
->output_section());
3959 // Create the IPLT section.
3961 template<int size
, bool big_endian
>
3963 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3966 if (this->iplt_
== NULL
)
3968 this->make_plt_section(symtab
, layout
);
3970 Reloc_section
* iplt_rel
= new Reloc_section(false);
3971 if (this->rela_dyn_
->output_section())
3972 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3974 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3976 if (this->plt_
->output_section())
3977 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3981 // A section for huge long branch addresses, similar to plt section.
3983 template<int size
, bool big_endian
>
3984 class Output_data_brlt_powerpc
: public Output_section_data_build
3987 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3988 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3989 size
, big_endian
> Reloc_section
;
3991 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3992 Reloc_section
* brlt_rel
)
3993 : Output_section_data_build(size
== 32 ? 4 : 8),
4001 this->reset_data_size();
4002 this->rel_
->reset_data_size();
4006 finalize_brlt_sizes()
4008 this->finalize_data_size();
4009 this->rel_
->finalize_data_size();
4012 // Add a reloc for an entry in the BRLT.
4014 add_reloc(Address to
, unsigned int off
)
4015 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
4017 // Update section and reloc section size.
4019 set_current_size(unsigned int num_branches
)
4021 this->reset_address_and_file_offset();
4022 this->set_current_data_size(num_branches
* 16);
4023 this->finalize_data_size();
4024 Output_section
* os
= this->output_section();
4025 os
->set_section_offsets_need_adjustment();
4026 if (this->rel_
!= NULL
)
4028 const unsigned int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
4029 this->rel_
->reset_address_and_file_offset();
4030 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
4031 this->rel_
->finalize_data_size();
4032 Output_section
* os
= this->rel_
->output_section();
4033 os
->set_section_offsets_need_adjustment();
4039 do_adjust_output_section(Output_section
* os
)
4044 // Write to a map file.
4046 do_print_to_mapfile(Mapfile
* mapfile
) const
4047 { mapfile
->print_output_data(this, "** BRLT"); }
4050 // Write out the BRLT data.
4052 do_write(Output_file
*);
4054 // The reloc section.
4055 Reloc_section
* rel_
;
4056 Target_powerpc
<size
, big_endian
>* targ_
;
4059 // Make the branch lookup table section.
4061 template<int size
, bool big_endian
>
4063 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
4065 if (size
== 64 && this->brlt_section_
== NULL
)
4067 Reloc_section
* brlt_rel
= NULL
;
4068 bool is_pic
= parameters
->options().output_is_position_independent();
4071 // When PIC we can't fill in .branch_lt but must initialise at
4072 // runtime via dynamic relocations.
4073 this->rela_dyn_section(layout
);
4074 brlt_rel
= new Reloc_section(false);
4075 if (this->rela_dyn_
->output_section())
4076 this->rela_dyn_
->output_section()
4077 ->add_output_section_data(brlt_rel
);
4080 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
4081 if (this->plt_
&& is_pic
&& this->plt_
->output_section())
4082 this->plt_
->output_section()
4083 ->add_output_section_data(this->brlt_section_
);
4085 layout
->add_output_section_data(".branch_lt",
4086 elfcpp::SHT_PROGBITS
,
4087 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
4088 this->brlt_section_
,
4094 // Write out .branch_lt when non-PIC.
4096 template<int size
, bool big_endian
>
4098 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
4100 if (size
== 64 && !parameters
->options().output_is_position_independent())
4102 const section_size_type offset
= this->offset();
4103 const section_size_type oview_size
4104 = convert_to_section_size_type(this->data_size());
4105 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
4107 this->targ_
->write_branch_lookup_table(oview
);
4108 of
->write_output_view(offset
, oview_size
, oview
);
4112 static inline uint32_t
4118 static inline uint32_t
4124 static inline uint32_t
4127 return hi(a
+ 0x8000);
4133 static const unsigned char eh_frame_cie
[12];
4137 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
4140 'z', 'R', 0, // Augmentation string.
4141 4, // Code alignment.
4142 0x80 - size
/ 8 , // Data alignment.
4144 1, // Augmentation size.
4145 (elfcpp::DW_EH_PE_pcrel
4146 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
4147 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
4150 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
4151 static const unsigned char glink_eh_frame_fde_64v1
[] =
4153 0, 0, 0, 0, // Replaced with offset to .glink.
4154 0, 0, 0, 0, // Replaced with size of .glink.
4155 0, // Augmentation size.
4156 elfcpp::DW_CFA_advance_loc
+ 1,
4157 elfcpp::DW_CFA_register
, 65, 12,
4158 elfcpp::DW_CFA_advance_loc
+ 5,
4159 elfcpp::DW_CFA_restore_extended
, 65
4162 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
4163 static const unsigned char glink_eh_frame_fde_64v2
[] =
4165 0, 0, 0, 0, // Replaced with offset to .glink.
4166 0, 0, 0, 0, // Replaced with size of .glink.
4167 0, // Augmentation size.
4168 elfcpp::DW_CFA_advance_loc
+ 1,
4169 elfcpp::DW_CFA_register
, 65, 0,
4170 elfcpp::DW_CFA_advance_loc
+ 7,
4171 elfcpp::DW_CFA_restore_extended
, 65
4174 // Describe __glink_PLTresolve use of LR, 32-bit version.
4175 static const unsigned char glink_eh_frame_fde_32
[] =
4177 0, 0, 0, 0, // Replaced with offset to .glink.
4178 0, 0, 0, 0, // Replaced with size of .glink.
4179 0, // Augmentation size.
4180 elfcpp::DW_CFA_advance_loc
+ 2,
4181 elfcpp::DW_CFA_register
, 65, 0,
4182 elfcpp::DW_CFA_advance_loc
+ 4,
4183 elfcpp::DW_CFA_restore_extended
, 65
4186 static const unsigned char default_fde
[] =
4188 0, 0, 0, 0, // Replaced with offset to stubs.
4189 0, 0, 0, 0, // Replaced with size of stubs.
4190 0, // Augmentation size.
4191 elfcpp::DW_CFA_nop
, // Pad.
4196 template<bool big_endian
>
4198 write_insn(unsigned char* p
, uint32_t v
)
4200 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
4204 static inline unsigned int
4207 if (!parameters
->options().user_set_plt_align())
4208 return size
== 64 ? 32 : 8;
4209 return 1 << parameters
->options().plt_align();
4212 // Stub_table holds information about plt and long branch stubs.
4213 // Stubs are built in an area following some input section determined
4214 // by group_sections(). This input section is converted to a relaxed
4215 // input section allowing it to be resized to accommodate the stubs
4217 template<int size
, bool big_endian
>
4218 class Stub_table
: public Output_relaxed_input_section
4223 Plt_stub_ent(unsigned int off
, unsigned int indx
)
4224 : off_(off
), indx_(indx
), r2save_(0), localentry0_(0)
4228 unsigned int indx_
: 30;
4229 unsigned int r2save_
: 1;
4230 unsigned int localentry0_
: 1;
4232 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4233 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4235 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
4236 Output_section
* output_section
,
4237 const Output_section::Input_section
* owner
,
4239 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
4241 ->section_addralign(owner
->shndx())),
4242 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
4243 orig_data_size_(owner
->current_data_size()),
4244 plt_size_(0), last_plt_size_(0),
4245 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
4246 need_save_res_(false), uniq_(id
), tls_get_addr_opt_bctrl_(-1u),
4249 this->set_output_section(output_section
);
4251 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
4252 new_relaxed
.push_back(this);
4253 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
4256 // Add a plt call stub.
4258 add_plt_call_entry(Address
,
4259 const Sized_relobj_file
<size
, big_endian
>*,
4266 add_plt_call_entry(Address
,
4267 const Sized_relobj_file
<size
, big_endian
>*,
4273 // Find a given plt call stub.
4275 find_plt_call_entry(const Symbol
*) const;
4278 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4279 unsigned int) const;
4282 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4288 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
4293 // Add a long branch stub.
4295 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4296 unsigned int, Address
, Address
, bool);
4299 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
4303 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
4305 Address max_branch_offset
= max_branch_delta(r_type
);
4306 if (max_branch_offset
== 0)
4308 gold_assert(from
!= invalid_address
);
4309 Address loc
= off
+ this->stub_address();
4310 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
4314 clear_stubs(bool all
)
4316 this->plt_call_stubs_
.clear();
4317 this->plt_size_
= 0;
4318 this->long_branch_stubs_
.clear();
4319 this->branch_size_
= 0;
4320 this->need_save_res_
= false;
4323 this->last_plt_size_
= 0;
4324 this->last_branch_size_
= 0;
4329 set_address_and_size(const Output_section
* os
, Address off
)
4331 Address start_off
= off
;
4332 off
+= this->orig_data_size_
;
4333 Address my_size
= this->plt_size_
+ this->branch_size_
;
4334 if (this->need_save_res_
)
4335 my_size
+= this->targ_
->savres_section()->data_size();
4337 off
= align_address(off
, this->stub_align());
4338 // Include original section size and alignment padding in size
4339 my_size
+= off
- start_off
;
4340 // Ensure new size is always larger than min size
4341 // threshold. Alignment requirement is included in "my_size", so
4342 // increase "my_size" does not invalidate alignment.
4343 if (my_size
< this->min_size_threshold_
)
4344 my_size
= this->min_size_threshold_
;
4345 this->reset_address_and_file_offset();
4346 this->set_current_data_size(my_size
);
4347 this->set_address_and_file_offset(os
->address() + start_off
,
4348 os
->offset() + start_off
);
4353 stub_address() const
4355 return align_address(this->address() + this->orig_data_size_
,
4356 this->stub_align());
4362 return align_address(this->offset() + this->orig_data_size_
,
4363 this->stub_align());
4368 { return this->plt_size_
; }
4371 set_min_size_threshold(Address min_size
)
4372 { this->min_size_threshold_
= min_size
; }
4375 define_stub_syms(Symbol_table
*);
4380 Output_section
* os
= this->output_section();
4381 if (os
->addralign() < this->stub_align())
4383 os
->set_addralign(this->stub_align());
4384 // FIXME: get rid of the insane checkpointing.
4385 // We can't increase alignment of the input section to which
4386 // stubs are attached; The input section may be .init which
4387 // is pasted together with other .init sections to form a
4388 // function. Aligning might insert zero padding resulting in
4389 // sigill. However we do need to increase alignment of the
4390 // output section so that the align_address() on offset in
4391 // set_address_and_size() adds the same padding as the
4392 // align_address() on address in stub_address().
4393 // What's more, we need this alignment for the layout done in
4394 // relaxation_loop_body() so that the output section starts at
4395 // a suitably aligned address.
4396 os
->checkpoint_set_addralign(this->stub_align());
4398 if (this->last_plt_size_
!= this->plt_size_
4399 || this->last_branch_size_
!= this->branch_size_
)
4401 this->last_plt_size_
= this->plt_size_
;
4402 this->last_branch_size_
= this->branch_size_
;
4408 // Generate a suitable FDE to describe code in this stub group.
4412 // Add .eh_frame info for this stub section.
4414 add_eh_frame(Layout
* layout
);
4416 // Remove .eh_frame info for this stub section.
4418 remove_eh_frame(Layout
* layout
);
4420 Target_powerpc
<size
, big_endian
>*
4426 class Plt_stub_key_hash
;
4427 typedef Unordered_map
<Plt_stub_key
, Plt_stub_ent
,
4428 Plt_stub_key_hash
> Plt_stub_entries
;
4429 class Branch_stub_ent
;
4430 class Branch_stub_ent_hash
;
4431 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
4432 Branch_stub_ent_hash
> Branch_stub_entries
;
4434 // Alignment of stub section.
4438 unsigned int min_align
= size
== 64 ? 32 : 16;
4439 unsigned int user_align
= 1 << parameters
->options().plt_align();
4440 return std::max(user_align
, min_align
);
4443 // Return the plt offset for the given call stub.
4445 plt_off(typename
Plt_stub_entries::const_iterator p
,
4446 const Output_data_plt_powerpc
<size
, big_endian
>** sec
) const
4448 const Symbol
* gsym
= p
->first
.sym_
;
4450 return this->targ_
->plt_off(gsym
, sec
);
4453 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
4454 unsigned int local_sym_index
= p
->first
.locsym_
;
4455 return this->targ_
->plt_off(relobj
, local_sym_index
, sec
);
4459 // Size of a given plt call stub.
4461 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
4465 const Symbol
* gsym
= p
->first
.sym_
;
4467 + (this->targ_
->is_tls_get_addr_opt(gsym
) ? 8 * 4 : 0));
4470 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
4471 Address plt_addr
= this->plt_off(p
, &plt
);
4472 plt_addr
+= plt
->address();
4473 Address got_addr
= this->targ_
->got_section()->output_section()->address();
4474 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4475 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
4476 got_addr
+= ppcobj
->toc_base_offset();
4477 Address off
= plt_addr
- got_addr
;
4478 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
4479 const Symbol
* gsym
= p
->first
.sym_
;
4480 if (this->targ_
->is_tls_get_addr_opt(gsym
))
4482 if (this->targ_
->abiversion() < 2)
4484 bool static_chain
= parameters
->options().plt_static_chain();
4485 bool thread_safe
= this->targ_
->plt_thread_safe();
4489 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
4495 plt_call_align(unsigned int bytes
) const
4497 unsigned int align
= param_plt_align
<size
>();
4498 return (bytes
+ align
- 1) & -align
;
4501 // Return long branch stub size.
4503 branch_stub_size(typename
Branch_stub_entries::const_iterator p
)
4505 Address loc
= this->stub_address() + this->last_plt_size_
+ p
->second
;
4506 if (p
->first
.dest_
- loc
+ (1 << 25) < 2 << 25)
4508 unsigned int bytes
= 16;
4509 if (size
== 32 && parameters
->options().output_is_position_independent())
4516 do_write(Output_file
*);
4518 // Plt call stub keys.
4522 Plt_stub_key(const Symbol
* sym
)
4523 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4526 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4527 unsigned int locsym_index
)
4528 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4531 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4533 unsigned int r_type
,
4535 : sym_(sym
), object_(0), addend_(0), locsym_(0)
4538 this->addend_
= addend
;
4539 else if (parameters
->options().output_is_position_independent()
4540 && r_type
== elfcpp::R_PPC_PLTREL24
)
4542 this->addend_
= addend
;
4543 if (this->addend_
>= 32768)
4544 this->object_
= object
;
4548 Plt_stub_key(const Sized_relobj_file
<size
, big_endian
>* object
,
4549 unsigned int locsym_index
,
4550 unsigned int r_type
,
4552 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4555 this->addend_
= addend
;
4556 else if (parameters
->options().output_is_position_independent()
4557 && r_type
== elfcpp::R_PPC_PLTREL24
)
4558 this->addend_
= addend
;
4561 bool operator==(const Plt_stub_key
& that
) const
4563 return (this->sym_
== that
.sym_
4564 && this->object_
== that
.object_
4565 && this->addend_
== that
.addend_
4566 && this->locsym_
== that
.locsym_
);
4570 const Sized_relobj_file
<size
, big_endian
>* object_
;
4571 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4572 unsigned int locsym_
;
4575 class Plt_stub_key_hash
4578 size_t operator()(const Plt_stub_key
& ent
) const
4580 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4581 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
4587 // Long branch stub keys.
4588 class Branch_stub_ent
4591 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
,
4592 Address to
, bool save_res
)
4593 : dest_(to
), toc_base_off_(0), save_res_(save_res
)
4596 toc_base_off_
= obj
->toc_base_offset();
4599 bool operator==(const Branch_stub_ent
& that
) const
4601 return (this->dest_
== that
.dest_
4603 || this->toc_base_off_
== that
.toc_base_off_
));
4607 unsigned int toc_base_off_
;
4611 class Branch_stub_ent_hash
4614 size_t operator()(const Branch_stub_ent
& ent
) const
4615 { return ent
.dest_
^ ent
.toc_base_off_
; }
4618 // In a sane world this would be a global.
4619 Target_powerpc
<size
, big_endian
>* targ_
;
4620 // Map sym/object/addend to stub offset.
4621 Plt_stub_entries plt_call_stubs_
;
4622 // Map destination address to stub offset.
4623 Branch_stub_entries long_branch_stubs_
;
4624 // size of input section
4625 section_size_type orig_data_size_
;
4627 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
4628 // Some rare cases cause (PR/20529) fluctuation in stub table
4629 // size, which leads to an endless relax loop. This is to be fixed
4630 // by, after the first few iterations, allowing only increase of
4631 // stub table size. This variable sets the minimal possible size of
4632 // a stub table, it is zero for the first few iterations, then
4633 // increases monotonically.
4634 Address min_size_threshold_
;
4635 // Set if this stub group needs a copy of out-of-line register
4636 // save/restore functions.
4637 bool need_save_res_
;
4638 // Per stub table unique identifier.
4640 // The bctrl in the __tls_get_addr_opt stub, if present.
4641 unsigned int tls_get_addr_opt_bctrl_
;
4642 // FDE unwind info for this stub group.
4643 unsigned int plt_fde_len_
;
4644 unsigned char plt_fde_
[20];
4647 // Add a plt call stub, if we do not already have one for this
4648 // sym/object/addend combo.
4650 template<int size
, bool big_endian
>
4652 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4654 const Sized_relobj_file
<size
, big_endian
>* object
,
4656 unsigned int r_type
,
4660 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
4661 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
4662 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4663 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
4666 this->plt_size_
= ent
.off_
+ this->plt_call_size(p
.first
);
4668 && this->targ_
->is_elfv2_localentry0(gsym
))
4670 p
.first
->second
.localentry0_
= 1;
4671 this->targ_
->set_has_localentry0();
4673 if (this->targ_
->is_tls_get_addr_opt(gsym
))
4675 this->targ_
->set_has_tls_get_addr_opt();
4676 this->tls_get_addr_opt_bctrl_
= this->plt_size_
- 5 * 4;
4678 this->plt_size_
= this->plt_call_align(this->plt_size_
);
4682 && !p
.first
->second
.localentry0_
)
4683 p
.first
->second
.r2save_
= 1;
4684 return this->can_reach_stub(from
, ent
.off_
, r_type
);
4687 template<int size
, bool big_endian
>
4689 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4691 const Sized_relobj_file
<size
, big_endian
>* object
,
4692 unsigned int locsym_index
,
4693 unsigned int r_type
,
4697 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
4698 Plt_stub_ent
ent(this->plt_size_
, this->plt_call_stubs_
.size());
4699 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4700 = this->plt_call_stubs_
.insert(std::make_pair(key
, ent
));
4703 this->plt_size_
= ent
.off_
+ this->plt_call_size(p
.first
);
4704 this->plt_size_
= this->plt_call_align(this->plt_size_
);
4706 && this->targ_
->is_elfv2_localentry0(object
, locsym_index
))
4708 p
.first
->second
.localentry0_
= 1;
4709 this->targ_
->set_has_localentry0();
4714 && !p
.first
->second
.localentry0_
)
4715 p
.first
->second
.r2save_
= 1;
4716 return this->can_reach_stub(from
, ent
.off_
, r_type
);
4719 // Find a plt call stub.
4721 template<int size
, bool big_endian
>
4722 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
4723 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4724 const Sized_relobj_file
<size
, big_endian
>* object
,
4726 unsigned int r_type
,
4727 Address addend
) const
4729 Plt_stub_key
key(object
, gsym
, r_type
, addend
);
4730 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
4731 if (p
== this->plt_call_stubs_
.end())
4736 template<int size
, bool big_endian
>
4737 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
4738 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
4740 Plt_stub_key
key(gsym
);
4741 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
4742 if (p
== this->plt_call_stubs_
.end())
4747 template<int size
, bool big_endian
>
4748 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
4749 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4750 const Sized_relobj_file
<size
, big_endian
>* object
,
4751 unsigned int locsym_index
,
4752 unsigned int r_type
,
4753 Address addend
) const
4755 Plt_stub_key
key(object
, locsym_index
, r_type
, addend
);
4756 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
4757 if (p
== this->plt_call_stubs_
.end())
4762 template<int size
, bool big_endian
>
4763 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
*
4764 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4765 const Sized_relobj_file
<size
, big_endian
>* object
,
4766 unsigned int locsym_index
) const
4768 Plt_stub_key
key(object
, locsym_index
);
4769 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(key
);
4770 if (p
== this->plt_call_stubs_
.end())
4775 // Add a long branch stub if we don't already have one to given
4778 template<int size
, bool big_endian
>
4780 Stub_table
<size
, big_endian
>::add_long_branch_entry(
4781 const Powerpc_relobj
<size
, big_endian
>* object
,
4782 unsigned int r_type
,
4787 Branch_stub_ent
ent(object
, to
, save_res
);
4788 Address off
= this->branch_size_
;
4789 std::pair
<typename
Branch_stub_entries::iterator
, bool> p
4790 = this->long_branch_stubs_
.insert(std::make_pair(ent
, off
));
4794 this->need_save_res_
= true;
4797 unsigned int stub_size
= this->branch_stub_size(p
.first
);
4798 this->branch_size_
= off
+ stub_size
;
4799 if (size
== 64 && stub_size
!= 4)
4800 this->targ_
->add_branch_lookup_table(to
);
4803 return this->can_reach_stub(from
, off
, r_type
);
4806 // Find long branch stub offset.
4808 template<int size
, bool big_endian
>
4809 typename Stub_table
<size
, big_endian
>::Address
4810 Stub_table
<size
, big_endian
>::find_long_branch_entry(
4811 const Powerpc_relobj
<size
, big_endian
>* object
,
4814 Branch_stub_ent
ent(object
, to
, false);
4815 typename
Branch_stub_entries::const_iterator p
4816 = this->long_branch_stubs_
.find(ent
);
4817 if (p
== this->long_branch_stubs_
.end())
4818 return invalid_address
;
4819 if (p
->first
.save_res_
)
4820 return to
- this->targ_
->savres_section()->address() + this->branch_size_
;
4824 // Generate a suitable FDE to describe code in this stub group.
4825 // The __tls_get_addr_opt call stub needs to describe where it saves
4826 // LR, to support exceptions that might be thrown from __tls_get_addr.
4828 template<int size
, bool big_endian
>
4830 Stub_table
<size
, big_endian
>::init_plt_fde()
4832 unsigned char* p
= this->plt_fde_
;
4833 // offset pcrel sdata4, size udata4, and augmentation size byte.
4836 if (this->tls_get_addr_opt_bctrl_
!= -1u)
4838 unsigned int to_bctrl
= this->tls_get_addr_opt_bctrl_
/ 4;
4840 *p
++ = elfcpp::DW_CFA_advance_loc
+ to_bctrl
;
4841 else if (to_bctrl
< 256)
4843 *p
++ = elfcpp::DW_CFA_advance_loc1
;
4846 else if (to_bctrl
< 65536)
4848 *p
++ = elfcpp::DW_CFA_advance_loc2
;
4849 elfcpp::Swap
<16, big_endian
>::writeval(p
, to_bctrl
);
4854 *p
++ = elfcpp::DW_CFA_advance_loc4
;
4855 elfcpp::Swap
<32, big_endian
>::writeval(p
, to_bctrl
);
4858 *p
++ = elfcpp::DW_CFA_offset_extended_sf
;
4860 *p
++ = -(this->targ_
->stk_linker() / 8) & 0x7f;
4861 *p
++ = elfcpp::DW_CFA_advance_loc
+ 4;
4862 *p
++ = elfcpp::DW_CFA_restore_extended
;
4865 this->plt_fde_len_
= p
- this->plt_fde_
;
4868 // Add .eh_frame info for this stub section. Unlike other linker
4869 // generated .eh_frame this is added late in the link, because we
4870 // only want the .eh_frame info if this particular stub section is
4873 template<int size
, bool big_endian
>
4875 Stub_table
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4877 if (!parameters
->options().ld_generated_unwind_info())
4880 // Since we add stub .eh_frame info late, it must be placed
4881 // after all other linker generated .eh_frame info so that
4882 // merge mapping need not be updated for input sections.
4883 // There is no provision to use a different CIE to that used
4885 if (!this->targ_
->has_glink())
4888 if (this->plt_size_
+ this->branch_size_
+ this->need_save_res_
== 0)
4891 this->init_plt_fde();
4892 layout
->add_eh_frame_for_plt(this,
4893 Eh_cie
<size
>::eh_frame_cie
,
4894 sizeof (Eh_cie
<size
>::eh_frame_cie
),
4895 this->plt_fde_
, this->plt_fde_len_
);
4898 template<int size
, bool big_endian
>
4900 Stub_table
<size
, big_endian
>::remove_eh_frame(Layout
* layout
)
4902 if (this->plt_fde_len_
!= 0)
4904 layout
->remove_eh_frame_for_plt(this,
4905 Eh_cie
<size
>::eh_frame_cie
,
4906 sizeof (Eh_cie
<size
>::eh_frame_cie
),
4907 this->plt_fde_
, this->plt_fde_len_
);
4908 this->plt_fde_len_
= 0;
4912 // A class to handle .glink.
4914 template<int size
, bool big_endian
>
4915 class Output_data_glink
: public Output_section_data
4918 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4919 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4921 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
4922 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
4923 end_branch_table_(), ge_size_(0)
4927 add_eh_frame(Layout
* layout
);
4930 add_global_entry(const Symbol
*);
4933 find_global_entry(const Symbol
*) const;
4936 global_entry_align(unsigned int off
) const
4938 unsigned int align
= param_plt_align
<size
>();
4939 return (off
+ align
- 1) & -align
;
4943 global_entry_off() const
4945 return this->global_entry_align(this->end_branch_table_
);
4949 global_entry_address() const
4951 gold_assert(this->is_data_size_valid());
4952 return this->address() + this->global_entry_off();
4956 pltresolve_size() const
4960 + (this->targ_
->abiversion() < 2 ? 11 * 4 : 14 * 4));
4965 // Write to a map file.
4967 do_print_to_mapfile(Mapfile
* mapfile
) const
4968 { mapfile
->print_output_data(this, _("** glink")); }
4972 set_final_data_size();
4976 do_write(Output_file
*);
4978 // Allows access to .got and .plt for do_write.
4979 Target_powerpc
<size
, big_endian
>* targ_
;
4981 // Map sym to stub offset.
4982 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4983 Global_entry_stub_entries global_entry_stubs_
;
4985 unsigned int end_branch_table_
, ge_size_
;
4988 template<int size
, bool big_endian
>
4990 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4992 if (!parameters
->options().ld_generated_unwind_info())
4997 if (this->targ_
->abiversion() < 2)
4998 layout
->add_eh_frame_for_plt(this,
4999 Eh_cie
<64>::eh_frame_cie
,
5000 sizeof (Eh_cie
<64>::eh_frame_cie
),
5001 glink_eh_frame_fde_64v1
,
5002 sizeof (glink_eh_frame_fde_64v1
));
5004 layout
->add_eh_frame_for_plt(this,
5005 Eh_cie
<64>::eh_frame_cie
,
5006 sizeof (Eh_cie
<64>::eh_frame_cie
),
5007 glink_eh_frame_fde_64v2
,
5008 sizeof (glink_eh_frame_fde_64v2
));
5012 // 32-bit .glink can use the default since the CIE return
5013 // address reg, LR, is valid.
5014 layout
->add_eh_frame_for_plt(this,
5015 Eh_cie
<32>::eh_frame_cie
,
5016 sizeof (Eh_cie
<32>::eh_frame_cie
),
5018 sizeof (default_fde
));
5019 // Except where LR is used in a PIC __glink_PLTresolve.
5020 if (parameters
->options().output_is_position_independent())
5021 layout
->add_eh_frame_for_plt(this,
5022 Eh_cie
<32>::eh_frame_cie
,
5023 sizeof (Eh_cie
<32>::eh_frame_cie
),
5024 glink_eh_frame_fde_32
,
5025 sizeof (glink_eh_frame_fde_32
));
5029 template<int size
, bool big_endian
>
5031 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
5033 unsigned int off
= this->global_entry_align(this->ge_size_
);
5034 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
5035 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, off
));
5037 this->ge_size_
= off
+ 16;
5040 template<int size
, bool big_endian
>
5041 typename Output_data_glink
<size
, big_endian
>::Address
5042 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
5044 typename
Global_entry_stub_entries::const_iterator p
5045 = this->global_entry_stubs_
.find(gsym
);
5046 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
5049 template<int size
, bool big_endian
>
5051 Output_data_glink
<size
, big_endian
>::set_final_data_size()
5053 unsigned int count
= this->targ_
->plt_entry_count();
5054 section_size_type total
= 0;
5060 // space for branch table
5061 total
+= 4 * (count
- 1);
5063 total
+= -total
& 15;
5064 total
+= this->pltresolve_size();
5068 total
+= this->pltresolve_size();
5070 // space for branch table
5072 if (this->targ_
->abiversion() < 2)
5076 total
+= 4 * (count
- 0x8000);
5080 this->end_branch_table_
= total
;
5081 total
= this->global_entry_align(total
);
5082 total
+= this->ge_size_
;
5084 this->set_data_size(total
);
5087 // Define symbols on stubs, identifying the stub.
5089 template<int size
, bool big_endian
>
5091 Stub_table
<size
, big_endian
>::define_stub_syms(Symbol_table
* symtab
)
5093 if (!this->plt_call_stubs_
.empty())
5095 // The key for the plt call stub hash table includes addresses,
5096 // therefore traversal order depends on those addresses, which
5097 // can change between runs if gold is a PIE. Unfortunately the
5098 // output .symtab ordering depends on the order in which symbols
5099 // are added to the linker symtab. We want reproducible output
5100 // so must sort the call stub symbols.
5101 typedef typename
Plt_stub_entries::const_iterator plt_iter
;
5102 std::vector
<plt_iter
> sorted
;
5103 sorted
.resize(this->plt_call_stubs_
.size());
5105 for (plt_iter cs
= this->plt_call_stubs_
.begin();
5106 cs
!= this->plt_call_stubs_
.end();
5108 sorted
[cs
->second
.indx_
] = cs
;
5110 for (unsigned int i
= 0; i
< this->plt_call_stubs_
.size(); ++i
)
5112 plt_iter cs
= sorted
[i
];
5115 if (cs
->first
.addend_
!= 0)
5116 sprintf(add
, "+%x", static_cast<uint32_t>(cs
->first
.addend_
));
5119 if (cs
->first
.object_
)
5121 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5122 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5123 sprintf(obj
, "%x:", ppcobj
->uniq());
5126 const char *symname
;
5127 if (cs
->first
.sym_
== NULL
)
5129 sprintf(localname
, "%x", cs
->first
.locsym_
);
5130 symname
= localname
;
5132 else if (this->targ_
->is_tls_get_addr_opt(cs
->first
.sym_
))
5133 symname
= this->targ_
->tls_get_addr_opt()->name();
5135 symname
= cs
->first
.sym_
->name();
5136 char* name
= new char[8 + 10 + strlen(obj
) + strlen(symname
) + strlen(add
) + 1];
5137 sprintf(name
, "%08x.plt_call.%s%s%s", this->uniq_
, obj
, symname
, add
);
5139 = this->stub_address() - this->address() + cs
->second
.off_
;
5140 unsigned int stub_size
= this->plt_call_align(this->plt_call_size(cs
));
5141 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5145 typedef typename
Branch_stub_entries::const_iterator branch_iter
;
5146 for (branch_iter bs
= this->long_branch_stubs_
.begin();
5147 bs
!= this->long_branch_stubs_
.end();
5150 if (bs
->first
.save_res_
)
5153 char* name
= new char[8 + 13 + 16 + 1];
5154 sprintf(name
, "%08x.long_branch.%llx", this->uniq_
,
5155 static_cast<unsigned long long>(bs
->first
.dest_
));
5156 Address value
= (this->stub_address() - this->address()
5157 + this->plt_size_
+ bs
->second
);
5158 unsigned int stub_size
= this->branch_stub_size(bs
);
5159 this->targ_
->define_local(symtab
, name
, this, value
, stub_size
);
5163 // Write out plt and long branch stub code.
5165 template<int size
, bool big_endian
>
5167 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
5169 if (this->plt_call_stubs_
.empty()
5170 && this->long_branch_stubs_
.empty())
5173 const section_size_type start_off
= this->offset();
5174 const section_size_type off
= this->stub_offset();
5175 const section_size_type oview_size
=
5176 convert_to_section_size_type(this->data_size() - (off
- start_off
));
5177 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5182 const Output_data_got_powerpc
<size
, big_endian
>* got
5183 = this->targ_
->got_section();
5184 Address got_os_addr
= got
->output_section()->address();
5186 if (!this->plt_call_stubs_
.empty())
5188 // Write out plt call stubs.
5189 typename
Plt_stub_entries::const_iterator cs
;
5190 for (cs
= this->plt_call_stubs_
.begin();
5191 cs
!= this->plt_call_stubs_
.end();
5194 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5195 Address pltoff
= this->plt_off(cs
, &plt
);
5196 Address plt_addr
= pltoff
+ plt
->address();
5197 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
5198 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
5199 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
5200 Address off
= plt_addr
- got_addr
;
5202 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
5203 gold_error(_("%s: linkage table error against `%s'"),
5204 cs
->first
.object_
->name().c_str(),
5205 cs
->first
.sym_
->demangled_name().c_str());
5207 bool plt_load_toc
= this->targ_
->abiversion() < 2;
5209 = plt_load_toc
&& parameters
->options().plt_static_chain();
5211 = plt_load_toc
&& this->targ_
->plt_thread_safe();
5212 bool use_fake_dep
= false;
5213 Address cmp_branch_off
= 0;
5216 unsigned int pltindex
5217 = ((pltoff
- this->targ_
->first_plt_entry_offset())
5218 / this->targ_
->plt_entry_size());
5220 = (this->targ_
->glink_section()->pltresolve_size()
5222 if (pltindex
> 32768)
5223 glinkoff
+= (pltindex
- 32768) * 4;
5225 = this->targ_
->glink_section()->address() + glinkoff
;
5227 = (this->stub_address() + cs
->second
.off_
+ 20
5228 + 4 * cs
->second
.r2save_
5229 + 4 * (ha(off
) != 0)
5230 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
5231 + 4 * static_chain
);
5232 cmp_branch_off
= to
- from
;
5233 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
5236 p
= oview
+ cs
->second
.off_
;
5237 const Symbol
* gsym
= cs
->first
.sym_
;
5238 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5240 write_insn
<big_endian
>(p
, ld_11_3
+ 0);
5242 write_insn
<big_endian
>(p
, ld_12_3
+ 8);
5244 write_insn
<big_endian
>(p
, mr_0_3
);
5246 write_insn
<big_endian
>(p
, cmpdi_11_0
);
5248 write_insn
<big_endian
>(p
, add_3_12_13
);
5250 write_insn
<big_endian
>(p
, beqlr
);
5252 write_insn
<big_endian
>(p
, mr_3_0
);
5254 if (!cs
->second
.localentry0_
)
5256 write_insn
<big_endian
>(p
, mflr_11
);
5258 write_insn
<big_endian
>(p
, (std_11_1
5259 + this->targ_
->stk_linker()));
5262 use_fake_dep
= thread_safe
;
5266 if (cs
->second
.r2save_
)
5268 write_insn
<big_endian
>(p
,
5269 std_2_1
+ this->targ_
->stk_toc());
5274 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
5276 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
5281 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
5283 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
5287 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
5289 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
5293 write_insn
<big_endian
>(p
, mtctr_12
);
5299 write_insn
<big_endian
>(p
, xor_2_12_12
);
5301 write_insn
<big_endian
>(p
, add_11_11_2
);
5304 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
5308 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
5315 if (cs
->second
.r2save_
)
5317 write_insn
<big_endian
>(p
,
5318 std_2_1
+ this->targ_
->stk_toc());
5321 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
5324 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
5326 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
5330 write_insn
<big_endian
>(p
, mtctr_12
);
5336 write_insn
<big_endian
>(p
, xor_11_12_12
);
5338 write_insn
<big_endian
>(p
, add_2_2_11
);
5343 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
5346 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
5350 if (!cs
->second
.localentry0_
5351 && this->targ_
->is_tls_get_addr_opt(gsym
))
5353 write_insn
<big_endian
>(p
, bctrl
);
5355 write_insn
<big_endian
>(p
, ld_2_1
+ this->targ_
->stk_toc());
5357 write_insn
<big_endian
>(p
, ld_11_1
+ this->targ_
->stk_linker());
5359 write_insn
<big_endian
>(p
, mtlr_11
);
5361 write_insn
<big_endian
>(p
, blr
);
5363 else if (thread_safe
&& !use_fake_dep
)
5365 write_insn
<big_endian
>(p
, cmpldi_2_0
);
5367 write_insn
<big_endian
>(p
, bnectr_p4
);
5369 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
5372 write_insn
<big_endian
>(p
, bctr
);
5376 // Write out long branch stubs.
5377 typename
Branch_stub_entries::const_iterator bs
;
5378 for (bs
= this->long_branch_stubs_
.begin();
5379 bs
!= this->long_branch_stubs_
.end();
5382 if (bs
->first
.save_res_
)
5384 p
= oview
+ this->plt_size_
+ bs
->second
;
5385 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
5386 Address delta
= bs
->first
.dest_
- loc
;
5387 if (delta
+ (1 << 25) < 2 << 25)
5388 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
5392 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
5393 gold_assert(brlt_addr
!= invalid_address
);
5394 brlt_addr
+= this->targ_
->brlt_section()->address();
5395 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
5396 Address brltoff
= brlt_addr
- got_addr
;
5397 if (ha(brltoff
) == 0)
5399 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
5403 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
5404 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
5406 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
5407 write_insn
<big_endian
>(p
, bctr
);
5413 if (!this->plt_call_stubs_
.empty())
5415 // The address of _GLOBAL_OFFSET_TABLE_.
5416 Address g_o_t
= invalid_address
;
5418 // Write out plt call stubs.
5419 typename
Plt_stub_entries::const_iterator cs
;
5420 for (cs
= this->plt_call_stubs_
.begin();
5421 cs
!= this->plt_call_stubs_
.end();
5424 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
5425 Address plt_addr
= this->plt_off(cs
, &plt
);
5426 plt_addr
+= plt
->address();
5428 p
= oview
+ cs
->second
.off_
;
5429 const Symbol
* gsym
= cs
->first
.sym_
;
5430 if (this->targ_
->is_tls_get_addr_opt(gsym
))
5432 write_insn
<big_endian
>(p
, lwz_11_3
+ 0);
5434 write_insn
<big_endian
>(p
, lwz_12_3
+ 4);
5436 write_insn
<big_endian
>(p
, mr_0_3
);
5438 write_insn
<big_endian
>(p
, cmpwi_11_0
);
5440 write_insn
<big_endian
>(p
, add_3_12_2
);
5442 write_insn
<big_endian
>(p
, beqlr
);
5444 write_insn
<big_endian
>(p
, mr_3_0
);
5446 write_insn
<big_endian
>(p
, nop
);
5449 if (parameters
->options().output_is_position_independent())
5452 const Powerpc_relobj
<size
, big_endian
>* ppcobj
5453 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
5454 (cs
->first
.object_
));
5455 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
5457 unsigned int got2
= ppcobj
->got2_shndx();
5458 got_addr
= ppcobj
->get_output_section_offset(got2
);
5459 gold_assert(got_addr
!= invalid_address
);
5460 got_addr
+= (ppcobj
->output_section(got2
)->address()
5461 + cs
->first
.addend_
);
5465 if (g_o_t
== invalid_address
)
5467 const Output_data_got_powerpc
<size
, big_endian
>* got
5468 = this->targ_
->got_section();
5469 g_o_t
= got
->address() + got
->g_o_t();
5474 Address off
= plt_addr
- got_addr
;
5476 write_insn
<big_endian
>(p
, lwz_11_30
+ l(off
));
5479 write_insn
<big_endian
>(p
, addis_11_30
+ ha(off
));
5481 write_insn
<big_endian
>(p
, lwz_11_11
+ l(off
));
5486 write_insn
<big_endian
>(p
, lis_11
+ ha(plt_addr
));
5488 write_insn
<big_endian
>(p
, lwz_11_11
+ l(plt_addr
));
5491 write_insn
<big_endian
>(p
, mtctr_11
);
5493 write_insn
<big_endian
>(p
, bctr
);
5497 // Write out long branch stubs.
5498 typename
Branch_stub_entries::const_iterator bs
;
5499 for (bs
= this->long_branch_stubs_
.begin();
5500 bs
!= this->long_branch_stubs_
.end();
5503 if (bs
->first
.save_res_
)
5505 p
= oview
+ this->plt_size_
+ bs
->second
;
5506 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
5507 Address delta
= bs
->first
.dest_
- loc
;
5508 if (delta
+ (1 << 25) < 2 << 25)
5509 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
5510 else if (!parameters
->options().output_is_position_independent())
5512 write_insn
<big_endian
>(p
, lis_12
+ ha(bs
->first
.dest_
));
5514 write_insn
<big_endian
>(p
, addi_12_12
+ l(bs
->first
.dest_
));
5519 write_insn
<big_endian
>(p
, mflr_0
);
5521 write_insn
<big_endian
>(p
, bcl_20_31
);
5523 write_insn
<big_endian
>(p
, mflr_12
);
5525 write_insn
<big_endian
>(p
, addis_12_12
+ ha(delta
));
5527 write_insn
<big_endian
>(p
, addi_12_12
+ l(delta
));
5529 write_insn
<big_endian
>(p
, mtlr_0
);
5532 write_insn
<big_endian
>(p
, mtctr_12
);
5534 write_insn
<big_endian
>(p
, bctr
);
5537 if (this->need_save_res_
)
5539 p
= oview
+ this->plt_size_
+ this->branch_size_
;
5540 memcpy (p
, this->targ_
->savres_section()->contents(),
5541 this->targ_
->savres_section()->data_size());
5545 // Write out .glink.
5547 template<int size
, bool big_endian
>
5549 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
5551 const section_size_type off
= this->offset();
5552 const section_size_type oview_size
=
5553 convert_to_section_size_type(this->data_size());
5554 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5557 // The base address of the .plt section.
5558 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
5559 Address plt_base
= this->targ_
->plt_section()->address();
5563 if (this->end_branch_table_
!= 0)
5565 // Write pltresolve stub.
5567 Address after_bcl
= this->address() + 16;
5568 Address pltoff
= plt_base
- after_bcl
;
5570 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
5572 if (this->targ_
->abiversion() < 2)
5574 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
5575 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
5576 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
5577 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
5578 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
5579 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
5580 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
5581 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
5582 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
5583 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
5587 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
5588 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
5589 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
5590 write_insn
<big_endian
>(p
, std_2_1
+ 24), p
+= 4;
5591 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
5592 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
5593 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
5594 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
5595 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
5596 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
5597 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
5598 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
5599 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
5601 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
5602 gold_assert(p
== oview
+ this->pltresolve_size());
5604 // Write lazy link call stubs.
5606 while (p
< oview
+ this->end_branch_table_
)
5608 if (this->targ_
->abiversion() < 2)
5612 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
5616 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
5617 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
5620 uint32_t branch_off
= 8 - (p
- oview
);
5621 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
5626 Address plt_base
= this->targ_
->plt_section()->address();
5627 Address iplt_base
= invalid_address
;
5628 unsigned int global_entry_off
= this->global_entry_off();
5629 Address global_entry_base
= this->address() + global_entry_off
;
5630 typename
Global_entry_stub_entries::const_iterator ge
;
5631 for (ge
= this->global_entry_stubs_
.begin();
5632 ge
!= this->global_entry_stubs_
.end();
5635 p
= oview
+ global_entry_off
+ ge
->second
;
5636 Address plt_addr
= ge
->first
->plt_offset();
5637 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
5638 && ge
->first
->can_use_relative_reloc(false))
5640 if (iplt_base
== invalid_address
)
5641 iplt_base
= this->targ_
->iplt_section()->address();
5642 plt_addr
+= iplt_base
;
5645 plt_addr
+= plt_base
;
5646 Address my_addr
= global_entry_base
+ ge
->second
;
5647 Address off
= plt_addr
- my_addr
;
5649 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
5650 gold_error(_("%s: linkage table error against `%s'"),
5651 ge
->first
->object()->name().c_str(),
5652 ge
->first
->demangled_name().c_str());
5654 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
5655 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
5656 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
5657 write_insn
<big_endian
>(p
, bctr
);
5662 const Output_data_got_powerpc
<size
, big_endian
>* got
5663 = this->targ_
->got_section();
5664 // The address of _GLOBAL_OFFSET_TABLE_.
5665 Address g_o_t
= got
->address() + got
->g_o_t();
5667 // Write out pltresolve branch table.
5669 unsigned int the_end
= oview_size
- this->pltresolve_size();
5670 unsigned char* end_p
= oview
+ the_end
;
5671 while (p
< end_p
- 8 * 4)
5672 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
5674 write_insn
<big_endian
>(p
, nop
), p
+= 4;
5676 // Write out pltresolve call stub.
5677 end_p
= oview
+ oview_size
;
5678 if (parameters
->options().output_is_position_independent())
5680 Address res0_off
= 0;
5681 Address after_bcl_off
= the_end
+ 12;
5682 Address bcl_res0
= after_bcl_off
- res0_off
;
5684 write_insn
<big_endian
>(p
, addis_11_11
+ ha(bcl_res0
));
5686 write_insn
<big_endian
>(p
, mflr_0
);
5688 write_insn
<big_endian
>(p
, bcl_20_31
);
5690 write_insn
<big_endian
>(p
, addi_11_11
+ l(bcl_res0
));
5692 write_insn
<big_endian
>(p
, mflr_12
);
5694 write_insn
<big_endian
>(p
, mtlr_0
);
5696 write_insn
<big_endian
>(p
, sub_11_11_12
);
5699 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
5701 write_insn
<big_endian
>(p
, addis_12_12
+ ha(got_bcl
));
5703 if (ha(got_bcl
) == ha(got_bcl
+ 4))
5705 write_insn
<big_endian
>(p
, lwz_0_12
+ l(got_bcl
));
5707 write_insn
<big_endian
>(p
, lwz_12_12
+ l(got_bcl
+ 4));
5711 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(got_bcl
));
5713 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
5716 write_insn
<big_endian
>(p
, mtctr_0
);
5718 write_insn
<big_endian
>(p
, add_0_11_11
);
5720 write_insn
<big_endian
>(p
, add_11_0_11
);
5724 Address res0
= this->address();
5726 write_insn
<big_endian
>(p
, lis_12
+ ha(g_o_t
+ 4));
5728 write_insn
<big_endian
>(p
, addis_11_11
+ ha(-res0
));
5730 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
5731 write_insn
<big_endian
>(p
, lwz_0_12
+ l(g_o_t
+ 4));
5733 write_insn
<big_endian
>(p
, lwzu_0_12
+ l(g_o_t
+ 4));
5735 write_insn
<big_endian
>(p
, addi_11_11
+ l(-res0
));
5737 write_insn
<big_endian
>(p
, mtctr_0
);
5739 write_insn
<big_endian
>(p
, add_0_11_11
);
5741 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
5742 write_insn
<big_endian
>(p
, lwz_12_12
+ l(g_o_t
+ 8));
5744 write_insn
<big_endian
>(p
, lwz_12_12
+ 4);
5746 write_insn
<big_endian
>(p
, add_11_0_11
);
5749 write_insn
<big_endian
>(p
, bctr
);
5753 write_insn
<big_endian
>(p
, nop
);
5758 of
->write_output_view(off
, oview_size
, oview
);
5762 // A class to handle linker generated save/restore functions.
5764 template<int size
, bool big_endian
>
5765 class Output_data_save_res
: public Output_section_data_build
5768 Output_data_save_res(Symbol_table
* symtab
);
5770 const unsigned char*
5777 // Write to a map file.
5779 do_print_to_mapfile(Mapfile
* mapfile
) const
5780 { mapfile
->print_output_data(this, _("** save/restore")); }
5783 do_write(Output_file
*);
5786 // The maximum size of save/restore contents.
5787 static const unsigned int savres_max
= 218*4;
5790 savres_define(Symbol_table
* symtab
,
5792 unsigned int lo
, unsigned int hi
,
5793 unsigned char* write_ent(unsigned char*, int),
5794 unsigned char* write_tail(unsigned char*, int));
5796 unsigned char *contents_
;
5799 template<bool big_endian
>
5800 static unsigned char*
5801 savegpr0(unsigned char* p
, int r
)
5803 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5804 write_insn
<big_endian
>(p
, insn
);
5808 template<bool big_endian
>
5809 static unsigned char*
5810 savegpr0_tail(unsigned char* p
, int r
)
5812 p
= savegpr0
<big_endian
>(p
, r
);
5813 uint32_t insn
= std_0_1
+ 16;
5814 write_insn
<big_endian
>(p
, insn
);
5816 write_insn
<big_endian
>(p
, blr
);
5820 template<bool big_endian
>
5821 static unsigned char*
5822 restgpr0(unsigned char* p
, int r
)
5824 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5825 write_insn
<big_endian
>(p
, insn
);
5829 template<bool big_endian
>
5830 static unsigned char*
5831 restgpr0_tail(unsigned char* p
, int r
)
5833 uint32_t insn
= ld_0_1
+ 16;
5834 write_insn
<big_endian
>(p
, insn
);
5836 p
= restgpr0
<big_endian
>(p
, r
);
5837 write_insn
<big_endian
>(p
, mtlr_0
);
5841 p
= restgpr0
<big_endian
>(p
, 30);
5842 p
= restgpr0
<big_endian
>(p
, 31);
5844 write_insn
<big_endian
>(p
, blr
);
5848 template<bool big_endian
>
5849 static unsigned char*
5850 savegpr1(unsigned char* p
, int r
)
5852 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5853 write_insn
<big_endian
>(p
, insn
);
5857 template<bool big_endian
>
5858 static unsigned char*
5859 savegpr1_tail(unsigned char* p
, int r
)
5861 p
= savegpr1
<big_endian
>(p
, r
);
5862 write_insn
<big_endian
>(p
, blr
);
5866 template<bool big_endian
>
5867 static unsigned char*
5868 restgpr1(unsigned char* p
, int r
)
5870 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5871 write_insn
<big_endian
>(p
, insn
);
5875 template<bool big_endian
>
5876 static unsigned char*
5877 restgpr1_tail(unsigned char* p
, int r
)
5879 p
= restgpr1
<big_endian
>(p
, r
);
5880 write_insn
<big_endian
>(p
, blr
);
5884 template<bool big_endian
>
5885 static unsigned char*
5886 savefpr(unsigned char* p
, int r
)
5888 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5889 write_insn
<big_endian
>(p
, insn
);
5893 template<bool big_endian
>
5894 static unsigned char*
5895 savefpr0_tail(unsigned char* p
, int r
)
5897 p
= savefpr
<big_endian
>(p
, r
);
5898 write_insn
<big_endian
>(p
, std_0_1
+ 16);
5900 write_insn
<big_endian
>(p
, blr
);
5904 template<bool big_endian
>
5905 static unsigned char*
5906 restfpr(unsigned char* p
, int r
)
5908 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5909 write_insn
<big_endian
>(p
, insn
);
5913 template<bool big_endian
>
5914 static unsigned char*
5915 restfpr0_tail(unsigned char* p
, int r
)
5917 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
5919 p
= restfpr
<big_endian
>(p
, r
);
5920 write_insn
<big_endian
>(p
, mtlr_0
);
5924 p
= restfpr
<big_endian
>(p
, 30);
5925 p
= restfpr
<big_endian
>(p
, 31);
5927 write_insn
<big_endian
>(p
, blr
);
5931 template<bool big_endian
>
5932 static unsigned char*
5933 savefpr1_tail(unsigned char* p
, int r
)
5935 p
= savefpr
<big_endian
>(p
, r
);
5936 write_insn
<big_endian
>(p
, blr
);
5940 template<bool big_endian
>
5941 static unsigned char*
5942 restfpr1_tail(unsigned char* p
, int r
)
5944 p
= restfpr
<big_endian
>(p
, r
);
5945 write_insn
<big_endian
>(p
, blr
);
5949 template<bool big_endian
>
5950 static unsigned char*
5951 savevr(unsigned char* p
, int r
)
5953 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5954 write_insn
<big_endian
>(p
, insn
);
5956 insn
= stvx_0_12_0
+ (r
<< 21);
5957 write_insn
<big_endian
>(p
, insn
);
5961 template<bool big_endian
>
5962 static unsigned char*
5963 savevr_tail(unsigned char* p
, int r
)
5965 p
= savevr
<big_endian
>(p
, r
);
5966 write_insn
<big_endian
>(p
, blr
);
5970 template<bool big_endian
>
5971 static unsigned char*
5972 restvr(unsigned char* p
, int r
)
5974 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5975 write_insn
<big_endian
>(p
, insn
);
5977 insn
= lvx_0_12_0
+ (r
<< 21);
5978 write_insn
<big_endian
>(p
, insn
);
5982 template<bool big_endian
>
5983 static unsigned char*
5984 restvr_tail(unsigned char* p
, int r
)
5986 p
= restvr
<big_endian
>(p
, r
);
5987 write_insn
<big_endian
>(p
, blr
);
5992 template<int size
, bool big_endian
>
5993 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
5994 Symbol_table
* symtab
)
5995 : Output_section_data_build(4),
5998 this->savres_define(symtab
,
5999 "_savegpr0_", 14, 31,
6000 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
6001 this->savres_define(symtab
,
6002 "_restgpr0_", 14, 29,
6003 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6004 this->savres_define(symtab
,
6005 "_restgpr0_", 30, 31,
6006 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
6007 this->savres_define(symtab
,
6008 "_savegpr1_", 14, 31,
6009 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
6010 this->savres_define(symtab
,
6011 "_restgpr1_", 14, 31,
6012 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
6013 this->savres_define(symtab
,
6014 "_savefpr_", 14, 31,
6015 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
6016 this->savres_define(symtab
,
6017 "_restfpr_", 14, 29,
6018 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6019 this->savres_define(symtab
,
6020 "_restfpr_", 30, 31,
6021 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
6022 this->savres_define(symtab
,
6024 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
6025 this->savres_define(symtab
,
6027 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
6028 this->savres_define(symtab
,
6030 savevr
<big_endian
>, savevr_tail
<big_endian
>);
6031 this->savres_define(symtab
,
6033 restvr
<big_endian
>, restvr_tail
<big_endian
>);
6036 template<int size
, bool big_endian
>
6038 Output_data_save_res
<size
, big_endian
>::savres_define(
6039 Symbol_table
* symtab
,
6041 unsigned int lo
, unsigned int hi
,
6042 unsigned char* write_ent(unsigned char*, int),
6043 unsigned char* write_tail(unsigned char*, int))
6045 size_t len
= strlen(name
);
6046 bool writing
= false;
6049 memcpy(sym
, name
, len
);
6052 for (unsigned int i
= lo
; i
<= hi
; i
++)
6054 sym
[len
+ 0] = i
/ 10 + '0';
6055 sym
[len
+ 1] = i
% 10 + '0';
6056 Symbol
* gsym
= symtab
->lookup(sym
);
6057 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
6058 writing
= writing
|| refd
;
6061 if (this->contents_
== NULL
)
6062 this->contents_
= new unsigned char[this->savres_max
];
6064 section_size_type value
= this->current_data_size();
6065 unsigned char* p
= this->contents_
+ value
;
6067 p
= write_ent(p
, i
);
6069 p
= write_tail(p
, i
);
6070 section_size_type cur_size
= p
- this->contents_
;
6071 this->set_current_data_size(cur_size
);
6073 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
6074 this, value
, cur_size
- value
,
6075 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
6076 elfcpp::STV_HIDDEN
, 0, false, false);
6081 // Write out save/restore.
6083 template<int size
, bool big_endian
>
6085 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
6087 const section_size_type off
= this->offset();
6088 const section_size_type oview_size
=
6089 convert_to_section_size_type(this->data_size());
6090 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
6091 memcpy(oview
, this->contents_
, oview_size
);
6092 of
->write_output_view(off
, oview_size
, oview
);
6096 // Create the glink section.
6098 template<int size
, bool big_endian
>
6100 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
6102 if (this->glink_
== NULL
)
6104 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
6105 this->glink_
->add_eh_frame(layout
);
6106 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6107 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6108 this->glink_
, ORDER_TEXT
, false);
6112 // Create a PLT entry for a global symbol.
6114 template<int size
, bool big_endian
>
6116 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
6120 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
6121 && gsym
->can_use_relative_reloc(false))
6123 if (this->iplt_
== NULL
)
6124 this->make_iplt_section(symtab
, layout
);
6125 this->iplt_
->add_ifunc_entry(gsym
);
6129 if (this->plt_
== NULL
)
6130 this->make_plt_section(symtab
, layout
);
6131 this->plt_
->add_entry(gsym
);
6135 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
6137 template<int size
, bool big_endian
>
6139 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
6140 Symbol_table
* symtab
,
6142 Sized_relobj_file
<size
, big_endian
>* relobj
,
6145 if (this->iplt_
== NULL
)
6146 this->make_iplt_section(symtab
, layout
);
6147 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
6150 // Return the number of entries in the PLT.
6152 template<int size
, bool big_endian
>
6154 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
6156 if (this->plt_
== NULL
)
6158 return this->plt_
->entry_count();
6161 // Create a GOT entry for local dynamic __tls_get_addr calls.
6163 template<int size
, bool big_endian
>
6165 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
6166 Symbol_table
* symtab
,
6168 Sized_relobj_file
<size
, big_endian
>* object
)
6170 if (this->tlsld_got_offset_
== -1U)
6172 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
6173 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
6174 Output_data_got_powerpc
<size
, big_endian
>* got
6175 = this->got_section(symtab
, layout
);
6176 unsigned int got_offset
= got
->add_constant_pair(0, 0);
6177 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
6179 this->tlsld_got_offset_
= got_offset
;
6181 return this->tlsld_got_offset_
;
6184 // Get the Reference_flags for a particular relocation.
6186 template<int size
, bool big_endian
>
6188 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
6189 unsigned int r_type
,
6190 const Target_powerpc
* target
)
6196 case elfcpp::R_POWERPC_NONE
:
6197 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6198 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6199 case elfcpp::R_PPC64_TOC
:
6200 // No symbol reference.
6203 case elfcpp::R_PPC64_ADDR64
:
6204 case elfcpp::R_PPC64_UADDR64
:
6205 case elfcpp::R_POWERPC_ADDR32
:
6206 case elfcpp::R_POWERPC_UADDR32
:
6207 case elfcpp::R_POWERPC_ADDR16
:
6208 case elfcpp::R_POWERPC_UADDR16
:
6209 case elfcpp::R_POWERPC_ADDR16_LO
:
6210 case elfcpp::R_POWERPC_ADDR16_HI
:
6211 case elfcpp::R_POWERPC_ADDR16_HA
:
6212 ref
= Symbol::ABSOLUTE_REF
;
6215 case elfcpp::R_POWERPC_ADDR24
:
6216 case elfcpp::R_POWERPC_ADDR14
:
6217 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6218 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6219 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
6222 case elfcpp::R_PPC64_REL64
:
6223 case elfcpp::R_POWERPC_REL32
:
6224 case elfcpp::R_PPC_LOCAL24PC
:
6225 case elfcpp::R_POWERPC_REL16
:
6226 case elfcpp::R_POWERPC_REL16_LO
:
6227 case elfcpp::R_POWERPC_REL16_HI
:
6228 case elfcpp::R_POWERPC_REL16_HA
:
6229 ref
= Symbol::RELATIVE_REF
;
6232 case elfcpp::R_POWERPC_REL24
:
6233 case elfcpp::R_PPC_PLTREL24
:
6234 case elfcpp::R_POWERPC_REL14
:
6235 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6236 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6237 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
6240 case elfcpp::R_POWERPC_GOT16
:
6241 case elfcpp::R_POWERPC_GOT16_LO
:
6242 case elfcpp::R_POWERPC_GOT16_HI
:
6243 case elfcpp::R_POWERPC_GOT16_HA
:
6244 case elfcpp::R_PPC64_GOT16_DS
:
6245 case elfcpp::R_PPC64_GOT16_LO_DS
:
6246 case elfcpp::R_PPC64_TOC16
:
6247 case elfcpp::R_PPC64_TOC16_LO
:
6248 case elfcpp::R_PPC64_TOC16_HI
:
6249 case elfcpp::R_PPC64_TOC16_HA
:
6250 case elfcpp::R_PPC64_TOC16_DS
:
6251 case elfcpp::R_PPC64_TOC16_LO_DS
:
6252 case elfcpp::R_POWERPC_PLT16_LO
:
6253 case elfcpp::R_POWERPC_PLT16_HI
:
6254 case elfcpp::R_POWERPC_PLT16_HA
:
6255 case elfcpp::R_PPC64_PLT16_LO_DS
:
6256 ref
= Symbol::RELATIVE_REF
;
6259 case elfcpp::R_POWERPC_GOT_TPREL16
:
6260 case elfcpp::R_POWERPC_TLS
:
6261 ref
= Symbol::TLS_REF
;
6264 case elfcpp::R_POWERPC_COPY
:
6265 case elfcpp::R_POWERPC_GLOB_DAT
:
6266 case elfcpp::R_POWERPC_JMP_SLOT
:
6267 case elfcpp::R_POWERPC_RELATIVE
:
6268 case elfcpp::R_POWERPC_DTPMOD
:
6270 // Not expected. We will give an error later.
6274 if (size
== 64 && target
->abiversion() < 2)
6275 ref
|= Symbol::FUNC_DESC_ABI
;
6279 // Report an unsupported relocation against a local symbol.
6281 template<int size
, bool big_endian
>
6283 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
6284 Sized_relobj_file
<size
, big_endian
>* object
,
6285 unsigned int r_type
)
6287 gold_error(_("%s: unsupported reloc %u against local symbol"),
6288 object
->name().c_str(), r_type
);
6291 // We are about to emit a dynamic relocation of type R_TYPE. If the
6292 // dynamic linker does not support it, issue an error.
6294 template<int size
, bool big_endian
>
6296 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
6297 unsigned int r_type
)
6299 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
6301 // These are the relocation types supported by glibc for both 32-bit
6302 // and 64-bit powerpc.
6305 case elfcpp::R_POWERPC_NONE
:
6306 case elfcpp::R_POWERPC_RELATIVE
:
6307 case elfcpp::R_POWERPC_GLOB_DAT
:
6308 case elfcpp::R_POWERPC_DTPMOD
:
6309 case elfcpp::R_POWERPC_DTPREL
:
6310 case elfcpp::R_POWERPC_TPREL
:
6311 case elfcpp::R_POWERPC_JMP_SLOT
:
6312 case elfcpp::R_POWERPC_COPY
:
6313 case elfcpp::R_POWERPC_IRELATIVE
:
6314 case elfcpp::R_POWERPC_ADDR32
:
6315 case elfcpp::R_POWERPC_UADDR32
:
6316 case elfcpp::R_POWERPC_ADDR24
:
6317 case elfcpp::R_POWERPC_ADDR16
:
6318 case elfcpp::R_POWERPC_UADDR16
:
6319 case elfcpp::R_POWERPC_ADDR16_LO
:
6320 case elfcpp::R_POWERPC_ADDR16_HI
:
6321 case elfcpp::R_POWERPC_ADDR16_HA
:
6322 case elfcpp::R_POWERPC_ADDR14
:
6323 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6324 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6325 case elfcpp::R_POWERPC_REL32
:
6326 case elfcpp::R_POWERPC_REL24
:
6327 case elfcpp::R_POWERPC_TPREL16
:
6328 case elfcpp::R_POWERPC_TPREL16_LO
:
6329 case elfcpp::R_POWERPC_TPREL16_HI
:
6330 case elfcpp::R_POWERPC_TPREL16_HA
:
6341 // These are the relocation types supported only on 64-bit.
6342 case elfcpp::R_PPC64_ADDR64
:
6343 case elfcpp::R_PPC64_UADDR64
:
6344 case elfcpp::R_PPC64_JMP_IREL
:
6345 case elfcpp::R_PPC64_ADDR16_DS
:
6346 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6347 case elfcpp::R_PPC64_ADDR16_HIGH
:
6348 case elfcpp::R_PPC64_ADDR16_HIGHA
:
6349 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6350 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6351 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6352 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6353 case elfcpp::R_PPC64_REL64
:
6354 case elfcpp::R_POWERPC_ADDR30
:
6355 case elfcpp::R_PPC64_TPREL16_DS
:
6356 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6357 case elfcpp::R_PPC64_TPREL16_HIGH
:
6358 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6359 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6360 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6361 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6362 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6373 // These are the relocation types supported only on 32-bit.
6374 // ??? glibc ld.so doesn't need to support these.
6375 case elfcpp::R_POWERPC_DTPREL16
:
6376 case elfcpp::R_POWERPC_DTPREL16_LO
:
6377 case elfcpp::R_POWERPC_DTPREL16_HI
:
6378 case elfcpp::R_POWERPC_DTPREL16_HA
:
6386 // This prevents us from issuing more than one error per reloc
6387 // section. But we can still wind up issuing more than one
6388 // error per object file.
6389 if (this->issued_non_pic_error_
)
6391 gold_assert(parameters
->options().output_is_position_independent());
6392 object
->error(_("requires unsupported dynamic reloc; "
6393 "recompile with -fPIC"));
6394 this->issued_non_pic_error_
= true;
6398 // Return whether we need to make a PLT entry for a relocation of the
6399 // given type against a STT_GNU_IFUNC symbol.
6401 template<int size
, bool big_endian
>
6403 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
6404 Target_powerpc
<size
, big_endian
>* target
,
6405 Sized_relobj_file
<size
, big_endian
>* object
,
6406 unsigned int r_type
,
6409 // In non-pic code any reference will resolve to the plt call stub
6410 // for the ifunc symbol.
6411 if ((size
== 32 || target
->abiversion() >= 2)
6412 && !parameters
->options().output_is_position_independent())
6417 // Word size refs from data sections are OK, but don't need a PLT entry.
6418 case elfcpp::R_POWERPC_ADDR32
:
6419 case elfcpp::R_POWERPC_UADDR32
:
6424 case elfcpp::R_PPC64_ADDR64
:
6425 case elfcpp::R_PPC64_UADDR64
:
6430 // GOT refs are good, but also don't need a PLT entry.
6431 case elfcpp::R_POWERPC_GOT16
:
6432 case elfcpp::R_POWERPC_GOT16_LO
:
6433 case elfcpp::R_POWERPC_GOT16_HI
:
6434 case elfcpp::R_POWERPC_GOT16_HA
:
6435 case elfcpp::R_PPC64_GOT16_DS
:
6436 case elfcpp::R_PPC64_GOT16_LO_DS
:
6439 // PLT relocs are OK and need a PLT entry.
6440 case elfcpp::R_POWERPC_PLT16_LO
:
6441 case elfcpp::R_POWERPC_PLT16_HI
:
6442 case elfcpp::R_POWERPC_PLT16_HA
:
6443 case elfcpp::R_PPC64_PLT16_LO_DS
:
6447 // Function calls are good, and these do need a PLT entry.
6448 case elfcpp::R_POWERPC_ADDR24
:
6449 case elfcpp::R_POWERPC_ADDR14
:
6450 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6451 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6452 case elfcpp::R_POWERPC_REL24
:
6453 case elfcpp::R_PPC_PLTREL24
:
6454 case elfcpp::R_POWERPC_REL14
:
6455 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6456 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6463 // Anything else is a problem.
6464 // If we are building a static executable, the libc startup function
6465 // responsible for applying indirect function relocations is going
6466 // to complain about the reloc type.
6467 // If we are building a dynamic executable, we will have a text
6468 // relocation. The dynamic loader will set the text segment
6469 // writable and non-executable to apply text relocations. So we'll
6470 // segfault when trying to run the indirection function to resolve
6473 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
6474 object
->name().c_str(), r_type
);
6478 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6482 ok_lo_toc_insn(uint32_t insn
, unsigned int r_type
)
6484 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
6485 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
6486 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6487 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6488 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6489 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6490 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6491 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6492 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6493 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6494 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6495 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6496 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6497 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6498 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6499 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
6500 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
6501 /* Exclude lfqu by testing reloc. If relocs are ever
6502 defined for the reduced D field in psq_lu then those
6503 will need testing too. */
6504 && r_type
!= elfcpp::R_PPC64_TOC16_LO
6505 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
6506 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
6508 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
6509 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
6510 /* Exclude stfqu. psq_stu as above for psq_lu. */
6511 && r_type
!= elfcpp::R_PPC64_TOC16_LO
6512 && r_type
!= elfcpp::R_POWERPC_GOT16_LO
)
6513 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
6514 && (insn
& 1) == 0));
6517 // Scan a relocation for a local symbol.
6519 template<int size
, bool big_endian
>
6521 Target_powerpc
<size
, big_endian
>::Scan::local(
6522 Symbol_table
* symtab
,
6524 Target_powerpc
<size
, big_endian
>* target
,
6525 Sized_relobj_file
<size
, big_endian
>* object
,
6526 unsigned int data_shndx
,
6527 Output_section
* output_section
,
6528 const elfcpp::Rela
<size
, big_endian
>& reloc
,
6529 unsigned int r_type
,
6530 const elfcpp::Sym
<size
, big_endian
>& lsym
,
6533 this->maybe_skip_tls_get_addr_call(target
, r_type
, NULL
);
6535 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
6536 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
6538 this->expect_tls_get_addr_call();
6539 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
6540 if (tls_type
!= tls::TLSOPT_NONE
)
6541 this->skip_next_tls_get_addr_call();
6543 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
6544 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
6546 this->expect_tls_get_addr_call();
6547 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6548 if (tls_type
!= tls::TLSOPT_NONE
)
6549 this->skip_next_tls_get_addr_call();
6552 Powerpc_relobj
<size
, big_endian
>* ppc_object
6553 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6558 && data_shndx
== ppc_object
->opd_shndx()
6559 && r_type
== elfcpp::R_PPC64_ADDR64
)
6560 ppc_object
->set_opd_discard(reloc
.get_r_offset());
6564 // A local STT_GNU_IFUNC symbol may require a PLT entry.
6565 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
6566 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
6568 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6569 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6570 r_type
, r_sym
, reloc
.get_r_addend());
6571 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
6576 case elfcpp::R_POWERPC_NONE
:
6577 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6578 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6579 case elfcpp::R_POWERPC_TLS
:
6580 case elfcpp::R_PPC64_ENTRY
:
6583 case elfcpp::R_PPC64_TOC
:
6585 Output_data_got_powerpc
<size
, big_endian
>* got
6586 = target
->got_section(symtab
, layout
);
6587 if (parameters
->options().output_is_position_independent())
6589 Address off
= reloc
.get_r_offset();
6591 && target
->abiversion() < 2
6592 && data_shndx
== ppc_object
->opd_shndx()
6593 && ppc_object
->get_opd_discard(off
- 8))
6596 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6597 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
6598 rela_dyn
->add_output_section_relative(got
->output_section(),
6599 elfcpp::R_POWERPC_RELATIVE
,
6601 object
, data_shndx
, off
,
6602 symobj
->toc_base_offset());
6607 case elfcpp::R_PPC64_ADDR64
:
6608 case elfcpp::R_PPC64_UADDR64
:
6609 case elfcpp::R_POWERPC_ADDR32
:
6610 case elfcpp::R_POWERPC_UADDR32
:
6611 case elfcpp::R_POWERPC_ADDR24
:
6612 case elfcpp::R_POWERPC_ADDR16
:
6613 case elfcpp::R_POWERPC_ADDR16_LO
:
6614 case elfcpp::R_POWERPC_ADDR16_HI
:
6615 case elfcpp::R_POWERPC_ADDR16_HA
:
6616 case elfcpp::R_POWERPC_UADDR16
:
6617 case elfcpp::R_PPC64_ADDR16_HIGH
:
6618 case elfcpp::R_PPC64_ADDR16_HIGHA
:
6619 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6620 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6621 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6622 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6623 case elfcpp::R_PPC64_ADDR16_DS
:
6624 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6625 case elfcpp::R_POWERPC_ADDR14
:
6626 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6627 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6628 // If building a shared library (or a position-independent
6629 // executable), we need to create a dynamic relocation for
6631 if (parameters
->options().output_is_position_independent()
6632 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
6634 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
6636 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6637 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
6638 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
6640 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6641 : elfcpp::R_POWERPC_RELATIVE
);
6642 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
6643 output_section
, data_shndx
,
6644 reloc
.get_r_offset(),
6645 reloc
.get_r_addend(), false);
6647 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
6649 check_non_pic(object
, r_type
);
6650 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
6651 data_shndx
, reloc
.get_r_offset(),
6652 reloc
.get_r_addend());
6656 gold_assert(lsym
.get_st_value() == 0);
6657 unsigned int shndx
= lsym
.get_st_shndx();
6659 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
6662 object
->error(_("section symbol %u has bad shndx %u"),
6665 rela_dyn
->add_local_section(object
, shndx
, r_type
,
6666 output_section
, data_shndx
,
6667 reloc
.get_r_offset());
6672 case elfcpp::R_POWERPC_REL24
:
6673 case elfcpp::R_PPC_PLTREL24
:
6674 case elfcpp::R_PPC_LOCAL24PC
:
6675 case elfcpp::R_POWERPC_REL14
:
6676 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6677 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6680 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6681 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6682 r_type
, r_sym
, reloc
.get_r_addend());
6686 case elfcpp::R_PPC64_TOCSAVE
:
6687 // R_PPC64_TOCSAVE follows a call instruction to indicate the
6688 // caller has already saved r2 and thus a plt call stub need not
6691 && target
->mark_pltcall(ppc_object
, data_shndx
,
6692 reloc
.get_r_offset() - 4, symtab
))
6694 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6695 unsigned int shndx
= lsym
.get_st_shndx();
6697 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
6699 object
->error(_("tocsave symbol %u has bad shndx %u"),
6702 target
->add_tocsave(ppc_object
, shndx
,
6703 lsym
.get_st_value() + reloc
.get_r_addend());
6707 case elfcpp::R_PPC64_REL64
:
6708 case elfcpp::R_POWERPC_REL32
:
6709 case elfcpp::R_POWERPC_REL16
:
6710 case elfcpp::R_POWERPC_REL16_LO
:
6711 case elfcpp::R_POWERPC_REL16_HI
:
6712 case elfcpp::R_POWERPC_REL16_HA
:
6713 case elfcpp::R_POWERPC_REL16DX_HA
:
6714 case elfcpp::R_POWERPC_SECTOFF
:
6715 case elfcpp::R_POWERPC_SECTOFF_LO
:
6716 case elfcpp::R_POWERPC_SECTOFF_HI
:
6717 case elfcpp::R_POWERPC_SECTOFF_HA
:
6718 case elfcpp::R_PPC64_SECTOFF_DS
:
6719 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6720 case elfcpp::R_POWERPC_TPREL16
:
6721 case elfcpp::R_POWERPC_TPREL16_LO
:
6722 case elfcpp::R_POWERPC_TPREL16_HI
:
6723 case elfcpp::R_POWERPC_TPREL16_HA
:
6724 case elfcpp::R_PPC64_TPREL16_DS
:
6725 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6726 case elfcpp::R_PPC64_TPREL16_HIGH
:
6727 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6728 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6729 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6730 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6731 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6732 case elfcpp::R_POWERPC_DTPREL16
:
6733 case elfcpp::R_POWERPC_DTPREL16_LO
:
6734 case elfcpp::R_POWERPC_DTPREL16_HI
:
6735 case elfcpp::R_POWERPC_DTPREL16_HA
:
6736 case elfcpp::R_PPC64_DTPREL16_DS
:
6737 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6738 case elfcpp::R_PPC64_DTPREL16_HIGH
:
6739 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
6740 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6741 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6742 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6743 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6744 case elfcpp::R_PPC64_TLSGD
:
6745 case elfcpp::R_PPC64_TLSLD
:
6746 case elfcpp::R_PPC64_ADDR64_LOCAL
:
6749 case elfcpp::R_POWERPC_GOT16
:
6750 case elfcpp::R_POWERPC_GOT16_LO
:
6751 case elfcpp::R_POWERPC_GOT16_HI
:
6752 case elfcpp::R_POWERPC_GOT16_HA
:
6753 case elfcpp::R_PPC64_GOT16_DS
:
6754 case elfcpp::R_PPC64_GOT16_LO_DS
:
6756 // The symbol requires a GOT entry.
6757 Output_data_got_powerpc
<size
, big_endian
>* got
6758 = target
->got_section(symtab
, layout
);
6759 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6761 if (!parameters
->options().output_is_position_independent())
6764 && (size
== 32 || target
->abiversion() >= 2))
6765 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
6767 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
6769 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
6771 // If we are generating a shared object or a pie, this
6772 // symbol's GOT entry will be set by a dynamic relocation.
6774 off
= got
->add_constant(0);
6775 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
6777 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
6779 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6780 : elfcpp::R_POWERPC_RELATIVE
);
6781 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
6782 got
, off
, 0, false);
6787 case elfcpp::R_PPC64_TOC16
:
6788 case elfcpp::R_PPC64_TOC16_LO
:
6789 case elfcpp::R_PPC64_TOC16_HI
:
6790 case elfcpp::R_PPC64_TOC16_HA
:
6791 case elfcpp::R_PPC64_TOC16_DS
:
6792 case elfcpp::R_PPC64_TOC16_LO_DS
:
6793 // We need a GOT section.
6794 target
->got_section(symtab
, layout
);
6797 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6798 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6799 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6800 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6802 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
6803 if (tls_type
== tls::TLSOPT_NONE
)
6805 Output_data_got_powerpc
<size
, big_endian
>* got
6806 = target
->got_section(symtab
, layout
);
6807 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6808 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6809 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
6810 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
6812 else if (tls_type
== tls::TLSOPT_TO_LE
)
6814 // no GOT relocs needed for Local Exec.
6821 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6822 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6823 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6824 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6826 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6827 if (tls_type
== tls::TLSOPT_NONE
)
6828 target
->tlsld_got_offset(symtab
, layout
, object
);
6829 else if (tls_type
== tls::TLSOPT_TO_LE
)
6831 // no GOT relocs needed for Local Exec.
6832 if (parameters
->options().emit_relocs())
6834 Output_section
* os
= layout
->tls_segment()->first_section();
6835 gold_assert(os
!= NULL
);
6836 os
->set_needs_symtab_index();
6844 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6845 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6846 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6847 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6849 Output_data_got_powerpc
<size
, big_endian
>* got
6850 = target
->got_section(symtab
, layout
);
6851 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6852 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
6856 case elfcpp::R_POWERPC_GOT_TPREL16
:
6857 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6858 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6859 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6861 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
6862 if (tls_type
== tls::TLSOPT_NONE
)
6864 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6865 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
6867 Output_data_got_powerpc
<size
, big_endian
>* got
6868 = target
->got_section(symtab
, layout
);
6869 unsigned int off
= got
->add_constant(0);
6870 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
6872 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6873 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
6874 elfcpp::R_POWERPC_TPREL
,
6878 else if (tls_type
== tls::TLSOPT_TO_LE
)
6880 // no GOT relocs needed for Local Exec.
6888 unsupported_reloc_local(object
, r_type
);
6893 && parameters
->options().toc_optimize())
6895 if (data_shndx
== ppc_object
->toc_shndx())
6898 if (r_type
!= elfcpp::R_PPC64_ADDR64
6899 || (is_ifunc
&& target
->abiversion() < 2))
6901 else if (parameters
->options().output_is_position_independent())
6907 unsigned int shndx
= lsym
.get_st_shndx();
6908 if (shndx
>= elfcpp::SHN_LORESERVE
6909 && shndx
!= elfcpp::SHN_XINDEX
)
6914 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
6917 enum {no_check
, check_lo
, check_ha
} insn_check
;
6921 insn_check
= no_check
;
6924 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6925 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6926 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6927 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6928 case elfcpp::R_POWERPC_GOT16_HA
:
6929 case elfcpp::R_PPC64_TOC16_HA
:
6930 insn_check
= check_ha
;
6933 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6934 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6935 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6936 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6937 case elfcpp::R_POWERPC_GOT16_LO
:
6938 case elfcpp::R_PPC64_GOT16_LO_DS
:
6939 case elfcpp::R_PPC64_TOC16_LO
:
6940 case elfcpp::R_PPC64_TOC16_LO_DS
:
6941 insn_check
= check_lo
;
6945 section_size_type slen
;
6946 const unsigned char* view
= NULL
;
6947 if (insn_check
!= no_check
)
6949 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
6950 section_size_type off
=
6951 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
6954 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
6955 if (insn_check
== check_lo
6956 ? !ok_lo_toc_insn(insn
, r_type
)
6957 : ((insn
& ((0x3f << 26) | 0x1f << 16))
6958 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
6960 ppc_object
->set_no_toc_opt();
6961 gold_warning(_("%s: toc optimization is not supported "
6962 "for %#08x instruction"),
6963 ppc_object
->name().c_str(), insn
);
6972 case elfcpp::R_PPC64_TOC16
:
6973 case elfcpp::R_PPC64_TOC16_LO
:
6974 case elfcpp::R_PPC64_TOC16_HI
:
6975 case elfcpp::R_PPC64_TOC16_HA
:
6976 case elfcpp::R_PPC64_TOC16_DS
:
6977 case elfcpp::R_PPC64_TOC16_LO_DS
:
6978 unsigned int shndx
= lsym
.get_st_shndx();
6979 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
6981 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
6982 if (is_ordinary
&& shndx
== ppc_object
->toc_shndx())
6984 Address dst_off
= lsym
.get_st_value() + reloc
.get_r_addend();
6985 if (dst_off
< ppc_object
->section_size(shndx
))
6988 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
6990 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
6992 // Need to check that the insn is a ld
6994 view
= ppc_object
->section_contents(data_shndx
,
6997 section_size_type off
=
6998 (convert_to_section_size_type(reloc
.get_r_offset())
6999 + (big_endian
? -2 : 3));
7001 && (view
[off
] & (0x3f << 2)) == 58u << 2)
7005 ppc_object
->set_no_toc_opt(dst_off
);
7016 case elfcpp::R_POWERPC_REL32
:
7017 if (ppc_object
->got2_shndx() != 0
7018 && parameters
->options().output_is_position_independent())
7020 unsigned int shndx
= lsym
.get_st_shndx();
7021 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7023 shndx
= ppc_object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
7024 if (is_ordinary
&& shndx
== ppc_object
->got2_shndx()
7025 && (ppc_object
->section_flags(data_shndx
)
7026 & elfcpp::SHF_EXECINSTR
) != 0)
7027 gold_error(_("%s: unsupported -mbss-plt code"),
7028 ppc_object
->name().c_str());
7038 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7039 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7040 case elfcpp::R_POWERPC_GOT_TPREL16
:
7041 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7042 case elfcpp::R_POWERPC_GOT16
:
7043 case elfcpp::R_PPC64_GOT16_DS
:
7044 case elfcpp::R_PPC64_TOC16
:
7045 case elfcpp::R_PPC64_TOC16_DS
:
7046 ppc_object
->set_has_small_toc_reloc();
7052 // Report an unsupported relocation against a global symbol.
7054 template<int size
, bool big_endian
>
7056 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
7057 Sized_relobj_file
<size
, big_endian
>* object
,
7058 unsigned int r_type
,
7061 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
7062 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
7065 // Scan a relocation for a global symbol.
7067 template<int size
, bool big_endian
>
7069 Target_powerpc
<size
, big_endian
>::Scan::global(
7070 Symbol_table
* symtab
,
7072 Target_powerpc
<size
, big_endian
>* target
,
7073 Sized_relobj_file
<size
, big_endian
>* object
,
7074 unsigned int data_shndx
,
7075 Output_section
* output_section
,
7076 const elfcpp::Rela
<size
, big_endian
>& reloc
,
7077 unsigned int r_type
,
7080 if (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
)
7084 if (target
->replace_tls_get_addr(gsym
))
7085 // Change a __tls_get_addr reference to __tls_get_addr_opt
7086 // so dynamic relocs are emitted against the latter symbol.
7087 gsym
= target
->tls_get_addr_opt();
7089 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7090 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7092 this->expect_tls_get_addr_call();
7093 const bool final
= gsym
->final_value_is_known();
7094 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7095 if (tls_type
!= tls::TLSOPT_NONE
)
7096 this->skip_next_tls_get_addr_call();
7098 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7099 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7101 this->expect_tls_get_addr_call();
7102 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7103 if (tls_type
!= tls::TLSOPT_NONE
)
7104 this->skip_next_tls_get_addr_call();
7107 Powerpc_relobj
<size
, big_endian
>* ppc_object
7108 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7110 // A STT_GNU_IFUNC symbol may require a PLT entry.
7111 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
7112 bool pushed_ifunc
= false;
7113 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
7115 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7116 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7117 r_type
, r_sym
, reloc
.get_r_addend());
7118 target
->make_plt_entry(symtab
, layout
, gsym
);
7119 pushed_ifunc
= true;
7124 case elfcpp::R_POWERPC_NONE
:
7125 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7126 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7127 case elfcpp::R_PPC_LOCAL24PC
:
7128 case elfcpp::R_POWERPC_TLS
:
7129 case elfcpp::R_PPC64_ENTRY
:
7132 case elfcpp::R_PPC64_TOC
:
7134 Output_data_got_powerpc
<size
, big_endian
>* got
7135 = target
->got_section(symtab
, layout
);
7136 if (parameters
->options().output_is_position_independent())
7138 Address off
= reloc
.get_r_offset();
7140 && data_shndx
== ppc_object
->opd_shndx()
7141 && ppc_object
->get_opd_discard(off
- 8))
7144 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7145 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
7146 if (data_shndx
!= ppc_object
->opd_shndx())
7147 symobj
= static_cast
7148 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
7149 rela_dyn
->add_output_section_relative(got
->output_section(),
7150 elfcpp::R_POWERPC_RELATIVE
,
7152 object
, data_shndx
, off
,
7153 symobj
->toc_base_offset());
7158 case elfcpp::R_PPC64_ADDR64
:
7160 && target
->abiversion() < 2
7161 && data_shndx
== ppc_object
->opd_shndx()
7162 && (gsym
->is_defined_in_discarded_section()
7163 || gsym
->object() != object
))
7165 ppc_object
->set_opd_discard(reloc
.get_r_offset());
7169 case elfcpp::R_PPC64_UADDR64
:
7170 case elfcpp::R_POWERPC_ADDR32
:
7171 case elfcpp::R_POWERPC_UADDR32
:
7172 case elfcpp::R_POWERPC_ADDR24
:
7173 case elfcpp::R_POWERPC_ADDR16
:
7174 case elfcpp::R_POWERPC_ADDR16_LO
:
7175 case elfcpp::R_POWERPC_ADDR16_HI
:
7176 case elfcpp::R_POWERPC_ADDR16_HA
:
7177 case elfcpp::R_POWERPC_UADDR16
:
7178 case elfcpp::R_PPC64_ADDR16_HIGH
:
7179 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7180 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7181 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7182 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7183 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7184 case elfcpp::R_PPC64_ADDR16_DS
:
7185 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7186 case elfcpp::R_POWERPC_ADDR14
:
7187 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7188 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7190 // Make a PLT entry if necessary.
7191 if (gsym
->needs_plt_entry())
7193 // Since this is not a PC-relative relocation, we may be
7194 // taking the address of a function. In that case we need to
7195 // set the entry in the dynamic symbol table to the address of
7196 // the PLT call stub.
7197 bool need_ifunc_plt
= false;
7198 if ((size
== 32 || target
->abiversion() >= 2)
7199 && gsym
->is_from_dynobj()
7200 && !parameters
->options().output_is_position_independent())
7202 gsym
->set_needs_dynsym_value();
7203 need_ifunc_plt
= true;
7205 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
7207 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7208 target
->push_branch(ppc_object
, data_shndx
,
7209 reloc
.get_r_offset(), r_type
, r_sym
,
7210 reloc
.get_r_addend());
7211 target
->make_plt_entry(symtab
, layout
, gsym
);
7214 // Make a dynamic relocation if necessary.
7215 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
7216 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
7218 if (!parameters
->options().output_is_position_independent()
7219 && gsym
->may_need_copy_reloc())
7221 target
->copy_reloc(symtab
, layout
, object
,
7222 data_shndx
, output_section
, gsym
, reloc
);
7224 else if ((((size
== 32
7225 && r_type
== elfcpp::R_POWERPC_ADDR32
)
7227 && r_type
== elfcpp::R_PPC64_ADDR64
7228 && target
->abiversion() >= 2))
7229 && gsym
->can_use_relative_reloc(false)
7230 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
7231 && parameters
->options().shared()))
7233 && r_type
== elfcpp::R_PPC64_ADDR64
7234 && target
->abiversion() < 2
7235 && (gsym
->can_use_relative_reloc(false)
7236 || data_shndx
== ppc_object
->opd_shndx())))
7238 Reloc_section
* rela_dyn
7239 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
7240 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7241 : elfcpp::R_POWERPC_RELATIVE
);
7242 rela_dyn
->add_symbolless_global_addend(
7243 gsym
, dynrel
, output_section
, object
, data_shndx
,
7244 reloc
.get_r_offset(), reloc
.get_r_addend());
7248 Reloc_section
* rela_dyn
7249 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
7250 check_non_pic(object
, r_type
);
7251 rela_dyn
->add_global(gsym
, r_type
, output_section
,
7253 reloc
.get_r_offset(),
7254 reloc
.get_r_addend());
7257 && parameters
->options().toc_optimize()
7258 && data_shndx
== ppc_object
->toc_shndx())
7259 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
7265 case elfcpp::R_POWERPC_PLT16_LO
:
7266 case elfcpp::R_POWERPC_PLT16_HI
:
7267 case elfcpp::R_POWERPC_PLT16_HA
:
7268 case elfcpp::R_PPC64_PLT16_LO_DS
:
7270 target
->make_plt_entry(symtab
, layout
, gsym
);
7273 case elfcpp::R_PPC_PLTREL24
:
7274 case elfcpp::R_POWERPC_REL24
:
7277 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7278 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7279 r_type
, r_sym
, reloc
.get_r_addend());
7280 if (gsym
->needs_plt_entry()
7281 || (!gsym
->final_value_is_known()
7282 && (gsym
->is_undefined()
7283 || gsym
->is_from_dynobj()
7284 || gsym
->is_preemptible())))
7285 target
->make_plt_entry(symtab
, layout
, gsym
);
7289 case elfcpp::R_PPC64_REL64
:
7290 case elfcpp::R_POWERPC_REL32
:
7291 // Make a dynamic relocation if necessary.
7292 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
7294 if (!parameters
->options().output_is_position_independent()
7295 && gsym
->may_need_copy_reloc())
7297 target
->copy_reloc(symtab
, layout
, object
,
7298 data_shndx
, output_section
, gsym
,
7303 Reloc_section
* rela_dyn
7304 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
7305 check_non_pic(object
, r_type
);
7306 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
7307 data_shndx
, reloc
.get_r_offset(),
7308 reloc
.get_r_addend());
7313 case elfcpp::R_POWERPC_REL14
:
7314 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7315 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7318 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7319 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
7320 r_type
, r_sym
, reloc
.get_r_addend());
7324 case elfcpp::R_PPC64_TOCSAVE
:
7325 // R_PPC64_TOCSAVE follows a call instruction to indicate the
7326 // caller has already saved r2 and thus a plt call stub need not
7329 && target
->mark_pltcall(ppc_object
, data_shndx
,
7330 reloc
.get_r_offset() - 4, symtab
))
7332 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
7334 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
7336 object
->error(_("tocsave symbol %u has bad shndx %u"),
7340 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
7341 target
->add_tocsave(ppc_object
, shndx
,
7342 sym
->value() + reloc
.get_r_addend());
7347 case elfcpp::R_POWERPC_REL16
:
7348 case elfcpp::R_POWERPC_REL16_LO
:
7349 case elfcpp::R_POWERPC_REL16_HI
:
7350 case elfcpp::R_POWERPC_REL16_HA
:
7351 case elfcpp::R_POWERPC_REL16DX_HA
:
7352 case elfcpp::R_POWERPC_SECTOFF
:
7353 case elfcpp::R_POWERPC_SECTOFF_LO
:
7354 case elfcpp::R_POWERPC_SECTOFF_HI
:
7355 case elfcpp::R_POWERPC_SECTOFF_HA
:
7356 case elfcpp::R_PPC64_SECTOFF_DS
:
7357 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7358 case elfcpp::R_POWERPC_TPREL16
:
7359 case elfcpp::R_POWERPC_TPREL16_LO
:
7360 case elfcpp::R_POWERPC_TPREL16_HI
:
7361 case elfcpp::R_POWERPC_TPREL16_HA
:
7362 case elfcpp::R_PPC64_TPREL16_DS
:
7363 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7364 case elfcpp::R_PPC64_TPREL16_HIGH
:
7365 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7366 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7367 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7368 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7369 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7370 case elfcpp::R_POWERPC_DTPREL16
:
7371 case elfcpp::R_POWERPC_DTPREL16_LO
:
7372 case elfcpp::R_POWERPC_DTPREL16_HI
:
7373 case elfcpp::R_POWERPC_DTPREL16_HA
:
7374 case elfcpp::R_PPC64_DTPREL16_DS
:
7375 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7376 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7377 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7378 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7379 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7380 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7381 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7382 case elfcpp::R_PPC64_TLSGD
:
7383 case elfcpp::R_PPC64_TLSLD
:
7384 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7387 case elfcpp::R_POWERPC_GOT16
:
7388 case elfcpp::R_POWERPC_GOT16_LO
:
7389 case elfcpp::R_POWERPC_GOT16_HI
:
7390 case elfcpp::R_POWERPC_GOT16_HA
:
7391 case elfcpp::R_PPC64_GOT16_DS
:
7392 case elfcpp::R_PPC64_GOT16_LO_DS
:
7394 // The symbol requires a GOT entry.
7395 Output_data_got_powerpc
<size
, big_endian
>* got
;
7397 got
= target
->got_section(symtab
, layout
);
7398 if (gsym
->final_value_is_known())
7401 && (size
== 32 || target
->abiversion() >= 2))
7402 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
7404 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
7406 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
7408 // If we are generating a shared object or a pie, this
7409 // symbol's GOT entry will be set by a dynamic relocation.
7410 unsigned int off
= got
->add_constant(0);
7411 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
7413 Reloc_section
* rela_dyn
7414 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
7416 if (gsym
->can_use_relative_reloc(false)
7418 || target
->abiversion() >= 2)
7419 && gsym
->visibility() == elfcpp::STV_PROTECTED
7420 && parameters
->options().shared()))
7422 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
7423 : elfcpp::R_POWERPC_RELATIVE
);
7424 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
7428 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
7429 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
7435 case elfcpp::R_PPC64_TOC16
:
7436 case elfcpp::R_PPC64_TOC16_LO
:
7437 case elfcpp::R_PPC64_TOC16_HI
:
7438 case elfcpp::R_PPC64_TOC16_HA
:
7439 case elfcpp::R_PPC64_TOC16_DS
:
7440 case elfcpp::R_PPC64_TOC16_LO_DS
:
7441 // We need a GOT section.
7442 target
->got_section(symtab
, layout
);
7445 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7446 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7447 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7448 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7450 const bool final
= gsym
->final_value_is_known();
7451 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7452 if (tls_type
== tls::TLSOPT_NONE
)
7454 Output_data_got_powerpc
<size
, big_endian
>* got
7455 = target
->got_section(symtab
, layout
);
7456 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7457 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
7458 elfcpp::R_POWERPC_DTPMOD
,
7459 elfcpp::R_POWERPC_DTPREL
);
7461 else if (tls_type
== tls::TLSOPT_TO_IE
)
7463 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
7465 Output_data_got_powerpc
<size
, big_endian
>* got
7466 = target
->got_section(symtab
, layout
);
7467 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7468 if (gsym
->is_undefined()
7469 || gsym
->is_from_dynobj())
7471 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
7472 elfcpp::R_POWERPC_TPREL
);
7476 unsigned int off
= got
->add_constant(0);
7477 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
7478 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
7479 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
7484 else if (tls_type
== tls::TLSOPT_TO_LE
)
7486 // no GOT relocs needed for Local Exec.
7493 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7494 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7495 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7496 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7498 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7499 if (tls_type
== tls::TLSOPT_NONE
)
7500 target
->tlsld_got_offset(symtab
, layout
, object
);
7501 else if (tls_type
== tls::TLSOPT_TO_LE
)
7503 // no GOT relocs needed for Local Exec.
7504 if (parameters
->options().emit_relocs())
7506 Output_section
* os
= layout
->tls_segment()->first_section();
7507 gold_assert(os
!= NULL
);
7508 os
->set_needs_symtab_index();
7516 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7517 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7518 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7519 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7521 Output_data_got_powerpc
<size
, big_endian
>* got
7522 = target
->got_section(symtab
, layout
);
7523 if (!gsym
->final_value_is_known()
7524 && (gsym
->is_from_dynobj()
7525 || gsym
->is_undefined()
7526 || gsym
->is_preemptible()))
7527 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
7528 target
->rela_dyn_section(layout
),
7529 elfcpp::R_POWERPC_DTPREL
);
7531 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
7535 case elfcpp::R_POWERPC_GOT_TPREL16
:
7536 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7537 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7538 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7540 const bool final
= gsym
->final_value_is_known();
7541 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7542 if (tls_type
== tls::TLSOPT_NONE
)
7544 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
7546 Output_data_got_powerpc
<size
, big_endian
>* got
7547 = target
->got_section(symtab
, layout
);
7548 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
7549 if (gsym
->is_undefined()
7550 || gsym
->is_from_dynobj())
7552 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
7553 elfcpp::R_POWERPC_TPREL
);
7557 unsigned int off
= got
->add_constant(0);
7558 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
7559 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
7560 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
7565 else if (tls_type
== tls::TLSOPT_TO_LE
)
7567 // no GOT relocs needed for Local Exec.
7575 unsupported_reloc_global(object
, r_type
, gsym
);
7580 && parameters
->options().toc_optimize())
7582 if (data_shndx
== ppc_object
->toc_shndx())
7585 if (r_type
!= elfcpp::R_PPC64_ADDR64
7586 || (is_ifunc
&& target
->abiversion() < 2))
7588 else if (parameters
->options().output_is_position_independent()
7589 && (is_ifunc
|| gsym
->is_absolute() || gsym
->is_undefined()))
7592 ppc_object
->set_no_toc_opt(reloc
.get_r_offset());
7595 enum {no_check
, check_lo
, check_ha
} insn_check
;
7599 insn_check
= no_check
;
7602 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7603 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7604 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7605 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7606 case elfcpp::R_POWERPC_GOT16_HA
:
7607 case elfcpp::R_PPC64_TOC16_HA
:
7608 insn_check
= check_ha
;
7611 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7612 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7613 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7614 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7615 case elfcpp::R_POWERPC_GOT16_LO
:
7616 case elfcpp::R_PPC64_GOT16_LO_DS
:
7617 case elfcpp::R_PPC64_TOC16_LO
:
7618 case elfcpp::R_PPC64_TOC16_LO_DS
:
7619 insn_check
= check_lo
;
7623 section_size_type slen
;
7624 const unsigned char* view
= NULL
;
7625 if (insn_check
!= no_check
)
7627 view
= ppc_object
->section_contents(data_shndx
, &slen
, false);
7628 section_size_type off
=
7629 convert_to_section_size_type(reloc
.get_r_offset()) & -4;
7632 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(view
+ off
);
7633 if (insn_check
== check_lo
7634 ? !ok_lo_toc_insn(insn
, r_type
)
7635 : ((insn
& ((0x3f << 26) | 0x1f << 16))
7636 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
7638 ppc_object
->set_no_toc_opt();
7639 gold_warning(_("%s: toc optimization is not supported "
7640 "for %#08x instruction"),
7641 ppc_object
->name().c_str(), insn
);
7650 case elfcpp::R_PPC64_TOC16
:
7651 case elfcpp::R_PPC64_TOC16_LO
:
7652 case elfcpp::R_PPC64_TOC16_HI
:
7653 case elfcpp::R_PPC64_TOC16_HA
:
7654 case elfcpp::R_PPC64_TOC16_DS
:
7655 case elfcpp::R_PPC64_TOC16_LO_DS
:
7656 if (gsym
->source() == Symbol::FROM_OBJECT
7657 && !gsym
->object()->is_dynamic())
7659 Powerpc_relobj
<size
, big_endian
>* sym_object
7660 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
7662 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
7663 if (shndx
== sym_object
->toc_shndx())
7665 Sized_symbol
<size
>* sym
= symtab
->get_sized_symbol
<size
>(gsym
);
7666 Address dst_off
= sym
->value() + reloc
.get_r_addend();
7667 if (dst_off
< sym_object
->section_size(shndx
))
7670 if (r_type
== elfcpp::R_PPC64_TOC16_HA
)
7672 else if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
)
7674 // Need to check that the insn is a ld
7676 view
= ppc_object
->section_contents(data_shndx
,
7679 section_size_type off
=
7680 (convert_to_section_size_type(reloc
.get_r_offset())
7681 + (big_endian
? -2 : 3));
7683 && (view
[off
] & (0x3f << 2)) == (58u << 2))
7687 sym_object
->set_no_toc_opt(dst_off
);
7699 case elfcpp::R_PPC_LOCAL24PC
:
7700 if (strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
7701 gold_error(_("%s: unsupported -mbss-plt code"),
7702 ppc_object
->name().c_str());
7711 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7712 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7713 case elfcpp::R_POWERPC_GOT_TPREL16
:
7714 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7715 case elfcpp::R_POWERPC_GOT16
:
7716 case elfcpp::R_PPC64_GOT16_DS
:
7717 case elfcpp::R_PPC64_TOC16
:
7718 case elfcpp::R_PPC64_TOC16_DS
:
7719 ppc_object
->set_has_small_toc_reloc();
7725 // Process relocations for gc.
7727 template<int size
, bool big_endian
>
7729 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
7730 Symbol_table
* symtab
,
7732 Sized_relobj_file
<size
, big_endian
>* object
,
7733 unsigned int data_shndx
,
7735 const unsigned char* prelocs
,
7737 Output_section
* output_section
,
7738 bool needs_special_offset_handling
,
7739 size_t local_symbol_count
,
7740 const unsigned char* plocal_symbols
)
7742 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
7743 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
7746 Powerpc_relobj
<size
, big_endian
>* ppc_object
7747 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
7749 ppc_object
->set_opd_valid();
7750 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
7752 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
7753 for (p
= ppc_object
->access_from_map()->begin();
7754 p
!= ppc_object
->access_from_map()->end();
7757 Address dst_off
= p
->first
;
7758 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
7759 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
7760 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
7762 Relobj
* src_obj
= s
->first
;
7763 unsigned int src_indx
= s
->second
;
7764 symtab
->gc()->add_reference(src_obj
, src_indx
,
7765 ppc_object
, dst_indx
);
7769 ppc_object
->access_from_map()->clear();
7770 ppc_object
->process_gc_mark(symtab
);
7771 // Don't look at .opd relocs as .opd will reference everything.
7775 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
7784 needs_special_offset_handling
,
7789 // Handle target specific gc actions when adding a gc reference from
7790 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
7791 // and DST_OFF. For powerpc64, this adds a referenc to the code
7792 // section of a function descriptor.
7794 template<int size
, bool big_endian
>
7796 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
7797 Symbol_table
* symtab
,
7799 unsigned int src_shndx
,
7801 unsigned int dst_shndx
,
7802 Address dst_off
) const
7804 if (size
!= 64 || dst_obj
->is_dynamic())
7807 Powerpc_relobj
<size
, big_endian
>* ppc_object
7808 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
7809 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
7811 if (ppc_object
->opd_valid())
7813 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
7814 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
7818 // If we haven't run scan_opd_relocs, we must delay
7819 // processing this function descriptor reference.
7820 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
7825 // Add any special sections for this symbol to the gc work list.
7826 // For powerpc64, this adds the code section of a function
7829 template<int size
, bool big_endian
>
7831 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
7832 Symbol_table
* symtab
,
7837 Powerpc_relobj
<size
, big_endian
>* ppc_object
7838 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
7840 unsigned int shndx
= sym
->shndx(&is_ordinary
);
7841 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
7843 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
7844 Address dst_off
= gsym
->value();
7845 if (ppc_object
->opd_valid())
7847 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
7848 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
7852 ppc_object
->add_gc_mark(dst_off
);
7857 // For a symbol location in .opd, set LOC to the location of the
7860 template<int size
, bool big_endian
>
7862 Target_powerpc
<size
, big_endian
>::do_function_location(
7863 Symbol_location
* loc
) const
7865 if (size
== 64 && loc
->shndx
!= 0)
7867 if (loc
->object
->is_dynamic())
7869 Powerpc_dynobj
<size
, big_endian
>* ppc_object
7870 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
7871 if (loc
->shndx
== ppc_object
->opd_shndx())
7874 Address off
= loc
->offset
- ppc_object
->opd_address();
7875 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
7876 loc
->offset
= dest_off
;
7881 const Powerpc_relobj
<size
, big_endian
>* ppc_object
7882 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
7883 if (loc
->shndx
== ppc_object
->opd_shndx())
7886 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
7887 loc
->offset
= dest_off
;
7893 // FNOFFSET in section SHNDX in OBJECT is the start of a function
7894 // compiled with -fsplit-stack. The function calls non-split-stack
7895 // code. Change the function to ensure it has enough stack space to
7896 // call some random function.
7898 template<int size
, bool big_endian
>
7900 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
7903 section_offset_type fnoffset
,
7904 section_size_type fnsize
,
7905 const unsigned char* prelocs
,
7907 unsigned char* view
,
7908 section_size_type view_size
,
7910 std::string
* to
) const
7912 // 32-bit not supported.
7916 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
7917 prelocs
, reloc_count
, view
, view_size
,
7922 // The function always starts with
7923 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
7924 // addis %r12,%r1,-allocate@ha
7925 // addi %r12,%r12,-allocate@l
7927 // but note that the addis or addi may be replaced with a nop
7929 unsigned char *entry
= view
+ fnoffset
;
7930 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
7932 if ((insn
& 0xffff0000) == addis_2_12
)
7934 /* Skip ELFv2 global entry code. */
7936 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
7939 unsigned char *pinsn
= entry
;
7941 const uint32_t ld_private_ss
= 0xe80d8fc0;
7942 if (insn
== ld_private_ss
)
7944 int32_t allocate
= 0;
7948 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
7949 if ((insn
& 0xffff0000) == addis_12_1
)
7950 allocate
+= (insn
& 0xffff) << 16;
7951 else if ((insn
& 0xffff0000) == addi_12_1
7952 || (insn
& 0xffff0000) == addi_12_12
)
7953 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
7954 else if (insn
!= nop
)
7957 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
7959 int extra
= parameters
->options().split_stack_adjust_size();
7961 if (allocate
>= 0 || extra
< 0)
7963 object
->error(_("split-stack stack size overflow at "
7964 "section %u offset %0zx"),
7965 shndx
, static_cast<size_t>(fnoffset
));
7969 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
7970 if (insn
!= addis_12_1
)
7972 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
7974 insn
= addi_12_12
| (allocate
& 0xffff);
7975 if (insn
!= addi_12_12
)
7977 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
7983 insn
= addi_12_1
| (allocate
& 0xffff);
7984 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
7987 if (pinsn
!= entry
+ 12)
7988 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
7996 if (!object
->has_no_split_stack())
7997 object
->error(_("failed to match split-stack sequence at "
7998 "section %u offset %0zx"),
7999 shndx
, static_cast<size_t>(fnoffset
));
8003 // Scan relocations for a section.
8005 template<int size
, bool big_endian
>
8007 Target_powerpc
<size
, big_endian
>::scan_relocs(
8008 Symbol_table
* symtab
,
8010 Sized_relobj_file
<size
, big_endian
>* object
,
8011 unsigned int data_shndx
,
8012 unsigned int sh_type
,
8013 const unsigned char* prelocs
,
8015 Output_section
* output_section
,
8016 bool needs_special_offset_handling
,
8017 size_t local_symbol_count
,
8018 const unsigned char* plocal_symbols
)
8020 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8021 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8024 if (!this->plt_localentry0_init_
)
8026 bool plt_localentry0
= false;
8028 && this->abiversion() >= 2)
8030 if (parameters
->options().user_set_plt_localentry())
8031 plt_localentry0
= parameters
->options().plt_localentry();
8033 && symtab
->lookup("GLIBC_2.26", NULL
) == NULL
)
8034 gold_warning(_("--plt-localentry is especially dangerous without "
8035 "ld.so support to detect ABI violations"));
8037 this->plt_localentry0_
= plt_localentry0
;
8038 this->plt_localentry0_init_
= true;
8041 if (sh_type
== elfcpp::SHT_REL
)
8043 gold_error(_("%s: unsupported REL reloc section"),
8044 object
->name().c_str());
8048 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
8057 needs_special_offset_handling
,
8062 // Functor class for processing the global symbol table.
8063 // Removes symbols defined on discarded opd entries.
8065 template<bool big_endian
>
8066 class Global_symbol_visitor_opd
8069 Global_symbol_visitor_opd()
8073 operator()(Sized_symbol
<64>* sym
)
8075 if (sym
->has_symtab_index()
8076 || sym
->source() != Symbol::FROM_OBJECT
8077 || !sym
->in_real_elf())
8080 if (sym
->object()->is_dynamic())
8083 Powerpc_relobj
<64, big_endian
>* symobj
8084 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
8085 if (symobj
->opd_shndx() == 0)
8089 unsigned int shndx
= sym
->shndx(&is_ordinary
);
8090 if (shndx
== symobj
->opd_shndx()
8091 && symobj
->get_opd_discard(sym
->value()))
8093 sym
->set_undefined();
8094 sym
->set_visibility(elfcpp::STV_DEFAULT
);
8095 sym
->set_is_defined_in_discarded_section();
8096 sym
->set_symtab_index(-1U);
8101 template<int size
, bool big_endian
>
8103 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
8105 Symbol_table
* symtab
)
8109 Output_data_save_res
<size
, big_endian
>* savres
8110 = new Output_data_save_res
<size
, big_endian
>(symtab
);
8111 this->savres_section_
= savres
;
8112 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
8113 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
8114 savres
, ORDER_TEXT
, false);
8118 // Sort linker created .got section first (for the header), then input
8119 // sections belonging to files using small model code.
8121 template<bool big_endian
>
8122 class Sort_toc_sections
8126 operator()(const Output_section::Input_section
& is1
,
8127 const Output_section::Input_section
& is2
) const
8129 if (!is1
.is_input_section() && is2
.is_input_section())
8132 = (is1
.is_input_section()
8133 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
8134 ->has_small_toc_reloc()));
8136 = (is2
.is_input_section()
8137 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
8138 ->has_small_toc_reloc()));
8139 return small1
&& !small2
;
8143 // Finalize the sections.
8145 template<int size
, bool big_endian
>
8147 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
8149 const Input_objects
*,
8150 Symbol_table
* symtab
)
8152 if (parameters
->doing_static_link())
8154 // At least some versions of glibc elf-init.o have a strong
8155 // reference to __rela_iplt marker syms. A weak ref would be
8157 if (this->iplt_
!= NULL
)
8159 Reloc_section
* rel
= this->iplt_
->rel_plt();
8160 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
8161 Symbol_table::PREDEFINED
, rel
, 0, 0,
8162 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8163 elfcpp::STV_HIDDEN
, 0, false, true);
8164 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
8165 Symbol_table::PREDEFINED
, rel
, 0, 0,
8166 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8167 elfcpp::STV_HIDDEN
, 0, true, true);
8171 symtab
->define_as_constant("__rela_iplt_start", NULL
,
8172 Symbol_table::PREDEFINED
, 0, 0,
8173 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8174 elfcpp::STV_HIDDEN
, 0, true, false);
8175 symtab
->define_as_constant("__rela_iplt_end", NULL
,
8176 Symbol_table::PREDEFINED
, 0, 0,
8177 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
8178 elfcpp::STV_HIDDEN
, 0, true, false);
8184 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
8185 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
8187 if (!parameters
->options().relocatable())
8189 this->define_save_restore_funcs(layout
, symtab
);
8191 // Annoyingly, we need to make these sections now whether or
8192 // not we need them. If we delay until do_relax then we
8193 // need to mess with the relaxation machinery checkpointing.
8194 this->got_section(symtab
, layout
);
8195 this->make_brlt_section(layout
);
8197 if (parameters
->options().toc_sort())
8199 Output_section
* os
= this->got_
->output_section();
8200 if (os
!= NULL
&& os
->input_sections().size() > 1)
8201 std::stable_sort(os
->input_sections().begin(),
8202 os
->input_sections().end(),
8203 Sort_toc_sections
<big_endian
>());
8208 // Fill in some more dynamic tags.
8209 Output_data_dynamic
* odyn
= layout
->dynamic_data();
8212 const Reloc_section
* rel_plt
= (this->plt_
== NULL
8214 : this->plt_
->rel_plt());
8215 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
8216 this->rela_dyn_
, true, size
== 32);
8220 if (this->got_
!= NULL
)
8222 this->got_
->finalize_data_size();
8223 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
8224 this->got_
, this->got_
->g_o_t());
8226 if (this->has_tls_get_addr_opt_
)
8227 odyn
->add_constant(elfcpp::DT_PPC_OPT
, elfcpp::PPC_OPT_TLS
);
8231 if (this->glink_
!= NULL
)
8233 this->glink_
->finalize_data_size();
8234 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
8236 (this->glink_
->pltresolve_size()
8239 if (this->has_localentry0_
|| this->has_tls_get_addr_opt_
)
8240 odyn
->add_constant(elfcpp::DT_PPC64_OPT
,
8241 ((this->has_localentry0_
8242 ? elfcpp::PPC64_OPT_LOCALENTRY
: 0)
8243 | (this->has_tls_get_addr_opt_
8244 ? elfcpp::PPC64_OPT_TLS
: 0)));
8248 // Emit any relocs we saved in an attempt to avoid generating COPY
8250 if (this->copy_relocs_
.any_saved_relocs())
8251 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
8254 // Emit any saved relocs, and mark toc entries using any of these
8255 // relocs as not optimizable.
8257 template<int sh_type
, int size
, bool big_endian
>
8259 Powerpc_copy_relocs
<sh_type
, size
, big_endian
>::emit(
8260 Output_data_reloc
<sh_type
, true, size
, big_endian
>* reloc_section
)
8263 && parameters
->options().toc_optimize())
8265 for (typename Copy_relocs
<sh_type
, size
, big_endian
>::
8266 Copy_reloc_entries::iterator p
= this->entries_
.begin();
8267 p
!= this->entries_
.end();
8270 typename Copy_relocs
<sh_type
, size
, big_endian
>::Copy_reloc_entry
&
8273 // If the symbol is no longer defined in a dynamic object,
8274 // then we emitted a COPY relocation. If it is still
8275 // dynamic then we'll need dynamic relocations and thus
8276 // can't optimize toc entries.
8277 if (entry
.sym_
->is_from_dynobj())
8279 Powerpc_relobj
<size
, big_endian
>* ppc_object
8280 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(entry
.relobj_
);
8281 if (entry
.shndx_
== ppc_object
->toc_shndx())
8282 ppc_object
->set_no_toc_opt(entry
.address_
);
8287 Copy_relocs
<sh_type
, size
, big_endian
>::emit(reloc_section
);
8290 // Return the value to use for a branch relocation.
8292 template<int size
, bool big_endian
>
8294 Target_powerpc
<size
, big_endian
>::symval_for_branch(
8295 const Symbol_table
* symtab
,
8296 const Sized_symbol
<size
>* gsym
,
8297 Powerpc_relobj
<size
, big_endian
>* object
,
8299 unsigned int *dest_shndx
)
8301 if (size
== 32 || this->abiversion() >= 2)
8305 // If the symbol is defined in an opd section, ie. is a function
8306 // descriptor, use the function descriptor code entry address
8307 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
8309 && (gsym
->source() != Symbol::FROM_OBJECT
8310 || gsym
->object()->is_dynamic()))
8313 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
8314 unsigned int shndx
= symobj
->opd_shndx();
8317 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
8318 if (opd_addr
== invalid_address
)
8320 opd_addr
+= symobj
->output_section_address(shndx
);
8321 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
8324 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
8325 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
8328 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
8329 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
8330 *dest_shndx
= folded
.second
;
8332 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
8333 if (sec_addr
== invalid_address
)
8336 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
8337 *value
= sec_addr
+ sec_off
;
8342 // Perform a relocation.
8344 template<int size
, bool big_endian
>
8346 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
8347 const Relocate_info
<size
, big_endian
>* relinfo
,
8349 Target_powerpc
* target
,
8352 const unsigned char* preloc
,
8353 const Sized_symbol
<size
>* gsym
,
8354 const Symbol_value
<size
>* psymval
,
8355 unsigned char* view
,
8357 section_size_type view_size
)
8362 if (target
->replace_tls_get_addr(gsym
))
8363 gsym
= static_cast<const Sized_symbol
<size
>*>(target
->tls_get_addr_opt());
8365 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
8366 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
8367 switch (this->maybe_skip_tls_get_addr_call(target
, r_type
, gsym
))
8369 case Track_tls::NOT_EXPECTED
:
8370 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8371 _("__tls_get_addr call lacks marker reloc"));
8373 case Track_tls::EXPECTED
:
8374 // We have already complained.
8376 case Track_tls::SKIP
:
8378 case Track_tls::NORMAL
:
8382 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
8383 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
8384 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
8385 // Offset from start of insn to d-field reloc.
8386 const int d_offset
= big_endian
? 2 : 0;
8388 Powerpc_relobj
<size
, big_endian
>* const object
8389 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
8391 bool has_stub_value
= false;
8392 bool localentry0
= false;
8393 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
8396 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
8397 : object
->local_has_plt_offset(r_sym
));
8399 && !is_plt16_reloc
<size
>(r_type
)
8400 && (!psymval
->is_ifunc_symbol()
8401 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
8405 && target
->abiversion() >= 2
8406 && !parameters
->options().output_is_position_independent()
8407 && !is_branch_reloc(r_type
))
8409 Address off
= target
->glink_section()->find_global_entry(gsym
);
8410 if (off
!= invalid_address
)
8412 value
= target
->glink_section()->global_entry_address() + off
;
8413 has_stub_value
= true;
8418 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
8419 if (target
->stub_tables().size() == 1)
8420 stub_table
= target
->stub_tables()[0];
8421 if (stub_table
== NULL
8424 && !parameters
->options().output_is_position_independent()
8425 && !is_branch_reloc(r_type
)))
8426 stub_table
= object
->stub_table(relinfo
->data_shndx
);
8427 if (stub_table
== NULL
)
8429 // This is a ref from a data section to an ifunc symbol,
8430 // or a non-branch reloc for which we always want to use
8431 // one set of stubs for resolving function addresses.
8432 if (target
->stub_tables().size() != 0)
8433 stub_table
= target
->stub_tables()[0];
8435 if (stub_table
!= NULL
)
8437 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
;
8439 ent
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
8440 rela
.get_r_addend());
8442 ent
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
8443 rela
.get_r_addend());
8446 value
= stub_table
->stub_address() + ent
->off_
;
8447 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
8448 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->reloc_shdr
);
8449 size_t reloc_count
= shdr
.get_sh_size() / reloc_size
;
8452 && relnum
+ 1 < reloc_count
)
8454 Reltype
next_rela(preloc
+ reloc_size
);
8455 if (elfcpp::elf_r_type
<size
>(next_rela
.get_r_info())
8456 == elfcpp::R_PPC64_TOCSAVE
8457 && next_rela
.get_r_offset() == rela
.get_r_offset() + 4)
8460 localentry0
= ent
->localentry0_
;
8461 has_stub_value
= true;
8465 // We don't care too much about bogus debug references to
8466 // non-local functions, but otherwise there had better be a plt
8467 // call stub or global entry stub as appropriate.
8468 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
8471 if (has_plt_offset
&& is_plt16_reloc
<size
>(r_type
))
8473 const Output_data_plt_powerpc
<size
, big_endian
>* plt
;
8475 value
= target
->plt_off(gsym
, &plt
);
8477 value
= target
->plt_off(object
, r_sym
, &plt
);
8478 value
+= plt
->address();
8481 value
-= (target
->got_section()->output_section()->address()
8482 + object
->toc_base_offset());
8483 else if (parameters
->options().output_is_position_independent())
8485 if (rela
.get_r_addend() >= 32768)
8487 unsigned int got2
= object
->got2_shndx();
8488 value
-= (object
->get_output_section_offset(got2
)
8489 + object
->output_section(got2
)->address()
8490 + rela
.get_r_addend());
8493 value
-= (target
->got_section()->address()
8494 + target
->got_section()->g_o_t());
8497 else if (r_type
== elfcpp::R_POWERPC_GOT16
8498 || r_type
== elfcpp::R_POWERPC_GOT16_LO
8499 || r_type
== elfcpp::R_POWERPC_GOT16_HI
8500 || r_type
== elfcpp::R_POWERPC_GOT16_HA
8501 || r_type
== elfcpp::R_PPC64_GOT16_DS
8502 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
8506 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
8507 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
8511 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
8512 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
8514 value
-= target
->got_section()->got_base_offset(object
);
8516 else if (r_type
== elfcpp::R_PPC64_TOC
)
8518 value
= (target
->got_section()->output_section()->address()
8519 + object
->toc_base_offset());
8521 else if (gsym
!= NULL
8522 && (r_type
== elfcpp::R_POWERPC_REL24
8523 || r_type
== elfcpp::R_PPC_PLTREL24
)
8528 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
8529 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
8530 bool can_plt_call
= localentry0
|| target
->is_tls_get_addr_opt(gsym
);
8531 if (!can_plt_call
&& rela
.get_r_offset() + 8 <= view_size
)
8533 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
8534 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
8537 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
8539 elfcpp::Swap
<32, big_endian
>::
8540 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
8541 can_plt_call
= true;
8546 // If we don't have a branch and link followed by a nop,
8547 // we can't go via the plt because there is no place to
8548 // put a toc restoring instruction.
8549 // Unless we know we won't be returning.
8550 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
8551 can_plt_call
= true;
8555 // g++ as of 20130507 emits self-calls without a
8556 // following nop. This is arguably wrong since we have
8557 // conflicting information. On the one hand a global
8558 // symbol and on the other a local call sequence, but
8559 // don't error for this special case.
8560 // It isn't possible to cheaply verify we have exactly
8561 // such a call. Allow all calls to the same section.
8563 Address code
= value
;
8564 if (gsym
->source() == Symbol::FROM_OBJECT
8565 && gsym
->object() == object
)
8567 unsigned int dest_shndx
= 0;
8568 if (target
->abiversion() < 2)
8570 Address addend
= rela
.get_r_addend();
8571 code
= psymval
->value(object
, addend
);
8572 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
8573 &code
, &dest_shndx
);
8576 if (dest_shndx
== 0)
8577 dest_shndx
= gsym
->shndx(&is_ordinary
);
8578 ok
= dest_shndx
== relinfo
->data_shndx
;
8582 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8583 _("call lacks nop, can't restore toc; "
8584 "recompile with -fPIC"));
8590 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8591 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
8592 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
8593 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
8595 // First instruction of a global dynamic sequence, arg setup insn.
8596 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8597 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8598 enum Got_type got_type
= GOT_TYPE_STANDARD
;
8599 if (tls_type
== tls::TLSOPT_NONE
)
8600 got_type
= GOT_TYPE_TLSGD
;
8601 else if (tls_type
== tls::TLSOPT_TO_IE
)
8602 got_type
= GOT_TYPE_TPREL
;
8603 if (got_type
!= GOT_TYPE_STANDARD
)
8607 gold_assert(gsym
->has_got_offset(got_type
));
8608 value
= gsym
->got_offset(got_type
);
8612 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
8613 value
= object
->local_got_offset(r_sym
, got_type
);
8615 value
-= target
->got_section()->got_base_offset(object
);
8617 if (tls_type
== tls::TLSOPT_TO_IE
)
8619 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8620 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8622 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8623 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8624 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
8626 insn
|= 32 << 26; // lwz
8628 insn
|= 58 << 26; // ld
8629 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8631 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
8632 - elfcpp::R_POWERPC_GOT_TLSGD16
);
8634 else if (tls_type
== tls::TLSOPT_TO_LE
)
8636 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8637 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8639 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8640 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8641 insn
&= (1 << 26) - (1 << 21); // extract rt
8646 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8647 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8648 value
= psymval
->value(object
, rela
.get_r_addend());
8652 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8654 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8655 r_type
= elfcpp::R_POWERPC_NONE
;
8659 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8660 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
8661 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
8662 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
8664 // First instruction of a local dynamic sequence, arg setup insn.
8665 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8666 if (tls_type
== tls::TLSOPT_NONE
)
8668 value
= target
->tlsld_got_offset();
8669 value
-= target
->got_section()->got_base_offset(object
);
8673 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
8674 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8675 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
8677 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8678 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8679 insn
&= (1 << 26) - (1 << 21); // extract rt
8684 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8685 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8690 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8692 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8693 r_type
= elfcpp::R_POWERPC_NONE
;
8697 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
8698 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
8699 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
8700 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
8702 // Accesses relative to a local dynamic sequence address,
8703 // no optimisation here.
8706 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
8707 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
8711 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
8712 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
8714 value
-= target
->got_section()->got_base_offset(object
);
8716 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8717 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
8718 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
8719 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8721 // First instruction of initial exec sequence.
8722 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8723 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8724 if (tls_type
== tls::TLSOPT_NONE
)
8728 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
8729 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
8733 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
8734 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
8736 value
-= target
->got_section()->got_base_offset(object
);
8740 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
8741 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8742 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8744 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8745 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8746 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
8751 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8752 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8753 value
= psymval
->value(object
, rela
.get_r_addend());
8757 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
8759 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8760 r_type
= elfcpp::R_POWERPC_NONE
;
8764 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8765 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8767 // Second instruction of a global dynamic sequence,
8768 // the __tls_get_addr call
8769 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
8770 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8771 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
8772 if (tls_type
!= tls::TLSOPT_NONE
)
8774 if (tls_type
== tls::TLSOPT_TO_IE
)
8776 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
8777 Insn insn
= add_3_3_13
;
8780 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8781 r_type
= elfcpp::R_POWERPC_NONE
;
8785 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
8786 Insn insn
= addi_3_3
;
8787 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8788 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8790 value
= psymval
->value(object
, rela
.get_r_addend());
8792 this->skip_next_tls_get_addr_call();
8795 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8796 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8798 // Second instruction of a local dynamic sequence,
8799 // the __tls_get_addr call
8800 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
8801 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
8802 if (tls_type
== tls::TLSOPT_TO_LE
)
8804 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
8805 Insn insn
= addi_3_3
;
8806 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8807 this->skip_next_tls_get_addr_call();
8808 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8813 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8815 // Second instruction of an initial exec sequence
8816 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8817 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
8818 if (tls_type
== tls::TLSOPT_TO_LE
)
8820 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
8821 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8822 unsigned int reg
= size
== 32 ? 2 : 13;
8823 insn
= at_tls_transform(insn
, reg
);
8824 gold_assert(insn
!= 0);
8825 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
8826 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8828 value
= psymval
->value(object
, rela
.get_r_addend());
8831 else if (!has_stub_value
)
8835 && (r_type
== elfcpp::R_PPC_PLTREL24
8836 || r_type
== elfcpp::R_POWERPC_PLT16_LO
8837 || r_type
== elfcpp::R_POWERPC_PLT16_HI
8838 || r_type
== elfcpp::R_POWERPC_PLT16_HA
)))
8839 addend
= rela
.get_r_addend();
8840 value
= psymval
->value(object
, addend
);
8841 if (size
== 64 && is_branch_reloc(r_type
))
8843 if (target
->abiversion() >= 2)
8846 value
+= object
->ppc64_local_entry_offset(gsym
);
8848 value
+= object
->ppc64_local_entry_offset(r_sym
);
8852 unsigned int dest_shndx
;
8853 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
8854 &value
, &dest_shndx
);
8857 Address max_branch_offset
= max_branch_delta(r_type
);
8858 if (max_branch_offset
!= 0
8859 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
8861 Stub_table
<size
, big_endian
>* stub_table
8862 = object
->stub_table(relinfo
->data_shndx
);
8863 if (stub_table
!= NULL
)
8865 Address off
= stub_table
->find_long_branch_entry(object
, value
);
8866 if (off
!= invalid_address
)
8868 value
= (stub_table
->stub_address() + stub_table
->plt_size()
8870 has_stub_value
= true;
8878 case elfcpp::R_PPC64_REL64
:
8879 case elfcpp::R_POWERPC_REL32
:
8880 case elfcpp::R_POWERPC_REL24
:
8881 case elfcpp::R_PPC_PLTREL24
:
8882 case elfcpp::R_PPC_LOCAL24PC
:
8883 case elfcpp::R_POWERPC_REL16
:
8884 case elfcpp::R_POWERPC_REL16_LO
:
8885 case elfcpp::R_POWERPC_REL16_HI
:
8886 case elfcpp::R_POWERPC_REL16_HA
:
8887 case elfcpp::R_POWERPC_REL16DX_HA
:
8888 case elfcpp::R_POWERPC_REL14
:
8889 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8890 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8894 case elfcpp::R_PPC64_TOC16
:
8895 case elfcpp::R_PPC64_TOC16_LO
:
8896 case elfcpp::R_PPC64_TOC16_HI
:
8897 case elfcpp::R_PPC64_TOC16_HA
:
8898 case elfcpp::R_PPC64_TOC16_DS
:
8899 case elfcpp::R_PPC64_TOC16_LO_DS
:
8900 // Subtract the TOC base address.
8901 value
-= (target
->got_section()->output_section()->address()
8902 + object
->toc_base_offset());
8905 case elfcpp::R_POWERPC_SECTOFF
:
8906 case elfcpp::R_POWERPC_SECTOFF_LO
:
8907 case elfcpp::R_POWERPC_SECTOFF_HI
:
8908 case elfcpp::R_POWERPC_SECTOFF_HA
:
8909 case elfcpp::R_PPC64_SECTOFF_DS
:
8910 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8912 value
-= os
->address();
8915 case elfcpp::R_PPC64_TPREL16_DS
:
8916 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8917 case elfcpp::R_PPC64_TPREL16_HIGH
:
8918 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8920 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
8923 case elfcpp::R_POWERPC_TPREL16
:
8924 case elfcpp::R_POWERPC_TPREL16_LO
:
8925 case elfcpp::R_POWERPC_TPREL16_HI
:
8926 case elfcpp::R_POWERPC_TPREL16_HA
:
8927 case elfcpp::R_POWERPC_TPREL
:
8928 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8929 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8930 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8931 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8932 // tls symbol values are relative to tls_segment()->vaddr()
8936 case elfcpp::R_PPC64_DTPREL16_DS
:
8937 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8938 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8939 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8940 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8941 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8943 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
8944 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
8947 case elfcpp::R_POWERPC_DTPREL16
:
8948 case elfcpp::R_POWERPC_DTPREL16_LO
:
8949 case elfcpp::R_POWERPC_DTPREL16_HI
:
8950 case elfcpp::R_POWERPC_DTPREL16_HA
:
8951 case elfcpp::R_POWERPC_DTPREL
:
8952 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8953 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8954 // tls symbol values are relative to tls_segment()->vaddr()
8955 value
-= dtp_offset
;
8958 case elfcpp::R_PPC64_ADDR64_LOCAL
:
8960 value
+= object
->ppc64_local_entry_offset(gsym
);
8962 value
+= object
->ppc64_local_entry_offset(r_sym
);
8969 Insn branch_bit
= 0;
8972 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8973 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8974 branch_bit
= 1 << 21;
8976 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8977 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8979 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
8980 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8983 if (this->is_isa_v2
)
8985 // Set 'a' bit. This is 0b00010 in BO field for branch
8986 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
8987 // for branch on CTR insns (BO == 1a00t or 1a01t).
8988 if ((insn
& (0x14 << 21)) == (0x04 << 21))
8990 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
8997 // Invert 'y' bit if not the default.
8998 if (static_cast<Signed_address
>(value
) < 0)
9001 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9005 case elfcpp::R_POWERPC_PLT16_HA
:
9007 && !parameters
->options().output_is_position_independent())
9009 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9010 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9012 // Convert addis to lis.
9013 if ((insn
& (0x3f << 26)) == 15u << 26
9014 && (insn
& (0x1f << 16)) != 0)
9016 insn
&= ~(0x1f << 16);
9017 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9033 // Multi-instruction sequences that access the GOT/TOC can
9034 // be optimized, eg.
9035 // addis ra,r2,x@got@ha; ld rb,x@got@l(ra);
9036 // to addis ra,r2,x@toc@ha; addi rb,ra,x@toc@l;
9038 // addis ra,r2,0; addi rb,ra,x@toc@l;
9039 // to nop; addi rb,r2,x@toc;
9040 // FIXME: the @got sequence shown above is not yet
9041 // optimized. Note that gcc as of 2017-01-07 doesn't use
9042 // the ELF @got relocs except for TLS, instead using the
9043 // PowerOpen variant of a compiler managed GOT (called TOC).
9044 // The PowerOpen TOC sequence equivalent to the first
9045 // example is optimized.
9046 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9047 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9048 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9049 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9050 case elfcpp::R_POWERPC_GOT16_HA
:
9051 case elfcpp::R_PPC64_TOC16_HA
:
9052 if (parameters
->options().toc_optimize())
9054 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9055 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9056 if (r_type
== elfcpp::R_PPC64_TOC16_HA
9057 && object
->make_toc_relative(target
, &value
))
9059 gold_assert((insn
& ((0x3f << 26) | 0x1f << 16))
9060 == ((15u << 26) | (2 << 16)));
9062 if (((insn
& ((0x3f << 26) | 0x1f << 16))
9063 == ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
9064 && value
+ 0x8000 < 0x10000)
9066 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9072 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9073 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9074 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9075 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9076 case elfcpp::R_POWERPC_GOT16_LO
:
9077 case elfcpp::R_PPC64_GOT16_LO_DS
:
9078 case elfcpp::R_PPC64_TOC16_LO
:
9079 case elfcpp::R_PPC64_TOC16_LO_DS
:
9080 if (parameters
->options().toc_optimize())
9082 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9083 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9084 bool changed
= false;
9085 if (r_type
== elfcpp::R_PPC64_TOC16_LO_DS
9086 && object
->make_toc_relative(target
, &value
))
9088 gold_assert ((insn
& (0x3f << 26)) == 58u << 26 /* ld */);
9089 insn
^= (14u << 26) ^ (58u << 26);
9090 r_type
= elfcpp::R_PPC64_TOC16_LO
;
9093 if (ok_lo_toc_insn(insn
, r_type
)
9094 && value
+ 0x8000 < 0x10000)
9096 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
9098 // Transform addic to addi when we change reg.
9099 insn
&= ~((0x3f << 26) | (0x1f << 16));
9100 insn
|= (14u << 26) | (2 << 16);
9104 insn
&= ~(0x1f << 16);
9110 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9114 case elfcpp::R_POWERPC_TPREL16_HA
:
9115 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
9117 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9118 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9119 if ((insn
& ((0x3f << 26) | 0x1f << 16))
9120 != ((15u << 26) | ((size
== 32 ? 2 : 13) << 16)))
9124 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
9130 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9132 // R_PPC_TLSGD, R_PPC_TLSLD
9135 case elfcpp::R_POWERPC_TPREL16_LO
:
9136 if (parameters
->options().tls_optimize() && value
+ 0x8000 < 0x10000)
9138 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9139 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9140 insn
&= ~(0x1f << 16);
9141 insn
|= (size
== 32 ? 2 : 13) << 16;
9142 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
9146 case elfcpp::R_PPC64_ENTRY
:
9147 value
= (target
->got_section()->output_section()->address()
9148 + object
->toc_base_offset());
9149 if (value
+ 0x80008000 <= 0xffffffff
9150 && !parameters
->options().output_is_position_independent())
9152 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9153 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9154 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
9156 if ((insn1
& ~0xfffc) == ld_2_12
9157 && insn2
== add_2_2_12
)
9159 insn1
= lis_2
+ ha(value
);
9160 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
9161 insn2
= addi_2_2
+ l(value
);
9162 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
9169 if (value
+ 0x80008000 <= 0xffffffff)
9171 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9172 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9173 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
9175 if ((insn1
& ~0xfffc) == ld_2_12
9176 && insn2
== add_2_2_12
)
9178 insn1
= addis_2_12
+ ha(value
);
9179 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
9180 insn2
= addi_2_2
+ l(value
);
9181 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
9188 case elfcpp::R_POWERPC_REL16_LO
:
9189 // If we are generating a non-PIC executable, edit
9190 // 0: addis 2,12,.TOC.-0b@ha
9191 // addi 2,2,.TOC.-0b@l
9192 // used by ELFv2 global entry points to set up r2, to
9195 // if .TOC. is in range. */
9196 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
9199 && target
->abiversion() >= 2
9200 && !parameters
->options().output_is_position_independent()
9201 && rela
.get_r_addend() == d_offset
+ 4
9203 && strcmp(gsym
->name(), ".TOC.") == 0)
9205 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9206 Reltype
prev_rela(preloc
- reloc_size
);
9207 if ((prev_rela
.get_r_info()
9208 == elfcpp::elf_r_info
<size
>(r_sym
,
9209 elfcpp::R_POWERPC_REL16_HA
))
9210 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
9211 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
9213 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9214 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
9215 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9217 if ((insn1
& 0xffff0000) == addis_2_12
9218 && (insn2
& 0xffff0000) == addi_2_2
)
9220 insn1
= lis_2
+ ha(value
+ address
- 4);
9221 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
9222 insn2
= addi_2_2
+ l(value
+ address
- 4);
9223 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
9226 relinfo
->rr
->set_strategy(relnum
- 1,
9227 Relocatable_relocs::RELOC_SPECIAL
);
9228 relinfo
->rr
->set_strategy(relnum
,
9229 Relocatable_relocs::RELOC_SPECIAL
);
9239 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
9240 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
9243 case elfcpp::R_POWERPC_ADDR32
:
9244 case elfcpp::R_POWERPC_UADDR32
:
9246 overflow
= Reloc::CHECK_BITFIELD
;
9249 case elfcpp::R_POWERPC_REL32
:
9250 case elfcpp::R_POWERPC_REL16DX_HA
:
9252 overflow
= Reloc::CHECK_SIGNED
;
9255 case elfcpp::R_POWERPC_UADDR16
:
9256 overflow
= Reloc::CHECK_BITFIELD
;
9259 case elfcpp::R_POWERPC_ADDR16
:
9260 // We really should have three separate relocations,
9261 // one for 16-bit data, one for insns with 16-bit signed fields,
9262 // and one for insns with 16-bit unsigned fields.
9263 overflow
= Reloc::CHECK_BITFIELD
;
9264 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
9265 overflow
= Reloc::CHECK_LOW_INSN
;
9268 case elfcpp::R_POWERPC_ADDR16_HI
:
9269 case elfcpp::R_POWERPC_ADDR16_HA
:
9270 case elfcpp::R_POWERPC_GOT16_HI
:
9271 case elfcpp::R_POWERPC_GOT16_HA
:
9272 case elfcpp::R_POWERPC_PLT16_HI
:
9273 case elfcpp::R_POWERPC_PLT16_HA
:
9274 case elfcpp::R_POWERPC_SECTOFF_HI
:
9275 case elfcpp::R_POWERPC_SECTOFF_HA
:
9276 case elfcpp::R_PPC64_TOC16_HI
:
9277 case elfcpp::R_PPC64_TOC16_HA
:
9278 case elfcpp::R_PPC64_PLTGOT16_HI
:
9279 case elfcpp::R_PPC64_PLTGOT16_HA
:
9280 case elfcpp::R_POWERPC_TPREL16_HI
:
9281 case elfcpp::R_POWERPC_TPREL16_HA
:
9282 case elfcpp::R_POWERPC_DTPREL16_HI
:
9283 case elfcpp::R_POWERPC_DTPREL16_HA
:
9284 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9285 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9286 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9287 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9288 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9289 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9290 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9291 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9292 case elfcpp::R_POWERPC_REL16_HI
:
9293 case elfcpp::R_POWERPC_REL16_HA
:
9295 overflow
= Reloc::CHECK_HIGH_INSN
;
9298 case elfcpp::R_POWERPC_REL16
:
9299 case elfcpp::R_PPC64_TOC16
:
9300 case elfcpp::R_POWERPC_GOT16
:
9301 case elfcpp::R_POWERPC_SECTOFF
:
9302 case elfcpp::R_POWERPC_TPREL16
:
9303 case elfcpp::R_POWERPC_DTPREL16
:
9304 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9305 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9306 case elfcpp::R_POWERPC_GOT_TPREL16
:
9307 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9308 overflow
= Reloc::CHECK_LOW_INSN
;
9311 case elfcpp::R_POWERPC_ADDR24
:
9312 case elfcpp::R_POWERPC_ADDR14
:
9313 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
9314 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
9315 case elfcpp::R_PPC64_ADDR16_DS
:
9316 case elfcpp::R_POWERPC_REL24
:
9317 case elfcpp::R_PPC_PLTREL24
:
9318 case elfcpp::R_PPC_LOCAL24PC
:
9319 case elfcpp::R_PPC64_TPREL16_DS
:
9320 case elfcpp::R_PPC64_DTPREL16_DS
:
9321 case elfcpp::R_PPC64_TOC16_DS
:
9322 case elfcpp::R_PPC64_GOT16_DS
:
9323 case elfcpp::R_PPC64_SECTOFF_DS
:
9324 case elfcpp::R_POWERPC_REL14
:
9325 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9326 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9327 overflow
= Reloc::CHECK_SIGNED
;
9331 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
9334 if (overflow
== Reloc::CHECK_LOW_INSN
9335 || overflow
== Reloc::CHECK_HIGH_INSN
)
9337 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9339 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
9340 overflow
= Reloc::CHECK_BITFIELD
;
9341 else if (overflow
== Reloc::CHECK_LOW_INSN
9342 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
9343 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
9344 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
9345 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
9346 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
9347 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
9348 overflow
= Reloc::CHECK_UNSIGNED
;
9350 overflow
= Reloc::CHECK_SIGNED
;
9353 bool maybe_dq_reloc
= false;
9354 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
9355 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
9358 case elfcpp::R_POWERPC_NONE
:
9359 case elfcpp::R_POWERPC_TLS
:
9360 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
9361 case elfcpp::R_POWERPC_GNU_VTENTRY
:
9364 case elfcpp::R_PPC64_ADDR64
:
9365 case elfcpp::R_PPC64_REL64
:
9366 case elfcpp::R_PPC64_TOC
:
9367 case elfcpp::R_PPC64_ADDR64_LOCAL
:
9368 Reloc::addr64(view
, value
);
9371 case elfcpp::R_POWERPC_TPREL
:
9372 case elfcpp::R_POWERPC_DTPREL
:
9374 Reloc::addr64(view
, value
);
9376 status
= Reloc::addr32(view
, value
, overflow
);
9379 case elfcpp::R_PPC64_UADDR64
:
9380 Reloc::addr64_u(view
, value
);
9383 case elfcpp::R_POWERPC_ADDR32
:
9384 status
= Reloc::addr32(view
, value
, overflow
);
9387 case elfcpp::R_POWERPC_REL32
:
9388 case elfcpp::R_POWERPC_UADDR32
:
9389 status
= Reloc::addr32_u(view
, value
, overflow
);
9392 case elfcpp::R_POWERPC_ADDR24
:
9393 case elfcpp::R_POWERPC_REL24
:
9394 case elfcpp::R_PPC_PLTREL24
:
9395 case elfcpp::R_PPC_LOCAL24PC
:
9396 status
= Reloc::addr24(view
, value
, overflow
);
9399 case elfcpp::R_POWERPC_GOT_DTPREL16
:
9400 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
9401 case elfcpp::R_POWERPC_GOT_TPREL16
:
9402 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
9405 // On ppc64 these are all ds form
9406 maybe_dq_reloc
= true;
9410 case elfcpp::R_POWERPC_ADDR16
:
9411 case elfcpp::R_POWERPC_REL16
:
9412 case elfcpp::R_PPC64_TOC16
:
9413 case elfcpp::R_POWERPC_GOT16
:
9414 case elfcpp::R_POWERPC_SECTOFF
:
9415 case elfcpp::R_POWERPC_TPREL16
:
9416 case elfcpp::R_POWERPC_DTPREL16
:
9417 case elfcpp::R_POWERPC_GOT_TLSGD16
:
9418 case elfcpp::R_POWERPC_GOT_TLSLD16
:
9419 case elfcpp::R_POWERPC_ADDR16_LO
:
9420 case elfcpp::R_POWERPC_REL16_LO
:
9421 case elfcpp::R_PPC64_TOC16_LO
:
9422 case elfcpp::R_POWERPC_GOT16_LO
:
9423 case elfcpp::R_POWERPC_PLT16_LO
:
9424 case elfcpp::R_POWERPC_SECTOFF_LO
:
9425 case elfcpp::R_POWERPC_TPREL16_LO
:
9426 case elfcpp::R_POWERPC_DTPREL16_LO
:
9427 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
9428 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
9430 status
= Reloc::addr16(view
, value
, overflow
);
9432 maybe_dq_reloc
= true;
9435 case elfcpp::R_POWERPC_UADDR16
:
9436 status
= Reloc::addr16_u(view
, value
, overflow
);
9439 case elfcpp::R_PPC64_ADDR16_HIGH
:
9440 case elfcpp::R_PPC64_TPREL16_HIGH
:
9441 case elfcpp::R_PPC64_DTPREL16_HIGH
:
9443 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
9446 case elfcpp::R_POWERPC_ADDR16_HI
:
9447 case elfcpp::R_POWERPC_REL16_HI
:
9448 case elfcpp::R_PPC64_TOC16_HI
:
9449 case elfcpp::R_POWERPC_GOT16_HI
:
9450 case elfcpp::R_POWERPC_PLT16_HI
:
9451 case elfcpp::R_POWERPC_SECTOFF_HI
:
9452 case elfcpp::R_POWERPC_TPREL16_HI
:
9453 case elfcpp::R_POWERPC_DTPREL16_HI
:
9454 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
9455 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
9456 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
9457 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
9458 Reloc::addr16_hi(view
, value
);
9461 case elfcpp::R_PPC64_ADDR16_HIGHA
:
9462 case elfcpp::R_PPC64_TPREL16_HIGHA
:
9463 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
9465 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
9468 case elfcpp::R_POWERPC_ADDR16_HA
:
9469 case elfcpp::R_POWERPC_REL16_HA
:
9470 case elfcpp::R_PPC64_TOC16_HA
:
9471 case elfcpp::R_POWERPC_GOT16_HA
:
9472 case elfcpp::R_POWERPC_PLT16_HA
:
9473 case elfcpp::R_POWERPC_SECTOFF_HA
:
9474 case elfcpp::R_POWERPC_TPREL16_HA
:
9475 case elfcpp::R_POWERPC_DTPREL16_HA
:
9476 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
9477 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
9478 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
9479 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
9480 Reloc::addr16_ha(view
, value
);
9483 case elfcpp::R_POWERPC_REL16DX_HA
:
9484 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
9487 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
9489 // R_PPC_EMB_NADDR16_LO
9492 case elfcpp::R_PPC64_ADDR16_HIGHER
:
9493 case elfcpp::R_PPC64_TPREL16_HIGHER
:
9494 Reloc::addr16_hi2(view
, value
);
9497 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
9499 // R_PPC_EMB_NADDR16_HI
9502 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
9503 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
9504 Reloc::addr16_ha2(view
, value
);
9507 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
9509 // R_PPC_EMB_NADDR16_HA
9512 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
9513 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
9514 Reloc::addr16_hi3(view
, value
);
9517 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
9522 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
9523 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
9524 Reloc::addr16_ha3(view
, value
);
9527 case elfcpp::R_PPC64_DTPREL16_DS
:
9528 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
9530 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
9533 case elfcpp::R_PPC64_TPREL16_DS
:
9534 case elfcpp::R_PPC64_TPREL16_LO_DS
:
9536 // R_PPC_TLSGD, R_PPC_TLSLD
9539 case elfcpp::R_PPC64_ADDR16_DS
:
9540 case elfcpp::R_PPC64_ADDR16_LO_DS
:
9541 case elfcpp::R_PPC64_TOC16_DS
:
9542 case elfcpp::R_PPC64_TOC16_LO_DS
:
9543 case elfcpp::R_PPC64_GOT16_DS
:
9544 case elfcpp::R_PPC64_GOT16_LO_DS
:
9545 case elfcpp::R_PPC64_PLT16_LO_DS
:
9546 case elfcpp::R_PPC64_SECTOFF_DS
:
9547 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
9548 maybe_dq_reloc
= true;
9551 case elfcpp::R_POWERPC_ADDR14
:
9552 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
9553 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
9554 case elfcpp::R_POWERPC_REL14
:
9555 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
9556 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
9557 status
= Reloc::addr14(view
, value
, overflow
);
9560 case elfcpp::R_POWERPC_COPY
:
9561 case elfcpp::R_POWERPC_GLOB_DAT
:
9562 case elfcpp::R_POWERPC_JMP_SLOT
:
9563 case elfcpp::R_POWERPC_RELATIVE
:
9564 case elfcpp::R_POWERPC_DTPMOD
:
9565 case elfcpp::R_PPC64_JMP_IREL
:
9566 case elfcpp::R_POWERPC_IRELATIVE
:
9567 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9568 _("unexpected reloc %u in object file"),
9572 case elfcpp::R_PPC64_TOCSAVE
:
9578 Symbol_location loc
;
9579 loc
.object
= relinfo
->object
;
9580 loc
.shndx
= relinfo
->data_shndx
;
9581 loc
.offset
= rela
.get_r_offset();
9582 Tocsave_loc::const_iterator p
= target
->tocsave_loc().find(loc
);
9583 if (p
!= target
->tocsave_loc().end())
9585 // If we've generated plt calls using this tocsave, then
9586 // the nop needs to be changed to save r2.
9587 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
9588 if (elfcpp::Swap
<32, big_endian
>::readval(iview
) == nop
)
9589 elfcpp::Swap
<32, big_endian
>::
9590 writeval(iview
, std_2_1
+ target
->stk_toc());
9595 case elfcpp::R_PPC_EMB_SDA2I16
:
9596 case elfcpp::R_PPC_EMB_SDA2REL
:
9599 // R_PPC64_TLSGD, R_PPC64_TLSLD
9602 case elfcpp::R_POWERPC_PLT32
:
9603 case elfcpp::R_POWERPC_PLTREL32
:
9604 case elfcpp::R_PPC_SDAREL16
:
9605 case elfcpp::R_POWERPC_ADDR30
:
9606 case elfcpp::R_PPC64_PLT64
:
9607 case elfcpp::R_PPC64_PLTREL64
:
9608 case elfcpp::R_PPC64_PLTGOT16
:
9609 case elfcpp::R_PPC64_PLTGOT16_LO
:
9610 case elfcpp::R_PPC64_PLTGOT16_HI
:
9611 case elfcpp::R_PPC64_PLTGOT16_HA
:
9612 case elfcpp::R_PPC64_PLTGOT16_DS
:
9613 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
9614 case elfcpp::R_PPC_EMB_RELSDA
:
9615 case elfcpp::R_PPC_TOC16
:
9618 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9619 _("unsupported reloc %u"),
9627 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
9629 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
9630 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
9631 && (insn
& 3) == 1))
9632 status
= Reloc::addr16_dq(view
, value
, overflow
);
9634 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
9635 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
9636 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
9637 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
9638 status
= Reloc::addr16_ds(view
, value
, overflow
);
9640 status
= Reloc::addr16(view
, value
, overflow
);
9643 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
9646 && gsym
->is_undefined()
9647 && is_branch_reloc(r_type
))))
9649 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
9650 _("relocation overflow"));
9652 gold_info(_("try relinking with a smaller --stub-group-size"));
9658 // Relocate section data.
9660 template<int size
, bool big_endian
>
9662 Target_powerpc
<size
, big_endian
>::relocate_section(
9663 const Relocate_info
<size
, big_endian
>* relinfo
,
9664 unsigned int sh_type
,
9665 const unsigned char* prelocs
,
9667 Output_section
* output_section
,
9668 bool needs_special_offset_handling
,
9669 unsigned char* view
,
9671 section_size_type view_size
,
9672 const Reloc_symbol_changes
* reloc_symbol_changes
)
9674 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
9675 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
9676 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
9677 Powerpc_comdat_behavior
;
9678 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9681 gold_assert(sh_type
== elfcpp::SHT_RELA
);
9683 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
9684 Powerpc_comdat_behavior
, Classify_reloc
>(
9690 needs_special_offset_handling
,
9694 reloc_symbol_changes
);
9697 template<int size
, bool big_endian
>
9698 class Powerpc_scan_relocatable_reloc
9701 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9702 static const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9703 static const int sh_type
= elfcpp::SHT_RELA
;
9705 // Return the symbol referred to by the relocation.
9706 static inline unsigned int
9707 get_r_sym(const Reltype
* reloc
)
9708 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
9710 // Return the type of the relocation.
9711 static inline unsigned int
9712 get_r_type(const Reltype
* reloc
)
9713 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
9715 // Return the strategy to use for a local symbol which is not a
9716 // section symbol, given the relocation type.
9717 inline Relocatable_relocs::Reloc_strategy
9718 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
9720 if (r_type
== 0 && r_sym
== 0)
9721 return Relocatable_relocs::RELOC_DISCARD
;
9722 return Relocatable_relocs::RELOC_COPY
;
9725 // Return the strategy to use for a local symbol which is a section
9726 // symbol, given the relocation type.
9727 inline Relocatable_relocs::Reloc_strategy
9728 local_section_strategy(unsigned int, Relobj
*)
9730 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
9733 // Return the strategy to use for a global symbol, given the
9734 // relocation type, the object, and the symbol index.
9735 inline Relocatable_relocs::Reloc_strategy
9736 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
9739 && (r_type
== elfcpp::R_PPC_PLTREL24
9740 || r_type
== elfcpp::R_POWERPC_PLT16_LO
9741 || r_type
== elfcpp::R_POWERPC_PLT16_HI
9742 || r_type
== elfcpp::R_POWERPC_PLT16_HA
))
9743 return Relocatable_relocs::RELOC_SPECIAL
;
9744 return Relocatable_relocs::RELOC_COPY
;
9748 // Scan the relocs during a relocatable link.
9750 template<int size
, bool big_endian
>
9752 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
9753 Symbol_table
* symtab
,
9755 Sized_relobj_file
<size
, big_endian
>* object
,
9756 unsigned int data_shndx
,
9757 unsigned int sh_type
,
9758 const unsigned char* prelocs
,
9760 Output_section
* output_section
,
9761 bool needs_special_offset_handling
,
9762 size_t local_symbol_count
,
9763 const unsigned char* plocal_symbols
,
9764 Relocatable_relocs
* rr
)
9766 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
9768 gold_assert(sh_type
== elfcpp::SHT_RELA
);
9770 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
9778 needs_special_offset_handling
,
9784 // Scan the relocs for --emit-relocs.
9786 template<int size
, bool big_endian
>
9788 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
9789 Symbol_table
* symtab
,
9791 Sized_relobj_file
<size
, big_endian
>* object
,
9792 unsigned int data_shndx
,
9793 unsigned int sh_type
,
9794 const unsigned char* prelocs
,
9796 Output_section
* output_section
,
9797 bool needs_special_offset_handling
,
9798 size_t local_symbol_count
,
9799 const unsigned char* plocal_syms
,
9800 Relocatable_relocs
* rr
)
9802 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
9804 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
9805 Emit_relocs_strategy
;
9807 gold_assert(sh_type
== elfcpp::SHT_RELA
);
9809 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
9817 needs_special_offset_handling
,
9823 // Emit relocations for a section.
9824 // This is a modified version of the function by the same name in
9825 // target-reloc.h. Using relocate_special_relocatable for
9826 // R_PPC_PLTREL24 would require duplication of the entire body of the
9827 // loop, so we may as well duplicate the whole thing.
9829 template<int size
, bool big_endian
>
9831 Target_powerpc
<size
, big_endian
>::relocate_relocs(
9832 const Relocate_info
<size
, big_endian
>* relinfo
,
9833 unsigned int sh_type
,
9834 const unsigned char* prelocs
,
9836 Output_section
* output_section
,
9837 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
9839 Address view_address
,
9841 unsigned char* reloc_view
,
9842 section_size_type reloc_view_size
)
9844 gold_assert(sh_type
== elfcpp::SHT_RELA
);
9846 typedef typename
elfcpp::Rela
<size
, big_endian
> Reltype
;
9847 typedef typename
elfcpp::Rela_write
<size
, big_endian
> Reltype_write
;
9848 const int reloc_size
= elfcpp::Elf_sizes
<size
>::rela_size
;
9849 // Offset from start of insn to d-field reloc.
9850 const int d_offset
= big_endian
? 2 : 0;
9852 Powerpc_relobj
<size
, big_endian
>* const object
9853 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
9854 const unsigned int local_count
= object
->local_symbol_count();
9855 unsigned int got2_shndx
= object
->got2_shndx();
9856 Address got2_addend
= 0;
9857 if (got2_shndx
!= 0)
9859 got2_addend
= object
->get_output_section_offset(got2_shndx
);
9860 gold_assert(got2_addend
!= invalid_address
);
9863 const bool relocatable
= parameters
->options().relocatable();
9865 unsigned char* pwrite
= reloc_view
;
9866 bool zap_next
= false;
9867 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
9869 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
9870 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
9873 Reltype
reloc(prelocs
);
9874 Reltype_write
reloc_write(pwrite
);
9876 Address offset
= reloc
.get_r_offset();
9877 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
9878 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
9879 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
9880 const unsigned int orig_r_sym
= r_sym
;
9881 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
9882 = reloc
.get_r_addend();
9883 const Symbol
* gsym
= NULL
;
9887 // We could arrange to discard these and other relocs for
9888 // tls optimised sequences in the strategy methods, but for
9889 // now do as BFD ld does.
9890 r_type
= elfcpp::R_POWERPC_NONE
;
9894 // Get the new symbol index.
9895 Output_section
* os
= NULL
;
9896 if (r_sym
< local_count
)
9900 case Relocatable_relocs::RELOC_COPY
:
9901 case Relocatable_relocs::RELOC_SPECIAL
:
9904 r_sym
= object
->symtab_index(r_sym
);
9905 gold_assert(r_sym
!= -1U);
9909 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
9911 // We are adjusting a section symbol. We need to find
9912 // the symbol table index of the section symbol for
9913 // the output section corresponding to input section
9914 // in which this symbol is defined.
9915 gold_assert(r_sym
< local_count
);
9917 unsigned int shndx
=
9918 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
9919 gold_assert(is_ordinary
);
9920 os
= object
->output_section(shndx
);
9921 gold_assert(os
!= NULL
);
9922 gold_assert(os
->needs_symtab_index());
9923 r_sym
= os
->symtab_index();
9933 gsym
= object
->global_symbol(r_sym
);
9934 gold_assert(gsym
!= NULL
);
9935 if (gsym
->is_forwarder())
9936 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
9938 gold_assert(gsym
->has_symtab_index());
9939 r_sym
= gsym
->symtab_index();
9942 // Get the new offset--the location in the output section where
9943 // this relocation should be applied.
9944 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
9945 offset
+= offset_in_output_section
;
9948 section_offset_type sot_offset
=
9949 convert_types
<section_offset_type
, Address
>(offset
);
9950 section_offset_type new_sot_offset
=
9951 output_section
->output_offset(object
, relinfo
->data_shndx
,
9953 gold_assert(new_sot_offset
!= -1);
9954 offset
= new_sot_offset
;
9957 // In an object file, r_offset is an offset within the section.
9958 // In an executable or dynamic object, generated by
9959 // --emit-relocs, r_offset is an absolute address.
9962 offset
+= view_address
;
9963 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
9964 offset
-= offset_in_output_section
;
9967 // Handle the reloc addend based on the strategy.
9968 if (strategy
== Relocatable_relocs::RELOC_COPY
)
9970 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
9972 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
9973 addend
= psymval
->value(object
, addend
);
9974 // In a relocatable link, the symbol value is relative to
9975 // the start of the output section. For a non-relocatable
9976 // link, we need to adjust the addend.
9979 gold_assert(os
!= NULL
);
9980 addend
-= os
->address();
9983 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
9987 if (addend
>= 32768)
9988 addend
+= got2_addend
;
9990 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
9992 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
9995 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
9997 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
9998 addend
-= d_offset
+ 4;
10002 gold_unreachable();
10006 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10007 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
10008 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
10009 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
10011 // First instruction of a global dynamic sequence,
10013 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10014 switch (this->optimize_tls_gd(final
))
10016 case tls::TLSOPT_TO_IE
:
10017 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
10018 - elfcpp::R_POWERPC_GOT_TLSGD16
);
10020 case tls::TLSOPT_TO_LE
:
10021 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
10022 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
10023 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10026 r_type
= elfcpp::R_POWERPC_NONE
;
10027 offset
-= d_offset
;
10034 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10035 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
10036 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
10037 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
10039 // First instruction of a local dynamic sequence,
10041 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
10043 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
10044 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
10046 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10047 const Output_section
* os
= relinfo
->layout
->tls_segment()
10049 gold_assert(os
!= NULL
);
10050 gold_assert(os
->needs_symtab_index());
10051 r_sym
= os
->symtab_index();
10052 addend
= dtp_offset
;
10056 r_type
= elfcpp::R_POWERPC_NONE
;
10057 offset
-= d_offset
;
10061 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10062 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
10063 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
10064 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
10066 // First instruction of initial exec sequence.
10067 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10068 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
10070 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
10071 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
10072 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
10075 r_type
= elfcpp::R_POWERPC_NONE
;
10076 offset
-= d_offset
;
10080 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
10081 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
10083 // Second instruction of a global dynamic sequence,
10084 // the __tls_get_addr call
10085 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10086 switch (this->optimize_tls_gd(final
))
10088 case tls::TLSOPT_TO_IE
:
10089 r_type
= elfcpp::R_POWERPC_NONE
;
10092 case tls::TLSOPT_TO_LE
:
10093 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10094 offset
+= d_offset
;
10101 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
10102 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
10104 // Second instruction of a local dynamic sequence,
10105 // the __tls_get_addr call
10106 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
10108 const Output_section
* os
= relinfo
->layout
->tls_segment()
10110 gold_assert(os
!= NULL
);
10111 gold_assert(os
->needs_symtab_index());
10112 r_sym
= os
->symtab_index();
10113 addend
= dtp_offset
;
10114 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10115 offset
+= d_offset
;
10119 else if (r_type
== elfcpp::R_POWERPC_TLS
)
10121 // Second instruction of an initial exec sequence
10122 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
10123 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
10125 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
10126 offset
+= d_offset
;
10131 reloc_write
.put_r_offset(offset
);
10132 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
10133 reloc_write
.put_r_addend(addend
);
10135 pwrite
+= reloc_size
;
10138 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
10139 == reloc_view_size
);
10142 // Return the value to use for a dynamic symbol which requires special
10143 // treatment. This is how we support equality comparisons of function
10144 // pointers across shared library boundaries, as described in the
10145 // processor specific ABI supplement.
10147 template<int size
, bool big_endian
>
10149 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
10153 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
10154 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
10155 p
!= this->stub_tables_
.end();
10158 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
10159 = (*p
)->find_plt_call_entry(gsym
);
10161 return (*p
)->stub_address() + ent
->off_
;
10164 else if (this->abiversion() >= 2)
10166 Address off
= this->glink_section()->find_global_entry(gsym
);
10167 if (off
!= invalid_address
)
10168 return this->glink_section()->global_entry_address() + off
;
10170 gold_unreachable();
10173 // Return the PLT address to use for a local symbol.
10174 template<int size
, bool big_endian
>
10176 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
10177 const Relobj
* object
,
10178 unsigned int symndx
) const
10182 const Sized_relobj
<size
, big_endian
>* relobj
10183 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
10184 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
10185 p
!= this->stub_tables_
.end();
10188 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
10189 = (*p
)->find_plt_call_entry(relobj
->sized_relobj(), symndx
);
10191 return (*p
)->stub_address() + ent
->off_
;
10194 gold_unreachable();
10197 // Return the PLT address to use for a global symbol.
10198 template<int size
, bool big_endian
>
10200 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
10201 const Symbol
* gsym
) const
10205 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
10206 p
!= this->stub_tables_
.end();
10209 const typename Stub_table
<size
, big_endian
>::Plt_stub_ent
* ent
10210 = (*p
)->find_plt_call_entry(gsym
);
10212 return (*p
)->stub_address() + ent
->off_
;
10215 else if (this->abiversion() >= 2)
10217 Address off
= this->glink_section()->find_global_entry(gsym
);
10218 if (off
!= invalid_address
)
10219 return this->glink_section()->global_entry_address() + off
;
10221 gold_unreachable();
10224 // Return the offset to use for the GOT_INDX'th got entry which is
10225 // for a local tls symbol specified by OBJECT, SYMNDX.
10226 template<int size
, bool big_endian
>
10228 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
10229 const Relobj
* object
,
10230 unsigned int symndx
,
10231 unsigned int got_indx
) const
10233 const Powerpc_relobj
<size
, big_endian
>* ppc_object
10234 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
10235 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
10237 for (Got_type got_type
= GOT_TYPE_TLSGD
;
10238 got_type
<= GOT_TYPE_TPREL
;
10239 got_type
= Got_type(got_type
+ 1))
10240 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
10242 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
10243 if (got_type
== GOT_TYPE_TLSGD
)
10245 if (off
== got_indx
* (size
/ 8))
10247 if (got_type
== GOT_TYPE_TPREL
)
10250 return -dtp_offset
;
10254 gold_unreachable();
10257 // Return the offset to use for the GOT_INDX'th got entry which is
10258 // for global tls symbol GSYM.
10259 template<int size
, bool big_endian
>
10261 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
10263 unsigned int got_indx
) const
10265 if (gsym
->type() == elfcpp::STT_TLS
)
10267 for (Got_type got_type
= GOT_TYPE_TLSGD
;
10268 got_type
<= GOT_TYPE_TPREL
;
10269 got_type
= Got_type(got_type
+ 1))
10270 if (gsym
->has_got_offset(got_type
))
10272 unsigned int off
= gsym
->got_offset(got_type
);
10273 if (got_type
== GOT_TYPE_TLSGD
)
10275 if (off
== got_indx
* (size
/ 8))
10277 if (got_type
== GOT_TYPE_TPREL
)
10280 return -dtp_offset
;
10284 gold_unreachable();
10287 // The selector for powerpc object files.
10289 template<int size
, bool big_endian
>
10290 class Target_selector_powerpc
: public Target_selector
10293 Target_selector_powerpc()
10294 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
10297 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
10298 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
10300 ? (big_endian
? "elf64ppc" : "elf64lppc")
10301 : (big_endian
? "elf32ppc" : "elf32lppc")))
10305 do_instantiate_target()
10306 { return new Target_powerpc
<size
, big_endian
>(); }
10309 Target_selector_powerpc
<32, true> target_selector_ppc32
;
10310 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
10311 Target_selector_powerpc
<64, true> target_selector_ppc64
;
10312 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
10314 // Instantiate these constants for -O0
10315 template<int size
, bool big_endian
>
10316 const typename Output_data_glink
<size
, big_endian
>::Address
10317 Output_data_glink
<size
, big_endian
>::invalid_address
;
10318 template<int size
, bool big_endian
>
10319 const typename Stub_table
<size
, big_endian
>::Address
10320 Stub_table
<size
, big_endian
>::invalid_address
;
10321 template<int size
, bool big_endian
>
10322 const typename Target_powerpc
<size
, big_endian
>::Address
10323 Target_powerpc
<size
, big_endian
>::invalid_address
;
10325 } // End anonymous namespace.