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
);
157 // Add a reference to the code section specified by the .opd entry
160 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
162 size_t ndx
= this->opd_ent_ndx(dst_off
);
163 if (ndx
>= this->opd_ent_
.size())
164 this->opd_ent_
.resize(ndx
+ 1);
165 this->opd_ent_
[ndx
].gc_mark
= true;
169 process_gc_mark(Symbol_table
* symtab
)
171 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
172 if (this->opd_ent_
[i
].gc_mark
)
174 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
175 symtab
->gc()->worklist().push(Section_id(this, shndx
));
181 { return this->opd_valid_
; }
185 { this->opd_valid_
= true; }
187 // Examine .rela.opd to build info about function entry points.
189 scan_opd_relocs(size_t reloc_count
,
190 const unsigned char* prelocs
,
191 const unsigned char* plocal_syms
);
194 do_read_relocs(Read_relocs_data
*);
197 do_find_special_sections(Read_symbols_data
* sd
);
199 // Adjust this local symbol value. Return false if the symbol
200 // should be discarded from the output file.
202 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
204 if (size
== 64 && this->opd_shndx() != 0)
207 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
209 if (this->get_opd_discard(lv
->input_value()))
215 // Return offset in output GOT section that this object will use
216 // as a TOC pointer. Won't be just a constant with multi-toc support.
218 toc_base_offset() const
230 // Return index into opd_ent_ array for .opd entry at OFF.
231 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
232 // apart when the language doesn't use the last 8-byte word, the
233 // environment pointer. Thus dividing the entry section offset by
234 // 16 will give an index into opd_ent_ that works for either layout
235 // of .opd. (It leaves some elements of the vector unused when .opd
236 // entries are spaced 24 bytes apart, but we don't know the spacing
237 // until relocations are processed, and in any case it is possible
238 // for an object to have some entries spaced 16 bytes apart and
239 // others 24 bytes apart.)
241 opd_ent_ndx(size_t off
) const
244 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
245 unsigned int special_
;
247 // Set at the start of gc_process_relocs, when we know opd_ent_
248 // vector is valid. The flag could be made atomic and set in
249 // do_read_relocs with memory_order_release and then tested with
250 // memory_order_acquire, potentially resulting in fewer entries in
254 // The first 8-byte word of an OPD entry gives the address of the
255 // entry point of the function. Relocatable object files have a
256 // relocation on this word. The following vector records the
257 // section and offset specified by these relocations.
258 std::vector
<Opd_ent
> opd_ent_
;
260 // References made to this object's .opd section when running
261 // gc_process_relocs for another object, before the opd_ent_ vector
262 // is valid for this object.
263 Access_from access_from_map_
;
266 template<int size
, bool big_endian
>
267 class Target_powerpc
: public Sized_target
<size
, big_endian
>
271 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
272 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
273 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
274 static const Address invalid_address
= static_cast<Address
>(0) - 1;
275 // Offset of tp and dtp pointers from start of TLS block.
276 static const Address tp_offset
= 0x7000;
277 static const Address dtp_offset
= 0x8000;
280 : Sized_target
<size
, big_endian
>(&powerpc_info
),
281 got_(NULL
), plt_(NULL
), iplt_(NULL
), glink_(NULL
), rela_dyn_(NULL
),
282 copy_relocs_(elfcpp::R_POWERPC_COPY
),
283 dynbss_(NULL
), tlsld_got_offset_(-1U)
287 // Process the relocations to determine unreferenced sections for
288 // garbage collection.
290 gc_process_relocs(Symbol_table
* symtab
,
292 Sized_relobj_file
<size
, big_endian
>* object
,
293 unsigned int data_shndx
,
294 unsigned int sh_type
,
295 const unsigned char* prelocs
,
297 Output_section
* output_section
,
298 bool needs_special_offset_handling
,
299 size_t local_symbol_count
,
300 const unsigned char* plocal_symbols
);
302 // Scan the relocations to look for symbol adjustments.
304 scan_relocs(Symbol_table
* symtab
,
306 Sized_relobj_file
<size
, big_endian
>* object
,
307 unsigned int data_shndx
,
308 unsigned int sh_type
,
309 const unsigned char* prelocs
,
311 Output_section
* output_section
,
312 bool needs_special_offset_handling
,
313 size_t local_symbol_count
,
314 const unsigned char* plocal_symbols
);
316 // Map input .toc section to output .got section.
318 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
320 if (size
== 64 && strcmp(name
, ".toc") == 0)
328 // Provide linker defined save/restore functions.
330 define_save_restore_funcs(Layout
*, Symbol_table
*);
332 // Finalize the sections.
334 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
336 // Return the value to use for a dynamic which requires special
339 do_dynsym_value(const Symbol
*) const;
341 // Return the PLT address to use for a local symbol.
343 do_plt_address_for_local(const Relobj
*, unsigned int) const;
345 // Return the PLT address to use for a global symbol.
347 do_plt_address_for_global(const Symbol
*) const;
349 // Return the offset to use for the GOT_INDX'th got entry which is
350 // for a local tls symbol specified by OBJECT, SYMNDX.
352 do_tls_offset_for_local(const Relobj
* object
,
354 unsigned int got_indx
) const;
356 // Return the offset to use for the GOT_INDX'th got entry which is
357 // for global tls symbol GSYM.
359 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
361 // Relocate a section.
363 relocate_section(const Relocate_info
<size
, big_endian
>*,
364 unsigned int sh_type
,
365 const unsigned char* prelocs
,
367 Output_section
* output_section
,
368 bool needs_special_offset_handling
,
370 Address view_address
,
371 section_size_type view_size
,
372 const Reloc_symbol_changes
*);
374 // Scan the relocs during a relocatable link.
376 scan_relocatable_relocs(Symbol_table
* symtab
,
378 Sized_relobj_file
<size
, big_endian
>* object
,
379 unsigned int data_shndx
,
380 unsigned int sh_type
,
381 const unsigned char* prelocs
,
383 Output_section
* output_section
,
384 bool needs_special_offset_handling
,
385 size_t local_symbol_count
,
386 const unsigned char* plocal_symbols
,
387 Relocatable_relocs
*);
389 // Emit relocations for a section.
391 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
392 unsigned int sh_type
,
393 const unsigned char* prelocs
,
395 Output_section
* output_section
,
396 off_t offset_in_output_section
,
397 const Relocatable_relocs
*,
399 Address view_address
,
401 unsigned char* reloc_view
,
402 section_size_type reloc_view_size
);
404 // Return whether SYM is defined by the ABI.
406 do_is_defined_by_abi(const Symbol
* sym
) const
408 return strcmp(sym
->name(), "__tls_get_addr") == 0;
411 // Return the size of the GOT section.
415 gold_assert(this->got_
!= NULL
);
416 return this->got_
->data_size();
419 // Get the PLT section.
420 const Output_data_plt_powerpc
<size
, big_endian
>*
423 gold_assert(this->plt_
!= NULL
);
427 // Get the IPLT section.
428 const Output_data_plt_powerpc
<size
, big_endian
>*
431 gold_assert(this->iplt_
!= NULL
);
435 // Get the .glink section.
436 const Output_data_glink
<size
, big_endian
>*
437 glink_section() const
439 gold_assert(this->glink_
!= NULL
);
443 // Get the GOT section.
444 const Output_data_got_powerpc
<size
, big_endian
>*
447 gold_assert(this->got_
!= NULL
);
452 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
453 const elfcpp::Ehdr
<size
, big_endian
>&);
455 // Return the number of entries in the GOT.
457 got_entry_count() const
459 if (this->got_
== NULL
)
461 return this->got_size() / (size
/ 8);
464 // Return the number of entries in the PLT.
466 plt_entry_count() const;
468 // Return the offset of the first non-reserved PLT entry.
470 first_plt_entry_offset() const;
472 // Return the size of each PLT entry.
474 plt_entry_size() const;
476 // Add any special sections for this symbol to the gc work list.
477 // For powerpc64, this adds the code section of a function
480 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
482 // Handle target specific gc actions when adding a gc reference from
483 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
484 // and DST_OFF. For powerpc64, this adds a referenc to the code
485 // section of a function descriptor.
487 do_gc_add_reference(Symbol_table
* symtab
,
489 unsigned int src_shndx
,
491 unsigned int dst_shndx
,
492 Address dst_off
) const;
496 // The class which scans relocations.
500 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
503 : issued_non_pic_error_(false)
507 get_reference_flags(unsigned int r_type
);
510 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
511 Sized_relobj_file
<size
, big_endian
>* object
,
512 unsigned int data_shndx
,
513 Output_section
* output_section
,
514 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
515 const elfcpp::Sym
<size
, big_endian
>& lsym
,
519 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
520 Sized_relobj_file
<size
, big_endian
>* object
,
521 unsigned int data_shndx
,
522 Output_section
* output_section
,
523 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
527 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
529 Sized_relobj_file
<size
, big_endian
>* ,
532 const elfcpp::Rela
<size
, big_endian
>& ,
534 const elfcpp::Sym
<size
, big_endian
>&)
538 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
540 Sized_relobj_file
<size
, big_endian
>* ,
543 const elfcpp::Rela
<size
,
545 unsigned int , Symbol
*)
550 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
551 unsigned int r_type
);
554 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
555 unsigned int r_type
, Symbol
*);
558 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
559 Target_powerpc
* target
);
562 check_non_pic(Relobj
*, unsigned int r_type
);
565 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>* object
,
566 unsigned int r_type
);
568 // Whether we have issued an error about a non-PIC compilation.
569 bool issued_non_pic_error_
;
573 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
574 Powerpc_relobj
<size
, big_endian
>* object
,
575 unsigned int *dest_shndx
);
577 // The class which implements relocation.
581 // Use 'at' branch hints when true, 'y' when false.
582 // FIXME maybe: set this with an option.
583 static const bool is_isa_v2
= true;
587 CALL_NOT_EXPECTED
= 0,
593 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
598 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
600 // FIXME: This needs to specify the location somehow.
601 gold_error(_("missing expected __tls_get_addr call"));
605 // Do a relocation. Return false if the caller should not issue
606 // any warnings about this relocation.
608 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
609 Output_section
*, size_t relnum
,
610 const elfcpp::Rela
<size
, big_endian
>&,
611 unsigned int r_type
, const Sized_symbol
<size
>*,
612 const Symbol_value
<size
>*,
614 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
617 // This is set if we should skip the next reloc, which should be a
618 // call to __tls_get_addr.
619 enum skip_tls call_tls_get_addr_
;
622 // A class which returns the size required for a relocation type,
623 // used while scanning relocs during a relocatable link.
624 class Relocatable_size_for_reloc
628 get_size_for_reloc(unsigned int, Relobj
*)
635 // Optimize the TLS relocation type based on what we know about the
636 // symbol. IS_FINAL is true if the final address of this symbol is
637 // known at link time.
639 tls::Tls_optimization
640 optimize_tls_gd(bool is_final
)
642 // If we are generating a shared library, then we can't do anything
644 if (parameters
->options().shared())
645 return tls::TLSOPT_NONE
;
648 return tls::TLSOPT_TO_IE
;
649 return tls::TLSOPT_TO_LE
;
652 tls::Tls_optimization
655 if (parameters
->options().shared())
656 return tls::TLSOPT_NONE
;
658 return tls::TLSOPT_TO_LE
;
661 tls::Tls_optimization
662 optimize_tls_ie(bool is_final
)
664 if (!is_final
|| parameters
->options().shared())
665 return tls::TLSOPT_NONE
;
667 return tls::TLSOPT_TO_LE
;
670 // Get the GOT section, creating it if necessary.
671 Output_data_got_powerpc
<size
, big_endian
>*
672 got_section(Symbol_table
*, Layout
*);
676 make_glink_section(Layout
*);
678 // Create the PLT section.
680 make_plt_section(Layout
*);
683 make_iplt_section(Layout
*);
685 // Create a PLT entry for a global symbol.
687 make_plt_entry(Layout
*, Symbol
*,
688 const elfcpp::Rela
<size
, big_endian
>&,
689 const Sized_relobj_file
<size
, big_endian
>* object
);
691 // Create a PLT entry for a local IFUNC symbol.
693 make_local_ifunc_plt_entry(Layout
*,
694 const elfcpp::Rela
<size
, big_endian
>&,
695 Sized_relobj_file
<size
, big_endian
>*);
697 // Create a GOT entry for local dynamic __tls_get_addr.
699 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
700 Sized_relobj_file
<size
, big_endian
>* object
);
703 tlsld_got_offset() const
705 return this->tlsld_got_offset_
;
708 // Get the dynamic reloc section, creating it if necessary.
710 rela_dyn_section(Layout
*);
712 // Copy a relocation against a global symbol.
714 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
715 Sized_relobj_file
<size
, big_endian
>* object
,
716 unsigned int shndx
, Output_section
* output_section
,
717 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
719 this->copy_relocs_
.copy_reloc(symtab
, layout
,
720 symtab
->get_sized_symbol
<size
>(sym
),
721 object
, shndx
, output_section
,
722 reloc
, this->rela_dyn_section(layout
));
725 // Information about this specific target which we pass to the
726 // general Target structure.
727 static Target::Target_info powerpc_info
;
729 // The types of GOT entries needed for this platform.
730 // These values are exposed to the ABI in an incremental link.
731 // Do not renumber existing values without changing the version
732 // number of the .gnu_incremental_inputs section.
736 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
737 GOT_TYPE_DTPREL
, // entry for @got@dtprel
738 GOT_TYPE_TPREL
// entry for @got@tprel
741 // The GOT output section.
742 Output_data_got_powerpc
<size
, big_endian
>* got_
;
743 // The PLT output section.
744 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
745 // The IPLT output section.
746 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
747 // The .glink output section.
748 Output_data_glink
<size
, big_endian
>* glink_
;
749 // The dynamic reloc output section.
750 Reloc_section
* rela_dyn_
;
751 // Relocs saved to avoid a COPY reloc.
752 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
753 // Space for variables copied with a COPY reloc.
754 Output_data_space
* dynbss_
;
755 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
756 unsigned int tlsld_got_offset_
;
760 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
763 true, // is_big_endian
764 elfcpp::EM_PPC
, // machine_code
765 false, // has_make_symbol
766 false, // has_resolve
767 false, // has_code_fill
768 true, // is_default_stack_executable
769 false, // can_icf_inline_merge_sections
771 "/usr/lib/ld.so.1", // dynamic_linker
772 0x10000000, // default_text_segment_address
773 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
774 4 * 1024, // common_pagesize (overridable by -z common-page-size)
775 false, // isolate_execinstr
777 elfcpp::SHN_UNDEF
, // small_common_shndx
778 elfcpp::SHN_UNDEF
, // large_common_shndx
779 0, // small_common_section_flags
780 0, // large_common_section_flags
781 NULL
, // attributes_section
782 NULL
// attributes_vendor
786 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
789 false, // is_big_endian
790 elfcpp::EM_PPC
, // machine_code
791 false, // has_make_symbol
792 false, // has_resolve
793 false, // has_code_fill
794 true, // is_default_stack_executable
795 false, // can_icf_inline_merge_sections
797 "/usr/lib/ld.so.1", // dynamic_linker
798 0x10000000, // default_text_segment_address
799 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
800 4 * 1024, // common_pagesize (overridable by -z common-page-size)
801 false, // isolate_execinstr
803 elfcpp::SHN_UNDEF
, // small_common_shndx
804 elfcpp::SHN_UNDEF
, // large_common_shndx
805 0, // small_common_section_flags
806 0, // large_common_section_flags
807 NULL
, // attributes_section
808 NULL
// attributes_vendor
812 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
815 true, // is_big_endian
816 elfcpp::EM_PPC64
, // machine_code
817 false, // has_make_symbol
818 false, // has_resolve
819 false, // has_code_fill
820 true, // is_default_stack_executable
821 false, // can_icf_inline_merge_sections
823 "/usr/lib/ld.so.1", // dynamic_linker
824 0x10000000, // default_text_segment_address
825 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
826 4 * 1024, // common_pagesize (overridable by -z common-page-size)
827 false, // isolate_execinstr
829 elfcpp::SHN_UNDEF
, // small_common_shndx
830 elfcpp::SHN_UNDEF
, // large_common_shndx
831 0, // small_common_section_flags
832 0, // large_common_section_flags
833 NULL
, // attributes_section
834 NULL
// attributes_vendor
838 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
841 false, // is_big_endian
842 elfcpp::EM_PPC64
, // machine_code
843 false, // has_make_symbol
844 false, // has_resolve
845 false, // has_code_fill
846 true, // is_default_stack_executable
847 false, // can_icf_inline_merge_sections
849 "/usr/lib/ld.so.1", // dynamic_linker
850 0x10000000, // default_text_segment_address
851 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
852 4 * 1024, // common_pagesize (overridable by -z common-page-size)
853 false, // isolate_execinstr
855 elfcpp::SHN_UNDEF
, // small_common_shndx
856 elfcpp::SHN_UNDEF
, // large_common_shndx
857 0, // small_common_section_flags
858 0, // large_common_section_flags
859 NULL
, // attributes_section
860 NULL
// attributes_vendor
864 is_branch_reloc(unsigned int r_type
)
866 return (r_type
== elfcpp::R_POWERPC_REL24
867 || r_type
== elfcpp::R_PPC_PLTREL24
868 || r_type
== elfcpp::R_PPC_LOCAL24PC
869 || r_type
== elfcpp::R_POWERPC_REL14
870 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
871 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
872 || r_type
== elfcpp::R_POWERPC_ADDR24
873 || r_type
== elfcpp::R_POWERPC_ADDR14
874 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
875 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
878 // If INSN is an opcode that may be used with an @tls operand, return
879 // the transformed insn for TLS optimisation, otherwise return 0. If
880 // REG is non-zero only match an insn with RB or RA equal to REG.
882 at_tls_transform(uint32_t insn
, unsigned int reg
)
884 if ((insn
& (0x3f << 26)) != 31 << 26)
888 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
889 rtra
= insn
& ((1 << 26) - (1 << 16));
890 else if (((insn
>> 16) & 0x1f) == reg
)
891 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
895 if ((insn
& (0x3ff << 1)) == 266 << 1)
898 else if ((insn
& (0x1f << 1)) == 23 << 1
899 && ((insn
& (0x1f << 6)) < 14 << 6
900 || ((insn
& (0x1f << 6)) >= 16 << 6
901 && (insn
& (0x1f << 6)) < 24 << 6)))
902 // load and store indexed -> dform
903 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
904 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
905 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
906 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
907 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
909 insn
= (58 << 26) | 2;
916 // Modified version of symtab.h class Symbol member
917 // Given a direct absolute or pc-relative static relocation against
918 // the global symbol, this function returns whether a dynamic relocation
923 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
925 // No dynamic relocations in a static link!
926 if (parameters
->doing_static_link())
929 // A reference to an undefined symbol from an executable should be
930 // statically resolved to 0, and does not need a dynamic relocation.
931 // This matches gnu ld behavior.
932 if (gsym
->is_undefined() && !parameters
->options().shared())
935 // A reference to an absolute symbol does not need a dynamic relocation.
936 if (gsym
->is_absolute())
939 // An absolute reference within a position-independent output file
940 // will need a dynamic relocation.
941 if ((flags
& Symbol::ABSOLUTE_REF
)
942 && parameters
->options().output_is_position_independent())
945 // A function call that can branch to a local PLT entry does not need
946 // a dynamic relocation.
947 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
950 // A reference to any PLT entry in a non-position-independent executable
951 // does not need a dynamic relocation.
952 // Except due to having function descriptors on powerpc64 we don't define
953 // functions to their plt code in an executable, so this doesn't apply.
955 && !parameters
->options().output_is_position_independent()
956 && gsym
->has_plt_offset())
959 // A reference to a symbol defined in a dynamic object or to a
960 // symbol that is preemptible will need a dynamic relocation.
961 if (gsym
->is_from_dynobj()
962 || gsym
->is_undefined()
963 || gsym
->is_preemptible())
966 // For all other cases, return FALSE.
970 // Modified version of symtab.h class Symbol member
971 // Whether we should use the PLT offset associated with a symbol for
972 // a relocation. FLAGS is a set of Reference_flags.
976 use_plt_offset(const Symbol
* gsym
, int flags
)
978 // If the symbol doesn't have a PLT offset, then naturally we
979 // don't want to use it.
980 if (!gsym
->has_plt_offset())
983 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
984 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
987 // If we are going to generate a dynamic relocation, then we will
988 // wind up using that, so no need to use the PLT entry.
989 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
992 // If the symbol is from a dynamic object, we need to use the PLT
994 if (gsym
->is_from_dynobj())
997 // If we are generating a shared object, and gsym symbol is
998 // undefined or preemptible, we need to use the PLT entry.
999 if (parameters
->options().shared()
1000 && (gsym
->is_undefined() || gsym
->is_preemptible()))
1003 // If gsym is a call to a weak undefined symbol, we need to use
1004 // the PLT entry; the symbol may be defined by a library loaded
1006 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
1009 // Otherwise we can use the regular definition.
1013 template<int size
, bool big_endian
>
1014 class Powerpc_relocate_functions
1031 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1032 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1034 template<int valsize
>
1036 has_overflow_signed(Address value
)
1038 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1039 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1040 limit
<<= ((valsize
- 1) >> 1);
1041 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1042 return value
+ limit
> (limit
<< 1) - 1;
1045 template<int valsize
>
1047 has_overflow_bitfield(Address value
)
1049 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1050 limit
<<= ((valsize
- 1) >> 1);
1051 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1052 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
1055 template<int valsize
>
1056 static inline Status
1057 overflowed(Address value
, Overflow_check overflow
)
1059 if (overflow
== CHECK_SIGNED
)
1061 if (has_overflow_signed
<valsize
>(value
))
1062 return STATUS_OVERFLOW
;
1064 else if (overflow
== CHECK_BITFIELD
)
1066 if (has_overflow_bitfield
<valsize
>(value
))
1067 return STATUS_OVERFLOW
;
1072 // Do a simple RELA relocation
1073 template<int valsize
>
1074 static inline Status
1075 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1077 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1078 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1079 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1080 return overflowed
<valsize
>(value
, overflow
);
1083 template<int valsize
>
1084 static inline Status
1085 rela(unsigned char* view
,
1086 unsigned int right_shift
,
1087 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1089 Overflow_check overflow
)
1091 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1092 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1093 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1094 Valtype reloc
= value
>> right_shift
;
1097 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1098 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1101 // Do a simple RELA relocation, unaligned.
1102 template<int valsize
>
1103 static inline Status
1104 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1106 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1107 return overflowed
<valsize
>(value
, overflow
);
1110 template<int valsize
>
1111 static inline Status
1112 rela_ua(unsigned char* view
,
1113 unsigned int right_shift
,
1114 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1116 Overflow_check overflow
)
1118 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1120 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1121 Valtype reloc
= value
>> right_shift
;
1124 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1125 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1129 // R_PPC64_ADDR64: (Symbol + Addend)
1131 addr64(unsigned char* view
, Address value
)
1132 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1134 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1136 addr64_u(unsigned char* view
, Address value
)
1137 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1139 // R_POWERPC_ADDR32: (Symbol + Addend)
1140 static inline Status
1141 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1142 { return This::template rela
<32>(view
, value
, overflow
); }
1144 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1145 static inline Status
1146 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1147 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1149 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1150 static inline Status
1151 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1153 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1154 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1155 stat
= STATUS_OVERFLOW
;
1159 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1160 static inline Status
1161 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1162 { return This::template rela
<16>(view
, value
, overflow
); }
1164 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1165 static inline Status
1166 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1167 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1169 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1170 static inline Status
1171 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1173 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1174 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1175 stat
= STATUS_OVERFLOW
;
1179 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1181 addr16_hi(unsigned char* view
, Address value
)
1182 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1184 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1186 addr16_ha(unsigned char* view
, Address value
)
1187 { This::addr16_hi(view
, value
+ 0x8000); }
1189 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1191 addr16_hi2(unsigned char* view
, Address value
)
1192 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1194 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1196 addr16_ha2(unsigned char* view
, Address value
)
1197 { This::addr16_hi2(view
, value
+ 0x8000); }
1199 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1201 addr16_hi3(unsigned char* view
, Address value
)
1202 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1204 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1206 addr16_ha3(unsigned char* view
, Address value
)
1207 { This::addr16_hi3(view
, value
+ 0x8000); }
1209 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1210 static inline Status
1211 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1213 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1214 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1215 stat
= STATUS_OVERFLOW
;
1220 // Stash away the index of .got2 or .opd in a relocatable object, if
1221 // such a section exists.
1223 template<int size
, bool big_endian
>
1225 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1226 Read_symbols_data
* sd
)
1228 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1229 const unsigned char* namesu
= sd
->section_names
->data();
1230 const char* names
= reinterpret_cast<const char*>(namesu
);
1231 section_size_type names_size
= sd
->section_names_size
;
1232 const unsigned char* s
;
1234 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1235 names
, names_size
, NULL
);
1238 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1239 this->special_
= ndx
;
1241 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1244 // Examine .rela.opd to build info about function entry points.
1246 template<int size
, bool big_endian
>
1248 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1250 const unsigned char* prelocs
,
1251 const unsigned char* plocal_syms
)
1255 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1257 const int reloc_size
1258 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1259 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1260 Address expected_off
= 0;
1261 bool regular
= true;
1262 unsigned int opd_ent_size
= 0;
1264 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1266 Reltype
reloc(prelocs
);
1267 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1268 = reloc
.get_r_info();
1269 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1270 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1272 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1273 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1276 if (r_sym
< this->local_symbol_count())
1278 typename
elfcpp::Sym
<size
, big_endian
>
1279 lsym(plocal_syms
+ r_sym
* sym_size
);
1280 shndx
= lsym
.get_st_shndx();
1281 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1282 value
= lsym
.get_st_value();
1285 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1287 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1288 value
+ reloc
.get_r_addend());
1291 expected_off
= reloc
.get_r_offset();
1292 opd_ent_size
= expected_off
;
1294 else if (expected_off
!= reloc
.get_r_offset())
1296 expected_off
+= opd_ent_size
;
1298 else if (r_type
== elfcpp::R_PPC64_TOC
)
1300 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1305 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1306 this->name().c_str(), r_type
);
1310 if (reloc_count
<= 2)
1311 opd_ent_size
= this->section_size(this->opd_shndx());
1312 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1316 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1317 this->name().c_str());
1323 template<int size
, bool big_endian
>
1325 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1327 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1330 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1331 p
!= rd
->relocs
.end();
1334 if (p
->data_shndx
== this->opd_shndx())
1336 uint64_t opd_size
= this->section_size(this->opd_shndx());
1337 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1340 this->init_opd(opd_size
);
1341 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1342 rd
->local_symbols
->data());
1350 // Set up PowerPC target specific relobj.
1352 template<int size
, bool big_endian
>
1354 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1355 const std::string
& name
,
1356 Input_file
* input_file
,
1357 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1359 int et
= ehdr
.get_e_type();
1360 // ET_EXEC files are valid input for --just-symbols/-R,
1361 // and we treat them as relocatable objects.
1362 if (et
== elfcpp::ET_REL
1363 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1365 Powerpc_relobj
<size
, big_endian
>* obj
=
1366 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1370 else if (et
== elfcpp::ET_DYN
)
1372 Sized_dynobj
<size
, big_endian
>* obj
=
1373 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1379 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1384 template<int size
, bool big_endian
>
1385 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1388 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1389 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1391 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1392 : Output_data_got
<size
, big_endian
>(),
1393 symtab_(symtab
), layout_(layout
),
1394 header_ent_cnt_(size
== 32 ? 3 : 1),
1395 header_index_(size
== 32 ? 0x2000 : 0)
1400 // Create a new GOT entry and return its offset.
1402 add_got_entry(Got_entry got_entry
)
1404 this->reserve_ent();
1405 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1408 // Create a pair of new GOT entries and return the offset of the first.
1410 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1412 this->reserve_ent(2);
1413 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1418 add_constant_pair(Valtype c1
, Valtype c2
)
1420 this->reserve_ent(2);
1421 unsigned int got_offset
= this->add_constant(c1
);
1422 this->add_constant(c2
);
1426 // Offset of _GLOBAL_OFFSET_TABLE_.
1430 return this->got_offset(this->header_index_
);
1433 // Offset of base used to access the GOT/TOC.
1434 // The got/toc pointer reg will be set to this value.
1435 typename
elfcpp::Elf_types
<size
>::Elf_Off
1436 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1439 return this->g_o_t();
1441 return (this->output_section()->address()
1442 + object
->toc_base_offset()
1446 // Ensure our GOT has a header.
1448 set_final_data_size()
1450 if (this->header_ent_cnt_
!= 0)
1451 this->make_header();
1452 Output_data_got
<size
, big_endian
>::set_final_data_size();
1455 // First word of GOT header needs some values that are not
1456 // handled by Output_data_got so poke them in here.
1457 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1459 do_write(Output_file
* of
)
1462 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
1463 val
= this->layout_
->dynamic_section()->address();
1465 val
= this->output_section()->address() + 0x8000;
1466 this->replace_constant(this->header_index_
, val
);
1467 Output_data_got
<size
, big_endian
>::do_write(of
);
1472 reserve_ent(unsigned int cnt
= 1)
1474 if (this->header_ent_cnt_
== 0)
1476 if (this->num_entries() + cnt
> this->header_index_
)
1477 this->make_header();
1483 this->header_ent_cnt_
= 0;
1484 this->header_index_
= this->num_entries();
1487 Output_data_got
<size
, big_endian
>::add_constant(0);
1488 Output_data_got
<size
, big_endian
>::add_constant(0);
1489 Output_data_got
<size
, big_endian
>::add_constant(0);
1491 // Define _GLOBAL_OFFSET_TABLE_ at the header
1492 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1493 Symbol_table::PREDEFINED
,
1494 this, this->g_o_t(), 0,
1501 Output_data_got
<size
, big_endian
>::add_constant(0);
1504 // Stashed pointers.
1505 Symbol_table
* symtab_
;
1509 unsigned int header_ent_cnt_
;
1510 // GOT header index.
1511 unsigned int header_index_
;
1514 // Get the GOT section, creating it if necessary.
1516 template<int size
, bool big_endian
>
1517 Output_data_got_powerpc
<size
, big_endian
>*
1518 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1521 if (this->got_
== NULL
)
1523 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1526 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1528 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1529 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1530 this->got_
, ORDER_DATA
, false);
1536 // Get the dynamic reloc section, creating it if necessary.
1538 template<int size
, bool big_endian
>
1539 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1540 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1542 if (this->rela_dyn_
== NULL
)
1544 gold_assert(layout
!= NULL
);
1545 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1546 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1547 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1548 ORDER_DYNAMIC_RELOCS
, false);
1550 return this->rela_dyn_
;
1553 // A class to handle the PLT data.
1555 template<int size
, bool big_endian
>
1556 class Output_data_plt_powerpc
: public Output_section_data_build
1559 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1560 size
, big_endian
> Reloc_section
;
1562 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
1563 Reloc_section
* plt_rel
,
1564 unsigned int reserved_size
,
1566 : Output_section_data_build(size
== 32 ? 4 : 8),
1569 initial_plt_entry_size_(reserved_size
),
1573 // Add an entry to the PLT.
1578 add_ifunc_entry(Symbol
*);
1581 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
1583 // Return the .rela.plt section data.
1590 // Return the number of PLT entries.
1594 return ((this->current_data_size() - this->initial_plt_entry_size_
)
1598 // Return the offset of the first non-reserved PLT entry.
1600 first_plt_entry_offset()
1601 { return this->initial_plt_entry_size_
; }
1603 // Return the size of a PLT entry.
1605 get_plt_entry_size()
1606 { return plt_entry_size
; }
1610 do_adjust_output_section(Output_section
* os
)
1615 // Write to a map file.
1617 do_print_to_mapfile(Mapfile
* mapfile
) const
1618 { mapfile
->print_output_data(this, this->name_
); }
1621 // The size of an entry in the PLT.
1622 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1624 // Write out the PLT data.
1626 do_write(Output_file
*);
1628 // The reloc section.
1629 Reloc_section
* rel_
;
1630 // Allows access to .glink for do_write.
1631 Target_powerpc
<size
, big_endian
>* targ_
;
1632 // The size of the first reserved entry.
1633 int initial_plt_entry_size_
;
1634 // What to report in map file.
1638 // Add an entry to the PLT.
1640 template<int size
, bool big_endian
>
1642 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1644 if (!gsym
->has_plt_offset())
1646 off_t off
= this->current_data_size();
1648 off
+= this->first_plt_entry_offset();
1649 gsym
->set_plt_offset(off
);
1650 gsym
->set_needs_dynsym_entry();
1651 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
1652 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
1653 off
+= plt_entry_size
;
1654 this->set_current_data_size(off
);
1658 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
1660 template<int size
, bool big_endian
>
1662 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
1664 if (!gsym
->has_plt_offset())
1666 off_t off
= this->current_data_size();
1667 gsym
->set_plt_offset(off
);
1668 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1670 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1671 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
1672 off
+= plt_entry_size
;
1673 this->set_current_data_size(off
);
1677 // Add an entry for a local ifunc symbol to the IPLT.
1679 template<int size
, bool big_endian
>
1681 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
1682 Sized_relobj_file
<size
, big_endian
>* relobj
,
1683 unsigned int local_sym_index
)
1685 if (!relobj
->local_has_plt_offset(local_sym_index
))
1687 off_t off
= this->current_data_size();
1688 relobj
->set_local_plt_offset(local_sym_index
, off
);
1689 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1691 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1692 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
1694 off
+= plt_entry_size
;
1695 this->set_current_data_size(off
);
1699 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1700 static const uint32_t add_3_3_2
= 0x7c631214;
1701 static const uint32_t add_3_3_13
= 0x7c636a14;
1702 static const uint32_t add_11_0_11
= 0x7d605a14;
1703 static const uint32_t add_12_2_11
= 0x7d825a14;
1704 static const uint32_t addi_11_11
= 0x396b0000;
1705 static const uint32_t addi_12_12
= 0x398c0000;
1706 static const uint32_t addi_2_2
= 0x38420000;
1707 static const uint32_t addi_3_2
= 0x38620000;
1708 static const uint32_t addi_3_3
= 0x38630000;
1709 static const uint32_t addis_0_2
= 0x3c020000;
1710 static const uint32_t addis_0_13
= 0x3c0d0000;
1711 static const uint32_t addis_11_11
= 0x3d6b0000;
1712 static const uint32_t addis_11_30
= 0x3d7e0000;
1713 static const uint32_t addis_12_12
= 0x3d8c0000;
1714 static const uint32_t addis_12_2
= 0x3d820000;
1715 static const uint32_t addis_3_2
= 0x3c620000;
1716 static const uint32_t addis_3_13
= 0x3c6d0000;
1717 static const uint32_t b
= 0x48000000;
1718 static const uint32_t bcl_20_31
= 0x429f0005;
1719 static const uint32_t bctr
= 0x4e800420;
1720 static const uint32_t blr
= 0x4e800020;
1721 static const uint32_t blrl
= 0x4e800021;
1722 static const uint32_t cror_15_15_15
= 0x4def7b82;
1723 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1724 static const uint32_t ld_0_1
= 0xe8010000;
1725 static const uint32_t ld_0_12
= 0xe80c0000;
1726 static const uint32_t ld_11_12
= 0xe96c0000;
1727 static const uint32_t ld_11_2
= 0xe9620000;
1728 static const uint32_t ld_2_1
= 0xe8410000;
1729 static const uint32_t ld_2_11
= 0xe84b0000;
1730 static const uint32_t ld_2_12
= 0xe84c0000;
1731 static const uint32_t ld_2_2
= 0xe8420000;
1732 static const uint32_t lfd_0_1
= 0xc8010000;
1733 static const uint32_t li_0_0
= 0x38000000;
1734 static const uint32_t li_12_0
= 0x39800000;
1735 static const uint32_t lis_0_0
= 0x3c000000;
1736 static const uint32_t lis_11
= 0x3d600000;
1737 static const uint32_t lis_12
= 0x3d800000;
1738 static const uint32_t lwz_0_12
= 0x800c0000;
1739 static const uint32_t lwz_11_11
= 0x816b0000;
1740 static const uint32_t lwz_11_30
= 0x817e0000;
1741 static const uint32_t lwz_12_12
= 0x818c0000;
1742 static const uint32_t lwzu_0_12
= 0x840c0000;
1743 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
1744 static const uint32_t mflr_0
= 0x7c0802a6;
1745 static const uint32_t mflr_11
= 0x7d6802a6;
1746 static const uint32_t mflr_12
= 0x7d8802a6;
1747 static const uint32_t mtctr_0
= 0x7c0903a6;
1748 static const uint32_t mtctr_11
= 0x7d6903a6;
1749 static const uint32_t mtlr_0
= 0x7c0803a6;
1750 static const uint32_t mtlr_12
= 0x7d8803a6;
1751 static const uint32_t nop
= 0x60000000;
1752 static const uint32_t ori_0_0_0
= 0x60000000;
1753 static const uint32_t std_0_1
= 0xf8010000;
1754 static const uint32_t std_0_12
= 0xf80c0000;
1755 static const uint32_t std_2_1
= 0xf8410000;
1756 static const uint32_t stfd_0_1
= 0xd8010000;
1757 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
1758 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1760 // Write out the PLT.
1762 template<int size
, bool big_endian
>
1764 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1768 const off_t offset
= this->offset();
1769 const section_size_type oview_size
1770 = convert_to_section_size_type(this->data_size());
1771 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1772 unsigned char* pov
= oview
;
1773 unsigned char* endpov
= oview
+ oview_size
;
1775 // The address of the .glink branch table
1776 const Output_data_glink
<size
, big_endian
>* glink
1777 = this->targ_
->glink_section();
1778 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1779 = glink
->address() + glink
->pltresolve();
1781 while (pov
< endpov
)
1783 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1788 of
->write_output_view(offset
, oview_size
, oview
);
1792 // Create the PLT section.
1794 template<int size
, bool big_endian
>
1796 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1798 if (this->plt_
== NULL
)
1800 if (this->glink_
== NULL
)
1801 make_glink_section(layout
);
1803 // Ensure that .rela.dyn always appears before .rela.plt This is
1804 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1805 // needs to include .rela.plt in it's range.
1806 this->rela_dyn_section(layout
);
1808 Reloc_section
* plt_rel
= new Reloc_section(false);
1809 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1810 elfcpp::SHF_ALLOC
, plt_rel
,
1811 ORDER_DYNAMIC_PLT_RELOCS
, false);
1813 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
1814 size
== 32 ? 0 : 24,
1816 layout
->add_output_section_data(".plt",
1818 ? elfcpp::SHT_PROGBITS
1819 : elfcpp::SHT_NOBITS
),
1820 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1829 // Create the IPLT section.
1831 template<int size
, bool big_endian
>
1833 Target_powerpc
<size
, big_endian
>::make_iplt_section(Layout
* layout
)
1835 if (this->iplt_
== NULL
)
1837 this->make_plt_section(layout
);
1839 Reloc_section
* iplt_rel
= new Reloc_section(false);
1840 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
1842 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
1844 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
1848 // A class to handle .glink.
1850 template<int size
, bool big_endian
>
1851 class Output_data_glink
: public Output_section_data
1854 static const int pltresolve_size
= 16*4;
1856 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1860 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1862 const elfcpp::Rela
<size
, big_endian
>&);
1865 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1867 const elfcpp::Rela
<size
, big_endian
>&);
1870 find_entry(const Symbol
*) const;
1873 find_entry(const Sized_relobj_file
<size
, big_endian
>*, unsigned int) const;
1876 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1878 const elfcpp::Rela
<size
, big_endian
>&) const;
1881 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1883 const elfcpp::Rela
<size
, big_endian
>&) const;
1886 glink_entry_size() const
1891 // FIXME: We should be using multiple glink sections for
1892 // stubs to support > 33M applications.
1899 return this->pltresolve_
;
1903 // Write to a map file.
1905 do_print_to_mapfile(Mapfile
* mapfile
) const
1906 { mapfile
->print_output_data(this, _("** glink")); }
1910 set_final_data_size();
1914 do_write(Output_file
*);
1919 Glink_sym_ent(const Symbol
* sym
)
1920 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1923 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1924 unsigned int locsym_index
)
1925 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1928 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1930 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1931 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1934 this->addend_
= reloc
.get_r_addend();
1935 else if (parameters
->options().output_is_position_independent()
1936 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1937 == elfcpp::R_PPC_PLTREL24
))
1939 this->addend_
= reloc
.get_r_addend();
1940 if (this->addend_
>= 32768)
1941 this->object_
= object
;
1945 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1946 unsigned int locsym_index
,
1947 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1948 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1951 this->addend_
= reloc
.get_r_addend();
1952 else if (parameters
->options().output_is_position_independent()
1953 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1954 == elfcpp::R_PPC_PLTREL24
))
1955 this->addend_
= reloc
.get_r_addend();
1958 bool operator==(const Glink_sym_ent
& that
) const
1960 return (this->sym_
== that
.sym_
1961 && this->object_
== that
.object_
1962 && this->addend_
== that
.addend_
1963 && this->locsym_
== that
.locsym_
);
1967 const Sized_relobj_file
<size
, big_endian
>* object_
;
1968 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
1969 unsigned int locsym_
;
1972 class Glink_sym_ent_hash
1975 size_t operator()(const Glink_sym_ent
& ent
) const
1977 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1978 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1984 // Map sym/object/addend to index.
1985 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1986 Glink_sym_ent_hash
> Glink_entries
;
1987 Glink_entries glink_entries_
;
1989 // Offset of pltresolve stub (actually, branch table for 32-bit)
1992 // Allows access to .got and .plt for do_write.
1993 Target_powerpc
<size
, big_endian
>* targ_
;
1996 // Create the glink section.
1998 template<int size
, bool big_endian
>
1999 Output_data_glink
<size
, big_endian
>::Output_data_glink(
2000 Target_powerpc
<size
, big_endian
>* targ
)
2001 : Output_section_data(16),
2002 pltresolve_(0), targ_(targ
)
2006 // Add an entry to glink, if we do not already have one for this
2007 // sym/object/addend combo.
2009 template<int size
, bool big_endian
>
2011 Output_data_glink
<size
, big_endian
>::add_entry(
2012 const Sized_relobj_file
<size
, big_endian
>* object
,
2014 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2016 Glink_sym_ent
ent(object
, gsym
, reloc
);
2017 unsigned int indx
= this->glink_entries_
.size();
2018 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2021 template<int size
, bool big_endian
>
2023 Output_data_glink
<size
, big_endian
>::add_entry(
2024 const Sized_relobj_file
<size
, big_endian
>* object
,
2025 unsigned int locsym_index
,
2026 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2028 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2029 unsigned int indx
= this->glink_entries_
.size();
2030 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2033 template<int size
, bool big_endian
>
2035 Output_data_glink
<size
, big_endian
>::find_entry(
2036 const Sized_relobj_file
<size
, big_endian
>* object
,
2038 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2040 Glink_sym_ent
ent(object
, gsym
, reloc
);
2041 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2042 gold_assert(p
!= this->glink_entries_
.end());
2046 template<int size
, bool big_endian
>
2048 Output_data_glink
<size
, big_endian
>::find_entry(const Symbol
* gsym
) const
2050 Glink_sym_ent
ent(gsym
);
2051 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2052 gold_assert(p
!= this->glink_entries_
.end());
2056 template<int size
, bool big_endian
>
2058 Output_data_glink
<size
, big_endian
>::find_entry(
2059 const Sized_relobj_file
<size
, big_endian
>* object
,
2060 unsigned int locsym_index
,
2061 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2063 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2064 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2065 gold_assert(p
!= this->glink_entries_
.end());
2069 template<int size
, bool big_endian
>
2071 Output_data_glink
<size
, big_endian
>::find_entry(
2072 const Sized_relobj_file
<size
, big_endian
>* object
,
2073 unsigned int locsym_index
) const
2075 Glink_sym_ent
ent(object
, locsym_index
);
2076 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2077 gold_assert(p
!= this->glink_entries_
.end());
2081 template<int size
, bool big_endian
>
2083 Output_data_glink
<size
, big_endian
>::set_final_data_size()
2085 unsigned int count
= this->glink_entries_
.size();
2086 off_t total
= count
;
2093 this->pltresolve_
= total
;
2095 // space for branch table
2096 total
+= 4 * (count
- 1);
2098 total
+= -total
& 15;
2099 total
+= this->pltresolve_size
;
2104 this->pltresolve_
= total
;
2105 total
+= this->pltresolve_size
;
2107 // space for branch table
2110 total
+= 4 * (count
- 0x8000);
2114 this->set_data_size(total
);
2117 static inline uint32_t
2123 static inline uint32_t
2129 static inline uint32_t
2132 return hi(a
+ 0x8000);
2135 template<bool big_endian
>
2137 write_insn(unsigned char* p
, uint32_t v
)
2139 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
2142 // Write out .glink.
2144 template<int size
, bool big_endian
>
2146 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
2148 const off_t off
= this->offset();
2149 const section_size_type oview_size
=
2150 convert_to_section_size_type(this->data_size());
2151 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
2154 // The base address of the .plt section.
2155 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2156 static const Address invalid_address
= static_cast<Address
>(0) - 1;
2157 Address plt_base
= this->targ_
->plt_section()->address();
2158 Address iplt_base
= invalid_address
;
2160 const Output_data_got_powerpc
<size
, big_endian
>* got
2161 = this->targ_
->got_section();
2165 Address got_os_addr
= got
->output_section()->address();
2167 // Write out call stubs.
2168 typename
Glink_entries::const_iterator g
;
2169 for (g
= this->glink_entries_
.begin();
2170 g
!= this->glink_entries_
.end();
2175 const Symbol
* gsym
= g
->first
.sym_
;
2178 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2179 && gsym
->can_use_relative_reloc(false));
2180 plt_addr
= gsym
->plt_offset();
2185 const Sized_relobj_file
<size
, big_endian
>* relobj
2187 unsigned int local_sym_index
= g
->first
.locsym_
;
2188 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2192 if (iplt_base
== invalid_address
)
2193 iplt_base
= this->targ_
->iplt_section()->address();
2194 plt_addr
+= iplt_base
;
2197 plt_addr
+= plt_base
;
2198 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2199 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2200 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
2201 Address pltoff
= plt_addr
- got_addr
;
2203 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
2204 gold_error(_("%s: linkage table error against `%s'"),
2205 g
->first
.object_
->name().c_str(),
2206 g
->first
.sym_
->demangled_name().c_str());
2208 p
= oview
+ g
->second
* this->glink_entry_size();
2209 if (ha(pltoff
) != 0)
2211 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
2212 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2213 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
2214 if (ha(pltoff
+ 16) != ha(pltoff
))
2216 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
2219 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2220 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
2221 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
2222 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2226 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2227 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
2228 if (ha(pltoff
+ 16) != ha(pltoff
))
2230 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
2233 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2234 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
2235 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
2236 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2240 // Write pltresolve stub.
2241 p
= oview
+ this->pltresolve_
;
2242 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
2243 Address pltoff
= plt_base
- after_bcl
;
2245 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
2247 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
2248 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
2249 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
2250 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
2251 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
2252 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
2253 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
2254 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
2255 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2256 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
2257 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2258 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
2259 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2261 // Write lazy link call stubs.
2263 while (p
< oview
+ oview_size
)
2267 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
2271 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
2272 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
2274 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
2275 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
2281 // The address of _GLOBAL_OFFSET_TABLE_.
2282 Address g_o_t
= got
->address() + got
->g_o_t();
2284 // Write out call stubs.
2285 typename
Glink_entries::const_iterator g
;
2286 for (g
= this->glink_entries_
.begin();
2287 g
!= this->glink_entries_
.end();
2292 const Symbol
* gsym
= g
->first
.sym_
;
2295 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2296 && gsym
->can_use_relative_reloc(false));
2297 plt_addr
= gsym
->plt_offset();
2302 const Sized_relobj_file
<size
, big_endian
>* relobj
2304 unsigned int local_sym_index
= g
->first
.locsym_
;
2305 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2309 if (iplt_base
== invalid_address
)
2310 iplt_base
= this->targ_
->iplt_section()->address();
2311 plt_addr
+= iplt_base
;
2314 plt_addr
+= plt_base
;
2316 p
= oview
+ g
->second
* this->glink_entry_size();
2317 if (parameters
->options().output_is_position_independent())
2320 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
2321 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2322 if (object
!= NULL
&& g
->first
.addend_
>= 32768)
2324 unsigned int got2
= object
->got2_shndx();
2325 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
2326 gold_assert(got_addr
!= invalid_address
);
2327 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
2328 + g
->first
.addend_
);
2333 Address pltoff
= plt_addr
- got_addr
;
2334 if (ha(pltoff
) == 0)
2336 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
2337 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
2338 write_insn
<big_endian
>(p
+ 8, bctr
);
2342 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
2343 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
2344 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2345 write_insn
<big_endian
>(p
+ 12, bctr
);
2350 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
2351 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
2352 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2353 write_insn
<big_endian
>(p
+ 12, bctr
);
2357 // Write out pltresolve branch table.
2358 p
= oview
+ this->pltresolve_
;
2359 unsigned int the_end
= oview_size
- this->pltresolve_size
;
2360 unsigned char* end_p
= oview
+ the_end
;
2361 while (p
< end_p
- 8 * 4)
2362 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
2364 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2366 // Write out pltresolve call stub.
2367 if (parameters
->options().output_is_position_independent())
2369 Address res0_off
= this->pltresolve_
;
2370 Address after_bcl_off
= the_end
+ 12;
2371 Address bcl_res0
= after_bcl_off
- res0_off
;
2373 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2374 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2375 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2376 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2377 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2378 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2379 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2381 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2383 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2384 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2386 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2387 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2391 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2392 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2394 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2395 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2396 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2397 write_insn
<big_endian
>(p
+ 52, bctr
);
2398 write_insn
<big_endian
>(p
+ 56, nop
);
2399 write_insn
<big_endian
>(p
+ 60, nop
);
2403 Address res0
= this->pltresolve_
+ this->address();
2405 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2406 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2407 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2408 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2410 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2411 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2412 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2413 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2414 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2415 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2417 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2418 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2419 write_insn
<big_endian
>(p
+ 32, bctr
);
2420 write_insn
<big_endian
>(p
+ 36, nop
);
2421 write_insn
<big_endian
>(p
+ 40, nop
);
2422 write_insn
<big_endian
>(p
+ 44, nop
);
2423 write_insn
<big_endian
>(p
+ 48, nop
);
2424 write_insn
<big_endian
>(p
+ 52, nop
);
2425 write_insn
<big_endian
>(p
+ 56, nop
);
2426 write_insn
<big_endian
>(p
+ 60, nop
);
2431 of
->write_output_view(off
, oview_size
, oview
);
2435 // A class to handle linker generated save/restore functions.
2437 template<int size
, bool big_endian
>
2438 class Output_data_save_res
: public Output_section_data_build
2441 Output_data_save_res(Symbol_table
* symtab
);
2444 // Write to a map file.
2446 do_print_to_mapfile(Mapfile
* mapfile
) const
2447 { mapfile
->print_output_data(this, _("** save/restore")); }
2450 do_write(Output_file
*);
2453 // The maximum size of save/restore contents.
2454 static const unsigned int savres_max
= 218*4;
2457 savres_define(Symbol_table
* symtab
,
2459 unsigned int lo
, unsigned int hi
,
2460 unsigned char* write_ent(unsigned char*, int),
2461 unsigned char* write_tail(unsigned char*, int));
2463 unsigned char *contents_
;
2466 template<bool big_endian
>
2467 static unsigned char*
2468 savegpr0(unsigned char* p
, int r
)
2470 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2471 write_insn
<big_endian
>(p
, insn
);
2475 template<bool big_endian
>
2476 static unsigned char*
2477 savegpr0_tail(unsigned char* p
, int r
)
2479 p
= savegpr0
<big_endian
>(p
, r
);
2480 uint32_t insn
= std_0_1
+ 16;
2481 write_insn
<big_endian
>(p
, insn
);
2483 write_insn
<big_endian
>(p
, blr
);
2487 template<bool big_endian
>
2488 static unsigned char*
2489 restgpr0(unsigned char* p
, int r
)
2491 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2492 write_insn
<big_endian
>(p
, insn
);
2496 template<bool big_endian
>
2497 static unsigned char*
2498 restgpr0_tail(unsigned char* p
, int r
)
2500 uint32_t insn
= ld_0_1
+ 16;
2501 write_insn
<big_endian
>(p
, insn
);
2503 p
= restgpr0
<big_endian
>(p
, r
);
2504 write_insn
<big_endian
>(p
, mtlr_0
);
2508 p
= restgpr0
<big_endian
>(p
, 30);
2509 p
= restgpr0
<big_endian
>(p
, 31);
2511 write_insn
<big_endian
>(p
, blr
);
2515 template<bool big_endian
>
2516 static unsigned char*
2517 savegpr1(unsigned char* p
, int r
)
2519 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2520 write_insn
<big_endian
>(p
, insn
);
2524 template<bool big_endian
>
2525 static unsigned char*
2526 savegpr1_tail(unsigned char* p
, int r
)
2528 p
= savegpr1
<big_endian
>(p
, r
);
2529 write_insn
<big_endian
>(p
, blr
);
2533 template<bool big_endian
>
2534 static unsigned char*
2535 restgpr1(unsigned char* p
, int r
)
2537 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2538 write_insn
<big_endian
>(p
, insn
);
2542 template<bool big_endian
>
2543 static unsigned char*
2544 restgpr1_tail(unsigned char* p
, int r
)
2546 p
= restgpr1
<big_endian
>(p
, r
);
2547 write_insn
<big_endian
>(p
, blr
);
2551 template<bool big_endian
>
2552 static unsigned char*
2553 savefpr(unsigned char* p
, int r
)
2555 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2556 write_insn
<big_endian
>(p
, insn
);
2560 template<bool big_endian
>
2561 static unsigned char*
2562 savefpr0_tail(unsigned char* p
, int r
)
2564 p
= savefpr
<big_endian
>(p
, r
);
2565 write_insn
<big_endian
>(p
, std_0_1
+ 16);
2567 write_insn
<big_endian
>(p
, blr
);
2571 template<bool big_endian
>
2572 static unsigned char*
2573 restfpr(unsigned char* p
, int r
)
2575 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2576 write_insn
<big_endian
>(p
, insn
);
2580 template<bool big_endian
>
2581 static unsigned char*
2582 restfpr0_tail(unsigned char* p
, int r
)
2584 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
2586 p
= restfpr
<big_endian
>(p
, r
);
2587 write_insn
<big_endian
>(p
, mtlr_0
);
2591 p
= restfpr
<big_endian
>(p
, 30);
2592 p
= restfpr
<big_endian
>(p
, 31);
2594 write_insn
<big_endian
>(p
, blr
);
2598 template<bool big_endian
>
2599 static unsigned char*
2600 savefpr1_tail(unsigned char* p
, int r
)
2602 p
= savefpr
<big_endian
>(p
, r
);
2603 write_insn
<big_endian
>(p
, blr
);
2607 template<bool big_endian
>
2608 static unsigned char*
2609 restfpr1_tail(unsigned char* p
, int r
)
2611 p
= restfpr
<big_endian
>(p
, r
);
2612 write_insn
<big_endian
>(p
, blr
);
2616 template<bool big_endian
>
2617 static unsigned char*
2618 savevr(unsigned char* p
, int r
)
2620 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
2621 write_insn
<big_endian
>(p
, insn
);
2623 insn
= stvx_0_12_0
+ (r
<< 21);
2624 write_insn
<big_endian
>(p
, insn
);
2628 template<bool big_endian
>
2629 static unsigned char*
2630 savevr_tail(unsigned char* p
, int r
)
2632 p
= savevr
<big_endian
>(p
, r
);
2633 write_insn
<big_endian
>(p
, blr
);
2637 template<bool big_endian
>
2638 static unsigned char*
2639 restvr(unsigned char* p
, int r
)
2641 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
2642 write_insn
<big_endian
>(p
, insn
);
2644 insn
= lvx_0_12_0
+ (r
<< 21);
2645 write_insn
<big_endian
>(p
, insn
);
2649 template<bool big_endian
>
2650 static unsigned char*
2651 restvr_tail(unsigned char* p
, int r
)
2653 p
= restvr
<big_endian
>(p
, r
);
2654 write_insn
<big_endian
>(p
, blr
);
2659 template<int size
, bool big_endian
>
2660 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
2661 Symbol_table
* symtab
)
2662 : Output_section_data_build(4),
2665 this->savres_define(symtab
,
2666 "_savegpr0_", 14, 31,
2667 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
2668 this->savres_define(symtab
,
2669 "_restgpr0_", 14, 29,
2670 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
2671 this->savres_define(symtab
,
2672 "_restgpr0_", 30, 31,
2673 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
2674 this->savres_define(symtab
,
2675 "_savegpr1_", 14, 31,
2676 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
2677 this->savres_define(symtab
,
2678 "_restgpr1_", 14, 31,
2679 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
2680 this->savres_define(symtab
,
2681 "_savefpr_", 14, 31,
2682 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
2683 this->savres_define(symtab
,
2684 "_restfpr_", 14, 29,
2685 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
2686 this->savres_define(symtab
,
2687 "_restfpr_", 30, 31,
2688 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
2689 this->savres_define(symtab
,
2691 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
2692 this->savres_define(symtab
,
2694 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
2695 this->savres_define(symtab
,
2697 savevr
<big_endian
>, savevr_tail
<big_endian
>);
2698 this->savres_define(symtab
,
2700 restvr
<big_endian
>, restvr_tail
<big_endian
>);
2703 template<int size
, bool big_endian
>
2705 Output_data_save_res
<size
, big_endian
>::savres_define(
2706 Symbol_table
* symtab
,
2708 unsigned int lo
, unsigned int hi
,
2709 unsigned char* write_ent(unsigned char*, int),
2710 unsigned char* write_tail(unsigned char*, int))
2712 size_t len
= strlen(name
);
2713 bool writing
= false;
2716 memcpy(sym
, name
, len
);
2719 for (unsigned int i
= lo
; i
<= hi
; i
++)
2721 sym
[len
+ 0] = i
/ 10 + '0';
2722 sym
[len
+ 1] = i
% 10 + '0';
2723 Symbol
* gsym
= symtab
->lookup(sym
);
2724 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
2725 writing
= writing
|| refd
;
2728 if (this->contents_
== NULL
)
2729 this->contents_
= new unsigned char[this->savres_max
];
2731 off_t value
= this->current_data_size();
2732 unsigned char* p
= this->contents_
+ value
;
2734 p
= write_ent(p
, i
);
2736 p
= write_tail(p
, i
);
2737 off_t cur_size
= p
- this->contents_
;
2738 this->set_current_data_size(cur_size
);
2740 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
2741 this, value
, cur_size
- value
,
2742 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
2743 elfcpp::STV_HIDDEN
, 0, false, false);
2748 // Write out save/restore.
2750 template<int size
, bool big_endian
>
2752 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
2754 const off_t off
= this->offset();
2755 const section_size_type oview_size
=
2756 convert_to_section_size_type(this->data_size());
2757 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
2758 memcpy(oview
, this->contents_
, oview_size
);
2759 of
->write_output_view(off
, oview_size
, oview
);
2763 // Create the glink section.
2765 template<int size
, bool big_endian
>
2767 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2769 if (this->glink_
== NULL
)
2771 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2772 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2773 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2774 this->glink_
, ORDER_TEXT
, false);
2778 // Create a PLT entry for a global symbol.
2780 template<int size
, bool big_endian
>
2782 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2785 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2786 const Sized_relobj_file
<size
, big_endian
>* object
)
2788 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
2789 && gsym
->can_use_relative_reloc(false))
2791 if (this->iplt_
== NULL
)
2792 this->make_iplt_section(layout
);
2793 this->iplt_
->add_ifunc_entry(gsym
);
2797 if (this->plt_
== NULL
)
2798 this->make_plt_section(layout
);
2799 this->plt_
->add_entry(gsym
);
2801 this->glink_
->add_entry(object
, gsym
, reloc
);
2804 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
2806 template<int size
, bool big_endian
>
2808 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
2810 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2811 Sized_relobj_file
<size
, big_endian
>* relobj
)
2813 if (this->iplt_
== NULL
)
2814 this->make_iplt_section(layout
);
2815 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2816 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
2817 this->glink_
->add_entry(relobj
, r_sym
, reloc
);
2820 // Return the number of entries in the PLT.
2822 template<int size
, bool big_endian
>
2824 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2826 if (this->plt_
== NULL
)
2828 unsigned int count
= this->plt_
->entry_count();
2829 if (this->iplt_
!= NULL
)
2830 count
+= this->iplt_
->entry_count();
2834 // Return the offset of the first non-reserved PLT entry.
2836 template<int size
, bool big_endian
>
2838 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2840 return this->plt_
->first_plt_entry_offset();
2843 // Return the size of each PLT entry.
2845 template<int size
, bool big_endian
>
2847 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2849 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2852 // Create a GOT entry for local dynamic __tls_get_addr calls.
2854 template<int size
, bool big_endian
>
2856 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2857 Symbol_table
* symtab
,
2859 Sized_relobj_file
<size
, big_endian
>* object
)
2861 if (this->tlsld_got_offset_
== -1U)
2863 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2864 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2865 Output_data_got_powerpc
<size
, big_endian
>* got
2866 = this->got_section(symtab
, layout
);
2867 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2868 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2870 this->tlsld_got_offset_
= got_offset
;
2872 return this->tlsld_got_offset_
;
2875 // Get the Reference_flags for a particular relocation.
2877 template<int size
, bool big_endian
>
2879 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2883 case elfcpp::R_POWERPC_NONE
:
2884 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2885 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2886 case elfcpp::R_PPC64_TOC
:
2887 // No symbol reference.
2890 case elfcpp::R_PPC64_ADDR64
:
2891 case elfcpp::R_PPC64_UADDR64
:
2892 case elfcpp::R_POWERPC_ADDR32
:
2893 case elfcpp::R_POWERPC_UADDR32
:
2894 case elfcpp::R_POWERPC_ADDR16
:
2895 case elfcpp::R_POWERPC_UADDR16
:
2896 case elfcpp::R_POWERPC_ADDR16_LO
:
2897 case elfcpp::R_POWERPC_ADDR16_HI
:
2898 case elfcpp::R_POWERPC_ADDR16_HA
:
2899 return Symbol::ABSOLUTE_REF
;
2901 case elfcpp::R_POWERPC_ADDR24
:
2902 case elfcpp::R_POWERPC_ADDR14
:
2903 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2904 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2905 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2907 case elfcpp::R_PPC64_REL64
:
2908 case elfcpp::R_POWERPC_REL32
:
2909 case elfcpp::R_PPC_LOCAL24PC
:
2910 case elfcpp::R_POWERPC_REL16
:
2911 case elfcpp::R_POWERPC_REL16_LO
:
2912 case elfcpp::R_POWERPC_REL16_HI
:
2913 case elfcpp::R_POWERPC_REL16_HA
:
2914 return Symbol::RELATIVE_REF
;
2916 case elfcpp::R_POWERPC_REL24
:
2917 case elfcpp::R_PPC_PLTREL24
:
2918 case elfcpp::R_POWERPC_REL14
:
2919 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2920 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2921 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2923 case elfcpp::R_POWERPC_GOT16
:
2924 case elfcpp::R_POWERPC_GOT16_LO
:
2925 case elfcpp::R_POWERPC_GOT16_HI
:
2926 case elfcpp::R_POWERPC_GOT16_HA
:
2927 case elfcpp::R_PPC64_GOT16_DS
:
2928 case elfcpp::R_PPC64_GOT16_LO_DS
:
2929 case elfcpp::R_PPC64_TOC16
:
2930 case elfcpp::R_PPC64_TOC16_LO
:
2931 case elfcpp::R_PPC64_TOC16_HI
:
2932 case elfcpp::R_PPC64_TOC16_HA
:
2933 case elfcpp::R_PPC64_TOC16_DS
:
2934 case elfcpp::R_PPC64_TOC16_LO_DS
:
2936 return Symbol::ABSOLUTE_REF
;
2938 case elfcpp::R_POWERPC_GOT_TPREL16
:
2939 case elfcpp::R_POWERPC_TLS
:
2940 return Symbol::TLS_REF
;
2942 case elfcpp::R_POWERPC_COPY
:
2943 case elfcpp::R_POWERPC_GLOB_DAT
:
2944 case elfcpp::R_POWERPC_JMP_SLOT
:
2945 case elfcpp::R_POWERPC_RELATIVE
:
2946 case elfcpp::R_POWERPC_DTPMOD
:
2948 // Not expected. We will give an error later.
2953 // Report an unsupported relocation against a local symbol.
2955 template<int size
, bool big_endian
>
2957 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2958 Sized_relobj_file
<size
, big_endian
>* object
,
2959 unsigned int r_type
)
2961 gold_error(_("%s: unsupported reloc %u against local symbol"),
2962 object
->name().c_str(), r_type
);
2965 // We are about to emit a dynamic relocation of type R_TYPE. If the
2966 // dynamic linker does not support it, issue an error.
2968 template<int size
, bool big_endian
>
2970 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2971 unsigned int r_type
)
2973 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
2975 // These are the relocation types supported by glibc for both 32-bit
2976 // and 64-bit powerpc.
2979 case elfcpp::R_POWERPC_NONE
:
2980 case elfcpp::R_POWERPC_RELATIVE
:
2981 case elfcpp::R_POWERPC_GLOB_DAT
:
2982 case elfcpp::R_POWERPC_DTPMOD
:
2983 case elfcpp::R_POWERPC_DTPREL
:
2984 case elfcpp::R_POWERPC_TPREL
:
2985 case elfcpp::R_POWERPC_JMP_SLOT
:
2986 case elfcpp::R_POWERPC_COPY
:
2987 case elfcpp::R_POWERPC_IRELATIVE
:
2988 case elfcpp::R_POWERPC_ADDR32
:
2989 case elfcpp::R_POWERPC_UADDR32
:
2990 case elfcpp::R_POWERPC_ADDR24
:
2991 case elfcpp::R_POWERPC_ADDR16
:
2992 case elfcpp::R_POWERPC_UADDR16
:
2993 case elfcpp::R_POWERPC_ADDR16_LO
:
2994 case elfcpp::R_POWERPC_ADDR16_HI
:
2995 case elfcpp::R_POWERPC_ADDR16_HA
:
2996 case elfcpp::R_POWERPC_ADDR14
:
2997 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2998 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2999 case elfcpp::R_POWERPC_REL32
:
3000 case elfcpp::R_POWERPC_REL24
:
3001 case elfcpp::R_POWERPC_TPREL16
:
3002 case elfcpp::R_POWERPC_TPREL16_LO
:
3003 case elfcpp::R_POWERPC_TPREL16_HI
:
3004 case elfcpp::R_POWERPC_TPREL16_HA
:
3015 // These are the relocation types supported only on 64-bit.
3016 case elfcpp::R_PPC64_ADDR64
:
3017 case elfcpp::R_PPC64_UADDR64
:
3018 case elfcpp::R_PPC64_JMP_IREL
:
3019 case elfcpp::R_PPC64_ADDR16_DS
:
3020 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3021 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3022 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3023 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3024 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3025 case elfcpp::R_PPC64_REL64
:
3026 case elfcpp::R_POWERPC_ADDR30
:
3027 case elfcpp::R_PPC64_TPREL16_DS
:
3028 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3029 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3030 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3031 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3032 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3043 // These are the relocation types supported only on 32-bit.
3044 // ??? glibc ld.so doesn't need to support these.
3045 case elfcpp::R_POWERPC_DTPREL16
:
3046 case elfcpp::R_POWERPC_DTPREL16_LO
:
3047 case elfcpp::R_POWERPC_DTPREL16_HI
:
3048 case elfcpp::R_POWERPC_DTPREL16_HA
:
3056 // This prevents us from issuing more than one error per reloc
3057 // section. But we can still wind up issuing more than one
3058 // error per object file.
3059 if (this->issued_non_pic_error_
)
3061 gold_assert(parameters
->options().output_is_position_independent());
3062 object
->error(_("requires unsupported dynamic reloc; "
3063 "recompile with -fPIC"));
3064 this->issued_non_pic_error_
= true;
3068 // Return whether we need to make a PLT entry for a relocation of the
3069 // given type against a STT_GNU_IFUNC symbol.
3071 template<int size
, bool big_endian
>
3073 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
3074 Sized_relobj_file
<size
, big_endian
>* object
,
3075 unsigned int r_type
)
3077 // In non-pic code any reference will resolve to the plt call stub
3078 // for the ifunc symbol.
3079 if (size
== 32 && !parameters
->options().output_is_position_independent())
3084 // Word size refs from data sections are OK.
3085 case elfcpp::R_POWERPC_ADDR32
:
3086 case elfcpp::R_POWERPC_UADDR32
:
3091 case elfcpp::R_PPC64_ADDR64
:
3092 case elfcpp::R_PPC64_UADDR64
:
3097 // GOT refs are good.
3098 case elfcpp::R_POWERPC_GOT16
:
3099 case elfcpp::R_POWERPC_GOT16_LO
:
3100 case elfcpp::R_POWERPC_GOT16_HI
:
3101 case elfcpp::R_POWERPC_GOT16_HA
:
3102 case elfcpp::R_PPC64_GOT16_DS
:
3103 case elfcpp::R_PPC64_GOT16_LO_DS
:
3106 // So are function calls.
3107 case elfcpp::R_POWERPC_ADDR24
:
3108 case elfcpp::R_POWERPC_ADDR14
:
3109 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3110 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3111 case elfcpp::R_POWERPC_REL24
:
3112 case elfcpp::R_PPC_PLTREL24
:
3113 case elfcpp::R_POWERPC_REL14
:
3114 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3115 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3122 // Anything else is a problem.
3123 // If we are building a static executable, the libc startup function
3124 // responsible for applying indirect function relocations is going
3125 // to complain about the reloc type.
3126 // If we are building a dynamic executable, we will have a text
3127 // relocation. The dynamic loader will set the text segment
3128 // writable and non-executable to apply text relocations. So we'll
3129 // segfault when trying to run the indirection function to resolve
3131 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
3132 object
->name().c_str(), r_type
);
3136 // Scan a relocation for a local symbol.
3138 template<int size
, bool big_endian
>
3140 Target_powerpc
<size
, big_endian
>::Scan::local(
3141 Symbol_table
* symtab
,
3143 Target_powerpc
<size
, big_endian
>* target
,
3144 Sized_relobj_file
<size
, big_endian
>* object
,
3145 unsigned int data_shndx
,
3146 Output_section
* output_section
,
3147 const elfcpp::Rela
<size
, big_endian
>& reloc
,
3148 unsigned int r_type
,
3149 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3152 Powerpc_relobj
<size
, big_endian
>* ppc_object
3153 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3158 && data_shndx
== ppc_object
->opd_shndx()
3159 && r_type
== elfcpp::R_PPC64_ADDR64
)
3160 ppc_object
->set_opd_discard(reloc
.get_r_offset());
3164 // A local STT_GNU_IFUNC symbol may require a PLT entry.
3165 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
3166 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
3167 target
->make_local_ifunc_plt_entry(layout
, reloc
, object
);
3171 case elfcpp::R_POWERPC_NONE
:
3172 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3173 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3174 case elfcpp::R_PPC64_TOCSAVE
:
3175 case elfcpp::R_PPC_EMB_MRKREF
:
3176 case elfcpp::R_POWERPC_TLS
:
3179 case elfcpp::R_PPC64_TOC
:
3181 Output_data_got_powerpc
<size
, big_endian
>* got
3182 = target
->got_section(symtab
, layout
);
3183 if (parameters
->options().output_is_position_independent())
3185 Address off
= reloc
.get_r_offset();
3187 && data_shndx
== ppc_object
->opd_shndx()
3188 && ppc_object
->get_opd_discard(off
- 8))
3191 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3192 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
3193 rela_dyn
->add_output_section_relative(got
->output_section(),
3194 elfcpp::R_POWERPC_RELATIVE
,
3196 object
, data_shndx
, off
,
3197 symobj
->toc_base_offset());
3202 case elfcpp::R_PPC64_ADDR64
:
3203 case elfcpp::R_PPC64_UADDR64
:
3204 case elfcpp::R_POWERPC_ADDR32
:
3205 case elfcpp::R_POWERPC_UADDR32
:
3206 case elfcpp::R_POWERPC_ADDR24
:
3207 case elfcpp::R_POWERPC_ADDR16
:
3208 case elfcpp::R_POWERPC_ADDR16_LO
:
3209 case elfcpp::R_POWERPC_ADDR16_HI
:
3210 case elfcpp::R_POWERPC_ADDR16_HA
:
3211 case elfcpp::R_POWERPC_UADDR16
:
3212 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3213 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3214 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3215 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3216 case elfcpp::R_PPC64_ADDR16_DS
:
3217 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3218 case elfcpp::R_POWERPC_ADDR14
:
3219 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3220 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3221 // If building a shared library (or a position-independent
3222 // executable), we need to create a dynamic relocation for
3224 if (parameters
->options().output_is_position_independent()
3225 || (size
== 64 && is_ifunc
))
3227 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3229 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
3230 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
3232 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3233 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3236 rela_dyn
= target
->iplt_section()->rel_plt();
3237 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3239 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
3240 output_section
, data_shndx
,
3241 reloc
.get_r_offset(),
3242 reloc
.get_r_addend(), false);
3246 check_non_pic(object
, r_type
);
3247 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3248 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
3249 data_shndx
, reloc
.get_r_offset(),
3250 reloc
.get_r_addend());
3255 case elfcpp::R_PPC64_REL64
:
3256 case elfcpp::R_POWERPC_REL32
:
3257 case elfcpp::R_POWERPC_REL24
:
3258 case elfcpp::R_PPC_PLTREL24
:
3259 case elfcpp::R_PPC_LOCAL24PC
:
3260 case elfcpp::R_POWERPC_REL16
:
3261 case elfcpp::R_POWERPC_REL16_LO
:
3262 case elfcpp::R_POWERPC_REL16_HI
:
3263 case elfcpp::R_POWERPC_REL16_HA
:
3264 case elfcpp::R_POWERPC_REL14
:
3265 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3266 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3267 case elfcpp::R_POWERPC_SECTOFF
:
3268 case elfcpp::R_POWERPC_TPREL16
:
3269 case elfcpp::R_POWERPC_DTPREL16
:
3270 case elfcpp::R_POWERPC_SECTOFF_LO
:
3271 case elfcpp::R_POWERPC_TPREL16_LO
:
3272 case elfcpp::R_POWERPC_DTPREL16_LO
:
3273 case elfcpp::R_POWERPC_SECTOFF_HI
:
3274 case elfcpp::R_POWERPC_TPREL16_HI
:
3275 case elfcpp::R_POWERPC_DTPREL16_HI
:
3276 case elfcpp::R_POWERPC_SECTOFF_HA
:
3277 case elfcpp::R_POWERPC_TPREL16_HA
:
3278 case elfcpp::R_POWERPC_DTPREL16_HA
:
3279 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3280 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3281 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3282 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3283 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3284 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3285 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3286 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3287 case elfcpp::R_PPC64_TPREL16_DS
:
3288 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3289 case elfcpp::R_PPC64_DTPREL16_DS
:
3290 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3291 case elfcpp::R_PPC64_SECTOFF_DS
:
3292 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3293 case elfcpp::R_PPC64_TLSGD
:
3294 case elfcpp::R_PPC64_TLSLD
:
3297 case elfcpp::R_POWERPC_GOT16
:
3298 case elfcpp::R_POWERPC_GOT16_LO
:
3299 case elfcpp::R_POWERPC_GOT16_HI
:
3300 case elfcpp::R_POWERPC_GOT16_HA
:
3301 case elfcpp::R_PPC64_GOT16_DS
:
3302 case elfcpp::R_PPC64_GOT16_LO_DS
:
3304 // The symbol requires a GOT entry.
3305 Output_data_got_powerpc
<size
, big_endian
>* got
3306 = target
->got_section(symtab
, layout
);
3307 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3309 if (!parameters
->options().output_is_position_independent())
3311 if (size
== 32 && is_ifunc
)
3312 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
3314 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
3316 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
3318 // If we are generating a shared object or a pie, this
3319 // symbol's GOT entry will be set by a dynamic relocation.
3321 off
= got
->add_constant(0);
3322 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
3324 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3325 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3328 rela_dyn
= target
->iplt_section()->rel_plt();
3329 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3331 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
3332 got
, off
, 0, false);
3337 case elfcpp::R_PPC64_TOC16
:
3338 case elfcpp::R_PPC64_TOC16_LO
:
3339 case elfcpp::R_PPC64_TOC16_HI
:
3340 case elfcpp::R_PPC64_TOC16_HA
:
3341 case elfcpp::R_PPC64_TOC16_DS
:
3342 case elfcpp::R_PPC64_TOC16_LO_DS
:
3343 // We need a GOT section.
3344 target
->got_section(symtab
, layout
);
3347 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3348 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3349 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3350 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3352 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
3353 if (tls_type
== tls::TLSOPT_NONE
)
3355 Output_data_got_powerpc
<size
, big_endian
>* got
3356 = target
->got_section(symtab
, layout
);
3357 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3358 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3359 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
3360 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
3362 else if (tls_type
== tls::TLSOPT_TO_LE
)
3364 // no GOT relocs needed for Local Exec.
3371 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3372 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3373 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3374 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3376 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3377 if (tls_type
== tls::TLSOPT_NONE
)
3378 target
->tlsld_got_offset(symtab
, layout
, object
);
3379 else if (tls_type
== tls::TLSOPT_TO_LE
)
3381 // no GOT relocs needed for Local Exec.
3382 if (parameters
->options().emit_relocs())
3384 Output_section
* os
= layout
->tls_segment()->first_section();
3385 gold_assert(os
!= NULL
);
3386 os
->set_needs_symtab_index();
3394 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3395 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3396 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3397 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3399 Output_data_got_powerpc
<size
, big_endian
>* got
3400 = target
->got_section(symtab
, layout
);
3401 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3402 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
3406 case elfcpp::R_POWERPC_GOT_TPREL16
:
3407 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3408 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3409 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3411 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
3412 if (tls_type
== tls::TLSOPT_NONE
)
3414 Output_data_got_powerpc
<size
, big_endian
>* got
3415 = target
->got_section(symtab
, layout
);
3416 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3417 got
->add_local_tls(object
, r_sym
, GOT_TYPE_TPREL
);
3419 else if (tls_type
== tls::TLSOPT_TO_LE
)
3421 // no GOT relocs needed for Local Exec.
3429 unsupported_reloc_local(object
, r_type
);
3434 // Report an unsupported relocation against a global symbol.
3436 template<int size
, bool big_endian
>
3438 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
3439 Sized_relobj_file
<size
, big_endian
>* object
,
3440 unsigned int r_type
,
3443 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3444 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3447 // Scan a relocation for a global symbol.
3449 template<int size
, bool big_endian
>
3451 Target_powerpc
<size
, big_endian
>::Scan::global(
3452 Symbol_table
* symtab
,
3454 Target_powerpc
<size
, big_endian
>* target
,
3455 Sized_relobj_file
<size
, big_endian
>* object
,
3456 unsigned int data_shndx
,
3457 Output_section
* output_section
,
3458 const elfcpp::Rela
<size
, big_endian
>& reloc
,
3459 unsigned int r_type
,
3462 Powerpc_relobj
<size
, big_endian
>* ppc_object
3463 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3465 // A STT_GNU_IFUNC symbol may require a PLT entry.
3466 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
3467 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
3468 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3472 case elfcpp::R_POWERPC_NONE
:
3473 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3474 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3475 case elfcpp::R_PPC_LOCAL24PC
:
3476 case elfcpp::R_PPC_EMB_MRKREF
:
3477 case elfcpp::R_POWERPC_TLS
:
3480 case elfcpp::R_PPC64_TOC
:
3482 Output_data_got_powerpc
<size
, big_endian
>* got
3483 = target
->got_section(symtab
, layout
);
3484 if (parameters
->options().output_is_position_independent())
3486 Address off
= reloc
.get_r_offset();
3488 && data_shndx
== ppc_object
->opd_shndx()
3489 && ppc_object
->get_opd_discard(off
- 8))
3492 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3493 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
3494 if (data_shndx
!= ppc_object
->opd_shndx())
3495 symobj
= static_cast
3496 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3497 rela_dyn
->add_output_section_relative(got
->output_section(),
3498 elfcpp::R_POWERPC_RELATIVE
,
3500 object
, data_shndx
, off
,
3501 symobj
->toc_base_offset());
3506 case elfcpp::R_PPC64_ADDR64
:
3508 && data_shndx
== ppc_object
->opd_shndx()
3509 && (gsym
->is_defined_in_discarded_section()
3510 || gsym
->object() != object
))
3512 ppc_object
->set_opd_discard(reloc
.get_r_offset());
3516 case elfcpp::R_PPC64_UADDR64
:
3517 case elfcpp::R_POWERPC_ADDR32
:
3518 case elfcpp::R_POWERPC_UADDR32
:
3519 case elfcpp::R_POWERPC_ADDR24
:
3520 case elfcpp::R_POWERPC_ADDR16
:
3521 case elfcpp::R_POWERPC_ADDR16_LO
:
3522 case elfcpp::R_POWERPC_ADDR16_HI
:
3523 case elfcpp::R_POWERPC_ADDR16_HA
:
3524 case elfcpp::R_POWERPC_UADDR16
:
3525 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3526 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3527 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3528 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3529 case elfcpp::R_PPC64_ADDR16_DS
:
3530 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3531 case elfcpp::R_POWERPC_ADDR14
:
3532 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3533 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3535 // Make a PLT entry if necessary.
3536 if (gsym
->needs_plt_entry())
3538 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
3539 // Since this is not a PC-relative relocation, we may be
3540 // taking the address of a function. In that case we need to
3541 // set the entry in the dynamic symbol table to the address of
3542 // the PLT call stub.
3544 && gsym
->is_from_dynobj()
3545 && !parameters
->options().output_is_position_independent())
3546 gsym
->set_needs_dynsym_value();
3548 // Make a dynamic relocation if necessary.
3549 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
))
3550 || (size
== 64 && gsym
->type() == elfcpp::STT_GNU_IFUNC
))
3552 if (gsym
->may_need_copy_reloc())
3554 target
->copy_reloc(symtab
, layout
, object
,
3555 data_shndx
, output_section
, gsym
, reloc
);
3557 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
3558 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
3559 && (gsym
->can_use_relative_reloc(false)
3561 && data_shndx
== ppc_object
->opd_shndx())))
3563 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3564 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3565 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3567 rela_dyn
= target
->iplt_section()->rel_plt();
3568 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3570 rela_dyn
->add_symbolless_global_addend(
3571 gsym
, dynrel
, output_section
, object
, data_shndx
,
3572 reloc
.get_r_offset(), reloc
.get_r_addend());
3576 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3577 check_non_pic(object
, r_type
);
3578 rela_dyn
->add_global(gsym
, r_type
, output_section
,
3580 reloc
.get_r_offset(),
3581 reloc
.get_r_addend());
3587 case elfcpp::R_PPC_PLTREL24
:
3588 case elfcpp::R_POWERPC_REL24
:
3589 if (gsym
->needs_plt_entry()
3590 || (!gsym
->final_value_is_known()
3591 && (gsym
->is_undefined()
3592 || gsym
->is_from_dynobj()
3593 || gsym
->is_preemptible())))
3594 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3597 case elfcpp::R_PPC64_REL64
:
3598 case elfcpp::R_POWERPC_REL32
:
3599 // Make a dynamic relocation if necessary.
3600 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3602 if (gsym
->may_need_copy_reloc())
3604 target
->copy_reloc(symtab
, layout
, object
,
3605 data_shndx
, output_section
, gsym
,
3610 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3611 check_non_pic(object
, r_type
);
3612 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
3613 data_shndx
, reloc
.get_r_offset(),
3614 reloc
.get_r_addend());
3619 case elfcpp::R_POWERPC_REL16
:
3620 case elfcpp::R_POWERPC_REL16_LO
:
3621 case elfcpp::R_POWERPC_REL16_HI
:
3622 case elfcpp::R_POWERPC_REL16_HA
:
3623 case elfcpp::R_POWERPC_REL14
:
3624 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3625 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3626 case elfcpp::R_POWERPC_SECTOFF
:
3627 case elfcpp::R_POWERPC_TPREL16
:
3628 case elfcpp::R_POWERPC_DTPREL16
:
3629 case elfcpp::R_POWERPC_SECTOFF_LO
:
3630 case elfcpp::R_POWERPC_TPREL16_LO
:
3631 case elfcpp::R_POWERPC_DTPREL16_LO
:
3632 case elfcpp::R_POWERPC_SECTOFF_HI
:
3633 case elfcpp::R_POWERPC_TPREL16_HI
:
3634 case elfcpp::R_POWERPC_DTPREL16_HI
:
3635 case elfcpp::R_POWERPC_SECTOFF_HA
:
3636 case elfcpp::R_POWERPC_TPREL16_HA
:
3637 case elfcpp::R_POWERPC_DTPREL16_HA
:
3638 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3639 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3640 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3641 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3642 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3643 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3644 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3645 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3646 case elfcpp::R_PPC64_TPREL16_DS
:
3647 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3648 case elfcpp::R_PPC64_DTPREL16_DS
:
3649 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3650 case elfcpp::R_PPC64_SECTOFF_DS
:
3651 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3652 case elfcpp::R_PPC64_TLSGD
:
3653 case elfcpp::R_PPC64_TLSLD
:
3656 case elfcpp::R_POWERPC_GOT16
:
3657 case elfcpp::R_POWERPC_GOT16_LO
:
3658 case elfcpp::R_POWERPC_GOT16_HI
:
3659 case elfcpp::R_POWERPC_GOT16_HA
:
3660 case elfcpp::R_PPC64_GOT16_DS
:
3661 case elfcpp::R_PPC64_GOT16_LO_DS
:
3663 // The symbol requires a GOT entry.
3664 Output_data_got_powerpc
<size
, big_endian
>* got
;
3666 got
= target
->got_section(symtab
, layout
);
3667 if (gsym
->final_value_is_known())
3669 if (size
== 32 && gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3670 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
3672 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
3674 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
3676 // If we are generating a shared object or a pie, this
3677 // symbol's GOT entry will be set by a dynamic relocation.
3678 unsigned int off
= got
->add_constant(0);
3679 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
3681 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3682 if (gsym
->can_use_relative_reloc(false)
3684 && gsym
->visibility() == elfcpp::STV_PROTECTED
3685 && parameters
->options().shared()))
3687 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3688 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3690 rela_dyn
= target
->iplt_section()->rel_plt();
3691 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3693 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
3697 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
3698 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
3704 case elfcpp::R_PPC64_TOC16
:
3705 case elfcpp::R_PPC64_TOC16_LO
:
3706 case elfcpp::R_PPC64_TOC16_HI
:
3707 case elfcpp::R_PPC64_TOC16_HA
:
3708 case elfcpp::R_PPC64_TOC16_DS
:
3709 case elfcpp::R_PPC64_TOC16_LO_DS
:
3710 // We need a GOT section.
3711 target
->got_section(symtab
, layout
);
3714 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3715 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3716 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3717 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3719 const bool final
= gsym
->final_value_is_known();
3720 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3721 if (tls_type
== tls::TLSOPT_NONE
)
3723 Output_data_got_powerpc
<size
, big_endian
>* got
3724 = target
->got_section(symtab
, layout
);
3725 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
3726 target
->rela_dyn_section(layout
),
3727 elfcpp::R_POWERPC_DTPMOD
,
3728 elfcpp::R_POWERPC_DTPREL
);
3730 else if (tls_type
== tls::TLSOPT_TO_IE
)
3732 Output_data_got_powerpc
<size
, big_endian
>* got
3733 = target
->got_section(symtab
, layout
);
3734 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
3735 target
->rela_dyn_section(layout
),
3736 elfcpp::R_POWERPC_TPREL
);
3738 else if (tls_type
== tls::TLSOPT_TO_LE
)
3740 // no GOT relocs needed for Local Exec.
3747 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3748 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3749 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3750 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3752 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3753 if (tls_type
== tls::TLSOPT_NONE
)
3754 target
->tlsld_got_offset(symtab
, layout
, object
);
3755 else if (tls_type
== tls::TLSOPT_TO_LE
)
3757 // no GOT relocs needed for Local Exec.
3758 if (parameters
->options().emit_relocs())
3760 Output_section
* os
= layout
->tls_segment()->first_section();
3761 gold_assert(os
!= NULL
);
3762 os
->set_needs_symtab_index();
3770 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3771 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3772 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3773 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3775 Output_data_got_powerpc
<size
, big_endian
>* got
3776 = target
->got_section(symtab
, layout
);
3777 if (!gsym
->final_value_is_known()
3778 && (gsym
->is_from_dynobj()
3779 || gsym
->is_undefined()
3780 || gsym
->is_preemptible()))
3781 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
3782 target
->rela_dyn_section(layout
),
3783 elfcpp::R_POWERPC_DTPREL
);
3785 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
3789 case elfcpp::R_POWERPC_GOT_TPREL16
:
3790 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3791 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3792 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3794 const bool final
= gsym
->final_value_is_known();
3795 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3796 if (tls_type
== tls::TLSOPT_NONE
)
3798 Output_data_got_powerpc
<size
, big_endian
>* got
3799 = target
->got_section(symtab
, layout
);
3800 if (!gsym
->final_value_is_known()
3801 && (gsym
->is_from_dynobj()
3802 || gsym
->is_undefined()
3803 || gsym
->is_preemptible()))
3804 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
3805 target
->rela_dyn_section(layout
),
3806 elfcpp::R_POWERPC_TPREL
);
3808 got
->add_global_tls(gsym
, GOT_TYPE_TPREL
);
3810 else if (tls_type
== tls::TLSOPT_TO_LE
)
3812 // no GOT relocs needed for Local Exec.
3820 unsupported_reloc_global(object
, r_type
, gsym
);
3825 // Process relocations for gc.
3827 template<int size
, bool big_endian
>
3829 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
3830 Symbol_table
* symtab
,
3832 Sized_relobj_file
<size
, big_endian
>* object
,
3833 unsigned int data_shndx
,
3835 const unsigned char* prelocs
,
3837 Output_section
* output_section
,
3838 bool needs_special_offset_handling
,
3839 size_t local_symbol_count
,
3840 const unsigned char* plocal_symbols
)
3842 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3843 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3844 Powerpc_relobj
<size
, big_endian
>* ppc_object
3845 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3847 ppc_object
->set_opd_valid();
3848 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
3850 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
3851 for (p
= ppc_object
->access_from_map()->begin();
3852 p
!= ppc_object
->access_from_map()->end();
3855 Address dst_off
= p
->first
;
3856 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3857 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
3858 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
3860 Object
* src_obj
= s
->first
;
3861 unsigned int src_indx
= s
->second
;
3862 symtab
->gc()->add_reference(src_obj
, src_indx
,
3863 ppc_object
, dst_indx
);
3867 ppc_object
->access_from_map()->clear();
3868 ppc_object
->process_gc_mark(symtab
);
3869 // Don't look at .opd relocs as .opd will reference everything.
3873 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3874 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3883 needs_special_offset_handling
,
3888 // Handle target specific gc actions when adding a gc reference from
3889 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3890 // and DST_OFF. For powerpc64, this adds a referenc to the code
3891 // section of a function descriptor.
3893 template<int size
, bool big_endian
>
3895 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3896 Symbol_table
* symtab
,
3898 unsigned int src_shndx
,
3900 unsigned int dst_shndx
,
3901 Address dst_off
) const
3903 Powerpc_relobj
<size
, big_endian
>* ppc_object
3904 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3905 if (size
== 64 && dst_shndx
== ppc_object
->opd_shndx())
3907 if (ppc_object
->opd_valid())
3909 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3910 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3914 // If we haven't run scan_opd_relocs, we must delay
3915 // processing this function descriptor reference.
3916 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3921 // Add any special sections for this symbol to the gc work list.
3922 // For powerpc64, this adds the code section of a function
3925 template<int size
, bool big_endian
>
3927 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3928 Symbol_table
* symtab
,
3933 Powerpc_relobj
<size
, big_endian
>* ppc_object
3934 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3936 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3937 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
3939 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
3940 Address dst_off
= gsym
->value();
3941 if (ppc_object
->opd_valid())
3943 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3944 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
3947 ppc_object
->add_gc_mark(dst_off
);
3952 // Scan relocations for a section.
3954 template<int size
, bool big_endian
>
3956 Target_powerpc
<size
, big_endian
>::scan_relocs(
3957 Symbol_table
* symtab
,
3959 Sized_relobj_file
<size
, big_endian
>* object
,
3960 unsigned int data_shndx
,
3961 unsigned int sh_type
,
3962 const unsigned char* prelocs
,
3964 Output_section
* output_section
,
3965 bool needs_special_offset_handling
,
3966 size_t local_symbol_count
,
3967 const unsigned char* plocal_symbols
)
3969 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3970 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3972 if (sh_type
== elfcpp::SHT_REL
)
3974 gold_error(_("%s: unsupported REL reloc section"),
3975 object
->name().c_str());
3981 static Output_data_space
* sdata
;
3983 // Define _SDA_BASE_ at the start of the .sdata section.
3986 // layout->find_output_section(".sdata") == NULL
3987 sdata
= new Output_data_space(4, "** sdata");
3989 = layout
->add_output_section_data(".sdata", 0,
3991 | elfcpp::SHF_WRITE
,
3992 sdata
, ORDER_SMALL_DATA
, false);
3993 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
3994 Symbol_table::PREDEFINED
,
3995 os
, 32768, 0, elfcpp::STT_OBJECT
,
3996 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
4001 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
4010 needs_special_offset_handling
,
4015 // Functor class for processing the global symbol table.
4016 // Removes symbols defined on discarded opd entries.
4018 template<bool big_endian
>
4019 class Global_symbol_visitor_opd
4022 Global_symbol_visitor_opd()
4026 operator()(Sized_symbol
<64>* sym
)
4028 if (sym
->has_symtab_index()
4029 || sym
->source() != Symbol::FROM_OBJECT
4030 || !sym
->in_real_elf())
4033 Powerpc_relobj
<64, big_endian
>* symobj
4034 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
4035 if (symobj
->is_dynamic()
4036 || symobj
->opd_shndx() == 0)
4040 unsigned int shndx
= sym
->shndx(&is_ordinary
);
4041 if (shndx
== symobj
->opd_shndx()
4042 && symobj
->get_opd_discard(sym
->value()))
4043 sym
->set_symtab_index(-1U);
4047 template<int size
, bool big_endian
>
4049 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
4051 Symbol_table
* symtab
)
4055 Output_data_save_res
<64, big_endian
>* savres
4056 = new Output_data_save_res
<64, big_endian
>(symtab
);
4057 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
4058 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
4059 savres
, ORDER_TEXT
, false);
4063 // Finalize the sections.
4065 template<int size
, bool big_endian
>
4067 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
4069 const Input_objects
*,
4070 Symbol_table
* symtab
)
4072 if (parameters
->doing_static_link())
4074 // At least some versions of glibc elf-init.o have a strong
4075 // reference to __rela_iplt marker syms. A weak ref would be
4077 if (this->iplt_
!= NULL
)
4079 Reloc_section
* rel
= this->iplt_
->rel_plt();
4080 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
4081 Symbol_table::PREDEFINED
, rel
, 0, 0,
4082 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4083 elfcpp::STV_HIDDEN
, 0, false, true);
4084 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
4085 Symbol_table::PREDEFINED
, rel
, 0, 0,
4086 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4087 elfcpp::STV_HIDDEN
, 0, true, true);
4091 symtab
->define_as_constant("__rela_iplt_start", NULL
,
4092 Symbol_table::PREDEFINED
, 0, 0,
4093 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4094 elfcpp::STV_HIDDEN
, 0, true, false);
4095 symtab
->define_as_constant("__rela_iplt_end", NULL
,
4096 Symbol_table::PREDEFINED
, 0, 0,
4097 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4098 elfcpp::STV_HIDDEN
, 0, true, false);
4104 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
4105 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
4106 this->define_save_restore_funcs(layout
, symtab
);
4109 // Fill in some more dynamic tags.
4110 Output_data_dynamic
* odyn
= layout
->dynamic_data();
4113 const Reloc_section
* rel_plt
= (this->plt_
== NULL
4115 : this->plt_
->rel_plt());
4116 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
4117 this->rela_dyn_
, true, size
== 32);
4121 if (this->got_
!= NULL
)
4123 this->got_
->finalize_data_size();
4124 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
4125 this->got_
, this->got_
->g_o_t());
4130 if (this->glink_
!= NULL
)
4132 this->glink_
->finalize_data_size();
4133 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
4135 (this->glink_
->pltresolve()
4136 + this->glink_
->pltresolve_size
4142 // Emit any relocs we saved in an attempt to avoid generating COPY
4144 if (this->copy_relocs_
.any_saved_relocs())
4145 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
4148 // Return the value to use for a branch relocation.
4150 template<int size
, bool big_endian
>
4151 typename
elfcpp::Elf_types
<size
>::Elf_Addr
4152 Target_powerpc
<size
, big_endian
>::symval_for_branch(
4154 const Sized_symbol
<size
>* gsym
,
4155 Powerpc_relobj
<size
, big_endian
>* object
,
4156 unsigned int *dest_shndx
)
4162 // If the symbol is defined in an opd section, ie. is a function
4163 // descriptor, use the function descriptor code entry address
4164 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
4166 && gsym
->source() != Symbol::FROM_OBJECT
)
4169 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
4170 unsigned int shndx
= symobj
->opd_shndx();
4173 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
4174 gold_assert(opd_addr
!= invalid_address
);
4175 opd_addr
+= symobj
->output_section(shndx
)->address();
4176 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
4179 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
4180 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
4181 gold_assert(sec_addr
!= invalid_address
);
4182 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
4183 value
= sec_addr
+ sec_off
;
4188 // Perform a relocation.
4190 template<int size
, bool big_endian
>
4192 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
4193 const Relocate_info
<size
, big_endian
>* relinfo
,
4194 Target_powerpc
* target
,
4197 const elfcpp::Rela
<size
, big_endian
>& rela
,
4198 unsigned int r_type
,
4199 const Sized_symbol
<size
>* gsym
,
4200 const Symbol_value
<size
>* psymval
,
4201 unsigned char* view
,
4203 section_size_type view_size
)
4206 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
4207 || r_type
== elfcpp::R_PPC_PLTREL24
)
4209 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
4210 enum skip_tls last_tls
= this->call_tls_get_addr_
;
4211 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
4214 if (last_tls
== CALL_NOT_EXPECTED
)
4215 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4216 _("__tls_get_addr call lacks marker reloc"));
4217 else if (last_tls
== CALL_SKIP
)
4220 else if (last_tls
!= CALL_NOT_EXPECTED
)
4221 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4222 _("missing expected __tls_get_addr call"));
4224 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
4225 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
4226 Powerpc_relobj
<size
, big_endian
>* const object
4227 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4229 bool has_plt_value
= false;
4230 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4232 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
))
4233 : object
->local_has_plt_offset(r_sym
))
4235 const Output_data_glink
<size
, big_endian
>* glink
4236 = target
->glink_section();
4237 unsigned int glink_index
;
4239 glink_index
= glink
->find_entry(object
, gsym
, rela
);
4241 glink_index
= glink
->find_entry(object
, r_sym
, rela
);
4242 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
4243 has_plt_value
= true;
4246 if (r_type
== elfcpp::R_POWERPC_GOT16
4247 || r_type
== elfcpp::R_POWERPC_GOT16_LO
4248 || r_type
== elfcpp::R_POWERPC_GOT16_HI
4249 || r_type
== elfcpp::R_POWERPC_GOT16_HA
4250 || r_type
== elfcpp::R_PPC64_GOT16_DS
4251 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
4255 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
4256 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
4260 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4261 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
4262 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
4264 value
-= target
->got_section()->got_base_offset(object
);
4266 else if (r_type
== elfcpp::R_PPC64_TOC
)
4268 value
= (target
->got_section()->output_section()->address()
4269 + object
->toc_base_offset());
4271 else if (gsym
!= NULL
4272 && (r_type
== elfcpp::R_POWERPC_REL24
4273 || r_type
== elfcpp::R_PPC_PLTREL24
)
4278 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
4279 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
4280 bool can_plt_call
= false;
4281 if (rela
.get_r_offset() + 8 <= view_size
)
4283 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4284 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
4287 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
4289 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
4290 can_plt_call
= true;
4295 // If we don't have a branch and link followed by a nop,
4296 // we can't go via the plt because there is no place to
4297 // put a toc restoring instruction.
4298 // Unless we know we won't be returning.
4299 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
4300 can_plt_call
= true;
4304 // This is not an error in one special case: A self
4305 // call. It isn't possible to cheaply verify we have
4306 // such a call so just check for a call to the same
4309 Address code
= value
;
4310 if (gsym
->source() == Symbol::FROM_OBJECT
4311 && gsym
->object() == object
)
4313 Address addend
= rela
.get_r_addend();
4314 unsigned int dest_shndx
;
4315 Address opdent
= psymval
->value(object
, addend
);
4316 code
= target
->symval_for_branch(opdent
, gsym
, object
,
4319 if (dest_shndx
== 0)
4320 dest_shndx
= gsym
->shndx(&is_ordinary
);
4321 ok
= dest_shndx
== relinfo
->data_shndx
;
4325 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4326 _("call lacks nop, can't restore toc; "
4327 "recompile with -fPIC"));
4333 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4334 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4335 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4336 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4338 // First instruction of a global dynamic sequence, arg setup insn.
4339 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4340 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
4341 enum Got_type got_type
= GOT_TYPE_STANDARD
;
4342 if (tls_type
== tls::TLSOPT_NONE
)
4343 got_type
= GOT_TYPE_TLSGD
;
4344 else if (tls_type
== tls::TLSOPT_TO_IE
)
4345 got_type
= GOT_TYPE_TPREL
;
4346 if (got_type
!= GOT_TYPE_STANDARD
)
4350 gold_assert(gsym
->has_got_offset(got_type
));
4351 value
= gsym
->got_offset(got_type
);
4355 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4356 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
4357 value
= object
->local_got_offset(r_sym
, got_type
);
4359 value
-= target
->got_section()->got_base_offset(object
);
4361 if (tls_type
== tls::TLSOPT_TO_IE
)
4363 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4364 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4366 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4367 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4368 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
4370 insn
|= 32 << 26; // lwz
4372 insn
|= 58 << 26; // ld
4373 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4375 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4376 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4378 else if (tls_type
== tls::TLSOPT_TO_LE
)
4380 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4381 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4383 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4384 Insn insn
= addis_3_13
;
4387 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4388 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4389 value
= psymval
->value(object
, rela
.get_r_addend());
4393 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4395 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4396 r_type
= elfcpp::R_POWERPC_NONE
;
4400 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4401 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4402 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4403 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4405 // First instruction of a local dynamic sequence, arg setup insn.
4406 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4407 if (tls_type
== tls::TLSOPT_NONE
)
4409 value
= target
->tlsld_got_offset();
4410 value
-= target
->got_section()->got_base_offset(object
);
4414 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4415 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4416 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4418 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4419 Insn insn
= addis_3_13
;
4422 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4423 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4428 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4430 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4431 r_type
= elfcpp::R_POWERPC_NONE
;
4435 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
4436 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
4437 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
4438 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
4440 // Accesses relative to a local dynamic sequence address,
4441 // no optimisation here.
4444 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
4445 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
4449 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4450 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
4451 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
4453 value
-= target
->got_section()->got_base_offset(object
);
4455 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4456 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4457 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4458 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4460 // First instruction of initial exec sequence.
4461 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4462 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4463 if (tls_type
== tls::TLSOPT_NONE
)
4467 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
4468 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
4472 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4473 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
4474 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
4476 value
-= target
->got_section()->got_base_offset(object
);
4480 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4481 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4482 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4484 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4485 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4486 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
4491 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4492 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4493 value
= psymval
->value(object
, rela
.get_r_addend());
4497 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4499 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4500 r_type
= elfcpp::R_POWERPC_NONE
;
4504 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4505 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4507 // Second instruction of a global dynamic sequence,
4508 // the __tls_get_addr call
4509 this->call_tls_get_addr_
= CALL_EXPECTED
;
4510 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4511 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
4512 if (tls_type
!= tls::TLSOPT_NONE
)
4514 if (tls_type
== tls::TLSOPT_TO_IE
)
4516 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4517 Insn insn
= add_3_3_13
;
4520 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4521 r_type
= elfcpp::R_POWERPC_NONE
;
4525 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4526 Insn insn
= addi_3_3
;
4527 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4528 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4529 view
+= 2 * big_endian
;
4530 value
= psymval
->value(object
, rela
.get_r_addend());
4532 this->call_tls_get_addr_
= CALL_SKIP
;
4535 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4536 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4538 // Second instruction of a local dynamic sequence,
4539 // the __tls_get_addr call
4540 this->call_tls_get_addr_
= CALL_EXPECTED
;
4541 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4542 if (tls_type
== tls::TLSOPT_TO_LE
)
4544 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4545 Insn insn
= addi_3_3
;
4546 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4547 this->call_tls_get_addr_
= CALL_SKIP
;
4548 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4549 view
+= 2 * big_endian
;
4553 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4555 // Second instruction of an initial exec sequence
4556 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4557 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4558 if (tls_type
== tls::TLSOPT_TO_LE
)
4560 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4561 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4562 unsigned int reg
= size
== 32 ? 2 : 13;
4563 insn
= at_tls_transform(insn
, reg
);
4564 gold_assert(insn
!= 0);
4565 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4566 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4567 view
+= 2 * big_endian
;
4568 value
= psymval
->value(object
, rela
.get_r_addend());
4571 else if (!has_plt_value
)
4574 unsigned int dest_shndx
;
4575 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
4576 addend
= rela
.get_r_addend();
4577 value
= psymval
->value(object
, addend
);
4578 if (size
== 64 && is_branch_reloc(r_type
))
4579 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
4584 case elfcpp::R_PPC64_REL64
:
4585 case elfcpp::R_POWERPC_REL32
:
4586 case elfcpp::R_POWERPC_REL24
:
4587 case elfcpp::R_PPC_PLTREL24
:
4588 case elfcpp::R_PPC_LOCAL24PC
:
4589 case elfcpp::R_POWERPC_REL16
:
4590 case elfcpp::R_POWERPC_REL16_LO
:
4591 case elfcpp::R_POWERPC_REL16_HI
:
4592 case elfcpp::R_POWERPC_REL16_HA
:
4593 case elfcpp::R_POWERPC_REL14
:
4594 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4595 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4599 case elfcpp::R_PPC64_TOC16
:
4600 case elfcpp::R_PPC64_TOC16_LO
:
4601 case elfcpp::R_PPC64_TOC16_HI
:
4602 case elfcpp::R_PPC64_TOC16_HA
:
4603 case elfcpp::R_PPC64_TOC16_DS
:
4604 case elfcpp::R_PPC64_TOC16_LO_DS
:
4605 // Subtract the TOC base address.
4606 value
-= (target
->got_section()->output_section()->address()
4607 + object
->toc_base_offset());
4610 case elfcpp::R_POWERPC_SECTOFF
:
4611 case elfcpp::R_POWERPC_SECTOFF_LO
:
4612 case elfcpp::R_POWERPC_SECTOFF_HI
:
4613 case elfcpp::R_POWERPC_SECTOFF_HA
:
4614 case elfcpp::R_PPC64_SECTOFF_DS
:
4615 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4617 value
-= os
->address();
4620 case elfcpp::R_PPC64_TPREL16_DS
:
4621 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4623 // R_PPC_TLSGD and R_PPC_TLSLD
4625 case elfcpp::R_POWERPC_TPREL16
:
4626 case elfcpp::R_POWERPC_TPREL16_LO
:
4627 case elfcpp::R_POWERPC_TPREL16_HI
:
4628 case elfcpp::R_POWERPC_TPREL16_HA
:
4629 case elfcpp::R_POWERPC_TPREL
:
4630 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4631 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4632 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4633 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4634 // tls symbol values are relative to tls_segment()->vaddr()
4638 case elfcpp::R_PPC64_DTPREL16_DS
:
4639 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4640 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4641 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4642 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4643 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4645 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
4646 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
4648 case elfcpp::R_POWERPC_DTPREL16
:
4649 case elfcpp::R_POWERPC_DTPREL16_LO
:
4650 case elfcpp::R_POWERPC_DTPREL16_HI
:
4651 case elfcpp::R_POWERPC_DTPREL16_HA
:
4652 case elfcpp::R_POWERPC_DTPREL
:
4653 // tls symbol values are relative to tls_segment()->vaddr()
4654 value
-= dtp_offset
;
4661 Insn branch_bit
= 0;
4664 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4665 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4666 branch_bit
= 1 << 21;
4667 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4668 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4670 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4671 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4674 if (this->is_isa_v2
)
4676 // Set 'a' bit. This is 0b00010 in BO field for branch
4677 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
4678 // for branch on CTR insns (BO == 1a00t or 1a01t).
4679 if ((insn
& (0x14 << 21)) == (0x04 << 21))
4681 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
4688 // Invert 'y' bit if not the default.
4689 if (static_cast<Signed_address
>(value
) < 0)
4692 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4700 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
4703 case elfcpp::R_POWERPC_ADDR32
:
4704 case elfcpp::R_POWERPC_UADDR32
:
4706 overflow
= Reloc::CHECK_BITFIELD
;
4709 case elfcpp::R_POWERPC_REL32
:
4711 overflow
= Reloc::CHECK_SIGNED
;
4714 case elfcpp::R_POWERPC_ADDR24
:
4715 case elfcpp::R_POWERPC_ADDR16
:
4716 case elfcpp::R_POWERPC_UADDR16
:
4717 case elfcpp::R_PPC64_ADDR16_DS
:
4718 case elfcpp::R_POWERPC_ADDR14
:
4719 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4720 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4721 overflow
= Reloc::CHECK_BITFIELD
;
4724 case elfcpp::R_POWERPC_REL24
:
4725 case elfcpp::R_PPC_PLTREL24
:
4726 case elfcpp::R_PPC_LOCAL24PC
:
4727 case elfcpp::R_POWERPC_REL16
:
4728 case elfcpp::R_PPC64_TOC16
:
4729 case elfcpp::R_POWERPC_GOT16
:
4730 case elfcpp::R_POWERPC_SECTOFF
:
4731 case elfcpp::R_POWERPC_TPREL16
:
4732 case elfcpp::R_POWERPC_DTPREL16
:
4733 case elfcpp::R_PPC64_TPREL16_DS
:
4734 case elfcpp::R_PPC64_DTPREL16_DS
:
4735 case elfcpp::R_PPC64_TOC16_DS
:
4736 case elfcpp::R_PPC64_GOT16_DS
:
4737 case elfcpp::R_PPC64_SECTOFF_DS
:
4738 case elfcpp::R_POWERPC_REL14
:
4739 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4740 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4741 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4742 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4743 case elfcpp::R_POWERPC_GOT_TPREL16
:
4744 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4745 overflow
= Reloc::CHECK_SIGNED
;
4749 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
4750 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
4753 case elfcpp::R_POWERPC_NONE
:
4754 case elfcpp::R_POWERPC_TLS
:
4755 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4756 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4757 case elfcpp::R_PPC_EMB_MRKREF
:
4760 case elfcpp::R_PPC64_ADDR64
:
4761 case elfcpp::R_PPC64_REL64
:
4762 case elfcpp::R_PPC64_TOC
:
4763 Reloc::addr64(view
, value
);
4766 case elfcpp::R_POWERPC_TPREL
:
4767 case elfcpp::R_POWERPC_DTPREL
:
4769 Reloc::addr64(view
, value
);
4771 status
= Reloc::addr32(view
, value
, overflow
);
4774 case elfcpp::R_PPC64_UADDR64
:
4775 Reloc::addr64_u(view
, value
);
4778 case elfcpp::R_POWERPC_ADDR32
:
4779 case elfcpp::R_POWERPC_REL32
:
4780 status
= Reloc::addr32(view
, value
, overflow
);
4783 case elfcpp::R_POWERPC_UADDR32
:
4784 status
= Reloc::addr32_u(view
, value
, overflow
);
4787 case elfcpp::R_POWERPC_ADDR24
:
4788 case elfcpp::R_POWERPC_REL24
:
4789 case elfcpp::R_PPC_PLTREL24
:
4790 case elfcpp::R_PPC_LOCAL24PC
:
4791 status
= Reloc::addr24(view
, value
, overflow
);
4794 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4795 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
4798 status
= Reloc::addr16_ds(view
, value
, overflow
);
4801 case elfcpp::R_POWERPC_ADDR16
:
4802 case elfcpp::R_POWERPC_REL16
:
4803 case elfcpp::R_PPC64_TOC16
:
4804 case elfcpp::R_POWERPC_GOT16
:
4805 case elfcpp::R_POWERPC_SECTOFF
:
4806 case elfcpp::R_POWERPC_TPREL16
:
4807 case elfcpp::R_POWERPC_DTPREL16
:
4808 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4809 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4810 case elfcpp::R_POWERPC_GOT_TPREL16
:
4811 case elfcpp::R_POWERPC_ADDR16_LO
:
4812 case elfcpp::R_POWERPC_REL16_LO
:
4813 case elfcpp::R_PPC64_TOC16_LO
:
4814 case elfcpp::R_POWERPC_GOT16_LO
:
4815 case elfcpp::R_POWERPC_SECTOFF_LO
:
4816 case elfcpp::R_POWERPC_TPREL16_LO
:
4817 case elfcpp::R_POWERPC_DTPREL16_LO
:
4818 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
4819 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
4820 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
4821 status
= Reloc::addr16(view
, value
, overflow
);
4824 case elfcpp::R_POWERPC_UADDR16
:
4825 status
= Reloc::addr16_u(view
, value
, overflow
);
4828 case elfcpp::R_POWERPC_ADDR16_HI
:
4829 case elfcpp::R_POWERPC_REL16_HI
:
4830 case elfcpp::R_PPC64_TOC16_HI
:
4831 case elfcpp::R_POWERPC_GOT16_HI
:
4832 case elfcpp::R_POWERPC_SECTOFF_HI
:
4833 case elfcpp::R_POWERPC_TPREL16_HI
:
4834 case elfcpp::R_POWERPC_DTPREL16_HI
:
4835 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
4836 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
4837 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
4838 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
4839 Reloc::addr16_hi(view
, value
);
4842 case elfcpp::R_POWERPC_ADDR16_HA
:
4843 case elfcpp::R_POWERPC_REL16_HA
:
4844 case elfcpp::R_PPC64_TOC16_HA
:
4845 case elfcpp::R_POWERPC_GOT16_HA
:
4846 case elfcpp::R_POWERPC_SECTOFF_HA
:
4847 case elfcpp::R_POWERPC_TPREL16_HA
:
4848 case elfcpp::R_POWERPC_DTPREL16_HA
:
4849 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
4850 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
4851 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
4852 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
4853 Reloc::addr16_ha(view
, value
);
4856 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4858 // R_PPC_EMB_NADDR16_LO
4860 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4861 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4862 Reloc::addr16_hi2(view
, value
);
4865 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4867 // R_PPC_EMB_NADDR16_HI
4869 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4870 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4871 Reloc::addr16_ha2(view
, value
);
4874 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4876 // R_PPC_EMB_NADDR16_HA
4878 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4879 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4880 Reloc::addr16_hi3(view
, value
);
4883 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4887 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4888 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4889 Reloc::addr16_ha3(view
, value
);
4892 case elfcpp::R_PPC64_DTPREL16_DS
:
4893 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4895 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
4897 case elfcpp::R_PPC64_TPREL16_DS
:
4898 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4900 // R_PPC_TLSGD, R_PPC_TLSLD
4902 case elfcpp::R_PPC64_ADDR16_DS
:
4903 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4904 case elfcpp::R_PPC64_TOC16_DS
:
4905 case elfcpp::R_PPC64_TOC16_LO_DS
:
4906 case elfcpp::R_PPC64_GOT16_DS
:
4907 case elfcpp::R_PPC64_GOT16_LO_DS
:
4908 case elfcpp::R_PPC64_SECTOFF_DS
:
4909 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4910 status
= Reloc::addr16_ds(view
, value
, overflow
);
4913 case elfcpp::R_POWERPC_ADDR14
:
4914 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4915 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4916 case elfcpp::R_POWERPC_REL14
:
4917 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4918 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4919 status
= Reloc::addr14(view
, value
, overflow
);
4922 case elfcpp::R_POWERPC_COPY
:
4923 case elfcpp::R_POWERPC_GLOB_DAT
:
4924 case elfcpp::R_POWERPC_JMP_SLOT
:
4925 case elfcpp::R_POWERPC_RELATIVE
:
4926 case elfcpp::R_POWERPC_DTPMOD
:
4927 case elfcpp::R_PPC64_JMP_IREL
:
4928 case elfcpp::R_POWERPC_IRELATIVE
:
4929 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4930 _("unexpected reloc %u in object file"),
4934 case elfcpp::R_PPC_EMB_SDA21
:
4939 // R_PPC64_TOCSAVE. For the time being this can be ignored.
4943 case elfcpp::R_PPC_EMB_SDA2I16
:
4944 case elfcpp::R_PPC_EMB_SDA2REL
:
4947 // R_PPC64_TLSGD, R_PPC64_TLSLD
4950 case elfcpp::R_POWERPC_PLT32
:
4951 case elfcpp::R_POWERPC_PLTREL32
:
4952 case elfcpp::R_POWERPC_PLT16_LO
:
4953 case elfcpp::R_POWERPC_PLT16_HI
:
4954 case elfcpp::R_POWERPC_PLT16_HA
:
4955 case elfcpp::R_PPC_SDAREL16
:
4956 case elfcpp::R_POWERPC_ADDR30
:
4957 case elfcpp::R_PPC64_PLT64
:
4958 case elfcpp::R_PPC64_PLTREL64
:
4959 case elfcpp::R_PPC64_PLTGOT16
:
4960 case elfcpp::R_PPC64_PLTGOT16_LO
:
4961 case elfcpp::R_PPC64_PLTGOT16_HI
:
4962 case elfcpp::R_PPC64_PLTGOT16_HA
:
4963 case elfcpp::R_PPC64_PLT16_LO_DS
:
4964 case elfcpp::R_PPC64_PLTGOT16_DS
:
4965 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
4966 case elfcpp::R_PPC_EMB_RELSEC16
:
4967 case elfcpp::R_PPC_EMB_RELST_LO
:
4968 case elfcpp::R_PPC_EMB_RELST_HI
:
4969 case elfcpp::R_PPC_EMB_RELST_HA
:
4970 case elfcpp::R_PPC_EMB_BIT_FLD
:
4971 case elfcpp::R_PPC_EMB_RELSDA
:
4972 case elfcpp::R_PPC_TOC16
:
4975 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4976 _("unsupported reloc %u"),
4980 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
4981 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4982 _("relocation overflow"));
4987 // Relocate section data.
4989 template<int size
, bool big_endian
>
4991 Target_powerpc
<size
, big_endian
>::relocate_section(
4992 const Relocate_info
<size
, big_endian
>* relinfo
,
4993 unsigned int sh_type
,
4994 const unsigned char* prelocs
,
4996 Output_section
* output_section
,
4997 bool needs_special_offset_handling
,
4998 unsigned char* view
,
5000 section_size_type view_size
,
5001 const Reloc_symbol_changes
* reloc_symbol_changes
)
5003 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5004 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
5006 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5008 unsigned char *opd_rel
= NULL
;
5009 Powerpc_relobj
<size
, big_endian
>* const object
5010 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
5012 && relinfo
->data_shndx
== object
->opd_shndx())
5014 // Rewrite opd relocs, omitting those for discarded sections
5015 // to silence gold::relocate_section errors.
5016 const int reloc_size
5017 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
5018 opd_rel
= new unsigned char[reloc_count
* reloc_size
];
5019 const unsigned char* rrel
= prelocs
;
5020 unsigned char* wrel
= opd_rel
;
5024 ++i
, rrel
+= reloc_size
, wrel
+= reloc_size
)
5026 typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
5028 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
5029 = reloc
.get_r_info();
5030 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
5031 Address r_off
= reloc
.get_r_offset();
5032 if (r_type
== elfcpp::R_PPC64_TOC
)
5034 bool is_discarded
= object
->get_opd_discard(r_off
);
5036 // Reloc number is reported in some errors, so keep all relocs.
5038 memset(wrel
, 0, reloc_size
);
5040 memcpy(wrel
, rrel
, reloc_size
);
5045 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
5052 needs_special_offset_handling
,
5056 reloc_symbol_changes
);
5058 if (opd_rel
!= NULL
)
5062 class Powerpc_scan_relocatable_reloc
5065 // Return the strategy to use for a local symbol which is not a
5066 // section symbol, given the relocation type.
5067 inline Relocatable_relocs::Reloc_strategy
5068 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
5070 if (r_type
== 0 && r_sym
== 0)
5071 return Relocatable_relocs::RELOC_DISCARD
;
5072 return Relocatable_relocs::RELOC_COPY
;
5075 // Return the strategy to use for a local symbol which is a section
5076 // symbol, given the relocation type.
5077 inline Relocatable_relocs::Reloc_strategy
5078 local_section_strategy(unsigned int, Relobj
*)
5080 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
5083 // Return the strategy to use for a global symbol, given the
5084 // relocation type, the object, and the symbol index.
5085 inline Relocatable_relocs::Reloc_strategy
5086 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
5088 if (r_type
== elfcpp::R_PPC_PLTREL24
)
5089 return Relocatable_relocs::RELOC_SPECIAL
;
5090 return Relocatable_relocs::RELOC_COPY
;
5094 // Scan the relocs during a relocatable link.
5096 template<int size
, bool big_endian
>
5098 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
5099 Symbol_table
* symtab
,
5101 Sized_relobj_file
<size
, big_endian
>* object
,
5102 unsigned int data_shndx
,
5103 unsigned int sh_type
,
5104 const unsigned char* prelocs
,
5106 Output_section
* output_section
,
5107 bool needs_special_offset_handling
,
5108 size_t local_symbol_count
,
5109 const unsigned char* plocal_symbols
,
5110 Relocatable_relocs
* rr
)
5112 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5114 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
5115 Powerpc_scan_relocatable_reloc
>(
5123 needs_special_offset_handling
,
5129 // Emit relocations for a section.
5130 // This is a modified version of the function by the same name in
5131 // target-reloc.h. Using relocate_special_relocatable for
5132 // R_PPC_PLTREL24 would require duplication of the entire body of the
5133 // loop, so we may as well duplicate the whole thing.
5135 template<int size
, bool big_endian
>
5137 Target_powerpc
<size
, big_endian
>::relocate_relocs(
5138 const Relocate_info
<size
, big_endian
>* relinfo
,
5139 unsigned int sh_type
,
5140 const unsigned char* prelocs
,
5142 Output_section
* output_section
,
5143 off_t offset_in_output_section
,
5144 const Relocatable_relocs
* rr
,
5146 Address view_address
,
5148 unsigned char* reloc_view
,
5149 section_size_type reloc_view_size
)
5151 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5153 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
5155 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
5157 const int reloc_size
5158 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
5160 Powerpc_relobj
<size
, big_endian
>* const object
5161 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
5162 const unsigned int local_count
= object
->local_symbol_count();
5163 unsigned int got2_shndx
= object
->got2_shndx();
5164 Address got2_addend
= 0;
5165 if (got2_shndx
!= 0)
5167 got2_addend
= object
->get_output_section_offset(got2_shndx
);
5168 gold_assert(got2_addend
!= invalid_address
);
5171 unsigned char* pwrite
= reloc_view
;
5172 bool zap_next
= false;
5173 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
5175 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
5176 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
5179 Reltype
reloc(prelocs
);
5180 Reltype_write
reloc_write(pwrite
);
5182 Address offset
= reloc
.get_r_offset();
5183 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
5184 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
5185 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
5186 const unsigned int orig_r_sym
= r_sym
;
5187 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
5188 = reloc
.get_r_addend();
5189 const Symbol
* gsym
= NULL
;
5193 // We could arrange to discard these and other relocs for
5194 // tls optimised sequences in the strategy methods, but for
5195 // now do as BFD ld does.
5196 r_type
= elfcpp::R_POWERPC_NONE
;
5200 // Get the new symbol index.
5201 if (r_sym
< local_count
)
5205 case Relocatable_relocs::RELOC_COPY
:
5206 case Relocatable_relocs::RELOC_SPECIAL
:
5209 r_sym
= object
->symtab_index(r_sym
);
5210 gold_assert(r_sym
!= -1U);
5214 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
5216 // We are adjusting a section symbol. We need to find
5217 // the symbol table index of the section symbol for
5218 // the output section corresponding to input section
5219 // in which this symbol is defined.
5220 gold_assert(r_sym
< local_count
);
5222 unsigned int shndx
=
5223 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
5224 gold_assert(is_ordinary
);
5225 Output_section
* os
= object
->output_section(shndx
);
5226 gold_assert(os
!= NULL
);
5227 gold_assert(os
->needs_symtab_index());
5228 r_sym
= os
->symtab_index();
5238 gsym
= object
->global_symbol(r_sym
);
5239 gold_assert(gsym
!= NULL
);
5240 if (gsym
->is_forwarder())
5241 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
5243 gold_assert(gsym
->has_symtab_index());
5244 r_sym
= gsym
->symtab_index();
5247 // Get the new offset--the location in the output section where
5248 // this relocation should be applied.
5249 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
5250 offset
+= offset_in_output_section
;
5253 section_offset_type sot_offset
=
5254 convert_types
<section_offset_type
, Address
>(offset
);
5255 section_offset_type new_sot_offset
=
5256 output_section
->output_offset(object
, relinfo
->data_shndx
,
5258 gold_assert(new_sot_offset
!= -1);
5259 offset
= new_sot_offset
;
5262 // In an object file, r_offset is an offset within the section.
5263 // In an executable or dynamic object, generated by
5264 // --emit-relocs, r_offset is an absolute address.
5265 if (!parameters
->options().relocatable())
5267 offset
+= view_address
;
5268 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
5269 offset
-= offset_in_output_section
;
5272 // Handle the reloc addend based on the strategy.
5273 if (strategy
== Relocatable_relocs::RELOC_COPY
)
5275 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
5277 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
5278 addend
= psymval
->value(object
, addend
);
5280 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
5282 if (addend
>= 32768)
5283 addend
+= got2_addend
;
5288 if (!parameters
->options().relocatable())
5290 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5291 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
5292 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
5293 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
5295 // First instruction of a global dynamic sequence,
5297 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5298 switch (this->optimize_tls_gd(final
))
5300 case tls::TLSOPT_TO_IE
:
5301 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
5302 - elfcpp::R_POWERPC_GOT_TLSGD16
);
5304 case tls::TLSOPT_TO_LE
:
5305 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5306 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
5307 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5310 r_type
= elfcpp::R_POWERPC_NONE
;
5311 offset
-= 2 * big_endian
;
5318 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5319 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
5320 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
5321 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
5323 // First instruction of a local dynamic sequence,
5325 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
5327 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5328 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
5330 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5331 const Output_section
* os
= relinfo
->layout
->tls_segment()
5333 gold_assert(os
!= NULL
);
5334 gold_assert(os
->needs_symtab_index());
5335 r_sym
= os
->symtab_index();
5336 addend
= dtp_offset
;
5340 r_type
= elfcpp::R_POWERPC_NONE
;
5341 offset
-= 2 * big_endian
;
5345 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5346 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
5347 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
5348 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
5350 // First instruction of initial exec sequence.
5351 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5352 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
5354 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5355 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
5356 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5359 r_type
= elfcpp::R_POWERPC_NONE
;
5360 offset
-= 2 * big_endian
;
5364 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5365 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5367 // Second instruction of a global dynamic sequence,
5368 // the __tls_get_addr call
5369 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5370 switch (this->optimize_tls_gd(final
))
5372 case tls::TLSOPT_TO_IE
:
5373 r_type
= elfcpp::R_POWERPC_NONE
;
5376 case tls::TLSOPT_TO_LE
:
5377 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5378 offset
+= 2 * big_endian
;
5385 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5386 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5388 // Second instruction of a local dynamic sequence,
5389 // the __tls_get_addr call
5390 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
5392 const Output_section
* os
= relinfo
->layout
->tls_segment()
5394 gold_assert(os
!= NULL
);
5395 gold_assert(os
->needs_symtab_index());
5396 r_sym
= os
->symtab_index();
5397 addend
= dtp_offset
;
5398 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5399 offset
+= 2 * big_endian
;
5403 else if (r_type
== elfcpp::R_POWERPC_TLS
)
5405 // Second instruction of an initial exec sequence
5406 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5407 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
5409 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5410 offset
+= 2 * big_endian
;
5415 reloc_write
.put_r_offset(offset
);
5416 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
5417 reloc_write
.put_r_addend(addend
);
5419 pwrite
+= reloc_size
;
5422 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
5423 == reloc_view_size
);
5426 // Return the value to use for a dynamic which requires special
5427 // treatment. This is how we support equality comparisons of function
5428 // pointers across shared library boundaries, as described in the
5429 // processor specific ABI supplement.
5431 template<int size
, bool big_endian
>
5433 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
5437 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
5438 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5439 unsigned int glink_index
= glink
->find_entry(gsym
);
5440 return glink
->address() + glink_index
* glink
->glink_entry_size();
5446 // Return the PLT address to use for a local symbol.
5447 template<int size
, bool big_endian
>
5449 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
5450 const Relobj
* object
,
5451 unsigned int symndx
) const
5455 const Sized_relobj
<size
, big_endian
>* relobj
5456 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
5457 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5458 unsigned int glink_index
= glink
->find_entry(relobj
->sized_relobj(),
5460 return glink
->address() + glink_index
* glink
->glink_entry_size();
5466 // Return the PLT address to use for a global symbol.
5467 template<int size
, bool big_endian
>
5469 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
5470 const Symbol
* gsym
) const
5474 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5475 unsigned int glink_index
= glink
->find_entry(gsym
);
5476 return glink
->address() + glink_index
* glink
->glink_entry_size();
5482 // Return the offset to use for the GOT_INDX'th got entry which is
5483 // for a local tls symbol specified by OBJECT, SYMNDX.
5484 template<int size
, bool big_endian
>
5486 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
5487 const Relobj
* object
,
5488 unsigned int symndx
,
5489 unsigned int got_indx
) const
5491 const Powerpc_relobj
<size
, big_endian
>* ppc_object
5492 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
5493 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
5495 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5496 got_type
<= GOT_TYPE_TPREL
;
5497 got_type
= Got_type(got_type
+ 1))
5498 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
5500 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
5501 if (got_type
== GOT_TYPE_TLSGD
)
5503 if (off
== got_indx
* (size
/ 8))
5505 if (got_type
== GOT_TYPE_TPREL
)
5515 // Return the offset to use for the GOT_INDX'th got entry which is
5516 // for global tls symbol GSYM.
5517 template<int size
, bool big_endian
>
5519 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
5521 unsigned int got_indx
) const
5523 if (gsym
->type() == elfcpp::STT_TLS
)
5525 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5526 got_type
<= GOT_TYPE_TPREL
;
5527 got_type
= Got_type(got_type
+ 1))
5528 if (gsym
->has_got_offset(got_type
))
5530 unsigned int off
= gsym
->got_offset(got_type
);
5531 if (got_type
== GOT_TYPE_TLSGD
)
5533 if (off
== got_indx
* (size
/ 8))
5535 if (got_type
== GOT_TYPE_TPREL
)
5545 // The selector for powerpc object files.
5547 template<int size
, bool big_endian
>
5548 class Target_selector_powerpc
: public Target_selector
5551 Target_selector_powerpc()
5552 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
5554 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
5555 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
5557 ? (big_endian
? "elf64ppc" : "elf64lppc")
5558 : (big_endian
? "elf32ppc" : "elf32lppc")))
5562 do_recognize(Input_file
*, off_t
, int machine
, int, int)
5567 if (machine
!= elfcpp::EM_PPC64
)
5572 if (machine
!= elfcpp::EM_PPC
)
5580 return this->instantiate_target();
5584 do_instantiate_target()
5585 { return new Target_powerpc
<size
, big_endian
>(); }
5588 Target_selector_powerpc
<32, true> target_selector_ppc32
;
5589 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
5590 Target_selector_powerpc
<64, true> target_selector_ppc64
;
5591 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
5593 } // End anonymous namespace.