1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 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.
27 #include "parameters.h"
34 #include "copy-relocs.h"
36 #include "target-reloc.h"
37 #include "target-select.h"
47 template<int size
, bool big_endian
>
48 class Output_data_plt_powerpc
;
50 template<int size
, bool big_endian
>
51 class Output_data_got_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_glink
;
56 template<int size
, bool big_endian
>
57 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
60 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
61 typedef typename
elfcpp::Elf_types
<size
>::Elf_Off Offset
;
62 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
63 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
65 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
66 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
67 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
68 special_(0), opd_valid_(false), opd_ent_(), access_from_map_()
74 // The .got2 section shndx.
79 return this->special_
;
84 // The .opd section shndx.
91 return this->special_
;
94 // Init OPD entry arrays.
96 init_opd(size_t opd_size
)
98 size_t count
= this->opd_ent_ndx(opd_size
);
99 this->opd_ent_
.resize(count
);
102 // Return section and offset of function entry for .opd + R_OFF.
104 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
106 size_t ndx
= this->opd_ent_ndx(r_off
);
107 gold_assert(ndx
< this->opd_ent_
.size());
108 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
110 *value
= this->opd_ent_
[ndx
].off
;
111 return this->opd_ent_
[ndx
].shndx
;
114 // Set section and offset of function entry for .opd + R_OFF.
116 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
118 size_t ndx
= this->opd_ent_ndx(r_off
);
119 gold_assert(ndx
< this->opd_ent_
.size());
120 this->opd_ent_
[ndx
].shndx
= shndx
;
121 this->opd_ent_
[ndx
].off
= value
;
124 // Return discard flag for .opd + R_OFF.
126 get_opd_discard(Address r_off
) const
128 size_t ndx
= this->opd_ent_ndx(r_off
);
129 gold_assert(ndx
< this->opd_ent_
.size());
130 return this->opd_ent_
[ndx
].discard
;
133 // Set discard flag for .opd + R_OFF.
135 set_opd_discard(Address r_off
)
137 size_t ndx
= this->opd_ent_ndx(r_off
);
138 gold_assert(ndx
< this->opd_ent_
.size());
139 this->opd_ent_
[ndx
].discard
= true;
144 { return &this->access_from_map_
; }
146 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
147 // section at DST_OFF.
149 add_reference(Object
* src_obj
,
150 unsigned int src_indx
,
151 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
153 Section_id
src_id(src_obj
, src_indx
);
154 this->access_from_map_
[dst_off
].insert(src_id
);
159 { return this->opd_valid_
; }
163 { this->opd_valid_
= true; }
165 // Examine .rela.opd to build info about function entry points.
167 scan_opd_relocs(size_t reloc_count
,
168 const unsigned char* prelocs
,
169 const unsigned char* plocal_syms
);
172 do_read_relocs(Read_relocs_data
*);
175 do_find_special_sections(Read_symbols_data
* sd
);
177 // Return offset in output GOT section that this object will use
178 // as a TOC pointer. Won't be just a constant with multi-toc support.
180 toc_base_offset() const
191 // Return index into opd_ent_ array for .opd entry at OFF.
192 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
193 // apart when the language doesn't use the last 8-byte word, the
194 // environment pointer. Thus dividing the entry section offset by
195 // 16 will give an index into opd_ent_ that works for either layout
196 // of .opd. (It leaves some elements of the vector unused when .opd
197 // entries are spaced 24 bytes apart, but we don't know the spacing
198 // until relocations are processed, and in any case it is possible
199 // for an object to have some entries spaced 16 bytes apart and
200 // others 24 bytes apart.)
202 opd_ent_ndx(size_t off
) const
205 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
206 unsigned int special_
;
208 // Set at the start of gc_process_relocs, when we know opd_ent_
209 // vector is valid. The flag could be made atomic and set in
210 // do_read_relocs with memory_order_release and then tested with
211 // memory_order_acquire, potentially resulting in fewer entries in
215 // The first 8-byte word of an OPD entry gives the address of the
216 // entry point of the function. Relocatable object files have a
217 // relocation on this word. The following vector records the
218 // section and offset specified by these relocations.
219 std::vector
<Opd_ent
> opd_ent_
;
221 // References made to this object's .opd section when running
222 // gc_process_relocs for another object, before the opd_ent_ vector
223 // is valid for this object.
224 Access_from access_from_map_
;
227 template<int size
, bool big_endian
>
228 class Target_powerpc
: public Sized_target
<size
, big_endian
>
232 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
233 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
234 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
235 static const Address invalid_address
= static_cast<Address
>(0) - 1;
236 // Offset of tp and dtp pointers from start of TLS block.
237 static const Address tp_offset
= 0x7000;
238 static const Address dtp_offset
= 0x8000;
241 : Sized_target
<size
, big_endian
>(&powerpc_info
),
242 got_(NULL
), plt_(NULL
), glink_(NULL
), rela_dyn_(NULL
),
243 copy_relocs_(elfcpp::R_POWERPC_COPY
),
244 dynbss_(NULL
), tlsld_got_offset_(-1U)
248 // Process the relocations to determine unreferenced sections for
249 // garbage collection.
251 gc_process_relocs(Symbol_table
* symtab
,
253 Sized_relobj_file
<size
, big_endian
>* object
,
254 unsigned int data_shndx
,
255 unsigned int sh_type
,
256 const unsigned char* prelocs
,
258 Output_section
* output_section
,
259 bool needs_special_offset_handling
,
260 size_t local_symbol_count
,
261 const unsigned char* plocal_symbols
);
263 // Scan the relocations to look for symbol adjustments.
265 scan_relocs(Symbol_table
* symtab
,
267 Sized_relobj_file
<size
, big_endian
>* object
,
268 unsigned int data_shndx
,
269 unsigned int sh_type
,
270 const unsigned char* prelocs
,
272 Output_section
* output_section
,
273 bool needs_special_offset_handling
,
274 size_t local_symbol_count
,
275 const unsigned char* plocal_symbols
);
277 // Map input .toc section to output .got section.
279 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
281 if (size
== 64 && strcmp(name
, ".toc") == 0)
289 // Finalize the sections.
291 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
293 // Return the value to use for a dynamic which requires special
296 do_dynsym_value(const Symbol
*) const;
298 // Return the offset to use for the GOT_INDX'th got entry which is
299 // for a local tls symbol specified by OBJECT, SYMNDX.
301 do_tls_offset_for_local(const Relobj
* object
,
303 unsigned int got_indx
) const;
305 // Return the offset to use for the GOT_INDX'th got entry which is
306 // for global tls symbol GSYM.
308 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
310 // Relocate a section.
312 relocate_section(const Relocate_info
<size
, big_endian
>*,
313 unsigned int sh_type
,
314 const unsigned char* prelocs
,
316 Output_section
* output_section
,
317 bool needs_special_offset_handling
,
319 Address view_address
,
320 section_size_type view_size
,
321 const Reloc_symbol_changes
*);
323 // Scan the relocs during a relocatable link.
325 scan_relocatable_relocs(Symbol_table
* symtab
,
327 Sized_relobj_file
<size
, big_endian
>* object
,
328 unsigned int data_shndx
,
329 unsigned int sh_type
,
330 const unsigned char* prelocs
,
332 Output_section
* output_section
,
333 bool needs_special_offset_handling
,
334 size_t local_symbol_count
,
335 const unsigned char* plocal_symbols
,
336 Relocatable_relocs
*);
338 // Emit relocations for a section.
340 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
341 unsigned int sh_type
,
342 const unsigned char* prelocs
,
344 Output_section
* output_section
,
345 off_t offset_in_output_section
,
346 const Relocatable_relocs
*,
348 Address view_address
,
350 unsigned char* reloc_view
,
351 section_size_type reloc_view_size
);
353 // Return whether SYM is defined by the ABI.
355 do_is_defined_by_abi(const Symbol
* sym
) const
357 return strcmp(sym
->name(), "__tls_get_addr") == 0;
360 // Return the size of the GOT section.
364 gold_assert(this->got_
!= NULL
);
365 return this->got_
->data_size();
368 // Get the PLT section.
369 const Output_data_plt_powerpc
<size
, big_endian
>*
372 gold_assert(this->plt_
!= NULL
);
376 // Get the .glink section.
377 const Output_data_glink
<size
, big_endian
>*
378 glink_section() const
380 gold_assert(this->glink_
!= NULL
);
384 // Get the GOT section.
385 const Output_data_got_powerpc
<size
, big_endian
>*
388 gold_assert(this->got_
!= NULL
);
393 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
394 const elfcpp::Ehdr
<size
, big_endian
>&);
396 // Return the number of entries in the GOT.
398 got_entry_count() const
400 if (this->got_
== NULL
)
402 return this->got_size() / (size
/ 8);
405 // Return the number of entries in the PLT.
407 plt_entry_count() const;
409 // Return the offset of the first non-reserved PLT entry.
411 first_plt_entry_offset() const;
413 // Return the size of each PLT entry.
415 plt_entry_size() const;
417 // Add any special sections for this symbol to the gc work list.
418 // For powerpc64, this adds the code section of a function
421 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
423 // Handle target specific gc actions when adding a gc reference from
424 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
425 // and DST_OFF. For powerpc64, this adds a referenc to the code
426 // section of a function descriptor.
428 do_gc_add_reference(Symbol_table
* symtab
,
430 unsigned int src_shndx
,
432 unsigned int dst_shndx
,
433 Address dst_off
) const;
437 // The class which scans relocations.
441 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
444 : issued_non_pic_error_(false)
448 get_reference_flags(unsigned int r_type
);
451 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
452 Sized_relobj_file
<size
, big_endian
>* object
,
453 unsigned int data_shndx
,
454 Output_section
* output_section
,
455 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
456 const elfcpp::Sym
<size
, big_endian
>& lsym
,
460 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
461 Sized_relobj_file
<size
, big_endian
>* object
,
462 unsigned int data_shndx
,
463 Output_section
* output_section
,
464 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
468 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
470 Sized_relobj_file
<size
, big_endian
>* ,
473 const elfcpp::Rela
<size
, big_endian
>& ,
475 const elfcpp::Sym
<size
, big_endian
>&)
479 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
481 Sized_relobj_file
<size
, big_endian
>* ,
484 const elfcpp::Rela
<size
,
486 unsigned int , Symbol
*)
491 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
492 unsigned int r_type
);
495 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
496 unsigned int r_type
, Symbol
*);
499 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
500 Target_powerpc
* target
);
503 check_non_pic(Relobj
*, unsigned int r_type
);
505 // Whether we have issued an error about a non-PIC compilation.
506 bool issued_non_pic_error_
;
510 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
511 Powerpc_relobj
<size
, big_endian
>* object
,
512 unsigned int *dest_shndx
);
514 // The class which implements relocation.
518 // Use 'at' branch hints when true, 'y' when false.
519 // FIXME maybe: set this with an option.
520 static const bool is_isa_v2
= true;
524 CALL_NOT_EXPECTED
= 0,
530 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
535 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
537 // FIXME: This needs to specify the location somehow.
538 gold_error(_("missing expected __tls_get_addr call"));
542 // Do a relocation. Return false if the caller should not issue
543 // any warnings about this relocation.
545 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
546 Output_section
*, size_t relnum
,
547 const elfcpp::Rela
<size
, big_endian
>&,
548 unsigned int r_type
, const Sized_symbol
<size
>*,
549 const Symbol_value
<size
>*,
551 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
554 // This is set if we should skip the next reloc, which should be a
555 // call to __tls_get_addr.
556 enum skip_tls call_tls_get_addr_
;
559 // A class which returns the size required for a relocation type,
560 // used while scanning relocs during a relocatable link.
561 class Relocatable_size_for_reloc
565 get_size_for_reloc(unsigned int, Relobj
*)
572 // Optimize the TLS relocation type based on what we know about the
573 // symbol. IS_FINAL is true if the final address of this symbol is
574 // known at link time.
576 tls::Tls_optimization
577 optimize_tls_gd(bool is_final
)
579 // If we are generating a shared library, then we can't do anything
581 if (parameters
->options().shared())
582 return tls::TLSOPT_NONE
;
585 return tls::TLSOPT_TO_IE
;
586 return tls::TLSOPT_TO_LE
;
589 tls::Tls_optimization
592 if (parameters
->options().shared())
593 return tls::TLSOPT_NONE
;
595 return tls::TLSOPT_TO_LE
;
598 tls::Tls_optimization
599 optimize_tls_ie(bool is_final
)
601 if (!is_final
|| parameters
->options().shared())
602 return tls::TLSOPT_NONE
;
604 return tls::TLSOPT_TO_LE
;
607 // Get the GOT section, creating it if necessary.
608 Output_data_got_powerpc
<size
, big_endian
>*
609 got_section(Symbol_table
*, Layout
*);
613 make_glink_section(Layout
*);
615 // Create the PLT section.
617 make_plt_section(Layout
*);
619 // Create a PLT entry for a global symbol.
621 make_plt_entry(Layout
*, Symbol
*,
622 const elfcpp::Rela
<size
, big_endian
>&,
623 const Sized_relobj
<size
, big_endian
>* object
);
625 // Create a GOT entry for local dynamic __tls_get_addr.
627 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
628 Sized_relobj_file
<size
, big_endian
>* object
);
631 tlsld_got_offset() const
633 return this->tlsld_got_offset_
;
636 // Get the dynamic reloc section, creating it if necessary.
638 rela_dyn_section(Layout
*);
640 // Copy a relocation against a global symbol.
642 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
643 Sized_relobj_file
<size
, big_endian
>* object
,
644 unsigned int shndx
, Output_section
* output_section
,
645 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
647 this->copy_relocs_
.copy_reloc(symtab
, layout
,
648 symtab
->get_sized_symbol
<size
>(sym
),
649 object
, shndx
, output_section
,
650 reloc
, this->rela_dyn_section(layout
));
653 // Information about this specific target which we pass to the
654 // general Target structure.
655 static Target::Target_info powerpc_info
;
657 // The types of GOT entries needed for this platform.
658 // These values are exposed to the ABI in an incremental link.
659 // Do not renumber existing values without changing the version
660 // number of the .gnu_incremental_inputs section.
664 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
665 GOT_TYPE_DTPREL
, // entry for @got@dtprel
666 GOT_TYPE_TPREL
// entry for @got@tprel
669 // The GOT output section.
670 Output_data_got_powerpc
<size
, big_endian
>* got_
;
671 // The PLT output section.
672 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
673 // The .glink output section.
674 Output_data_glink
<size
, big_endian
>* glink_
;
675 // The dynamic reloc output section.
676 Reloc_section
* rela_dyn_
;
677 // Relocs saved to avoid a COPY reloc.
678 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
679 // Space for variables copied with a COPY reloc.
680 Output_data_space
* dynbss_
;
681 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
682 unsigned int tlsld_got_offset_
;
686 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
689 true, // is_big_endian
690 elfcpp::EM_PPC
, // machine_code
691 false, // has_make_symbol
692 false, // has_resolve
693 false, // has_code_fill
694 true, // is_default_stack_executable
695 false, // can_icf_inline_merge_sections
697 "/usr/lib/ld.so.1", // dynamic_linker
698 0x10000000, // default_text_segment_address
699 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
700 4 * 1024, // common_pagesize (overridable by -z common-page-size)
701 false, // isolate_execinstr
703 elfcpp::SHN_UNDEF
, // small_common_shndx
704 elfcpp::SHN_UNDEF
, // large_common_shndx
705 0, // small_common_section_flags
706 0, // large_common_section_flags
707 NULL
, // attributes_section
708 NULL
// attributes_vendor
712 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
715 false, // is_big_endian
716 elfcpp::EM_PPC
, // machine_code
717 false, // has_make_symbol
718 false, // has_resolve
719 false, // has_code_fill
720 true, // is_default_stack_executable
721 false, // can_icf_inline_merge_sections
723 "/usr/lib/ld.so.1", // dynamic_linker
724 0x10000000, // default_text_segment_address
725 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
726 4 * 1024, // common_pagesize (overridable by -z common-page-size)
727 false, // isolate_execinstr
729 elfcpp::SHN_UNDEF
, // small_common_shndx
730 elfcpp::SHN_UNDEF
, // large_common_shndx
731 0, // small_common_section_flags
732 0, // large_common_section_flags
733 NULL
, // attributes_section
734 NULL
// attributes_vendor
738 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
741 true, // is_big_endian
742 elfcpp::EM_PPC64
, // machine_code
743 false, // has_make_symbol
744 false, // has_resolve
745 false, // has_code_fill
746 true, // is_default_stack_executable
747 false, // can_icf_inline_merge_sections
749 "/usr/lib/ld.so.1", // dynamic_linker
750 0x10000000, // default_text_segment_address
751 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
752 4 * 1024, // common_pagesize (overridable by -z common-page-size)
753 false, // isolate_execinstr
755 elfcpp::SHN_UNDEF
, // small_common_shndx
756 elfcpp::SHN_UNDEF
, // large_common_shndx
757 0, // small_common_section_flags
758 0, // large_common_section_flags
759 NULL
, // attributes_section
760 NULL
// attributes_vendor
764 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
767 false, // is_big_endian
768 elfcpp::EM_PPC64
, // machine_code
769 false, // has_make_symbol
770 false, // has_resolve
771 false, // has_code_fill
772 true, // is_default_stack_executable
773 false, // can_icf_inline_merge_sections
775 "/usr/lib/ld.so.1", // dynamic_linker
776 0x10000000, // default_text_segment_address
777 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
778 4 * 1024, // common_pagesize (overridable by -z common-page-size)
779 false, // isolate_execinstr
781 elfcpp::SHN_UNDEF
, // small_common_shndx
782 elfcpp::SHN_UNDEF
, // large_common_shndx
783 0, // small_common_section_flags
784 0, // large_common_section_flags
785 NULL
, // attributes_section
786 NULL
// attributes_vendor
790 is_branch_reloc(unsigned int r_type
)
792 return (r_type
== elfcpp::R_POWERPC_REL24
793 || r_type
== elfcpp::R_PPC_PLTREL24
794 || r_type
== elfcpp::R_PPC_LOCAL24PC
795 || r_type
== elfcpp::R_POWERPC_REL14
796 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
797 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
798 || r_type
== elfcpp::R_POWERPC_ADDR24
799 || r_type
== elfcpp::R_POWERPC_ADDR14
800 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
801 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
804 // If INSN is an opcode that may be used with an @tls operand, return
805 // the transformed insn for TLS optimisation, otherwise return 0. If
806 // REG is non-zero only match an insn with RB or RA equal to REG.
808 at_tls_transform(uint32_t insn
, unsigned int reg
)
810 if ((insn
& (0x3f << 26)) != 31 << 26)
814 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
815 rtra
= insn
& ((1 << 26) - (1 << 16));
816 else if (((insn
>> 16) & 0x1f) == reg
)
817 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
821 if ((insn
& (0x3ff << 1)) == 266 << 1)
824 else if ((insn
& (0x1f << 1)) == 23 << 1
825 && ((insn
& (0x1f << 6)) < 14 << 6
826 || ((insn
& (0x1f << 6)) >= 16 << 6
827 && (insn
& (0x1f << 6)) < 24 << 6)))
828 // load and store indexed -> dform
829 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
830 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
831 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
832 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
833 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
835 insn
= (58 << 26) | 2;
842 // Modified version of symtab.h class Symbol member
843 // Given a direct absolute or pc-relative static relocation against
844 // the global symbol, this function returns whether a dynamic relocation
849 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
851 // No dynamic relocations in a static link!
852 if (parameters
->doing_static_link())
855 // A reference to an undefined symbol from an executable should be
856 // statically resolved to 0, and does not need a dynamic relocation.
857 // This matches gnu ld behavior.
858 if (gsym
->is_undefined() && !parameters
->options().shared())
861 // A reference to an absolute symbol does not need a dynamic relocation.
862 if (gsym
->is_absolute())
865 // An absolute reference within a position-independent output file
866 // will need a dynamic relocation.
867 if ((flags
& Symbol::ABSOLUTE_REF
)
868 && parameters
->options().output_is_position_independent())
871 // A function call that can branch to a local PLT entry does not need
872 // a dynamic relocation.
873 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
876 // A reference to any PLT entry in a non-position-independent executable
877 // does not need a dynamic relocation.
878 // Except due to having function descriptors on powerpc64 we don't define
879 // functions to their plt code in an executable, so this doesn't apply.
881 && !parameters
->options().output_is_position_independent()
882 && gsym
->has_plt_offset())
885 // A reference to a symbol defined in a dynamic object or to a
886 // symbol that is preemptible will need a dynamic relocation.
887 if (gsym
->is_from_dynobj()
888 || gsym
->is_undefined()
889 || gsym
->is_preemptible())
892 // For all other cases, return FALSE.
896 // Modified version of symtab.h class Symbol member
897 // Whether we should use the PLT offset associated with a symbol for
898 // a relocation. FLAGS is a set of Reference_flags.
902 use_plt_offset(const Symbol
* gsym
, int flags
)
904 // If the symbol doesn't have a PLT offset, then naturally we
905 // don't want to use it.
906 if (!gsym
->has_plt_offset())
909 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
910 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
913 // If we are going to generate a dynamic relocation, then we will
914 // wind up using that, so no need to use the PLT entry.
915 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
918 // If the symbol is from a dynamic object, we need to use the PLT
920 if (gsym
->is_from_dynobj())
923 // If we are generating a shared object, and gsym symbol is
924 // undefined or preemptible, we need to use the PLT entry.
925 if (parameters
->options().shared()
926 && (gsym
->is_undefined() || gsym
->is_preemptible()))
929 // If gsym is a call to a weak undefined symbol, we need to use
930 // the PLT entry; the symbol may be defined by a library loaded
932 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
935 // Otherwise we can use the regular definition.
939 template<int size
, bool big_endian
>
940 class Powerpc_relocate_functions
957 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
958 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
960 template<int valsize
>
962 has_overflow_signed(Address value
)
964 // limit = 1 << (valsize - 1) without shift count exceeding size of type
965 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
966 limit
<<= ((valsize
- 1) >> 1);
967 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
968 return value
+ limit
> (limit
<< 1) - 1;
971 template<int valsize
>
973 has_overflow_bitfield(Address value
)
975 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
976 limit
<<= ((valsize
- 1) >> 1);
977 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
978 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
981 template<int valsize
>
983 overflowed(Address value
, Overflow_check overflow
)
985 if (overflow
== CHECK_SIGNED
)
987 if (has_overflow_signed
<valsize
>(value
))
988 return STATUS_OVERFLOW
;
990 else if (overflow
== CHECK_BITFIELD
)
992 if (has_overflow_bitfield
<valsize
>(value
))
993 return STATUS_OVERFLOW
;
998 // Do a simple RELA relocation
999 template<int valsize
>
1000 static inline Status
1001 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1003 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1004 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1005 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1006 return overflowed
<valsize
>(value
, overflow
);
1009 template<int valsize
>
1010 static inline Status
1011 rela(unsigned char* view
,
1012 unsigned int right_shift
,
1013 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1015 Overflow_check overflow
)
1017 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1018 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1019 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1020 Valtype reloc
= value
>> right_shift
;
1023 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1024 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1027 // Do a simple RELA relocation, unaligned.
1028 template<int valsize
>
1029 static inline Status
1030 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1032 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1033 return overflowed
<valsize
>(value
, overflow
);
1036 template<int valsize
>
1037 static inline Status
1038 rela_ua(unsigned char* view
,
1039 unsigned int right_shift
,
1040 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1042 Overflow_check overflow
)
1044 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1046 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1047 Valtype reloc
= value
>> right_shift
;
1050 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1051 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1055 // R_PPC64_ADDR64: (Symbol + Addend)
1057 addr64(unsigned char* view
, Address value
)
1058 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1060 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1062 addr64_u(unsigned char* view
, Address value
)
1063 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1065 // R_POWERPC_ADDR32: (Symbol + Addend)
1066 static inline Status
1067 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1068 { return This::template rela
<32>(view
, value
, overflow
); }
1070 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1071 static inline Status
1072 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1073 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1075 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1076 static inline Status
1077 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1079 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1080 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1081 stat
= STATUS_OVERFLOW
;
1085 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1086 static inline Status
1087 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1088 { return This::template rela
<16>(view
, value
, overflow
); }
1090 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1091 static inline Status
1092 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1093 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1095 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1096 static inline Status
1097 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1099 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1100 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1101 stat
= STATUS_OVERFLOW
;
1105 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1107 addr16_hi(unsigned char* view
, Address value
)
1108 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1110 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1112 addr16_ha(unsigned char* view
, Address value
)
1113 { This::addr16_hi(view
, value
+ 0x8000); }
1115 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1117 addr16_hi2(unsigned char* view
, Address value
)
1118 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1120 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1122 addr16_ha2(unsigned char* view
, Address value
)
1123 { This::addr16_hi2(view
, value
+ 0x8000); }
1125 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1127 addr16_hi3(unsigned char* view
, Address value
)
1128 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1130 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1132 addr16_ha3(unsigned char* view
, Address value
)
1133 { This::addr16_hi3(view
, value
+ 0x8000); }
1135 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1136 static inline Status
1137 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1139 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1140 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1141 stat
= STATUS_OVERFLOW
;
1146 // Stash away the index of .got2 or .opd in a relocatable object, if
1147 // such a section exists.
1149 template<int size
, bool big_endian
>
1151 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1152 Read_symbols_data
* sd
)
1154 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1155 const unsigned char* namesu
= sd
->section_names
->data();
1156 const char* names
= reinterpret_cast<const char*>(namesu
);
1157 section_size_type names_size
= sd
->section_names_size
;
1158 const unsigned char* s
;
1160 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1161 names
, names_size
, NULL
);
1164 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1165 this->special_
= ndx
;
1167 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1170 // Examine .rela.opd to build info about function entry points.
1172 template<int size
, bool big_endian
>
1174 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1176 const unsigned char* prelocs
,
1177 const unsigned char* plocal_syms
)
1181 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1183 const int reloc_size
1184 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1185 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1187 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1189 Reltype
reloc(prelocs
);
1190 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1191 = reloc
.get_r_info();
1192 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1193 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1195 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1196 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1199 if (r_sym
< this->local_symbol_count())
1201 typename
elfcpp::Sym
<size
, big_endian
>
1202 lsym(plocal_syms
+ r_sym
* sym_size
);
1203 shndx
= lsym
.get_st_shndx();
1204 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1205 value
= lsym
.get_st_value();
1208 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1210 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1211 value
+ reloc
.get_r_addend());
1217 template<int size
, bool big_endian
>
1219 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1221 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1224 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1225 p
!= rd
->relocs
.end();
1228 if (p
->data_shndx
== this->opd_shndx())
1230 this->init_opd(this->section_size(this->opd_shndx()));
1231 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1232 rd
->local_symbols
->data());
1239 // Set up PowerPC target specific relobj.
1241 template<int size
, bool big_endian
>
1243 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1244 const std::string
& name
,
1245 Input_file
* input_file
,
1246 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1248 int et
= ehdr
.get_e_type();
1249 // ET_EXEC files are valid input for --just-symbols/-R,
1250 // and we treat them as relocatable objects.
1251 if (et
== elfcpp::ET_REL
1252 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1254 Powerpc_relobj
<size
, big_endian
>* obj
=
1255 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1259 else if (et
== elfcpp::ET_DYN
)
1261 Sized_dynobj
<size
, big_endian
>* obj
=
1262 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1268 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1273 template<int size
, bool big_endian
>
1274 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1277 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1278 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1280 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1281 : Output_data_got
<size
, big_endian
>(),
1282 symtab_(symtab
), layout_(layout
),
1283 header_ent_cnt_(size
== 32 ? 3 : 1),
1284 header_index_(size
== 32 ? 0x2000 : 0)
1289 // Create a new GOT entry and return its offset.
1291 add_got_entry(Got_entry got_entry
)
1293 this->reserve_ent();
1294 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1297 // Create a pair of new GOT entries and return the offset of the first.
1299 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1301 this->reserve_ent(2);
1302 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1307 add_constant_pair(Valtype c1
, Valtype c2
)
1309 this->reserve_ent(2);
1310 unsigned int got_offset
= this->add_constant(c1
);
1311 this->add_constant(c2
);
1315 // Offset of _GLOBAL_OFFSET_TABLE_.
1319 return this->got_offset(this->header_index_
);
1322 // Offset of base used to access the GOT/TOC.
1323 // The got/toc pointer reg will be set to this value.
1324 typename
elfcpp::Elf_types
<size
>::Elf_Off
1325 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1328 return this->g_o_t();
1330 return (this->output_section()->address()
1331 + object
->toc_base_offset()
1335 // Ensure our GOT has a header.
1337 set_final_data_size()
1339 if (this->header_ent_cnt_
!= 0)
1340 this->make_header();
1341 Output_data_got
<size
, big_endian
>::set_final_data_size();
1344 // First word of GOT header needs some values that are not
1345 // handled by Output_data_got so poke them in here.
1346 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1348 do_write(Output_file
* of
)
1350 this->replace_constant(this->header_index_
,
1352 ? this->layout_
->dynamic_section()->address()
1353 : this->output_section()->address() + 0x8000));
1355 Output_data_got
<size
, big_endian
>::do_write(of
);
1360 reserve_ent(unsigned int cnt
= 1)
1362 if (this->header_ent_cnt_
== 0)
1364 if (this->num_entries() + cnt
> this->header_index_
)
1365 this->make_header();
1371 this->header_ent_cnt_
= 0;
1372 this->header_index_
= this->num_entries();
1375 Output_data_got
<size
, big_endian
>::add_constant(0);
1376 Output_data_got
<size
, big_endian
>::add_constant(0);
1377 Output_data_got
<size
, big_endian
>::add_constant(0);
1379 // Define _GLOBAL_OFFSET_TABLE_ at the header
1380 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1381 Symbol_table::PREDEFINED
,
1382 this, this->g_o_t(), 0,
1389 Output_data_got
<size
, big_endian
>::add_constant(0);
1392 // Stashed pointers.
1393 Symbol_table
* symtab_
;
1397 unsigned int header_ent_cnt_
;
1398 // GOT header index.
1399 unsigned int header_index_
;
1402 // Get the GOT section, creating it if necessary.
1404 template<int size
, bool big_endian
>
1405 Output_data_got_powerpc
<size
, big_endian
>*
1406 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1409 if (this->got_
== NULL
)
1411 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1414 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1416 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1417 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1418 this->got_
, ORDER_DATA
, false);
1424 // Get the dynamic reloc section, creating it if necessary.
1426 template<int size
, bool big_endian
>
1427 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1428 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1430 if (this->rela_dyn_
== NULL
)
1432 gold_assert(layout
!= NULL
);
1433 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1434 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1435 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1436 ORDER_DYNAMIC_RELOCS
, false);
1438 return this->rela_dyn_
;
1441 // A class to handle the PLT data.
1443 template<int size
, bool big_endian
>
1444 class Output_data_plt_powerpc
: public Output_section_data_build
1447 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1448 size
, big_endian
> Reloc_section
;
1450 Output_data_plt_powerpc(Layout
*, Target_powerpc
<size
, big_endian
>*);
1452 // Add an entry to the PLT.
1456 // Return the .rela.plt section data.
1457 const Reloc_section
*
1463 // Return the number of PLT entries.
1467 return ((this->current_data_size() - initial_plt_entry_size
)
1471 // Return the offset of the first non-reserved PLT entry.
1473 first_plt_entry_offset()
1474 { return initial_plt_entry_size
; }
1476 // Return the size of a PLT entry.
1478 get_plt_entry_size()
1479 { return plt_entry_size
; }
1483 do_adjust_output_section(Output_section
* os
)
1488 // Write to a map file.
1490 do_print_to_mapfile(Mapfile
* mapfile
) const
1491 { mapfile
->print_output_data(this, _("** PLT")); }
1494 // The size of an entry in the PLT.
1495 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1496 // The size of the first reserved entry.
1497 static const int initial_plt_entry_size
= size
== 32 ? 0 : 24;
1499 // Write out the PLT data.
1501 do_write(Output_file
*);
1503 // The reloc section.
1504 Reloc_section
* rel_
;
1505 // Allows access to .glink for do_write.
1506 Target_powerpc
<size
, big_endian
>* targ_
;
1509 // Create the PLT section.
1511 template<int size
, bool big_endian
>
1512 Output_data_plt_powerpc
<size
, big_endian
>::Output_data_plt_powerpc(
1514 Target_powerpc
<size
, big_endian
>* targ
)
1515 : Output_section_data_build(size
== 32 ? 4 : 8),
1518 this->rel_
= new Reloc_section(false);
1519 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1520 elfcpp::SHF_ALLOC
, this->rel_
,
1521 ORDER_DYNAMIC_PLT_RELOCS
, false);
1524 // Add an entry to the PLT.
1526 template<int size
, bool big_endian
>
1528 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1530 if (!gsym
->has_plt_offset())
1532 off_t off
= this->current_data_size();
1535 off
+= initial_plt_entry_size
;
1536 gsym
->set_plt_offset(off
);
1537 gsym
->set_needs_dynsym_entry();
1538 this->rel_
->add_global(gsym
, elfcpp::R_POWERPC_JMP_SLOT
, this, off
, 0);
1539 off
+= plt_entry_size
;
1540 this->set_current_data_size(off
);
1544 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1545 static const uint32_t add_3_3_2
= 0x7c631214;
1546 static const uint32_t add_3_3_13
= 0x7c636a14;
1547 static const uint32_t add_11_0_11
= 0x7d605a14;
1548 static const uint32_t add_12_2_11
= 0x7d825a14;
1549 static const uint32_t addi_11_11
= 0x396b0000;
1550 static const uint32_t addi_12_12
= 0x398c0000;
1551 static const uint32_t addi_2_2
= 0x38420000;
1552 static const uint32_t addi_3_2
= 0x38620000;
1553 static const uint32_t addi_3_3
= 0x38630000;
1554 static const uint32_t addis_0_2
= 0x3c020000;
1555 static const uint32_t addis_0_13
= 0x3c0d0000;
1556 static const uint32_t addis_11_11
= 0x3d6b0000;
1557 static const uint32_t addis_11_30
= 0x3d7e0000;
1558 static const uint32_t addis_12_12
= 0x3d8c0000;
1559 static const uint32_t addis_12_2
= 0x3d820000;
1560 static const uint32_t addis_3_2
= 0x3c620000;
1561 static const uint32_t addis_3_13
= 0x3c6d0000;
1562 static const uint32_t b
= 0x48000000;
1563 static const uint32_t bcl_20_31
= 0x429f0005;
1564 static const uint32_t bctr
= 0x4e800420;
1565 static const uint32_t blrl
= 0x4e800021;
1566 static const uint32_t cror_15_15_15
= 0x4def7b82;
1567 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1568 static const uint32_t ld_11_12
= 0xe96c0000;
1569 static const uint32_t ld_11_2
= 0xe9620000;
1570 static const uint32_t ld_2_1
= 0xe8410000;
1571 static const uint32_t ld_2_11
= 0xe84b0000;
1572 static const uint32_t ld_2_12
= 0xe84c0000;
1573 static const uint32_t ld_2_2
= 0xe8420000;
1574 static const uint32_t li_0_0
= 0x38000000;
1575 static const uint32_t lis_0_0
= 0x3c000000;
1576 static const uint32_t lis_11
= 0x3d600000;
1577 static const uint32_t lis_12
= 0x3d800000;
1578 static const uint32_t lwz_0_12
= 0x800c0000;
1579 static const uint32_t lwz_11_11
= 0x816b0000;
1580 static const uint32_t lwz_11_30
= 0x817e0000;
1581 static const uint32_t lwz_12_12
= 0x818c0000;
1582 static const uint32_t lwzu_0_12
= 0x840c0000;
1583 static const uint32_t mflr_0
= 0x7c0802a6;
1584 static const uint32_t mflr_11
= 0x7d6802a6;
1585 static const uint32_t mflr_12
= 0x7d8802a6;
1586 static const uint32_t mtctr_0
= 0x7c0903a6;
1587 static const uint32_t mtctr_11
= 0x7d6903a6;
1588 static const uint32_t mtlr_0
= 0x7c0803a6;
1589 static const uint32_t mtlr_12
= 0x7d8803a6;
1590 static const uint32_t nop
= 0x60000000;
1591 static const uint32_t ori_0_0_0
= 0x60000000;
1592 static const uint32_t std_2_1
= 0xf8410000;
1593 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1595 // Write out the PLT.
1597 template<int size
, bool big_endian
>
1599 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1603 const off_t offset
= this->offset();
1604 const section_size_type oview_size
1605 = convert_to_section_size_type(this->data_size());
1606 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1607 unsigned char* pov
= oview
;
1608 unsigned char* endpov
= oview
+ oview_size
;
1610 // The address the .glink branch table
1611 const Output_data_glink
<size
, big_endian
>* glink
1612 = this->targ_
->glink_section();
1613 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1614 = glink
->address() + glink
->pltresolve();
1616 while (pov
< endpov
)
1618 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1623 of
->write_output_view(offset
, oview_size
, oview
);
1627 // Create the PLT section.
1629 template<int size
, bool big_endian
>
1631 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1633 if (this->plt_
== NULL
)
1635 if (this->glink_
== NULL
)
1636 make_glink_section(layout
);
1638 // Ensure that .rela.dyn always appears before .rela.plt This is
1639 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1640 // needs to include .rela.plt in it's range.
1641 this->rela_dyn_section(layout
);
1643 this->plt_
= new Output_data_plt_powerpc
<size
, big_endian
>(layout
, this);
1644 layout
->add_output_section_data(".plt",
1646 ? elfcpp::SHT_PROGBITS
1647 : elfcpp::SHT_NOBITS
),
1648 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1657 // A class to handle .glink.
1659 template<int size
, bool big_endian
>
1660 class Output_data_glink
: public Output_section_data
1663 static const int pltresolve_size
= 16*4;
1665 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1669 add_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1670 const Sized_relobj
<size
, big_endian
>*);
1673 find_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1674 const Sized_relobj
<size
, big_endian
>*) const;
1677 glink_entry_size() const
1682 // FIXME: We should be using multiple glink sections for
1683 // stubs to support > 33M applications.
1690 return this->pltresolve_
;
1694 // Write to a map file.
1696 do_print_to_mapfile(Mapfile
* mapfile
) const
1697 { mapfile
->print_output_data(this, _("** glink")); }
1701 set_final_data_size();
1705 do_write(Output_file
*);
1710 Glink_sym_ent(const Symbol
* sym
,
1711 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1712 const Sized_relobj
<size
, big_endian
>* object
)
1713 : sym_(sym
), addend_(0), object_(0)
1716 this->addend_
= reloc
.get_r_addend();
1717 else if (parameters
->options().output_is_position_independent()
1718 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1719 == elfcpp::R_PPC_PLTREL24
))
1721 this->addend_
= reloc
.get_r_addend();
1722 if (this->addend_
!= 0)
1723 this->object_
= object
;
1727 bool operator==(const Glink_sym_ent
& that
) const
1729 return (this->sym_
== that
.sym_
1730 && this->object_
== that
.object_
1731 && this->addend_
== that
.addend_
);
1735 unsigned int addend_
;
1736 const Sized_relobj
<size
, big_endian
>* object_
;
1739 class Glink_sym_ent_hash
1742 size_t operator()(const Glink_sym_ent
& ent
) const
1744 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1745 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1750 // Map sym/object/addend to index.
1751 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1752 Glink_sym_ent_hash
> Glink_entries
;
1753 Glink_entries glink_entries_
;
1755 // Offset of pltresolve stub (actually, branch table for 32-bit)
1758 // Allows access to .got and .plt for do_write.
1759 Target_powerpc
<size
, big_endian
>* targ_
;
1762 // Create the glink section.
1764 template<int size
, bool big_endian
>
1765 Output_data_glink
<size
, big_endian
>::Output_data_glink(
1766 Target_powerpc
<size
, big_endian
>* targ
)
1767 : Output_section_data(16),
1768 pltresolve_(0), targ_(targ
)
1772 // Add an entry to glink, if we do not already have one for this
1773 // sym/object/addend combo.
1775 template<int size
, bool big_endian
>
1777 Output_data_glink
<size
, big_endian
>::add_entry(
1779 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1780 const Sized_relobj
<size
, big_endian
>* object
)
1782 Glink_sym_ent
ent(gsym
, reloc
, object
);
1783 unsigned int indx
= this->glink_entries_
.size();
1784 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
1787 template<int size
, bool big_endian
>
1789 Output_data_glink
<size
, big_endian
>::find_entry(
1791 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1792 const Sized_relobj
<size
, big_endian
>* object
) const
1794 Glink_sym_ent
ent(gsym
, reloc
, object
);
1795 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
1796 gold_assert(p
!= this->glink_entries_
.end());
1800 template<int size
, bool big_endian
>
1802 Output_data_glink
<size
, big_endian
>::set_final_data_size()
1804 unsigned int count
= this->glink_entries_
.size();
1805 off_t total
= count
;
1812 this->pltresolve_
= total
;
1814 // space for branch table
1815 total
+= 4 * (count
- 1);
1817 total
+= -total
& 15;
1818 total
+= this->pltresolve_size
;
1823 this->pltresolve_
= total
;
1824 total
+= this->pltresolve_size
;
1826 // space for branch table
1829 total
+= 4 * (count
- 0x8000);
1833 this->set_data_size(total
);
1836 static inline uint32_t
1842 static inline uint32_t
1848 static inline uint32_t
1851 return hi(a
+ 0x8000);
1854 template<bool big_endian
>
1856 write_insn(unsigned char* p
, uint32_t v
)
1858 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
1861 // Write out .glink.
1863 template<int size
, bool big_endian
>
1865 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
1867 const off_t off
= this->offset();
1868 const section_size_type oview_size
=
1869 convert_to_section_size_type(this->data_size());
1870 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1873 // The base address of the .plt section.
1874 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1875 Address plt_base
= this->targ_
->plt_section()->address();
1877 const Output_data_got_powerpc
<size
, big_endian
>* got
1878 = this->targ_
->got_section();
1882 Address got_os_addr
= got
->output_section()->address();
1884 // Write out call stubs.
1885 typename
Glink_entries::const_iterator g
;
1886 for (g
= this->glink_entries_
.begin();
1887 g
!= this->glink_entries_
.end();
1890 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1891 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1892 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1893 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
1894 Address pltoff
= plt_addr
- got_addr
;
1896 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
1897 gold_error(_("%s: linkage table error against `%s'"),
1898 g
->first
.object_
->name().c_str(),
1899 g
->first
.sym_
->demangled_name().c_str());
1901 p
= oview
+ g
->second
* this->glink_entry_size();
1902 if (ha(pltoff
) != 0)
1904 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
1905 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1906 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
1907 if (ha(pltoff
+ 16) != ha(pltoff
))
1909 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
1912 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1913 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
1914 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
1915 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1919 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1920 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
1921 if (ha(pltoff
+ 16) != ha(pltoff
))
1923 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
1926 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1927 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
1928 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
1929 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1933 // Write pltresolve stub.
1934 p
= oview
+ this->pltresolve_
;
1935 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
1936 Address pltoff
= plt_base
- after_bcl
;
1938 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
1940 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
1941 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
1942 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
1943 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
1944 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
1945 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
1946 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
1947 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
1948 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1949 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
1950 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1951 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
1952 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1954 // Write lazy link call stubs.
1956 while (p
< oview
+ oview_size
)
1960 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
1964 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
1965 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
1967 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
1968 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
1974 // The address of _GLOBAL_OFFSET_TABLE_.
1975 Address g_o_t
= got
->address() + got
->g_o_t();
1977 // Write out call stubs.
1978 typename
Glink_entries::const_iterator g
;
1979 for (g
= this->glink_entries_
.begin();
1980 g
!= this->glink_entries_
.end();
1983 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1985 const Address invalid_address
= static_cast<Address
>(-1);
1987 p
= oview
+ g
->second
* this->glink_entry_size();
1988 if (parameters
->options().output_is_position_independent())
1990 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
1991 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1994 unsigned int got2
= object
->got2_shndx();
1995 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
1996 gold_assert(got_addr
!= invalid_address
);
1997 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
1998 + g
->first
.addend_
);
2003 Address pltoff
= plt_addr
- got_addr
;
2004 if (ha(pltoff
) == 0)
2006 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
2007 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
2008 write_insn
<big_endian
>(p
+ 8, bctr
);
2012 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
2013 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
2014 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2015 write_insn
<big_endian
>(p
+ 12, bctr
);
2020 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
2021 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
2022 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2023 write_insn
<big_endian
>(p
+ 12, bctr
);
2027 // Write out pltresolve branch table.
2028 p
= oview
+ this->pltresolve_
;
2029 unsigned int the_end
= oview_size
- this->pltresolve_size
;
2030 unsigned char* end_p
= oview
+ the_end
;
2031 while (p
< end_p
- 8 * 4)
2032 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
2034 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2036 // Write out pltresolve call stub.
2037 if (parameters
->options().output_is_position_independent())
2039 Address res0_off
= this->pltresolve_
;
2040 Address after_bcl_off
= the_end
+ 12;
2041 Address bcl_res0
= after_bcl_off
- res0_off
;
2043 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2044 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2045 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2046 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2047 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2048 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2049 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2051 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2053 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2054 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2056 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2057 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2061 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2062 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2064 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2065 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2066 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2067 write_insn
<big_endian
>(p
+ 52, bctr
);
2068 write_insn
<big_endian
>(p
+ 56, nop
);
2069 write_insn
<big_endian
>(p
+ 60, nop
);
2073 Address res0
= this->pltresolve_
+ this->address();
2075 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2076 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2077 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2078 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2080 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2081 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2082 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2083 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2084 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2085 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2087 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2088 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2089 write_insn
<big_endian
>(p
+ 32, bctr
);
2090 write_insn
<big_endian
>(p
+ 36, nop
);
2091 write_insn
<big_endian
>(p
+ 40, nop
);
2092 write_insn
<big_endian
>(p
+ 44, nop
);
2093 write_insn
<big_endian
>(p
+ 48, nop
);
2094 write_insn
<big_endian
>(p
+ 52, nop
);
2095 write_insn
<big_endian
>(p
+ 56, nop
);
2096 write_insn
<big_endian
>(p
+ 60, nop
);
2101 of
->write_output_view(off
, oview_size
, oview
);
2104 // Create the glink section.
2106 template<int size
, bool big_endian
>
2108 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2110 if (this->glink_
== NULL
)
2112 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2113 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2114 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2115 this->glink_
, ORDER_TEXT
, false);
2119 // Create a PLT entry for a global symbol.
2121 template<int size
, bool big_endian
>
2123 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2126 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2127 const Sized_relobj
<size
, big_endian
>* object
)
2129 if (this->plt_
== NULL
)
2130 this->make_plt_section(layout
);
2132 this->plt_
->add_entry(gsym
);
2134 this->glink_
->add_entry(gsym
, reloc
, object
);
2137 // Return the number of entries in the PLT.
2139 template<int size
, bool big_endian
>
2141 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2143 if (this->plt_
== NULL
)
2145 return this->plt_
->entry_count();
2148 // Return the offset of the first non-reserved PLT entry.
2150 template<int size
, bool big_endian
>
2152 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2154 return Output_data_plt_powerpc
<size
, big_endian
>::first_plt_entry_offset();
2157 // Return the size of each PLT entry.
2159 template<int size
, bool big_endian
>
2161 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2163 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2166 // Create a GOT entry for local dynamic __tls_get_addr calls.
2168 template<int size
, bool big_endian
>
2170 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2171 Symbol_table
* symtab
,
2173 Sized_relobj_file
<size
, big_endian
>* object
)
2175 if (this->tlsld_got_offset_
== -1U)
2177 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2178 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2179 Output_data_got_powerpc
<size
, big_endian
>* got
2180 = this->got_section(symtab
, layout
);
2181 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2182 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2184 this->tlsld_got_offset_
= got_offset
;
2186 return this->tlsld_got_offset_
;
2189 // Get the Reference_flags for a particular relocation.
2191 template<int size
, bool big_endian
>
2193 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2197 case elfcpp::R_POWERPC_NONE
:
2198 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2199 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2200 case elfcpp::R_PPC64_TOC
:
2201 // No symbol reference.
2204 case elfcpp::R_PPC64_ADDR64
:
2205 case elfcpp::R_PPC64_UADDR64
:
2206 case elfcpp::R_POWERPC_ADDR32
:
2207 case elfcpp::R_POWERPC_UADDR32
:
2208 case elfcpp::R_POWERPC_ADDR16
:
2209 case elfcpp::R_POWERPC_UADDR16
:
2210 case elfcpp::R_POWERPC_ADDR16_LO
:
2211 case elfcpp::R_POWERPC_ADDR16_HI
:
2212 case elfcpp::R_POWERPC_ADDR16_HA
:
2213 return Symbol::ABSOLUTE_REF
;
2215 case elfcpp::R_POWERPC_ADDR24
:
2216 case elfcpp::R_POWERPC_ADDR14
:
2217 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2218 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2219 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2221 case elfcpp::R_POWERPC_REL32
:
2222 case elfcpp::R_PPC_LOCAL24PC
:
2223 case elfcpp::R_POWERPC_REL16
:
2224 case elfcpp::R_POWERPC_REL16_LO
:
2225 case elfcpp::R_POWERPC_REL16_HI
:
2226 case elfcpp::R_POWERPC_REL16_HA
:
2227 return Symbol::RELATIVE_REF
;
2229 case elfcpp::R_POWERPC_REL24
:
2230 case elfcpp::R_PPC_PLTREL24
:
2231 case elfcpp::R_POWERPC_REL14
:
2232 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2233 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2234 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2236 case elfcpp::R_POWERPC_GOT16
:
2237 case elfcpp::R_POWERPC_GOT16_LO
:
2238 case elfcpp::R_POWERPC_GOT16_HI
:
2239 case elfcpp::R_POWERPC_GOT16_HA
:
2240 case elfcpp::R_PPC64_TOC16
:
2241 case elfcpp::R_PPC64_TOC16_LO
:
2242 case elfcpp::R_PPC64_TOC16_HI
:
2243 case elfcpp::R_PPC64_TOC16_HA
:
2244 case elfcpp::R_PPC64_TOC16_DS
:
2245 case elfcpp::R_PPC64_TOC16_LO_DS
:
2247 return Symbol::ABSOLUTE_REF
;
2249 case elfcpp::R_POWERPC_GOT_TPREL16
:
2250 case elfcpp::R_POWERPC_TLS
:
2251 return Symbol::TLS_REF
;
2253 case elfcpp::R_POWERPC_COPY
:
2254 case elfcpp::R_POWERPC_GLOB_DAT
:
2255 case elfcpp::R_POWERPC_JMP_SLOT
:
2256 case elfcpp::R_POWERPC_RELATIVE
:
2257 case elfcpp::R_POWERPC_DTPMOD
:
2259 // Not expected. We will give an error later.
2264 // Report an unsupported relocation against a local symbol.
2266 template<int size
, bool big_endian
>
2268 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2269 Sized_relobj_file
<size
, big_endian
>* object
,
2270 unsigned int r_type
)
2272 gold_error(_("%s: unsupported reloc %u against local symbol"),
2273 object
->name().c_str(), r_type
);
2276 // We are about to emit a dynamic relocation of type R_TYPE. If the
2277 // dynamic linker does not support it, issue an error.
2279 template<int size
, bool big_endian
>
2281 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2282 unsigned int r_type
)
2284 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
2286 // These are the relocation types supported by glibc for both 32-bit
2287 // and 64-bit powerpc.
2290 case elfcpp::R_POWERPC_NONE
:
2291 case elfcpp::R_POWERPC_RELATIVE
:
2292 case elfcpp::R_POWERPC_GLOB_DAT
:
2293 case elfcpp::R_POWERPC_DTPMOD
:
2294 case elfcpp::R_POWERPC_DTPREL
:
2295 case elfcpp::R_POWERPC_TPREL
:
2296 case elfcpp::R_POWERPC_JMP_SLOT
:
2297 case elfcpp::R_POWERPC_COPY
:
2298 case elfcpp::R_POWERPC_IRELATIVE
:
2299 case elfcpp::R_POWERPC_ADDR32
:
2300 case elfcpp::R_POWERPC_UADDR32
:
2301 case elfcpp::R_POWERPC_ADDR24
:
2302 case elfcpp::R_POWERPC_ADDR16
:
2303 case elfcpp::R_POWERPC_UADDR16
:
2304 case elfcpp::R_POWERPC_ADDR16_LO
:
2305 case elfcpp::R_POWERPC_ADDR16_HI
:
2306 case elfcpp::R_POWERPC_ADDR16_HA
:
2307 case elfcpp::R_POWERPC_ADDR14
:
2308 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2309 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2310 case elfcpp::R_POWERPC_REL32
:
2311 case elfcpp::R_POWERPC_REL24
:
2312 case elfcpp::R_POWERPC_TPREL16
:
2313 case elfcpp::R_POWERPC_TPREL16_LO
:
2314 case elfcpp::R_POWERPC_TPREL16_HI
:
2315 case elfcpp::R_POWERPC_TPREL16_HA
:
2326 // These are the relocation types supported only on 64-bit.
2327 case elfcpp::R_PPC64_ADDR64
:
2328 case elfcpp::R_PPC64_UADDR64
:
2329 case elfcpp::R_PPC64_JMP_IREL
:
2330 case elfcpp::R_PPC64_ADDR16_DS
:
2331 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2332 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2333 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2334 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2335 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2336 case elfcpp::R_PPC64_REL64
:
2337 case elfcpp::R_POWERPC_ADDR30
:
2338 case elfcpp::R_PPC64_TPREL16_DS
:
2339 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2340 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2341 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2342 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2343 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2354 // These are the relocation types supported only on 32-bit.
2355 // ??? glibc ld.so doesn't need to support these.
2356 case elfcpp::R_POWERPC_DTPREL16
:
2357 case elfcpp::R_POWERPC_DTPREL16_LO
:
2358 case elfcpp::R_POWERPC_DTPREL16_HI
:
2359 case elfcpp::R_POWERPC_DTPREL16_HA
:
2367 // This prevents us from issuing more than one error per reloc
2368 // section. But we can still wind up issuing more than one
2369 // error per object file.
2370 if (this->issued_non_pic_error_
)
2372 gold_assert(parameters
->options().output_is_position_independent());
2373 object
->error(_("requires unsupported dynamic reloc; "
2374 "recompile with -fPIC"));
2375 this->issued_non_pic_error_
= true;
2379 // Scan a relocation for a local symbol.
2381 template<int size
, bool big_endian
>
2383 Target_powerpc
<size
, big_endian
>::Scan::local(
2384 Symbol_table
* symtab
,
2386 Target_powerpc
<size
, big_endian
>* target
,
2387 Sized_relobj_file
<size
, big_endian
>* object
,
2388 unsigned int data_shndx
,
2389 Output_section
* output_section
,
2390 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2391 unsigned int r_type
,
2392 const elfcpp::Sym
<size
, big_endian
>& /* lsym */,
2395 Powerpc_relobj
<size
, big_endian
>* ppc_object
2396 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2401 && data_shndx
== ppc_object
->opd_shndx()
2402 && r_type
== elfcpp::R_PPC64_ADDR64
)
2403 ppc_object
->set_opd_discard(reloc
.get_r_offset());
2409 case elfcpp::R_POWERPC_NONE
:
2410 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2411 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2412 case elfcpp::R_PPC64_TOCSAVE
:
2413 case elfcpp::R_PPC_EMB_MRKREF
:
2414 case elfcpp::R_POWERPC_TLS
:
2417 case elfcpp::R_PPC64_TOC
:
2419 Output_data_got_powerpc
<size
, big_endian
>* got
2420 = target
->got_section(symtab
, layout
);
2421 if (parameters
->options().output_is_position_independent())
2423 Address off
= reloc
.get_r_offset();
2425 && data_shndx
== ppc_object
->opd_shndx()
2426 && ppc_object
->get_opd_discard(off
- 8))
2429 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2430 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
2431 rela_dyn
->add_output_section_relative(got
->output_section(),
2432 elfcpp::R_POWERPC_RELATIVE
,
2434 object
, data_shndx
, off
,
2435 symobj
->toc_base_offset());
2440 case elfcpp::R_PPC64_ADDR64
:
2441 case elfcpp::R_PPC64_UADDR64
:
2442 case elfcpp::R_POWERPC_ADDR32
:
2443 case elfcpp::R_POWERPC_UADDR32
:
2444 case elfcpp::R_POWERPC_ADDR24
:
2445 case elfcpp::R_POWERPC_ADDR16
:
2446 case elfcpp::R_POWERPC_ADDR16_LO
:
2447 case elfcpp::R_POWERPC_ADDR16_HI
:
2448 case elfcpp::R_POWERPC_ADDR16_HA
:
2449 case elfcpp::R_POWERPC_UADDR16
:
2450 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2451 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2452 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2453 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2454 case elfcpp::R_PPC64_ADDR16_DS
:
2455 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2456 case elfcpp::R_POWERPC_ADDR14
:
2457 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2458 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2459 // If building a shared library (or a position-independent
2460 // executable), we need to create a dynamic relocation for
2462 if (parameters
->options().output_is_position_independent())
2464 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2466 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2467 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2469 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2470 rela_dyn
->add_local_relative(object
, r_sym
,
2471 elfcpp::R_POWERPC_RELATIVE
,
2472 output_section
, data_shndx
,
2473 reloc
.get_r_offset(),
2474 reloc
.get_r_addend(), false);
2478 check_non_pic(object
, r_type
);
2479 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2480 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2481 data_shndx
, reloc
.get_r_offset(),
2482 reloc
.get_r_addend());
2487 case elfcpp::R_PPC64_REL64
:
2488 case elfcpp::R_POWERPC_REL32
:
2489 case elfcpp::R_POWERPC_REL24
:
2490 case elfcpp::R_PPC_LOCAL24PC
:
2491 case elfcpp::R_POWERPC_REL16
:
2492 case elfcpp::R_POWERPC_REL16_LO
:
2493 case elfcpp::R_POWERPC_REL16_HI
:
2494 case elfcpp::R_POWERPC_REL16_HA
:
2495 case elfcpp::R_POWERPC_REL14
:
2496 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2497 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2498 case elfcpp::R_POWERPC_SECTOFF
:
2499 case elfcpp::R_POWERPC_TPREL16
:
2500 case elfcpp::R_POWERPC_DTPREL16
:
2501 case elfcpp::R_POWERPC_SECTOFF_LO
:
2502 case elfcpp::R_POWERPC_TPREL16_LO
:
2503 case elfcpp::R_POWERPC_DTPREL16_LO
:
2504 case elfcpp::R_POWERPC_SECTOFF_HI
:
2505 case elfcpp::R_POWERPC_TPREL16_HI
:
2506 case elfcpp::R_POWERPC_DTPREL16_HI
:
2507 case elfcpp::R_POWERPC_SECTOFF_HA
:
2508 case elfcpp::R_POWERPC_TPREL16_HA
:
2509 case elfcpp::R_POWERPC_DTPREL16_HA
:
2510 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2511 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2512 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2513 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2514 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2515 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2516 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2517 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2518 case elfcpp::R_PPC64_TPREL16_DS
:
2519 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2520 case elfcpp::R_PPC64_DTPREL16_DS
:
2521 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2522 case elfcpp::R_PPC64_SECTOFF_DS
:
2523 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2524 case elfcpp::R_PPC64_TLSGD
:
2525 case elfcpp::R_PPC64_TLSLD
:
2528 case elfcpp::R_POWERPC_GOT16
:
2529 case elfcpp::R_POWERPC_GOT16_LO
:
2530 case elfcpp::R_POWERPC_GOT16_HI
:
2531 case elfcpp::R_POWERPC_GOT16_HA
:
2532 case elfcpp::R_PPC64_GOT16_DS
:
2533 case elfcpp::R_PPC64_GOT16_LO_DS
:
2535 // The symbol requires a GOT entry.
2536 Output_data_got_powerpc
<size
, big_endian
>* got
2537 = target
->got_section(symtab
, layout
);
2538 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2540 // If we are generating a shared object, we need to add a
2541 // dynamic relocation for this symbol's GOT entry.
2542 if (parameters
->options().output_is_position_independent())
2544 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2546 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2549 off
= got
->add_constant(0);
2550 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2551 rela_dyn
->add_local_relative(object
, r_sym
,
2552 elfcpp::R_POWERPC_RELATIVE
,
2553 got
, off
, 0, false);
2557 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2561 case elfcpp::R_PPC64_TOC16
:
2562 case elfcpp::R_PPC64_TOC16_LO
:
2563 case elfcpp::R_PPC64_TOC16_HI
:
2564 case elfcpp::R_PPC64_TOC16_HA
:
2565 case elfcpp::R_PPC64_TOC16_DS
:
2566 case elfcpp::R_PPC64_TOC16_LO_DS
:
2567 // We need a GOT section.
2568 target
->got_section(symtab
, layout
);
2571 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2572 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2573 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2574 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2576 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
2577 if (tls_type
== tls::TLSOPT_NONE
)
2579 Output_data_got_powerpc
<size
, big_endian
>* got
2580 = target
->got_section(symtab
, layout
);
2581 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2582 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2583 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
2584 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
2586 else if (tls_type
== tls::TLSOPT_TO_LE
)
2588 // no GOT relocs needed for Local Exec.
2595 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2596 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2597 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2598 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2600 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2601 if (tls_type
== tls::TLSOPT_NONE
)
2602 target
->tlsld_got_offset(symtab
, layout
, object
);
2603 else if (tls_type
== tls::TLSOPT_TO_LE
)
2605 // no GOT relocs needed for Local Exec.
2606 if (parameters
->options().emit_relocs())
2608 Output_section
* os
= layout
->tls_segment()->first_section();
2609 gold_assert(os
!= NULL
);
2610 os
->set_needs_symtab_index();
2618 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2619 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2620 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2621 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2623 Output_data_got_powerpc
<size
, big_endian
>* got
2624 = target
->got_section(symtab
, layout
);
2625 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2626 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
2630 case elfcpp::R_POWERPC_GOT_TPREL16
:
2631 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2632 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2633 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2635 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
2636 if (tls_type
== tls::TLSOPT_NONE
)
2638 Output_data_got_powerpc
<size
, big_endian
>* got
2639 = target
->got_section(symtab
, layout
);
2640 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2641 got
->add_local_tls(object
, r_sym
, GOT_TYPE_TPREL
);
2643 else if (tls_type
== tls::TLSOPT_TO_LE
)
2645 // no GOT relocs needed for Local Exec.
2653 unsupported_reloc_local(object
, r_type
);
2658 // Report an unsupported relocation against a global symbol.
2660 template<int size
, bool big_endian
>
2662 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2663 Sized_relobj_file
<size
, big_endian
>* object
,
2664 unsigned int r_type
,
2667 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2668 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2671 // Scan a relocation for a global symbol.
2673 template<int size
, bool big_endian
>
2675 Target_powerpc
<size
, big_endian
>::Scan::global(
2676 Symbol_table
* symtab
,
2678 Target_powerpc
<size
, big_endian
>* target
,
2679 Sized_relobj_file
<size
, big_endian
>* object
,
2680 unsigned int data_shndx
,
2681 Output_section
* output_section
,
2682 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2683 unsigned int r_type
,
2686 Powerpc_relobj
<size
, big_endian
>* ppc_object
2687 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2691 case elfcpp::R_POWERPC_NONE
:
2692 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2693 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2694 case elfcpp::R_PPC_LOCAL24PC
:
2695 case elfcpp::R_PPC_EMB_MRKREF
:
2696 case elfcpp::R_POWERPC_TLS
:
2699 case elfcpp::R_PPC64_TOC
:
2701 Output_data_got_powerpc
<size
, big_endian
>* got
2702 = target
->got_section(symtab
, layout
);
2703 if (parameters
->options().output_is_position_independent())
2705 Address off
= reloc
.get_r_offset();
2707 && data_shndx
== ppc_object
->opd_shndx()
2708 && ppc_object
->get_opd_discard(off
- 8))
2711 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2712 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
2713 if (data_shndx
!= ppc_object
->opd_shndx())
2714 symobj
= static_cast
2715 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
2716 rela_dyn
->add_output_section_relative(got
->output_section(),
2717 elfcpp::R_POWERPC_RELATIVE
,
2719 object
, data_shndx
, off
,
2720 symobj
->toc_base_offset());
2725 case elfcpp::R_PPC64_ADDR64
:
2727 && data_shndx
== ppc_object
->opd_shndx()
2728 && (gsym
->is_defined_in_discarded_section()
2729 || gsym
->object() != object
))
2731 ppc_object
->set_opd_discard(reloc
.get_r_offset());
2735 case elfcpp::R_PPC64_UADDR64
:
2736 case elfcpp::R_POWERPC_ADDR32
:
2737 case elfcpp::R_POWERPC_UADDR32
:
2738 case elfcpp::R_POWERPC_ADDR24
:
2739 case elfcpp::R_POWERPC_ADDR16
:
2740 case elfcpp::R_POWERPC_ADDR16_LO
:
2741 case elfcpp::R_POWERPC_ADDR16_HI
:
2742 case elfcpp::R_POWERPC_ADDR16_HA
:
2743 case elfcpp::R_POWERPC_UADDR16
:
2744 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2745 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2746 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2747 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2748 case elfcpp::R_PPC64_ADDR16_DS
:
2749 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2750 case elfcpp::R_POWERPC_ADDR14
:
2751 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2752 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2754 // Make a PLT entry if necessary.
2755 if (gsym
->needs_plt_entry())
2757 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
2758 // Since this is not a PC-relative relocation, we may be
2759 // taking the address of a function. In that case we need to
2760 // set the entry in the dynamic symbol table to the address of
2763 && gsym
->is_from_dynobj() && !parameters
->options().shared())
2764 gsym
->set_needs_dynsym_value();
2766 // Make a dynamic relocation if necessary.
2767 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2769 if (gsym
->may_need_copy_reloc())
2771 target
->copy_reloc(symtab
, layout
, object
,
2772 data_shndx
, output_section
, gsym
, reloc
);
2774 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2775 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2776 && (gsym
->can_use_relative_reloc(false)
2777 || data_shndx
== ppc_object
->opd_shndx()))
2779 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2780 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2781 output_section
, object
,
2782 data_shndx
, reloc
.get_r_offset(),
2783 reloc
.get_r_addend(), false);
2787 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2788 check_non_pic(object
, r_type
);
2789 rela_dyn
->add_global(gsym
, r_type
, output_section
,
2791 reloc
.get_r_offset(),
2792 reloc
.get_r_addend());
2798 case elfcpp::R_PPC_PLTREL24
:
2799 case elfcpp::R_POWERPC_REL24
:
2800 if (gsym
->needs_plt_entry()
2801 || (!gsym
->final_value_is_known()
2802 && (gsym
->is_undefined()
2803 || gsym
->is_from_dynobj()
2804 || gsym
->is_preemptible())))
2805 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
2808 case elfcpp::R_PPC64_REL64
:
2809 case elfcpp::R_POWERPC_REL32
:
2810 // Make a dynamic relocation if necessary.
2811 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2813 if (gsym
->may_need_copy_reloc())
2815 target
->copy_reloc(symtab
, layout
, object
,
2816 data_shndx
, output_section
, gsym
,
2821 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2822 check_non_pic(object
, r_type
);
2823 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2824 data_shndx
, reloc
.get_r_offset(),
2825 reloc
.get_r_addend());
2830 case elfcpp::R_POWERPC_REL16
:
2831 case elfcpp::R_POWERPC_REL16_LO
:
2832 case elfcpp::R_POWERPC_REL16_HI
:
2833 case elfcpp::R_POWERPC_REL16_HA
:
2834 case elfcpp::R_POWERPC_REL14
:
2835 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2836 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2837 case elfcpp::R_POWERPC_SECTOFF
:
2838 case elfcpp::R_POWERPC_TPREL16
:
2839 case elfcpp::R_POWERPC_DTPREL16
:
2840 case elfcpp::R_POWERPC_SECTOFF_LO
:
2841 case elfcpp::R_POWERPC_TPREL16_LO
:
2842 case elfcpp::R_POWERPC_DTPREL16_LO
:
2843 case elfcpp::R_POWERPC_SECTOFF_HI
:
2844 case elfcpp::R_POWERPC_TPREL16_HI
:
2845 case elfcpp::R_POWERPC_DTPREL16_HI
:
2846 case elfcpp::R_POWERPC_SECTOFF_HA
:
2847 case elfcpp::R_POWERPC_TPREL16_HA
:
2848 case elfcpp::R_POWERPC_DTPREL16_HA
:
2849 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2850 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2851 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2852 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2853 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2854 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2855 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2856 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2857 case elfcpp::R_PPC64_TPREL16_DS
:
2858 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2859 case elfcpp::R_PPC64_DTPREL16_DS
:
2860 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2861 case elfcpp::R_PPC64_SECTOFF_DS
:
2862 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2863 case elfcpp::R_PPC64_TLSGD
:
2864 case elfcpp::R_PPC64_TLSLD
:
2867 case elfcpp::R_POWERPC_GOT16
:
2868 case elfcpp::R_POWERPC_GOT16_LO
:
2869 case elfcpp::R_POWERPC_GOT16_HI
:
2870 case elfcpp::R_POWERPC_GOT16_HA
:
2871 case elfcpp::R_PPC64_GOT16_DS
:
2872 case elfcpp::R_PPC64_GOT16_LO_DS
:
2874 // The symbol requires a GOT entry.
2875 Output_data_got_powerpc
<size
, big_endian
>* got
;
2877 got
= target
->got_section(symtab
, layout
);
2878 if (gsym
->final_value_is_known())
2879 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2882 // If this symbol is not fully resolved, we need to add a
2883 // dynamic relocation for it.
2884 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2885 if (gsym
->is_from_dynobj()
2886 || gsym
->is_undefined()
2887 || gsym
->is_preemptible())
2888 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2889 elfcpp::R_POWERPC_GLOB_DAT
);
2890 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2892 unsigned int off
= got
->add_constant(0);
2894 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2895 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2896 got
, off
, 0, false);
2902 case elfcpp::R_PPC64_TOC16
:
2903 case elfcpp::R_PPC64_TOC16_LO
:
2904 case elfcpp::R_PPC64_TOC16_HI
:
2905 case elfcpp::R_PPC64_TOC16_HA
:
2906 case elfcpp::R_PPC64_TOC16_DS
:
2907 case elfcpp::R_PPC64_TOC16_LO_DS
:
2908 // We need a GOT section.
2909 target
->got_section(symtab
, layout
);
2912 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2913 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2914 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2915 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2917 const bool final
= gsym
->final_value_is_known();
2918 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
2919 if (tls_type
== tls::TLSOPT_NONE
)
2921 Output_data_got_powerpc
<size
, big_endian
>* got
2922 = target
->got_section(symtab
, layout
);
2923 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
2924 target
->rela_dyn_section(layout
),
2925 elfcpp::R_POWERPC_DTPMOD
,
2926 elfcpp::R_POWERPC_DTPREL
);
2928 else if (tls_type
== tls::TLSOPT_TO_IE
)
2930 Output_data_got_powerpc
<size
, big_endian
>* got
2931 = target
->got_section(symtab
, layout
);
2932 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
2933 target
->rela_dyn_section(layout
),
2934 elfcpp::R_POWERPC_TPREL
);
2936 else if (tls_type
== tls::TLSOPT_TO_LE
)
2938 // no GOT relocs needed for Local Exec.
2945 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2946 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2947 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2948 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2950 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2951 if (tls_type
== tls::TLSOPT_NONE
)
2952 target
->tlsld_got_offset(symtab
, layout
, object
);
2953 else if (tls_type
== tls::TLSOPT_TO_LE
)
2955 // no GOT relocs needed for Local Exec.
2956 if (parameters
->options().emit_relocs())
2958 Output_section
* os
= layout
->tls_segment()->first_section();
2959 gold_assert(os
!= NULL
);
2960 os
->set_needs_symtab_index();
2968 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2969 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2970 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2971 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2973 Output_data_got_powerpc
<size
, big_endian
>* got
2974 = target
->got_section(symtab
, layout
);
2975 if (!gsym
->final_value_is_known()
2976 && (gsym
->is_from_dynobj()
2977 || gsym
->is_undefined()
2978 || gsym
->is_preemptible()))
2979 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
2980 target
->rela_dyn_section(layout
),
2981 elfcpp::R_POWERPC_DTPREL
);
2983 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
2987 case elfcpp::R_POWERPC_GOT_TPREL16
:
2988 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2989 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2990 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2992 const bool final
= gsym
->final_value_is_known();
2993 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
2994 if (tls_type
== tls::TLSOPT_NONE
)
2996 Output_data_got_powerpc
<size
, big_endian
>* got
2997 = target
->got_section(symtab
, layout
);
2998 if (!gsym
->final_value_is_known()
2999 && (gsym
->is_from_dynobj()
3000 || gsym
->is_undefined()
3001 || gsym
->is_preemptible()))
3002 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
3003 target
->rela_dyn_section(layout
),
3004 elfcpp::R_POWERPC_TPREL
);
3006 got
->add_global_tls(gsym
, GOT_TYPE_TPREL
);
3008 else if (tls_type
== tls::TLSOPT_TO_LE
)
3010 // no GOT relocs needed for Local Exec.
3018 unsupported_reloc_global(object
, r_type
, gsym
);
3023 // Process relocations for gc.
3025 template<int size
, bool big_endian
>
3027 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
3028 Symbol_table
* symtab
,
3030 Sized_relobj_file
<size
, big_endian
>* object
,
3031 unsigned int data_shndx
,
3033 const unsigned char* prelocs
,
3035 Output_section
* output_section
,
3036 bool needs_special_offset_handling
,
3037 size_t local_symbol_count
,
3038 const unsigned char* plocal_symbols
)
3040 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3041 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3042 Powerpc_relobj
<size
, big_endian
>* ppc_object
3043 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3045 ppc_object
->set_opd_valid();
3046 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
3048 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
3049 for (p
= ppc_object
->access_from_map()->begin();
3050 p
!= ppc_object
->access_from_map()->end();
3053 Address dst_off
= p
->first
;
3054 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3055 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
3056 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
3058 Object
* src_obj
= s
->first
;
3059 unsigned int src_indx
= s
->second
;
3060 symtab
->gc()->add_reference(src_obj
, src_indx
,
3061 ppc_object
, dst_indx
);
3065 ppc_object
->access_from_map()->clear();
3066 // Don't look at .opd relocs as .opd will reference everything.
3070 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3071 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3080 needs_special_offset_handling
,
3085 // Handle target specific gc actions when adding a gc reference from
3086 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3087 // and DST_OFF. For powerpc64, this adds a referenc to the code
3088 // section of a function descriptor.
3090 template<int size
, bool big_endian
>
3092 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3093 Symbol_table
* symtab
,
3095 unsigned int src_shndx
,
3097 unsigned int dst_shndx
,
3098 Address dst_off
) const
3100 Powerpc_relobj
<size
, big_endian
>* ppc_object
3101 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3102 if (size
== 64 && dst_shndx
== ppc_object
->opd_shndx())
3104 if (ppc_object
->opd_valid())
3106 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3107 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3111 // If we haven't run scan_opd_relocs, we must delay
3112 // processing this function descriptor reference.
3113 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3118 // Add any special sections for this symbol to the gc work list.
3119 // For powerpc64, this adds the code section of a function
3122 template<int size
, bool big_endian
>
3124 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3125 Symbol_table
* symtab
,
3130 Powerpc_relobj
<size
, big_endian
>* ppc_object
3131 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3133 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3134 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
3136 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
3137 Address dst_off
= gsym
->value();
3138 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3139 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
3144 // Scan relocations for a section.
3146 template<int size
, bool big_endian
>
3148 Target_powerpc
<size
, big_endian
>::scan_relocs(
3149 Symbol_table
* symtab
,
3151 Sized_relobj_file
<size
, big_endian
>* object
,
3152 unsigned int data_shndx
,
3153 unsigned int sh_type
,
3154 const unsigned char* prelocs
,
3156 Output_section
* output_section
,
3157 bool needs_special_offset_handling
,
3158 size_t local_symbol_count
,
3159 const unsigned char* plocal_symbols
)
3161 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3162 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3164 if (sh_type
== elfcpp::SHT_REL
)
3166 gold_error(_("%s: unsupported REL reloc section"),
3167 object
->name().c_str());
3173 static Output_data_space
* sdata
;
3175 // Define _SDA_BASE_ at the start of the .sdata section.
3178 // layout->find_output_section(".sdata") == NULL
3179 sdata
= new Output_data_space(4, "** sdata");
3181 = layout
->add_output_section_data(".sdata", 0,
3183 | elfcpp::SHF_WRITE
,
3184 sdata
, ORDER_SMALL_DATA
, false);
3185 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
3186 Symbol_table::PREDEFINED
,
3187 os
, 32768, 0, elfcpp::STT_OBJECT
,
3188 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
3193 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
3202 needs_special_offset_handling
,
3207 // Finalize the sections.
3209 template<int size
, bool big_endian
>
3211 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
3213 const Input_objects
*,
3216 // Fill in some more dynamic tags.
3217 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3219 : this->plt_
->rel_plt());
3220 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3221 this->rela_dyn_
, true, size
== 32);
3223 Output_data_dynamic
* odyn
= layout
->dynamic_data();
3226 if (this->got_
!= NULL
)
3228 this->got_
->finalize_data_size();
3229 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
3230 this->got_
, this->got_
->g_o_t());
3235 if (this->glink_
!= NULL
)
3237 this->glink_
->finalize_data_size();
3238 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
3240 (this->glink_
->pltresolve()
3241 + this->glink_
->pltresolve_size
- 32));
3245 // Emit any relocs we saved in an attempt to avoid generating COPY
3247 if (this->copy_relocs_
.any_saved_relocs())
3248 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3251 // Return the value to use for a branch relocation.
3253 template<int size
, bool big_endian
>
3254 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3255 Target_powerpc
<size
, big_endian
>::symval_for_branch(
3257 const Sized_symbol
<size
>* gsym
,
3258 Powerpc_relobj
<size
, big_endian
>* object
,
3259 unsigned int *dest_shndx
)
3265 // If the symbol is defined in an opd section, ie. is a function
3266 // descriptor, use the function descriptor code entry address
3267 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
3269 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3270 unsigned int shndx
= symobj
->opd_shndx();
3273 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
3274 gold_assert(opd_addr
!= invalid_address
);
3275 opd_addr
+= symobj
->output_section(shndx
)->address();
3276 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
3279 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
3280 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
3281 gold_assert(sec_addr
!= invalid_address
);
3282 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
3283 value
= sec_addr
+ sec_off
;
3288 // Perform a relocation.
3290 template<int size
, bool big_endian
>
3292 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
3293 const Relocate_info
<size
, big_endian
>* relinfo
,
3294 Target_powerpc
* target
,
3297 const elfcpp::Rela
<size
, big_endian
>& rela
,
3298 unsigned int r_type
,
3299 const Sized_symbol
<size
>* gsym
,
3300 const Symbol_value
<size
>* psymval
,
3301 unsigned char* view
,
3303 section_size_type view_size
)
3306 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
3307 || r_type
== elfcpp::R_PPC_PLTREL24
)
3309 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
3310 enum skip_tls last_tls
= this->call_tls_get_addr_
;
3311 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
3314 if (last_tls
== CALL_NOT_EXPECTED
)
3315 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3316 _("__tls_get_addr call lacks marker reloc"));
3317 else if (last_tls
== CALL_SKIP
)
3320 else if (last_tls
!= CALL_NOT_EXPECTED
)
3321 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3322 _("missing expected __tls_get_addr call"));
3324 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
3325 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
3326 Powerpc_relobj
<size
, big_endian
>* const object
3327 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
3329 bool has_plt_value
= false;
3331 && use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3333 const Output_data_glink
<size
, big_endian
>* glink
3334 = target
->glink_section();
3335 unsigned int glink_index
= glink
->find_entry(gsym
, rela
, object
);
3336 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
3337 has_plt_value
= true;
3340 if (r_type
== elfcpp::R_POWERPC_GOT16
3341 || r_type
== elfcpp::R_POWERPC_GOT16_LO
3342 || r_type
== elfcpp::R_POWERPC_GOT16_HI
3343 || r_type
== elfcpp::R_POWERPC_GOT16_HA
3344 || r_type
== elfcpp::R_PPC64_GOT16_DS
3345 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
3349 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3350 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3354 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3355 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3356 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3358 value
-= target
->got_section()->got_base_offset(object
);
3360 else if (r_type
== elfcpp::R_PPC64_TOC
)
3362 value
= (target
->got_section()->output_section()->address()
3363 + object
->toc_base_offset());
3365 else if (gsym
!= NULL
3366 && (r_type
== elfcpp::R_POWERPC_REL24
3367 || r_type
== elfcpp::R_PPC_PLTREL24
)
3372 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3373 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3374 bool can_plt_call
= false;
3375 if (rela
.get_r_offset() + 8 <= view_size
)
3377 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3378 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
3381 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
3383 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
3384 can_plt_call
= true;
3389 // If we don't have a branch and link followed by a nop,
3390 // we can't go via the plt because there is no place to
3391 // put a toc restoring instruction.
3392 // Unless we know we won't be returning.
3393 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
3394 can_plt_call
= true;
3398 // This is not an error in one special case: A self
3399 // call. It isn't possible to cheaply verify we have
3400 // such a call so just check for a call to the same
3403 if (gsym
->source() == Symbol::FROM_OBJECT
3404 && gsym
->object() == object
)
3406 Address addend
= rela
.get_r_addend();
3407 unsigned int dest_shndx
;
3408 value
= psymval
->value(object
, addend
);
3409 value
= target
->symval_for_branch(value
, gsym
, object
,
3412 if (dest_shndx
== 0)
3413 dest_shndx
= gsym
->shndx(&is_ordinary
);
3414 ok
= dest_shndx
== relinfo
->data_shndx
;
3417 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3418 _("call lacks nop, can't restore toc; "
3419 "recompile with -fPIC"));
3423 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3424 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
3425 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
3426 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
3428 // First instruction of a global dynamic sequence, arg setup insn.
3429 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3430 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3431 enum Got_type got_type
= GOT_TYPE_STANDARD
;
3432 if (tls_type
== tls::TLSOPT_NONE
)
3433 got_type
= GOT_TYPE_TLSGD
;
3434 else if (tls_type
== tls::TLSOPT_TO_IE
)
3435 got_type
= GOT_TYPE_TPREL
;
3436 if (got_type
!= GOT_TYPE_STANDARD
)
3440 gold_assert(gsym
->has_got_offset(got_type
));
3441 value
= gsym
->got_offset(got_type
);
3445 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3446 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3447 value
= object
->local_got_offset(r_sym
, got_type
);
3449 value
-= target
->got_section()->got_base_offset(object
);
3451 if (tls_type
== tls::TLSOPT_TO_IE
)
3453 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3454 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3456 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3457 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3458 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
3460 insn
|= 32 << 26; // lwz
3462 insn
|= 58 << 26; // ld
3463 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3465 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
3466 - elfcpp::R_POWERPC_GOT_TLSGD16
);
3468 else if (tls_type
== tls::TLSOPT_TO_LE
)
3470 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3471 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3473 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3474 Insn insn
= addis_3_13
;
3477 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3478 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3479 value
= psymval
->value(object
, rela
.get_r_addend());
3483 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3485 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3486 r_type
= elfcpp::R_POWERPC_NONE
;
3490 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3491 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
3492 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
3493 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
3495 // First instruction of a local dynamic sequence, arg setup insn.
3496 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3497 if (tls_type
== tls::TLSOPT_NONE
)
3499 value
= target
->tlsld_got_offset();
3500 value
-= target
->got_section()->got_base_offset(object
);
3504 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3505 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3506 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
3508 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3509 Insn insn
= addis_3_13
;
3512 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3513 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3518 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3520 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3521 r_type
= elfcpp::R_POWERPC_NONE
;
3525 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
3526 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
3527 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
3528 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
3530 // Accesses relative to a local dynamic sequence address,
3531 // no optimisation here.
3534 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
3535 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
3539 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3540 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
3541 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
3543 value
-= target
->got_section()->got_base_offset(object
);
3545 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3546 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
3547 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
3548 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
3550 // First instruction of initial exec sequence.
3551 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3552 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3553 if (tls_type
== tls::TLSOPT_NONE
)
3557 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
3558 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
3562 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3563 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
3564 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
3566 value
-= target
->got_section()->got_base_offset(object
);
3570 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3571 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3572 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
3574 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3575 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3576 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
3581 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3582 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3583 value
= psymval
->value(object
, rela
.get_r_addend());
3587 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3589 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3590 r_type
= elfcpp::R_POWERPC_NONE
;
3594 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
3595 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
3597 // Second instruction of a global dynamic sequence,
3598 // the __tls_get_addr call
3599 this->call_tls_get_addr_
= CALL_EXPECTED
;
3600 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3601 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3602 if (tls_type
!= tls::TLSOPT_NONE
)
3604 if (tls_type
== tls::TLSOPT_TO_IE
)
3606 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3607 Insn insn
= add_3_3_13
;
3610 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3611 r_type
= elfcpp::R_POWERPC_NONE
;
3615 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3616 Insn insn
= addi_3_3
;
3617 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3618 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3619 view
+= 2 * big_endian
;
3620 value
= psymval
->value(object
, rela
.get_r_addend());
3622 this->call_tls_get_addr_
= CALL_SKIP
;
3625 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
3626 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
3628 // Second instruction of a local dynamic sequence,
3629 // the __tls_get_addr call
3630 this->call_tls_get_addr_
= CALL_EXPECTED
;
3631 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3632 if (tls_type
== tls::TLSOPT_TO_LE
)
3634 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3635 Insn insn
= addi_3_3
;
3636 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3637 this->call_tls_get_addr_
= CALL_SKIP
;
3638 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3639 view
+= 2 * big_endian
;
3643 else if (r_type
== elfcpp::R_POWERPC_TLS
)
3645 // Second instruction of an initial exec sequence
3646 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3647 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3648 if (tls_type
== tls::TLSOPT_TO_LE
)
3650 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3651 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3652 unsigned int reg
= size
== 32 ? 2 : 13;
3653 insn
= at_tls_transform(insn
, reg
);
3654 gold_assert(insn
!= 0);
3655 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3656 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3657 view
+= 2 * big_endian
;
3658 value
= psymval
->value(object
, rela
.get_r_addend());
3664 unsigned int dest_shndx
;
3665 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
3666 addend
= rela
.get_r_addend();
3667 if (size
== 64 || !has_plt_value
)
3668 value
= psymval
->value(object
, addend
);
3669 if (size
== 64 && is_branch_reloc(r_type
))
3670 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
3675 case elfcpp::R_PPC64_REL64
:
3676 case elfcpp::R_POWERPC_REL32
:
3677 case elfcpp::R_POWERPC_REL24
:
3678 case elfcpp::R_PPC_PLTREL24
:
3679 case elfcpp::R_PPC_LOCAL24PC
:
3680 case elfcpp::R_POWERPC_REL16
:
3681 case elfcpp::R_POWERPC_REL16_LO
:
3682 case elfcpp::R_POWERPC_REL16_HI
:
3683 case elfcpp::R_POWERPC_REL16_HA
:
3684 case elfcpp::R_POWERPC_REL14
:
3685 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3686 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3690 case elfcpp::R_PPC64_TOC16
:
3691 case elfcpp::R_PPC64_TOC16_LO
:
3692 case elfcpp::R_PPC64_TOC16_HI
:
3693 case elfcpp::R_PPC64_TOC16_HA
:
3694 case elfcpp::R_PPC64_TOC16_DS
:
3695 case elfcpp::R_PPC64_TOC16_LO_DS
:
3696 // Subtract the TOC base address.
3697 value
-= (target
->got_section()->output_section()->address()
3698 + object
->toc_base_offset());
3701 case elfcpp::R_POWERPC_SECTOFF
:
3702 case elfcpp::R_POWERPC_SECTOFF_LO
:
3703 case elfcpp::R_POWERPC_SECTOFF_HI
:
3704 case elfcpp::R_POWERPC_SECTOFF_HA
:
3705 case elfcpp::R_PPC64_SECTOFF_DS
:
3706 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3708 value
-= os
->address();
3711 case elfcpp::R_PPC64_TPREL16_DS
:
3712 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3714 // R_PPC_TLSGD and R_PPC_TLSLD
3716 case elfcpp::R_POWERPC_TPREL16
:
3717 case elfcpp::R_POWERPC_TPREL16_LO
:
3718 case elfcpp::R_POWERPC_TPREL16_HI
:
3719 case elfcpp::R_POWERPC_TPREL16_HA
:
3720 case elfcpp::R_POWERPC_TPREL
:
3721 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3722 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3723 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3724 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3725 // tls symbol values are relative to tls_segment()->vaddr()
3729 case elfcpp::R_PPC64_DTPREL16_DS
:
3730 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3731 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3732 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3733 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3734 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3736 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
3737 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
3739 case elfcpp::R_POWERPC_DTPREL16
:
3740 case elfcpp::R_POWERPC_DTPREL16_LO
:
3741 case elfcpp::R_POWERPC_DTPREL16_HI
:
3742 case elfcpp::R_POWERPC_DTPREL16_HA
:
3743 case elfcpp::R_POWERPC_DTPREL
:
3744 // tls symbol values are relative to tls_segment()->vaddr()
3745 value
-= dtp_offset
;
3752 Insn branch_bit
= 0;
3755 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3756 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3757 branch_bit
= 1 << 21;
3758 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3759 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3761 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3762 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3765 if (this->is_isa_v2
)
3767 // Set 'a' bit. This is 0b00010 in BO field for branch
3768 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
3769 // for branch on CTR insns (BO == 1a00t or 1a01t).
3770 if ((insn
& (0x14 << 21)) == (0x04 << 21))
3772 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
3779 // Invert 'y' bit if not the default.
3780 if (static_cast<Signed_address
>(value
) < 0)
3783 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3791 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
3794 case elfcpp::R_POWERPC_ADDR32
:
3795 case elfcpp::R_POWERPC_UADDR32
:
3797 overflow
= Reloc::CHECK_BITFIELD
;
3800 case elfcpp::R_POWERPC_REL32
:
3802 overflow
= Reloc::CHECK_SIGNED
;
3805 case elfcpp::R_POWERPC_ADDR24
:
3806 case elfcpp::R_POWERPC_ADDR16
:
3807 case elfcpp::R_POWERPC_UADDR16
:
3808 case elfcpp::R_PPC64_ADDR16_DS
:
3809 case elfcpp::R_POWERPC_ADDR14
:
3810 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3811 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3812 overflow
= Reloc::CHECK_BITFIELD
;
3815 case elfcpp::R_POWERPC_REL24
:
3816 case elfcpp::R_PPC_PLTREL24
:
3817 case elfcpp::R_PPC_LOCAL24PC
:
3818 case elfcpp::R_POWERPC_REL16
:
3819 case elfcpp::R_PPC64_TOC16
:
3820 case elfcpp::R_POWERPC_GOT16
:
3821 case elfcpp::R_POWERPC_SECTOFF
:
3822 case elfcpp::R_POWERPC_TPREL16
:
3823 case elfcpp::R_POWERPC_DTPREL16
:
3824 case elfcpp::R_PPC64_TPREL16_DS
:
3825 case elfcpp::R_PPC64_DTPREL16_DS
:
3826 case elfcpp::R_PPC64_TOC16_DS
:
3827 case elfcpp::R_PPC64_GOT16_DS
:
3828 case elfcpp::R_PPC64_SECTOFF_DS
:
3829 case elfcpp::R_POWERPC_REL14
:
3830 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3831 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3832 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3833 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3834 case elfcpp::R_POWERPC_GOT_TPREL16
:
3835 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3836 overflow
= Reloc::CHECK_SIGNED
;
3840 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
3841 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
3844 case elfcpp::R_POWERPC_NONE
:
3845 case elfcpp::R_POWERPC_TLS
:
3846 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3847 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3848 case elfcpp::R_PPC_EMB_MRKREF
:
3851 case elfcpp::R_PPC64_ADDR64
:
3852 case elfcpp::R_PPC64_REL64
:
3853 case elfcpp::R_PPC64_TOC
:
3854 Reloc::addr64(view
, value
);
3857 case elfcpp::R_POWERPC_TPREL
:
3858 case elfcpp::R_POWERPC_DTPREL
:
3860 Reloc::addr64(view
, value
);
3862 status
= Reloc::addr32(view
, value
, overflow
);
3865 case elfcpp::R_PPC64_UADDR64
:
3866 Reloc::addr64_u(view
, value
);
3869 case elfcpp::R_POWERPC_ADDR32
:
3870 case elfcpp::R_POWERPC_REL32
:
3871 status
= Reloc::addr32(view
, value
, overflow
);
3874 case elfcpp::R_POWERPC_UADDR32
:
3875 status
= Reloc::addr32_u(view
, value
, overflow
);
3878 case elfcpp::R_POWERPC_ADDR24
:
3879 case elfcpp::R_POWERPC_REL24
:
3880 case elfcpp::R_PPC_PLTREL24
:
3881 case elfcpp::R_PPC_LOCAL24PC
:
3882 status
= Reloc::addr24(view
, value
, overflow
);
3885 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3886 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3889 status
= Reloc::addr16_ds(view
, value
, overflow
);
3892 case elfcpp::R_POWERPC_ADDR16
:
3893 case elfcpp::R_POWERPC_REL16
:
3894 case elfcpp::R_PPC64_TOC16
:
3895 case elfcpp::R_POWERPC_GOT16
:
3896 case elfcpp::R_POWERPC_SECTOFF
:
3897 case elfcpp::R_POWERPC_TPREL16
:
3898 case elfcpp::R_POWERPC_DTPREL16
:
3899 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3900 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3901 case elfcpp::R_POWERPC_GOT_TPREL16
:
3902 case elfcpp::R_POWERPC_ADDR16_LO
:
3903 case elfcpp::R_POWERPC_REL16_LO
:
3904 case elfcpp::R_PPC64_TOC16_LO
:
3905 case elfcpp::R_POWERPC_GOT16_LO
:
3906 case elfcpp::R_POWERPC_SECTOFF_LO
:
3907 case elfcpp::R_POWERPC_TPREL16_LO
:
3908 case elfcpp::R_POWERPC_DTPREL16_LO
:
3909 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3910 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3911 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3912 status
= Reloc::addr16(view
, value
, overflow
);
3915 case elfcpp::R_POWERPC_UADDR16
:
3916 status
= Reloc::addr16_u(view
, value
, overflow
);
3919 case elfcpp::R_POWERPC_ADDR16_HI
:
3920 case elfcpp::R_POWERPC_REL16_HI
:
3921 case elfcpp::R_PPC64_TOC16_HI
:
3922 case elfcpp::R_POWERPC_GOT16_HI
:
3923 case elfcpp::R_POWERPC_SECTOFF_HI
:
3924 case elfcpp::R_POWERPC_TPREL16_HI
:
3925 case elfcpp::R_POWERPC_DTPREL16_HI
:
3926 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3927 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3928 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3929 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3930 Reloc::addr16_hi(view
, value
);
3933 case elfcpp::R_POWERPC_ADDR16_HA
:
3934 case elfcpp::R_POWERPC_REL16_HA
:
3935 case elfcpp::R_PPC64_TOC16_HA
:
3936 case elfcpp::R_POWERPC_GOT16_HA
:
3937 case elfcpp::R_POWERPC_SECTOFF_HA
:
3938 case elfcpp::R_POWERPC_TPREL16_HA
:
3939 case elfcpp::R_POWERPC_DTPREL16_HA
:
3940 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3941 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3942 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3943 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3944 Reloc::addr16_ha(view
, value
);
3947 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3949 // R_PPC_EMB_NADDR16_LO
3951 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3952 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3953 Reloc::addr16_hi2(view
, value
);
3956 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3958 // R_PPC_EMB_NADDR16_HI
3960 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3961 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3962 Reloc::addr16_ha2(view
, value
);
3965 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3967 // R_PPC_EMB_NADDR16_HA
3969 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3970 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3971 Reloc::addr16_hi3(view
, value
);
3974 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3978 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3979 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3980 Reloc::addr16_ha3(view
, value
);
3983 case elfcpp::R_PPC64_DTPREL16_DS
:
3984 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3986 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
3988 case elfcpp::R_PPC64_TPREL16_DS
:
3989 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3991 // R_PPC_TLSGD, R_PPC_TLSLD
3993 case elfcpp::R_PPC64_ADDR16_DS
:
3994 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3995 case elfcpp::R_PPC64_TOC16_DS
:
3996 case elfcpp::R_PPC64_TOC16_LO_DS
:
3997 case elfcpp::R_PPC64_GOT16_DS
:
3998 case elfcpp::R_PPC64_GOT16_LO_DS
:
3999 case elfcpp::R_PPC64_SECTOFF_DS
:
4000 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4001 status
= Reloc::addr16_ds(view
, value
, overflow
);
4004 case elfcpp::R_POWERPC_ADDR14
:
4005 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4006 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4007 case elfcpp::R_POWERPC_REL14
:
4008 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4009 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4010 status
= Reloc::addr14(view
, value
, overflow
);
4013 case elfcpp::R_POWERPC_COPY
:
4014 case elfcpp::R_POWERPC_GLOB_DAT
:
4015 case elfcpp::R_POWERPC_JMP_SLOT
:
4016 case elfcpp::R_POWERPC_RELATIVE
:
4017 case elfcpp::R_POWERPC_DTPMOD
:
4018 case elfcpp::R_PPC64_JMP_IREL
:
4019 case elfcpp::R_POWERPC_IRELATIVE
:
4020 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4021 _("unexpected reloc %u in object file"),
4025 case elfcpp::R_PPC_EMB_SDA21
:
4030 // R_PPC64_TOCSAVE. For the time being this can be ignored.
4034 case elfcpp::R_PPC_EMB_SDA2I16
:
4035 case elfcpp::R_PPC_EMB_SDA2REL
:
4038 // R_PPC64_TLSGD, R_PPC64_TLSLD
4041 case elfcpp::R_POWERPC_PLT32
:
4042 case elfcpp::R_POWERPC_PLTREL32
:
4043 case elfcpp::R_POWERPC_PLT16_LO
:
4044 case elfcpp::R_POWERPC_PLT16_HI
:
4045 case elfcpp::R_POWERPC_PLT16_HA
:
4046 case elfcpp::R_PPC_SDAREL16
:
4047 case elfcpp::R_POWERPC_ADDR30
:
4048 case elfcpp::R_PPC64_PLT64
:
4049 case elfcpp::R_PPC64_PLTREL64
:
4050 case elfcpp::R_PPC64_PLTGOT16
:
4051 case elfcpp::R_PPC64_PLTGOT16_LO
:
4052 case elfcpp::R_PPC64_PLTGOT16_HI
:
4053 case elfcpp::R_PPC64_PLTGOT16_HA
:
4054 case elfcpp::R_PPC64_PLT16_LO_DS
:
4055 case elfcpp::R_PPC64_PLTGOT16_DS
:
4056 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
4057 case elfcpp::R_PPC_EMB_RELSEC16
:
4058 case elfcpp::R_PPC_EMB_RELST_LO
:
4059 case elfcpp::R_PPC_EMB_RELST_HI
:
4060 case elfcpp::R_PPC_EMB_RELST_HA
:
4061 case elfcpp::R_PPC_EMB_BIT_FLD
:
4062 case elfcpp::R_PPC_EMB_RELSDA
:
4063 case elfcpp::R_PPC_TOC16
:
4066 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4067 _("unsupported reloc %u"),
4071 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
4072 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4073 _("relocation overflow"));
4078 // Relocate section data.
4080 template<int size
, bool big_endian
>
4082 Target_powerpc
<size
, big_endian
>::relocate_section(
4083 const Relocate_info
<size
, big_endian
>* relinfo
,
4084 unsigned int sh_type
,
4085 const unsigned char* prelocs
,
4087 Output_section
* output_section
,
4088 bool needs_special_offset_handling
,
4089 unsigned char* view
,
4091 section_size_type view_size
,
4092 const Reloc_symbol_changes
* reloc_symbol_changes
)
4094 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
4095 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
4097 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4099 unsigned char *opd_rel
= NULL
;
4100 Powerpc_relobj
<size
, big_endian
>* const object
4101 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4103 && relinfo
->data_shndx
== object
->opd_shndx())
4105 // Rewrite opd relocs, omitting those for discarded sections
4106 // to silence gold::relocate_section errors.
4107 const int reloc_size
4108 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4109 opd_rel
= new unsigned char[reloc_count
* reloc_size
];
4110 const unsigned char* rrel
= prelocs
;
4111 unsigned char* wrel
= opd_rel
;
4115 ++i
, rrel
+= reloc_size
, wrel
+= reloc_size
)
4117 typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4119 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
4120 = reloc
.get_r_info();
4121 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4122 Address r_off
= reloc
.get_r_offset();
4123 if (r_type
== elfcpp::R_PPC64_TOC
)
4125 bool is_discarded
= object
->get_opd_discard(r_off
);
4127 // Reloc number is reported in some errors, so keep all relocs.
4129 memset(wrel
, 0, reloc_size
);
4131 memcpy(wrel
, rrel
, reloc_size
);
4136 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
4143 needs_special_offset_handling
,
4147 reloc_symbol_changes
);
4149 if (opd_rel
!= NULL
)
4153 class Powerpc_scan_relocatable_reloc
4156 // Return the strategy to use for a local symbol which is not a
4157 // section symbol, given the relocation type.
4158 inline Relocatable_relocs::Reloc_strategy
4159 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
4161 if (r_type
== 0 && r_sym
== 0)
4162 return Relocatable_relocs::RELOC_DISCARD
;
4163 return Relocatable_relocs::RELOC_COPY
;
4166 // Return the strategy to use for a local symbol which is a section
4167 // symbol, given the relocation type.
4168 inline Relocatable_relocs::Reloc_strategy
4169 local_section_strategy(unsigned int, Relobj
*)
4171 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
4174 // Return the strategy to use for a global symbol, given the
4175 // relocation type, the object, and the symbol index.
4176 inline Relocatable_relocs::Reloc_strategy
4177 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
4179 if (r_type
== elfcpp::R_PPC_PLTREL24
)
4180 return Relocatable_relocs::RELOC_SPECIAL
;
4181 return Relocatable_relocs::RELOC_COPY
;
4185 // Scan the relocs during a relocatable link.
4187 template<int size
, bool big_endian
>
4189 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
4190 Symbol_table
* symtab
,
4192 Sized_relobj_file
<size
, big_endian
>* object
,
4193 unsigned int data_shndx
,
4194 unsigned int sh_type
,
4195 const unsigned char* prelocs
,
4197 Output_section
* output_section
,
4198 bool needs_special_offset_handling
,
4199 size_t local_symbol_count
,
4200 const unsigned char* plocal_symbols
,
4201 Relocatable_relocs
* rr
)
4203 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4205 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4206 Powerpc_scan_relocatable_reloc
>(
4214 needs_special_offset_handling
,
4220 // Emit relocations for a section.
4221 // This is a modified version of the function by the same name in
4222 // target-reloc.h. Using relocate_special_relocatable for
4223 // R_PPC_PLTREL24 would require duplication of the entire body of the
4224 // loop, so we may as well duplicate the whole thing.
4226 template<int size
, bool big_endian
>
4228 Target_powerpc
<size
, big_endian
>::relocate_relocs(
4229 const Relocate_info
<size
, big_endian
>* relinfo
,
4230 unsigned int sh_type
,
4231 const unsigned char* prelocs
,
4233 Output_section
* output_section
,
4234 off_t offset_in_output_section
,
4235 const Relocatable_relocs
* rr
,
4237 Address view_address
,
4239 unsigned char* reloc_view
,
4240 section_size_type reloc_view_size
)
4242 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4244 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4246 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
4248 const int reloc_size
4249 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4251 Powerpc_relobj
<size
, big_endian
>* const object
4252 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4253 const unsigned int local_count
= object
->local_symbol_count();
4254 unsigned int got2_shndx
= object
->got2_shndx();
4255 Address got2_addend
= 0;
4256 if (got2_shndx
!= 0)
4258 got2_addend
= object
->get_output_section_offset(got2_shndx
);
4259 gold_assert(got2_addend
!= invalid_address
);
4262 unsigned char* pwrite
= reloc_view
;
4263 bool zap_next
= false;
4264 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
4266 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
4267 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
4270 Reltype
reloc(prelocs
);
4271 Reltype_write
reloc_write(pwrite
);
4273 Address offset
= reloc
.get_r_offset();
4274 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
4275 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
4276 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4277 const unsigned int orig_r_sym
= r_sym
;
4278 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
4279 = reloc
.get_r_addend();
4280 const Symbol
* gsym
= NULL
;
4284 // We could arrange to discard these and other relocs for
4285 // tls optimised sequences in the strategy methods, but for
4286 // now do as BFD ld does.
4287 r_type
= elfcpp::R_POWERPC_NONE
;
4291 // Get the new symbol index.
4292 if (r_sym
< local_count
)
4296 case Relocatable_relocs::RELOC_COPY
:
4297 case Relocatable_relocs::RELOC_SPECIAL
:
4300 r_sym
= object
->symtab_index(r_sym
);
4301 gold_assert(r_sym
!= -1U);
4305 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
4307 // We are adjusting a section symbol. We need to find
4308 // the symbol table index of the section symbol for
4309 // the output section corresponding to input section
4310 // in which this symbol is defined.
4311 gold_assert(r_sym
< local_count
);
4313 unsigned int shndx
=
4314 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
4315 gold_assert(is_ordinary
);
4316 Output_section
* os
= object
->output_section(shndx
);
4317 gold_assert(os
!= NULL
);
4318 gold_assert(os
->needs_symtab_index());
4319 r_sym
= os
->symtab_index();
4329 gsym
= object
->global_symbol(r_sym
);
4330 gold_assert(gsym
!= NULL
);
4331 if (gsym
->is_forwarder())
4332 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
4334 gold_assert(gsym
->has_symtab_index());
4335 r_sym
= gsym
->symtab_index();
4338 // Get the new offset--the location in the output section where
4339 // this relocation should be applied.
4340 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4341 offset
+= offset_in_output_section
;
4344 section_offset_type sot_offset
=
4345 convert_types
<section_offset_type
, Address
>(offset
);
4346 section_offset_type new_sot_offset
=
4347 output_section
->output_offset(object
, relinfo
->data_shndx
,
4349 gold_assert(new_sot_offset
!= -1);
4350 offset
= new_sot_offset
;
4353 // In an object file, r_offset is an offset within the section.
4354 // In an executable or dynamic object, generated by
4355 // --emit-relocs, r_offset is an absolute address.
4356 if (!parameters
->options().relocatable())
4358 offset
+= view_address
;
4359 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4360 offset
-= offset_in_output_section
;
4363 // Handle the reloc addend based on the strategy.
4364 if (strategy
== Relocatable_relocs::RELOC_COPY
)
4366 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
4368 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
4369 addend
= psymval
->value(object
, addend
);
4371 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
4373 if (addend
>= 32768)
4374 addend
+= got2_addend
;
4379 if (!parameters
->options().relocatable())
4381 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4382 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4383 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4384 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4386 // First instruction of a global dynamic sequence,
4388 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4389 switch (this->optimize_tls_gd(final
))
4391 case tls::TLSOPT_TO_IE
:
4392 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4393 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4395 case tls::TLSOPT_TO_LE
:
4396 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4397 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4398 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4401 r_type
= elfcpp::R_POWERPC_NONE
;
4402 offset
-= 2 * big_endian
;
4409 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4410 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4411 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4412 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4414 // First instruction of a local dynamic sequence,
4416 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4418 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4419 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4421 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4422 const Output_section
* os
= relinfo
->layout
->tls_segment()
4424 gold_assert(os
!= NULL
);
4425 gold_assert(os
->needs_symtab_index());
4426 r_sym
= os
->symtab_index();
4427 addend
= dtp_offset
;
4431 r_type
= elfcpp::R_POWERPC_NONE
;
4432 offset
-= 2 * big_endian
;
4436 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4437 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4438 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4439 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4441 // First instruction of initial exec sequence.
4442 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4443 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4445 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4446 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4447 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4450 r_type
= elfcpp::R_POWERPC_NONE
;
4451 offset
-= 2 * big_endian
;
4455 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4456 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4458 // Second instruction of a global dynamic sequence,
4459 // the __tls_get_addr call
4460 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4461 switch (this->optimize_tls_gd(final
))
4463 case tls::TLSOPT_TO_IE
:
4464 r_type
= elfcpp::R_POWERPC_NONE
;
4467 case tls::TLSOPT_TO_LE
:
4468 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4469 offset
+= 2 * big_endian
;
4476 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4477 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4479 // Second instruction of a local dynamic sequence,
4480 // the __tls_get_addr call
4481 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4483 const Output_section
* os
= relinfo
->layout
->tls_segment()
4485 gold_assert(os
!= NULL
);
4486 gold_assert(os
->needs_symtab_index());
4487 r_sym
= os
->symtab_index();
4488 addend
= dtp_offset
;
4489 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4490 offset
+= 2 * big_endian
;
4494 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4496 // Second instruction of an initial exec sequence
4497 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4498 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4500 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4501 offset
+= 2 * big_endian
;
4506 reloc_write
.put_r_offset(offset
);
4507 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
4508 reloc_write
.put_r_addend(addend
);
4510 pwrite
+= reloc_size
;
4513 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
4514 == reloc_view_size
);
4517 // Return the value to use for a dynamic which requires special
4518 // treatment. This is how we support equality comparisons of function
4519 // pointers across shared library boundaries, as described in the
4520 // processor specific ABI supplement.
4522 template<int size
, bool big_endian
>
4524 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4528 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4529 return this->plt_section()->address() + gsym
->plt_offset();
4535 // Return the offset to use for the GOT_INDX'th got entry which is
4536 // for a local tls symbol specified by OBJECT, SYMNDX.
4537 template<int size
, bool big_endian
>
4539 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
4540 const Relobj
* object
,
4541 unsigned int symndx
,
4542 unsigned int got_indx
) const
4544 const Powerpc_relobj
<size
, big_endian
>* ppc_object
4545 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
4546 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
4548 for (Got_type got_type
= GOT_TYPE_TLSGD
;
4549 got_type
<= GOT_TYPE_TPREL
;
4550 got_type
= Got_type(got_type
+ 1))
4551 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
4553 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
4554 if (got_type
== GOT_TYPE_TLSGD
)
4556 if (off
== got_indx
* (size
/ 8))
4558 if (got_type
== GOT_TYPE_TPREL
)
4568 // Return the offset to use for the GOT_INDX'th got entry which is
4569 // for global tls symbol GSYM.
4570 template<int size
, bool big_endian
>
4572 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
4574 unsigned int got_indx
) const
4576 if (gsym
->type() == elfcpp::STT_TLS
)
4578 for (Got_type got_type
= GOT_TYPE_TLSGD
;
4579 got_type
<= GOT_TYPE_TPREL
;
4580 got_type
= Got_type(got_type
+ 1))
4581 if (gsym
->has_got_offset(got_type
))
4583 unsigned int off
= gsym
->got_offset(got_type
);
4584 if (got_type
== GOT_TYPE_TLSGD
)
4586 if (off
== got_indx
* (size
/ 8))
4588 if (got_type
== GOT_TYPE_TPREL
)
4598 // The selector for powerpc object files.
4600 template<int size
, bool big_endian
>
4601 class Target_selector_powerpc
: public Target_selector
4604 Target_selector_powerpc()
4605 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4607 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
4608 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
4610 ? (big_endian
? "elf64ppc" : "elf64lppc")
4611 : (big_endian
? "elf32ppc" : "elf32lppc")))
4615 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4620 if (machine
!= elfcpp::EM_PPC64
)
4625 if (machine
!= elfcpp::EM_PPC
)
4633 return this->instantiate_target();
4637 do_instantiate_target()
4638 { return new Target_powerpc
<size
, big_endian
>(); }
4641 Target_selector_powerpc
<32, true> target_selector_ppc32
;
4642 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
4643 Target_selector_powerpc
<64, true> target_selector_ppc64
;
4644 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
4646 } // End anonymous namespace.