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.
28 #include "parameters.h"
35 #include "copy-relocs.h"
37 #include "target-reloc.h"
38 #include "target-select.h"
48 template<int size
, bool big_endian
>
49 class Output_data_plt_powerpc
;
51 template<int size
, bool big_endian
>
52 class Output_data_brlt_powerpc
;
54 template<int size
, bool big_endian
>
55 class Output_data_got_powerpc
;
57 template<int size
, bool big_endian
>
58 class Output_data_glink
;
60 template<int size
, bool big_endian
>
63 template<int size
, bool big_endian
>
64 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
67 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
68 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
69 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
71 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
72 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
73 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
74 special_(0), opd_valid_(false),
75 opd_ent_(), access_from_map_(), has14_(), stub_table_()
81 // The .got2 section shndx.
86 return this->special_
;
91 // The .opd section shndx.
98 return this->special_
;
101 // Init OPD entry arrays.
103 init_opd(size_t opd_size
)
105 size_t count
= this->opd_ent_ndx(opd_size
);
106 this->opd_ent_
.resize(count
);
109 // Return section and offset of function entry for .opd + R_OFF.
111 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
113 size_t ndx
= this->opd_ent_ndx(r_off
);
114 gold_assert(ndx
< this->opd_ent_
.size());
115 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
117 *value
= this->opd_ent_
[ndx
].off
;
118 return this->opd_ent_
[ndx
].shndx
;
121 // Set section and offset of function entry for .opd + R_OFF.
123 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
125 size_t ndx
= this->opd_ent_ndx(r_off
);
126 gold_assert(ndx
< this->opd_ent_
.size());
127 this->opd_ent_
[ndx
].shndx
= shndx
;
128 this->opd_ent_
[ndx
].off
= value
;
131 // Return discard flag for .opd + R_OFF.
133 get_opd_discard(Address r_off
) const
135 size_t ndx
= this->opd_ent_ndx(r_off
);
136 gold_assert(ndx
< this->opd_ent_
.size());
137 return this->opd_ent_
[ndx
].discard
;
140 // Set discard flag for .opd + R_OFF.
142 set_opd_discard(Address r_off
)
144 size_t ndx
= this->opd_ent_ndx(r_off
);
145 gold_assert(ndx
< this->opd_ent_
.size());
146 this->opd_ent_
[ndx
].discard
= true;
151 { return &this->access_from_map_
; }
153 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
154 // section at DST_OFF.
156 add_reference(Object
* src_obj
,
157 unsigned int src_indx
,
158 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
160 Section_id
src_id(src_obj
, src_indx
);
161 this->access_from_map_
[dst_off
].insert(src_id
);
164 // Add a reference to the code section specified by the .opd entry
167 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
169 size_t ndx
= this->opd_ent_ndx(dst_off
);
170 if (ndx
>= this->opd_ent_
.size())
171 this->opd_ent_
.resize(ndx
+ 1);
172 this->opd_ent_
[ndx
].gc_mark
= true;
176 process_gc_mark(Symbol_table
* symtab
)
178 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
179 if (this->opd_ent_
[i
].gc_mark
)
181 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
182 symtab
->gc()->worklist().push(Section_id(this, shndx
));
188 { return this->opd_valid_
; }
192 { this->opd_valid_
= true; }
194 // Examine .rela.opd to build info about function entry points.
196 scan_opd_relocs(size_t reloc_count
,
197 const unsigned char* prelocs
,
198 const unsigned char* plocal_syms
);
200 // Perform the Sized_relobj_file method, then set up opd info from
203 do_read_relocs(Read_relocs_data
*);
206 do_find_special_sections(Read_symbols_data
* sd
);
208 // Adjust this local symbol value. Return false if the symbol
209 // should be discarded from the output file.
211 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
213 if (size
== 64 && this->opd_shndx() != 0)
216 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
218 if (this->get_opd_discard(lv
->input_value()))
224 // Return offset in output GOT section that this object will use
225 // as a TOC pointer. Won't be just a constant with multi-toc support.
227 toc_base_offset() const
231 set_has_14bit_branch(unsigned int shndx
)
233 if (shndx
>= this->has14_
.size())
234 this->has14_
.resize(shndx
+ 1);
235 this->has14_
[shndx
] = true;
239 has_14bit_branch(unsigned int shndx
) const
240 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
243 set_stub_table(unsigned int shndx
, Stub_table
<size
, big_endian
>* stub_table
)
245 if (shndx
>= this->stub_table_
.size())
246 this->stub_table_
.resize(shndx
+ 1);
247 this->stub_table_
[shndx
] = stub_table
;
250 Stub_table
<size
, big_endian
>*
251 stub_table(unsigned int shndx
)
253 if (shndx
< this->stub_table_
.size())
254 return this->stub_table_
[shndx
];
267 // Return index into opd_ent_ array for .opd entry at OFF.
268 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
269 // apart when the language doesn't use the last 8-byte word, the
270 // environment pointer. Thus dividing the entry section offset by
271 // 16 will give an index into opd_ent_ that works for either layout
272 // of .opd. (It leaves some elements of the vector unused when .opd
273 // entries are spaced 24 bytes apart, but we don't know the spacing
274 // until relocations are processed, and in any case it is possible
275 // for an object to have some entries spaced 16 bytes apart and
276 // others 24 bytes apart.)
278 opd_ent_ndx(size_t off
) const
281 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
282 unsigned int special_
;
284 // Set at the start of gc_process_relocs, when we know opd_ent_
285 // vector is valid. The flag could be made atomic and set in
286 // do_read_relocs with memory_order_release and then tested with
287 // memory_order_acquire, potentially resulting in fewer entries in
291 // The first 8-byte word of an OPD entry gives the address of the
292 // entry point of the function. Relocatable object files have a
293 // relocation on this word. The following vector records the
294 // section and offset specified by these relocations.
295 std::vector
<Opd_ent
> opd_ent_
;
297 // References made to this object's .opd section when running
298 // gc_process_relocs for another object, before the opd_ent_ vector
299 // is valid for this object.
300 Access_from access_from_map_
;
302 // Whether input section has a 14-bit branch reloc.
303 std::vector
<bool> has14_
;
305 // The stub table to use for a given input section.
306 std::vector
<Stub_table
<size
, big_endian
>*> stub_table_
;
309 template<int size
, bool big_endian
>
310 class Target_powerpc
: public Sized_target
<size
, big_endian
>
314 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
315 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
316 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
317 static const Address invalid_address
= static_cast<Address
>(0) - 1;
318 // Offset of tp and dtp pointers from start of TLS block.
319 static const Address tp_offset
= 0x7000;
320 static const Address dtp_offset
= 0x8000;
323 : Sized_target
<size
, big_endian
>(&powerpc_info
),
324 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
325 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
326 dynbss_(NULL
), tlsld_got_offset_(-1U),
327 stub_tables_(), branch_lookup_table_(), branch_info_(),
328 plt_thread_safe_(false)
332 // Process the relocations to determine unreferenced sections for
333 // garbage collection.
335 gc_process_relocs(Symbol_table
* symtab
,
337 Sized_relobj_file
<size
, big_endian
>* object
,
338 unsigned int data_shndx
,
339 unsigned int sh_type
,
340 const unsigned char* prelocs
,
342 Output_section
* output_section
,
343 bool needs_special_offset_handling
,
344 size_t local_symbol_count
,
345 const unsigned char* plocal_symbols
);
347 // Scan the relocations to look for symbol adjustments.
349 scan_relocs(Symbol_table
* symtab
,
351 Sized_relobj_file
<size
, big_endian
>* object
,
352 unsigned int data_shndx
,
353 unsigned int sh_type
,
354 const unsigned char* prelocs
,
356 Output_section
* output_section
,
357 bool needs_special_offset_handling
,
358 size_t local_symbol_count
,
359 const unsigned char* plocal_symbols
);
361 // Map input .toc section to output .got section.
363 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
365 if (size
== 64 && strcmp(name
, ".toc") == 0)
373 // Provide linker defined save/restore functions.
375 define_save_restore_funcs(Layout
*, Symbol_table
*);
377 // No stubs unless a final link.
380 { return !parameters
->options().relocatable(); }
383 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
385 // Stash info about branches, for stub generation.
387 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
388 unsigned int data_shndx
, Address r_offset
,
389 unsigned int r_type
, unsigned int r_sym
, Address addend
)
391 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
392 this->branch_info_
.push_back(info
);
393 if (r_type
== elfcpp::R_POWERPC_REL14
394 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
395 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
396 ppc_object
->set_has_14bit_branch(data_shndx
);
399 Stub_table
<size
, big_endian
>*
403 do_define_standard_symbols(Symbol_table
*, Layout
*);
405 // Finalize the sections.
407 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
409 // Return the value to use for a dynamic which requires special
412 do_dynsym_value(const Symbol
*) const;
414 // Return the PLT address to use for a local symbol.
416 do_plt_address_for_local(const Relobj
*, unsigned int) const;
418 // Return the PLT address to use for a global symbol.
420 do_plt_address_for_global(const Symbol
*) const;
422 // Return the offset to use for the GOT_INDX'th got entry which is
423 // for a local tls symbol specified by OBJECT, SYMNDX.
425 do_tls_offset_for_local(const Relobj
* object
,
427 unsigned int got_indx
) const;
429 // Return the offset to use for the GOT_INDX'th got entry which is
430 // for global tls symbol GSYM.
432 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
434 // Relocate a section.
436 relocate_section(const Relocate_info
<size
, big_endian
>*,
437 unsigned int sh_type
,
438 const unsigned char* prelocs
,
440 Output_section
* output_section
,
441 bool needs_special_offset_handling
,
443 Address view_address
,
444 section_size_type view_size
,
445 const Reloc_symbol_changes
*);
447 // Scan the relocs during a relocatable link.
449 scan_relocatable_relocs(Symbol_table
* symtab
,
451 Sized_relobj_file
<size
, big_endian
>* object
,
452 unsigned int data_shndx
,
453 unsigned int sh_type
,
454 const unsigned char* prelocs
,
456 Output_section
* output_section
,
457 bool needs_special_offset_handling
,
458 size_t local_symbol_count
,
459 const unsigned char* plocal_symbols
,
460 Relocatable_relocs
*);
462 // Emit relocations for a section.
464 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
465 unsigned int sh_type
,
466 const unsigned char* prelocs
,
468 Output_section
* output_section
,
469 typename
elfcpp::Elf_types
<size
>::Elf_Off
470 offset_in_output_section
,
471 const Relocatable_relocs
*,
473 Address view_address
,
475 unsigned char* reloc_view
,
476 section_size_type reloc_view_size
);
478 // Return whether SYM is defined by the ABI.
480 do_is_defined_by_abi(const Symbol
* sym
) const
482 return strcmp(sym
->name(), "__tls_get_addr") == 0;
485 // Return the size of the GOT section.
489 gold_assert(this->got_
!= NULL
);
490 return this->got_
->data_size();
493 // Get the PLT section.
494 const Output_data_plt_powerpc
<size
, big_endian
>*
497 gold_assert(this->plt_
!= NULL
);
501 // Get the IPLT section.
502 const Output_data_plt_powerpc
<size
, big_endian
>*
505 gold_assert(this->iplt_
!= NULL
);
509 // Get the .glink section.
510 const Output_data_glink
<size
, big_endian
>*
511 glink_section() const
513 gold_assert(this->glink_
!= NULL
);
517 // Get the GOT section.
518 const Output_data_got_powerpc
<size
, big_endian
>*
521 gold_assert(this->got_
!= NULL
);
525 // Get the GOT section, creating it if necessary.
526 Output_data_got_powerpc
<size
, big_endian
>*
527 got_section(Symbol_table
*, Layout
*);
530 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
531 const elfcpp::Ehdr
<size
, big_endian
>&);
533 // Return the number of entries in the GOT.
535 got_entry_count() const
537 if (this->got_
== NULL
)
539 return this->got_size() / (size
/ 8);
542 // Return the number of entries in the PLT.
544 plt_entry_count() const;
546 // Return the offset of the first non-reserved PLT entry.
548 first_plt_entry_offset() const;
550 // Return the size of each PLT entry.
552 plt_entry_size() const;
554 // Add any special sections for this symbol to the gc work list.
555 // For powerpc64, this adds the code section of a function
558 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
560 // Handle target specific gc actions when adding a gc reference from
561 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
562 // and DST_OFF. For powerpc64, this adds a referenc to the code
563 // section of a function descriptor.
565 do_gc_add_reference(Symbol_table
* symtab
,
567 unsigned int src_shndx
,
569 unsigned int dst_shndx
,
570 Address dst_off
) const;
572 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
575 { return this->stub_tables_
; }
577 const Output_data_brlt_powerpc
<size
, big_endian
>*
579 { return this->brlt_section_
; }
582 add_branch_lookup_table(Address to
)
584 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
585 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
589 find_branch_lookup_table(Address to
)
591 typename
Branch_lookup_table::const_iterator p
592 = this->branch_lookup_table_
.find(to
);
593 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
597 write_branch_lookup_table(unsigned char *oview
)
599 for (typename
Branch_lookup_table::const_iterator p
600 = this->branch_lookup_table_
.begin();
601 p
!= this->branch_lookup_table_
.end();
604 elfcpp::Swap
<32, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
609 plt_thread_safe() const
610 { return this->plt_thread_safe_
; }
614 // The class which scans relocations.
618 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
621 : issued_non_pic_error_(false)
625 get_reference_flags(unsigned int r_type
);
628 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
629 Sized_relobj_file
<size
, big_endian
>* object
,
630 unsigned int data_shndx
,
631 Output_section
* output_section
,
632 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
633 const elfcpp::Sym
<size
, big_endian
>& lsym
,
637 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
638 Sized_relobj_file
<size
, big_endian
>* object
,
639 unsigned int data_shndx
,
640 Output_section
* output_section
,
641 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
645 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
647 Sized_relobj_file
<size
, big_endian
>* ,
650 const elfcpp::Rela
<size
, big_endian
>& ,
652 const elfcpp::Sym
<size
, big_endian
>&)
656 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
658 Sized_relobj_file
<size
, big_endian
>* ,
661 const elfcpp::Rela
<size
,
663 unsigned int , Symbol
*)
668 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
669 unsigned int r_type
);
672 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
673 unsigned int r_type
, Symbol
*);
676 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
677 Target_powerpc
* target
);
680 check_non_pic(Relobj
*, unsigned int r_type
);
683 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>* object
,
684 unsigned int r_type
);
686 // Whether we have issued an error about a non-PIC compilation.
687 bool issued_non_pic_error_
;
691 symval_for_branch(Address value
, const Sized_symbol
<size
>* gsym
,
692 Powerpc_relobj
<size
, big_endian
>* object
,
693 unsigned int *dest_shndx
);
695 // The class which implements relocation.
699 // Use 'at' branch hints when true, 'y' when false.
700 // FIXME maybe: set this with an option.
701 static const bool is_isa_v2
= true;
705 CALL_NOT_EXPECTED
= 0,
711 : call_tls_get_addr_(CALL_NOT_EXPECTED
)
716 if (this->call_tls_get_addr_
!= CALL_NOT_EXPECTED
)
718 // FIXME: This needs to specify the location somehow.
719 gold_error(_("missing expected __tls_get_addr call"));
723 // Do a relocation. Return false if the caller should not issue
724 // any warnings about this relocation.
726 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
727 Output_section
*, size_t relnum
,
728 const elfcpp::Rela
<size
, big_endian
>&,
729 unsigned int r_type
, const Sized_symbol
<size
>*,
730 const Symbol_value
<size
>*,
732 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
735 // This is set if we should skip the next reloc, which should be a
736 // call to __tls_get_addr.
737 enum skip_tls call_tls_get_addr_
;
740 class Relocate_comdat_behavior
743 // Decide what the linker should do for relocations that refer to
744 // discarded comdat sections.
745 inline Comdat_behavior
746 get(const char* name
)
748 gold::Default_comdat_behavior default_behavior
;
749 Comdat_behavior ret
= default_behavior
.get(name
);
750 if (ret
== CB_WARNING
)
753 && (strcmp(name
, ".fixup") == 0
754 || strcmp(name
, ".got2") == 0))
757 && (strcmp(name
, ".opd") == 0
758 || strcmp(name
, ".toc") == 0
759 || strcmp(name
, ".toc1") == 0))
766 // A class which returns the size required for a relocation type,
767 // used while scanning relocs during a relocatable link.
768 class Relocatable_size_for_reloc
772 get_size_for_reloc(unsigned int, Relobj
*)
779 // Optimize the TLS relocation type based on what we know about the
780 // symbol. IS_FINAL is true if the final address of this symbol is
781 // known at link time.
783 tls::Tls_optimization
784 optimize_tls_gd(bool is_final
)
786 // If we are generating a shared library, then we can't do anything
788 if (parameters
->options().shared())
789 return tls::TLSOPT_NONE
;
792 return tls::TLSOPT_TO_IE
;
793 return tls::TLSOPT_TO_LE
;
796 tls::Tls_optimization
799 if (parameters
->options().shared())
800 return tls::TLSOPT_NONE
;
802 return tls::TLSOPT_TO_LE
;
805 tls::Tls_optimization
806 optimize_tls_ie(bool is_final
)
808 if (!is_final
|| parameters
->options().shared())
809 return tls::TLSOPT_NONE
;
811 return tls::TLSOPT_TO_LE
;
816 make_glink_section(Layout
*);
818 // Create the PLT section.
820 make_plt_section(Symbol_table
*, Layout
*);
823 make_iplt_section(Symbol_table
*, Layout
*);
826 make_brlt_section(Layout
*);
828 // Create a PLT entry for a global symbol.
830 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
832 // Create a PLT entry for a local IFUNC symbol.
834 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
835 Sized_relobj_file
<size
, big_endian
>*,
839 // Create a GOT entry for local dynamic __tls_get_addr.
841 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
842 Sized_relobj_file
<size
, big_endian
>* object
);
845 tlsld_got_offset() const
847 return this->tlsld_got_offset_
;
850 // Get the dynamic reloc section, creating it if necessary.
852 rela_dyn_section(Layout
*);
854 // Copy a relocation against a global symbol.
856 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
857 Sized_relobj_file
<size
, big_endian
>* object
,
858 unsigned int shndx
, Output_section
* output_section
,
859 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
861 this->copy_relocs_
.copy_reloc(symtab
, layout
,
862 symtab
->get_sized_symbol
<size
>(sym
),
863 object
, shndx
, output_section
,
864 reloc
, this->rela_dyn_section(layout
));
867 // Look over all the input sections, deciding where to place stub.
869 group_sections(Layout
*, const Task
*);
871 // Sort output sections by address.
875 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
876 { return sec1
->address() < sec2
->address(); }
882 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
883 unsigned int data_shndx
,
888 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
889 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
895 // If this branch needs a plt call stub, or a long branch stub, make one.
897 make_stub(Stub_table
<size
, big_endian
>*,
898 Stub_table
<size
, big_endian
>*,
899 Symbol_table
*) const;
902 // The branch location..
903 Powerpc_relobj
<size
, big_endian
>* object_
;
906 // ..and the branch type and destination.
907 unsigned int r_type_
;
912 // Information about this specific target which we pass to the
913 // general Target structure.
914 static Target::Target_info powerpc_info
;
916 // The types of GOT entries needed for this platform.
917 // These values are exposed to the ABI in an incremental link.
918 // Do not renumber existing values without changing the version
919 // number of the .gnu_incremental_inputs section.
923 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
924 GOT_TYPE_DTPREL
, // entry for @got@dtprel
925 GOT_TYPE_TPREL
// entry for @got@tprel
929 Output_data_got_powerpc
<size
, big_endian
>* got_
;
931 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
933 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
934 // Section holding long branch destinations.
935 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
936 // The .glink section.
937 Output_data_glink
<size
, big_endian
>* glink_
;
938 // The dynamic reloc section.
939 Reloc_section
* rela_dyn_
;
940 // Relocs saved to avoid a COPY reloc.
941 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
942 // Space for variables copied with a COPY reloc.
943 Output_data_space
* dynbss_
;
944 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
945 unsigned int tlsld_got_offset_
;
947 Stub_tables stub_tables_
;
948 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
949 Branch_lookup_table branch_lookup_table_
;
951 typedef std::vector
<Branch_info
> Branches
;
952 Branches branch_info_
;
954 bool plt_thread_safe_
;
958 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
961 true, // is_big_endian
962 elfcpp::EM_PPC
, // machine_code
963 false, // has_make_symbol
964 false, // has_resolve
965 false, // has_code_fill
966 true, // is_default_stack_executable
967 false, // can_icf_inline_merge_sections
969 "/usr/lib/ld.so.1", // dynamic_linker
970 0x10000000, // default_text_segment_address
971 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
972 4 * 1024, // common_pagesize (overridable by -z common-page-size)
973 false, // isolate_execinstr
975 elfcpp::SHN_UNDEF
, // small_common_shndx
976 elfcpp::SHN_UNDEF
, // large_common_shndx
977 0, // small_common_section_flags
978 0, // large_common_section_flags
979 NULL
, // attributes_section
980 NULL
// attributes_vendor
984 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
987 false, // is_big_endian
988 elfcpp::EM_PPC
, // machine_code
989 false, // has_make_symbol
990 false, // has_resolve
991 false, // has_code_fill
992 true, // is_default_stack_executable
993 false, // can_icf_inline_merge_sections
995 "/usr/lib/ld.so.1", // dynamic_linker
996 0x10000000, // default_text_segment_address
997 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
998 4 * 1024, // common_pagesize (overridable by -z common-page-size)
999 false, // isolate_execinstr
1001 elfcpp::SHN_UNDEF
, // small_common_shndx
1002 elfcpp::SHN_UNDEF
, // large_common_shndx
1003 0, // small_common_section_flags
1004 0, // large_common_section_flags
1005 NULL
, // attributes_section
1006 NULL
// attributes_vendor
1010 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1013 true, // is_big_endian
1014 elfcpp::EM_PPC64
, // machine_code
1015 false, // has_make_symbol
1016 false, // has_resolve
1017 false, // has_code_fill
1018 true, // is_default_stack_executable
1019 false, // can_icf_inline_merge_sections
1021 "/usr/lib/ld.so.1", // dynamic_linker
1022 0x10000000, // default_text_segment_address
1023 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1024 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1025 false, // isolate_execinstr
1027 elfcpp::SHN_UNDEF
, // small_common_shndx
1028 elfcpp::SHN_UNDEF
, // large_common_shndx
1029 0, // small_common_section_flags
1030 0, // large_common_section_flags
1031 NULL
, // attributes_section
1032 NULL
// attributes_vendor
1036 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1039 false, // is_big_endian
1040 elfcpp::EM_PPC64
, // machine_code
1041 false, // has_make_symbol
1042 false, // has_resolve
1043 false, // has_code_fill
1044 true, // is_default_stack_executable
1045 false, // can_icf_inline_merge_sections
1047 "/usr/lib/ld.so.1", // dynamic_linker
1048 0x10000000, // default_text_segment_address
1049 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1050 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1051 false, // isolate_execinstr
1053 elfcpp::SHN_UNDEF
, // small_common_shndx
1054 elfcpp::SHN_UNDEF
, // large_common_shndx
1055 0, // small_common_section_flags
1056 0, // large_common_section_flags
1057 NULL
, // attributes_section
1058 NULL
// attributes_vendor
1062 is_branch_reloc(unsigned int r_type
)
1064 return (r_type
== elfcpp::R_POWERPC_REL24
1065 || r_type
== elfcpp::R_PPC_PLTREL24
1066 || r_type
== elfcpp::R_PPC_LOCAL24PC
1067 || r_type
== elfcpp::R_POWERPC_REL14
1068 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1069 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1070 || r_type
== elfcpp::R_POWERPC_ADDR24
1071 || r_type
== elfcpp::R_POWERPC_ADDR14
1072 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1073 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1076 // If INSN is an opcode that may be used with an @tls operand, return
1077 // the transformed insn for TLS optimisation, otherwise return 0. If
1078 // REG is non-zero only match an insn with RB or RA equal to REG.
1080 at_tls_transform(uint32_t insn
, unsigned int reg
)
1082 if ((insn
& (0x3f << 26)) != 31 << 26)
1086 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1087 rtra
= insn
& ((1 << 26) - (1 << 16));
1088 else if (((insn
>> 16) & 0x1f) == reg
)
1089 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1093 if ((insn
& (0x3ff << 1)) == 266 << 1)
1096 else if ((insn
& (0x1f << 1)) == 23 << 1
1097 && ((insn
& (0x1f << 6)) < 14 << 6
1098 || ((insn
& (0x1f << 6)) >= 16 << 6
1099 && (insn
& (0x1f << 6)) < 24 << 6)))
1100 // load and store indexed -> dform
1101 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1102 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1103 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1104 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1105 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1107 insn
= (58 << 26) | 2;
1114 // Modified version of symtab.h class Symbol member
1115 // Given a direct absolute or pc-relative static relocation against
1116 // the global symbol, this function returns whether a dynamic relocation
1121 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
1123 // No dynamic relocations in a static link!
1124 if (parameters
->doing_static_link())
1127 // A reference to an undefined symbol from an executable should be
1128 // statically resolved to 0, and does not need a dynamic relocation.
1129 // This matches gnu ld behavior.
1130 if (gsym
->is_undefined() && !parameters
->options().shared())
1133 // A reference to an absolute symbol does not need a dynamic relocation.
1134 if (gsym
->is_absolute())
1137 // An absolute reference within a position-independent output file
1138 // will need a dynamic relocation.
1139 if ((flags
& Symbol::ABSOLUTE_REF
)
1140 && parameters
->options().output_is_position_independent())
1143 // A function call that can branch to a local PLT entry does not need
1144 // a dynamic relocation.
1145 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
1148 // A reference to any PLT entry in a non-position-independent executable
1149 // does not need a dynamic relocation.
1150 // Except due to having function descriptors on powerpc64 we don't define
1151 // functions to their plt code in an executable, so this doesn't apply.
1153 && !parameters
->options().output_is_position_independent()
1154 && gsym
->has_plt_offset())
1157 // A reference to a symbol defined in a dynamic object or to a
1158 // symbol that is preemptible will need a dynamic relocation.
1159 if (gsym
->is_from_dynobj()
1160 || gsym
->is_undefined()
1161 || gsym
->is_preemptible())
1164 // For all other cases, return FALSE.
1168 // Modified version of symtab.h class Symbol member
1169 // Whether we should use the PLT offset associated with a symbol for
1170 // a relocation. FLAGS is a set of Reference_flags.
1174 use_plt_offset(const Symbol
* gsym
, int flags
)
1176 // If the symbol doesn't have a PLT offset, then naturally we
1177 // don't want to use it.
1178 if (!gsym
->has_plt_offset())
1181 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
1182 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
1185 // If we are going to generate a dynamic relocation, then we will
1186 // wind up using that, so no need to use the PLT entry.
1187 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
1190 // If the symbol is from a dynamic object, we need to use the PLT
1192 if (gsym
->is_from_dynobj())
1195 // If we are generating a shared object, and this symbol is
1196 // undefined or preemptible, we need to use the PLT entry.
1197 if (parameters
->options().shared()
1198 && (gsym
->is_undefined() || gsym
->is_preemptible()))
1201 // If this is a call to a weak undefined symbol, we need to use
1202 // the PLT entry; the symbol may be defined by a library loaded
1204 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
1207 // Otherwise we can use the regular definition.
1211 template<int size
, bool big_endian
>
1212 class Powerpc_relocate_functions
1229 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1230 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1232 template<int valsize
>
1234 has_overflow_signed(Address value
)
1236 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1237 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1238 limit
<<= ((valsize
- 1) >> 1);
1239 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1240 return value
+ limit
> (limit
<< 1) - 1;
1243 template<int valsize
>
1245 has_overflow_bitfield(Address value
)
1247 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1248 limit
<<= ((valsize
- 1) >> 1);
1249 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1250 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
1253 template<int valsize
>
1254 static inline Status
1255 overflowed(Address value
, Overflow_check overflow
)
1257 if (overflow
== CHECK_SIGNED
)
1259 if (has_overflow_signed
<valsize
>(value
))
1260 return STATUS_OVERFLOW
;
1262 else if (overflow
== CHECK_BITFIELD
)
1264 if (has_overflow_bitfield
<valsize
>(value
))
1265 return STATUS_OVERFLOW
;
1270 // Do a simple RELA relocation
1271 template<int valsize
>
1272 static inline Status
1273 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1275 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1276 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1277 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1278 return overflowed
<valsize
>(value
, overflow
);
1281 template<int valsize
>
1282 static inline Status
1283 rela(unsigned char* view
,
1284 unsigned int right_shift
,
1285 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1287 Overflow_check overflow
)
1289 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1290 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1291 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1292 Valtype reloc
= value
>> right_shift
;
1295 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1296 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1299 // Do a simple RELA relocation, unaligned.
1300 template<int valsize
>
1301 static inline Status
1302 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1304 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1305 return overflowed
<valsize
>(value
, overflow
);
1308 template<int valsize
>
1309 static inline Status
1310 rela_ua(unsigned char* view
,
1311 unsigned int right_shift
,
1312 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1314 Overflow_check overflow
)
1316 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1318 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1319 Valtype reloc
= value
>> right_shift
;
1322 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1323 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1327 // R_PPC64_ADDR64: (Symbol + Addend)
1329 addr64(unsigned char* view
, Address value
)
1330 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1332 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1334 addr64_u(unsigned char* view
, Address value
)
1335 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1337 // R_POWERPC_ADDR32: (Symbol + Addend)
1338 static inline Status
1339 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1340 { return This::template rela
<32>(view
, value
, overflow
); }
1342 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1343 static inline Status
1344 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1345 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1347 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1348 static inline Status
1349 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1351 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1352 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1353 stat
= STATUS_OVERFLOW
;
1357 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1358 static inline Status
1359 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1360 { return This::template rela
<16>(view
, value
, overflow
); }
1362 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1363 static inline Status
1364 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1365 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1367 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1368 static inline Status
1369 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1371 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1372 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1373 stat
= STATUS_OVERFLOW
;
1377 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1379 addr16_hi(unsigned char* view
, Address value
)
1380 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1382 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1384 addr16_ha(unsigned char* view
, Address value
)
1385 { This::addr16_hi(view
, value
+ 0x8000); }
1387 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1389 addr16_hi2(unsigned char* view
, Address value
)
1390 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1392 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1394 addr16_ha2(unsigned char* view
, Address value
)
1395 { This::addr16_hi2(view
, value
+ 0x8000); }
1397 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1399 addr16_hi3(unsigned char* view
, Address value
)
1400 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1402 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1404 addr16_ha3(unsigned char* view
, Address value
)
1405 { This::addr16_hi3(view
, value
+ 0x8000); }
1407 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1408 static inline Status
1409 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1411 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1412 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1413 stat
= STATUS_OVERFLOW
;
1418 // Stash away the index of .got2 or .opd in a relocatable object, if
1419 // such a section exists.
1421 template<int size
, bool big_endian
>
1423 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1424 Read_symbols_data
* sd
)
1426 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1427 const unsigned char* namesu
= sd
->section_names
->data();
1428 const char* names
= reinterpret_cast<const char*>(namesu
);
1429 section_size_type names_size
= sd
->section_names_size
;
1430 const unsigned char* s
;
1432 s
= this->find_shdr(pshdrs
, size
== 32 ? ".got2" : ".opd",
1433 names
, names_size
, NULL
);
1436 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1437 this->special_
= ndx
;
1439 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1442 // Examine .rela.opd to build info about function entry points.
1444 template<int size
, bool big_endian
>
1446 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1448 const unsigned char* prelocs
,
1449 const unsigned char* plocal_syms
)
1453 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1455 const int reloc_size
1456 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1457 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1458 Address expected_off
= 0;
1459 bool regular
= true;
1460 unsigned int opd_ent_size
= 0;
1462 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1464 Reltype
reloc(prelocs
);
1465 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1466 = reloc
.get_r_info();
1467 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1468 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1470 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1471 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1474 if (r_sym
< this->local_symbol_count())
1476 typename
elfcpp::Sym
<size
, big_endian
>
1477 lsym(plocal_syms
+ r_sym
* sym_size
);
1478 shndx
= lsym
.get_st_shndx();
1479 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1480 value
= lsym
.get_st_value();
1483 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1485 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1486 value
+ reloc
.get_r_addend());
1489 expected_off
= reloc
.get_r_offset();
1490 opd_ent_size
= expected_off
;
1492 else if (expected_off
!= reloc
.get_r_offset())
1494 expected_off
+= opd_ent_size
;
1496 else if (r_type
== elfcpp::R_PPC64_TOC
)
1498 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1503 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1504 this->name().c_str(), r_type
);
1508 if (reloc_count
<= 2)
1509 opd_ent_size
= this->section_size(this->opd_shndx());
1510 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1514 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1515 this->name().c_str());
1521 template<int size
, bool big_endian
>
1523 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1525 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1528 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1529 p
!= rd
->relocs
.end();
1532 if (p
->data_shndx
== this->opd_shndx())
1534 uint64_t opd_size
= this->section_size(this->opd_shndx());
1535 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1538 this->init_opd(opd_size
);
1539 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1540 rd
->local_symbols
->data());
1548 // Set up some symbols.
1550 template<int size
, bool big_endian
>
1552 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
1553 Symbol_table
* symtab
,
1558 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
1559 // undefined when scanning relocs (and thus requires
1560 // non-relative dynamic relocs). The proper value will be
1562 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
1563 if (gotsym
!= NULL
&& gotsym
->is_undefined())
1565 Target_powerpc
<size
, big_endian
>* target
=
1566 static_cast<Target_powerpc
<size
, big_endian
>*>(
1567 parameters
->sized_target
<size
, big_endian
>());
1568 Output_data_got_powerpc
<size
, big_endian
>* got
1569 = target
->got_section(symtab
, layout
);
1570 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1571 Symbol_table::PREDEFINED
,
1575 elfcpp::STV_HIDDEN
, 0,
1579 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
1580 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
1581 if (sdasym
!= NULL
&& sdasym
->is_undefined())
1583 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
1585 = layout
->add_output_section_data(".sdata", 0,
1587 | elfcpp::SHF_WRITE
,
1588 sdata
, ORDER_SMALL_DATA
, false);
1589 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
1590 Symbol_table::PREDEFINED
,
1591 os
, 32768, 0, elfcpp::STT_OBJECT
,
1592 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
1598 // Set up PowerPC target specific relobj.
1600 template<int size
, bool big_endian
>
1602 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1603 const std::string
& name
,
1604 Input_file
* input_file
,
1605 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1607 int et
= ehdr
.get_e_type();
1608 // ET_EXEC files are valid input for --just-symbols/-R,
1609 // and we treat them as relocatable objects.
1610 if (et
== elfcpp::ET_REL
1611 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1613 Powerpc_relobj
<size
, big_endian
>* obj
=
1614 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1618 else if (et
== elfcpp::ET_DYN
)
1620 Sized_dynobj
<size
, big_endian
>* obj
=
1621 new Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1627 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1632 template<int size
, bool big_endian
>
1633 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1636 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1637 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1639 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1640 : Output_data_got
<size
, big_endian
>(),
1641 symtab_(symtab
), layout_(layout
),
1642 header_ent_cnt_(size
== 32 ? 3 : 1),
1643 header_index_(size
== 32 ? 0x2000 : 0)
1648 // Create a new GOT entry and return its offset.
1650 add_got_entry(Got_entry got_entry
)
1652 this->reserve_ent();
1653 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1656 // Create a pair of new GOT entries and return the offset of the first.
1658 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1660 this->reserve_ent(2);
1661 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1666 add_constant_pair(Valtype c1
, Valtype c2
)
1668 this->reserve_ent(2);
1669 unsigned int got_offset
= this->add_constant(c1
);
1670 this->add_constant(c2
);
1674 // Offset of _GLOBAL_OFFSET_TABLE_.
1678 return this->got_offset(this->header_index_
);
1681 // Offset of base used to access the GOT/TOC.
1682 // The got/toc pointer reg will be set to this value.
1684 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
1687 return this->g_o_t();
1689 return (this->output_section()->address()
1690 + object
->toc_base_offset()
1694 // Ensure our GOT has a header.
1696 set_final_data_size()
1698 if (this->header_ent_cnt_
!= 0)
1699 this->make_header();
1700 Output_data_got
<size
, big_endian
>::set_final_data_size();
1703 // First word of GOT header needs some values that are not
1704 // handled by Output_data_got so poke them in here.
1705 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
1707 do_write(Output_file
* of
)
1710 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
1711 val
= this->layout_
->dynamic_section()->address();
1713 val
= this->output_section()->address() + 0x8000;
1714 this->replace_constant(this->header_index_
, val
);
1715 Output_data_got
<size
, big_endian
>::do_write(of
);
1720 reserve_ent(unsigned int cnt
= 1)
1722 if (this->header_ent_cnt_
== 0)
1724 if (this->num_entries() + cnt
> this->header_index_
)
1725 this->make_header();
1731 this->header_ent_cnt_
= 0;
1732 this->header_index_
= this->num_entries();
1735 Output_data_got
<size
, big_endian
>::add_constant(0);
1736 Output_data_got
<size
, big_endian
>::add_constant(0);
1737 Output_data_got
<size
, big_endian
>::add_constant(0);
1739 // Define _GLOBAL_OFFSET_TABLE_ at the header
1740 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
1743 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
1744 sym
->set_value(this->g_o_t());
1747 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1748 Symbol_table::PREDEFINED
,
1749 this, this->g_o_t(), 0,
1752 elfcpp::STV_HIDDEN
, 0,
1756 Output_data_got
<size
, big_endian
>::add_constant(0);
1759 // Stashed pointers.
1760 Symbol_table
* symtab_
;
1764 unsigned int header_ent_cnt_
;
1765 // GOT header index.
1766 unsigned int header_index_
;
1769 // Get the GOT section, creating it if necessary.
1771 template<int size
, bool big_endian
>
1772 Output_data_got_powerpc
<size
, big_endian
>*
1773 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1776 if (this->got_
== NULL
)
1778 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1781 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
1783 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1784 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
1785 this->got_
, ORDER_DATA
, false);
1791 // Get the dynamic reloc section, creating it if necessary.
1793 template<int size
, bool big_endian
>
1794 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
1795 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1797 if (this->rela_dyn_
== NULL
)
1799 gold_assert(layout
!= NULL
);
1800 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1801 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1802 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1803 ORDER_DYNAMIC_RELOCS
, false);
1805 return this->rela_dyn_
;
1811 // Determine the stub group size. The group size is the absolute
1812 // value of the parameter --stub-group-size. If --stub-group-size
1813 // is passed a negative value, we restrict stubs to be always before
1814 // the stubbed branches.
1815 Stub_control(int32_t size
)
1816 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
1817 stub14_group_size_(abs(size
)),
1818 stubs_always_before_branch_(size
< 0), suppress_size_errors_(false),
1819 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
1821 if (stub_group_size_
== 1)
1824 if (stubs_always_before_branch_
)
1826 stub_group_size_
= 0x1e00000;
1827 stub14_group_size_
= 0x7800;
1831 stub_group_size_
= 0x1c00000;
1832 stub14_group_size_
= 0x7000;
1834 suppress_size_errors_
= true;
1838 // Return true iff input section can be handled by current stub
1841 can_add_to_stub_group(Output_section
* o
,
1842 const Output_section::Input_section
* i
,
1845 const Output_section::Input_section
*
1851 { return output_section_
; }
1857 FINDING_STUB_SECTION
,
1862 uint32_t stub_group_size_
;
1863 uint32_t stub14_group_size_
;
1864 bool stubs_always_before_branch_
;
1865 bool suppress_size_errors_
;
1866 uint64_t group_end_addr_
;
1867 const Output_section::Input_section
* owner_
;
1868 Output_section
* output_section_
;
1871 // Return true iff input section can be handled by current stub/
1875 Stub_control::can_add_to_stub_group(Output_section
* o
,
1876 const Output_section::Input_section
* i
,
1880 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
1881 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
1883 uint64_t start_addr
= o
->address();
1886 // .init and .fini sections are pasted together to form a single
1887 // function. We can't be adding stubs in the middle of the function.
1888 this_size
= o
->data_size();
1891 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
1892 this_size
= i
->data_size();
1894 uint64_t end_addr
= start_addr
+ this_size
;
1895 bool toobig
= this_size
> group_size
;
1897 if (toobig
&& !this->suppress_size_errors_
)
1898 gold_warning(_("%s:%s exceeds group size"),
1899 i
->relobj()->name().c_str(),
1900 i
->relobj()->section_name(i
->shndx()).c_str());
1902 if (this->state_
!= HAS_STUB_SECTION
1903 && (!whole_sec
|| this->output_section_
!= o
))
1906 this->output_section_
= o
;
1909 if (this->state_
== NO_GROUP
)
1911 this->state_
= FINDING_STUB_SECTION
;
1912 this->group_end_addr_
= end_addr
;
1914 else if (this->group_end_addr_
- start_addr
< group_size
)
1916 // Adding this section would make the group larger than GROUP_SIZE.
1917 else if (this->state_
== FINDING_STUB_SECTION
1918 && !this->stubs_always_before_branch_
1921 // But wait, there's more! Input sections up to GROUP_SIZE
1922 // bytes before the stub table can be handled by it too.
1923 this->state_
= HAS_STUB_SECTION
;
1924 this->group_end_addr_
= end_addr
;
1928 this->state_
= NO_GROUP
;
1934 // Look over all the input sections, deciding where to place stubs.
1936 template<int size
, bool big_endian
>
1938 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
1941 Stub_control
stub_control(parameters
->options().stub_group_size());
1943 // Group input sections and insert stub table
1944 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
1945 Layout::Section_list section_list
;
1946 layout
->get_executable_sections(§ion_list
);
1947 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
1948 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
1949 o
!= section_list
.rend();
1952 typedef Output_section::Input_section_list Input_section_list
;
1953 for (Input_section_list::const_reverse_iterator i
1954 = (*o
)->input_sections().rbegin();
1955 i
!= (*o
)->input_sections().rend();
1958 if (i
->is_input_section())
1960 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1961 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
1962 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
1963 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
1965 stub_table
->init(stub_control
.owner(),
1966 stub_control
.output_section());
1969 if (stub_table
== NULL
)
1970 stub_table
= this->new_stub_table();
1971 ppcobj
->set_stub_table(i
->shndx(), stub_table
);
1975 if (stub_table
!= NULL
)
1976 stub_table
->init(stub_control
.owner(), stub_control
.output_section());
1979 // If this branch needs a plt call stub, or a long branch stub, make one.
1981 template<int size
, bool big_endian
>
1983 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
1984 Stub_table
<size
, big_endian
>* stub_table
,
1985 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
1986 Symbol_table
* symtab
) const
1988 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
1989 if (sym
!= NULL
&& sym
->is_forwarder())
1990 sym
= symtab
->resolve_forwards(sym
);
1991 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
1993 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(this->r_type_
))
1994 : this->object_
->local_has_plt_offset(this->r_sym_
))
1996 if (stub_table
== NULL
)
1997 stub_table
= this->object_
->stub_table(this->shndx_
);
1998 if (stub_table
== NULL
)
2000 // This is a ref from a data section to an ifunc symbol.
2001 stub_table
= ifunc_stub_table
;
2003 gold_assert(stub_table
!= NULL
);
2005 stub_table
->add_plt_call_entry(this->object_
, gsym
,
2006 this->r_type_
, this->addend_
);
2008 stub_table
->add_plt_call_entry(this->object_
, this->r_sym_
,
2009 this->r_type_
, this->addend_
);
2013 unsigned int max_branch_offset
;
2014 if (this->r_type_
== elfcpp::R_POWERPC_REL14
2015 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRTAKEN
2016 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2017 max_branch_offset
= 1 << 15;
2018 else if (this->r_type_
== elfcpp::R_POWERPC_REL24
2019 || this->r_type_
== elfcpp::R_PPC_PLTREL24
2020 || this->r_type_
== elfcpp::R_PPC_LOCAL24PC
)
2021 max_branch_offset
= 1 << 25;
2024 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2025 gold_assert(from
!= invalid_address
);
2026 from
+= (this->object_
->output_section(this->shndx_
)->address()
2031 switch (gsym
->source())
2033 case Symbol::FROM_OBJECT
:
2035 Object
* symobj
= gsym
->object();
2036 if (symobj
->is_dynamic()
2037 || symobj
->pluginobj() != NULL
)
2040 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2041 if (shndx
== elfcpp::SHN_UNDEF
)
2046 case Symbol::IS_UNDEFINED
:
2052 Symbol_table::Compute_final_value_status status
;
2053 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2054 if (status
!= Symbol_table::CFVS_OK
)
2059 const Symbol_value
<size
>* psymval
2060 = this->object_
->local_symbol(this->r_sym_
);
2061 Symbol_value
<size
> symval
;
2062 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2063 typename
ObjType::Compute_final_local_value_status status
2064 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2066 if (status
!= ObjType::CFLV_OK
2067 || !symval
.has_output_value())
2069 to
= symval
.value(this->object_
, 0);
2071 to
+= this->addend_
;
2072 if (stub_table
== NULL
)
2073 stub_table
= this->object_
->stub_table(this->shndx_
);
2074 gold_assert(stub_table
!= NULL
);
2075 if (size
== 64 && is_branch_reloc(this->r_type_
))
2077 unsigned int dest_shndx
;
2078 to
= stub_table
->targ()->symval_for_branch(to
, gsym
, this->object_
,
2081 Address delta
= to
- from
;
2082 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2084 stub_table
->add_long_branch_entry(this->object_
, to
);
2089 // Relaxation hook. This is where we do stub generation.
2091 template<int size
, bool big_endian
>
2093 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2094 const Input_objects
*,
2095 Symbol_table
* symtab
,
2099 unsigned int prev_brlt_size
= 0;
2102 bool thread_safe
= parameters
->options().plt_thread_safe();
2103 if (size
== 64 && !parameters
->options().user_set_plt_thread_safe())
2105 const char* const thread_starter
[] =
2109 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2111 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2112 "mq_notify", "create_timer",
2116 "GOMP_parallel_start",
2117 "GOMP_parallel_loop_static_start",
2118 "GOMP_parallel_loop_dynamic_start",
2119 "GOMP_parallel_loop_guided_start",
2120 "GOMP_parallel_loop_runtime_start",
2121 "GOMP_parallel_sections_start",
2124 for (unsigned int i
= 0;
2125 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2128 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2129 thread_safe
= sym
!= NULL
&& sym
->in_reg() && sym
->in_real_elf();
2134 this->plt_thread_safe_
= thread_safe
;
2135 this->group_sections(layout
, task
);
2138 // We need address of stub tables valid for make_stub.
2139 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2140 p
!= this->stub_tables_
.end();
2143 const Powerpc_relobj
<size
, big_endian
>* object
2144 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2145 Address off
= object
->get_output_section_offset((*p
)->shndx());
2146 gold_assert(off
!= invalid_address
);
2147 Output_section
* os
= (*p
)->output_section();
2148 (*p
)->set_address_and_size(os
, off
);
2153 // Clear plt call stubs, long branch stubs and branch lookup table.
2154 prev_brlt_size
= this->branch_lookup_table_
.size();
2155 this->branch_lookup_table_
.clear();
2156 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2157 p
!= this->stub_tables_
.end();
2160 (*p
)->clear_stubs();
2164 // Build all the stubs.
2165 Stub_table
<size
, big_endian
>* ifunc_stub_table
2166 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2167 Stub_table
<size
, big_endian
>* one_stub_table
2168 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2169 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2170 b
!= this->branch_info_
.end();
2173 b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
);
2176 // Did anything change size?
2177 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2178 bool again
= num_huge_branches
!= prev_brlt_size
;
2179 if (size
== 64 && num_huge_branches
!= 0)
2180 this->make_brlt_section(layout
);
2181 if (size
== 64 && again
)
2182 this->brlt_section_
->set_current_size(num_huge_branches
);
2184 typedef Unordered_set
<Output_section
*> Output_sections
;
2185 Output_sections os_need_update
;
2186 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2187 p
!= this->stub_tables_
.end();
2190 if ((*p
)->size_update())
2193 os_need_update
.insert((*p
)->output_section());
2197 // Set output section offsets for all input sections in an output
2198 // section that just changed size. Anything past the stubs will
2200 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2201 p
!= os_need_update
.end();
2204 Output_section
* os
= *p
;
2206 typedef Output_section::Input_section_list Input_section_list
;
2207 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2208 i
!= os
->input_sections().end();
2211 off
= align_address(off
, i
->addralign());
2212 if (i
->is_input_section() || i
->is_relaxed_input_section())
2213 i
->relobj()->set_section_offset(i
->shndx(), off
);
2214 if (i
->is_relaxed_input_section())
2216 Stub_table
<size
, big_endian
>* stub_table
2217 = static_cast<Stub_table
<size
, big_endian
>*>(
2218 i
->relaxed_input_section());
2219 off
+= stub_table
->set_address_and_size(os
, off
);
2222 off
+= i
->data_size();
2224 // If .brlt is part of this output section, then we have just
2225 // done the offset adjustment.
2226 os
->clear_section_offsets_need_adjustment();
2231 && num_huge_branches
!= 0
2232 && parameters
->options().output_is_position_independent())
2234 // Fill in the BRLT relocs.
2235 this->brlt_section_
->reset_data_size();
2236 for (typename
Branch_lookup_table::const_iterator p
2237 = this->branch_lookup_table_
.begin();
2238 p
!= this->branch_lookup_table_
.end();
2241 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
2243 this->brlt_section_
->finalize_data_size();
2248 // A class to handle the PLT data.
2250 template<int size
, bool big_endian
>
2251 class Output_data_plt_powerpc
: public Output_section_data_build
2254 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
2255 size
, big_endian
> Reloc_section
;
2257 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
2258 Reloc_section
* plt_rel
,
2259 unsigned int reserved_size
,
2261 : Output_section_data_build(size
== 32 ? 4 : 8),
2264 initial_plt_entry_size_(reserved_size
),
2268 // Add an entry to the PLT.
2273 add_ifunc_entry(Symbol
*);
2276 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
2278 // Return the .rela.plt section data.
2285 // Return the number of PLT entries.
2289 return ((this->current_data_size() - this->initial_plt_entry_size_
)
2293 // Return the offset of the first non-reserved PLT entry.
2295 first_plt_entry_offset()
2296 { return this->initial_plt_entry_size_
; }
2298 // Return the size of a PLT entry.
2300 get_plt_entry_size()
2301 { return plt_entry_size
; }
2305 do_adjust_output_section(Output_section
* os
)
2310 // Write to a map file.
2312 do_print_to_mapfile(Mapfile
* mapfile
) const
2313 { mapfile
->print_output_data(this, this->name_
); }
2316 // The size of an entry in the PLT.
2317 static const int plt_entry_size
= size
== 32 ? 4 : 24;
2319 // Write out the PLT data.
2321 do_write(Output_file
*);
2323 // The reloc section.
2324 Reloc_section
* rel_
;
2325 // Allows access to .glink for do_write.
2326 Target_powerpc
<size
, big_endian
>* targ_
;
2327 // The size of the first reserved entry.
2328 int initial_plt_entry_size_
;
2329 // What to report in map file.
2333 // Add an entry to the PLT.
2335 template<int size
, bool big_endian
>
2337 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
2339 if (!gsym
->has_plt_offset())
2341 section_size_type off
= this->current_data_size();
2343 off
+= this->first_plt_entry_offset();
2344 gsym
->set_plt_offset(off
);
2345 gsym
->set_needs_dynsym_entry();
2346 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
2347 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
2348 off
+= plt_entry_size
;
2349 this->set_current_data_size(off
);
2353 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
2355 template<int size
, bool big_endian
>
2357 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
2359 if (!gsym
->has_plt_offset())
2361 section_size_type off
= this->current_data_size();
2362 gsym
->set_plt_offset(off
);
2363 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2365 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
2366 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
2367 off
+= plt_entry_size
;
2368 this->set_current_data_size(off
);
2372 // Add an entry for a local ifunc symbol to the IPLT.
2374 template<int size
, bool big_endian
>
2376 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
2377 Sized_relobj_file
<size
, big_endian
>* relobj
,
2378 unsigned int local_sym_index
)
2380 if (!relobj
->local_has_plt_offset(local_sym_index
))
2382 section_size_type off
= this->current_data_size();
2383 relobj
->set_local_plt_offset(local_sym_index
, off
);
2384 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2386 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
2387 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
2389 off
+= plt_entry_size
;
2390 this->set_current_data_size(off
);
2394 static const uint32_t add_0_11_11
= 0x7c0b5a14;
2395 static const uint32_t add_2_2_11
= 0x7c425a14;
2396 static const uint32_t add_3_3_2
= 0x7c631214;
2397 static const uint32_t add_3_3_13
= 0x7c636a14;
2398 static const uint32_t add_11_0_11
= 0x7d605a14;
2399 static const uint32_t add_12_2_11
= 0x7d825a14;
2400 static const uint32_t add_12_12_11
= 0x7d8c5a14;
2401 static const uint32_t addi_11_11
= 0x396b0000;
2402 static const uint32_t addi_12_12
= 0x398c0000;
2403 static const uint32_t addi_2_2
= 0x38420000;
2404 static const uint32_t addi_3_2
= 0x38620000;
2405 static const uint32_t addi_3_3
= 0x38630000;
2406 static const uint32_t addis_0_2
= 0x3c020000;
2407 static const uint32_t addis_0_13
= 0x3c0d0000;
2408 static const uint32_t addis_11_11
= 0x3d6b0000;
2409 static const uint32_t addis_11_30
= 0x3d7e0000;
2410 static const uint32_t addis_12_12
= 0x3d8c0000;
2411 static const uint32_t addis_12_2
= 0x3d820000;
2412 static const uint32_t addis_3_2
= 0x3c620000;
2413 static const uint32_t addis_3_13
= 0x3c6d0000;
2414 static const uint32_t b
= 0x48000000;
2415 static const uint32_t bcl_20_31
= 0x429f0005;
2416 static const uint32_t bctr
= 0x4e800420;
2417 static const uint32_t blr
= 0x4e800020;
2418 static const uint32_t blrl
= 0x4e800021;
2419 static const uint32_t bnectr_p4
= 0x4ce20420;
2420 static const uint32_t cmpldi_2_0
= 0x28220000;
2421 static const uint32_t cror_15_15_15
= 0x4def7b82;
2422 static const uint32_t cror_31_31_31
= 0x4ffffb82;
2423 static const uint32_t ld_0_1
= 0xe8010000;
2424 static const uint32_t ld_0_12
= 0xe80c0000;
2425 static const uint32_t ld_11_12
= 0xe96c0000;
2426 static const uint32_t ld_11_2
= 0xe9620000;
2427 static const uint32_t ld_2_1
= 0xe8410000;
2428 static const uint32_t ld_2_11
= 0xe84b0000;
2429 static const uint32_t ld_2_12
= 0xe84c0000;
2430 static const uint32_t ld_2_2
= 0xe8420000;
2431 static const uint32_t lfd_0_1
= 0xc8010000;
2432 static const uint32_t li_0_0
= 0x38000000;
2433 static const uint32_t li_12_0
= 0x39800000;
2434 static const uint32_t lis_0_0
= 0x3c000000;
2435 static const uint32_t lis_11
= 0x3d600000;
2436 static const uint32_t lis_12
= 0x3d800000;
2437 static const uint32_t lwz_0_12
= 0x800c0000;
2438 static const uint32_t lwz_11_11
= 0x816b0000;
2439 static const uint32_t lwz_11_30
= 0x817e0000;
2440 static const uint32_t lwz_12_12
= 0x818c0000;
2441 static const uint32_t lwzu_0_12
= 0x840c0000;
2442 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
2443 static const uint32_t mflr_0
= 0x7c0802a6;
2444 static const uint32_t mflr_11
= 0x7d6802a6;
2445 static const uint32_t mflr_12
= 0x7d8802a6;
2446 static const uint32_t mtctr_0
= 0x7c0903a6;
2447 static const uint32_t mtctr_11
= 0x7d6903a6;
2448 static const uint32_t mtctr_12
= 0x7d8903a6;
2449 static const uint32_t mtlr_0
= 0x7c0803a6;
2450 static const uint32_t mtlr_12
= 0x7d8803a6;
2451 static const uint32_t nop
= 0x60000000;
2452 static const uint32_t ori_0_0_0
= 0x60000000;
2453 static const uint32_t std_0_1
= 0xf8010000;
2454 static const uint32_t std_0_12
= 0xf80c0000;
2455 static const uint32_t std_2_1
= 0xf8410000;
2456 static const uint32_t stfd_0_1
= 0xd8010000;
2457 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
2458 static const uint32_t sub_11_11_12
= 0x7d6c5850;
2459 static const uint32_t xor_11_11_11
= 0x7d6b5a78;
2461 // Write out the PLT.
2463 template<int size
, bool big_endian
>
2465 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
2469 const section_size_type offset
= this->offset();
2470 const section_size_type oview_size
2471 = convert_to_section_size_type(this->data_size());
2472 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2473 unsigned char* pov
= oview
;
2474 unsigned char* endpov
= oview
+ oview_size
;
2476 // The address of the .glink branch table
2477 const Output_data_glink
<size
, big_endian
>* glink
2478 = this->targ_
->glink_section();
2479 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
2481 while (pov
< endpov
)
2483 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
2488 of
->write_output_view(offset
, oview_size
, oview
);
2492 // Create the PLT section.
2494 template<int size
, bool big_endian
>
2496 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
2499 if (this->plt_
== NULL
)
2501 if (this->got_
== NULL
)
2502 this->got_section(symtab
, layout
);
2504 if (this->glink_
== NULL
)
2505 make_glink_section(layout
);
2507 // Ensure that .rela.dyn always appears before .rela.plt This is
2508 // necessary due to how, on PowerPC and some other targets, .rela.dyn
2509 // needs to include .rela.plt in it's range.
2510 this->rela_dyn_section(layout
);
2512 Reloc_section
* plt_rel
= new Reloc_section(false);
2513 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
2514 elfcpp::SHF_ALLOC
, plt_rel
,
2515 ORDER_DYNAMIC_PLT_RELOCS
, false);
2517 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
2518 size
== 32 ? 0 : 24,
2520 layout
->add_output_section_data(".plt",
2522 ? elfcpp::SHT_PROGBITS
2523 : elfcpp::SHT_NOBITS
),
2524 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2533 // Create the IPLT section.
2535 template<int size
, bool big_endian
>
2537 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
2540 if (this->iplt_
== NULL
)
2542 this->make_plt_section(symtab
, layout
);
2544 Reloc_section
* iplt_rel
= new Reloc_section(false);
2545 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
2547 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
2549 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
2553 // A section for huge long branch addresses, similar to plt section.
2555 template<int size
, bool big_endian
>
2556 class Output_data_brlt_powerpc
: public Output_section_data_build
2559 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2560 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
2561 size
, big_endian
> Reloc_section
;
2563 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
2564 Reloc_section
* brlt_rel
)
2565 : Output_section_data_build(size
== 32 ? 4 : 8),
2570 // Add a reloc for an entry in the BRLT.
2572 add_reloc(Address to
, unsigned int off
)
2573 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
2575 // Update section and reloc section size.
2577 set_current_size(unsigned int num_branches
)
2579 this->reset_address_and_file_offset();
2580 this->set_current_data_size(num_branches
* 16);
2581 this->finalize_data_size();
2582 Output_section
* os
= this->output_section();
2583 os
->set_section_offsets_need_adjustment();
2584 if (this->rel_
!= NULL
)
2586 unsigned int reloc_size
2587 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
2588 this->rel_
->reset_address_and_file_offset();
2589 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
2590 this->rel_
->finalize_data_size();
2591 Output_section
* os
= this->rel_
->output_section();
2592 os
->set_section_offsets_need_adjustment();
2598 do_adjust_output_section(Output_section
* os
)
2603 // Write to a map file.
2605 do_print_to_mapfile(Mapfile
* mapfile
) const
2606 { mapfile
->print_output_data(this, "** BRLT"); }
2609 // Write out the BRLT data.
2611 do_write(Output_file
*);
2613 // The reloc section.
2614 Reloc_section
* rel_
;
2615 Target_powerpc
<size
, big_endian
>* targ_
;
2618 // Make the branch lookup table section.
2620 template<int size
, bool big_endian
>
2622 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
2624 if (size
== 64 && this->brlt_section_
== NULL
)
2626 Reloc_section
* brlt_rel
= NULL
;
2627 bool is_pic
= parameters
->options().output_is_position_independent();
2630 // When PIC we can't fill in .brlt (like .plt it can be a
2631 // bss style section) but must initialise at runtime via
2632 // dynamic relocats.
2633 this->rela_dyn_section(layout
);
2634 brlt_rel
= new Reloc_section(false);
2635 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
2638 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
2639 if (this->plt_
&& is_pic
)
2640 this->plt_
->output_section()
2641 ->add_output_section_data(this->brlt_section_
);
2643 layout
->add_output_section_data(".brlt",
2644 (is_pic
? elfcpp::SHT_NOBITS
2645 : elfcpp::SHT_PROGBITS
),
2646 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2647 this->brlt_section_
,
2648 (is_pic
? ORDER_SMALL_BSS
2649 : ORDER_SMALL_DATA
),
2654 // Write out .brlt when non-PIC.
2656 template<int size
, bool big_endian
>
2658 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
2660 if (size
== 64 && !parameters
->options().output_is_position_independent())
2662 const section_size_type offset
= this->offset();
2663 const section_size_type oview_size
2664 = convert_to_section_size_type(this->data_size());
2665 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2667 this->targ_
->write_branch_lookup_table(oview
);
2668 of
->write_output_view(offset
, oview_size
, oview
);
2672 static inline uint32_t
2678 static inline uint32_t
2684 static inline uint32_t
2687 return hi(a
+ 0x8000);
2690 template<bool big_endian
>
2692 write_insn(unsigned char* p
, uint32_t v
)
2694 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
2697 // Stub_table holds information about plt and long branch stubs.
2698 // Stubs are built in an area following some input section determined
2699 // by group_sections(). This input section is converted to a relaxed
2700 // input section allowing it to be resized to accommodate the stubs
2702 template<int size
, bool big_endian
>
2703 class Stub_table
: public Output_relaxed_input_section
2706 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2707 static const Address invalid_address
= static_cast<Address
>(0) - 1;
2709 Stub_table(Target_powerpc
<size
, big_endian
>* targ
)
2710 : Output_relaxed_input_section(NULL
, 0, 0),
2711 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
2712 orig_data_size_(0), plt_size_(0), last_plt_size_(0),
2713 branch_size_(0), last_branch_size_(0)
2716 // Delayed Output_relaxed_input_section init.
2718 init(const Output_section::Input_section
*, Output_section
*);
2720 // Add a plt call stub.
2722 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
2728 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
2733 // Find a given plt call stub.
2735 find_plt_call_entry(const Symbol
*) const;
2738 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
2739 unsigned int) const;
2742 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
2748 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
2753 // Add a long branch stub.
2755 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*, Address
);
2758 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*, Address
);
2763 this->plt_call_stubs_
.clear();
2764 this->plt_size_
= 0;
2765 this->long_branch_stubs_
.clear();
2766 this->branch_size_
= 0;
2770 set_address_and_size(const Output_section
* os
, Address off
)
2772 Address start_off
= off
;
2773 off
+= this->orig_data_size_
;
2774 Address my_size
= this->plt_size_
+ this->branch_size_
;
2776 off
= align_address(off
, this->stub_align());
2777 // Include original section size and alignment padding in size
2778 my_size
+= off
- start_off
;
2779 this->reset_address_and_file_offset();
2780 this->set_current_data_size(my_size
);
2781 this->set_address_and_file_offset(os
->address() + start_off
,
2782 os
->offset() + start_off
);
2789 return align_address(this->address() + this->orig_data_size_
,
2790 this->stub_align());
2796 return align_address(this->offset() + this->orig_data_size_
,
2797 this->stub_align());
2802 { return this->plt_size_
; }
2807 Output_section
* os
= this->output_section();
2808 if (os
->addralign() < this->stub_align())
2810 os
->set_addralign(this->stub_align());
2811 // FIXME: get rid of the insane checkpointing.
2812 // We can't increase alignment of the input section to which
2813 // stubs are attached; The input section may be .init which
2814 // is pasted together with other .init sections to form a
2815 // function. Aligning might insert zero padding resulting in
2816 // sigill. However we do need to increase alignment of the
2817 // output section so that the align_address() on offset in
2818 // set_address_and_size() adds the same padding as the
2819 // align_address() on address in stub_address().
2820 // What's more, we need this alignment for the layout done in
2821 // relaxation_loop_body() so that the output section starts at
2822 // a suitably aligned address.
2823 os
->checkpoint_set_addralign(this->stub_align());
2825 if (this->last_plt_size_
!= this->plt_size_
2826 || this->last_branch_size_
!= this->branch_size_
)
2828 this->last_plt_size_
= this->plt_size_
;
2829 this->last_branch_size_
= this->branch_size_
;
2835 Target_powerpc
<size
, big_endian
>*
2841 class Plt_stub_ent_hash
;
2842 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
2843 Plt_stub_ent_hash
> Plt_stub_entries
;
2845 // Alignment of stub section.
2851 unsigned int min_align
= 32;
2852 unsigned int user_align
= 1 << parameters
->options().plt_align();
2853 return std::max(user_align
, min_align
);
2856 // Size of a given plt call stub.
2858 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
2863 Address pltaddr
= p
->second
;
2864 if (p
->first
.sym_
== NULL
2865 || (p
->first
.sym_
->type() == elfcpp::STT_GNU_IFUNC
2866 && p
->first
.sym_
->can_use_relative_reloc(false)))
2867 pltaddr
+= this->targ_
->iplt_section()->address();
2869 pltaddr
+= this->targ_
->plt_section()->address();
2870 Address tocbase
= this->targ_
->got_section()->output_section()->address();
2871 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2872 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
2873 tocbase
+= ppcobj
->toc_base_offset();
2874 Address off
= pltaddr
- tocbase
;
2875 bool static_chain
= parameters
->options().plt_static_chain();
2876 bool thread_safe
= this->targ_
->plt_thread_safe();
2877 unsigned int bytes
= (4 * 5
2880 + 4 * (ha(off
) != 0)
2881 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
2882 unsigned int align
= 1 << parameters
->options().plt_align();
2884 bytes
= (bytes
+ align
- 1) & -align
;
2888 // Return long branch stub size.
2890 branch_stub_size(Address to
)
2893 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
2894 if (to
- loc
+ (1 << 25) < 2 << 25)
2896 if (size
== 64 || !parameters
->options().output_is_position_independent())
2903 do_write(Output_file
*);
2905 // Plt call stub keys.
2909 Plt_stub_ent(const Symbol
* sym
)
2910 : sym_(sym
), object_(0), addend_(0), locsym_(0)
2913 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
2914 unsigned int locsym_index
)
2915 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
2918 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
2920 unsigned int r_type
,
2922 : sym_(sym
), object_(0), addend_(0), locsym_(0)
2925 this->addend_
= addend
;
2926 else if (parameters
->options().output_is_position_independent()
2927 && r_type
== elfcpp::R_PPC_PLTREL24
)
2929 this->addend_
= addend
;
2930 if (this->addend_
>= 32768)
2931 this->object_
= object
;
2935 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
2936 unsigned int locsym_index
,
2937 unsigned int r_type
,
2939 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
2942 this->addend_
= addend
;
2943 else if (parameters
->options().output_is_position_independent()
2944 && r_type
== elfcpp::R_PPC_PLTREL24
)
2945 this->addend_
= addend
;
2948 bool operator==(const Plt_stub_ent
& that
) const
2950 return (this->sym_
== that
.sym_
2951 && this->object_
== that
.object_
2952 && this->addend_
== that
.addend_
2953 && this->locsym_
== that
.locsym_
);
2957 const Sized_relobj_file
<size
, big_endian
>* object_
;
2958 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
2959 unsigned int locsym_
;
2962 class Plt_stub_ent_hash
2965 size_t operator()(const Plt_stub_ent
& ent
) const
2967 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
2968 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
2974 // Long branch stub keys.
2975 class Branch_stub_ent
2978 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
2979 : dest_(to
), toc_base_off_(0)
2982 toc_base_off_
= obj
->toc_base_offset();
2985 bool operator==(const Branch_stub_ent
& that
) const
2987 return (this->dest_
== that
.dest_
2989 || this->toc_base_off_
== that
.toc_base_off_
));
2993 unsigned int toc_base_off_
;
2996 class Branch_stub_ent_hash
2999 size_t operator()(const Branch_stub_ent
& ent
) const
3000 { return ent
.dest_
^ ent
.toc_base_off_
; }
3003 // In a sane world this would be a global.
3004 Target_powerpc
<size
, big_endian
>* targ_
;
3005 // Map sym/object/addend to stub offset.
3006 Plt_stub_entries plt_call_stubs_
;
3007 // Map destination address to stub offset.
3008 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
3009 Branch_stub_ent_hash
> Branch_stub_entries
;
3010 Branch_stub_entries long_branch_stubs_
;
3011 // size of input section
3012 section_size_type orig_data_size_
;
3014 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
3017 // Make a new stub table, and record.
3019 template<int size
, bool big_endian
>
3020 Stub_table
<size
, big_endian
>*
3021 Target_powerpc
<size
, big_endian
>::new_stub_table()
3023 Stub_table
<size
, big_endian
>* stub_table
3024 = new Stub_table
<size
, big_endian
>(this);
3025 this->stub_tables_
.push_back(stub_table
);
3029 // Delayed stub table initialisation, because we create the stub table
3030 // before we know to which section it will be attached.
3032 template<int size
, bool big_endian
>
3034 Stub_table
<size
, big_endian
>::init(
3035 const Output_section::Input_section
* owner
,
3036 Output_section
* output_section
)
3038 this->set_relobj(owner
->relobj());
3039 this->set_shndx(owner
->shndx());
3040 this->set_addralign(this->relobj()->section_addralign(this->shndx()));
3041 this->set_output_section(output_section
);
3042 this->orig_data_size_
= owner
->current_data_size();
3044 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3045 new_relaxed
.push_back(this);
3046 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3049 // Add a plt call stub, if we do not already have one for this
3050 // sym/object/addend combo.
3052 template<int size
, bool big_endian
>
3054 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3055 const Sized_relobj_file
<size
, big_endian
>* object
,
3057 unsigned int r_type
,
3060 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3061 Address off
= this->plt_size_
;
3062 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3063 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3065 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3068 template<int size
, bool big_endian
>
3070 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3071 const Sized_relobj_file
<size
, big_endian
>* object
,
3072 unsigned int locsym_index
,
3073 unsigned int r_type
,
3076 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3077 Address off
= this->plt_size_
;
3078 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3079 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3081 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3084 // Find a plt call stub.
3086 template<int size
, bool big_endian
>
3087 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3088 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3089 const Sized_relobj_file
<size
, big_endian
>* object
,
3091 unsigned int r_type
,
3092 Address addend
) const
3094 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3095 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3096 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3099 template<int size
, bool big_endian
>
3100 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3101 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
3103 Plt_stub_ent
ent(gsym
);
3104 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3105 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3108 template<int size
, bool big_endian
>
3109 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3110 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3111 const Sized_relobj_file
<size
, big_endian
>* object
,
3112 unsigned int locsym_index
,
3113 unsigned int r_type
,
3114 Address addend
) const
3116 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3117 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3118 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3121 template<int size
, bool big_endian
>
3122 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3123 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3124 const Sized_relobj_file
<size
, big_endian
>* object
,
3125 unsigned int locsym_index
) const
3127 Plt_stub_ent
ent(object
, locsym_index
);
3128 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3129 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3132 // Add a long branch stub if we don't already have one to given
3135 template<int size
, bool big_endian
>
3137 Stub_table
<size
, big_endian
>::add_long_branch_entry(
3138 const Powerpc_relobj
<size
, big_endian
>* object
,
3141 Branch_stub_ent
ent(object
, to
);
3142 Address off
= this->branch_size_
;
3143 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
3145 unsigned int stub_size
= this->branch_stub_size(to
);
3146 this->branch_size_
= off
+ stub_size
;
3147 if (size
== 64 && stub_size
!= 4)
3148 this->targ_
->add_branch_lookup_table(to
);
3152 // Find long branch stub.
3154 template<int size
, bool big_endian
>
3155 typename
elfcpp::Elf_types
<size
>::Elf_Addr
3156 Stub_table
<size
, big_endian
>::find_long_branch_entry(
3157 const Powerpc_relobj
<size
, big_endian
>* object
,
3160 Branch_stub_ent
ent(object
, to
);
3161 typename
Branch_stub_entries::const_iterator p
3162 = this->long_branch_stubs_
.find(ent
);
3163 return p
== this->long_branch_stubs_
.end() ? invalid_address
: p
->second
;
3166 // A class to handle .glink.
3168 template<int size
, bool big_endian
>
3169 class Output_data_glink
: public Output_section_data
3172 static const int pltresolve_size
= 16*4;
3174 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
3175 : Output_section_data(16), targ_(targ
)
3179 // Write to a map file.
3181 do_print_to_mapfile(Mapfile
* mapfile
) const
3182 { mapfile
->print_output_data(this, _("** glink")); }
3186 set_final_data_size();
3190 do_write(Output_file
*);
3192 // Allows access to .got and .plt for do_write.
3193 Target_powerpc
<size
, big_endian
>* targ_
;
3196 template<int size
, bool big_endian
>
3198 Output_data_glink
<size
, big_endian
>::set_final_data_size()
3200 unsigned int count
= this->targ_
->plt_entry_count();
3201 section_size_type total
= 0;
3207 // space for branch table
3208 total
+= 4 * (count
- 1);
3210 total
+= -total
& 15;
3211 total
+= this->pltresolve_size
;
3215 total
+= this->pltresolve_size
;
3217 // space for branch table
3220 total
+= 4 * (count
- 0x8000);
3224 this->set_data_size(total
);
3227 // Write out plt and long branch stub code.
3229 template<int size
, bool big_endian
>
3231 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
3233 if (this->plt_call_stubs_
.empty()
3234 && this->long_branch_stubs_
.empty())
3237 const section_size_type start_off
= this->offset();
3238 const section_size_type off
= this->stub_offset();
3239 const section_size_type oview_size
=
3240 convert_to_section_size_type(this->data_size() - (off
- start_off
));
3241 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
3246 const Output_data_got_powerpc
<size
, big_endian
>* got
3247 = this->targ_
->got_section();
3248 Address got_os_addr
= got
->output_section()->address();
3250 if (!this->plt_call_stubs_
.empty())
3252 // The base address of the .plt section.
3253 Address plt_base
= this->targ_
->plt_section()->address();
3254 Address iplt_base
= invalid_address
;
3256 // Write out plt call stubs.
3257 typename
Plt_stub_entries::const_iterator cs
;
3258 for (cs
= this->plt_call_stubs_
.begin();
3259 cs
!= this->plt_call_stubs_
.end();
3264 const Symbol
* gsym
= cs
->first
.sym_
;
3267 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3268 && gsym
->can_use_relative_reloc(false));
3269 pltoff
= gsym
->plt_offset();
3274 const Sized_relobj_file
<size
, big_endian
>* relobj
3275 = cs
->first
.object_
;
3276 unsigned int local_sym_index
= cs
->first
.locsym_
;
3277 pltoff
= relobj
->local_plt_offset(local_sym_index
);
3279 Address plt_addr
= pltoff
;
3282 if (iplt_base
== invalid_address
)
3283 iplt_base
= this->targ_
->iplt_section()->address();
3284 plt_addr
+= iplt_base
;
3287 plt_addr
+= plt_base
;
3288 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3289 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
3290 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
3291 Address off
= plt_addr
- got_addr
;
3293 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
3294 gold_error(_("%s: linkage table error against `%s'"),
3295 cs
->first
.object_
->name().c_str(),
3296 cs
->first
.sym_
->demangled_name().c_str());
3298 bool static_chain
= parameters
->options().plt_static_chain();
3299 bool thread_safe
= this->targ_
->plt_thread_safe();
3300 bool use_fake_dep
= false;
3301 Address cmp_branch_off
= 0;
3304 unsigned int pltindex
3305 = ((pltoff
- this->targ_
->first_plt_entry_offset())
3306 / this->targ_
->plt_entry_size());
3308 = (this->targ_
->glink_section()->pltresolve_size
3310 if (pltindex
> 32768)
3311 glinkoff
+= (pltindex
- 32768) * 4;
3313 = this->targ_
->glink_section()->address() + glinkoff
;
3315 = (this->stub_address() + cs
->second
+ 24
3316 + 4 * (ha(off
) != 0)
3317 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3318 + 4 * static_chain
);
3319 cmp_branch_off
= to
- from
;
3320 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
3323 p
= oview
+ cs
->second
;
3326 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
3327 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
)), p
+= 4;
3328 write_insn
<big_endian
>(p
, ld_11_12
+ l(off
)), p
+= 4;
3329 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3331 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
)), p
+= 4;
3334 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3337 write_insn
<big_endian
>(p
, xor_11_11_11
), p
+= 4;
3338 write_insn
<big_endian
>(p
, add_12_12_11
), p
+= 4;
3340 write_insn
<big_endian
>(p
, ld_2_12
+ l(off
+ 8)), p
+= 4;
3342 write_insn
<big_endian
>(p
, ld_11_12
+ l(off
+ 16)), p
+= 4;
3346 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
3347 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
)), p
+= 4;
3348 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3350 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
)), p
+= 4;
3353 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3356 write_insn
<big_endian
>(p
, xor_11_11_11
), p
+= 4;
3357 write_insn
<big_endian
>(p
, add_2_2_11
), p
+= 4;
3360 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16)), p
+= 4;
3361 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8)), p
+= 4;
3363 if (thread_safe
&& !use_fake_dep
)
3365 write_insn
<big_endian
>(p
, cmpldi_2_0
), p
+= 4;
3366 write_insn
<big_endian
>(p
, bnectr_p4
), p
+= 4;
3367 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
3370 write_insn
<big_endian
>(p
, bctr
);
3374 // Write out long branch stubs.
3375 typename
Branch_stub_entries::const_iterator bs
;
3376 for (bs
= this->long_branch_stubs_
.begin();
3377 bs
!= this->long_branch_stubs_
.end();
3380 p
= oview
+ this->plt_size_
+ bs
->second
;
3381 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
3382 Address delta
= bs
->first
.dest_
- loc
;
3383 if (delta
+ (1 << 25) < 2 << 25)
3384 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
3388 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
3389 gold_assert(brlt_addr
!= invalid_address
);
3390 brlt_addr
+= this->targ_
->brlt_section()->address();
3391 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
3392 Address brltoff
= brlt_addr
- got_addr
;
3393 if (ha(brltoff
) == 0)
3395 write_insn
<big_endian
>(p
, ld_11_2
+ l(brltoff
)), p
+= 4;
3399 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
3400 write_insn
<big_endian
>(p
, ld_11_12
+ l(brltoff
)), p
+= 4;
3402 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3403 write_insn
<big_endian
>(p
, bctr
);
3409 if (!this->plt_call_stubs_
.empty())
3411 // The base address of the .plt section.
3412 Address plt_base
= this->targ_
->plt_section()->address();
3413 Address iplt_base
= invalid_address
;
3414 // The address of _GLOBAL_OFFSET_TABLE_.
3415 Address g_o_t
= invalid_address
;
3417 // Write out plt call stubs.
3418 typename
Plt_stub_entries::const_iterator cs
;
3419 for (cs
= this->plt_call_stubs_
.begin();
3420 cs
!= this->plt_call_stubs_
.end();
3425 const Symbol
* gsym
= cs
->first
.sym_
;
3428 is_ifunc
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3429 && gsym
->can_use_relative_reloc(false));
3430 plt_addr
= gsym
->plt_offset();
3435 const Sized_relobj_file
<size
, big_endian
>* relobj
3436 = cs
->first
.object_
;
3437 unsigned int local_sym_index
= cs
->first
.locsym_
;
3438 plt_addr
= relobj
->local_plt_offset(local_sym_index
);
3442 if (iplt_base
== invalid_address
)
3443 iplt_base
= this->targ_
->iplt_section()->address();
3444 plt_addr
+= iplt_base
;
3447 plt_addr
+= plt_base
;
3449 p
= oview
+ cs
->second
;
3450 if (parameters
->options().output_is_position_independent())
3453 const Powerpc_relobj
<size
, big_endian
>* ppcobj
3454 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
3455 (cs
->first
.object_
));
3456 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
3458 unsigned int got2
= ppcobj
->got2_shndx();
3459 got_addr
= ppcobj
->get_output_section_offset(got2
);
3460 gold_assert(got_addr
!= invalid_address
);
3461 got_addr
+= (ppcobj
->output_section(got2
)->address()
3462 + cs
->first
.addend_
);
3466 if (g_o_t
== invalid_address
)
3468 const Output_data_got_powerpc
<size
, big_endian
>* got
3469 = this->targ_
->got_section();
3470 g_o_t
= got
->address() + got
->g_o_t();
3475 Address off
= plt_addr
- got_addr
;
3478 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
3479 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
3480 write_insn
<big_endian
>(p
+ 8, bctr
);
3484 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
3485 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
3486 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
3487 write_insn
<big_endian
>(p
+ 12, bctr
);
3492 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
3493 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
3494 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
3495 write_insn
<big_endian
>(p
+ 12, bctr
);
3500 // Write out long branch stubs.
3501 typename
Branch_stub_entries::const_iterator bs
;
3502 for (bs
= this->long_branch_stubs_
.begin();
3503 bs
!= this->long_branch_stubs_
.end();
3506 p
= oview
+ this->plt_size_
+ bs
->second
;
3507 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
3508 Address delta
= bs
->first
.dest_
- loc
;
3509 if (delta
+ (1 << 25) < 2 << 25)
3510 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
3511 else if (!parameters
->options().output_is_position_independent())
3513 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
3514 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
3515 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
3516 write_insn
<big_endian
>(p
+ 12, bctr
);
3521 write_insn
<big_endian
>(p
+ 0, mflr_0
);
3522 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
3523 write_insn
<big_endian
>(p
+ 8, mflr_12
);
3524 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
3525 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
3526 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
3527 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
3528 write_insn
<big_endian
>(p
+ 28, bctr
);
3534 // Write out .glink.
3536 template<int size
, bool big_endian
>
3538 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
3540 const section_size_type off
= this->offset();
3541 const section_size_type oview_size
=
3542 convert_to_section_size_type(this->data_size());
3543 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
3546 // The base address of the .plt section.
3547 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3548 Address plt_base
= this->targ_
->plt_section()->address();
3552 // Write pltresolve stub.
3554 Address after_bcl
= this->address() + 16;
3555 Address pltoff
= plt_base
- after_bcl
;
3557 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
3559 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
3560 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
3561 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
3562 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
3563 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
3564 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
3565 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
3566 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
3567 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3568 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
3569 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
3570 while (p
< oview
+ this->pltresolve_size
)
3571 write_insn
<big_endian
>(p
, nop
), p
+= 4;
3573 // Write lazy link call stubs.
3575 while (p
< oview
+ oview_size
)
3579 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
3583 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
3584 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
3586 uint32_t branch_off
= 8 - (p
- oview
);
3587 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
3593 const Output_data_got_powerpc
<size
, big_endian
>* got
3594 = this->targ_
->got_section();
3595 // The address of _GLOBAL_OFFSET_TABLE_.
3596 Address g_o_t
= got
->address() + got
->g_o_t();
3598 // Write out pltresolve branch table.
3600 unsigned int the_end
= oview_size
- this->pltresolve_size
;
3601 unsigned char* end_p
= oview
+ the_end
;
3602 while (p
< end_p
- 8 * 4)
3603 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
3605 write_insn
<big_endian
>(p
, nop
), p
+= 4;
3607 // Write out pltresolve call stub.
3608 if (parameters
->options().output_is_position_independent())
3610 Address res0_off
= 0;
3611 Address after_bcl_off
= the_end
+ 12;
3612 Address bcl_res0
= after_bcl_off
- res0_off
;
3614 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
3615 write_insn
<big_endian
>(p
+ 4, mflr_0
);
3616 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
3617 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
3618 write_insn
<big_endian
>(p
+ 16, mflr_12
);
3619 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
3620 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
3622 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
3624 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
3625 if (ha(got_bcl
) == ha(got_bcl
+ 4))
3627 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
3628 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
3632 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
3633 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
3635 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
3636 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
3637 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
3638 write_insn
<big_endian
>(p
+ 52, bctr
);
3639 write_insn
<big_endian
>(p
+ 56, nop
);
3640 write_insn
<big_endian
>(p
+ 60, nop
);
3644 Address res0
= this->address();
3646 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
3647 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
3648 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
3649 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
3651 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
3652 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
3653 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
3654 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
3655 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
3656 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
3658 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
3659 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
3660 write_insn
<big_endian
>(p
+ 32, bctr
);
3661 write_insn
<big_endian
>(p
+ 36, nop
);
3662 write_insn
<big_endian
>(p
+ 40, nop
);
3663 write_insn
<big_endian
>(p
+ 44, nop
);
3664 write_insn
<big_endian
>(p
+ 48, nop
);
3665 write_insn
<big_endian
>(p
+ 52, nop
);
3666 write_insn
<big_endian
>(p
+ 56, nop
);
3667 write_insn
<big_endian
>(p
+ 60, nop
);
3672 of
->write_output_view(off
, oview_size
, oview
);
3676 // A class to handle linker generated save/restore functions.
3678 template<int size
, bool big_endian
>
3679 class Output_data_save_res
: public Output_section_data_build
3682 Output_data_save_res(Symbol_table
* symtab
);
3685 // Write to a map file.
3687 do_print_to_mapfile(Mapfile
* mapfile
) const
3688 { mapfile
->print_output_data(this, _("** save/restore")); }
3691 do_write(Output_file
*);
3694 // The maximum size of save/restore contents.
3695 static const unsigned int savres_max
= 218*4;
3698 savres_define(Symbol_table
* symtab
,
3700 unsigned int lo
, unsigned int hi
,
3701 unsigned char* write_ent(unsigned char*, int),
3702 unsigned char* write_tail(unsigned char*, int));
3704 unsigned char *contents_
;
3707 template<bool big_endian
>
3708 static unsigned char*
3709 savegpr0(unsigned char* p
, int r
)
3711 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3712 write_insn
<big_endian
>(p
, insn
);
3716 template<bool big_endian
>
3717 static unsigned char*
3718 savegpr0_tail(unsigned char* p
, int r
)
3720 p
= savegpr0
<big_endian
>(p
, r
);
3721 uint32_t insn
= std_0_1
+ 16;
3722 write_insn
<big_endian
>(p
, insn
);
3724 write_insn
<big_endian
>(p
, blr
);
3728 template<bool big_endian
>
3729 static unsigned char*
3730 restgpr0(unsigned char* p
, int r
)
3732 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3733 write_insn
<big_endian
>(p
, insn
);
3737 template<bool big_endian
>
3738 static unsigned char*
3739 restgpr0_tail(unsigned char* p
, int r
)
3741 uint32_t insn
= ld_0_1
+ 16;
3742 write_insn
<big_endian
>(p
, insn
);
3744 p
= restgpr0
<big_endian
>(p
, r
);
3745 write_insn
<big_endian
>(p
, mtlr_0
);
3749 p
= restgpr0
<big_endian
>(p
, 30);
3750 p
= restgpr0
<big_endian
>(p
, 31);
3752 write_insn
<big_endian
>(p
, blr
);
3756 template<bool big_endian
>
3757 static unsigned char*
3758 savegpr1(unsigned char* p
, int r
)
3760 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3761 write_insn
<big_endian
>(p
, insn
);
3765 template<bool big_endian
>
3766 static unsigned char*
3767 savegpr1_tail(unsigned char* p
, int r
)
3769 p
= savegpr1
<big_endian
>(p
, r
);
3770 write_insn
<big_endian
>(p
, blr
);
3774 template<bool big_endian
>
3775 static unsigned char*
3776 restgpr1(unsigned char* p
, int r
)
3778 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3779 write_insn
<big_endian
>(p
, insn
);
3783 template<bool big_endian
>
3784 static unsigned char*
3785 restgpr1_tail(unsigned char* p
, int r
)
3787 p
= restgpr1
<big_endian
>(p
, r
);
3788 write_insn
<big_endian
>(p
, blr
);
3792 template<bool big_endian
>
3793 static unsigned char*
3794 savefpr(unsigned char* p
, int r
)
3796 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3797 write_insn
<big_endian
>(p
, insn
);
3801 template<bool big_endian
>
3802 static unsigned char*
3803 savefpr0_tail(unsigned char* p
, int r
)
3805 p
= savefpr
<big_endian
>(p
, r
);
3806 write_insn
<big_endian
>(p
, std_0_1
+ 16);
3808 write_insn
<big_endian
>(p
, blr
);
3812 template<bool big_endian
>
3813 static unsigned char*
3814 restfpr(unsigned char* p
, int r
)
3816 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
3817 write_insn
<big_endian
>(p
, insn
);
3821 template<bool big_endian
>
3822 static unsigned char*
3823 restfpr0_tail(unsigned char* p
, int r
)
3825 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
3827 p
= restfpr
<big_endian
>(p
, r
);
3828 write_insn
<big_endian
>(p
, mtlr_0
);
3832 p
= restfpr
<big_endian
>(p
, 30);
3833 p
= restfpr
<big_endian
>(p
, 31);
3835 write_insn
<big_endian
>(p
, blr
);
3839 template<bool big_endian
>
3840 static unsigned char*
3841 savefpr1_tail(unsigned char* p
, int r
)
3843 p
= savefpr
<big_endian
>(p
, r
);
3844 write_insn
<big_endian
>(p
, blr
);
3848 template<bool big_endian
>
3849 static unsigned char*
3850 restfpr1_tail(unsigned char* p
, int r
)
3852 p
= restfpr
<big_endian
>(p
, r
);
3853 write_insn
<big_endian
>(p
, blr
);
3857 template<bool big_endian
>
3858 static unsigned char*
3859 savevr(unsigned char* p
, int r
)
3861 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
3862 write_insn
<big_endian
>(p
, insn
);
3864 insn
= stvx_0_12_0
+ (r
<< 21);
3865 write_insn
<big_endian
>(p
, insn
);
3869 template<bool big_endian
>
3870 static unsigned char*
3871 savevr_tail(unsigned char* p
, int r
)
3873 p
= savevr
<big_endian
>(p
, r
);
3874 write_insn
<big_endian
>(p
, blr
);
3878 template<bool big_endian
>
3879 static unsigned char*
3880 restvr(unsigned char* p
, int r
)
3882 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
3883 write_insn
<big_endian
>(p
, insn
);
3885 insn
= lvx_0_12_0
+ (r
<< 21);
3886 write_insn
<big_endian
>(p
, insn
);
3890 template<bool big_endian
>
3891 static unsigned char*
3892 restvr_tail(unsigned char* p
, int r
)
3894 p
= restvr
<big_endian
>(p
, r
);
3895 write_insn
<big_endian
>(p
, blr
);
3900 template<int size
, bool big_endian
>
3901 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
3902 Symbol_table
* symtab
)
3903 : Output_section_data_build(4),
3906 this->savres_define(symtab
,
3907 "_savegpr0_", 14, 31,
3908 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
3909 this->savres_define(symtab
,
3910 "_restgpr0_", 14, 29,
3911 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
3912 this->savres_define(symtab
,
3913 "_restgpr0_", 30, 31,
3914 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
3915 this->savres_define(symtab
,
3916 "_savegpr1_", 14, 31,
3917 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
3918 this->savres_define(symtab
,
3919 "_restgpr1_", 14, 31,
3920 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
3921 this->savres_define(symtab
,
3922 "_savefpr_", 14, 31,
3923 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
3924 this->savres_define(symtab
,
3925 "_restfpr_", 14, 29,
3926 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
3927 this->savres_define(symtab
,
3928 "_restfpr_", 30, 31,
3929 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
3930 this->savres_define(symtab
,
3932 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
3933 this->savres_define(symtab
,
3935 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
3936 this->savres_define(symtab
,
3938 savevr
<big_endian
>, savevr_tail
<big_endian
>);
3939 this->savres_define(symtab
,
3941 restvr
<big_endian
>, restvr_tail
<big_endian
>);
3944 template<int size
, bool big_endian
>
3946 Output_data_save_res
<size
, big_endian
>::savres_define(
3947 Symbol_table
* symtab
,
3949 unsigned int lo
, unsigned int hi
,
3950 unsigned char* write_ent(unsigned char*, int),
3951 unsigned char* write_tail(unsigned char*, int))
3953 size_t len
= strlen(name
);
3954 bool writing
= false;
3957 memcpy(sym
, name
, len
);
3960 for (unsigned int i
= lo
; i
<= hi
; i
++)
3962 sym
[len
+ 0] = i
/ 10 + '0';
3963 sym
[len
+ 1] = i
% 10 + '0';
3964 Symbol
* gsym
= symtab
->lookup(sym
);
3965 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
3966 writing
= writing
|| refd
;
3969 if (this->contents_
== NULL
)
3970 this->contents_
= new unsigned char[this->savres_max
];
3972 section_size_type value
= this->current_data_size();
3973 unsigned char* p
= this->contents_
+ value
;
3975 p
= write_ent(p
, i
);
3977 p
= write_tail(p
, i
);
3978 section_size_type cur_size
= p
- this->contents_
;
3979 this->set_current_data_size(cur_size
);
3981 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
3982 this, value
, cur_size
- value
,
3983 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
3984 elfcpp::STV_HIDDEN
, 0, false, false);
3989 // Write out save/restore.
3991 template<int size
, bool big_endian
>
3993 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
3995 const section_size_type off
= this->offset();
3996 const section_size_type oview_size
=
3997 convert_to_section_size_type(this->data_size());
3998 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
3999 memcpy(oview
, this->contents_
, oview_size
);
4000 of
->write_output_view(off
, oview_size
, oview
);
4004 // Create the glink section.
4006 template<int size
, bool big_endian
>
4008 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
4010 if (this->glink_
== NULL
)
4012 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
4013 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
4014 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
4015 this->glink_
, ORDER_TEXT
, false);
4019 // Create a PLT entry for a global symbol.
4021 template<int size
, bool big_endian
>
4023 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
4027 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
4028 && gsym
->can_use_relative_reloc(false))
4030 if (this->iplt_
== NULL
)
4031 this->make_iplt_section(symtab
, layout
);
4032 this->iplt_
->add_ifunc_entry(gsym
);
4036 if (this->plt_
== NULL
)
4037 this->make_plt_section(symtab
, layout
);
4038 this->plt_
->add_entry(gsym
);
4042 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
4044 template<int size
, bool big_endian
>
4046 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
4047 Symbol_table
* symtab
,
4049 Sized_relobj_file
<size
, big_endian
>* relobj
,
4052 if (this->iplt_
== NULL
)
4053 this->make_iplt_section(symtab
, layout
);
4054 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
4057 // Return the number of entries in the PLT.
4059 template<int size
, bool big_endian
>
4061 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
4063 if (this->plt_
== NULL
)
4065 unsigned int count
= this->plt_
->entry_count();
4066 if (this->iplt_
!= NULL
)
4067 count
+= this->iplt_
->entry_count();
4071 // Return the offset of the first non-reserved PLT entry.
4073 template<int size
, bool big_endian
>
4075 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
4077 return this->plt_
->first_plt_entry_offset();
4080 // Return the size of each PLT entry.
4082 template<int size
, bool big_endian
>
4084 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
4086 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
4089 // Create a GOT entry for local dynamic __tls_get_addr calls.
4091 template<int size
, bool big_endian
>
4093 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
4094 Symbol_table
* symtab
,
4096 Sized_relobj_file
<size
, big_endian
>* object
)
4098 if (this->tlsld_got_offset_
== -1U)
4100 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
4101 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
4102 Output_data_got_powerpc
<size
, big_endian
>* got
4103 = this->got_section(symtab
, layout
);
4104 unsigned int got_offset
= got
->add_constant_pair(0, 0);
4105 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
4107 this->tlsld_got_offset_
= got_offset
;
4109 return this->tlsld_got_offset_
;
4112 // Get the Reference_flags for a particular relocation.
4114 template<int size
, bool big_endian
>
4116 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
4120 case elfcpp::R_POWERPC_NONE
:
4121 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4122 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4123 case elfcpp::R_PPC64_TOC
:
4124 // No symbol reference.
4127 case elfcpp::R_PPC64_ADDR64
:
4128 case elfcpp::R_PPC64_UADDR64
:
4129 case elfcpp::R_POWERPC_ADDR32
:
4130 case elfcpp::R_POWERPC_UADDR32
:
4131 case elfcpp::R_POWERPC_ADDR16
:
4132 case elfcpp::R_POWERPC_UADDR16
:
4133 case elfcpp::R_POWERPC_ADDR16_LO
:
4134 case elfcpp::R_POWERPC_ADDR16_HI
:
4135 case elfcpp::R_POWERPC_ADDR16_HA
:
4136 return Symbol::ABSOLUTE_REF
;
4138 case elfcpp::R_POWERPC_ADDR24
:
4139 case elfcpp::R_POWERPC_ADDR14
:
4140 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4141 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4142 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
4144 case elfcpp::R_PPC64_REL64
:
4145 case elfcpp::R_POWERPC_REL32
:
4146 case elfcpp::R_PPC_LOCAL24PC
:
4147 case elfcpp::R_POWERPC_REL16
:
4148 case elfcpp::R_POWERPC_REL16_LO
:
4149 case elfcpp::R_POWERPC_REL16_HI
:
4150 case elfcpp::R_POWERPC_REL16_HA
:
4151 return Symbol::RELATIVE_REF
;
4153 case elfcpp::R_POWERPC_REL24
:
4154 case elfcpp::R_PPC_PLTREL24
:
4155 case elfcpp::R_POWERPC_REL14
:
4156 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4157 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4158 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
4160 case elfcpp::R_POWERPC_GOT16
:
4161 case elfcpp::R_POWERPC_GOT16_LO
:
4162 case elfcpp::R_POWERPC_GOT16_HI
:
4163 case elfcpp::R_POWERPC_GOT16_HA
:
4164 case elfcpp::R_PPC64_GOT16_DS
:
4165 case elfcpp::R_PPC64_GOT16_LO_DS
:
4166 case elfcpp::R_PPC64_TOC16
:
4167 case elfcpp::R_PPC64_TOC16_LO
:
4168 case elfcpp::R_PPC64_TOC16_HI
:
4169 case elfcpp::R_PPC64_TOC16_HA
:
4170 case elfcpp::R_PPC64_TOC16_DS
:
4171 case elfcpp::R_PPC64_TOC16_LO_DS
:
4173 return Symbol::ABSOLUTE_REF
;
4175 case elfcpp::R_POWERPC_GOT_TPREL16
:
4176 case elfcpp::R_POWERPC_TLS
:
4177 return Symbol::TLS_REF
;
4179 case elfcpp::R_POWERPC_COPY
:
4180 case elfcpp::R_POWERPC_GLOB_DAT
:
4181 case elfcpp::R_POWERPC_JMP_SLOT
:
4182 case elfcpp::R_POWERPC_RELATIVE
:
4183 case elfcpp::R_POWERPC_DTPMOD
:
4185 // Not expected. We will give an error later.
4190 // Report an unsupported relocation against a local symbol.
4192 template<int size
, bool big_endian
>
4194 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
4195 Sized_relobj_file
<size
, big_endian
>* object
,
4196 unsigned int r_type
)
4198 gold_error(_("%s: unsupported reloc %u against local symbol"),
4199 object
->name().c_str(), r_type
);
4202 // We are about to emit a dynamic relocation of type R_TYPE. If the
4203 // dynamic linker does not support it, issue an error.
4205 template<int size
, bool big_endian
>
4207 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
4208 unsigned int r_type
)
4210 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
4212 // These are the relocation types supported by glibc for both 32-bit
4213 // and 64-bit powerpc.
4216 case elfcpp::R_POWERPC_NONE
:
4217 case elfcpp::R_POWERPC_RELATIVE
:
4218 case elfcpp::R_POWERPC_GLOB_DAT
:
4219 case elfcpp::R_POWERPC_DTPMOD
:
4220 case elfcpp::R_POWERPC_DTPREL
:
4221 case elfcpp::R_POWERPC_TPREL
:
4222 case elfcpp::R_POWERPC_JMP_SLOT
:
4223 case elfcpp::R_POWERPC_COPY
:
4224 case elfcpp::R_POWERPC_IRELATIVE
:
4225 case elfcpp::R_POWERPC_ADDR32
:
4226 case elfcpp::R_POWERPC_UADDR32
:
4227 case elfcpp::R_POWERPC_ADDR24
:
4228 case elfcpp::R_POWERPC_ADDR16
:
4229 case elfcpp::R_POWERPC_UADDR16
:
4230 case elfcpp::R_POWERPC_ADDR16_LO
:
4231 case elfcpp::R_POWERPC_ADDR16_HI
:
4232 case elfcpp::R_POWERPC_ADDR16_HA
:
4233 case elfcpp::R_POWERPC_ADDR14
:
4234 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4235 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4236 case elfcpp::R_POWERPC_REL32
:
4237 case elfcpp::R_POWERPC_REL24
:
4238 case elfcpp::R_POWERPC_TPREL16
:
4239 case elfcpp::R_POWERPC_TPREL16_LO
:
4240 case elfcpp::R_POWERPC_TPREL16_HI
:
4241 case elfcpp::R_POWERPC_TPREL16_HA
:
4252 // These are the relocation types supported only on 64-bit.
4253 case elfcpp::R_PPC64_ADDR64
:
4254 case elfcpp::R_PPC64_UADDR64
:
4255 case elfcpp::R_PPC64_JMP_IREL
:
4256 case elfcpp::R_PPC64_ADDR16_DS
:
4257 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4258 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4259 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4260 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4261 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4262 case elfcpp::R_PPC64_REL64
:
4263 case elfcpp::R_POWERPC_ADDR30
:
4264 case elfcpp::R_PPC64_TPREL16_DS
:
4265 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4266 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4267 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4268 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4269 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4280 // These are the relocation types supported only on 32-bit.
4281 // ??? glibc ld.so doesn't need to support these.
4282 case elfcpp::R_POWERPC_DTPREL16
:
4283 case elfcpp::R_POWERPC_DTPREL16_LO
:
4284 case elfcpp::R_POWERPC_DTPREL16_HI
:
4285 case elfcpp::R_POWERPC_DTPREL16_HA
:
4293 // This prevents us from issuing more than one error per reloc
4294 // section. But we can still wind up issuing more than one
4295 // error per object file.
4296 if (this->issued_non_pic_error_
)
4298 gold_assert(parameters
->options().output_is_position_independent());
4299 object
->error(_("requires unsupported dynamic reloc; "
4300 "recompile with -fPIC"));
4301 this->issued_non_pic_error_
= true;
4305 // Return whether we need to make a PLT entry for a relocation of the
4306 // given type against a STT_GNU_IFUNC symbol.
4308 template<int size
, bool big_endian
>
4310 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
4311 Sized_relobj_file
<size
, big_endian
>* object
,
4312 unsigned int r_type
)
4314 // In non-pic code any reference will resolve to the plt call stub
4315 // for the ifunc symbol.
4316 if (size
== 32 && !parameters
->options().output_is_position_independent())
4321 // Word size refs from data sections are OK.
4322 case elfcpp::R_POWERPC_ADDR32
:
4323 case elfcpp::R_POWERPC_UADDR32
:
4328 case elfcpp::R_PPC64_ADDR64
:
4329 case elfcpp::R_PPC64_UADDR64
:
4334 // GOT refs are good.
4335 case elfcpp::R_POWERPC_GOT16
:
4336 case elfcpp::R_POWERPC_GOT16_LO
:
4337 case elfcpp::R_POWERPC_GOT16_HI
:
4338 case elfcpp::R_POWERPC_GOT16_HA
:
4339 case elfcpp::R_PPC64_GOT16_DS
:
4340 case elfcpp::R_PPC64_GOT16_LO_DS
:
4343 // So are function calls.
4344 case elfcpp::R_POWERPC_ADDR24
:
4345 case elfcpp::R_POWERPC_ADDR14
:
4346 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4347 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4348 case elfcpp::R_POWERPC_REL24
:
4349 case elfcpp::R_PPC_PLTREL24
:
4350 case elfcpp::R_POWERPC_REL14
:
4351 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4352 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4359 // Anything else is a problem.
4360 // If we are building a static executable, the libc startup function
4361 // responsible for applying indirect function relocations is going
4362 // to complain about the reloc type.
4363 // If we are building a dynamic executable, we will have a text
4364 // relocation. The dynamic loader will set the text segment
4365 // writable and non-executable to apply text relocations. So we'll
4366 // segfault when trying to run the indirection function to resolve
4368 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
4369 object
->name().c_str(), r_type
);
4373 // Scan a relocation for a local symbol.
4375 template<int size
, bool big_endian
>
4377 Target_powerpc
<size
, big_endian
>::Scan::local(
4378 Symbol_table
* symtab
,
4380 Target_powerpc
<size
, big_endian
>* target
,
4381 Sized_relobj_file
<size
, big_endian
>* object
,
4382 unsigned int data_shndx
,
4383 Output_section
* output_section
,
4384 const elfcpp::Rela
<size
, big_endian
>& reloc
,
4385 unsigned int r_type
,
4386 const elfcpp::Sym
<size
, big_endian
>& lsym
,
4389 Powerpc_relobj
<size
, big_endian
>* ppc_object
4390 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
4395 && data_shndx
== ppc_object
->opd_shndx()
4396 && r_type
== elfcpp::R_PPC64_ADDR64
)
4397 ppc_object
->set_opd_discard(reloc
.get_r_offset());
4401 // A local STT_GNU_IFUNC symbol may require a PLT entry.
4402 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
4403 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
4405 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4406 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4407 r_type
, r_sym
, reloc
.get_r_addend());
4408 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
4413 case elfcpp::R_POWERPC_NONE
:
4414 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4415 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4416 case elfcpp::R_PPC64_TOCSAVE
:
4417 case elfcpp::R_PPC_EMB_MRKREF
:
4418 case elfcpp::R_POWERPC_TLS
:
4421 case elfcpp::R_PPC64_TOC
:
4423 Output_data_got_powerpc
<size
, big_endian
>* got
4424 = target
->got_section(symtab
, layout
);
4425 if (parameters
->options().output_is_position_independent())
4427 Address off
= reloc
.get_r_offset();
4429 && data_shndx
== ppc_object
->opd_shndx()
4430 && ppc_object
->get_opd_discard(off
- 8))
4433 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4434 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
4435 rela_dyn
->add_output_section_relative(got
->output_section(),
4436 elfcpp::R_POWERPC_RELATIVE
,
4438 object
, data_shndx
, off
,
4439 symobj
->toc_base_offset());
4444 case elfcpp::R_PPC64_ADDR64
:
4445 case elfcpp::R_PPC64_UADDR64
:
4446 case elfcpp::R_POWERPC_ADDR32
:
4447 case elfcpp::R_POWERPC_UADDR32
:
4448 case elfcpp::R_POWERPC_ADDR24
:
4449 case elfcpp::R_POWERPC_ADDR16
:
4450 case elfcpp::R_POWERPC_ADDR16_LO
:
4451 case elfcpp::R_POWERPC_ADDR16_HI
:
4452 case elfcpp::R_POWERPC_ADDR16_HA
:
4453 case elfcpp::R_POWERPC_UADDR16
:
4454 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4455 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4456 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4457 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4458 case elfcpp::R_PPC64_ADDR16_DS
:
4459 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4460 case elfcpp::R_POWERPC_ADDR14
:
4461 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4462 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4463 // If building a shared library (or a position-independent
4464 // executable), we need to create a dynamic relocation for
4466 if (parameters
->options().output_is_position_independent()
4467 || (size
== 64 && is_ifunc
))
4469 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4471 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
4472 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
4474 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4475 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4478 rela_dyn
= target
->iplt_section()->rel_plt();
4479 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4481 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
4482 output_section
, data_shndx
,
4483 reloc
.get_r_offset(),
4484 reloc
.get_r_addend(), false);
4488 check_non_pic(object
, r_type
);
4489 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4490 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
4491 data_shndx
, reloc
.get_r_offset(),
4492 reloc
.get_r_addend());
4497 case elfcpp::R_POWERPC_REL24
:
4498 case elfcpp::R_PPC_PLTREL24
:
4499 case elfcpp::R_PPC_LOCAL24PC
:
4500 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4501 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4502 reloc
.get_r_addend());
4505 case elfcpp::R_POWERPC_REL14
:
4506 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4507 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4508 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4509 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4510 reloc
.get_r_addend());
4513 case elfcpp::R_PPC64_REL64
:
4514 case elfcpp::R_POWERPC_REL32
:
4515 case elfcpp::R_POWERPC_REL16
:
4516 case elfcpp::R_POWERPC_REL16_LO
:
4517 case elfcpp::R_POWERPC_REL16_HI
:
4518 case elfcpp::R_POWERPC_REL16_HA
:
4519 case elfcpp::R_POWERPC_SECTOFF
:
4520 case elfcpp::R_POWERPC_TPREL16
:
4521 case elfcpp::R_POWERPC_DTPREL16
:
4522 case elfcpp::R_POWERPC_SECTOFF_LO
:
4523 case elfcpp::R_POWERPC_TPREL16_LO
:
4524 case elfcpp::R_POWERPC_DTPREL16_LO
:
4525 case elfcpp::R_POWERPC_SECTOFF_HI
:
4526 case elfcpp::R_POWERPC_TPREL16_HI
:
4527 case elfcpp::R_POWERPC_DTPREL16_HI
:
4528 case elfcpp::R_POWERPC_SECTOFF_HA
:
4529 case elfcpp::R_POWERPC_TPREL16_HA
:
4530 case elfcpp::R_POWERPC_DTPREL16_HA
:
4531 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4532 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4533 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4534 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4535 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4536 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4537 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4538 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4539 case elfcpp::R_PPC64_TPREL16_DS
:
4540 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4541 case elfcpp::R_PPC64_DTPREL16_DS
:
4542 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4543 case elfcpp::R_PPC64_SECTOFF_DS
:
4544 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4545 case elfcpp::R_PPC64_TLSGD
:
4546 case elfcpp::R_PPC64_TLSLD
:
4549 case elfcpp::R_POWERPC_GOT16
:
4550 case elfcpp::R_POWERPC_GOT16_LO
:
4551 case elfcpp::R_POWERPC_GOT16_HI
:
4552 case elfcpp::R_POWERPC_GOT16_HA
:
4553 case elfcpp::R_PPC64_GOT16_DS
:
4554 case elfcpp::R_PPC64_GOT16_LO_DS
:
4556 // The symbol requires a GOT entry.
4557 Output_data_got_powerpc
<size
, big_endian
>* got
4558 = target
->got_section(symtab
, layout
);
4559 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4561 if (!parameters
->options().output_is_position_independent())
4563 if (size
== 32 && is_ifunc
)
4564 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
4566 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
4568 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
4570 // If we are generating a shared object or a pie, this
4571 // symbol's GOT entry will be set by a dynamic relocation.
4573 off
= got
->add_constant(0);
4574 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
4576 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4577 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4580 rela_dyn
= target
->iplt_section()->rel_plt();
4581 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4583 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
4584 got
, off
, 0, false);
4589 case elfcpp::R_PPC64_TOC16
:
4590 case elfcpp::R_PPC64_TOC16_LO
:
4591 case elfcpp::R_PPC64_TOC16_HI
:
4592 case elfcpp::R_PPC64_TOC16_HA
:
4593 case elfcpp::R_PPC64_TOC16_DS
:
4594 case elfcpp::R_PPC64_TOC16_LO_DS
:
4595 // We need a GOT section.
4596 target
->got_section(symtab
, layout
);
4599 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4600 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
4601 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
4602 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
4604 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
4605 if (tls_type
== tls::TLSOPT_NONE
)
4607 Output_data_got_powerpc
<size
, big_endian
>* got
4608 = target
->got_section(symtab
, layout
);
4609 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4610 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4611 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
4612 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
4614 else if (tls_type
== tls::TLSOPT_TO_LE
)
4616 // no GOT relocs needed for Local Exec.
4623 case elfcpp::R_POWERPC_GOT_TLSLD16
:
4624 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
4625 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
4626 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
4628 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4629 if (tls_type
== tls::TLSOPT_NONE
)
4630 target
->tlsld_got_offset(symtab
, layout
, object
);
4631 else if (tls_type
== tls::TLSOPT_TO_LE
)
4633 // no GOT relocs needed for Local Exec.
4634 if (parameters
->options().emit_relocs())
4636 Output_section
* os
= layout
->tls_segment()->first_section();
4637 gold_assert(os
!= NULL
);
4638 os
->set_needs_symtab_index();
4646 case elfcpp::R_POWERPC_GOT_DTPREL16
:
4647 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
4648 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
4649 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
4651 Output_data_got_powerpc
<size
, big_endian
>* got
4652 = target
->got_section(symtab
, layout
);
4653 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4654 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
4658 case elfcpp::R_POWERPC_GOT_TPREL16
:
4659 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
4660 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
4661 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
4663 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
4664 if (tls_type
== tls::TLSOPT_NONE
)
4666 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4667 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
4669 Output_data_got_powerpc
<size
, big_endian
>* got
4670 = target
->got_section(symtab
, layout
);
4671 unsigned int off
= got
->add_constant(0);
4672 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
4674 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4675 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
4676 elfcpp::R_POWERPC_TPREL
,
4680 else if (tls_type
== tls::TLSOPT_TO_LE
)
4682 // no GOT relocs needed for Local Exec.
4690 unsupported_reloc_local(object
, r_type
);
4695 // Report an unsupported relocation against a global symbol.
4697 template<int size
, bool big_endian
>
4699 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
4700 Sized_relobj_file
<size
, big_endian
>* object
,
4701 unsigned int r_type
,
4704 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
4705 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
4708 // Scan a relocation for a global symbol.
4710 template<int size
, bool big_endian
>
4712 Target_powerpc
<size
, big_endian
>::Scan::global(
4713 Symbol_table
* symtab
,
4715 Target_powerpc
<size
, big_endian
>* target
,
4716 Sized_relobj_file
<size
, big_endian
>* object
,
4717 unsigned int data_shndx
,
4718 Output_section
* output_section
,
4719 const elfcpp::Rela
<size
, big_endian
>& reloc
,
4720 unsigned int r_type
,
4723 Powerpc_relobj
<size
, big_endian
>* ppc_object
4724 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
4726 // A STT_GNU_IFUNC symbol may require a PLT entry.
4727 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
4728 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
4730 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4731 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4732 reloc
.get_r_addend());
4733 target
->make_plt_entry(symtab
, layout
, gsym
);
4738 case elfcpp::R_POWERPC_NONE
:
4739 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4740 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4741 case elfcpp::R_PPC_LOCAL24PC
:
4742 case elfcpp::R_PPC_EMB_MRKREF
:
4743 case elfcpp::R_POWERPC_TLS
:
4746 case elfcpp::R_PPC64_TOC
:
4748 Output_data_got_powerpc
<size
, big_endian
>* got
4749 = target
->got_section(symtab
, layout
);
4750 if (parameters
->options().output_is_position_independent())
4752 Address off
= reloc
.get_r_offset();
4754 && data_shndx
== ppc_object
->opd_shndx()
4755 && ppc_object
->get_opd_discard(off
- 8))
4758 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4759 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
4760 if (data_shndx
!= ppc_object
->opd_shndx())
4761 symobj
= static_cast
4762 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
4763 rela_dyn
->add_output_section_relative(got
->output_section(),
4764 elfcpp::R_POWERPC_RELATIVE
,
4766 object
, data_shndx
, off
,
4767 symobj
->toc_base_offset());
4772 case elfcpp::R_PPC64_ADDR64
:
4774 && data_shndx
== ppc_object
->opd_shndx()
4775 && (gsym
->is_defined_in_discarded_section()
4776 || gsym
->object() != object
))
4778 ppc_object
->set_opd_discard(reloc
.get_r_offset());
4782 case elfcpp::R_PPC64_UADDR64
:
4783 case elfcpp::R_POWERPC_ADDR32
:
4784 case elfcpp::R_POWERPC_UADDR32
:
4785 case elfcpp::R_POWERPC_ADDR24
:
4786 case elfcpp::R_POWERPC_ADDR16
:
4787 case elfcpp::R_POWERPC_ADDR16_LO
:
4788 case elfcpp::R_POWERPC_ADDR16_HI
:
4789 case elfcpp::R_POWERPC_ADDR16_HA
:
4790 case elfcpp::R_POWERPC_UADDR16
:
4791 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4792 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4793 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4794 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4795 case elfcpp::R_PPC64_ADDR16_DS
:
4796 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4797 case elfcpp::R_POWERPC_ADDR14
:
4798 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4799 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4801 // Make a PLT entry if necessary.
4802 if (gsym
->needs_plt_entry())
4804 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4806 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4807 reloc
.get_r_addend());
4808 target
->make_plt_entry(symtab
, layout
, gsym
);
4809 // Since this is not a PC-relative relocation, we may be
4810 // taking the address of a function. In that case we need to
4811 // set the entry in the dynamic symbol table to the address of
4812 // the PLT call stub.
4814 && gsym
->is_from_dynobj()
4815 && !parameters
->options().output_is_position_independent())
4816 gsym
->set_needs_dynsym_value();
4818 // Make a dynamic relocation if necessary.
4819 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
))
4820 || (size
== 64 && gsym
->type() == elfcpp::STT_GNU_IFUNC
))
4822 if (gsym
->may_need_copy_reloc())
4824 target
->copy_reloc(symtab
, layout
, object
,
4825 data_shndx
, output_section
, gsym
, reloc
);
4827 else if ((size
== 32
4828 && r_type
== elfcpp::R_POWERPC_ADDR32
4829 && gsym
->can_use_relative_reloc(false)
4830 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
4831 && parameters
->options().shared()))
4833 && r_type
== elfcpp::R_PPC64_ADDR64
4834 && (gsym
->can_use_relative_reloc(false)
4835 || data_shndx
== ppc_object
->opd_shndx())))
4837 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4838 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4839 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
4841 rela_dyn
= target
->iplt_section()->rel_plt();
4842 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4844 rela_dyn
->add_symbolless_global_addend(
4845 gsym
, dynrel
, output_section
, object
, data_shndx
,
4846 reloc
.get_r_offset(), reloc
.get_r_addend());
4850 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4851 check_non_pic(object
, r_type
);
4852 rela_dyn
->add_global(gsym
, r_type
, output_section
,
4854 reloc
.get_r_offset(),
4855 reloc
.get_r_addend());
4861 case elfcpp::R_PPC_PLTREL24
:
4862 case elfcpp::R_POWERPC_REL24
:
4863 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4864 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4865 reloc
.get_r_addend());
4866 if (gsym
->needs_plt_entry()
4867 || (!gsym
->final_value_is_known()
4868 && (gsym
->is_undefined()
4869 || gsym
->is_from_dynobj()
4870 || gsym
->is_preemptible())))
4871 target
->make_plt_entry(symtab
, layout
, gsym
);
4874 case elfcpp::R_PPC64_REL64
:
4875 case elfcpp::R_POWERPC_REL32
:
4876 // Make a dynamic relocation if necessary.
4877 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
4879 if (gsym
->may_need_copy_reloc())
4881 target
->copy_reloc(symtab
, layout
, object
,
4882 data_shndx
, output_section
, gsym
,
4887 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4888 check_non_pic(object
, r_type
);
4889 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
4890 data_shndx
, reloc
.get_r_offset(),
4891 reloc
.get_r_addend());
4896 case elfcpp::R_POWERPC_REL14
:
4897 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4898 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4899 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4900 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
4901 reloc
.get_r_addend());
4904 case elfcpp::R_POWERPC_REL16
:
4905 case elfcpp::R_POWERPC_REL16_LO
:
4906 case elfcpp::R_POWERPC_REL16_HI
:
4907 case elfcpp::R_POWERPC_REL16_HA
:
4908 case elfcpp::R_POWERPC_SECTOFF
:
4909 case elfcpp::R_POWERPC_TPREL16
:
4910 case elfcpp::R_POWERPC_DTPREL16
:
4911 case elfcpp::R_POWERPC_SECTOFF_LO
:
4912 case elfcpp::R_POWERPC_TPREL16_LO
:
4913 case elfcpp::R_POWERPC_DTPREL16_LO
:
4914 case elfcpp::R_POWERPC_SECTOFF_HI
:
4915 case elfcpp::R_POWERPC_TPREL16_HI
:
4916 case elfcpp::R_POWERPC_DTPREL16_HI
:
4917 case elfcpp::R_POWERPC_SECTOFF_HA
:
4918 case elfcpp::R_POWERPC_TPREL16_HA
:
4919 case elfcpp::R_POWERPC_DTPREL16_HA
:
4920 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
4921 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4922 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
4923 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4924 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
4925 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4926 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
4927 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4928 case elfcpp::R_PPC64_TPREL16_DS
:
4929 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4930 case elfcpp::R_PPC64_DTPREL16_DS
:
4931 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
4932 case elfcpp::R_PPC64_SECTOFF_DS
:
4933 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
4934 case elfcpp::R_PPC64_TLSGD
:
4935 case elfcpp::R_PPC64_TLSLD
:
4938 case elfcpp::R_POWERPC_GOT16
:
4939 case elfcpp::R_POWERPC_GOT16_LO
:
4940 case elfcpp::R_POWERPC_GOT16_HI
:
4941 case elfcpp::R_POWERPC_GOT16_HA
:
4942 case elfcpp::R_PPC64_GOT16_DS
:
4943 case elfcpp::R_PPC64_GOT16_LO_DS
:
4945 // The symbol requires a GOT entry.
4946 Output_data_got_powerpc
<size
, big_endian
>* got
;
4948 got
= target
->got_section(symtab
, layout
);
4949 if (gsym
->final_value_is_known())
4951 if (size
== 32 && gsym
->type() == elfcpp::STT_GNU_IFUNC
)
4952 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
4954 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
4956 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
4958 // If we are generating a shared object or a pie, this
4959 // symbol's GOT entry will be set by a dynamic relocation.
4960 unsigned int off
= got
->add_constant(0);
4961 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
4963 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4964 if (gsym
->can_use_relative_reloc(false)
4966 && gsym
->visibility() == elfcpp::STV_PROTECTED
4967 && parameters
->options().shared()))
4969 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4970 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
4972 rela_dyn
= target
->iplt_section()->rel_plt();
4973 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4975 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
4979 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
4980 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
4986 case elfcpp::R_PPC64_TOC16
:
4987 case elfcpp::R_PPC64_TOC16_LO
:
4988 case elfcpp::R_PPC64_TOC16_HI
:
4989 case elfcpp::R_PPC64_TOC16_HA
:
4990 case elfcpp::R_PPC64_TOC16_DS
:
4991 case elfcpp::R_PPC64_TOC16_LO_DS
:
4992 // We need a GOT section.
4993 target
->got_section(symtab
, layout
);
4996 case elfcpp::R_POWERPC_GOT_TLSGD16
:
4997 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
4998 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
4999 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5001 const bool final
= gsym
->final_value_is_known();
5002 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5003 if (tls_type
== tls::TLSOPT_NONE
)
5005 Output_data_got_powerpc
<size
, big_endian
>* got
5006 = target
->got_section(symtab
, layout
);
5007 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
5008 target
->rela_dyn_section(layout
),
5009 elfcpp::R_POWERPC_DTPMOD
,
5010 elfcpp::R_POWERPC_DTPREL
);
5012 else if (tls_type
== tls::TLSOPT_TO_IE
)
5014 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
5016 Output_data_got_powerpc
<size
, big_endian
>* got
5017 = target
->got_section(symtab
, layout
);
5018 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5019 if (gsym
->is_undefined()
5020 || gsym
->is_from_dynobj())
5022 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
5023 elfcpp::R_POWERPC_TPREL
);
5027 unsigned int off
= got
->add_constant(0);
5028 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
5029 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
5030 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
5035 else if (tls_type
== tls::TLSOPT_TO_LE
)
5037 // no GOT relocs needed for Local Exec.
5044 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5045 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5046 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5047 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5049 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5050 if (tls_type
== tls::TLSOPT_NONE
)
5051 target
->tlsld_got_offset(symtab
, layout
, object
);
5052 else if (tls_type
== tls::TLSOPT_TO_LE
)
5054 // no GOT relocs needed for Local Exec.
5055 if (parameters
->options().emit_relocs())
5057 Output_section
* os
= layout
->tls_segment()->first_section();
5058 gold_assert(os
!= NULL
);
5059 os
->set_needs_symtab_index();
5067 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5068 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5069 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5070 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5072 Output_data_got_powerpc
<size
, big_endian
>* got
5073 = target
->got_section(symtab
, layout
);
5074 if (!gsym
->final_value_is_known()
5075 && (gsym
->is_from_dynobj()
5076 || gsym
->is_undefined()
5077 || gsym
->is_preemptible()))
5078 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
5079 target
->rela_dyn_section(layout
),
5080 elfcpp::R_POWERPC_DTPREL
);
5082 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
5086 case elfcpp::R_POWERPC_GOT_TPREL16
:
5087 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5088 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5089 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5091 const bool final
= gsym
->final_value_is_known();
5092 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
5093 if (tls_type
== tls::TLSOPT_NONE
)
5095 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
5097 Output_data_got_powerpc
<size
, big_endian
>* got
5098 = target
->got_section(symtab
, layout
);
5099 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5100 if (gsym
->is_undefined()
5101 || gsym
->is_from_dynobj())
5103 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
5104 elfcpp::R_POWERPC_TPREL
);
5108 unsigned int off
= got
->add_constant(0);
5109 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
5110 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
5111 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
5116 else if (tls_type
== tls::TLSOPT_TO_LE
)
5118 // no GOT relocs needed for Local Exec.
5126 unsupported_reloc_global(object
, r_type
, gsym
);
5131 // Process relocations for gc.
5133 template<int size
, bool big_endian
>
5135 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
5136 Symbol_table
* symtab
,
5138 Sized_relobj_file
<size
, big_endian
>* object
,
5139 unsigned int data_shndx
,
5141 const unsigned char* prelocs
,
5143 Output_section
* output_section
,
5144 bool needs_special_offset_handling
,
5145 size_t local_symbol_count
,
5146 const unsigned char* plocal_symbols
)
5148 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5149 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
5150 Powerpc_relobj
<size
, big_endian
>* ppc_object
5151 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5153 ppc_object
->set_opd_valid();
5154 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
5156 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
5157 for (p
= ppc_object
->access_from_map()->begin();
5158 p
!= ppc_object
->access_from_map()->end();
5161 Address dst_off
= p
->first
;
5162 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
5163 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
5164 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
5166 Object
* src_obj
= s
->first
;
5167 unsigned int src_indx
= s
->second
;
5168 symtab
->gc()->add_reference(src_obj
, src_indx
,
5169 ppc_object
, dst_indx
);
5173 ppc_object
->access_from_map()->clear();
5174 ppc_object
->process_gc_mark(symtab
);
5175 // Don't look at .opd relocs as .opd will reference everything.
5179 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
5180 typename
Target_powerpc::Relocatable_size_for_reloc
>(
5189 needs_special_offset_handling
,
5194 // Handle target specific gc actions when adding a gc reference from
5195 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
5196 // and DST_OFF. For powerpc64, this adds a referenc to the code
5197 // section of a function descriptor.
5199 template<int size
, bool big_endian
>
5201 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
5202 Symbol_table
* symtab
,
5204 unsigned int src_shndx
,
5206 unsigned int dst_shndx
,
5207 Address dst_off
) const
5209 Powerpc_relobj
<size
, big_endian
>* ppc_object
5210 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
5212 && !ppc_object
->is_dynamic()
5213 && dst_shndx
== ppc_object
->opd_shndx())
5215 if (ppc_object
->opd_valid())
5217 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
5218 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
5222 // If we haven't run scan_opd_relocs, we must delay
5223 // processing this function descriptor reference.
5224 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
5229 // Add any special sections for this symbol to the gc work list.
5230 // For powerpc64, this adds the code section of a function
5233 template<int size
, bool big_endian
>
5235 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
5236 Symbol_table
* symtab
,
5241 Powerpc_relobj
<size
, big_endian
>* ppc_object
5242 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
5244 unsigned int shndx
= sym
->shndx(&is_ordinary
);
5245 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
5247 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
5248 Address dst_off
= gsym
->value();
5249 if (ppc_object
->opd_valid())
5251 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
5252 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
5255 ppc_object
->add_gc_mark(dst_off
);
5260 // Scan relocations for a section.
5262 template<int size
, bool big_endian
>
5264 Target_powerpc
<size
, big_endian
>::scan_relocs(
5265 Symbol_table
* symtab
,
5267 Sized_relobj_file
<size
, big_endian
>* object
,
5268 unsigned int data_shndx
,
5269 unsigned int sh_type
,
5270 const unsigned char* prelocs
,
5272 Output_section
* output_section
,
5273 bool needs_special_offset_handling
,
5274 size_t local_symbol_count
,
5275 const unsigned char* plocal_symbols
)
5277 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5278 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
5280 if (sh_type
== elfcpp::SHT_REL
)
5282 gold_error(_("%s: unsupported REL reloc section"),
5283 object
->name().c_str());
5287 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
5296 needs_special_offset_handling
,
5301 // Functor class for processing the global symbol table.
5302 // Removes symbols defined on discarded opd entries.
5304 template<bool big_endian
>
5305 class Global_symbol_visitor_opd
5308 Global_symbol_visitor_opd()
5312 operator()(Sized_symbol
<64>* sym
)
5314 if (sym
->has_symtab_index()
5315 || sym
->source() != Symbol::FROM_OBJECT
5316 || !sym
->in_real_elf())
5319 Powerpc_relobj
<64, big_endian
>* symobj
5320 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
5321 if (symobj
->is_dynamic()
5322 || symobj
->opd_shndx() == 0)
5326 unsigned int shndx
= sym
->shndx(&is_ordinary
);
5327 if (shndx
== symobj
->opd_shndx()
5328 && symobj
->get_opd_discard(sym
->value()))
5329 sym
->set_symtab_index(-1U);
5333 template<int size
, bool big_endian
>
5335 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
5337 Symbol_table
* symtab
)
5341 Output_data_save_res
<64, big_endian
>* savres
5342 = new Output_data_save_res
<64, big_endian
>(symtab
);
5343 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5344 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5345 savres
, ORDER_TEXT
, false);
5349 // Finalize the sections.
5351 template<int size
, bool big_endian
>
5353 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
5355 const Input_objects
*,
5356 Symbol_table
* symtab
)
5358 if (parameters
->doing_static_link())
5360 // At least some versions of glibc elf-init.o have a strong
5361 // reference to __rela_iplt marker syms. A weak ref would be
5363 if (this->iplt_
!= NULL
)
5365 Reloc_section
* rel
= this->iplt_
->rel_plt();
5366 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
5367 Symbol_table::PREDEFINED
, rel
, 0, 0,
5368 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5369 elfcpp::STV_HIDDEN
, 0, false, true);
5370 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
5371 Symbol_table::PREDEFINED
, rel
, 0, 0,
5372 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5373 elfcpp::STV_HIDDEN
, 0, true, true);
5377 symtab
->define_as_constant("__rela_iplt_start", NULL
,
5378 Symbol_table::PREDEFINED
, 0, 0,
5379 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5380 elfcpp::STV_HIDDEN
, 0, true, false);
5381 symtab
->define_as_constant("__rela_iplt_end", NULL
,
5382 Symbol_table::PREDEFINED
, 0, 0,
5383 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5384 elfcpp::STV_HIDDEN
, 0, true, false);
5390 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
5391 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
5393 if (!parameters
->options().relocatable())
5395 this->define_save_restore_funcs(layout
, symtab
);
5397 // Annoyingly, we need to make these sections now whether or
5398 // not we need them. If we delay until do_relax then we
5399 // need to mess with the relaxation machinery checkpointing.
5400 this->got_section(symtab
, layout
);
5401 this->make_brlt_section(layout
);
5405 // Fill in some more dynamic tags.
5406 Output_data_dynamic
* odyn
= layout
->dynamic_data();
5409 const Reloc_section
* rel_plt
= (this->plt_
== NULL
5411 : this->plt_
->rel_plt());
5412 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
5413 this->rela_dyn_
, true, size
== 32);
5417 if (this->got_
!= NULL
)
5419 this->got_
->finalize_data_size();
5420 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
5421 this->got_
, this->got_
->g_o_t());
5426 if (this->glink_
!= NULL
)
5428 this->glink_
->finalize_data_size();
5429 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
5431 (this->glink_
->pltresolve_size
5437 // Emit any relocs we saved in an attempt to avoid generating COPY
5439 if (this->copy_relocs_
.any_saved_relocs())
5440 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
5443 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
5447 ok_lo_toc_insn(uint32_t insn
)
5449 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
5450 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
5451 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
5452 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
5453 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
5454 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
5455 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
5456 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
5457 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
5458 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
5459 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
5460 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
5461 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
5462 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
5463 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
5465 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
5466 && ((insn
& 3) == 0 || (insn
& 3) == 3))
5467 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
5470 // Return the value to use for a branch relocation.
5472 template<int size
, bool big_endian
>
5473 typename
elfcpp::Elf_types
<size
>::Elf_Addr
5474 Target_powerpc
<size
, big_endian
>::symval_for_branch(
5476 const Sized_symbol
<size
>* gsym
,
5477 Powerpc_relobj
<size
, big_endian
>* object
,
5478 unsigned int *dest_shndx
)
5484 // If the symbol is defined in an opd section, ie. is a function
5485 // descriptor, use the function descriptor code entry address
5486 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
5488 && gsym
->source() != Symbol::FROM_OBJECT
)
5491 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
5492 unsigned int shndx
= symobj
->opd_shndx();
5495 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
5496 gold_assert(opd_addr
!= invalid_address
);
5497 opd_addr
+= symobj
->output_section(shndx
)->address();
5498 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
5501 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
5502 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
5503 gold_assert(sec_addr
!= invalid_address
);
5504 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
5505 value
= sec_addr
+ sec_off
;
5510 // Perform a relocation.
5512 template<int size
, bool big_endian
>
5514 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
5515 const Relocate_info
<size
, big_endian
>* relinfo
,
5516 Target_powerpc
* target
,
5519 const elfcpp::Rela
<size
, big_endian
>& rela
,
5520 unsigned int r_type
,
5521 const Sized_symbol
<size
>* gsym
,
5522 const Symbol_value
<size
>* psymval
,
5523 unsigned char* view
,
5525 section_size_type view_size
)
5527 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
5528 || r_type
== elfcpp::R_PPC_PLTREL24
)
5530 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
5531 enum skip_tls last_tls
= this->call_tls_get_addr_
;
5532 this->call_tls_get_addr_
= CALL_NOT_EXPECTED
;
5535 if (last_tls
== CALL_NOT_EXPECTED
)
5536 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5537 _("__tls_get_addr call lacks marker reloc"));
5538 else if (last_tls
== CALL_SKIP
)
5541 else if (last_tls
!= CALL_NOT_EXPECTED
)
5542 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5543 _("missing expected __tls_get_addr call"));
5545 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
5546 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
5547 Powerpc_relobj
<size
, big_endian
>* const object
5548 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
5550 bool has_plt_value
= false;
5551 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
5553 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
))
5554 : object
->local_has_plt_offset(r_sym
))
5556 Stub_table
<size
, big_endian
>* stub_table
5557 = object
->stub_table(relinfo
->data_shndx
);
5558 if (stub_table
== NULL
)
5560 // This is a ref from a data section to an ifunc symbol.
5561 if (target
->stub_tables().size() != 0)
5562 stub_table
= target
->stub_tables()[0];
5564 gold_assert(stub_table
!= NULL
);
5567 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
5568 rela
.get_r_addend());
5570 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
5571 rela
.get_r_addend());
5572 gold_assert(off
!= invalid_address
);
5573 value
= stub_table
->stub_address() + off
;
5574 has_plt_value
= true;
5577 if (r_type
== elfcpp::R_POWERPC_GOT16
5578 || r_type
== elfcpp::R_POWERPC_GOT16_LO
5579 || r_type
== elfcpp::R_POWERPC_GOT16_HI
5580 || r_type
== elfcpp::R_POWERPC_GOT16_HA
5581 || r_type
== elfcpp::R_PPC64_GOT16_DS
5582 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
5586 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
5587 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
5591 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
5592 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
5593 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
5595 value
-= target
->got_section()->got_base_offset(object
);
5597 else if (r_type
== elfcpp::R_PPC64_TOC
)
5599 value
= (target
->got_section()->output_section()->address()
5600 + object
->toc_base_offset());
5602 else if (gsym
!= NULL
5603 && (r_type
== elfcpp::R_POWERPC_REL24
5604 || r_type
== elfcpp::R_PPC_PLTREL24
)
5609 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
5610 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
5611 bool can_plt_call
= false;
5612 if (rela
.get_r_offset() + 8 <= view_size
)
5614 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
5615 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
5618 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
5620 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
5621 can_plt_call
= true;
5626 // If we don't have a branch and link followed by a nop,
5627 // we can't go via the plt because there is no place to
5628 // put a toc restoring instruction.
5629 // Unless we know we won't be returning.
5630 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
5631 can_plt_call
= true;
5635 // This is not an error in one special case: A self
5636 // call. It isn't possible to cheaply verify we have
5637 // such a call so just check for a call to the same
5640 Address code
= value
;
5641 if (gsym
->source() == Symbol::FROM_OBJECT
5642 && gsym
->object() == object
)
5644 Address addend
= rela
.get_r_addend();
5645 unsigned int dest_shndx
;
5646 Address opdent
= psymval
->value(object
, addend
);
5647 code
= target
->symval_for_branch(opdent
, gsym
, object
,
5650 if (dest_shndx
== 0)
5651 dest_shndx
= gsym
->shndx(&is_ordinary
);
5652 ok
= dest_shndx
== relinfo
->data_shndx
;
5656 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
5657 _("call lacks nop, can't restore toc; "
5658 "recompile with -fPIC"));
5664 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5665 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
5666 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
5667 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
5669 // First instruction of a global dynamic sequence, arg setup insn.
5670 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5671 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5672 enum Got_type got_type
= GOT_TYPE_STANDARD
;
5673 if (tls_type
== tls::TLSOPT_NONE
)
5674 got_type
= GOT_TYPE_TLSGD
;
5675 else if (tls_type
== tls::TLSOPT_TO_IE
)
5676 got_type
= GOT_TYPE_TPREL
;
5677 if (got_type
!= GOT_TYPE_STANDARD
)
5681 gold_assert(gsym
->has_got_offset(got_type
));
5682 value
= gsym
->got_offset(got_type
);
5686 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
5687 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
5688 value
= object
->local_got_offset(r_sym
, got_type
);
5690 value
-= target
->got_section()->got_base_offset(object
);
5692 if (tls_type
== tls::TLSOPT_TO_IE
)
5694 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5695 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
5697 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5698 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
5699 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
5701 insn
|= 32 << 26; // lwz
5703 insn
|= 58 << 26; // ld
5704 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5706 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
5707 - elfcpp::R_POWERPC_GOT_TLSGD16
);
5709 else if (tls_type
== tls::TLSOPT_TO_LE
)
5711 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
5712 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
5714 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5715 Insn insn
= addis_3_13
;
5718 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5719 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5720 value
= psymval
->value(object
, rela
.get_r_addend());
5724 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5726 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5727 r_type
= elfcpp::R_POWERPC_NONE
;
5731 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5732 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
5733 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
5734 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
5736 // First instruction of a local dynamic sequence, arg setup insn.
5737 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5738 if (tls_type
== tls::TLSOPT_NONE
)
5740 value
= target
->tlsld_got_offset();
5741 value
-= target
->got_section()->got_base_offset(object
);
5745 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
5746 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
5747 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
5749 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5750 Insn insn
= addis_3_13
;
5753 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5754 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5759 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5761 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5762 r_type
= elfcpp::R_POWERPC_NONE
;
5766 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
5767 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
5768 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
5769 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
5771 // Accesses relative to a local dynamic sequence address,
5772 // no optimisation here.
5775 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
5776 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
5780 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
5781 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
5782 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
5784 value
-= target
->got_section()->got_base_offset(object
);
5786 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5787 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
5788 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
5789 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
5791 // First instruction of initial exec sequence.
5792 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5793 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
5794 if (tls_type
== tls::TLSOPT_NONE
)
5798 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
5799 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
5803 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
5804 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
5805 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
5807 value
-= target
->got_section()->got_base_offset(object
);
5811 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
5812 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
5813 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
5815 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5816 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
5817 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
5822 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5823 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
5824 value
= psymval
->value(object
, rela
.get_r_addend());
5828 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
5830 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5831 r_type
= elfcpp::R_POWERPC_NONE
;
5835 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5836 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5838 // Second instruction of a global dynamic sequence,
5839 // the __tls_get_addr call
5840 this->call_tls_get_addr_
= CALL_EXPECTED
;
5841 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5842 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5843 if (tls_type
!= tls::TLSOPT_NONE
)
5845 if (tls_type
== tls::TLSOPT_TO_IE
)
5847 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
5848 Insn insn
= add_3_3_13
;
5851 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5852 r_type
= elfcpp::R_POWERPC_NONE
;
5856 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
5857 Insn insn
= addi_3_3
;
5858 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5859 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5860 view
+= 2 * big_endian
;
5861 value
= psymval
->value(object
, rela
.get_r_addend());
5863 this->call_tls_get_addr_
= CALL_SKIP
;
5866 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5867 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5869 // Second instruction of a local dynamic sequence,
5870 // the __tls_get_addr call
5871 this->call_tls_get_addr_
= CALL_EXPECTED
;
5872 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5873 if (tls_type
== tls::TLSOPT_TO_LE
)
5875 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
5876 Insn insn
= addi_3_3
;
5877 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5878 this->call_tls_get_addr_
= CALL_SKIP
;
5879 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5880 view
+= 2 * big_endian
;
5884 else if (r_type
== elfcpp::R_POWERPC_TLS
)
5886 // Second instruction of an initial exec sequence
5887 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
5888 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
5889 if (tls_type
== tls::TLSOPT_TO_LE
)
5891 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
5892 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
5893 unsigned int reg
= size
== 32 ? 2 : 13;
5894 insn
= at_tls_transform(insn
, reg
);
5895 gold_assert(insn
!= 0);
5896 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
5897 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
5898 view
+= 2 * big_endian
;
5899 value
= psymval
->value(object
, rela
.get_r_addend());
5902 else if (!has_plt_value
)
5905 unsigned int dest_shndx
;
5906 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
5907 addend
= rela
.get_r_addend();
5908 value
= psymval
->value(object
, addend
);
5909 if (size
== 64 && is_branch_reloc(r_type
))
5910 value
= target
->symval_for_branch(value
, gsym
, object
, &dest_shndx
);
5911 unsigned int max_branch_offset
= 0;
5912 if (r_type
== elfcpp::R_POWERPC_REL24
5913 || r_type
== elfcpp::R_PPC_PLTREL24
5914 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
5915 max_branch_offset
= 1 << 25;
5916 else if (r_type
== elfcpp::R_POWERPC_REL14
5917 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
5918 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
5919 max_branch_offset
= 1 << 15;
5920 if (max_branch_offset
!= 0
5921 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
5923 Stub_table
<size
, big_endian
>* stub_table
5924 = object
->stub_table(relinfo
->data_shndx
);
5925 gold_assert(stub_table
!= NULL
);
5926 Address off
= stub_table
->find_long_branch_entry(object
, value
);
5927 if (off
!= invalid_address
)
5928 value
= stub_table
->stub_address() + stub_table
->plt_size() + off
;
5934 case elfcpp::R_PPC64_REL64
:
5935 case elfcpp::R_POWERPC_REL32
:
5936 case elfcpp::R_POWERPC_REL24
:
5937 case elfcpp::R_PPC_PLTREL24
:
5938 case elfcpp::R_PPC_LOCAL24PC
:
5939 case elfcpp::R_POWERPC_REL16
:
5940 case elfcpp::R_POWERPC_REL16_LO
:
5941 case elfcpp::R_POWERPC_REL16_HI
:
5942 case elfcpp::R_POWERPC_REL16_HA
:
5943 case elfcpp::R_POWERPC_REL14
:
5944 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5945 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5949 case elfcpp::R_PPC64_TOC16
:
5950 case elfcpp::R_PPC64_TOC16_LO
:
5951 case elfcpp::R_PPC64_TOC16_HI
:
5952 case elfcpp::R_PPC64_TOC16_HA
:
5953 case elfcpp::R_PPC64_TOC16_DS
:
5954 case elfcpp::R_PPC64_TOC16_LO_DS
:
5955 // Subtract the TOC base address.
5956 value
-= (target
->got_section()->output_section()->address()
5957 + object
->toc_base_offset());
5960 case elfcpp::R_POWERPC_SECTOFF
:
5961 case elfcpp::R_POWERPC_SECTOFF_LO
:
5962 case elfcpp::R_POWERPC_SECTOFF_HI
:
5963 case elfcpp::R_POWERPC_SECTOFF_HA
:
5964 case elfcpp::R_PPC64_SECTOFF_DS
:
5965 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5967 value
-= os
->address();
5970 case elfcpp::R_PPC64_TPREL16_DS
:
5971 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5973 // R_PPC_TLSGD and R_PPC_TLSLD
5975 case elfcpp::R_POWERPC_TPREL16
:
5976 case elfcpp::R_POWERPC_TPREL16_LO
:
5977 case elfcpp::R_POWERPC_TPREL16_HI
:
5978 case elfcpp::R_POWERPC_TPREL16_HA
:
5979 case elfcpp::R_POWERPC_TPREL
:
5980 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5981 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5982 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5983 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5984 // tls symbol values are relative to tls_segment()->vaddr()
5988 case elfcpp::R_PPC64_DTPREL16_DS
:
5989 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5990 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5991 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5992 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5993 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5995 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
5996 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
5998 case elfcpp::R_POWERPC_DTPREL16
:
5999 case elfcpp::R_POWERPC_DTPREL16_LO
:
6000 case elfcpp::R_POWERPC_DTPREL16_HI
:
6001 case elfcpp::R_POWERPC_DTPREL16_HA
:
6002 case elfcpp::R_POWERPC_DTPREL
:
6003 // tls symbol values are relative to tls_segment()->vaddr()
6004 value
-= dtp_offset
;
6011 Insn branch_bit
= 0;
6014 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6015 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6016 branch_bit
= 1 << 21;
6017 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6018 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6020 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6021 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6024 if (this->is_isa_v2
)
6026 // Set 'a' bit. This is 0b00010 in BO field for branch
6027 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
6028 // for branch on CTR insns (BO == 1a00t or 1a01t).
6029 if ((insn
& (0x14 << 21)) == (0x04 << 21))
6031 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
6038 // Invert 'y' bit if not the default.
6039 if (static_cast<Signed_address
>(value
) < 0)
6042 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6052 // Multi-instruction sequences that access the TOC can be
6053 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
6054 // to nop; addi rb,r2,x;
6060 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6061 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6062 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6063 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6064 case elfcpp::R_POWERPC_GOT16_HA
:
6065 case elfcpp::R_PPC64_TOC16_HA
:
6066 if (!parameters
->options().no_toc_optimize())
6068 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6069 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6070 if ((insn
& ((0x3f << 26) | 0x1f << 16))
6071 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
6072 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6073 _("toc optimization is not supported "
6074 "for %#08x instruction"), insn
);
6075 else if (value
+ 0x8000 < 0x10000)
6077 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
6083 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6084 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6085 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6086 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6087 case elfcpp::R_POWERPC_GOT16_LO
:
6088 case elfcpp::R_PPC64_GOT16_LO_DS
:
6089 case elfcpp::R_PPC64_TOC16_LO
:
6090 case elfcpp::R_PPC64_TOC16_LO_DS
:
6091 if (!parameters
->options().no_toc_optimize())
6093 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6094 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6095 if (!ok_lo_toc_insn(insn
))
6096 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6097 _("toc optimization is not supported "
6098 "for %#08x instruction"), insn
);
6099 else if (value
+ 0x8000 < 0x10000)
6101 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
6103 // Transform addic to addi when we change reg.
6104 insn
&= ~((0x3f << 26) | (0x1f << 16));
6105 insn
|= (14u << 26) | (2 << 16);
6109 insn
&= ~(0x1f << 16);
6112 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6119 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
6122 case elfcpp::R_POWERPC_ADDR32
:
6123 case elfcpp::R_POWERPC_UADDR32
:
6125 overflow
= Reloc::CHECK_BITFIELD
;
6128 case elfcpp::R_POWERPC_REL32
:
6130 overflow
= Reloc::CHECK_SIGNED
;
6133 case elfcpp::R_POWERPC_ADDR24
:
6134 case elfcpp::R_POWERPC_ADDR16
:
6135 case elfcpp::R_POWERPC_UADDR16
:
6136 case elfcpp::R_PPC64_ADDR16_DS
:
6137 case elfcpp::R_POWERPC_ADDR14
:
6138 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6139 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6140 overflow
= Reloc::CHECK_BITFIELD
;
6143 case elfcpp::R_POWERPC_REL24
:
6144 case elfcpp::R_PPC_PLTREL24
:
6145 case elfcpp::R_PPC_LOCAL24PC
:
6146 case elfcpp::R_POWERPC_REL16
:
6147 case elfcpp::R_PPC64_TOC16
:
6148 case elfcpp::R_POWERPC_GOT16
:
6149 case elfcpp::R_POWERPC_SECTOFF
:
6150 case elfcpp::R_POWERPC_TPREL16
:
6151 case elfcpp::R_POWERPC_DTPREL16
:
6152 case elfcpp::R_PPC64_TPREL16_DS
:
6153 case elfcpp::R_PPC64_DTPREL16_DS
:
6154 case elfcpp::R_PPC64_TOC16_DS
:
6155 case elfcpp::R_PPC64_GOT16_DS
:
6156 case elfcpp::R_PPC64_SECTOFF_DS
:
6157 case elfcpp::R_POWERPC_REL14
:
6158 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6159 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6160 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6161 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6162 case elfcpp::R_POWERPC_GOT_TPREL16
:
6163 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6164 overflow
= Reloc::CHECK_SIGNED
;
6168 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
6169 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
6172 case elfcpp::R_POWERPC_NONE
:
6173 case elfcpp::R_POWERPC_TLS
:
6174 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6175 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6176 case elfcpp::R_PPC_EMB_MRKREF
:
6179 case elfcpp::R_PPC64_ADDR64
:
6180 case elfcpp::R_PPC64_REL64
:
6181 case elfcpp::R_PPC64_TOC
:
6182 Reloc::addr64(view
, value
);
6185 case elfcpp::R_POWERPC_TPREL
:
6186 case elfcpp::R_POWERPC_DTPREL
:
6188 Reloc::addr64(view
, value
);
6190 status
= Reloc::addr32(view
, value
, overflow
);
6193 case elfcpp::R_PPC64_UADDR64
:
6194 Reloc::addr64_u(view
, value
);
6197 case elfcpp::R_POWERPC_ADDR32
:
6198 status
= Reloc::addr32(view
, value
, overflow
);
6201 case elfcpp::R_POWERPC_REL32
:
6202 case elfcpp::R_POWERPC_UADDR32
:
6203 status
= Reloc::addr32_u(view
, value
, overflow
);
6206 case elfcpp::R_POWERPC_ADDR24
:
6207 case elfcpp::R_POWERPC_REL24
:
6208 case elfcpp::R_PPC_PLTREL24
:
6209 case elfcpp::R_PPC_LOCAL24PC
:
6210 status
= Reloc::addr24(view
, value
, overflow
);
6213 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6214 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6217 status
= Reloc::addr16_ds(view
, value
, overflow
);
6220 case elfcpp::R_POWERPC_ADDR16
:
6221 case elfcpp::R_POWERPC_REL16
:
6222 case elfcpp::R_PPC64_TOC16
:
6223 case elfcpp::R_POWERPC_GOT16
:
6224 case elfcpp::R_POWERPC_SECTOFF
:
6225 case elfcpp::R_POWERPC_TPREL16
:
6226 case elfcpp::R_POWERPC_DTPREL16
:
6227 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6228 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6229 case elfcpp::R_POWERPC_GOT_TPREL16
:
6230 case elfcpp::R_POWERPC_ADDR16_LO
:
6231 case elfcpp::R_POWERPC_REL16_LO
:
6232 case elfcpp::R_PPC64_TOC16_LO
:
6233 case elfcpp::R_POWERPC_GOT16_LO
:
6234 case elfcpp::R_POWERPC_SECTOFF_LO
:
6235 case elfcpp::R_POWERPC_TPREL16_LO
:
6236 case elfcpp::R_POWERPC_DTPREL16_LO
:
6237 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6238 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6239 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6240 status
= Reloc::addr16(view
, value
, overflow
);
6243 case elfcpp::R_POWERPC_UADDR16
:
6244 status
= Reloc::addr16_u(view
, value
, overflow
);
6247 case elfcpp::R_POWERPC_ADDR16_HI
:
6248 case elfcpp::R_POWERPC_REL16_HI
:
6249 case elfcpp::R_PPC64_TOC16_HI
:
6250 case elfcpp::R_POWERPC_GOT16_HI
:
6251 case elfcpp::R_POWERPC_SECTOFF_HI
:
6252 case elfcpp::R_POWERPC_TPREL16_HI
:
6253 case elfcpp::R_POWERPC_DTPREL16_HI
:
6254 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6255 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6256 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6257 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6258 Reloc::addr16_hi(view
, value
);
6261 case elfcpp::R_POWERPC_ADDR16_HA
:
6262 case elfcpp::R_POWERPC_REL16_HA
:
6263 case elfcpp::R_PPC64_TOC16_HA
:
6264 case elfcpp::R_POWERPC_GOT16_HA
:
6265 case elfcpp::R_POWERPC_SECTOFF_HA
:
6266 case elfcpp::R_POWERPC_TPREL16_HA
:
6267 case elfcpp::R_POWERPC_DTPREL16_HA
:
6268 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6269 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6270 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6271 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6272 Reloc::addr16_ha(view
, value
);
6275 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6277 // R_PPC_EMB_NADDR16_LO
6279 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6280 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6281 Reloc::addr16_hi2(view
, value
);
6284 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6286 // R_PPC_EMB_NADDR16_HI
6288 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6289 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6290 Reloc::addr16_ha2(view
, value
);
6293 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6295 // R_PPC_EMB_NADDR16_HA
6297 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6298 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6299 Reloc::addr16_hi3(view
, value
);
6302 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6306 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6307 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6308 Reloc::addr16_ha3(view
, value
);
6311 case elfcpp::R_PPC64_DTPREL16_DS
:
6312 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6314 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
6316 case elfcpp::R_PPC64_TPREL16_DS
:
6317 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6319 // R_PPC_TLSGD, R_PPC_TLSLD
6321 case elfcpp::R_PPC64_ADDR16_DS
:
6322 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6323 case elfcpp::R_PPC64_TOC16_DS
:
6324 case elfcpp::R_PPC64_TOC16_LO_DS
:
6325 case elfcpp::R_PPC64_GOT16_DS
:
6326 case elfcpp::R_PPC64_GOT16_LO_DS
:
6327 case elfcpp::R_PPC64_SECTOFF_DS
:
6328 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6329 status
= Reloc::addr16_ds(view
, value
, overflow
);
6332 case elfcpp::R_POWERPC_ADDR14
:
6333 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6334 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6335 case elfcpp::R_POWERPC_REL14
:
6336 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6337 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6338 status
= Reloc::addr14(view
, value
, overflow
);
6341 case elfcpp::R_POWERPC_COPY
:
6342 case elfcpp::R_POWERPC_GLOB_DAT
:
6343 case elfcpp::R_POWERPC_JMP_SLOT
:
6344 case elfcpp::R_POWERPC_RELATIVE
:
6345 case elfcpp::R_POWERPC_DTPMOD
:
6346 case elfcpp::R_PPC64_JMP_IREL
:
6347 case elfcpp::R_POWERPC_IRELATIVE
:
6348 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6349 _("unexpected reloc %u in object file"),
6353 case elfcpp::R_PPC_EMB_SDA21
:
6358 // R_PPC64_TOCSAVE. For the time being this can be ignored.
6362 case elfcpp::R_PPC_EMB_SDA2I16
:
6363 case elfcpp::R_PPC_EMB_SDA2REL
:
6366 // R_PPC64_TLSGD, R_PPC64_TLSLD
6369 case elfcpp::R_POWERPC_PLT32
:
6370 case elfcpp::R_POWERPC_PLTREL32
:
6371 case elfcpp::R_POWERPC_PLT16_LO
:
6372 case elfcpp::R_POWERPC_PLT16_HI
:
6373 case elfcpp::R_POWERPC_PLT16_HA
:
6374 case elfcpp::R_PPC_SDAREL16
:
6375 case elfcpp::R_POWERPC_ADDR30
:
6376 case elfcpp::R_PPC64_PLT64
:
6377 case elfcpp::R_PPC64_PLTREL64
:
6378 case elfcpp::R_PPC64_PLTGOT16
:
6379 case elfcpp::R_PPC64_PLTGOT16_LO
:
6380 case elfcpp::R_PPC64_PLTGOT16_HI
:
6381 case elfcpp::R_PPC64_PLTGOT16_HA
:
6382 case elfcpp::R_PPC64_PLT16_LO_DS
:
6383 case elfcpp::R_PPC64_PLTGOT16_DS
:
6384 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
6385 case elfcpp::R_PPC_EMB_RELSEC16
:
6386 case elfcpp::R_PPC_EMB_RELST_LO
:
6387 case elfcpp::R_PPC_EMB_RELST_HI
:
6388 case elfcpp::R_PPC_EMB_RELST_HA
:
6389 case elfcpp::R_PPC_EMB_BIT_FLD
:
6390 case elfcpp::R_PPC_EMB_RELSDA
:
6391 case elfcpp::R_PPC_TOC16
:
6394 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6395 _("unsupported reloc %u"),
6399 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
6400 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6401 _("relocation overflow"));
6406 // Relocate section data.
6408 template<int size
, bool big_endian
>
6410 Target_powerpc
<size
, big_endian
>::relocate_section(
6411 const Relocate_info
<size
, big_endian
>* relinfo
,
6412 unsigned int sh_type
,
6413 const unsigned char* prelocs
,
6415 Output_section
* output_section
,
6416 bool needs_special_offset_handling
,
6417 unsigned char* view
,
6419 section_size_type view_size
,
6420 const Reloc_symbol_changes
* reloc_symbol_changes
)
6422 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6423 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
6424 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
6425 Powerpc_comdat_behavior
;
6427 gold_assert(sh_type
== elfcpp::SHT_RELA
);
6429 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
6430 Powerpc_relocate
, Powerpc_comdat_behavior
>(
6436 needs_special_offset_handling
,
6440 reloc_symbol_changes
);
6443 class Powerpc_scan_relocatable_reloc
6446 // Return the strategy to use for a local symbol which is not a
6447 // section symbol, given the relocation type.
6448 inline Relocatable_relocs::Reloc_strategy
6449 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
6451 if (r_type
== 0 && r_sym
== 0)
6452 return Relocatable_relocs::RELOC_DISCARD
;
6453 return Relocatable_relocs::RELOC_COPY
;
6456 // Return the strategy to use for a local symbol which is a section
6457 // symbol, given the relocation type.
6458 inline Relocatable_relocs::Reloc_strategy
6459 local_section_strategy(unsigned int, Relobj
*)
6461 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
6464 // Return the strategy to use for a global symbol, given the
6465 // relocation type, the object, and the symbol index.
6466 inline Relocatable_relocs::Reloc_strategy
6467 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
6469 if (r_type
== elfcpp::R_PPC_PLTREL24
)
6470 return Relocatable_relocs::RELOC_SPECIAL
;
6471 return Relocatable_relocs::RELOC_COPY
;
6475 // Scan the relocs during a relocatable link.
6477 template<int size
, bool big_endian
>
6479 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
6480 Symbol_table
* symtab
,
6482 Sized_relobj_file
<size
, big_endian
>* object
,
6483 unsigned int data_shndx
,
6484 unsigned int sh_type
,
6485 const unsigned char* prelocs
,
6487 Output_section
* output_section
,
6488 bool needs_special_offset_handling
,
6489 size_t local_symbol_count
,
6490 const unsigned char* plocal_symbols
,
6491 Relocatable_relocs
* rr
)
6493 gold_assert(sh_type
== elfcpp::SHT_RELA
);
6495 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
6496 Powerpc_scan_relocatable_reloc
>(
6504 needs_special_offset_handling
,
6510 // Emit relocations for a section.
6511 // This is a modified version of the function by the same name in
6512 // target-reloc.h. Using relocate_special_relocatable for
6513 // R_PPC_PLTREL24 would require duplication of the entire body of the
6514 // loop, so we may as well duplicate the whole thing.
6516 template<int size
, bool big_endian
>
6518 Target_powerpc
<size
, big_endian
>::relocate_relocs(
6519 const Relocate_info
<size
, big_endian
>* relinfo
,
6520 unsigned int sh_type
,
6521 const unsigned char* prelocs
,
6523 Output_section
* output_section
,
6524 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
6525 const Relocatable_relocs
* rr
,
6527 Address view_address
,
6529 unsigned char* reloc_view
,
6530 section_size_type reloc_view_size
)
6532 gold_assert(sh_type
== elfcpp::SHT_RELA
);
6534 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
6536 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
6538 const int reloc_size
6539 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
6541 Powerpc_relobj
<size
, big_endian
>* const object
6542 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
6543 const unsigned int local_count
= object
->local_symbol_count();
6544 unsigned int got2_shndx
= object
->got2_shndx();
6545 Address got2_addend
= 0;
6546 if (got2_shndx
!= 0)
6548 got2_addend
= object
->get_output_section_offset(got2_shndx
);
6549 gold_assert(got2_addend
!= invalid_address
);
6552 unsigned char* pwrite
= reloc_view
;
6553 bool zap_next
= false;
6554 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
6556 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
6557 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
6560 Reltype
reloc(prelocs
);
6561 Reltype_write
reloc_write(pwrite
);
6563 Address offset
= reloc
.get_r_offset();
6564 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
6565 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
6566 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
6567 const unsigned int orig_r_sym
= r_sym
;
6568 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
6569 = reloc
.get_r_addend();
6570 const Symbol
* gsym
= NULL
;
6574 // We could arrange to discard these and other relocs for
6575 // tls optimised sequences in the strategy methods, but for
6576 // now do as BFD ld does.
6577 r_type
= elfcpp::R_POWERPC_NONE
;
6581 // Get the new symbol index.
6582 if (r_sym
< local_count
)
6586 case Relocatable_relocs::RELOC_COPY
:
6587 case Relocatable_relocs::RELOC_SPECIAL
:
6590 r_sym
= object
->symtab_index(r_sym
);
6591 gold_assert(r_sym
!= -1U);
6595 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
6597 // We are adjusting a section symbol. We need to find
6598 // the symbol table index of the section symbol for
6599 // the output section corresponding to input section
6600 // in which this symbol is defined.
6601 gold_assert(r_sym
< local_count
);
6603 unsigned int shndx
=
6604 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
6605 gold_assert(is_ordinary
);
6606 Output_section
* os
= object
->output_section(shndx
);
6607 gold_assert(os
!= NULL
);
6608 gold_assert(os
->needs_symtab_index());
6609 r_sym
= os
->symtab_index();
6619 gsym
= object
->global_symbol(r_sym
);
6620 gold_assert(gsym
!= NULL
);
6621 if (gsym
->is_forwarder())
6622 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
6624 gold_assert(gsym
->has_symtab_index());
6625 r_sym
= gsym
->symtab_index();
6628 // Get the new offset--the location in the output section where
6629 // this relocation should be applied.
6630 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
6631 offset
+= offset_in_output_section
;
6634 section_offset_type sot_offset
=
6635 convert_types
<section_offset_type
, Address
>(offset
);
6636 section_offset_type new_sot_offset
=
6637 output_section
->output_offset(object
, relinfo
->data_shndx
,
6639 gold_assert(new_sot_offset
!= -1);
6640 offset
= new_sot_offset
;
6643 // In an object file, r_offset is an offset within the section.
6644 // In an executable or dynamic object, generated by
6645 // --emit-relocs, r_offset is an absolute address.
6646 if (!parameters
->options().relocatable())
6648 offset
+= view_address
;
6649 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
6650 offset
-= offset_in_output_section
;
6653 // Handle the reloc addend based on the strategy.
6654 if (strategy
== Relocatable_relocs::RELOC_COPY
)
6656 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
6658 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
6659 addend
= psymval
->value(object
, addend
);
6661 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
6663 if (addend
>= 32768)
6664 addend
+= got2_addend
;
6669 if (!parameters
->options().relocatable())
6671 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6672 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
6673 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
6674 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
6676 // First instruction of a global dynamic sequence,
6678 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6679 switch (this->optimize_tls_gd(final
))
6681 case tls::TLSOPT_TO_IE
:
6682 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
6683 - elfcpp::R_POWERPC_GOT_TLSGD16
);
6685 case tls::TLSOPT_TO_LE
:
6686 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6687 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6688 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6691 r_type
= elfcpp::R_POWERPC_NONE
;
6692 offset
-= 2 * big_endian
;
6699 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6700 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
6701 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
6702 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
6704 // First instruction of a local dynamic sequence,
6706 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
6708 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6709 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
6711 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6712 const Output_section
* os
= relinfo
->layout
->tls_segment()
6714 gold_assert(os
!= NULL
);
6715 gold_assert(os
->needs_symtab_index());
6716 r_sym
= os
->symtab_index();
6717 addend
= dtp_offset
;
6721 r_type
= elfcpp::R_POWERPC_NONE
;
6722 offset
-= 2 * big_endian
;
6726 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6727 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
6728 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
6729 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
6731 // First instruction of initial exec sequence.
6732 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6733 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
6735 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6736 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
6737 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6740 r_type
= elfcpp::R_POWERPC_NONE
;
6741 offset
-= 2 * big_endian
;
6745 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
6746 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
6748 // Second instruction of a global dynamic sequence,
6749 // the __tls_get_addr call
6750 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6751 switch (this->optimize_tls_gd(final
))
6753 case tls::TLSOPT_TO_IE
:
6754 r_type
= elfcpp::R_POWERPC_NONE
;
6757 case tls::TLSOPT_TO_LE
:
6758 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6759 offset
+= 2 * big_endian
;
6766 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
6767 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
6769 // Second instruction of a local dynamic sequence,
6770 // the __tls_get_addr call
6771 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
6773 const Output_section
* os
= relinfo
->layout
->tls_segment()
6775 gold_assert(os
!= NULL
);
6776 gold_assert(os
->needs_symtab_index());
6777 r_sym
= os
->symtab_index();
6778 addend
= dtp_offset
;
6779 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6780 offset
+= 2 * big_endian
;
6784 else if (r_type
== elfcpp::R_POWERPC_TLS
)
6786 // Second instruction of an initial exec sequence
6787 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6788 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
6790 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6791 offset
+= 2 * big_endian
;
6796 reloc_write
.put_r_offset(offset
);
6797 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
6798 reloc_write
.put_r_addend(addend
);
6800 pwrite
+= reloc_size
;
6803 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
6804 == reloc_view_size
);
6807 // Return the value to use for a dynamic symbol which requires special
6808 // treatment. This is how we support equality comparisons of function
6809 // pointers across shared library boundaries, as described in the
6810 // processor specific ABI supplement.
6812 template<int size
, bool big_endian
>
6814 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
6818 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
6819 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
6820 p
!= this->stub_tables_
.end();
6823 Address off
= (*p
)->find_plt_call_entry(gsym
);
6824 if (off
!= invalid_address
)
6825 return (*p
)->stub_address() + off
;
6831 // Return the PLT address to use for a local symbol.
6832 template<int size
, bool big_endian
>
6834 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
6835 const Relobj
* object
,
6836 unsigned int symndx
) const
6840 const Sized_relobj
<size
, big_endian
>* relobj
6841 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
6842 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
6843 p
!= this->stub_tables_
.end();
6846 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
6848 if (off
!= invalid_address
)
6849 return (*p
)->stub_address() + off
;
6855 // Return the PLT address to use for a global symbol.
6856 template<int size
, bool big_endian
>
6858 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
6859 const Symbol
* gsym
) const
6863 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
6864 p
!= this->stub_tables_
.end();
6867 Address off
= (*p
)->find_plt_call_entry(gsym
);
6868 if (off
!= invalid_address
)
6869 return (*p
)->stub_address() + off
;
6875 // Return the offset to use for the GOT_INDX'th got entry which is
6876 // for a local tls symbol specified by OBJECT, SYMNDX.
6877 template<int size
, bool big_endian
>
6879 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
6880 const Relobj
* object
,
6881 unsigned int symndx
,
6882 unsigned int got_indx
) const
6884 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6885 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
6886 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
6888 for (Got_type got_type
= GOT_TYPE_TLSGD
;
6889 got_type
<= GOT_TYPE_TPREL
;
6890 got_type
= Got_type(got_type
+ 1))
6891 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
6893 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
6894 if (got_type
== GOT_TYPE_TLSGD
)
6896 if (off
== got_indx
* (size
/ 8))
6898 if (got_type
== GOT_TYPE_TPREL
)
6908 // Return the offset to use for the GOT_INDX'th got entry which is
6909 // for global tls symbol GSYM.
6910 template<int size
, bool big_endian
>
6912 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
6914 unsigned int got_indx
) const
6916 if (gsym
->type() == elfcpp::STT_TLS
)
6918 for (Got_type got_type
= GOT_TYPE_TLSGD
;
6919 got_type
<= GOT_TYPE_TPREL
;
6920 got_type
= Got_type(got_type
+ 1))
6921 if (gsym
->has_got_offset(got_type
))
6923 unsigned int off
= gsym
->got_offset(got_type
);
6924 if (got_type
== GOT_TYPE_TLSGD
)
6926 if (off
== got_indx
* (size
/ 8))
6928 if (got_type
== GOT_TYPE_TPREL
)
6938 // The selector for powerpc object files.
6940 template<int size
, bool big_endian
>
6941 class Target_selector_powerpc
: public Target_selector
6944 Target_selector_powerpc()
6945 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
6948 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
6949 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
6951 ? (big_endian
? "elf64ppc" : "elf64lppc")
6952 : (big_endian
? "elf32ppc" : "elf32lppc")))
6956 do_instantiate_target()
6957 { return new Target_powerpc
<size
, big_endian
>(); }
6960 Target_selector_powerpc
<32, true> target_selector_ppc32
;
6961 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
6962 Target_selector_powerpc
<64, true> target_selector_ppc64
;
6963 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
6965 // Instantiate these constants for -O0
6966 template<int size
, bool big_endian
>
6967 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
6968 template<int size
, bool big_endian
>
6969 const typename Stub_table
<size
, big_endian
>::Address
6970 Stub_table
<size
, big_endian
>::invalid_address
;
6971 template<int size
, bool big_endian
>
6972 const typename Target_powerpc
<size
, big_endian
>::Address
6973 Target_powerpc
<size
, big_endian
>::invalid_address
;
6975 } // End anonymous namespace.