1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
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_()
86 // The .got2 section shndx.
91 return this->special_
;
96 // The .opd section shndx.
103 return this->special_
;
106 // Init OPD entry arrays.
108 init_opd(size_t opd_size
)
110 size_t count
= this->opd_ent_ndx(opd_size
);
111 this->opd_ent_
.resize(count
);
114 // Return section and offset of function entry for .opd + R_OFF.
116 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
118 size_t ndx
= this->opd_ent_ndx(r_off
);
119 gold_assert(ndx
< this->opd_ent_
.size());
120 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
122 *value
= this->opd_ent_
[ndx
].off
;
123 return this->opd_ent_
[ndx
].shndx
;
126 // Set section and offset of function entry for .opd + R_OFF.
128 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
130 size_t ndx
= this->opd_ent_ndx(r_off
);
131 gold_assert(ndx
< this->opd_ent_
.size());
132 this->opd_ent_
[ndx
].shndx
= shndx
;
133 this->opd_ent_
[ndx
].off
= value
;
136 // Return discard flag for .opd + R_OFF.
138 get_opd_discard(Address r_off
) const
140 size_t ndx
= this->opd_ent_ndx(r_off
);
141 gold_assert(ndx
< this->opd_ent_
.size());
142 return this->opd_ent_
[ndx
].discard
;
145 // Set discard flag for .opd + R_OFF.
147 set_opd_discard(Address r_off
)
149 size_t ndx
= this->opd_ent_ndx(r_off
);
150 gold_assert(ndx
< this->opd_ent_
.size());
151 this->opd_ent_
[ndx
].discard
= true;
156 { return this->opd_valid_
; }
160 { this->opd_valid_
= true; }
162 // Examine .rela.opd to build info about function entry points.
164 scan_opd_relocs(size_t reloc_count
,
165 const unsigned char* prelocs
,
166 const unsigned char* plocal_syms
);
168 // Perform the Sized_relobj_file method, then set up opd info from
171 do_read_relocs(Read_relocs_data
*);
174 do_find_special_sections(Read_symbols_data
* sd
);
176 // Adjust this local symbol value. Return false if the symbol
177 // should be discarded from the output file.
179 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
181 if (size
== 64 && this->opd_shndx() != 0)
184 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
186 if (this->get_opd_discard(lv
->input_value()))
194 { return &this->access_from_map_
; }
196 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
197 // section at DST_OFF.
199 add_reference(Object
* src_obj
,
200 unsigned int src_indx
,
201 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
203 Section_id
src_id(src_obj
, src_indx
);
204 this->access_from_map_
[dst_off
].insert(src_id
);
207 // Add a reference to the code section specified by the .opd entry
210 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
212 size_t ndx
= this->opd_ent_ndx(dst_off
);
213 if (ndx
>= this->opd_ent_
.size())
214 this->opd_ent_
.resize(ndx
+ 1);
215 this->opd_ent_
[ndx
].gc_mark
= true;
219 process_gc_mark(Symbol_table
* symtab
)
221 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
222 if (this->opd_ent_
[i
].gc_mark
)
224 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
225 symtab
->gc()->worklist().push(Section_id(this, shndx
));
229 // Return offset in output GOT section that this object will use
230 // as a TOC pointer. Won't be just a constant with multi-toc support.
232 toc_base_offset() const
236 set_has_small_toc_reloc()
237 { has_small_toc_reloc_
= true; }
240 has_small_toc_reloc() const
241 { return has_small_toc_reloc_
; }
244 set_has_14bit_branch(unsigned int shndx
)
246 if (shndx
>= this->has14_
.size())
247 this->has14_
.resize(shndx
+ 1);
248 this->has14_
[shndx
] = true;
252 has_14bit_branch(unsigned int shndx
) const
253 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
256 set_stub_table(unsigned int shndx
, Stub_table
<size
, big_endian
>* stub_table
)
258 if (shndx
>= this->stub_table_
.size())
259 this->stub_table_
.resize(shndx
+ 1);
260 this->stub_table_
[shndx
] = stub_table
;
263 Stub_table
<size
, big_endian
>*
264 stub_table(unsigned int shndx
)
266 if (shndx
< this->stub_table_
.size())
267 return this->stub_table_
[shndx
];
280 // Return index into opd_ent_ array for .opd entry at OFF.
281 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
282 // apart when the language doesn't use the last 8-byte word, the
283 // environment pointer. Thus dividing the entry section offset by
284 // 16 will give an index into opd_ent_ that works for either layout
285 // of .opd. (It leaves some elements of the vector unused when .opd
286 // entries are spaced 24 bytes apart, but we don't know the spacing
287 // until relocations are processed, and in any case it is possible
288 // for an object to have some entries spaced 16 bytes apart and
289 // others 24 bytes apart.)
291 opd_ent_ndx(size_t off
) const
294 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
295 unsigned int special_
;
297 // For 64-bit, whether this object uses small model relocs to access
299 bool has_small_toc_reloc_
;
301 // Set at the start of gc_process_relocs, when we know opd_ent_
302 // vector is valid. The flag could be made atomic and set in
303 // do_read_relocs with memory_order_release and then tested with
304 // memory_order_acquire, potentially resulting in fewer entries in
308 // The first 8-byte word of an OPD entry gives the address of the
309 // entry point of the function. Relocatable object files have a
310 // relocation on this word. The following vector records the
311 // section and offset specified by these relocations.
312 std::vector
<Opd_ent
> opd_ent_
;
314 // References made to this object's .opd section when running
315 // gc_process_relocs for another object, before the opd_ent_ vector
316 // is valid for this object.
317 Access_from access_from_map_
;
319 // Whether input section has a 14-bit branch reloc.
320 std::vector
<bool> has14_
;
322 // The stub table to use for a given input section.
323 std::vector
<Stub_table
<size
, big_endian
>*> stub_table_
;
326 template<int size
, bool big_endian
>
327 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
330 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
332 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
333 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
334 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
335 opd_shndx_(0), opd_ent_()
341 // Call Sized_dynobj::do_read_symbols to read the symbols then
342 // read .opd from a dynamic object, filling in opd_ent_ vector,
344 do_read_symbols(Read_symbols_data
*);
346 // The .opd section shndx.
350 return this->opd_shndx_
;
353 // The .opd section address.
357 return this->opd_address_
;
360 // Init OPD entry arrays.
362 init_opd(size_t opd_size
)
364 size_t count
= this->opd_ent_ndx(opd_size
);
365 this->opd_ent_
.resize(count
);
368 // Return section and offset of function entry for .opd + R_OFF.
370 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
372 size_t ndx
= this->opd_ent_ndx(r_off
);
373 gold_assert(ndx
< this->opd_ent_
.size());
374 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
376 *value
= this->opd_ent_
[ndx
].off
;
377 return this->opd_ent_
[ndx
].shndx
;
380 // Set section and offset of function entry for .opd + R_OFF.
382 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
384 size_t ndx
= this->opd_ent_ndx(r_off
);
385 gold_assert(ndx
< this->opd_ent_
.size());
386 this->opd_ent_
[ndx
].shndx
= shndx
;
387 this->opd_ent_
[ndx
].off
= value
;
391 // Used to specify extent of executable sections.
394 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
395 : start(start_
), len(len_
), shndx(shndx_
)
399 operator<(const Sec_info
& that
) const
400 { return this->start
< that
.start
; }
413 // Return index into opd_ent_ array for .opd entry at OFF.
415 opd_ent_ndx(size_t off
) const
418 // For 64-bit the .opd section shndx and address.
419 unsigned int opd_shndx_
;
420 Address opd_address_
;
422 // The first 8-byte word of an OPD entry gives the address of the
423 // entry point of the function. Records the section and offset
424 // corresponding to the address. Note that in dynamic objects,
425 // offset is *not* relative to the section.
426 std::vector
<Opd_ent
> opd_ent_
;
429 template<int size
, bool big_endian
>
430 class Target_powerpc
: public Sized_target
<size
, big_endian
>
434 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
435 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
436 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
437 static const Address invalid_address
= static_cast<Address
>(0) - 1;
438 // Offset of tp and dtp pointers from start of TLS block.
439 static const Address tp_offset
= 0x7000;
440 static const Address dtp_offset
= 0x8000;
443 : Sized_target
<size
, big_endian
>(&powerpc_info
),
444 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
445 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
446 dynbss_(NULL
), tlsld_got_offset_(-1U),
447 stub_tables_(), branch_lookup_table_(), branch_info_(),
448 plt_thread_safe_(false)
452 // Process the relocations to determine unreferenced sections for
453 // garbage collection.
455 gc_process_relocs(Symbol_table
* symtab
,
457 Sized_relobj_file
<size
, big_endian
>* object
,
458 unsigned int data_shndx
,
459 unsigned int sh_type
,
460 const unsigned char* prelocs
,
462 Output_section
* output_section
,
463 bool needs_special_offset_handling
,
464 size_t local_symbol_count
,
465 const unsigned char* plocal_symbols
);
467 // Scan the relocations to look for symbol adjustments.
469 scan_relocs(Symbol_table
* symtab
,
471 Sized_relobj_file
<size
, big_endian
>* object
,
472 unsigned int data_shndx
,
473 unsigned int sh_type
,
474 const unsigned char* prelocs
,
476 Output_section
* output_section
,
477 bool needs_special_offset_handling
,
478 size_t local_symbol_count
,
479 const unsigned char* plocal_symbols
);
481 // Map input .toc section to output .got section.
483 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
485 if (size
== 64 && strcmp(name
, ".toc") == 0)
493 // Provide linker defined save/restore functions.
495 define_save_restore_funcs(Layout
*, Symbol_table
*);
497 // No stubs unless a final link.
500 { return !parameters
->options().relocatable(); }
503 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
506 do_plt_fde_location(const Output_data
*, unsigned char*,
507 uint64_t*, off_t
*) const;
509 // Stash info about branches, for stub generation.
511 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
512 unsigned int data_shndx
, Address r_offset
,
513 unsigned int r_type
, unsigned int r_sym
, Address addend
)
515 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
516 this->branch_info_
.push_back(info
);
517 if (r_type
== elfcpp::R_POWERPC_REL14
518 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
519 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
520 ppc_object
->set_has_14bit_branch(data_shndx
);
523 Stub_table
<size
, big_endian
>*
527 do_define_standard_symbols(Symbol_table
*, Layout
*);
529 // Finalize the sections.
531 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
533 // Return the value to use for a dynamic which requires special
536 do_dynsym_value(const Symbol
*) const;
538 // Return the PLT address to use for a local symbol.
540 do_plt_address_for_local(const Relobj
*, unsigned int) const;
542 // Return the PLT address to use for a global symbol.
544 do_plt_address_for_global(const Symbol
*) const;
546 // Return the offset to use for the GOT_INDX'th got entry which is
547 // for a local tls symbol specified by OBJECT, SYMNDX.
549 do_tls_offset_for_local(const Relobj
* object
,
551 unsigned int got_indx
) const;
553 // Return the offset to use for the GOT_INDX'th got entry which is
554 // for global tls symbol GSYM.
556 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
559 do_function_location(Symbol_location
*) const;
562 do_can_check_for_function_pointers() const
565 // Relocate a section.
567 relocate_section(const Relocate_info
<size
, big_endian
>*,
568 unsigned int sh_type
,
569 const unsigned char* prelocs
,
571 Output_section
* output_section
,
572 bool needs_special_offset_handling
,
574 Address view_address
,
575 section_size_type view_size
,
576 const Reloc_symbol_changes
*);
578 // Scan the relocs during a relocatable link.
580 scan_relocatable_relocs(Symbol_table
* symtab
,
582 Sized_relobj_file
<size
, big_endian
>* object
,
583 unsigned int data_shndx
,
584 unsigned int sh_type
,
585 const unsigned char* prelocs
,
587 Output_section
* output_section
,
588 bool needs_special_offset_handling
,
589 size_t local_symbol_count
,
590 const unsigned char* plocal_symbols
,
591 Relocatable_relocs
*);
593 // Emit relocations for a section.
595 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
596 unsigned int sh_type
,
597 const unsigned char* prelocs
,
599 Output_section
* output_section
,
600 typename
elfcpp::Elf_types
<size
>::Elf_Off
601 offset_in_output_section
,
602 const Relocatable_relocs
*,
604 Address view_address
,
606 unsigned char* reloc_view
,
607 section_size_type reloc_view_size
);
609 // Return whether SYM is defined by the ABI.
611 do_is_defined_by_abi(const Symbol
* sym
) const
613 return strcmp(sym
->name(), "__tls_get_addr") == 0;
616 // Return the size of the GOT section.
620 gold_assert(this->got_
!= NULL
);
621 return this->got_
->data_size();
624 // Get the PLT section.
625 const Output_data_plt_powerpc
<size
, big_endian
>*
628 gold_assert(this->plt_
!= NULL
);
632 // Get the IPLT section.
633 const Output_data_plt_powerpc
<size
, big_endian
>*
636 gold_assert(this->iplt_
!= NULL
);
640 // Get the .glink section.
641 const Output_data_glink
<size
, big_endian
>*
642 glink_section() const
644 gold_assert(this->glink_
!= NULL
);
648 bool has_glink() const
649 { return this->glink_
!= NULL
; }
651 // Get the GOT section.
652 const Output_data_got_powerpc
<size
, big_endian
>*
655 gold_assert(this->got_
!= NULL
);
659 // Get the GOT section, creating it if necessary.
660 Output_data_got_powerpc
<size
, big_endian
>*
661 got_section(Symbol_table
*, Layout
*);
664 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
665 const elfcpp::Ehdr
<size
, big_endian
>&);
667 // Return the number of entries in the GOT.
669 got_entry_count() const
671 if (this->got_
== NULL
)
673 return this->got_size() / (size
/ 8);
676 // Return the number of entries in the PLT.
678 plt_entry_count() const;
680 // Return the offset of the first non-reserved PLT entry.
682 first_plt_entry_offset() const;
684 // Return the size of each PLT entry.
686 plt_entry_size() const;
688 // Add any special sections for this symbol to the gc work list.
689 // For powerpc64, this adds the code section of a function
692 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
694 // Handle target specific gc actions when adding a gc reference from
695 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
696 // and DST_OFF. For powerpc64, this adds a referenc to the code
697 // section of a function descriptor.
699 do_gc_add_reference(Symbol_table
* symtab
,
701 unsigned int src_shndx
,
703 unsigned int dst_shndx
,
704 Address dst_off
) const;
706 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
709 { return this->stub_tables_
; }
711 const Output_data_brlt_powerpc
<size
, big_endian
>*
713 { return this->brlt_section_
; }
716 add_branch_lookup_table(Address to
)
718 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
719 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
723 find_branch_lookup_table(Address to
)
725 typename
Branch_lookup_table::const_iterator p
726 = this->branch_lookup_table_
.find(to
);
727 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
731 write_branch_lookup_table(unsigned char *oview
)
733 for (typename
Branch_lookup_table::const_iterator p
734 = this->branch_lookup_table_
.begin();
735 p
!= this->branch_lookup_table_
.end();
738 elfcpp::Swap
<32, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
743 plt_thread_safe() const
744 { return this->plt_thread_safe_
; }
760 : tls_get_addr_(NOT_EXPECTED
),
761 relinfo_(NULL
), relnum_(0), r_offset_(0)
766 if (this->tls_get_addr_
!= NOT_EXPECTED
)
773 if (this->relinfo_
!= NULL
)
774 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
775 _("missing expected __tls_get_addr call"));
779 expect_tls_get_addr_call(
780 const Relocate_info
<size
, big_endian
>* relinfo
,
784 this->tls_get_addr_
= EXPECTED
;
785 this->relinfo_
= relinfo
;
786 this->relnum_
= relnum
;
787 this->r_offset_
= r_offset
;
791 expect_tls_get_addr_call()
792 { this->tls_get_addr_
= EXPECTED
; }
795 skip_next_tls_get_addr_call()
796 {this->tls_get_addr_
= SKIP
; }
799 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
801 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
802 || r_type
== elfcpp::R_PPC_PLTREL24
)
804 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
805 Tls_get_addr last_tls
= this->tls_get_addr_
;
806 this->tls_get_addr_
= NOT_EXPECTED
;
807 if (is_tls_call
&& last_tls
!= EXPECTED
)
809 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
818 // What we're up to regarding calls to __tls_get_addr.
819 // On powerpc, the branch and link insn making a call to
820 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
821 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
822 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
823 // The marker relocation always comes first, and has the same
824 // symbol as the reloc on the insn setting up the __tls_get_addr
825 // argument. This ties the arg setup insn with the call insn,
826 // allowing ld to safely optimize away the call. We check that
827 // every call to __tls_get_addr has a marker relocation, and that
828 // every marker relocation is on a call to __tls_get_addr.
829 Tls_get_addr tls_get_addr_
;
830 // Info about the last reloc for error message.
831 const Relocate_info
<size
, big_endian
>* relinfo_
;
836 // The class which scans relocations.
837 class Scan
: protected Track_tls
840 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
843 : Track_tls(), issued_non_pic_error_(false)
847 get_reference_flags(unsigned int r_type
);
850 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
851 Sized_relobj_file
<size
, big_endian
>* object
,
852 unsigned int data_shndx
,
853 Output_section
* output_section
,
854 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
855 const elfcpp::Sym
<size
, big_endian
>& lsym
,
859 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
860 Sized_relobj_file
<size
, big_endian
>* object
,
861 unsigned int data_shndx
,
862 Output_section
* output_section
,
863 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
867 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
869 Sized_relobj_file
<size
, big_endian
>* ,
872 const elfcpp::Rela
<size
, big_endian
>& ,
874 const elfcpp::Sym
<size
, big_endian
>&)
876 // PowerPC64 .opd is not folded, so any identical function text
877 // may be folded and we'll still keep function addresses distinct.
878 // That means no reloc is of concern here.
881 // For 32-bit, conservatively assume anything but calls to
882 // function code might be taking the address of the function.
883 return !is_branch_reloc(r_type
);
887 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
889 Sized_relobj_file
<size
, big_endian
>* ,
892 const elfcpp::Rela
<size
, big_endian
>& ,
899 return !is_branch_reloc(r_type
);
904 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
905 unsigned int r_type
);
908 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
909 unsigned int r_type
, Symbol
*);
912 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
913 Target_powerpc
* target
);
916 check_non_pic(Relobj
*, unsigned int r_type
);
919 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>* object
,
920 unsigned int r_type
);
922 // Whether we have issued an error about a non-PIC compilation.
923 bool issued_non_pic_error_
;
927 symval_for_branch(const Symbol_table
* symtab
, Address value
,
928 const Sized_symbol
<size
>* gsym
,
929 Powerpc_relobj
<size
, big_endian
>* object
,
930 unsigned int *dest_shndx
);
932 // The class which implements relocation.
933 class Relocate
: protected Track_tls
936 // Use 'at' branch hints when true, 'y' when false.
937 // FIXME maybe: set this with an option.
938 static const bool is_isa_v2
= true;
944 // Do a relocation. Return false if the caller should not issue
945 // any warnings about this relocation.
947 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
948 Output_section
*, size_t relnum
,
949 const elfcpp::Rela
<size
, big_endian
>&,
950 unsigned int r_type
, const Sized_symbol
<size
>*,
951 const Symbol_value
<size
>*,
953 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
957 class Relocate_comdat_behavior
960 // Decide what the linker should do for relocations that refer to
961 // discarded comdat sections.
962 inline Comdat_behavior
963 get(const char* name
)
965 gold::Default_comdat_behavior default_behavior
;
966 Comdat_behavior ret
= default_behavior
.get(name
);
967 if (ret
== CB_WARNING
)
970 && (strcmp(name
, ".fixup") == 0
971 || strcmp(name
, ".got2") == 0))
974 && (strcmp(name
, ".opd") == 0
975 || strcmp(name
, ".toc") == 0
976 || strcmp(name
, ".toc1") == 0))
983 // A class which returns the size required for a relocation type,
984 // used while scanning relocs during a relocatable link.
985 class Relocatable_size_for_reloc
989 get_size_for_reloc(unsigned int, Relobj
*)
996 // Optimize the TLS relocation type based on what we know about the
997 // symbol. IS_FINAL is true if the final address of this symbol is
998 // known at link time.
1000 tls::Tls_optimization
1001 optimize_tls_gd(bool is_final
)
1003 // If we are generating a shared library, then we can't do anything
1005 if (parameters
->options().shared())
1006 return tls::TLSOPT_NONE
;
1009 return tls::TLSOPT_TO_IE
;
1010 return tls::TLSOPT_TO_LE
;
1013 tls::Tls_optimization
1016 if (parameters
->options().shared())
1017 return tls::TLSOPT_NONE
;
1019 return tls::TLSOPT_TO_LE
;
1022 tls::Tls_optimization
1023 optimize_tls_ie(bool is_final
)
1025 if (!is_final
|| parameters
->options().shared())
1026 return tls::TLSOPT_NONE
;
1028 return tls::TLSOPT_TO_LE
;
1033 make_glink_section(Layout
*);
1035 // Create the PLT section.
1037 make_plt_section(Symbol_table
*, Layout
*);
1040 make_iplt_section(Symbol_table
*, Layout
*);
1043 make_brlt_section(Layout
*);
1045 // Create a PLT entry for a global symbol.
1047 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1049 // Create a PLT entry for a local IFUNC symbol.
1051 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1052 Sized_relobj_file
<size
, big_endian
>*,
1056 // Create a GOT entry for local dynamic __tls_get_addr.
1058 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1059 Sized_relobj_file
<size
, big_endian
>* object
);
1062 tlsld_got_offset() const
1064 return this->tlsld_got_offset_
;
1067 // Get the dynamic reloc section, creating it if necessary.
1069 rela_dyn_section(Layout
*);
1071 // Copy a relocation against a global symbol.
1073 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1074 Sized_relobj_file
<size
, big_endian
>* object
,
1075 unsigned int shndx
, Output_section
* output_section
,
1076 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1078 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1079 symtab
->get_sized_symbol
<size
>(sym
),
1080 object
, shndx
, output_section
,
1081 reloc
, this->rela_dyn_section(layout
));
1084 // Look over all the input sections, deciding where to place stub.
1086 group_sections(Layout
*, const Task
*);
1088 // Sort output sections by address.
1089 struct Sort_sections
1092 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1093 { return sec1
->address() < sec2
->address(); }
1099 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1100 unsigned int data_shndx
,
1102 unsigned int r_type
,
1105 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1106 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1112 // If this branch needs a plt call stub, or a long branch stub, make one.
1114 make_stub(Stub_table
<size
, big_endian
>*,
1115 Stub_table
<size
, big_endian
>*,
1116 Symbol_table
*) const;
1119 // The branch location..
1120 Powerpc_relobj
<size
, big_endian
>* object_
;
1121 unsigned int shndx_
;
1123 // ..and the branch type and destination.
1124 unsigned int r_type_
;
1125 unsigned int r_sym_
;
1129 // Information about this specific target which we pass to the
1130 // general Target structure.
1131 static Target::Target_info powerpc_info
;
1133 // The types of GOT entries needed for this platform.
1134 // These values are exposed to the ABI in an incremental link.
1135 // Do not renumber existing values without changing the version
1136 // number of the .gnu_incremental_inputs section.
1140 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1141 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1142 GOT_TYPE_TPREL
// entry for @got@tprel
1146 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1148 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1149 // The IPLT section.
1150 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1151 // Section holding long branch destinations.
1152 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1153 // The .glink section.
1154 Output_data_glink
<size
, big_endian
>* glink_
;
1155 // The dynamic reloc section.
1156 Reloc_section
* rela_dyn_
;
1157 // Relocs saved to avoid a COPY reloc.
1158 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1159 // Space for variables copied with a COPY reloc.
1160 Output_data_space
* dynbss_
;
1161 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1162 unsigned int tlsld_got_offset_
;
1164 Stub_tables stub_tables_
;
1165 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1166 Branch_lookup_table branch_lookup_table_
;
1168 typedef std::vector
<Branch_info
> Branches
;
1169 Branches branch_info_
;
1171 bool plt_thread_safe_
;
1175 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1178 true, // is_big_endian
1179 elfcpp::EM_PPC
, // machine_code
1180 false, // has_make_symbol
1181 false, // has_resolve
1182 false, // has_code_fill
1183 true, // is_default_stack_executable
1184 false, // can_icf_inline_merge_sections
1186 "/usr/lib/ld.so.1", // dynamic_linker
1187 0x10000000, // default_text_segment_address
1188 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1189 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1190 false, // isolate_execinstr
1192 elfcpp::SHN_UNDEF
, // small_common_shndx
1193 elfcpp::SHN_UNDEF
, // large_common_shndx
1194 0, // small_common_section_flags
1195 0, // large_common_section_flags
1196 NULL
, // attributes_section
1197 NULL
// attributes_vendor
1201 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1204 false, // is_big_endian
1205 elfcpp::EM_PPC
, // machine_code
1206 false, // has_make_symbol
1207 false, // has_resolve
1208 false, // has_code_fill
1209 true, // is_default_stack_executable
1210 false, // can_icf_inline_merge_sections
1212 "/usr/lib/ld.so.1", // dynamic_linker
1213 0x10000000, // default_text_segment_address
1214 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1215 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1216 false, // isolate_execinstr
1218 elfcpp::SHN_UNDEF
, // small_common_shndx
1219 elfcpp::SHN_UNDEF
, // large_common_shndx
1220 0, // small_common_section_flags
1221 0, // large_common_section_flags
1222 NULL
, // attributes_section
1223 NULL
// attributes_vendor
1227 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1230 true, // is_big_endian
1231 elfcpp::EM_PPC64
, // machine_code
1232 false, // has_make_symbol
1233 false, // has_resolve
1234 false, // has_code_fill
1235 true, // is_default_stack_executable
1236 false, // can_icf_inline_merge_sections
1238 "/usr/lib/ld.so.1", // dynamic_linker
1239 0x10000000, // default_text_segment_address
1240 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1241 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1242 false, // isolate_execinstr
1244 elfcpp::SHN_UNDEF
, // small_common_shndx
1245 elfcpp::SHN_UNDEF
, // large_common_shndx
1246 0, // small_common_section_flags
1247 0, // large_common_section_flags
1248 NULL
, // attributes_section
1249 NULL
// attributes_vendor
1253 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1256 false, // is_big_endian
1257 elfcpp::EM_PPC64
, // machine_code
1258 false, // has_make_symbol
1259 false, // has_resolve
1260 false, // has_code_fill
1261 true, // is_default_stack_executable
1262 false, // can_icf_inline_merge_sections
1264 "/usr/lib/ld.so.1", // dynamic_linker
1265 0x10000000, // default_text_segment_address
1266 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1267 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1268 false, // isolate_execinstr
1270 elfcpp::SHN_UNDEF
, // small_common_shndx
1271 elfcpp::SHN_UNDEF
, // large_common_shndx
1272 0, // small_common_section_flags
1273 0, // large_common_section_flags
1274 NULL
, // attributes_section
1275 NULL
// attributes_vendor
1279 is_branch_reloc(unsigned int r_type
)
1281 return (r_type
== elfcpp::R_POWERPC_REL24
1282 || r_type
== elfcpp::R_PPC_PLTREL24
1283 || r_type
== elfcpp::R_PPC_LOCAL24PC
1284 || r_type
== elfcpp::R_POWERPC_REL14
1285 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1286 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1287 || r_type
== elfcpp::R_POWERPC_ADDR24
1288 || r_type
== elfcpp::R_POWERPC_ADDR14
1289 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1290 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1293 // If INSN is an opcode that may be used with an @tls operand, return
1294 // the transformed insn for TLS optimisation, otherwise return 0. If
1295 // REG is non-zero only match an insn with RB or RA equal to REG.
1297 at_tls_transform(uint32_t insn
, unsigned int reg
)
1299 if ((insn
& (0x3f << 26)) != 31 << 26)
1303 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1304 rtra
= insn
& ((1 << 26) - (1 << 16));
1305 else if (((insn
>> 16) & 0x1f) == reg
)
1306 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1310 if ((insn
& (0x3ff << 1)) == 266 << 1)
1313 else if ((insn
& (0x1f << 1)) == 23 << 1
1314 && ((insn
& (0x1f << 6)) < 14 << 6
1315 || ((insn
& (0x1f << 6)) >= 16 << 6
1316 && (insn
& (0x1f << 6)) < 24 << 6)))
1317 // load and store indexed -> dform
1318 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1319 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1320 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1321 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1322 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1324 insn
= (58 << 26) | 2;
1331 // Modified version of symtab.h class Symbol member
1332 // Given a direct absolute or pc-relative static relocation against
1333 // the global symbol, this function returns whether a dynamic relocation
1338 needs_dynamic_reloc(const Symbol
* gsym
, int flags
)
1340 // No dynamic relocations in a static link!
1341 if (parameters
->doing_static_link())
1344 // A reference to an undefined symbol from an executable should be
1345 // statically resolved to 0, and does not need a dynamic relocation.
1346 // This matches gnu ld behavior.
1347 if (gsym
->is_undefined() && !parameters
->options().shared())
1350 // A reference to an absolute symbol does not need a dynamic relocation.
1351 if (gsym
->is_absolute())
1354 // An absolute reference within a position-independent output file
1355 // will need a dynamic relocation.
1356 if ((flags
& Symbol::ABSOLUTE_REF
)
1357 && parameters
->options().output_is_position_independent())
1360 // A function call that can branch to a local PLT entry does not need
1361 // a dynamic relocation.
1362 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->has_plt_offset())
1365 // A reference to any PLT entry in a non-position-independent executable
1366 // does not need a dynamic relocation.
1367 // Except due to having function descriptors on powerpc64 we don't define
1368 // functions to their plt code in an executable, so this doesn't apply.
1370 && !parameters
->options().output_is_position_independent()
1371 && gsym
->has_plt_offset())
1374 // A reference to a symbol defined in a dynamic object or to a
1375 // symbol that is preemptible will need a dynamic relocation.
1376 if (gsym
->is_from_dynobj()
1377 || gsym
->is_undefined()
1378 || gsym
->is_preemptible())
1381 // For all other cases, return FALSE.
1385 // Modified version of symtab.h class Symbol member
1386 // Whether we should use the PLT offset associated with a symbol for
1387 // a relocation. FLAGS is a set of Reference_flags.
1391 use_plt_offset(const Symbol
* gsym
, int flags
)
1393 // If the symbol doesn't have a PLT offset, then naturally we
1394 // don't want to use it.
1395 if (!gsym
->has_plt_offset())
1398 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
1399 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
1402 // If we are going to generate a dynamic relocation, then we will
1403 // wind up using that, so no need to use the PLT entry.
1404 if (needs_dynamic_reloc
<size
>(gsym
, flags
))
1407 // If the symbol is from a dynamic object, we need to use the PLT
1409 if (gsym
->is_from_dynobj())
1412 // If we are generating a shared object, and this symbol is
1413 // undefined or preemptible, we need to use the PLT entry.
1414 if (parameters
->options().shared()
1415 && (gsym
->is_undefined() || gsym
->is_preemptible()))
1418 // If this is a call to a weak undefined symbol, we need to use
1419 // the PLT entry; the symbol may be defined by a library loaded
1421 if ((flags
& Symbol::FUNCTION_CALL
) && gsym
->is_weak_undefined())
1424 // Otherwise we can use the regular definition.
1428 template<int size
, bool big_endian
>
1429 class Powerpc_relocate_functions
1446 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1447 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1449 template<int valsize
>
1451 has_overflow_signed(Address value
)
1453 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1454 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1455 limit
<<= ((valsize
- 1) >> 1);
1456 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1457 return value
+ limit
> (limit
<< 1) - 1;
1460 template<int valsize
>
1462 has_overflow_bitfield(Address value
)
1464 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1465 limit
<<= ((valsize
- 1) >> 1);
1466 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1467 return value
> (limit
<< 1) - 1 && value
+ limit
> (limit
<< 1) - 1;
1470 template<int valsize
>
1471 static inline Status
1472 overflowed(Address value
, Overflow_check overflow
)
1474 if (overflow
== CHECK_SIGNED
)
1476 if (has_overflow_signed
<valsize
>(value
))
1477 return STATUS_OVERFLOW
;
1479 else if (overflow
== CHECK_BITFIELD
)
1481 if (has_overflow_bitfield
<valsize
>(value
))
1482 return STATUS_OVERFLOW
;
1487 // Do a simple RELA relocation
1488 template<int valsize
>
1489 static inline Status
1490 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1492 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1493 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1494 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, value
);
1495 return overflowed
<valsize
>(value
, overflow
);
1498 template<int valsize
>
1499 static inline Status
1500 rela(unsigned char* view
,
1501 unsigned int right_shift
,
1502 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1504 Overflow_check overflow
)
1506 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
1507 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1508 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
1509 Valtype reloc
= value
>> right_shift
;
1512 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
1513 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1516 // Do a simple RELA relocation, unaligned.
1517 template<int valsize
>
1518 static inline Status
1519 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1521 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, value
);
1522 return overflowed
<valsize
>(value
, overflow
);
1525 template<int valsize
>
1526 static inline Status
1527 rela_ua(unsigned char* view
,
1528 unsigned int right_shift
,
1529 typename
elfcpp::Valtype_base
<valsize
>::Valtype dst_mask
,
1531 Overflow_check overflow
)
1533 typedef typename
elfcpp::Swap_unaligned
<valsize
, big_endian
>::Valtype
1535 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(view
);
1536 Valtype reloc
= value
>> right_shift
;
1539 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(view
, val
| reloc
);
1540 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1544 // R_PPC64_ADDR64: (Symbol + Addend)
1546 addr64(unsigned char* view
, Address value
)
1547 { This::template rela
<64>(view
, value
, CHECK_NONE
); }
1549 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1551 addr64_u(unsigned char* view
, Address value
)
1552 { This::template rela_ua
<64>(view
, value
, CHECK_NONE
); }
1554 // R_POWERPC_ADDR32: (Symbol + Addend)
1555 static inline Status
1556 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1557 { return This::template rela
<32>(view
, value
, overflow
); }
1559 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1560 static inline Status
1561 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1562 { return This::template rela_ua
<32>(view
, value
, overflow
); }
1564 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1565 static inline Status
1566 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1568 Status stat
= This::template rela
<32>(view
, 0, 0x03fffffc, value
, overflow
);
1569 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1570 stat
= STATUS_OVERFLOW
;
1574 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1575 static inline Status
1576 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1577 { return This::template rela
<16>(view
, value
, overflow
); }
1579 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1580 static inline Status
1581 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1582 { return This::template rela_ua
<16>(view
, value
, overflow
); }
1584 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1585 static inline Status
1586 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1588 Status stat
= This::template rela
<16>(view
, 0, 0xfffc, value
, overflow
);
1589 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1590 stat
= STATUS_OVERFLOW
;
1594 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1596 addr16_hi(unsigned char* view
, Address value
)
1597 { This::template rela
<16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1599 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1601 addr16_ha(unsigned char* view
, Address value
)
1602 { This::addr16_hi(view
, value
+ 0x8000); }
1604 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1606 addr16_hi2(unsigned char* view
, Address value
)
1607 { This::template rela
<16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1609 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1611 addr16_ha2(unsigned char* view
, Address value
)
1612 { This::addr16_hi2(view
, value
+ 0x8000); }
1614 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1616 addr16_hi3(unsigned char* view
, Address value
)
1617 { This::template rela
<16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1619 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1621 addr16_ha3(unsigned char* view
, Address value
)
1622 { This::addr16_hi3(view
, value
+ 0x8000); }
1624 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1625 static inline Status
1626 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1628 Status stat
= This::template rela
<32>(view
, 0, 0xfffc, value
, overflow
);
1629 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1630 stat
= STATUS_OVERFLOW
;
1635 // Stash away the index of .got2 or .opd in a relocatable object, if
1636 // such a section exists.
1638 template<int size
, bool big_endian
>
1640 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1641 Read_symbols_data
* sd
)
1643 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1644 const unsigned char* namesu
= sd
->section_names
->data();
1645 const char* names
= reinterpret_cast<const char*>(namesu
);
1646 section_size_type names_size
= sd
->section_names_size
;
1647 const unsigned char* s
;
1649 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1650 size
== 32 ? ".got2" : ".opd",
1651 names
, names_size
, NULL
);
1654 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1655 this->special_
= ndx
;
1657 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1660 // Examine .rela.opd to build info about function entry points.
1662 template<int size
, bool big_endian
>
1664 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1666 const unsigned char* prelocs
,
1667 const unsigned char* plocal_syms
)
1671 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1673 const int reloc_size
1674 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1675 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1676 Address expected_off
= 0;
1677 bool regular
= true;
1678 unsigned int opd_ent_size
= 0;
1680 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1682 Reltype
reloc(prelocs
);
1683 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1684 = reloc
.get_r_info();
1685 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1686 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1688 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1689 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1692 if (r_sym
< this->local_symbol_count())
1694 typename
elfcpp::Sym
<size
, big_endian
>
1695 lsym(plocal_syms
+ r_sym
* sym_size
);
1696 shndx
= lsym
.get_st_shndx();
1697 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1698 value
= lsym
.get_st_value();
1701 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1703 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1704 value
+ reloc
.get_r_addend());
1707 expected_off
= reloc
.get_r_offset();
1708 opd_ent_size
= expected_off
;
1710 else if (expected_off
!= reloc
.get_r_offset())
1712 expected_off
+= opd_ent_size
;
1714 else if (r_type
== elfcpp::R_PPC64_TOC
)
1716 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1721 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1722 this->name().c_str(), r_type
);
1726 if (reloc_count
<= 2)
1727 opd_ent_size
= this->section_size(this->opd_shndx());
1728 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1732 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1733 this->name().c_str());
1739 template<int size
, bool big_endian
>
1741 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1743 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1746 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1747 p
!= rd
->relocs
.end();
1750 if (p
->data_shndx
== this->opd_shndx())
1752 uint64_t opd_size
= this->section_size(this->opd_shndx());
1753 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1756 this->init_opd(opd_size
);
1757 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1758 rd
->local_symbols
->data());
1766 // Call Sized_dynobj::do_read_symbols to read the symbols then
1767 // read .opd from a dynamic object, filling in opd_ent_ vector,
1769 template<int size
, bool big_endian
>
1771 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1773 Sized_dynobj
<size
, big_endian
>::do_read_symbols(sd
);
1776 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1777 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1778 const unsigned char* namesu
= sd
->section_names
->data();
1779 const char* names
= reinterpret_cast<const char*>(namesu
);
1780 const unsigned char* s
= NULL
;
1781 const unsigned char* opd
;
1782 section_size_type opd_size
;
1784 // Find and read .opd section.
1787 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1788 sd
->section_names_size
,
1793 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1794 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1795 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1797 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
1798 this->opd_address_
= shdr
.get_sh_addr();
1799 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
1800 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
1806 // Build set of executable sections.
1807 // Using a set is probably overkill. There is likely to be only
1808 // a few executable sections, typically .init, .text and .fini,
1809 // and they are generally grouped together.
1810 typedef std::set
<Sec_info
> Exec_sections
;
1811 Exec_sections exec_sections
;
1813 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
1815 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1816 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1817 && ((shdr
.get_sh_flags()
1818 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1819 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
1820 && shdr
.get_sh_size() != 0)
1822 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
1823 shdr
.get_sh_size(), i
));
1826 if (exec_sections
.empty())
1829 // Look over the OPD entries. This is complicated by the fact
1830 // that some binaries will use two-word entries while others
1831 // will use the standard three-word entries. In most cases
1832 // the third word (the environment pointer for languages like
1833 // Pascal) is unused and will be zero. If the third word is
1834 // used it should not be pointing into executable sections,
1836 this->init_opd(opd_size
);
1837 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
1839 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
1840 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
1841 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
1843 // Chances are that this is the third word of an OPD entry.
1845 typename
Exec_sections::const_iterator e
1846 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
1847 if (e
!= exec_sections
.begin())
1850 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
1852 // We have an address in an executable section.
1853 // VAL ought to be the function entry, set it up.
1854 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
1855 // Skip second word of OPD entry, the TOC pointer.
1859 // If we didn't match any executable sections, we likely
1860 // have a non-zero third word in the OPD entry.
1865 // Set up some symbols.
1867 template<int size
, bool big_endian
>
1869 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
1870 Symbol_table
* symtab
,
1875 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
1876 // undefined when scanning relocs (and thus requires
1877 // non-relative dynamic relocs). The proper value will be
1879 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
1880 if (gotsym
!= NULL
&& gotsym
->is_undefined())
1882 Target_powerpc
<size
, big_endian
>* target
=
1883 static_cast<Target_powerpc
<size
, big_endian
>*>(
1884 parameters
->sized_target
<size
, big_endian
>());
1885 Output_data_got_powerpc
<size
, big_endian
>* got
1886 = target
->got_section(symtab
, layout
);
1887 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1888 Symbol_table::PREDEFINED
,
1892 elfcpp::STV_HIDDEN
, 0,
1896 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
1897 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
1898 if (sdasym
!= NULL
&& sdasym
->is_undefined())
1900 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
1902 = layout
->add_output_section_data(".sdata", 0,
1904 | elfcpp::SHF_WRITE
,
1905 sdata
, ORDER_SMALL_DATA
, false);
1906 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
1907 Symbol_table::PREDEFINED
,
1908 os
, 32768, 0, elfcpp::STT_OBJECT
,
1909 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
1915 // Set up PowerPC target specific relobj.
1917 template<int size
, bool big_endian
>
1919 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
1920 const std::string
& name
,
1921 Input_file
* input_file
,
1922 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
1924 int et
= ehdr
.get_e_type();
1925 // ET_EXEC files are valid input for --just-symbols/-R,
1926 // and we treat them as relocatable objects.
1927 if (et
== elfcpp::ET_REL
1928 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
1930 Powerpc_relobj
<size
, big_endian
>* obj
=
1931 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1935 else if (et
== elfcpp::ET_DYN
)
1937 Powerpc_dynobj
<size
, big_endian
>* obj
=
1938 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
1944 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
1949 template<int size
, bool big_endian
>
1950 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
1953 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
1954 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
1956 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
1957 : Output_data_got
<size
, big_endian
>(),
1958 symtab_(symtab
), layout_(layout
),
1959 header_ent_cnt_(size
== 32 ? 3 : 1),
1960 header_index_(size
== 32 ? 0x2000 : 0)
1965 // Create a new GOT entry and return its offset.
1967 add_got_entry(Got_entry got_entry
)
1969 this->reserve_ent();
1970 return Output_data_got
<size
, big_endian
>::add_got_entry(got_entry
);
1973 // Create a pair of new GOT entries and return the offset of the first.
1975 add_got_entry_pair(Got_entry got_entry_1
, Got_entry got_entry_2
)
1977 this->reserve_ent(2);
1978 return Output_data_got
<size
, big_endian
>::add_got_entry_pair(got_entry_1
,
1983 add_constant_pair(Valtype c1
, Valtype c2
)
1985 this->reserve_ent(2);
1986 unsigned int got_offset
= this->add_constant(c1
);
1987 this->add_constant(c2
);
1991 // Offset of _GLOBAL_OFFSET_TABLE_.
1995 return this->got_offset(this->header_index_
);
1998 // Offset of base used to access the GOT/TOC.
1999 // The got/toc pointer reg will be set to this value.
2001 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2004 return this->g_o_t();
2006 return (this->output_section()->address()
2007 + object
->toc_base_offset()
2011 // Ensure our GOT has a header.
2013 set_final_data_size()
2015 if (this->header_ent_cnt_
!= 0)
2016 this->make_header();
2017 Output_data_got
<size
, big_endian
>::set_final_data_size();
2020 // First word of GOT header needs some values that are not
2021 // handled by Output_data_got so poke them in here.
2022 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2024 do_write(Output_file
* of
)
2027 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2028 val
= this->layout_
->dynamic_section()->address();
2030 val
= this->output_section()->address() + 0x8000;
2031 this->replace_constant(this->header_index_
, val
);
2032 Output_data_got
<size
, big_endian
>::do_write(of
);
2037 reserve_ent(unsigned int cnt
= 1)
2039 if (this->header_ent_cnt_
== 0)
2041 if (this->num_entries() + cnt
> this->header_index_
)
2042 this->make_header();
2048 this->header_ent_cnt_
= 0;
2049 this->header_index_
= this->num_entries();
2052 Output_data_got
<size
, big_endian
>::add_constant(0);
2053 Output_data_got
<size
, big_endian
>::add_constant(0);
2054 Output_data_got
<size
, big_endian
>::add_constant(0);
2056 // Define _GLOBAL_OFFSET_TABLE_ at the header
2057 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2060 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2061 sym
->set_value(this->g_o_t());
2064 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2065 Symbol_table::PREDEFINED
,
2066 this, this->g_o_t(), 0,
2069 elfcpp::STV_HIDDEN
, 0,
2073 Output_data_got
<size
, big_endian
>::add_constant(0);
2076 // Stashed pointers.
2077 Symbol_table
* symtab_
;
2081 unsigned int header_ent_cnt_
;
2082 // GOT header index.
2083 unsigned int header_index_
;
2086 // Get the GOT section, creating it if necessary.
2088 template<int size
, bool big_endian
>
2089 Output_data_got_powerpc
<size
, big_endian
>*
2090 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2093 if (this->got_
== NULL
)
2095 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2098 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2100 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2101 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2102 this->got_
, ORDER_DATA
, false);
2108 // Get the dynamic reloc section, creating it if necessary.
2110 template<int size
, bool big_endian
>
2111 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2112 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2114 if (this->rela_dyn_
== NULL
)
2116 gold_assert(layout
!= NULL
);
2117 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2118 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2119 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2120 ORDER_DYNAMIC_RELOCS
, false);
2122 return this->rela_dyn_
;
2128 // Determine the stub group size. The group size is the absolute
2129 // value of the parameter --stub-group-size. If --stub-group-size
2130 // is passed a negative value, we restrict stubs to be always before
2131 // the stubbed branches.
2132 Stub_control(int32_t size
)
2133 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
2134 stub14_group_size_(abs(size
)),
2135 stubs_always_before_branch_(size
< 0), suppress_size_errors_(false),
2136 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
2138 if (stub_group_size_
== 1)
2141 if (stubs_always_before_branch_
)
2143 stub_group_size_
= 0x1e00000;
2144 stub14_group_size_
= 0x7800;
2148 stub_group_size_
= 0x1c00000;
2149 stub14_group_size_
= 0x7000;
2151 suppress_size_errors_
= true;
2155 // Return true iff input section can be handled by current stub
2158 can_add_to_stub_group(Output_section
* o
,
2159 const Output_section::Input_section
* i
,
2162 const Output_section::Input_section
*
2168 { return output_section_
; }
2174 FINDING_STUB_SECTION
,
2179 uint32_t stub_group_size_
;
2180 uint32_t stub14_group_size_
;
2181 bool stubs_always_before_branch_
;
2182 bool suppress_size_errors_
;
2183 uint64_t group_end_addr_
;
2184 const Output_section::Input_section
* owner_
;
2185 Output_section
* output_section_
;
2188 // Return true iff input section can be handled by current stub/
2192 Stub_control::can_add_to_stub_group(Output_section
* o
,
2193 const Output_section::Input_section
* i
,
2197 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
2198 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2200 uint64_t start_addr
= o
->address();
2203 // .init and .fini sections are pasted together to form a single
2204 // function. We can't be adding stubs in the middle of the function.
2205 this_size
= o
->data_size();
2208 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2209 this_size
= i
->data_size();
2211 uint64_t end_addr
= start_addr
+ this_size
;
2212 bool toobig
= this_size
> group_size
;
2214 if (toobig
&& !this->suppress_size_errors_
)
2215 gold_warning(_("%s:%s exceeds group size"),
2216 i
->relobj()->name().c_str(),
2217 i
->relobj()->section_name(i
->shndx()).c_str());
2219 if (this->state_
!= HAS_STUB_SECTION
2220 && (!whole_sec
|| this->output_section_
!= o
))
2223 this->output_section_
= o
;
2226 if (this->state_
== NO_GROUP
)
2228 this->state_
= FINDING_STUB_SECTION
;
2229 this->group_end_addr_
= end_addr
;
2231 else if (this->group_end_addr_
- start_addr
< group_size
)
2233 // Adding this section would make the group larger than GROUP_SIZE.
2234 else if (this->state_
== FINDING_STUB_SECTION
2235 && !this->stubs_always_before_branch_
2238 // But wait, there's more! Input sections up to GROUP_SIZE
2239 // bytes before the stub table can be handled by it too.
2240 this->state_
= HAS_STUB_SECTION
;
2241 this->group_end_addr_
= end_addr
;
2245 this->state_
= NO_GROUP
;
2251 // Look over all the input sections, deciding where to place stubs.
2253 template<int size
, bool big_endian
>
2255 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2258 Stub_control
stub_control(parameters
->options().stub_group_size());
2260 // Group input sections and insert stub table
2261 Stub_table
<size
, big_endian
>* stub_table
= NULL
;
2262 Layout::Section_list section_list
;
2263 layout
->get_executable_sections(§ion_list
);
2264 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2265 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
2266 o
!= section_list
.rend();
2269 typedef Output_section::Input_section_list Input_section_list
;
2270 for (Input_section_list::const_reverse_iterator i
2271 = (*o
)->input_sections().rbegin();
2272 i
!= (*o
)->input_sections().rend();
2275 if (i
->is_input_section())
2277 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2278 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2279 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2280 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2282 stub_table
->init(stub_control
.owner(),
2283 stub_control
.output_section());
2286 if (stub_table
== NULL
)
2287 stub_table
= this->new_stub_table();
2288 ppcobj
->set_stub_table(i
->shndx(), stub_table
);
2292 if (stub_table
!= NULL
)
2293 stub_table
->init(stub_control
.owner(), stub_control
.output_section());
2296 // If this branch needs a plt call stub, or a long branch stub, make one.
2298 template<int size
, bool big_endian
>
2300 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2301 Stub_table
<size
, big_endian
>* stub_table
,
2302 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2303 Symbol_table
* symtab
) const
2305 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2306 if (sym
!= NULL
&& sym
->is_forwarder())
2307 sym
= symtab
->resolve_forwards(sym
);
2308 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2310 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(this->r_type_
))
2311 : this->object_
->local_has_plt_offset(this->r_sym_
))
2313 if (stub_table
== NULL
)
2314 stub_table
= this->object_
->stub_table(this->shndx_
);
2315 if (stub_table
== NULL
)
2317 // This is a ref from a data section to an ifunc symbol.
2318 stub_table
= ifunc_stub_table
;
2320 gold_assert(stub_table
!= NULL
);
2322 stub_table
->add_plt_call_entry(this->object_
, gsym
,
2323 this->r_type_
, this->addend_
);
2325 stub_table
->add_plt_call_entry(this->object_
, this->r_sym_
,
2326 this->r_type_
, this->addend_
);
2330 unsigned int max_branch_offset
;
2331 if (this->r_type_
== elfcpp::R_POWERPC_REL14
2332 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRTAKEN
2333 || this->r_type_
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2334 max_branch_offset
= 1 << 15;
2335 else if (this->r_type_
== elfcpp::R_POWERPC_REL24
2336 || this->r_type_
== elfcpp::R_PPC_PLTREL24
2337 || this->r_type_
== elfcpp::R_PPC_LOCAL24PC
)
2338 max_branch_offset
= 1 << 25;
2341 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2342 gold_assert(from
!= invalid_address
);
2343 from
+= (this->object_
->output_section(this->shndx_
)->address()
2348 switch (gsym
->source())
2350 case Symbol::FROM_OBJECT
:
2352 Object
* symobj
= gsym
->object();
2353 if (symobj
->is_dynamic()
2354 || symobj
->pluginobj() != NULL
)
2357 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2358 if (shndx
== elfcpp::SHN_UNDEF
)
2363 case Symbol::IS_UNDEFINED
:
2369 Symbol_table::Compute_final_value_status status
;
2370 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2371 if (status
!= Symbol_table::CFVS_OK
)
2376 const Symbol_value
<size
>* psymval
2377 = this->object_
->local_symbol(this->r_sym_
);
2378 Symbol_value
<size
> symval
;
2379 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2380 typename
ObjType::Compute_final_local_value_status status
2381 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2383 if (status
!= ObjType::CFLV_OK
2384 || !symval
.has_output_value())
2386 to
= symval
.value(this->object_
, 0);
2388 to
+= this->addend_
;
2389 if (stub_table
== NULL
)
2390 stub_table
= this->object_
->stub_table(this->shndx_
);
2391 gold_assert(stub_table
!= NULL
);
2392 if (size
== 64 && is_branch_reloc(this->r_type_
))
2394 unsigned int dest_shndx
;
2395 to
= stub_table
->targ()->symval_for_branch(symtab
, to
, gsym
,
2399 Address delta
= to
- from
;
2400 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2402 stub_table
->add_long_branch_entry(this->object_
, to
);
2407 // Relaxation hook. This is where we do stub generation.
2409 template<int size
, bool big_endian
>
2411 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2412 const Input_objects
*,
2413 Symbol_table
* symtab
,
2417 unsigned int prev_brlt_size
= 0;
2420 bool thread_safe
= parameters
->options().plt_thread_safe();
2421 if (size
== 64 && !parameters
->options().user_set_plt_thread_safe())
2423 static const char* const thread_starter
[] =
2427 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2429 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2430 "mq_notify", "create_timer",
2434 "GOMP_parallel_start",
2435 "GOMP_parallel_loop_static_start",
2436 "GOMP_parallel_loop_dynamic_start",
2437 "GOMP_parallel_loop_guided_start",
2438 "GOMP_parallel_loop_runtime_start",
2439 "GOMP_parallel_sections_start",
2442 if (parameters
->options().shared())
2446 for (unsigned int i
= 0;
2447 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2450 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2451 thread_safe
= (sym
!= NULL
2453 && sym
->in_real_elf());
2459 this->plt_thread_safe_
= thread_safe
;
2460 this->group_sections(layout
, task
);
2463 // We need address of stub tables valid for make_stub.
2464 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2465 p
!= this->stub_tables_
.end();
2468 const Powerpc_relobj
<size
, big_endian
>* object
2469 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2470 Address off
= object
->get_output_section_offset((*p
)->shndx());
2471 gold_assert(off
!= invalid_address
);
2472 Output_section
* os
= (*p
)->output_section();
2473 (*p
)->set_address_and_size(os
, off
);
2478 // Clear plt call stubs, long branch stubs and branch lookup table.
2479 prev_brlt_size
= this->branch_lookup_table_
.size();
2480 this->branch_lookup_table_
.clear();
2481 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2482 p
!= this->stub_tables_
.end();
2485 (*p
)->clear_stubs();
2489 // Build all the stubs.
2490 Stub_table
<size
, big_endian
>* ifunc_stub_table
2491 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2492 Stub_table
<size
, big_endian
>* one_stub_table
2493 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2494 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2495 b
!= this->branch_info_
.end();
2498 b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
);
2501 // Did anything change size?
2502 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2503 bool again
= num_huge_branches
!= prev_brlt_size
;
2504 if (size
== 64 && num_huge_branches
!= 0)
2505 this->make_brlt_section(layout
);
2506 if (size
== 64 && again
)
2507 this->brlt_section_
->set_current_size(num_huge_branches
);
2509 typedef Unordered_set
<Output_section
*> Output_sections
;
2510 Output_sections os_need_update
;
2511 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2512 p
!= this->stub_tables_
.end();
2515 if ((*p
)->size_update())
2518 (*p
)->add_eh_frame(layout
);
2519 os_need_update
.insert((*p
)->output_section());
2523 // Set output section offsets for all input sections in an output
2524 // section that just changed size. Anything past the stubs will
2526 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2527 p
!= os_need_update
.end();
2530 Output_section
* os
= *p
;
2532 typedef Output_section::Input_section_list Input_section_list
;
2533 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2534 i
!= os
->input_sections().end();
2537 off
= align_address(off
, i
->addralign());
2538 if (i
->is_input_section() || i
->is_relaxed_input_section())
2539 i
->relobj()->set_section_offset(i
->shndx(), off
);
2540 if (i
->is_relaxed_input_section())
2542 Stub_table
<size
, big_endian
>* stub_table
2543 = static_cast<Stub_table
<size
, big_endian
>*>(
2544 i
->relaxed_input_section());
2545 off
+= stub_table
->set_address_and_size(os
, off
);
2548 off
+= i
->data_size();
2550 // If .brlt is part of this output section, then we have just
2551 // done the offset adjustment.
2552 os
->clear_section_offsets_need_adjustment();
2557 && num_huge_branches
!= 0
2558 && parameters
->options().output_is_position_independent())
2560 // Fill in the BRLT relocs.
2561 this->brlt_section_
->reset_data_size();
2562 for (typename
Branch_lookup_table::const_iterator p
2563 = this->branch_lookup_table_
.begin();
2564 p
!= this->branch_lookup_table_
.end();
2567 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
2569 this->brlt_section_
->finalize_data_size();
2574 template<int size
, bool big_endian
>
2576 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
2577 unsigned char* oview
,
2581 uint64_t address
= plt
->address();
2582 off_t len
= plt
->data_size();
2584 if (plt
== this->glink_
)
2586 // See Output_data_glink::do_write() for glink contents.
2589 // There is one word before __glink_PLTresolve
2593 else if (parameters
->options().output_is_position_independent())
2595 // There are two FDEs for a position independent glink.
2596 // The first covers the branch table, the second
2597 // __glink_PLTresolve at the end of glink.
2598 off_t resolve_size
= this->glink_
->pltresolve_size
;
2600 len
-= resolve_size
;
2603 address
+= len
- resolve_size
;
2610 // Must be a stub table.
2611 const Stub_table
<size
, big_endian
>* stub_table
2612 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
2613 uint64_t stub_address
= stub_table
->stub_address();
2614 len
-= stub_address
- address
;
2615 address
= stub_address
;
2618 *paddress
= address
;
2622 // A class to handle the PLT data.
2624 template<int size
, bool big_endian
>
2625 class Output_data_plt_powerpc
: public Output_section_data_build
2628 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
2629 size
, big_endian
> Reloc_section
;
2631 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
2632 Reloc_section
* plt_rel
,
2633 unsigned int reserved_size
,
2635 : Output_section_data_build(size
== 32 ? 4 : 8),
2638 initial_plt_entry_size_(reserved_size
),
2642 // Add an entry to the PLT.
2647 add_ifunc_entry(Symbol
*);
2650 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
2652 // Return the .rela.plt section data.
2659 // Return the number of PLT entries.
2663 return ((this->current_data_size() - this->initial_plt_entry_size_
)
2667 // Return the offset of the first non-reserved PLT entry.
2669 first_plt_entry_offset()
2670 { return this->initial_plt_entry_size_
; }
2672 // Return the size of a PLT entry.
2674 get_plt_entry_size()
2675 { return plt_entry_size
; }
2679 do_adjust_output_section(Output_section
* os
)
2684 // Write to a map file.
2686 do_print_to_mapfile(Mapfile
* mapfile
) const
2687 { mapfile
->print_output_data(this, this->name_
); }
2690 // The size of an entry in the PLT.
2691 static const int plt_entry_size
= size
== 32 ? 4 : 24;
2693 // Write out the PLT data.
2695 do_write(Output_file
*);
2697 // The reloc section.
2698 Reloc_section
* rel_
;
2699 // Allows access to .glink for do_write.
2700 Target_powerpc
<size
, big_endian
>* targ_
;
2701 // The size of the first reserved entry.
2702 int initial_plt_entry_size_
;
2703 // What to report in map file.
2707 // Add an entry to the PLT.
2709 template<int size
, bool big_endian
>
2711 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
2713 if (!gsym
->has_plt_offset())
2715 section_size_type off
= this->current_data_size();
2717 off
+= this->first_plt_entry_offset();
2718 gsym
->set_plt_offset(off
);
2719 gsym
->set_needs_dynsym_entry();
2720 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
2721 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
2722 off
+= plt_entry_size
;
2723 this->set_current_data_size(off
);
2727 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
2729 template<int size
, bool big_endian
>
2731 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
2733 if (!gsym
->has_plt_offset())
2735 section_size_type off
= this->current_data_size();
2736 gsym
->set_plt_offset(off
);
2737 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2739 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
2740 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
2741 off
+= plt_entry_size
;
2742 this->set_current_data_size(off
);
2746 // Add an entry for a local ifunc symbol to the IPLT.
2748 template<int size
, bool big_endian
>
2750 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
2751 Sized_relobj_file
<size
, big_endian
>* relobj
,
2752 unsigned int local_sym_index
)
2754 if (!relobj
->local_has_plt_offset(local_sym_index
))
2756 section_size_type off
= this->current_data_size();
2757 relobj
->set_local_plt_offset(local_sym_index
, off
);
2758 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
2760 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
2761 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
2763 off
+= plt_entry_size
;
2764 this->set_current_data_size(off
);
2768 static const uint32_t add_0_11_11
= 0x7c0b5a14;
2769 static const uint32_t add_2_2_11
= 0x7c425a14;
2770 static const uint32_t add_3_3_2
= 0x7c631214;
2771 static const uint32_t add_3_3_13
= 0x7c636a14;
2772 static const uint32_t add_11_0_11
= 0x7d605a14;
2773 static const uint32_t add_12_2_11
= 0x7d825a14;
2774 static const uint32_t add_12_12_11
= 0x7d8c5a14;
2775 static const uint32_t addi_11_11
= 0x396b0000;
2776 static const uint32_t addi_12_12
= 0x398c0000;
2777 static const uint32_t addi_2_2
= 0x38420000;
2778 static const uint32_t addi_3_2
= 0x38620000;
2779 static const uint32_t addi_3_3
= 0x38630000;
2780 static const uint32_t addis_0_2
= 0x3c020000;
2781 static const uint32_t addis_0_13
= 0x3c0d0000;
2782 static const uint32_t addis_11_11
= 0x3d6b0000;
2783 static const uint32_t addis_11_30
= 0x3d7e0000;
2784 static const uint32_t addis_12_12
= 0x3d8c0000;
2785 static const uint32_t addis_12_2
= 0x3d820000;
2786 static const uint32_t addis_3_2
= 0x3c620000;
2787 static const uint32_t addis_3_13
= 0x3c6d0000;
2788 static const uint32_t b
= 0x48000000;
2789 static const uint32_t bcl_20_31
= 0x429f0005;
2790 static const uint32_t bctr
= 0x4e800420;
2791 static const uint32_t blr
= 0x4e800020;
2792 static const uint32_t blrl
= 0x4e800021;
2793 static const uint32_t bnectr_p4
= 0x4ce20420;
2794 static const uint32_t cmpldi_2_0
= 0x28220000;
2795 static const uint32_t cror_15_15_15
= 0x4def7b82;
2796 static const uint32_t cror_31_31_31
= 0x4ffffb82;
2797 static const uint32_t ld_0_1
= 0xe8010000;
2798 static const uint32_t ld_0_12
= 0xe80c0000;
2799 static const uint32_t ld_11_12
= 0xe96c0000;
2800 static const uint32_t ld_11_2
= 0xe9620000;
2801 static const uint32_t ld_2_1
= 0xe8410000;
2802 static const uint32_t ld_2_11
= 0xe84b0000;
2803 static const uint32_t ld_2_12
= 0xe84c0000;
2804 static const uint32_t ld_2_2
= 0xe8420000;
2805 static const uint32_t lfd_0_1
= 0xc8010000;
2806 static const uint32_t li_0_0
= 0x38000000;
2807 static const uint32_t li_12_0
= 0x39800000;
2808 static const uint32_t lis_0_0
= 0x3c000000;
2809 static const uint32_t lis_11
= 0x3d600000;
2810 static const uint32_t lis_12
= 0x3d800000;
2811 static const uint32_t lwz_0_12
= 0x800c0000;
2812 static const uint32_t lwz_11_11
= 0x816b0000;
2813 static const uint32_t lwz_11_30
= 0x817e0000;
2814 static const uint32_t lwz_12_12
= 0x818c0000;
2815 static const uint32_t lwzu_0_12
= 0x840c0000;
2816 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
2817 static const uint32_t mflr_0
= 0x7c0802a6;
2818 static const uint32_t mflr_11
= 0x7d6802a6;
2819 static const uint32_t mflr_12
= 0x7d8802a6;
2820 static const uint32_t mtctr_0
= 0x7c0903a6;
2821 static const uint32_t mtctr_11
= 0x7d6903a6;
2822 static const uint32_t mtctr_12
= 0x7d8903a6;
2823 static const uint32_t mtlr_0
= 0x7c0803a6;
2824 static const uint32_t mtlr_12
= 0x7d8803a6;
2825 static const uint32_t nop
= 0x60000000;
2826 static const uint32_t ori_0_0_0
= 0x60000000;
2827 static const uint32_t std_0_1
= 0xf8010000;
2828 static const uint32_t std_0_12
= 0xf80c0000;
2829 static const uint32_t std_2_1
= 0xf8410000;
2830 static const uint32_t stfd_0_1
= 0xd8010000;
2831 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
2832 static const uint32_t sub_11_11_12
= 0x7d6c5850;
2833 static const uint32_t xor_11_11_11
= 0x7d6b5a78;
2835 // Write out the PLT.
2837 template<int size
, bool big_endian
>
2839 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
2843 const section_size_type offset
= this->offset();
2844 const section_size_type oview_size
2845 = convert_to_section_size_type(this->data_size());
2846 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2847 unsigned char* pov
= oview
;
2848 unsigned char* endpov
= oview
+ oview_size
;
2850 // The address of the .glink branch table
2851 const Output_data_glink
<size
, big_endian
>* glink
2852 = this->targ_
->glink_section();
2853 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
2855 while (pov
< endpov
)
2857 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
2862 of
->write_output_view(offset
, oview_size
, oview
);
2866 // Create the PLT section.
2868 template<int size
, bool big_endian
>
2870 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
2873 if (this->plt_
== NULL
)
2875 if (this->got_
== NULL
)
2876 this->got_section(symtab
, layout
);
2878 if (this->glink_
== NULL
)
2879 make_glink_section(layout
);
2881 // Ensure that .rela.dyn always appears before .rela.plt This is
2882 // necessary due to how, on PowerPC and some other targets, .rela.dyn
2883 // needs to include .rela.plt in it's range.
2884 this->rela_dyn_section(layout
);
2886 Reloc_section
* plt_rel
= new Reloc_section(false);
2887 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
2888 elfcpp::SHF_ALLOC
, plt_rel
,
2889 ORDER_DYNAMIC_PLT_RELOCS
, false);
2891 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
2892 size
== 32 ? 0 : 24,
2894 layout
->add_output_section_data(".plt",
2896 ? elfcpp::SHT_PROGBITS
2897 : elfcpp::SHT_NOBITS
),
2898 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2907 // Create the IPLT section.
2909 template<int size
, bool big_endian
>
2911 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
2914 if (this->iplt_
== NULL
)
2916 this->make_plt_section(symtab
, layout
);
2918 Reloc_section
* iplt_rel
= new Reloc_section(false);
2919 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
2921 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
2923 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
2927 // A section for huge long branch addresses, similar to plt section.
2929 template<int size
, bool big_endian
>
2930 class Output_data_brlt_powerpc
: public Output_section_data_build
2933 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
2934 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
2935 size
, big_endian
> Reloc_section
;
2937 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
2938 Reloc_section
* brlt_rel
)
2939 : Output_section_data_build(size
== 32 ? 4 : 8),
2944 // Add a reloc for an entry in the BRLT.
2946 add_reloc(Address to
, unsigned int off
)
2947 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
2949 // Update section and reloc section size.
2951 set_current_size(unsigned int num_branches
)
2953 this->reset_address_and_file_offset();
2954 this->set_current_data_size(num_branches
* 16);
2955 this->finalize_data_size();
2956 Output_section
* os
= this->output_section();
2957 os
->set_section_offsets_need_adjustment();
2958 if (this->rel_
!= NULL
)
2960 unsigned int reloc_size
2961 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
2962 this->rel_
->reset_address_and_file_offset();
2963 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
2964 this->rel_
->finalize_data_size();
2965 Output_section
* os
= this->rel_
->output_section();
2966 os
->set_section_offsets_need_adjustment();
2972 do_adjust_output_section(Output_section
* os
)
2977 // Write to a map file.
2979 do_print_to_mapfile(Mapfile
* mapfile
) const
2980 { mapfile
->print_output_data(this, "** BRLT"); }
2983 // Write out the BRLT data.
2985 do_write(Output_file
*);
2987 // The reloc section.
2988 Reloc_section
* rel_
;
2989 Target_powerpc
<size
, big_endian
>* targ_
;
2992 // Make the branch lookup table section.
2994 template<int size
, bool big_endian
>
2996 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
2998 if (size
== 64 && this->brlt_section_
== NULL
)
3000 Reloc_section
* brlt_rel
= NULL
;
3001 bool is_pic
= parameters
->options().output_is_position_independent();
3004 // When PIC we can't fill in .brlt (like .plt it can be a
3005 // bss style section) but must initialise at runtime via
3006 // dynamic relocats.
3007 this->rela_dyn_section(layout
);
3008 brlt_rel
= new Reloc_section(false);
3009 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3012 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3013 if (this->plt_
&& is_pic
)
3014 this->plt_
->output_section()
3015 ->add_output_section_data(this->brlt_section_
);
3017 layout
->add_output_section_data(".brlt",
3018 (is_pic
? elfcpp::SHT_NOBITS
3019 : elfcpp::SHT_PROGBITS
),
3020 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3021 this->brlt_section_
,
3022 (is_pic
? ORDER_SMALL_BSS
3023 : ORDER_SMALL_DATA
),
3028 // Write out .brlt when non-PIC.
3030 template<int size
, bool big_endian
>
3032 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3034 if (size
== 64 && !parameters
->options().output_is_position_independent())
3036 const section_size_type offset
= this->offset();
3037 const section_size_type oview_size
3038 = convert_to_section_size_type(this->data_size());
3039 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3041 this->targ_
->write_branch_lookup_table(oview
);
3042 of
->write_output_view(offset
, oview_size
, oview
);
3046 static inline uint32_t
3052 static inline uint32_t
3058 static inline uint32_t
3061 return hi(a
+ 0x8000);
3067 static const unsigned char eh_frame_cie
[12];
3071 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3074 'z', 'R', 0, // Augmentation string.
3075 4, // Code alignment.
3076 0x80 - size
/ 8 , // Data alignment.
3078 1, // Augmentation size.
3079 (elfcpp::DW_EH_PE_pcrel
3080 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3081 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3084 // Describe __glink_PLTresolve use of LR, 64-bit version.
3085 static const unsigned char glink_eh_frame_fde_64
[] =
3087 0, 0, 0, 0, // Replaced with offset to .glink.
3088 0, 0, 0, 0, // Replaced with size of .glink.
3089 0, // Augmentation size.
3090 elfcpp::DW_CFA_advance_loc
+ 1,
3091 elfcpp::DW_CFA_register
, 65, 12,
3092 elfcpp::DW_CFA_advance_loc
+ 4,
3093 elfcpp::DW_CFA_restore_extended
, 65
3096 // Describe __glink_PLTresolve use of LR, 32-bit version.
3097 static const unsigned char glink_eh_frame_fde_32
[] =
3099 0, 0, 0, 0, // Replaced with offset to .glink.
3100 0, 0, 0, 0, // Replaced with size of .glink.
3101 0, // Augmentation size.
3102 elfcpp::DW_CFA_advance_loc
+ 2,
3103 elfcpp::DW_CFA_register
, 65, 0,
3104 elfcpp::DW_CFA_advance_loc
+ 4,
3105 elfcpp::DW_CFA_restore_extended
, 65
3108 static const unsigned char default_fde
[] =
3110 0, 0, 0, 0, // Replaced with offset to stubs.
3111 0, 0, 0, 0, // Replaced with size of stubs.
3112 0, // Augmentation size.
3113 elfcpp::DW_CFA_nop
, // Pad.
3118 template<bool big_endian
>
3120 write_insn(unsigned char* p
, uint32_t v
)
3122 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3125 // Stub_table holds information about plt and long branch stubs.
3126 // Stubs are built in an area following some input section determined
3127 // by group_sections(). This input section is converted to a relaxed
3128 // input section allowing it to be resized to accommodate the stubs
3130 template<int size
, bool big_endian
>
3131 class Stub_table
: public Output_relaxed_input_section
3134 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3135 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3137 Stub_table(Target_powerpc
<size
, big_endian
>* targ
)
3138 : Output_relaxed_input_section(NULL
, 0, 0),
3139 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3140 orig_data_size_(0), plt_size_(0), last_plt_size_(0),
3141 branch_size_(0), last_branch_size_(0), eh_frame_added_(false)
3144 // Delayed Output_relaxed_input_section init.
3146 init(const Output_section::Input_section
*, Output_section
*);
3148 // Add a plt call stub.
3150 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3156 add_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3161 // Find a given plt call stub.
3163 find_plt_call_entry(const Symbol
*) const;
3166 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3167 unsigned int) const;
3170 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3176 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3181 // Add a long branch stub.
3183 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*, Address
);
3186 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3192 this->plt_call_stubs_
.clear();
3193 this->plt_size_
= 0;
3194 this->long_branch_stubs_
.clear();
3195 this->branch_size_
= 0;
3199 set_address_and_size(const Output_section
* os
, Address off
)
3201 Address start_off
= off
;
3202 off
+= this->orig_data_size_
;
3203 Address my_size
= this->plt_size_
+ this->branch_size_
;
3205 off
= align_address(off
, this->stub_align());
3206 // Include original section size and alignment padding in size
3207 my_size
+= off
- start_off
;
3208 this->reset_address_and_file_offset();
3209 this->set_current_data_size(my_size
);
3210 this->set_address_and_file_offset(os
->address() + start_off
,
3211 os
->offset() + start_off
);
3216 stub_address() const
3218 return align_address(this->address() + this->orig_data_size_
,
3219 this->stub_align());
3225 return align_address(this->offset() + this->orig_data_size_
,
3226 this->stub_align());
3231 { return this->plt_size_
; }
3236 Output_section
* os
= this->output_section();
3237 if (os
->addralign() < this->stub_align())
3239 os
->set_addralign(this->stub_align());
3240 // FIXME: get rid of the insane checkpointing.
3241 // We can't increase alignment of the input section to which
3242 // stubs are attached; The input section may be .init which
3243 // is pasted together with other .init sections to form a
3244 // function. Aligning might insert zero padding resulting in
3245 // sigill. However we do need to increase alignment of the
3246 // output section so that the align_address() on offset in
3247 // set_address_and_size() adds the same padding as the
3248 // align_address() on address in stub_address().
3249 // What's more, we need this alignment for the layout done in
3250 // relaxation_loop_body() so that the output section starts at
3251 // a suitably aligned address.
3252 os
->checkpoint_set_addralign(this->stub_align());
3254 if (this->last_plt_size_
!= this->plt_size_
3255 || this->last_branch_size_
!= this->branch_size_
)
3257 this->last_plt_size_
= this->plt_size_
;
3258 this->last_branch_size_
= this->branch_size_
;
3264 // Add .eh_frame info for this stub section. Unlike other linker
3265 // generated .eh_frame this is added late in the link, because we
3266 // only want the .eh_frame info if this particular stub section is
3269 add_eh_frame(Layout
* layout
)
3271 if (!this->eh_frame_added_
)
3273 if (!parameters
->options().ld_generated_unwind_info())
3276 // Since we add stub .eh_frame info late, it must be placed
3277 // after all other linker generated .eh_frame info so that
3278 // merge mapping need not be updated for input sections.
3279 // There is no provision to use a different CIE to that used
3281 if (!this->targ_
->has_glink())
3284 layout
->add_eh_frame_for_plt(this,
3285 Eh_cie
<size
>::eh_frame_cie
,
3286 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3288 sizeof (default_fde
));
3289 this->eh_frame_added_
= true;
3293 Target_powerpc
<size
, big_endian
>*
3299 class Plt_stub_ent_hash
;
3300 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3301 Plt_stub_ent_hash
> Plt_stub_entries
;
3303 // Alignment of stub section.
3309 unsigned int min_align
= 32;
3310 unsigned int user_align
= 1 << parameters
->options().plt_align();
3311 return std::max(user_align
, min_align
);
3314 // Return the plt offset for the given call stub.
3316 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3318 const Symbol
* gsym
= p
->first
.sym_
;
3321 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3322 && gsym
->can_use_relative_reloc(false));
3323 return gsym
->plt_offset();
3328 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3329 unsigned int local_sym_index
= p
->first
.locsym_
;
3330 return relobj
->local_plt_offset(local_sym_index
);
3334 // Size of a given plt call stub.
3336 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3342 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3344 plt_addr
+= this->targ_
->iplt_section()->address();
3346 plt_addr
+= this->targ_
->plt_section()->address();
3347 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3348 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3349 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3350 got_addr
+= ppcobj
->toc_base_offset();
3351 Address off
= plt_addr
- got_addr
;
3352 bool static_chain
= parameters
->options().plt_static_chain();
3353 bool thread_safe
= this->targ_
->plt_thread_safe();
3354 unsigned int bytes
= (4 * 5
3357 + 4 * (ha(off
) != 0)
3358 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3359 unsigned int align
= 1 << parameters
->options().plt_align();
3361 bytes
= (bytes
+ align
- 1) & -align
;
3365 // Return long branch stub size.
3367 branch_stub_size(Address to
)
3370 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3371 if (to
- loc
+ (1 << 25) < 2 << 25)
3373 if (size
== 64 || !parameters
->options().output_is_position_independent())
3380 do_write(Output_file
*);
3382 // Plt call stub keys.
3386 Plt_stub_ent(const Symbol
* sym
)
3387 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3390 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3391 unsigned int locsym_index
)
3392 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3395 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3397 unsigned int r_type
,
3399 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3402 this->addend_
= addend
;
3403 else if (parameters
->options().output_is_position_independent()
3404 && r_type
== elfcpp::R_PPC_PLTREL24
)
3406 this->addend_
= addend
;
3407 if (this->addend_
>= 32768)
3408 this->object_
= object
;
3412 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3413 unsigned int locsym_index
,
3414 unsigned int r_type
,
3416 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3419 this->addend_
= addend
;
3420 else if (parameters
->options().output_is_position_independent()
3421 && r_type
== elfcpp::R_PPC_PLTREL24
)
3422 this->addend_
= addend
;
3425 bool operator==(const Plt_stub_ent
& that
) const
3427 return (this->sym_
== that
.sym_
3428 && this->object_
== that
.object_
3429 && this->addend_
== that
.addend_
3430 && this->locsym_
== that
.locsym_
);
3434 const Sized_relobj_file
<size
, big_endian
>* object_
;
3435 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
3436 unsigned int locsym_
;
3439 class Plt_stub_ent_hash
3442 size_t operator()(const Plt_stub_ent
& ent
) const
3444 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
3445 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
3451 // Long branch stub keys.
3452 class Branch_stub_ent
3455 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
, Address to
)
3456 : dest_(to
), toc_base_off_(0)
3459 toc_base_off_
= obj
->toc_base_offset();
3462 bool operator==(const Branch_stub_ent
& that
) const
3464 return (this->dest_
== that
.dest_
3466 || this->toc_base_off_
== that
.toc_base_off_
));
3470 unsigned int toc_base_off_
;
3473 class Branch_stub_ent_hash
3476 size_t operator()(const Branch_stub_ent
& ent
) const
3477 { return ent
.dest_
^ ent
.toc_base_off_
; }
3480 // In a sane world this would be a global.
3481 Target_powerpc
<size
, big_endian
>* targ_
;
3482 // Map sym/object/addend to stub offset.
3483 Plt_stub_entries plt_call_stubs_
;
3484 // Map destination address to stub offset.
3485 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
3486 Branch_stub_ent_hash
> Branch_stub_entries
;
3487 Branch_stub_entries long_branch_stubs_
;
3488 // size of input section
3489 section_size_type orig_data_size_
;
3491 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
3492 // Whether .eh_frame info has been created for this stub section.
3493 bool eh_frame_added_
;
3496 // Make a new stub table, and record.
3498 template<int size
, bool big_endian
>
3499 Stub_table
<size
, big_endian
>*
3500 Target_powerpc
<size
, big_endian
>::new_stub_table()
3502 Stub_table
<size
, big_endian
>* stub_table
3503 = new Stub_table
<size
, big_endian
>(this);
3504 this->stub_tables_
.push_back(stub_table
);
3508 // Delayed stub table initialisation, because we create the stub table
3509 // before we know to which section it will be attached.
3511 template<int size
, bool big_endian
>
3513 Stub_table
<size
, big_endian
>::init(
3514 const Output_section::Input_section
* owner
,
3515 Output_section
* output_section
)
3517 this->set_relobj(owner
->relobj());
3518 this->set_shndx(owner
->shndx());
3519 this->set_addralign(this->relobj()->section_addralign(this->shndx()));
3520 this->set_output_section(output_section
);
3521 this->orig_data_size_
= owner
->current_data_size();
3523 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3524 new_relaxed
.push_back(this);
3525 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3528 // Add a plt call stub, if we do not already have one for this
3529 // sym/object/addend combo.
3531 template<int size
, bool big_endian
>
3533 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3534 const Sized_relobj_file
<size
, big_endian
>* object
,
3536 unsigned int r_type
,
3539 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3540 Address off
= this->plt_size_
;
3541 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3542 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3544 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3547 template<int size
, bool big_endian
>
3549 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3550 const Sized_relobj_file
<size
, big_endian
>* object
,
3551 unsigned int locsym_index
,
3552 unsigned int r_type
,
3555 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3556 Address off
= this->plt_size_
;
3557 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
3558 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
3560 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
3563 // Find a plt call stub.
3565 template<int size
, bool big_endian
>
3566 typename Stub_table
<size
, big_endian
>::Address
3567 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3568 const Sized_relobj_file
<size
, big_endian
>* object
,
3570 unsigned int r_type
,
3571 Address addend
) const
3573 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
3574 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3575 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3578 template<int size
, bool big_endian
>
3579 typename Stub_table
<size
, big_endian
>::Address
3580 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
3582 Plt_stub_ent
ent(gsym
);
3583 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3584 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3587 template<int size
, bool big_endian
>
3588 typename Stub_table
<size
, big_endian
>::Address
3589 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3590 const Sized_relobj_file
<size
, big_endian
>* object
,
3591 unsigned int locsym_index
,
3592 unsigned int r_type
,
3593 Address addend
) const
3595 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
3596 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3597 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3600 template<int size
, bool big_endian
>
3601 typename Stub_table
<size
, big_endian
>::Address
3602 Stub_table
<size
, big_endian
>::find_plt_call_entry(
3603 const Sized_relobj_file
<size
, big_endian
>* object
,
3604 unsigned int locsym_index
) const
3606 Plt_stub_ent
ent(object
, locsym_index
);
3607 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
3608 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
3611 // Add a long branch stub if we don't already have one to given
3614 template<int size
, bool big_endian
>
3616 Stub_table
<size
, big_endian
>::add_long_branch_entry(
3617 const Powerpc_relobj
<size
, big_endian
>* object
,
3620 Branch_stub_ent
ent(object
, to
);
3621 Address off
= this->branch_size_
;
3622 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
3624 unsigned int stub_size
= this->branch_stub_size(to
);
3625 this->branch_size_
= off
+ stub_size
;
3626 if (size
== 64 && stub_size
!= 4)
3627 this->targ_
->add_branch_lookup_table(to
);
3631 // Find long branch stub.
3633 template<int size
, bool big_endian
>
3634 typename Stub_table
<size
, big_endian
>::Address
3635 Stub_table
<size
, big_endian
>::find_long_branch_entry(
3636 const Powerpc_relobj
<size
, big_endian
>* object
,
3639 Branch_stub_ent
ent(object
, to
);
3640 typename
Branch_stub_entries::const_iterator p
3641 = this->long_branch_stubs_
.find(ent
);
3642 return p
== this->long_branch_stubs_
.end() ? invalid_address
: p
->second
;
3645 // A class to handle .glink.
3647 template<int size
, bool big_endian
>
3648 class Output_data_glink
: public Output_section_data
3651 static const int pltresolve_size
= 16*4;
3653 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
3654 : Output_section_data(16), targ_(targ
)
3658 add_eh_frame(Layout
* layout
)
3660 if (!parameters
->options().ld_generated_unwind_info())
3664 layout
->add_eh_frame_for_plt(this,
3665 Eh_cie
<64>::eh_frame_cie
,
3666 sizeof (Eh_cie
<64>::eh_frame_cie
),
3667 glink_eh_frame_fde_64
,
3668 sizeof (glink_eh_frame_fde_64
));
3671 // 32-bit .glink can use the default since the CIE return
3672 // address reg, LR, is valid.
3673 layout
->add_eh_frame_for_plt(this,
3674 Eh_cie
<32>::eh_frame_cie
,
3675 sizeof (Eh_cie
<32>::eh_frame_cie
),
3677 sizeof (default_fde
));
3678 // Except where LR is used in a PIC __glink_PLTresolve.
3679 if (parameters
->options().output_is_position_independent())
3680 layout
->add_eh_frame_for_plt(this,
3681 Eh_cie
<32>::eh_frame_cie
,
3682 sizeof (Eh_cie
<32>::eh_frame_cie
),
3683 glink_eh_frame_fde_32
,
3684 sizeof (glink_eh_frame_fde_32
));
3689 // Write to a map file.
3691 do_print_to_mapfile(Mapfile
* mapfile
) const
3692 { mapfile
->print_output_data(this, _("** glink")); }
3696 set_final_data_size();
3700 do_write(Output_file
*);
3702 // Allows access to .got and .plt for do_write.
3703 Target_powerpc
<size
, big_endian
>* targ_
;
3706 template<int size
, bool big_endian
>
3708 Output_data_glink
<size
, big_endian
>::set_final_data_size()
3710 unsigned int count
= this->targ_
->plt_entry_count();
3711 section_size_type total
= 0;
3717 // space for branch table
3718 total
+= 4 * (count
- 1);
3720 total
+= -total
& 15;
3721 total
+= this->pltresolve_size
;
3725 total
+= this->pltresolve_size
;
3727 // space for branch table
3730 total
+= 4 * (count
- 0x8000);
3734 this->set_data_size(total
);
3737 // Write out plt and long branch stub code.
3739 template<int size
, bool big_endian
>
3741 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
3743 if (this->plt_call_stubs_
.empty()
3744 && this->long_branch_stubs_
.empty())
3747 const section_size_type start_off
= this->offset();
3748 const section_size_type off
= this->stub_offset();
3749 const section_size_type oview_size
=
3750 convert_to_section_size_type(this->data_size() - (off
- start_off
));
3751 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
3756 const Output_data_got_powerpc
<size
, big_endian
>* got
3757 = this->targ_
->got_section();
3758 Address got_os_addr
= got
->output_section()->address();
3760 if (!this->plt_call_stubs_
.empty())
3762 // The base address of the .plt section.
3763 Address plt_base
= this->targ_
->plt_section()->address();
3764 Address iplt_base
= invalid_address
;
3766 // Write out plt call stubs.
3767 typename
Plt_stub_entries::const_iterator cs
;
3768 for (cs
= this->plt_call_stubs_
.begin();
3769 cs
!= this->plt_call_stubs_
.end();
3773 Address pltoff
= this->plt_off(cs
, &is_iplt
);
3774 Address plt_addr
= pltoff
;
3777 if (iplt_base
== invalid_address
)
3778 iplt_base
= this->targ_
->iplt_section()->address();
3779 plt_addr
+= iplt_base
;
3782 plt_addr
+= plt_base
;
3783 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3784 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
3785 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
3786 Address off
= plt_addr
- got_addr
;
3788 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
3789 gold_error(_("%s: linkage table error against `%s'"),
3790 cs
->first
.object_
->name().c_str(),
3791 cs
->first
.sym_
->demangled_name().c_str());
3793 bool static_chain
= parameters
->options().plt_static_chain();
3794 bool thread_safe
= this->targ_
->plt_thread_safe();
3795 bool use_fake_dep
= false;
3796 Address cmp_branch_off
= 0;
3799 unsigned int pltindex
3800 = ((pltoff
- this->targ_
->first_plt_entry_offset())
3801 / this->targ_
->plt_entry_size());
3803 = (this->targ_
->glink_section()->pltresolve_size
3805 if (pltindex
> 32768)
3806 glinkoff
+= (pltindex
- 32768) * 4;
3808 = this->targ_
->glink_section()->address() + glinkoff
;
3810 = (this->stub_address() + cs
->second
+ 24
3811 + 4 * (ha(off
) != 0)
3812 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3813 + 4 * static_chain
);
3814 cmp_branch_off
= to
- from
;
3815 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
3818 p
= oview
+ cs
->second
;
3821 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
3822 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
)), p
+= 4;
3823 write_insn
<big_endian
>(p
, ld_11_12
+ l(off
)), p
+= 4;
3824 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3826 write_insn
<big_endian
>(p
, addi_12_12
+ l(off
)), p
+= 4;
3829 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3832 write_insn
<big_endian
>(p
, xor_11_11_11
), p
+= 4;
3833 write_insn
<big_endian
>(p
, add_12_12_11
), p
+= 4;
3835 write_insn
<big_endian
>(p
, ld_2_12
+ l(off
+ 8)), p
+= 4;
3837 write_insn
<big_endian
>(p
, ld_11_12
+ l(off
+ 16)), p
+= 4;
3841 write_insn
<big_endian
>(p
, std_2_1
+ 40), p
+= 4;
3842 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
)), p
+= 4;
3843 if (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
3845 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
)), p
+= 4;
3848 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3851 write_insn
<big_endian
>(p
, xor_11_11_11
), p
+= 4;
3852 write_insn
<big_endian
>(p
, add_2_2_11
), p
+= 4;
3855 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16)), p
+= 4;
3856 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8)), p
+= 4;
3858 if (thread_safe
&& !use_fake_dep
)
3860 write_insn
<big_endian
>(p
, cmpldi_2_0
), p
+= 4;
3861 write_insn
<big_endian
>(p
, bnectr_p4
), p
+= 4;
3862 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
3865 write_insn
<big_endian
>(p
, bctr
);
3869 // Write out long branch stubs.
3870 typename
Branch_stub_entries::const_iterator bs
;
3871 for (bs
= this->long_branch_stubs_
.begin();
3872 bs
!= this->long_branch_stubs_
.end();
3875 p
= oview
+ this->plt_size_
+ bs
->second
;
3876 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
3877 Address delta
= bs
->first
.dest_
- loc
;
3878 if (delta
+ (1 << 25) < 2 << 25)
3879 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
3883 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
3884 gold_assert(brlt_addr
!= invalid_address
);
3885 brlt_addr
+= this->targ_
->brlt_section()->address();
3886 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
3887 Address brltoff
= brlt_addr
- got_addr
;
3888 if (ha(brltoff
) == 0)
3890 write_insn
<big_endian
>(p
, ld_11_2
+ l(brltoff
)), p
+= 4;
3894 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
3895 write_insn
<big_endian
>(p
, ld_11_12
+ l(brltoff
)), p
+= 4;
3897 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
3898 write_insn
<big_endian
>(p
, bctr
);
3904 if (!this->plt_call_stubs_
.empty())
3906 // The base address of the .plt section.
3907 Address plt_base
= this->targ_
->plt_section()->address();
3908 Address iplt_base
= invalid_address
;
3909 // The address of _GLOBAL_OFFSET_TABLE_.
3910 Address g_o_t
= invalid_address
;
3912 // Write out plt call stubs.
3913 typename
Plt_stub_entries::const_iterator cs
;
3914 for (cs
= this->plt_call_stubs_
.begin();
3915 cs
!= this->plt_call_stubs_
.end();
3919 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
3922 if (iplt_base
== invalid_address
)
3923 iplt_base
= this->targ_
->iplt_section()->address();
3924 plt_addr
+= iplt_base
;
3927 plt_addr
+= plt_base
;
3929 p
= oview
+ cs
->second
;
3930 if (parameters
->options().output_is_position_independent())
3933 const Powerpc_relobj
<size
, big_endian
>* ppcobj
3934 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
3935 (cs
->first
.object_
));
3936 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
3938 unsigned int got2
= ppcobj
->got2_shndx();
3939 got_addr
= ppcobj
->get_output_section_offset(got2
);
3940 gold_assert(got_addr
!= invalid_address
);
3941 got_addr
+= (ppcobj
->output_section(got2
)->address()
3942 + cs
->first
.addend_
);
3946 if (g_o_t
== invalid_address
)
3948 const Output_data_got_powerpc
<size
, big_endian
>* got
3949 = this->targ_
->got_section();
3950 g_o_t
= got
->address() + got
->g_o_t();
3955 Address off
= plt_addr
- got_addr
;
3958 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
3959 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
3960 write_insn
<big_endian
>(p
+ 8, bctr
);
3964 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
3965 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
3966 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
3967 write_insn
<big_endian
>(p
+ 12, bctr
);
3972 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
3973 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
3974 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
3975 write_insn
<big_endian
>(p
+ 12, bctr
);
3980 // Write out long branch stubs.
3981 typename
Branch_stub_entries::const_iterator bs
;
3982 for (bs
= this->long_branch_stubs_
.begin();
3983 bs
!= this->long_branch_stubs_
.end();
3986 p
= oview
+ this->plt_size_
+ bs
->second
;
3987 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
3988 Address delta
= bs
->first
.dest_
- loc
;
3989 if (delta
+ (1 << 25) < 2 << 25)
3990 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
3991 else if (!parameters
->options().output_is_position_independent())
3993 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
3994 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
3995 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
3996 write_insn
<big_endian
>(p
+ 12, bctr
);
4001 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4002 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4003 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4004 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4005 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4006 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4007 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4008 write_insn
<big_endian
>(p
+ 28, bctr
);
4014 // Write out .glink.
4016 template<int size
, bool big_endian
>
4018 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4020 const section_size_type off
= this->offset();
4021 const section_size_type oview_size
=
4022 convert_to_section_size_type(this->data_size());
4023 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4026 // The base address of the .plt section.
4027 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4028 Address plt_base
= this->targ_
->plt_section()->address();
4032 // Write pltresolve stub.
4034 Address after_bcl
= this->address() + 16;
4035 Address pltoff
= plt_base
- after_bcl
;
4037 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4039 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4040 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4041 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4042 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4043 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4044 write_insn
<big_endian
>(p
, add_12_2_11
), p
+= 4;
4045 write_insn
<big_endian
>(p
, ld_11_12
+ 0), p
+= 4;
4046 write_insn
<big_endian
>(p
, ld_2_12
+ 8), p
+= 4;
4047 write_insn
<big_endian
>(p
, mtctr_11
), p
+= 4;
4048 write_insn
<big_endian
>(p
, ld_11_12
+ 16), p
+= 4;
4049 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4050 while (p
< oview
+ this->pltresolve_size
)
4051 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4053 // Write lazy link call stubs.
4055 while (p
< oview
+ oview_size
)
4059 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4063 write_insn
<big_endian
>(p
, lis_0_0
+ hi(indx
)), p
+= 4;
4064 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4066 uint32_t branch_off
= 8 - (p
- oview
);
4067 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4073 const Output_data_got_powerpc
<size
, big_endian
>* got
4074 = this->targ_
->got_section();
4075 // The address of _GLOBAL_OFFSET_TABLE_.
4076 Address g_o_t
= got
->address() + got
->g_o_t();
4078 // Write out pltresolve branch table.
4080 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4081 unsigned char* end_p
= oview
+ the_end
;
4082 while (p
< end_p
- 8 * 4)
4083 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4085 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4087 // Write out pltresolve call stub.
4088 if (parameters
->options().output_is_position_independent())
4090 Address res0_off
= 0;
4091 Address after_bcl_off
= the_end
+ 12;
4092 Address bcl_res0
= after_bcl_off
- res0_off
;
4094 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4095 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4096 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4097 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4098 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4099 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4100 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4102 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4104 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4105 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4107 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4108 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4112 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4113 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4115 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4116 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4117 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4118 write_insn
<big_endian
>(p
+ 52, bctr
);
4119 write_insn
<big_endian
>(p
+ 56, nop
);
4120 write_insn
<big_endian
>(p
+ 60, nop
);
4124 Address res0
= this->address();
4126 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4127 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4128 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4129 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4131 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4132 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4133 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4134 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4135 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4136 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4138 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4139 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4140 write_insn
<big_endian
>(p
+ 32, bctr
);
4141 write_insn
<big_endian
>(p
+ 36, nop
);
4142 write_insn
<big_endian
>(p
+ 40, nop
);
4143 write_insn
<big_endian
>(p
+ 44, nop
);
4144 write_insn
<big_endian
>(p
+ 48, nop
);
4145 write_insn
<big_endian
>(p
+ 52, nop
);
4146 write_insn
<big_endian
>(p
+ 56, nop
);
4147 write_insn
<big_endian
>(p
+ 60, nop
);
4152 of
->write_output_view(off
, oview_size
, oview
);
4156 // A class to handle linker generated save/restore functions.
4158 template<int size
, bool big_endian
>
4159 class Output_data_save_res
: public Output_section_data_build
4162 Output_data_save_res(Symbol_table
* symtab
);
4165 // Write to a map file.
4167 do_print_to_mapfile(Mapfile
* mapfile
) const
4168 { mapfile
->print_output_data(this, _("** save/restore")); }
4171 do_write(Output_file
*);
4174 // The maximum size of save/restore contents.
4175 static const unsigned int savres_max
= 218*4;
4178 savres_define(Symbol_table
* symtab
,
4180 unsigned int lo
, unsigned int hi
,
4181 unsigned char* write_ent(unsigned char*, int),
4182 unsigned char* write_tail(unsigned char*, int));
4184 unsigned char *contents_
;
4187 template<bool big_endian
>
4188 static unsigned char*
4189 savegpr0(unsigned char* p
, int r
)
4191 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4192 write_insn
<big_endian
>(p
, insn
);
4196 template<bool big_endian
>
4197 static unsigned char*
4198 savegpr0_tail(unsigned char* p
, int r
)
4200 p
= savegpr0
<big_endian
>(p
, r
);
4201 uint32_t insn
= std_0_1
+ 16;
4202 write_insn
<big_endian
>(p
, insn
);
4204 write_insn
<big_endian
>(p
, blr
);
4208 template<bool big_endian
>
4209 static unsigned char*
4210 restgpr0(unsigned char* p
, int r
)
4212 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4213 write_insn
<big_endian
>(p
, insn
);
4217 template<bool big_endian
>
4218 static unsigned char*
4219 restgpr0_tail(unsigned char* p
, int r
)
4221 uint32_t insn
= ld_0_1
+ 16;
4222 write_insn
<big_endian
>(p
, insn
);
4224 p
= restgpr0
<big_endian
>(p
, r
);
4225 write_insn
<big_endian
>(p
, mtlr_0
);
4229 p
= restgpr0
<big_endian
>(p
, 30);
4230 p
= restgpr0
<big_endian
>(p
, 31);
4232 write_insn
<big_endian
>(p
, blr
);
4236 template<bool big_endian
>
4237 static unsigned char*
4238 savegpr1(unsigned char* p
, int r
)
4240 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4241 write_insn
<big_endian
>(p
, insn
);
4245 template<bool big_endian
>
4246 static unsigned char*
4247 savegpr1_tail(unsigned char* p
, int r
)
4249 p
= savegpr1
<big_endian
>(p
, r
);
4250 write_insn
<big_endian
>(p
, blr
);
4254 template<bool big_endian
>
4255 static unsigned char*
4256 restgpr1(unsigned char* p
, int r
)
4258 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4259 write_insn
<big_endian
>(p
, insn
);
4263 template<bool big_endian
>
4264 static unsigned char*
4265 restgpr1_tail(unsigned char* p
, int r
)
4267 p
= restgpr1
<big_endian
>(p
, r
);
4268 write_insn
<big_endian
>(p
, blr
);
4272 template<bool big_endian
>
4273 static unsigned char*
4274 savefpr(unsigned char* p
, int r
)
4276 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4277 write_insn
<big_endian
>(p
, insn
);
4281 template<bool big_endian
>
4282 static unsigned char*
4283 savefpr0_tail(unsigned char* p
, int r
)
4285 p
= savefpr
<big_endian
>(p
, r
);
4286 write_insn
<big_endian
>(p
, std_0_1
+ 16);
4288 write_insn
<big_endian
>(p
, blr
);
4292 template<bool big_endian
>
4293 static unsigned char*
4294 restfpr(unsigned char* p
, int r
)
4296 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4297 write_insn
<big_endian
>(p
, insn
);
4301 template<bool big_endian
>
4302 static unsigned char*
4303 restfpr0_tail(unsigned char* p
, int r
)
4305 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
4307 p
= restfpr
<big_endian
>(p
, r
);
4308 write_insn
<big_endian
>(p
, mtlr_0
);
4312 p
= restfpr
<big_endian
>(p
, 30);
4313 p
= restfpr
<big_endian
>(p
, 31);
4315 write_insn
<big_endian
>(p
, blr
);
4319 template<bool big_endian
>
4320 static unsigned char*
4321 savefpr1_tail(unsigned char* p
, int r
)
4323 p
= savefpr
<big_endian
>(p
, r
);
4324 write_insn
<big_endian
>(p
, blr
);
4328 template<bool big_endian
>
4329 static unsigned char*
4330 restfpr1_tail(unsigned char* p
, int r
)
4332 p
= restfpr
<big_endian
>(p
, r
);
4333 write_insn
<big_endian
>(p
, blr
);
4337 template<bool big_endian
>
4338 static unsigned char*
4339 savevr(unsigned char* p
, int r
)
4341 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4342 write_insn
<big_endian
>(p
, insn
);
4344 insn
= stvx_0_12_0
+ (r
<< 21);
4345 write_insn
<big_endian
>(p
, insn
);
4349 template<bool big_endian
>
4350 static unsigned char*
4351 savevr_tail(unsigned char* p
, int r
)
4353 p
= savevr
<big_endian
>(p
, r
);
4354 write_insn
<big_endian
>(p
, blr
);
4358 template<bool big_endian
>
4359 static unsigned char*
4360 restvr(unsigned char* p
, int r
)
4362 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4363 write_insn
<big_endian
>(p
, insn
);
4365 insn
= lvx_0_12_0
+ (r
<< 21);
4366 write_insn
<big_endian
>(p
, insn
);
4370 template<bool big_endian
>
4371 static unsigned char*
4372 restvr_tail(unsigned char* p
, int r
)
4374 p
= restvr
<big_endian
>(p
, r
);
4375 write_insn
<big_endian
>(p
, blr
);
4380 template<int size
, bool big_endian
>
4381 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
4382 Symbol_table
* symtab
)
4383 : Output_section_data_build(4),
4386 this->savres_define(symtab
,
4387 "_savegpr0_", 14, 31,
4388 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
4389 this->savres_define(symtab
,
4390 "_restgpr0_", 14, 29,
4391 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4392 this->savres_define(symtab
,
4393 "_restgpr0_", 30, 31,
4394 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
4395 this->savres_define(symtab
,
4396 "_savegpr1_", 14, 31,
4397 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
4398 this->savres_define(symtab
,
4399 "_restgpr1_", 14, 31,
4400 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
4401 this->savres_define(symtab
,
4402 "_savefpr_", 14, 31,
4403 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
4404 this->savres_define(symtab
,
4405 "_restfpr_", 14, 29,
4406 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
4407 this->savres_define(symtab
,
4408 "_restfpr_", 30, 31,
4409 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
4410 this->savres_define(symtab
,
4412 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
4413 this->savres_define(symtab
,
4415 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
4416 this->savres_define(symtab
,
4418 savevr
<big_endian
>, savevr_tail
<big_endian
>);
4419 this->savres_define(symtab
,
4421 restvr
<big_endian
>, restvr_tail
<big_endian
>);
4424 template<int size
, bool big_endian
>
4426 Output_data_save_res
<size
, big_endian
>::savres_define(
4427 Symbol_table
* symtab
,
4429 unsigned int lo
, unsigned int hi
,
4430 unsigned char* write_ent(unsigned char*, int),
4431 unsigned char* write_tail(unsigned char*, int))
4433 size_t len
= strlen(name
);
4434 bool writing
= false;
4437 memcpy(sym
, name
, len
);
4440 for (unsigned int i
= lo
; i
<= hi
; i
++)
4442 sym
[len
+ 0] = i
/ 10 + '0';
4443 sym
[len
+ 1] = i
% 10 + '0';
4444 Symbol
* gsym
= symtab
->lookup(sym
);
4445 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
4446 writing
= writing
|| refd
;
4449 if (this->contents_
== NULL
)
4450 this->contents_
= new unsigned char[this->savres_max
];
4452 section_size_type value
= this->current_data_size();
4453 unsigned char* p
= this->contents_
+ value
;
4455 p
= write_ent(p
, i
);
4457 p
= write_tail(p
, i
);
4458 section_size_type cur_size
= p
- this->contents_
;
4459 this->set_current_data_size(cur_size
);
4461 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
4462 this, value
, cur_size
- value
,
4463 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
4464 elfcpp::STV_HIDDEN
, 0, false, false);
4469 // Write out save/restore.
4471 template<int size
, bool big_endian
>
4473 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
4475 const section_size_type off
= this->offset();
4476 const section_size_type oview_size
=
4477 convert_to_section_size_type(this->data_size());
4478 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4479 memcpy(oview
, this->contents_
, oview_size
);
4480 of
->write_output_view(off
, oview_size
, oview
);
4484 // Create the glink section.
4486 template<int size
, bool big_endian
>
4488 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
4490 if (this->glink_
== NULL
)
4492 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
4493 this->glink_
->add_eh_frame(layout
);
4494 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
4495 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
4496 this->glink_
, ORDER_TEXT
, false);
4500 // Create a PLT entry for a global symbol.
4502 template<int size
, bool big_endian
>
4504 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
4508 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
4509 && gsym
->can_use_relative_reloc(false))
4511 if (this->iplt_
== NULL
)
4512 this->make_iplt_section(symtab
, layout
);
4513 this->iplt_
->add_ifunc_entry(gsym
);
4517 if (this->plt_
== NULL
)
4518 this->make_plt_section(symtab
, layout
);
4519 this->plt_
->add_entry(gsym
);
4523 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
4525 template<int size
, bool big_endian
>
4527 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
4528 Symbol_table
* symtab
,
4530 Sized_relobj_file
<size
, big_endian
>* relobj
,
4533 if (this->iplt_
== NULL
)
4534 this->make_iplt_section(symtab
, layout
);
4535 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
4538 // Return the number of entries in the PLT.
4540 template<int size
, bool big_endian
>
4542 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
4544 if (this->plt_
== NULL
)
4546 unsigned int count
= this->plt_
->entry_count();
4547 if (this->iplt_
!= NULL
)
4548 count
+= this->iplt_
->entry_count();
4552 // Return the offset of the first non-reserved PLT entry.
4554 template<int size
, bool big_endian
>
4556 Target_powerpc
<size
, big_endian
>::first_plt_entry_offset() const
4558 return this->plt_
->first_plt_entry_offset();
4561 // Return the size of each PLT entry.
4563 template<int size
, bool big_endian
>
4565 Target_powerpc
<size
, big_endian
>::plt_entry_size() const
4567 return Output_data_plt_powerpc
<size
, big_endian
>::get_plt_entry_size();
4570 // Create a GOT entry for local dynamic __tls_get_addr calls.
4572 template<int size
, bool big_endian
>
4574 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
4575 Symbol_table
* symtab
,
4577 Sized_relobj_file
<size
, big_endian
>* object
)
4579 if (this->tlsld_got_offset_
== -1U)
4581 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
4582 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
4583 Output_data_got_powerpc
<size
, big_endian
>* got
4584 = this->got_section(symtab
, layout
);
4585 unsigned int got_offset
= got
->add_constant_pair(0, 0);
4586 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
4588 this->tlsld_got_offset_
= got_offset
;
4590 return this->tlsld_got_offset_
;
4593 // Get the Reference_flags for a particular relocation.
4595 template<int size
, bool big_endian
>
4597 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
4601 case elfcpp::R_POWERPC_NONE
:
4602 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4603 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4604 case elfcpp::R_PPC64_TOC
:
4605 // No symbol reference.
4608 case elfcpp::R_PPC64_ADDR64
:
4609 case elfcpp::R_PPC64_UADDR64
:
4610 case elfcpp::R_POWERPC_ADDR32
:
4611 case elfcpp::R_POWERPC_UADDR32
:
4612 case elfcpp::R_POWERPC_ADDR16
:
4613 case elfcpp::R_POWERPC_UADDR16
:
4614 case elfcpp::R_POWERPC_ADDR16_LO
:
4615 case elfcpp::R_POWERPC_ADDR16_HI
:
4616 case elfcpp::R_POWERPC_ADDR16_HA
:
4617 return Symbol::ABSOLUTE_REF
;
4619 case elfcpp::R_POWERPC_ADDR24
:
4620 case elfcpp::R_POWERPC_ADDR14
:
4621 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4622 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4623 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
4625 case elfcpp::R_PPC64_REL64
:
4626 case elfcpp::R_POWERPC_REL32
:
4627 case elfcpp::R_PPC_LOCAL24PC
:
4628 case elfcpp::R_POWERPC_REL16
:
4629 case elfcpp::R_POWERPC_REL16_LO
:
4630 case elfcpp::R_POWERPC_REL16_HI
:
4631 case elfcpp::R_POWERPC_REL16_HA
:
4632 return Symbol::RELATIVE_REF
;
4634 case elfcpp::R_POWERPC_REL24
:
4635 case elfcpp::R_PPC_PLTREL24
:
4636 case elfcpp::R_POWERPC_REL14
:
4637 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4638 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4639 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
4641 case elfcpp::R_POWERPC_GOT16
:
4642 case elfcpp::R_POWERPC_GOT16_LO
:
4643 case elfcpp::R_POWERPC_GOT16_HI
:
4644 case elfcpp::R_POWERPC_GOT16_HA
:
4645 case elfcpp::R_PPC64_GOT16_DS
:
4646 case elfcpp::R_PPC64_GOT16_LO_DS
:
4647 case elfcpp::R_PPC64_TOC16
:
4648 case elfcpp::R_PPC64_TOC16_LO
:
4649 case elfcpp::R_PPC64_TOC16_HI
:
4650 case elfcpp::R_PPC64_TOC16_HA
:
4651 case elfcpp::R_PPC64_TOC16_DS
:
4652 case elfcpp::R_PPC64_TOC16_LO_DS
:
4654 return Symbol::ABSOLUTE_REF
;
4656 case elfcpp::R_POWERPC_GOT_TPREL16
:
4657 case elfcpp::R_POWERPC_TLS
:
4658 return Symbol::TLS_REF
;
4660 case elfcpp::R_POWERPC_COPY
:
4661 case elfcpp::R_POWERPC_GLOB_DAT
:
4662 case elfcpp::R_POWERPC_JMP_SLOT
:
4663 case elfcpp::R_POWERPC_RELATIVE
:
4664 case elfcpp::R_POWERPC_DTPMOD
:
4666 // Not expected. We will give an error later.
4671 // Report an unsupported relocation against a local symbol.
4673 template<int size
, bool big_endian
>
4675 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
4676 Sized_relobj_file
<size
, big_endian
>* object
,
4677 unsigned int r_type
)
4679 gold_error(_("%s: unsupported reloc %u against local symbol"),
4680 object
->name().c_str(), r_type
);
4683 // We are about to emit a dynamic relocation of type R_TYPE. If the
4684 // dynamic linker does not support it, issue an error.
4686 template<int size
, bool big_endian
>
4688 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
4689 unsigned int r_type
)
4691 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
4693 // These are the relocation types supported by glibc for both 32-bit
4694 // and 64-bit powerpc.
4697 case elfcpp::R_POWERPC_NONE
:
4698 case elfcpp::R_POWERPC_RELATIVE
:
4699 case elfcpp::R_POWERPC_GLOB_DAT
:
4700 case elfcpp::R_POWERPC_DTPMOD
:
4701 case elfcpp::R_POWERPC_DTPREL
:
4702 case elfcpp::R_POWERPC_TPREL
:
4703 case elfcpp::R_POWERPC_JMP_SLOT
:
4704 case elfcpp::R_POWERPC_COPY
:
4705 case elfcpp::R_POWERPC_IRELATIVE
:
4706 case elfcpp::R_POWERPC_ADDR32
:
4707 case elfcpp::R_POWERPC_UADDR32
:
4708 case elfcpp::R_POWERPC_ADDR24
:
4709 case elfcpp::R_POWERPC_ADDR16
:
4710 case elfcpp::R_POWERPC_UADDR16
:
4711 case elfcpp::R_POWERPC_ADDR16_LO
:
4712 case elfcpp::R_POWERPC_ADDR16_HI
:
4713 case elfcpp::R_POWERPC_ADDR16_HA
:
4714 case elfcpp::R_POWERPC_ADDR14
:
4715 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4716 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4717 case elfcpp::R_POWERPC_REL32
:
4718 case elfcpp::R_POWERPC_REL24
:
4719 case elfcpp::R_POWERPC_TPREL16
:
4720 case elfcpp::R_POWERPC_TPREL16_LO
:
4721 case elfcpp::R_POWERPC_TPREL16_HI
:
4722 case elfcpp::R_POWERPC_TPREL16_HA
:
4733 // These are the relocation types supported only on 64-bit.
4734 case elfcpp::R_PPC64_ADDR64
:
4735 case elfcpp::R_PPC64_UADDR64
:
4736 case elfcpp::R_PPC64_JMP_IREL
:
4737 case elfcpp::R_PPC64_ADDR16_DS
:
4738 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4739 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4740 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4741 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4742 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4743 case elfcpp::R_PPC64_REL64
:
4744 case elfcpp::R_POWERPC_ADDR30
:
4745 case elfcpp::R_PPC64_TPREL16_DS
:
4746 case elfcpp::R_PPC64_TPREL16_LO_DS
:
4747 case elfcpp::R_PPC64_TPREL16_HIGHER
:
4748 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
4749 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
4750 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
4761 // These are the relocation types supported only on 32-bit.
4762 // ??? glibc ld.so doesn't need to support these.
4763 case elfcpp::R_POWERPC_DTPREL16
:
4764 case elfcpp::R_POWERPC_DTPREL16_LO
:
4765 case elfcpp::R_POWERPC_DTPREL16_HI
:
4766 case elfcpp::R_POWERPC_DTPREL16_HA
:
4774 // This prevents us from issuing more than one error per reloc
4775 // section. But we can still wind up issuing more than one
4776 // error per object file.
4777 if (this->issued_non_pic_error_
)
4779 gold_assert(parameters
->options().output_is_position_independent());
4780 object
->error(_("requires unsupported dynamic reloc; "
4781 "recompile with -fPIC"));
4782 this->issued_non_pic_error_
= true;
4786 // Return whether we need to make a PLT entry for a relocation of the
4787 // given type against a STT_GNU_IFUNC symbol.
4789 template<int size
, bool big_endian
>
4791 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
4792 Sized_relobj_file
<size
, big_endian
>* object
,
4793 unsigned int r_type
)
4795 // In non-pic code any reference will resolve to the plt call stub
4796 // for the ifunc symbol.
4797 if (size
== 32 && !parameters
->options().output_is_position_independent())
4802 // Word size refs from data sections are OK.
4803 case elfcpp::R_POWERPC_ADDR32
:
4804 case elfcpp::R_POWERPC_UADDR32
:
4809 case elfcpp::R_PPC64_ADDR64
:
4810 case elfcpp::R_PPC64_UADDR64
:
4815 // GOT refs are good.
4816 case elfcpp::R_POWERPC_GOT16
:
4817 case elfcpp::R_POWERPC_GOT16_LO
:
4818 case elfcpp::R_POWERPC_GOT16_HI
:
4819 case elfcpp::R_POWERPC_GOT16_HA
:
4820 case elfcpp::R_PPC64_GOT16_DS
:
4821 case elfcpp::R_PPC64_GOT16_LO_DS
:
4824 // So are function calls.
4825 case elfcpp::R_POWERPC_ADDR24
:
4826 case elfcpp::R_POWERPC_ADDR14
:
4827 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4828 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4829 case elfcpp::R_POWERPC_REL24
:
4830 case elfcpp::R_PPC_PLTREL24
:
4831 case elfcpp::R_POWERPC_REL14
:
4832 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
4833 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
4840 // Anything else is a problem.
4841 // If we are building a static executable, the libc startup function
4842 // responsible for applying indirect function relocations is going
4843 // to complain about the reloc type.
4844 // If we are building a dynamic executable, we will have a text
4845 // relocation. The dynamic loader will set the text segment
4846 // writable and non-executable to apply text relocations. So we'll
4847 // segfault when trying to run the indirection function to resolve
4849 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
4850 object
->name().c_str(), r_type
);
4854 // Scan a relocation for a local symbol.
4856 template<int size
, bool big_endian
>
4858 Target_powerpc
<size
, big_endian
>::Scan::local(
4859 Symbol_table
* symtab
,
4861 Target_powerpc
<size
, big_endian
>* target
,
4862 Sized_relobj_file
<size
, big_endian
>* object
,
4863 unsigned int data_shndx
,
4864 Output_section
* output_section
,
4865 const elfcpp::Rela
<size
, big_endian
>& reloc
,
4866 unsigned int r_type
,
4867 const elfcpp::Sym
<size
, big_endian
>& lsym
,
4870 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
4872 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
4873 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
4875 this->expect_tls_get_addr_call();
4876 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
4877 if (tls_type
!= tls::TLSOPT_NONE
)
4878 this->skip_next_tls_get_addr_call();
4880 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
4881 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
4883 this->expect_tls_get_addr_call();
4884 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
4885 if (tls_type
!= tls::TLSOPT_NONE
)
4886 this->skip_next_tls_get_addr_call();
4889 Powerpc_relobj
<size
, big_endian
>* ppc_object
4890 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
4895 && data_shndx
== ppc_object
->opd_shndx()
4896 && r_type
== elfcpp::R_PPC64_ADDR64
)
4897 ppc_object
->set_opd_discard(reloc
.get_r_offset());
4901 // A local STT_GNU_IFUNC symbol may require a PLT entry.
4902 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
4903 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
4905 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4906 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
4907 r_type
, r_sym
, reloc
.get_r_addend());
4908 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
4913 case elfcpp::R_POWERPC_NONE
:
4914 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
4915 case elfcpp::R_POWERPC_GNU_VTENTRY
:
4916 case elfcpp::R_PPC64_TOCSAVE
:
4917 case elfcpp::R_PPC_EMB_MRKREF
:
4918 case elfcpp::R_POWERPC_TLS
:
4921 case elfcpp::R_PPC64_TOC
:
4923 Output_data_got_powerpc
<size
, big_endian
>* got
4924 = target
->got_section(symtab
, layout
);
4925 if (parameters
->options().output_is_position_independent())
4927 Address off
= reloc
.get_r_offset();
4929 && data_shndx
== ppc_object
->opd_shndx()
4930 && ppc_object
->get_opd_discard(off
- 8))
4933 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4934 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
4935 rela_dyn
->add_output_section_relative(got
->output_section(),
4936 elfcpp::R_POWERPC_RELATIVE
,
4938 object
, data_shndx
, off
,
4939 symobj
->toc_base_offset());
4944 case elfcpp::R_PPC64_ADDR64
:
4945 case elfcpp::R_PPC64_UADDR64
:
4946 case elfcpp::R_POWERPC_ADDR32
:
4947 case elfcpp::R_POWERPC_UADDR32
:
4948 case elfcpp::R_POWERPC_ADDR24
:
4949 case elfcpp::R_POWERPC_ADDR16
:
4950 case elfcpp::R_POWERPC_ADDR16_LO
:
4951 case elfcpp::R_POWERPC_ADDR16_HI
:
4952 case elfcpp::R_POWERPC_ADDR16_HA
:
4953 case elfcpp::R_POWERPC_UADDR16
:
4954 case elfcpp::R_PPC64_ADDR16_HIGHER
:
4955 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
4956 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
4957 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
4958 case elfcpp::R_PPC64_ADDR16_DS
:
4959 case elfcpp::R_PPC64_ADDR16_LO_DS
:
4960 case elfcpp::R_POWERPC_ADDR14
:
4961 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
4962 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
4963 // If building a shared library (or a position-independent
4964 // executable), we need to create a dynamic relocation for
4966 if (parameters
->options().output_is_position_independent()
4967 || (size
== 64 && is_ifunc
))
4969 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
4971 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
4972 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
4974 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4975 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
4978 rela_dyn
= target
->iplt_section()->rel_plt();
4979 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
4981 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
4982 output_section
, data_shndx
,
4983 reloc
.get_r_offset(),
4984 reloc
.get_r_addend(), false);
4988 check_non_pic(object
, r_type
);
4989 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
4990 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
4991 data_shndx
, reloc
.get_r_offset(),
4992 reloc
.get_r_addend());
4997 case elfcpp::R_POWERPC_REL24
:
4998 case elfcpp::R_PPC_PLTREL24
:
4999 case elfcpp::R_PPC_LOCAL24PC
:
5000 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5001 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5002 reloc
.get_r_addend());
5005 case elfcpp::R_POWERPC_REL14
:
5006 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5007 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5008 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5009 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5010 reloc
.get_r_addend());
5013 case elfcpp::R_PPC64_REL64
:
5014 case elfcpp::R_POWERPC_REL32
:
5015 case elfcpp::R_POWERPC_REL16
:
5016 case elfcpp::R_POWERPC_REL16_LO
:
5017 case elfcpp::R_POWERPC_REL16_HI
:
5018 case elfcpp::R_POWERPC_REL16_HA
:
5019 case elfcpp::R_POWERPC_SECTOFF
:
5020 case elfcpp::R_POWERPC_TPREL16
:
5021 case elfcpp::R_POWERPC_DTPREL16
:
5022 case elfcpp::R_POWERPC_SECTOFF_LO
:
5023 case elfcpp::R_POWERPC_TPREL16_LO
:
5024 case elfcpp::R_POWERPC_DTPREL16_LO
:
5025 case elfcpp::R_POWERPC_SECTOFF_HI
:
5026 case elfcpp::R_POWERPC_TPREL16_HI
:
5027 case elfcpp::R_POWERPC_DTPREL16_HI
:
5028 case elfcpp::R_POWERPC_SECTOFF_HA
:
5029 case elfcpp::R_POWERPC_TPREL16_HA
:
5030 case elfcpp::R_POWERPC_DTPREL16_HA
:
5031 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5032 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5033 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5034 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5035 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5036 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5037 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5038 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5039 case elfcpp::R_PPC64_TPREL16_DS
:
5040 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5041 case elfcpp::R_PPC64_DTPREL16_DS
:
5042 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5043 case elfcpp::R_PPC64_SECTOFF_DS
:
5044 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5045 case elfcpp::R_PPC64_TLSGD
:
5046 case elfcpp::R_PPC64_TLSLD
:
5049 case elfcpp::R_POWERPC_GOT16
:
5050 case elfcpp::R_POWERPC_GOT16_LO
:
5051 case elfcpp::R_POWERPC_GOT16_HI
:
5052 case elfcpp::R_POWERPC_GOT16_HA
:
5053 case elfcpp::R_PPC64_GOT16_DS
:
5054 case elfcpp::R_PPC64_GOT16_LO_DS
:
5056 // The symbol requires a GOT entry.
5057 Output_data_got_powerpc
<size
, big_endian
>* got
5058 = target
->got_section(symtab
, layout
);
5059 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5061 if (!parameters
->options().output_is_position_independent())
5063 if (size
== 32 && is_ifunc
)
5064 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5066 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5068 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5070 // If we are generating a shared object or a pie, this
5071 // symbol's GOT entry will be set by a dynamic relocation.
5073 off
= got
->add_constant(0);
5074 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5076 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5077 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
5080 rela_dyn
= target
->iplt_section()->rel_plt();
5081 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
5083 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5084 got
, off
, 0, false);
5089 case elfcpp::R_PPC64_TOC16
:
5090 case elfcpp::R_PPC64_TOC16_LO
:
5091 case elfcpp::R_PPC64_TOC16_HI
:
5092 case elfcpp::R_PPC64_TOC16_HA
:
5093 case elfcpp::R_PPC64_TOC16_DS
:
5094 case elfcpp::R_PPC64_TOC16_LO_DS
:
5095 // We need a GOT section.
5096 target
->got_section(symtab
, layout
);
5099 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5100 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5101 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5102 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5104 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5105 if (tls_type
== tls::TLSOPT_NONE
)
5107 Output_data_got_powerpc
<size
, big_endian
>* got
5108 = target
->got_section(symtab
, layout
);
5109 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5110 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5111 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5112 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5114 else if (tls_type
== tls::TLSOPT_TO_LE
)
5116 // no GOT relocs needed for Local Exec.
5123 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5124 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5125 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5126 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5128 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5129 if (tls_type
== tls::TLSOPT_NONE
)
5130 target
->tlsld_got_offset(symtab
, layout
, object
);
5131 else if (tls_type
== tls::TLSOPT_TO_LE
)
5133 // no GOT relocs needed for Local Exec.
5134 if (parameters
->options().emit_relocs())
5136 Output_section
* os
= layout
->tls_segment()->first_section();
5137 gold_assert(os
!= NULL
);
5138 os
->set_needs_symtab_index();
5146 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5147 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5148 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5149 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5151 Output_data_got_powerpc
<size
, big_endian
>* got
5152 = target
->got_section(symtab
, layout
);
5153 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5154 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5158 case elfcpp::R_POWERPC_GOT_TPREL16
:
5159 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5160 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5161 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5163 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5164 if (tls_type
== tls::TLSOPT_NONE
)
5166 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5167 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5169 Output_data_got_powerpc
<size
, big_endian
>* got
5170 = target
->got_section(symtab
, layout
);
5171 unsigned int off
= got
->add_constant(0);
5172 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5174 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5175 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5176 elfcpp::R_POWERPC_TPREL
,
5180 else if (tls_type
== tls::TLSOPT_TO_LE
)
5182 // no GOT relocs needed for Local Exec.
5190 unsupported_reloc_local(object
, r_type
);
5196 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5197 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5198 case elfcpp::R_POWERPC_GOT_TPREL16
:
5199 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5200 case elfcpp::R_POWERPC_GOT16
:
5201 case elfcpp::R_PPC64_GOT16_DS
:
5202 case elfcpp::R_PPC64_TOC16
:
5203 case elfcpp::R_PPC64_TOC16_DS
:
5204 ppc_object
->set_has_small_toc_reloc();
5210 // Report an unsupported relocation against a global symbol.
5212 template<int size
, bool big_endian
>
5214 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5215 Sized_relobj_file
<size
, big_endian
>* object
,
5216 unsigned int r_type
,
5219 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5220 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
5223 // Scan a relocation for a global symbol.
5225 template<int size
, bool big_endian
>
5227 Target_powerpc
<size
, big_endian
>::Scan::global(
5228 Symbol_table
* symtab
,
5230 Target_powerpc
<size
, big_endian
>* target
,
5231 Sized_relobj_file
<size
, big_endian
>* object
,
5232 unsigned int data_shndx
,
5233 Output_section
* output_section
,
5234 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5235 unsigned int r_type
,
5238 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
5241 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5242 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5244 this->expect_tls_get_addr_call();
5245 const bool final
= gsym
->final_value_is_known();
5246 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5247 if (tls_type
!= tls::TLSOPT_NONE
)
5248 this->skip_next_tls_get_addr_call();
5250 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5251 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5253 this->expect_tls_get_addr_call();
5254 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5255 if (tls_type
!= tls::TLSOPT_NONE
)
5256 this->skip_next_tls_get_addr_call();
5259 Powerpc_relobj
<size
, big_endian
>* ppc_object
5260 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5262 // A STT_GNU_IFUNC symbol may require a PLT entry.
5263 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5264 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
5266 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5267 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5268 reloc
.get_r_addend());
5269 target
->make_plt_entry(symtab
, layout
, gsym
);
5274 case elfcpp::R_POWERPC_NONE
:
5275 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5276 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5277 case elfcpp::R_PPC_LOCAL24PC
:
5278 case elfcpp::R_PPC_EMB_MRKREF
:
5279 case elfcpp::R_POWERPC_TLS
:
5282 case elfcpp::R_PPC64_TOC
:
5284 Output_data_got_powerpc
<size
, big_endian
>* got
5285 = target
->got_section(symtab
, layout
);
5286 if (parameters
->options().output_is_position_independent())
5288 Address off
= reloc
.get_r_offset();
5290 && data_shndx
== ppc_object
->opd_shndx()
5291 && ppc_object
->get_opd_discard(off
- 8))
5294 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5295 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5296 if (data_shndx
!= ppc_object
->opd_shndx())
5297 symobj
= static_cast
5298 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
5299 rela_dyn
->add_output_section_relative(got
->output_section(),
5300 elfcpp::R_POWERPC_RELATIVE
,
5302 object
, data_shndx
, off
,
5303 symobj
->toc_base_offset());
5308 case elfcpp::R_PPC64_ADDR64
:
5310 && data_shndx
== ppc_object
->opd_shndx()
5311 && (gsym
->is_defined_in_discarded_section()
5312 || gsym
->object() != object
))
5314 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5318 case elfcpp::R_PPC64_UADDR64
:
5319 case elfcpp::R_POWERPC_ADDR32
:
5320 case elfcpp::R_POWERPC_UADDR32
:
5321 case elfcpp::R_POWERPC_ADDR24
:
5322 case elfcpp::R_POWERPC_ADDR16
:
5323 case elfcpp::R_POWERPC_ADDR16_LO
:
5324 case elfcpp::R_POWERPC_ADDR16_HI
:
5325 case elfcpp::R_POWERPC_ADDR16_HA
:
5326 case elfcpp::R_POWERPC_UADDR16
:
5327 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5328 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5329 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5330 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5331 case elfcpp::R_PPC64_ADDR16_DS
:
5332 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5333 case elfcpp::R_POWERPC_ADDR14
:
5334 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5335 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5337 // Make a PLT entry if necessary.
5338 if (gsym
->needs_plt_entry())
5340 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5342 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5343 reloc
.get_r_addend());
5344 target
->make_plt_entry(symtab
, layout
, gsym
);
5345 // Since this is not a PC-relative relocation, we may be
5346 // taking the address of a function. In that case we need to
5347 // set the entry in the dynamic symbol table to the address of
5348 // the PLT call stub.
5350 && gsym
->is_from_dynobj()
5351 && !parameters
->options().output_is_position_independent())
5352 gsym
->set_needs_dynsym_value();
5354 // Make a dynamic relocation if necessary.
5355 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
))
5356 || (size
== 64 && gsym
->type() == elfcpp::STT_GNU_IFUNC
))
5358 if (gsym
->may_need_copy_reloc())
5360 target
->copy_reloc(symtab
, layout
, object
,
5361 data_shndx
, output_section
, gsym
, reloc
);
5363 else if ((size
== 32
5364 && r_type
== elfcpp::R_POWERPC_ADDR32
5365 && gsym
->can_use_relative_reloc(false)
5366 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
5367 && parameters
->options().shared()))
5369 && r_type
== elfcpp::R_PPC64_ADDR64
5370 && (gsym
->can_use_relative_reloc(false)
5371 || data_shndx
== ppc_object
->opd_shndx())))
5373 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5374 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
5375 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
5377 rela_dyn
= target
->iplt_section()->rel_plt();
5378 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
5380 rela_dyn
->add_symbolless_global_addend(
5381 gsym
, dynrel
, output_section
, object
, data_shndx
,
5382 reloc
.get_r_offset(), reloc
.get_r_addend());
5386 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5387 check_non_pic(object
, r_type
);
5388 rela_dyn
->add_global(gsym
, r_type
, output_section
,
5390 reloc
.get_r_offset(),
5391 reloc
.get_r_addend());
5397 case elfcpp::R_PPC_PLTREL24
:
5398 case elfcpp::R_POWERPC_REL24
:
5399 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5400 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5401 reloc
.get_r_addend());
5402 if (gsym
->needs_plt_entry()
5403 || (!gsym
->final_value_is_known()
5404 && (gsym
->is_undefined()
5405 || gsym
->is_from_dynobj()
5406 || gsym
->is_preemptible())))
5407 target
->make_plt_entry(symtab
, layout
, gsym
);
5410 case elfcpp::R_PPC64_REL64
:
5411 case elfcpp::R_POWERPC_REL32
:
5412 // Make a dynamic relocation if necessary.
5413 if (needs_dynamic_reloc
<size
>(gsym
, Scan::get_reference_flags(r_type
)))
5415 if (gsym
->may_need_copy_reloc())
5417 target
->copy_reloc(symtab
, layout
, object
,
5418 data_shndx
, output_section
, gsym
,
5423 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5424 check_non_pic(object
, r_type
);
5425 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
5426 data_shndx
, reloc
.get_r_offset(),
5427 reloc
.get_r_addend());
5432 case elfcpp::R_POWERPC_REL14
:
5433 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5434 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5435 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5436 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5437 reloc
.get_r_addend());
5440 case elfcpp::R_POWERPC_REL16
:
5441 case elfcpp::R_POWERPC_REL16_LO
:
5442 case elfcpp::R_POWERPC_REL16_HI
:
5443 case elfcpp::R_POWERPC_REL16_HA
:
5444 case elfcpp::R_POWERPC_SECTOFF
:
5445 case elfcpp::R_POWERPC_TPREL16
:
5446 case elfcpp::R_POWERPC_DTPREL16
:
5447 case elfcpp::R_POWERPC_SECTOFF_LO
:
5448 case elfcpp::R_POWERPC_TPREL16_LO
:
5449 case elfcpp::R_POWERPC_DTPREL16_LO
:
5450 case elfcpp::R_POWERPC_SECTOFF_HI
:
5451 case elfcpp::R_POWERPC_TPREL16_HI
:
5452 case elfcpp::R_POWERPC_DTPREL16_HI
:
5453 case elfcpp::R_POWERPC_SECTOFF_HA
:
5454 case elfcpp::R_POWERPC_TPREL16_HA
:
5455 case elfcpp::R_POWERPC_DTPREL16_HA
:
5456 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5457 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5458 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5459 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5460 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5461 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5462 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5463 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5464 case elfcpp::R_PPC64_TPREL16_DS
:
5465 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5466 case elfcpp::R_PPC64_DTPREL16_DS
:
5467 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5468 case elfcpp::R_PPC64_SECTOFF_DS
:
5469 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5470 case elfcpp::R_PPC64_TLSGD
:
5471 case elfcpp::R_PPC64_TLSLD
:
5474 case elfcpp::R_POWERPC_GOT16
:
5475 case elfcpp::R_POWERPC_GOT16_LO
:
5476 case elfcpp::R_POWERPC_GOT16_HI
:
5477 case elfcpp::R_POWERPC_GOT16_HA
:
5478 case elfcpp::R_PPC64_GOT16_DS
:
5479 case elfcpp::R_PPC64_GOT16_LO_DS
:
5481 // The symbol requires a GOT entry.
5482 Output_data_got_powerpc
<size
, big_endian
>* got
;
5484 got
= target
->got_section(symtab
, layout
);
5485 if (gsym
->final_value_is_known())
5487 if (size
== 32 && gsym
->type() == elfcpp::STT_GNU_IFUNC
)
5488 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
5490 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
5492 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
5494 // If we are generating a shared object or a pie, this
5495 // symbol's GOT entry will be set by a dynamic relocation.
5496 unsigned int off
= got
->add_constant(0);
5497 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
5499 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5500 if (gsym
->can_use_relative_reloc(false)
5502 && gsym
->visibility() == elfcpp::STV_PROTECTED
5503 && parameters
->options().shared()))
5505 unsigned int dynrel
= elfcpp::R_POWERPC_RELATIVE
;
5506 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
5508 rela_dyn
= target
->iplt_section()->rel_plt();
5509 dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
5511 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
5515 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
5516 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
5522 case elfcpp::R_PPC64_TOC16
:
5523 case elfcpp::R_PPC64_TOC16_LO
:
5524 case elfcpp::R_PPC64_TOC16_HI
:
5525 case elfcpp::R_PPC64_TOC16_HA
:
5526 case elfcpp::R_PPC64_TOC16_DS
:
5527 case elfcpp::R_PPC64_TOC16_LO_DS
:
5528 // We need a GOT section.
5529 target
->got_section(symtab
, layout
);
5532 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5533 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5534 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5535 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5537 const bool final
= gsym
->final_value_is_known();
5538 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5539 if (tls_type
== tls::TLSOPT_NONE
)
5541 Output_data_got_powerpc
<size
, big_endian
>* got
5542 = target
->got_section(symtab
, layout
);
5543 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
,
5544 target
->rela_dyn_section(layout
),
5545 elfcpp::R_POWERPC_DTPMOD
,
5546 elfcpp::R_POWERPC_DTPREL
);
5548 else if (tls_type
== tls::TLSOPT_TO_IE
)
5550 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
5552 Output_data_got_powerpc
<size
, big_endian
>* got
5553 = target
->got_section(symtab
, layout
);
5554 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5555 if (gsym
->is_undefined()
5556 || gsym
->is_from_dynobj())
5558 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
5559 elfcpp::R_POWERPC_TPREL
);
5563 unsigned int off
= got
->add_constant(0);
5564 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
5565 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
5566 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
5571 else if (tls_type
== tls::TLSOPT_TO_LE
)
5573 // no GOT relocs needed for Local Exec.
5580 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5581 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5582 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5583 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5585 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5586 if (tls_type
== tls::TLSOPT_NONE
)
5587 target
->tlsld_got_offset(symtab
, layout
, object
);
5588 else if (tls_type
== tls::TLSOPT_TO_LE
)
5590 // no GOT relocs needed for Local Exec.
5591 if (parameters
->options().emit_relocs())
5593 Output_section
* os
= layout
->tls_segment()->first_section();
5594 gold_assert(os
!= NULL
);
5595 os
->set_needs_symtab_index();
5603 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5604 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5605 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5606 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5608 Output_data_got_powerpc
<size
, big_endian
>* got
5609 = target
->got_section(symtab
, layout
);
5610 if (!gsym
->final_value_is_known()
5611 && (gsym
->is_from_dynobj()
5612 || gsym
->is_undefined()
5613 || gsym
->is_preemptible()))
5614 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
5615 target
->rela_dyn_section(layout
),
5616 elfcpp::R_POWERPC_DTPREL
);
5618 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
5622 case elfcpp::R_POWERPC_GOT_TPREL16
:
5623 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5624 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5625 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5627 const bool final
= gsym
->final_value_is_known();
5628 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
5629 if (tls_type
== tls::TLSOPT_NONE
)
5631 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
5633 Output_data_got_powerpc
<size
, big_endian
>* got
5634 = target
->got_section(symtab
, layout
);
5635 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5636 if (gsym
->is_undefined()
5637 || gsym
->is_from_dynobj())
5639 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
5640 elfcpp::R_POWERPC_TPREL
);
5644 unsigned int off
= got
->add_constant(0);
5645 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
5646 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
5647 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
5652 else if (tls_type
== tls::TLSOPT_TO_LE
)
5654 // no GOT relocs needed for Local Exec.
5662 unsupported_reloc_global(object
, r_type
, gsym
);
5668 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5669 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5670 case elfcpp::R_POWERPC_GOT_TPREL16
:
5671 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5672 case elfcpp::R_POWERPC_GOT16
:
5673 case elfcpp::R_PPC64_GOT16_DS
:
5674 case elfcpp::R_PPC64_TOC16
:
5675 case elfcpp::R_PPC64_TOC16_DS
:
5676 ppc_object
->set_has_small_toc_reloc();
5682 // Process relocations for gc.
5684 template<int size
, bool big_endian
>
5686 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
5687 Symbol_table
* symtab
,
5689 Sized_relobj_file
<size
, big_endian
>* object
,
5690 unsigned int data_shndx
,
5692 const unsigned char* prelocs
,
5694 Output_section
* output_section
,
5695 bool needs_special_offset_handling
,
5696 size_t local_symbol_count
,
5697 const unsigned char* plocal_symbols
)
5699 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5700 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
5701 Powerpc_relobj
<size
, big_endian
>* ppc_object
5702 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5704 ppc_object
->set_opd_valid();
5705 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
5707 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
5708 for (p
= ppc_object
->access_from_map()->begin();
5709 p
!= ppc_object
->access_from_map()->end();
5712 Address dst_off
= p
->first
;
5713 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
5714 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
5715 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
5717 Object
* src_obj
= s
->first
;
5718 unsigned int src_indx
= s
->second
;
5719 symtab
->gc()->add_reference(src_obj
, src_indx
,
5720 ppc_object
, dst_indx
);
5724 ppc_object
->access_from_map()->clear();
5725 ppc_object
->process_gc_mark(symtab
);
5726 // Don't look at .opd relocs as .opd will reference everything.
5730 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
5731 typename
Target_powerpc::Relocatable_size_for_reloc
>(
5740 needs_special_offset_handling
,
5745 // Handle target specific gc actions when adding a gc reference from
5746 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
5747 // and DST_OFF. For powerpc64, this adds a referenc to the code
5748 // section of a function descriptor.
5750 template<int size
, bool big_endian
>
5752 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
5753 Symbol_table
* symtab
,
5755 unsigned int src_shndx
,
5757 unsigned int dst_shndx
,
5758 Address dst_off
) const
5760 if (size
!= 64 || dst_obj
->is_dynamic())
5763 Powerpc_relobj
<size
, big_endian
>* ppc_object
5764 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
5765 if (dst_shndx
== ppc_object
->opd_shndx())
5767 if (ppc_object
->opd_valid())
5769 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
5770 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
5774 // If we haven't run scan_opd_relocs, we must delay
5775 // processing this function descriptor reference.
5776 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
5781 // Add any special sections for this symbol to the gc work list.
5782 // For powerpc64, this adds the code section of a function
5785 template<int size
, bool big_endian
>
5787 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
5788 Symbol_table
* symtab
,
5793 Powerpc_relobj
<size
, big_endian
>* ppc_object
5794 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
5796 unsigned int shndx
= sym
->shndx(&is_ordinary
);
5797 if (is_ordinary
&& shndx
== ppc_object
->opd_shndx())
5799 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
5800 Address dst_off
= gsym
->value();
5801 if (ppc_object
->opd_valid())
5803 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
5804 symtab
->gc()->worklist().push(Section_id(ppc_object
, dst_indx
));
5807 ppc_object
->add_gc_mark(dst_off
);
5812 // For a symbol location in .opd, set LOC to the location of the
5815 template<int size
, bool big_endian
>
5817 Target_powerpc
<size
, big_endian
>::do_function_location(
5818 Symbol_location
* loc
) const
5822 if (loc
->object
->is_dynamic())
5824 Powerpc_dynobj
<size
, big_endian
>* ppc_object
5825 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
5826 if (loc
->shndx
== ppc_object
->opd_shndx())
5829 Address off
= loc
->offset
- ppc_object
->opd_address();
5830 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
5831 loc
->offset
= dest_off
;
5836 const Powerpc_relobj
<size
, big_endian
>* ppc_object
5837 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
5838 if (loc
->shndx
== ppc_object
->opd_shndx())
5841 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
5842 loc
->offset
= dest_off
;
5848 // Scan relocations for a section.
5850 template<int size
, bool big_endian
>
5852 Target_powerpc
<size
, big_endian
>::scan_relocs(
5853 Symbol_table
* symtab
,
5855 Sized_relobj_file
<size
, big_endian
>* object
,
5856 unsigned int data_shndx
,
5857 unsigned int sh_type
,
5858 const unsigned char* prelocs
,
5860 Output_section
* output_section
,
5861 bool needs_special_offset_handling
,
5862 size_t local_symbol_count
,
5863 const unsigned char* plocal_symbols
)
5865 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
5866 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
5868 if (sh_type
== elfcpp::SHT_REL
)
5870 gold_error(_("%s: unsupported REL reloc section"),
5871 object
->name().c_str());
5875 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
5884 needs_special_offset_handling
,
5889 // Functor class for processing the global symbol table.
5890 // Removes symbols defined on discarded opd entries.
5892 template<bool big_endian
>
5893 class Global_symbol_visitor_opd
5896 Global_symbol_visitor_opd()
5900 operator()(Sized_symbol
<64>* sym
)
5902 if (sym
->has_symtab_index()
5903 || sym
->source() != Symbol::FROM_OBJECT
5904 || !sym
->in_real_elf())
5907 if (sym
->object()->is_dynamic())
5910 Powerpc_relobj
<64, big_endian
>* symobj
5911 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
5912 if (symobj
->opd_shndx() == 0)
5916 unsigned int shndx
= sym
->shndx(&is_ordinary
);
5917 if (shndx
== symobj
->opd_shndx()
5918 && symobj
->get_opd_discard(sym
->value()))
5919 sym
->set_symtab_index(-1U);
5923 template<int size
, bool big_endian
>
5925 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
5927 Symbol_table
* symtab
)
5931 Output_data_save_res
<64, big_endian
>* savres
5932 = new Output_data_save_res
<64, big_endian
>(symtab
);
5933 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5934 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5935 savres
, ORDER_TEXT
, false);
5939 // Sort linker created .got section first (for the header), then input
5940 // sections belonging to files using small model code.
5942 template<bool big_endian
>
5943 class Sort_toc_sections
5947 operator()(const Output_section::Input_section
& is1
,
5948 const Output_section::Input_section
& is2
) const
5950 if (!is1
.is_input_section() && is2
.is_input_section())
5953 = (is1
.is_input_section()
5954 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
5955 ->has_small_toc_reloc()));
5957 = (is2
.is_input_section()
5958 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
5959 ->has_small_toc_reloc()));
5960 return small1
&& !small2
;
5964 // Finalize the sections.
5966 template<int size
, bool big_endian
>
5968 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
5970 const Input_objects
*,
5971 Symbol_table
* symtab
)
5973 if (parameters
->doing_static_link())
5975 // At least some versions of glibc elf-init.o have a strong
5976 // reference to __rela_iplt marker syms. A weak ref would be
5978 if (this->iplt_
!= NULL
)
5980 Reloc_section
* rel
= this->iplt_
->rel_plt();
5981 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
5982 Symbol_table::PREDEFINED
, rel
, 0, 0,
5983 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5984 elfcpp::STV_HIDDEN
, 0, false, true);
5985 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
5986 Symbol_table::PREDEFINED
, rel
, 0, 0,
5987 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5988 elfcpp::STV_HIDDEN
, 0, true, true);
5992 symtab
->define_as_constant("__rela_iplt_start", NULL
,
5993 Symbol_table::PREDEFINED
, 0, 0,
5994 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5995 elfcpp::STV_HIDDEN
, 0, true, false);
5996 symtab
->define_as_constant("__rela_iplt_end", NULL
,
5997 Symbol_table::PREDEFINED
, 0, 0,
5998 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
5999 elfcpp::STV_HIDDEN
, 0, true, false);
6005 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6006 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6008 if (!parameters
->options().relocatable())
6010 this->define_save_restore_funcs(layout
, symtab
);
6012 // Annoyingly, we need to make these sections now whether or
6013 // not we need them. If we delay until do_relax then we
6014 // need to mess with the relaxation machinery checkpointing.
6015 this->got_section(symtab
, layout
);
6016 this->make_brlt_section(layout
);
6018 if (parameters
->options().toc_sort())
6020 Output_section
* os
= this->got_
->output_section();
6021 if (os
!= NULL
&& os
->input_sections().size() > 1)
6022 std::stable_sort(os
->input_sections().begin(),
6023 os
->input_sections().end(),
6024 Sort_toc_sections
<big_endian
>());
6029 // Fill in some more dynamic tags.
6030 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6033 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6035 : this->plt_
->rel_plt());
6036 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6037 this->rela_dyn_
, true, size
== 32);
6041 if (this->got_
!= NULL
)
6043 this->got_
->finalize_data_size();
6044 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6045 this->got_
, this->got_
->g_o_t());
6050 if (this->glink_
!= NULL
)
6052 this->glink_
->finalize_data_size();
6053 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6055 (this->glink_
->pltresolve_size
6061 // Emit any relocs we saved in an attempt to avoid generating COPY
6063 if (this->copy_relocs_
.any_saved_relocs())
6064 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6067 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6071 ok_lo_toc_insn(uint32_t insn
)
6073 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6074 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6075 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6076 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6077 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6078 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6079 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6080 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6081 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6082 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6083 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6084 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6085 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6086 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6087 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6089 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6090 && ((insn
& 3) == 0 || (insn
& 3) == 3))
6091 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
6094 // Return the value to use for a branch relocation.
6096 template<int size
, bool big_endian
>
6097 typename Target_powerpc
<size
, big_endian
>::Address
6098 Target_powerpc
<size
, big_endian
>::symval_for_branch(
6099 const Symbol_table
* symtab
,
6101 const Sized_symbol
<size
>* gsym
,
6102 Powerpc_relobj
<size
, big_endian
>* object
,
6103 unsigned int *dest_shndx
)
6109 // If the symbol is defined in an opd section, ie. is a function
6110 // descriptor, use the function descriptor code entry address
6111 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
6113 && gsym
->source() != Symbol::FROM_OBJECT
)
6116 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6117 unsigned int shndx
= symobj
->opd_shndx();
6120 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
6121 gold_assert(opd_addr
!= invalid_address
);
6122 opd_addr
+= symobj
->output_section(shndx
)->address();
6123 if (value
>= opd_addr
&& value
< opd_addr
+ symobj
->section_size(shndx
))
6126 *dest_shndx
= symobj
->get_opd_ent(value
- opd_addr
, &sec_off
);
6127 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
6130 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
6131 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
6132 *dest_shndx
= folded
.second
;
6134 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
6135 gold_assert(sec_addr
!= invalid_address
);
6136 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
6137 value
= sec_addr
+ sec_off
;
6142 // Perform a relocation.
6144 template<int size
, bool big_endian
>
6146 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
6147 const Relocate_info
<size
, big_endian
>* relinfo
,
6148 Target_powerpc
* target
,
6151 const elfcpp::Rela
<size
, big_endian
>& rela
,
6152 unsigned int r_type
,
6153 const Sized_symbol
<size
>* gsym
,
6154 const Symbol_value
<size
>* psymval
,
6155 unsigned char* view
,
6157 section_size_type view_size
)
6159 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
6161 case Track_tls::NOT_EXPECTED
:
6162 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6163 _("__tls_get_addr call lacks marker reloc"));
6165 case Track_tls::EXPECTED
:
6166 // We have already complained.
6168 case Track_tls::SKIP
:
6170 case Track_tls::NORMAL
:
6174 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
6175 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
6176 Powerpc_relobj
<size
, big_endian
>* const object
6177 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
6179 bool has_plt_value
= false;
6180 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6182 ? use_plt_offset
<size
>(gsym
, Scan::get_reference_flags(r_type
))
6183 : object
->local_has_plt_offset(r_sym
))
6185 Stub_table
<size
, big_endian
>* stub_table
6186 = object
->stub_table(relinfo
->data_shndx
);
6187 if (stub_table
== NULL
)
6189 // This is a ref from a data section to an ifunc symbol.
6190 if (target
->stub_tables().size() != 0)
6191 stub_table
= target
->stub_tables()[0];
6193 gold_assert(stub_table
!= NULL
);
6196 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
6197 rela
.get_r_addend());
6199 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
6200 rela
.get_r_addend());
6201 gold_assert(off
!= invalid_address
);
6202 value
= stub_table
->stub_address() + off
;
6203 has_plt_value
= true;
6206 if (r_type
== elfcpp::R_POWERPC_GOT16
6207 || r_type
== elfcpp::R_POWERPC_GOT16_LO
6208 || r_type
== elfcpp::R_POWERPC_GOT16_HI
6209 || r_type
== elfcpp::R_POWERPC_GOT16_HA
6210 || r_type
== elfcpp::R_PPC64_GOT16_DS
6211 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
6215 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
6216 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
6220 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6221 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
6222 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
6224 value
-= target
->got_section()->got_base_offset(object
);
6226 else if (r_type
== elfcpp::R_PPC64_TOC
)
6228 value
= (target
->got_section()->output_section()->address()
6229 + object
->toc_base_offset());
6231 else if (gsym
!= NULL
6232 && (r_type
== elfcpp::R_POWERPC_REL24
6233 || r_type
== elfcpp::R_PPC_PLTREL24
)
6238 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
6239 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
6240 bool can_plt_call
= false;
6241 if (rela
.get_r_offset() + 8 <= view_size
)
6243 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
6244 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
6247 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
6249 elfcpp::Swap
<32, big_endian
>::writeval(wv
+ 1, ld_2_1
+ 40);
6250 can_plt_call
= true;
6255 // If we don't have a branch and link followed by a nop,
6256 // we can't go via the plt because there is no place to
6257 // put a toc restoring instruction.
6258 // Unless we know we won't be returning.
6259 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
6260 can_plt_call
= true;
6264 // This is not an error in one special case: A self
6265 // call. It isn't possible to cheaply verify we have
6266 // such a call so just check for a call to the same
6269 Address code
= value
;
6270 if (gsym
->source() == Symbol::FROM_OBJECT
6271 && gsym
->object() == object
)
6273 Address addend
= rela
.get_r_addend();
6274 unsigned int dest_shndx
;
6275 Address opdent
= psymval
->value(object
, addend
);
6276 code
= target
->symval_for_branch(relinfo
->symtab
, opdent
,
6277 gsym
, object
, &dest_shndx
);
6279 if (dest_shndx
== 0)
6280 dest_shndx
= gsym
->shndx(&is_ordinary
);
6281 ok
= dest_shndx
== relinfo
->data_shndx
;
6285 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6286 _("call lacks nop, can't restore toc; "
6287 "recompile with -fPIC"));
6293 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6294 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
6295 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
6296 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
6298 // First instruction of a global dynamic sequence, arg setup insn.
6299 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6300 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6301 enum Got_type got_type
= GOT_TYPE_STANDARD
;
6302 if (tls_type
== tls::TLSOPT_NONE
)
6303 got_type
= GOT_TYPE_TLSGD
;
6304 else if (tls_type
== tls::TLSOPT_TO_IE
)
6305 got_type
= GOT_TYPE_TPREL
;
6306 if (got_type
!= GOT_TYPE_STANDARD
)
6310 gold_assert(gsym
->has_got_offset(got_type
));
6311 value
= gsym
->got_offset(got_type
);
6315 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6316 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
6317 value
= object
->local_got_offset(r_sym
, got_type
);
6319 value
-= target
->got_section()->got_base_offset(object
);
6321 if (tls_type
== tls::TLSOPT_TO_IE
)
6323 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6324 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6326 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6327 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6328 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
6330 insn
|= 32 << 26; // lwz
6332 insn
|= 58 << 26; // ld
6333 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6335 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
6336 - elfcpp::R_POWERPC_GOT_TLSGD16
);
6338 else if (tls_type
== tls::TLSOPT_TO_LE
)
6340 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
6341 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
6343 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6344 Insn insn
= addis_3_13
;
6347 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6348 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6349 value
= psymval
->value(object
, rela
.get_r_addend());
6353 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6355 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6356 r_type
= elfcpp::R_POWERPC_NONE
;
6360 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6361 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
6362 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
6363 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
6365 // First instruction of a local dynamic sequence, arg setup insn.
6366 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6367 if (tls_type
== tls::TLSOPT_NONE
)
6369 value
= target
->tlsld_got_offset();
6370 value
-= target
->got_section()->got_base_offset(object
);
6374 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
6375 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
6376 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
6378 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6379 Insn insn
= addis_3_13
;
6382 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6383 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6388 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6390 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6391 r_type
= elfcpp::R_POWERPC_NONE
;
6395 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
6396 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
6397 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
6398 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
6400 // Accesses relative to a local dynamic sequence address,
6401 // no optimisation here.
6404 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
6405 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
6409 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6410 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
6411 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
6413 value
-= target
->got_section()->got_base_offset(object
);
6415 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6416 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
6417 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
6418 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
6420 // First instruction of initial exec sequence.
6421 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6422 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6423 if (tls_type
== tls::TLSOPT_NONE
)
6427 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
6428 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
6432 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6433 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
6434 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
6436 value
-= target
->got_section()->got_base_offset(object
);
6440 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
6441 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
6442 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
6444 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6445 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6446 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
6451 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6452 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
6453 value
= psymval
->value(object
, rela
.get_r_addend());
6457 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6459 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6460 r_type
= elfcpp::R_POWERPC_NONE
;
6464 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
6465 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
6467 // Second instruction of a global dynamic sequence,
6468 // the __tls_get_addr call
6469 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
6470 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6471 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6472 if (tls_type
!= tls::TLSOPT_NONE
)
6474 if (tls_type
== tls::TLSOPT_TO_IE
)
6476 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6477 Insn insn
= add_3_3_13
;
6480 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6481 r_type
= elfcpp::R_POWERPC_NONE
;
6485 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6486 Insn insn
= addi_3_3
;
6487 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6488 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6489 view
+= 2 * big_endian
;
6490 value
= psymval
->value(object
, rela
.get_r_addend());
6492 this->skip_next_tls_get_addr_call();
6495 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
6496 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
6498 // Second instruction of a local dynamic sequence,
6499 // the __tls_get_addr call
6500 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
6501 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6502 if (tls_type
== tls::TLSOPT_TO_LE
)
6504 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6505 Insn insn
= addi_3_3
;
6506 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6507 this->skip_next_tls_get_addr_call();
6508 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6509 view
+= 2 * big_endian
;
6513 else if (r_type
== elfcpp::R_POWERPC_TLS
)
6515 // Second instruction of an initial exec sequence
6516 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
6517 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6518 if (tls_type
== tls::TLSOPT_TO_LE
)
6520 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6521 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6522 unsigned int reg
= size
== 32 ? 2 : 13;
6523 insn
= at_tls_transform(insn
, reg
);
6524 gold_assert(insn
!= 0);
6525 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6526 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
6527 view
+= 2 * big_endian
;
6528 value
= psymval
->value(object
, rela
.get_r_addend());
6531 else if (!has_plt_value
)
6534 unsigned int dest_shndx
;
6535 if (r_type
!= elfcpp::R_PPC_PLTREL24
)
6536 addend
= rela
.get_r_addend();
6537 value
= psymval
->value(object
, addend
);
6538 if (size
== 64 && is_branch_reloc(r_type
))
6539 value
= target
->symval_for_branch(relinfo
->symtab
, value
,
6540 gsym
, object
, &dest_shndx
);
6541 unsigned int max_branch_offset
= 0;
6542 if (r_type
== elfcpp::R_POWERPC_REL24
6543 || r_type
== elfcpp::R_PPC_PLTREL24
6544 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
6545 max_branch_offset
= 1 << 25;
6546 else if (r_type
== elfcpp::R_POWERPC_REL14
6547 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
6548 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
6549 max_branch_offset
= 1 << 15;
6550 if (max_branch_offset
!= 0
6551 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
6553 Stub_table
<size
, big_endian
>* stub_table
6554 = object
->stub_table(relinfo
->data_shndx
);
6555 gold_assert(stub_table
!= NULL
);
6556 Address off
= stub_table
->find_long_branch_entry(object
, value
);
6557 if (off
!= invalid_address
)
6558 value
= stub_table
->stub_address() + stub_table
->plt_size() + off
;
6564 case elfcpp::R_PPC64_REL64
:
6565 case elfcpp::R_POWERPC_REL32
:
6566 case elfcpp::R_POWERPC_REL24
:
6567 case elfcpp::R_PPC_PLTREL24
:
6568 case elfcpp::R_PPC_LOCAL24PC
:
6569 case elfcpp::R_POWERPC_REL16
:
6570 case elfcpp::R_POWERPC_REL16_LO
:
6571 case elfcpp::R_POWERPC_REL16_HI
:
6572 case elfcpp::R_POWERPC_REL16_HA
:
6573 case elfcpp::R_POWERPC_REL14
:
6574 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6575 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6579 case elfcpp::R_PPC64_TOC16
:
6580 case elfcpp::R_PPC64_TOC16_LO
:
6581 case elfcpp::R_PPC64_TOC16_HI
:
6582 case elfcpp::R_PPC64_TOC16_HA
:
6583 case elfcpp::R_PPC64_TOC16_DS
:
6584 case elfcpp::R_PPC64_TOC16_LO_DS
:
6585 // Subtract the TOC base address.
6586 value
-= (target
->got_section()->output_section()->address()
6587 + object
->toc_base_offset());
6590 case elfcpp::R_POWERPC_SECTOFF
:
6591 case elfcpp::R_POWERPC_SECTOFF_LO
:
6592 case elfcpp::R_POWERPC_SECTOFF_HI
:
6593 case elfcpp::R_POWERPC_SECTOFF_HA
:
6594 case elfcpp::R_PPC64_SECTOFF_DS
:
6595 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6597 value
-= os
->address();
6600 case elfcpp::R_PPC64_TPREL16_DS
:
6601 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6603 // R_PPC_TLSGD and R_PPC_TLSLD
6605 case elfcpp::R_POWERPC_TPREL16
:
6606 case elfcpp::R_POWERPC_TPREL16_LO
:
6607 case elfcpp::R_POWERPC_TPREL16_HI
:
6608 case elfcpp::R_POWERPC_TPREL16_HA
:
6609 case elfcpp::R_POWERPC_TPREL
:
6610 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6611 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6612 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6613 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6614 // tls symbol values are relative to tls_segment()->vaddr()
6618 case elfcpp::R_PPC64_DTPREL16_DS
:
6619 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6620 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6621 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6622 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6623 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6625 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
6626 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
6628 case elfcpp::R_POWERPC_DTPREL16
:
6629 case elfcpp::R_POWERPC_DTPREL16_LO
:
6630 case elfcpp::R_POWERPC_DTPREL16_HI
:
6631 case elfcpp::R_POWERPC_DTPREL16_HA
:
6632 case elfcpp::R_POWERPC_DTPREL
:
6633 // tls symbol values are relative to tls_segment()->vaddr()
6634 value
-= dtp_offset
;
6641 Insn branch_bit
= 0;
6644 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6645 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6646 branch_bit
= 1 << 21;
6647 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6648 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6650 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
6651 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6654 if (this->is_isa_v2
)
6656 // Set 'a' bit. This is 0b00010 in BO field for branch
6657 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
6658 // for branch on CTR insns (BO == 1a00t or 1a01t).
6659 if ((insn
& (0x14 << 21)) == (0x04 << 21))
6661 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
6668 // Invert 'y' bit if not the default.
6669 if (static_cast<Signed_address
>(value
) < 0)
6672 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6682 // Multi-instruction sequences that access the TOC can be
6683 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
6684 // to nop; addi rb,r2,x;
6690 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6691 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6692 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6693 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6694 case elfcpp::R_POWERPC_GOT16_HA
:
6695 case elfcpp::R_PPC64_TOC16_HA
:
6696 if (parameters
->options().toc_optimize())
6698 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6699 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6700 if ((insn
& ((0x3f << 26) | 0x1f << 16))
6701 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
6702 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6703 _("toc optimization is not supported "
6704 "for %#08x instruction"), insn
);
6705 else if (value
+ 0x8000 < 0x10000)
6707 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
6713 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6714 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6715 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6716 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6717 case elfcpp::R_POWERPC_GOT16_LO
:
6718 case elfcpp::R_PPC64_GOT16_LO_DS
:
6719 case elfcpp::R_PPC64_TOC16_LO
:
6720 case elfcpp::R_PPC64_TOC16_LO_DS
:
6721 if (parameters
->options().toc_optimize())
6723 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
6724 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
6725 if (!ok_lo_toc_insn(insn
))
6726 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6727 _("toc optimization is not supported "
6728 "for %#08x instruction"), insn
);
6729 else if (value
+ 0x8000 < 0x10000)
6731 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
6733 // Transform addic to addi when we change reg.
6734 insn
&= ~((0x3f << 26) | (0x1f << 16));
6735 insn
|= (14u << 26) | (2 << 16);
6739 insn
&= ~(0x1f << 16);
6742 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
6749 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
6752 case elfcpp::R_POWERPC_ADDR32
:
6753 case elfcpp::R_POWERPC_UADDR32
:
6755 overflow
= Reloc::CHECK_BITFIELD
;
6758 case elfcpp::R_POWERPC_REL32
:
6760 overflow
= Reloc::CHECK_SIGNED
;
6763 case elfcpp::R_POWERPC_ADDR24
:
6764 case elfcpp::R_POWERPC_ADDR16
:
6765 case elfcpp::R_POWERPC_UADDR16
:
6766 case elfcpp::R_PPC64_ADDR16_DS
:
6767 case elfcpp::R_POWERPC_ADDR14
:
6768 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6769 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6770 overflow
= Reloc::CHECK_BITFIELD
;
6773 case elfcpp::R_POWERPC_REL24
:
6774 case elfcpp::R_PPC_PLTREL24
:
6775 case elfcpp::R_PPC_LOCAL24PC
:
6776 case elfcpp::R_POWERPC_REL16
:
6777 case elfcpp::R_PPC64_TOC16
:
6778 case elfcpp::R_POWERPC_GOT16
:
6779 case elfcpp::R_POWERPC_SECTOFF
:
6780 case elfcpp::R_POWERPC_TPREL16
:
6781 case elfcpp::R_POWERPC_DTPREL16
:
6782 case elfcpp::R_PPC64_TPREL16_DS
:
6783 case elfcpp::R_PPC64_DTPREL16_DS
:
6784 case elfcpp::R_PPC64_TOC16_DS
:
6785 case elfcpp::R_PPC64_GOT16_DS
:
6786 case elfcpp::R_PPC64_SECTOFF_DS
:
6787 case elfcpp::R_POWERPC_REL14
:
6788 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6789 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6790 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6791 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6792 case elfcpp::R_POWERPC_GOT_TPREL16
:
6793 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6794 overflow
= Reloc::CHECK_SIGNED
;
6798 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
6799 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
6802 case elfcpp::R_POWERPC_NONE
:
6803 case elfcpp::R_POWERPC_TLS
:
6804 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6805 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6806 case elfcpp::R_PPC_EMB_MRKREF
:
6809 case elfcpp::R_PPC64_ADDR64
:
6810 case elfcpp::R_PPC64_REL64
:
6811 case elfcpp::R_PPC64_TOC
:
6812 Reloc::addr64(view
, value
);
6815 case elfcpp::R_POWERPC_TPREL
:
6816 case elfcpp::R_POWERPC_DTPREL
:
6818 Reloc::addr64(view
, value
);
6820 status
= Reloc::addr32(view
, value
, overflow
);
6823 case elfcpp::R_PPC64_UADDR64
:
6824 Reloc::addr64_u(view
, value
);
6827 case elfcpp::R_POWERPC_ADDR32
:
6828 status
= Reloc::addr32(view
, value
, overflow
);
6831 case elfcpp::R_POWERPC_REL32
:
6832 case elfcpp::R_POWERPC_UADDR32
:
6833 status
= Reloc::addr32_u(view
, value
, overflow
);
6836 case elfcpp::R_POWERPC_ADDR24
:
6837 case elfcpp::R_POWERPC_REL24
:
6838 case elfcpp::R_PPC_PLTREL24
:
6839 case elfcpp::R_PPC_LOCAL24PC
:
6840 status
= Reloc::addr24(view
, value
, overflow
);
6843 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6844 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6847 status
= Reloc::addr16_ds(view
, value
, overflow
);
6850 case elfcpp::R_POWERPC_ADDR16
:
6851 case elfcpp::R_POWERPC_REL16
:
6852 case elfcpp::R_PPC64_TOC16
:
6853 case elfcpp::R_POWERPC_GOT16
:
6854 case elfcpp::R_POWERPC_SECTOFF
:
6855 case elfcpp::R_POWERPC_TPREL16
:
6856 case elfcpp::R_POWERPC_DTPREL16
:
6857 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6858 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6859 case elfcpp::R_POWERPC_GOT_TPREL16
:
6860 case elfcpp::R_POWERPC_ADDR16_LO
:
6861 case elfcpp::R_POWERPC_REL16_LO
:
6862 case elfcpp::R_PPC64_TOC16_LO
:
6863 case elfcpp::R_POWERPC_GOT16_LO
:
6864 case elfcpp::R_POWERPC_SECTOFF_LO
:
6865 case elfcpp::R_POWERPC_TPREL16_LO
:
6866 case elfcpp::R_POWERPC_DTPREL16_LO
:
6867 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6868 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6869 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6870 status
= Reloc::addr16(view
, value
, overflow
);
6873 case elfcpp::R_POWERPC_UADDR16
:
6874 status
= Reloc::addr16_u(view
, value
, overflow
);
6877 case elfcpp::R_POWERPC_ADDR16_HI
:
6878 case elfcpp::R_POWERPC_REL16_HI
:
6879 case elfcpp::R_PPC64_TOC16_HI
:
6880 case elfcpp::R_POWERPC_GOT16_HI
:
6881 case elfcpp::R_POWERPC_SECTOFF_HI
:
6882 case elfcpp::R_POWERPC_TPREL16_HI
:
6883 case elfcpp::R_POWERPC_DTPREL16_HI
:
6884 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6885 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6886 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6887 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6888 Reloc::addr16_hi(view
, value
);
6891 case elfcpp::R_POWERPC_ADDR16_HA
:
6892 case elfcpp::R_POWERPC_REL16_HA
:
6893 case elfcpp::R_PPC64_TOC16_HA
:
6894 case elfcpp::R_POWERPC_GOT16_HA
:
6895 case elfcpp::R_POWERPC_SECTOFF_HA
:
6896 case elfcpp::R_POWERPC_TPREL16_HA
:
6897 case elfcpp::R_POWERPC_DTPREL16_HA
:
6898 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6899 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6900 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6901 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6902 Reloc::addr16_ha(view
, value
);
6905 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6907 // R_PPC_EMB_NADDR16_LO
6909 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6910 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6911 Reloc::addr16_hi2(view
, value
);
6914 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6916 // R_PPC_EMB_NADDR16_HI
6918 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6919 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6920 Reloc::addr16_ha2(view
, value
);
6923 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6925 // R_PPC_EMB_NADDR16_HA
6927 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6928 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6929 Reloc::addr16_hi3(view
, value
);
6932 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6936 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6937 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6938 Reloc::addr16_ha3(view
, value
);
6941 case elfcpp::R_PPC64_DTPREL16_DS
:
6942 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6944 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
6946 case elfcpp::R_PPC64_TPREL16_DS
:
6947 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6949 // R_PPC_TLSGD, R_PPC_TLSLD
6951 case elfcpp::R_PPC64_ADDR16_DS
:
6952 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6953 case elfcpp::R_PPC64_TOC16_DS
:
6954 case elfcpp::R_PPC64_TOC16_LO_DS
:
6955 case elfcpp::R_PPC64_GOT16_DS
:
6956 case elfcpp::R_PPC64_GOT16_LO_DS
:
6957 case elfcpp::R_PPC64_SECTOFF_DS
:
6958 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6959 status
= Reloc::addr16_ds(view
, value
, overflow
);
6962 case elfcpp::R_POWERPC_ADDR14
:
6963 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6964 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6965 case elfcpp::R_POWERPC_REL14
:
6966 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6967 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6968 status
= Reloc::addr14(view
, value
, overflow
);
6971 case elfcpp::R_POWERPC_COPY
:
6972 case elfcpp::R_POWERPC_GLOB_DAT
:
6973 case elfcpp::R_POWERPC_JMP_SLOT
:
6974 case elfcpp::R_POWERPC_RELATIVE
:
6975 case elfcpp::R_POWERPC_DTPMOD
:
6976 case elfcpp::R_PPC64_JMP_IREL
:
6977 case elfcpp::R_POWERPC_IRELATIVE
:
6978 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6979 _("unexpected reloc %u in object file"),
6983 case elfcpp::R_PPC_EMB_SDA21
:
6988 // R_PPC64_TOCSAVE. For the time being this can be ignored.
6992 case elfcpp::R_PPC_EMB_SDA2I16
:
6993 case elfcpp::R_PPC_EMB_SDA2REL
:
6996 // R_PPC64_TLSGD, R_PPC64_TLSLD
6999 case elfcpp::R_POWERPC_PLT32
:
7000 case elfcpp::R_POWERPC_PLTREL32
:
7001 case elfcpp::R_POWERPC_PLT16_LO
:
7002 case elfcpp::R_POWERPC_PLT16_HI
:
7003 case elfcpp::R_POWERPC_PLT16_HA
:
7004 case elfcpp::R_PPC_SDAREL16
:
7005 case elfcpp::R_POWERPC_ADDR30
:
7006 case elfcpp::R_PPC64_PLT64
:
7007 case elfcpp::R_PPC64_PLTREL64
:
7008 case elfcpp::R_PPC64_PLTGOT16
:
7009 case elfcpp::R_PPC64_PLTGOT16_LO
:
7010 case elfcpp::R_PPC64_PLTGOT16_HI
:
7011 case elfcpp::R_PPC64_PLTGOT16_HA
:
7012 case elfcpp::R_PPC64_PLT16_LO_DS
:
7013 case elfcpp::R_PPC64_PLTGOT16_DS
:
7014 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
7015 case elfcpp::R_PPC_EMB_RELSEC16
:
7016 case elfcpp::R_PPC_EMB_RELST_LO
:
7017 case elfcpp::R_PPC_EMB_RELST_HI
:
7018 case elfcpp::R_PPC_EMB_RELST_HA
:
7019 case elfcpp::R_PPC_EMB_BIT_FLD
:
7020 case elfcpp::R_PPC_EMB_RELSDA
:
7021 case elfcpp::R_PPC_TOC16
:
7024 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7025 _("unsupported reloc %u"),
7029 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
)
7030 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7031 _("relocation overflow"));
7036 // Relocate section data.
7038 template<int size
, bool big_endian
>
7040 Target_powerpc
<size
, big_endian
>::relocate_section(
7041 const Relocate_info
<size
, big_endian
>* relinfo
,
7042 unsigned int sh_type
,
7043 const unsigned char* prelocs
,
7045 Output_section
* output_section
,
7046 bool needs_special_offset_handling
,
7047 unsigned char* view
,
7049 section_size_type view_size
,
7050 const Reloc_symbol_changes
* reloc_symbol_changes
)
7052 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
7053 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
7054 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
7055 Powerpc_comdat_behavior
;
7057 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7059 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
7060 Powerpc_relocate
, Powerpc_comdat_behavior
>(
7066 needs_special_offset_handling
,
7070 reloc_symbol_changes
);
7073 class Powerpc_scan_relocatable_reloc
7076 // Return the strategy to use for a local symbol which is not a
7077 // section symbol, given the relocation type.
7078 inline Relocatable_relocs::Reloc_strategy
7079 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
7081 if (r_type
== 0 && r_sym
== 0)
7082 return Relocatable_relocs::RELOC_DISCARD
;
7083 return Relocatable_relocs::RELOC_COPY
;
7086 // Return the strategy to use for a local symbol which is a section
7087 // symbol, given the relocation type.
7088 inline Relocatable_relocs::Reloc_strategy
7089 local_section_strategy(unsigned int, Relobj
*)
7091 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
7094 // Return the strategy to use for a global symbol, given the
7095 // relocation type, the object, and the symbol index.
7096 inline Relocatable_relocs::Reloc_strategy
7097 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
7099 if (r_type
== elfcpp::R_PPC_PLTREL24
)
7100 return Relocatable_relocs::RELOC_SPECIAL
;
7101 return Relocatable_relocs::RELOC_COPY
;
7105 // Scan the relocs during a relocatable link.
7107 template<int size
, bool big_endian
>
7109 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
7110 Symbol_table
* symtab
,
7112 Sized_relobj_file
<size
, big_endian
>* object
,
7113 unsigned int data_shndx
,
7114 unsigned int sh_type
,
7115 const unsigned char* prelocs
,
7117 Output_section
* output_section
,
7118 bool needs_special_offset_handling
,
7119 size_t local_symbol_count
,
7120 const unsigned char* plocal_symbols
,
7121 Relocatable_relocs
* rr
)
7123 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7125 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
7126 Powerpc_scan_relocatable_reloc
>(
7134 needs_special_offset_handling
,
7140 // Emit relocations for a section.
7141 // This is a modified version of the function by the same name in
7142 // target-reloc.h. Using relocate_special_relocatable for
7143 // R_PPC_PLTREL24 would require duplication of the entire body of the
7144 // loop, so we may as well duplicate the whole thing.
7146 template<int size
, bool big_endian
>
7148 Target_powerpc
<size
, big_endian
>::relocate_relocs(
7149 const Relocate_info
<size
, big_endian
>* relinfo
,
7150 unsigned int sh_type
,
7151 const unsigned char* prelocs
,
7153 Output_section
* output_section
,
7154 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
7155 const Relocatable_relocs
* rr
,
7157 Address view_address
,
7159 unsigned char* reloc_view
,
7160 section_size_type reloc_view_size
)
7162 gold_assert(sh_type
== elfcpp::SHT_RELA
);
7164 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
7166 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
7168 const int reloc_size
7169 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
7171 Powerpc_relobj
<size
, big_endian
>* const object
7172 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
7173 const unsigned int local_count
= object
->local_symbol_count();
7174 unsigned int got2_shndx
= object
->got2_shndx();
7175 Address got2_addend
= 0;
7176 if (got2_shndx
!= 0)
7178 got2_addend
= object
->get_output_section_offset(got2_shndx
);
7179 gold_assert(got2_addend
!= invalid_address
);
7182 unsigned char* pwrite
= reloc_view
;
7183 bool zap_next
= false;
7184 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
7186 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
7187 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
7190 Reltype
reloc(prelocs
);
7191 Reltype_write
reloc_write(pwrite
);
7193 Address offset
= reloc
.get_r_offset();
7194 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
7195 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
7196 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
7197 const unsigned int orig_r_sym
= r_sym
;
7198 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
7199 = reloc
.get_r_addend();
7200 const Symbol
* gsym
= NULL
;
7204 // We could arrange to discard these and other relocs for
7205 // tls optimised sequences in the strategy methods, but for
7206 // now do as BFD ld does.
7207 r_type
= elfcpp::R_POWERPC_NONE
;
7211 // Get the new symbol index.
7212 if (r_sym
< local_count
)
7216 case Relocatable_relocs::RELOC_COPY
:
7217 case Relocatable_relocs::RELOC_SPECIAL
:
7220 r_sym
= object
->symtab_index(r_sym
);
7221 gold_assert(r_sym
!= -1U);
7225 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
7227 // We are adjusting a section symbol. We need to find
7228 // the symbol table index of the section symbol for
7229 // the output section corresponding to input section
7230 // in which this symbol is defined.
7231 gold_assert(r_sym
< local_count
);
7233 unsigned int shndx
=
7234 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
7235 gold_assert(is_ordinary
);
7236 Output_section
* os
= object
->output_section(shndx
);
7237 gold_assert(os
!= NULL
);
7238 gold_assert(os
->needs_symtab_index());
7239 r_sym
= os
->symtab_index();
7249 gsym
= object
->global_symbol(r_sym
);
7250 gold_assert(gsym
!= NULL
);
7251 if (gsym
->is_forwarder())
7252 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
7254 gold_assert(gsym
->has_symtab_index());
7255 r_sym
= gsym
->symtab_index();
7258 // Get the new offset--the location in the output section where
7259 // this relocation should be applied.
7260 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
7261 offset
+= offset_in_output_section
;
7264 section_offset_type sot_offset
=
7265 convert_types
<section_offset_type
, Address
>(offset
);
7266 section_offset_type new_sot_offset
=
7267 output_section
->output_offset(object
, relinfo
->data_shndx
,
7269 gold_assert(new_sot_offset
!= -1);
7270 offset
= new_sot_offset
;
7273 // In an object file, r_offset is an offset within the section.
7274 // In an executable or dynamic object, generated by
7275 // --emit-relocs, r_offset is an absolute address.
7276 if (!parameters
->options().relocatable())
7278 offset
+= view_address
;
7279 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
7280 offset
-= offset_in_output_section
;
7283 // Handle the reloc addend based on the strategy.
7284 if (strategy
== Relocatable_relocs::RELOC_COPY
)
7286 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
7288 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
7289 addend
= psymval
->value(object
, addend
);
7291 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
7293 if (addend
>= 32768)
7294 addend
+= got2_addend
;
7299 if (!parameters
->options().relocatable())
7301 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7302 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
7303 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
7304 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
7306 // First instruction of a global dynamic sequence,
7308 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7309 switch (this->optimize_tls_gd(final
))
7311 case tls::TLSOPT_TO_IE
:
7312 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7313 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7315 case tls::TLSOPT_TO_LE
:
7316 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7317 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7318 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7321 r_type
= elfcpp::R_POWERPC_NONE
;
7322 offset
-= 2 * big_endian
;
7329 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7330 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7331 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7332 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7334 // First instruction of a local dynamic sequence,
7336 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
7338 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7339 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7341 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7342 const Output_section
* os
= relinfo
->layout
->tls_segment()
7344 gold_assert(os
!= NULL
);
7345 gold_assert(os
->needs_symtab_index());
7346 r_sym
= os
->symtab_index();
7347 addend
= dtp_offset
;
7351 r_type
= elfcpp::R_POWERPC_NONE
;
7352 offset
-= 2 * big_endian
;
7356 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7357 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7358 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7359 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
7361 // First instruction of initial exec sequence.
7362 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7363 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
7365 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7366 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
7367 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7370 r_type
= elfcpp::R_POWERPC_NONE
;
7371 offset
-= 2 * big_endian
;
7375 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7376 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7378 // Second instruction of a global dynamic sequence,
7379 // the __tls_get_addr call
7380 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7381 switch (this->optimize_tls_gd(final
))
7383 case tls::TLSOPT_TO_IE
:
7384 r_type
= elfcpp::R_POWERPC_NONE
;
7387 case tls::TLSOPT_TO_LE
:
7388 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7389 offset
+= 2 * big_endian
;
7396 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7397 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7399 // Second instruction of a local dynamic sequence,
7400 // the __tls_get_addr call
7401 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
7403 const Output_section
* os
= relinfo
->layout
->tls_segment()
7405 gold_assert(os
!= NULL
);
7406 gold_assert(os
->needs_symtab_index());
7407 r_sym
= os
->symtab_index();
7408 addend
= dtp_offset
;
7409 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7410 offset
+= 2 * big_endian
;
7414 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7416 // Second instruction of an initial exec sequence
7417 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7418 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
7420 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7421 offset
+= 2 * big_endian
;
7426 reloc_write
.put_r_offset(offset
);
7427 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
7428 reloc_write
.put_r_addend(addend
);
7430 pwrite
+= reloc_size
;
7433 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
7434 == reloc_view_size
);
7437 // Return the value to use for a dynamic symbol which requires special
7438 // treatment. This is how we support equality comparisons of function
7439 // pointers across shared library boundaries, as described in the
7440 // processor specific ABI supplement.
7442 template<int size
, bool big_endian
>
7444 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
7448 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
7449 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
7450 p
!= this->stub_tables_
.end();
7453 Address off
= (*p
)->find_plt_call_entry(gsym
);
7454 if (off
!= invalid_address
)
7455 return (*p
)->stub_address() + off
;
7461 // Return the PLT address to use for a local symbol.
7462 template<int size
, bool big_endian
>
7464 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
7465 const Relobj
* object
,
7466 unsigned int symndx
) const
7470 const Sized_relobj
<size
, big_endian
>* relobj
7471 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
7472 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
7473 p
!= this->stub_tables_
.end();
7476 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
7478 if (off
!= invalid_address
)
7479 return (*p
)->stub_address() + off
;
7485 // Return the PLT address to use for a global symbol.
7486 template<int size
, bool big_endian
>
7488 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
7489 const Symbol
* gsym
) const
7493 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
7494 p
!= this->stub_tables_
.end();
7497 Address off
= (*p
)->find_plt_call_entry(gsym
);
7498 if (off
!= invalid_address
)
7499 return (*p
)->stub_address() + off
;
7505 // Return the offset to use for the GOT_INDX'th got entry which is
7506 // for a local tls symbol specified by OBJECT, SYMNDX.
7507 template<int size
, bool big_endian
>
7509 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
7510 const Relobj
* object
,
7511 unsigned int symndx
,
7512 unsigned int got_indx
) const
7514 const Powerpc_relobj
<size
, big_endian
>* ppc_object
7515 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
7516 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
7518 for (Got_type got_type
= GOT_TYPE_TLSGD
;
7519 got_type
<= GOT_TYPE_TPREL
;
7520 got_type
= Got_type(got_type
+ 1))
7521 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
7523 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
7524 if (got_type
== GOT_TYPE_TLSGD
)
7526 if (off
== got_indx
* (size
/ 8))
7528 if (got_type
== GOT_TYPE_TPREL
)
7538 // Return the offset to use for the GOT_INDX'th got entry which is
7539 // for global tls symbol GSYM.
7540 template<int size
, bool big_endian
>
7542 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
7544 unsigned int got_indx
) const
7546 if (gsym
->type() == elfcpp::STT_TLS
)
7548 for (Got_type got_type
= GOT_TYPE_TLSGD
;
7549 got_type
<= GOT_TYPE_TPREL
;
7550 got_type
= Got_type(got_type
+ 1))
7551 if (gsym
->has_got_offset(got_type
))
7553 unsigned int off
= gsym
->got_offset(got_type
);
7554 if (got_type
== GOT_TYPE_TLSGD
)
7556 if (off
== got_indx
* (size
/ 8))
7558 if (got_type
== GOT_TYPE_TPREL
)
7568 // The selector for powerpc object files.
7570 template<int size
, bool big_endian
>
7571 class Target_selector_powerpc
: public Target_selector
7574 Target_selector_powerpc()
7575 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
7578 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
7579 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
7581 ? (big_endian
? "elf64ppc" : "elf64lppc")
7582 : (big_endian
? "elf32ppc" : "elf32lppc")))
7586 do_instantiate_target()
7587 { return new Target_powerpc
<size
, big_endian
>(); }
7590 Target_selector_powerpc
<32, true> target_selector_ppc32
;
7591 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
7592 Target_selector_powerpc
<64, true> target_selector_ppc64
;
7593 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
7595 // Instantiate these constants for -O0
7596 template<int size
, bool big_endian
>
7597 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
7598 template<int size
, bool big_endian
>
7599 const typename Stub_table
<size
, big_endian
>::Address
7600 Stub_table
<size
, big_endian
>::invalid_address
;
7601 template<int size
, bool big_endian
>
7602 const typename Target_powerpc
<size
, big_endian
>::Address
7603 Target_powerpc
<size
, big_endian
>::invalid_address
;
7605 } // End anonymous namespace.