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 // Relocate a section.
275 relocate_section(const Relocate_info
<size
, big_endian
>*,
276 unsigned int sh_type
,
277 const unsigned char* prelocs
,
279 Output_section
* output_section
,
280 bool needs_special_offset_handling
,
282 Address view_address
,
283 section_size_type view_size
,
284 const Reloc_symbol_changes
*);
286 // Scan the relocs during a relocatable link.
288 scan_relocatable_relocs(Symbol_table
* symtab
,
290 Sized_relobj_file
<size
, big_endian
>* object
,
291 unsigned int data_shndx
,
292 unsigned int sh_type
,
293 const unsigned char* prelocs
,
295 Output_section
* output_section
,
296 bool needs_special_offset_handling
,
297 size_t local_symbol_count
,
298 const unsigned char* plocal_symbols
,
299 Relocatable_relocs
*);
301 // Emit relocations for a section.
303 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
304 unsigned int sh_type
,
305 const unsigned char* prelocs
,
307 Output_section
* output_section
,
308 off_t offset_in_output_section
,
309 const Relocatable_relocs
*,
311 Address view_address
,
313 unsigned char* reloc_view
,
314 section_size_type reloc_view_size
);
316 // Return whether SYM is defined by the ABI.
318 do_is_defined_by_abi(const Symbol
* sym
) const
320 return strcmp(sym
->name(), "__tls_get_addr") == 0;
323 // Return the size of the GOT section.
327 gold_assert(this->got_
!= NULL
);
328 return this->got_
->data_size();
331 // Get the PLT section.
332 const Output_data_plt_powerpc
<size
, big_endian
>*
335 gold_assert(this->plt_
!= NULL
);
339 // Get the .glink section.
340 const Output_data_glink
<size
, big_endian
>*
341 glink_section() const
343 gold_assert(this->glink_
!= NULL
);
347 // Get the GOT section.
348 const Output_data_got_powerpc
<size
, big_endian
>*
351 gold_assert(this->got_
!= NULL
);
356 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
357 const elfcpp::Ehdr
<size
, big_endian
>&);
359 // Return the number of entries in the GOT.
361 got_entry_count() const
363 if (this->got_
== NULL
)
365 return this->got_size() / (size
/ 8);
368 // Return the number of entries in the PLT.
370 plt_entry_count() const;
372 // Return the offset of the first non-reserved PLT entry.
374 first_plt_entry_offset() const;
376 // Return the size of each PLT entry.
378 plt_entry_size() const;
380 // Add any special sections for this symbol to the gc work list.
381 // For powerpc64, this adds the code section of a function
384 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
386 // Handle target specific gc actions when adding a gc reference from
387 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
388 // and DST_OFF. For powerpc64, this adds a referenc to the code
389 // section of a function descriptor.
391 do_gc_add_reference(Symbol_table
* symtab
,
393 unsigned int src_shndx
,
395 unsigned int dst_shndx
,
396 Address dst_off
) const;
400 // The class which scans relocations.
405 : issued_non_pic_error_(false)
409 get_reference_flags(unsigned int r_type
);
412 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
413 Sized_relobj_file
<size
, big_endian
>* object
,
414 unsigned int data_shndx
,
415 Output_section
* output_section
,
416 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
417 const elfcpp::Sym
<size
, big_endian
>& lsym
);
420 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
421 Sized_relobj_file
<size
, big_endian
>* object
,
422 unsigned int data_shndx
,
423 Output_section
* output_section
,
424 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
428 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
430 Sized_relobj_file
<size
, big_endian
>* ,
433 const elfcpp::Rela
<size
, big_endian
>& ,
435 const elfcpp::Sym
<size
, big_endian
>&)
439 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
441 Sized_relobj_file
<size
, big_endian
>* ,
444 const elfcpp::Rela
<size
,
446 unsigned int , Symbol
*)
451 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
452 unsigned int r_type
);
455 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
456 unsigned int r_type
, Symbol
*);
459 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
460 Target_powerpc
* target
);
463 check_non_pic(Relobj
*, unsigned int r_type
);
465 // Whether we have issued an error about a non-PIC compilation.
466 bool issued_non_pic_error_
;
470 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
471 Powerpc_relobj
<size
, big_endian
>* object
,
472 unsigned int *dest_shndx
);
474 // The class which implements relocation.
478 // Use 'at' branch hints when true, 'y' when false.
479 // FIXME maybe: set this with an option.
480 static const bool is_isa_v2
= true;
484 CALL_NOT_EXPECTED
= 0,
490 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
495 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
497 // FIXME: This needs to specify the location somehow.
498 gold_error(_("missing expected __tls_get_addr call"));
502 // Do a relocation. Return false if the caller should not issue
503 // any warnings about this relocation.
505 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
506 Output_section
*, size_t relnum
,
507 const elfcpp::Rela
<size
, big_endian
>&,
508 unsigned int r_type
, const Sized_symbol
<size
>*,
509 const Symbol_value
<size
>*,
511 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
514 // This is set if we should skip the next reloc, which should be a
515 // call to __tls_get_addr.
516 enum skip_tls call_tls_get_addr_
;
519 // A class which returns the size required for a relocation type,
520 // used while scanning relocs during a relocatable link.
521 class Relocatable_size_for_reloc
525 get_size_for_reloc(unsigned int, Relobj
*)
532 // Optimize the TLS relocation type based on what we know about the
533 // symbol. IS_FINAL is true if the final address of this symbol is
534 // known at link time.
536 tls::Tls_optimization
537 optimize_tls_gd(bool is_final
)
539 // If we are generating a shared library, then we can't do anything
541 if (parameters
->options().shared())
542 return tls::TLSOPT_NONE
;
545 return tls::TLSOPT_TO_IE
;
546 return tls::TLSOPT_TO_LE
;
549 tls::Tls_optimization
552 if (parameters
->options().shared())
553 return tls::TLSOPT_NONE
;
555 return tls::TLSOPT_TO_LE
;
558 tls::Tls_optimization
559 optimize_tls_ie(bool is_final
)
561 if (!is_final
|| parameters
->options().shared())
562 return tls::TLSOPT_NONE
;
564 return tls::TLSOPT_TO_LE
;
567 // Get the GOT section, creating it if necessary.
568 Output_data_got_powerpc
<size
, big_endian
>*
569 got_section(Symbol_table
*, Layout
*);
573 make_glink_section(Layout
*);
575 // Create the PLT section.
577 make_plt_section(Layout
*);
579 // Create a PLT entry for a global symbol.
581 make_plt_entry(Layout
*, Symbol
*,
582 const elfcpp::Rela
<size
, big_endian
>&,
583 const Sized_relobj
<size
, big_endian
>* object
);
585 // Create a GOT entry for local dynamic __tls_get_addr.
587 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
588 Sized_relobj_file
<size
, big_endian
>* object
);
591 tlsld_got_offset() const
593 return this->tlsld_got_offset_
;
596 // Get the dynamic reloc section, creating it if necessary.
598 rela_dyn_section(Layout
*);
600 // Copy a relocation against a global symbol.
602 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
603 Sized_relobj_file
<size
, big_endian
>* object
,
604 unsigned int shndx
, Output_section
* output_section
,
605 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
607 this->copy_relocs_
.copy_reloc(symtab
, layout
,
608 symtab
->get_sized_symbol
<size
>(sym
),
609 object
, shndx
, output_section
,
610 reloc
, this->rela_dyn_section(layout
));
613 // Information about this specific target which we pass to the
614 // general Target structure.
615 static Target::Target_info powerpc_info
;
617 // The types of GOT entries needed for this platform.
618 // These values are exposed to the ABI in an incremental link.
619 // Do not renumber existing values without changing the version
620 // number of the .gnu_incremental_inputs section.
624 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
625 GOT_TYPE_DTPREL
, // entry for @got@dtprel
626 GOT_TYPE_TPREL
// entry for @got@tprel
629 // The GOT output section.
630 Output_data_got_powerpc
<size
, big_endian
>* got_
;
631 // The PLT output section.
632 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
633 // The .glink output section.
634 Output_data_glink
<size
, big_endian
>* glink_
;
635 // The dynamic reloc output section.
636 Reloc_section
* rela_dyn_
;
637 // Relocs saved to avoid a COPY reloc.
638 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
639 // Space for variables copied with a COPY reloc.
640 Output_data_space
* dynbss_
;
641 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
642 unsigned int tlsld_got_offset_
;
646 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
649 true, // is_big_endian
650 elfcpp::EM_PPC
, // machine_code
651 false, // has_make_symbol
652 false, // has_resolve
653 false, // has_code_fill
654 true, // is_default_stack_executable
655 false, // can_icf_inline_merge_sections
657 "/usr/lib/ld.so.1", // dynamic_linker
658 0x10000000, // default_text_segment_address
659 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
660 4 * 1024, // common_pagesize (overridable by -z common-page-size)
661 false, // isolate_execinstr
663 elfcpp::SHN_UNDEF
, // small_common_shndx
664 elfcpp::SHN_UNDEF
, // large_common_shndx
665 0, // small_common_section_flags
666 0, // large_common_section_flags
667 NULL
, // attributes_section
668 NULL
// attributes_vendor
672 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
675 false, // is_big_endian
676 elfcpp::EM_PPC
, // machine_code
677 false, // has_make_symbol
678 false, // has_resolve
679 false, // has_code_fill
680 true, // is_default_stack_executable
681 false, // can_icf_inline_merge_sections
683 "/usr/lib/ld.so.1", // dynamic_linker
684 0x10000000, // default_text_segment_address
685 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
686 4 * 1024, // common_pagesize (overridable by -z common-page-size)
687 false, // isolate_execinstr
689 elfcpp::SHN_UNDEF
, // small_common_shndx
690 elfcpp::SHN_UNDEF
, // large_common_shndx
691 0, // small_common_section_flags
692 0, // large_common_section_flags
693 NULL
, // attributes_section
694 NULL
// attributes_vendor
698 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
701 true, // is_big_endian
702 elfcpp::EM_PPC64
, // machine_code
703 false, // has_make_symbol
704 false, // has_resolve
705 false, // has_code_fill
706 true, // is_default_stack_executable
707 false, // can_icf_inline_merge_sections
709 "/usr/lib/ld.so.1", // dynamic_linker
710 0x10000000, // default_text_segment_address
711 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
712 4 * 1024, // common_pagesize (overridable by -z common-page-size)
713 false, // isolate_execinstr
715 elfcpp::SHN_UNDEF
, // small_common_shndx
716 elfcpp::SHN_UNDEF
, // large_common_shndx
717 0, // small_common_section_flags
718 0, // large_common_section_flags
719 NULL
, // attributes_section
720 NULL
// attributes_vendor
724 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
727 false, // is_big_endian
728 elfcpp::EM_PPC64
, // machine_code
729 false, // has_make_symbol
730 false, // has_resolve
731 false, // has_code_fill
732 true, // is_default_stack_executable
733 false, // can_icf_inline_merge_sections
735 "/usr/lib/ld.so.1", // dynamic_linker
736 0x10000000, // default_text_segment_address
737 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
738 4 * 1024, // common_pagesize (overridable by -z common-page-size)
739 false, // isolate_execinstr
741 elfcpp::SHN_UNDEF
, // small_common_shndx
742 elfcpp::SHN_UNDEF
, // large_common_shndx
743 0, // small_common_section_flags
744 0, // large_common_section_flags
745 NULL
, // attributes_section
746 NULL
// attributes_vendor
750 is_branch_reloc(unsigned int r_type
)
752 return (r_type
== elfcpp::R_POWERPC_REL24
753 || r_type
== elfcpp::R_PPC_PLTREL24
754 || r_type
== elfcpp::R_PPC_LOCAL24PC
755 || r_type
== elfcpp::R_POWERPC_REL14
756 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
757 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
758 || r_type
== elfcpp::R_POWERPC_ADDR24
759 || r_type
== elfcpp::R_POWERPC_ADDR14
760 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
761 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
764 // If INSN is an opcode that may be used with an @tls operand, return
765 // the transformed insn for TLS optimisation, otherwise return 0. If
766 // REG is non-zero only match an insn with RB or RA equal to REG.
768 at_tls_transform(uint32_t insn
, unsigned int reg
)
770 if ((insn
& (0x3f << 26)) != 31 << 26)
774 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
775 rtra
= insn
& ((1 << 26) - (1 << 16));
776 else if (((insn
>> 16) & 0x1f) == reg
)
777 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
781 if ((insn
& (0x3ff << 1)) == 266 << 1)
784 else if ((insn
& (0x1f << 1)) == 23 << 1
785 && ((insn
& (0x1f << 6)) < 14 << 6
786 || ((insn
& (0x1f << 6)) >= 16 << 6
787 && (insn
& (0x1f << 6)) < 24 << 6)))
788 // load and store indexed -> dform
789 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
790 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
791 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
792 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
793 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
795 insn
= (58 << 26) | 2;
802 // Modified version of symtab.h class Symbol member
803 // Given a direct absolute or pc-relative static relocation against
804 // the global symbol, this function returns whether a dynamic relocation
809 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
811 // No dynamic relocations in a static link!
812 if (parameters
->doing_static_link())
815 // A reference to an undefined symbol from an executable should be
816 // statically resolved to 0, and does not need a dynamic relocation.
817 // This matches gnu ld behavior.
818 if (gsym
->is_undefined() && !parameters
->options().shared())
821 // A reference to an absolute symbol does not need a dynamic relocation.
822 if (gsym
->is_absolute())
825 // An absolute reference within a position-independent output file
826 // will need a dynamic relocation.
827 if ((flags
& Symbol::ABSOLUTE_REF
)
828 && parameters
->options().output_is_position_independent())
831 // A function call that can branch to a local PLT entry does not need
832 // a dynamic relocation.
833 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
836 // A reference to any PLT entry in a non-position-independent executable
837 // does not need a dynamic relocation.
838 // Except due to having function descriptors on powerpc64 we don't define
839 // functions to their plt code in an executable, so this doesn't apply.
841 && !parameters
->options().output_is_position_independent()
842 && gsym
->has_plt_offset())
845 // A reference to a symbol defined in a dynamic object or to a
846 // symbol that is preemptible will need a dynamic relocation.
847 if (gsym
->is_from_dynobj()
848 || gsym
->is_undefined()
849 || gsym
->is_preemptible())
852 // For all other cases, return FALSE.
856 // Modified version of symtab.h class Symbol member
857 // Whether we should use the PLT offset associated with a symbol for
858 // a relocation. FLAGS is a set of Reference_flags.
862 use_plt_offset(const Symbol
* gsym
, int flags
)
864 // If the symbol doesn't have a PLT offset, then naturally we
865 // don't want to use it.
866 if (!gsym
->has_plt_offset())
869 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
870 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
873 // If we are going to generate a dynamic relocation, then we will
874 // wind up using that, so no need to use the PLT entry.
875 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
878 // If the symbol is from a dynamic object, we need to use the PLT
880 if (gsym
->is_from_dynobj())
883 // If we are generating a shared object, and gsym symbol is
884 // undefined or preemptible, we need to use the PLT entry.
885 if (parameters
->options().shared()
886 && (gsym
->is_undefined() || gsym
->is_preemptible()))
889 // If gsym is a call to a weak undefined symbol, we need to use
890 // the PLT entry; the symbol may be defined by a library loaded
892 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
895 // Otherwise we can use the regular definition.
899 template<int size
, bool big_endian
>
900 class Powerpc_relocate_functions
917 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
918 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
920 template<int valsize
>
922 has_overflow_signed(Address value
)
924 // limit = 1 << (valsize - 1) without shift count exceeding size of type
925 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
926 limit
<<= ((valsize
- 1) >> 1);
927 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
928 return value
+ limit
> (limit
<< 1) - 1;
931 template<int valsize
>
933 has_overflow_bitfield(Address value
)
935 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
936 limit
<<= ((valsize
- 1) >> 1);
937 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
938 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
941 template<int valsize
>
943 overflowed(Address value
, Overflow_check overflow
)
945 if (overflow
== CHECK_SIGNED
)
947 if (has_overflow_signed
<valsize
>(value
))
948 return STATUS_OVERFLOW
;
950 else if (overflow
== CHECK_BITFIELD
)
952 if (has_overflow_bitfield
<valsize
>(value
))
953 return STATUS_OVERFLOW
;
958 // Do a simple RELA relocation
959 template<int valsize
>
961 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
963 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
964 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
965 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
966 return overflowed
<valsize
>(value
, overflow
);
969 template<int valsize
>
971 rela(unsigned char* view
,
972 unsigned int right_shift
,
973 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
975 Overflow_check overflow
)
977 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
978 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
979 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
980 Valtype reloc
= value
>> right_shift
;
983 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
984 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
987 // Do a simple RELA relocation, unaligned.
988 template<int valsize
>
990 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
992 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
993 return overflowed
<valsize
>(value
, overflow
);
996 template<int valsize
>
998 rela_ua(unsigned char* view
,
999 unsigned int right_shift
,
1000 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1002 Overflow_check overflow
)
1004 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1006 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1007 Valtype reloc
= value
>> right_shift
;
1010 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1011 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1015 // R_PPC64_ADDR64: (Symbol + Addend)
1017 addr64(unsigned char* view
, Address value
)
1018 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1020 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1022 addr64_u(unsigned char* view
, Address value
)
1023 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1025 // R_POWERPC_ADDR32: (Symbol + Addend)
1026 static inline Status
1027 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1028 { return This::template rela
<32>(view
, value
, overflow
); }
1030 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1031 static inline Status
1032 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1033 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1035 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1036 static inline Status
1037 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1039 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1040 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1041 stat
= STATUS_OVERFLOW
;
1045 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1046 static inline Status
1047 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1048 { return This::template rela
<16>(view
, value
, overflow
); }
1050 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1051 static inline Status
1052 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1053 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1055 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1056 static inline Status
1057 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1059 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1060 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1061 stat
= STATUS_OVERFLOW
;
1065 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1067 addr16_hi(unsigned char* view
, Address value
)
1068 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1070 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1072 addr16_ha(unsigned char* view
, Address value
)
1073 { This::addr16_hi(view
, value
+ 0x8000); }
1075 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1077 addr16_hi2(unsigned char* view
, Address value
)
1078 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1080 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1082 addr16_ha2(unsigned char* view
, Address value
)
1083 { This::addr16_hi2(view
, value
+ 0x8000); }
1085 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1087 addr16_hi3(unsigned char* view
, Address value
)
1088 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1090 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1092 addr16_ha3(unsigned char* view
, Address value
)
1093 { This::addr16_hi3(view
, value
+ 0x8000); }
1095 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1096 static inline Status
1097 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1099 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1100 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1101 stat
= STATUS_OVERFLOW
;
1106 // Stash away the index of .got2 or .opd in a relocatable object, if
1107 // such a section exists.
1109 template<int size
, bool big_endian
>
1111 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1112 Read_symbols_data
* sd
)
1114 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1115 const unsigned char* namesu
= sd
->section_names
->data();
1116 const char* names
= reinterpret_cast<const char*>(namesu
);
1117 section_size_type names_size
= sd
->section_names_size
;
1118 const unsigned char* s
;
1120 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1121 names
, names_size
, NULL
);
1124 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1125 this->special_
= ndx
;
1127 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1130 // Examine .rela.opd to build info about function entry points.
1132 template<int size
, bool big_endian
>
1134 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1136 const unsigned char* prelocs
,
1137 const unsigned char* plocal_syms
)
1141 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1143 const int reloc_size
1144 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1145 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1147 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1149 Reltype
reloc(prelocs
);
1150 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1151 = reloc
.get_r_info();
1152 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1153 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1155 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1156 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1159 if (r_sym
< this->local_symbol_count())
1161 typename
elfcpp::Sym
<size
, big_endian
>
1162 lsym(plocal_syms
+ r_sym
* sym_size
);
1163 shndx
= lsym
.get_st_shndx();
1164 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1165 value
= lsym
.get_st_value();
1168 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1170 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1171 value
+ reloc
.get_r_addend());
1177 template<int size
, bool big_endian
>
1179 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1181 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1184 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1185 p
!= rd
->relocs
.end();
1188 if (p
->data_shndx
== this->opd_shndx())
1190 this->init_opd(this->section_size(this->opd_shndx()));
1191 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1192 rd
->local_symbols
->data());
1199 // Set up PowerPC target specific relobj.
1201 template<int size
, bool big_endian
>
1203 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1204 const std::string
& name
,
1205 Input_file
* input_file
,
1206 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1208 int et
= ehdr
.get_e_type();
1209 // ET_EXEC files are valid input for --just-symbols/-R,
1210 // and we treat them as relocatable objects.
1211 if (et
== elfcpp::ET_REL
1212 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1214 Powerpc_relobj
<size
, big_endian
>* obj
=
1215 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1219 else if (et
== elfcpp::ET_DYN
)
1221 Sized_dynobj
<size
, big_endian
>* obj
=
1222 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1228 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1233 template<int size
, bool big_endian
>
1234 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1237 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1238 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1240 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1241 : Output_data_got
<size
, big_endian
>(),
1242 symtab_(symtab
), layout_(layout
),
1243 header_ent_cnt_(size
== 32 ? 3 : 1),
1244 header_index_(size
== 32 ? 0x2000 : 0)
1249 // Create a new GOT entry and return its offset.
1251 add_got_entry(Got_entry got_entry
)
1253 this->reserve_ent();
1254 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1257 // Create a pair of new GOT entries and return the offset of the first.
1259 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1261 this->reserve_ent(2);
1262 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1267 add_constant_pair(Valtype c1
, Valtype c2
)
1269 this->reserve_ent(2);
1270 unsigned int got_offset
= this->add_constant(c1
);
1271 this->add_constant(c2
);
1275 // Offset of _GLOBAL_OFFSET_TABLE_.
1279 return this->got_offset(this->header_index_
);
1282 // Offset of base used to access the GOT/TOC.
1283 // The got/toc pointer reg will be set to this value.
1284 typename
elfcpp::Elf_types
<size
>::Elf_Off
1285 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1288 return this->g_o_t();
1290 return (this->output_section()->address()
1291 + object
->toc_base_offset()
1295 // Ensure our GOT has a header.
1297 set_final_data_size()
1299 if (this->header_ent_cnt_
!= 0)
1300 this->make_header();
1301 Output_data_got
<size
, big_endian
>::set_final_data_size();
1304 // First word of GOT header needs some values that are not
1305 // handled by Output_data_got so poke them in here.
1306 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1308 do_write(Output_file
* of
)
1310 this->replace_constant(this->header_index_
,
1312 ? this->layout_
->dynamic_section()->address()
1313 : this->output_section()->address() + 0x8000));
1315 Output_data_got
<size
, big_endian
>::do_write(of
);
1320 reserve_ent(unsigned int cnt
= 1)
1322 if (this->header_ent_cnt_
== 0)
1324 if (this->num_entries() + cnt
> this->header_index_
)
1325 this->make_header();
1331 this->header_ent_cnt_
= 0;
1332 this->header_index_
= this->num_entries();
1335 Output_data_got
<size
, big_endian
>::add_constant(0);
1336 Output_data_got
<size
, big_endian
>::add_constant(0);
1337 Output_data_got
<size
, big_endian
>::add_constant(0);
1339 // Define _GLOBAL_OFFSET_TABLE_ at the header
1340 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1341 Symbol_table::PREDEFINED
,
1342 this, this->g_o_t(), 0,
1349 Output_data_got
<size
, big_endian
>::add_constant(0);
1352 // Stashed pointers.
1353 Symbol_table
* symtab_
;
1357 unsigned int header_ent_cnt_
;
1358 // GOT header index.
1359 unsigned int header_index_
;
1362 // Get the GOT section, creating it if necessary.
1364 template<int size
, bool big_endian
>
1365 Output_data_got_powerpc
<size
, big_endian
>*
1366 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1369 if (this->got_
== NULL
)
1371 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1374 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1376 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1377 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1378 this->got_
, ORDER_DATA
, false);
1384 // Get the dynamic reloc section, creating it if necessary.
1386 template<int size
, bool big_endian
>
1387 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1388 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1390 if (this->rela_dyn_
== NULL
)
1392 gold_assert(layout
!= NULL
);
1393 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1394 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1395 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1396 ORDER_DYNAMIC_RELOCS
, false);
1398 return this->rela_dyn_
;
1401 // A class to handle the PLT data.
1403 template<int size
, bool big_endian
>
1404 class Output_data_plt_powerpc
: public Output_section_data_build
1407 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1408 size
, big_endian
> Reloc_section
;
1410 Output_data_plt_powerpc(Layout
*, Target_powerpc
<size
, big_endian
>*);
1412 // Add an entry to the PLT.
1416 // Return the .rela.plt section data.
1417 const Reloc_section
*
1423 // Return the number of PLT entries.
1427 return ((this->current_data_size() - initial_plt_entry_size
)
1431 // Return the offset of the first non-reserved PLT entry.
1433 first_plt_entry_offset()
1434 { return initial_plt_entry_size
; }
1436 // Return the size of a PLT entry.
1438 get_plt_entry_size()
1439 { return plt_entry_size
; }
1443 do_adjust_output_section(Output_section
* os
)
1448 // Write to a map file.
1450 do_print_to_mapfile(Mapfile
* mapfile
) const
1451 { mapfile
->print_output_data(this, _("** PLT")); }
1454 // The size of an entry in the PLT.
1455 static const int plt_entry_size
= size
== 32 ? 4 : 24;
1456 // The size of the first reserved entry.
1457 static const int initial_plt_entry_size
= size
== 32 ? 0 : 24;
1459 // Write out the PLT data.
1461 do_write(Output_file
*);
1463 // The reloc section.
1464 Reloc_section
* rel_
;
1465 // Allows access to .glink for do_write.
1466 Target_powerpc
<size
, big_endian
>* targ_
;
1469 // Create the PLT section.
1471 template<int size
, bool big_endian
>
1472 Output_data_plt_powerpc
<size
, big_endian
>::Output_data_plt_powerpc(
1474 Target_powerpc
<size
, big_endian
>* targ
)
1475 : Output_section_data_build(size
== 32 ? 4 : 8),
1478 this->rel_
= new Reloc_section(false);
1479 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1480 elfcpp::SHF_ALLOC
, this->rel_
,
1481 ORDER_DYNAMIC_PLT_RELOCS
, false);
1484 // Add an entry to the PLT.
1486 template<int size
, bool big_endian
>
1488 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1490 if (!gsym
->has_plt_offset())
1492 off_t off
= this->current_data_size();
1495 off
+= initial_plt_entry_size
;
1496 gsym
->set_plt_offset(off
);
1497 gsym
->set_needs_dynsym_entry();
1498 this->rel_
->add_global(gsym
, elfcpp::R_POWERPC_JMP_SLOT
, this, off
, 0);
1499 off
+= plt_entry_size
;
1500 this->set_current_data_size(off
);
1504 static const uint32_t add_0_11_11
= 0x7c0b5a14;
1505 static const uint32_t add_3_3_2
= 0x7c631214;
1506 static const uint32_t add_3_3_13
= 0x7c636a14;
1507 static const uint32_t add_11_0_11
= 0x7d605a14;
1508 static const uint32_t add_12_2_11
= 0x7d825a14;
1509 static const uint32_t addi_11_11
= 0x396b0000;
1510 static const uint32_t addi_12_12
= 0x398c0000;
1511 static const uint32_t addi_2_2
= 0x38420000;
1512 static const uint32_t addi_3_2
= 0x38620000;
1513 static const uint32_t addi_3_3
= 0x38630000;
1514 static const uint32_t addis_0_2
= 0x3c020000;
1515 static const uint32_t addis_0_13
= 0x3c0d0000;
1516 static const uint32_t addis_11_11
= 0x3d6b0000;
1517 static const uint32_t addis_11_30
= 0x3d7e0000;
1518 static const uint32_t addis_12_12
= 0x3d8c0000;
1519 static const uint32_t addis_12_2
= 0x3d820000;
1520 static const uint32_t addis_3_2
= 0x3c620000;
1521 static const uint32_t addis_3_13
= 0x3c6d0000;
1522 static const uint32_t b
= 0x48000000;
1523 static const uint32_t bcl_20_31
= 0x429f0005;
1524 static const uint32_t bctr
= 0x4e800420;
1525 static const uint32_t blrl
= 0x4e800021;
1526 static const uint32_t cror_15_15_15
= 0x4def7b82;
1527 static const uint32_t cror_31_31_31
= 0x4ffffb82;
1528 static const uint32_t ld_11_12
= 0xe96c0000;
1529 static const uint32_t ld_11_2
= 0xe9620000;
1530 static const uint32_t ld_2_1
= 0xe8410000;
1531 static const uint32_t ld_2_11
= 0xe84b0000;
1532 static const uint32_t ld_2_12
= 0xe84c0000;
1533 static const uint32_t ld_2_2
= 0xe8420000;
1534 static const uint32_t li_0_0
= 0x38000000;
1535 static const uint32_t lis_0_0
= 0x3c000000;
1536 static const uint32_t lis_11
= 0x3d600000;
1537 static const uint32_t lis_12
= 0x3d800000;
1538 static const uint32_t lwz_0_12
= 0x800c0000;
1539 static const uint32_t lwz_11_11
= 0x816b0000;
1540 static const uint32_t lwz_11_30
= 0x817e0000;
1541 static const uint32_t lwz_12_12
= 0x818c0000;
1542 static const uint32_t lwzu_0_12
= 0x840c0000;
1543 static const uint32_t mflr_0
= 0x7c0802a6;
1544 static const uint32_t mflr_11
= 0x7d6802a6;
1545 static const uint32_t mflr_12
= 0x7d8802a6;
1546 static const uint32_t mtctr_0
= 0x7c0903a6;
1547 static const uint32_t mtctr_11
= 0x7d6903a6;
1548 static const uint32_t mtlr_0
= 0x7c0803a6;
1549 static const uint32_t mtlr_12
= 0x7d8803a6;
1550 static const uint32_t nop
= 0x60000000;
1551 static const uint32_t ori_0_0_0
= 0x60000000;
1552 static const uint32_t std_2_1
= 0xf8410000;
1553 static const uint32_t sub_11_11_12
= 0x7d6c5850;
1555 // Write out the PLT.
1557 template<int size
, bool big_endian
>
1559 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
1563 const off_t offset
= this->offset();
1564 const section_size_type oview_size
1565 = convert_to_section_size_type(this->data_size());
1566 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1567 unsigned char* pov
= oview
;
1568 unsigned char* endpov
= oview
+ oview_size
;
1570 // The address the .glink branch table
1571 const Output_data_glink
<size
, big_endian
>* glink
1572 = this->targ_
->glink_section();
1573 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
1574 = glink
->address() + glink
->pltresolve();
1576 while (pov
< endpov
)
1578 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
1583 of
->write_output_view(offset
, oview_size
, oview
);
1587 // Create the PLT section.
1589 template<int size
, bool big_endian
>
1591 Target_powerpc
<size
, big_endian
>::make_plt_section(Layout
* layout
)
1593 if (this->plt_
== NULL
)
1595 if (this->glink_
== NULL
)
1596 make_glink_section(layout
);
1598 // Ensure that .rela.dyn always appears before .rela.plt This is
1599 // necessary due to how, on PowerPC and some other targets, .rela.dyn
1600 // needs to include .rela.plt in it's range.
1601 this->rela_dyn_section(layout
);
1603 this->plt_
= new Output_data_plt_powerpc
<size
, big_endian
>(layout
, this);
1604 layout
->add_output_section_data(".plt",
1606 ? elfcpp::SHT_PROGBITS
1607 : elfcpp::SHT_NOBITS
),
1608 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1617 // A class to handle .glink.
1619 template<int size
, bool big_endian
>
1620 class Output_data_glink
: public Output_section_data
1623 static const int pltresolve_size
= 16*4;
1625 Output_data_glink(Target_powerpc
<size
, big_endian
>*);
1629 add_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1630 const Sized_relobj
<size
, big_endian
>*);
1633 find_entry(const Symbol
*, const elfcpp::Rela
<size
, big_endian
>&,
1634 const Sized_relobj
<size
, big_endian
>*) const;
1637 glink_entry_size() const
1642 // FIXME: We should be using multiple glink sections for
1643 // stubs to support > 33M applications.
1650 return this->pltresolve_
;
1654 // Write to a map file.
1656 do_print_to_mapfile(Mapfile
* mapfile
) const
1657 { mapfile
->print_output_data(this, _("** glink")); }
1661 set_final_data_size();
1665 do_write(Output_file
*);
1670 Glink_sym_ent(const Symbol
* sym
,
1671 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1672 const Sized_relobj
<size
, big_endian
>* object
)
1673 : sym_(sym
), addend_(0), object_(0)
1676 this->addend_
= reloc
.get_r_addend();
1677 else if (parameters
->options().output_is_position_independent()
1678 && (elfcpp::elf_r_type
<size
>(reloc
.get_r_info())
1679 == elfcpp::R_PPC_PLTREL24
))
1681 this->addend_
= reloc
.get_r_addend();
1682 if (this->addend_
!= 0)
1683 this->object_
= object
;
1687 bool operator==(const Glink_sym_ent
& that
) const
1689 return (this->sym_
== that
.sym_
1690 && this->object_
== that
.object_
1691 && this->addend_
== that
.addend_
);
1695 unsigned int addend_
;
1696 const Sized_relobj
<size
, big_endian
>* object_
;
1699 class Glink_sym_ent_hash
1702 size_t operator()(const Glink_sym_ent
& ent
) const
1704 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
1705 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
1710 // Map sym/object/addend to index.
1711 typedef Unordered_map
<Glink_sym_ent
, unsigned int,
1712 Glink_sym_ent_hash
> Glink_entries
;
1713 Glink_entries glink_entries_
;
1715 // Offset of pltresolve stub (actually, branch table for 32-bit)
1718 // Allows access to .got and .plt for do_write.
1719 Target_powerpc
<size
, big_endian
>* targ_
;
1722 // Create the glink section.
1724 template<int size
, bool big_endian
>
1725 Output_data_glink
<size
, big_endian
>::Output_data_glink(
1726 Target_powerpc
<size
, big_endian
>* targ
)
1727 : Output_section_data(16),
1728 pltresolve_(0), targ_(targ
)
1732 // Add an entry to glink, if we do not already have one for this
1733 // sym/object/addend combo.
1735 template<int size
, bool big_endian
>
1737 Output_data_glink
<size
, big_endian
>::add_entry(
1739 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1740 const Sized_relobj
<size
, big_endian
>* object
)
1742 Glink_sym_ent
ent(gsym
, reloc
, object
);
1743 unsigned int indx
= this->glink_entries_
.size();
1744 this->glink_entries_
.insert(std::make_pair(ent
, indx
));
1747 template<int size
, bool big_endian
>
1749 Output_data_glink
<size
, big_endian
>::find_entry(
1751 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1752 const Sized_relobj
<size
, big_endian
>* object
) const
1754 Glink_sym_ent
ent(gsym
, reloc
, object
);
1755 typename
Glink_entries::const_iterator p
= this->glink_entries_
.find(ent
);
1756 gold_assert(p
!= this->glink_entries_
.end());
1760 template<int size
, bool big_endian
>
1762 Output_data_glink
<size
, big_endian
>::set_final_data_size()
1764 unsigned int count
= this->glink_entries_
.size();
1765 off_t total
= count
;
1772 this->pltresolve_
= total
;
1774 // space for branch table
1775 total
+= 4 * (count
- 1);
1777 total
+= -total
& 15;
1778 total
+= this->pltresolve_size
;
1783 this->pltresolve_
= total
;
1784 total
+= this->pltresolve_size
;
1786 // space for branch table
1789 total
+= 4 * (count
- 0x8000);
1793 this->set_data_size(total
);
1796 static inline uint32_t
1802 static inline uint32_t
1808 static inline uint32_t
1811 return hi(a
+ 0x8000);
1814 template<bool big_endian
>
1816 write_insn(unsigned char* p
, uint32_t v
)
1818 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
1821 // Write out .glink.
1823 template<int size
, bool big_endian
>
1825 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
1827 const off_t off
= this->offset();
1828 const section_size_type oview_size
=
1829 convert_to_section_size_type(this->data_size());
1830 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1833 // The base address of the .plt section.
1834 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1835 Address plt_base
= this->targ_
->plt_section()->address();
1837 const Output_data_got_powerpc
<size
, big_endian
>* got
1838 = this->targ_
->got_section();
1842 Address got_os_addr
= got
->output_section()->address();
1844 // Write out call stubs.
1845 typename
Glink_entries::const_iterator g
;
1846 for (g
= this->glink_entries_
.begin();
1847 g
!= this->glink_entries_
.end();
1850 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1851 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1852 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1853 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
1854 Address pltoff
= plt_addr
- got_addr
;
1856 if (pltoff
+ 0x80008000 > 0xffffffff || (pltoff
& 7) != 0)
1857 gold_error(_("%s: linkage table error against `%s'"),
1858 g
->first
.object_
->name().c_str(),
1859 g
->first
.sym_
->demangled_name().c_str());
1861 p
= oview
+ g
->second
* this->glink_entry_size();
1862 if (ha(pltoff
) != 0)
1864 write_insn
<big_endian
>(p
, addis_12_2
+ ha(pltoff
)), p
+= 4;
1865 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1866 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
)), p
+= 4;
1867 if (ha(pltoff
+ 16) != ha(pltoff
))
1869 write_insn
<big_endian
>(p
, addi_12_12
+ l(pltoff
)), p
+= 4;
1872 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1873 write_insn
<big_endian
>(p
, ld_2_12
+ l(pltoff
+ 8)), p
+= 4;
1874 write_insn
<big_endian
>(p
, ld_11_12
+ l(pltoff
+ 16)), p
+= 4;
1875 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1879 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
1880 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
)), p
+= 4;
1881 if (ha(pltoff
+ 16) != ha(pltoff
))
1883 write_insn
<big_endian
>(p
, addi_2_2
+ l(pltoff
)), p
+= 4;
1886 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1887 write_insn
<big_endian
>(p
, ld_11_2
+ l(pltoff
+ 16)), p
+= 4;
1888 write_insn
<big_endian
>(p
, ld_2_2
+ l(pltoff
+ 8)), p
+= 4;
1889 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1893 // Write pltresolve stub.
1894 p
= oview
+ this->pltresolve_
;
1895 Address after_bcl
= this->address() + this->pltresolve_
+ 16;
1896 Address pltoff
= plt_base
- after_bcl
;
1898 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
1900 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
1901 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
1902 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
1903 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
1904 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
1905 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
1906 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
1907 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
1908 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
1909 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
1910 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
1911 while (p
< oview
+ this->pltresolve_
+ this->pltresolve_size
)
1912 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1914 // Write lazy link call stubs.
1916 while (p
< oview
+ oview_size
)
1920 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
1924 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
1925 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
1927 uint32_t branch_off
= this->pltresolve_
+ 8 - (p
- oview
);
1928 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
1934 // The address of _GLOBAL_OFFSET_TABLE_.
1935 Address g_o_t
= got
->address() + got
->g_o_t();
1937 // Write out call stubs.
1938 typename
Glink_entries::const_iterator g
;
1939 for (g
= this->glink_entries_
.begin();
1940 g
!= this->glink_entries_
.end();
1943 Address plt_addr
= plt_base
+ g
->first
.sym_
->plt_offset();
1945 const Address invalid_address
= static_cast<Address
>(-1);
1947 p
= oview
+ g
->second
* this->glink_entry_size();
1948 if (parameters
->options().output_is_position_independent())
1950 const Powerpc_relobj
<size
, big_endian
>* object
= static_cast
1951 <const Powerpc_relobj
<size
, big_endian
>*>(g
->first
.object_
);
1954 unsigned int got2
= object
->got2_shndx();
1955 got_addr
= g
->first
.object_
->get_output_section_offset(got2
);
1956 gold_assert(got_addr
!= invalid_address
);
1957 got_addr
+= (g
->first
.object_
->output_section(got2
)->address()
1958 + g
->first
.addend_
);
1963 Address pltoff
= plt_addr
- got_addr
;
1964 if (ha(pltoff
) == 0)
1966 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(pltoff
));
1967 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
1968 write_insn
<big_endian
>(p
+ 8, bctr
);
1972 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(pltoff
));
1973 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(pltoff
));
1974 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1975 write_insn
<big_endian
>(p
+ 12, bctr
);
1980 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
1981 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
1982 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
1983 write_insn
<big_endian
>(p
+ 12, bctr
);
1987 // Write out pltresolve branch table.
1988 p
= oview
+ this->pltresolve_
;
1989 unsigned int the_end
= oview_size
- this->pltresolve_size
;
1990 unsigned char* end_p
= oview
+ the_end
;
1991 while (p
< end_p
- 8 * 4)
1992 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
1994 write_insn
<big_endian
>(p
, nop
), p
+= 4;
1996 // Write out pltresolve call stub.
1997 if (parameters
->options().output_is_position_independent())
1999 Address res0_off
= this->pltresolve_
;
2000 Address after_bcl_off
= the_end
+ 12;
2001 Address bcl_res0
= after_bcl_off
- res0_off
;
2003 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
2004 write_insn
<big_endian
>(p
+ 4, mflr_0
);
2005 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
2006 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
2007 write_insn
<big_endian
>(p
+ 16, mflr_12
);
2008 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
2009 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
2011 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
2013 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
2014 if (ha(got_bcl
) == ha(got_bcl
+ 4))
2016 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
2017 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
2021 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
2022 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
2024 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
2025 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
2026 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
2027 write_insn
<big_endian
>(p
+ 52, bctr
);
2028 write_insn
<big_endian
>(p
+ 56, nop
);
2029 write_insn
<big_endian
>(p
+ 60, nop
);
2033 Address res0
= this->pltresolve_
+ this->address();
2035 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
2036 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
2037 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2038 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
2040 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
2041 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
2042 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
2043 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
2044 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
2045 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
2047 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
2048 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
2049 write_insn
<big_endian
>(p
+ 32, bctr
);
2050 write_insn
<big_endian
>(p
+ 36, nop
);
2051 write_insn
<big_endian
>(p
+ 40, nop
);
2052 write_insn
<big_endian
>(p
+ 44, nop
);
2053 write_insn
<big_endian
>(p
+ 48, nop
);
2054 write_insn
<big_endian
>(p
+ 52, nop
);
2055 write_insn
<big_endian
>(p
+ 56, nop
);
2056 write_insn
<big_endian
>(p
+ 60, nop
);
2061 of
->write_output_view(off
, oview_size
, oview
);
2064 // Create the glink section.
2066 template<int size
, bool big_endian
>
2068 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
2070 if (this->glink_
== NULL
)
2072 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
2073 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
2074 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2075 this->glink_
, ORDER_TEXT
, false);
2079 // Create a PLT entry for a global symbol.
2081 template<int size
, bool big_endian
>
2083 Target_powerpc
<size
, big_endian
>::make_plt_entry(
2086 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2087 const Sized_relobj
<size
, big_endian
>* object
)
2089 if (this->plt_
== NULL
)
2090 this->make_plt_section(layout
);
2092 this->plt_
->add_entry(gsym
);
2094 this->glink_
->add_entry(gsym
, reloc
, object
);
2097 // Return the number of entries in the PLT.
2099 template<int size
, bool big_endian
>
2101 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
2103 if (this->plt_
== NULL
)
2105 return this->plt_
->entry_count();
2108 // Return the offset of the first non-reserved PLT entry.
2110 template<int size
, bool big_endian
>
2112 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
2114 return Output_data_plt_powerpc
<size
, big_endian
>::first_plt_entry_offset();
2117 // Return the size of each PLT entry.
2119 template<int size
, bool big_endian
>
2121 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
2123 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
2126 // Create a GOT entry for local dynamic __tls_get_addr calls.
2128 template<int size
, bool big_endian
>
2130 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
2131 Symbol_table
* symtab
,
2133 Sized_relobj_file
<size
, big_endian
>* object
)
2135 if (this->tlsld_got_offset_
== -1U)
2137 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2138 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2139 Output_data_got_powerpc
<size
, big_endian
>* got
2140 = this->got_section(symtab
, layout
);
2141 unsigned int got_offset
= got
->add_constant_pair(0, 0);
2142 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
2144 this->tlsld_got_offset_
= got_offset
;
2146 return this->tlsld_got_offset_
;
2149 // Get the Reference_flags for a particular relocation.
2151 template<int size
, bool big_endian
>
2153 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
2157 case elfcpp::R_POWERPC_NONE
:
2158 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2159 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2160 case elfcpp::R_PPC64_TOC
:
2161 // No symbol reference.
2164 case elfcpp::R_PPC64_ADDR64
:
2165 case elfcpp::R_PPC64_UADDR64
:
2166 case elfcpp::R_POWERPC_ADDR32
:
2167 case elfcpp::R_POWERPC_UADDR32
:
2168 case elfcpp::R_POWERPC_ADDR16
:
2169 case elfcpp::R_POWERPC_UADDR16
:
2170 case elfcpp::R_POWERPC_ADDR16_LO
:
2171 case elfcpp::R_POWERPC_ADDR16_HI
:
2172 case elfcpp::R_POWERPC_ADDR16_HA
:
2173 return Symbol::ABSOLUTE_REF
;
2175 case elfcpp::R_POWERPC_ADDR24
:
2176 case elfcpp::R_POWERPC_ADDR14
:
2177 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2178 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2179 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2181 case elfcpp::R_POWERPC_REL32
:
2182 case elfcpp::R_PPC_LOCAL24PC
:
2183 case elfcpp::R_POWERPC_REL16
:
2184 case elfcpp::R_POWERPC_REL16_LO
:
2185 case elfcpp::R_POWERPC_REL16_HI
:
2186 case elfcpp::R_POWERPC_REL16_HA
:
2187 return Symbol::RELATIVE_REF
;
2189 case elfcpp::R_POWERPC_REL24
:
2190 case elfcpp::R_PPC_PLTREL24
:
2191 case elfcpp::R_POWERPC_REL14
:
2192 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2193 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2194 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2196 case elfcpp::R_POWERPC_GOT16
:
2197 case elfcpp::R_POWERPC_GOT16_LO
:
2198 case elfcpp::R_POWERPC_GOT16_HI
:
2199 case elfcpp::R_POWERPC_GOT16_HA
:
2200 case elfcpp::R_PPC64_TOC16
:
2201 case elfcpp::R_PPC64_TOC16_LO
:
2202 case elfcpp::R_PPC64_TOC16_HI
:
2203 case elfcpp::R_PPC64_TOC16_HA
:
2204 case elfcpp::R_PPC64_TOC16_DS
:
2205 case elfcpp::R_PPC64_TOC16_LO_DS
:
2207 return Symbol::ABSOLUTE_REF
;
2209 case elfcpp::R_POWERPC_GOT_TPREL16
:
2210 case elfcpp::R_POWERPC_TLS
:
2211 return Symbol::TLS_REF
;
2213 case elfcpp::R_POWERPC_COPY
:
2214 case elfcpp::R_POWERPC_GLOB_DAT
:
2215 case elfcpp::R_POWERPC_JMP_SLOT
:
2216 case elfcpp::R_POWERPC_RELATIVE
:
2217 case elfcpp::R_POWERPC_DTPMOD
:
2219 // Not expected. We will give an error later.
2224 // Report an unsupported relocation against a local symbol.
2226 template<int size
, bool big_endian
>
2228 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2229 Sized_relobj_file
<size
, big_endian
>* object
,
2230 unsigned int r_type
)
2232 gold_error(_("%s: unsupported reloc %u against local symbol"),
2233 object
->name().c_str(), r_type
);
2236 // We are about to emit a dynamic relocation of type R_TYPE. If the
2237 // dynamic linker does not support it, issue an error.
2239 template<int size
, bool big_endian
>
2241 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
2242 unsigned int r_type
)
2244 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
2246 // These are the relocation types supported by glibc for both 32-bit
2247 // and 64-bit powerpc.
2250 case elfcpp::R_POWERPC_NONE
:
2251 case elfcpp::R_POWERPC_RELATIVE
:
2252 case elfcpp::R_POWERPC_GLOB_DAT
:
2253 case elfcpp::R_POWERPC_DTPMOD
:
2254 case elfcpp::R_POWERPC_DTPREL
:
2255 case elfcpp::R_POWERPC_TPREL
:
2256 case elfcpp::R_POWERPC_JMP_SLOT
:
2257 case elfcpp::R_POWERPC_COPY
:
2258 case elfcpp::R_POWERPC_IRELATIVE
:
2259 case elfcpp::R_POWERPC_ADDR32
:
2260 case elfcpp::R_POWERPC_UADDR32
:
2261 case elfcpp::R_POWERPC_ADDR24
:
2262 case elfcpp::R_POWERPC_ADDR16
:
2263 case elfcpp::R_POWERPC_UADDR16
:
2264 case elfcpp::R_POWERPC_ADDR16_LO
:
2265 case elfcpp::R_POWERPC_ADDR16_HI
:
2266 case elfcpp::R_POWERPC_ADDR16_HA
:
2267 case elfcpp::R_POWERPC_ADDR14
:
2268 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2269 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2270 case elfcpp::R_POWERPC_REL32
:
2271 case elfcpp::R_POWERPC_REL24
:
2272 case elfcpp::R_POWERPC_TPREL16
:
2273 case elfcpp::R_POWERPC_TPREL16_LO
:
2274 case elfcpp::R_POWERPC_TPREL16_HI
:
2275 case elfcpp::R_POWERPC_TPREL16_HA
:
2286 // These are the relocation types supported only on 64-bit.
2287 case elfcpp::R_PPC64_ADDR64
:
2288 case elfcpp::R_PPC64_UADDR64
:
2289 case elfcpp::R_PPC64_JMP_IREL
:
2290 case elfcpp::R_PPC64_ADDR16_DS
:
2291 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2292 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2293 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2294 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2295 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2296 case elfcpp::R_PPC64_REL64
:
2297 case elfcpp::R_POWERPC_ADDR30
:
2298 case elfcpp::R_PPC64_TPREL16_DS
:
2299 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2300 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2301 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2302 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2303 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2314 // These are the relocation types supported only on 32-bit.
2315 // ??? glibc ld.so doesn't need to support these.
2316 case elfcpp::R_POWERPC_DTPREL16
:
2317 case elfcpp::R_POWERPC_DTPREL16_LO
:
2318 case elfcpp::R_POWERPC_DTPREL16_HI
:
2319 case elfcpp::R_POWERPC_DTPREL16_HA
:
2327 // This prevents us from issuing more than one error per reloc
2328 // section. But we can still wind up issuing more than one
2329 // error per object file.
2330 if (this->issued_non_pic_error_
)
2332 gold_assert(parameters
->options().output_is_position_independent());
2333 object
->error(_("requires unsupported dynamic reloc; "
2334 "recompile with -fPIC"));
2335 this->issued_non_pic_error_
= true;
2339 // Scan a relocation for a local symbol.
2341 template<int size
, bool big_endian
>
2343 Target_powerpc
<size
, big_endian
>::Scan::local(
2344 Symbol_table
* symtab
,
2346 Target_powerpc
<size
, big_endian
>* target
,
2347 Sized_relobj_file
<size
, big_endian
>* object
,
2348 unsigned int data_shndx
,
2349 Output_section
* output_section
,
2350 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2351 unsigned int r_type
,
2352 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2354 Powerpc_relobj
<size
, big_endian
>* ppc_object
2355 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2359 case elfcpp::R_POWERPC_NONE
:
2360 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2361 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2362 case elfcpp::R_PPC64_TOCSAVE
:
2363 case elfcpp::R_PPC_EMB_MRKREF
:
2364 case elfcpp::R_POWERPC_TLS
:
2367 case elfcpp::R_PPC64_TOC
:
2369 Output_data_got_powerpc
<size
, big_endian
>* got
2370 = target
->got_section(symtab
, layout
);
2371 if (parameters
->options().output_is_position_independent())
2373 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2374 rela_dyn
->add_output_section_relative(got
->output_section(),
2375 elfcpp::R_POWERPC_RELATIVE
,
2378 reloc
.get_r_offset(),
2379 ppc_object
->toc_base_offset());
2384 case elfcpp::R_PPC64_ADDR64
:
2385 case elfcpp::R_PPC64_UADDR64
:
2386 case elfcpp::R_POWERPC_ADDR32
:
2387 case elfcpp::R_POWERPC_UADDR32
:
2388 case elfcpp::R_POWERPC_ADDR24
:
2389 case elfcpp::R_POWERPC_ADDR16
:
2390 case elfcpp::R_POWERPC_ADDR16_LO
:
2391 case elfcpp::R_POWERPC_ADDR16_HI
:
2392 case elfcpp::R_POWERPC_ADDR16_HA
:
2393 case elfcpp::R_POWERPC_UADDR16
:
2394 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2395 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2396 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2397 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2398 case elfcpp::R_PPC64_ADDR16_DS
:
2399 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2400 case elfcpp::R_POWERPC_ADDR14
:
2401 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2402 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2403 // If building a shared library (or a position-independent
2404 // executable), we need to create a dynamic relocation for
2406 if (parameters
->options().output_is_position_independent())
2408 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2410 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2411 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2413 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2414 rela_dyn
->add_local_relative(object
, r_sym
,
2415 elfcpp::R_POWERPC_RELATIVE
,
2416 output_section
, data_shndx
,
2417 reloc
.get_r_offset(),
2418 reloc
.get_r_addend(), false);
2422 check_non_pic(object
, r_type
);
2423 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2424 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
2425 data_shndx
, reloc
.get_r_offset(),
2426 reloc
.get_r_addend());
2431 case elfcpp::R_PPC64_REL64
:
2432 case elfcpp::R_POWERPC_REL32
:
2433 case elfcpp::R_POWERPC_REL24
:
2434 case elfcpp::R_PPC_LOCAL24PC
:
2435 case elfcpp::R_POWERPC_REL16
:
2436 case elfcpp::R_POWERPC_REL16_LO
:
2437 case elfcpp::R_POWERPC_REL16_HI
:
2438 case elfcpp::R_POWERPC_REL16_HA
:
2439 case elfcpp::R_POWERPC_REL14
:
2440 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2441 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2442 case elfcpp::R_POWERPC_SECTOFF
:
2443 case elfcpp::R_POWERPC_TPREL16
:
2444 case elfcpp::R_POWERPC_DTPREL16
:
2445 case elfcpp::R_POWERPC_SECTOFF_LO
:
2446 case elfcpp::R_POWERPC_TPREL16_LO
:
2447 case elfcpp::R_POWERPC_DTPREL16_LO
:
2448 case elfcpp::R_POWERPC_SECTOFF_HI
:
2449 case elfcpp::R_POWERPC_TPREL16_HI
:
2450 case elfcpp::R_POWERPC_DTPREL16_HI
:
2451 case elfcpp::R_POWERPC_SECTOFF_HA
:
2452 case elfcpp::R_POWERPC_TPREL16_HA
:
2453 case elfcpp::R_POWERPC_DTPREL16_HA
:
2454 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2455 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2456 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2457 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2458 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2459 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2460 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2461 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2462 case elfcpp::R_PPC64_TPREL16_DS
:
2463 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2464 case elfcpp::R_PPC64_DTPREL16_DS
:
2465 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2466 case elfcpp::R_PPC64_SECTOFF_DS
:
2467 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2468 case elfcpp::R_PPC64_TLSGD
:
2469 case elfcpp::R_PPC64_TLSLD
:
2472 case elfcpp::R_POWERPC_GOT16
:
2473 case elfcpp::R_POWERPC_GOT16_LO
:
2474 case elfcpp::R_POWERPC_GOT16_HI
:
2475 case elfcpp::R_POWERPC_GOT16_HA
:
2476 case elfcpp::R_PPC64_GOT16_DS
:
2477 case elfcpp::R_PPC64_GOT16_LO_DS
:
2479 // The symbol requires a GOT entry.
2480 Output_data_got_powerpc
<size
, big_endian
>* got
2481 = target
->got_section(symtab
, layout
);
2482 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2484 // If we are generating a shared object, we need to add a
2485 // dynamic relocation for this symbol's GOT entry.
2486 if (parameters
->options().output_is_position_independent())
2488 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2490 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2493 off
= got
->add_constant(0);
2494 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2495 rela_dyn
->add_local_relative(object
, r_sym
,
2496 elfcpp::R_POWERPC_RELATIVE
,
2497 got
, off
, 0, false);
2501 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2505 case elfcpp::R_PPC64_TOC16
:
2506 case elfcpp::R_PPC64_TOC16_LO
:
2507 case elfcpp::R_PPC64_TOC16_HI
:
2508 case elfcpp::R_PPC64_TOC16_HA
:
2509 case elfcpp::R_PPC64_TOC16_DS
:
2510 case elfcpp::R_PPC64_TOC16_LO_DS
:
2511 // We need a GOT section.
2512 target
->got_section(symtab
, layout
);
2515 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2516 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2517 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2518 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2520 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
2521 if (tls_type
== tls::TLSOPT_NONE
)
2523 Output_data_got_powerpc
<size
, big_endian
>* got
2524 = target
->got_section(symtab
, layout
);
2525 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2526 unsigned int shndx
= lsym
.get_st_shndx();
2528 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2529 gold_assert(is_ordinary
);
2530 got
->add_local_pair_with_rel(object
, r_sym
,
2533 target
->rela_dyn_section(layout
),
2534 elfcpp::R_POWERPC_DTPMOD
,
2535 elfcpp::R_POWERPC_DTPREL
);
2537 else if (tls_type
== tls::TLSOPT_TO_LE
)
2539 // no GOT relocs needed for Local Exec.
2546 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2547 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2548 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2549 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2551 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2552 if (tls_type
== tls::TLSOPT_NONE
)
2553 target
->tlsld_got_offset(symtab
, layout
, object
);
2554 else if (tls_type
== tls::TLSOPT_TO_LE
)
2556 // no GOT relocs needed for Local Exec.
2557 if (parameters
->options().emit_relocs())
2559 Output_section
* os
= layout
->tls_segment()->first_section();
2560 gold_assert(os
!= NULL
);
2561 os
->set_needs_symtab_index();
2569 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2570 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2571 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2572 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2574 Output_data_got_powerpc
<size
, big_endian
>* got
2575 = target
->got_section(symtab
, layout
);
2576 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2577 got
->add_local_with_rel(object
, r_sym
, GOT_TYPE_DTPREL
,
2578 target
->rela_dyn_section(layout
),
2579 elfcpp::R_POWERPC_DTPREL
);
2583 case elfcpp::R_POWERPC_GOT_TPREL16
:
2584 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2585 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2586 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2588 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
2589 if (tls_type
== tls::TLSOPT_NONE
)
2591 Output_data_got_powerpc
<size
, big_endian
>* got
2592 = target
->got_section(symtab
, layout
);
2593 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2594 got
->add_local_with_rel(object
, r_sym
, GOT_TYPE_TPREL
,
2595 target
->rela_dyn_section(layout
),
2596 elfcpp::R_POWERPC_TPREL
);
2598 else if (tls_type
== tls::TLSOPT_TO_LE
)
2600 // no GOT relocs needed for Local Exec.
2608 unsupported_reloc_local(object
, r_type
);
2613 // Report an unsupported relocation against a global symbol.
2615 template<int size
, bool big_endian
>
2617 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2618 Sized_relobj_file
<size
, big_endian
>* object
,
2619 unsigned int r_type
,
2622 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2623 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2626 // Scan a relocation for a global symbol.
2628 template<int size
, bool big_endian
>
2630 Target_powerpc
<size
, big_endian
>::Scan::global(
2631 Symbol_table
* symtab
,
2633 Target_powerpc
<size
, big_endian
>* target
,
2634 Sized_relobj_file
<size
, big_endian
>* object
,
2635 unsigned int data_shndx
,
2636 Output_section
* output_section
,
2637 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2638 unsigned int r_type
,
2641 Powerpc_relobj
<size
, big_endian
>* ppc_object
2642 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2646 case elfcpp::R_POWERPC_NONE
:
2647 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
2648 case elfcpp::R_POWERPC_GNU_VTENTRY
:
2649 case elfcpp::R_PPC_LOCAL24PC
:
2650 case elfcpp::R_PPC_EMB_MRKREF
:
2651 case elfcpp::R_POWERPC_TLS
:
2654 case elfcpp::R_PPC64_TOC
:
2656 Output_data_got_powerpc
<size
, big_endian
>* got
2657 = target
->got_section(symtab
, layout
);
2658 if (parameters
->options().output_is_position_independent())
2660 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2661 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
2662 if (data_shndx
!= ppc_object
->opd_shndx())
2663 symobj
= static_cast
2664 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
2665 rela_dyn
->add_output_section_relative(got
->output_section(),
2666 elfcpp::R_POWERPC_RELATIVE
,
2669 reloc
.get_r_offset(),
2670 symobj
->toc_base_offset());
2675 case elfcpp::R_PPC64_ADDR64
:
2676 case elfcpp::R_PPC64_UADDR64
:
2677 case elfcpp::R_POWERPC_ADDR32
:
2678 case elfcpp::R_POWERPC_UADDR32
:
2679 case elfcpp::R_POWERPC_ADDR24
:
2680 case elfcpp::R_POWERPC_ADDR16
:
2681 case elfcpp::R_POWERPC_ADDR16_LO
:
2682 case elfcpp::R_POWERPC_ADDR16_HI
:
2683 case elfcpp::R_POWERPC_ADDR16_HA
:
2684 case elfcpp::R_POWERPC_UADDR16
:
2685 case elfcpp::R_PPC64_ADDR16_HIGHER
:
2686 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
2687 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
2688 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
2689 case elfcpp::R_PPC64_ADDR16_DS
:
2690 case elfcpp::R_PPC64_ADDR16_LO_DS
:
2691 case elfcpp::R_POWERPC_ADDR14
:
2692 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
2693 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
2695 // Make a PLT entry if necessary.
2696 if (gsym
->needs_plt_entry())
2698 target
->make_plt_entry(layout
, gsym
, reloc
, 0);
2699 // Since this is not a PC-relative relocation, we may be
2700 // taking the address of a function. In that case we need to
2701 // set the entry in the dynamic symbol table to the address of
2704 && gsym
->is_from_dynobj() && !parameters
->options().shared())
2705 gsym
->set_needs_dynsym_value();
2707 // Make a dynamic relocation if necessary.
2708 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2710 if (gsym
->may_need_copy_reloc())
2712 target
->copy_reloc(symtab
, layout
, object
,
2713 data_shndx
, output_section
, gsym
, reloc
);
2715 else if (((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
2716 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
2717 && (gsym
->can_use_relative_reloc(false)
2718 || data_shndx
== ppc_object
->opd_shndx()))
2720 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2721 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2722 output_section
, object
,
2723 data_shndx
, reloc
.get_r_offset(),
2724 reloc
.get_r_addend(), false);
2728 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2729 check_non_pic(object
, r_type
);
2730 rela_dyn
->add_global(gsym
, r_type
, output_section
,
2732 reloc
.get_r_offset(),
2733 reloc
.get_r_addend());
2739 case elfcpp::R_PPC_PLTREL24
:
2740 case elfcpp::R_POWERPC_REL24
:
2741 if (gsym
->needs_plt_entry()
2742 || (!gsym
->final_value_is_known()
2743 && (gsym
->is_undefined()
2744 || gsym
->is_from_dynobj()
2745 || gsym
->is_preemptible())))
2746 target
->make_plt_entry(layout
, gsym
, reloc
, object
);
2749 case elfcpp::R_PPC64_REL64
:
2750 case elfcpp::R_POWERPC_REL32
:
2751 // Make a dynamic relocation if necessary.
2752 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
2754 if (gsym
->may_need_copy_reloc())
2756 target
->copy_reloc(symtab
, layout
, object
,
2757 data_shndx
, output_section
, gsym
,
2762 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2763 check_non_pic(object
, r_type
);
2764 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
2765 data_shndx
, reloc
.get_r_offset(),
2766 reloc
.get_r_addend());
2771 case elfcpp::R_POWERPC_REL16
:
2772 case elfcpp::R_POWERPC_REL16_LO
:
2773 case elfcpp::R_POWERPC_REL16_HI
:
2774 case elfcpp::R_POWERPC_REL16_HA
:
2775 case elfcpp::R_POWERPC_REL14
:
2776 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
2777 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
2778 case elfcpp::R_POWERPC_SECTOFF
:
2779 case elfcpp::R_POWERPC_TPREL16
:
2780 case elfcpp::R_POWERPC_DTPREL16
:
2781 case elfcpp::R_POWERPC_SECTOFF_LO
:
2782 case elfcpp::R_POWERPC_TPREL16_LO
:
2783 case elfcpp::R_POWERPC_DTPREL16_LO
:
2784 case elfcpp::R_POWERPC_SECTOFF_HI
:
2785 case elfcpp::R_POWERPC_TPREL16_HI
:
2786 case elfcpp::R_POWERPC_DTPREL16_HI
:
2787 case elfcpp::R_POWERPC_SECTOFF_HA
:
2788 case elfcpp::R_POWERPC_TPREL16_HA
:
2789 case elfcpp::R_POWERPC_DTPREL16_HA
:
2790 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
2791 case elfcpp::R_PPC64_TPREL16_HIGHER
:
2792 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
2793 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
2794 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
2795 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
2796 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
2797 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
2798 case elfcpp::R_PPC64_TPREL16_DS
:
2799 case elfcpp::R_PPC64_TPREL16_LO_DS
:
2800 case elfcpp::R_PPC64_DTPREL16_DS
:
2801 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
2802 case elfcpp::R_PPC64_SECTOFF_DS
:
2803 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
2804 case elfcpp::R_PPC64_TLSGD
:
2805 case elfcpp::R_PPC64_TLSLD
:
2808 case elfcpp::R_POWERPC_GOT16
:
2809 case elfcpp::R_POWERPC_GOT16_LO
:
2810 case elfcpp::R_POWERPC_GOT16_HI
:
2811 case elfcpp::R_POWERPC_GOT16_HA
:
2812 case elfcpp::R_PPC64_GOT16_DS
:
2813 case elfcpp::R_PPC64_GOT16_LO_DS
:
2815 // The symbol requires a GOT entry.
2816 Output_data_got_powerpc
<size
, big_endian
>* got
;
2818 got
= target
->got_section(symtab
, layout
);
2819 if (gsym
->final_value_is_known())
2820 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2823 // If this symbol is not fully resolved, we need to add a
2824 // dynamic relocation for it.
2825 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2826 if (gsym
->is_from_dynobj()
2827 || gsym
->is_undefined()
2828 || gsym
->is_preemptible())
2829 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2830 elfcpp::R_POWERPC_GLOB_DAT
);
2831 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2833 unsigned int off
= got
->add_constant(0);
2835 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2836 rela_dyn
->add_global_relative(gsym
, elfcpp::R_POWERPC_RELATIVE
,
2837 got
, off
, 0, false);
2843 case elfcpp::R_PPC64_TOC16
:
2844 case elfcpp::R_PPC64_TOC16_LO
:
2845 case elfcpp::R_PPC64_TOC16_HI
:
2846 case elfcpp::R_PPC64_TOC16_HA
:
2847 case elfcpp::R_PPC64_TOC16_DS
:
2848 case elfcpp::R_PPC64_TOC16_LO_DS
:
2849 // We need a GOT section.
2850 target
->got_section(symtab
, layout
);
2853 case elfcpp::R_POWERPC_GOT_TLSGD16
:
2854 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
2855 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
2856 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
2858 const bool final
= gsym
->final_value_is_known();
2859 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
2860 if (tls_type
== tls::TLSOPT_NONE
)
2862 Output_data_got_powerpc
<size
, big_endian
>* got
2863 = target
->got_section(symtab
, layout
);
2864 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
2865 target
->rela_dyn_section(layout
),
2866 elfcpp::R_POWERPC_DTPMOD
,
2867 elfcpp::R_POWERPC_DTPREL
);
2869 else if (tls_type
== tls::TLSOPT_TO_IE
)
2871 Output_data_got_powerpc
<size
, big_endian
>* got
2872 = target
->got_section(symtab
, layout
);
2873 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
2874 target
->rela_dyn_section(layout
),
2875 elfcpp::R_POWERPC_TPREL
);
2877 else if (tls_type
== tls::TLSOPT_TO_LE
)
2879 // no GOT relocs needed for Local Exec.
2886 case elfcpp::R_POWERPC_GOT_TLSLD16
:
2887 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
2888 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
2889 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
2891 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
2892 if (tls_type
== tls::TLSOPT_NONE
)
2893 target
->tlsld_got_offset(symtab
, layout
, object
);
2894 else if (tls_type
== tls::TLSOPT_TO_LE
)
2896 // no GOT relocs needed for Local Exec.
2897 if (parameters
->options().emit_relocs())
2899 Output_section
* os
= layout
->tls_segment()->first_section();
2900 gold_assert(os
!= NULL
);
2901 os
->set_needs_symtab_index();
2909 case elfcpp::R_POWERPC_GOT_DTPREL16
:
2910 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
2911 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
2912 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
2914 Output_data_got_powerpc
<size
, big_endian
>* got
2915 = target
->got_section(symtab
, layout
);
2916 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
2917 target
->rela_dyn_section(layout
),
2918 elfcpp::R_POWERPC_DTPREL
);
2922 case elfcpp::R_POWERPC_GOT_TPREL16
:
2923 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
2924 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
2925 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
2927 const bool final
= gsym
->final_value_is_known();
2928 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
2929 if (tls_type
== tls::TLSOPT_NONE
)
2931 Output_data_got_powerpc
<size
, big_endian
>* got
2932 = target
->got_section(symtab
, layout
);
2933 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
,
2934 target
->rela_dyn_section(layout
),
2935 elfcpp::R_POWERPC_TPREL
);
2937 else if (tls_type
== tls::TLSOPT_TO_LE
)
2939 // no GOT relocs needed for Local Exec.
2947 unsupported_reloc_global(object
, r_type
, gsym
);
2952 // Process relocations for gc.
2954 template<int size
, bool big_endian
>
2956 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
2957 Symbol_table
* symtab
,
2959 Sized_relobj_file
<size
, big_endian
>* object
,
2960 unsigned int data_shndx
,
2962 const unsigned char* prelocs
,
2964 Output_section
* output_section
,
2965 bool needs_special_offset_handling
,
2966 size_t local_symbol_count
,
2967 const unsigned char* plocal_symbols
)
2969 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
2970 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
2971 Powerpc_relobj
<size
, big_endian
>* ppc_object
2972 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
2974 ppc_object
->set_opd_valid();
2975 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
2977 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
2978 for (p
= ppc_object
->access_from_map()->begin();
2979 p
!= ppc_object
->access_from_map()->end();
2982 Address dst_off
= p
->first
;
2983 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
2984 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
2985 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
2987 Object
* src_obj
= s
->first
;
2988 unsigned int src_indx
= s
->second
;
2989 symtab
->gc()->add_reference(src_obj
, src_indx
,
2990 ppc_object
, dst_indx
);
2994 ppc_object
->access_from_map()->clear();
2995 // Don't look at .opd relocs as .opd will reference everything.
2999 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
3000 typename
Target_powerpc::Relocatable_size_for_reloc
>(
3009 needs_special_offset_handling
,
3014 // Handle target specific gc actions when adding a gc reference from
3015 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
3016 // and DST_OFF. For powerpc64, this adds a referenc to the code
3017 // section of a function descriptor.
3019 template<int size
, bool big_endian
>
3021 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
3022 Symbol_table
* symtab
,
3024 unsigned int src_shndx
,
3026 unsigned int dst_shndx
,
3027 Address dst_off
) const
3029 Powerpc_relobj
<size
, big_endian
>* ppc_object
3030 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
3031 if (size
== 64 && dst_shndx
== ppc_object
->opd_shndx())
3033 if (ppc_object
->opd_valid())
3035 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
3036 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
3040 // If we haven't run scan_opd_relocs, we must delay
3041 // processing this function descriptor reference.
3042 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
3047 // Add any special sections for this symbol to the gc work list.
3048 // For powerpc64, this adds the code section of a function
3051 template<int size
, bool big_endian
>
3053 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
3054 Symbol_table
* symtab
,
3059 Powerpc_relobj
<size
, big_endian
>* ppc_object
3060 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
3062 unsigned int shndx
= sym
->shndx(&is_ordinary
);
3063 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
3065 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
3066 Address dst_off
= gsym
->value();
3067 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
3068 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
3073 // Scan relocations for a section.
3075 template<int size
, bool big_endian
>
3077 Target_powerpc
<size
, big_endian
>::scan_relocs(
3078 Symbol_table
* symtab
,
3080 Sized_relobj_file
<size
, big_endian
>* object
,
3081 unsigned int data_shndx
,
3082 unsigned int sh_type
,
3083 const unsigned char* prelocs
,
3085 Output_section
* output_section
,
3086 bool needs_special_offset_handling
,
3087 size_t local_symbol_count
,
3088 const unsigned char* plocal_symbols
)
3090 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
3091 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
3093 if (sh_type
== elfcpp::SHT_REL
)
3095 gold_error(_("%s: unsupported REL reloc section"),
3096 object
->name().c_str());
3102 static Output_data_space
* sdata
;
3104 // Define _SDA_BASE_ at the start of the .sdata section.
3107 // layout->find_output_section(".sdata") == NULL
3108 sdata
= new Output_data_space(4, "** sdata");
3110 = layout
->add_output_section_data(".sdata", 0,
3112 | elfcpp::SHF_WRITE
,
3113 sdata
, ORDER_SMALL_DATA
, false);
3114 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
3115 Symbol_table::PREDEFINED
,
3116 os
, 32768, 0, elfcpp::STT_OBJECT
,
3117 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
3122 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
3131 needs_special_offset_handling
,
3136 // Finalize the sections.
3138 template<int size
, bool big_endian
>
3140 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
3142 const Input_objects
*,
3145 // Fill in some more dynamic tags.
3146 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3148 : this->plt_
->rel_plt());
3149 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3150 this->rela_dyn_
, true, size
== 32);
3152 Output_data_dynamic
* odyn
= layout
->dynamic_data();
3155 if (this->got_
!= NULL
)
3157 this->got_
->finalize_data_size();
3158 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
3159 this->got_
, this->got_
->g_o_t());
3164 if (this->glink_
!= NULL
)
3166 this->glink_
->finalize_data_size();
3167 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
3169 (this->glink_
->pltresolve()
3170 + this->glink_
->pltresolve_size
- 32));
3174 // Emit any relocs we saved in an attempt to avoid generating COPY
3176 if (this->copy_relocs_
.any_saved_relocs())
3177 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3180 // Return the value to use for a branch relocation.
3182 template<int size
, bool big_endian
>
3183 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3184 Target_powerpc
<size
, big_endian
>::symval_for_branch(
3186 const Sized_symbol
<size
>* gsym
,
3187 Powerpc_relobj
<size
, big_endian
>* object
,
3188 unsigned int *dest_shndx
)
3194 // If the symbol is defined in an opd section, ie. is a function
3195 // descriptor, use the function descriptor code entry address
3196 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
3198 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
3199 unsigned int shndx
= symobj
->opd_shndx();
3202 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
3203 gold_assert(opd_addr
!= invalid_address
);
3204 opd_addr
+= symobj
->output_section(shndx
)->address();
3205 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
3208 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
3209 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
3210 gold_assert(sec_addr
!= invalid_address
);
3211 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
3212 value
= sec_addr
+ sec_off
;
3217 // Perform a relocation.
3219 template<int size
, bool big_endian
>
3221 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
3222 const Relocate_info
<size
, big_endian
>* relinfo
,
3223 Target_powerpc
* target
,
3226 const elfcpp::Rela
<size
, big_endian
>& rela
,
3227 unsigned int r_type
,
3228 const Sized_symbol
<size
>* gsym
,
3229 const Symbol_value
<size
>* psymval
,
3230 unsigned char* view
,
3232 section_size_type view_size
)
3235 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
3236 || r_type
== elfcpp::R_PPC_PLTREL24
)
3238 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
3239 enum skip_tls last_tls
= this->call_tls_get_addr_
;
3240 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
3243 if (last_tls
== CALL_NOT_EXPECTED
)
3244 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3245 _("__tls_get_addr call lacks marker reloc"));
3246 else if (last_tls
== CALL_SKIP
)
3249 else if (last_tls
!= CALL_NOT_EXPECTED
)
3250 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3251 _("missing expected __tls_get_addr call"));
3253 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
3254 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
3255 Powerpc_relobj
<size
, big_endian
>* const object
3256 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
3258 bool has_plt_value
= false;
3260 && use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
3262 const Output_data_glink
<size
, big_endian
>* glink
3263 = target
->glink_section();
3264 unsigned int glink_index
= glink
->find_entry(gsym
, rela
, object
);
3265 value
= glink
->address() + glink_index
* glink
->glink_entry_size();
3266 has_plt_value
= true;
3269 if (r_type
== elfcpp::R_POWERPC_GOT16
3270 || r_type
== elfcpp::R_POWERPC_GOT16_LO
3271 || r_type
== elfcpp::R_POWERPC_GOT16_HI
3272 || r_type
== elfcpp::R_POWERPC_GOT16_HA
3273 || r_type
== elfcpp::R_PPC64_GOT16_DS
3274 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
3278 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3279 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3283 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3284 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3285 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3287 value
-= target
->got_section()->got_base_offset(object
);
3289 else if (r_type
== elfcpp::R_PPC64_TOC
)
3291 value
= (target
->got_section()->output_section()->address()
3292 + object
->toc_base_offset());
3294 else if (gsym
!= NULL
3295 && (r_type
== elfcpp::R_POWERPC_REL24
3296 || r_type
== elfcpp::R_PPC_PLTREL24
)
3301 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
3302 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
3303 bool can_plt_call
= false;
3304 if (rela
.get_r_offset() + 8 <= view_size
)
3306 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
3307 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
3310 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
3312 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
3313 can_plt_call
= true;
3318 // If we don't have a branch and link followed by a nop,
3319 // we can't go via the plt because there is no place to
3320 // put a toc restoring instruction.
3321 // Unless we know we won't be returning.
3322 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
3323 can_plt_call
= true;
3327 // This is not an error in one special case: A self
3328 // call. It isn't possible to cheaply verify we have
3329 // such a call so just check for a call to the same
3332 if (gsym
->source() == Symbol::FROM_OBJECT
3333 && gsym
->object() == object
)
3335 Address addend
= rela
.get_r_addend();
3336 unsigned int dest_shndx
;
3337 value
= psymval
->value(object
, addend
);
3338 value
= target
->symval_for_branch(value
, gsym
, object
,
3341 if (dest_shndx
== 0)
3342 dest_shndx
= gsym
->shndx(&is_ordinary
);
3343 ok
= dest_shndx
== relinfo
->data_shndx
;
3346 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3347 _("call lacks nop, can't restore toc; "
3348 "recompile with -fPIC"));
3352 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3353 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
3354 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
3355 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
3357 // First instruction of a global dynamic sequence, arg setup insn.
3358 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3359 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3360 enum Got_type got_type
= GOT_TYPE_STANDARD
;
3361 if (tls_type
== tls::TLSOPT_NONE
)
3362 got_type
= GOT_TYPE_TLSGD
;
3363 else if (tls_type
== tls::TLSOPT_TO_IE
)
3364 got_type
= GOT_TYPE_TPREL
;
3365 if (got_type
!= GOT_TYPE_STANDARD
)
3369 gold_assert(gsym
->has_got_offset(got_type
));
3370 value
= gsym
->got_offset(got_type
);
3374 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3375 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3376 value
= object
->local_got_offset(r_sym
, got_type
);
3378 value
-= target
->got_section()->got_base_offset(object
);
3380 if (tls_type
== tls::TLSOPT_TO_IE
)
3382 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3383 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3385 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3386 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3387 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
3389 insn
|= 32 << 26; // lwz
3391 insn
|= 58 << 26; // ld
3392 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3394 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
3395 - elfcpp::R_POWERPC_GOT_TLSGD16
);
3397 else if (tls_type
== tls::TLSOPT_TO_LE
)
3399 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
3400 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
3402 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3403 Insn insn
= addis_3_13
;
3406 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3407 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3408 value
= psymval
->value(object
, rela
.get_r_addend());
3412 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3414 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3415 r_type
= elfcpp::R_POWERPC_NONE
;
3419 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3420 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
3421 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
3422 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
3424 // First instruction of a local dynamic sequence, arg setup insn.
3425 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3426 if (tls_type
== tls::TLSOPT_NONE
)
3428 value
= target
->tlsld_got_offset();
3429 value
-= target
->got_section()->got_base_offset(object
);
3433 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3434 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
3435 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
3437 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3438 Insn insn
= addis_3_13
;
3441 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3442 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3447 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3449 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3450 r_type
= elfcpp::R_POWERPC_NONE
;
3454 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
3455 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
3456 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
3457 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
3459 // Accesses relative to a local dynamic sequence address,
3460 // no optimisation here.
3463 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
3464 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
3468 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3469 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
3470 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
3472 value
-= target
->got_section()->got_base_offset(object
);
3474 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3475 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
3476 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
3477 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
3479 // First instruction of initial exec sequence.
3480 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3481 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3482 if (tls_type
== tls::TLSOPT_NONE
)
3486 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
3487 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
3491 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3492 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
3493 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
3495 value
-= target
->got_section()->got_base_offset(object
);
3499 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
3500 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
3501 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
3503 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3504 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3505 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
3510 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3511 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
3512 value
= psymval
->value(object
, rela
.get_r_addend());
3516 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
3518 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3519 r_type
= elfcpp::R_POWERPC_NONE
;
3523 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
3524 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
3526 // Second instruction of a global dynamic sequence,
3527 // the __tls_get_addr call
3528 this->call_tls_get_addr_
= CALL_EXPECTED
;
3529 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3530 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
3531 if (tls_type
!= tls::TLSOPT_NONE
)
3533 if (tls_type
== tls::TLSOPT_TO_IE
)
3535 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3536 Insn insn
= add_3_3_13
;
3539 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3540 r_type
= elfcpp::R_POWERPC_NONE
;
3544 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3545 Insn insn
= addi_3_3
;
3546 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3547 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3548 view
+= 2 * big_endian
;
3549 value
= psymval
->value(object
, rela
.get_r_addend());
3551 this->call_tls_get_addr_
= CALL_SKIP
;
3554 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
3555 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
3557 // Second instruction of a local dynamic sequence,
3558 // the __tls_get_addr call
3559 this->call_tls_get_addr_
= CALL_EXPECTED
;
3560 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
3561 if (tls_type
== tls::TLSOPT_TO_LE
)
3563 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3564 Insn insn
= addi_3_3
;
3565 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3566 this->call_tls_get_addr_
= CALL_SKIP
;
3567 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3568 view
+= 2 * big_endian
;
3572 else if (r_type
== elfcpp::R_POWERPC_TLS
)
3574 // Second instruction of an initial exec sequence
3575 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
3576 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
3577 if (tls_type
== tls::TLSOPT_TO_LE
)
3579 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3580 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3581 unsigned int reg
= size
== 32 ? 2 : 13;
3582 insn
= at_tls_transform(insn
, reg
);
3583 gold_assert(insn
!= 0);
3584 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3585 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
3586 view
+= 2 * big_endian
;
3587 value
= psymval
->value(object
, rela
.get_r_addend());
3593 unsigned int dest_shndx
;
3594 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
3595 addend
= rela
.get_r_addend();
3596 if (size
== 64 || !has_plt_value
)
3597 value
= psymval
->value(object
, addend
);
3598 if (size
== 64 && is_branch_reloc(r_type
))
3599 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
3604 case elfcpp::R_PPC64_REL64
:
3605 case elfcpp::R_POWERPC_REL32
:
3606 case elfcpp::R_POWERPC_REL24
:
3607 case elfcpp::R_PPC_PLTREL24
:
3608 case elfcpp::R_PPC_LOCAL24PC
:
3609 case elfcpp::R_POWERPC_REL16
:
3610 case elfcpp::R_POWERPC_REL16_LO
:
3611 case elfcpp::R_POWERPC_REL16_HI
:
3612 case elfcpp::R_POWERPC_REL16_HA
:
3613 case elfcpp::R_POWERPC_REL14
:
3614 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3615 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3619 case elfcpp::R_PPC64_TOC16
:
3620 case elfcpp::R_PPC64_TOC16_LO
:
3621 case elfcpp::R_PPC64_TOC16_HI
:
3622 case elfcpp::R_PPC64_TOC16_HA
:
3623 case elfcpp::R_PPC64_TOC16_DS
:
3624 case elfcpp::R_PPC64_TOC16_LO_DS
:
3625 // Subtract the TOC base address.
3626 value
-= (target
->got_section()->output_section()->address()
3627 + object
->toc_base_offset());
3630 case elfcpp::R_POWERPC_SECTOFF
:
3631 case elfcpp::R_POWERPC_SECTOFF_LO
:
3632 case elfcpp::R_POWERPC_SECTOFF_HI
:
3633 case elfcpp::R_POWERPC_SECTOFF_HA
:
3634 case elfcpp::R_PPC64_SECTOFF_DS
:
3635 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3637 value
-= os
->address();
3640 case elfcpp::R_PPC64_TPREL16_DS
:
3641 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3643 // R_PPC_TLSGD and R_PPC_TLSLD
3645 case elfcpp::R_POWERPC_TPREL16
:
3646 case elfcpp::R_POWERPC_TPREL16_LO
:
3647 case elfcpp::R_POWERPC_TPREL16_HI
:
3648 case elfcpp::R_POWERPC_TPREL16_HA
:
3649 case elfcpp::R_POWERPC_TPREL
:
3650 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3651 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3652 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3653 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3654 // tls symbol values are relative to tls_segment()->vaddr()
3658 case elfcpp::R_PPC64_DTPREL16_DS
:
3659 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3660 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3661 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3662 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3663 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3665 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
3666 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
3668 case elfcpp::R_POWERPC_DTPREL16
:
3669 case elfcpp::R_POWERPC_DTPREL16_LO
:
3670 case elfcpp::R_POWERPC_DTPREL16_HI
:
3671 case elfcpp::R_POWERPC_DTPREL16_HA
:
3672 case elfcpp::R_POWERPC_DTPREL
:
3673 // tls symbol values are relative to tls_segment()->vaddr()
3674 value
-= dtp_offset
;
3681 Insn branch_bit
= 0;
3684 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3685 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3686 branch_bit
= 1 << 21;
3687 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3688 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3690 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
3691 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
3694 if (this->is_isa_v2
)
3696 // Set 'a' bit. This is 0b00010 in BO field for branch
3697 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
3698 // for branch on CTR insns (BO == 1a00t or 1a01t).
3699 if ((insn
& (0x14 << 21)) == (0x04 << 21))
3701 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
3708 // Invert 'y' bit if not the default.
3709 if (static_cast<Signed_address
>(value
) < 0)
3712 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
3720 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
3723 case elfcpp::R_POWERPC_ADDR32
:
3724 case elfcpp::R_POWERPC_UADDR32
:
3726 overflow
= Reloc::CHECK_BITFIELD
;
3729 case elfcpp::R_POWERPC_REL32
:
3731 overflow
= Reloc::CHECK_SIGNED
;
3734 case elfcpp::R_POWERPC_ADDR24
:
3735 case elfcpp::R_POWERPC_ADDR16
:
3736 case elfcpp::R_POWERPC_UADDR16
:
3737 case elfcpp::R_PPC64_ADDR16_DS
:
3738 case elfcpp::R_POWERPC_ADDR14
:
3739 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3740 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3741 overflow
= Reloc::CHECK_BITFIELD
;
3744 case elfcpp::R_POWERPC_REL24
:
3745 case elfcpp::R_PPC_PLTREL24
:
3746 case elfcpp::R_PPC_LOCAL24PC
:
3747 case elfcpp::R_POWERPC_REL16
:
3748 case elfcpp::R_PPC64_TOC16
:
3749 case elfcpp::R_POWERPC_GOT16
:
3750 case elfcpp::R_POWERPC_SECTOFF
:
3751 case elfcpp::R_POWERPC_TPREL16
:
3752 case elfcpp::R_POWERPC_DTPREL16
:
3753 case elfcpp::R_PPC64_TPREL16_DS
:
3754 case elfcpp::R_PPC64_DTPREL16_DS
:
3755 case elfcpp::R_PPC64_TOC16_DS
:
3756 case elfcpp::R_PPC64_GOT16_DS
:
3757 case elfcpp::R_PPC64_SECTOFF_DS
:
3758 case elfcpp::R_POWERPC_REL14
:
3759 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3760 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3761 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3762 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3763 case elfcpp::R_POWERPC_GOT_TPREL16
:
3764 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3765 overflow
= Reloc::CHECK_SIGNED
;
3769 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
3770 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
3773 case elfcpp::R_POWERPC_NONE
:
3774 case elfcpp::R_POWERPC_TLS
:
3775 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
3776 case elfcpp::R_POWERPC_GNU_VTENTRY
:
3777 case elfcpp::R_PPC_EMB_MRKREF
:
3780 case elfcpp::R_PPC64_ADDR64
:
3781 case elfcpp::R_PPC64_REL64
:
3782 case elfcpp::R_PPC64_TOC
:
3783 Reloc::addr64(view
, value
);
3786 case elfcpp::R_POWERPC_TPREL
:
3787 case elfcpp::R_POWERPC_DTPREL
:
3789 Reloc::addr64(view
, value
);
3791 status
= Reloc::addr32(view
, value
, overflow
);
3794 case elfcpp::R_PPC64_UADDR64
:
3795 Reloc::addr64_u(view
, value
);
3798 case elfcpp::R_POWERPC_ADDR32
:
3799 case elfcpp::R_POWERPC_REL32
:
3800 status
= Reloc::addr32(view
, value
, overflow
);
3803 case elfcpp::R_POWERPC_UADDR32
:
3804 status
= Reloc::addr32_u(view
, value
, overflow
);
3807 case elfcpp::R_POWERPC_ADDR24
:
3808 case elfcpp::R_POWERPC_REL24
:
3809 case elfcpp::R_PPC_PLTREL24
:
3810 case elfcpp::R_PPC_LOCAL24PC
:
3811 status
= Reloc::addr24(view
, value
, overflow
);
3814 case elfcpp::R_POWERPC_GOT_DTPREL16
:
3815 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
3818 status
= Reloc::addr16_ds(view
, value
, overflow
);
3821 case elfcpp::R_POWERPC_ADDR16
:
3822 case elfcpp::R_POWERPC_REL16
:
3823 case elfcpp::R_PPC64_TOC16
:
3824 case elfcpp::R_POWERPC_GOT16
:
3825 case elfcpp::R_POWERPC_SECTOFF
:
3826 case elfcpp::R_POWERPC_TPREL16
:
3827 case elfcpp::R_POWERPC_DTPREL16
:
3828 case elfcpp::R_POWERPC_GOT_TLSGD16
:
3829 case elfcpp::R_POWERPC_GOT_TLSLD16
:
3830 case elfcpp::R_POWERPC_GOT_TPREL16
:
3831 case elfcpp::R_POWERPC_ADDR16_LO
:
3832 case elfcpp::R_POWERPC_REL16_LO
:
3833 case elfcpp::R_PPC64_TOC16_LO
:
3834 case elfcpp::R_POWERPC_GOT16_LO
:
3835 case elfcpp::R_POWERPC_SECTOFF_LO
:
3836 case elfcpp::R_POWERPC_TPREL16_LO
:
3837 case elfcpp::R_POWERPC_DTPREL16_LO
:
3838 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
3839 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
3840 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
3841 status
= Reloc::addr16(view
, value
, overflow
);
3844 case elfcpp::R_POWERPC_UADDR16
:
3845 status
= Reloc::addr16_u(view
, value
, overflow
);
3848 case elfcpp::R_POWERPC_ADDR16_HI
:
3849 case elfcpp::R_POWERPC_REL16_HI
:
3850 case elfcpp::R_PPC64_TOC16_HI
:
3851 case elfcpp::R_POWERPC_GOT16_HI
:
3852 case elfcpp::R_POWERPC_SECTOFF_HI
:
3853 case elfcpp::R_POWERPC_TPREL16_HI
:
3854 case elfcpp::R_POWERPC_DTPREL16_HI
:
3855 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
3856 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
3857 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
3858 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
3859 Reloc::addr16_hi(view
, value
);
3862 case elfcpp::R_POWERPC_ADDR16_HA
:
3863 case elfcpp::R_POWERPC_REL16_HA
:
3864 case elfcpp::R_PPC64_TOC16_HA
:
3865 case elfcpp::R_POWERPC_GOT16_HA
:
3866 case elfcpp::R_POWERPC_SECTOFF_HA
:
3867 case elfcpp::R_POWERPC_TPREL16_HA
:
3868 case elfcpp::R_POWERPC_DTPREL16_HA
:
3869 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
3870 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
3871 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
3872 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
3873 Reloc::addr16_ha(view
, value
);
3876 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
3878 // R_PPC_EMB_NADDR16_LO
3880 case elfcpp::R_PPC64_ADDR16_HIGHER
:
3881 case elfcpp::R_PPC64_TPREL16_HIGHER
:
3882 Reloc::addr16_hi2(view
, value
);
3885 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
3887 // R_PPC_EMB_NADDR16_HI
3889 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
3890 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
3891 Reloc::addr16_ha2(view
, value
);
3894 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
3896 // R_PPC_EMB_NADDR16_HA
3898 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
3899 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
3900 Reloc::addr16_hi3(view
, value
);
3903 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
3907 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
3908 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
3909 Reloc::addr16_ha3(view
, value
);
3912 case elfcpp::R_PPC64_DTPREL16_DS
:
3913 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
3915 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
3917 case elfcpp::R_PPC64_TPREL16_DS
:
3918 case elfcpp::R_PPC64_TPREL16_LO_DS
:
3920 // R_PPC_TLSGD, R_PPC_TLSLD
3922 case elfcpp::R_PPC64_ADDR16_DS
:
3923 case elfcpp::R_PPC64_ADDR16_LO_DS
:
3924 case elfcpp::R_PPC64_TOC16_DS
:
3925 case elfcpp::R_PPC64_TOC16_LO_DS
:
3926 case elfcpp::R_PPC64_GOT16_DS
:
3927 case elfcpp::R_PPC64_GOT16_LO_DS
:
3928 case elfcpp::R_PPC64_SECTOFF_DS
:
3929 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
3930 status
= Reloc::addr16_ds(view
, value
, overflow
);
3933 case elfcpp::R_POWERPC_ADDR14
:
3934 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
3935 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
3936 case elfcpp::R_POWERPC_REL14
:
3937 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
3938 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
3939 status
= Reloc::addr14(view
, value
, overflow
);
3942 case elfcpp::R_POWERPC_COPY
:
3943 case elfcpp::R_POWERPC_GLOB_DAT
:
3944 case elfcpp::R_POWERPC_JMP_SLOT
:
3945 case elfcpp::R_POWERPC_RELATIVE
:
3946 case elfcpp::R_POWERPC_DTPMOD
:
3947 case elfcpp::R_PPC64_JMP_IREL
:
3948 case elfcpp::R_POWERPC_IRELATIVE
:
3949 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3950 _("unexpected reloc %u in object file"),
3954 case elfcpp::R_PPC_EMB_SDA21
:
3959 // R_PPC64_TOCSAVE. For the time being this can be ignored.
3963 case elfcpp::R_PPC_EMB_SDA2I16
:
3964 case elfcpp::R_PPC_EMB_SDA2REL
:
3967 // R_PPC64_TLSGD, R_PPC64_TLSLD
3970 case elfcpp::R_POWERPC_PLT32
:
3971 case elfcpp::R_POWERPC_PLTREL32
:
3972 case elfcpp::R_POWERPC_PLT16_LO
:
3973 case elfcpp::R_POWERPC_PLT16_HI
:
3974 case elfcpp::R_POWERPC_PLT16_HA
:
3975 case elfcpp::R_PPC_SDAREL16
:
3976 case elfcpp::R_POWERPC_ADDR30
:
3977 case elfcpp::R_PPC64_PLT64
:
3978 case elfcpp::R_PPC64_PLTREL64
:
3979 case elfcpp::R_PPC64_PLTGOT16
:
3980 case elfcpp::R_PPC64_PLTGOT16_LO
:
3981 case elfcpp::R_PPC64_PLTGOT16_HI
:
3982 case elfcpp::R_PPC64_PLTGOT16_HA
:
3983 case elfcpp::R_PPC64_PLT16_LO_DS
:
3984 case elfcpp::R_PPC64_PLTGOT16_DS
:
3985 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
3986 case elfcpp::R_PPC_EMB_RELSEC16
:
3987 case elfcpp::R_PPC_EMB_RELST_LO
:
3988 case elfcpp::R_PPC_EMB_RELST_HI
:
3989 case elfcpp::R_PPC_EMB_RELST_HA
:
3990 case elfcpp::R_PPC_EMB_BIT_FLD
:
3991 case elfcpp::R_PPC_EMB_RELSDA
:
3992 case elfcpp::R_PPC_TOC16
:
3995 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3996 _("unsupported reloc %u"),
4000 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
4001 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4002 _("relocation overflow"));
4007 // Relocate section data.
4009 template<int size
, bool big_endian
>
4011 Target_powerpc
<size
, big_endian
>::relocate_section(
4012 const Relocate_info
<size
, big_endian
>* relinfo
,
4013 unsigned int sh_type
,
4014 const unsigned char* prelocs
,
4016 Output_section
* output_section
,
4017 bool needs_special_offset_handling
,
4018 unsigned char* view
,
4020 section_size_type view_size
,
4021 const Reloc_symbol_changes
* reloc_symbol_changes
)
4023 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
4024 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
4026 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4028 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
4035 needs_special_offset_handling
,
4039 reloc_symbol_changes
);
4042 class Powerpc_scan_relocatable_reloc
4045 // Return the strategy to use for a local symbol which is not a
4046 // section symbol, given the relocation type.
4047 inline Relocatable_relocs::Reloc_strategy
4048 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
4050 if (r_type
== 0 && r_sym
== 0)
4051 return Relocatable_relocs::RELOC_DISCARD
;
4052 return Relocatable_relocs::RELOC_COPY
;
4055 // Return the strategy to use for a local symbol which is a section
4056 // symbol, given the relocation type.
4057 inline Relocatable_relocs::Reloc_strategy
4058 local_section_strategy(unsigned int, Relobj
*)
4060 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
4063 // Return the strategy to use for a global symbol, given the
4064 // relocation type, the object, and the symbol index.
4065 inline Relocatable_relocs::Reloc_strategy
4066 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
4068 if (r_type
== elfcpp::R_PPC_PLTREL24
)
4069 return Relocatable_relocs::RELOC_SPECIAL
;
4070 return Relocatable_relocs::RELOC_COPY
;
4074 // Scan the relocs during a relocatable link.
4076 template<int size
, bool big_endian
>
4078 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
4079 Symbol_table
* symtab
,
4081 Sized_relobj_file
<size
, big_endian
>* object
,
4082 unsigned int data_shndx
,
4083 unsigned int sh_type
,
4084 const unsigned char* prelocs
,
4086 Output_section
* output_section
,
4087 bool needs_special_offset_handling
,
4088 size_t local_symbol_count
,
4089 const unsigned char* plocal_symbols
,
4090 Relocatable_relocs
* rr
)
4092 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4094 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4095 Powerpc_scan_relocatable_reloc
>(
4103 needs_special_offset_handling
,
4109 // Emit relocations for a section.
4110 // This is a modified version of the function by the same name in
4111 // target-reloc.h. Using relocate_special_relocatable for
4112 // R_PPC_PLTREL24 would require duplication of the entire body of the
4113 // loop, so we may as well duplicate the whole thing.
4115 template<int size
, bool big_endian
>
4117 Target_powerpc
<size
, big_endian
>::relocate_relocs(
4118 const Relocate_info
<size
, big_endian
>* relinfo
,
4119 unsigned int sh_type
,
4120 const unsigned char* prelocs
,
4122 Output_section
* output_section
,
4123 off_t offset_in_output_section
,
4124 const Relocatable_relocs
* rr
,
4126 Address view_address
,
4128 unsigned char* reloc_view
,
4129 section_size_type reloc_view_size
)
4131 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4133 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
4135 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
4137 const int reloc_size
4138 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
4140 Powerpc_relobj
<size
, big_endian
>* const object
4141 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
4142 const unsigned int local_count
= object
->local_symbol_count();
4143 unsigned int got2_shndx
= object
->got2_shndx();
4144 Address got2_addend
= 0;
4145 if (got2_shndx
!= 0)
4147 got2_addend
= object
->get_output_section_offset(got2_shndx
);
4148 gold_assert(got2_addend
!= invalid_address
);
4151 unsigned char* pwrite
= reloc_view
;
4152 bool zap_next
= false;
4153 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
4155 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
4156 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
4159 Reltype
reloc(prelocs
);
4160 Reltype_write
reloc_write(pwrite
);
4162 Address offset
= reloc
.get_r_offset();
4163 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
4164 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
4165 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
4166 const unsigned int orig_r_sym
= r_sym
;
4167 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
4168 = reloc
.get_r_addend();
4169 const Symbol
* gsym
= NULL
;
4173 // We could arrange to discard these and other relocs for
4174 // tls optimised sequences in the strategy methods, but for
4175 // now do as BFD ld does.
4176 r_type
= elfcpp::R_POWERPC_NONE
;
4180 // Get the new symbol index.
4181 if (r_sym
< local_count
)
4185 case Relocatable_relocs::RELOC_COPY
:
4186 case Relocatable_relocs::RELOC_SPECIAL
:
4189 r_sym
= object
->symtab_index(r_sym
);
4190 gold_assert(r_sym
!= -1U);
4194 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
4196 // We are adjusting a section symbol. We need to find
4197 // the symbol table index of the section symbol for
4198 // the output section corresponding to input section
4199 // in which this symbol is defined.
4200 gold_assert(r_sym
< local_count
);
4202 unsigned int shndx
=
4203 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
4204 gold_assert(is_ordinary
);
4205 Output_section
* os
= object
->output_section(shndx
);
4206 gold_assert(os
!= NULL
);
4207 gold_assert(os
->needs_symtab_index());
4208 r_sym
= os
->symtab_index();
4218 gsym
= object
->global_symbol(r_sym
);
4219 gold_assert(gsym
!= NULL
);
4220 if (gsym
->is_forwarder())
4221 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
4223 gold_assert(gsym
->has_symtab_index());
4224 r_sym
= gsym
->symtab_index();
4227 // Get the new offset--the location in the output section where
4228 // this relocation should be applied.
4229 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4230 offset
+= offset_in_output_section
;
4233 section_offset_type sot_offset
=
4234 convert_types
<section_offset_type
, Address
>(offset
);
4235 section_offset_type new_sot_offset
=
4236 output_section
->output_offset(object
, relinfo
->data_shndx
,
4238 gold_assert(new_sot_offset
!= -1);
4239 offset
= new_sot_offset
;
4242 // In an object file, r_offset is an offset within the section.
4243 // In an executable or dynamic object, generated by
4244 // --emit-relocs, r_offset is an absolute address.
4245 if (!parameters
->options().relocatable())
4247 offset
+= view_address
;
4248 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
4249 offset
-= offset_in_output_section
;
4252 // Handle the reloc addend based on the strategy.
4253 if (strategy
== Relocatable_relocs::RELOC_COPY
)
4255 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
4257 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
4258 addend
= psymval
->value(object
, addend
);
4260 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
4262 if (addend
>= 32768)
4263 addend
+= got2_addend
;
4268 if (!parameters
->options().relocatable())
4270 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4271 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
4272 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
4273 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
4275 // First instruction of a global dynamic sequence,
4277 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4278 switch (this->optimize_tls_gd(final
))
4280 case tls::TLSOPT_TO_IE
:
4281 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
4282 - elfcpp::R_POWERPC_GOT_TLSGD16
);
4284 case tls::TLSOPT_TO_LE
:
4285 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
4286 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
4287 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4290 r_type
= elfcpp::R_POWERPC_NONE
;
4291 offset
-= 2 * big_endian
;
4298 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4299 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
4300 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
4301 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
4303 // First instruction of a local dynamic sequence,
4305 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4307 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
4308 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
4310 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4311 const Output_section
* os
= relinfo
->layout
->tls_segment()
4313 gold_assert(os
!= NULL
);
4314 gold_assert(os
->needs_symtab_index());
4315 r_sym
= os
->symtab_index();
4316 addend
= dtp_offset
;
4320 r_type
= elfcpp::R_POWERPC_NONE
;
4321 offset
-= 2 * big_endian
;
4325 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4326 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
4327 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
4328 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
4330 // First instruction of initial exec sequence.
4331 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4332 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4334 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
4335 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
4336 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
4339 r_type
= elfcpp::R_POWERPC_NONE
;
4340 offset
-= 2 * big_endian
;
4344 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4345 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4347 // Second instruction of a global dynamic sequence,
4348 // the __tls_get_addr call
4349 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4350 switch (this->optimize_tls_gd(final
))
4352 case tls::TLSOPT_TO_IE
:
4353 r_type
= elfcpp::R_POWERPC_NONE
;
4356 case tls::TLSOPT_TO_LE
:
4357 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4358 offset
+= 2 * big_endian
;
4365 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4366 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4368 // Second instruction of a local dynamic sequence,
4369 // the __tls_get_addr call
4370 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
4372 const Output_section
* os
= relinfo
->layout
->tls_segment()
4374 gold_assert(os
!= NULL
);
4375 gold_assert(os
->needs_symtab_index());
4376 r_sym
= os
->symtab_index();
4377 addend
= dtp_offset
;
4378 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4379 offset
+= 2 * big_endian
;
4383 else if (r_type
== elfcpp::R_POWERPC_TLS
)
4385 // Second instruction of an initial exec sequence
4386 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
4387 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
4389 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
4390 offset
+= 2 * big_endian
;
4395 reloc_write
.put_r_offset(offset
);
4396 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
4397 reloc_write
.put_r_addend(addend
);
4399 pwrite
+= reloc_size
;
4402 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
4403 == reloc_view_size
);
4406 // Return the value to use for a dynamic which requires special
4407 // treatment. This is how we support equality comparisons of function
4408 // pointers across shared library boundaries, as described in the
4409 // processor specific ABI supplement.
4411 template<int size
, bool big_endian
>
4413 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4417 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4418 return this->plt_section()->address() + gsym
->plt_offset();
4424 // The selector for powerpc object files.
4426 template<int size
, bool big_endian
>
4427 class Target_selector_powerpc
: public Target_selector
4430 Target_selector_powerpc()
4431 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4433 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
4434 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
4436 ? (big_endian
? "elf64ppc" : "elf64lppc")
4437 : (big_endian
? "elf32ppc" : "elf32lppc")))
4441 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4446 if (machine
!= elfcpp::EM_PPC64
)
4451 if (machine
!= elfcpp::EM_PPC
)
4459 return this->instantiate_target();
4463 do_instantiate_target()
4464 { return new Target_powerpc
<size
, big_endian
>(); }
4467 Target_selector_powerpc
<32, true> target_selector_ppc32
;
4468 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
4469 Target_selector_powerpc
<64, true> target_selector_ppc64
;
4470 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
4472 } // End anonymous namespace.