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 class Relocate_comdat_behavior
625 // Decide what the linker should do for relocations that refer to
626 // discarded comdat sections.
627 inline Comdat_behavior
628 get(const char* name
)
630 gold::Default_comdat_behavior default_behavior
;
631 Comdat_behavior ret
= default_behavior
.get(name
);
632 if (ret
== CB_WARNING
)
635 && (strcmp(name
, ".fixup") == 0
636 || strcmp(name
, ".got2") == 0))
639 && (strcmp(name
, ".opd") == 0
640 || strcmp(name
, ".toc") == 0
641 || strcmp(name
, ".toc1") == 0))
648 // A class which returns the size required for a relocation type,
649 // used while scanning relocs during a relocatable link.
650 class Relocatable_size_for_reloc
654 get_size_for_reloc(unsigned int, Relobj
*)
661 // Optimize the TLS relocation type based on what we know about the
662 // symbol. IS_FINAL is true if the final address of this symbol is
663 // known at link time.
665 tls::Tls_optimization
666 optimize_tls_gd(bool is_final
)
668 // If we are generating a shared library, then we can't do anything
670 if (parameters
->options().shared())
671 return tls::TLSOPT_NONE
;
674 return tls::TLSOPT_TO_IE
;
675 return tls::TLSOPT_TO_LE
;
678 tls::Tls_optimization
681 if (parameters
->options().shared())
682 return tls::TLSOPT_NONE
;
684 return tls::TLSOPT_TO_LE
;
687 tls::Tls_optimization
688 optimize_tls_ie(bool is_final
)
690 if (!is_final
|| parameters
->options().shared())
691 return tls::TLSOPT_NONE
;
693 return tls::TLSOPT_TO_LE
;
696 // Get the GOT section, creating it if necessary.
697 Output_data_got_powerpc
<size
, big_endian
>*
698 got_section(Symbol_table
*, Layout
*);
702 make_glink_section(Layout
*);
704 // Create the PLT section.
706 make_plt_section(Layout
*);
709 make_iplt_section(Layout
*);
711 // Create a PLT entry for a global symbol.
713 make_plt_entry(Layout
*, Symbol
*,
714 const elfcpp::Rela
<size
, big_endian
>&,
715 const Sized_relobj_file
<size
, big_endian
>* object
);
717 // Create a PLT entry for a local IFUNC symbol.
719 make_local_ifunc_plt_entry(Layout
*,
720 const elfcpp::Rela
<size
, big_endian
>&,
721 Sized_relobj_file
<size
, big_endian
>*);
723 // Create a GOT entry for local dynamic __tls_get_addr.
725 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
726 Sized_relobj_file
<size
, big_endian
>* object
);
729 tlsld_got_offset() const
731 return this->tlsld_got_offset_
;
734 // Get the dynamic reloc section, creating it if necessary.
736 rela_dyn_section(Layout
*);
738 // Copy a relocation against a global symbol.
740 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
741 Sized_relobj_file
<size
, big_endian
>* object
,
742 unsigned int shndx
, Output_section
* output_section
,
743 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
745 this->copy_relocs_
.copy_reloc(symtab
, layout
,
746 symtab
->get_sized_symbol
<size
>(sym
),
747 object
, shndx
, output_section
,
748 reloc
, this->rela_dyn_section(layout
));
751 // Information about this specific target which we pass to the
752 // general Target structure.
753 static Target::Target_info powerpc_info
;
755 // The types of GOT entries needed for this platform.
756 // These values are exposed to the ABI in an incremental link.
757 // Do not renumber existing values without changing the version
758 // number of the .gnu_incremental_inputs section.
762 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
763 GOT_TYPE_DTPREL
, // entry for @got@dtprel
764 GOT_TYPE_TPREL
// entry for @got@tprel
767 // The GOT output section.
768 Output_data_got_powerpc
<size
, big_endian
>* got_
;
769 // The PLT output section.
770 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
771 // The IPLT output section.
772 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
773 // The .glink output section.
774 Output_data_glink
<size
, big_endian
>* glink_
;
775 // The dynamic reloc output section.
776 Reloc_section
* rela_dyn_
;
777 // Relocs saved to avoid a COPY reloc.
778 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
779 // Space for variables copied with a COPY reloc.
780 Output_data_space
* dynbss_
;
781 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
782 unsigned int tlsld_got_offset_
;
786 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
789 true, // 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
<32, false>::powerpc_info
=
815 false, // is_big_endian
816 elfcpp::EM_PPC
, // 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, true>::powerpc_info
=
841 true, // 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 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
867 false, // is_big_endian
868 elfcpp::EM_PPC64
, // machine_code
869 false, // has_make_symbol
870 false, // has_resolve
871 false, // has_code_fill
872 true, // is_default_stack_executable
873 false, // can_icf_inline_merge_sections
875 "/usr/lib/ld.so.1", // dynamic_linker
876 0x10000000, // default_text_segment_address
877 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
878 4 * 1024, // common_pagesize (overridable by -z common-page-size)
879 false, // isolate_execinstr
881 elfcpp::SHN_UNDEF
, // small_common_shndx
882 elfcpp::SHN_UNDEF
, // large_common_shndx
883 0, // small_common_section_flags
884 0, // large_common_section_flags
885 NULL
, // attributes_section
886 NULL
// attributes_vendor
890 is_branch_reloc(unsigned int r_type
)
892 return (r_type
== elfcpp::R_POWERPC_REL24
893 || r_type
== elfcpp::R_PPC_PLTREL24
894 || r_type
== elfcpp::R_PPC_LOCAL24PC
895 || r_type
== elfcpp::R_POWERPC_REL14
896 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
897 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
898 || r_type
== elfcpp::R_POWERPC_ADDR24
899 || r_type
== elfcpp::R_POWERPC_ADDR14
900 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
901 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
904 // If INSN is an opcode that may be used with an @tls operand, return
905 // the transformed insn for TLS optimisation, otherwise return 0. If
906 // REG is non-zero only match an insn with RB or RA equal to REG.
908 at_tls_transform(uint32_t insn
, unsigned int reg
)
910 if ((insn
& (0x3f << 26)) != 31 << 26)
914 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
915 rtra
= insn
& ((1 << 26) - (1 << 16));
916 else if (((insn
>> 16) & 0x1f) == reg
)
917 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
921 if ((insn
& (0x3ff << 1)) == 266 << 1)
924 else if ((insn
& (0x1f << 1)) == 23 << 1
925 && ((insn
& (0x1f << 6)) < 14 << 6
926 || ((insn
& (0x1f << 6)) >= 16 << 6
927 && (insn
& (0x1f << 6)) < 24 << 6)))
928 // load and store indexed -> dform
929 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
930 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
931 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
932 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
933 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
935 insn
= (58 << 26) | 2;
942 // Modified version of symtab.h class Symbol member
943 // Given a direct absolute or pc-relative static relocation against
944 // the global symbol, this function returns whether a dynamic relocation
949 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
951 // No dynamic relocations in a static link!
952 if (parameters
->doing_static_link())
955 // A reference to an undefined symbol from an executable should be
956 // statically resolved to 0, and does not need a dynamic relocation.
957 // This matches gnu ld behavior.
958 if (gsym
->is_undefined() && !parameters
->options().shared())
961 // A reference to an absolute symbol does not need a dynamic relocation.
962 if (gsym
->is_absolute())
965 // An absolute reference within a position-independent output file
966 // will need a dynamic relocation.
967 if ((flags
& Symbol::ABSOLUTE_REF
)
968 && parameters
->options().output_is_position_independent())
971 // A function call that can branch to a local PLT entry does not need
972 // a dynamic relocation.
973 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
976 // A reference to any PLT entry in a non-position-independent executable
977 // does not need a dynamic relocation.
978 // Except due to having function descriptors on powerpc64 we don't define
979 // functions to their plt code in an executable, so this doesn't apply.
981 && !parameters
->options().output_is_position_independent()
982 && gsym
->has_plt_offset())
985 // A reference to a symbol defined in a dynamic object or to a
986 // symbol that is preemptible will need a dynamic relocation.
987 if (gsym
->is_from_dynobj()
988 || gsym
->is_undefined()
989 || gsym
->is_preemptible())
992 // For all other cases, return FALSE.
996 // Modified version of symtab.h class Symbol member
997 // Whether we should use the PLT offset associated with a symbol for
998 // a relocation. FLAGS is a set of Reference_flags.
1002 use_plt_offset(const Symbol
* gsym
, int flags
)
1004 // If the symbol doesn't have a PLT offset, then naturally we
1005 // don't want to use it.
1006 if (!gsym
->has_plt_offset())
1009 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
1010 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
1013 // If we are going to generate a dynamic relocation, then we will
1014 // wind up using that, so no need to use the PLT entry.
1015 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
1018 // If the symbol is from a dynamic object, we need to use the PLT
1020 if (gsym
->is_from_dynobj())
1023 // If we are generating a shared object, and gsym symbol is
1024 // undefined or preemptible, we need to use the PLT entry.
1025 if (parameters
->options().shared()
1026 && (gsym
->is_undefined() || gsym
->is_preemptible()))
1029 // If gsym is a call to a weak undefined symbol, we need to use
1030 // the PLT entry; the symbol may be defined by a library loaded
1032 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
1035 // Otherwise we can use the regular definition.
1039 template<int size
, bool big_endian
>
1040 class Powerpc_relocate_functions
1057 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1058 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1060 template<int valsize
>
1062 has_overflow_signed(Address value
)
1064 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1065 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1066 limit
<<= ((valsize
- 1) >> 1);
1067 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1068 return value
+ limit
> (limit
<< 1) - 1;
1071 template<int valsize
>
1073 has_overflow_bitfield(Address value
)
1075 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1076 limit
<<= ((valsize
- 1) >> 1);
1077 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1078 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
1081 template<int valsize
>
1082 static inline Status
1083 overflowed(Address value
, Overflow_check overflow
)
1085 if (overflow
== CHECK_SIGNED
)
1087 if (has_overflow_signed
<valsize
>(value
))
1088 return STATUS_OVERFLOW
;
1090 else if (overflow
== CHECK_BITFIELD
)
1092 if (has_overflow_bitfield
<valsize
>(value
))
1093 return STATUS_OVERFLOW
;
1098 // Do a simple RELA relocation
1099 template<int valsize
>
1100 static inline Status
1101 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1103 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1104 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1105 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1106 return overflowed
<valsize
>(value
, overflow
);
1109 template<int valsize
>
1110 static inline Status
1111 rela(unsigned char* view
,
1112 unsigned int right_shift
,
1113 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1115 Overflow_check overflow
)
1117 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1118 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1119 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1120 Valtype reloc
= value
>> right_shift
;
1123 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1124 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1127 // Do a simple RELA relocation, unaligned.
1128 template<int valsize
>
1129 static inline Status
1130 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1132 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1133 return overflowed
<valsize
>(value
, overflow
);
1136 template<int valsize
>
1137 static inline Status
1138 rela_ua(unsigned char* view
,
1139 unsigned int right_shift
,
1140 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1142 Overflow_check overflow
)
1144 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1146 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1147 Valtype reloc
= value
>> right_shift
;
1150 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1151 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1155 // R_PPC64_ADDR64: (Symbol + Addend)
1157 addr64(unsigned char* view
, Address value
)
1158 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1160 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1162 addr64_u(unsigned char* view
, Address value
)
1163 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1165 // R_POWERPC_ADDR32: (Symbol + Addend)
1166 static inline Status
1167 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1168 { return This::template rela
<32>(view
, value
, overflow
); }
1170 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1171 static inline Status
1172 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1173 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1175 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1176 static inline Status
1177 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1179 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1180 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1181 stat
= STATUS_OVERFLOW
;
1185 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1186 static inline Status
1187 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1188 { return This::template rela
<16>(view
, value
, overflow
); }
1190 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1191 static inline Status
1192 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1193 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1195 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1196 static inline Status
1197 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1199 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1200 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1201 stat
= STATUS_OVERFLOW
;
1205 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1207 addr16_hi(unsigned char* view
, Address value
)
1208 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1210 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1212 addr16_ha(unsigned char* view
, Address value
)
1213 { This::addr16_hi(view
, value
+ 0x8000); }
1215 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1217 addr16_hi2(unsigned char* view
, Address value
)
1218 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1220 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1222 addr16_ha2(unsigned char* view
, Address value
)
1223 { This::addr16_hi2(view
, value
+ 0x8000); }
1225 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1227 addr16_hi3(unsigned char* view
, Address value
)
1228 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1230 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1232 addr16_ha3(unsigned char* view
, Address value
)
1233 { This::addr16_hi3(view
, value
+ 0x8000); }
1235 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1236 static inline Status
1237 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1239 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1240 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1241 stat
= STATUS_OVERFLOW
;
1246 // Stash away the index of .got2 or .opd in a relocatable object, if
1247 // such a section exists.
1249 template<int size
, bool big_endian
>
1251 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1252 Read_symbols_data
* sd
)
1254 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1255 const unsigned char* namesu
= sd
->section_names
->data();
1256 const char* names
= reinterpret_cast<const char*>(namesu
);
1257 section_size_type names_size
= sd
->section_names_size
;
1258 const unsigned char* s
;
1260 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1261 names
, names_size
, NULL
);
1264 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1265 this->special_
= ndx
;
1267 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1270 // Examine .rela.opd to build info about function entry points.
1272 template<int size
, bool big_endian
>
1274 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1276 const unsigned char* prelocs
,
1277 const unsigned char* plocal_syms
)
1281 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1283 const int reloc_size
1284 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1285 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1286 Address expected_off
= 0;
1287 bool regular
= true;
1288 unsigned int opd_ent_size
= 0;
1290 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1292 Reltype
reloc(prelocs
);
1293 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1294 = reloc
.get_r_info();
1295 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1296 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1298 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1299 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1302 if (r_sym
< this->local_symbol_count())
1304 typename
elfcpp::Sym
<size
, big_endian
>
1305 lsym(plocal_syms
+ r_sym
* sym_size
);
1306 shndx
= lsym
.get_st_shndx();
1307 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1308 value
= lsym
.get_st_value();
1311 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1313 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1314 value
+ reloc
.get_r_addend());
1317 expected_off
= reloc
.get_r_offset();
1318 opd_ent_size
= expected_off
;
1320 else if (expected_off
!= reloc
.get_r_offset())
1322 expected_off
+= opd_ent_size
;
1324 else if (r_type
== elfcpp::R_PPC64_TOC
)
1326 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1331 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1332 this->name().c_str(), r_type
);
1336 if (reloc_count
<= 2)
1337 opd_ent_size
= this->section_size(this->opd_shndx());
1338 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1342 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1343 this->name().c_str());
1349 template<int size
, bool big_endian
>
1351 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1353 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1356 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1357 p
!= rd
->relocs
.end();
1360 if (p
->data_shndx
== this->opd_shndx())
1362 uint64_t opd_size
= this->section_size(this->opd_shndx());
1363 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1366 this->init_opd(opd_size
);
1367 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1368 rd
->local_symbols
->data());
1376 // Set up PowerPC target specific relobj.
1378 template<int size
, bool big_endian
>
1380 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1381 const std::string
& name
,
1382 Input_file
* input_file
,
1383 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1385 int et
= ehdr
.get_e_type();
1386 // ET_EXEC files are valid input for --just-symbols/-R,
1387 // and we treat them as relocatable objects.
1388 if (et
== elfcpp::ET_REL
1389 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1391 Powerpc_relobj
<size
, big_endian
>* obj
=
1392 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1396 else if (et
== elfcpp::ET_DYN
)
1398 Sized_dynobj
<size
, big_endian
>* obj
=
1399 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1405 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1410 template<int size
, bool big_endian
>
1411 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1414 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1415 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1417 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1418 : Output_data_got
<size
, big_endian
>(),
1419 symtab_(symtab
), layout_(layout
),
1420 header_ent_cnt_(size
== 32 ? 3 : 1),
1421 header_index_(size
== 32 ? 0x2000 : 0)
1426 // Create a new GOT entry and return its offset.
1428 add_got_entry(Got_entry got_entry
)
1430 this->reserve_ent();
1431 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1434 // Create a pair of new GOT entries and return the offset of the first.
1436 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1438 this->reserve_ent(2);
1439 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1444 add_constant_pair(Valtype c1
, Valtype c2
)
1446 this->reserve_ent(2);
1447 unsigned int got_offset
= this->add_constant(c1
);
1448 this->add_constant(c2
);
1452 // Offset of _GLOBAL_OFFSET_TABLE_.
1456 return this->got_offset(this->header_index_
);
1459 // Offset of base used to access the GOT/TOC.
1460 // The got/toc pointer reg will be set to this value.
1461 typename
elfcpp::Elf_types
<size
>::Elf_Off
1462 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1465 return this->g_o_t();
1467 return (this->output_section()->address()
1468 + object
->toc_base_offset()
1472 // Ensure our GOT has a header.
1474 set_final_data_size()
1476 if (this->header_ent_cnt_
!= 0)
1477 this->make_header();
1478 Output_data_got
<size
, big_endian
>::set_final_data_size();
1481 // First word of GOT header needs some values that are not
1482 // handled by Output_data_got so poke them in here.
1483 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1485 do_write(Output_file
* of
)
1488 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
1489 val
= this->layout_
->dynamic_section()->address();
1491 val
= this->output_section()->address() + 0x8000;
1492 this->replace_constant(this->header_index_
, val
);
1493 Output_data_got
<size
, big_endian
>::do_write(of
);
1498 reserve_ent(unsigned int cnt
= 1)
1500 if (this->header_ent_cnt_
== 0)
1502 if (this->num_entries() + cnt
> this->header_index_
)
1503 this->make_header();
1509 this->header_ent_cnt_
= 0;
1510 this->header_index_
= this->num_entries();
1513 Output_data_got
<size
, big_endian
>::add_constant(0);
1514 Output_data_got
<size
, big_endian
>::add_constant(0);
1515 Output_data_got
<size
, big_endian
>::add_constant(0);
1517 // Define _GLOBAL_OFFSET_TABLE_ at the header
1518 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1519 Symbol_table::PREDEFINED
,
1520 this, this->g_o_t(), 0,
1527 Output_data_got
<size
, big_endian
>::add_constant(0);
1530 // Stashed pointers.
1531 Symbol_table
* symtab_
;
1535 unsigned int header_ent_cnt_
;
1536 // GOT header index.
1537 unsigned int header_index_
;
1540 // Get the GOT section, creating it if necessary.
1542 template<int size
, bool big_endian
>
1543 Output_data_got_powerpc
<size
, big_endian
>*
1544 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1547 if (this->got_
== NULL
)
1549 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1552 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1554 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1555 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1556 this->got_
, ORDER_DATA
, false);
1562 // Get the dynamic reloc section, creating it if necessary.
1564 template<int size
, bool big_endian
>
1565 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1566 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1568 if (this->rela_dyn_
== NULL
)
1570 gold_assert(layout
!= NULL
);
1571 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1572 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1573 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1574 ORDER_DYNAMIC_RELOCS
, false);
1576 return this->rela_dyn_
;
1579 // A class to handle the PLT data.
1581 template<int size
, bool big_endian
>
1582 class Output_data_plt_powerpc
: public Output_section_data_build
1585 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1586 size
, big_endian
> Reloc_section
;
1588 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
1589 Reloc_section
* plt_rel
,
1590 unsigned int reserved_size
,
1592 : Output_section_data_build(size
== 32 ? 4 : 8),
1595 initial_plt_entry_size_(reserved_size
),
1599 // Add an entry to the PLT.
1604 add_ifunc_entry(Symbol
*);
1607 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
1609 // Return the .rela.plt section data.
1616 // Return the number of PLT entries.
1620 return ((this->current_data_size() - this->initial_plt_entry_size_
)
1624 // Return the offset of the first non-reserved PLT entry.
1626 first_plt_entry_offset()
1627 { return this->initial_plt_entry_size_
; }
1629 // Return the size of a PLT entry.
1631 get_plt_entry_size()
1632 { return plt_entry_size
; }
1636 do_adjust_output_section(Output_section
* os
)
1641 // Write to a map file.
1643 do_print_to_mapfile(Mapfile
* mapfile
) const
1644 { mapfile
->print_output_data(this, this->name_
); }
1647 // The size of an entry in the PLT.
1648 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1650 // Write out the PLT data.
1652 do_write(Output_file
*);
1654 // The reloc section.
1655 Reloc_section
* rel_
;
1656 // Allows access to .glink for do_write.
1657 Target_powerpc
<size
, big_endian
>* targ_
;
1658 // The size of the first reserved entry.
1659 int initial_plt_entry_size_
;
1660 // What to report in map file.
1664 // Add an entry to the PLT.
1666 template<int size
, bool big_endian
>
1668 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1670 if (!gsym
->has_plt_offset())
1672 off_t off
= this->current_data_size();
1674 off
+= this->first_plt_entry_offset();
1675 gsym
->set_plt_offset(off
);
1676 gsym
->set_needs_dynsym_entry();
1677 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
1678 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
1679 off
+= plt_entry_size
;
1680 this->set_current_data_size(off
);
1684 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
1686 template<int size
, bool big_endian
>
1688 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
1690 if (!gsym
->has_plt_offset())
1692 off_t off
= this->current_data_size();
1693 gsym
->set_plt_offset(off
);
1694 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1696 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1697 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
1698 off
+= plt_entry_size
;
1699 this->set_current_data_size(off
);
1703 // Add an entry for a local ifunc symbol to the IPLT.
1705 template<int size
, bool big_endian
>
1707 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
1708 Sized_relobj_file
<size
, big_endian
>* relobj
,
1709 unsigned int local_sym_index
)
1711 if (!relobj
->local_has_plt_offset(local_sym_index
))
1713 off_t off
= this->current_data_size();
1714 relobj
->set_local_plt_offset(local_sym_index
, off
);
1715 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1717 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1718 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
1720 off
+= plt_entry_size
;
1721 this->set_current_data_size(off
);
1725 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1726 static const uint32_t add_3_3_2
= 0x7c631214;
1727 static const uint32_t add_3_3_13
= 0x7c636a14;
1728 static const uint32_t add_11_0_11
= 0x7d605a14;
1729 static const uint32_t add_12_2_11
= 0x7d825a14;
1730 static const uint32_t addi_11_11
= 0x396b0000;
1731 static const uint32_t addi_12_12
= 0x398c0000;
1732 static const uint32_t addi_2_2
= 0x38420000;
1733 static const uint32_t addi_3_2
= 0x38620000;
1734 static const uint32_t addi_3_3
= 0x38630000;
1735 static const uint32_t addis_0_2
= 0x3c020000;
1736 static const uint32_t addis_0_13
= 0x3c0d0000;
1737 static const uint32_t addis_11_11
= 0x3d6b0000;
1738 static const uint32_t addis_11_30
= 0x3d7e0000;
1739 static const uint32_t addis_12_12
= 0x3d8c0000;
1740 static const uint32_t addis_12_2
= 0x3d820000;
1741 static const uint32_t addis_3_2
= 0x3c620000;
1742 static const uint32_t addis_3_13
= 0x3c6d0000;
1743 static const uint32_t b
= 0x48000000;
1744 static const uint32_t bcl_20_31
= 0x429f0005;
1745 static const uint32_t bctr
= 0x4e800420;
1746 static const uint32_t blr
= 0x4e800020;
1747 static const uint32_t blrl
= 0x4e800021;
1748 static const uint32_t cror_15_15_15
= 0x4def7b82;
1749 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1750 static const uint32_t ld_0_1
= 0xe8010000;
1751 static const uint32_t ld_0_12
= 0xe80c0000;
1752 static const uint32_t ld_11_12
= 0xe96c0000;
1753 static const uint32_t ld_11_2
= 0xe9620000;
1754 static const uint32_t ld_2_1
= 0xe8410000;
1755 static const uint32_t ld_2_11
= 0xe84b0000;
1756 static const uint32_t ld_2_12
= 0xe84c0000;
1757 static const uint32_t ld_2_2
= 0xe8420000;
1758 static const uint32_t lfd_0_1
= 0xc8010000;
1759 static const uint32_t li_0_0
= 0x38000000;
1760 static const uint32_t li_12_0
= 0x39800000;
1761 static const uint32_t lis_0_0
= 0x3c000000;
1762 static const uint32_t lis_11
= 0x3d600000;
1763 static const uint32_t lis_12
= 0x3d800000;
1764 static const uint32_t lwz_0_12
= 0x800c0000;
1765 static const uint32_t lwz_11_11
= 0x816b0000;
1766 static const uint32_t lwz_11_30
= 0x817e0000;
1767 static const uint32_t lwz_12_12
= 0x818c0000;
1768 static const uint32_t lwzu_0_12
= 0x840c0000;
1769 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
1770 static const uint32_t mflr_0
= 0x7c0802a6;
1771 static const uint32_t mflr_11
= 0x7d6802a6;
1772 static const uint32_t mflr_12
= 0x7d8802a6;
1773 static const uint32_t mtctr_0
= 0x7c0903a6;
1774 static const uint32_t mtctr_11
= 0x7d6903a6;
1775 static const uint32_t mtlr_0
= 0x7c0803a6;
1776 static const uint32_t mtlr_12
= 0x7d8803a6;
1777 static const uint32_t nop
= 0x60000000;
1778 static const uint32_t ori_0_0_0
= 0x60000000;
1779 static const uint32_t std_0_1
= 0xf8010000;
1780 static const uint32_t std_0_12
= 0xf80c0000;
1781 static const uint32_t std_2_1
= 0xf8410000;
1782 static const uint32_t stfd_0_1
= 0xd8010000;
1783 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
1784 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1786 // Write out the PLT.
1788 template<int size
, bool big_endian
>
1790 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1794 const off_t offset
= this->offset();
1795 const section_size_type oview_size
1796 = convert_to_section_size_type(this->data_size());
1797 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1798 unsigned char* pov
= oview
;
1799 unsigned char* endpov
= oview
+ oview_size
;
1801 // The address of the .glink branch table
1802 const Output_data_glink
<size
, big_endian
>* glink
1803 = this->targ_
->glink_section();
1804 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1805 = glink
->address() + glink
->pltresolve();
1807 while (pov
< endpov
)
1809 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1814 of
->write_output_view(offset
, oview_size
, oview
);
1818 // Create the PLT section.
1820 template<int size
, bool big_endian
>
1822 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1824 if (this->plt_
== NULL
)
1826 if (this->glink_
== NULL
)
1827 make_glink_section(layout
);
1829 // Ensure that .rela.dyn always appears before .rela.plt This is
1830 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1831 // needs to include .rela.plt in it's range.
1832 this->rela_dyn_section(layout
);
1834 Reloc_section
* plt_rel
= new Reloc_section(false);
1835 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1836 elfcpp::SHF_ALLOC
, plt_rel
,
1837 ORDER_DYNAMIC_PLT_RELOCS
, false);
1839 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
1840 size
== 32 ? 0 : 24,
1842 layout
->add_output_section_data(".plt",
1844 ? elfcpp::SHT_PROGBITS
1845 : elfcpp::SHT_NOBITS
),
1846 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1855 // Create the IPLT section.
1857 template<int size
, bool big_endian
>
1859 Target_powerpc
<size
, big_endian
>::make_iplt_section(Layout
* layout
)
1861 if (this->iplt_
== NULL
)
1863 this->make_plt_section(layout
);
1865 Reloc_section
* iplt_rel
= new Reloc_section(false);
1866 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
1868 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
1870 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
1874 // A class to handle .glink.
1876 template<int size
, bool big_endian
>
1877 class Output_data_glink
: public Output_section_data
1880 static const int pltresolve_size
= 16*4;
1882 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1886 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1888 const elfcpp::Rela
<size
, big_endian
>&);
1891 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1893 const elfcpp::Rela
<size
, big_endian
>&);
1896 find_entry(const Symbol
*) const;
1899 find_entry(const Sized_relobj_file
<size
, big_endian
>*, unsigned int) const;
1902 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1904 const elfcpp::Rela
<size
, big_endian
>&) const;
1907 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1909 const elfcpp::Rela
<size
, big_endian
>&) const;
1912 glink_entry_size() const
1917 // FIXME: We should be using multiple glink sections for
1918 // stubs to support > 33M applications.
1925 return this->pltresolve_
;
1929 // Write to a map file.
1931 do_print_to_mapfile(Mapfile
* mapfile
) const
1932 { mapfile
->print_output_data(this, _("** glink")); }
1936 set_final_data_size();
1940 do_write(Output_file
*);
1945 Glink_sym_ent(const Symbol
* sym
)
1946 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1949 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1950 unsigned int locsym_index
)
1951 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1954 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1956 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1957 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1960 this->addend_
= reloc
.get_r_addend();
1961 else if (parameters
->options().output_is_position_independent()
1962 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1963 == elfcpp::R_PPC_PLTREL24
))
1965 this->addend_
= reloc
.get_r_addend();
1966 if (this->addend_
>= 32768)
1967 this->object_
= object
;
1971 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1972 unsigned int locsym_index
,
1973 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1974 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1977 this->addend_
= reloc
.get_r_addend();
1978 else if (parameters
->options().output_is_position_independent()
1979 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1980 == elfcpp::R_PPC_PLTREL24
))
1981 this->addend_
= reloc
.get_r_addend();
1984 bool operator==(const Glink_sym_ent
& that
) const
1986 return (this->sym_
== that
.sym_
1987 && this->object_
== that
.object_
1988 && this->addend_
== that
.addend_
1989 && this->locsym_
== that
.locsym_
);
1993 const Sized_relobj_file
<size
, big_endian
>* object_
;
1994 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
1995 unsigned int locsym_
;
1998 class Glink_sym_ent_hash
2001 size_t operator()(const Glink_sym_ent
& ent
) const
2003 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
2004 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
2010 // Map sym/object/addend to index.
2011 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
2012 Glink_sym_ent_hash
> Glink_entries
;
2013 Glink_entries glink_entries_
;
2015 // Offset of pltresolve stub (actually, branch table for 32-bit)
2018 // Allows access to .got and .plt for do_write.
2019 Target_powerpc
<size
, big_endian
>* targ_
;
2022 // Create the glink section.
2024 template<int size
, bool big_endian
>
2025 Output_data_glink
<size
, big_endian
>::Output_data_glink(
2026 Target_powerpc
<size
, big_endian
>* targ
)
2027 : Output_section_data(16),
2028 pltresolve_(0), targ_(targ
)
2032 // Add an entry to glink, if we do not already have one for this
2033 // sym/object/addend combo.
2035 template<int size
, bool big_endian
>
2037 Output_data_glink
<size
, big_endian
>::add_entry(
2038 const Sized_relobj_file
<size
, big_endian
>* object
,
2040 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2042 Glink_sym_ent
ent(object
, gsym
, reloc
);
2043 unsigned int indx
= this->glink_entries_
.size();
2044 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2047 template<int size
, bool big_endian
>
2049 Output_data_glink
<size
, big_endian
>::add_entry(
2050 const Sized_relobj_file
<size
, big_endian
>* object
,
2051 unsigned int locsym_index
,
2052 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2054 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2055 unsigned int indx
= this->glink_entries_
.size();
2056 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2059 template<int size
, bool big_endian
>
2061 Output_data_glink
<size
, big_endian
>::find_entry(
2062 const Sized_relobj_file
<size
, big_endian
>* object
,
2064 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2066 Glink_sym_ent
ent(object
, gsym
, reloc
);
2067 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2068 gold_assert(p
!= this->glink_entries_
.end());
2072 template<int size
, bool big_endian
>
2074 Output_data_glink
<size
, big_endian
>::find_entry(const Symbol
* gsym
) const
2076 Glink_sym_ent
ent(gsym
);
2077 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2078 gold_assert(p
!= this->glink_entries_
.end());
2082 template<int size
, bool big_endian
>
2084 Output_data_glink
<size
, big_endian
>::find_entry(
2085 const Sized_relobj_file
<size
, big_endian
>* object
,
2086 unsigned int locsym_index
,
2087 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2089 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2090 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2091 gold_assert(p
!= this->glink_entries_
.end());
2095 template<int size
, bool big_endian
>
2097 Output_data_glink
<size
, big_endian
>::find_entry(
2098 const Sized_relobj_file
<size
, big_endian
>* object
,
2099 unsigned int locsym_index
) const
2101 Glink_sym_ent
ent(object
, locsym_index
);
2102 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2103 gold_assert(p
!= this->glink_entries_
.end());
2107 template<int size
, bool big_endian
>
2109 Output_data_glink
<size
, big_endian
>::set_final_data_size()
2111 unsigned int count
= this->glink_entries_
.size();
2112 off_t total
= count
;
2119 this->pltresolve_
= total
;
2121 // space for branch table
2122 total
+= 4 * (count
- 1);
2124 total
+= -total
& 15;
2125 total
+= this->pltresolve_size
;
2130 this->pltresolve_
= total
;
2131 total
+= this->pltresolve_size
;
2133 // space for branch table
2136 total
+= 4 * (count
- 0x8000);
2140 this->set_data_size(total
);
2143 static inline uint32_t
2149 static inline uint32_t
2155 static inline uint32_t
2158 return hi(a
+ 0x8000);
2161 template<bool big_endian
>
2163 write_insn(unsigned char* p
, uint32_t v
)
2165 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
2168 // Write out .glink.
2170 template<int size
, bool big_endian
>
2172 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
2174 const off_t off
= this->offset();
2175 const section_size_type oview_size
=
2176 convert_to_section_size_type(this->data_size());
2177 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
2180 // The base address of the .plt section.
2181 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2182 static const Address invalid_address
= static_cast<Address
>(0) - 1;
2183 Address plt_base
= this->targ_
->plt_section()->address();
2184 Address iplt_base
= invalid_address
;
2186 const Output_data_got_powerpc
<size
, big_endian
>* got
2187 = this->targ_
->got_section();
2191 Address got_os_addr
= got
->output_section()->address();
2193 // Write out call stubs.
2194 typename
Glink_entries::const_iterator g
;
2195 for (g
= this->glink_entries_
.begin();
2196 g
!= this->glink_entries_
.end();
2201 const Symbol
* gsym
= g
->first
.sym_
;
2204 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2205 && gsym
->can_use_relative_reloc(false));
2206 plt_addr
= gsym
->plt_offset();
2211 const Sized_relobj_file
<size
, big_endian
>* relobj
2213 unsigned int local_sym_index
= g
->first
.locsym_
;
2214 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2218 if (iplt_base
== invalid_address
)
2219 iplt_base
= this->targ_
->iplt_section()->address();
2220 plt_addr
+= iplt_base
;
2223 plt_addr
+= plt_base
;
2224 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2225 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2226 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
2227 Address pltoff
= plt_addr
- got_addr
;
2229 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
2230 gold_error(_("%s: linkage table error against `%s'"),
2231 g
->first
.object_
->name().c_str(),
2232 g
->first
.sym_
->demangled_name().c_str());
2234 p
= oview
+ g
->second
* this->glink_entry_size();
2235 if (ha(pltoff
) != 0)
2237 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
2238 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2239 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
2240 if (ha(pltoff
+ 16) != ha(pltoff
))
2242 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
2245 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2246 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
2247 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
2248 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2252 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2253 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
2254 if (ha(pltoff
+ 16) != ha(pltoff
))
2256 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
2259 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2260 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
2261 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
2262 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2266 // Write pltresolve stub.
2267 p
= oview
+ this->pltresolve_
;
2268 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
2269 Address pltoff
= plt_base
- after_bcl
;
2271 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
2273 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
2274 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
2275 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
2276 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
2277 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
2278 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
2279 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
2280 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
2281 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2282 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
2283 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2284 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
2285 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2287 // Write lazy link call stubs.
2289 while (p
< oview
+ oview_size
)
2293 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
2297 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
2298 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
2300 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
2301 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
2307 // The address of _GLOBAL_OFFSET_TABLE_.
2308 Address g_o_t
= got
->address() + got
->g_o_t();
2310 // Write out call stubs.
2311 typename
Glink_entries::const_iterator g
;
2312 for (g
= this->glink_entries_
.begin();
2313 g
!= this->glink_entries_
.end();
2318 const Symbol
* gsym
= g
->first
.sym_
;
2321 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2322 && gsym
->can_use_relative_reloc(false));
2323 plt_addr
= gsym
->plt_offset();
2328 const Sized_relobj_file
<size
, big_endian
>* relobj
2330 unsigned int local_sym_index
= g
->first
.locsym_
;
2331 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2335 if (iplt_base
== invalid_address
)
2336 iplt_base
= this->targ_
->iplt_section()->address();
2337 plt_addr
+= iplt_base
;
2340 plt_addr
+= plt_base
;
2342 p
= oview
+ g
->second
* this->glink_entry_size();
2343 if (parameters
->options().output_is_position_independent())
2346 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
2347 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2348 if (object
!= NULL
&& g
->first
.addend_
>= 32768)
2350 unsigned int got2
= object
->got2_shndx();
2351 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
2352 gold_assert(got_addr
!= invalid_address
);
2353 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
2354 + g
->first
.addend_
);
2359 Address pltoff
= plt_addr
- got_addr
;
2360 if (ha(pltoff
) == 0)
2362 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
2363 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
2364 write_insn
<big_endian
>(p
+ 8, bctr
);
2368 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
2369 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
2370 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2371 write_insn
<big_endian
>(p
+ 12, bctr
);
2376 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
2377 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
2378 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2379 write_insn
<big_endian
>(p
+ 12, bctr
);
2383 // Write out pltresolve branch table.
2384 p
= oview
+ this->pltresolve_
;
2385 unsigned int the_end
= oview_size
- this->pltresolve_size
;
2386 unsigned char* end_p
= oview
+ the_end
;
2387 while (p
< end_p
- 8 * 4)
2388 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
2390 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2392 // Write out pltresolve call stub.
2393 if (parameters
->options().output_is_position_independent())
2395 Address res0_off
= this->pltresolve_
;
2396 Address after_bcl_off
= the_end
+ 12;
2397 Address bcl_res0
= after_bcl_off
- res0_off
;
2399 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2400 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2401 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2402 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2403 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2404 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2405 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2407 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2409 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2410 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2412 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2413 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2417 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2418 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2420 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2421 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2422 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2423 write_insn
<big_endian
>(p
+ 52, bctr
);
2424 write_insn
<big_endian
>(p
+ 56, nop
);
2425 write_insn
<big_endian
>(p
+ 60, nop
);
2429 Address res0
= this->pltresolve_
+ this->address();
2431 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2432 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2433 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2434 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2436 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2437 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2438 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2439 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2440 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2441 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2443 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2444 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2445 write_insn
<big_endian
>(p
+ 32, bctr
);
2446 write_insn
<big_endian
>(p
+ 36, nop
);
2447 write_insn
<big_endian
>(p
+ 40, nop
);
2448 write_insn
<big_endian
>(p
+ 44, nop
);
2449 write_insn
<big_endian
>(p
+ 48, nop
);
2450 write_insn
<big_endian
>(p
+ 52, nop
);
2451 write_insn
<big_endian
>(p
+ 56, nop
);
2452 write_insn
<big_endian
>(p
+ 60, nop
);
2457 of
->write_output_view(off
, oview_size
, oview
);
2461 // A class to handle linker generated save/restore functions.
2463 template<int size
, bool big_endian
>
2464 class Output_data_save_res
: public Output_section_data_build
2467 Output_data_save_res(Symbol_table
* symtab
);
2470 // Write to a map file.
2472 do_print_to_mapfile(Mapfile
* mapfile
) const
2473 { mapfile
->print_output_data(this, _("** save/restore")); }
2476 do_write(Output_file
*);
2479 // The maximum size of save/restore contents.
2480 static const unsigned int savres_max
= 218*4;
2483 savres_define(Symbol_table
* symtab
,
2485 unsigned int lo
, unsigned int hi
,
2486 unsigned char* write_ent(unsigned char*, int),
2487 unsigned char* write_tail(unsigned char*, int));
2489 unsigned char *contents_
;
2492 template<bool big_endian
>
2493 static unsigned char*
2494 savegpr0(unsigned char* p
, int r
)
2496 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2497 write_insn
<big_endian
>(p
, insn
);
2501 template<bool big_endian
>
2502 static unsigned char*
2503 savegpr0_tail(unsigned char* p
, int r
)
2505 p
= savegpr0
<big_endian
>(p
, r
);
2506 uint32_t insn
= std_0_1
+ 16;
2507 write_insn
<big_endian
>(p
, insn
);
2509 write_insn
<big_endian
>(p
, blr
);
2513 template<bool big_endian
>
2514 static unsigned char*
2515 restgpr0(unsigned char* p
, int r
)
2517 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2518 write_insn
<big_endian
>(p
, insn
);
2522 template<bool big_endian
>
2523 static unsigned char*
2524 restgpr0_tail(unsigned char* p
, int r
)
2526 uint32_t insn
= ld_0_1
+ 16;
2527 write_insn
<big_endian
>(p
, insn
);
2529 p
= restgpr0
<big_endian
>(p
, r
);
2530 write_insn
<big_endian
>(p
, mtlr_0
);
2534 p
= restgpr0
<big_endian
>(p
, 30);
2535 p
= restgpr0
<big_endian
>(p
, 31);
2537 write_insn
<big_endian
>(p
, blr
);
2541 template<bool big_endian
>
2542 static unsigned char*
2543 savegpr1(unsigned char* p
, int r
)
2545 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2546 write_insn
<big_endian
>(p
, insn
);
2550 template<bool big_endian
>
2551 static unsigned char*
2552 savegpr1_tail(unsigned char* p
, int r
)
2554 p
= savegpr1
<big_endian
>(p
, r
);
2555 write_insn
<big_endian
>(p
, blr
);
2559 template<bool big_endian
>
2560 static unsigned char*
2561 restgpr1(unsigned char* p
, int r
)
2563 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2564 write_insn
<big_endian
>(p
, insn
);
2568 template<bool big_endian
>
2569 static unsigned char*
2570 restgpr1_tail(unsigned char* p
, int r
)
2572 p
= restgpr1
<big_endian
>(p
, r
);
2573 write_insn
<big_endian
>(p
, blr
);
2577 template<bool big_endian
>
2578 static unsigned char*
2579 savefpr(unsigned char* p
, int r
)
2581 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2582 write_insn
<big_endian
>(p
, insn
);
2586 template<bool big_endian
>
2587 static unsigned char*
2588 savefpr0_tail(unsigned char* p
, int r
)
2590 p
= savefpr
<big_endian
>(p
, r
);
2591 write_insn
<big_endian
>(p
, std_0_1
+ 16);
2593 write_insn
<big_endian
>(p
, blr
);
2597 template<bool big_endian
>
2598 static unsigned char*
2599 restfpr(unsigned char* p
, int r
)
2601 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
2602 write_insn
<big_endian
>(p
, insn
);
2606 template<bool big_endian
>
2607 static unsigned char*
2608 restfpr0_tail(unsigned char* p
, int r
)
2610 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
2612 p
= restfpr
<big_endian
>(p
, r
);
2613 write_insn
<big_endian
>(p
, mtlr_0
);
2617 p
= restfpr
<big_endian
>(p
, 30);
2618 p
= restfpr
<big_endian
>(p
, 31);
2620 write_insn
<big_endian
>(p
, blr
);
2624 template<bool big_endian
>
2625 static unsigned char*
2626 savefpr1_tail(unsigned char* p
, int r
)
2628 p
= savefpr
<big_endian
>(p
, r
);
2629 write_insn
<big_endian
>(p
, blr
);
2633 template<bool big_endian
>
2634 static unsigned char*
2635 restfpr1_tail(unsigned char* p
, int r
)
2637 p
= restfpr
<big_endian
>(p
, r
);
2638 write_insn
<big_endian
>(p
, blr
);
2642 template<bool big_endian
>
2643 static unsigned char*
2644 savevr(unsigned char* p
, int r
)
2646 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
2647 write_insn
<big_endian
>(p
, insn
);
2649 insn
= stvx_0_12_0
+ (r
<< 21);
2650 write_insn
<big_endian
>(p
, insn
);
2654 template<bool big_endian
>
2655 static unsigned char*
2656 savevr_tail(unsigned char* p
, int r
)
2658 p
= savevr
<big_endian
>(p
, r
);
2659 write_insn
<big_endian
>(p
, blr
);
2663 template<bool big_endian
>
2664 static unsigned char*
2665 restvr(unsigned char* p
, int r
)
2667 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
2668 write_insn
<big_endian
>(p
, insn
);
2670 insn
= lvx_0_12_0
+ (r
<< 21);
2671 write_insn
<big_endian
>(p
, insn
);
2675 template<bool big_endian
>
2676 static unsigned char*
2677 restvr_tail(unsigned char* p
, int r
)
2679 p
= restvr
<big_endian
>(p
, r
);
2680 write_insn
<big_endian
>(p
, blr
);
2685 template<int size
, bool big_endian
>
2686 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
2687 Symbol_table
* symtab
)
2688 : Output_section_data_build(4),
2691 this->savres_define(symtab
,
2692 "_savegpr0_", 14, 31,
2693 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
2694 this->savres_define(symtab
,
2695 "_restgpr0_", 14, 29,
2696 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
2697 this->savres_define(symtab
,
2698 "_restgpr0_", 30, 31,
2699 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
2700 this->savres_define(symtab
,
2701 "_savegpr1_", 14, 31,
2702 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
2703 this->savres_define(symtab
,
2704 "_restgpr1_", 14, 31,
2705 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
2706 this->savres_define(symtab
,
2707 "_savefpr_", 14, 31,
2708 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
2709 this->savres_define(symtab
,
2710 "_restfpr_", 14, 29,
2711 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
2712 this->savres_define(symtab
,
2713 "_restfpr_", 30, 31,
2714 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
2715 this->savres_define(symtab
,
2717 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
2718 this->savres_define(symtab
,
2720 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
2721 this->savres_define(symtab
,
2723 savevr
<big_endian
>, savevr_tail
<big_endian
>);
2724 this->savres_define(symtab
,
2726 restvr
<big_endian
>, restvr_tail
<big_endian
>);
2729 template<int size
, bool big_endian
>
2731 Output_data_save_res
<size
, big_endian
>::savres_define(
2732 Symbol_table
* symtab
,
2734 unsigned int lo
, unsigned int hi
,
2735 unsigned char* write_ent(unsigned char*, int),
2736 unsigned char* write_tail(unsigned char*, int))
2738 size_t len
= strlen(name
);
2739 bool writing
= false;
2742 memcpy(sym
, name
, len
);
2745 for (unsigned int i
= lo
; i
<= hi
; i
++)
2747 sym
[len
+ 0] = i
/ 10 + '0';
2748 sym
[len
+ 1] = i
% 10 + '0';
2749 Symbol
* gsym
= symtab
->lookup(sym
);
2750 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
2751 writing
= writing
|| refd
;
2754 if (this->contents_
== NULL
)
2755 this->contents_
= new unsigned char[this->savres_max
];
2757 off_t value
= this->current_data_size();
2758 unsigned char* p
= this->contents_
+ value
;
2760 p
= write_ent(p
, i
);
2762 p
= write_tail(p
, i
);
2763 off_t cur_size
= p
- this->contents_
;
2764 this->set_current_data_size(cur_size
);
2766 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
2767 this, value
, cur_size
- value
,
2768 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
2769 elfcpp::STV_HIDDEN
, 0, false, false);
2774 // Write out save/restore.
2776 template<int size
, bool big_endian
>
2778 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
2780 const off_t off
= this->offset();
2781 const section_size_type oview_size
=
2782 convert_to_section_size_type(this->data_size());
2783 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
2784 memcpy(oview
, this->contents_
, oview_size
);
2785 of
->write_output_view(off
, oview_size
, oview
);
2789 // Create the glink section.
2791 template<int size
, bool big_endian
>
2793 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2795 if (this->glink_
== NULL
)
2797 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2798 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2799 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2800 this->glink_
, ORDER_TEXT
, false);
2804 // Create a PLT entry for a global symbol.
2806 template<int size
, bool big_endian
>
2808 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2811 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2812 const Sized_relobj_file
<size
, big_endian
>* object
)
2814 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
2815 && gsym
->can_use_relative_reloc(false))
2817 if (this->iplt_
== NULL
)
2818 this->make_iplt_section(layout
);
2819 this->iplt_
->add_ifunc_entry(gsym
);
2823 if (this->plt_
== NULL
)
2824 this->make_plt_section(layout
);
2825 this->plt_
->add_entry(gsym
);
2827 this->glink_
->add_entry(object
, gsym
, reloc
);
2830 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
2832 template<int size
, bool big_endian
>
2834 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
2836 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2837 Sized_relobj_file
<size
, big_endian
>* relobj
)
2839 if (this->iplt_
== NULL
)
2840 this->make_iplt_section(layout
);
2841 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2842 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
2843 this->glink_
->add_entry(relobj
, r_sym
, reloc
);
2846 // Return the number of entries in the PLT.
2848 template<int size
, bool big_endian
>
2850 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2852 if (this->plt_
== NULL
)
2854 unsigned int count
= this->plt_
->entry_count();
2855 if (this->iplt_
!= NULL
)
2856 count
+= this->iplt_
->entry_count();
2860 // Return the offset of the first non-reserved PLT entry.
2862 template<int size
, bool big_endian
>
2864 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2866 return this->plt_
->first_plt_entry_offset();
2869 // Return the size of each PLT entry.
2871 template<int size
, bool big_endian
>
2873 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2875 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2878 // Create a GOT entry for local dynamic __tls_get_addr calls.
2880 template<int size
, bool big_endian
>
2882 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2883 Symbol_table
* symtab
,
2885 Sized_relobj_file
<size
, big_endian
>* object
)
2887 if (this->tlsld_got_offset_
== -1U)
2889 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2890 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2891 Output_data_got_powerpc
<size
, big_endian
>* got
2892 = this->got_section(symtab
, layout
);
2893 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2894 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2896 this->tlsld_got_offset_
= got_offset
;
2898 return this->tlsld_got_offset_
;
2901 // Get the Reference_flags for a particular relocation.
2903 template<int size
, bool big_endian
>
2905 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2909 case elfcpp::R_POWERPC_NONE
:
2910 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2911 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2912 case elfcpp::R_PPC64_TOC
:
2913 // No symbol reference.
2916 case elfcpp::R_PPC64_ADDR64
:
2917 case elfcpp::R_PPC64_UADDR64
:
2918 case elfcpp::R_POWERPC_ADDR32
:
2919 case elfcpp::R_POWERPC_UADDR32
:
2920 case elfcpp::R_POWERPC_ADDR16
:
2921 case elfcpp::R_POWERPC_UADDR16
:
2922 case elfcpp::R_POWERPC_ADDR16_LO
:
2923 case elfcpp::R_POWERPC_ADDR16_HI
:
2924 case elfcpp::R_POWERPC_ADDR16_HA
:
2925 return Symbol::ABSOLUTE_REF
;
2927 case elfcpp::R_POWERPC_ADDR24
:
2928 case elfcpp::R_POWERPC_ADDR14
:
2929 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2930 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2931 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2933 case elfcpp::R_PPC64_REL64
:
2934 case elfcpp::R_POWERPC_REL32
:
2935 case elfcpp::R_PPC_LOCAL24PC
:
2936 case elfcpp::R_POWERPC_REL16
:
2937 case elfcpp::R_POWERPC_REL16_LO
:
2938 case elfcpp::R_POWERPC_REL16_HI
:
2939 case elfcpp::R_POWERPC_REL16_HA
:
2940 return Symbol::RELATIVE_REF
;
2942 case elfcpp::R_POWERPC_REL24
:
2943 case elfcpp::R_PPC_PLTREL24
:
2944 case elfcpp::R_POWERPC_REL14
:
2945 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2946 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2947 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2949 case elfcpp::R_POWERPC_GOT16
:
2950 case elfcpp::R_POWERPC_GOT16_LO
:
2951 case elfcpp::R_POWERPC_GOT16_HI
:
2952 case elfcpp::R_POWERPC_GOT16_HA
:
2953 case elfcpp::R_PPC64_GOT16_DS
:
2954 case elfcpp::R_PPC64_GOT16_LO_DS
:
2955 case elfcpp::R_PPC64_TOC16
:
2956 case elfcpp::R_PPC64_TOC16_LO
:
2957 case elfcpp::R_PPC64_TOC16_HI
:
2958 case elfcpp::R_PPC64_TOC16_HA
:
2959 case elfcpp::R_PPC64_TOC16_DS
:
2960 case elfcpp::R_PPC64_TOC16_LO_DS
:
2962 return Symbol::ABSOLUTE_REF
;
2964 case elfcpp::R_POWERPC_GOT_TPREL16
:
2965 case elfcpp::R_POWERPC_TLS
:
2966 return Symbol::TLS_REF
;
2968 case elfcpp::R_POWERPC_COPY
:
2969 case elfcpp::R_POWERPC_GLOB_DAT
:
2970 case elfcpp::R_POWERPC_JMP_SLOT
:
2971 case elfcpp::R_POWERPC_RELATIVE
:
2972 case elfcpp::R_POWERPC_DTPMOD
:
2974 // Not expected. We will give an error later.
2979 // Report an unsupported relocation against a local symbol.
2981 template<int size
, bool big_endian
>
2983 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2984 Sized_relobj_file
<size
, big_endian
>* object
,
2985 unsigned int r_type
)
2987 gold_error(_("%s: unsupported reloc %u against local symbol"),
2988 object
->name().c_str(), r_type
);
2991 // We are about to emit a dynamic relocation of type R_TYPE. If the
2992 // dynamic linker does not support it, issue an error.
2994 template<int size
, bool big_endian
>
2996 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2997 unsigned int r_type
)
2999 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
3001 // These are the relocation types supported by glibc for both 32-bit
3002 // and 64-bit powerpc.
3005 case elfcpp::R_POWERPC_NONE
:
3006 case elfcpp::R_POWERPC_RELATIVE
:
3007 case elfcpp::R_POWERPC_GLOB_DAT
:
3008 case elfcpp::R_POWERPC_DTPMOD
:
3009 case elfcpp::R_POWERPC_DTPREL
:
3010 case elfcpp::R_POWERPC_TPREL
:
3011 case elfcpp::R_POWERPC_JMP_SLOT
:
3012 case elfcpp::R_POWERPC_COPY
:
3013 case elfcpp::R_POWERPC_IRELATIVE
:
3014 case elfcpp::R_POWERPC_ADDR32
:
3015 case elfcpp::R_POWERPC_UADDR32
:
3016 case elfcpp::R_POWERPC_ADDR24
:
3017 case elfcpp::R_POWERPC_ADDR16
:
3018 case elfcpp::R_POWERPC_UADDR16
:
3019 case elfcpp::R_POWERPC_ADDR16_LO
:
3020 case elfcpp::R_POWERPC_ADDR16_HI
:
3021 case elfcpp::R_POWERPC_ADDR16_HA
:
3022 case elfcpp::R_POWERPC_ADDR14
:
3023 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3024 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3025 case elfcpp::R_POWERPC_REL32
:
3026 case elfcpp::R_POWERPC_REL24
:
3027 case elfcpp::R_POWERPC_TPREL16
:
3028 case elfcpp::R_POWERPC_TPREL16_LO
:
3029 case elfcpp::R_POWERPC_TPREL16_HI
:
3030 case elfcpp::R_POWERPC_TPREL16_HA
:
3041 // These are the relocation types supported only on 64-bit.
3042 case elfcpp::R_PPC64_ADDR64
:
3043 case elfcpp::R_PPC64_UADDR64
:
3044 case elfcpp::R_PPC64_JMP_IREL
:
3045 case elfcpp::R_PPC64_ADDR16_DS
:
3046 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3047 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3048 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3049 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3050 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3051 case elfcpp::R_PPC64_REL64
:
3052 case elfcpp::R_POWERPC_ADDR30
:
3053 case elfcpp::R_PPC64_TPREL16_DS
:
3054 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3055 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3056 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3057 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3058 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3069 // These are the relocation types supported only on 32-bit.
3070 // ??? glibc ld.so doesn't need to support these.
3071 case elfcpp::R_POWERPC_DTPREL16
:
3072 case elfcpp::R_POWERPC_DTPREL16_LO
:
3073 case elfcpp::R_POWERPC_DTPREL16_HI
:
3074 case elfcpp::R_POWERPC_DTPREL16_HA
:
3082 // This prevents us from issuing more than one error per reloc
3083 // section. But we can still wind up issuing more than one
3084 // error per object file.
3085 if (this->issued_non_pic_error_
)
3087 gold_assert(parameters
->options().output_is_position_independent());
3088 object
->error(_("requires unsupported dynamic reloc; "
3089 "recompile with -fPIC"));
3090 this->issued_non_pic_error_
= true;
3094 // Return whether we need to make a PLT entry for a relocation of the
3095 // given type against a STT_GNU_IFUNC symbol.
3097 template<int size
, bool big_endian
>
3099 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
3100 Sized_relobj_file
<size
, big_endian
>* object
,
3101 unsigned int r_type
)
3103 // In non-pic code any reference will resolve to the plt call stub
3104 // for the ifunc symbol.
3105 if (size
== 32 && !parameters
->options().output_is_position_independent())
3110 // Word size refs from data sections are OK.
3111 case elfcpp::R_POWERPC_ADDR32
:
3112 case elfcpp::R_POWERPC_UADDR32
:
3117 case elfcpp::R_PPC64_ADDR64
:
3118 case elfcpp::R_PPC64_UADDR64
:
3123 // GOT refs are good.
3124 case elfcpp::R_POWERPC_GOT16
:
3125 case elfcpp::R_POWERPC_GOT16_LO
:
3126 case elfcpp::R_POWERPC_GOT16_HI
:
3127 case elfcpp::R_POWERPC_GOT16_HA
:
3128 case elfcpp::R_PPC64_GOT16_DS
:
3129 case elfcpp::R_PPC64_GOT16_LO_DS
:
3132 // So are function calls.
3133 case elfcpp::R_POWERPC_ADDR24
:
3134 case elfcpp::R_POWERPC_ADDR14
:
3135 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3136 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3137 case elfcpp::R_POWERPC_REL24
:
3138 case elfcpp::R_PPC_PLTREL24
:
3139 case elfcpp::R_POWERPC_REL14
:
3140 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3141 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3148 // Anything else is a problem.
3149 // If we are building a static executable, the libc startup function
3150 // responsible for applying indirect function relocations is going
3151 // to complain about the reloc type.
3152 // If we are building a dynamic executable, we will have a text
3153 // relocation. The dynamic loader will set the text segment
3154 // writable and non-executable to apply text relocations. So we'll
3155 // segfault when trying to run the indirection function to resolve
3157 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
3158 object
->name().c_str(), r_type
);
3162 // Scan a relocation for a local symbol.
3164 template<int size
, bool big_endian
>
3166 Target_powerpc
<size
, big_endian
>::Scan::local(
3167 Symbol_table
* symtab
,
3169 Target_powerpc
<size
, big_endian
>* target
,
3170 Sized_relobj_file
<size
, big_endian
>* object
,
3171 unsigned int data_shndx
,
3172 Output_section
* output_section
,
3173 const elfcpp::Rela
<size
, big_endian
>& reloc
,
3174 unsigned int r_type
,
3175 const elfcpp::Sym
<size
, big_endian
>& lsym
,
3178 Powerpc_relobj
<size
, big_endian
>* ppc_object
3179 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3184 && data_shndx
== ppc_object
->opd_shndx()
3185 && r_type
== elfcpp::R_PPC64_ADDR64
)
3186 ppc_object
->set_opd_discard(reloc
.get_r_offset());
3190 // A local STT_GNU_IFUNC symbol may require a PLT entry.
3191 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
3192 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
3193 target
->make_local_ifunc_plt_entry(layout
, reloc
, object
);
3197 case elfcpp::R_POWERPC_NONE
:
3198 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3199 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3200 case elfcpp::R_PPC64_TOCSAVE
:
3201 case elfcpp::R_PPC_EMB_MRKREF
:
3202 case elfcpp::R_POWERPC_TLS
:
3205 case elfcpp::R_PPC64_TOC
:
3207 Output_data_got_powerpc
<size
, big_endian
>* got
3208 = target
->got_section(symtab
, layout
);
3209 if (parameters
->options().output_is_position_independent())
3211 Address off
= reloc
.get_r_offset();
3213 && data_shndx
== ppc_object
->opd_shndx()
3214 && ppc_object
->get_opd_discard(off
- 8))
3217 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3218 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
3219 rela_dyn
->add_output_section_relative(got
->output_section(),
3220 elfcpp::R_POWERPC_RELATIVE
,
3222 object
, data_shndx
, off
,
3223 symobj
->toc_base_offset());
3228 case elfcpp::R_PPC64_ADDR64
:
3229 case elfcpp::R_PPC64_UADDR64
:
3230 case elfcpp::R_POWERPC_ADDR32
:
3231 case elfcpp::R_POWERPC_UADDR32
:
3232 case elfcpp::R_POWERPC_ADDR24
:
3233 case elfcpp::R_POWERPC_ADDR16
:
3234 case elfcpp::R_POWERPC_ADDR16_LO
:
3235 case elfcpp::R_POWERPC_ADDR16_HI
:
3236 case elfcpp::R_POWERPC_ADDR16_HA
:
3237 case elfcpp::R_POWERPC_UADDR16
:
3238 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3239 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3240 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3241 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3242 case elfcpp::R_PPC64_ADDR16_DS
:
3243 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3244 case elfcpp::R_POWERPC_ADDR14
:
3245 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3246 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3247 // If building a shared library (or a position-independent
3248 // executable), we need to create a dynamic relocation for
3250 if (parameters
->options().output_is_position_independent()
3251 || (size
== 64 && is_ifunc
))
3253 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3255 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
3256 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
3258 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3259 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3262 rela_dyn
= target
->iplt_section()->rel_plt();
3263 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3265 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
3266 output_section
, data_shndx
,
3267 reloc
.get_r_offset(),
3268 reloc
.get_r_addend(), false);
3272 check_non_pic(object
, r_type
);
3273 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3274 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
3275 data_shndx
, reloc
.get_r_offset(),
3276 reloc
.get_r_addend());
3281 case elfcpp::R_PPC64_REL64
:
3282 case elfcpp::R_POWERPC_REL32
:
3283 case elfcpp::R_POWERPC_REL24
:
3284 case elfcpp::R_PPC_PLTREL24
:
3285 case elfcpp::R_PPC_LOCAL24PC
:
3286 case elfcpp::R_POWERPC_REL16
:
3287 case elfcpp::R_POWERPC_REL16_LO
:
3288 case elfcpp::R_POWERPC_REL16_HI
:
3289 case elfcpp::R_POWERPC_REL16_HA
:
3290 case elfcpp::R_POWERPC_REL14
:
3291 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3292 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3293 case elfcpp::R_POWERPC_SECTOFF
:
3294 case elfcpp::R_POWERPC_TPREL16
:
3295 case elfcpp::R_POWERPC_DTPREL16
:
3296 case elfcpp::R_POWERPC_SECTOFF_LO
:
3297 case elfcpp::R_POWERPC_TPREL16_LO
:
3298 case elfcpp::R_POWERPC_DTPREL16_LO
:
3299 case elfcpp::R_POWERPC_SECTOFF_HI
:
3300 case elfcpp::R_POWERPC_TPREL16_HI
:
3301 case elfcpp::R_POWERPC_DTPREL16_HI
:
3302 case elfcpp::R_POWERPC_SECTOFF_HA
:
3303 case elfcpp::R_POWERPC_TPREL16_HA
:
3304 case elfcpp::R_POWERPC_DTPREL16_HA
:
3305 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3306 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3307 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3308 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3309 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3310 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3311 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3312 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3313 case elfcpp::R_PPC64_TPREL16_DS
:
3314 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3315 case elfcpp::R_PPC64_DTPREL16_DS
:
3316 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3317 case elfcpp::R_PPC64_SECTOFF_DS
:
3318 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3319 case elfcpp::R_PPC64_TLSGD
:
3320 case elfcpp::R_PPC64_TLSLD
:
3323 case elfcpp::R_POWERPC_GOT16
:
3324 case elfcpp::R_POWERPC_GOT16_LO
:
3325 case elfcpp::R_POWERPC_GOT16_HI
:
3326 case elfcpp::R_POWERPC_GOT16_HA
:
3327 case elfcpp::R_PPC64_GOT16_DS
:
3328 case elfcpp::R_PPC64_GOT16_LO_DS
:
3330 // The symbol requires a GOT entry.
3331 Output_data_got_powerpc
<size
, big_endian
>* got
3332 = target
->got_section(symtab
, layout
);
3333 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3335 if (!parameters
->options().output_is_position_independent())
3337 if (size
== 32 && is_ifunc
)
3338 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
3340 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
3342 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
3344 // If we are generating a shared object or a pie, this
3345 // symbol's GOT entry will be set by a dynamic relocation.
3347 off
= got
->add_constant(0);
3348 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
3350 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3351 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3354 rela_dyn
= target
->iplt_section()->rel_plt();
3355 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3357 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
3358 got
, off
, 0, false);
3363 case elfcpp::R_PPC64_TOC16
:
3364 case elfcpp::R_PPC64_TOC16_LO
:
3365 case elfcpp::R_PPC64_TOC16_HI
:
3366 case elfcpp::R_PPC64_TOC16_HA
:
3367 case elfcpp::R_PPC64_TOC16_DS
:
3368 case elfcpp::R_PPC64_TOC16_LO_DS
:
3369 // We need a GOT section.
3370 target
->got_section(symtab
, layout
);
3373 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3374 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3375 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3376 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3378 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
3379 if (tls_type
== tls::TLSOPT_NONE
)
3381 Output_data_got_powerpc
<size
, big_endian
>* got
3382 = target
->got_section(symtab
, layout
);
3383 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3384 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3385 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
3386 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
3388 else if (tls_type
== tls::TLSOPT_TO_LE
)
3390 // no GOT relocs needed for Local Exec.
3397 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3398 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3399 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3400 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3402 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3403 if (tls_type
== tls::TLSOPT_NONE
)
3404 target
->tlsld_got_offset(symtab
, layout
, object
);
3405 else if (tls_type
== tls::TLSOPT_TO_LE
)
3407 // no GOT relocs needed for Local Exec.
3408 if (parameters
->options().emit_relocs())
3410 Output_section
* os
= layout
->tls_segment()->first_section();
3411 gold_assert(os
!= NULL
);
3412 os
->set_needs_symtab_index();
3420 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3421 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3422 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3423 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3425 Output_data_got_powerpc
<size
, big_endian
>* got
3426 = target
->got_section(symtab
, layout
);
3427 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3428 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
3432 case elfcpp::R_POWERPC_GOT_TPREL16
:
3433 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3434 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3435 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3437 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
3438 if (tls_type
== tls::TLSOPT_NONE
)
3440 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3441 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
3443 Output_data_got_powerpc
<size
, big_endian
>* got
3444 = target
->got_section(symtab
, layout
);
3445 unsigned int off
= got
->add_constant(0);
3446 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
3448 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3449 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
3450 elfcpp::R_POWERPC_TPREL
,
3454 else if (tls_type
== tls::TLSOPT_TO_LE
)
3456 // no GOT relocs needed for Local Exec.
3464 unsupported_reloc_local(object
, r_type
);
3469 // Report an unsupported relocation against a global symbol.
3471 template<int size
, bool big_endian
>
3473 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
3474 Sized_relobj_file
<size
, big_endian
>* object
,
3475 unsigned int r_type
,
3478 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3479 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3482 // Scan a relocation for a global symbol.
3484 template<int size
, bool big_endian
>
3486 Target_powerpc
<size
, big_endian
>::Scan::global(
3487 Symbol_table
* symtab
,
3489 Target_powerpc
<size
, big_endian
>* target
,
3490 Sized_relobj_file
<size
, big_endian
>* object
,
3491 unsigned int data_shndx
,
3492 Output_section
* output_section
,
3493 const elfcpp::Rela
<size
, big_endian
>& reloc
,
3494 unsigned int r_type
,
3497 Powerpc_relobj
<size
, big_endian
>* ppc_object
3498 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3500 // A STT_GNU_IFUNC symbol may require a PLT entry.
3501 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
3502 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
3503 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3507 case elfcpp::R_POWERPC_NONE
:
3508 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3509 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3510 case elfcpp::R_PPC_LOCAL24PC
:
3511 case elfcpp::R_PPC_EMB_MRKREF
:
3512 case elfcpp::R_POWERPC_TLS
:
3515 case elfcpp::R_PPC64_TOC
:
3517 Output_data_got_powerpc
<size
, big_endian
>* got
3518 = target
->got_section(symtab
, layout
);
3519 if (parameters
->options().output_is_position_independent())
3521 Address off
= reloc
.get_r_offset();
3523 && data_shndx
== ppc_object
->opd_shndx()
3524 && ppc_object
->get_opd_discard(off
- 8))
3527 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3528 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
3529 if (data_shndx
!= ppc_object
->opd_shndx())
3530 symobj
= static_cast
3531 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3532 rela_dyn
->add_output_section_relative(got
->output_section(),
3533 elfcpp::R_POWERPC_RELATIVE
,
3535 object
, data_shndx
, off
,
3536 symobj
->toc_base_offset());
3541 case elfcpp::R_PPC64_ADDR64
:
3543 && data_shndx
== ppc_object
->opd_shndx()
3544 && (gsym
->is_defined_in_discarded_section()
3545 || gsym
->object() != object
))
3547 ppc_object
->set_opd_discard(reloc
.get_r_offset());
3551 case elfcpp::R_PPC64_UADDR64
:
3552 case elfcpp::R_POWERPC_ADDR32
:
3553 case elfcpp::R_POWERPC_UADDR32
:
3554 case elfcpp::R_POWERPC_ADDR24
:
3555 case elfcpp::R_POWERPC_ADDR16
:
3556 case elfcpp::R_POWERPC_ADDR16_LO
:
3557 case elfcpp::R_POWERPC_ADDR16_HI
:
3558 case elfcpp::R_POWERPC_ADDR16_HA
:
3559 case elfcpp::R_POWERPC_UADDR16
:
3560 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3561 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3562 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3563 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3564 case elfcpp::R_PPC64_ADDR16_DS
:
3565 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3566 case elfcpp::R_POWERPC_ADDR14
:
3567 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3568 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3570 // Make a PLT entry if necessary.
3571 if (gsym
->needs_plt_entry())
3573 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
3574 // Since this is not a PC-relative relocation, we may be
3575 // taking the address of a function. In that case we need to
3576 // set the entry in the dynamic symbol table to the address of
3577 // the PLT call stub.
3579 && gsym
->is_from_dynobj()
3580 && !parameters
->options().output_is_position_independent())
3581 gsym
->set_needs_dynsym_value();
3583 // Make a dynamic relocation if necessary.
3584 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
))
3585 || (size
== 64 && gsym
->type() == elfcpp::STT_GNU_IFUNC
))
3587 if (gsym
->may_need_copy_reloc())
3589 target
->copy_reloc(symtab
, layout
, object
,
3590 data_shndx
, output_section
, gsym
, reloc
);
3592 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
3593 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
3594 && (gsym
->can_use_relative_reloc(false)
3596 && data_shndx
== ppc_object
->opd_shndx())))
3598 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3599 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3600 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3602 rela_dyn
= target
->iplt_section()->rel_plt();
3603 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3605 rela_dyn
->add_symbolless_global_addend(
3606 gsym
, dynrel
, output_section
, object
, data_shndx
,
3607 reloc
.get_r_offset(), reloc
.get_r_addend());
3611 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3612 check_non_pic(object
, r_type
);
3613 rela_dyn
->add_global(gsym
, r_type
, output_section
,
3615 reloc
.get_r_offset(),
3616 reloc
.get_r_addend());
3622 case elfcpp::R_PPC_PLTREL24
:
3623 case elfcpp::R_POWERPC_REL24
:
3624 if (gsym
->needs_plt_entry()
3625 || (!gsym
->final_value_is_known()
3626 && (gsym
->is_undefined()
3627 || gsym
->is_from_dynobj()
3628 || gsym
->is_preemptible())))
3629 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3632 case elfcpp::R_PPC64_REL64
:
3633 case elfcpp::R_POWERPC_REL32
:
3634 // Make a dynamic relocation if necessary.
3635 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3637 if (gsym
->may_need_copy_reloc())
3639 target
->copy_reloc(symtab
, layout
, object
,
3640 data_shndx
, output_section
, gsym
,
3645 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3646 check_non_pic(object
, r_type
);
3647 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
3648 data_shndx
, reloc
.get_r_offset(),
3649 reloc
.get_r_addend());
3654 case elfcpp::R_POWERPC_REL16
:
3655 case elfcpp::R_POWERPC_REL16_LO
:
3656 case elfcpp::R_POWERPC_REL16_HI
:
3657 case elfcpp::R_POWERPC_REL16_HA
:
3658 case elfcpp::R_POWERPC_REL14
:
3659 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3660 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3661 case elfcpp::R_POWERPC_SECTOFF
:
3662 case elfcpp::R_POWERPC_TPREL16
:
3663 case elfcpp::R_POWERPC_DTPREL16
:
3664 case elfcpp::R_POWERPC_SECTOFF_LO
:
3665 case elfcpp::R_POWERPC_TPREL16_LO
:
3666 case elfcpp::R_POWERPC_DTPREL16_LO
:
3667 case elfcpp::R_POWERPC_SECTOFF_HI
:
3668 case elfcpp::R_POWERPC_TPREL16_HI
:
3669 case elfcpp::R_POWERPC_DTPREL16_HI
:
3670 case elfcpp::R_POWERPC_SECTOFF_HA
:
3671 case elfcpp::R_POWERPC_TPREL16_HA
:
3672 case elfcpp::R_POWERPC_DTPREL16_HA
:
3673 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3674 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3675 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3676 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3677 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3678 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3679 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3680 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3681 case elfcpp::R_PPC64_TPREL16_DS
:
3682 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3683 case elfcpp::R_PPC64_DTPREL16_DS
:
3684 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3685 case elfcpp::R_PPC64_SECTOFF_DS
:
3686 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3687 case elfcpp::R_PPC64_TLSGD
:
3688 case elfcpp::R_PPC64_TLSLD
:
3691 case elfcpp::R_POWERPC_GOT16
:
3692 case elfcpp::R_POWERPC_GOT16_LO
:
3693 case elfcpp::R_POWERPC_GOT16_HI
:
3694 case elfcpp::R_POWERPC_GOT16_HA
:
3695 case elfcpp::R_PPC64_GOT16_DS
:
3696 case elfcpp::R_PPC64_GOT16_LO_DS
:
3698 // The symbol requires a GOT entry.
3699 Output_data_got_powerpc
<size
, big_endian
>* got
;
3701 got
= target
->got_section(symtab
, layout
);
3702 if (gsym
->final_value_is_known())
3704 if (size
== 32 && gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3705 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
3707 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
3709 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
3711 // If we are generating a shared object or a pie, this
3712 // symbol's GOT entry will be set by a dynamic relocation.
3713 unsigned int off
= got
->add_constant(0);
3714 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
3716 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3717 if (gsym
->can_use_relative_reloc(false)
3719 && gsym
->visibility() == elfcpp::STV_PROTECTED
3720 && parameters
->options().shared()))
3722 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3723 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3725 rela_dyn
= target
->iplt_section()->rel_plt();
3726 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3728 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
3732 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
3733 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
3739 case elfcpp::R_PPC64_TOC16
:
3740 case elfcpp::R_PPC64_TOC16_LO
:
3741 case elfcpp::R_PPC64_TOC16_HI
:
3742 case elfcpp::R_PPC64_TOC16_HA
:
3743 case elfcpp::R_PPC64_TOC16_DS
:
3744 case elfcpp::R_PPC64_TOC16_LO_DS
:
3745 // We need a GOT section.
3746 target
->got_section(symtab
, layout
);
3749 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3750 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3751 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3752 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3754 const bool final
= gsym
->final_value_is_known();
3755 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3756 if (tls_type
== tls::TLSOPT_NONE
)
3758 Output_data_got_powerpc
<size
, big_endian
>* got
3759 = target
->got_section(symtab
, layout
);
3760 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
3761 target
->rela_dyn_section(layout
),
3762 elfcpp::R_POWERPC_DTPMOD
,
3763 elfcpp::R_POWERPC_DTPREL
);
3765 else if (tls_type
== tls::TLSOPT_TO_IE
)
3767 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
3769 Output_data_got_powerpc
<size
, big_endian
>* got
3770 = target
->got_section(symtab
, layout
);
3771 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3772 if (gsym
->is_undefined()
3773 || gsym
->is_from_dynobj())
3775 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
3776 elfcpp::R_POWERPC_TPREL
);
3780 unsigned int off
= got
->add_constant(0);
3781 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
3782 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
3783 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
3788 else if (tls_type
== tls::TLSOPT_TO_LE
)
3790 // no GOT relocs needed for Local Exec.
3797 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3798 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3799 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3800 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3802 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3803 if (tls_type
== tls::TLSOPT_NONE
)
3804 target
->tlsld_got_offset(symtab
, layout
, object
);
3805 else if (tls_type
== tls::TLSOPT_TO_LE
)
3807 // no GOT relocs needed for Local Exec.
3808 if (parameters
->options().emit_relocs())
3810 Output_section
* os
= layout
->tls_segment()->first_section();
3811 gold_assert(os
!= NULL
);
3812 os
->set_needs_symtab_index();
3820 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3821 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3822 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3823 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3825 Output_data_got_powerpc
<size
, big_endian
>* got
3826 = target
->got_section(symtab
, layout
);
3827 if (!gsym
->final_value_is_known()
3828 && (gsym
->is_from_dynobj()
3829 || gsym
->is_undefined()
3830 || gsym
->is_preemptible()))
3831 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
3832 target
->rela_dyn_section(layout
),
3833 elfcpp::R_POWERPC_DTPREL
);
3835 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
3839 case elfcpp::R_POWERPC_GOT_TPREL16
:
3840 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3841 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3842 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3844 const bool final
= gsym
->final_value_is_known();
3845 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3846 if (tls_type
== tls::TLSOPT_NONE
)
3848 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
3850 Output_data_got_powerpc
<size
, big_endian
>* got
3851 = target
->got_section(symtab
, layout
);
3852 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3853 if (gsym
->is_undefined()
3854 || gsym
->is_from_dynobj())
3856 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
3857 elfcpp::R_POWERPC_TPREL
);
3861 unsigned int off
= got
->add_constant(0);
3862 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
3863 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
3864 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
3869 else if (tls_type
== tls::TLSOPT_TO_LE
)
3871 // no GOT relocs needed for Local Exec.
3879 unsupported_reloc_global(object
, r_type
, gsym
);
3884 // Process relocations for gc.
3886 template<int size
, bool big_endian
>
3888 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
3889 Symbol_table
* symtab
,
3891 Sized_relobj_file
<size
, big_endian
>* object
,
3892 unsigned int data_shndx
,
3894 const unsigned char* prelocs
,
3896 Output_section
* output_section
,
3897 bool needs_special_offset_handling
,
3898 size_t local_symbol_count
,
3899 const unsigned char* plocal_symbols
)
3901 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3902 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3903 Powerpc_relobj
<size
, big_endian
>* ppc_object
3904 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3906 ppc_object
->set_opd_valid();
3907 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
3909 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
3910 for (p
= ppc_object
->access_from_map()->begin();
3911 p
!= ppc_object
->access_from_map()->end();
3914 Address dst_off
= p
->first
;
3915 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3916 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
3917 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
3919 Object
* src_obj
= s
->first
;
3920 unsigned int src_indx
= s
->second
;
3921 symtab
->gc()->add_reference(src_obj
, src_indx
,
3922 ppc_object
, dst_indx
);
3926 ppc_object
->access_from_map()->clear();
3927 ppc_object
->process_gc_mark(symtab
);
3928 // Don't look at .opd relocs as .opd will reference everything.
3932 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3933 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3942 needs_special_offset_handling
,
3947 // Handle target specific gc actions when adding a gc reference from
3948 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3949 // and DST_OFF. For powerpc64, this adds a referenc to the code
3950 // section of a function descriptor.
3952 template<int size
, bool big_endian
>
3954 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3955 Symbol_table
* symtab
,
3957 unsigned int src_shndx
,
3959 unsigned int dst_shndx
,
3960 Address dst_off
) const
3962 Powerpc_relobj
<size
, big_endian
>* ppc_object
3963 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3965 && !ppc_object
->is_dynamic()
3966 && dst_shndx
== ppc_object
->opd_shndx())
3968 if (ppc_object
->opd_valid())
3970 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3971 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3975 // If we haven't run scan_opd_relocs, we must delay
3976 // processing this function descriptor reference.
3977 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3982 // Add any special sections for this symbol to the gc work list.
3983 // For powerpc64, this adds the code section of a function
3986 template<int size
, bool big_endian
>
3988 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3989 Symbol_table
* symtab
,
3994 Powerpc_relobj
<size
, big_endian
>* ppc_object
3995 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3997 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3998 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
4000 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
4001 Address dst_off
= gsym
->value();
4002 if (ppc_object
->opd_valid())
4004 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
4005 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
4008 ppc_object
->add_gc_mark(dst_off
);
4013 // Scan relocations for a section.
4015 template<int size
, bool big_endian
>
4017 Target_powerpc
<size
, big_endian
>::scan_relocs(
4018 Symbol_table
* symtab
,
4020 Sized_relobj_file
<size
, big_endian
>* object
,
4021 unsigned int data_shndx
,
4022 unsigned int sh_type
,
4023 const unsigned char* prelocs
,
4025 Output_section
* output_section
,
4026 bool needs_special_offset_handling
,
4027 size_t local_symbol_count
,
4028 const unsigned char* plocal_symbols
)
4030 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
4031 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
4033 if (sh_type
== elfcpp::SHT_REL
)
4035 gold_error(_("%s: unsupported REL reloc section"),
4036 object
->name().c_str());
4042 // Define a weak hidden _GLOBAL_OFFSET_TABLE_ to ensure it isn't
4043 // seen as undefined when scanning relocs (and thus requires
4044 // non-relative dynamic relocs). The proper value will be
4046 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
4047 if (gotsym
!= NULL
&& gotsym
->is_undefined())
4048 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
4049 Symbol_table::PREDEFINED
,
4050 this->got_section(symtab
, layout
), 0, 0,
4053 elfcpp::STV_HIDDEN
, 0,
4056 static Output_data_space
* sdata
;
4058 // Define _SDA_BASE_ at the start of the .sdata section.
4061 // layout->find_output_section(".sdata") == NULL
4062 sdata
= new Output_data_space(4, "** sdata");
4064 = layout
->add_output_section_data(".sdata", 0,
4066 | elfcpp::SHF_WRITE
,
4067 sdata
, ORDER_SMALL_DATA
, false);
4068 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
4069 Symbol_table::PREDEFINED
,
4070 os
, 32768, 0, elfcpp::STT_OBJECT
,
4071 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
4076 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
4085 needs_special_offset_handling
,
4090 // Functor class for processing the global symbol table.
4091 // Removes symbols defined on discarded opd entries.
4093 template<bool big_endian
>
4094 class Global_symbol_visitor_opd
4097 Global_symbol_visitor_opd()
4101 operator()(Sized_symbol
<64>* sym
)
4103 if (sym
->has_symtab_index()
4104 || sym
->source() != Symbol::FROM_OBJECT
4105 || !sym
->in_real_elf())
4108 Powerpc_relobj
<64, big_endian
>* symobj
4109 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
4110 if (symobj
->is_dynamic()
4111 || symobj
->opd_shndx() == 0)
4115 unsigned int shndx
= sym
->shndx(&is_ordinary
);
4116 if (shndx
== symobj
->opd_shndx()
4117 && symobj
->get_opd_discard(sym
->value()))
4118 sym
->set_symtab_index(-1U);
4122 template<int size
, bool big_endian
>
4124 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
4126 Symbol_table
* symtab
)
4130 Output_data_save_res
<64, big_endian
>* savres
4131 = new Output_data_save_res
<64, big_endian
>(symtab
);
4132 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
4133 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
4134 savres
, ORDER_TEXT
, false);
4138 // Finalize the sections.
4140 template<int size
, bool big_endian
>
4142 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
4144 const Input_objects
*,
4145 Symbol_table
* symtab
)
4147 if (parameters
->doing_static_link())
4149 // At least some versions of glibc elf-init.o have a strong
4150 // reference to __rela_iplt marker syms. A weak ref would be
4152 if (this->iplt_
!= NULL
)
4154 Reloc_section
* rel
= this->iplt_
->rel_plt();
4155 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
4156 Symbol_table::PREDEFINED
, rel
, 0, 0,
4157 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4158 elfcpp::STV_HIDDEN
, 0, false, true);
4159 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
4160 Symbol_table::PREDEFINED
, rel
, 0, 0,
4161 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4162 elfcpp::STV_HIDDEN
, 0, true, true);
4166 symtab
->define_as_constant("__rela_iplt_start", NULL
,
4167 Symbol_table::PREDEFINED
, 0, 0,
4168 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4169 elfcpp::STV_HIDDEN
, 0, true, false);
4170 symtab
->define_as_constant("__rela_iplt_end", NULL
,
4171 Symbol_table::PREDEFINED
, 0, 0,
4172 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
4173 elfcpp::STV_HIDDEN
, 0, true, false);
4179 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
4180 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
4181 this->define_save_restore_funcs(layout
, symtab
);
4184 // Fill in some more dynamic tags.
4185 Output_data_dynamic
* odyn
= layout
->dynamic_data();
4188 const Reloc_section
* rel_plt
= (this->plt_
== NULL
4190 : this->plt_
->rel_plt());
4191 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
4192 this->rela_dyn_
, true, size
== 32);
4196 if (this->got_
!= NULL
)
4198 this->got_
->finalize_data_size();
4199 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
4200 this->got_
, this->got_
->g_o_t());
4205 if (this->glink_
!= NULL
)
4207 this->glink_
->finalize_data_size();
4208 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
4210 (this->glink_
->pltresolve()
4211 + this->glink_
->pltresolve_size
4217 // Emit any relocs we saved in an attempt to avoid generating COPY
4219 if (this->copy_relocs_
.any_saved_relocs())
4220 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
4223 // Return the value to use for a branch relocation.
4225 template<int size
, bool big_endian
>
4226 typename
elfcpp::Elf_types
<size
>::Elf_Addr
4227 Target_powerpc
<size
, big_endian
>::symval_for_branch(
4229 const Sized_symbol
<size
>* gsym
,
4230 Powerpc_relobj
<size
, big_endian
>* object
,
4231 unsigned int *dest_shndx
)
4237 // If the symbol is defined in an opd section, ie. is a function
4238 // descriptor, use the function descriptor code entry address
4239 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
4241 && gsym
->source() != Symbol::FROM_OBJECT
)
4244 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
4245 unsigned int shndx
= symobj
->opd_shndx();
4248 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
4249 gold_assert(opd_addr
!= invalid_address
);
4250 opd_addr
+= symobj
->output_section(shndx
)->address();
4251 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
4254 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
4255 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
4256 gold_assert(sec_addr
!= invalid_address
);
4257 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
4258 value
= sec_addr
+ sec_off
;
4263 // Perform a relocation.
4265 template<int size
, bool big_endian
>
4267 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
4268 const Relocate_info
<size
, big_endian
>* relinfo
,
4269 Target_powerpc
* target
,
4272 const elfcpp::Rela
<size
, big_endian
>& rela
,
4273 unsigned int r_type
,
4274 const Sized_symbol
<size
>* gsym
,
4275 const Symbol_value
<size
>* psymval
,
4276 unsigned char* view
,
4278 section_size_type view_size
)
4281 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
4282 || r_type
== elfcpp::R_PPC_PLTREL24
)
4284 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
4285 enum skip_tls last_tls
= this->call_tls_get_addr_
;
4286 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
4289 if (last_tls
== CALL_NOT_EXPECTED
)
4290 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4291 _("__tls_get_addr call lacks marker reloc"));
4292 else if (last_tls
== CALL_SKIP
)
4295 else if (last_tls
!= CALL_NOT_EXPECTED
)
4296 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4297 _("missing expected __tls_get_addr call"));
4299 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
4300 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
4301 Powerpc_relobj
<size
, big_endian
>* const object
4302 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4304 bool has_plt_value
= false;
4305 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4307 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
))
4308 : object
->local_has_plt_offset(r_sym
))
4310 const Output_data_glink
<size
, big_endian
>* glink
4311 = target
->glink_section();
4312 unsigned int glink_index
;
4314 glink_index
= glink
->find_entry(object
, gsym
, rela
);
4316 glink_index
= glink
->find_entry(object
, r_sym
, rela
);
4317 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
4318 has_plt_value
= true;
4321 if (r_type
== elfcpp::R_POWERPC_GOT16
4322 || r_type
== elfcpp::R_POWERPC_GOT16_LO
4323 || r_type
== elfcpp::R_POWERPC_GOT16_HI
4324 || r_type
== elfcpp::R_POWERPC_GOT16_HA
4325 || r_type
== elfcpp::R_PPC64_GOT16_DS
4326 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
4330 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
4331 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
4335 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4336 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
4337 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
4339 value
-= target
->got_section()->got_base_offset(object
);
4341 else if (r_type
== elfcpp::R_PPC64_TOC
)
4343 value
= (target
->got_section()->output_section()->address()
4344 + object
->toc_base_offset());
4346 else if (gsym
!= NULL
4347 && (r_type
== elfcpp::R_POWERPC_REL24
4348 || r_type
== elfcpp::R_PPC_PLTREL24
)
4353 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
4354 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
4355 bool can_plt_call
= false;
4356 if (rela
.get_r_offset() + 8 <= view_size
)
4358 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
4359 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
4362 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
4364 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
4365 can_plt_call
= true;
4370 // If we don't have a branch and link followed by a nop,
4371 // we can't go via the plt because there is no place to
4372 // put a toc restoring instruction.
4373 // Unless we know we won't be returning.
4374 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
4375 can_plt_call
= true;
4379 // This is not an error in one special case: A self
4380 // call. It isn't possible to cheaply verify we have
4381 // such a call so just check for a call to the same
4384 Address code
= value
;
4385 if (gsym
->source() == Symbol::FROM_OBJECT
4386 && gsym
->object() == object
)
4388 Address addend
= rela
.get_r_addend();
4389 unsigned int dest_shndx
;
4390 Address opdent
= psymval
->value(object
, addend
);
4391 code
= target
->symval_for_branch(opdent
, gsym
, object
,
4394 if (dest_shndx
== 0)
4395 dest_shndx
= gsym
->shndx(&is_ordinary
);
4396 ok
= dest_shndx
== relinfo
->data_shndx
;
4400 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4401 _("call lacks nop, can't restore toc; "
4402 "recompile with -fPIC"));
4408 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4409 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4410 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4411 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4413 // First instruction of a global dynamic sequence, arg setup insn.
4414 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4415 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
4416 enum Got_type got_type
= GOT_TYPE_STANDARD
;
4417 if (tls_type
== tls::TLSOPT_NONE
)
4418 got_type
= GOT_TYPE_TLSGD
;
4419 else if (tls_type
== tls::TLSOPT_TO_IE
)
4420 got_type
= GOT_TYPE_TPREL
;
4421 if (got_type
!= GOT_TYPE_STANDARD
)
4425 gold_assert(gsym
->has_got_offset(got_type
));
4426 value
= gsym
->got_offset(got_type
);
4430 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4431 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
4432 value
= object
->local_got_offset(r_sym
, got_type
);
4434 value
-= target
->got_section()->got_base_offset(object
);
4436 if (tls_type
== tls::TLSOPT_TO_IE
)
4438 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4439 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4441 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4442 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4443 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
4445 insn
|= 32 << 26; // lwz
4447 insn
|= 58 << 26; // ld
4448 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4450 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4451 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4453 else if (tls_type
== tls::TLSOPT_TO_LE
)
4455 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4456 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4458 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4459 Insn insn
= addis_3_13
;
4462 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4463 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4464 value
= psymval
->value(object
, rela
.get_r_addend());
4468 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4470 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4471 r_type
= elfcpp::R_POWERPC_NONE
;
4475 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4476 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4477 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4478 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4480 // First instruction of a local dynamic sequence, arg setup insn.
4481 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4482 if (tls_type
== tls::TLSOPT_NONE
)
4484 value
= target
->tlsld_got_offset();
4485 value
-= target
->got_section()->got_base_offset(object
);
4489 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4490 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4491 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4493 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4494 Insn insn
= addis_3_13
;
4497 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4498 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4503 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4505 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4506 r_type
= elfcpp::R_POWERPC_NONE
;
4510 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
4511 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
4512 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
4513 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
4515 // Accesses relative to a local dynamic sequence address,
4516 // no optimisation here.
4519 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
4520 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
4524 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4525 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
4526 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
4528 value
-= target
->got_section()->got_base_offset(object
);
4530 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4531 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4532 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4533 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4535 // First instruction of initial exec sequence.
4536 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4537 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4538 if (tls_type
== tls::TLSOPT_NONE
)
4542 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
4543 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
4547 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4548 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
4549 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
4551 value
-= target
->got_section()->got_base_offset(object
);
4555 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4556 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4557 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4559 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4560 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4561 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
4566 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4567 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4568 value
= psymval
->value(object
, rela
.get_r_addend());
4572 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4574 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4575 r_type
= elfcpp::R_POWERPC_NONE
;
4579 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4580 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4582 // Second instruction of a global dynamic sequence,
4583 // the __tls_get_addr call
4584 this->call_tls_get_addr_
= CALL_EXPECTED
;
4585 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4586 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
4587 if (tls_type
!= tls::TLSOPT_NONE
)
4589 if (tls_type
== tls::TLSOPT_TO_IE
)
4591 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4592 Insn insn
= add_3_3_13
;
4595 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4596 r_type
= elfcpp::R_POWERPC_NONE
;
4600 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4601 Insn insn
= addi_3_3
;
4602 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4603 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4604 view
+= 2 * big_endian
;
4605 value
= psymval
->value(object
, rela
.get_r_addend());
4607 this->call_tls_get_addr_
= CALL_SKIP
;
4610 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4611 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4613 // Second instruction of a local dynamic sequence,
4614 // the __tls_get_addr call
4615 this->call_tls_get_addr_
= CALL_EXPECTED
;
4616 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4617 if (tls_type
== tls::TLSOPT_TO_LE
)
4619 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4620 Insn insn
= addi_3_3
;
4621 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4622 this->call_tls_get_addr_
= CALL_SKIP
;
4623 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4624 view
+= 2 * big_endian
;
4628 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4630 // Second instruction of an initial exec sequence
4631 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4632 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4633 if (tls_type
== tls::TLSOPT_TO_LE
)
4635 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4636 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4637 unsigned int reg
= size
== 32 ? 2 : 13;
4638 insn
= at_tls_transform(insn
, reg
);
4639 gold_assert(insn
!= 0);
4640 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4641 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4642 view
+= 2 * big_endian
;
4643 value
= psymval
->value(object
, rela
.get_r_addend());
4646 else if (!has_plt_value
)
4649 unsigned int dest_shndx
;
4650 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
4651 addend
= rela
.get_r_addend();
4652 value
= psymval
->value(object
, addend
);
4653 if (size
== 64 && is_branch_reloc(r_type
))
4654 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
4659 case elfcpp::R_PPC64_REL64
:
4660 case elfcpp::R_POWERPC_REL32
:
4661 case elfcpp::R_POWERPC_REL24
:
4662 case elfcpp::R_PPC_PLTREL24
:
4663 case elfcpp::R_PPC_LOCAL24PC
:
4664 case elfcpp::R_POWERPC_REL16
:
4665 case elfcpp::R_POWERPC_REL16_LO
:
4666 case elfcpp::R_POWERPC_REL16_HI
:
4667 case elfcpp::R_POWERPC_REL16_HA
:
4668 case elfcpp::R_POWERPC_REL14
:
4669 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4670 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4674 case elfcpp::R_PPC64_TOC16
:
4675 case elfcpp::R_PPC64_TOC16_LO
:
4676 case elfcpp::R_PPC64_TOC16_HI
:
4677 case elfcpp::R_PPC64_TOC16_HA
:
4678 case elfcpp::R_PPC64_TOC16_DS
:
4679 case elfcpp::R_PPC64_TOC16_LO_DS
:
4680 // Subtract the TOC base address.
4681 value
-= (target
->got_section()->output_section()->address()
4682 + object
->toc_base_offset());
4685 case elfcpp::R_POWERPC_SECTOFF
:
4686 case elfcpp::R_POWERPC_SECTOFF_LO
:
4687 case elfcpp::R_POWERPC_SECTOFF_HI
:
4688 case elfcpp::R_POWERPC_SECTOFF_HA
:
4689 case elfcpp::R_PPC64_SECTOFF_DS
:
4690 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4692 value
-= os
->address();
4695 case elfcpp::R_PPC64_TPREL16_DS
:
4696 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4698 // R_PPC_TLSGD and R_PPC_TLSLD
4700 case elfcpp::R_POWERPC_TPREL16
:
4701 case elfcpp::R_POWERPC_TPREL16_LO
:
4702 case elfcpp::R_POWERPC_TPREL16_HI
:
4703 case elfcpp::R_POWERPC_TPREL16_HA
:
4704 case elfcpp::R_POWERPC_TPREL
:
4705 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4706 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4707 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4708 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4709 // tls symbol values are relative to tls_segment()->vaddr()
4713 case elfcpp::R_PPC64_DTPREL16_DS
:
4714 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4715 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4716 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4717 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4718 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4720 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
4721 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
4723 case elfcpp::R_POWERPC_DTPREL16
:
4724 case elfcpp::R_POWERPC_DTPREL16_LO
:
4725 case elfcpp::R_POWERPC_DTPREL16_HI
:
4726 case elfcpp::R_POWERPC_DTPREL16_HA
:
4727 case elfcpp::R_POWERPC_DTPREL
:
4728 // tls symbol values are relative to tls_segment()->vaddr()
4729 value
-= dtp_offset
;
4736 Insn branch_bit
= 0;
4739 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4740 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4741 branch_bit
= 1 << 21;
4742 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4743 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4745 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4746 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4749 if (this->is_isa_v2
)
4751 // Set 'a' bit. This is 0b00010 in BO field for branch
4752 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
4753 // for branch on CTR insns (BO == 1a00t or 1a01t).
4754 if ((insn
& (0x14 << 21)) == (0x04 << 21))
4756 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
4763 // Invert 'y' bit if not the default.
4764 if (static_cast<Signed_address
>(value
) < 0)
4767 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4775 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
4778 case elfcpp::R_POWERPC_ADDR32
:
4779 case elfcpp::R_POWERPC_UADDR32
:
4781 overflow
= Reloc::CHECK_BITFIELD
;
4784 case elfcpp::R_POWERPC_REL32
:
4786 overflow
= Reloc::CHECK_SIGNED
;
4789 case elfcpp::R_POWERPC_ADDR24
:
4790 case elfcpp::R_POWERPC_ADDR16
:
4791 case elfcpp::R_POWERPC_UADDR16
:
4792 case elfcpp::R_PPC64_ADDR16_DS
:
4793 case elfcpp::R_POWERPC_ADDR14
:
4794 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4795 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4796 overflow
= Reloc::CHECK_BITFIELD
;
4799 case elfcpp::R_POWERPC_REL24
:
4800 case elfcpp::R_PPC_PLTREL24
:
4801 case elfcpp::R_PPC_LOCAL24PC
:
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_PPC64_TPREL16_DS
:
4809 case elfcpp::R_PPC64_DTPREL16_DS
:
4810 case elfcpp::R_PPC64_TOC16_DS
:
4811 case elfcpp::R_PPC64_GOT16_DS
:
4812 case elfcpp::R_PPC64_SECTOFF_DS
:
4813 case elfcpp::R_POWERPC_REL14
:
4814 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4815 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4816 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4817 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4818 case elfcpp::R_POWERPC_GOT_TPREL16
:
4819 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4820 overflow
= Reloc::CHECK_SIGNED
;
4824 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
4825 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
4828 case elfcpp::R_POWERPC_NONE
:
4829 case elfcpp::R_POWERPC_TLS
:
4830 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4831 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4832 case elfcpp::R_PPC_EMB_MRKREF
:
4835 case elfcpp::R_PPC64_ADDR64
:
4836 case elfcpp::R_PPC64_REL64
:
4837 case elfcpp::R_PPC64_TOC
:
4838 Reloc::addr64(view
, value
);
4841 case elfcpp::R_POWERPC_TPREL
:
4842 case elfcpp::R_POWERPC_DTPREL
:
4844 Reloc::addr64(view
, value
);
4846 status
= Reloc::addr32(view
, value
, overflow
);
4849 case elfcpp::R_PPC64_UADDR64
:
4850 Reloc::addr64_u(view
, value
);
4853 case elfcpp::R_POWERPC_ADDR32
:
4854 status
= Reloc::addr32(view
, value
, overflow
);
4857 case elfcpp::R_POWERPC_REL32
:
4858 case elfcpp::R_POWERPC_UADDR32
:
4859 status
= Reloc::addr32_u(view
, value
, overflow
);
4862 case elfcpp::R_POWERPC_ADDR24
:
4863 case elfcpp::R_POWERPC_REL24
:
4864 case elfcpp::R_PPC_PLTREL24
:
4865 case elfcpp::R_PPC_LOCAL24PC
:
4866 status
= Reloc::addr24(view
, value
, overflow
);
4869 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4870 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
4873 status
= Reloc::addr16_ds(view
, value
, overflow
);
4876 case elfcpp::R_POWERPC_ADDR16
:
4877 case elfcpp::R_POWERPC_REL16
:
4878 case elfcpp::R_PPC64_TOC16
:
4879 case elfcpp::R_POWERPC_GOT16
:
4880 case elfcpp::R_POWERPC_SECTOFF
:
4881 case elfcpp::R_POWERPC_TPREL16
:
4882 case elfcpp::R_POWERPC_DTPREL16
:
4883 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4884 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4885 case elfcpp::R_POWERPC_GOT_TPREL16
:
4886 case elfcpp::R_POWERPC_ADDR16_LO
:
4887 case elfcpp::R_POWERPC_REL16_LO
:
4888 case elfcpp::R_PPC64_TOC16_LO
:
4889 case elfcpp::R_POWERPC_GOT16_LO
:
4890 case elfcpp::R_POWERPC_SECTOFF_LO
:
4891 case elfcpp::R_POWERPC_TPREL16_LO
:
4892 case elfcpp::R_POWERPC_DTPREL16_LO
:
4893 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
4894 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
4895 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
4896 status
= Reloc::addr16(view
, value
, overflow
);
4899 case elfcpp::R_POWERPC_UADDR16
:
4900 status
= Reloc::addr16_u(view
, value
, overflow
);
4903 case elfcpp::R_POWERPC_ADDR16_HI
:
4904 case elfcpp::R_POWERPC_REL16_HI
:
4905 case elfcpp::R_PPC64_TOC16_HI
:
4906 case elfcpp::R_POWERPC_GOT16_HI
:
4907 case elfcpp::R_POWERPC_SECTOFF_HI
:
4908 case elfcpp::R_POWERPC_TPREL16_HI
:
4909 case elfcpp::R_POWERPC_DTPREL16_HI
:
4910 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
4911 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
4912 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
4913 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
4914 Reloc::addr16_hi(view
, value
);
4917 case elfcpp::R_POWERPC_ADDR16_HA
:
4918 case elfcpp::R_POWERPC_REL16_HA
:
4919 case elfcpp::R_PPC64_TOC16_HA
:
4920 case elfcpp::R_POWERPC_GOT16_HA
:
4921 case elfcpp::R_POWERPC_SECTOFF_HA
:
4922 case elfcpp::R_POWERPC_TPREL16_HA
:
4923 case elfcpp::R_POWERPC_DTPREL16_HA
:
4924 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
4925 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
4926 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
4927 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
4928 Reloc::addr16_ha(view
, value
);
4931 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4933 // R_PPC_EMB_NADDR16_LO
4935 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4936 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4937 Reloc::addr16_hi2(view
, value
);
4940 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4942 // R_PPC_EMB_NADDR16_HI
4944 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4945 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4946 Reloc::addr16_ha2(view
, value
);
4949 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4951 // R_PPC_EMB_NADDR16_HA
4953 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4954 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4955 Reloc::addr16_hi3(view
, value
);
4958 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4962 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4963 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4964 Reloc::addr16_ha3(view
, value
);
4967 case elfcpp::R_PPC64_DTPREL16_DS
:
4968 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4970 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
4972 case elfcpp::R_PPC64_TPREL16_DS
:
4973 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4975 // R_PPC_TLSGD, R_PPC_TLSLD
4977 case elfcpp::R_PPC64_ADDR16_DS
:
4978 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4979 case elfcpp::R_PPC64_TOC16_DS
:
4980 case elfcpp::R_PPC64_TOC16_LO_DS
:
4981 case elfcpp::R_PPC64_GOT16_DS
:
4982 case elfcpp::R_PPC64_GOT16_LO_DS
:
4983 case elfcpp::R_PPC64_SECTOFF_DS
:
4984 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4985 status
= Reloc::addr16_ds(view
, value
, overflow
);
4988 case elfcpp::R_POWERPC_ADDR14
:
4989 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4990 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4991 case elfcpp::R_POWERPC_REL14
:
4992 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4993 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4994 status
= Reloc::addr14(view
, value
, overflow
);
4997 case elfcpp::R_POWERPC_COPY
:
4998 case elfcpp::R_POWERPC_GLOB_DAT
:
4999 case elfcpp::R_POWERPC_JMP_SLOT
:
5000 case elfcpp::R_POWERPC_RELATIVE
:
5001 case elfcpp::R_POWERPC_DTPMOD
:
5002 case elfcpp::R_PPC64_JMP_IREL
:
5003 case elfcpp::R_POWERPC_IRELATIVE
:
5004 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5005 _("unexpected reloc %u in object file"),
5009 case elfcpp::R_PPC_EMB_SDA21
:
5014 // R_PPC64_TOCSAVE. For the time being this can be ignored.
5018 case elfcpp::R_PPC_EMB_SDA2I16
:
5019 case elfcpp::R_PPC_EMB_SDA2REL
:
5022 // R_PPC64_TLSGD, R_PPC64_TLSLD
5025 case elfcpp::R_POWERPC_PLT32
:
5026 case elfcpp::R_POWERPC_PLTREL32
:
5027 case elfcpp::R_POWERPC_PLT16_LO
:
5028 case elfcpp::R_POWERPC_PLT16_HI
:
5029 case elfcpp::R_POWERPC_PLT16_HA
:
5030 case elfcpp::R_PPC_SDAREL16
:
5031 case elfcpp::R_POWERPC_ADDR30
:
5032 case elfcpp::R_PPC64_PLT64
:
5033 case elfcpp::R_PPC64_PLTREL64
:
5034 case elfcpp::R_PPC64_PLTGOT16
:
5035 case elfcpp::R_PPC64_PLTGOT16_LO
:
5036 case elfcpp::R_PPC64_PLTGOT16_HI
:
5037 case elfcpp::R_PPC64_PLTGOT16_HA
:
5038 case elfcpp::R_PPC64_PLT16_LO_DS
:
5039 case elfcpp::R_PPC64_PLTGOT16_DS
:
5040 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
5041 case elfcpp::R_PPC_EMB_RELSEC16
:
5042 case elfcpp::R_PPC_EMB_RELST_LO
:
5043 case elfcpp::R_PPC_EMB_RELST_HI
:
5044 case elfcpp::R_PPC_EMB_RELST_HA
:
5045 case elfcpp::R_PPC_EMB_BIT_FLD
:
5046 case elfcpp::R_PPC_EMB_RELSDA
:
5047 case elfcpp::R_PPC_TOC16
:
5050 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5051 _("unsupported reloc %u"),
5055 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
5056 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5057 _("relocation overflow"));
5062 // Relocate section data.
5064 template<int size
, bool big_endian
>
5066 Target_powerpc
<size
, big_endian
>::relocate_section(
5067 const Relocate_info
<size
, big_endian
>* relinfo
,
5068 unsigned int sh_type
,
5069 const unsigned char* prelocs
,
5071 Output_section
* output_section
,
5072 bool needs_special_offset_handling
,
5073 unsigned char* view
,
5075 section_size_type view_size
,
5076 const Reloc_symbol_changes
* reloc_symbol_changes
)
5078 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5079 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
5080 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
5081 Powerpc_comdat_behavior
;
5083 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5085 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
5086 Powerpc_relocate
, Powerpc_comdat_behavior
>(
5092 needs_special_offset_handling
,
5096 reloc_symbol_changes
);
5099 class Powerpc_scan_relocatable_reloc
5102 // Return the strategy to use for a local symbol which is not a
5103 // section symbol, given the relocation type.
5104 inline Relocatable_relocs::Reloc_strategy
5105 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
5107 if (r_type
== 0 && r_sym
== 0)
5108 return Relocatable_relocs::RELOC_DISCARD
;
5109 return Relocatable_relocs::RELOC_COPY
;
5112 // Return the strategy to use for a local symbol which is a section
5113 // symbol, given the relocation type.
5114 inline Relocatable_relocs::Reloc_strategy
5115 local_section_strategy(unsigned int, Relobj
*)
5117 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
5120 // Return the strategy to use for a global symbol, given the
5121 // relocation type, the object, and the symbol index.
5122 inline Relocatable_relocs::Reloc_strategy
5123 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
5125 if (r_type
== elfcpp::R_PPC_PLTREL24
)
5126 return Relocatable_relocs::RELOC_SPECIAL
;
5127 return Relocatable_relocs::RELOC_COPY
;
5131 // Scan the relocs during a relocatable link.
5133 template<int size
, bool big_endian
>
5135 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
5136 Symbol_table
* symtab
,
5138 Sized_relobj_file
<size
, big_endian
>* object
,
5139 unsigned int data_shndx
,
5140 unsigned int sh_type
,
5141 const unsigned char* prelocs
,
5143 Output_section
* output_section
,
5144 bool needs_special_offset_handling
,
5145 size_t local_symbol_count
,
5146 const unsigned char* plocal_symbols
,
5147 Relocatable_relocs
* rr
)
5149 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5151 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
5152 Powerpc_scan_relocatable_reloc
>(
5160 needs_special_offset_handling
,
5166 // Emit relocations for a section.
5167 // This is a modified version of the function by the same name in
5168 // target-reloc.h. Using relocate_special_relocatable for
5169 // R_PPC_PLTREL24 would require duplication of the entire body of the
5170 // loop, so we may as well duplicate the whole thing.
5172 template<int size
, bool big_endian
>
5174 Target_powerpc
<size
, big_endian
>::relocate_relocs(
5175 const Relocate_info
<size
, big_endian
>* relinfo
,
5176 unsigned int sh_type
,
5177 const unsigned char* prelocs
,
5179 Output_section
* output_section
,
5180 off_t offset_in_output_section
,
5181 const Relocatable_relocs
* rr
,
5183 Address view_address
,
5185 unsigned char* reloc_view
,
5186 section_size_type reloc_view_size
)
5188 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5190 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
5192 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
5194 const int reloc_size
5195 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
5197 Powerpc_relobj
<size
, big_endian
>* const object
5198 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
5199 const unsigned int local_count
= object
->local_symbol_count();
5200 unsigned int got2_shndx
= object
->got2_shndx();
5201 Address got2_addend
= 0;
5202 if (got2_shndx
!= 0)
5204 got2_addend
= object
->get_output_section_offset(got2_shndx
);
5205 gold_assert(got2_addend
!= invalid_address
);
5208 unsigned char* pwrite
= reloc_view
;
5209 bool zap_next
= false;
5210 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
5212 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
5213 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
5216 Reltype
reloc(prelocs
);
5217 Reltype_write
reloc_write(pwrite
);
5219 Address offset
= reloc
.get_r_offset();
5220 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
5221 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
5222 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
5223 const unsigned int orig_r_sym
= r_sym
;
5224 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
5225 = reloc
.get_r_addend();
5226 const Symbol
* gsym
= NULL
;
5230 // We could arrange to discard these and other relocs for
5231 // tls optimised sequences in the strategy methods, but for
5232 // now do as BFD ld does.
5233 r_type
= elfcpp::R_POWERPC_NONE
;
5237 // Get the new symbol index.
5238 if (r_sym
< local_count
)
5242 case Relocatable_relocs::RELOC_COPY
:
5243 case Relocatable_relocs::RELOC_SPECIAL
:
5246 r_sym
= object
->symtab_index(r_sym
);
5247 gold_assert(r_sym
!= -1U);
5251 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
5253 // We are adjusting a section symbol. We need to find
5254 // the symbol table index of the section symbol for
5255 // the output section corresponding to input section
5256 // in which this symbol is defined.
5257 gold_assert(r_sym
< local_count
);
5259 unsigned int shndx
=
5260 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
5261 gold_assert(is_ordinary
);
5262 Output_section
* os
= object
->output_section(shndx
);
5263 gold_assert(os
!= NULL
);
5264 gold_assert(os
->needs_symtab_index());
5265 r_sym
= os
->symtab_index();
5275 gsym
= object
->global_symbol(r_sym
);
5276 gold_assert(gsym
!= NULL
);
5277 if (gsym
->is_forwarder())
5278 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
5280 gold_assert(gsym
->has_symtab_index());
5281 r_sym
= gsym
->symtab_index();
5284 // Get the new offset--the location in the output section where
5285 // this relocation should be applied.
5286 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
5287 offset
+= offset_in_output_section
;
5290 section_offset_type sot_offset
=
5291 convert_types
<section_offset_type
, Address
>(offset
);
5292 section_offset_type new_sot_offset
=
5293 output_section
->output_offset(object
, relinfo
->data_shndx
,
5295 gold_assert(new_sot_offset
!= -1);
5296 offset
= new_sot_offset
;
5299 // In an object file, r_offset is an offset within the section.
5300 // In an executable or dynamic object, generated by
5301 // --emit-relocs, r_offset is an absolute address.
5302 if (!parameters
->options().relocatable())
5304 offset
+= view_address
;
5305 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
5306 offset
-= offset_in_output_section
;
5309 // Handle the reloc addend based on the strategy.
5310 if (strategy
== Relocatable_relocs::RELOC_COPY
)
5312 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
5314 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
5315 addend
= psymval
->value(object
, addend
);
5317 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
5319 if (addend
>= 32768)
5320 addend
+= got2_addend
;
5325 if (!parameters
->options().relocatable())
5327 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5328 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
5329 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
5330 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
5332 // First instruction of a global dynamic sequence,
5334 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5335 switch (this->optimize_tls_gd(final
))
5337 case tls::TLSOPT_TO_IE
:
5338 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
5339 - elfcpp::R_POWERPC_GOT_TLSGD16
);
5341 case tls::TLSOPT_TO_LE
:
5342 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5343 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
5344 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5347 r_type
= elfcpp::R_POWERPC_NONE
;
5348 offset
-= 2 * big_endian
;
5355 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5356 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
5357 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
5358 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
5360 // First instruction of a local dynamic sequence,
5362 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
5364 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5365 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
5367 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5368 const Output_section
* os
= relinfo
->layout
->tls_segment()
5370 gold_assert(os
!= NULL
);
5371 gold_assert(os
->needs_symtab_index());
5372 r_sym
= os
->symtab_index();
5373 addend
= dtp_offset
;
5377 r_type
= elfcpp::R_POWERPC_NONE
;
5378 offset
-= 2 * big_endian
;
5382 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5383 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
5384 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
5385 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
5387 // First instruction of initial exec sequence.
5388 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5389 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
5391 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5392 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
5393 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5396 r_type
= elfcpp::R_POWERPC_NONE
;
5397 offset
-= 2 * big_endian
;
5401 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5402 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5404 // Second instruction of a global dynamic sequence,
5405 // the __tls_get_addr call
5406 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5407 switch (this->optimize_tls_gd(final
))
5409 case tls::TLSOPT_TO_IE
:
5410 r_type
= elfcpp::R_POWERPC_NONE
;
5413 case tls::TLSOPT_TO_LE
:
5414 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5415 offset
+= 2 * big_endian
;
5422 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5423 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5425 // Second instruction of a local dynamic sequence,
5426 // the __tls_get_addr call
5427 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
5429 const Output_section
* os
= relinfo
->layout
->tls_segment()
5431 gold_assert(os
!= NULL
);
5432 gold_assert(os
->needs_symtab_index());
5433 r_sym
= os
->symtab_index();
5434 addend
= dtp_offset
;
5435 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5436 offset
+= 2 * big_endian
;
5440 else if (r_type
== elfcpp::R_POWERPC_TLS
)
5442 // Second instruction of an initial exec sequence
5443 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5444 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
5446 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5447 offset
+= 2 * big_endian
;
5452 reloc_write
.put_r_offset(offset
);
5453 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
5454 reloc_write
.put_r_addend(addend
);
5456 pwrite
+= reloc_size
;
5459 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
5460 == reloc_view_size
);
5463 // Return the value to use for a dynamic which requires special
5464 // treatment. This is how we support equality comparisons of function
5465 // pointers across shared library boundaries, as described in the
5466 // processor specific ABI supplement.
5468 template<int size
, bool big_endian
>
5470 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
5474 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
5475 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5476 unsigned int glink_index
= glink
->find_entry(gsym
);
5477 return glink
->address() + glink_index
* glink
->glink_entry_size();
5483 // Return the PLT address to use for a local symbol.
5484 template<int size
, bool big_endian
>
5486 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
5487 const Relobj
* object
,
5488 unsigned int symndx
) const
5492 const Sized_relobj
<size
, big_endian
>* relobj
5493 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
5494 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5495 unsigned int glink_index
= glink
->find_entry(relobj
->sized_relobj(),
5497 return glink
->address() + glink_index
* glink
->glink_entry_size();
5503 // Return the PLT address to use for a global symbol.
5504 template<int size
, bool big_endian
>
5506 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
5507 const Symbol
* gsym
) const
5511 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5512 unsigned int glink_index
= glink
->find_entry(gsym
);
5513 return glink
->address() + glink_index
* glink
->glink_entry_size();
5519 // Return the offset to use for the GOT_INDX'th got entry which is
5520 // for a local tls symbol specified by OBJECT, SYMNDX.
5521 template<int size
, bool big_endian
>
5523 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
5524 const Relobj
* object
,
5525 unsigned int symndx
,
5526 unsigned int got_indx
) const
5528 const Powerpc_relobj
<size
, big_endian
>* ppc_object
5529 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
5530 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
5532 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5533 got_type
<= GOT_TYPE_TPREL
;
5534 got_type
= Got_type(got_type
+ 1))
5535 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
5537 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
5538 if (got_type
== GOT_TYPE_TLSGD
)
5540 if (off
== got_indx
* (size
/ 8))
5542 if (got_type
== GOT_TYPE_TPREL
)
5552 // Return the offset to use for the GOT_INDX'th got entry which is
5553 // for global tls symbol GSYM.
5554 template<int size
, bool big_endian
>
5556 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
5558 unsigned int got_indx
) const
5560 if (gsym
->type() == elfcpp::STT_TLS
)
5562 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5563 got_type
<= GOT_TYPE_TPREL
;
5564 got_type
= Got_type(got_type
+ 1))
5565 if (gsym
->has_got_offset(got_type
))
5567 unsigned int off
= gsym
->got_offset(got_type
);
5568 if (got_type
== GOT_TYPE_TLSGD
)
5570 if (off
== got_indx
* (size
/ 8))
5572 if (got_type
== GOT_TYPE_TPREL
)
5582 // The selector for powerpc object files.
5584 template<int size
, bool big_endian
>
5585 class Target_selector_powerpc
: public Target_selector
5588 Target_selector_powerpc()
5589 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
5591 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
5592 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
5594 ? (big_endian
? "elf64ppc" : "elf64lppc")
5595 : (big_endian
? "elf32ppc" : "elf32lppc")))
5599 do_recognize(Input_file
*, off_t
, int machine
, int, int)
5604 if (machine
!= elfcpp::EM_PPC64
)
5609 if (machine
!= elfcpp::EM_PPC
)
5617 return this->instantiate_target();
5621 do_instantiate_target()
5622 { return new Target_powerpc
<size
, big_endian
>(); }
5625 Target_selector_powerpc
<32, true> target_selector_ppc32
;
5626 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
5627 Target_selector_powerpc
<64, true> target_selector_ppc64
;
5628 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
5630 } // End anonymous namespace.