1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2014 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.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_brlt_powerpc
;
56 template<int size
, bool big_endian
>
57 class Output_data_got_powerpc
;
59 template<int size
, bool big_endian
>
60 class Output_data_glink
;
62 template<int size
, bool big_endian
>
66 is_branch_reloc(unsigned int r_type
);
68 template<int size
, bool big_endian
>
69 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
72 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
73 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
74 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
76 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
77 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
78 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
79 special_(0), has_small_toc_reloc_(false), opd_valid_(false),
80 opd_ent_(), access_from_map_(), has14_(), stub_table_(),
81 e_flags_(ehdr
.get_e_flags()), st_other_()
83 this->set_abiversion(0);
89 // Read the symbols then set up st_other vector.
91 do_read_symbols(Read_symbols_data
*);
93 // The .got2 section shndx.
98 return this->special_
;
103 // The .opd section shndx.
110 return this->special_
;
113 // Init OPD entry arrays.
115 init_opd(size_t opd_size
)
117 size_t count
= this->opd_ent_ndx(opd_size
);
118 this->opd_ent_
.resize(count
);
121 // Return section and offset of function entry for .opd + R_OFF.
123 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
125 size_t ndx
= this->opd_ent_ndx(r_off
);
126 gold_assert(ndx
< this->opd_ent_
.size());
127 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
129 *value
= this->opd_ent_
[ndx
].off
;
130 return this->opd_ent_
[ndx
].shndx
;
133 // Set section and offset of function entry for .opd + R_OFF.
135 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
137 size_t ndx
= this->opd_ent_ndx(r_off
);
138 gold_assert(ndx
< this->opd_ent_
.size());
139 this->opd_ent_
[ndx
].shndx
= shndx
;
140 this->opd_ent_
[ndx
].off
= value
;
143 // Return discard flag for .opd + R_OFF.
145 get_opd_discard(Address r_off
) const
147 size_t ndx
= this->opd_ent_ndx(r_off
);
148 gold_assert(ndx
< this->opd_ent_
.size());
149 return this->opd_ent_
[ndx
].discard
;
152 // Set discard flag for .opd + R_OFF.
154 set_opd_discard(Address r_off
)
156 size_t ndx
= this->opd_ent_ndx(r_off
);
157 gold_assert(ndx
< this->opd_ent_
.size());
158 this->opd_ent_
[ndx
].discard
= true;
163 { return this->opd_valid_
; }
167 { this->opd_valid_
= true; }
169 // Examine .rela.opd to build info about function entry points.
171 scan_opd_relocs(size_t reloc_count
,
172 const unsigned char* prelocs
,
173 const unsigned char* plocal_syms
);
175 // Perform the Sized_relobj_file method, then set up opd info from
178 do_read_relocs(Read_relocs_data
*);
181 do_find_special_sections(Read_symbols_data
* sd
);
183 // Adjust this local symbol value. Return false if the symbol
184 // should be discarded from the output file.
186 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
188 if (size
== 64 && this->opd_shndx() != 0)
191 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
193 if (this->get_opd_discard(lv
->input_value()))
201 { return &this->access_from_map_
; }
203 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
204 // section at DST_OFF.
206 add_reference(Object
* src_obj
,
207 unsigned int src_indx
,
208 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
210 Section_id
src_id(src_obj
, src_indx
);
211 this->access_from_map_
[dst_off
].insert(src_id
);
214 // Add a reference to the code section specified by the .opd entry
217 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
219 size_t ndx
= this->opd_ent_ndx(dst_off
);
220 if (ndx
>= this->opd_ent_
.size())
221 this->opd_ent_
.resize(ndx
+ 1);
222 this->opd_ent_
[ndx
].gc_mark
= true;
226 process_gc_mark(Symbol_table
* symtab
)
228 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
229 if (this->opd_ent_
[i
].gc_mark
)
231 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
232 symtab
->gc()->worklist().push(Section_id(this, shndx
));
236 // Return offset in output GOT section that this object will use
237 // as a TOC pointer. Won't be just a constant with multi-toc support.
239 toc_base_offset() const
243 set_has_small_toc_reloc()
244 { has_small_toc_reloc_
= true; }
247 has_small_toc_reloc() const
248 { return has_small_toc_reloc_
; }
251 set_has_14bit_branch(unsigned int shndx
)
253 if (shndx
>= this->has14_
.size())
254 this->has14_
.resize(shndx
+ 1);
255 this->has14_
[shndx
] = true;
259 has_14bit_branch(unsigned int shndx
) const
260 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
263 set_stub_table(unsigned int shndx
, Stub_table
<size
, big_endian
>* stub_table
)
265 if (shndx
>= this->stub_table_
.size())
266 this->stub_table_
.resize(shndx
+ 1);
267 this->stub_table_
[shndx
] = stub_table
;
270 Stub_table
<size
, big_endian
>*
271 stub_table(unsigned int shndx
)
273 if (shndx
< this->stub_table_
.size())
274 return this->stub_table_
[shndx
];
280 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
282 // Set ABI version for input and output
284 set_abiversion(int ver
);
287 ppc64_local_entry_offset(const Symbol
* sym
) const
288 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
291 ppc64_local_entry_offset(unsigned int symndx
) const
292 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
303 // Return index into opd_ent_ array for .opd entry at OFF.
304 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
305 // apart when the language doesn't use the last 8-byte word, the
306 // environment pointer. Thus dividing the entry section offset by
307 // 16 will give an index into opd_ent_ that works for either layout
308 // of .opd. (It leaves some elements of the vector unused when .opd
309 // entries are spaced 24 bytes apart, but we don't know the spacing
310 // until relocations are processed, and in any case it is possible
311 // for an object to have some entries spaced 16 bytes apart and
312 // others 24 bytes apart.)
314 opd_ent_ndx(size_t off
) const
317 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
318 unsigned int special_
;
320 // For 64-bit, whether this object uses small model relocs to access
322 bool has_small_toc_reloc_
;
324 // Set at the start of gc_process_relocs, when we know opd_ent_
325 // vector is valid. The flag could be made atomic and set in
326 // do_read_relocs with memory_order_release and then tested with
327 // memory_order_acquire, potentially resulting in fewer entries in
331 // The first 8-byte word of an OPD entry gives the address of the
332 // entry point of the function. Relocatable object files have a
333 // relocation on this word. The following vector records the
334 // section and offset specified by these relocations.
335 std::vector
<Opd_ent
> opd_ent_
;
337 // References made to this object's .opd section when running
338 // gc_process_relocs for another object, before the opd_ent_ vector
339 // is valid for this object.
340 Access_from access_from_map_
;
342 // Whether input section has a 14-bit branch reloc.
343 std::vector
<bool> has14_
;
345 // The stub table to use for a given input section.
346 std::vector
<Stub_table
<size
, big_endian
>*> stub_table_
;
349 elfcpp::Elf_Word e_flags_
;
351 // ELF st_other field for local symbols.
352 std::vector
<unsigned char> st_other_
;
355 template<int size
, bool big_endian
>
356 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
359 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
361 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
362 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
363 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
364 opd_shndx_(0), opd_ent_(), e_flags_(ehdr
.get_e_flags())
366 this->set_abiversion(0);
372 // Call Sized_dynobj::do_read_symbols to read the symbols then
373 // read .opd from a dynamic object, filling in opd_ent_ vector,
375 do_read_symbols(Read_symbols_data
*);
377 // The .opd section shndx.
381 return this->opd_shndx_
;
384 // The .opd section address.
388 return this->opd_address_
;
391 // Init OPD entry arrays.
393 init_opd(size_t opd_size
)
395 size_t count
= this->opd_ent_ndx(opd_size
);
396 this->opd_ent_
.resize(count
);
399 // Return section and offset of function entry for .opd + R_OFF.
401 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
403 size_t ndx
= this->opd_ent_ndx(r_off
);
404 gold_assert(ndx
< this->opd_ent_
.size());
405 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
407 *value
= this->opd_ent_
[ndx
].off
;
408 return this->opd_ent_
[ndx
].shndx
;
411 // Set section and offset of function entry for .opd + R_OFF.
413 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
415 size_t ndx
= this->opd_ent_ndx(r_off
);
416 gold_assert(ndx
< this->opd_ent_
.size());
417 this->opd_ent_
[ndx
].shndx
= shndx
;
418 this->opd_ent_
[ndx
].off
= value
;
423 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
425 // Set ABI version for input and output.
427 set_abiversion(int ver
);
430 // Used to specify extent of executable sections.
433 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
434 : start(start_
), len(len_
), shndx(shndx_
)
438 operator<(const Sec_info
& that
) const
439 { return this->start
< that
.start
; }
452 // Return index into opd_ent_ array for .opd entry at OFF.
454 opd_ent_ndx(size_t off
) const
457 // For 64-bit the .opd section shndx and address.
458 unsigned int opd_shndx_
;
459 Address opd_address_
;
461 // The first 8-byte word of an OPD entry gives the address of the
462 // entry point of the function. Records the section and offset
463 // corresponding to the address. Note that in dynamic objects,
464 // offset is *not* relative to the section.
465 std::vector
<Opd_ent
> opd_ent_
;
468 elfcpp::Elf_Word e_flags_
;
471 template<int size
, bool big_endian
>
472 class Target_powerpc
: public Sized_target
<size
, big_endian
>
476 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
477 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
478 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
479 static const Address invalid_address
= static_cast<Address
>(0) - 1;
480 // Offset of tp and dtp pointers from start of TLS block.
481 static const Address tp_offset
= 0x7000;
482 static const Address dtp_offset
= 0x8000;
485 : Sized_target
<size
, big_endian
>(&powerpc_info
),
486 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
487 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
488 tlsld_got_offset_(-1U),
489 stub_tables_(), branch_lookup_table_(), branch_info_(),
490 plt_thread_safe_(false)
494 // Process the relocations to determine unreferenced sections for
495 // garbage collection.
497 gc_process_relocs(Symbol_table
* symtab
,
499 Sized_relobj_file
<size
, big_endian
>* object
,
500 unsigned int data_shndx
,
501 unsigned int sh_type
,
502 const unsigned char* prelocs
,
504 Output_section
* output_section
,
505 bool needs_special_offset_handling
,
506 size_t local_symbol_count
,
507 const unsigned char* plocal_symbols
);
509 // Scan the relocations to look for symbol adjustments.
511 scan_relocs(Symbol_table
* symtab
,
513 Sized_relobj_file
<size
, big_endian
>* object
,
514 unsigned int data_shndx
,
515 unsigned int sh_type
,
516 const unsigned char* prelocs
,
518 Output_section
* output_section
,
519 bool needs_special_offset_handling
,
520 size_t local_symbol_count
,
521 const unsigned char* plocal_symbols
);
523 // Map input .toc section to output .got section.
525 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
527 if (size
== 64 && strcmp(name
, ".toc") == 0)
535 // Provide linker defined save/restore functions.
537 define_save_restore_funcs(Layout
*, Symbol_table
*);
539 // No stubs unless a final link.
542 { return !parameters
->options().relocatable(); }
545 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
548 do_plt_fde_location(const Output_data
*, unsigned char*,
549 uint64_t*, off_t
*) const;
551 // Stash info about branches, for stub generation.
553 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
554 unsigned int data_shndx
, Address r_offset
,
555 unsigned int r_type
, unsigned int r_sym
, Address addend
)
557 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
558 this->branch_info_
.push_back(info
);
559 if (r_type
== elfcpp::R_POWERPC_REL14
560 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
561 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
562 ppc_object
->set_has_14bit_branch(data_shndx
);
565 Stub_table
<size
, big_endian
>*
569 do_define_standard_symbols(Symbol_table
*, Layout
*);
571 // Finalize the sections.
573 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
575 // Return the value to use for a dynamic which requires special
578 do_dynsym_value(const Symbol
*) const;
580 // Return the PLT address to use for a local symbol.
582 do_plt_address_for_local(const Relobj
*, unsigned int) const;
584 // Return the PLT address to use for a global symbol.
586 do_plt_address_for_global(const Symbol
*) const;
588 // Return the offset to use for the GOT_INDX'th got entry which is
589 // for a local tls symbol specified by OBJECT, SYMNDX.
591 do_tls_offset_for_local(const Relobj
* object
,
593 unsigned int got_indx
) const;
595 // Return the offset to use for the GOT_INDX'th got entry which is
596 // for global tls symbol GSYM.
598 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
601 do_function_location(Symbol_location
*) const;
604 do_can_check_for_function_pointers() const
607 // Relocate a section.
609 relocate_section(const Relocate_info
<size
, big_endian
>*,
610 unsigned int sh_type
,
611 const unsigned char* prelocs
,
613 Output_section
* output_section
,
614 bool needs_special_offset_handling
,
616 Address view_address
,
617 section_size_type view_size
,
618 const Reloc_symbol_changes
*);
620 // Scan the relocs during a relocatable link.
622 scan_relocatable_relocs(Symbol_table
* symtab
,
624 Sized_relobj_file
<size
, big_endian
>* object
,
625 unsigned int data_shndx
,
626 unsigned int sh_type
,
627 const unsigned char* prelocs
,
629 Output_section
* output_section
,
630 bool needs_special_offset_handling
,
631 size_t local_symbol_count
,
632 const unsigned char* plocal_symbols
,
633 Relocatable_relocs
*);
635 // Emit relocations for a section.
637 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
638 unsigned int sh_type
,
639 const unsigned char* prelocs
,
641 Output_section
* output_section
,
642 typename
elfcpp::Elf_types
<size
>::Elf_Off
643 offset_in_output_section
,
644 const Relocatable_relocs
*,
646 Address view_address
,
648 unsigned char* reloc_view
,
649 section_size_type reloc_view_size
);
651 // Return whether SYM is defined by the ABI.
653 do_is_defined_by_abi(const Symbol
* sym
) const
655 return strcmp(sym
->name(), "__tls_get_addr") == 0;
658 // Return the size of the GOT section.
662 gold_assert(this->got_
!= NULL
);
663 return this->got_
->data_size();
666 // Get the PLT section.
667 const Output_data_plt_powerpc
<size
, big_endian
>*
670 gold_assert(this->plt_
!= NULL
);
674 // Get the IPLT section.
675 const Output_data_plt_powerpc
<size
, big_endian
>*
678 gold_assert(this->iplt_
!= NULL
);
682 // Get the .glink section.
683 const Output_data_glink
<size
, big_endian
>*
684 glink_section() const
686 gold_assert(this->glink_
!= NULL
);
690 Output_data_glink
<size
, big_endian
>*
693 gold_assert(this->glink_
!= NULL
);
697 bool has_glink() const
698 { return this->glink_
!= NULL
; }
700 // Get the GOT section.
701 const Output_data_got_powerpc
<size
, big_endian
>*
704 gold_assert(this->got_
!= NULL
);
708 // Get the GOT section, creating it if necessary.
709 Output_data_got_powerpc
<size
, big_endian
>*
710 got_section(Symbol_table
*, Layout
*);
713 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
714 const elfcpp::Ehdr
<size
, big_endian
>&);
716 // Return the number of entries in the GOT.
718 got_entry_count() const
720 if (this->got_
== NULL
)
722 return this->got_size() / (size
/ 8);
725 // Return the number of entries in the PLT.
727 plt_entry_count() const;
729 // Return the offset of the first non-reserved PLT entry.
731 first_plt_entry_offset() const
735 if (this->abiversion() >= 2)
740 // Return the size of each PLT entry.
742 plt_entry_size() const
746 if (this->abiversion() >= 2)
751 // Add any special sections for this symbol to the gc work list.
752 // For powerpc64, this adds the code section of a function
755 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
757 // Handle target specific gc actions when adding a gc reference from
758 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
759 // and DST_OFF. For powerpc64, this adds a referenc to the code
760 // section of a function descriptor.
762 do_gc_add_reference(Symbol_table
* symtab
,
764 unsigned int src_shndx
,
766 unsigned int dst_shndx
,
767 Address dst_off
) const;
769 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
772 { return this->stub_tables_
; }
774 const Output_data_brlt_powerpc
<size
, big_endian
>*
776 { return this->brlt_section_
; }
779 add_branch_lookup_table(Address to
)
781 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
782 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
786 find_branch_lookup_table(Address to
)
788 typename
Branch_lookup_table::const_iterator p
789 = this->branch_lookup_table_
.find(to
);
790 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
794 write_branch_lookup_table(unsigned char *oview
)
796 for (typename
Branch_lookup_table::const_iterator p
797 = this->branch_lookup_table_
.begin();
798 p
!= this->branch_lookup_table_
.end();
801 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
806 plt_thread_safe() const
807 { return this->plt_thread_safe_
; }
811 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
814 set_abiversion (int ver
)
816 elfcpp::Elf_Word flags
= this->processor_specific_flags();
817 flags
&= ~elfcpp::EF_PPC64_ABI
;
818 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
819 this->set_processor_specific_flags(flags
);
822 // Offset to to save stack slot
825 { return this->abiversion() < 2 ? 40 : 24; }
841 : tls_get_addr_(NOT_EXPECTED
),
842 relinfo_(NULL
), relnum_(0), r_offset_(0)
847 if (this->tls_get_addr_
!= NOT_EXPECTED
)
854 if (this->relinfo_
!= NULL
)
855 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
856 _("missing expected __tls_get_addr call"));
860 expect_tls_get_addr_call(
861 const Relocate_info
<size
, big_endian
>* relinfo
,
865 this->tls_get_addr_
= EXPECTED
;
866 this->relinfo_
= relinfo
;
867 this->relnum_
= relnum
;
868 this->r_offset_
= r_offset
;
872 expect_tls_get_addr_call()
873 { this->tls_get_addr_
= EXPECTED
; }
876 skip_next_tls_get_addr_call()
877 {this->tls_get_addr_
= SKIP
; }
880 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
882 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
883 || r_type
== elfcpp::R_PPC_PLTREL24
)
885 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
886 Tls_get_addr last_tls
= this->tls_get_addr_
;
887 this->tls_get_addr_
= NOT_EXPECTED
;
888 if (is_tls_call
&& last_tls
!= EXPECTED
)
890 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
899 // What we're up to regarding calls to __tls_get_addr.
900 // On powerpc, the branch and link insn making a call to
901 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
902 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
903 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
904 // The marker relocation always comes first, and has the same
905 // symbol as the reloc on the insn setting up the __tls_get_addr
906 // argument. This ties the arg setup insn with the call insn,
907 // allowing ld to safely optimize away the call. We check that
908 // every call to __tls_get_addr has a marker relocation, and that
909 // every marker relocation is on a call to __tls_get_addr.
910 Tls_get_addr tls_get_addr_
;
911 // Info about the last reloc for error message.
912 const Relocate_info
<size
, big_endian
>* relinfo_
;
917 // The class which scans relocations.
918 class Scan
: protected Track_tls
921 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
924 : Track_tls(), issued_non_pic_error_(false)
928 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
931 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
932 Sized_relobj_file
<size
, big_endian
>* object
,
933 unsigned int data_shndx
,
934 Output_section
* output_section
,
935 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
936 const elfcpp::Sym
<size
, big_endian
>& lsym
,
940 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
941 Sized_relobj_file
<size
, big_endian
>* object
,
942 unsigned int data_shndx
,
943 Output_section
* output_section
,
944 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
948 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
950 Sized_relobj_file
<size
, big_endian
>* relobj
,
953 const elfcpp::Rela
<size
, big_endian
>& ,
955 const elfcpp::Sym
<size
, big_endian
>&)
957 // PowerPC64 .opd is not folded, so any identical function text
958 // may be folded and we'll still keep function addresses distinct.
959 // That means no reloc is of concern here.
962 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
963 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
964 if (ppcobj
->abiversion() == 1)
967 // For 32-bit and ELFv2, conservatively assume anything but calls to
968 // function code might be taking the address of the function.
969 return !is_branch_reloc(r_type
);
973 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
975 Sized_relobj_file
<size
, big_endian
>* relobj
,
978 const elfcpp::Rela
<size
, big_endian
>& ,
985 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
986 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
987 if (ppcobj
->abiversion() == 1)
990 return !is_branch_reloc(r_type
);
994 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
995 Sized_relobj_file
<size
, big_endian
>* object
,
996 unsigned int r_type
, bool report_err
);
1000 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1001 unsigned int r_type
);
1004 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1005 unsigned int r_type
, Symbol
*);
1008 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1009 Target_powerpc
* target
);
1012 check_non_pic(Relobj
*, unsigned int r_type
);
1014 // Whether we have issued an error about a non-PIC compilation.
1015 bool issued_non_pic_error_
;
1019 symval_for_branch(const Symbol_table
* symtab
, Address value
,
1020 const Sized_symbol
<size
>* gsym
,
1021 Powerpc_relobj
<size
, big_endian
>* object
,
1022 unsigned int *dest_shndx
);
1024 // The class which implements relocation.
1025 class Relocate
: protected Track_tls
1028 // Use 'at' branch hints when true, 'y' when false.
1029 // FIXME maybe: set this with an option.
1030 static const bool is_isa_v2
= true;
1036 // Do a relocation. Return false if the caller should not issue
1037 // any warnings about this relocation.
1039 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
1040 Output_section
*, size_t relnum
,
1041 const elfcpp::Rela
<size
, big_endian
>&,
1042 unsigned int r_type
, const Sized_symbol
<size
>*,
1043 const Symbol_value
<size
>*,
1045 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1049 class Relocate_comdat_behavior
1052 // Decide what the linker should do for relocations that refer to
1053 // discarded comdat sections.
1054 inline Comdat_behavior
1055 get(const char* name
)
1057 gold::Default_comdat_behavior default_behavior
;
1058 Comdat_behavior ret
= default_behavior
.get(name
);
1059 if (ret
== CB_WARNING
)
1062 && (strcmp(name
, ".fixup") == 0
1063 || strcmp(name
, ".got2") == 0))
1066 && (strcmp(name
, ".opd") == 0
1067 || strcmp(name
, ".toc") == 0
1068 || strcmp(name
, ".toc1") == 0))
1075 // A class which returns the size required for a relocation type,
1076 // used while scanning relocs during a relocatable link.
1077 class Relocatable_size_for_reloc
1081 get_size_for_reloc(unsigned int, Relobj
*)
1088 // Optimize the TLS relocation type based on what we know about the
1089 // symbol. IS_FINAL is true if the final address of this symbol is
1090 // known at link time.
1092 tls::Tls_optimization
1093 optimize_tls_gd(bool is_final
)
1095 // If we are generating a shared library, then we can't do anything
1097 if (parameters
->options().shared())
1098 return tls::TLSOPT_NONE
;
1101 return tls::TLSOPT_TO_IE
;
1102 return tls::TLSOPT_TO_LE
;
1105 tls::Tls_optimization
1108 if (parameters
->options().shared())
1109 return tls::TLSOPT_NONE
;
1111 return tls::TLSOPT_TO_LE
;
1114 tls::Tls_optimization
1115 optimize_tls_ie(bool is_final
)
1117 if (!is_final
|| parameters
->options().shared())
1118 return tls::TLSOPT_NONE
;
1120 return tls::TLSOPT_TO_LE
;
1125 make_glink_section(Layout
*);
1127 // Create the PLT section.
1129 make_plt_section(Symbol_table
*, Layout
*);
1132 make_iplt_section(Symbol_table
*, Layout
*);
1135 make_brlt_section(Layout
*);
1137 // Create a PLT entry for a global symbol.
1139 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1141 // Create a PLT entry for a local IFUNC symbol.
1143 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1144 Sized_relobj_file
<size
, big_endian
>*,
1148 // Create a GOT entry for local dynamic __tls_get_addr.
1150 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1151 Sized_relobj_file
<size
, big_endian
>* object
);
1154 tlsld_got_offset() const
1156 return this->tlsld_got_offset_
;
1159 // Get the dynamic reloc section, creating it if necessary.
1161 rela_dyn_section(Layout
*);
1163 // Similarly, but for ifunc symbols get the one for ifunc.
1165 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1167 // Copy a relocation against a global symbol.
1169 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1170 Sized_relobj_file
<size
, big_endian
>* object
,
1171 unsigned int shndx
, Output_section
* output_section
,
1172 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1174 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1175 symtab
->get_sized_symbol
<size
>(sym
),
1176 object
, shndx
, output_section
,
1177 reloc
, this->rela_dyn_section(layout
));
1180 // Look over all the input sections, deciding where to place stubs.
1182 group_sections(Layout
*, const Task
*);
1184 // Sort output sections by address.
1185 struct Sort_sections
1188 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1189 { return sec1
->address() < sec2
->address(); }
1195 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1196 unsigned int data_shndx
,
1198 unsigned int r_type
,
1201 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1202 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1208 // If this branch needs a plt call stub, or a long branch stub, make one.
1210 make_stub(Stub_table
<size
, big_endian
>*,
1211 Stub_table
<size
, big_endian
>*,
1212 Symbol_table
*) const;
1215 // The branch location..
1216 Powerpc_relobj
<size
, big_endian
>* object_
;
1217 unsigned int shndx_
;
1219 // ..and the branch type and destination.
1220 unsigned int r_type_
;
1221 unsigned int r_sym_
;
1225 // Information about this specific target which we pass to the
1226 // general Target structure.
1227 static Target::Target_info powerpc_info
;
1229 // The types of GOT entries needed for this platform.
1230 // These values are exposed to the ABI in an incremental link.
1231 // Do not renumber existing values without changing the version
1232 // number of the .gnu_incremental_inputs section.
1236 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1237 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1238 GOT_TYPE_TPREL
// entry for @got@tprel
1242 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1243 // The PLT section. This is a container for a table of addresses,
1244 // and their relocations. Each address in the PLT has a dynamic
1245 // relocation (R_*_JMP_SLOT) and each address will have a
1246 // corresponding entry in .glink for lazy resolution of the PLT.
1247 // ppc32 initialises the PLT to point at the .glink entry, while
1248 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1249 // linker adds a stub that loads the PLT entry into ctr then
1250 // branches to ctr. There may be more than one stub for each PLT
1251 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1252 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1253 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1254 // The IPLT section. Like plt_, this is a container for a table of
1255 // addresses and their relocations, specifically for STT_GNU_IFUNC
1256 // functions that resolve locally (STT_GNU_IFUNC functions that
1257 // don't resolve locally go in PLT). Unlike plt_, these have no
1258 // entry in .glink for lazy resolution, and the relocation section
1259 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1260 // the relocation section may contain relocations against
1261 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1262 // relocation section will appear at the end of other dynamic
1263 // relocations, so that ld.so applies these relocations after other
1264 // dynamic relocations. In a static executable, the relocation
1265 // section is emitted and marked with __rela_iplt_start and
1266 // __rela_iplt_end symbols.
1267 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1268 // Section holding long branch destinations.
1269 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1270 // The .glink section.
1271 Output_data_glink
<size
, big_endian
>* glink_
;
1272 // The dynamic reloc section.
1273 Reloc_section
* rela_dyn_
;
1274 // Relocs saved to avoid a COPY reloc.
1275 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1276 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1277 unsigned int tlsld_got_offset_
;
1279 Stub_tables stub_tables_
;
1280 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1281 Branch_lookup_table branch_lookup_table_
;
1283 typedef std::vector
<Branch_info
> Branches
;
1284 Branches branch_info_
;
1286 bool plt_thread_safe_
;
1290 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1293 true, // is_big_endian
1294 elfcpp::EM_PPC
, // machine_code
1295 false, // has_make_symbol
1296 false, // has_resolve
1297 false, // has_code_fill
1298 true, // is_default_stack_executable
1299 false, // can_icf_inline_merge_sections
1301 "/usr/lib/ld.so.1", // dynamic_linker
1302 0x10000000, // default_text_segment_address
1303 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1304 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1305 false, // isolate_execinstr
1307 elfcpp::SHN_UNDEF
, // small_common_shndx
1308 elfcpp::SHN_UNDEF
, // large_common_shndx
1309 0, // small_common_section_flags
1310 0, // large_common_section_flags
1311 NULL
, // attributes_section
1312 NULL
, // attributes_vendor
1313 "_start" // entry_symbol_name
1317 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1320 false, // is_big_endian
1321 elfcpp::EM_PPC
, // machine_code
1322 false, // has_make_symbol
1323 false, // has_resolve
1324 false, // has_code_fill
1325 true, // is_default_stack_executable
1326 false, // can_icf_inline_merge_sections
1328 "/usr/lib/ld.so.1", // dynamic_linker
1329 0x10000000, // default_text_segment_address
1330 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1331 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1332 false, // isolate_execinstr
1334 elfcpp::SHN_UNDEF
, // small_common_shndx
1335 elfcpp::SHN_UNDEF
, // large_common_shndx
1336 0, // small_common_section_flags
1337 0, // large_common_section_flags
1338 NULL
, // attributes_section
1339 NULL
, // attributes_vendor
1340 "_start" // entry_symbol_name
1344 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1347 true, // is_big_endian
1348 elfcpp::EM_PPC64
, // machine_code
1349 false, // has_make_symbol
1350 false, // has_resolve
1351 false, // has_code_fill
1352 true, // is_default_stack_executable
1353 false, // can_icf_inline_merge_sections
1355 "/usr/lib/ld.so.1", // dynamic_linker
1356 0x10000000, // default_text_segment_address
1357 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1358 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1359 false, // isolate_execinstr
1361 elfcpp::SHN_UNDEF
, // small_common_shndx
1362 elfcpp::SHN_UNDEF
, // large_common_shndx
1363 0, // small_common_section_flags
1364 0, // large_common_section_flags
1365 NULL
, // attributes_section
1366 NULL
, // attributes_vendor
1367 "_start" // entry_symbol_name
1371 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1374 false, // is_big_endian
1375 elfcpp::EM_PPC64
, // machine_code
1376 false, // has_make_symbol
1377 false, // has_resolve
1378 false, // has_code_fill
1379 true, // is_default_stack_executable
1380 false, // can_icf_inline_merge_sections
1382 "/usr/lib/ld.so.1", // dynamic_linker
1383 0x10000000, // default_text_segment_address
1384 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1385 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1386 false, // isolate_execinstr
1388 elfcpp::SHN_UNDEF
, // small_common_shndx
1389 elfcpp::SHN_UNDEF
, // large_common_shndx
1390 0, // small_common_section_flags
1391 0, // large_common_section_flags
1392 NULL
, // attributes_section
1393 NULL
, // attributes_vendor
1394 "_start" // entry_symbol_name
1398 is_branch_reloc(unsigned int r_type
)
1400 return (r_type
== elfcpp::R_POWERPC_REL24
1401 || r_type
== elfcpp::R_PPC_PLTREL24
1402 || r_type
== elfcpp::R_PPC_LOCAL24PC
1403 || r_type
== elfcpp::R_POWERPC_REL14
1404 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1405 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1406 || r_type
== elfcpp::R_POWERPC_ADDR24
1407 || r_type
== elfcpp::R_POWERPC_ADDR14
1408 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1409 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1412 // If INSN is an opcode that may be used with an @tls operand, return
1413 // the transformed insn for TLS optimisation, otherwise return 0. If
1414 // REG is non-zero only match an insn with RB or RA equal to REG.
1416 at_tls_transform(uint32_t insn
, unsigned int reg
)
1418 if ((insn
& (0x3f << 26)) != 31 << 26)
1422 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1423 rtra
= insn
& ((1 << 26) - (1 << 16));
1424 else if (((insn
>> 16) & 0x1f) == reg
)
1425 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1429 if ((insn
& (0x3ff << 1)) == 266 << 1)
1432 else if ((insn
& (0x1f << 1)) == 23 << 1
1433 && ((insn
& (0x1f << 6)) < 14 << 6
1434 || ((insn
& (0x1f << 6)) >= 16 << 6
1435 && (insn
& (0x1f << 6)) < 24 << 6)))
1436 // load and store indexed -> dform
1437 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1438 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1439 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1440 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1441 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1443 insn
= (58 << 26) | 2;
1451 template<int size
, bool big_endian
>
1452 class Powerpc_relocate_functions
1472 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1473 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1475 template<int valsize
>
1477 has_overflow_signed(Address value
)
1479 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1480 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1481 limit
<<= ((valsize
- 1) >> 1);
1482 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1483 return value
+ limit
> (limit
<< 1) - 1;
1486 template<int valsize
>
1488 has_overflow_unsigned(Address value
)
1490 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1491 limit
<<= ((valsize
- 1) >> 1);
1492 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1493 return value
> (limit
<< 1) - 1;
1496 template<int valsize
>
1498 has_overflow_bitfield(Address value
)
1500 return (has_overflow_unsigned
<valsize
>(value
)
1501 && has_overflow_signed
<valsize
>(value
));
1504 template<int valsize
>
1505 static inline Status
1506 overflowed(Address value
, Overflow_check overflow
)
1508 if (overflow
== CHECK_SIGNED
)
1510 if (has_overflow_signed
<valsize
>(value
))
1511 return STATUS_OVERFLOW
;
1513 else if (overflow
== CHECK_UNSIGNED
)
1515 if (has_overflow_unsigned
<valsize
>(value
))
1516 return STATUS_OVERFLOW
;
1518 else if (overflow
== CHECK_BITFIELD
)
1520 if (has_overflow_bitfield
<valsize
>(value
))
1521 return STATUS_OVERFLOW
;
1526 // Do a simple RELA relocation
1527 template<int valsize
>
1528 static inline Status
1529 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1531 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1532 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1533 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1534 return overflowed
<valsize
>(value
, overflow
);
1537 template<int valsize
>
1538 static inline Status
1539 rela(unsigned char* view
,
1540 unsigned int right_shift
,
1541 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1543 Overflow_check overflow
)
1545 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1546 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1547 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1548 Valtype reloc
= value
>> right_shift
;
1551 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1552 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1555 // Do a simple RELA relocation, unaligned.
1556 template<int valsize
>
1557 static inline Status
1558 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1560 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1561 return overflowed
<valsize
>(value
, overflow
);
1564 template<int valsize
>
1565 static inline Status
1566 rela_ua(unsigned char* view
,
1567 unsigned int right_shift
,
1568 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1570 Overflow_check overflow
)
1572 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1574 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1575 Valtype reloc
= value
>> right_shift
;
1578 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1579 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1583 // R_PPC64_ADDR64: (Symbol + Addend)
1585 addr64(unsigned char* view
, Address value
)
1586 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1588 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1590 addr64_u(unsigned char* view
, Address value
)
1591 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1593 // R_POWERPC_ADDR32: (Symbol + Addend)
1594 static inline Status
1595 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1596 { return This::template rela
<32>(view
, value
, overflow
); }
1598 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1599 static inline Status
1600 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1601 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1603 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1604 static inline Status
1605 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1607 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1608 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1609 stat
= STATUS_OVERFLOW
;
1613 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1614 static inline Status
1615 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1616 { return This::template rela
<16>(view
, value
, overflow
); }
1618 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1619 static inline Status
1620 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1621 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1623 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1624 static inline Status
1625 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1627 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1628 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1629 stat
= STATUS_OVERFLOW
;
1633 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1635 addr16_hi(unsigned char* view
, Address value
)
1636 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1638 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1640 addr16_ha(unsigned char* view
, Address value
)
1641 { This::addr16_hi(view
, value
+ 0x8000); }
1643 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1645 addr16_hi2(unsigned char* view
, Address value
)
1646 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1648 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1650 addr16_ha2(unsigned char* view
, Address value
)
1651 { This::addr16_hi2(view
, value
+ 0x8000); }
1653 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1655 addr16_hi3(unsigned char* view
, Address value
)
1656 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1658 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1660 addr16_ha3(unsigned char* view
, Address value
)
1661 { This::addr16_hi3(view
, value
+ 0x8000); }
1663 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1664 static inline Status
1665 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1667 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1668 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1669 stat
= STATUS_OVERFLOW
;
1674 // Set ABI version for input and output.
1676 template<int size
, bool big_endian
>
1678 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
1680 this->e_flags_
|= ver
;
1681 if (this->abiversion() != 0)
1683 Target_powerpc
<size
, big_endian
>* target
=
1684 static_cast<Target_powerpc
<size
, big_endian
>*>(
1685 parameters
->sized_target
<size
, big_endian
>());
1686 if (target
->abiversion() == 0)
1687 target
->set_abiversion(this->abiversion());
1688 else if (target
->abiversion() != this->abiversion())
1689 gold_error(_("%s: ABI version %d is not compatible "
1690 "with ABI version %d output"),
1691 this->name().c_str(),
1692 this->abiversion(), target
->abiversion());
1697 // Stash away the index of .got2 or .opd in a relocatable object, if
1698 // such a section exists.
1700 template<int size
, bool big_endian
>
1702 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1703 Read_symbols_data
* sd
)
1705 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1706 const unsigned char* namesu
= sd
->section_names
->data();
1707 const char* names
= reinterpret_cast<const char*>(namesu
);
1708 section_size_type names_size
= sd
->section_names_size
;
1709 const unsigned char* s
;
1711 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1712 size
== 32 ? ".got2" : ".opd",
1713 names
, names_size
, NULL
);
1716 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1717 this->special_
= ndx
;
1720 if (this->abiversion() == 0)
1721 this->set_abiversion(1);
1722 else if (this->abiversion() > 1)
1723 gold_error(_("%s: .opd invalid in abiv%d"),
1724 this->name().c_str(), this->abiversion());
1727 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1730 // Examine .rela.opd to build info about function entry points.
1732 template<int size
, bool big_endian
>
1734 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1736 const unsigned char* prelocs
,
1737 const unsigned char* plocal_syms
)
1741 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1743 const int reloc_size
1744 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1745 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1746 Address expected_off
= 0;
1747 bool regular
= true;
1748 unsigned int opd_ent_size
= 0;
1750 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1752 Reltype
reloc(prelocs
);
1753 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1754 = reloc
.get_r_info();
1755 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1756 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1758 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1759 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1762 if (r_sym
< this->local_symbol_count())
1764 typename
elfcpp::Sym
<size
, big_endian
>
1765 lsym(plocal_syms
+ r_sym
* sym_size
);
1766 shndx
= lsym
.get_st_shndx();
1767 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1768 value
= lsym
.get_st_value();
1771 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1773 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1774 value
+ reloc
.get_r_addend());
1777 expected_off
= reloc
.get_r_offset();
1778 opd_ent_size
= expected_off
;
1780 else if (expected_off
!= reloc
.get_r_offset())
1782 expected_off
+= opd_ent_size
;
1784 else if (r_type
== elfcpp::R_PPC64_TOC
)
1786 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1791 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1792 this->name().c_str(), r_type
);
1796 if (reloc_count
<= 2)
1797 opd_ent_size
= this->section_size(this->opd_shndx());
1798 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1802 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1803 this->name().c_str());
1809 template<int size
, bool big_endian
>
1811 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1813 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1816 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1817 p
!= rd
->relocs
.end();
1820 if (p
->data_shndx
== this->opd_shndx())
1822 uint64_t opd_size
= this->section_size(this->opd_shndx());
1823 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1826 this->init_opd(opd_size
);
1827 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1828 rd
->local_symbols
->data());
1836 // Read the symbols then set up st_other vector.
1838 template<int size
, bool big_endian
>
1840 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1842 this->base_read_symbols(sd
);
1845 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1846 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1847 const unsigned int loccount
= this->do_local_symbol_count();
1850 this->st_other_
.resize(loccount
);
1851 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1852 off_t locsize
= loccount
* sym_size
;
1853 const unsigned int symtab_shndx
= this->symtab_shndx();
1854 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
1855 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
1856 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
1857 locsize
, true, false);
1859 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
1861 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
1862 unsigned char st_other
= sym
.get_st_other();
1863 this->st_other_
[i
] = st_other
;
1864 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1866 if (this->abiversion() == 0)
1867 this->set_abiversion(2);
1868 else if (this->abiversion() < 2)
1869 gold_error(_("%s: local symbol %d has invalid st_other"
1870 " for ABI version 1"),
1871 this->name().c_str(), i
);
1878 template<int size
, bool big_endian
>
1880 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
1882 this->e_flags_
|= ver
;
1883 if (this->abiversion() != 0)
1885 Target_powerpc
<size
, big_endian
>* target
=
1886 static_cast<Target_powerpc
<size
, big_endian
>*>(
1887 parameters
->sized_target
<size
, big_endian
>());
1888 if (target
->abiversion() == 0)
1889 target
->set_abiversion(this->abiversion());
1890 else if (target
->abiversion() != this->abiversion())
1891 gold_error(_("%s: ABI version %d is not compatible "
1892 "with ABI version %d output"),
1893 this->name().c_str(),
1894 this->abiversion(), target
->abiversion());
1899 // Call Sized_dynobj::base_read_symbols to read the symbols then
1900 // read .opd from a dynamic object, filling in opd_ent_ vector,
1902 template<int size
, bool big_endian
>
1904 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1906 this->base_read_symbols(sd
);
1909 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1910 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1911 const unsigned char* namesu
= sd
->section_names
->data();
1912 const char* names
= reinterpret_cast<const char*>(namesu
);
1913 const unsigned char* s
= NULL
;
1914 const unsigned char* opd
;
1915 section_size_type opd_size
;
1917 // Find and read .opd section.
1920 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1921 sd
->section_names_size
,
1926 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1927 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1928 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1930 if (this->abiversion() == 0)
1931 this->set_abiversion(1);
1932 else if (this->abiversion() > 1)
1933 gold_error(_("%s: .opd invalid in abiv%d"),
1934 this->name().c_str(), this->abiversion());
1936 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
1937 this->opd_address_
= shdr
.get_sh_addr();
1938 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
1939 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
1945 // Build set of executable sections.
1946 // Using a set is probably overkill. There is likely to be only
1947 // a few executable sections, typically .init, .text and .fini,
1948 // and they are generally grouped together.
1949 typedef std::set
<Sec_info
> Exec_sections
;
1950 Exec_sections exec_sections
;
1952 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
1954 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1955 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1956 && ((shdr
.get_sh_flags()
1957 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1958 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1959 && shdr
.get_sh_size() != 0)
1961 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
1962 shdr
.get_sh_size(), i
));
1965 if (exec_sections
.empty())
1968 // Look over the OPD entries. This is complicated by the fact
1969 // that some binaries will use two-word entries while others
1970 // will use the standard three-word entries. In most cases
1971 // the third word (the environment pointer for languages like
1972 // Pascal) is unused and will be zero. If the third word is
1973 // used it should not be pointing into executable sections,
1975 this->init_opd(opd_size
);
1976 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
1978 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
1979 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
1980 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
1982 // Chances are that this is the third word of an OPD entry.
1984 typename
Exec_sections::const_iterator e
1985 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
1986 if (e
!= exec_sections
.begin())
1989 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
1991 // We have an address in an executable section.
1992 // VAL ought to be the function entry, set it up.
1993 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
1994 // Skip second word of OPD entry, the TOC pointer.
1998 // If we didn't match any executable sections, we likely
1999 // have a non-zero third word in the OPD entry.
2004 // Set up some symbols.
2006 template<int size
, bool big_endian
>
2008 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2009 Symbol_table
* symtab
,
2014 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2015 // undefined when scanning relocs (and thus requires
2016 // non-relative dynamic relocs). The proper value will be
2018 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2019 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2021 Target_powerpc
<size
, big_endian
>* target
=
2022 static_cast<Target_powerpc
<size
, big_endian
>*>(
2023 parameters
->sized_target
<size
, big_endian
>());
2024 Output_data_got_powerpc
<size
, big_endian
>* got
2025 = target
->got_section(symtab
, layout
);
2026 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2027 Symbol_table::PREDEFINED
,
2031 elfcpp::STV_HIDDEN
, 0,
2035 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2036 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2037 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2039 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2041 = layout
->add_output_section_data(".sdata", 0,
2043 | elfcpp::SHF_WRITE
,
2044 sdata
, ORDER_SMALL_DATA
, false);
2045 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2046 Symbol_table::PREDEFINED
,
2047 os
, 32768, 0, elfcpp::STT_OBJECT
,
2048 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2054 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2055 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2056 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2058 Target_powerpc
<size
, big_endian
>* target
=
2059 static_cast<Target_powerpc
<size
, big_endian
>*>(
2060 parameters
->sized_target
<size
, big_endian
>());
2061 Output_data_got_powerpc
<size
, big_endian
>* got
2062 = target
->got_section(symtab
, layout
);
2063 symtab
->define_in_output_data(".TOC.", NULL
,
2064 Symbol_table::PREDEFINED
,
2068 elfcpp::STV_HIDDEN
, 0,
2074 // Set up PowerPC target specific relobj.
2076 template<int size
, bool big_endian
>
2078 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2079 const std::string
& name
,
2080 Input_file
* input_file
,
2081 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2083 int et
= ehdr
.get_e_type();
2084 // ET_EXEC files are valid input for --just-symbols/-R,
2085 // and we treat them as relocatable objects.
2086 if (et
== elfcpp::ET_REL
2087 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2089 Powerpc_relobj
<size
, big_endian
>* obj
=
2090 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2094 else if (et
== elfcpp::ET_DYN
)
2096 Powerpc_dynobj
<size
, big_endian
>* obj
=
2097 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2103 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2108 template<int size
, bool big_endian
>
2109 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2112 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2113 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2115 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2116 : Output_data_got
<size
, big_endian
>(),
2117 symtab_(symtab
), layout_(layout
),
2118 header_ent_cnt_(size
== 32 ? 3 : 1),
2119 header_index_(size
== 32 ? 0x2000 : 0)
2122 // Override all the Output_data_got methods we use so as to first call
2125 add_global(Symbol
* gsym
, unsigned int got_type
)
2127 this->reserve_ent();
2128 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2132 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2134 this->reserve_ent();
2135 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2139 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2140 { return this->add_global_plt(gsym
, got_type
); }
2143 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2144 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2146 this->reserve_ent();
2147 Output_data_got
<size
, big_endian
>::
2148 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2152 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2153 Output_data_reloc_generic
* rel_dyn
,
2154 unsigned int r_type_1
, unsigned int r_type_2
)
2156 this->reserve_ent(2);
2157 Output_data_got
<size
, big_endian
>::
2158 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2162 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2164 this->reserve_ent();
2165 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2170 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2172 this->reserve_ent();
2173 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2178 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2179 { return this->add_local_plt(object
, sym_index
, got_type
); }
2182 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2183 unsigned int got_type
,
2184 Output_data_reloc_generic
* rel_dyn
,
2185 unsigned int r_type
)
2187 this->reserve_ent(2);
2188 Output_data_got
<size
, big_endian
>::
2189 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2193 add_constant(Valtype constant
)
2195 this->reserve_ent();
2196 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2200 add_constant_pair(Valtype c1
, Valtype c2
)
2202 this->reserve_ent(2);
2203 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2206 // Offset of _GLOBAL_OFFSET_TABLE_.
2210 return this->got_offset(this->header_index_
);
2213 // Offset of base used to access the GOT/TOC.
2214 // The got/toc pointer reg will be set to this value.
2216 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2219 return this->g_o_t();
2221 return (this->output_section()->address()
2222 + object
->toc_base_offset()
2226 // Ensure our GOT has a header.
2228 set_final_data_size()
2230 if (this->header_ent_cnt_
!= 0)
2231 this->make_header();
2232 Output_data_got
<size
, big_endian
>::set_final_data_size();
2235 // First word of GOT header needs some values that are not
2236 // handled by Output_data_got so poke them in here.
2237 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2239 do_write(Output_file
* of
)
2242 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2243 val
= this->layout_
->dynamic_section()->address();
2245 val
= this->output_section()->address() + 0x8000;
2246 this->replace_constant(this->header_index_
, val
);
2247 Output_data_got
<size
, big_endian
>::do_write(of
);
2252 reserve_ent(unsigned int cnt
= 1)
2254 if (this->header_ent_cnt_
== 0)
2256 if (this->num_entries() + cnt
> this->header_index_
)
2257 this->make_header();
2263 this->header_ent_cnt_
= 0;
2264 this->header_index_
= this->num_entries();
2267 Output_data_got
<size
, big_endian
>::add_constant(0);
2268 Output_data_got
<size
, big_endian
>::add_constant(0);
2269 Output_data_got
<size
, big_endian
>::add_constant(0);
2271 // Define _GLOBAL_OFFSET_TABLE_ at the header
2272 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2275 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2276 sym
->set_value(this->g_o_t());
2279 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2280 Symbol_table::PREDEFINED
,
2281 this, this->g_o_t(), 0,
2284 elfcpp::STV_HIDDEN
, 0,
2288 Output_data_got
<size
, big_endian
>::add_constant(0);
2291 // Stashed pointers.
2292 Symbol_table
* symtab_
;
2296 unsigned int header_ent_cnt_
;
2297 // GOT header index.
2298 unsigned int header_index_
;
2301 // Get the GOT section, creating it if necessary.
2303 template<int size
, bool big_endian
>
2304 Output_data_got_powerpc
<size
, big_endian
>*
2305 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2308 if (this->got_
== NULL
)
2310 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2313 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2315 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2316 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2317 this->got_
, ORDER_DATA
, false);
2323 // Get the dynamic reloc section, creating it if necessary.
2325 template<int size
, bool big_endian
>
2326 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2327 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2329 if (this->rela_dyn_
== NULL
)
2331 gold_assert(layout
!= NULL
);
2332 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2333 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2334 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2335 ORDER_DYNAMIC_RELOCS
, false);
2337 return this->rela_dyn_
;
2340 // Similarly, but for ifunc symbols get the one for ifunc.
2342 template<int size
, bool big_endian
>
2343 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2344 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2349 return this->rela_dyn_section(layout
);
2351 if (this->iplt_
== NULL
)
2352 this->make_iplt_section(symtab
, layout
);
2353 return this->iplt_
->rel_plt();
2359 // Determine the stub group size. The group size is the absolute
2360 // value of the parameter --stub-group-size. If --stub-group-size
2361 // is passed a negative value, we restrict stubs to be always before
2362 // the stubbed branches.
2363 Stub_control(int32_t size
)
2364 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
2365 stub14_group_size_(abs(size
)),
2366 stubs_always_before_branch_(size
< 0), suppress_size_errors_(false),
2367 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
2369 if (stub_group_size_
== 1)
2372 if (stubs_always_before_branch_
)
2374 stub_group_size_
= 0x1e00000;
2375 stub14_group_size_
= 0x7800;
2379 stub_group_size_
= 0x1c00000;
2380 stub14_group_size_
= 0x7000;
2382 suppress_size_errors_
= true;
2386 // Return true iff input section can be handled by current stub
2389 can_add_to_stub_group(Output_section
* o
,
2390 const Output_section::Input_section
* i
,
2393 const Output_section::Input_section
*
2399 { return output_section_
; }
2405 FINDING_STUB_SECTION
,
2410 uint32_t stub_group_size_
;
2411 uint32_t stub14_group_size_
;
2412 bool stubs_always_before_branch_
;
2413 bool suppress_size_errors_
;
2414 uint64_t group_end_addr_
;
2415 const Output_section::Input_section
* owner_
;
2416 Output_section
* output_section_
;
2419 // Return true iff input section can be handled by current stub
2423 Stub_control::can_add_to_stub_group(Output_section
* o
,
2424 const Output_section::Input_section
* i
,
2428 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
2429 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2431 uint64_t start_addr
= o
->address();
2434 // .init and .fini sections are pasted together to form a single
2435 // function. We can't be adding stubs in the middle of the function.
2436 this_size
= o
->data_size();
2439 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2440 this_size
= i
->data_size();
2442 uint64_t end_addr
= start_addr
+ this_size
;
2443 bool toobig
= this_size
> group_size
;
2445 if (toobig
&& !this->suppress_size_errors_
)
2446 gold_warning(_("%s:%s exceeds group size"),
2447 i
->relobj()->name().c_str(),
2448 i
->relobj()->section_name(i
->shndx()).c_str());
2450 if (this->state_
!= HAS_STUB_SECTION
2451 && (!whole_sec
|| this->output_section_
!= o
)
2452 && (this->state_
== NO_GROUP
2453 || this->group_end_addr_
- end_addr
< group_size
))
2456 this->output_section_
= o
;
2459 if (this->state_
== NO_GROUP
)
2461 this->state_
= FINDING_STUB_SECTION
;
2462 this->group_end_addr_
= end_addr
;
2464 else if (this->group_end_addr_
- start_addr
< group_size
)
2466 // Adding this section would make the group larger than GROUP_SIZE.
2467 else if (this->state_
== FINDING_STUB_SECTION
2468 && !this->stubs_always_before_branch_
2471 // But wait, there's more! Input sections up to GROUP_SIZE
2472 // bytes before the stub table can be handled by it too.
2473 this->state_
= HAS_STUB_SECTION
;
2474 this->group_end_addr_
= end_addr
;
2478 this->state_
= NO_GROUP
;
2484 // Look over all the input sections, deciding where to place stubs.
2486 template<int size
, bool big_endian
>
2488 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2491 Stub_control
stub_control(parameters
->options().stub_group_size());
2493 // Group input sections and insert stub table
2494 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
2495 Layout::Section_list section_list
;
2496 layout
->get_executable_sections(§ion_list
);
2497 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2498 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
2499 o
!= section_list
.rend();
2502 typedef Output_section::Input_section_list Input_section_list
;
2503 for (Input_section_list::const_reverse_iterator i
2504 = (*o
)->input_sections().rbegin();
2505 i
!= (*o
)->input_sections().rend();
2508 if (i
->is_input_section())
2510 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2511 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2512 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2513 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2515 stub_table
->init(stub_control
.owner(),
2516 stub_control
.output_section());
2519 if (stub_table
== NULL
)
2520 stub_table
= this->new_stub_table();
2521 ppcobj
->set_stub_table(i
->shndx(), stub_table
);
2525 if (stub_table
!= NULL
)
2527 const Output_section::Input_section
* i
= stub_control
.owner();
2528 if (!i
->is_input_section())
2530 // Corner case. A new stub group was made for the first
2531 // section (last one looked at here) for some reason, but
2532 // the first section is already being used as the owner for
2533 // a stub table for following sections. Force it into that
2535 gold_assert(this->stub_tables_
.size() >= 2);
2536 this->stub_tables_
.pop_back();
2538 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2539 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2540 ppcobj
->set_stub_table(i
->shndx(), this->stub_tables_
.back());
2543 stub_table
->init(i
, stub_control
.output_section());
2547 // If this branch needs a plt call stub, or a long branch stub, make one.
2549 template<int size
, bool big_endian
>
2551 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2552 Stub_table
<size
, big_endian
>* stub_table
,
2553 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2554 Symbol_table
* symtab
) const
2556 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2557 if (sym
!= NULL
&& sym
->is_forwarder())
2558 sym
= symtab
->resolve_forwards(sym
);
2559 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2560 Target_powerpc
<size
, big_endian
>* target
=
2561 static_cast<Target_powerpc
<size
, big_endian
>*>(
2562 parameters
->sized_target
<size
, big_endian
>());
2564 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
2565 : this->object_
->local_has_plt_offset(this->r_sym_
))
2569 && target
->abiversion() >= 2
2570 && !parameters
->options().output_is_position_independent()
2571 && !is_branch_reloc(this->r_type_
))
2572 target
->glink_section()->add_global_entry(gsym
);
2575 if (stub_table
== NULL
)
2576 stub_table
= this->object_
->stub_table(this->shndx_
);
2577 if (stub_table
== NULL
)
2579 // This is a ref from a data section to an ifunc symbol.
2580 stub_table
= ifunc_stub_table
;
2582 gold_assert(stub_table
!= NULL
);
2584 stub_table
->add_plt_call_entry(this->object_
, gsym
,
2585 this->r_type_
, this->addend_
);
2587 stub_table
->add_plt_call_entry(this->object_
, this->r_sym_
,
2588 this->r_type_
, this->addend_
);
2593 unsigned long max_branch_offset
;
2594 if (this->r_type_
== elfcpp::R_POWERPC_REL14
2595 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRTAKEN
2596 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2597 max_branch_offset
= 1 << 15;
2598 else if (this->r_type_
== elfcpp::R_POWERPC_REL24
2599 || this->r_type_
== elfcpp::R_PPC_PLTREL24
2600 || this->r_type_
== elfcpp::R_PPC_LOCAL24PC
)
2601 max_branch_offset
= 1 << 25;
2604 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2605 gold_assert(from
!= invalid_address
);
2606 from
+= (this->object_
->output_section(this->shndx_
)->address()
2611 switch (gsym
->source())
2613 case Symbol::FROM_OBJECT
:
2615 Object
* symobj
= gsym
->object();
2616 if (symobj
->is_dynamic()
2617 || symobj
->pluginobj() != NULL
)
2620 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2621 if (shndx
== elfcpp::SHN_UNDEF
)
2626 case Symbol::IS_UNDEFINED
:
2632 Symbol_table::Compute_final_value_status status
;
2633 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2634 if (status
!= Symbol_table::CFVS_OK
)
2637 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
2641 const Symbol_value
<size
>* psymval
2642 = this->object_
->local_symbol(this->r_sym_
);
2643 Symbol_value
<size
> symval
;
2644 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2645 typename
ObjType::Compute_final_local_value_status status
2646 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2648 if (status
!= ObjType::CFLV_OK
2649 || !symval
.has_output_value())
2651 to
= symval
.value(this->object_
, 0);
2653 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
2655 to
+= this->addend_
;
2656 if (stub_table
== NULL
)
2657 stub_table
= this->object_
->stub_table(this->shndx_
);
2658 if (size
== 64 && target
->abiversion() < 2)
2660 unsigned int dest_shndx
;
2661 to
= target
->symval_for_branch(symtab
, to
, gsym
,
2662 this->object_
, &dest_shndx
);
2664 Address delta
= to
- from
;
2665 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2667 if (stub_table
== NULL
)
2669 gold_warning(_("%s:%s: branch in non-executable section,"
2670 " no long branch stub for you"),
2671 this->object_
->name().c_str(),
2672 this->object_
->section_name(this->shndx_
).c_str());
2675 stub_table
->add_long_branch_entry(this->object_
, to
);
2680 // Relaxation hook. This is where we do stub generation.
2682 template<int size
, bool big_endian
>
2684 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2685 const Input_objects
*,
2686 Symbol_table
* symtab
,
2690 unsigned int prev_brlt_size
= 0;
2694 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
2696 && this->abiversion() < 2
2698 && !parameters
->options().user_set_plt_thread_safe())
2700 static const char* const thread_starter
[] =
2704 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2706 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2707 "mq_notify", "create_timer",
2712 "GOMP_parallel_start",
2713 "GOMP_parallel_loop_static",
2714 "GOMP_parallel_loop_static_start",
2715 "GOMP_parallel_loop_dynamic",
2716 "GOMP_parallel_loop_dynamic_start",
2717 "GOMP_parallel_loop_guided",
2718 "GOMP_parallel_loop_guided_start",
2719 "GOMP_parallel_loop_runtime",
2720 "GOMP_parallel_loop_runtime_start",
2721 "GOMP_parallel_sections",
2722 "GOMP_parallel_sections_start",
2725 if (parameters
->options().shared())
2729 for (unsigned int i
= 0;
2730 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2733 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2734 thread_safe
= (sym
!= NULL
2736 && sym
->in_real_elf());
2742 this->plt_thread_safe_
= thread_safe
;
2743 this->group_sections(layout
, task
);
2746 // We need address of stub tables valid for make_stub.
2747 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2748 p
!= this->stub_tables_
.end();
2751 const Powerpc_relobj
<size
, big_endian
>* object
2752 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2753 Address off
= object
->get_output_section_offset((*p
)->shndx());
2754 gold_assert(off
!= invalid_address
);
2755 Output_section
* os
= (*p
)->output_section();
2756 (*p
)->set_address_and_size(os
, off
);
2761 // Clear plt call stubs, long branch stubs and branch lookup table.
2762 prev_brlt_size
= this->branch_lookup_table_
.size();
2763 this->branch_lookup_table_
.clear();
2764 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2765 p
!= this->stub_tables_
.end();
2768 (*p
)->clear_stubs();
2772 // Build all the stubs.
2773 Stub_table
<size
, big_endian
>* ifunc_stub_table
2774 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2775 Stub_table
<size
, big_endian
>* one_stub_table
2776 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2777 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2778 b
!= this->branch_info_
.end();
2781 b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
);
2784 // Did anything change size?
2785 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2786 bool again
= num_huge_branches
!= prev_brlt_size
;
2787 if (size
== 64 && num_huge_branches
!= 0)
2788 this->make_brlt_section(layout
);
2789 if (size
== 64 && again
)
2790 this->brlt_section_
->set_current_size(num_huge_branches
);
2792 typedef Unordered_set
<Output_section
*> Output_sections
;
2793 Output_sections os_need_update
;
2794 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2795 p
!= this->stub_tables_
.end();
2798 if ((*p
)->size_update())
2801 (*p
)->add_eh_frame(layout
);
2802 os_need_update
.insert((*p
)->output_section());
2806 // Set output section offsets for all input sections in an output
2807 // section that just changed size. Anything past the stubs will
2809 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2810 p
!= os_need_update
.end();
2813 Output_section
* os
= *p
;
2815 typedef Output_section::Input_section_list Input_section_list
;
2816 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2817 i
!= os
->input_sections().end();
2820 off
= align_address(off
, i
->addralign());
2821 if (i
->is_input_section() || i
->is_relaxed_input_section())
2822 i
->relobj()->set_section_offset(i
->shndx(), off
);
2823 if (i
->is_relaxed_input_section())
2825 Stub_table
<size
, big_endian
>* stub_table
2826 = static_cast<Stub_table
<size
, big_endian
>*>(
2827 i
->relaxed_input_section());
2828 off
+= stub_table
->set_address_and_size(os
, off
);
2831 off
+= i
->data_size();
2833 // If .branch_lt is part of this output section, then we have
2834 // just done the offset adjustment.
2835 os
->clear_section_offsets_need_adjustment();
2840 && num_huge_branches
!= 0
2841 && parameters
->options().output_is_position_independent())
2843 // Fill in the BRLT relocs.
2844 this->brlt_section_
->reset_brlt_sizes();
2845 for (typename
Branch_lookup_table::const_iterator p
2846 = this->branch_lookup_table_
.begin();
2847 p
!= this->branch_lookup_table_
.end();
2850 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
2852 this->brlt_section_
->finalize_brlt_sizes();
2857 template<int size
, bool big_endian
>
2859 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
2860 unsigned char* oview
,
2864 uint64_t address
= plt
->address();
2865 off_t len
= plt
->data_size();
2867 if (plt
== this->glink_
)
2869 // See Output_data_glink::do_write() for glink contents.
2872 gold_assert(parameters
->doing_static_link());
2873 // Static linking may need stubs, to support ifunc and long
2874 // branches. We need to create an output section for
2875 // .eh_frame early in the link process, to have a place to
2876 // attach stub .eh_frame info. We also need to have
2877 // registered a CIE that matches the stub CIE. Both of
2878 // these requirements are satisfied by creating an FDE and
2879 // CIE for .glink, even though static linking will leave
2880 // .glink zero length.
2881 // ??? Hopefully generating an FDE with a zero address range
2882 // won't confuse anything that consumes .eh_frame info.
2884 else if (size
== 64)
2886 // There is one word before __glink_PLTresolve
2890 else if (parameters
->options().output_is_position_independent())
2892 // There are two FDEs for a position independent glink.
2893 // The first covers the branch table, the second
2894 // __glink_PLTresolve at the end of glink.
2895 off_t resolve_size
= this->glink_
->pltresolve_size
;
2896 if (oview
[9] == elfcpp::DW_CFA_nop
)
2897 len
-= resolve_size
;
2900 address
+= len
- resolve_size
;
2907 // Must be a stub table.
2908 const Stub_table
<size
, big_endian
>* stub_table
2909 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
2910 uint64_t stub_address
= stub_table
->stub_address();
2911 len
-= stub_address
- address
;
2912 address
= stub_address
;
2915 *paddress
= address
;
2919 // A class to handle the PLT data.
2921 template<int size
, bool big_endian
>
2922 class Output_data_plt_powerpc
: public Output_section_data_build
2925 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
2926 size
, big_endian
> Reloc_section
;
2928 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
2929 Reloc_section
* plt_rel
,
2931 : Output_section_data_build(size
== 32 ? 4 : 8),
2937 // Add an entry to the PLT.
2942 add_ifunc_entry(Symbol
*);
2945 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
2947 // Return the .rela.plt section data.
2954 // Return the number of PLT entries.
2958 if (this->current_data_size() == 0)
2960 return ((this->current_data_size() - this->first_plt_entry_offset())
2961 / this->plt_entry_size());
2966 do_adjust_output_section(Output_section
* os
)
2971 // Write to a map file.
2973 do_print_to_mapfile(Mapfile
* mapfile
) const
2974 { mapfile
->print_output_data(this, this->name_
); }
2977 // Return the offset of the first non-reserved PLT entry.
2979 first_plt_entry_offset() const
2981 // IPLT has no reserved entry.
2982 if (this->name_
[3] == 'I')
2984 return this->targ_
->first_plt_entry_offset();
2987 // Return the size of each PLT entry.
2989 plt_entry_size() const
2991 return this->targ_
->plt_entry_size();
2994 // Write out the PLT data.
2996 do_write(Output_file
*);
2998 // The reloc section.
2999 Reloc_section
* rel_
;
3000 // Allows access to .glink for do_write.
3001 Target_powerpc
<size
, big_endian
>* targ_
;
3002 // What to report in map file.
3006 // Add an entry to the PLT.
3008 template<int size
, bool big_endian
>
3010 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3012 if (!gsym
->has_plt_offset())
3014 section_size_type off
= this->current_data_size();
3016 off
+= this->first_plt_entry_offset();
3017 gsym
->set_plt_offset(off
);
3018 gsym
->set_needs_dynsym_entry();
3019 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3020 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3021 off
+= this->plt_entry_size();
3022 this->set_current_data_size(off
);
3026 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3028 template<int size
, bool big_endian
>
3030 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3032 if (!gsym
->has_plt_offset())
3034 section_size_type off
= this->current_data_size();
3035 gsym
->set_plt_offset(off
);
3036 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3037 if (size
== 64 && this->targ_
->abiversion() < 2)
3038 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3039 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3040 off
+= this->plt_entry_size();
3041 this->set_current_data_size(off
);
3045 // Add an entry for a local ifunc symbol to the IPLT.
3047 template<int size
, bool big_endian
>
3049 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3050 Sized_relobj_file
<size
, big_endian
>* relobj
,
3051 unsigned int local_sym_index
)
3053 if (!relobj
->local_has_plt_offset(local_sym_index
))
3055 section_size_type off
= this->current_data_size();
3056 relobj
->set_local_plt_offset(local_sym_index
, off
);
3057 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3058 if (size
== 64 && this->targ_
->abiversion() < 2)
3059 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3060 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3062 off
+= this->plt_entry_size();
3063 this->set_current_data_size(off
);
3067 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3068 static const uint32_t add_2_2_11
= 0x7c425a14;
3069 static const uint32_t add_3_3_2
= 0x7c631214;
3070 static const uint32_t add_3_3_13
= 0x7c636a14;
3071 static const uint32_t add_11_0_11
= 0x7d605a14;
3072 static const uint32_t add_11_2_11
= 0x7d625a14;
3073 static const uint32_t add_11_11_2
= 0x7d6b1214;
3074 static const uint32_t addi_0_12
= 0x380c0000;
3075 static const uint32_t addi_2_2
= 0x38420000;
3076 static const uint32_t addi_3_3
= 0x38630000;
3077 static const uint32_t addi_11_11
= 0x396b0000;
3078 static const uint32_t addi_12_12
= 0x398c0000;
3079 static const uint32_t addis_0_2
= 0x3c020000;
3080 static const uint32_t addis_0_13
= 0x3c0d0000;
3081 static const uint32_t addis_3_2
= 0x3c620000;
3082 static const uint32_t addis_3_13
= 0x3c6d0000;
3083 static const uint32_t addis_11_2
= 0x3d620000;
3084 static const uint32_t addis_11_11
= 0x3d6b0000;
3085 static const uint32_t addis_11_30
= 0x3d7e0000;
3086 static const uint32_t addis_12_2
= 0x3d820000;
3087 static const uint32_t addis_12_12
= 0x3d8c0000;
3088 static const uint32_t b
= 0x48000000;
3089 static const uint32_t bcl_20_31
= 0x429f0005;
3090 static const uint32_t bctr
= 0x4e800420;
3091 static const uint32_t blr
= 0x4e800020;
3092 static const uint32_t bnectr_p4
= 0x4ce20420;
3093 static const uint32_t cmpldi_2_0
= 0x28220000;
3094 static const uint32_t cror_15_15_15
= 0x4def7b82;
3095 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3096 static const uint32_t ld_0_1
= 0xe8010000;
3097 static const uint32_t ld_0_12
= 0xe80c0000;
3098 static const uint32_t ld_2_1
= 0xe8410000;
3099 static const uint32_t ld_2_2
= 0xe8420000;
3100 static const uint32_t ld_2_11
= 0xe84b0000;
3101 static const uint32_t ld_11_2
= 0xe9620000;
3102 static const uint32_t ld_11_11
= 0xe96b0000;
3103 static const uint32_t ld_12_2
= 0xe9820000;
3104 static const uint32_t ld_12_11
= 0xe98b0000;
3105 static const uint32_t ld_12_12
= 0xe98c0000;
3106 static const uint32_t lfd_0_1
= 0xc8010000;
3107 static const uint32_t li_0_0
= 0x38000000;
3108 static const uint32_t li_12_0
= 0x39800000;
3109 static const uint32_t lis_0_0
= 0x3c000000;
3110 static const uint32_t lis_11
= 0x3d600000;
3111 static const uint32_t lis_12
= 0x3d800000;
3112 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3113 static const uint32_t lwz_0_12
= 0x800c0000;
3114 static const uint32_t lwz_11_11
= 0x816b0000;
3115 static const uint32_t lwz_11_30
= 0x817e0000;
3116 static const uint32_t lwz_12_12
= 0x818c0000;
3117 static const uint32_t lwzu_0_12
= 0x840c0000;
3118 static const uint32_t mflr_0
= 0x7c0802a6;
3119 static const uint32_t mflr_11
= 0x7d6802a6;
3120 static const uint32_t mflr_12
= 0x7d8802a6;
3121 static const uint32_t mtctr_0
= 0x7c0903a6;
3122 static const uint32_t mtctr_11
= 0x7d6903a6;
3123 static const uint32_t mtctr_12
= 0x7d8903a6;
3124 static const uint32_t mtlr_0
= 0x7c0803a6;
3125 static const uint32_t mtlr_12
= 0x7d8803a6;
3126 static const uint32_t nop
= 0x60000000;
3127 static const uint32_t ori_0_0_0
= 0x60000000;
3128 static const uint32_t srdi_0_0_2
= 0x7800f082;
3129 static const uint32_t std_0_1
= 0xf8010000;
3130 static const uint32_t std_0_12
= 0xf80c0000;
3131 static const uint32_t std_2_1
= 0xf8410000;
3132 static const uint32_t stfd_0_1
= 0xd8010000;
3133 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3134 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3135 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3136 static const uint32_t xor_2_12_12
= 0x7d826278;
3137 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3139 // Write out the PLT.
3141 template<int size
, bool big_endian
>
3143 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3145 if (size
== 32 && this->name_
[3] != 'I')
3147 const section_size_type offset
= this->offset();
3148 const section_size_type oview_size
3149 = convert_to_section_size_type(this->data_size());
3150 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3151 unsigned char* pov
= oview
;
3152 unsigned char* endpov
= oview
+ oview_size
;
3154 // The address of the .glink branch table
3155 const Output_data_glink
<size
, big_endian
>* glink
3156 = this->targ_
->glink_section();
3157 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3159 while (pov
< endpov
)
3161 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3166 of
->write_output_view(offset
, oview_size
, oview
);
3170 // Create the PLT section.
3172 template<int size
, bool big_endian
>
3174 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3177 if (this->plt_
== NULL
)
3179 if (this->got_
== NULL
)
3180 this->got_section(symtab
, layout
);
3182 if (this->glink_
== NULL
)
3183 make_glink_section(layout
);
3185 // Ensure that .rela.dyn always appears before .rela.plt This is
3186 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3187 // needs to include .rela.plt in its range.
3188 this->rela_dyn_section(layout
);
3190 Reloc_section
* plt_rel
= new Reloc_section(false);
3191 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3192 elfcpp::SHF_ALLOC
, plt_rel
,
3193 ORDER_DYNAMIC_PLT_RELOCS
, false);
3195 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3197 layout
->add_output_section_data(".plt",
3199 ? elfcpp::SHT_PROGBITS
3200 : elfcpp::SHT_NOBITS
),
3201 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3210 // Create the IPLT section.
3212 template<int size
, bool big_endian
>
3214 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3217 if (this->iplt_
== NULL
)
3219 this->make_plt_section(symtab
, layout
);
3221 Reloc_section
* iplt_rel
= new Reloc_section(false);
3222 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3224 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3226 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3230 // A section for huge long branch addresses, similar to plt section.
3232 template<int size
, bool big_endian
>
3233 class Output_data_brlt_powerpc
: public Output_section_data_build
3236 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3237 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3238 size
, big_endian
> Reloc_section
;
3240 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3241 Reloc_section
* brlt_rel
)
3242 : Output_section_data_build(size
== 32 ? 4 : 8),
3250 this->reset_data_size();
3251 this->rel_
->reset_data_size();
3255 finalize_brlt_sizes()
3257 this->finalize_data_size();
3258 this->rel_
->finalize_data_size();
3261 // Add a reloc for an entry in the BRLT.
3263 add_reloc(Address to
, unsigned int off
)
3264 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
3266 // Update section and reloc section size.
3268 set_current_size(unsigned int num_branches
)
3270 this->reset_address_and_file_offset();
3271 this->set_current_data_size(num_branches
* 16);
3272 this->finalize_data_size();
3273 Output_section
* os
= this->output_section();
3274 os
->set_section_offsets_need_adjustment();
3275 if (this->rel_
!= NULL
)
3277 unsigned int reloc_size
3278 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
3279 this->rel_
->reset_address_and_file_offset();
3280 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
3281 this->rel_
->finalize_data_size();
3282 Output_section
* os
= this->rel_
->output_section();
3283 os
->set_section_offsets_need_adjustment();
3289 do_adjust_output_section(Output_section
* os
)
3294 // Write to a map file.
3296 do_print_to_mapfile(Mapfile
* mapfile
) const
3297 { mapfile
->print_output_data(this, "** BRLT"); }
3300 // Write out the BRLT data.
3302 do_write(Output_file
*);
3304 // The reloc section.
3305 Reloc_section
* rel_
;
3306 Target_powerpc
<size
, big_endian
>* targ_
;
3309 // Make the branch lookup table section.
3311 template<int size
, bool big_endian
>
3313 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
3315 if (size
== 64 && this->brlt_section_
== NULL
)
3317 Reloc_section
* brlt_rel
= NULL
;
3318 bool is_pic
= parameters
->options().output_is_position_independent();
3321 // When PIC we can't fill in .branch_lt (like .plt it can be
3322 // a bss style section) but must initialise at runtime via
3323 // dynamic relocats.
3324 this->rela_dyn_section(layout
);
3325 brlt_rel
= new Reloc_section(false);
3326 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3329 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3330 if (this->plt_
&& is_pic
)
3331 this->plt_
->output_section()
3332 ->add_output_section_data(this->brlt_section_
);
3334 layout
->add_output_section_data(".branch_lt",
3335 (is_pic
? elfcpp::SHT_NOBITS
3336 : elfcpp::SHT_PROGBITS
),
3337 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3338 this->brlt_section_
,
3339 (is_pic
? ORDER_SMALL_BSS
3340 : ORDER_SMALL_DATA
),
3345 // Write out .branch_lt when non-PIC.
3347 template<int size
, bool big_endian
>
3349 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3351 if (size
== 64 && !parameters
->options().output_is_position_independent())
3353 const section_size_type offset
= this->offset();
3354 const section_size_type oview_size
3355 = convert_to_section_size_type(this->data_size());
3356 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3358 this->targ_
->write_branch_lookup_table(oview
);
3359 of
->write_output_view(offset
, oview_size
, oview
);
3363 static inline uint32_t
3369 static inline uint32_t
3375 static inline uint32_t
3378 return hi(a
+ 0x8000);
3384 static const unsigned char eh_frame_cie
[12];
3388 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3391 'z', 'R', 0, // Augmentation string.
3392 4, // Code alignment.
3393 0x80 - size
/ 8 , // Data alignment.
3395 1, // Augmentation size.
3396 (elfcpp::DW_EH_PE_pcrel
3397 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3398 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3401 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3402 static const unsigned char glink_eh_frame_fde_64v1
[] =
3404 0, 0, 0, 0, // Replaced with offset to .glink.
3405 0, 0, 0, 0, // Replaced with size of .glink.
3406 0, // Augmentation size.
3407 elfcpp::DW_CFA_advance_loc
+ 1,
3408 elfcpp::DW_CFA_register
, 65, 12,
3409 elfcpp::DW_CFA_advance_loc
+ 4,
3410 elfcpp::DW_CFA_restore_extended
, 65
3413 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3414 static const unsigned char glink_eh_frame_fde_64v2
[] =
3416 0, 0, 0, 0, // Replaced with offset to .glink.
3417 0, 0, 0, 0, // Replaced with size of .glink.
3418 0, // Augmentation size.
3419 elfcpp::DW_CFA_advance_loc
+ 1,
3420 elfcpp::DW_CFA_register
, 65, 0,
3421 elfcpp::DW_CFA_advance_loc
+ 4,
3422 elfcpp::DW_CFA_restore_extended
, 65
3425 // Describe __glink_PLTresolve use of LR, 32-bit version.
3426 static const unsigned char glink_eh_frame_fde_32
[] =
3428 0, 0, 0, 0, // Replaced with offset to .glink.
3429 0, 0, 0, 0, // Replaced with size of .glink.
3430 0, // Augmentation size.
3431 elfcpp::DW_CFA_advance_loc
+ 2,
3432 elfcpp::DW_CFA_register
, 65, 0,
3433 elfcpp::DW_CFA_advance_loc
+ 4,
3434 elfcpp::DW_CFA_restore_extended
, 65
3437 static const unsigned char default_fde
[] =
3439 0, 0, 0, 0, // Replaced with offset to stubs.
3440 0, 0, 0, 0, // Replaced with size of stubs.
3441 0, // Augmentation size.
3442 elfcpp::DW_CFA_nop
, // Pad.
3447 template<bool big_endian
>
3449 write_insn(unsigned char* p
, uint32_t v
)
3451 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3454 // Stub_table holds information about plt and long branch stubs.
3455 // Stubs are built in an area following some input section determined
3456 // by group_sections(). This input section is converted to a relaxed
3457 // input section allowing it to be resized to accommodate the stubs
3459 template<int size
, bool big_endian
>
3460 class Stub_table
: public Output_relaxed_input_section
3463 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3464 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3466 Stub_table(Target_powerpc
<size
, big_endian
>* targ
)
3467 : Output_relaxed_input_section(NULL
, 0, 0),
3468 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3469 orig_data_size_(0), plt_size_(0), last_plt_size_(0),
3470 branch_size_(0), last_branch_size_(0), eh_frame_added_(false)
3473 // Delayed Output_relaxed_input_section init.
3475 init(const Output_section::Input_section
*, Output_section
*);
3477 // Add a plt call stub.
3479 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3485 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3490 // Find a given plt call stub.
3492 find_plt_call_entry(const Symbol
*) const;
3495 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3496 unsigned int) const;
3499 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3505 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3510 // Add a long branch stub.
3512 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*, Address
);
3515 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3521 this->plt_call_stubs_
.clear();
3522 this->plt_size_
= 0;
3523 this->long_branch_stubs_
.clear();
3524 this->branch_size_
= 0;
3528 set_address_and_size(const Output_section
* os
, Address off
)
3530 Address start_off
= off
;
3531 off
+= this->orig_data_size_
;
3532 Address my_size
= this->plt_size_
+ this->branch_size_
;
3534 off
= align_address(off
, this->stub_align());
3535 // Include original section size and alignment padding in size
3536 my_size
+= off
- start_off
;
3537 this->reset_address_and_file_offset();
3538 this->set_current_data_size(my_size
);
3539 this->set_address_and_file_offset(os
->address() + start_off
,
3540 os
->offset() + start_off
);
3545 stub_address() const
3547 return align_address(this->address() + this->orig_data_size_
,
3548 this->stub_align());
3554 return align_address(this->offset() + this->orig_data_size_
,
3555 this->stub_align());
3560 { return this->plt_size_
; }
3565 Output_section
* os
= this->output_section();
3566 if (os
->addralign() < this->stub_align())
3568 os
->set_addralign(this->stub_align());
3569 // FIXME: get rid of the insane checkpointing.
3570 // We can't increase alignment of the input section to which
3571 // stubs are attached; The input section may be .init which
3572 // is pasted together with other .init sections to form a
3573 // function. Aligning might insert zero padding resulting in
3574 // sigill. However we do need to increase alignment of the
3575 // output section so that the align_address() on offset in
3576 // set_address_and_size() adds the same padding as the
3577 // align_address() on address in stub_address().
3578 // What's more, we need this alignment for the layout done in
3579 // relaxation_loop_body() so that the output section starts at
3580 // a suitably aligned address.
3581 os
->checkpoint_set_addralign(this->stub_align());
3583 if (this->last_plt_size_
!= this->plt_size_
3584 || this->last_branch_size_
!= this->branch_size_
)
3586 this->last_plt_size_
= this->plt_size_
;
3587 this->last_branch_size_
= this->branch_size_
;
3593 // Add .eh_frame info for this stub section. Unlike other linker
3594 // generated .eh_frame this is added late in the link, because we
3595 // only want the .eh_frame info if this particular stub section is
3598 add_eh_frame(Layout
* layout
)
3600 if (!this->eh_frame_added_
)
3602 if (!parameters
->options().ld_generated_unwind_info())
3605 // Since we add stub .eh_frame info late, it must be placed
3606 // after all other linker generated .eh_frame info so that
3607 // merge mapping need not be updated for input sections.
3608 // There is no provision to use a different CIE to that used
3610 if (!this->targ_
->has_glink())
3613 layout
->add_eh_frame_for_plt(this,
3614 Eh_cie
<size
>::eh_frame_cie
,
3615 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3617 sizeof (default_fde
));
3618 this->eh_frame_added_
= true;
3622 Target_powerpc
<size
, big_endian
>*
3628 class Plt_stub_ent_hash
;
3629 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3630 Plt_stub_ent_hash
> Plt_stub_entries
;
3632 // Alignment of stub section.
3638 unsigned int min_align
= 32;
3639 unsigned int user_align
= 1 << parameters
->options().plt_align();
3640 return std::max(user_align
, min_align
);
3643 // Return the plt offset for the given call stub.
3645 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3647 const Symbol
* gsym
= p
->first
.sym_
;
3650 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3651 && gsym
->can_use_relative_reloc(false));
3652 return gsym
->plt_offset();
3657 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3658 unsigned int local_sym_index
= p
->first
.locsym_
;
3659 return relobj
->local_plt_offset(local_sym_index
);
3663 // Size of a given plt call stub.
3665 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3671 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3673 plt_addr
+= this->targ_
->iplt_section()->address();
3675 plt_addr
+= this->targ_
->plt_section()->address();
3676 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3677 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3678 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3679 got_addr
+= ppcobj
->toc_base_offset();
3680 Address off
= plt_addr
- got_addr
;
3681 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
3682 if (this->targ_
->abiversion() < 2)
3684 bool static_chain
= parameters
->options().plt_static_chain();
3685 bool thread_safe
= this->targ_
->plt_thread_safe();
3689 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3691 unsigned int align
= 1 << parameters
->options().plt_align();
3693 bytes
= (bytes
+ align
- 1) & -align
;
3697 // Return long branch stub size.
3699 branch_stub_size(Address to
)
3702 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3703 if (to
- loc
+ (1 << 25) < 2 << 25)
3705 if (size
== 64 || !parameters
->options().output_is_position_independent())
3712 do_write(Output_file
*);
3714 // Plt call stub keys.
3718 Plt_stub_ent(const Symbol
* sym
)
3719 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3722 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3723 unsigned int locsym_index
)
3724 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3727 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3729 unsigned int r_type
,
3731 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3734 this->addend_
= addend
;
3735 else if (parameters
->options().output_is_position_independent()
3736 && r_type
== elfcpp::R_PPC_PLTREL24
)
3738 this->addend_
= addend
;
3739 if (this->addend_
>= 32768)
3740 this->object_
= object
;
3744 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3745 unsigned int locsym_index
,
3746 unsigned int r_type
,
3748 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3751 this->addend_
= addend
;
3752 else if (parameters
->options().output_is_position_independent()
3753 && r_type
== elfcpp::R_PPC_PLTREL24
)
3754 this->addend_
= addend
;
3757 bool operator==(const Plt_stub_ent
& that
) const
3759 return (this->sym_
== that
.sym_
3760 && this->object_
== that
.object_
3761 && this->addend_
== that
.addend_
3762 && this->locsym_
== that
.locsym_
);
3766 const Sized_relobj_file
<size
, big_endian
>* object_
;
3767 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
3768 unsigned int locsym_
;
3771 class Plt_stub_ent_hash
3774 size_t operator()(const Plt_stub_ent
& ent
) const
3776 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
3777 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
3783 // Long branch stub keys.
3784 class Branch_stub_ent
3787 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
3788 : dest_(to
), toc_base_off_(0)
3791 toc_base_off_
= obj
->toc_base_offset();
3794 bool operator==(const Branch_stub_ent
& that
) const
3796 return (this->dest_
== that
.dest_
3798 || this->toc_base_off_
== that
.toc_base_off_
));
3802 unsigned int toc_base_off_
;
3805 class Branch_stub_ent_hash
3808 size_t operator()(const Branch_stub_ent
& ent
) const
3809 { return ent
.dest_
^ ent
.toc_base_off_
; }
3812 // In a sane world this would be a global.
3813 Target_powerpc
<size
, big_endian
>* targ_
;
3814 // Map sym/object/addend to stub offset.
3815 Plt_stub_entries plt_call_stubs_
;
3816 // Map destination address to stub offset.
3817 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
3818 Branch_stub_ent_hash
> Branch_stub_entries
;
3819 Branch_stub_entries long_branch_stubs_
;
3820 // size of input section
3821 section_size_type orig_data_size_
;
3823 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
3824 // Whether .eh_frame info has been created for this stub section.
3825 bool eh_frame_added_
;
3828 // Make a new stub table, and record.
3830 template<int size
, bool big_endian
>
3831 Stub_table
<size
, big_endian
>*
3832 Target_powerpc
<size
, big_endian
>::new_stub_table()
3834 Stub_table
<size
, big_endian
>* stub_table
3835 = new Stub_table
<size
, big_endian
>(this);
3836 this->stub_tables_
.push_back(stub_table
);
3840 // Delayed stub table initialisation, because we create the stub table
3841 // before we know to which section it will be attached.
3843 template<int size
, bool big_endian
>
3845 Stub_table
<size
, big_endian
>::init(
3846 const Output_section::Input_section
* owner
,
3847 Output_section
* output_section
)
3849 this->set_relobj(owner
->relobj());
3850 this->set_shndx(owner
->shndx());
3851 this->set_addralign(this->relobj()->section_addralign(this->shndx()));
3852 this->set_output_section(output_section
);
3853 this->orig_data_size_
= owner
->current_data_size();
3855 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3856 new_relaxed
.push_back(this);
3857 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3860 // Add a plt call stub, if we do not already have one for this
3861 // sym/object/addend combo.
3863 template<int size
, bool big_endian
>
3865 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3866 const Sized_relobj_file
<size
, big_endian
>* object
,
3868 unsigned int r_type
,
3871 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3872 unsigned int off
= this->plt_size_
;
3873 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3874 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3876 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3879 template<int size
, bool big_endian
>
3881 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3882 const Sized_relobj_file
<size
, big_endian
>* object
,
3883 unsigned int locsym_index
,
3884 unsigned int r_type
,
3887 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3888 unsigned int off
= this->plt_size_
;
3889 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3890 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3892 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3895 // Find a plt call stub.
3897 template<int size
, bool big_endian
>
3898 typename Stub_table
<size
, big_endian
>::Address
3899 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3900 const Sized_relobj_file
<size
, big_endian
>* object
,
3902 unsigned int r_type
,
3903 Address addend
) const
3905 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3906 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3907 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3910 template<int size
, bool big_endian
>
3911 typename Stub_table
<size
, big_endian
>::Address
3912 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
3914 Plt_stub_ent
ent(gsym
);
3915 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3916 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3919 template<int size
, bool big_endian
>
3920 typename Stub_table
<size
, big_endian
>::Address
3921 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3922 const Sized_relobj_file
<size
, big_endian
>* object
,
3923 unsigned int locsym_index
,
3924 unsigned int r_type
,
3925 Address addend
) const
3927 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3928 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3929 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3932 template<int size
, bool big_endian
>
3933 typename Stub_table
<size
, big_endian
>::Address
3934 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3935 const Sized_relobj_file
<size
, big_endian
>* object
,
3936 unsigned int locsym_index
) const
3938 Plt_stub_ent
ent(object
, locsym_index
);
3939 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3940 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3943 // Add a long branch stub if we don't already have one to given
3946 template<int size
, bool big_endian
>
3948 Stub_table
<size
, big_endian
>::add_long_branch_entry(
3949 const Powerpc_relobj
<size
, big_endian
>* object
,
3952 Branch_stub_ent
ent(object
, to
);
3953 Address off
= this->branch_size_
;
3954 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
3956 unsigned int stub_size
= this->branch_stub_size(to
);
3957 this->branch_size_
= off
+ stub_size
;
3958 if (size
== 64 && stub_size
!= 4)
3959 this->targ_
->add_branch_lookup_table(to
);
3963 // Find long branch stub.
3965 template<int size
, bool big_endian
>
3966 typename Stub_table
<size
, big_endian
>::Address
3967 Stub_table
<size
, big_endian
>::find_long_branch_entry(
3968 const Powerpc_relobj
<size
, big_endian
>* object
,
3971 Branch_stub_ent
ent(object
, to
);
3972 typename
Branch_stub_entries::const_iterator p
3973 = this->long_branch_stubs_
.find(ent
);
3974 return p
== this->long_branch_stubs_
.end() ? invalid_address
: p
->second
;
3977 // A class to handle .glink.
3979 template<int size
, bool big_endian
>
3980 class Output_data_glink
: public Output_section_data
3983 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3984 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3985 static const int pltresolve_size
= 16*4;
3987 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
3988 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
3989 end_branch_table_(), ge_size_(0)
3993 add_eh_frame(Layout
* layout
);
3996 add_global_entry(const Symbol
*);
3999 find_global_entry(const Symbol
*) const;
4002 global_entry_address() const
4004 gold_assert(this->is_data_size_valid());
4005 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4006 return this->address() + global_entry_off
;
4010 // Write to a map file.
4012 do_print_to_mapfile(Mapfile
* mapfile
) const
4013 { mapfile
->print_output_data(this, _("** glink")); }
4017 set_final_data_size();
4021 do_write(Output_file
*);
4023 // Allows access to .got and .plt for do_write.
4024 Target_powerpc
<size
, big_endian
>* targ_
;
4026 // Map sym to stub offset.
4027 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4028 Global_entry_stub_entries global_entry_stubs_
;
4030 unsigned int end_branch_table_
, ge_size_
;
4033 template<int size
, bool big_endian
>
4035 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4037 if (!parameters
->options().ld_generated_unwind_info())
4042 if (this->targ_
->abiversion() < 2)
4043 layout
->add_eh_frame_for_plt(this,
4044 Eh_cie
<64>::eh_frame_cie
,
4045 sizeof (Eh_cie
<64>::eh_frame_cie
),
4046 glink_eh_frame_fde_64v1
,
4047 sizeof (glink_eh_frame_fde_64v1
));
4049 layout
->add_eh_frame_for_plt(this,
4050 Eh_cie
<64>::eh_frame_cie
,
4051 sizeof (Eh_cie
<64>::eh_frame_cie
),
4052 glink_eh_frame_fde_64v2
,
4053 sizeof (glink_eh_frame_fde_64v2
));
4057 // 32-bit .glink can use the default since the CIE return
4058 // address reg, LR, is valid.
4059 layout
->add_eh_frame_for_plt(this,
4060 Eh_cie
<32>::eh_frame_cie
,
4061 sizeof (Eh_cie
<32>::eh_frame_cie
),
4063 sizeof (default_fde
));
4064 // Except where LR is used in a PIC __glink_PLTresolve.
4065 if (parameters
->options().output_is_position_independent())
4066 layout
->add_eh_frame_for_plt(this,
4067 Eh_cie
<32>::eh_frame_cie
,
4068 sizeof (Eh_cie
<32>::eh_frame_cie
),
4069 glink_eh_frame_fde_32
,
4070 sizeof (glink_eh_frame_fde_32
));
4074 template<int size
, bool big_endian
>
4076 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
4078 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
4079 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, this->ge_size_
));
4081 this->ge_size_
+= 16;
4084 template<int size
, bool big_endian
>
4085 typename Output_data_glink
<size
, big_endian
>::Address
4086 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
4088 typename
Global_entry_stub_entries::const_iterator p
4089 = this->global_entry_stubs_
.find(gsym
);
4090 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
4093 template<int size
, bool big_endian
>
4095 Output_data_glink
<size
, big_endian
>::set_final_data_size()
4097 unsigned int count
= this->targ_
->plt_entry_count();
4098 section_size_type total
= 0;
4104 // space for branch table
4105 total
+= 4 * (count
- 1);
4107 total
+= -total
& 15;
4108 total
+= this->pltresolve_size
;
4112 total
+= this->pltresolve_size
;
4114 // space for branch table
4116 if (this->targ_
->abiversion() < 2)
4120 total
+= 4 * (count
- 0x8000);
4124 this->end_branch_table_
= total
;
4125 total
= (total
+ 15) & -16;
4126 total
+= this->ge_size_
;
4128 this->set_data_size(total
);
4131 // Write out plt and long branch stub code.
4133 template<int size
, bool big_endian
>
4135 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
4137 if (this->plt_call_stubs_
.empty()
4138 && this->long_branch_stubs_
.empty())
4141 const section_size_type start_off
= this->offset();
4142 const section_size_type off
= this->stub_offset();
4143 const section_size_type oview_size
=
4144 convert_to_section_size_type(this->data_size() - (off
- start_off
));
4145 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4150 const Output_data_got_powerpc
<size
, big_endian
>* got
4151 = this->targ_
->got_section();
4152 Address got_os_addr
= got
->output_section()->address();
4154 if (!this->plt_call_stubs_
.empty())
4156 // The base address of the .plt section.
4157 Address plt_base
= this->targ_
->plt_section()->address();
4158 Address iplt_base
= invalid_address
;
4160 // Write out plt call stubs.
4161 typename
Plt_stub_entries::const_iterator cs
;
4162 for (cs
= this->plt_call_stubs_
.begin();
4163 cs
!= this->plt_call_stubs_
.end();
4167 Address pltoff
= this->plt_off(cs
, &is_iplt
);
4168 Address plt_addr
= pltoff
;
4171 if (iplt_base
== invalid_address
)
4172 iplt_base
= this->targ_
->iplt_section()->address();
4173 plt_addr
+= iplt_base
;
4176 plt_addr
+= plt_base
;
4177 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4178 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
4179 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
4180 Address off
= plt_addr
- got_addr
;
4182 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
4183 gold_error(_("%s: linkage table error against `%s'"),
4184 cs
->first
.object_
->name().c_str(),
4185 cs
->first
.sym_
->demangled_name().c_str());
4187 bool plt_load_toc
= this->targ_
->abiversion() < 2;
4189 = plt_load_toc
&& parameters
->options().plt_static_chain();
4191 = plt_load_toc
&& this->targ_
->plt_thread_safe();
4192 bool use_fake_dep
= false;
4193 Address cmp_branch_off
= 0;
4196 unsigned int pltindex
4197 = ((pltoff
- this->targ_
->first_plt_entry_offset())
4198 / this->targ_
->plt_entry_size());
4200 = (this->targ_
->glink_section()->pltresolve_size
4202 if (pltindex
> 32768)
4203 glinkoff
+= (pltindex
- 32768) * 4;
4205 = this->targ_
->glink_section()->address() + glinkoff
;
4207 = (this->stub_address() + cs
->second
+ 24
4208 + 4 * (ha(off
) != 0)
4209 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4210 + 4 * static_chain
);
4211 cmp_branch_off
= to
- from
;
4212 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
4215 p
= oview
+ cs
->second
;
4218 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4222 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
4224 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
4229 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
4231 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
4235 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4237 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
4241 write_insn
<big_endian
>(p
, mtctr_12
);
4247 write_insn
<big_endian
>(p
, xor_2_12_12
);
4249 write_insn
<big_endian
>(p
, add_11_11_2
);
4252 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
4256 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
4263 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4265 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
4268 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4270 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
4274 write_insn
<big_endian
>(p
, mtctr_12
);
4280 write_insn
<big_endian
>(p
, xor_11_12_12
);
4282 write_insn
<big_endian
>(p
, add_2_2_11
);
4287 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
4290 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
4294 if (thread_safe
&& !use_fake_dep
)
4296 write_insn
<big_endian
>(p
, cmpldi_2_0
);
4298 write_insn
<big_endian
>(p
, bnectr_p4
);
4300 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
4303 write_insn
<big_endian
>(p
, bctr
);
4307 // Write out long branch stubs.
4308 typename
Branch_stub_entries::const_iterator bs
;
4309 for (bs
= this->long_branch_stubs_
.begin();
4310 bs
!= this->long_branch_stubs_
.end();
4313 p
= oview
+ this->plt_size_
+ bs
->second
;
4314 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4315 Address delta
= bs
->first
.dest_
- loc
;
4316 if (delta
+ (1 << 25) < 2 << 25)
4317 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4321 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
4322 gold_assert(brlt_addr
!= invalid_address
);
4323 brlt_addr
+= this->targ_
->brlt_section()->address();
4324 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
4325 Address brltoff
= brlt_addr
- got_addr
;
4326 if (ha(brltoff
) == 0)
4328 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
4332 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
4333 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
4335 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4336 write_insn
<big_endian
>(p
, bctr
);
4342 if (!this->plt_call_stubs_
.empty())
4344 // The base address of the .plt section.
4345 Address plt_base
= this->targ_
->plt_section()->address();
4346 Address iplt_base
= invalid_address
;
4347 // The address of _GLOBAL_OFFSET_TABLE_.
4348 Address g_o_t
= invalid_address
;
4350 // Write out plt call stubs.
4351 typename
Plt_stub_entries::const_iterator cs
;
4352 for (cs
= this->plt_call_stubs_
.begin();
4353 cs
!= this->plt_call_stubs_
.end();
4357 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
4360 if (iplt_base
== invalid_address
)
4361 iplt_base
= this->targ_
->iplt_section()->address();
4362 plt_addr
+= iplt_base
;
4365 plt_addr
+= plt_base
;
4367 p
= oview
+ cs
->second
;
4368 if (parameters
->options().output_is_position_independent())
4371 const Powerpc_relobj
<size
, big_endian
>* ppcobj
4372 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
4373 (cs
->first
.object_
));
4374 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
4376 unsigned int got2
= ppcobj
->got2_shndx();
4377 got_addr
= ppcobj
->get_output_section_offset(got2
);
4378 gold_assert(got_addr
!= invalid_address
);
4379 got_addr
+= (ppcobj
->output_section(got2
)->address()
4380 + cs
->first
.addend_
);
4384 if (g_o_t
== invalid_address
)
4386 const Output_data_got_powerpc
<size
, big_endian
>* got
4387 = this->targ_
->got_section();
4388 g_o_t
= got
->address() + got
->g_o_t();
4393 Address off
= plt_addr
- got_addr
;
4396 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
4397 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
4398 write_insn
<big_endian
>(p
+ 8, bctr
);
4402 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
4403 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
4404 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4405 write_insn
<big_endian
>(p
+ 12, bctr
);
4410 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
4411 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
4412 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4413 write_insn
<big_endian
>(p
+ 12, bctr
);
4418 // Write out long branch stubs.
4419 typename
Branch_stub_entries::const_iterator bs
;
4420 for (bs
= this->long_branch_stubs_
.begin();
4421 bs
!= this->long_branch_stubs_
.end();
4424 p
= oview
+ this->plt_size_
+ bs
->second
;
4425 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4426 Address delta
= bs
->first
.dest_
- loc
;
4427 if (delta
+ (1 << 25) < 2 << 25)
4428 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4429 else if (!parameters
->options().output_is_position_independent())
4431 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
4432 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
4433 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
4434 write_insn
<big_endian
>(p
+ 12, bctr
);
4439 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4440 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4441 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4442 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4443 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4444 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4445 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4446 write_insn
<big_endian
>(p
+ 28, bctr
);
4452 // Write out .glink.
4454 template<int size
, bool big_endian
>
4456 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4458 const section_size_type off
= this->offset();
4459 const section_size_type oview_size
=
4460 convert_to_section_size_type(this->data_size());
4461 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4464 // The base address of the .plt section.
4465 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4466 Address plt_base
= this->targ_
->plt_section()->address();
4470 if (this->end_branch_table_
!= 0)
4472 // Write pltresolve stub.
4474 Address after_bcl
= this->address() + 16;
4475 Address pltoff
= plt_base
- after_bcl
;
4477 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4479 if (this->targ_
->abiversion() < 2)
4481 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4482 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4483 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4484 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4485 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4486 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4487 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4488 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
4489 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4490 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
4494 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
4495 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4496 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4497 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4498 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
4499 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
4500 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4501 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
4502 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4503 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
4504 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4505 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
4507 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4508 while (p
< oview
+ this->pltresolve_size
)
4509 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4511 // Write lazy link call stubs.
4513 while (p
< oview
+ this->end_branch_table_
)
4515 if (this->targ_
->abiversion() < 2)
4519 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4523 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
4524 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4527 uint32_t branch_off
= 8 - (p
- oview
);
4528 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4533 Address plt_base
= this->targ_
->plt_section()->address();
4534 Address iplt_base
= invalid_address
;
4535 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4536 Address global_entry_base
= this->address() + global_entry_off
;
4537 typename
Global_entry_stub_entries::const_iterator ge
;
4538 for (ge
= this->global_entry_stubs_
.begin();
4539 ge
!= this->global_entry_stubs_
.end();
4542 p
= oview
+ global_entry_off
+ ge
->second
;
4543 Address plt_addr
= ge
->first
->plt_offset();
4544 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
4545 && ge
->first
->can_use_relative_reloc(false))
4547 if (iplt_base
== invalid_address
)
4548 iplt_base
= this->targ_
->iplt_section()->address();
4549 plt_addr
+= iplt_base
;
4552 plt_addr
+= plt_base
;
4553 Address my_addr
= global_entry_base
+ ge
->second
;
4554 Address off
= plt_addr
- my_addr
;
4556 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
4557 gold_error(_("%s: linkage table error against `%s'"),
4558 ge
->first
->object()->name().c_str(),
4559 ge
->first
->demangled_name().c_str());
4561 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
4562 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
4563 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4564 write_insn
<big_endian
>(p
, bctr
);
4569 const Output_data_got_powerpc
<size
, big_endian
>* got
4570 = this->targ_
->got_section();
4571 // The address of _GLOBAL_OFFSET_TABLE_.
4572 Address g_o_t
= got
->address() + got
->g_o_t();
4574 // Write out pltresolve branch table.
4576 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4577 unsigned char* end_p
= oview
+ the_end
;
4578 while (p
< end_p
- 8 * 4)
4579 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4581 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4583 // Write out pltresolve call stub.
4584 if (parameters
->options().output_is_position_independent())
4586 Address res0_off
= 0;
4587 Address after_bcl_off
= the_end
+ 12;
4588 Address bcl_res0
= after_bcl_off
- res0_off
;
4590 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4591 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4592 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4593 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4594 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4595 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4596 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4598 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4600 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4601 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4603 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4604 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4608 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4609 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4611 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4612 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4613 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4614 write_insn
<big_endian
>(p
+ 52, bctr
);
4615 write_insn
<big_endian
>(p
+ 56, nop
);
4616 write_insn
<big_endian
>(p
+ 60, nop
);
4620 Address res0
= this->address();
4622 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4623 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4624 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4625 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4627 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4628 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4629 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4630 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4631 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4632 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4634 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4635 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4636 write_insn
<big_endian
>(p
+ 32, bctr
);
4637 write_insn
<big_endian
>(p
+ 36, nop
);
4638 write_insn
<big_endian
>(p
+ 40, nop
);
4639 write_insn
<big_endian
>(p
+ 44, nop
);
4640 write_insn
<big_endian
>(p
+ 48, nop
);
4641 write_insn
<big_endian
>(p
+ 52, nop
);
4642 write_insn
<big_endian
>(p
+ 56, nop
);
4643 write_insn
<big_endian
>(p
+ 60, nop
);
4648 of
->write_output_view(off
, oview_size
, oview
);
4652 // A class to handle linker generated save/restore functions.
4654 template<int size
, bool big_endian
>
4655 class Output_data_save_res
: public Output_section_data_build
4658 Output_data_save_res(Symbol_table
* symtab
);
4661 // Write to a map file.
4663 do_print_to_mapfile(Mapfile
* mapfile
) const
4664 { mapfile
->print_output_data(this, _("** save/restore")); }
4667 do_write(Output_file
*);
4670 // The maximum size of save/restore contents.
4671 static const unsigned int savres_max
= 218*4;
4674 savres_define(Symbol_table
* symtab
,
4676 unsigned int lo
, unsigned int hi
,
4677 unsigned char* write_ent(unsigned char*, int),
4678 unsigned char* write_tail(unsigned char*, int));
4680 unsigned char *contents_
;
4683 template<bool big_endian
>
4684 static unsigned char*
4685 savegpr0(unsigned char* p
, int r
)
4687 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4688 write_insn
<big_endian
>(p
, insn
);
4692 template<bool big_endian
>
4693 static unsigned char*
4694 savegpr0_tail(unsigned char* p
, int r
)
4696 p
= savegpr0
<big_endian
>(p
, r
);
4697 uint32_t insn
= std_0_1
+ 16;
4698 write_insn
<big_endian
>(p
, insn
);
4700 write_insn
<big_endian
>(p
, blr
);
4704 template<bool big_endian
>
4705 static unsigned char*
4706 restgpr0(unsigned char* p
, int r
)
4708 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4709 write_insn
<big_endian
>(p
, insn
);
4713 template<bool big_endian
>
4714 static unsigned char*
4715 restgpr0_tail(unsigned char* p
, int r
)
4717 uint32_t insn
= ld_0_1
+ 16;
4718 write_insn
<big_endian
>(p
, insn
);
4720 p
= restgpr0
<big_endian
>(p
, r
);
4721 write_insn
<big_endian
>(p
, mtlr_0
);
4725 p
= restgpr0
<big_endian
>(p
, 30);
4726 p
= restgpr0
<big_endian
>(p
, 31);
4728 write_insn
<big_endian
>(p
, blr
);
4732 template<bool big_endian
>
4733 static unsigned char*
4734 savegpr1(unsigned char* p
, int r
)
4736 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4737 write_insn
<big_endian
>(p
, insn
);
4741 template<bool big_endian
>
4742 static unsigned char*
4743 savegpr1_tail(unsigned char* p
, int r
)
4745 p
= savegpr1
<big_endian
>(p
, r
);
4746 write_insn
<big_endian
>(p
, blr
);
4750 template<bool big_endian
>
4751 static unsigned char*
4752 restgpr1(unsigned char* p
, int r
)
4754 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4755 write_insn
<big_endian
>(p
, insn
);
4759 template<bool big_endian
>
4760 static unsigned char*
4761 restgpr1_tail(unsigned char* p
, int r
)
4763 p
= restgpr1
<big_endian
>(p
, r
);
4764 write_insn
<big_endian
>(p
, blr
);
4768 template<bool big_endian
>
4769 static unsigned char*
4770 savefpr(unsigned char* p
, int r
)
4772 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4773 write_insn
<big_endian
>(p
, insn
);
4777 template<bool big_endian
>
4778 static unsigned char*
4779 savefpr0_tail(unsigned char* p
, int r
)
4781 p
= savefpr
<big_endian
>(p
, r
);
4782 write_insn
<big_endian
>(p
, std_0_1
+ 16);
4784 write_insn
<big_endian
>(p
, blr
);
4788 template<bool big_endian
>
4789 static unsigned char*
4790 restfpr(unsigned char* p
, int r
)
4792 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4793 write_insn
<big_endian
>(p
, insn
);
4797 template<bool big_endian
>
4798 static unsigned char*
4799 restfpr0_tail(unsigned char* p
, int r
)
4801 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
4803 p
= restfpr
<big_endian
>(p
, r
);
4804 write_insn
<big_endian
>(p
, mtlr_0
);
4808 p
= restfpr
<big_endian
>(p
, 30);
4809 p
= restfpr
<big_endian
>(p
, 31);
4811 write_insn
<big_endian
>(p
, blr
);
4815 template<bool big_endian
>
4816 static unsigned char*
4817 savefpr1_tail(unsigned char* p
, int r
)
4819 p
= savefpr
<big_endian
>(p
, r
);
4820 write_insn
<big_endian
>(p
, blr
);
4824 template<bool big_endian
>
4825 static unsigned char*
4826 restfpr1_tail(unsigned char* p
, int r
)
4828 p
= restfpr
<big_endian
>(p
, r
);
4829 write_insn
<big_endian
>(p
, blr
);
4833 template<bool big_endian
>
4834 static unsigned char*
4835 savevr(unsigned char* p
, int r
)
4837 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4838 write_insn
<big_endian
>(p
, insn
);
4840 insn
= stvx_0_12_0
+ (r
<< 21);
4841 write_insn
<big_endian
>(p
, insn
);
4845 template<bool big_endian
>
4846 static unsigned char*
4847 savevr_tail(unsigned char* p
, int r
)
4849 p
= savevr
<big_endian
>(p
, r
);
4850 write_insn
<big_endian
>(p
, blr
);
4854 template<bool big_endian
>
4855 static unsigned char*
4856 restvr(unsigned char* p
, int r
)
4858 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4859 write_insn
<big_endian
>(p
, insn
);
4861 insn
= lvx_0_12_0
+ (r
<< 21);
4862 write_insn
<big_endian
>(p
, insn
);
4866 template<bool big_endian
>
4867 static unsigned char*
4868 restvr_tail(unsigned char* p
, int r
)
4870 p
= restvr
<big_endian
>(p
, r
);
4871 write_insn
<big_endian
>(p
, blr
);
4876 template<int size
, bool big_endian
>
4877 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
4878 Symbol_table
* symtab
)
4879 : Output_section_data_build(4),
4882 this->savres_define(symtab
,
4883 "_savegpr0_", 14, 31,
4884 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
4885 this->savres_define(symtab
,
4886 "_restgpr0_", 14, 29,
4887 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4888 this->savres_define(symtab
,
4889 "_restgpr0_", 30, 31,
4890 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4891 this->savres_define(symtab
,
4892 "_savegpr1_", 14, 31,
4893 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
4894 this->savres_define(symtab
,
4895 "_restgpr1_", 14, 31,
4896 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
4897 this->savres_define(symtab
,
4898 "_savefpr_", 14, 31,
4899 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
4900 this->savres_define(symtab
,
4901 "_restfpr_", 14, 29,
4902 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
4903 this->savres_define(symtab
,
4904 "_restfpr_", 30, 31,
4905 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
4906 this->savres_define(symtab
,
4908 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
4909 this->savres_define(symtab
,
4911 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
4912 this->savres_define(symtab
,
4914 savevr
<big_endian
>, savevr_tail
<big_endian
>);
4915 this->savres_define(symtab
,
4917 restvr
<big_endian
>, restvr_tail
<big_endian
>);
4920 template<int size
, bool big_endian
>
4922 Output_data_save_res
<size
, big_endian
>::savres_define(
4923 Symbol_table
* symtab
,
4925 unsigned int lo
, unsigned int hi
,
4926 unsigned char* write_ent(unsigned char*, int),
4927 unsigned char* write_tail(unsigned char*, int))
4929 size_t len
= strlen(name
);
4930 bool writing
= false;
4933 memcpy(sym
, name
, len
);
4936 for (unsigned int i
= lo
; i
<= hi
; i
++)
4938 sym
[len
+ 0] = i
/ 10 + '0';
4939 sym
[len
+ 1] = i
% 10 + '0';
4940 Symbol
* gsym
= symtab
->lookup(sym
);
4941 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
4942 writing
= writing
|| refd
;
4945 if (this->contents_
== NULL
)
4946 this->contents_
= new unsigned char[this->savres_max
];
4948 section_size_type value
= this->current_data_size();
4949 unsigned char* p
= this->contents_
+ value
;
4951 p
= write_ent(p
, i
);
4953 p
= write_tail(p
, i
);
4954 section_size_type cur_size
= p
- this->contents_
;
4955 this->set_current_data_size(cur_size
);
4957 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
4958 this, value
, cur_size
- value
,
4959 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
4960 elfcpp::STV_HIDDEN
, 0, false, false);
4965 // Write out save/restore.
4967 template<int size
, bool big_endian
>
4969 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
4971 const section_size_type off
= this->offset();
4972 const section_size_type oview_size
=
4973 convert_to_section_size_type(this->data_size());
4974 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4975 memcpy(oview
, this->contents_
, oview_size
);
4976 of
->write_output_view(off
, oview_size
, oview
);
4980 // Create the glink section.
4982 template<int size
, bool big_endian
>
4984 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
4986 if (this->glink_
== NULL
)
4988 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
4989 this->glink_
->add_eh_frame(layout
);
4990 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
4991 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
4992 this->glink_
, ORDER_TEXT
, false);
4996 // Create a PLT entry for a global symbol.
4998 template<int size
, bool big_endian
>
5000 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
5004 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5005 && gsym
->can_use_relative_reloc(false))
5007 if (this->iplt_
== NULL
)
5008 this->make_iplt_section(symtab
, layout
);
5009 this->iplt_
->add_ifunc_entry(gsym
);
5013 if (this->plt_
== NULL
)
5014 this->make_plt_section(symtab
, layout
);
5015 this->plt_
->add_entry(gsym
);
5019 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
5021 template<int size
, bool big_endian
>
5023 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
5024 Symbol_table
* symtab
,
5026 Sized_relobj_file
<size
, big_endian
>* relobj
,
5029 if (this->iplt_
== NULL
)
5030 this->make_iplt_section(symtab
, layout
);
5031 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
5034 // Return the number of entries in the PLT.
5036 template<int size
, bool big_endian
>
5038 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
5040 if (this->plt_
== NULL
)
5042 return this->plt_
->entry_count();
5045 // Create a GOT entry for local dynamic __tls_get_addr calls.
5047 template<int size
, bool big_endian
>
5049 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
5050 Symbol_table
* symtab
,
5052 Sized_relobj_file
<size
, big_endian
>* object
)
5054 if (this->tlsld_got_offset_
== -1U)
5056 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
5057 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
5058 Output_data_got_powerpc
<size
, big_endian
>* got
5059 = this->got_section(symtab
, layout
);
5060 unsigned int got_offset
= got
->add_constant_pair(0, 0);
5061 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
5063 this->tlsld_got_offset_
= got_offset
;
5065 return this->tlsld_got_offset_
;
5068 // Get the Reference_flags for a particular relocation.
5070 template<int size
, bool big_endian
>
5072 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
5073 unsigned int r_type
,
5074 const Target_powerpc
* target
)
5080 case elfcpp::R_POWERPC_NONE
:
5081 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5082 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5083 case elfcpp::R_PPC64_TOC
:
5084 // No symbol reference.
5087 case elfcpp::R_PPC64_ADDR64
:
5088 case elfcpp::R_PPC64_UADDR64
:
5089 case elfcpp::R_POWERPC_ADDR32
:
5090 case elfcpp::R_POWERPC_UADDR32
:
5091 case elfcpp::R_POWERPC_ADDR16
:
5092 case elfcpp::R_POWERPC_UADDR16
:
5093 case elfcpp::R_POWERPC_ADDR16_LO
:
5094 case elfcpp::R_POWERPC_ADDR16_HI
:
5095 case elfcpp::R_POWERPC_ADDR16_HA
:
5096 ref
= Symbol::ABSOLUTE_REF
;
5099 case elfcpp::R_POWERPC_ADDR24
:
5100 case elfcpp::R_POWERPC_ADDR14
:
5101 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5102 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5103 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
5106 case elfcpp::R_PPC64_REL64
:
5107 case elfcpp::R_POWERPC_REL32
:
5108 case elfcpp::R_PPC_LOCAL24PC
:
5109 case elfcpp::R_POWERPC_REL16
:
5110 case elfcpp::R_POWERPC_REL16_LO
:
5111 case elfcpp::R_POWERPC_REL16_HI
:
5112 case elfcpp::R_POWERPC_REL16_HA
:
5113 ref
= Symbol::RELATIVE_REF
;
5116 case elfcpp::R_POWERPC_REL24
:
5117 case elfcpp::R_PPC_PLTREL24
:
5118 case elfcpp::R_POWERPC_REL14
:
5119 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5120 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5121 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
5124 case elfcpp::R_POWERPC_GOT16
:
5125 case elfcpp::R_POWERPC_GOT16_LO
:
5126 case elfcpp::R_POWERPC_GOT16_HI
:
5127 case elfcpp::R_POWERPC_GOT16_HA
:
5128 case elfcpp::R_PPC64_GOT16_DS
:
5129 case elfcpp::R_PPC64_GOT16_LO_DS
:
5130 case elfcpp::R_PPC64_TOC16
:
5131 case elfcpp::R_PPC64_TOC16_LO
:
5132 case elfcpp::R_PPC64_TOC16_HI
:
5133 case elfcpp::R_PPC64_TOC16_HA
:
5134 case elfcpp::R_PPC64_TOC16_DS
:
5135 case elfcpp::R_PPC64_TOC16_LO_DS
:
5137 ref
= Symbol::ABSOLUTE_REF
;
5140 case elfcpp::R_POWERPC_GOT_TPREL16
:
5141 case elfcpp::R_POWERPC_TLS
:
5142 ref
= Symbol::TLS_REF
;
5145 case elfcpp::R_POWERPC_COPY
:
5146 case elfcpp::R_POWERPC_GLOB_DAT
:
5147 case elfcpp::R_POWERPC_JMP_SLOT
:
5148 case elfcpp::R_POWERPC_RELATIVE
:
5149 case elfcpp::R_POWERPC_DTPMOD
:
5151 // Not expected. We will give an error later.
5155 if (size
== 64 && target
->abiversion() < 2)
5156 ref
|= Symbol::FUNC_DESC_ABI
;
5160 // Report an unsupported relocation against a local symbol.
5162 template<int size
, bool big_endian
>
5164 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
5165 Sized_relobj_file
<size
, big_endian
>* object
,
5166 unsigned int r_type
)
5168 gold_error(_("%s: unsupported reloc %u against local symbol"),
5169 object
->name().c_str(), r_type
);
5172 // We are about to emit a dynamic relocation of type R_TYPE. If the
5173 // dynamic linker does not support it, issue an error.
5175 template<int size
, bool big_endian
>
5177 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
5178 unsigned int r_type
)
5180 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
5182 // These are the relocation types supported by glibc for both 32-bit
5183 // and 64-bit powerpc.
5186 case elfcpp::R_POWERPC_NONE
:
5187 case elfcpp::R_POWERPC_RELATIVE
:
5188 case elfcpp::R_POWERPC_GLOB_DAT
:
5189 case elfcpp::R_POWERPC_DTPMOD
:
5190 case elfcpp::R_POWERPC_DTPREL
:
5191 case elfcpp::R_POWERPC_TPREL
:
5192 case elfcpp::R_POWERPC_JMP_SLOT
:
5193 case elfcpp::R_POWERPC_COPY
:
5194 case elfcpp::R_POWERPC_IRELATIVE
:
5195 case elfcpp::R_POWERPC_ADDR32
:
5196 case elfcpp::R_POWERPC_UADDR32
:
5197 case elfcpp::R_POWERPC_ADDR24
:
5198 case elfcpp::R_POWERPC_ADDR16
:
5199 case elfcpp::R_POWERPC_UADDR16
:
5200 case elfcpp::R_POWERPC_ADDR16_LO
:
5201 case elfcpp::R_POWERPC_ADDR16_HI
:
5202 case elfcpp::R_POWERPC_ADDR16_HA
:
5203 case elfcpp::R_POWERPC_ADDR14
:
5204 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5205 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5206 case elfcpp::R_POWERPC_REL32
:
5207 case elfcpp::R_POWERPC_REL24
:
5208 case elfcpp::R_POWERPC_TPREL16
:
5209 case elfcpp::R_POWERPC_TPREL16_LO
:
5210 case elfcpp::R_POWERPC_TPREL16_HI
:
5211 case elfcpp::R_POWERPC_TPREL16_HA
:
5222 // These are the relocation types supported only on 64-bit.
5223 case elfcpp::R_PPC64_ADDR64
:
5224 case elfcpp::R_PPC64_UADDR64
:
5225 case elfcpp::R_PPC64_JMP_IREL
:
5226 case elfcpp::R_PPC64_ADDR16_DS
:
5227 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5228 case elfcpp::R_PPC64_ADDR16_HIGH
:
5229 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5230 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5231 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5232 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5233 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5234 case elfcpp::R_PPC64_REL64
:
5235 case elfcpp::R_POWERPC_ADDR30
:
5236 case elfcpp::R_PPC64_TPREL16_DS
:
5237 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5238 case elfcpp::R_PPC64_TPREL16_HIGH
:
5239 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5240 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5241 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5242 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5243 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5254 // These are the relocation types supported only on 32-bit.
5255 // ??? glibc ld.so doesn't need to support these.
5256 case elfcpp::R_POWERPC_DTPREL16
:
5257 case elfcpp::R_POWERPC_DTPREL16_LO
:
5258 case elfcpp::R_POWERPC_DTPREL16_HI
:
5259 case elfcpp::R_POWERPC_DTPREL16_HA
:
5267 // This prevents us from issuing more than one error per reloc
5268 // section. But we can still wind up issuing more than one
5269 // error per object file.
5270 if (this->issued_non_pic_error_
)
5272 gold_assert(parameters
->options().output_is_position_independent());
5273 object
->error(_("requires unsupported dynamic reloc; "
5274 "recompile with -fPIC"));
5275 this->issued_non_pic_error_
= true;
5279 // Return whether we need to make a PLT entry for a relocation of the
5280 // given type against a STT_GNU_IFUNC symbol.
5282 template<int size
, bool big_endian
>
5284 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
5285 Target_powerpc
<size
, big_endian
>* target
,
5286 Sized_relobj_file
<size
, big_endian
>* object
,
5287 unsigned int r_type
,
5290 // In non-pic code any reference will resolve to the plt call stub
5291 // for the ifunc symbol.
5292 if ((size
== 32 || target
->abiversion() >= 2)
5293 && !parameters
->options().output_is_position_independent())
5298 // Word size refs from data sections are OK, but don't need a PLT entry.
5299 case elfcpp::R_POWERPC_ADDR32
:
5300 case elfcpp::R_POWERPC_UADDR32
:
5305 case elfcpp::R_PPC64_ADDR64
:
5306 case elfcpp::R_PPC64_UADDR64
:
5311 // GOT refs are good, but also don't need a PLT entry.
5312 case elfcpp::R_POWERPC_GOT16
:
5313 case elfcpp::R_POWERPC_GOT16_LO
:
5314 case elfcpp::R_POWERPC_GOT16_HI
:
5315 case elfcpp::R_POWERPC_GOT16_HA
:
5316 case elfcpp::R_PPC64_GOT16_DS
:
5317 case elfcpp::R_PPC64_GOT16_LO_DS
:
5320 // Function calls are good, and these do need a PLT entry.
5321 case elfcpp::R_POWERPC_ADDR24
:
5322 case elfcpp::R_POWERPC_ADDR14
:
5323 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5324 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5325 case elfcpp::R_POWERPC_REL24
:
5326 case elfcpp::R_PPC_PLTREL24
:
5327 case elfcpp::R_POWERPC_REL14
:
5328 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5329 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5336 // Anything else is a problem.
5337 // If we are building a static executable, the libc startup function
5338 // responsible for applying indirect function relocations is going
5339 // to complain about the reloc type.
5340 // If we are building a dynamic executable, we will have a text
5341 // relocation. The dynamic loader will set the text segment
5342 // writable and non-executable to apply text relocations. So we'll
5343 // segfault when trying to run the indirection function to resolve
5346 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5347 object
->name().c_str(), r_type
);
5351 // Scan a relocation for a local symbol.
5353 template<int size
, bool big_endian
>
5355 Target_powerpc
<size
, big_endian
>::Scan::local(
5356 Symbol_table
* symtab
,
5358 Target_powerpc
<size
, big_endian
>* target
,
5359 Sized_relobj_file
<size
, big_endian
>* object
,
5360 unsigned int data_shndx
,
5361 Output_section
* output_section
,
5362 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5363 unsigned int r_type
,
5364 const elfcpp::Sym
<size
, big_endian
>& lsym
,
5367 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
5369 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5370 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5372 this->expect_tls_get_addr_call();
5373 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5374 if (tls_type
!= tls::TLSOPT_NONE
)
5375 this->skip_next_tls_get_addr_call();
5377 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5378 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5380 this->expect_tls_get_addr_call();
5381 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5382 if (tls_type
!= tls::TLSOPT_NONE
)
5383 this->skip_next_tls_get_addr_call();
5386 Powerpc_relobj
<size
, big_endian
>* ppc_object
5387 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5392 && data_shndx
== ppc_object
->opd_shndx()
5393 && r_type
== elfcpp::R_PPC64_ADDR64
)
5394 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5398 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5399 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
5400 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5402 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5403 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5404 r_type
, r_sym
, reloc
.get_r_addend());
5405 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
5410 case elfcpp::R_POWERPC_NONE
:
5411 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5412 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5413 case elfcpp::R_PPC64_TOCSAVE
:
5414 case elfcpp::R_POWERPC_TLS
:
5417 case elfcpp::R_PPC64_TOC
:
5419 Output_data_got_powerpc
<size
, big_endian
>* got
5420 = target
->got_section(symtab
, layout
);
5421 if (parameters
->options().output_is_position_independent())
5423 Address off
= reloc
.get_r_offset();
5425 && target
->abiversion() < 2
5426 && data_shndx
== ppc_object
->opd_shndx()
5427 && ppc_object
->get_opd_discard(off
- 8))
5430 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5431 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5432 rela_dyn
->add_output_section_relative(got
->output_section(),
5433 elfcpp::R_POWERPC_RELATIVE
,
5435 object
, data_shndx
, off
,
5436 symobj
->toc_base_offset());
5441 case elfcpp::R_PPC64_ADDR64
:
5442 case elfcpp::R_PPC64_UADDR64
:
5443 case elfcpp::R_POWERPC_ADDR32
:
5444 case elfcpp::R_POWERPC_UADDR32
:
5445 case elfcpp::R_POWERPC_ADDR24
:
5446 case elfcpp::R_POWERPC_ADDR16
:
5447 case elfcpp::R_POWERPC_ADDR16_LO
:
5448 case elfcpp::R_POWERPC_ADDR16_HI
:
5449 case elfcpp::R_POWERPC_ADDR16_HA
:
5450 case elfcpp::R_POWERPC_UADDR16
:
5451 case elfcpp::R_PPC64_ADDR16_HIGH
:
5452 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5453 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5454 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5455 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5456 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5457 case elfcpp::R_PPC64_ADDR16_DS
:
5458 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5459 case elfcpp::R_POWERPC_ADDR14
:
5460 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5461 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5462 // If building a shared library (or a position-independent
5463 // executable), we need to create a dynamic relocation for
5465 if (parameters
->options().output_is_position_independent()
5466 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5468 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5470 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5471 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
5473 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5474 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5475 : elfcpp::R_POWERPC_RELATIVE
);
5476 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5477 output_section
, data_shndx
,
5478 reloc
.get_r_offset(),
5479 reloc
.get_r_addend(), false);
5483 check_non_pic(object
, r_type
);
5484 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5485 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
5486 data_shndx
, reloc
.get_r_offset(),
5487 reloc
.get_r_addend());
5492 case elfcpp::R_POWERPC_REL24
:
5493 case elfcpp::R_PPC_PLTREL24
:
5494 case elfcpp::R_PPC_LOCAL24PC
:
5495 case elfcpp::R_POWERPC_REL14
:
5496 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5497 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5499 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5500 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5501 reloc
.get_r_addend());
5504 case elfcpp::R_PPC64_REL64
:
5505 case elfcpp::R_POWERPC_REL32
:
5506 case elfcpp::R_POWERPC_REL16
:
5507 case elfcpp::R_POWERPC_REL16_LO
:
5508 case elfcpp::R_POWERPC_REL16_HI
:
5509 case elfcpp::R_POWERPC_REL16_HA
:
5510 case elfcpp::R_POWERPC_SECTOFF
:
5511 case elfcpp::R_POWERPC_SECTOFF_LO
:
5512 case elfcpp::R_POWERPC_SECTOFF_HI
:
5513 case elfcpp::R_POWERPC_SECTOFF_HA
:
5514 case elfcpp::R_PPC64_SECTOFF_DS
:
5515 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5516 case elfcpp::R_POWERPC_TPREL16
:
5517 case elfcpp::R_POWERPC_TPREL16_LO
:
5518 case elfcpp::R_POWERPC_TPREL16_HI
:
5519 case elfcpp::R_POWERPC_TPREL16_HA
:
5520 case elfcpp::R_PPC64_TPREL16_DS
:
5521 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5522 case elfcpp::R_PPC64_TPREL16_HIGH
:
5523 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5524 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5525 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5526 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5527 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5528 case elfcpp::R_POWERPC_DTPREL16
:
5529 case elfcpp::R_POWERPC_DTPREL16_LO
:
5530 case elfcpp::R_POWERPC_DTPREL16_HI
:
5531 case elfcpp::R_POWERPC_DTPREL16_HA
:
5532 case elfcpp::R_PPC64_DTPREL16_DS
:
5533 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5534 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5535 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5536 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5537 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5538 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5539 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5540 case elfcpp::R_PPC64_TLSGD
:
5541 case elfcpp::R_PPC64_TLSLD
:
5542 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5545 case elfcpp::R_POWERPC_GOT16
:
5546 case elfcpp::R_POWERPC_GOT16_LO
:
5547 case elfcpp::R_POWERPC_GOT16_HI
:
5548 case elfcpp::R_POWERPC_GOT16_HA
:
5549 case elfcpp::R_PPC64_GOT16_DS
:
5550 case elfcpp::R_PPC64_GOT16_LO_DS
:
5552 // The symbol requires a GOT entry.
5553 Output_data_got_powerpc
<size
, big_endian
>* got
5554 = target
->got_section(symtab
, layout
);
5555 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5557 if (!parameters
->options().output_is_position_independent())
5559 if ((size
== 32 && is_ifunc
)
5560 || (size
== 64 && target
->abiversion() >= 2))
5561 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5563 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5565 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5567 // If we are generating a shared object or a pie, this
5568 // symbol's GOT entry will be set by a dynamic relocation.
5570 off
= got
->add_constant(0);
5571 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5573 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5575 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5576 : elfcpp::R_POWERPC_RELATIVE
);
5577 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5578 got
, off
, 0, false);
5583 case elfcpp::R_PPC64_TOC16
:
5584 case elfcpp::R_PPC64_TOC16_LO
:
5585 case elfcpp::R_PPC64_TOC16_HI
:
5586 case elfcpp::R_PPC64_TOC16_HA
:
5587 case elfcpp::R_PPC64_TOC16_DS
:
5588 case elfcpp::R_PPC64_TOC16_LO_DS
:
5589 // We need a GOT section.
5590 target
->got_section(symtab
, layout
);
5593 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5594 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5595 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5596 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5598 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5599 if (tls_type
== tls::TLSOPT_NONE
)
5601 Output_data_got_powerpc
<size
, big_endian
>* got
5602 = target
->got_section(symtab
, layout
);
5603 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5604 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5605 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5606 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5608 else if (tls_type
== tls::TLSOPT_TO_LE
)
5610 // no GOT relocs needed for Local Exec.
5617 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5618 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5619 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5620 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5622 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5623 if (tls_type
== tls::TLSOPT_NONE
)
5624 target
->tlsld_got_offset(symtab
, layout
, object
);
5625 else if (tls_type
== tls::TLSOPT_TO_LE
)
5627 // no GOT relocs needed for Local Exec.
5628 if (parameters
->options().emit_relocs())
5630 Output_section
* os
= layout
->tls_segment()->first_section();
5631 gold_assert(os
!= NULL
);
5632 os
->set_needs_symtab_index();
5640 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5641 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5642 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5643 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5645 Output_data_got_powerpc
<size
, big_endian
>* got
5646 = target
->got_section(symtab
, layout
);
5647 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5648 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5652 case elfcpp::R_POWERPC_GOT_TPREL16
:
5653 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5654 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5655 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5657 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5658 if (tls_type
== tls::TLSOPT_NONE
)
5660 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5661 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5663 Output_data_got_powerpc
<size
, big_endian
>* got
5664 = target
->got_section(symtab
, layout
);
5665 unsigned int off
= got
->add_constant(0);
5666 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5668 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5669 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5670 elfcpp::R_POWERPC_TPREL
,
5674 else if (tls_type
== tls::TLSOPT_TO_LE
)
5676 // no GOT relocs needed for Local Exec.
5684 unsupported_reloc_local(object
, r_type
);
5690 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5691 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5692 case elfcpp::R_POWERPC_GOT_TPREL16
:
5693 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5694 case elfcpp::R_POWERPC_GOT16
:
5695 case elfcpp::R_PPC64_GOT16_DS
:
5696 case elfcpp::R_PPC64_TOC16
:
5697 case elfcpp::R_PPC64_TOC16_DS
:
5698 ppc_object
->set_has_small_toc_reloc();
5704 // Report an unsupported relocation against a global symbol.
5706 template<int size
, bool big_endian
>
5708 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5709 Sized_relobj_file
<size
, big_endian
>* object
,
5710 unsigned int r_type
,
5713 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5714 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
5717 // Scan a relocation for a global symbol.
5719 template<int size
, bool big_endian
>
5721 Target_powerpc
<size
, big_endian
>::Scan::global(
5722 Symbol_table
* symtab
,
5724 Target_powerpc
<size
, big_endian
>* target
,
5725 Sized_relobj_file
<size
, big_endian
>* object
,
5726 unsigned int data_shndx
,
5727 Output_section
* output_section
,
5728 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5729 unsigned int r_type
,
5732 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
5735 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5736 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5738 this->expect_tls_get_addr_call();
5739 const bool final
= gsym
->final_value_is_known();
5740 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5741 if (tls_type
!= tls::TLSOPT_NONE
)
5742 this->skip_next_tls_get_addr_call();
5744 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5745 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5747 this->expect_tls_get_addr_call();
5748 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5749 if (tls_type
!= tls::TLSOPT_NONE
)
5750 this->skip_next_tls_get_addr_call();
5753 Powerpc_relobj
<size
, big_endian
>* ppc_object
5754 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5756 // A STT_GNU_IFUNC symbol may require a PLT entry.
5757 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
5758 bool pushed_ifunc
= false;
5759 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5761 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5762 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5763 reloc
.get_r_addend());
5764 target
->make_plt_entry(symtab
, layout
, gsym
);
5765 pushed_ifunc
= true;
5770 case elfcpp::R_POWERPC_NONE
:
5771 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5772 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5773 case elfcpp::R_PPC_LOCAL24PC
:
5774 case elfcpp::R_POWERPC_TLS
:
5777 case elfcpp::R_PPC64_TOC
:
5779 Output_data_got_powerpc
<size
, big_endian
>* got
5780 = target
->got_section(symtab
, layout
);
5781 if (parameters
->options().output_is_position_independent())
5783 Address off
= reloc
.get_r_offset();
5785 && data_shndx
== ppc_object
->opd_shndx()
5786 && ppc_object
->get_opd_discard(off
- 8))
5789 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5790 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5791 if (data_shndx
!= ppc_object
->opd_shndx())
5792 symobj
= static_cast
5793 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
5794 rela_dyn
->add_output_section_relative(got
->output_section(),
5795 elfcpp::R_POWERPC_RELATIVE
,
5797 object
, data_shndx
, off
,
5798 symobj
->toc_base_offset());
5803 case elfcpp::R_PPC64_ADDR64
:
5805 && target
->abiversion() < 2
5806 && data_shndx
== ppc_object
->opd_shndx()
5807 && (gsym
->is_defined_in_discarded_section()
5808 || gsym
->object() != object
))
5810 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5814 case elfcpp::R_PPC64_UADDR64
:
5815 case elfcpp::R_POWERPC_ADDR32
:
5816 case elfcpp::R_POWERPC_UADDR32
:
5817 case elfcpp::R_POWERPC_ADDR24
:
5818 case elfcpp::R_POWERPC_ADDR16
:
5819 case elfcpp::R_POWERPC_ADDR16_LO
:
5820 case elfcpp::R_POWERPC_ADDR16_HI
:
5821 case elfcpp::R_POWERPC_ADDR16_HA
:
5822 case elfcpp::R_POWERPC_UADDR16
:
5823 case elfcpp::R_PPC64_ADDR16_HIGH
:
5824 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5825 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5826 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5827 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5828 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5829 case elfcpp::R_PPC64_ADDR16_DS
:
5830 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5831 case elfcpp::R_POWERPC_ADDR14
:
5832 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5833 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5835 // Make a PLT entry if necessary.
5836 if (gsym
->needs_plt_entry())
5838 // Since this is not a PC-relative relocation, we may be
5839 // taking the address of a function. In that case we need to
5840 // set the entry in the dynamic symbol table to the address of
5841 // the PLT call stub.
5842 bool need_ifunc_plt
= false;
5843 if ((size
== 32 || target
->abiversion() >= 2)
5844 && gsym
->is_from_dynobj()
5845 && !parameters
->options().output_is_position_independent())
5847 gsym
->set_needs_dynsym_value();
5848 need_ifunc_plt
= true;
5850 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
5852 target
->push_branch(ppc_object
, data_shndx
,
5853 reloc
.get_r_offset(), r_type
,
5854 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5855 reloc
.get_r_addend());
5856 target
->make_plt_entry(symtab
, layout
, gsym
);
5859 // Make a dynamic relocation if necessary.
5860 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
5861 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5863 if (!parameters
->options().output_is_position_independent()
5864 && gsym
->may_need_copy_reloc())
5866 target
->copy_reloc(symtab
, layout
, object
,
5867 data_shndx
, output_section
, gsym
, reloc
);
5869 else if ((((size
== 32
5870 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5872 && r_type
== elfcpp::R_PPC64_ADDR64
5873 && target
->abiversion() >= 2))
5874 && gsym
->can_use_relative_reloc(false)
5875 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
5876 && parameters
->options().shared()))
5878 && r_type
== elfcpp::R_PPC64_ADDR64
5879 && target
->abiversion() < 2
5880 && (gsym
->can_use_relative_reloc(false)
5881 || data_shndx
== ppc_object
->opd_shndx())))
5883 Reloc_section
* rela_dyn
5884 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
5885 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5886 : elfcpp::R_POWERPC_RELATIVE
);
5887 rela_dyn
->add_symbolless_global_addend(
5888 gsym
, dynrel
, output_section
, object
, data_shndx
,
5889 reloc
.get_r_offset(), reloc
.get_r_addend());
5893 Reloc_section
* rela_dyn
5894 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
5895 check_non_pic(object
, r_type
);
5896 rela_dyn
->add_global(gsym
, r_type
, output_section
,
5898 reloc
.get_r_offset(),
5899 reloc
.get_r_addend());
5905 case elfcpp::R_PPC_PLTREL24
:
5906 case elfcpp::R_POWERPC_REL24
:
5909 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5911 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5912 reloc
.get_r_addend());
5913 if (gsym
->needs_plt_entry()
5914 || (!gsym
->final_value_is_known()
5915 && (gsym
->is_undefined()
5916 || gsym
->is_from_dynobj()
5917 || gsym
->is_preemptible())))
5918 target
->make_plt_entry(symtab
, layout
, gsym
);
5922 case elfcpp::R_PPC64_REL64
:
5923 case elfcpp::R_POWERPC_REL32
:
5924 // Make a dynamic relocation if necessary.
5925 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
5927 if (!parameters
->options().output_is_position_independent()
5928 && gsym
->may_need_copy_reloc())
5930 target
->copy_reloc(symtab
, layout
, object
,
5931 data_shndx
, output_section
, gsym
,
5936 Reloc_section
* rela_dyn
5937 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
5938 check_non_pic(object
, r_type
);
5939 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
5940 data_shndx
, reloc
.get_r_offset(),
5941 reloc
.get_r_addend());
5946 case elfcpp::R_POWERPC_REL14
:
5947 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5948 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5950 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5951 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5952 reloc
.get_r_addend());
5955 case elfcpp::R_POWERPC_REL16
:
5956 case elfcpp::R_POWERPC_REL16_LO
:
5957 case elfcpp::R_POWERPC_REL16_HI
:
5958 case elfcpp::R_POWERPC_REL16_HA
:
5959 case elfcpp::R_POWERPC_SECTOFF
:
5960 case elfcpp::R_POWERPC_SECTOFF_LO
:
5961 case elfcpp::R_POWERPC_SECTOFF_HI
:
5962 case elfcpp::R_POWERPC_SECTOFF_HA
:
5963 case elfcpp::R_PPC64_SECTOFF_DS
:
5964 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5965 case elfcpp::R_POWERPC_TPREL16
:
5966 case elfcpp::R_POWERPC_TPREL16_LO
:
5967 case elfcpp::R_POWERPC_TPREL16_HI
:
5968 case elfcpp::R_POWERPC_TPREL16_HA
:
5969 case elfcpp::R_PPC64_TPREL16_DS
:
5970 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5971 case elfcpp::R_PPC64_TPREL16_HIGH
:
5972 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5973 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5974 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5975 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5976 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5977 case elfcpp::R_POWERPC_DTPREL16
:
5978 case elfcpp::R_POWERPC_DTPREL16_LO
:
5979 case elfcpp::R_POWERPC_DTPREL16_HI
:
5980 case elfcpp::R_POWERPC_DTPREL16_HA
:
5981 case elfcpp::R_PPC64_DTPREL16_DS
:
5982 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5983 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5984 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5985 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5986 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5987 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5988 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5989 case elfcpp::R_PPC64_TLSGD
:
5990 case elfcpp::R_PPC64_TLSLD
:
5991 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5994 case elfcpp::R_POWERPC_GOT16
:
5995 case elfcpp::R_POWERPC_GOT16_LO
:
5996 case elfcpp::R_POWERPC_GOT16_HI
:
5997 case elfcpp::R_POWERPC_GOT16_HA
:
5998 case elfcpp::R_PPC64_GOT16_DS
:
5999 case elfcpp::R_PPC64_GOT16_LO_DS
:
6001 // The symbol requires a GOT entry.
6002 Output_data_got_powerpc
<size
, big_endian
>* got
;
6004 got
= target
->got_section(symtab
, layout
);
6005 if (gsym
->final_value_is_known())
6007 if ((size
== 32 && is_ifunc
)
6008 || (size
== 64 && target
->abiversion() >= 2))
6009 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
6011 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
6013 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
6015 // If we are generating a shared object or a pie, this
6016 // symbol's GOT entry will be set by a dynamic relocation.
6017 unsigned int off
= got
->add_constant(0);
6018 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
6020 Reloc_section
* rela_dyn
6021 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6023 if (gsym
->can_use_relative_reloc(false)
6025 || target
->abiversion() >= 2)
6026 && gsym
->visibility() == elfcpp::STV_PROTECTED
6027 && parameters
->options().shared()))
6029 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6030 : elfcpp::R_POWERPC_RELATIVE
);
6031 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
6035 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
6036 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
6042 case elfcpp::R_PPC64_TOC16
:
6043 case elfcpp::R_PPC64_TOC16_LO
:
6044 case elfcpp::R_PPC64_TOC16_HI
:
6045 case elfcpp::R_PPC64_TOC16_HA
:
6046 case elfcpp::R_PPC64_TOC16_DS
:
6047 case elfcpp::R_PPC64_TOC16_LO_DS
:
6048 // We need a GOT section.
6049 target
->got_section(symtab
, layout
);
6052 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6053 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6054 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6055 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6057 const bool final
= gsym
->final_value_is_known();
6058 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6059 if (tls_type
== tls::TLSOPT_NONE
)
6061 Output_data_got_powerpc
<size
, big_endian
>* got
6062 = target
->got_section(symtab
, layout
);
6063 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6064 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
6065 elfcpp::R_POWERPC_DTPMOD
,
6066 elfcpp::R_POWERPC_DTPREL
);
6068 else if (tls_type
== tls::TLSOPT_TO_IE
)
6070 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6072 Output_data_got_powerpc
<size
, big_endian
>* got
6073 = target
->got_section(symtab
, layout
);
6074 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6075 if (gsym
->is_undefined()
6076 || gsym
->is_from_dynobj())
6078 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6079 elfcpp::R_POWERPC_TPREL
);
6083 unsigned int off
= got
->add_constant(0);
6084 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6085 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6086 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6091 else if (tls_type
== tls::TLSOPT_TO_LE
)
6093 // no GOT relocs needed for Local Exec.
6100 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6101 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6102 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6103 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6105 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6106 if (tls_type
== tls::TLSOPT_NONE
)
6107 target
->tlsld_got_offset(symtab
, layout
, object
);
6108 else if (tls_type
== tls::TLSOPT_TO_LE
)
6110 // no GOT relocs needed for Local Exec.
6111 if (parameters
->options().emit_relocs())
6113 Output_section
* os
= layout
->tls_segment()->first_section();
6114 gold_assert(os
!= NULL
);
6115 os
->set_needs_symtab_index();
6123 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6124 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6125 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6126 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6128 Output_data_got_powerpc
<size
, big_endian
>* got
6129 = target
->got_section(symtab
, layout
);
6130 if (!gsym
->final_value_is_known()
6131 && (gsym
->is_from_dynobj()
6132 || gsym
->is_undefined()
6133 || gsym
->is_preemptible()))
6134 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
6135 target
->rela_dyn_section(layout
),
6136 elfcpp::R_POWERPC_DTPREL
);
6138 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
6142 case elfcpp::R_POWERPC_GOT_TPREL16
:
6143 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6144 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6145 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6147 const bool final
= gsym
->final_value_is_known();
6148 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6149 if (tls_type
== tls::TLSOPT_NONE
)
6151 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6153 Output_data_got_powerpc
<size
, big_endian
>* got
6154 = target
->got_section(symtab
, layout
);
6155 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6156 if (gsym
->is_undefined()
6157 || gsym
->is_from_dynobj())
6159 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6160 elfcpp::R_POWERPC_TPREL
);
6164 unsigned int off
= got
->add_constant(0);
6165 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6166 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6167 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6172 else if (tls_type
== tls::TLSOPT_TO_LE
)
6174 // no GOT relocs needed for Local Exec.
6182 unsupported_reloc_global(object
, r_type
, gsym
);
6188 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6189 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6190 case elfcpp::R_POWERPC_GOT_TPREL16
:
6191 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6192 case elfcpp::R_POWERPC_GOT16
:
6193 case elfcpp::R_PPC64_GOT16_DS
:
6194 case elfcpp::R_PPC64_TOC16
:
6195 case elfcpp::R_PPC64_TOC16_DS
:
6196 ppc_object
->set_has_small_toc_reloc();
6202 // Process relocations for gc.
6204 template<int size
, bool big_endian
>
6206 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
6207 Symbol_table
* symtab
,
6209 Sized_relobj_file
<size
, big_endian
>* object
,
6210 unsigned int data_shndx
,
6212 const unsigned char* prelocs
,
6214 Output_section
* output_section
,
6215 bool needs_special_offset_handling
,
6216 size_t local_symbol_count
,
6217 const unsigned char* plocal_symbols
)
6219 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6220 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6221 Powerpc_relobj
<size
, big_endian
>* ppc_object
6222 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6224 ppc_object
->set_opd_valid();
6225 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
6227 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
6228 for (p
= ppc_object
->access_from_map()->begin();
6229 p
!= ppc_object
->access_from_map()->end();
6232 Address dst_off
= p
->first
;
6233 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6234 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
6235 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
6237 Object
* src_obj
= s
->first
;
6238 unsigned int src_indx
= s
->second
;
6239 symtab
->gc()->add_reference(src_obj
, src_indx
,
6240 ppc_object
, dst_indx
);
6244 ppc_object
->access_from_map()->clear();
6245 ppc_object
->process_gc_mark(symtab
);
6246 // Don't look at .opd relocs as .opd will reference everything.
6250 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
6251 typename
Target_powerpc::Relocatable_size_for_reloc
>(
6260 needs_special_offset_handling
,
6265 // Handle target specific gc actions when adding a gc reference from
6266 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6267 // and DST_OFF. For powerpc64, this adds a referenc to the code
6268 // section of a function descriptor.
6270 template<int size
, bool big_endian
>
6272 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
6273 Symbol_table
* symtab
,
6275 unsigned int src_shndx
,
6277 unsigned int dst_shndx
,
6278 Address dst_off
) const
6280 if (size
!= 64 || dst_obj
->is_dynamic())
6283 Powerpc_relobj
<size
, big_endian
>* ppc_object
6284 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
6285 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
6287 if (ppc_object
->opd_valid())
6289 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
6290 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
6294 // If we haven't run scan_opd_relocs, we must delay
6295 // processing this function descriptor reference.
6296 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
6301 // Add any special sections for this symbol to the gc work list.
6302 // For powerpc64, this adds the code section of a function
6305 template<int size
, bool big_endian
>
6307 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
6308 Symbol_table
* symtab
,
6313 Powerpc_relobj
<size
, big_endian
>* ppc_object
6314 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
6316 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6317 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
6319 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
6320 Address dst_off
= gsym
->value();
6321 if (ppc_object
->opd_valid())
6323 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6324 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
6327 ppc_object
->add_gc_mark(dst_off
);
6332 // For a symbol location in .opd, set LOC to the location of the
6335 template<int size
, bool big_endian
>
6337 Target_powerpc
<size
, big_endian
>::do_function_location(
6338 Symbol_location
* loc
) const
6340 if (size
== 64 && loc
->shndx
!= 0)
6342 if (loc
->object
->is_dynamic())
6344 Powerpc_dynobj
<size
, big_endian
>* ppc_object
6345 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
6346 if (loc
->shndx
== ppc_object
->opd_shndx())
6349 Address off
= loc
->offset
- ppc_object
->opd_address();
6350 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
6351 loc
->offset
= dest_off
;
6356 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6357 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
6358 if (loc
->shndx
== ppc_object
->opd_shndx())
6361 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
6362 loc
->offset
= dest_off
;
6368 // Scan relocations for a section.
6370 template<int size
, bool big_endian
>
6372 Target_powerpc
<size
, big_endian
>::scan_relocs(
6373 Symbol_table
* symtab
,
6375 Sized_relobj_file
<size
, big_endian
>* object
,
6376 unsigned int data_shndx
,
6377 unsigned int sh_type
,
6378 const unsigned char* prelocs
,
6380 Output_section
* output_section
,
6381 bool needs_special_offset_handling
,
6382 size_t local_symbol_count
,
6383 const unsigned char* plocal_symbols
)
6385 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6386 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6388 if (sh_type
== elfcpp::SHT_REL
)
6390 gold_error(_("%s: unsupported REL reloc section"),
6391 object
->name().c_str());
6395 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
6404 needs_special_offset_handling
,
6409 // Functor class for processing the global symbol table.
6410 // Removes symbols defined on discarded opd entries.
6412 template<bool big_endian
>
6413 class Global_symbol_visitor_opd
6416 Global_symbol_visitor_opd()
6420 operator()(Sized_symbol
<64>* sym
)
6422 if (sym
->has_symtab_index()
6423 || sym
->source() != Symbol::FROM_OBJECT
6424 || !sym
->in_real_elf())
6427 if (sym
->object()->is_dynamic())
6430 Powerpc_relobj
<64, big_endian
>* symobj
6431 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
6432 if (symobj
->opd_shndx() == 0)
6436 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6437 if (shndx
== symobj
->opd_shndx()
6438 && symobj
->get_opd_discard(sym
->value()))
6439 sym
->set_symtab_index(-1U);
6443 template<int size
, bool big_endian
>
6445 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
6447 Symbol_table
* symtab
)
6451 Output_data_save_res
<64, big_endian
>* savres
6452 = new Output_data_save_res
<64, big_endian
>(symtab
);
6453 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6454 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6455 savres
, ORDER_TEXT
, false);
6459 // Sort linker created .got section first (for the header), then input
6460 // sections belonging to files using small model code.
6462 template<bool big_endian
>
6463 class Sort_toc_sections
6467 operator()(const Output_section::Input_section
& is1
,
6468 const Output_section::Input_section
& is2
) const
6470 if (!is1
.is_input_section() && is2
.is_input_section())
6473 = (is1
.is_input_section()
6474 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
6475 ->has_small_toc_reloc()));
6477 = (is2
.is_input_section()
6478 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
6479 ->has_small_toc_reloc()));
6480 return small1
&& !small2
;
6484 // Finalize the sections.
6486 template<int size
, bool big_endian
>
6488 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
6490 const Input_objects
*,
6491 Symbol_table
* symtab
)
6493 if (parameters
->doing_static_link())
6495 // At least some versions of glibc elf-init.o have a strong
6496 // reference to __rela_iplt marker syms. A weak ref would be
6498 if (this->iplt_
!= NULL
)
6500 Reloc_section
* rel
= this->iplt_
->rel_plt();
6501 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
6502 Symbol_table::PREDEFINED
, rel
, 0, 0,
6503 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6504 elfcpp::STV_HIDDEN
, 0, false, true);
6505 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
6506 Symbol_table::PREDEFINED
, rel
, 0, 0,
6507 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6508 elfcpp::STV_HIDDEN
, 0, true, true);
6512 symtab
->define_as_constant("__rela_iplt_start", NULL
,
6513 Symbol_table::PREDEFINED
, 0, 0,
6514 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6515 elfcpp::STV_HIDDEN
, 0, true, false);
6516 symtab
->define_as_constant("__rela_iplt_end", NULL
,
6517 Symbol_table::PREDEFINED
, 0, 0,
6518 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6519 elfcpp::STV_HIDDEN
, 0, true, false);
6525 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6526 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6528 if (!parameters
->options().relocatable())
6530 this->define_save_restore_funcs(layout
, symtab
);
6532 // Annoyingly, we need to make these sections now whether or
6533 // not we need them. If we delay until do_relax then we
6534 // need to mess with the relaxation machinery checkpointing.
6535 this->got_section(symtab
, layout
);
6536 this->make_brlt_section(layout
);
6538 if (parameters
->options().toc_sort())
6540 Output_section
* os
= this->got_
->output_section();
6541 if (os
!= NULL
&& os
->input_sections().size() > 1)
6542 std::stable_sort(os
->input_sections().begin(),
6543 os
->input_sections().end(),
6544 Sort_toc_sections
<big_endian
>());
6549 // Fill in some more dynamic tags.
6550 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6553 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6555 : this->plt_
->rel_plt());
6556 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6557 this->rela_dyn_
, true, size
== 32);
6561 if (this->got_
!= NULL
)
6563 this->got_
->finalize_data_size();
6564 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6565 this->got_
, this->got_
->g_o_t());
6570 if (this->glink_
!= NULL
)
6572 this->glink_
->finalize_data_size();
6573 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6575 (this->glink_
->pltresolve_size
6581 // Emit any relocs we saved in an attempt to avoid generating COPY
6583 if (this->copy_relocs_
.any_saved_relocs())
6584 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6587 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6591 ok_lo_toc_insn(uint32_t insn
)
6593 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6594 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6595 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6596 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6597 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6598 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6599 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6600 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6601 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6602 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6603 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6604 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6605 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6606 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6607 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6609 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6610 && ((insn
& 3) == 0 || (insn
& 3) == 3))
6611 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
6614 // Return the value to use for a branch relocation.
6616 template<int size
, bool big_endian
>
6617 typename Target_powerpc
<size
, big_endian
>::Address
6618 Target_powerpc
<size
, big_endian
>::symval_for_branch(
6619 const Symbol_table
* symtab
,
6621 const Sized_symbol
<size
>* gsym
,
6622 Powerpc_relobj
<size
, big_endian
>* object
,
6623 unsigned int *dest_shndx
)
6625 if (size
== 32 || this->abiversion() >= 2)
6629 // If the symbol is defined in an opd section, ie. is a function
6630 // descriptor, use the function descriptor code entry address
6631 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
6633 && gsym
->source() != Symbol::FROM_OBJECT
)
6636 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6637 unsigned int shndx
= symobj
->opd_shndx();
6640 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
6641 if (opd_addr
== invalid_address
)
6643 opd_addr
+= symobj
->output_section_address(shndx
);
6644 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
6647 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
6648 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
6651 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
6652 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
6653 *dest_shndx
= folded
.second
;
6655 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
6656 gold_assert(sec_addr
!= invalid_address
);
6657 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
6658 value
= sec_addr
+ sec_off
;
6663 // Perform a relocation.
6665 template<int size
, bool big_endian
>
6667 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
6668 const Relocate_info
<size
, big_endian
>* relinfo
,
6669 Target_powerpc
* target
,
6672 const elfcpp::Rela
<size
, big_endian
>& rela
,
6673 unsigned int r_type
,
6674 const Sized_symbol
<size
>* gsym
,
6675 const Symbol_value
<size
>* psymval
,
6676 unsigned char* view
,
6678 section_size_type view_size
)
6683 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
6685 case Track_tls::NOT_EXPECTED
:
6686 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6687 _("__tls_get_addr call lacks marker reloc"));
6689 case Track_tls::EXPECTED
:
6690 // We have already complained.
6692 case Track_tls::SKIP
:
6694 case Track_tls::NORMAL
:
6698 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
6699 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
6700 Powerpc_relobj
<size
, big_endian
>* const object
6701 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
6703 bool has_plt_value
= false;
6704 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6706 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
6707 : object
->local_has_plt_offset(r_sym
))
6708 && (!psymval
->is_ifunc_symbol()
6709 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
6713 && target
->abiversion() >= 2
6714 && !parameters
->options().output_is_position_independent()
6715 && !is_branch_reloc(r_type
))
6717 unsigned int off
= target
->glink_section()->find_global_entry(gsym
);
6718 gold_assert(off
!= (unsigned int)-1);
6719 value
= target
->glink_section()->global_entry_address() + off
;
6723 Stub_table
<size
, big_endian
>* stub_table
6724 = object
->stub_table(relinfo
->data_shndx
);
6725 if (stub_table
== NULL
)
6727 // This is a ref from a data section to an ifunc symbol.
6728 if (target
->stub_tables().size() != 0)
6729 stub_table
= target
->stub_tables()[0];
6731 gold_assert(stub_table
!= NULL
);
6734 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
6735 rela
.get_r_addend());
6737 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
6738 rela
.get_r_addend());
6739 gold_assert(off
!= invalid_address
);
6740 value
= stub_table
->stub_address() + off
;
6742 has_plt_value
= true;
6745 if (r_type
== elfcpp::R_POWERPC_GOT16
6746 || r_type
== elfcpp::R_POWERPC_GOT16_LO
6747 || r_type
== elfcpp::R_POWERPC_GOT16_HI
6748 || r_type
== elfcpp::R_POWERPC_GOT16_HA
6749 || r_type
== elfcpp::R_PPC64_GOT16_DS
6750 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
6754 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
6755 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
6759 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6760 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
6761 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
6763 value
-= target
->got_section()->got_base_offset(object
);
6765 else if (r_type
== elfcpp::R_PPC64_TOC
)
6767 value
= (target
->got_section()->output_section()->address()
6768 + object
->toc_base_offset());
6770 else if (gsym
!= NULL
6771 && (r_type
== elfcpp::R_POWERPC_REL24
6772 || r_type
== elfcpp::R_PPC_PLTREL24
)
6777 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
6778 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
6779 bool can_plt_call
= false;
6780 if (rela
.get_r_offset() + 8 <= view_size
)
6782 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
6783 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
6786 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
6788 elfcpp::Swap
<32, big_endian
>::
6789 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
6790 can_plt_call
= true;
6795 // If we don't have a branch and link followed by a nop,
6796 // we can't go via the plt because there is no place to
6797 // put a toc restoring instruction.
6798 // Unless we know we won't be returning.
6799 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
6800 can_plt_call
= true;
6804 // g++ as of 20130507 emits self-calls without a
6805 // following nop. This is arguably wrong since we have
6806 // conflicting information. On the one hand a global
6807 // symbol and on the other a local call sequence, but
6808 // don't error for this special case.
6809 // It isn't possible to cheaply verify we have exactly
6810 // such a call. Allow all calls to the same section.
6812 Address code
= value
;
6813 if (gsym
->source() == Symbol::FROM_OBJECT
6814 && gsym
->object() == object
)
6816 unsigned int dest_shndx
= 0;
6817 if (target
->abiversion() < 2)
6819 Address addend
= rela
.get_r_addend();
6820 Address opdent
= psymval
->value(object
, addend
);
6821 code
= target
->symval_for_branch(relinfo
->symtab
,
6822 opdent
, gsym
, object
,
6826 if (dest_shndx
== 0)
6827 dest_shndx
= gsym
->shndx(&is_ordinary
);
6828 ok
= dest_shndx
== relinfo
->data_shndx
;
6832 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6833 _("call lacks nop, can't restore toc; "
6834 "recompile with -fPIC"));
6840 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6841 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
6842 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
6843 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
6845 // First instruction of a global dynamic sequence, arg setup insn.
6846 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6847 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6848 enum Got_type got_type
= GOT_TYPE_STANDARD
;
6849 if (tls_type
== tls::TLSOPT_NONE
)
6850 got_type
= GOT_TYPE_TLSGD
;
6851 else if (tls_type
== tls::TLSOPT_TO_IE
)
6852 got_type
= GOT_TYPE_TPREL
;
6853 if (got_type
!= GOT_TYPE_STANDARD
)
6857 gold_assert(gsym
->has_got_offset(got_type
));
6858 value
= gsym
->got_offset(got_type
);
6862 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6863 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
6864 value
= object
->local_got_offset(r_sym
, got_type
);
6866 value
-= target
->got_section()->got_base_offset(object
);
6868 if (tls_type
== tls::TLSOPT_TO_IE
)
6870 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6871 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6873 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6874 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6875 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
6877 insn
|= 32 << 26; // lwz
6879 insn
|= 58 << 26; // ld
6880 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6882 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
6883 - elfcpp::R_POWERPC_GOT_TLSGD16
);
6885 else if (tls_type
== tls::TLSOPT_TO_LE
)
6887 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6888 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6890 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6891 Insn insn
= addis_3_13
;
6894 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6895 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6896 value
= psymval
->value(object
, rela
.get_r_addend());
6900 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6902 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6903 r_type
= elfcpp::R_POWERPC_NONE
;
6907 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6908 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
6909 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
6910 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
6912 // First instruction of a local dynamic sequence, arg setup insn.
6913 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6914 if (tls_type
== tls::TLSOPT_NONE
)
6916 value
= target
->tlsld_got_offset();
6917 value
-= target
->got_section()->got_base_offset(object
);
6921 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
6922 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6923 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
6925 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6926 Insn insn
= addis_3_13
;
6929 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6930 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6935 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6937 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6938 r_type
= elfcpp::R_POWERPC_NONE
;
6942 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
6943 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
6944 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
6945 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
6947 // Accesses relative to a local dynamic sequence address,
6948 // no optimisation here.
6951 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
6952 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
6956 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6957 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
6958 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
6960 value
-= target
->got_section()->got_base_offset(object
);
6962 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6963 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
6964 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
6965 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
6967 // First instruction of initial exec sequence.
6968 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6969 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6970 if (tls_type
== tls::TLSOPT_NONE
)
6974 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
6975 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
6979 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6980 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
6981 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
6983 value
-= target
->got_section()->got_base_offset(object
);
6987 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
6988 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6989 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
6991 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6992 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6993 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
6998 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6999 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7000 value
= psymval
->value(object
, rela
.get_r_addend());
7004 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7006 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7007 r_type
= elfcpp::R_POWERPC_NONE
;
7011 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7012 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7014 // Second instruction of a global dynamic sequence,
7015 // the __tls_get_addr call
7016 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7017 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7018 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7019 if (tls_type
!= tls::TLSOPT_NONE
)
7021 if (tls_type
== tls::TLSOPT_TO_IE
)
7023 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7024 Insn insn
= add_3_3_13
;
7027 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7028 r_type
= elfcpp::R_POWERPC_NONE
;
7032 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7033 Insn insn
= addi_3_3
;
7034 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7035 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7036 view
+= 2 * big_endian
;
7037 value
= psymval
->value(object
, rela
.get_r_addend());
7039 this->skip_next_tls_get_addr_call();
7042 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7043 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7045 // Second instruction of a local dynamic sequence,
7046 // the __tls_get_addr call
7047 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7048 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7049 if (tls_type
== tls::TLSOPT_TO_LE
)
7051 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7052 Insn insn
= addi_3_3
;
7053 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7054 this->skip_next_tls_get_addr_call();
7055 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7056 view
+= 2 * big_endian
;
7060 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7062 // Second instruction of an initial exec sequence
7063 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7064 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7065 if (tls_type
== tls::TLSOPT_TO_LE
)
7067 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7068 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7069 unsigned int reg
= size
== 32 ? 2 : 13;
7070 insn
= at_tls_transform(insn
, reg
);
7071 gold_assert(insn
!= 0);
7072 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7073 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7074 view
+= 2 * big_endian
;
7075 value
= psymval
->value(object
, rela
.get_r_addend());
7078 else if (!has_plt_value
)
7081 unsigned int dest_shndx
;
7082 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
7083 addend
= rela
.get_r_addend();
7084 value
= psymval
->value(object
, addend
);
7085 if (size
== 64 && is_branch_reloc(r_type
))
7087 if (target
->abiversion() >= 2)
7090 value
+= object
->ppc64_local_entry_offset(gsym
);
7092 value
+= object
->ppc64_local_entry_offset(r_sym
);
7095 value
= target
->symval_for_branch(relinfo
->symtab
, value
,
7096 gsym
, object
, &dest_shndx
);
7098 unsigned int max_branch_offset
= 0;
7099 if (r_type
== elfcpp::R_POWERPC_REL24
7100 || r_type
== elfcpp::R_PPC_PLTREL24
7101 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
7102 max_branch_offset
= 1 << 25;
7103 else if (r_type
== elfcpp::R_POWERPC_REL14
7104 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
7105 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
7106 max_branch_offset
= 1 << 15;
7107 if (max_branch_offset
!= 0
7108 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
7110 Stub_table
<size
, big_endian
>* stub_table
7111 = object
->stub_table(relinfo
->data_shndx
);
7112 if (stub_table
!= NULL
)
7114 Address off
= stub_table
->find_long_branch_entry(object
, value
);
7115 if (off
!= invalid_address
)
7116 value
= (stub_table
->stub_address() + stub_table
->plt_size()
7124 case elfcpp::R_PPC64_REL64
:
7125 case elfcpp::R_POWERPC_REL32
:
7126 case elfcpp::R_POWERPC_REL24
:
7127 case elfcpp::R_PPC_PLTREL24
:
7128 case elfcpp::R_PPC_LOCAL24PC
:
7129 case elfcpp::R_POWERPC_REL16
:
7130 case elfcpp::R_POWERPC_REL16_LO
:
7131 case elfcpp::R_POWERPC_REL16_HI
:
7132 case elfcpp::R_POWERPC_REL16_HA
:
7133 case elfcpp::R_POWERPC_REL14
:
7134 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7135 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7139 case elfcpp::R_PPC64_TOC16
:
7140 case elfcpp::R_PPC64_TOC16_LO
:
7141 case elfcpp::R_PPC64_TOC16_HI
:
7142 case elfcpp::R_PPC64_TOC16_HA
:
7143 case elfcpp::R_PPC64_TOC16_DS
:
7144 case elfcpp::R_PPC64_TOC16_LO_DS
:
7145 // Subtract the TOC base address.
7146 value
-= (target
->got_section()->output_section()->address()
7147 + object
->toc_base_offset());
7150 case elfcpp::R_POWERPC_SECTOFF
:
7151 case elfcpp::R_POWERPC_SECTOFF_LO
:
7152 case elfcpp::R_POWERPC_SECTOFF_HI
:
7153 case elfcpp::R_POWERPC_SECTOFF_HA
:
7154 case elfcpp::R_PPC64_SECTOFF_DS
:
7155 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7157 value
-= os
->address();
7160 case elfcpp::R_PPC64_TPREL16_DS
:
7161 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7162 case elfcpp::R_PPC64_TPREL16_HIGH
:
7163 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7165 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7167 case elfcpp::R_POWERPC_TPREL16
:
7168 case elfcpp::R_POWERPC_TPREL16_LO
:
7169 case elfcpp::R_POWERPC_TPREL16_HI
:
7170 case elfcpp::R_POWERPC_TPREL16_HA
:
7171 case elfcpp::R_POWERPC_TPREL
:
7172 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7173 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7174 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7175 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7176 // tls symbol values are relative to tls_segment()->vaddr()
7180 case elfcpp::R_PPC64_DTPREL16_DS
:
7181 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7182 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7183 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7184 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7185 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7187 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7188 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7190 case elfcpp::R_POWERPC_DTPREL16
:
7191 case elfcpp::R_POWERPC_DTPREL16_LO
:
7192 case elfcpp::R_POWERPC_DTPREL16_HI
:
7193 case elfcpp::R_POWERPC_DTPREL16_HA
:
7194 case elfcpp::R_POWERPC_DTPREL
:
7195 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7196 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7197 // tls symbol values are relative to tls_segment()->vaddr()
7198 value
-= dtp_offset
;
7201 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7203 value
+= object
->ppc64_local_entry_offset(gsym
);
7205 value
+= object
->ppc64_local_entry_offset(r_sym
);
7212 Insn branch_bit
= 0;
7215 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7216 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7217 branch_bit
= 1 << 21;
7218 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7219 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7221 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7222 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7225 if (this->is_isa_v2
)
7227 // Set 'a' bit. This is 0b00010 in BO field for branch
7228 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7229 // for branch on CTR insns (BO == 1a00t or 1a01t).
7230 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7232 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7239 // Invert 'y' bit if not the default.
7240 if (static_cast<Signed_address
>(value
) < 0)
7243 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7253 // Multi-instruction sequences that access the TOC can be
7254 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7255 // to nop; addi rb,r2,x;
7261 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7262 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7263 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7264 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7265 case elfcpp::R_POWERPC_GOT16_HA
:
7266 case elfcpp::R_PPC64_TOC16_HA
:
7267 if (parameters
->options().toc_optimize())
7269 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7270 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7271 if ((insn
& ((0x3f << 26) | 0x1f << 16))
7272 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7273 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7274 _("toc optimization is not supported "
7275 "for %#08x instruction"), insn
);
7276 else if (value
+ 0x8000 < 0x10000)
7278 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
7284 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7285 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7286 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7287 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7288 case elfcpp::R_POWERPC_GOT16_LO
:
7289 case elfcpp::R_PPC64_GOT16_LO_DS
:
7290 case elfcpp::R_PPC64_TOC16_LO
:
7291 case elfcpp::R_PPC64_TOC16_LO_DS
:
7292 if (parameters
->options().toc_optimize())
7294 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7295 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7296 if (!ok_lo_toc_insn(insn
))
7297 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7298 _("toc optimization is not supported "
7299 "for %#08x instruction"), insn
);
7300 else if (value
+ 0x8000 < 0x10000)
7302 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
7304 // Transform addic to addi when we change reg.
7305 insn
&= ~((0x3f << 26) | (0x1f << 16));
7306 insn
|= (14u << 26) | (2 << 16);
7310 insn
&= ~(0x1f << 16);
7313 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7320 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
7321 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
7324 case elfcpp::R_POWERPC_ADDR32
:
7325 case elfcpp::R_POWERPC_UADDR32
:
7327 overflow
= Reloc::CHECK_BITFIELD
;
7330 case elfcpp::R_POWERPC_REL32
:
7332 overflow
= Reloc::CHECK_SIGNED
;
7335 case elfcpp::R_POWERPC_UADDR16
:
7336 overflow
= Reloc::CHECK_BITFIELD
;
7339 case elfcpp::R_POWERPC_ADDR16
:
7340 // We really should have three separate relocations,
7341 // one for 16-bit data, one for insns with 16-bit signed fields,
7342 // and one for insns with 16-bit unsigned fields.
7343 overflow
= Reloc::CHECK_BITFIELD
;
7344 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
7345 overflow
= Reloc::CHECK_LOW_INSN
;
7348 case elfcpp::R_POWERPC_ADDR16_HI
:
7349 case elfcpp::R_POWERPC_ADDR16_HA
:
7350 case elfcpp::R_POWERPC_GOT16_HI
:
7351 case elfcpp::R_POWERPC_GOT16_HA
:
7352 case elfcpp::R_POWERPC_PLT16_HI
:
7353 case elfcpp::R_POWERPC_PLT16_HA
:
7354 case elfcpp::R_POWERPC_SECTOFF_HI
:
7355 case elfcpp::R_POWERPC_SECTOFF_HA
:
7356 case elfcpp::R_PPC64_TOC16_HI
:
7357 case elfcpp::R_PPC64_TOC16_HA
:
7358 case elfcpp::R_PPC64_PLTGOT16_HI
:
7359 case elfcpp::R_PPC64_PLTGOT16_HA
:
7360 case elfcpp::R_POWERPC_TPREL16_HI
:
7361 case elfcpp::R_POWERPC_TPREL16_HA
:
7362 case elfcpp::R_POWERPC_DTPREL16_HI
:
7363 case elfcpp::R_POWERPC_DTPREL16_HA
:
7364 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7365 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7366 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7367 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7368 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7369 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7370 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7371 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7372 case elfcpp::R_POWERPC_REL16_HI
:
7373 case elfcpp::R_POWERPC_REL16_HA
:
7375 overflow
= Reloc::CHECK_HIGH_INSN
;
7378 case elfcpp::R_POWERPC_REL16
:
7379 case elfcpp::R_PPC64_TOC16
:
7380 case elfcpp::R_POWERPC_GOT16
:
7381 case elfcpp::R_POWERPC_SECTOFF
:
7382 case elfcpp::R_POWERPC_TPREL16
:
7383 case elfcpp::R_POWERPC_DTPREL16
:
7384 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7385 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7386 case elfcpp::R_POWERPC_GOT_TPREL16
:
7387 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7388 overflow
= Reloc::CHECK_LOW_INSN
;
7391 case elfcpp::R_POWERPC_ADDR24
:
7392 case elfcpp::R_POWERPC_ADDR14
:
7393 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7394 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7395 case elfcpp::R_PPC64_ADDR16_DS
:
7396 case elfcpp::R_POWERPC_REL24
:
7397 case elfcpp::R_PPC_PLTREL24
:
7398 case elfcpp::R_PPC_LOCAL24PC
:
7399 case elfcpp::R_PPC64_TPREL16_DS
:
7400 case elfcpp::R_PPC64_DTPREL16_DS
:
7401 case elfcpp::R_PPC64_TOC16_DS
:
7402 case elfcpp::R_PPC64_GOT16_DS
:
7403 case elfcpp::R_PPC64_SECTOFF_DS
:
7404 case elfcpp::R_POWERPC_REL14
:
7405 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7406 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7407 overflow
= Reloc::CHECK_SIGNED
;
7411 if (overflow
== Reloc::CHECK_LOW_INSN
7412 || overflow
== Reloc::CHECK_HIGH_INSN
)
7414 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7415 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7417 overflow
= Reloc::CHECK_SIGNED
;
7418 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
7419 overflow
= Reloc::CHECK_BITFIELD
;
7420 else if (overflow
== Reloc::CHECK_LOW_INSN
7421 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
7422 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
7423 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
7424 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
7425 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
7426 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
7427 overflow
= Reloc::CHECK_UNSIGNED
;
7430 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
7431 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
7434 case elfcpp::R_POWERPC_NONE
:
7435 case elfcpp::R_POWERPC_TLS
:
7436 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7437 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7440 case elfcpp::R_PPC64_ADDR64
:
7441 case elfcpp::R_PPC64_REL64
:
7442 case elfcpp::R_PPC64_TOC
:
7443 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7444 Reloc::addr64(view
, value
);
7447 case elfcpp::R_POWERPC_TPREL
:
7448 case elfcpp::R_POWERPC_DTPREL
:
7450 Reloc::addr64(view
, value
);
7452 status
= Reloc::addr32(view
, value
, overflow
);
7455 case elfcpp::R_PPC64_UADDR64
:
7456 Reloc::addr64_u(view
, value
);
7459 case elfcpp::R_POWERPC_ADDR32
:
7460 status
= Reloc::addr32(view
, value
, overflow
);
7463 case elfcpp::R_POWERPC_REL32
:
7464 case elfcpp::R_POWERPC_UADDR32
:
7465 status
= Reloc::addr32_u(view
, value
, overflow
);
7468 case elfcpp::R_POWERPC_ADDR24
:
7469 case elfcpp::R_POWERPC_REL24
:
7470 case elfcpp::R_PPC_PLTREL24
:
7471 case elfcpp::R_PPC_LOCAL24PC
:
7472 status
= Reloc::addr24(view
, value
, overflow
);
7475 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7476 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7479 status
= Reloc::addr16_ds(view
, value
, overflow
);
7482 case elfcpp::R_POWERPC_ADDR16
:
7483 case elfcpp::R_POWERPC_REL16
:
7484 case elfcpp::R_PPC64_TOC16
:
7485 case elfcpp::R_POWERPC_GOT16
:
7486 case elfcpp::R_POWERPC_SECTOFF
:
7487 case elfcpp::R_POWERPC_TPREL16
:
7488 case elfcpp::R_POWERPC_DTPREL16
:
7489 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7490 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7491 case elfcpp::R_POWERPC_GOT_TPREL16
:
7492 case elfcpp::R_POWERPC_ADDR16_LO
:
7493 case elfcpp::R_POWERPC_REL16_LO
:
7494 case elfcpp::R_PPC64_TOC16_LO
:
7495 case elfcpp::R_POWERPC_GOT16_LO
:
7496 case elfcpp::R_POWERPC_SECTOFF_LO
:
7497 case elfcpp::R_POWERPC_TPREL16_LO
:
7498 case elfcpp::R_POWERPC_DTPREL16_LO
:
7499 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7500 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7501 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7502 status
= Reloc::addr16(view
, value
, overflow
);
7505 case elfcpp::R_POWERPC_UADDR16
:
7506 status
= Reloc::addr16_u(view
, value
, overflow
);
7509 case elfcpp::R_PPC64_ADDR16_HIGH
:
7510 case elfcpp::R_PPC64_TPREL16_HIGH
:
7511 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7513 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
7515 case elfcpp::R_POWERPC_ADDR16_HI
:
7516 case elfcpp::R_POWERPC_REL16_HI
:
7517 case elfcpp::R_PPC64_TOC16_HI
:
7518 case elfcpp::R_POWERPC_GOT16_HI
:
7519 case elfcpp::R_POWERPC_SECTOFF_HI
:
7520 case elfcpp::R_POWERPC_TPREL16_HI
:
7521 case elfcpp::R_POWERPC_DTPREL16_HI
:
7522 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7523 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7524 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7525 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7526 Reloc::addr16_hi(view
, value
);
7529 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7530 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7531 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7533 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
7535 case elfcpp::R_POWERPC_ADDR16_HA
:
7536 case elfcpp::R_POWERPC_REL16_HA
:
7537 case elfcpp::R_PPC64_TOC16_HA
:
7538 case elfcpp::R_POWERPC_GOT16_HA
:
7539 case elfcpp::R_POWERPC_SECTOFF_HA
:
7540 case elfcpp::R_POWERPC_TPREL16_HA
:
7541 case elfcpp::R_POWERPC_DTPREL16_HA
:
7542 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7543 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7544 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7545 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7546 Reloc::addr16_ha(view
, value
);
7549 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7551 // R_PPC_EMB_NADDR16_LO
7553 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7554 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7555 Reloc::addr16_hi2(view
, value
);
7558 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7560 // R_PPC_EMB_NADDR16_HI
7562 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7563 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7564 Reloc::addr16_ha2(view
, value
);
7567 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7569 // R_PPC_EMB_NADDR16_HA
7571 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7572 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7573 Reloc::addr16_hi3(view
, value
);
7576 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7580 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7581 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7582 Reloc::addr16_ha3(view
, value
);
7585 case elfcpp::R_PPC64_DTPREL16_DS
:
7586 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7588 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
7590 case elfcpp::R_PPC64_TPREL16_DS
:
7591 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7593 // R_PPC_TLSGD, R_PPC_TLSLD
7595 case elfcpp::R_PPC64_ADDR16_DS
:
7596 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7597 case elfcpp::R_PPC64_TOC16_DS
:
7598 case elfcpp::R_PPC64_TOC16_LO_DS
:
7599 case elfcpp::R_PPC64_GOT16_DS
:
7600 case elfcpp::R_PPC64_GOT16_LO_DS
:
7601 case elfcpp::R_PPC64_SECTOFF_DS
:
7602 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7603 status
= Reloc::addr16_ds(view
, value
, overflow
);
7606 case elfcpp::R_POWERPC_ADDR14
:
7607 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7608 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7609 case elfcpp::R_POWERPC_REL14
:
7610 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7611 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7612 status
= Reloc::addr14(view
, value
, overflow
);
7615 case elfcpp::R_POWERPC_COPY
:
7616 case elfcpp::R_POWERPC_GLOB_DAT
:
7617 case elfcpp::R_POWERPC_JMP_SLOT
:
7618 case elfcpp::R_POWERPC_RELATIVE
:
7619 case elfcpp::R_POWERPC_DTPMOD
:
7620 case elfcpp::R_PPC64_JMP_IREL
:
7621 case elfcpp::R_POWERPC_IRELATIVE
:
7622 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7623 _("unexpected reloc %u in object file"),
7627 case elfcpp::R_PPC_EMB_SDA21
:
7632 // R_PPC64_TOCSAVE. For the time being this can be ignored.
7636 case elfcpp::R_PPC_EMB_SDA2I16
:
7637 case elfcpp::R_PPC_EMB_SDA2REL
:
7640 // R_PPC64_TLSGD, R_PPC64_TLSLD
7643 case elfcpp::R_POWERPC_PLT32
:
7644 case elfcpp::R_POWERPC_PLTREL32
:
7645 case elfcpp::R_POWERPC_PLT16_LO
:
7646 case elfcpp::R_POWERPC_PLT16_HI
:
7647 case elfcpp::R_POWERPC_PLT16_HA
:
7648 case elfcpp::R_PPC_SDAREL16
:
7649 case elfcpp::R_POWERPC_ADDR30
:
7650 case elfcpp::R_PPC64_PLT64
:
7651 case elfcpp::R_PPC64_PLTREL64
:
7652 case elfcpp::R_PPC64_PLTGOT16
:
7653 case elfcpp::R_PPC64_PLTGOT16_LO
:
7654 case elfcpp::R_PPC64_PLTGOT16_HI
:
7655 case elfcpp::R_PPC64_PLTGOT16_HA
:
7656 case elfcpp::R_PPC64_PLT16_LO_DS
:
7657 case elfcpp::R_PPC64_PLTGOT16_DS
:
7658 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
7659 case elfcpp::R_PPC_EMB_RELSDA
:
7660 case elfcpp::R_PPC_TOC16
:
7663 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7664 _("unsupported reloc %u"),
7668 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
7669 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7670 _("relocation overflow"));
7675 // Relocate section data.
7677 template<int size
, bool big_endian
>
7679 Target_powerpc
<size
, big_endian
>::relocate_section(
7680 const Relocate_info
<size
, big_endian
>* relinfo
,
7681 unsigned int sh_type
,
7682 const unsigned char* prelocs
,
7684 Output_section
* output_section
,
7685 bool needs_special_offset_handling
,
7686 unsigned char* view
,
7688 section_size_type view_size
,
7689 const Reloc_symbol_changes
* reloc_symbol_changes
)
7691 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
7692 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
7693 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
7694 Powerpc_comdat_behavior
;
7696 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7698 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
7699 Powerpc_relocate
, Powerpc_comdat_behavior
>(
7705 needs_special_offset_handling
,
7709 reloc_symbol_changes
);
7712 class Powerpc_scan_relocatable_reloc
7715 // Return the strategy to use for a local symbol which is not a
7716 // section symbol, given the relocation type.
7717 inline Relocatable_relocs::Reloc_strategy
7718 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
7720 if (r_type
== 0 && r_sym
== 0)
7721 return Relocatable_relocs::RELOC_DISCARD
;
7722 return Relocatable_relocs::RELOC_COPY
;
7725 // Return the strategy to use for a local symbol which is a section
7726 // symbol, given the relocation type.
7727 inline Relocatable_relocs::Reloc_strategy
7728 local_section_strategy(unsigned int, Relobj
*)
7730 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
7733 // Return the strategy to use for a global symbol, given the
7734 // relocation type, the object, and the symbol index.
7735 inline Relocatable_relocs::Reloc_strategy
7736 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
7738 if (r_type
== elfcpp::R_PPC_PLTREL24
)
7739 return Relocatable_relocs::RELOC_SPECIAL
;
7740 return Relocatable_relocs::RELOC_COPY
;
7744 // Scan the relocs during a relocatable link.
7746 template<int size
, bool big_endian
>
7748 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
7749 Symbol_table
* symtab
,
7751 Sized_relobj_file
<size
, big_endian
>* object
,
7752 unsigned int data_shndx
,
7753 unsigned int sh_type
,
7754 const unsigned char* prelocs
,
7756 Output_section
* output_section
,
7757 bool needs_special_offset_handling
,
7758 size_t local_symbol_count
,
7759 const unsigned char* plocal_symbols
,
7760 Relocatable_relocs
* rr
)
7762 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7764 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
7765 Powerpc_scan_relocatable_reloc
>(
7773 needs_special_offset_handling
,
7779 // Emit relocations for a section.
7780 // This is a modified version of the function by the same name in
7781 // target-reloc.h. Using relocate_special_relocatable for
7782 // R_PPC_PLTREL24 would require duplication of the entire body of the
7783 // loop, so we may as well duplicate the whole thing.
7785 template<int size
, bool big_endian
>
7787 Target_powerpc
<size
, big_endian
>::relocate_relocs(
7788 const Relocate_info
<size
, big_endian
>* relinfo
,
7789 unsigned int sh_type
,
7790 const unsigned char* prelocs
,
7792 Output_section
* output_section
,
7793 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
7794 const Relocatable_relocs
* rr
,
7796 Address view_address
,
7798 unsigned char* reloc_view
,
7799 section_size_type reloc_view_size
)
7801 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7803 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
7805 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
7807 const int reloc_size
7808 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
7810 Powerpc_relobj
<size
, big_endian
>* const object
7811 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
7812 const unsigned int local_count
= object
->local_symbol_count();
7813 unsigned int got2_shndx
= object
->got2_shndx();
7814 Address got2_addend
= 0;
7815 if (got2_shndx
!= 0)
7817 got2_addend
= object
->get_output_section_offset(got2_shndx
);
7818 gold_assert(got2_addend
!= invalid_address
);
7821 unsigned char* pwrite
= reloc_view
;
7822 bool zap_next
= false;
7823 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
7825 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
7826 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
7829 Reltype
reloc(prelocs
);
7830 Reltype_write
reloc_write(pwrite
);
7832 Address offset
= reloc
.get_r_offset();
7833 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
7834 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
7835 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
7836 const unsigned int orig_r_sym
= r_sym
;
7837 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
7838 = reloc
.get_r_addend();
7839 const Symbol
* gsym
= NULL
;
7843 // We could arrange to discard these and other relocs for
7844 // tls optimised sequences in the strategy methods, but for
7845 // now do as BFD ld does.
7846 r_type
= elfcpp::R_POWERPC_NONE
;
7850 // Get the new symbol index.
7851 if (r_sym
< local_count
)
7855 case Relocatable_relocs::RELOC_COPY
:
7856 case Relocatable_relocs::RELOC_SPECIAL
:
7859 r_sym
= object
->symtab_index(r_sym
);
7860 gold_assert(r_sym
!= -1U);
7864 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
7866 // We are adjusting a section symbol. We need to find
7867 // the symbol table index of the section symbol for
7868 // the output section corresponding to input section
7869 // in which this symbol is defined.
7870 gold_assert(r_sym
< local_count
);
7872 unsigned int shndx
=
7873 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
7874 gold_assert(is_ordinary
);
7875 Output_section
* os
= object
->output_section(shndx
);
7876 gold_assert(os
!= NULL
);
7877 gold_assert(os
->needs_symtab_index());
7878 r_sym
= os
->symtab_index();
7888 gsym
= object
->global_symbol(r_sym
);
7889 gold_assert(gsym
!= NULL
);
7890 if (gsym
->is_forwarder())
7891 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
7893 gold_assert(gsym
->has_symtab_index());
7894 r_sym
= gsym
->symtab_index();
7897 // Get the new offset--the location in the output section where
7898 // this relocation should be applied.
7899 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
7900 offset
+= offset_in_output_section
;
7903 section_offset_type sot_offset
=
7904 convert_types
<section_offset_type
, Address
>(offset
);
7905 section_offset_type new_sot_offset
=
7906 output_section
->output_offset(object
, relinfo
->data_shndx
,
7908 gold_assert(new_sot_offset
!= -1);
7909 offset
= new_sot_offset
;
7912 // In an object file, r_offset is an offset within the section.
7913 // In an executable or dynamic object, generated by
7914 // --emit-relocs, r_offset is an absolute address.
7915 if (!parameters
->options().relocatable())
7917 offset
+= view_address
;
7918 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
7919 offset
-= offset_in_output_section
;
7922 // Handle the reloc addend based on the strategy.
7923 if (strategy
== Relocatable_relocs::RELOC_COPY
)
7925 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
7927 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
7928 addend
= psymval
->value(object
, addend
);
7930 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
7932 if (addend
>= 32768)
7933 addend
+= got2_addend
;
7938 if (!parameters
->options().relocatable())
7940 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7941 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
7942 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
7943 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
7945 // First instruction of a global dynamic sequence,
7947 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7948 switch (this->optimize_tls_gd(final
))
7950 case tls::TLSOPT_TO_IE
:
7951 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7952 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7954 case tls::TLSOPT_TO_LE
:
7955 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7956 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7957 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7960 r_type
= elfcpp::R_POWERPC_NONE
;
7961 offset
-= 2 * big_endian
;
7968 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7969 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7970 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7971 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7973 // First instruction of a local dynamic sequence,
7975 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
7977 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7978 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7980 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7981 const Output_section
* os
= relinfo
->layout
->tls_segment()
7983 gold_assert(os
!= NULL
);
7984 gold_assert(os
->needs_symtab_index());
7985 r_sym
= os
->symtab_index();
7986 addend
= dtp_offset
;
7990 r_type
= elfcpp::R_POWERPC_NONE
;
7991 offset
-= 2 * big_endian
;
7995 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7996 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7997 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7998 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8000 // First instruction of initial exec sequence.
8001 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8002 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8004 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8005 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8006 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8009 r_type
= elfcpp::R_POWERPC_NONE
;
8010 offset
-= 2 * big_endian
;
8014 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8015 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8017 // Second instruction of a global dynamic sequence,
8018 // the __tls_get_addr call
8019 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8020 switch (this->optimize_tls_gd(final
))
8022 case tls::TLSOPT_TO_IE
:
8023 r_type
= elfcpp::R_POWERPC_NONE
;
8026 case tls::TLSOPT_TO_LE
:
8027 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8028 offset
+= 2 * big_endian
;
8035 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8036 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8038 // Second instruction of a local dynamic sequence,
8039 // the __tls_get_addr call
8040 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8042 const Output_section
* os
= relinfo
->layout
->tls_segment()
8044 gold_assert(os
!= NULL
);
8045 gold_assert(os
->needs_symtab_index());
8046 r_sym
= os
->symtab_index();
8047 addend
= dtp_offset
;
8048 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8049 offset
+= 2 * big_endian
;
8053 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8055 // Second instruction of an initial exec sequence
8056 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8057 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8059 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8060 offset
+= 2 * big_endian
;
8065 reloc_write
.put_r_offset(offset
);
8066 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
8067 reloc_write
.put_r_addend(addend
);
8069 pwrite
+= reloc_size
;
8072 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
8073 == reloc_view_size
);
8076 // Return the value to use for a dynamic symbol which requires special
8077 // treatment. This is how we support equality comparisons of function
8078 // pointers across shared library boundaries, as described in the
8079 // processor specific ABI supplement.
8081 template<int size
, bool big_endian
>
8083 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8087 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
8088 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8089 p
!= this->stub_tables_
.end();
8092 Address off
= (*p
)->find_plt_call_entry(gsym
);
8093 if (off
!= invalid_address
)
8094 return (*p
)->stub_address() + off
;
8097 else if (this->abiversion() >= 2)
8099 unsigned int off
= this->glink_section()->find_global_entry(gsym
);
8100 if (off
!= (unsigned int)-1)
8101 return this->glink_section()->global_entry_address() + off
;
8106 // Return the PLT address to use for a local symbol.
8107 template<int size
, bool big_endian
>
8109 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
8110 const Relobj
* object
,
8111 unsigned int symndx
) const
8115 const Sized_relobj
<size
, big_endian
>* relobj
8116 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
8117 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8118 p
!= this->stub_tables_
.end();
8121 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
8123 if (off
!= invalid_address
)
8124 return (*p
)->stub_address() + off
;
8130 // Return the PLT address to use for a global symbol.
8131 template<int size
, bool big_endian
>
8133 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
8134 const Symbol
* gsym
) const
8138 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8139 p
!= this->stub_tables_
.end();
8142 Address off
= (*p
)->find_plt_call_entry(gsym
);
8143 if (off
!= invalid_address
)
8144 return (*p
)->stub_address() + off
;
8147 else if (this->abiversion() >= 2)
8149 unsigned int off
= this->glink_section()->find_global_entry(gsym
);
8150 if (off
!= (unsigned int)-1)
8151 return this->glink_section()->global_entry_address() + off
;
8156 // Return the offset to use for the GOT_INDX'th got entry which is
8157 // for a local tls symbol specified by OBJECT, SYMNDX.
8158 template<int size
, bool big_endian
>
8160 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
8161 const Relobj
* object
,
8162 unsigned int symndx
,
8163 unsigned int got_indx
) const
8165 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8166 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
8167 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
8169 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8170 got_type
<= GOT_TYPE_TPREL
;
8171 got_type
= Got_type(got_type
+ 1))
8172 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
8174 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
8175 if (got_type
== GOT_TYPE_TLSGD
)
8177 if (off
== got_indx
* (size
/ 8))
8179 if (got_type
== GOT_TYPE_TPREL
)
8189 // Return the offset to use for the GOT_INDX'th got entry which is
8190 // for global tls symbol GSYM.
8191 template<int size
, bool big_endian
>
8193 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
8195 unsigned int got_indx
) const
8197 if (gsym
->type() == elfcpp::STT_TLS
)
8199 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8200 got_type
<= GOT_TYPE_TPREL
;
8201 got_type
= Got_type(got_type
+ 1))
8202 if (gsym
->has_got_offset(got_type
))
8204 unsigned int off
= gsym
->got_offset(got_type
);
8205 if (got_type
== GOT_TYPE_TLSGD
)
8207 if (off
== got_indx
* (size
/ 8))
8209 if (got_type
== GOT_TYPE_TPREL
)
8219 // The selector for powerpc object files.
8221 template<int size
, bool big_endian
>
8222 class Target_selector_powerpc
: public Target_selector
8225 Target_selector_powerpc()
8226 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
8229 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
8230 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
8232 ? (big_endian
? "elf64ppc" : "elf64lppc")
8233 : (big_endian
? "elf32ppc" : "elf32lppc")))
8237 do_instantiate_target()
8238 { return new Target_powerpc
<size
, big_endian
>(); }
8241 Target_selector_powerpc
<32, true> target_selector_ppc32
;
8242 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
8243 Target_selector_powerpc
<64, true> target_selector_ppc64
;
8244 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
8246 // Instantiate these constants for -O0
8247 template<int size
, bool big_endian
>
8248 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
8249 template<int size
, bool big_endian
>
8250 const typename Output_data_glink
<size
, big_endian
>::Address
8251 Output_data_glink
<size
, big_endian
>::invalid_address
;
8252 template<int size
, bool big_endian
>
8253 const typename Stub_table
<size
, big_endian
>::Address
8254 Stub_table
<size
, big_endian
>::invalid_address
;
8255 template<int size
, bool big_endian
>
8256 const typename Target_powerpc
<size
, big_endian
>::Address
8257 Target_powerpc
<size
, big_endian
>::invalid_address
;
8259 } // End anonymous namespace.