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 // Finalize the sections.
330 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
332 // Return the value to use for a dynamic which requires special
335 do_dynsym_value(const Symbol
*) const;
337 // Return the PLT address to use for a local symbol.
339 do_plt_address_for_local(const Relobj
*, unsigned int) const;
341 // Return the PLT address to use for a global symbol.
343 do_plt_address_for_global(const Symbol
*) const;
345 // Return the offset to use for the GOT_INDX'th got entry which is
346 // for a local tls symbol specified by OBJECT, SYMNDX.
348 do_tls_offset_for_local(const Relobj
* object
,
350 unsigned int got_indx
) const;
352 // Return the offset to use for the GOT_INDX'th got entry which is
353 // for global tls symbol GSYM.
355 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
357 // Relocate a section.
359 relocate_section(const Relocate_info
<size
, big_endian
>*,
360 unsigned int sh_type
,
361 const unsigned char* prelocs
,
363 Output_section
* output_section
,
364 bool needs_special_offset_handling
,
366 Address view_address
,
367 section_size_type view_size
,
368 const Reloc_symbol_changes
*);
370 // Scan the relocs during a relocatable link.
372 scan_relocatable_relocs(Symbol_table
* symtab
,
374 Sized_relobj_file
<size
, big_endian
>* object
,
375 unsigned int data_shndx
,
376 unsigned int sh_type
,
377 const unsigned char* prelocs
,
379 Output_section
* output_section
,
380 bool needs_special_offset_handling
,
381 size_t local_symbol_count
,
382 const unsigned char* plocal_symbols
,
383 Relocatable_relocs
*);
385 // Emit relocations for a section.
387 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
388 unsigned int sh_type
,
389 const unsigned char* prelocs
,
391 Output_section
* output_section
,
392 off_t offset_in_output_section
,
393 const Relocatable_relocs
*,
395 Address view_address
,
397 unsigned char* reloc_view
,
398 section_size_type reloc_view_size
);
400 // Return whether SYM is defined by the ABI.
402 do_is_defined_by_abi(const Symbol
* sym
) const
404 return strcmp(sym
->name(), "__tls_get_addr") == 0;
407 // Return the size of the GOT section.
411 gold_assert(this->got_
!= NULL
);
412 return this->got_
->data_size();
415 // Get the PLT section.
416 const Output_data_plt_powerpc
<size
, big_endian
>*
419 gold_assert(this->plt_
!= NULL
);
423 // Get the IPLT section.
424 const Output_data_plt_powerpc
<size
, big_endian
>*
427 gold_assert(this->iplt_
!= NULL
);
431 // Get the .glink section.
432 const Output_data_glink
<size
, big_endian
>*
433 glink_section() const
435 gold_assert(this->glink_
!= NULL
);
439 // Get the GOT section.
440 const Output_data_got_powerpc
<size
, big_endian
>*
443 gold_assert(this->got_
!= NULL
);
448 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
449 const elfcpp::Ehdr
<size
, big_endian
>&);
451 // Return the number of entries in the GOT.
453 got_entry_count() const
455 if (this->got_
== NULL
)
457 return this->got_size() / (size
/ 8);
460 // Return the number of entries in the PLT.
462 plt_entry_count() const;
464 // Return the offset of the first non-reserved PLT entry.
466 first_plt_entry_offset() const;
468 // Return the size of each PLT entry.
470 plt_entry_size() const;
472 // Add any special sections for this symbol to the gc work list.
473 // For powerpc64, this adds the code section of a function
476 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
478 // Handle target specific gc actions when adding a gc reference from
479 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
480 // and DST_OFF. For powerpc64, this adds a referenc to the code
481 // section of a function descriptor.
483 do_gc_add_reference(Symbol_table
* symtab
,
485 unsigned int src_shndx
,
487 unsigned int dst_shndx
,
488 Address dst_off
) const;
492 // The class which scans relocations.
496 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
499 : issued_non_pic_error_(false)
503 get_reference_flags(unsigned int r_type
);
506 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
507 Sized_relobj_file
<size
, big_endian
>* object
,
508 unsigned int data_shndx
,
509 Output_section
* output_section
,
510 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
511 const elfcpp::Sym
<size
, big_endian
>& lsym
,
515 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
516 Sized_relobj_file
<size
, big_endian
>* object
,
517 unsigned int data_shndx
,
518 Output_section
* output_section
,
519 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
523 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
525 Sized_relobj_file
<size
, big_endian
>* ,
528 const elfcpp::Rela
<size
, big_endian
>& ,
530 const elfcpp::Sym
<size
, big_endian
>&)
534 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
536 Sized_relobj_file
<size
, big_endian
>* ,
539 const elfcpp::Rela
<size
,
541 unsigned int , Symbol
*)
546 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
547 unsigned int r_type
);
550 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
551 unsigned int r_type
, Symbol
*);
554 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
555 Target_powerpc
* target
);
558 check_non_pic(Relobj
*, unsigned int r_type
);
561 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>* object
,
562 unsigned int r_type
);
564 // Whether we have issued an error about a non-PIC compilation.
565 bool issued_non_pic_error_
;
569 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
570 Powerpc_relobj
<size
, big_endian
>* object
,
571 unsigned int *dest_shndx
);
573 // The class which implements relocation.
577 // Use 'at' branch hints when true, 'y' when false.
578 // FIXME maybe: set this with an option.
579 static const bool is_isa_v2
= true;
583 CALL_NOT_EXPECTED
= 0,
589 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
594 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
596 // FIXME: This needs to specify the location somehow.
597 gold_error(_("missing expected __tls_get_addr call"));
601 // Do a relocation. Return false if the caller should not issue
602 // any warnings about this relocation.
604 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
605 Output_section
*, size_t relnum
,
606 const elfcpp::Rela
<size
, big_endian
>&,
607 unsigned int r_type
, const Sized_symbol
<size
>*,
608 const Symbol_value
<size
>*,
610 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
613 // This is set if we should skip the next reloc, which should be a
614 // call to __tls_get_addr.
615 enum skip_tls call_tls_get_addr_
;
618 // A class which returns the size required for a relocation type,
619 // used while scanning relocs during a relocatable link.
620 class Relocatable_size_for_reloc
624 get_size_for_reloc(unsigned int, Relobj
*)
631 // Optimize the TLS relocation type based on what we know about the
632 // symbol. IS_FINAL is true if the final address of this symbol is
633 // known at link time.
635 tls::Tls_optimization
636 optimize_tls_gd(bool is_final
)
638 // If we are generating a shared library, then we can't do anything
640 if (parameters
->options().shared())
641 return tls::TLSOPT_NONE
;
644 return tls::TLSOPT_TO_IE
;
645 return tls::TLSOPT_TO_LE
;
648 tls::Tls_optimization
651 if (parameters
->options().shared())
652 return tls::TLSOPT_NONE
;
654 return tls::TLSOPT_TO_LE
;
657 tls::Tls_optimization
658 optimize_tls_ie(bool is_final
)
660 if (!is_final
|| parameters
->options().shared())
661 return tls::TLSOPT_NONE
;
663 return tls::TLSOPT_TO_LE
;
666 // Get the GOT section, creating it if necessary.
667 Output_data_got_powerpc
<size
, big_endian
>*
668 got_section(Symbol_table
*, Layout
*);
672 make_glink_section(Layout
*);
674 // Create the PLT section.
676 make_plt_section(Layout
*);
679 make_iplt_section(Layout
*);
681 // Create a PLT entry for a global symbol.
683 make_plt_entry(Layout
*, Symbol
*,
684 const elfcpp::Rela
<size
, big_endian
>&,
685 const Sized_relobj_file
<size
, big_endian
>* object
);
687 // Create a PLT entry for a local IFUNC symbol.
689 make_local_ifunc_plt_entry(Layout
*,
690 const elfcpp::Rela
<size
, big_endian
>&,
691 Sized_relobj_file
<size
, big_endian
>*);
693 // Create a GOT entry for local dynamic __tls_get_addr.
695 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
696 Sized_relobj_file
<size
, big_endian
>* object
);
699 tlsld_got_offset() const
701 return this->tlsld_got_offset_
;
704 // Get the dynamic reloc section, creating it if necessary.
706 rela_dyn_section(Layout
*);
708 // Copy a relocation against a global symbol.
710 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
711 Sized_relobj_file
<size
, big_endian
>* object
,
712 unsigned int shndx
, Output_section
* output_section
,
713 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
715 this->copy_relocs_
.copy_reloc(symtab
, layout
,
716 symtab
->get_sized_symbol
<size
>(sym
),
717 object
, shndx
, output_section
,
718 reloc
, this->rela_dyn_section(layout
));
721 // Information about this specific target which we pass to the
722 // general Target structure.
723 static Target::Target_info powerpc_info
;
725 // The types of GOT entries needed for this platform.
726 // These values are exposed to the ABI in an incremental link.
727 // Do not renumber existing values without changing the version
728 // number of the .gnu_incremental_inputs section.
732 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
733 GOT_TYPE_DTPREL
, // entry for @got@dtprel
734 GOT_TYPE_TPREL
// entry for @got@tprel
737 // The GOT output section.
738 Output_data_got_powerpc
<size
, big_endian
>* got_
;
739 // The PLT output section.
740 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
741 // The IPLT output section.
742 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
743 // The .glink output section.
744 Output_data_glink
<size
, big_endian
>* glink_
;
745 // The dynamic reloc output section.
746 Reloc_section
* rela_dyn_
;
747 // Relocs saved to avoid a COPY reloc.
748 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
749 // Space for variables copied with a COPY reloc.
750 Output_data_space
* dynbss_
;
751 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
752 unsigned int tlsld_got_offset_
;
756 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
759 true, // is_big_endian
760 elfcpp::EM_PPC
, // machine_code
761 false, // has_make_symbol
762 false, // has_resolve
763 false, // has_code_fill
764 true, // is_default_stack_executable
765 false, // can_icf_inline_merge_sections
767 "/usr/lib/ld.so.1", // dynamic_linker
768 0x10000000, // default_text_segment_address
769 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
770 4 * 1024, // common_pagesize (overridable by -z common-page-size)
771 false, // isolate_execinstr
773 elfcpp::SHN_UNDEF
, // small_common_shndx
774 elfcpp::SHN_UNDEF
, // large_common_shndx
775 0, // small_common_section_flags
776 0, // large_common_section_flags
777 NULL
, // attributes_section
778 NULL
// attributes_vendor
782 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
785 false, // is_big_endian
786 elfcpp::EM_PPC
, // machine_code
787 false, // has_make_symbol
788 false, // has_resolve
789 false, // has_code_fill
790 true, // is_default_stack_executable
791 false, // can_icf_inline_merge_sections
793 "/usr/lib/ld.so.1", // dynamic_linker
794 0x10000000, // default_text_segment_address
795 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
796 4 * 1024, // common_pagesize (overridable by -z common-page-size)
797 false, // isolate_execinstr
799 elfcpp::SHN_UNDEF
, // small_common_shndx
800 elfcpp::SHN_UNDEF
, // large_common_shndx
801 0, // small_common_section_flags
802 0, // large_common_section_flags
803 NULL
, // attributes_section
804 NULL
// attributes_vendor
808 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
811 true, // is_big_endian
812 elfcpp::EM_PPC64
, // machine_code
813 false, // has_make_symbol
814 false, // has_resolve
815 false, // has_code_fill
816 true, // is_default_stack_executable
817 false, // can_icf_inline_merge_sections
819 "/usr/lib/ld.so.1", // dynamic_linker
820 0x10000000, // default_text_segment_address
821 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
822 4 * 1024, // common_pagesize (overridable by -z common-page-size)
823 false, // isolate_execinstr
825 elfcpp::SHN_UNDEF
, // small_common_shndx
826 elfcpp::SHN_UNDEF
, // large_common_shndx
827 0, // small_common_section_flags
828 0, // large_common_section_flags
829 NULL
, // attributes_section
830 NULL
// attributes_vendor
834 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
837 false, // is_big_endian
838 elfcpp::EM_PPC64
, // machine_code
839 false, // has_make_symbol
840 false, // has_resolve
841 false, // has_code_fill
842 true, // is_default_stack_executable
843 false, // can_icf_inline_merge_sections
845 "/usr/lib/ld.so.1", // dynamic_linker
846 0x10000000, // default_text_segment_address
847 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
848 4 * 1024, // common_pagesize (overridable by -z common-page-size)
849 false, // isolate_execinstr
851 elfcpp::SHN_UNDEF
, // small_common_shndx
852 elfcpp::SHN_UNDEF
, // large_common_shndx
853 0, // small_common_section_flags
854 0, // large_common_section_flags
855 NULL
, // attributes_section
856 NULL
// attributes_vendor
860 is_branch_reloc(unsigned int r_type
)
862 return (r_type
== elfcpp::R_POWERPC_REL24
863 || r_type
== elfcpp::R_PPC_PLTREL24
864 || r_type
== elfcpp::R_PPC_LOCAL24PC
865 || r_type
== elfcpp::R_POWERPC_REL14
866 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
867 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
868 || r_type
== elfcpp::R_POWERPC_ADDR24
869 || r_type
== elfcpp::R_POWERPC_ADDR14
870 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
871 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
874 // If INSN is an opcode that may be used with an @tls operand, return
875 // the transformed insn for TLS optimisation, otherwise return 0. If
876 // REG is non-zero only match an insn with RB or RA equal to REG.
878 at_tls_transform(uint32_t insn
, unsigned int reg
)
880 if ((insn
& (0x3f << 26)) != 31 << 26)
884 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
885 rtra
= insn
& ((1 << 26) - (1 << 16));
886 else if (((insn
>> 16) & 0x1f) == reg
)
887 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
891 if ((insn
& (0x3ff << 1)) == 266 << 1)
894 else if ((insn
& (0x1f << 1)) == 23 << 1
895 && ((insn
& (0x1f << 6)) < 14 << 6
896 || ((insn
& (0x1f << 6)) >= 16 << 6
897 && (insn
& (0x1f << 6)) < 24 << 6)))
898 // load and store indexed -> dform
899 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
900 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
901 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
902 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
903 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
905 insn
= (58 << 26) | 2;
912 // Modified version of symtab.h class Symbol member
913 // Given a direct absolute or pc-relative static relocation against
914 // the global symbol, this function returns whether a dynamic relocation
919 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
921 // No dynamic relocations in a static link!
922 if (parameters
->doing_static_link())
925 // A reference to an undefined symbol from an executable should be
926 // statically resolved to 0, and does not need a dynamic relocation.
927 // This matches gnu ld behavior.
928 if (gsym
->is_undefined() && !parameters
->options().shared())
931 // A reference to an absolute symbol does not need a dynamic relocation.
932 if (gsym
->is_absolute())
935 // An absolute reference within a position-independent output file
936 // will need a dynamic relocation.
937 if ((flags
& Symbol::ABSOLUTE_REF
)
938 && parameters
->options().output_is_position_independent())
941 // A function call that can branch to a local PLT entry does not need
942 // a dynamic relocation.
943 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
946 // A reference to any PLT entry in a non-position-independent executable
947 // does not need a dynamic relocation.
948 // Except due to having function descriptors on powerpc64 we don't define
949 // functions to their plt code in an executable, so this doesn't apply.
951 && !parameters
->options().output_is_position_independent()
952 && gsym
->has_plt_offset())
955 // A reference to a symbol defined in a dynamic object or to a
956 // symbol that is preemptible will need a dynamic relocation.
957 if (gsym
->is_from_dynobj()
958 || gsym
->is_undefined()
959 || gsym
->is_preemptible())
962 // For all other cases, return FALSE.
966 // Modified version of symtab.h class Symbol member
967 // Whether we should use the PLT offset associated with a symbol for
968 // a relocation. FLAGS is a set of Reference_flags.
972 use_plt_offset(const Symbol
* gsym
, int flags
)
974 // If the symbol doesn't have a PLT offset, then naturally we
975 // don't want to use it.
976 if (!gsym
->has_plt_offset())
979 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
980 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
983 // If we are going to generate a dynamic relocation, then we will
984 // wind up using that, so no need to use the PLT entry.
985 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
988 // If the symbol is from a dynamic object, we need to use the PLT
990 if (gsym
->is_from_dynobj())
993 // If we are generating a shared object, and gsym symbol is
994 // undefined or preemptible, we need to use the PLT entry.
995 if (parameters
->options().shared()
996 && (gsym
->is_undefined() || gsym
->is_preemptible()))
999 // If gsym is a call to a weak undefined symbol, we need to use
1000 // the PLT entry; the symbol may be defined by a library loaded
1002 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
1005 // Otherwise we can use the regular definition.
1009 template<int size
, bool big_endian
>
1010 class Powerpc_relocate_functions
1027 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1028 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1030 template<int valsize
>
1032 has_overflow_signed(Address value
)
1034 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1035 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1036 limit
<<= ((valsize
- 1) >> 1);
1037 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1038 return value
+ limit
> (limit
<< 1) - 1;
1041 template<int valsize
>
1043 has_overflow_bitfield(Address value
)
1045 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1046 limit
<<= ((valsize
- 1) >> 1);
1047 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1048 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
1051 template<int valsize
>
1052 static inline Status
1053 overflowed(Address value
, Overflow_check overflow
)
1055 if (overflow
== CHECK_SIGNED
)
1057 if (has_overflow_signed
<valsize
>(value
))
1058 return STATUS_OVERFLOW
;
1060 else if (overflow
== CHECK_BITFIELD
)
1062 if (has_overflow_bitfield
<valsize
>(value
))
1063 return STATUS_OVERFLOW
;
1068 // Do a simple RELA relocation
1069 template<int valsize
>
1070 static inline Status
1071 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1073 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1074 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1075 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1076 return overflowed
<valsize
>(value
, overflow
);
1079 template<int valsize
>
1080 static inline Status
1081 rela(unsigned char* view
,
1082 unsigned int right_shift
,
1083 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1085 Overflow_check overflow
)
1087 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1088 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1089 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1090 Valtype reloc
= value
>> right_shift
;
1093 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1094 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1097 // Do a simple RELA relocation, unaligned.
1098 template<int valsize
>
1099 static inline Status
1100 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1102 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1103 return overflowed
<valsize
>(value
, overflow
);
1106 template<int valsize
>
1107 static inline Status
1108 rela_ua(unsigned char* view
,
1109 unsigned int right_shift
,
1110 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1112 Overflow_check overflow
)
1114 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1116 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1117 Valtype reloc
= value
>> right_shift
;
1120 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1121 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1125 // R_PPC64_ADDR64: (Symbol + Addend)
1127 addr64(unsigned char* view
, Address value
)
1128 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1130 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1132 addr64_u(unsigned char* view
, Address value
)
1133 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1135 // R_POWERPC_ADDR32: (Symbol + Addend)
1136 static inline Status
1137 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1138 { return This::template rela
<32>(view
, value
, overflow
); }
1140 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1141 static inline Status
1142 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1143 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1145 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1146 static inline Status
1147 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1149 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1150 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1151 stat
= STATUS_OVERFLOW
;
1155 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1156 static inline Status
1157 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1158 { return This::template rela
<16>(view
, value
, overflow
); }
1160 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1161 static inline Status
1162 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1163 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1165 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1166 static inline Status
1167 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1169 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1170 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1171 stat
= STATUS_OVERFLOW
;
1175 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1177 addr16_hi(unsigned char* view
, Address value
)
1178 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1180 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1182 addr16_ha(unsigned char* view
, Address value
)
1183 { This::addr16_hi(view
, value
+ 0x8000); }
1185 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1187 addr16_hi2(unsigned char* view
, Address value
)
1188 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1190 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1192 addr16_ha2(unsigned char* view
, Address value
)
1193 { This::addr16_hi2(view
, value
+ 0x8000); }
1195 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1197 addr16_hi3(unsigned char* view
, Address value
)
1198 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1200 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1202 addr16_ha3(unsigned char* view
, Address value
)
1203 { This::addr16_hi3(view
, value
+ 0x8000); }
1205 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1206 static inline Status
1207 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1209 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1210 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1211 stat
= STATUS_OVERFLOW
;
1216 // Stash away the index of .got2 or .opd in a relocatable object, if
1217 // such a section exists.
1219 template<int size
, bool big_endian
>
1221 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1222 Read_symbols_data
* sd
)
1224 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1225 const unsigned char* namesu
= sd
->section_names
->data();
1226 const char* names
= reinterpret_cast<const char*>(namesu
);
1227 section_size_type names_size
= sd
->section_names_size
;
1228 const unsigned char* s
;
1230 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1231 names
, names_size
, NULL
);
1234 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1235 this->special_
= ndx
;
1237 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1240 // Examine .rela.opd to build info about function entry points.
1242 template<int size
, bool big_endian
>
1244 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1246 const unsigned char* prelocs
,
1247 const unsigned char* plocal_syms
)
1251 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1253 const int reloc_size
1254 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1255 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1256 Address expected_off
= 0;
1257 bool regular
= true;
1258 unsigned int opd_ent_size
= 0;
1260 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1262 Reltype
reloc(prelocs
);
1263 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1264 = reloc
.get_r_info();
1265 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1266 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1268 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1269 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1272 if (r_sym
< this->local_symbol_count())
1274 typename
elfcpp::Sym
<size
, big_endian
>
1275 lsym(plocal_syms
+ r_sym
* sym_size
);
1276 shndx
= lsym
.get_st_shndx();
1277 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1278 value
= lsym
.get_st_value();
1281 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1283 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1284 value
+ reloc
.get_r_addend());
1287 expected_off
= reloc
.get_r_offset();
1288 opd_ent_size
= expected_off
;
1290 else if (expected_off
!= reloc
.get_r_offset())
1292 expected_off
+= opd_ent_size
;
1294 else if (r_type
== elfcpp::R_PPC64_TOC
)
1296 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1301 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1302 this->name().c_str(), r_type
);
1306 if (reloc_count
<= 2)
1307 opd_ent_size
= this->section_size(this->opd_shndx());
1308 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1312 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1313 this->name().c_str());
1319 template<int size
, bool big_endian
>
1321 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1323 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1326 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1327 p
!= rd
->relocs
.end();
1330 if (p
->data_shndx
== this->opd_shndx())
1332 uint64_t opd_size
= this->section_size(this->opd_shndx());
1333 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1336 this->init_opd(opd_size
);
1337 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1338 rd
->local_symbols
->data());
1346 // Set up PowerPC target specific relobj.
1348 template<int size
, bool big_endian
>
1350 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1351 const std::string
& name
,
1352 Input_file
* input_file
,
1353 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1355 int et
= ehdr
.get_e_type();
1356 // ET_EXEC files are valid input for --just-symbols/-R,
1357 // and we treat them as relocatable objects.
1358 if (et
== elfcpp::ET_REL
1359 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1361 Powerpc_relobj
<size
, big_endian
>* obj
=
1362 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1366 else if (et
== elfcpp::ET_DYN
)
1368 Sized_dynobj
<size
, big_endian
>* obj
=
1369 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1375 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1380 template<int size
, bool big_endian
>
1381 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1384 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1385 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1387 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1388 : Output_data_got
<size
, big_endian
>(),
1389 symtab_(symtab
), layout_(layout
),
1390 header_ent_cnt_(size
== 32 ? 3 : 1),
1391 header_index_(size
== 32 ? 0x2000 : 0)
1396 // Create a new GOT entry and return its offset.
1398 add_got_entry(Got_entry got_entry
)
1400 this->reserve_ent();
1401 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1404 // Create a pair of new GOT entries and return the offset of the first.
1406 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1408 this->reserve_ent(2);
1409 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1414 add_constant_pair(Valtype c1
, Valtype c2
)
1416 this->reserve_ent(2);
1417 unsigned int got_offset
= this->add_constant(c1
);
1418 this->add_constant(c2
);
1422 // Offset of _GLOBAL_OFFSET_TABLE_.
1426 return this->got_offset(this->header_index_
);
1429 // Offset of base used to access the GOT/TOC.
1430 // The got/toc pointer reg will be set to this value.
1431 typename
elfcpp::Elf_types
<size
>::Elf_Off
1432 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1435 return this->g_o_t();
1437 return (this->output_section()->address()
1438 + object
->toc_base_offset()
1442 // Ensure our GOT has a header.
1444 set_final_data_size()
1446 if (this->header_ent_cnt_
!= 0)
1447 this->make_header();
1448 Output_data_got
<size
, big_endian
>::set_final_data_size();
1451 // First word of GOT header needs some values that are not
1452 // handled by Output_data_got so poke them in here.
1453 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1455 do_write(Output_file
* of
)
1458 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
1459 val
= this->layout_
->dynamic_section()->address();
1461 val
= this->output_section()->address() + 0x8000;
1462 this->replace_constant(this->header_index_
, val
);
1463 Output_data_got
<size
, big_endian
>::do_write(of
);
1468 reserve_ent(unsigned int cnt
= 1)
1470 if (this->header_ent_cnt_
== 0)
1472 if (this->num_entries() + cnt
> this->header_index_
)
1473 this->make_header();
1479 this->header_ent_cnt_
= 0;
1480 this->header_index_
= this->num_entries();
1483 Output_data_got
<size
, big_endian
>::add_constant(0);
1484 Output_data_got
<size
, big_endian
>::add_constant(0);
1485 Output_data_got
<size
, big_endian
>::add_constant(0);
1487 // Define _GLOBAL_OFFSET_TABLE_ at the header
1488 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1489 Symbol_table::PREDEFINED
,
1490 this, this->g_o_t(), 0,
1497 Output_data_got
<size
, big_endian
>::add_constant(0);
1500 // Stashed pointers.
1501 Symbol_table
* symtab_
;
1505 unsigned int header_ent_cnt_
;
1506 // GOT header index.
1507 unsigned int header_index_
;
1510 // Get the GOT section, creating it if necessary.
1512 template<int size
, bool big_endian
>
1513 Output_data_got_powerpc
<size
, big_endian
>*
1514 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1517 if (this->got_
== NULL
)
1519 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1522 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1524 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1525 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1526 this->got_
, ORDER_DATA
, false);
1532 // Get the dynamic reloc section, creating it if necessary.
1534 template<int size
, bool big_endian
>
1535 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1536 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1538 if (this->rela_dyn_
== NULL
)
1540 gold_assert(layout
!= NULL
);
1541 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1542 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1543 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1544 ORDER_DYNAMIC_RELOCS
, false);
1546 return this->rela_dyn_
;
1549 // A class to handle the PLT data.
1551 template<int size
, bool big_endian
>
1552 class Output_data_plt_powerpc
: public Output_section_data_build
1555 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1556 size
, big_endian
> Reloc_section
;
1558 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
1559 Reloc_section
* plt_rel
,
1560 unsigned int reserved_size
,
1562 : Output_section_data_build(size
== 32 ? 4 : 8),
1565 initial_plt_entry_size_(reserved_size
),
1569 // Add an entry to the PLT.
1574 add_ifunc_entry(Symbol
*);
1577 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
1579 // Return the .rela.plt section data.
1586 // Return the number of PLT entries.
1590 return ((this->current_data_size() - this->initial_plt_entry_size_
)
1594 // Return the offset of the first non-reserved PLT entry.
1596 first_plt_entry_offset()
1597 { return this->initial_plt_entry_size_
; }
1599 // Return the size of a PLT entry.
1601 get_plt_entry_size()
1602 { return plt_entry_size
; }
1606 do_adjust_output_section(Output_section
* os
)
1611 // Write to a map file.
1613 do_print_to_mapfile(Mapfile
* mapfile
) const
1614 { mapfile
->print_output_data(this, this->name_
); }
1617 // The size of an entry in the PLT.
1618 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1620 // Write out the PLT data.
1622 do_write(Output_file
*);
1624 // The reloc section.
1625 Reloc_section
* rel_
;
1626 // Allows access to .glink for do_write.
1627 Target_powerpc
<size
, big_endian
>* targ_
;
1628 // The size of the first reserved entry.
1629 int initial_plt_entry_size_
;
1630 // What to report in map file.
1634 // Add an entry to the PLT.
1636 template<int size
, bool big_endian
>
1638 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1640 if (!gsym
->has_plt_offset())
1642 off_t off
= this->current_data_size();
1644 off
+= this->first_plt_entry_offset();
1645 gsym
->set_plt_offset(off
);
1646 gsym
->set_needs_dynsym_entry();
1647 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
1648 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
1649 off
+= plt_entry_size
;
1650 this->set_current_data_size(off
);
1654 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
1656 template<int size
, bool big_endian
>
1658 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
1660 if (!gsym
->has_plt_offset())
1662 off_t off
= this->current_data_size();
1663 gsym
->set_plt_offset(off
);
1664 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1666 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1667 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
1668 off
+= plt_entry_size
;
1669 this->set_current_data_size(off
);
1673 // Add an entry for a local ifunc symbol to the IPLT.
1675 template<int size
, bool big_endian
>
1677 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
1678 Sized_relobj_file
<size
, big_endian
>* relobj
,
1679 unsigned int local_sym_index
)
1681 if (!relobj
->local_has_plt_offset(local_sym_index
))
1683 off_t off
= this->current_data_size();
1684 relobj
->set_local_plt_offset(local_sym_index
, off
);
1685 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
1687 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
1688 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
1690 off
+= plt_entry_size
;
1691 this->set_current_data_size(off
);
1695 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1696 static const uint32_t add_3_3_2
= 0x7c631214;
1697 static const uint32_t add_3_3_13
= 0x7c636a14;
1698 static const uint32_t add_11_0_11
= 0x7d605a14;
1699 static const uint32_t add_12_2_11
= 0x7d825a14;
1700 static const uint32_t addi_11_11
= 0x396b0000;
1701 static const uint32_t addi_12_12
= 0x398c0000;
1702 static const uint32_t addi_2_2
= 0x38420000;
1703 static const uint32_t addi_3_2
= 0x38620000;
1704 static const uint32_t addi_3_3
= 0x38630000;
1705 static const uint32_t addis_0_2
= 0x3c020000;
1706 static const uint32_t addis_0_13
= 0x3c0d0000;
1707 static const uint32_t addis_11_11
= 0x3d6b0000;
1708 static const uint32_t addis_11_30
= 0x3d7e0000;
1709 static const uint32_t addis_12_12
= 0x3d8c0000;
1710 static const uint32_t addis_12_2
= 0x3d820000;
1711 static const uint32_t addis_3_2
= 0x3c620000;
1712 static const uint32_t addis_3_13
= 0x3c6d0000;
1713 static const uint32_t b
= 0x48000000;
1714 static const uint32_t bcl_20_31
= 0x429f0005;
1715 static const uint32_t bctr
= 0x4e800420;
1716 static const uint32_t blrl
= 0x4e800021;
1717 static const uint32_t cror_15_15_15
= 0x4def7b82;
1718 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1719 static const uint32_t ld_11_12
= 0xe96c0000;
1720 static const uint32_t ld_11_2
= 0xe9620000;
1721 static const uint32_t ld_2_1
= 0xe8410000;
1722 static const uint32_t ld_2_11
= 0xe84b0000;
1723 static const uint32_t ld_2_12
= 0xe84c0000;
1724 static const uint32_t ld_2_2
= 0xe8420000;
1725 static const uint32_t li_0_0
= 0x38000000;
1726 static const uint32_t lis_0_0
= 0x3c000000;
1727 static const uint32_t lis_11
= 0x3d600000;
1728 static const uint32_t lis_12
= 0x3d800000;
1729 static const uint32_t lwz_0_12
= 0x800c0000;
1730 static const uint32_t lwz_11_11
= 0x816b0000;
1731 static const uint32_t lwz_11_30
= 0x817e0000;
1732 static const uint32_t lwz_12_12
= 0x818c0000;
1733 static const uint32_t lwzu_0_12
= 0x840c0000;
1734 static const uint32_t mflr_0
= 0x7c0802a6;
1735 static const uint32_t mflr_11
= 0x7d6802a6;
1736 static const uint32_t mflr_12
= 0x7d8802a6;
1737 static const uint32_t mtctr_0
= 0x7c0903a6;
1738 static const uint32_t mtctr_11
= 0x7d6903a6;
1739 static const uint32_t mtlr_0
= 0x7c0803a6;
1740 static const uint32_t mtlr_12
= 0x7d8803a6;
1741 static const uint32_t nop
= 0x60000000;
1742 static const uint32_t ori_0_0_0
= 0x60000000;
1743 static const uint32_t std_2_1
= 0xf8410000;
1744 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1746 // Write out the PLT.
1748 template<int size
, bool big_endian
>
1750 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1754 const off_t offset
= this->offset();
1755 const section_size_type oview_size
1756 = convert_to_section_size_type(this->data_size());
1757 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1758 unsigned char* pov
= oview
;
1759 unsigned char* endpov
= oview
+ oview_size
;
1761 // The address of the .glink branch table
1762 const Output_data_glink
<size
, big_endian
>* glink
1763 = this->targ_
->glink_section();
1764 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1765 = glink
->address() + glink
->pltresolve();
1767 while (pov
< endpov
)
1769 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1774 of
->write_output_view(offset
, oview_size
, oview
);
1778 // Create the PLT section.
1780 template<int size
, bool big_endian
>
1782 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1784 if (this->plt_
== NULL
)
1786 if (this->glink_
== NULL
)
1787 make_glink_section(layout
);
1789 // Ensure that .rela.dyn always appears before .rela.plt This is
1790 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1791 // needs to include .rela.plt in it's range.
1792 this->rela_dyn_section(layout
);
1794 Reloc_section
* plt_rel
= new Reloc_section(false);
1795 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1796 elfcpp::SHF_ALLOC
, plt_rel
,
1797 ORDER_DYNAMIC_PLT_RELOCS
, false);
1799 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
1800 size
== 32 ? 0 : 24,
1802 layout
->add_output_section_data(".plt",
1804 ? elfcpp::SHT_PROGBITS
1805 : elfcpp::SHT_NOBITS
),
1806 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1815 // Create the IPLT section.
1817 template<int size
, bool big_endian
>
1819 Target_powerpc
<size
, big_endian
>::make_iplt_section(Layout
* layout
)
1821 if (this->iplt_
== NULL
)
1823 this->make_plt_section(layout
);
1825 Reloc_section
* iplt_rel
= new Reloc_section(false);
1826 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
1828 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
1830 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
1834 // A class to handle .glink.
1836 template<int size
, bool big_endian
>
1837 class Output_data_glink
: public Output_section_data
1840 static const int pltresolve_size
= 16*4;
1842 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1846 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1848 const elfcpp::Rela
<size
, big_endian
>&);
1851 add_entry(const Sized_relobj_file
<size
, big_endian
>*,
1853 const elfcpp::Rela
<size
, big_endian
>&);
1856 find_entry(const Symbol
*) const;
1859 find_entry(const Sized_relobj_file
<size
, big_endian
>*, unsigned int) const;
1862 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1864 const elfcpp::Rela
<size
, big_endian
>&) const;
1867 find_entry(const Sized_relobj_file
<size
, big_endian
>*,
1869 const elfcpp::Rela
<size
, big_endian
>&) const;
1872 glink_entry_size() const
1877 // FIXME: We should be using multiple glink sections for
1878 // stubs to support > 33M applications.
1885 return this->pltresolve_
;
1889 // Write to a map file.
1891 do_print_to_mapfile(Mapfile
* mapfile
) const
1892 { mapfile
->print_output_data(this, _("** glink")); }
1896 set_final_data_size();
1900 do_write(Output_file
*);
1905 Glink_sym_ent(const Symbol
* sym
)
1906 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1909 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1910 unsigned int locsym_index
)
1911 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1914 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1916 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1917 : sym_(sym
), object_(0), addend_(0), locsym_(0)
1920 this->addend_
= reloc
.get_r_addend();
1921 else if (parameters
->options().output_is_position_independent()
1922 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1923 == elfcpp::R_PPC_PLTREL24
))
1925 this->addend_
= reloc
.get_r_addend();
1926 if (this->addend_
>= 32768)
1927 this->object_
= object
;
1931 Glink_sym_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
1932 unsigned int locsym_index
,
1933 const elfcpp::Rela
<size
, big_endian
>& reloc
)
1934 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
1937 this->addend_
= reloc
.get_r_addend();
1938 else if (parameters
->options().output_is_position_independent()
1939 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1940 == elfcpp::R_PPC_PLTREL24
))
1941 this->addend_
= reloc
.get_r_addend();
1944 bool operator==(const Glink_sym_ent
& that
) const
1946 return (this->sym_
== that
.sym_
1947 && this->object_
== that
.object_
1948 && this->addend_
== that
.addend_
1949 && this->locsym_
== that
.locsym_
);
1953 const Sized_relobj_file
<size
, big_endian
>* object_
;
1954 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
1955 unsigned int locsym_
;
1958 class Glink_sym_ent_hash
1961 size_t operator()(const Glink_sym_ent
& ent
) const
1963 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1964 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1970 // Map sym/object/addend to index.
1971 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1972 Glink_sym_ent_hash
> Glink_entries
;
1973 Glink_entries glink_entries_
;
1975 // Offset of pltresolve stub (actually, branch table for 32-bit)
1978 // Allows access to .got and .plt for do_write.
1979 Target_powerpc
<size
, big_endian
>* targ_
;
1982 // Create the glink section.
1984 template<int size
, bool big_endian
>
1985 Output_data_glink
<size
, big_endian
>::Output_data_glink(
1986 Target_powerpc
<size
, big_endian
>* targ
)
1987 : Output_section_data(16),
1988 pltresolve_(0), targ_(targ
)
1992 // Add an entry to glink, if we do not already have one for this
1993 // sym/object/addend combo.
1995 template<int size
, bool big_endian
>
1997 Output_data_glink
<size
, big_endian
>::add_entry(
1998 const Sized_relobj_file
<size
, big_endian
>* object
,
2000 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2002 Glink_sym_ent
ent(object
, gsym
, reloc
);
2003 unsigned int indx
= this->glink_entries_
.size();
2004 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2007 template<int size
, bool big_endian
>
2009 Output_data_glink
<size
, big_endian
>::add_entry(
2010 const Sized_relobj_file
<size
, big_endian
>* object
,
2011 unsigned int locsym_index
,
2012 const elfcpp::Rela
<size
, big_endian
>& reloc
)
2014 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2015 unsigned int indx
= this->glink_entries_
.size();
2016 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
2019 template<int size
, bool big_endian
>
2021 Output_data_glink
<size
, big_endian
>::find_entry(
2022 const Sized_relobj_file
<size
, big_endian
>* object
,
2024 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2026 Glink_sym_ent
ent(object
, gsym
, reloc
);
2027 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2028 gold_assert(p
!= this->glink_entries_
.end());
2032 template<int size
, bool big_endian
>
2034 Output_data_glink
<size
, big_endian
>::find_entry(const Symbol
* gsym
) const
2036 Glink_sym_ent
ent(gsym
);
2037 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2038 gold_assert(p
!= this->glink_entries_
.end());
2042 template<int size
, bool big_endian
>
2044 Output_data_glink
<size
, big_endian
>::find_entry(
2045 const Sized_relobj_file
<size
, big_endian
>* object
,
2046 unsigned int locsym_index
,
2047 const elfcpp::Rela
<size
, big_endian
>& reloc
) const
2049 Glink_sym_ent
ent(object
, locsym_index
, reloc
);
2050 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2051 gold_assert(p
!= this->glink_entries_
.end());
2055 template<int size
, bool big_endian
>
2057 Output_data_glink
<size
, big_endian
>::find_entry(
2058 const Sized_relobj_file
<size
, big_endian
>* object
,
2059 unsigned int locsym_index
) const
2061 Glink_sym_ent
ent(object
, locsym_index
);
2062 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
2063 gold_assert(p
!= this->glink_entries_
.end());
2067 template<int size
, bool big_endian
>
2069 Output_data_glink
<size
, big_endian
>::set_final_data_size()
2071 unsigned int count
= this->glink_entries_
.size();
2072 off_t total
= count
;
2079 this->pltresolve_
= total
;
2081 // space for branch table
2082 total
+= 4 * (count
- 1);
2084 total
+= -total
& 15;
2085 total
+= this->pltresolve_size
;
2090 this->pltresolve_
= total
;
2091 total
+= this->pltresolve_size
;
2093 // space for branch table
2096 total
+= 4 * (count
- 0x8000);
2100 this->set_data_size(total
);
2103 static inline uint32_t
2109 static inline uint32_t
2115 static inline uint32_t
2118 return hi(a
+ 0x8000);
2121 template<bool big_endian
>
2123 write_insn(unsigned char* p
, uint32_t v
)
2125 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
2128 // Write out .glink.
2130 template<int size
, bool big_endian
>
2132 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
2134 const off_t off
= this->offset();
2135 const section_size_type oview_size
=
2136 convert_to_section_size_type(this->data_size());
2137 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
2140 // The base address of the .plt section.
2141 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2142 static const Address invalid_address
= static_cast<Address
>(0) - 1;
2143 Address plt_base
= this->targ_
->plt_section()->address();
2144 Address iplt_base
= invalid_address
;
2146 const Output_data_got_powerpc
<size
, big_endian
>* got
2147 = this->targ_
->got_section();
2151 Address got_os_addr
= got
->output_section()->address();
2153 // Write out call stubs.
2154 typename
Glink_entries::const_iterator g
;
2155 for (g
= this->glink_entries_
.begin();
2156 g
!= this->glink_entries_
.end();
2161 const Symbol
* gsym
= g
->first
.sym_
;
2164 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2165 && gsym
->can_use_relative_reloc(false));
2166 plt_addr
= gsym
->plt_offset();
2171 const Sized_relobj_file
<size
, big_endian
>* relobj
2173 unsigned int local_sym_index
= g
->first
.locsym_
;
2174 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2178 if (iplt_base
== invalid_address
)
2179 iplt_base
= this->targ_
->iplt_section()->address();
2180 plt_addr
+= iplt_base
;
2183 plt_addr
+= plt_base
;
2184 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2185 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2186 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
2187 Address pltoff
= plt_addr
- got_addr
;
2189 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
2190 gold_error(_("%s: linkage table error against `%s'"),
2191 g
->first
.object_
->name().c_str(),
2192 g
->first
.sym_
->demangled_name().c_str());
2194 p
= oview
+ g
->second
* this->glink_entry_size();
2195 if (ha(pltoff
) != 0)
2197 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
2198 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2199 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
2200 if (ha(pltoff
+ 16) != ha(pltoff
))
2202 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
2205 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2206 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
2207 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
2208 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2212 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
2213 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
2214 if (ha(pltoff
+ 16) != ha(pltoff
))
2216 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
2219 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2220 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
2221 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
2222 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2226 // Write pltresolve stub.
2227 p
= oview
+ this->pltresolve_
;
2228 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
2229 Address pltoff
= plt_base
- after_bcl
;
2231 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
2233 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
2234 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
2235 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
2236 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
2237 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
2238 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
2239 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
2240 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
2241 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
2242 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
2243 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
2244 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
2245 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2247 // Write lazy link call stubs.
2249 while (p
< oview
+ oview_size
)
2253 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
2257 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
2258 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
2260 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
2261 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
2267 // The address of _GLOBAL_OFFSET_TABLE_.
2268 Address g_o_t
= got
->address() + got
->g_o_t();
2270 // Write out call stubs.
2271 typename
Glink_entries::const_iterator g
;
2272 for (g
= this->glink_entries_
.begin();
2273 g
!= this->glink_entries_
.end();
2278 const Symbol
* gsym
= g
->first
.sym_
;
2281 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
2282 && gsym
->can_use_relative_reloc(false));
2283 plt_addr
= gsym
->plt_offset();
2288 const Sized_relobj_file
<size
, big_endian
>* relobj
2290 unsigned int local_sym_index
= g
->first
.locsym_
;
2291 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
2295 if (iplt_base
== invalid_address
)
2296 iplt_base
= this->targ_
->iplt_section()->address();
2297 plt_addr
+= iplt_base
;
2300 plt_addr
+= plt_base
;
2302 p
= oview
+ g
->second
* this->glink_entry_size();
2303 if (parameters
->options().output_is_position_independent())
2306 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
2307 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
2308 if (object
!= NULL
&& g
->first
.addend_
>= 32768)
2310 unsigned int got2
= object
->got2_shndx();
2311 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
2312 gold_assert(got_addr
!= invalid_address
);
2313 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
2314 + g
->first
.addend_
);
2319 Address pltoff
= plt_addr
- got_addr
;
2320 if (ha(pltoff
) == 0)
2322 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
2323 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
2324 write_insn
<big_endian
>(p
+ 8, bctr
);
2328 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
2329 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
2330 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2331 write_insn
<big_endian
>(p
+ 12, bctr
);
2336 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
2337 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
2338 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
2339 write_insn
<big_endian
>(p
+ 12, bctr
);
2343 // Write out pltresolve branch table.
2344 p
= oview
+ this->pltresolve_
;
2345 unsigned int the_end
= oview_size
- this->pltresolve_size
;
2346 unsigned char* end_p
= oview
+ the_end
;
2347 while (p
< end_p
- 8 * 4)
2348 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
2350 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2352 // Write out pltresolve call stub.
2353 if (parameters
->options().output_is_position_independent())
2355 Address res0_off
= this->pltresolve_
;
2356 Address after_bcl_off
= the_end
+ 12;
2357 Address bcl_res0
= after_bcl_off
- res0_off
;
2359 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2360 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2361 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2362 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2363 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2364 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2365 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2367 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2369 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2370 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2372 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2373 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2377 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2378 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2380 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2381 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2382 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2383 write_insn
<big_endian
>(p
+ 52, bctr
);
2384 write_insn
<big_endian
>(p
+ 56, nop
);
2385 write_insn
<big_endian
>(p
+ 60, nop
);
2389 Address res0
= this->pltresolve_
+ this->address();
2391 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2392 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2393 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2394 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2396 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2397 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2398 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2399 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2400 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2401 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2403 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2404 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2405 write_insn
<big_endian
>(p
+ 32, bctr
);
2406 write_insn
<big_endian
>(p
+ 36, nop
);
2407 write_insn
<big_endian
>(p
+ 40, nop
);
2408 write_insn
<big_endian
>(p
+ 44, nop
);
2409 write_insn
<big_endian
>(p
+ 48, nop
);
2410 write_insn
<big_endian
>(p
+ 52, nop
);
2411 write_insn
<big_endian
>(p
+ 56, nop
);
2412 write_insn
<big_endian
>(p
+ 60, nop
);
2417 of
->write_output_view(off
, oview_size
, oview
);
2420 // Create the glink section.
2422 template<int size
, bool big_endian
>
2424 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2426 if (this->glink_
== NULL
)
2428 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2429 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2430 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2431 this->glink_
, ORDER_TEXT
, false);
2435 // Create a PLT entry for a global symbol.
2437 template<int size
, bool big_endian
>
2439 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2442 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2443 const Sized_relobj_file
<size
, big_endian
>* object
)
2445 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
2446 && gsym
->can_use_relative_reloc(false))
2448 if (this->iplt_
== NULL
)
2449 this->make_iplt_section(layout
);
2450 this->iplt_
->add_ifunc_entry(gsym
);
2454 if (this->plt_
== NULL
)
2455 this->make_plt_section(layout
);
2456 this->plt_
->add_entry(gsym
);
2458 this->glink_
->add_entry(object
, gsym
, reloc
);
2461 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
2463 template<int size
, bool big_endian
>
2465 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
2467 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2468 Sized_relobj_file
<size
, big_endian
>* relobj
)
2470 if (this->iplt_
== NULL
)
2471 this->make_iplt_section(layout
);
2472 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2473 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
2474 this->glink_
->add_entry(relobj
, r_sym
, reloc
);
2477 // Return the number of entries in the PLT.
2479 template<int size
, bool big_endian
>
2481 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2483 if (this->plt_
== NULL
)
2485 unsigned int count
= this->plt_
->entry_count();
2486 if (this->iplt_
!= NULL
)
2487 count
+= this->iplt_
->entry_count();
2491 // Return the offset of the first non-reserved PLT entry.
2493 template<int size
, bool big_endian
>
2495 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2497 return this->plt_
->first_plt_entry_offset();
2500 // Return the size of each PLT entry.
2502 template<int size
, bool big_endian
>
2504 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2506 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2509 // Create a GOT entry for local dynamic __tls_get_addr calls.
2511 template<int size
, bool big_endian
>
2513 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2514 Symbol_table
* symtab
,
2516 Sized_relobj_file
<size
, big_endian
>* object
)
2518 if (this->tlsld_got_offset_
== -1U)
2520 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2521 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2522 Output_data_got_powerpc
<size
, big_endian
>* got
2523 = this->got_section(symtab
, layout
);
2524 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2525 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2527 this->tlsld_got_offset_
= got_offset
;
2529 return this->tlsld_got_offset_
;
2532 // Get the Reference_flags for a particular relocation.
2534 template<int size
, bool big_endian
>
2536 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2540 case elfcpp::R_POWERPC_NONE
:
2541 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2542 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2543 case elfcpp::R_PPC64_TOC
:
2544 // No symbol reference.
2547 case elfcpp::R_PPC64_ADDR64
:
2548 case elfcpp::R_PPC64_UADDR64
:
2549 case elfcpp::R_POWERPC_ADDR32
:
2550 case elfcpp::R_POWERPC_UADDR32
:
2551 case elfcpp::R_POWERPC_ADDR16
:
2552 case elfcpp::R_POWERPC_UADDR16
:
2553 case elfcpp::R_POWERPC_ADDR16_LO
:
2554 case elfcpp::R_POWERPC_ADDR16_HI
:
2555 case elfcpp::R_POWERPC_ADDR16_HA
:
2556 return Symbol::ABSOLUTE_REF
;
2558 case elfcpp::R_POWERPC_ADDR24
:
2559 case elfcpp::R_POWERPC_ADDR14
:
2560 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2561 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2562 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2564 case elfcpp::R_PPC64_REL64
:
2565 case elfcpp::R_POWERPC_REL32
:
2566 case elfcpp::R_PPC_LOCAL24PC
:
2567 case elfcpp::R_POWERPC_REL16
:
2568 case elfcpp::R_POWERPC_REL16_LO
:
2569 case elfcpp::R_POWERPC_REL16_HI
:
2570 case elfcpp::R_POWERPC_REL16_HA
:
2571 return Symbol::RELATIVE_REF
;
2573 case elfcpp::R_POWERPC_REL24
:
2574 case elfcpp::R_PPC_PLTREL24
:
2575 case elfcpp::R_POWERPC_REL14
:
2576 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2577 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2578 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2580 case elfcpp::R_POWERPC_GOT16
:
2581 case elfcpp::R_POWERPC_GOT16_LO
:
2582 case elfcpp::R_POWERPC_GOT16_HI
:
2583 case elfcpp::R_POWERPC_GOT16_HA
:
2584 case elfcpp::R_PPC64_GOT16_DS
:
2585 case elfcpp::R_PPC64_GOT16_LO_DS
:
2586 case elfcpp::R_PPC64_TOC16
:
2587 case elfcpp::R_PPC64_TOC16_LO
:
2588 case elfcpp::R_PPC64_TOC16_HI
:
2589 case elfcpp::R_PPC64_TOC16_HA
:
2590 case elfcpp::R_PPC64_TOC16_DS
:
2591 case elfcpp::R_PPC64_TOC16_LO_DS
:
2593 return Symbol::ABSOLUTE_REF
;
2595 case elfcpp::R_POWERPC_GOT_TPREL16
:
2596 case elfcpp::R_POWERPC_TLS
:
2597 return Symbol::TLS_REF
;
2599 case elfcpp::R_POWERPC_COPY
:
2600 case elfcpp::R_POWERPC_GLOB_DAT
:
2601 case elfcpp::R_POWERPC_JMP_SLOT
:
2602 case elfcpp::R_POWERPC_RELATIVE
:
2603 case elfcpp::R_POWERPC_DTPMOD
:
2605 // Not expected. We will give an error later.
2610 // Report an unsupported relocation against a local symbol.
2612 template<int size
, bool big_endian
>
2614 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2615 Sized_relobj_file
<size
, big_endian
>* object
,
2616 unsigned int r_type
)
2618 gold_error(_("%s: unsupported reloc %u against local symbol"),
2619 object
->name().c_str(), r_type
);
2622 // We are about to emit a dynamic relocation of type R_TYPE. If the
2623 // dynamic linker does not support it, issue an error.
2625 template<int size
, bool big_endian
>
2627 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2628 unsigned int r_type
)
2630 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
2632 // These are the relocation types supported by glibc for both 32-bit
2633 // and 64-bit powerpc.
2636 case elfcpp::R_POWERPC_NONE
:
2637 case elfcpp::R_POWERPC_RELATIVE
:
2638 case elfcpp::R_POWERPC_GLOB_DAT
:
2639 case elfcpp::R_POWERPC_DTPMOD
:
2640 case elfcpp::R_POWERPC_DTPREL
:
2641 case elfcpp::R_POWERPC_TPREL
:
2642 case elfcpp::R_POWERPC_JMP_SLOT
:
2643 case elfcpp::R_POWERPC_COPY
:
2644 case elfcpp::R_POWERPC_IRELATIVE
:
2645 case elfcpp::R_POWERPC_ADDR32
:
2646 case elfcpp::R_POWERPC_UADDR32
:
2647 case elfcpp::R_POWERPC_ADDR24
:
2648 case elfcpp::R_POWERPC_ADDR16
:
2649 case elfcpp::R_POWERPC_UADDR16
:
2650 case elfcpp::R_POWERPC_ADDR16_LO
:
2651 case elfcpp::R_POWERPC_ADDR16_HI
:
2652 case elfcpp::R_POWERPC_ADDR16_HA
:
2653 case elfcpp::R_POWERPC_ADDR14
:
2654 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2655 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2656 case elfcpp::R_POWERPC_REL32
:
2657 case elfcpp::R_POWERPC_REL24
:
2658 case elfcpp::R_POWERPC_TPREL16
:
2659 case elfcpp::R_POWERPC_TPREL16_LO
:
2660 case elfcpp::R_POWERPC_TPREL16_HI
:
2661 case elfcpp::R_POWERPC_TPREL16_HA
:
2672 // These are the relocation types supported only on 64-bit.
2673 case elfcpp::R_PPC64_ADDR64
:
2674 case elfcpp::R_PPC64_UADDR64
:
2675 case elfcpp::R_PPC64_JMP_IREL
:
2676 case elfcpp::R_PPC64_ADDR16_DS
:
2677 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2678 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2679 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2680 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2681 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2682 case elfcpp::R_PPC64_REL64
:
2683 case elfcpp::R_POWERPC_ADDR30
:
2684 case elfcpp::R_PPC64_TPREL16_DS
:
2685 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2686 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2687 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2688 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2689 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2700 // These are the relocation types supported only on 32-bit.
2701 // ??? glibc ld.so doesn't need to support these.
2702 case elfcpp::R_POWERPC_DTPREL16
:
2703 case elfcpp::R_POWERPC_DTPREL16_LO
:
2704 case elfcpp::R_POWERPC_DTPREL16_HI
:
2705 case elfcpp::R_POWERPC_DTPREL16_HA
:
2713 // This prevents us from issuing more than one error per reloc
2714 // section. But we can still wind up issuing more than one
2715 // error per object file.
2716 if (this->issued_non_pic_error_
)
2718 gold_assert(parameters
->options().output_is_position_independent());
2719 object
->error(_("requires unsupported dynamic reloc; "
2720 "recompile with -fPIC"));
2721 this->issued_non_pic_error_
= true;
2725 // Return whether we need to make a PLT entry for a relocation of the
2726 // given type against a STT_GNU_IFUNC symbol.
2728 template<int size
, bool big_endian
>
2730 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2731 Sized_relobj_file
<size
, big_endian
>* object
,
2732 unsigned int r_type
)
2734 // In non-pic code any reference will resolve to the plt call stub
2735 // for the ifunc symbol.
2736 if (size
== 32 && !parameters
->options().output_is_position_independent())
2741 // Word size refs from data sections are OK.
2742 case elfcpp::R_POWERPC_ADDR32
:
2743 case elfcpp::R_POWERPC_UADDR32
:
2748 case elfcpp::R_PPC64_ADDR64
:
2749 case elfcpp::R_PPC64_UADDR64
:
2754 // GOT refs are good.
2755 case elfcpp::R_POWERPC_GOT16
:
2756 case elfcpp::R_POWERPC_GOT16_LO
:
2757 case elfcpp::R_POWERPC_GOT16_HI
:
2758 case elfcpp::R_POWERPC_GOT16_HA
:
2759 case elfcpp::R_PPC64_GOT16_DS
:
2760 case elfcpp::R_PPC64_GOT16_LO_DS
:
2763 // So are function calls.
2764 case elfcpp::R_POWERPC_ADDR24
:
2765 case elfcpp::R_POWERPC_ADDR14
:
2766 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2767 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2768 case elfcpp::R_POWERPC_REL24
:
2769 case elfcpp::R_PPC_PLTREL24
:
2770 case elfcpp::R_POWERPC_REL14
:
2771 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2772 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2779 // Anything else is a problem.
2780 // If we are building a static executable, the libc startup function
2781 // responsible for applying indirect function relocations is going
2782 // to complain about the reloc type.
2783 // If we are building a dynamic executable, we will have a text
2784 // relocation. The dynamic loader will set the text segment
2785 // writable and non-executable to apply text relocations. So we'll
2786 // segfault when trying to run the indirection function to resolve
2788 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
2789 object
->name().c_str(), r_type
);
2793 // Scan a relocation for a local symbol.
2795 template<int size
, bool big_endian
>
2797 Target_powerpc
<size
, big_endian
>::Scan::local(
2798 Symbol_table
* symtab
,
2800 Target_powerpc
<size
, big_endian
>* target
,
2801 Sized_relobj_file
<size
, big_endian
>* object
,
2802 unsigned int data_shndx
,
2803 Output_section
* output_section
,
2804 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2805 unsigned int r_type
,
2806 const elfcpp::Sym
<size
, big_endian
>& lsym
,
2809 Powerpc_relobj
<size
, big_endian
>* ppc_object
2810 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2815 && data_shndx
== ppc_object
->opd_shndx()
2816 && r_type
== elfcpp::R_PPC64_ADDR64
)
2817 ppc_object
->set_opd_discard(reloc
.get_r_offset());
2821 // A local STT_GNU_IFUNC symbol may require a PLT entry.
2822 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2823 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
2824 target
->make_local_ifunc_plt_entry(layout
, reloc
, object
);
2828 case elfcpp::R_POWERPC_NONE
:
2829 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2830 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2831 case elfcpp::R_PPC64_TOCSAVE
:
2832 case elfcpp::R_PPC_EMB_MRKREF
:
2833 case elfcpp::R_POWERPC_TLS
:
2836 case elfcpp::R_PPC64_TOC
:
2838 Output_data_got_powerpc
<size
, big_endian
>* got
2839 = target
->got_section(symtab
, layout
);
2840 if (parameters
->options().output_is_position_independent())
2842 Address off
= reloc
.get_r_offset();
2844 && data_shndx
== ppc_object
->opd_shndx()
2845 && ppc_object
->get_opd_discard(off
- 8))
2848 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2849 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
2850 rela_dyn
->add_output_section_relative(got
->output_section(),
2851 elfcpp::R_POWERPC_RELATIVE
,
2853 object
, data_shndx
, off
,
2854 symobj
->toc_base_offset());
2859 case elfcpp::R_PPC64_ADDR64
:
2860 case elfcpp::R_PPC64_UADDR64
:
2861 case elfcpp::R_POWERPC_ADDR32
:
2862 case elfcpp::R_POWERPC_UADDR32
:
2863 case elfcpp::R_POWERPC_ADDR24
:
2864 case elfcpp::R_POWERPC_ADDR16
:
2865 case elfcpp::R_POWERPC_ADDR16_LO
:
2866 case elfcpp::R_POWERPC_ADDR16_HI
:
2867 case elfcpp::R_POWERPC_ADDR16_HA
:
2868 case elfcpp::R_POWERPC_UADDR16
:
2869 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2870 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2871 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2872 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2873 case elfcpp::R_PPC64_ADDR16_DS
:
2874 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2875 case elfcpp::R_POWERPC_ADDR14
:
2876 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2877 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2878 // If building a shared library (or a position-independent
2879 // executable), we need to create a dynamic relocation for
2881 if (parameters
->options().output_is_position_independent()
2882 || (size
== 64 && is_ifunc
))
2884 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2886 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2887 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2889 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2890 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
2893 rela_dyn
= target
->iplt_section()->rel_plt();
2894 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2896 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
2897 output_section
, data_shndx
,
2898 reloc
.get_r_offset(),
2899 reloc
.get_r_addend(), false);
2903 check_non_pic(object
, r_type
);
2904 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2905 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2906 data_shndx
, reloc
.get_r_offset(),
2907 reloc
.get_r_addend());
2912 case elfcpp::R_PPC64_REL64
:
2913 case elfcpp::R_POWERPC_REL32
:
2914 case elfcpp::R_POWERPC_REL24
:
2915 case elfcpp::R_PPC_PLTREL24
:
2916 case elfcpp::R_PPC_LOCAL24PC
:
2917 case elfcpp::R_POWERPC_REL16
:
2918 case elfcpp::R_POWERPC_REL16_LO
:
2919 case elfcpp::R_POWERPC_REL16_HI
:
2920 case elfcpp::R_POWERPC_REL16_HA
:
2921 case elfcpp::R_POWERPC_REL14
:
2922 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2923 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2924 case elfcpp::R_POWERPC_SECTOFF
:
2925 case elfcpp::R_POWERPC_TPREL16
:
2926 case elfcpp::R_POWERPC_DTPREL16
:
2927 case elfcpp::R_POWERPC_SECTOFF_LO
:
2928 case elfcpp::R_POWERPC_TPREL16_LO
:
2929 case elfcpp::R_POWERPC_DTPREL16_LO
:
2930 case elfcpp::R_POWERPC_SECTOFF_HI
:
2931 case elfcpp::R_POWERPC_TPREL16_HI
:
2932 case elfcpp::R_POWERPC_DTPREL16_HI
:
2933 case elfcpp::R_POWERPC_SECTOFF_HA
:
2934 case elfcpp::R_POWERPC_TPREL16_HA
:
2935 case elfcpp::R_POWERPC_DTPREL16_HA
:
2936 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2937 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2938 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2939 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2940 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2941 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2942 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2943 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2944 case elfcpp::R_PPC64_TPREL16_DS
:
2945 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2946 case elfcpp::R_PPC64_DTPREL16_DS
:
2947 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2948 case elfcpp::R_PPC64_SECTOFF_DS
:
2949 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2950 case elfcpp::R_PPC64_TLSGD
:
2951 case elfcpp::R_PPC64_TLSLD
:
2954 case elfcpp::R_POWERPC_GOT16
:
2955 case elfcpp::R_POWERPC_GOT16_LO
:
2956 case elfcpp::R_POWERPC_GOT16_HI
:
2957 case elfcpp::R_POWERPC_GOT16_HA
:
2958 case elfcpp::R_PPC64_GOT16_DS
:
2959 case elfcpp::R_PPC64_GOT16_LO_DS
:
2961 // The symbol requires a GOT entry.
2962 Output_data_got_powerpc
<size
, big_endian
>* got
2963 = target
->got_section(symtab
, layout
);
2964 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2966 if (!parameters
->options().output_is_position_independent())
2968 if (size
== 32 && is_ifunc
)
2969 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
2971 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2973 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2975 // If we are generating a shared object or a pie, this
2976 // symbol's GOT entry will be set by a dynamic relocation.
2978 off
= got
->add_constant(0);
2979 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2981 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2982 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
2985 rela_dyn
= target
->iplt_section()->rel_plt();
2986 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2988 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
2989 got
, off
, 0, false);
2994 case elfcpp::R_PPC64_TOC16
:
2995 case elfcpp::R_PPC64_TOC16_LO
:
2996 case elfcpp::R_PPC64_TOC16_HI
:
2997 case elfcpp::R_PPC64_TOC16_HA
:
2998 case elfcpp::R_PPC64_TOC16_DS
:
2999 case elfcpp::R_PPC64_TOC16_LO_DS
:
3000 // We need a GOT section.
3001 target
->got_section(symtab
, layout
);
3004 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3005 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3006 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3007 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3009 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
3010 if (tls_type
== tls::TLSOPT_NONE
)
3012 Output_data_got_powerpc
<size
, big_endian
>* got
3013 = target
->got_section(symtab
, layout
);
3014 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3015 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3016 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
3017 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
3019 else if (tls_type
== tls::TLSOPT_TO_LE
)
3021 // no GOT relocs needed for Local Exec.
3028 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3029 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3030 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3031 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3033 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3034 if (tls_type
== tls::TLSOPT_NONE
)
3035 target
->tlsld_got_offset(symtab
, layout
, object
);
3036 else if (tls_type
== tls::TLSOPT_TO_LE
)
3038 // no GOT relocs needed for Local Exec.
3039 if (parameters
->options().emit_relocs())
3041 Output_section
* os
= layout
->tls_segment()->first_section();
3042 gold_assert(os
!= NULL
);
3043 os
->set_needs_symtab_index();
3051 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3052 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3053 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3054 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3056 Output_data_got_powerpc
<size
, big_endian
>* got
3057 = target
->got_section(symtab
, layout
);
3058 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3059 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
3063 case elfcpp::R_POWERPC_GOT_TPREL16
:
3064 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3065 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3066 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3068 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
3069 if (tls_type
== tls::TLSOPT_NONE
)
3071 Output_data_got_powerpc
<size
, big_endian
>* got
3072 = target
->got_section(symtab
, layout
);
3073 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3074 got
->add_local_tls(object
, r_sym
, GOT_TYPE_TPREL
);
3076 else if (tls_type
== tls::TLSOPT_TO_LE
)
3078 // no GOT relocs needed for Local Exec.
3086 unsupported_reloc_local(object
, r_type
);
3091 // Report an unsupported relocation against a global symbol.
3093 template<int size
, bool big_endian
>
3095 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
3096 Sized_relobj_file
<size
, big_endian
>* object
,
3097 unsigned int r_type
,
3100 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3101 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3104 // Scan a relocation for a global symbol.
3106 template<int size
, bool big_endian
>
3108 Target_powerpc
<size
, big_endian
>::Scan::global(
3109 Symbol_table
* symtab
,
3111 Target_powerpc
<size
, big_endian
>* target
,
3112 Sized_relobj_file
<size
, big_endian
>* object
,
3113 unsigned int data_shndx
,
3114 Output_section
* output_section
,
3115 const elfcpp::Rela
<size
, big_endian
>& reloc
,
3116 unsigned int r_type
,
3119 Powerpc_relobj
<size
, big_endian
>* ppc_object
3120 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3122 // A STT_GNU_IFUNC symbol may require a PLT entry.
3123 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
3124 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
3125 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3129 case elfcpp::R_POWERPC_NONE
:
3130 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3131 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3132 case elfcpp::R_PPC_LOCAL24PC
:
3133 case elfcpp::R_PPC_EMB_MRKREF
:
3134 case elfcpp::R_POWERPC_TLS
:
3137 case elfcpp::R_PPC64_TOC
:
3139 Output_data_got_powerpc
<size
, big_endian
>* got
3140 = target
->got_section(symtab
, layout
);
3141 if (parameters
->options().output_is_position_independent())
3143 Address off
= reloc
.get_r_offset();
3145 && data_shndx
== ppc_object
->opd_shndx()
3146 && ppc_object
->get_opd_discard(off
- 8))
3149 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3150 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
3151 if (data_shndx
!= ppc_object
->opd_shndx())
3152 symobj
= static_cast
3153 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3154 rela_dyn
->add_output_section_relative(got
->output_section(),
3155 elfcpp::R_POWERPC_RELATIVE
,
3157 object
, data_shndx
, off
,
3158 symobj
->toc_base_offset());
3163 case elfcpp::R_PPC64_ADDR64
:
3165 && data_shndx
== ppc_object
->opd_shndx()
3166 && (gsym
->is_defined_in_discarded_section()
3167 || gsym
->object() != object
))
3169 ppc_object
->set_opd_discard(reloc
.get_r_offset());
3173 case elfcpp::R_PPC64_UADDR64
:
3174 case elfcpp::R_POWERPC_ADDR32
:
3175 case elfcpp::R_POWERPC_UADDR32
:
3176 case elfcpp::R_POWERPC_ADDR24
:
3177 case elfcpp::R_POWERPC_ADDR16
:
3178 case elfcpp::R_POWERPC_ADDR16_LO
:
3179 case elfcpp::R_POWERPC_ADDR16_HI
:
3180 case elfcpp::R_POWERPC_ADDR16_HA
:
3181 case elfcpp::R_POWERPC_UADDR16
:
3182 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3183 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3184 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3185 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3186 case elfcpp::R_PPC64_ADDR16_DS
:
3187 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3188 case elfcpp::R_POWERPC_ADDR14
:
3189 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3190 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3192 // Make a PLT entry if necessary.
3193 if (gsym
->needs_plt_entry())
3195 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
3196 // Since this is not a PC-relative relocation, we may be
3197 // taking the address of a function. In that case we need to
3198 // set the entry in the dynamic symbol table to the address of
3199 // the PLT call stub.
3201 && gsym
->is_from_dynobj()
3202 && !parameters
->options().output_is_position_independent())
3203 gsym
->set_needs_dynsym_value();
3205 // Make a dynamic relocation if necessary.
3206 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
))
3207 || (size
== 64 && gsym
->type() == elfcpp::STT_GNU_IFUNC
))
3209 if (gsym
->may_need_copy_reloc())
3211 target
->copy_reloc(symtab
, layout
, object
,
3212 data_shndx
, output_section
, gsym
, reloc
);
3214 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
3215 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
3216 && (gsym
->can_use_relative_reloc(false)
3218 && data_shndx
== ppc_object
->opd_shndx())))
3220 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3221 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3222 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3224 rela_dyn
= target
->iplt_section()->rel_plt();
3225 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3227 rela_dyn
->add_symbolless_global_addend(
3228 gsym
, dynrel
, output_section
, object
, data_shndx
,
3229 reloc
.get_r_offset(), reloc
.get_r_addend());
3233 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3234 check_non_pic(object
, r_type
);
3235 rela_dyn
->add_global(gsym
, r_type
, output_section
,
3237 reloc
.get_r_offset(),
3238 reloc
.get_r_addend());
3244 case elfcpp::R_PPC_PLTREL24
:
3245 case elfcpp::R_POWERPC_REL24
:
3246 if (gsym
->needs_plt_entry()
3247 || (!gsym
->final_value_is_known()
3248 && (gsym
->is_undefined()
3249 || gsym
->is_from_dynobj()
3250 || gsym
->is_preemptible())))
3251 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
3254 case elfcpp::R_PPC64_REL64
:
3255 case elfcpp::R_POWERPC_REL32
:
3256 // Make a dynamic relocation if necessary.
3257 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3259 if (gsym
->may_need_copy_reloc())
3261 target
->copy_reloc(symtab
, layout
, object
,
3262 data_shndx
, output_section
, gsym
,
3267 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3268 check_non_pic(object
, r_type
);
3269 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
3270 data_shndx
, reloc
.get_r_offset(),
3271 reloc
.get_r_addend());
3276 case elfcpp::R_POWERPC_REL16
:
3277 case elfcpp::R_POWERPC_REL16_LO
:
3278 case elfcpp::R_POWERPC_REL16_HI
:
3279 case elfcpp::R_POWERPC_REL16_HA
:
3280 case elfcpp::R_POWERPC_REL14
:
3281 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3282 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3283 case elfcpp::R_POWERPC_SECTOFF
:
3284 case elfcpp::R_POWERPC_TPREL16
:
3285 case elfcpp::R_POWERPC_DTPREL16
:
3286 case elfcpp::R_POWERPC_SECTOFF_LO
:
3287 case elfcpp::R_POWERPC_TPREL16_LO
:
3288 case elfcpp::R_POWERPC_DTPREL16_LO
:
3289 case elfcpp::R_POWERPC_SECTOFF_HI
:
3290 case elfcpp::R_POWERPC_TPREL16_HI
:
3291 case elfcpp::R_POWERPC_DTPREL16_HI
:
3292 case elfcpp::R_POWERPC_SECTOFF_HA
:
3293 case elfcpp::R_POWERPC_TPREL16_HA
:
3294 case elfcpp::R_POWERPC_DTPREL16_HA
:
3295 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3296 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3297 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3298 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3299 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3300 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3301 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3302 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3303 case elfcpp::R_PPC64_TPREL16_DS
:
3304 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3305 case elfcpp::R_PPC64_DTPREL16_DS
:
3306 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3307 case elfcpp::R_PPC64_SECTOFF_DS
:
3308 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3309 case elfcpp::R_PPC64_TLSGD
:
3310 case elfcpp::R_PPC64_TLSLD
:
3313 case elfcpp::R_POWERPC_GOT16
:
3314 case elfcpp::R_POWERPC_GOT16_LO
:
3315 case elfcpp::R_POWERPC_GOT16_HI
:
3316 case elfcpp::R_POWERPC_GOT16_HA
:
3317 case elfcpp::R_PPC64_GOT16_DS
:
3318 case elfcpp::R_PPC64_GOT16_LO_DS
:
3320 // The symbol requires a GOT entry.
3321 Output_data_got_powerpc
<size
, big_endian
>* got
;
3323 got
= target
->got_section(symtab
, layout
);
3324 if (gsym
->final_value_is_known())
3326 if (size
== 32 && gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3327 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
3329 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
3331 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
3333 // If we are generating a shared object or a pie, this
3334 // symbol's GOT entry will be set by a dynamic relocation.
3335 unsigned int off
= got
->add_constant(0);
3336 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
3338 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3339 if (gsym
->can_use_relative_reloc(false)
3341 && gsym
->visibility() == elfcpp::STV_PROTECTED
3342 && parameters
->options().shared()))
3344 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
3345 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3347 rela_dyn
= target
->iplt_section()->rel_plt();
3348 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3350 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
3354 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
3355 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
3361 case elfcpp::R_PPC64_TOC16
:
3362 case elfcpp::R_PPC64_TOC16_LO
:
3363 case elfcpp::R_PPC64_TOC16_HI
:
3364 case elfcpp::R_PPC64_TOC16_HA
:
3365 case elfcpp::R_PPC64_TOC16_DS
:
3366 case elfcpp::R_PPC64_TOC16_LO_DS
:
3367 // We need a GOT section.
3368 target
->got_section(symtab
, layout
);
3371 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3372 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3373 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3374 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3376 const bool final
= gsym
->final_value_is_known();
3377 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3378 if (tls_type
== tls::TLSOPT_NONE
)
3380 Output_data_got_powerpc
<size
, big_endian
>* got
3381 = target
->got_section(symtab
, layout
);
3382 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
3383 target
->rela_dyn_section(layout
),
3384 elfcpp::R_POWERPC_DTPMOD
,
3385 elfcpp::R_POWERPC_DTPREL
);
3387 else if (tls_type
== tls::TLSOPT_TO_IE
)
3389 Output_data_got_powerpc
<size
, big_endian
>* got
3390 = target
->got_section(symtab
, layout
);
3391 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
3392 target
->rela_dyn_section(layout
),
3393 elfcpp::R_POWERPC_TPREL
);
3395 else if (tls_type
== tls::TLSOPT_TO_LE
)
3397 // no GOT relocs needed for Local Exec.
3404 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3405 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3406 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3407 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3409 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3410 if (tls_type
== tls::TLSOPT_NONE
)
3411 target
->tlsld_got_offset(symtab
, layout
, object
);
3412 else if (tls_type
== tls::TLSOPT_TO_LE
)
3414 // no GOT relocs needed for Local Exec.
3415 if (parameters
->options().emit_relocs())
3417 Output_section
* os
= layout
->tls_segment()->first_section();
3418 gold_assert(os
!= NULL
);
3419 os
->set_needs_symtab_index();
3427 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3428 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3429 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3430 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3432 Output_data_got_powerpc
<size
, big_endian
>* got
3433 = target
->got_section(symtab
, layout
);
3434 if (!gsym
->final_value_is_known()
3435 && (gsym
->is_from_dynobj()
3436 || gsym
->is_undefined()
3437 || gsym
->is_preemptible()))
3438 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
3439 target
->rela_dyn_section(layout
),
3440 elfcpp::R_POWERPC_DTPREL
);
3442 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
3446 case elfcpp::R_POWERPC_GOT_TPREL16
:
3447 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3448 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3449 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3451 const bool final
= gsym
->final_value_is_known();
3452 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3453 if (tls_type
== tls::TLSOPT_NONE
)
3455 Output_data_got_powerpc
<size
, big_endian
>* got
3456 = target
->got_section(symtab
, layout
);
3457 if (!gsym
->final_value_is_known()
3458 && (gsym
->is_from_dynobj()
3459 || gsym
->is_undefined()
3460 || gsym
->is_preemptible()))
3461 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
3462 target
->rela_dyn_section(layout
),
3463 elfcpp::R_POWERPC_TPREL
);
3465 got
->add_global_tls(gsym
, GOT_TYPE_TPREL
);
3467 else if (tls_type
== tls::TLSOPT_TO_LE
)
3469 // no GOT relocs needed for Local Exec.
3477 unsupported_reloc_global(object
, r_type
, gsym
);
3482 // Process relocations for gc.
3484 template<int size
, bool big_endian
>
3486 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
3487 Symbol_table
* symtab
,
3489 Sized_relobj_file
<size
, big_endian
>* object
,
3490 unsigned int data_shndx
,
3492 const unsigned char* prelocs
,
3494 Output_section
* output_section
,
3495 bool needs_special_offset_handling
,
3496 size_t local_symbol_count
,
3497 const unsigned char* plocal_symbols
)
3499 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3500 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3501 Powerpc_relobj
<size
, big_endian
>* ppc_object
3502 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
3504 ppc_object
->set_opd_valid();
3505 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
3507 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
3508 for (p
= ppc_object
->access_from_map()->begin();
3509 p
!= ppc_object
->access_from_map()->end();
3512 Address dst_off
= p
->first
;
3513 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3514 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
3515 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
3517 Object
* src_obj
= s
->first
;
3518 unsigned int src_indx
= s
->second
;
3519 symtab
->gc()->add_reference(src_obj
, src_indx
,
3520 ppc_object
, dst_indx
);
3524 ppc_object
->access_from_map()->clear();
3525 ppc_object
->process_gc_mark(symtab
);
3526 // Don't look at .opd relocs as .opd will reference everything.
3530 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3531 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3540 needs_special_offset_handling
,
3545 // Handle target specific gc actions when adding a gc reference from
3546 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3547 // and DST_OFF. For powerpc64, this adds a referenc to the code
3548 // section of a function descriptor.
3550 template<int size
, bool big_endian
>
3552 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3553 Symbol_table
* symtab
,
3555 unsigned int src_shndx
,
3557 unsigned int dst_shndx
,
3558 Address dst_off
) const
3560 Powerpc_relobj
<size
, big_endian
>* ppc_object
3561 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3562 if (size
== 64 && dst_shndx
== ppc_object
->opd_shndx())
3564 if (ppc_object
->opd_valid())
3566 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3567 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3571 // If we haven't run scan_opd_relocs, we must delay
3572 // processing this function descriptor reference.
3573 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3578 // Add any special sections for this symbol to the gc work list.
3579 // For powerpc64, this adds the code section of a function
3582 template<int size
, bool big_endian
>
3584 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3585 Symbol_table
* symtab
,
3590 Powerpc_relobj
<size
, big_endian
>* ppc_object
3591 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3593 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3594 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
3596 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
3597 Address dst_off
= gsym
->value();
3598 if (ppc_object
->opd_valid())
3600 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3601 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
3604 ppc_object
->add_gc_mark(dst_off
);
3609 // Scan relocations for a section.
3611 template<int size
, bool big_endian
>
3613 Target_powerpc
<size
, big_endian
>::scan_relocs(
3614 Symbol_table
* symtab
,
3616 Sized_relobj_file
<size
, big_endian
>* object
,
3617 unsigned int data_shndx
,
3618 unsigned int sh_type
,
3619 const unsigned char* prelocs
,
3621 Output_section
* output_section
,
3622 bool needs_special_offset_handling
,
3623 size_t local_symbol_count
,
3624 const unsigned char* plocal_symbols
)
3626 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3627 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3629 if (sh_type
== elfcpp::SHT_REL
)
3631 gold_error(_("%s: unsupported REL reloc section"),
3632 object
->name().c_str());
3638 static Output_data_space
* sdata
;
3640 // Define _SDA_BASE_ at the start of the .sdata section.
3643 // layout->find_output_section(".sdata") == NULL
3644 sdata
= new Output_data_space(4, "** sdata");
3646 = layout
->add_output_section_data(".sdata", 0,
3648 | elfcpp::SHF_WRITE
,
3649 sdata
, ORDER_SMALL_DATA
, false);
3650 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
3651 Symbol_table::PREDEFINED
,
3652 os
, 32768, 0, elfcpp::STT_OBJECT
,
3653 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
3658 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
3667 needs_special_offset_handling
,
3672 // Functor class for processing the global symbol table.
3673 // Removes symbols defined on discarded opd entries.
3675 template<bool big_endian
>
3676 class Global_symbol_visitor_opd
3679 Global_symbol_visitor_opd()
3683 operator()(Sized_symbol
<64>* sym
)
3685 if (sym
->has_symtab_index()
3686 || sym
->source() != Symbol::FROM_OBJECT
3687 || !sym
->in_real_elf())
3690 Powerpc_relobj
<64, big_endian
>* symobj
3691 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
3692 if (symobj
->is_dynamic()
3693 || symobj
->opd_shndx() == 0)
3697 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3698 if (shndx
== symobj
->opd_shndx()
3699 && symobj
->get_opd_discard(sym
->value()))
3700 sym
->set_symtab_index(-1U);
3704 // Finalize the sections.
3706 template<int size
, bool big_endian
>
3708 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
3710 const Input_objects
*,
3711 Symbol_table
* symtab
)
3713 if (parameters
->doing_static_link())
3715 // At least some versions of glibc elf-init.o have a strong
3716 // reference to __rela_iplt marker syms. A weak ref would be
3718 if (this->iplt_
!= NULL
)
3720 Reloc_section
* rel
= this->iplt_
->rel_plt();
3721 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
3722 Symbol_table::PREDEFINED
, rel
, 0, 0,
3723 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
3724 elfcpp::STV_HIDDEN
, 0, false, true);
3725 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
3726 Symbol_table::PREDEFINED
, rel
, 0, 0,
3727 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
3728 elfcpp::STV_HIDDEN
, 0, true, true);
3732 symtab
->define_as_constant("__rela_iplt_start", NULL
,
3733 Symbol_table::PREDEFINED
, 0, 0,
3734 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
3735 elfcpp::STV_HIDDEN
, 0, true, false);
3736 symtab
->define_as_constant("__rela_iplt_end", NULL
,
3737 Symbol_table::PREDEFINED
, 0, 0,
3738 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
3739 elfcpp::STV_HIDDEN
, 0, true, false);
3745 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
3746 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
3749 // Fill in some more dynamic tags.
3750 Output_data_dynamic
* odyn
= layout
->dynamic_data();
3753 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3755 : this->plt_
->rel_plt());
3756 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3757 this->rela_dyn_
, true, size
== 32);
3761 if (this->got_
!= NULL
)
3763 this->got_
->finalize_data_size();
3764 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
3765 this->got_
, this->got_
->g_o_t());
3770 if (this->glink_
!= NULL
)
3772 this->glink_
->finalize_data_size();
3773 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
3775 (this->glink_
->pltresolve()
3776 + this->glink_
->pltresolve_size
3782 // Emit any relocs we saved in an attempt to avoid generating COPY
3784 if (this->copy_relocs_
.any_saved_relocs())
3785 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3788 // Return the value to use for a branch relocation.
3790 template<int size
, bool big_endian
>
3791 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3792 Target_powerpc
<size
, big_endian
>::symval_for_branch(
3794 const Sized_symbol
<size
>* gsym
,
3795 Powerpc_relobj
<size
, big_endian
>* object
,
3796 unsigned int *dest_shndx
)
3802 // If the symbol is defined in an opd section, ie. is a function
3803 // descriptor, use the function descriptor code entry address
3804 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
3806 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3807 unsigned int shndx
= symobj
->opd_shndx();
3810 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
3811 gold_assert(opd_addr
!= invalid_address
);
3812 opd_addr
+= symobj
->output_section(shndx
)->address();
3813 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
3816 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
3817 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
3818 gold_assert(sec_addr
!= invalid_address
);
3819 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
3820 value
= sec_addr
+ sec_off
;
3825 // Perform a relocation.
3827 template<int size
, bool big_endian
>
3829 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
3830 const Relocate_info
<size
, big_endian
>* relinfo
,
3831 Target_powerpc
* target
,
3834 const elfcpp::Rela
<size
, big_endian
>& rela
,
3835 unsigned int r_type
,
3836 const Sized_symbol
<size
>* gsym
,
3837 const Symbol_value
<size
>* psymval
,
3838 unsigned char* view
,
3840 section_size_type view_size
)
3843 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
3844 || r_type
== elfcpp::R_PPC_PLTREL24
)
3846 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
3847 enum skip_tls last_tls
= this->call_tls_get_addr_
;
3848 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
3851 if (last_tls
== CALL_NOT_EXPECTED
)
3852 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3853 _("__tls_get_addr call lacks marker reloc"));
3854 else if (last_tls
== CALL_SKIP
)
3857 else if (last_tls
!= CALL_NOT_EXPECTED
)
3858 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3859 _("missing expected __tls_get_addr call"));
3861 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
3862 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
3863 Powerpc_relobj
<size
, big_endian
>* const object
3864 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
3866 bool has_plt_value
= false;
3867 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3869 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
))
3870 : object
->local_has_plt_offset(r_sym
))
3872 const Output_data_glink
<size
, big_endian
>* glink
3873 = target
->glink_section();
3874 unsigned int glink_index
;
3876 glink_index
= glink
->find_entry(object
, gsym
, rela
);
3878 glink_index
= glink
->find_entry(object
, r_sym
, rela
);
3879 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
3880 has_plt_value
= true;
3883 if (r_type
== elfcpp::R_POWERPC_GOT16
3884 || r_type
== elfcpp::R_POWERPC_GOT16_LO
3885 || r_type
== elfcpp::R_POWERPC_GOT16_HI
3886 || r_type
== elfcpp::R_POWERPC_GOT16_HA
3887 || r_type
== elfcpp::R_PPC64_GOT16_DS
3888 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
3892 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3893 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3897 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3898 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3899 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3901 value
-= target
->got_section()->got_base_offset(object
);
3903 else if (r_type
== elfcpp::R_PPC64_TOC
)
3905 value
= (target
->got_section()->output_section()->address()
3906 + object
->toc_base_offset());
3908 else if (gsym
!= NULL
3909 && (r_type
== elfcpp::R_POWERPC_REL24
3910 || r_type
== elfcpp::R_PPC_PLTREL24
)
3915 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3916 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3917 bool can_plt_call
= false;
3918 if (rela
.get_r_offset() + 8 <= view_size
)
3920 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3921 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
3924 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
3926 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
3927 can_plt_call
= true;
3932 // If we don't have a branch and link followed by a nop,
3933 // we can't go via the plt because there is no place to
3934 // put a toc restoring instruction.
3935 // Unless we know we won't be returning.
3936 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
3937 can_plt_call
= true;
3941 // This is not an error in one special case: A self
3942 // call. It isn't possible to cheaply verify we have
3943 // such a call so just check for a call to the same
3946 Address code
= value
;
3947 if (gsym
->source() == Symbol::FROM_OBJECT
3948 && gsym
->object() == object
)
3950 Address addend
= rela
.get_r_addend();
3951 unsigned int dest_shndx
;
3952 Address opdent
= psymval
->value(object
, addend
);
3953 code
= target
->symval_for_branch(opdent
, gsym
, object
,
3956 if (dest_shndx
== 0)
3957 dest_shndx
= gsym
->shndx(&is_ordinary
);
3958 ok
= dest_shndx
== relinfo
->data_shndx
;
3962 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3963 _("call lacks nop, can't restore toc; "
3964 "recompile with -fPIC"));
3970 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3971 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
3972 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
3973 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
3975 // First instruction of a global dynamic sequence, arg setup insn.
3976 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3977 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3978 enum Got_type got_type
= GOT_TYPE_STANDARD
;
3979 if (tls_type
== tls::TLSOPT_NONE
)
3980 got_type
= GOT_TYPE_TLSGD
;
3981 else if (tls_type
== tls::TLSOPT_TO_IE
)
3982 got_type
= GOT_TYPE_TPREL
;
3983 if (got_type
!= GOT_TYPE_STANDARD
)
3987 gold_assert(gsym
->has_got_offset(got_type
));
3988 value
= gsym
->got_offset(got_type
);
3992 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3993 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3994 value
= object
->local_got_offset(r_sym
, got_type
);
3996 value
-= target
->got_section()->got_base_offset(object
);
3998 if (tls_type
== tls::TLSOPT_TO_IE
)
4000 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4001 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4003 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4004 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4005 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
4007 insn
|= 32 << 26; // lwz
4009 insn
|= 58 << 26; // ld
4010 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4012 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4013 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4015 else if (tls_type
== tls::TLSOPT_TO_LE
)
4017 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4018 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4020 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4021 Insn insn
= addis_3_13
;
4024 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4025 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4026 value
= psymval
->value(object
, rela
.get_r_addend());
4030 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4032 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4033 r_type
= elfcpp::R_POWERPC_NONE
;
4037 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4038 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4039 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4040 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4042 // First instruction of a local dynamic sequence, arg setup insn.
4043 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4044 if (tls_type
== tls::TLSOPT_NONE
)
4046 value
= target
->tlsld_got_offset();
4047 value
-= target
->got_section()->got_base_offset(object
);
4051 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4052 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4053 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4055 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4056 Insn insn
= addis_3_13
;
4059 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4060 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4065 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4067 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4068 r_type
= elfcpp::R_POWERPC_NONE
;
4072 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
4073 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
4074 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
4075 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
4077 // Accesses relative to a local dynamic sequence address,
4078 // no optimisation here.
4081 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
4082 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
4086 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4087 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
4088 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
4090 value
-= target
->got_section()->got_base_offset(object
);
4092 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4093 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4094 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4095 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4097 // First instruction of initial exec sequence.
4098 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4099 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4100 if (tls_type
== tls::TLSOPT_NONE
)
4104 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
4105 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
4109 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4110 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
4111 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
4113 value
-= target
->got_section()->got_base_offset(object
);
4117 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
4118 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4119 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4121 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4122 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4123 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
4128 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4129 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4130 value
= psymval
->value(object
, rela
.get_r_addend());
4134 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
4136 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4137 r_type
= elfcpp::R_POWERPC_NONE
;
4141 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4142 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4144 // Second instruction of a global dynamic sequence,
4145 // the __tls_get_addr call
4146 this->call_tls_get_addr_
= CALL_EXPECTED
;
4147 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4148 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
4149 if (tls_type
!= tls::TLSOPT_NONE
)
4151 if (tls_type
== tls::TLSOPT_TO_IE
)
4153 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4154 Insn insn
= add_3_3_13
;
4157 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4158 r_type
= elfcpp::R_POWERPC_NONE
;
4162 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4163 Insn insn
= addi_3_3
;
4164 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4165 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4166 view
+= 2 * big_endian
;
4167 value
= psymval
->value(object
, rela
.get_r_addend());
4169 this->call_tls_get_addr_
= CALL_SKIP
;
4172 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4173 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4175 // Second instruction of a local dynamic sequence,
4176 // the __tls_get_addr call
4177 this->call_tls_get_addr_
= CALL_EXPECTED
;
4178 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4179 if (tls_type
== tls::TLSOPT_TO_LE
)
4181 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4182 Insn insn
= addi_3_3
;
4183 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4184 this->call_tls_get_addr_
= CALL_SKIP
;
4185 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4186 view
+= 2 * big_endian
;
4190 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4192 // Second instruction of an initial exec sequence
4193 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4194 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
4195 if (tls_type
== tls::TLSOPT_TO_LE
)
4197 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4198 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4199 unsigned int reg
= size
== 32 ? 2 : 13;
4200 insn
= at_tls_transform(insn
, reg
);
4201 gold_assert(insn
!= 0);
4202 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4203 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4204 view
+= 2 * big_endian
;
4205 value
= psymval
->value(object
, rela
.get_r_addend());
4208 else if (!has_plt_value
)
4211 unsigned int dest_shndx
;
4212 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
4213 addend
= rela
.get_r_addend();
4214 value
= psymval
->value(object
, addend
);
4215 if (size
== 64 && is_branch_reloc(r_type
))
4216 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
4221 case elfcpp::R_PPC64_REL64
:
4222 case elfcpp::R_POWERPC_REL32
:
4223 case elfcpp::R_POWERPC_REL24
:
4224 case elfcpp::R_PPC_PLTREL24
:
4225 case elfcpp::R_PPC_LOCAL24PC
:
4226 case elfcpp::R_POWERPC_REL16
:
4227 case elfcpp::R_POWERPC_REL16_LO
:
4228 case elfcpp::R_POWERPC_REL16_HI
:
4229 case elfcpp::R_POWERPC_REL16_HA
:
4230 case elfcpp::R_POWERPC_REL14
:
4231 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4232 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4236 case elfcpp::R_PPC64_TOC16
:
4237 case elfcpp::R_PPC64_TOC16_LO
:
4238 case elfcpp::R_PPC64_TOC16_HI
:
4239 case elfcpp::R_PPC64_TOC16_HA
:
4240 case elfcpp::R_PPC64_TOC16_DS
:
4241 case elfcpp::R_PPC64_TOC16_LO_DS
:
4242 // Subtract the TOC base address.
4243 value
-= (target
->got_section()->output_section()->address()
4244 + object
->toc_base_offset());
4247 case elfcpp::R_POWERPC_SECTOFF
:
4248 case elfcpp::R_POWERPC_SECTOFF_LO
:
4249 case elfcpp::R_POWERPC_SECTOFF_HI
:
4250 case elfcpp::R_POWERPC_SECTOFF_HA
:
4251 case elfcpp::R_PPC64_SECTOFF_DS
:
4252 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4254 value
-= os
->address();
4257 case elfcpp::R_PPC64_TPREL16_DS
:
4258 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4260 // R_PPC_TLSGD and R_PPC_TLSLD
4262 case elfcpp::R_POWERPC_TPREL16
:
4263 case elfcpp::R_POWERPC_TPREL16_LO
:
4264 case elfcpp::R_POWERPC_TPREL16_HI
:
4265 case elfcpp::R_POWERPC_TPREL16_HA
:
4266 case elfcpp::R_POWERPC_TPREL
:
4267 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4268 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4269 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4270 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4271 // tls symbol values are relative to tls_segment()->vaddr()
4275 case elfcpp::R_PPC64_DTPREL16_DS
:
4276 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4277 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4278 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4279 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4280 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4282 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
4283 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
4285 case elfcpp::R_POWERPC_DTPREL16
:
4286 case elfcpp::R_POWERPC_DTPREL16_LO
:
4287 case elfcpp::R_POWERPC_DTPREL16_HI
:
4288 case elfcpp::R_POWERPC_DTPREL16_HA
:
4289 case elfcpp::R_POWERPC_DTPREL
:
4290 // tls symbol values are relative to tls_segment()->vaddr()
4291 value
-= dtp_offset
;
4298 Insn branch_bit
= 0;
4301 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4302 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4303 branch_bit
= 1 << 21;
4304 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4305 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4307 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
4308 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
4311 if (this->is_isa_v2
)
4313 // Set 'a' bit. This is 0b00010 in BO field for branch
4314 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
4315 // for branch on CTR insns (BO == 1a00t or 1a01t).
4316 if ((insn
& (0x14 << 21)) == (0x04 << 21))
4318 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
4325 // Invert 'y' bit if not the default.
4326 if (static_cast<Signed_address
>(value
) < 0)
4329 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
4337 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
4340 case elfcpp::R_POWERPC_ADDR32
:
4341 case elfcpp::R_POWERPC_UADDR32
:
4343 overflow
= Reloc::CHECK_BITFIELD
;
4346 case elfcpp::R_POWERPC_REL32
:
4348 overflow
= Reloc::CHECK_SIGNED
;
4351 case elfcpp::R_POWERPC_ADDR24
:
4352 case elfcpp::R_POWERPC_ADDR16
:
4353 case elfcpp::R_POWERPC_UADDR16
:
4354 case elfcpp::R_PPC64_ADDR16_DS
:
4355 case elfcpp::R_POWERPC_ADDR14
:
4356 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4357 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4358 overflow
= Reloc::CHECK_BITFIELD
;
4361 case elfcpp::R_POWERPC_REL24
:
4362 case elfcpp::R_PPC_PLTREL24
:
4363 case elfcpp::R_PPC_LOCAL24PC
:
4364 case elfcpp::R_POWERPC_REL16
:
4365 case elfcpp::R_PPC64_TOC16
:
4366 case elfcpp::R_POWERPC_GOT16
:
4367 case elfcpp::R_POWERPC_SECTOFF
:
4368 case elfcpp::R_POWERPC_TPREL16
:
4369 case elfcpp::R_POWERPC_DTPREL16
:
4370 case elfcpp::R_PPC64_TPREL16_DS
:
4371 case elfcpp::R_PPC64_DTPREL16_DS
:
4372 case elfcpp::R_PPC64_TOC16_DS
:
4373 case elfcpp::R_PPC64_GOT16_DS
:
4374 case elfcpp::R_PPC64_SECTOFF_DS
:
4375 case elfcpp::R_POWERPC_REL14
:
4376 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4377 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4378 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4379 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4380 case elfcpp::R_POWERPC_GOT_TPREL16
:
4381 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4382 overflow
= Reloc::CHECK_SIGNED
;
4386 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
4387 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
4390 case elfcpp::R_POWERPC_NONE
:
4391 case elfcpp::R_POWERPC_TLS
:
4392 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4393 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4394 case elfcpp::R_PPC_EMB_MRKREF
:
4397 case elfcpp::R_PPC64_ADDR64
:
4398 case elfcpp::R_PPC64_REL64
:
4399 case elfcpp::R_PPC64_TOC
:
4400 Reloc::addr64(view
, value
);
4403 case elfcpp::R_POWERPC_TPREL
:
4404 case elfcpp::R_POWERPC_DTPREL
:
4406 Reloc::addr64(view
, value
);
4408 status
= Reloc::addr32(view
, value
, overflow
);
4411 case elfcpp::R_PPC64_UADDR64
:
4412 Reloc::addr64_u(view
, value
);
4415 case elfcpp::R_POWERPC_ADDR32
:
4416 case elfcpp::R_POWERPC_REL32
:
4417 status
= Reloc::addr32(view
, value
, overflow
);
4420 case elfcpp::R_POWERPC_UADDR32
:
4421 status
= Reloc::addr32_u(view
, value
, overflow
);
4424 case elfcpp::R_POWERPC_ADDR24
:
4425 case elfcpp::R_POWERPC_REL24
:
4426 case elfcpp::R_PPC_PLTREL24
:
4427 case elfcpp::R_PPC_LOCAL24PC
:
4428 status
= Reloc::addr24(view
, value
, overflow
);
4431 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4432 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
4435 status
= Reloc::addr16_ds(view
, value
, overflow
);
4438 case elfcpp::R_POWERPC_ADDR16
:
4439 case elfcpp::R_POWERPC_REL16
:
4440 case elfcpp::R_PPC64_TOC16
:
4441 case elfcpp::R_POWERPC_GOT16
:
4442 case elfcpp::R_POWERPC_SECTOFF
:
4443 case elfcpp::R_POWERPC_TPREL16
:
4444 case elfcpp::R_POWERPC_DTPREL16
:
4445 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4446 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4447 case elfcpp::R_POWERPC_GOT_TPREL16
:
4448 case elfcpp::R_POWERPC_ADDR16_LO
:
4449 case elfcpp::R_POWERPC_REL16_LO
:
4450 case elfcpp::R_PPC64_TOC16_LO
:
4451 case elfcpp::R_POWERPC_GOT16_LO
:
4452 case elfcpp::R_POWERPC_SECTOFF_LO
:
4453 case elfcpp::R_POWERPC_TPREL16_LO
:
4454 case elfcpp::R_POWERPC_DTPREL16_LO
:
4455 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
4456 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
4457 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
4458 status
= Reloc::addr16(view
, value
, overflow
);
4461 case elfcpp::R_POWERPC_UADDR16
:
4462 status
= Reloc::addr16_u(view
, value
, overflow
);
4465 case elfcpp::R_POWERPC_ADDR16_HI
:
4466 case elfcpp::R_POWERPC_REL16_HI
:
4467 case elfcpp::R_PPC64_TOC16_HI
:
4468 case elfcpp::R_POWERPC_GOT16_HI
:
4469 case elfcpp::R_POWERPC_SECTOFF_HI
:
4470 case elfcpp::R_POWERPC_TPREL16_HI
:
4471 case elfcpp::R_POWERPC_DTPREL16_HI
:
4472 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
4473 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
4474 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
4475 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
4476 Reloc::addr16_hi(view
, value
);
4479 case elfcpp::R_POWERPC_ADDR16_HA
:
4480 case elfcpp::R_POWERPC_REL16_HA
:
4481 case elfcpp::R_PPC64_TOC16_HA
:
4482 case elfcpp::R_POWERPC_GOT16_HA
:
4483 case elfcpp::R_POWERPC_SECTOFF_HA
:
4484 case elfcpp::R_POWERPC_TPREL16_HA
:
4485 case elfcpp::R_POWERPC_DTPREL16_HA
:
4486 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
4487 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
4488 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
4489 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
4490 Reloc::addr16_ha(view
, value
);
4493 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4495 // R_PPC_EMB_NADDR16_LO
4497 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4498 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4499 Reloc::addr16_hi2(view
, value
);
4502 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4504 // R_PPC_EMB_NADDR16_HI
4506 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4507 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4508 Reloc::addr16_ha2(view
, value
);
4511 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4513 // R_PPC_EMB_NADDR16_HA
4515 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4516 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4517 Reloc::addr16_hi3(view
, value
);
4520 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4524 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4525 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4526 Reloc::addr16_ha3(view
, value
);
4529 case elfcpp::R_PPC64_DTPREL16_DS
:
4530 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4532 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
4534 case elfcpp::R_PPC64_TPREL16_DS
:
4535 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4537 // R_PPC_TLSGD, R_PPC_TLSLD
4539 case elfcpp::R_PPC64_ADDR16_DS
:
4540 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4541 case elfcpp::R_PPC64_TOC16_DS
:
4542 case elfcpp::R_PPC64_TOC16_LO_DS
:
4543 case elfcpp::R_PPC64_GOT16_DS
:
4544 case elfcpp::R_PPC64_GOT16_LO_DS
:
4545 case elfcpp::R_PPC64_SECTOFF_DS
:
4546 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4547 status
= Reloc::addr16_ds(view
, value
, overflow
);
4550 case elfcpp::R_POWERPC_ADDR14
:
4551 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4552 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4553 case elfcpp::R_POWERPC_REL14
:
4554 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4555 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4556 status
= Reloc::addr14(view
, value
, overflow
);
4559 case elfcpp::R_POWERPC_COPY
:
4560 case elfcpp::R_POWERPC_GLOB_DAT
:
4561 case elfcpp::R_POWERPC_JMP_SLOT
:
4562 case elfcpp::R_POWERPC_RELATIVE
:
4563 case elfcpp::R_POWERPC_DTPMOD
:
4564 case elfcpp::R_PPC64_JMP_IREL
:
4565 case elfcpp::R_POWERPC_IRELATIVE
:
4566 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4567 _("unexpected reloc %u in object file"),
4571 case elfcpp::R_PPC_EMB_SDA21
:
4576 // R_PPC64_TOCSAVE. For the time being this can be ignored.
4580 case elfcpp::R_PPC_EMB_SDA2I16
:
4581 case elfcpp::R_PPC_EMB_SDA2REL
:
4584 // R_PPC64_TLSGD, R_PPC64_TLSLD
4587 case elfcpp::R_POWERPC_PLT32
:
4588 case elfcpp::R_POWERPC_PLTREL32
:
4589 case elfcpp::R_POWERPC_PLT16_LO
:
4590 case elfcpp::R_POWERPC_PLT16_HI
:
4591 case elfcpp::R_POWERPC_PLT16_HA
:
4592 case elfcpp::R_PPC_SDAREL16
:
4593 case elfcpp::R_POWERPC_ADDR30
:
4594 case elfcpp::R_PPC64_PLT64
:
4595 case elfcpp::R_PPC64_PLTREL64
:
4596 case elfcpp::R_PPC64_PLTGOT16
:
4597 case elfcpp::R_PPC64_PLTGOT16_LO
:
4598 case elfcpp::R_PPC64_PLTGOT16_HI
:
4599 case elfcpp::R_PPC64_PLTGOT16_HA
:
4600 case elfcpp::R_PPC64_PLT16_LO_DS
:
4601 case elfcpp::R_PPC64_PLTGOT16_DS
:
4602 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
4603 case elfcpp::R_PPC_EMB_RELSEC16
:
4604 case elfcpp::R_PPC_EMB_RELST_LO
:
4605 case elfcpp::R_PPC_EMB_RELST_HI
:
4606 case elfcpp::R_PPC_EMB_RELST_HA
:
4607 case elfcpp::R_PPC_EMB_BIT_FLD
:
4608 case elfcpp::R_PPC_EMB_RELSDA
:
4609 case elfcpp::R_PPC_TOC16
:
4612 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4613 _("unsupported reloc %u"),
4617 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
4618 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4619 _("relocation overflow"));
4624 // Relocate section data.
4626 template<int size
, bool big_endian
>
4628 Target_powerpc
<size
, big_endian
>::relocate_section(
4629 const Relocate_info
<size
, big_endian
>* relinfo
,
4630 unsigned int sh_type
,
4631 const unsigned char* prelocs
,
4633 Output_section
* output_section
,
4634 bool needs_special_offset_handling
,
4635 unsigned char* view
,
4637 section_size_type view_size
,
4638 const Reloc_symbol_changes
* reloc_symbol_changes
)
4640 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
4641 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
4643 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4645 unsigned char *opd_rel
= NULL
;
4646 Powerpc_relobj
<size
, big_endian
>* const object
4647 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4649 && relinfo
->data_shndx
== object
->opd_shndx())
4651 // Rewrite opd relocs, omitting those for discarded sections
4652 // to silence gold::relocate_section errors.
4653 const int reloc_size
4654 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4655 opd_rel
= new unsigned char[reloc_count
* reloc_size
];
4656 const unsigned char* rrel
= prelocs
;
4657 unsigned char* wrel
= opd_rel
;
4661 ++i
, rrel
+= reloc_size
, wrel
+= reloc_size
)
4663 typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4665 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
4666 = reloc
.get_r_info();
4667 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4668 Address r_off
= reloc
.get_r_offset();
4669 if (r_type
== elfcpp::R_PPC64_TOC
)
4671 bool is_discarded
= object
->get_opd_discard(r_off
);
4673 // Reloc number is reported in some errors, so keep all relocs.
4675 memset(wrel
, 0, reloc_size
);
4677 memcpy(wrel
, rrel
, reloc_size
);
4682 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
4689 needs_special_offset_handling
,
4693 reloc_symbol_changes
);
4695 if (opd_rel
!= NULL
)
4699 class Powerpc_scan_relocatable_reloc
4702 // Return the strategy to use for a local symbol which is not a
4703 // section symbol, given the relocation type.
4704 inline Relocatable_relocs::Reloc_strategy
4705 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
4707 if (r_type
== 0 && r_sym
== 0)
4708 return Relocatable_relocs::RELOC_DISCARD
;
4709 return Relocatable_relocs::RELOC_COPY
;
4712 // Return the strategy to use for a local symbol which is a section
4713 // symbol, given the relocation type.
4714 inline Relocatable_relocs::Reloc_strategy
4715 local_section_strategy(unsigned int, Relobj
*)
4717 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
4720 // Return the strategy to use for a global symbol, given the
4721 // relocation type, the object, and the symbol index.
4722 inline Relocatable_relocs::Reloc_strategy
4723 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
4725 if (r_type
== elfcpp::R_PPC_PLTREL24
)
4726 return Relocatable_relocs::RELOC_SPECIAL
;
4727 return Relocatable_relocs::RELOC_COPY
;
4731 // Scan the relocs during a relocatable link.
4733 template<int size
, bool big_endian
>
4735 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
4736 Symbol_table
* symtab
,
4738 Sized_relobj_file
<size
, big_endian
>* object
,
4739 unsigned int data_shndx
,
4740 unsigned int sh_type
,
4741 const unsigned char* prelocs
,
4743 Output_section
* output_section
,
4744 bool needs_special_offset_handling
,
4745 size_t local_symbol_count
,
4746 const unsigned char* plocal_symbols
,
4747 Relocatable_relocs
* rr
)
4749 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4751 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4752 Powerpc_scan_relocatable_reloc
>(
4760 needs_special_offset_handling
,
4766 // Emit relocations for a section.
4767 // This is a modified version of the function by the same name in
4768 // target-reloc.h. Using relocate_special_relocatable for
4769 // R_PPC_PLTREL24 would require duplication of the entire body of the
4770 // loop, so we may as well duplicate the whole thing.
4772 template<int size
, bool big_endian
>
4774 Target_powerpc
<size
, big_endian
>::relocate_relocs(
4775 const Relocate_info
<size
, big_endian
>* relinfo
,
4776 unsigned int sh_type
,
4777 const unsigned char* prelocs
,
4779 Output_section
* output_section
,
4780 off_t offset_in_output_section
,
4781 const Relocatable_relocs
* rr
,
4783 Address view_address
,
4785 unsigned char* reloc_view
,
4786 section_size_type reloc_view_size
)
4788 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4790 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4792 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
4794 const int reloc_size
4795 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4797 Powerpc_relobj
<size
, big_endian
>* const object
4798 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4799 const unsigned int local_count
= object
->local_symbol_count();
4800 unsigned int got2_shndx
= object
->got2_shndx();
4801 Address got2_addend
= 0;
4802 if (got2_shndx
!= 0)
4804 got2_addend
= object
->get_output_section_offset(got2_shndx
);
4805 gold_assert(got2_addend
!= invalid_address
);
4808 unsigned char* pwrite
= reloc_view
;
4809 bool zap_next
= false;
4810 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
4812 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
4813 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
4816 Reltype
reloc(prelocs
);
4817 Reltype_write
reloc_write(pwrite
);
4819 Address offset
= reloc
.get_r_offset();
4820 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
4821 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
4822 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4823 const unsigned int orig_r_sym
= r_sym
;
4824 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
4825 = reloc
.get_r_addend();
4826 const Symbol
* gsym
= NULL
;
4830 // We could arrange to discard these and other relocs for
4831 // tls optimised sequences in the strategy methods, but for
4832 // now do as BFD ld does.
4833 r_type
= elfcpp::R_POWERPC_NONE
;
4837 // Get the new symbol index.
4838 if (r_sym
< local_count
)
4842 case Relocatable_relocs::RELOC_COPY
:
4843 case Relocatable_relocs::RELOC_SPECIAL
:
4846 r_sym
= object
->symtab_index(r_sym
);
4847 gold_assert(r_sym
!= -1U);
4851 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
4853 // We are adjusting a section symbol. We need to find
4854 // the symbol table index of the section symbol for
4855 // the output section corresponding to input section
4856 // in which this symbol is defined.
4857 gold_assert(r_sym
< local_count
);
4859 unsigned int shndx
=
4860 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
4861 gold_assert(is_ordinary
);
4862 Output_section
* os
= object
->output_section(shndx
);
4863 gold_assert(os
!= NULL
);
4864 gold_assert(os
->needs_symtab_index());
4865 r_sym
= os
->symtab_index();
4875 gsym
= object
->global_symbol(r_sym
);
4876 gold_assert(gsym
!= NULL
);
4877 if (gsym
->is_forwarder())
4878 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
4880 gold_assert(gsym
->has_symtab_index());
4881 r_sym
= gsym
->symtab_index();
4884 // Get the new offset--the location in the output section where
4885 // this relocation should be applied.
4886 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4887 offset
+= offset_in_output_section
;
4890 section_offset_type sot_offset
=
4891 convert_types
<section_offset_type
, Address
>(offset
);
4892 section_offset_type new_sot_offset
=
4893 output_section
->output_offset(object
, relinfo
->data_shndx
,
4895 gold_assert(new_sot_offset
!= -1);
4896 offset
= new_sot_offset
;
4899 // In an object file, r_offset is an offset within the section.
4900 // In an executable or dynamic object, generated by
4901 // --emit-relocs, r_offset is an absolute address.
4902 if (!parameters
->options().relocatable())
4904 offset
+= view_address
;
4905 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4906 offset
-= offset_in_output_section
;
4909 // Handle the reloc addend based on the strategy.
4910 if (strategy
== Relocatable_relocs::RELOC_COPY
)
4912 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
4914 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
4915 addend
= psymval
->value(object
, addend
);
4917 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
4919 if (addend
>= 32768)
4920 addend
+= got2_addend
;
4925 if (!parameters
->options().relocatable())
4927 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4928 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4929 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4930 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4932 // First instruction of a global dynamic sequence,
4934 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4935 switch (this->optimize_tls_gd(final
))
4937 case tls::TLSOPT_TO_IE
:
4938 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4939 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4941 case tls::TLSOPT_TO_LE
:
4942 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4943 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4944 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4947 r_type
= elfcpp::R_POWERPC_NONE
;
4948 offset
-= 2 * big_endian
;
4955 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4956 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4957 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4958 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4960 // First instruction of a local dynamic sequence,
4962 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4964 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4965 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4967 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4968 const Output_section
* os
= relinfo
->layout
->tls_segment()
4970 gold_assert(os
!= NULL
);
4971 gold_assert(os
->needs_symtab_index());
4972 r_sym
= os
->symtab_index();
4973 addend
= dtp_offset
;
4977 r_type
= elfcpp::R_POWERPC_NONE
;
4978 offset
-= 2 * big_endian
;
4982 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4983 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4984 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4985 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4987 // First instruction of initial exec sequence.
4988 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4989 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4991 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4992 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4993 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4996 r_type
= elfcpp::R_POWERPC_NONE
;
4997 offset
-= 2 * big_endian
;
5001 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5002 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5004 // Second instruction of a global dynamic sequence,
5005 // the __tls_get_addr call
5006 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5007 switch (this->optimize_tls_gd(final
))
5009 case tls::TLSOPT_TO_IE
:
5010 r_type
= elfcpp::R_POWERPC_NONE
;
5013 case tls::TLSOPT_TO_LE
:
5014 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5015 offset
+= 2 * big_endian
;
5022 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5023 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5025 // Second instruction of a local dynamic sequence,
5026 // the __tls_get_addr call
5027 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
5029 const Output_section
* os
= relinfo
->layout
->tls_segment()
5031 gold_assert(os
!= NULL
);
5032 gold_assert(os
->needs_symtab_index());
5033 r_sym
= os
->symtab_index();
5034 addend
= dtp_offset
;
5035 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5036 offset
+= 2 * big_endian
;
5040 else if (r_type
== elfcpp::R_POWERPC_TLS
)
5042 // Second instruction of an initial exec sequence
5043 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5044 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
5046 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5047 offset
+= 2 * big_endian
;
5052 reloc_write
.put_r_offset(offset
);
5053 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
5054 reloc_write
.put_r_addend(addend
);
5056 pwrite
+= reloc_size
;
5059 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
5060 == reloc_view_size
);
5063 // Return the value to use for a dynamic which requires special
5064 // treatment. This is how we support equality comparisons of function
5065 // pointers across shared library boundaries, as described in the
5066 // processor specific ABI supplement.
5068 template<int size
, bool big_endian
>
5070 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
5074 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
5075 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5076 unsigned int glink_index
= glink
->find_entry(gsym
);
5077 return glink
->address() + glink_index
* glink
->glink_entry_size();
5083 // Return the PLT address to use for a local symbol.
5084 template<int size
, bool big_endian
>
5086 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
5087 const Relobj
* object
,
5088 unsigned int symndx
) const
5092 const Sized_relobj
<size
, big_endian
>* relobj
5093 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
5094 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5095 unsigned int glink_index
= glink
->find_entry(relobj
->sized_relobj(),
5097 return glink
->address() + glink_index
* glink
->glink_entry_size();
5103 // Return the PLT address to use for a global symbol.
5104 template<int size
, bool big_endian
>
5106 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
5107 const Symbol
* gsym
) const
5111 const Output_data_glink
<size
, big_endian
>* glink
= this->glink_section();
5112 unsigned int glink_index
= glink
->find_entry(gsym
);
5113 return glink
->address() + glink_index
* glink
->glink_entry_size();
5119 // Return the offset to use for the GOT_INDX'th got entry which is
5120 // for a local tls symbol specified by OBJECT, SYMNDX.
5121 template<int size
, bool big_endian
>
5123 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
5124 const Relobj
* object
,
5125 unsigned int symndx
,
5126 unsigned int got_indx
) const
5128 const Powerpc_relobj
<size
, big_endian
>* ppc_object
5129 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
5130 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
5132 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5133 got_type
<= GOT_TYPE_TPREL
;
5134 got_type
= Got_type(got_type
+ 1))
5135 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
5137 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
5138 if (got_type
== GOT_TYPE_TLSGD
)
5140 if (off
== got_indx
* (size
/ 8))
5142 if (got_type
== GOT_TYPE_TPREL
)
5152 // Return the offset to use for the GOT_INDX'th got entry which is
5153 // for global tls symbol GSYM.
5154 template<int size
, bool big_endian
>
5156 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
5158 unsigned int got_indx
) const
5160 if (gsym
->type() == elfcpp::STT_TLS
)
5162 for (Got_type got_type
= GOT_TYPE_TLSGD
;
5163 got_type
<= GOT_TYPE_TPREL
;
5164 got_type
= Got_type(got_type
+ 1))
5165 if (gsym
->has_got_offset(got_type
))
5167 unsigned int off
= gsym
->got_offset(got_type
);
5168 if (got_type
== GOT_TYPE_TLSGD
)
5170 if (off
== got_indx
* (size
/ 8))
5172 if (got_type
== GOT_TYPE_TPREL
)
5182 // The selector for powerpc object files.
5184 template<int size
, bool big_endian
>
5185 class Target_selector_powerpc
: public Target_selector
5188 Target_selector_powerpc()
5189 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
5191 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
5192 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
5194 ? (big_endian
? "elf64ppc" : "elf64lppc")
5195 : (big_endian
? "elf32ppc" : "elf32lppc")))
5199 do_recognize(Input_file
*, off_t
, int machine
, int, int)
5204 if (machine
!= elfcpp::EM_PPC64
)
5209 if (machine
!= elfcpp::EM_PPC
)
5217 return this->instantiate_target();
5221 do_instantiate_target()
5222 { return new Target_powerpc
<size
, big_endian
>(); }
5225 Target_selector_powerpc
<32, true> target_selector_ppc32
;
5226 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
5227 Target_selector_powerpc
<64, true> target_selector_ppc64
;
5228 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
5230 } // End anonymous namespace.