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_ent_shndx_(), opd_ent_off_(), access_from_map_(),
75 // The .got2 section shndx.
80 return this->special_
;
85 // The .opd section shndx.
92 return this->special_
;
95 // Init OPD entry arrays.
97 init_opd(size_t opd_size
)
99 size_t count
= this->opd_ent_ndx(opd_size
);
100 this->opd_ent_shndx_
.resize(count
);
101 this->opd_ent_off_
.reserve(count
);
104 // Return section and offset of function entry for .opd + R_OFF.
106 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
108 size_t ndx
= this->opd_ent_ndx(r_off
);
109 gold_assert(ndx
< this->opd_ent_shndx_
.size());
110 gold_assert(this->opd_ent_shndx_
[ndx
] != 0);
112 *value
= this->opd_ent_off_
[ndx
];
113 return this->opd_ent_shndx_
[ndx
];
116 // Set section and offset of function entry for .opd + R_OFF.
118 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
120 size_t ndx
= this->opd_ent_ndx(r_off
);
121 gold_assert(ndx
< this->opd_ent_shndx_
.size());
122 this->opd_ent_shndx_
[ndx
] = shndx
;
123 this->opd_ent_off_
[ndx
] = value
;
128 { return &this->access_from_map_
; }
130 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
131 // section at DST_OFF.
133 add_reference(Object
* src_obj
,
134 unsigned int src_indx
,
135 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
137 Section_id
src_id(src_obj
, src_indx
);
138 this->access_from_map_
[dst_off
].insert(src_id
);
143 { return this->opd_valid_
; }
147 { this->opd_valid_
= true; }
149 // Examine .rela.opd to build info about function entry points.
151 scan_opd_relocs(size_t reloc_count
,
152 const unsigned char* prelocs
,
153 const unsigned char* plocal_syms
);
156 do_read_relocs(Read_relocs_data
*);
159 do_find_special_sections(Read_symbols_data
* sd
);
161 // Return offset in output GOT section that this object will use
162 // as a TOC pointer. Won't be just a constant with multi-toc support.
164 toc_base_offset() const
168 // Return index into opd_ent_shndx or opd_ent_off array for .opd entry
169 // at OFF. .opd entries are 24 bytes long, but they can be spaced
170 // 16 bytes apart when the language doesn't use the last 8-byte
171 // word, the environment pointer. Thus dividing the entry section
172 // offset by 16 will give an index into opd_ent_shndx_ and
173 // opd_ent_off_ that works for either layout of .opd. (It leaves
174 // some elements of the vectors unused when .opd entries are spaced
175 // 24 bytes apart, but we don't know the spacing until relocations
176 // are processed, and in any case it is possible for an object to
177 // have some entries spaced 16 bytes apart and others 24 bytes apart.)
179 opd_ent_ndx(size_t off
) const
182 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
183 unsigned int special_
;
184 // The first 8-byte word of an OPD entry gives the address of the
185 // entry point of the function. Relocatable object files have a
186 // relocation on this word. The following two vectors record the
187 // section and offset specified by these relocations.
188 std::vector
<unsigned int> opd_ent_shndx_
;
189 std::vector
<Offset
> opd_ent_off_
;
190 // References made to this object's .opd section when running
191 // gc_process_relocs for another object, before the opd_ent vectors
192 // are valid for this object.
193 Access_from access_from_map_
;
194 // Set at the start of gc_process_relocs, when we know opd_ent
195 // vectors are valid. The flag could be made atomic and set in
196 // do_read_relocs with memory_order_release and then tested with
197 // memory_order_acquire, potentially resulting in fewer entries in
202 template<int size
, bool big_endian
>
203 class Target_powerpc
: public Sized_target
<size
, big_endian
>
207 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
208 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
209 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
210 static const Address invalid_address
= static_cast<Address
>(0) - 1;
211 // Offset of tp and dtp pointers from start of TLS block.
212 static const Address tp_offset
= 0x7000;
213 static const Address dtp_offset
= 0x8000;
216 : Sized_target
<size
, big_endian
>(&powerpc_info
),
217 got_(NULL
), plt_(NULL
), glink_(NULL
), rela_dyn_(NULL
),
218 copy_relocs_(elfcpp::R_POWERPC_COPY
),
219 dynbss_(NULL
), tlsld_got_offset_(-1U)
223 // Process the relocations to determine unreferenced sections for
224 // garbage collection.
226 gc_process_relocs(Symbol_table
* symtab
,
228 Sized_relobj_file
<size
, big_endian
>* object
,
229 unsigned int data_shndx
,
230 unsigned int sh_type
,
231 const unsigned char* prelocs
,
233 Output_section
* output_section
,
234 bool needs_special_offset_handling
,
235 size_t local_symbol_count
,
236 const unsigned char* plocal_symbols
);
238 // Scan the relocations to look for symbol adjustments.
240 scan_relocs(Symbol_table
* symtab
,
242 Sized_relobj_file
<size
, big_endian
>* object
,
243 unsigned int data_shndx
,
244 unsigned int sh_type
,
245 const unsigned char* prelocs
,
247 Output_section
* output_section
,
248 bool needs_special_offset_handling
,
249 size_t local_symbol_count
,
250 const unsigned char* plocal_symbols
);
252 // Map input .toc section to output .got section.
254 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
256 if (size
== 64 && strcmp(name
, ".toc") == 0)
264 // Finalize the sections.
266 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
268 // Return the value to use for a dynamic which requires special
271 do_dynsym_value(const Symbol
*) const;
273 // Return the offset to use for the GOT_INDX'th got entry which is
274 // for a local tls symbol specified by OBJECT, SYMNDX.
276 do_tls_offset_for_local(const Relobj
* object
,
278 unsigned int got_indx
) const;
280 // Return the offset to use for the GOT_INDX'th got entry which is
281 // for global tls symbol GSYM.
283 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
285 // Relocate a section.
287 relocate_section(const Relocate_info
<size
, big_endian
>*,
288 unsigned int sh_type
,
289 const unsigned char* prelocs
,
291 Output_section
* output_section
,
292 bool needs_special_offset_handling
,
294 Address view_address
,
295 section_size_type view_size
,
296 const Reloc_symbol_changes
*);
298 // Scan the relocs during a relocatable link.
300 scan_relocatable_relocs(Symbol_table
* symtab
,
302 Sized_relobj_file
<size
, big_endian
>* object
,
303 unsigned int data_shndx
,
304 unsigned int sh_type
,
305 const unsigned char* prelocs
,
307 Output_section
* output_section
,
308 bool needs_special_offset_handling
,
309 size_t local_symbol_count
,
310 const unsigned char* plocal_symbols
,
311 Relocatable_relocs
*);
313 // Emit relocations for a section.
315 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
316 unsigned int sh_type
,
317 const unsigned char* prelocs
,
319 Output_section
* output_section
,
320 off_t offset_in_output_section
,
321 const Relocatable_relocs
*,
323 Address view_address
,
325 unsigned char* reloc_view
,
326 section_size_type reloc_view_size
);
328 // Return whether SYM is defined by the ABI.
330 do_is_defined_by_abi(const Symbol
* sym
) const
332 return strcmp(sym
->name(), "__tls_get_addr") == 0;
335 // Return the size of the GOT section.
339 gold_assert(this->got_
!= NULL
);
340 return this->got_
->data_size();
343 // Get the PLT section.
344 const Output_data_plt_powerpc
<size
, big_endian
>*
347 gold_assert(this->plt_
!= NULL
);
351 // Get the .glink section.
352 const Output_data_glink
<size
, big_endian
>*
353 glink_section() const
355 gold_assert(this->glink_
!= NULL
);
359 // Get the GOT section.
360 const Output_data_got_powerpc
<size
, big_endian
>*
363 gold_assert(this->got_
!= NULL
);
368 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
369 const elfcpp::Ehdr
<size
, big_endian
>&);
371 // Return the number of entries in the GOT.
373 got_entry_count() const
375 if (this->got_
== NULL
)
377 return this->got_size() / (size
/ 8);
380 // Return the number of entries in the PLT.
382 plt_entry_count() const;
384 // Return the offset of the first non-reserved PLT entry.
386 first_plt_entry_offset() const;
388 // Return the size of each PLT entry.
390 plt_entry_size() const;
392 // Add any special sections for this symbol to the gc work list.
393 // For powerpc64, this adds the code section of a function
396 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
398 // Handle target specific gc actions when adding a gc reference from
399 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
400 // and DST_OFF. For powerpc64, this adds a referenc to the code
401 // section of a function descriptor.
403 do_gc_add_reference(Symbol_table
* symtab
,
405 unsigned int src_shndx
,
407 unsigned int dst_shndx
,
408 Address dst_off
) const;
412 // The class which scans relocations.
417 : issued_non_pic_error_(false)
421 get_reference_flags(unsigned int r_type
);
424 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
425 Sized_relobj_file
<size
, big_endian
>* object
,
426 unsigned int data_shndx
,
427 Output_section
* output_section
,
428 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
429 const elfcpp::Sym
<size
, big_endian
>& lsym
);
432 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
433 Sized_relobj_file
<size
, big_endian
>* object
,
434 unsigned int data_shndx
,
435 Output_section
* output_section
,
436 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
440 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
442 Sized_relobj_file
<size
, big_endian
>* ,
445 const elfcpp::Rela
<size
, big_endian
>& ,
447 const elfcpp::Sym
<size
, big_endian
>&)
451 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
453 Sized_relobj_file
<size
, big_endian
>* ,
456 const elfcpp::Rela
<size
,
458 unsigned int , Symbol
*)
463 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
464 unsigned int r_type
);
467 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
468 unsigned int r_type
, Symbol
*);
471 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
472 Target_powerpc
* target
);
475 check_non_pic(Relobj
*, unsigned int r_type
);
477 // Whether we have issued an error about a non-PIC compilation.
478 bool issued_non_pic_error_
;
482 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
483 Powerpc_relobj
<size
, big_endian
>* object
,
484 unsigned int *dest_shndx
);
486 // The class which implements relocation.
490 // Use 'at' branch hints when true, 'y' when false.
491 // FIXME maybe: set this with an option.
492 static const bool is_isa_v2
= true;
496 CALL_NOT_EXPECTED
= 0,
502 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
507 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
509 // FIXME: This needs to specify the location somehow.
510 gold_error(_("missing expected __tls_get_addr call"));
514 // Do a relocation. Return false if the caller should not issue
515 // any warnings about this relocation.
517 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
518 Output_section
*, size_t relnum
,
519 const elfcpp::Rela
<size
, big_endian
>&,
520 unsigned int r_type
, const Sized_symbol
<size
>*,
521 const Symbol_value
<size
>*,
523 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
526 // This is set if we should skip the next reloc, which should be a
527 // call to __tls_get_addr.
528 enum skip_tls call_tls_get_addr_
;
531 // A class which returns the size required for a relocation type,
532 // used while scanning relocs during a relocatable link.
533 class Relocatable_size_for_reloc
537 get_size_for_reloc(unsigned int, Relobj
*)
544 // Optimize the TLS relocation type based on what we know about the
545 // symbol. IS_FINAL is true if the final address of this symbol is
546 // known at link time.
548 tls::Tls_optimization
549 optimize_tls_gd(bool is_final
)
551 // If we are generating a shared library, then we can't do anything
553 if (parameters
->options().shared())
554 return tls::TLSOPT_NONE
;
557 return tls::TLSOPT_TO_IE
;
558 return tls::TLSOPT_TO_LE
;
561 tls::Tls_optimization
564 if (parameters
->options().shared())
565 return tls::TLSOPT_NONE
;
567 return tls::TLSOPT_TO_LE
;
570 tls::Tls_optimization
571 optimize_tls_ie(bool is_final
)
573 if (!is_final
|| parameters
->options().shared())
574 return tls::TLSOPT_NONE
;
576 return tls::TLSOPT_TO_LE
;
579 // Get the GOT section, creating it if necessary.
580 Output_data_got_powerpc
<size
, big_endian
>*
581 got_section(Symbol_table
*, Layout
*);
585 make_glink_section(Layout
*);
587 // Create the PLT section.
589 make_plt_section(Layout
*);
591 // Create a PLT entry for a global symbol.
593 make_plt_entry(Layout
*, Symbol
*,
594 const elfcpp::Rela
<size
, big_endian
>&,
595 const Sized_relobj
<size
, big_endian
>* object
);
597 // Create a GOT entry for local dynamic __tls_get_addr.
599 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
600 Sized_relobj_file
<size
, big_endian
>* object
);
603 tlsld_got_offset() const
605 return this->tlsld_got_offset_
;
608 // Get the dynamic reloc section, creating it if necessary.
610 rela_dyn_section(Layout
*);
612 // Copy a relocation against a global symbol.
614 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
615 Sized_relobj_file
<size
, big_endian
>* object
,
616 unsigned int shndx
, Output_section
* output_section
,
617 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
619 this->copy_relocs_
.copy_reloc(symtab
, layout
,
620 symtab
->get_sized_symbol
<size
>(sym
),
621 object
, shndx
, output_section
,
622 reloc
, this->rela_dyn_section(layout
));
625 // Information about this specific target which we pass to the
626 // general Target structure.
627 static Target::Target_info powerpc_info
;
629 // The types of GOT entries needed for this platform.
630 // These values are exposed to the ABI in an incremental link.
631 // Do not renumber existing values without changing the version
632 // number of the .gnu_incremental_inputs section.
636 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
637 GOT_TYPE_DTPREL
, // entry for @got@dtprel
638 GOT_TYPE_TPREL
// entry for @got@tprel
641 // The GOT output section.
642 Output_data_got_powerpc
<size
, big_endian
>* got_
;
643 // The PLT output section.
644 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
645 // The .glink output section.
646 Output_data_glink
<size
, big_endian
>* glink_
;
647 // The dynamic reloc output section.
648 Reloc_section
* rela_dyn_
;
649 // Relocs saved to avoid a COPY reloc.
650 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
651 // Space for variables copied with a COPY reloc.
652 Output_data_space
* dynbss_
;
653 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
654 unsigned int tlsld_got_offset_
;
658 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
661 true, // is_big_endian
662 elfcpp::EM_PPC
, // machine_code
663 false, // has_make_symbol
664 false, // has_resolve
665 false, // has_code_fill
666 true, // is_default_stack_executable
667 false, // can_icf_inline_merge_sections
669 "/usr/lib/ld.so.1", // dynamic_linker
670 0x10000000, // default_text_segment_address
671 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
672 4 * 1024, // common_pagesize (overridable by -z common-page-size)
673 false, // isolate_execinstr
675 elfcpp::SHN_UNDEF
, // small_common_shndx
676 elfcpp::SHN_UNDEF
, // large_common_shndx
677 0, // small_common_section_flags
678 0, // large_common_section_flags
679 NULL
, // attributes_section
680 NULL
// attributes_vendor
684 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
687 false, // is_big_endian
688 elfcpp::EM_PPC
, // machine_code
689 false, // has_make_symbol
690 false, // has_resolve
691 false, // has_code_fill
692 true, // is_default_stack_executable
693 false, // can_icf_inline_merge_sections
695 "/usr/lib/ld.so.1", // dynamic_linker
696 0x10000000, // default_text_segment_address
697 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
698 4 * 1024, // common_pagesize (overridable by -z common-page-size)
699 false, // isolate_execinstr
701 elfcpp::SHN_UNDEF
, // small_common_shndx
702 elfcpp::SHN_UNDEF
, // large_common_shndx
703 0, // small_common_section_flags
704 0, // large_common_section_flags
705 NULL
, // attributes_section
706 NULL
// attributes_vendor
710 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
713 true, // is_big_endian
714 elfcpp::EM_PPC64
, // machine_code
715 false, // has_make_symbol
716 false, // has_resolve
717 false, // has_code_fill
718 true, // is_default_stack_executable
719 false, // can_icf_inline_merge_sections
721 "/usr/lib/ld.so.1", // dynamic_linker
722 0x10000000, // default_text_segment_address
723 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
724 4 * 1024, // common_pagesize (overridable by -z common-page-size)
725 false, // isolate_execinstr
727 elfcpp::SHN_UNDEF
, // small_common_shndx
728 elfcpp::SHN_UNDEF
, // large_common_shndx
729 0, // small_common_section_flags
730 0, // large_common_section_flags
731 NULL
, // attributes_section
732 NULL
// attributes_vendor
736 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
739 false, // is_big_endian
740 elfcpp::EM_PPC64
, // machine_code
741 false, // has_make_symbol
742 false, // has_resolve
743 false, // has_code_fill
744 true, // is_default_stack_executable
745 false, // can_icf_inline_merge_sections
747 "/usr/lib/ld.so.1", // dynamic_linker
748 0x10000000, // default_text_segment_address
749 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
750 4 * 1024, // common_pagesize (overridable by -z common-page-size)
751 false, // isolate_execinstr
753 elfcpp::SHN_UNDEF
, // small_common_shndx
754 elfcpp::SHN_UNDEF
, // large_common_shndx
755 0, // small_common_section_flags
756 0, // large_common_section_flags
757 NULL
, // attributes_section
758 NULL
// attributes_vendor
762 is_branch_reloc(unsigned int r_type
)
764 return (r_type
== elfcpp::R_POWERPC_REL24
765 || r_type
== elfcpp::R_PPC_PLTREL24
766 || r_type
== elfcpp::R_PPC_LOCAL24PC
767 || r_type
== elfcpp::R_POWERPC_REL14
768 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
769 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
770 || r_type
== elfcpp::R_POWERPC_ADDR24
771 || r_type
== elfcpp::R_POWERPC_ADDR14
772 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
773 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
776 // If INSN is an opcode that may be used with an @tls operand, return
777 // the transformed insn for TLS optimisation, otherwise return 0. If
778 // REG is non-zero only match an insn with RB or RA equal to REG.
780 at_tls_transform(uint32_t insn
, unsigned int reg
)
782 if ((insn
& (0x3f << 26)) != 31 << 26)
786 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
787 rtra
= insn
& ((1 << 26) - (1 << 16));
788 else if (((insn
>> 16) & 0x1f) == reg
)
789 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
793 if ((insn
& (0x3ff << 1)) == 266 << 1)
796 else if ((insn
& (0x1f << 1)) == 23 << 1
797 && ((insn
& (0x1f << 6)) < 14 << 6
798 || ((insn
& (0x1f << 6)) >= 16 << 6
799 && (insn
& (0x1f << 6)) < 24 << 6)))
800 // load and store indexed -> dform
801 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
802 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
803 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
804 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
805 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
807 insn
= (58 << 26) | 2;
814 // Modified version of symtab.h class Symbol member
815 // Given a direct absolute or pc-relative static relocation against
816 // the global symbol, this function returns whether a dynamic relocation
821 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
823 // No dynamic relocations in a static link!
824 if (parameters
->doing_static_link())
827 // A reference to an undefined symbol from an executable should be
828 // statically resolved to 0, and does not need a dynamic relocation.
829 // This matches gnu ld behavior.
830 if (gsym
->is_undefined() && !parameters
->options().shared())
833 // A reference to an absolute symbol does not need a dynamic relocation.
834 if (gsym
->is_absolute())
837 // An absolute reference within a position-independent output file
838 // will need a dynamic relocation.
839 if ((flags
& Symbol::ABSOLUTE_REF
)
840 && parameters
->options().output_is_position_independent())
843 // A function call that can branch to a local PLT entry does not need
844 // a dynamic relocation.
845 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
848 // A reference to any PLT entry in a non-position-independent executable
849 // does not need a dynamic relocation.
850 // Except due to having function descriptors on powerpc64 we don't define
851 // functions to their plt code in an executable, so this doesn't apply.
853 && !parameters
->options().output_is_position_independent()
854 && gsym
->has_plt_offset())
857 // A reference to a symbol defined in a dynamic object or to a
858 // symbol that is preemptible will need a dynamic relocation.
859 if (gsym
->is_from_dynobj()
860 || gsym
->is_undefined()
861 || gsym
->is_preemptible())
864 // For all other cases, return FALSE.
868 // Modified version of symtab.h class Symbol member
869 // Whether we should use the PLT offset associated with a symbol for
870 // a relocation. FLAGS is a set of Reference_flags.
874 use_plt_offset(const Symbol
* gsym
, int flags
)
876 // If the symbol doesn't have a PLT offset, then naturally we
877 // don't want to use it.
878 if (!gsym
->has_plt_offset())
881 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
882 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
885 // If we are going to generate a dynamic relocation, then we will
886 // wind up using that, so no need to use the PLT entry.
887 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
890 // If the symbol is from a dynamic object, we need to use the PLT
892 if (gsym
->is_from_dynobj())
895 // If we are generating a shared object, and gsym symbol is
896 // undefined or preemptible, we need to use the PLT entry.
897 if (parameters
->options().shared()
898 && (gsym
->is_undefined() || gsym
->is_preemptible()))
901 // If gsym is a call to a weak undefined symbol, we need to use
902 // the PLT entry; the symbol may be defined by a library loaded
904 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
907 // Otherwise we can use the regular definition.
911 template<int size
, bool big_endian
>
912 class Powerpc_relocate_functions
929 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
930 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
932 template<int valsize
>
934 has_overflow_signed(Address value
)
936 // limit = 1 << (valsize - 1) without shift count exceeding size of type
937 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
938 limit
<<= ((valsize
- 1) >> 1);
939 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
940 return value
+ limit
> (limit
<< 1) - 1;
943 template<int valsize
>
945 has_overflow_bitfield(Address value
)
947 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
948 limit
<<= ((valsize
- 1) >> 1);
949 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
950 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
953 template<int valsize
>
955 overflowed(Address value
, Overflow_check overflow
)
957 if (overflow
== CHECK_SIGNED
)
959 if (has_overflow_signed
<valsize
>(value
))
960 return STATUS_OVERFLOW
;
962 else if (overflow
== CHECK_BITFIELD
)
964 if (has_overflow_bitfield
<valsize
>(value
))
965 return STATUS_OVERFLOW
;
970 // Do a simple RELA relocation
971 template<int valsize
>
973 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
975 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
976 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
977 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
978 return overflowed
<valsize
>(value
, overflow
);
981 template<int valsize
>
983 rela(unsigned char* view
,
984 unsigned int right_shift
,
985 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
987 Overflow_check overflow
)
989 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
990 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
991 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
992 Valtype reloc
= value
>> right_shift
;
995 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
996 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
999 // Do a simple RELA relocation, unaligned.
1000 template<int valsize
>
1001 static inline Status
1002 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1004 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1005 return overflowed
<valsize
>(value
, overflow
);
1008 template<int valsize
>
1009 static inline Status
1010 rela_ua(unsigned char* view
,
1011 unsigned int right_shift
,
1012 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1014 Overflow_check overflow
)
1016 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1018 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1019 Valtype reloc
= value
>> right_shift
;
1022 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1023 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1027 // R_PPC64_ADDR64: (Symbol + Addend)
1029 addr64(unsigned char* view
, Address value
)
1030 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1032 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1034 addr64_u(unsigned char* view
, Address value
)
1035 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1037 // R_POWERPC_ADDR32: (Symbol + Addend)
1038 static inline Status
1039 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1040 { return This::template rela
<32>(view
, value
, overflow
); }
1042 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1043 static inline Status
1044 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1045 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1047 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1048 static inline Status
1049 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1051 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1052 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1053 stat
= STATUS_OVERFLOW
;
1057 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1058 static inline Status
1059 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1060 { return This::template rela
<16>(view
, value
, overflow
); }
1062 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1063 static inline Status
1064 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1065 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1067 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1068 static inline Status
1069 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1071 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1072 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1073 stat
= STATUS_OVERFLOW
;
1077 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1079 addr16_hi(unsigned char* view
, Address value
)
1080 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1082 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1084 addr16_ha(unsigned char* view
, Address value
)
1085 { This::addr16_hi(view
, value
+ 0x8000); }
1087 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1089 addr16_hi2(unsigned char* view
, Address value
)
1090 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1092 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1094 addr16_ha2(unsigned char* view
, Address value
)
1095 { This::addr16_hi2(view
, value
+ 0x8000); }
1097 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1099 addr16_hi3(unsigned char* view
, Address value
)
1100 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1102 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1104 addr16_ha3(unsigned char* view
, Address value
)
1105 { This::addr16_hi3(view
, value
+ 0x8000); }
1107 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1108 static inline Status
1109 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1111 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1112 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1113 stat
= STATUS_OVERFLOW
;
1118 // Stash away the index of .got2 or .opd in a relocatable object, if
1119 // such a section exists.
1121 template<int size
, bool big_endian
>
1123 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1124 Read_symbols_data
* sd
)
1126 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1127 const unsigned char* namesu
= sd
->section_names
->data();
1128 const char* names
= reinterpret_cast<const char*>(namesu
);
1129 section_size_type names_size
= sd
->section_names_size
;
1130 const unsigned char* s
;
1132 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1133 names
, names_size
, NULL
);
1136 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1137 this->special_
= ndx
;
1139 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1142 // Examine .rela.opd to build info about function entry points.
1144 template<int size
, bool big_endian
>
1146 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1148 const unsigned char* prelocs
,
1149 const unsigned char* plocal_syms
)
1153 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1155 const int reloc_size
1156 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1157 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1159 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1161 Reltype
reloc(prelocs
);
1162 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1163 = reloc
.get_r_info();
1164 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1165 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1167 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1168 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1171 if (r_sym
< this->local_symbol_count())
1173 typename
elfcpp::Sym
<size
, big_endian
>
1174 lsym(plocal_syms
+ r_sym
* sym_size
);
1175 shndx
= lsym
.get_st_shndx();
1176 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1177 value
= lsym
.get_st_value();
1180 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1182 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1183 value
+ reloc
.get_r_addend());
1189 template<int size
, bool big_endian
>
1191 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1193 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1196 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1197 p
!= rd
->relocs
.end();
1200 if (p
->data_shndx
== this->opd_shndx())
1202 this->init_opd(this->section_size(this->opd_shndx()));
1203 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1204 rd
->local_symbols
->data());
1211 // Set up PowerPC target specific relobj.
1213 template<int size
, bool big_endian
>
1215 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1216 const std::string
& name
,
1217 Input_file
* input_file
,
1218 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1220 int et
= ehdr
.get_e_type();
1221 // ET_EXEC files are valid input for --just-symbols/-R,
1222 // and we treat them as relocatable objects.
1223 if (et
== elfcpp::ET_REL
1224 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1226 Powerpc_relobj
<size
, big_endian
>* obj
=
1227 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1231 else if (et
== elfcpp::ET_DYN
)
1233 Sized_dynobj
<size
, big_endian
>* obj
=
1234 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1240 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1245 template<int size
, bool big_endian
>
1246 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1249 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1250 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1252 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1253 : Output_data_got
<size
, big_endian
>(),
1254 symtab_(symtab
), layout_(layout
),
1255 header_ent_cnt_(size
== 32 ? 3 : 1),
1256 header_index_(size
== 32 ? 0x2000 : 0)
1261 // Create a new GOT entry and return its offset.
1263 add_got_entry(Got_entry got_entry
)
1265 this->reserve_ent();
1266 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1269 // Create a pair of new GOT entries and return the offset of the first.
1271 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1273 this->reserve_ent(2);
1274 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1279 add_constant_pair(Valtype c1
, Valtype c2
)
1281 this->reserve_ent(2);
1282 unsigned int got_offset
= this->add_constant(c1
);
1283 this->add_constant(c2
);
1287 // Offset of _GLOBAL_OFFSET_TABLE_.
1291 return this->got_offset(this->header_index_
);
1294 // Offset of base used to access the GOT/TOC.
1295 // The got/toc pointer reg will be set to this value.
1296 typename
elfcpp::Elf_types
<size
>::Elf_Off
1297 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1300 return this->g_o_t();
1302 return (this->output_section()->address()
1303 + object
->toc_base_offset()
1307 // Ensure our GOT has a header.
1309 set_final_data_size()
1311 if (this->header_ent_cnt_
!= 0)
1312 this->make_header();
1313 Output_data_got
<size
, big_endian
>::set_final_data_size();
1316 // First word of GOT header needs some values that are not
1317 // handled by Output_data_got so poke them in here.
1318 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1320 do_write(Output_file
* of
)
1322 this->replace_constant(this->header_index_
,
1324 ? this->layout_
->dynamic_section()->address()
1325 : this->output_section()->address() + 0x8000));
1327 Output_data_got
<size
, big_endian
>::do_write(of
);
1332 reserve_ent(unsigned int cnt
= 1)
1334 if (this->header_ent_cnt_
== 0)
1336 if (this->num_entries() + cnt
> this->header_index_
)
1337 this->make_header();
1343 this->header_ent_cnt_
= 0;
1344 this->header_index_
= this->num_entries();
1347 Output_data_got
<size
, big_endian
>::add_constant(0);
1348 Output_data_got
<size
, big_endian
>::add_constant(0);
1349 Output_data_got
<size
, big_endian
>::add_constant(0);
1351 // Define _GLOBAL_OFFSET_TABLE_ at the header
1352 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1353 Symbol_table::PREDEFINED
,
1354 this, this->g_o_t(), 0,
1361 Output_data_got
<size
, big_endian
>::add_constant(0);
1364 // Stashed pointers.
1365 Symbol_table
* symtab_
;
1369 unsigned int header_ent_cnt_
;
1370 // GOT header index.
1371 unsigned int header_index_
;
1374 // Get the GOT section, creating it if necessary.
1376 template<int size
, bool big_endian
>
1377 Output_data_got_powerpc
<size
, big_endian
>*
1378 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1381 if (this->got_
== NULL
)
1383 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1386 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1388 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1389 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1390 this->got_
, ORDER_DATA
, false);
1396 // Get the dynamic reloc section, creating it if necessary.
1398 template<int size
, bool big_endian
>
1399 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1400 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1402 if (this->rela_dyn_
== NULL
)
1404 gold_assert(layout
!= NULL
);
1405 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1406 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1407 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1408 ORDER_DYNAMIC_RELOCS
, false);
1410 return this->rela_dyn_
;
1413 // A class to handle the PLT data.
1415 template<int size
, bool big_endian
>
1416 class Output_data_plt_powerpc
: public Output_section_data_build
1419 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1420 size
, big_endian
> Reloc_section
;
1422 Output_data_plt_powerpc(Layout
*, Target_powerpc
<size
, big_endian
>*);
1424 // Add an entry to the PLT.
1428 // Return the .rela.plt section data.
1429 const Reloc_section
*
1435 // Return the number of PLT entries.
1439 return ((this->current_data_size() - initial_plt_entry_size
)
1443 // Return the offset of the first non-reserved PLT entry.
1445 first_plt_entry_offset()
1446 { return initial_plt_entry_size
; }
1448 // Return the size of a PLT entry.
1450 get_plt_entry_size()
1451 { return plt_entry_size
; }
1455 do_adjust_output_section(Output_section
* os
)
1460 // Write to a map file.
1462 do_print_to_mapfile(Mapfile
* mapfile
) const
1463 { mapfile
->print_output_data(this, _("** PLT")); }
1466 // The size of an entry in the PLT.
1467 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1468 // The size of the first reserved entry.
1469 static const int initial_plt_entry_size
= size
== 32 ? 0 : 24;
1471 // Write out the PLT data.
1473 do_write(Output_file
*);
1475 // The reloc section.
1476 Reloc_section
* rel_
;
1477 // Allows access to .glink for do_write.
1478 Target_powerpc
<size
, big_endian
>* targ_
;
1481 // Create the PLT section.
1483 template<int size
, bool big_endian
>
1484 Output_data_plt_powerpc
<size
, big_endian
>::Output_data_plt_powerpc(
1486 Target_powerpc
<size
, big_endian
>* targ
)
1487 : Output_section_data_build(size
== 32 ? 4 : 8),
1490 this->rel_
= new Reloc_section(false);
1491 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1492 elfcpp::SHF_ALLOC
, this->rel_
,
1493 ORDER_DYNAMIC_PLT_RELOCS
, false);
1496 // Add an entry to the PLT.
1498 template<int size
, bool big_endian
>
1500 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1502 if (!gsym
->has_plt_offset())
1504 off_t off
= this->current_data_size();
1507 off
+= initial_plt_entry_size
;
1508 gsym
->set_plt_offset(off
);
1509 gsym
->set_needs_dynsym_entry();
1510 this->rel_
->add_global(gsym
, elfcpp::R_POWERPC_JMP_SLOT
, this, off
, 0);
1511 off
+= plt_entry_size
;
1512 this->set_current_data_size(off
);
1516 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1517 static const uint32_t add_3_3_2
= 0x7c631214;
1518 static const uint32_t add_3_3_13
= 0x7c636a14;
1519 static const uint32_t add_11_0_11
= 0x7d605a14;
1520 static const uint32_t add_12_2_11
= 0x7d825a14;
1521 static const uint32_t addi_11_11
= 0x396b0000;
1522 static const uint32_t addi_12_12
= 0x398c0000;
1523 static const uint32_t addi_2_2
= 0x38420000;
1524 static const uint32_t addi_3_2
= 0x38620000;
1525 static const uint32_t addi_3_3
= 0x38630000;
1526 static const uint32_t addis_0_2
= 0x3c020000;
1527 static const uint32_t addis_0_13
= 0x3c0d0000;
1528 static const uint32_t addis_11_11
= 0x3d6b0000;
1529 static const uint32_t addis_11_30
= 0x3d7e0000;
1530 static const uint32_t addis_12_12
= 0x3d8c0000;
1531 static const uint32_t addis_12_2
= 0x3d820000;
1532 static const uint32_t addis_3_2
= 0x3c620000;
1533 static const uint32_t addis_3_13
= 0x3c6d0000;
1534 static const uint32_t b
= 0x48000000;
1535 static const uint32_t bcl_20_31
= 0x429f0005;
1536 static const uint32_t bctr
= 0x4e800420;
1537 static const uint32_t blrl
= 0x4e800021;
1538 static const uint32_t cror_15_15_15
= 0x4def7b82;
1539 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1540 static const uint32_t ld_11_12
= 0xe96c0000;
1541 static const uint32_t ld_11_2
= 0xe9620000;
1542 static const uint32_t ld_2_1
= 0xe8410000;
1543 static const uint32_t ld_2_11
= 0xe84b0000;
1544 static const uint32_t ld_2_12
= 0xe84c0000;
1545 static const uint32_t ld_2_2
= 0xe8420000;
1546 static const uint32_t li_0_0
= 0x38000000;
1547 static const uint32_t lis_0_0
= 0x3c000000;
1548 static const uint32_t lis_11
= 0x3d600000;
1549 static const uint32_t lis_12
= 0x3d800000;
1550 static const uint32_t lwz_0_12
= 0x800c0000;
1551 static const uint32_t lwz_11_11
= 0x816b0000;
1552 static const uint32_t lwz_11_30
= 0x817e0000;
1553 static const uint32_t lwz_12_12
= 0x818c0000;
1554 static const uint32_t lwzu_0_12
= 0x840c0000;
1555 static const uint32_t mflr_0
= 0x7c0802a6;
1556 static const uint32_t mflr_11
= 0x7d6802a6;
1557 static const uint32_t mflr_12
= 0x7d8802a6;
1558 static const uint32_t mtctr_0
= 0x7c0903a6;
1559 static const uint32_t mtctr_11
= 0x7d6903a6;
1560 static const uint32_t mtlr_0
= 0x7c0803a6;
1561 static const uint32_t mtlr_12
= 0x7d8803a6;
1562 static const uint32_t nop
= 0x60000000;
1563 static const uint32_t ori_0_0_0
= 0x60000000;
1564 static const uint32_t std_2_1
= 0xf8410000;
1565 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1567 // Write out the PLT.
1569 template<int size
, bool big_endian
>
1571 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1575 const off_t offset
= this->offset();
1576 const section_size_type oview_size
1577 = convert_to_section_size_type(this->data_size());
1578 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1579 unsigned char* pov
= oview
;
1580 unsigned char* endpov
= oview
+ oview_size
;
1582 // The address the .glink branch table
1583 const Output_data_glink
<size
, big_endian
>* glink
1584 = this->targ_
->glink_section();
1585 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1586 = glink
->address() + glink
->pltresolve();
1588 while (pov
< endpov
)
1590 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1595 of
->write_output_view(offset
, oview_size
, oview
);
1599 // Create the PLT section.
1601 template<int size
, bool big_endian
>
1603 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1605 if (this->plt_
== NULL
)
1607 if (this->glink_
== NULL
)
1608 make_glink_section(layout
);
1610 // Ensure that .rela.dyn always appears before .rela.plt This is
1611 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1612 // needs to include .rela.plt in it's range.
1613 this->rela_dyn_section(layout
);
1615 this->plt_
= new Output_data_plt_powerpc
<size
, big_endian
>(layout
, this);
1616 layout
->add_output_section_data(".plt",
1618 ? elfcpp::SHT_PROGBITS
1619 : elfcpp::SHT_NOBITS
),
1620 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1629 // A class to handle .glink.
1631 template<int size
, bool big_endian
>
1632 class Output_data_glink
: public Output_section_data
1635 static const int pltresolve_size
= 16*4;
1637 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1641 add_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1642 const Sized_relobj
<size
, big_endian
>*);
1645 find_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1646 const Sized_relobj
<size
, big_endian
>*) const;
1649 glink_entry_size() const
1654 // FIXME: We should be using multiple glink sections for
1655 // stubs to support > 33M applications.
1662 return this->pltresolve_
;
1666 // Write to a map file.
1668 do_print_to_mapfile(Mapfile
* mapfile
) const
1669 { mapfile
->print_output_data(this, _("** glink")); }
1673 set_final_data_size();
1677 do_write(Output_file
*);
1682 Glink_sym_ent(const Symbol
* sym
,
1683 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1684 const Sized_relobj
<size
, big_endian
>* object
)
1685 : sym_(sym
), addend_(0), object_(0)
1688 this->addend_
= reloc
.get_r_addend();
1689 else if (parameters
->options().output_is_position_independent()
1690 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1691 == elfcpp::R_PPC_PLTREL24
))
1693 this->addend_
= reloc
.get_r_addend();
1694 if (this->addend_
!= 0)
1695 this->object_
= object
;
1699 bool operator==(const Glink_sym_ent
& that
) const
1701 return (this->sym_
== that
.sym_
1702 && this->object_
== that
.object_
1703 && this->addend_
== that
.addend_
);
1707 unsigned int addend_
;
1708 const Sized_relobj
<size
, big_endian
>* object_
;
1711 class Glink_sym_ent_hash
1714 size_t operator()(const Glink_sym_ent
& ent
) const
1716 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1717 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1722 // Map sym/object/addend to index.
1723 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1724 Glink_sym_ent_hash
> Glink_entries
;
1725 Glink_entries glink_entries_
;
1727 // Offset of pltresolve stub (actually, branch table for 32-bit)
1730 // Allows access to .got and .plt for do_write.
1731 Target_powerpc
<size
, big_endian
>* targ_
;
1734 // Create the glink section.
1736 template<int size
, bool big_endian
>
1737 Output_data_glink
<size
, big_endian
>::Output_data_glink(
1738 Target_powerpc
<size
, big_endian
>* targ
)
1739 : Output_section_data(16),
1740 pltresolve_(0), targ_(targ
)
1744 // Add an entry to glink, if we do not already have one for this
1745 // sym/object/addend combo.
1747 template<int size
, bool big_endian
>
1749 Output_data_glink
<size
, big_endian
>::add_entry(
1751 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1752 const Sized_relobj
<size
, big_endian
>* object
)
1754 Glink_sym_ent
ent(gsym
, reloc
, object
);
1755 unsigned int indx
= this->glink_entries_
.size();
1756 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
1759 template<int size
, bool big_endian
>
1761 Output_data_glink
<size
, big_endian
>::find_entry(
1763 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1764 const Sized_relobj
<size
, big_endian
>* object
) const
1766 Glink_sym_ent
ent(gsym
, reloc
, object
);
1767 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
1768 gold_assert(p
!= this->glink_entries_
.end());
1772 template<int size
, bool big_endian
>
1774 Output_data_glink
<size
, big_endian
>::set_final_data_size()
1776 unsigned int count
= this->glink_entries_
.size();
1777 off_t total
= count
;
1784 this->pltresolve_
= total
;
1786 // space for branch table
1787 total
+= 4 * (count
- 1);
1789 total
+= -total
& 15;
1790 total
+= this->pltresolve_size
;
1795 this->pltresolve_
= total
;
1796 total
+= this->pltresolve_size
;
1798 // space for branch table
1801 total
+= 4 * (count
- 0x8000);
1805 this->set_data_size(total
);
1808 static inline uint32_t
1814 static inline uint32_t
1820 static inline uint32_t
1823 return hi(a
+ 0x8000);
1826 template<bool big_endian
>
1828 write_insn(unsigned char* p
, uint32_t v
)
1830 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
1833 // Write out .glink.
1835 template<int size
, bool big_endian
>
1837 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
1839 const off_t off
= this->offset();
1840 const section_size_type oview_size
=
1841 convert_to_section_size_type(this->data_size());
1842 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1845 // The base address of the .plt section.
1846 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1847 Address plt_base
= this->targ_
->plt_section()->address();
1849 const Output_data_got_powerpc
<size
, big_endian
>* got
1850 = this->targ_
->got_section();
1854 Address got_os_addr
= got
->output_section()->address();
1856 // Write out call stubs.
1857 typename
Glink_entries::const_iterator g
;
1858 for (g
= this->glink_entries_
.begin();
1859 g
!= this->glink_entries_
.end();
1862 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1863 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1864 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1865 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
1866 Address pltoff
= plt_addr
- got_addr
;
1868 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
1869 gold_error(_("%s: linkage table error against `%s'"),
1870 g
->first
.object_
->name().c_str(),
1871 g
->first
.sym_
->demangled_name().c_str());
1873 p
= oview
+ g
->second
* this->glink_entry_size();
1874 if (ha(pltoff
) != 0)
1876 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
1877 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1878 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
1879 if (ha(pltoff
+ 16) != ha(pltoff
))
1881 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
1884 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1885 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
1886 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
1887 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1891 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1892 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
1893 if (ha(pltoff
+ 16) != ha(pltoff
))
1895 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
1898 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1899 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
1900 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
1901 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1905 // Write pltresolve stub.
1906 p
= oview
+ this->pltresolve_
;
1907 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
1908 Address pltoff
= plt_base
- after_bcl
;
1910 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
1912 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
1913 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
1914 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
1915 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
1916 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
1917 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
1918 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
1919 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
1920 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1921 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
1922 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1923 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
1924 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1926 // Write lazy link call stubs.
1928 while (p
< oview
+ oview_size
)
1932 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
1936 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
1937 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
1939 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
1940 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
1946 // The address of _GLOBAL_OFFSET_TABLE_.
1947 Address g_o_t
= got
->address() + got
->g_o_t();
1949 // Write out call stubs.
1950 typename
Glink_entries::const_iterator g
;
1951 for (g
= this->glink_entries_
.begin();
1952 g
!= this->glink_entries_
.end();
1955 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1957 const Address invalid_address
= static_cast<Address
>(-1);
1959 p
= oview
+ g
->second
* this->glink_entry_size();
1960 if (parameters
->options().output_is_position_independent())
1962 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
1963 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1966 unsigned int got2
= object
->got2_shndx();
1967 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
1968 gold_assert(got_addr
!= invalid_address
);
1969 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
1970 + g
->first
.addend_
);
1975 Address pltoff
= plt_addr
- got_addr
;
1976 if (ha(pltoff
) == 0)
1978 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
1979 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
1980 write_insn
<big_endian
>(p
+ 8, bctr
);
1984 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
1985 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
1986 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1987 write_insn
<big_endian
>(p
+ 12, bctr
);
1992 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
1993 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
1994 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1995 write_insn
<big_endian
>(p
+ 12, bctr
);
1999 // Write out pltresolve branch table.
2000 p
= oview
+ this->pltresolve_
;
2001 unsigned int the_end
= oview_size
- this->pltresolve_size
;
2002 unsigned char* end_p
= oview
+ the_end
;
2003 while (p
< end_p
- 8 * 4)
2004 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
2006 write_insn
<big_endian
>(p
, nop
), p
+= 4;
2008 // Write out pltresolve call stub.
2009 if (parameters
->options().output_is_position_independent())
2011 Address res0_off
= this->pltresolve_
;
2012 Address after_bcl_off
= the_end
+ 12;
2013 Address bcl_res0
= after_bcl_off
- res0_off
;
2015 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2016 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2017 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2018 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2019 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2020 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2021 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2023 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2025 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2026 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2028 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2029 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2033 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2034 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2036 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2037 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2038 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2039 write_insn
<big_endian
>(p
+ 52, bctr
);
2040 write_insn
<big_endian
>(p
+ 56, nop
);
2041 write_insn
<big_endian
>(p
+ 60, nop
);
2045 Address res0
= this->pltresolve_
+ this->address();
2047 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2048 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2049 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2050 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2052 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2053 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2054 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2055 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2056 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2057 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2059 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2060 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2061 write_insn
<big_endian
>(p
+ 32, bctr
);
2062 write_insn
<big_endian
>(p
+ 36, nop
);
2063 write_insn
<big_endian
>(p
+ 40, nop
);
2064 write_insn
<big_endian
>(p
+ 44, nop
);
2065 write_insn
<big_endian
>(p
+ 48, nop
);
2066 write_insn
<big_endian
>(p
+ 52, nop
);
2067 write_insn
<big_endian
>(p
+ 56, nop
);
2068 write_insn
<big_endian
>(p
+ 60, nop
);
2073 of
->write_output_view(off
, oview_size
, oview
);
2076 // Create the glink section.
2078 template<int size
, bool big_endian
>
2080 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2082 if (this->glink_
== NULL
)
2084 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2085 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2086 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2087 this->glink_
, ORDER_TEXT
, false);
2091 // Create a PLT entry for a global symbol.
2093 template<int size
, bool big_endian
>
2095 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2098 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2099 const Sized_relobj
<size
, big_endian
>* object
)
2101 if (this->plt_
== NULL
)
2102 this->make_plt_section(layout
);
2104 this->plt_
->add_entry(gsym
);
2106 this->glink_
->add_entry(gsym
, reloc
, object
);
2109 // Return the number of entries in the PLT.
2111 template<int size
, bool big_endian
>
2113 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2115 if (this->plt_
== NULL
)
2117 return this->plt_
->entry_count();
2120 // Return the offset of the first non-reserved PLT entry.
2122 template<int size
, bool big_endian
>
2124 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2126 return Output_data_plt_powerpc
<size
, big_endian
>::first_plt_entry_offset();
2129 // Return the size of each PLT entry.
2131 template<int size
, bool big_endian
>
2133 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2135 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2138 // Create a GOT entry for local dynamic __tls_get_addr calls.
2140 template<int size
, bool big_endian
>
2142 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2143 Symbol_table
* symtab
,
2145 Sized_relobj_file
<size
, big_endian
>* object
)
2147 if (this->tlsld_got_offset_
== -1U)
2149 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2150 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2151 Output_data_got_powerpc
<size
, big_endian
>* got
2152 = this->got_section(symtab
, layout
);
2153 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2154 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2156 this->tlsld_got_offset_
= got_offset
;
2158 return this->tlsld_got_offset_
;
2161 // Get the Reference_flags for a particular relocation.
2163 template<int size
, bool big_endian
>
2165 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2169 case elfcpp::R_POWERPC_NONE
:
2170 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2171 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2172 case elfcpp::R_PPC64_TOC
:
2173 // No symbol reference.
2176 case elfcpp::R_PPC64_ADDR64
:
2177 case elfcpp::R_PPC64_UADDR64
:
2178 case elfcpp::R_POWERPC_ADDR32
:
2179 case elfcpp::R_POWERPC_UADDR32
:
2180 case elfcpp::R_POWERPC_ADDR16
:
2181 case elfcpp::R_POWERPC_UADDR16
:
2182 case elfcpp::R_POWERPC_ADDR16_LO
:
2183 case elfcpp::R_POWERPC_ADDR16_HI
:
2184 case elfcpp::R_POWERPC_ADDR16_HA
:
2185 return Symbol::ABSOLUTE_REF
;
2187 case elfcpp::R_POWERPC_ADDR24
:
2188 case elfcpp::R_POWERPC_ADDR14
:
2189 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2190 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2191 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2193 case elfcpp::R_POWERPC_REL32
:
2194 case elfcpp::R_PPC_LOCAL24PC
:
2195 case elfcpp::R_POWERPC_REL16
:
2196 case elfcpp::R_POWERPC_REL16_LO
:
2197 case elfcpp::R_POWERPC_REL16_HI
:
2198 case elfcpp::R_POWERPC_REL16_HA
:
2199 return Symbol::RELATIVE_REF
;
2201 case elfcpp::R_POWERPC_REL24
:
2202 case elfcpp::R_PPC_PLTREL24
:
2203 case elfcpp::R_POWERPC_REL14
:
2204 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2205 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2206 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2208 case elfcpp::R_POWERPC_GOT16
:
2209 case elfcpp::R_POWERPC_GOT16_LO
:
2210 case elfcpp::R_POWERPC_GOT16_HI
:
2211 case elfcpp::R_POWERPC_GOT16_HA
:
2212 case elfcpp::R_PPC64_TOC16
:
2213 case elfcpp::R_PPC64_TOC16_LO
:
2214 case elfcpp::R_PPC64_TOC16_HI
:
2215 case elfcpp::R_PPC64_TOC16_HA
:
2216 case elfcpp::R_PPC64_TOC16_DS
:
2217 case elfcpp::R_PPC64_TOC16_LO_DS
:
2219 return Symbol::ABSOLUTE_REF
;
2221 case elfcpp::R_POWERPC_GOT_TPREL16
:
2222 case elfcpp::R_POWERPC_TLS
:
2223 return Symbol::TLS_REF
;
2225 case elfcpp::R_POWERPC_COPY
:
2226 case elfcpp::R_POWERPC_GLOB_DAT
:
2227 case elfcpp::R_POWERPC_JMP_SLOT
:
2228 case elfcpp::R_POWERPC_RELATIVE
:
2229 case elfcpp::R_POWERPC_DTPMOD
:
2231 // Not expected. We will give an error later.
2236 // Report an unsupported relocation against a local symbol.
2238 template<int size
, bool big_endian
>
2240 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2241 Sized_relobj_file
<size
, big_endian
>* object
,
2242 unsigned int r_type
)
2244 gold_error(_("%s: unsupported reloc %u against local symbol"),
2245 object
->name().c_str(), r_type
);
2248 // We are about to emit a dynamic relocation of type R_TYPE. If the
2249 // dynamic linker does not support it, issue an error.
2251 template<int size
, bool big_endian
>
2253 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2254 unsigned int r_type
)
2256 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
2258 // These are the relocation types supported by glibc for both 32-bit
2259 // and 64-bit powerpc.
2262 case elfcpp::R_POWERPC_NONE
:
2263 case elfcpp::R_POWERPC_RELATIVE
:
2264 case elfcpp::R_POWERPC_GLOB_DAT
:
2265 case elfcpp::R_POWERPC_DTPMOD
:
2266 case elfcpp::R_POWERPC_DTPREL
:
2267 case elfcpp::R_POWERPC_TPREL
:
2268 case elfcpp::R_POWERPC_JMP_SLOT
:
2269 case elfcpp::R_POWERPC_COPY
:
2270 case elfcpp::R_POWERPC_IRELATIVE
:
2271 case elfcpp::R_POWERPC_ADDR32
:
2272 case elfcpp::R_POWERPC_UADDR32
:
2273 case elfcpp::R_POWERPC_ADDR24
:
2274 case elfcpp::R_POWERPC_ADDR16
:
2275 case elfcpp::R_POWERPC_UADDR16
:
2276 case elfcpp::R_POWERPC_ADDR16_LO
:
2277 case elfcpp::R_POWERPC_ADDR16_HI
:
2278 case elfcpp::R_POWERPC_ADDR16_HA
:
2279 case elfcpp::R_POWERPC_ADDR14
:
2280 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2281 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2282 case elfcpp::R_POWERPC_REL32
:
2283 case elfcpp::R_POWERPC_REL24
:
2284 case elfcpp::R_POWERPC_TPREL16
:
2285 case elfcpp::R_POWERPC_TPREL16_LO
:
2286 case elfcpp::R_POWERPC_TPREL16_HI
:
2287 case elfcpp::R_POWERPC_TPREL16_HA
:
2298 // These are the relocation types supported only on 64-bit.
2299 case elfcpp::R_PPC64_ADDR64
:
2300 case elfcpp::R_PPC64_UADDR64
:
2301 case elfcpp::R_PPC64_JMP_IREL
:
2302 case elfcpp::R_PPC64_ADDR16_DS
:
2303 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2304 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2305 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2306 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2307 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2308 case elfcpp::R_PPC64_REL64
:
2309 case elfcpp::R_POWERPC_ADDR30
:
2310 case elfcpp::R_PPC64_TPREL16_DS
:
2311 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2312 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2313 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2314 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2315 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2326 // These are the relocation types supported only on 32-bit.
2327 // ??? glibc ld.so doesn't need to support these.
2328 case elfcpp::R_POWERPC_DTPREL16
:
2329 case elfcpp::R_POWERPC_DTPREL16_LO
:
2330 case elfcpp::R_POWERPC_DTPREL16_HI
:
2331 case elfcpp::R_POWERPC_DTPREL16_HA
:
2339 // This prevents us from issuing more than one error per reloc
2340 // section. But we can still wind up issuing more than one
2341 // error per object file.
2342 if (this->issued_non_pic_error_
)
2344 gold_assert(parameters
->options().output_is_position_independent());
2345 object
->error(_("requires unsupported dynamic reloc; "
2346 "recompile with -fPIC"));
2347 this->issued_non_pic_error_
= true;
2351 // Scan a relocation for a local symbol.
2353 template<int size
, bool big_endian
>
2355 Target_powerpc
<size
, big_endian
>::Scan::local(
2356 Symbol_table
* symtab
,
2358 Target_powerpc
<size
, big_endian
>* target
,
2359 Sized_relobj_file
<size
, big_endian
>* object
,
2360 unsigned int data_shndx
,
2361 Output_section
* output_section
,
2362 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2363 unsigned int r_type
,
2364 const elfcpp::Sym
<size
, big_endian
>& /* lsym */)
2366 Powerpc_relobj
<size
, big_endian
>* ppc_object
2367 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2371 case elfcpp::R_POWERPC_NONE
:
2372 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2373 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2374 case elfcpp::R_PPC64_TOCSAVE
:
2375 case elfcpp::R_PPC_EMB_MRKREF
:
2376 case elfcpp::R_POWERPC_TLS
:
2379 case elfcpp::R_PPC64_TOC
:
2381 Output_data_got_powerpc
<size
, big_endian
>* got
2382 = target
->got_section(symtab
, layout
);
2383 if (parameters
->options().output_is_position_independent())
2385 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2386 rela_dyn
->add_output_section_relative(got
->output_section(),
2387 elfcpp::R_POWERPC_RELATIVE
,
2390 reloc
.get_r_offset(),
2391 ppc_object
->toc_base_offset());
2396 case elfcpp::R_PPC64_ADDR64
:
2397 case elfcpp::R_PPC64_UADDR64
:
2398 case elfcpp::R_POWERPC_ADDR32
:
2399 case elfcpp::R_POWERPC_UADDR32
:
2400 case elfcpp::R_POWERPC_ADDR24
:
2401 case elfcpp::R_POWERPC_ADDR16
:
2402 case elfcpp::R_POWERPC_ADDR16_LO
:
2403 case elfcpp::R_POWERPC_ADDR16_HI
:
2404 case elfcpp::R_POWERPC_ADDR16_HA
:
2405 case elfcpp::R_POWERPC_UADDR16
:
2406 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2407 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2408 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2409 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2410 case elfcpp::R_PPC64_ADDR16_DS
:
2411 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2412 case elfcpp::R_POWERPC_ADDR14
:
2413 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2414 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2415 // If building a shared library (or a position-independent
2416 // executable), we need to create a dynamic relocation for
2418 if (parameters
->options().output_is_position_independent())
2420 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2422 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2423 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2425 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2426 rela_dyn
->add_local_relative(object
, r_sym
,
2427 elfcpp::R_POWERPC_RELATIVE
,
2428 output_section
, data_shndx
,
2429 reloc
.get_r_offset(),
2430 reloc
.get_r_addend(), false);
2434 check_non_pic(object
, r_type
);
2435 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2436 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2437 data_shndx
, reloc
.get_r_offset(),
2438 reloc
.get_r_addend());
2443 case elfcpp::R_PPC64_REL64
:
2444 case elfcpp::R_POWERPC_REL32
:
2445 case elfcpp::R_POWERPC_REL24
:
2446 case elfcpp::R_PPC_LOCAL24PC
:
2447 case elfcpp::R_POWERPC_REL16
:
2448 case elfcpp::R_POWERPC_REL16_LO
:
2449 case elfcpp::R_POWERPC_REL16_HI
:
2450 case elfcpp::R_POWERPC_REL16_HA
:
2451 case elfcpp::R_POWERPC_REL14
:
2452 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2453 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2454 case elfcpp::R_POWERPC_SECTOFF
:
2455 case elfcpp::R_POWERPC_TPREL16
:
2456 case elfcpp::R_POWERPC_DTPREL16
:
2457 case elfcpp::R_POWERPC_SECTOFF_LO
:
2458 case elfcpp::R_POWERPC_TPREL16_LO
:
2459 case elfcpp::R_POWERPC_DTPREL16_LO
:
2460 case elfcpp::R_POWERPC_SECTOFF_HI
:
2461 case elfcpp::R_POWERPC_TPREL16_HI
:
2462 case elfcpp::R_POWERPC_DTPREL16_HI
:
2463 case elfcpp::R_POWERPC_SECTOFF_HA
:
2464 case elfcpp::R_POWERPC_TPREL16_HA
:
2465 case elfcpp::R_POWERPC_DTPREL16_HA
:
2466 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2467 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2468 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2469 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2470 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2471 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2472 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2473 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2474 case elfcpp::R_PPC64_TPREL16_DS
:
2475 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2476 case elfcpp::R_PPC64_DTPREL16_DS
:
2477 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2478 case elfcpp::R_PPC64_SECTOFF_DS
:
2479 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2480 case elfcpp::R_PPC64_TLSGD
:
2481 case elfcpp::R_PPC64_TLSLD
:
2484 case elfcpp::R_POWERPC_GOT16
:
2485 case elfcpp::R_POWERPC_GOT16_LO
:
2486 case elfcpp::R_POWERPC_GOT16_HI
:
2487 case elfcpp::R_POWERPC_GOT16_HA
:
2488 case elfcpp::R_PPC64_GOT16_DS
:
2489 case elfcpp::R_PPC64_GOT16_LO_DS
:
2491 // The symbol requires a GOT entry.
2492 Output_data_got_powerpc
<size
, big_endian
>* got
2493 = target
->got_section(symtab
, layout
);
2494 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2496 // If we are generating a shared object, we need to add a
2497 // dynamic relocation for this symbol's GOT entry.
2498 if (parameters
->options().output_is_position_independent())
2500 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2502 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2505 off
= got
->add_constant(0);
2506 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2507 rela_dyn
->add_local_relative(object
, r_sym
,
2508 elfcpp::R_POWERPC_RELATIVE
,
2509 got
, off
, 0, false);
2513 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2517 case elfcpp::R_PPC64_TOC16
:
2518 case elfcpp::R_PPC64_TOC16_LO
:
2519 case elfcpp::R_PPC64_TOC16_HI
:
2520 case elfcpp::R_PPC64_TOC16_HA
:
2521 case elfcpp::R_PPC64_TOC16_DS
:
2522 case elfcpp::R_PPC64_TOC16_LO_DS
:
2523 // We need a GOT section.
2524 target
->got_section(symtab
, layout
);
2527 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2528 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2529 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2530 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2532 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
2533 if (tls_type
== tls::TLSOPT_NONE
)
2535 Output_data_got_powerpc
<size
, big_endian
>* got
2536 = target
->got_section(symtab
, layout
);
2537 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2538 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2539 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
2540 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
2542 else if (tls_type
== tls::TLSOPT_TO_LE
)
2544 // no GOT relocs needed for Local Exec.
2551 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2552 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2553 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2554 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2556 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2557 if (tls_type
== tls::TLSOPT_NONE
)
2558 target
->tlsld_got_offset(symtab
, layout
, object
);
2559 else if (tls_type
== tls::TLSOPT_TO_LE
)
2561 // no GOT relocs needed for Local Exec.
2562 if (parameters
->options().emit_relocs())
2564 Output_section
* os
= layout
->tls_segment()->first_section();
2565 gold_assert(os
!= NULL
);
2566 os
->set_needs_symtab_index();
2574 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2575 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2576 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2577 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2579 Output_data_got_powerpc
<size
, big_endian
>* got
2580 = target
->got_section(symtab
, layout
);
2581 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2582 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
2586 case elfcpp::R_POWERPC_GOT_TPREL16
:
2587 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2588 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2589 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2591 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
2592 if (tls_type
== tls::TLSOPT_NONE
)
2594 Output_data_got_powerpc
<size
, big_endian
>* got
2595 = target
->got_section(symtab
, layout
);
2596 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2597 got
->add_local_tls(object
, r_sym
, GOT_TYPE_TPREL
);
2599 else if (tls_type
== tls::TLSOPT_TO_LE
)
2601 // no GOT relocs needed for Local Exec.
2609 unsupported_reloc_local(object
, r_type
);
2614 // Report an unsupported relocation against a global symbol.
2616 template<int size
, bool big_endian
>
2618 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2619 Sized_relobj_file
<size
, big_endian
>* object
,
2620 unsigned int r_type
,
2623 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2624 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2627 // Scan a relocation for a global symbol.
2629 template<int size
, bool big_endian
>
2631 Target_powerpc
<size
, big_endian
>::Scan::global(
2632 Symbol_table
* symtab
,
2634 Target_powerpc
<size
, big_endian
>* target
,
2635 Sized_relobj_file
<size
, big_endian
>* object
,
2636 unsigned int data_shndx
,
2637 Output_section
* output_section
,
2638 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2639 unsigned int r_type
,
2642 Powerpc_relobj
<size
, big_endian
>* ppc_object
2643 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2647 case elfcpp::R_POWERPC_NONE
:
2648 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2649 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2650 case elfcpp::R_PPC_LOCAL24PC
:
2651 case elfcpp::R_PPC_EMB_MRKREF
:
2652 case elfcpp::R_POWERPC_TLS
:
2655 case elfcpp::R_PPC64_TOC
:
2657 Output_data_got_powerpc
<size
, big_endian
>* got
2658 = target
->got_section(symtab
, layout
);
2659 if (parameters
->options().output_is_position_independent())
2661 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2662 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
2663 if (data_shndx
!= ppc_object
->opd_shndx())
2664 symobj
= static_cast
2665 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
2666 rela_dyn
->add_output_section_relative(got
->output_section(),
2667 elfcpp::R_POWERPC_RELATIVE
,
2670 reloc
.get_r_offset(),
2671 symobj
->toc_base_offset());
2676 case elfcpp::R_PPC64_ADDR64
:
2677 case elfcpp::R_PPC64_UADDR64
:
2678 case elfcpp::R_POWERPC_ADDR32
:
2679 case elfcpp::R_POWERPC_UADDR32
:
2680 case elfcpp::R_POWERPC_ADDR24
:
2681 case elfcpp::R_POWERPC_ADDR16
:
2682 case elfcpp::R_POWERPC_ADDR16_LO
:
2683 case elfcpp::R_POWERPC_ADDR16_HI
:
2684 case elfcpp::R_POWERPC_ADDR16_HA
:
2685 case elfcpp::R_POWERPC_UADDR16
:
2686 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2687 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2688 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2689 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2690 case elfcpp::R_PPC64_ADDR16_DS
:
2691 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2692 case elfcpp::R_POWERPC_ADDR14
:
2693 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2694 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2696 // Make a PLT entry if necessary.
2697 if (gsym
->needs_plt_entry())
2699 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
2700 // Since this is not a PC-relative relocation, we may be
2701 // taking the address of a function. In that case we need to
2702 // set the entry in the dynamic symbol table to the address of
2705 && gsym
->is_from_dynobj() && !parameters
->options().shared())
2706 gsym
->set_needs_dynsym_value();
2708 // Make a dynamic relocation if necessary.
2709 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2711 if (gsym
->may_need_copy_reloc())
2713 target
->copy_reloc(symtab
, layout
, object
,
2714 data_shndx
, output_section
, gsym
, reloc
);
2716 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2717 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2718 && (gsym
->can_use_relative_reloc(false)
2719 || data_shndx
== ppc_object
->opd_shndx()))
2721 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2722 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2723 output_section
, object
,
2724 data_shndx
, reloc
.get_r_offset(),
2725 reloc
.get_r_addend(), false);
2729 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2730 check_non_pic(object
, r_type
);
2731 rela_dyn
->add_global(gsym
, r_type
, output_section
,
2733 reloc
.get_r_offset(),
2734 reloc
.get_r_addend());
2740 case elfcpp::R_PPC_PLTREL24
:
2741 case elfcpp::R_POWERPC_REL24
:
2742 if (gsym
->needs_plt_entry()
2743 || (!gsym
->final_value_is_known()
2744 && (gsym
->is_undefined()
2745 || gsym
->is_from_dynobj()
2746 || gsym
->is_preemptible())))
2747 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
2750 case elfcpp::R_PPC64_REL64
:
2751 case elfcpp::R_POWERPC_REL32
:
2752 // Make a dynamic relocation if necessary.
2753 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2755 if (gsym
->may_need_copy_reloc())
2757 target
->copy_reloc(symtab
, layout
, object
,
2758 data_shndx
, output_section
, gsym
,
2763 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2764 check_non_pic(object
, r_type
);
2765 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2766 data_shndx
, reloc
.get_r_offset(),
2767 reloc
.get_r_addend());
2772 case elfcpp::R_POWERPC_REL16
:
2773 case elfcpp::R_POWERPC_REL16_LO
:
2774 case elfcpp::R_POWERPC_REL16_HI
:
2775 case elfcpp::R_POWERPC_REL16_HA
:
2776 case elfcpp::R_POWERPC_REL14
:
2777 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2778 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2779 case elfcpp::R_POWERPC_SECTOFF
:
2780 case elfcpp::R_POWERPC_TPREL16
:
2781 case elfcpp::R_POWERPC_DTPREL16
:
2782 case elfcpp::R_POWERPC_SECTOFF_LO
:
2783 case elfcpp::R_POWERPC_TPREL16_LO
:
2784 case elfcpp::R_POWERPC_DTPREL16_LO
:
2785 case elfcpp::R_POWERPC_SECTOFF_HI
:
2786 case elfcpp::R_POWERPC_TPREL16_HI
:
2787 case elfcpp::R_POWERPC_DTPREL16_HI
:
2788 case elfcpp::R_POWERPC_SECTOFF_HA
:
2789 case elfcpp::R_POWERPC_TPREL16_HA
:
2790 case elfcpp::R_POWERPC_DTPREL16_HA
:
2791 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2792 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2793 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2794 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2795 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2796 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2797 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2798 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2799 case elfcpp::R_PPC64_TPREL16_DS
:
2800 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2801 case elfcpp::R_PPC64_DTPREL16_DS
:
2802 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2803 case elfcpp::R_PPC64_SECTOFF_DS
:
2804 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2805 case elfcpp::R_PPC64_TLSGD
:
2806 case elfcpp::R_PPC64_TLSLD
:
2809 case elfcpp::R_POWERPC_GOT16
:
2810 case elfcpp::R_POWERPC_GOT16_LO
:
2811 case elfcpp::R_POWERPC_GOT16_HI
:
2812 case elfcpp::R_POWERPC_GOT16_HA
:
2813 case elfcpp::R_PPC64_GOT16_DS
:
2814 case elfcpp::R_PPC64_GOT16_LO_DS
:
2816 // The symbol requires a GOT entry.
2817 Output_data_got_powerpc
<size
, big_endian
>* got
;
2819 got
= target
->got_section(symtab
, layout
);
2820 if (gsym
->final_value_is_known())
2821 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2824 // If this symbol is not fully resolved, we need to add a
2825 // dynamic relocation for it.
2826 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2827 if (gsym
->is_from_dynobj()
2828 || gsym
->is_undefined()
2829 || gsym
->is_preemptible())
2830 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2831 elfcpp::R_POWERPC_GLOB_DAT
);
2832 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2834 unsigned int off
= got
->add_constant(0);
2836 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2837 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2838 got
, off
, 0, false);
2844 case elfcpp::R_PPC64_TOC16
:
2845 case elfcpp::R_PPC64_TOC16_LO
:
2846 case elfcpp::R_PPC64_TOC16_HI
:
2847 case elfcpp::R_PPC64_TOC16_HA
:
2848 case elfcpp::R_PPC64_TOC16_DS
:
2849 case elfcpp::R_PPC64_TOC16_LO_DS
:
2850 // We need a GOT section.
2851 target
->got_section(symtab
, layout
);
2854 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2855 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2856 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2857 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2859 const bool final
= gsym
->final_value_is_known();
2860 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
2861 if (tls_type
== tls::TLSOPT_NONE
)
2863 Output_data_got_powerpc
<size
, big_endian
>* got
2864 = target
->got_section(symtab
, layout
);
2865 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
2866 target
->rela_dyn_section(layout
),
2867 elfcpp::R_POWERPC_DTPMOD
,
2868 elfcpp::R_POWERPC_DTPREL
);
2870 else if (tls_type
== tls::TLSOPT_TO_IE
)
2872 Output_data_got_powerpc
<size
, big_endian
>* got
2873 = target
->got_section(symtab
, layout
);
2874 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
2875 target
->rela_dyn_section(layout
),
2876 elfcpp::R_POWERPC_TPREL
);
2878 else if (tls_type
== tls::TLSOPT_TO_LE
)
2880 // no GOT relocs needed for Local Exec.
2887 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2888 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2889 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2890 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2892 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2893 if (tls_type
== tls::TLSOPT_NONE
)
2894 target
->tlsld_got_offset(symtab
, layout
, object
);
2895 else if (tls_type
== tls::TLSOPT_TO_LE
)
2897 // no GOT relocs needed for Local Exec.
2898 if (parameters
->options().emit_relocs())
2900 Output_section
* os
= layout
->tls_segment()->first_section();
2901 gold_assert(os
!= NULL
);
2902 os
->set_needs_symtab_index();
2910 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2911 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2912 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2913 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2915 Output_data_got_powerpc
<size
, big_endian
>* got
2916 = target
->got_section(symtab
, layout
);
2917 if (!gsym
->final_value_is_known()
2918 && (gsym
->is_from_dynobj()
2919 || gsym
->is_undefined()
2920 || gsym
->is_preemptible()))
2921 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
2922 target
->rela_dyn_section(layout
),
2923 elfcpp::R_POWERPC_DTPREL
);
2925 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
2929 case elfcpp::R_POWERPC_GOT_TPREL16
:
2930 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2931 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2932 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2934 const bool final
= gsym
->final_value_is_known();
2935 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
2936 if (tls_type
== tls::TLSOPT_NONE
)
2938 Output_data_got_powerpc
<size
, big_endian
>* got
2939 = target
->got_section(symtab
, layout
);
2940 if (!gsym
->final_value_is_known()
2941 && (gsym
->is_from_dynobj()
2942 || gsym
->is_undefined()
2943 || gsym
->is_preemptible()))
2944 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
2945 target
->rela_dyn_section(layout
),
2946 elfcpp::R_POWERPC_TPREL
);
2948 got
->add_global_tls(gsym
, GOT_TYPE_TPREL
);
2950 else if (tls_type
== tls::TLSOPT_TO_LE
)
2952 // no GOT relocs needed for Local Exec.
2960 unsupported_reloc_global(object
, r_type
, gsym
);
2965 // Process relocations for gc.
2967 template<int size
, bool big_endian
>
2969 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
2970 Symbol_table
* symtab
,
2972 Sized_relobj_file
<size
, big_endian
>* object
,
2973 unsigned int data_shndx
,
2975 const unsigned char* prelocs
,
2977 Output_section
* output_section
,
2978 bool needs_special_offset_handling
,
2979 size_t local_symbol_count
,
2980 const unsigned char* plocal_symbols
)
2982 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
2983 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
2984 Powerpc_relobj
<size
, big_endian
>* ppc_object
2985 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2987 ppc_object
->set_opd_valid();
2988 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
2990 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
2991 for (p
= ppc_object
->access_from_map()->begin();
2992 p
!= ppc_object
->access_from_map()->end();
2995 Address dst_off
= p
->first
;
2996 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
2997 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
2998 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
3000 Object
* src_obj
= s
->first
;
3001 unsigned int src_indx
= s
->second
;
3002 symtab
->gc()->add_reference(src_obj
, src_indx
,
3003 ppc_object
, dst_indx
);
3007 ppc_object
->access_from_map()->clear();
3008 // Don't look at .opd relocs as .opd will reference everything.
3012 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3013 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3022 needs_special_offset_handling
,
3027 // Handle target specific gc actions when adding a gc reference from
3028 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3029 // and DST_OFF. For powerpc64, this adds a referenc to the code
3030 // section of a function descriptor.
3032 template<int size
, bool big_endian
>
3034 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3035 Symbol_table
* symtab
,
3037 unsigned int src_shndx
,
3039 unsigned int dst_shndx
,
3040 Address dst_off
) const
3042 Powerpc_relobj
<size
, big_endian
>* ppc_object
3043 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3044 if (size
== 64 && dst_shndx
== ppc_object
->opd_shndx())
3046 if (ppc_object
->opd_valid())
3048 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3049 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3053 // If we haven't run scan_opd_relocs, we must delay
3054 // processing this function descriptor reference.
3055 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3060 // Add any special sections for this symbol to the gc work list.
3061 // For powerpc64, this adds the code section of a function
3064 template<int size
, bool big_endian
>
3066 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3067 Symbol_table
* symtab
,
3072 Powerpc_relobj
<size
, big_endian
>* ppc_object
3073 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3075 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3076 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
3078 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
3079 Address dst_off
= gsym
->value();
3080 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3081 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
3086 // Scan relocations for a section.
3088 template<int size
, bool big_endian
>
3090 Target_powerpc
<size
, big_endian
>::scan_relocs(
3091 Symbol_table
* symtab
,
3093 Sized_relobj_file
<size
, big_endian
>* object
,
3094 unsigned int data_shndx
,
3095 unsigned int sh_type
,
3096 const unsigned char* prelocs
,
3098 Output_section
* output_section
,
3099 bool needs_special_offset_handling
,
3100 size_t local_symbol_count
,
3101 const unsigned char* plocal_symbols
)
3103 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3104 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3106 if (sh_type
== elfcpp::SHT_REL
)
3108 gold_error(_("%s: unsupported REL reloc section"),
3109 object
->name().c_str());
3115 static Output_data_space
* sdata
;
3117 // Define _SDA_BASE_ at the start of the .sdata section.
3120 // layout->find_output_section(".sdata") == NULL
3121 sdata
= new Output_data_space(4, "** sdata");
3123 = layout
->add_output_section_data(".sdata", 0,
3125 | elfcpp::SHF_WRITE
,
3126 sdata
, ORDER_SMALL_DATA
, false);
3127 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
3128 Symbol_table::PREDEFINED
,
3129 os
, 32768, 0, elfcpp::STT_OBJECT
,
3130 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
3135 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
3144 needs_special_offset_handling
,
3149 // Finalize the sections.
3151 template<int size
, bool big_endian
>
3153 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
3155 const Input_objects
*,
3158 // Fill in some more dynamic tags.
3159 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3161 : this->plt_
->rel_plt());
3162 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3163 this->rela_dyn_
, true, size
== 32);
3165 Output_data_dynamic
* odyn
= layout
->dynamic_data();
3168 if (this->got_
!= NULL
)
3170 this->got_
->finalize_data_size();
3171 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
3172 this->got_
, this->got_
->g_o_t());
3177 if (this->glink_
!= NULL
)
3179 this->glink_
->finalize_data_size();
3180 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
3182 (this->glink_
->pltresolve()
3183 + this->glink_
->pltresolve_size
- 32));
3187 // Emit any relocs we saved in an attempt to avoid generating COPY
3189 if (this->copy_relocs_
.any_saved_relocs())
3190 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3193 // Return the value to use for a branch relocation.
3195 template<int size
, bool big_endian
>
3196 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3197 Target_powerpc
<size
, big_endian
>::symval_for_branch(
3199 const Sized_symbol
<size
>* gsym
,
3200 Powerpc_relobj
<size
, big_endian
>* object
,
3201 unsigned int *dest_shndx
)
3207 // If the symbol is defined in an opd section, ie. is a function
3208 // descriptor, use the function descriptor code entry address
3209 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
3211 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3212 unsigned int shndx
= symobj
->opd_shndx();
3215 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
3216 gold_assert(opd_addr
!= invalid_address
);
3217 opd_addr
+= symobj
->output_section(shndx
)->address();
3218 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
3221 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
3222 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
3223 gold_assert(sec_addr
!= invalid_address
);
3224 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
3225 value
= sec_addr
+ sec_off
;
3230 // Perform a relocation.
3232 template<int size
, bool big_endian
>
3234 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
3235 const Relocate_info
<size
, big_endian
>* relinfo
,
3236 Target_powerpc
* target
,
3239 const elfcpp::Rela
<size
, big_endian
>& rela
,
3240 unsigned int r_type
,
3241 const Sized_symbol
<size
>* gsym
,
3242 const Symbol_value
<size
>* psymval
,
3243 unsigned char* view
,
3245 section_size_type view_size
)
3248 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
3249 || r_type
== elfcpp::R_PPC_PLTREL24
)
3251 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
3252 enum skip_tls last_tls
= this->call_tls_get_addr_
;
3253 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
3256 if (last_tls
== CALL_NOT_EXPECTED
)
3257 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3258 _("__tls_get_addr call lacks marker reloc"));
3259 else if (last_tls
== CALL_SKIP
)
3262 else if (last_tls
!= CALL_NOT_EXPECTED
)
3263 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3264 _("missing expected __tls_get_addr call"));
3266 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
3267 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
3268 Powerpc_relobj
<size
, big_endian
>* const object
3269 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
3271 bool has_plt_value
= false;
3273 && use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3275 const Output_data_glink
<size
, big_endian
>* glink
3276 = target
->glink_section();
3277 unsigned int glink_index
= glink
->find_entry(gsym
, rela
, object
);
3278 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
3279 has_plt_value
= true;
3282 if (r_type
== elfcpp::R_POWERPC_GOT16
3283 || r_type
== elfcpp::R_POWERPC_GOT16_LO
3284 || r_type
== elfcpp::R_POWERPC_GOT16_HI
3285 || r_type
== elfcpp::R_POWERPC_GOT16_HA
3286 || r_type
== elfcpp::R_PPC64_GOT16_DS
3287 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
3291 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3292 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3296 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3297 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3298 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3300 value
-= target
->got_section()->got_base_offset(object
);
3302 else if (r_type
== elfcpp::R_PPC64_TOC
)
3304 value
= (target
->got_section()->output_section()->address()
3305 + object
->toc_base_offset());
3307 else if (gsym
!= NULL
3308 && (r_type
== elfcpp::R_POWERPC_REL24
3309 || r_type
== elfcpp::R_PPC_PLTREL24
)
3314 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3315 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3316 bool can_plt_call
= false;
3317 if (rela
.get_r_offset() + 8 <= view_size
)
3319 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3320 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
3323 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
3325 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
3326 can_plt_call
= true;
3331 // If we don't have a branch and link followed by a nop,
3332 // we can't go via the plt because there is no place to
3333 // put a toc restoring instruction.
3334 // Unless we know we won't be returning.
3335 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
3336 can_plt_call
= true;
3340 // This is not an error in one special case: A self
3341 // call. It isn't possible to cheaply verify we have
3342 // such a call so just check for a call to the same
3345 if (gsym
->source() == Symbol::FROM_OBJECT
3346 && gsym
->object() == object
)
3348 Address addend
= rela
.get_r_addend();
3349 unsigned int dest_shndx
;
3350 value
= psymval
->value(object
, addend
);
3351 value
= target
->symval_for_branch(value
, gsym
, object
,
3354 if (dest_shndx
== 0)
3355 dest_shndx
= gsym
->shndx(&is_ordinary
);
3356 ok
= dest_shndx
== relinfo
->data_shndx
;
3359 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3360 _("call lacks nop, can't restore toc; "
3361 "recompile with -fPIC"));
3365 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3366 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
3367 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
3368 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
3370 // First instruction of a global dynamic sequence, arg setup insn.
3371 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3372 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3373 enum Got_type got_type
= GOT_TYPE_STANDARD
;
3374 if (tls_type
== tls::TLSOPT_NONE
)
3375 got_type
= GOT_TYPE_TLSGD
;
3376 else if (tls_type
== tls::TLSOPT_TO_IE
)
3377 got_type
= GOT_TYPE_TPREL
;
3378 if (got_type
!= GOT_TYPE_STANDARD
)
3382 gold_assert(gsym
->has_got_offset(got_type
));
3383 value
= gsym
->got_offset(got_type
);
3387 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3388 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3389 value
= object
->local_got_offset(r_sym
, got_type
);
3391 value
-= target
->got_section()->got_base_offset(object
);
3393 if (tls_type
== tls::TLSOPT_TO_IE
)
3395 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3396 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3398 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3399 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3400 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
3402 insn
|= 32 << 26; // lwz
3404 insn
|= 58 << 26; // ld
3405 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3407 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
3408 - elfcpp::R_POWERPC_GOT_TLSGD16
);
3410 else if (tls_type
== tls::TLSOPT_TO_LE
)
3412 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3413 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3415 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3416 Insn insn
= addis_3_13
;
3419 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3420 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3421 value
= psymval
->value(object
, rela
.get_r_addend());
3425 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3427 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3428 r_type
= elfcpp::R_POWERPC_NONE
;
3432 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3433 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
3434 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
3435 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
3437 // First instruction of a local dynamic sequence, arg setup insn.
3438 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3439 if (tls_type
== tls::TLSOPT_NONE
)
3441 value
= target
->tlsld_got_offset();
3442 value
-= target
->got_section()->got_base_offset(object
);
3446 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3447 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3448 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
3450 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3451 Insn insn
= addis_3_13
;
3454 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3455 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3460 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3462 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3463 r_type
= elfcpp::R_POWERPC_NONE
;
3467 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
3468 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
3469 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
3470 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
3472 // Accesses relative to a local dynamic sequence address,
3473 // no optimisation here.
3476 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
3477 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
3481 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3482 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
3483 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
3485 value
-= target
->got_section()->got_base_offset(object
);
3487 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3488 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
3489 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
3490 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
3492 // First instruction of initial exec sequence.
3493 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3494 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3495 if (tls_type
== tls::TLSOPT_NONE
)
3499 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
3500 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
3504 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3505 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
3506 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
3508 value
-= target
->got_section()->got_base_offset(object
);
3512 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3513 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3514 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
3516 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3517 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3518 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
3523 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3524 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3525 value
= psymval
->value(object
, rela
.get_r_addend());
3529 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3531 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3532 r_type
= elfcpp::R_POWERPC_NONE
;
3536 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
3537 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
3539 // Second instruction of a global dynamic sequence,
3540 // the __tls_get_addr call
3541 this->call_tls_get_addr_
= CALL_EXPECTED
;
3542 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3543 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3544 if (tls_type
!= tls::TLSOPT_NONE
)
3546 if (tls_type
== tls::TLSOPT_TO_IE
)
3548 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3549 Insn insn
= add_3_3_13
;
3552 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3553 r_type
= elfcpp::R_POWERPC_NONE
;
3557 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3558 Insn insn
= addi_3_3
;
3559 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3560 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3561 view
+= 2 * big_endian
;
3562 value
= psymval
->value(object
, rela
.get_r_addend());
3564 this->call_tls_get_addr_
= CALL_SKIP
;
3567 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
3568 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
3570 // Second instruction of a local dynamic sequence,
3571 // the __tls_get_addr call
3572 this->call_tls_get_addr_
= CALL_EXPECTED
;
3573 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3574 if (tls_type
== tls::TLSOPT_TO_LE
)
3576 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3577 Insn insn
= addi_3_3
;
3578 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3579 this->call_tls_get_addr_
= CALL_SKIP
;
3580 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3581 view
+= 2 * big_endian
;
3585 else if (r_type
== elfcpp::R_POWERPC_TLS
)
3587 // Second instruction of an initial exec sequence
3588 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3589 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3590 if (tls_type
== tls::TLSOPT_TO_LE
)
3592 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3593 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3594 unsigned int reg
= size
== 32 ? 2 : 13;
3595 insn
= at_tls_transform(insn
, reg
);
3596 gold_assert(insn
!= 0);
3597 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3598 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3599 view
+= 2 * big_endian
;
3600 value
= psymval
->value(object
, rela
.get_r_addend());
3606 unsigned int dest_shndx
;
3607 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
3608 addend
= rela
.get_r_addend();
3609 if (size
== 64 || !has_plt_value
)
3610 value
= psymval
->value(object
, addend
);
3611 if (size
== 64 && is_branch_reloc(r_type
))
3612 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
3617 case elfcpp::R_PPC64_REL64
:
3618 case elfcpp::R_POWERPC_REL32
:
3619 case elfcpp::R_POWERPC_REL24
:
3620 case elfcpp::R_PPC_PLTREL24
:
3621 case elfcpp::R_PPC_LOCAL24PC
:
3622 case elfcpp::R_POWERPC_REL16
:
3623 case elfcpp::R_POWERPC_REL16_LO
:
3624 case elfcpp::R_POWERPC_REL16_HI
:
3625 case elfcpp::R_POWERPC_REL16_HA
:
3626 case elfcpp::R_POWERPC_REL14
:
3627 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3628 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3632 case elfcpp::R_PPC64_TOC16
:
3633 case elfcpp::R_PPC64_TOC16_LO
:
3634 case elfcpp::R_PPC64_TOC16_HI
:
3635 case elfcpp::R_PPC64_TOC16_HA
:
3636 case elfcpp::R_PPC64_TOC16_DS
:
3637 case elfcpp::R_PPC64_TOC16_LO_DS
:
3638 // Subtract the TOC base address.
3639 value
-= (target
->got_section()->output_section()->address()
3640 + object
->toc_base_offset());
3643 case elfcpp::R_POWERPC_SECTOFF
:
3644 case elfcpp::R_POWERPC_SECTOFF_LO
:
3645 case elfcpp::R_POWERPC_SECTOFF_HI
:
3646 case elfcpp::R_POWERPC_SECTOFF_HA
:
3647 case elfcpp::R_PPC64_SECTOFF_DS
:
3648 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3650 value
-= os
->address();
3653 case elfcpp::R_PPC64_TPREL16_DS
:
3654 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3656 // R_PPC_TLSGD and R_PPC_TLSLD
3658 case elfcpp::R_POWERPC_TPREL16
:
3659 case elfcpp::R_POWERPC_TPREL16_LO
:
3660 case elfcpp::R_POWERPC_TPREL16_HI
:
3661 case elfcpp::R_POWERPC_TPREL16_HA
:
3662 case elfcpp::R_POWERPC_TPREL
:
3663 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3664 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3665 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3666 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3667 // tls symbol values are relative to tls_segment()->vaddr()
3671 case elfcpp::R_PPC64_DTPREL16_DS
:
3672 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3673 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3674 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3675 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3676 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3678 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
3679 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
3681 case elfcpp::R_POWERPC_DTPREL16
:
3682 case elfcpp::R_POWERPC_DTPREL16_LO
:
3683 case elfcpp::R_POWERPC_DTPREL16_HI
:
3684 case elfcpp::R_POWERPC_DTPREL16_HA
:
3685 case elfcpp::R_POWERPC_DTPREL
:
3686 // tls symbol values are relative to tls_segment()->vaddr()
3687 value
-= dtp_offset
;
3694 Insn branch_bit
= 0;
3697 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3698 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3699 branch_bit
= 1 << 21;
3700 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3701 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3703 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3704 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3707 if (this->is_isa_v2
)
3709 // Set 'a' bit. This is 0b00010 in BO field for branch
3710 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
3711 // for branch on CTR insns (BO == 1a00t or 1a01t).
3712 if ((insn
& (0x14 << 21)) == (0x04 << 21))
3714 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
3721 // Invert 'y' bit if not the default.
3722 if (static_cast<Signed_address
>(value
) < 0)
3725 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3733 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
3736 case elfcpp::R_POWERPC_ADDR32
:
3737 case elfcpp::R_POWERPC_UADDR32
:
3739 overflow
= Reloc::CHECK_BITFIELD
;
3742 case elfcpp::R_POWERPC_REL32
:
3744 overflow
= Reloc::CHECK_SIGNED
;
3747 case elfcpp::R_POWERPC_ADDR24
:
3748 case elfcpp::R_POWERPC_ADDR16
:
3749 case elfcpp::R_POWERPC_UADDR16
:
3750 case elfcpp::R_PPC64_ADDR16_DS
:
3751 case elfcpp::R_POWERPC_ADDR14
:
3752 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3753 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3754 overflow
= Reloc::CHECK_BITFIELD
;
3757 case elfcpp::R_POWERPC_REL24
:
3758 case elfcpp::R_PPC_PLTREL24
:
3759 case elfcpp::R_PPC_LOCAL24PC
:
3760 case elfcpp::R_POWERPC_REL16
:
3761 case elfcpp::R_PPC64_TOC16
:
3762 case elfcpp::R_POWERPC_GOT16
:
3763 case elfcpp::R_POWERPC_SECTOFF
:
3764 case elfcpp::R_POWERPC_TPREL16
:
3765 case elfcpp::R_POWERPC_DTPREL16
:
3766 case elfcpp::R_PPC64_TPREL16_DS
:
3767 case elfcpp::R_PPC64_DTPREL16_DS
:
3768 case elfcpp::R_PPC64_TOC16_DS
:
3769 case elfcpp::R_PPC64_GOT16_DS
:
3770 case elfcpp::R_PPC64_SECTOFF_DS
:
3771 case elfcpp::R_POWERPC_REL14
:
3772 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3773 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3774 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3775 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3776 case elfcpp::R_POWERPC_GOT_TPREL16
:
3777 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3778 overflow
= Reloc::CHECK_SIGNED
;
3782 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
3783 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
3786 case elfcpp::R_POWERPC_NONE
:
3787 case elfcpp::R_POWERPC_TLS
:
3788 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3789 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3790 case elfcpp::R_PPC_EMB_MRKREF
:
3793 case elfcpp::R_PPC64_ADDR64
:
3794 case elfcpp::R_PPC64_REL64
:
3795 case elfcpp::R_PPC64_TOC
:
3796 Reloc::addr64(view
, value
);
3799 case elfcpp::R_POWERPC_TPREL
:
3800 case elfcpp::R_POWERPC_DTPREL
:
3802 Reloc::addr64(view
, value
);
3804 status
= Reloc::addr32(view
, value
, overflow
);
3807 case elfcpp::R_PPC64_UADDR64
:
3808 Reloc::addr64_u(view
, value
);
3811 case elfcpp::R_POWERPC_ADDR32
:
3812 case elfcpp::R_POWERPC_REL32
:
3813 status
= Reloc::addr32(view
, value
, overflow
);
3816 case elfcpp::R_POWERPC_UADDR32
:
3817 status
= Reloc::addr32_u(view
, value
, overflow
);
3820 case elfcpp::R_POWERPC_ADDR24
:
3821 case elfcpp::R_POWERPC_REL24
:
3822 case elfcpp::R_PPC_PLTREL24
:
3823 case elfcpp::R_PPC_LOCAL24PC
:
3824 status
= Reloc::addr24(view
, value
, overflow
);
3827 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3828 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3831 status
= Reloc::addr16_ds(view
, value
, overflow
);
3834 case elfcpp::R_POWERPC_ADDR16
:
3835 case elfcpp::R_POWERPC_REL16
:
3836 case elfcpp::R_PPC64_TOC16
:
3837 case elfcpp::R_POWERPC_GOT16
:
3838 case elfcpp::R_POWERPC_SECTOFF
:
3839 case elfcpp::R_POWERPC_TPREL16
:
3840 case elfcpp::R_POWERPC_DTPREL16
:
3841 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3842 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3843 case elfcpp::R_POWERPC_GOT_TPREL16
:
3844 case elfcpp::R_POWERPC_ADDR16_LO
:
3845 case elfcpp::R_POWERPC_REL16_LO
:
3846 case elfcpp::R_PPC64_TOC16_LO
:
3847 case elfcpp::R_POWERPC_GOT16_LO
:
3848 case elfcpp::R_POWERPC_SECTOFF_LO
:
3849 case elfcpp::R_POWERPC_TPREL16_LO
:
3850 case elfcpp::R_POWERPC_DTPREL16_LO
:
3851 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3852 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3853 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3854 status
= Reloc::addr16(view
, value
, overflow
);
3857 case elfcpp::R_POWERPC_UADDR16
:
3858 status
= Reloc::addr16_u(view
, value
, overflow
);
3861 case elfcpp::R_POWERPC_ADDR16_HI
:
3862 case elfcpp::R_POWERPC_REL16_HI
:
3863 case elfcpp::R_PPC64_TOC16_HI
:
3864 case elfcpp::R_POWERPC_GOT16_HI
:
3865 case elfcpp::R_POWERPC_SECTOFF_HI
:
3866 case elfcpp::R_POWERPC_TPREL16_HI
:
3867 case elfcpp::R_POWERPC_DTPREL16_HI
:
3868 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3869 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3870 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3871 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3872 Reloc::addr16_hi(view
, value
);
3875 case elfcpp::R_POWERPC_ADDR16_HA
:
3876 case elfcpp::R_POWERPC_REL16_HA
:
3877 case elfcpp::R_PPC64_TOC16_HA
:
3878 case elfcpp::R_POWERPC_GOT16_HA
:
3879 case elfcpp::R_POWERPC_SECTOFF_HA
:
3880 case elfcpp::R_POWERPC_TPREL16_HA
:
3881 case elfcpp::R_POWERPC_DTPREL16_HA
:
3882 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3883 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3884 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3885 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3886 Reloc::addr16_ha(view
, value
);
3889 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3891 // R_PPC_EMB_NADDR16_LO
3893 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3894 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3895 Reloc::addr16_hi2(view
, value
);
3898 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3900 // R_PPC_EMB_NADDR16_HI
3902 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3903 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3904 Reloc::addr16_ha2(view
, value
);
3907 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3909 // R_PPC_EMB_NADDR16_HA
3911 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3912 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3913 Reloc::addr16_hi3(view
, value
);
3916 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3920 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3921 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3922 Reloc::addr16_ha3(view
, value
);
3925 case elfcpp::R_PPC64_DTPREL16_DS
:
3926 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3928 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
3930 case elfcpp::R_PPC64_TPREL16_DS
:
3931 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3933 // R_PPC_TLSGD, R_PPC_TLSLD
3935 case elfcpp::R_PPC64_ADDR16_DS
:
3936 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3937 case elfcpp::R_PPC64_TOC16_DS
:
3938 case elfcpp::R_PPC64_TOC16_LO_DS
:
3939 case elfcpp::R_PPC64_GOT16_DS
:
3940 case elfcpp::R_PPC64_GOT16_LO_DS
:
3941 case elfcpp::R_PPC64_SECTOFF_DS
:
3942 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3943 status
= Reloc::addr16_ds(view
, value
, overflow
);
3946 case elfcpp::R_POWERPC_ADDR14
:
3947 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3948 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3949 case elfcpp::R_POWERPC_REL14
:
3950 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3951 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3952 status
= Reloc::addr14(view
, value
, overflow
);
3955 case elfcpp::R_POWERPC_COPY
:
3956 case elfcpp::R_POWERPC_GLOB_DAT
:
3957 case elfcpp::R_POWERPC_JMP_SLOT
:
3958 case elfcpp::R_POWERPC_RELATIVE
:
3959 case elfcpp::R_POWERPC_DTPMOD
:
3960 case elfcpp::R_PPC64_JMP_IREL
:
3961 case elfcpp::R_POWERPC_IRELATIVE
:
3962 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3963 _("unexpected reloc %u in object file"),
3967 case elfcpp::R_PPC_EMB_SDA21
:
3972 // R_PPC64_TOCSAVE. For the time being this can be ignored.
3976 case elfcpp::R_PPC_EMB_SDA2I16
:
3977 case elfcpp::R_PPC_EMB_SDA2REL
:
3980 // R_PPC64_TLSGD, R_PPC64_TLSLD
3983 case elfcpp::R_POWERPC_PLT32
:
3984 case elfcpp::R_POWERPC_PLTREL32
:
3985 case elfcpp::R_POWERPC_PLT16_LO
:
3986 case elfcpp::R_POWERPC_PLT16_HI
:
3987 case elfcpp::R_POWERPC_PLT16_HA
:
3988 case elfcpp::R_PPC_SDAREL16
:
3989 case elfcpp::R_POWERPC_ADDR30
:
3990 case elfcpp::R_PPC64_PLT64
:
3991 case elfcpp::R_PPC64_PLTREL64
:
3992 case elfcpp::R_PPC64_PLTGOT16
:
3993 case elfcpp::R_PPC64_PLTGOT16_LO
:
3994 case elfcpp::R_PPC64_PLTGOT16_HI
:
3995 case elfcpp::R_PPC64_PLTGOT16_HA
:
3996 case elfcpp::R_PPC64_PLT16_LO_DS
:
3997 case elfcpp::R_PPC64_PLTGOT16_DS
:
3998 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
3999 case elfcpp::R_PPC_EMB_RELSEC16
:
4000 case elfcpp::R_PPC_EMB_RELST_LO
:
4001 case elfcpp::R_PPC_EMB_RELST_HI
:
4002 case elfcpp::R_PPC_EMB_RELST_HA
:
4003 case elfcpp::R_PPC_EMB_BIT_FLD
:
4004 case elfcpp::R_PPC_EMB_RELSDA
:
4005 case elfcpp::R_PPC_TOC16
:
4008 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4009 _("unsupported reloc %u"),
4013 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
4014 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4015 _("relocation overflow"));
4020 // Relocate section data.
4022 template<int size
, bool big_endian
>
4024 Target_powerpc
<size
, big_endian
>::relocate_section(
4025 const Relocate_info
<size
, big_endian
>* relinfo
,
4026 unsigned int sh_type
,
4027 const unsigned char* prelocs
,
4029 Output_section
* output_section
,
4030 bool needs_special_offset_handling
,
4031 unsigned char* view
,
4033 section_size_type view_size
,
4034 const Reloc_symbol_changes
* reloc_symbol_changes
)
4036 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
4037 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
4039 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4041 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
4048 needs_special_offset_handling
,
4052 reloc_symbol_changes
);
4055 class Powerpc_scan_relocatable_reloc
4058 // Return the strategy to use for a local symbol which is not a
4059 // section symbol, given the relocation type.
4060 inline Relocatable_relocs::Reloc_strategy
4061 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
4063 if (r_type
== 0 && r_sym
== 0)
4064 return Relocatable_relocs::RELOC_DISCARD
;
4065 return Relocatable_relocs::RELOC_COPY
;
4068 // Return the strategy to use for a local symbol which is a section
4069 // symbol, given the relocation type.
4070 inline Relocatable_relocs::Reloc_strategy
4071 local_section_strategy(unsigned int, Relobj
*)
4073 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
4076 // Return the strategy to use for a global symbol, given the
4077 // relocation type, the object, and the symbol index.
4078 inline Relocatable_relocs::Reloc_strategy
4079 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
4081 if (r_type
== elfcpp::R_PPC_PLTREL24
)
4082 return Relocatable_relocs::RELOC_SPECIAL
;
4083 return Relocatable_relocs::RELOC_COPY
;
4087 // Scan the relocs during a relocatable link.
4089 template<int size
, bool big_endian
>
4091 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
4092 Symbol_table
* symtab
,
4094 Sized_relobj_file
<size
, big_endian
>* object
,
4095 unsigned int data_shndx
,
4096 unsigned int sh_type
,
4097 const unsigned char* prelocs
,
4099 Output_section
* output_section
,
4100 bool needs_special_offset_handling
,
4101 size_t local_symbol_count
,
4102 const unsigned char* plocal_symbols
,
4103 Relocatable_relocs
* rr
)
4105 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4107 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4108 Powerpc_scan_relocatable_reloc
>(
4116 needs_special_offset_handling
,
4122 // Emit relocations for a section.
4123 // This is a modified version of the function by the same name in
4124 // target-reloc.h. Using relocate_special_relocatable for
4125 // R_PPC_PLTREL24 would require duplication of the entire body of the
4126 // loop, so we may as well duplicate the whole thing.
4128 template<int size
, bool big_endian
>
4130 Target_powerpc
<size
, big_endian
>::relocate_relocs(
4131 const Relocate_info
<size
, big_endian
>* relinfo
,
4132 unsigned int sh_type
,
4133 const unsigned char* prelocs
,
4135 Output_section
* output_section
,
4136 off_t offset_in_output_section
,
4137 const Relocatable_relocs
* rr
,
4139 Address view_address
,
4141 unsigned char* reloc_view
,
4142 section_size_type reloc_view_size
)
4144 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4146 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4148 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
4150 const int reloc_size
4151 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4153 Powerpc_relobj
<size
, big_endian
>* const object
4154 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4155 const unsigned int local_count
= object
->local_symbol_count();
4156 unsigned int got2_shndx
= object
->got2_shndx();
4157 Address got2_addend
= 0;
4158 if (got2_shndx
!= 0)
4160 got2_addend
= object
->get_output_section_offset(got2_shndx
);
4161 gold_assert(got2_addend
!= invalid_address
);
4164 unsigned char* pwrite
= reloc_view
;
4165 bool zap_next
= false;
4166 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
4168 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
4169 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
4172 Reltype
reloc(prelocs
);
4173 Reltype_write
reloc_write(pwrite
);
4175 Address offset
= reloc
.get_r_offset();
4176 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
4177 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
4178 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4179 const unsigned int orig_r_sym
= r_sym
;
4180 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
4181 = reloc
.get_r_addend();
4182 const Symbol
* gsym
= NULL
;
4186 // We could arrange to discard these and other relocs for
4187 // tls optimised sequences in the strategy methods, but for
4188 // now do as BFD ld does.
4189 r_type
= elfcpp::R_POWERPC_NONE
;
4193 // Get the new symbol index.
4194 if (r_sym
< local_count
)
4198 case Relocatable_relocs::RELOC_COPY
:
4199 case Relocatable_relocs::RELOC_SPECIAL
:
4202 r_sym
= object
->symtab_index(r_sym
);
4203 gold_assert(r_sym
!= -1U);
4207 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
4209 // We are adjusting a section symbol. We need to find
4210 // the symbol table index of the section symbol for
4211 // the output section corresponding to input section
4212 // in which this symbol is defined.
4213 gold_assert(r_sym
< local_count
);
4215 unsigned int shndx
=
4216 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
4217 gold_assert(is_ordinary
);
4218 Output_section
* os
= object
->output_section(shndx
);
4219 gold_assert(os
!= NULL
);
4220 gold_assert(os
->needs_symtab_index());
4221 r_sym
= os
->symtab_index();
4231 gsym
= object
->global_symbol(r_sym
);
4232 gold_assert(gsym
!= NULL
);
4233 if (gsym
->is_forwarder())
4234 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
4236 gold_assert(gsym
->has_symtab_index());
4237 r_sym
= gsym
->symtab_index();
4240 // Get the new offset--the location in the output section where
4241 // this relocation should be applied.
4242 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4243 offset
+= offset_in_output_section
;
4246 section_offset_type sot_offset
=
4247 convert_types
<section_offset_type
, Address
>(offset
);
4248 section_offset_type new_sot_offset
=
4249 output_section
->output_offset(object
, relinfo
->data_shndx
,
4251 gold_assert(new_sot_offset
!= -1);
4252 offset
= new_sot_offset
;
4255 // In an object file, r_offset is an offset within the section.
4256 // In an executable or dynamic object, generated by
4257 // --emit-relocs, r_offset is an absolute address.
4258 if (!parameters
->options().relocatable())
4260 offset
+= view_address
;
4261 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4262 offset
-= offset_in_output_section
;
4265 // Handle the reloc addend based on the strategy.
4266 if (strategy
== Relocatable_relocs::RELOC_COPY
)
4268 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
4270 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
4271 addend
= psymval
->value(object
, addend
);
4273 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
4275 if (addend
>= 32768)
4276 addend
+= got2_addend
;
4281 if (!parameters
->options().relocatable())
4283 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4284 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4285 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4286 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4288 // First instruction of a global dynamic sequence,
4290 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4291 switch (this->optimize_tls_gd(final
))
4293 case tls::TLSOPT_TO_IE
:
4294 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4295 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4297 case tls::TLSOPT_TO_LE
:
4298 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4299 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4300 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4303 r_type
= elfcpp::R_POWERPC_NONE
;
4304 offset
-= 2 * big_endian
;
4311 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4312 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4313 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4314 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4316 // First instruction of a local dynamic sequence,
4318 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4320 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4321 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4323 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4324 const Output_section
* os
= relinfo
->layout
->tls_segment()
4326 gold_assert(os
!= NULL
);
4327 gold_assert(os
->needs_symtab_index());
4328 r_sym
= os
->symtab_index();
4329 addend
= dtp_offset
;
4333 r_type
= elfcpp::R_POWERPC_NONE
;
4334 offset
-= 2 * big_endian
;
4338 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4339 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4340 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4341 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4343 // First instruction of initial exec sequence.
4344 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4345 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4347 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4348 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4349 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4352 r_type
= elfcpp::R_POWERPC_NONE
;
4353 offset
-= 2 * big_endian
;
4357 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4358 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4360 // Second instruction of a global dynamic sequence,
4361 // the __tls_get_addr call
4362 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4363 switch (this->optimize_tls_gd(final
))
4365 case tls::TLSOPT_TO_IE
:
4366 r_type
= elfcpp::R_POWERPC_NONE
;
4369 case tls::TLSOPT_TO_LE
:
4370 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4371 offset
+= 2 * big_endian
;
4378 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4379 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4381 // Second instruction of a local dynamic sequence,
4382 // the __tls_get_addr call
4383 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4385 const Output_section
* os
= relinfo
->layout
->tls_segment()
4387 gold_assert(os
!= NULL
);
4388 gold_assert(os
->needs_symtab_index());
4389 r_sym
= os
->symtab_index();
4390 addend
= dtp_offset
;
4391 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4392 offset
+= 2 * big_endian
;
4396 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4398 // Second instruction of an initial exec sequence
4399 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4400 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4402 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4403 offset
+= 2 * big_endian
;
4408 reloc_write
.put_r_offset(offset
);
4409 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
4410 reloc_write
.put_r_addend(addend
);
4412 pwrite
+= reloc_size
;
4415 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
4416 == reloc_view_size
);
4419 // Return the value to use for a dynamic which requires special
4420 // treatment. This is how we support equality comparisons of function
4421 // pointers across shared library boundaries, as described in the
4422 // processor specific ABI supplement.
4424 template<int size
, bool big_endian
>
4426 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4430 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4431 return this->plt_section()->address() + gsym
->plt_offset();
4437 // Return the offset to use for the GOT_INDX'th got entry which is
4438 // for a local tls symbol specified by OBJECT, SYMNDX.
4439 template<int size
, bool big_endian
>
4441 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
4442 const Relobj
* object
,
4443 unsigned int symndx
,
4444 unsigned int got_indx
) const
4446 const Powerpc_relobj
<size
, big_endian
>* ppc_object
4447 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
4448 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
4450 for (Got_type got_type
= GOT_TYPE_TLSGD
;
4451 got_type
<= GOT_TYPE_TPREL
;
4452 got_type
= Got_type(got_type
+ 1))
4453 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
4455 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
4456 if (got_type
== GOT_TYPE_TLSGD
)
4458 if (off
== got_indx
* (size
/ 8))
4460 if (got_type
== GOT_TYPE_TPREL
)
4470 // Return the offset to use for the GOT_INDX'th got entry which is
4471 // for global tls symbol GSYM.
4472 template<int size
, bool big_endian
>
4474 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
4476 unsigned int got_indx
) const
4478 if (gsym
->type() == elfcpp::STT_TLS
)
4480 for (Got_type got_type
= GOT_TYPE_TLSGD
;
4481 got_type
<= GOT_TYPE_TPREL
;
4482 got_type
= Got_type(got_type
+ 1))
4483 if (gsym
->has_got_offset(got_type
))
4485 unsigned int off
= gsym
->got_offset(got_type
);
4486 if (got_type
== GOT_TYPE_TLSGD
)
4488 if (off
== got_indx
* (size
/ 8))
4490 if (got_type
== GOT_TYPE_TPREL
)
4500 // The selector for powerpc object files.
4502 template<int size
, bool big_endian
>
4503 class Target_selector_powerpc
: public Target_selector
4506 Target_selector_powerpc()
4507 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4509 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
4510 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
4512 ? (big_endian
? "elf64ppc" : "elf64lppc")
4513 : (big_endian
? "elf32ppc" : "elf32lppc")))
4517 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4522 if (machine
!= elfcpp::EM_PPC64
)
4527 if (machine
!= elfcpp::EM_PPC
)
4535 return this->instantiate_target();
4539 do_instantiate_target()
4540 { return new Target_powerpc
<size
, big_endian
>(); }
4543 Target_selector_powerpc
<32, true> target_selector_ppc32
;
4544 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
4545 Target_selector_powerpc
<64, true> target_selector_ppc64
;
4546 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
4548 } // End anonymous namespace.