1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2016 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
>
65 template<int size
, bool big_endian
>
66 class Output_data_save_res
;
68 template<int size
, bool big_endian
>
71 struct Stub_table_owner
73 Output_section
* output_section
;
74 const Output_section::Input_section
* owner
;
78 is_branch_reloc(unsigned int r_type
);
80 template<int size
, bool big_endian
>
81 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
84 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
85 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
86 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
88 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
89 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
90 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
91 special_(0), has_small_toc_reloc_(false), opd_valid_(false),
92 opd_ent_(), access_from_map_(), has14_(), stub_table_index_(),
93 e_flags_(ehdr
.get_e_flags()), st_other_()
95 this->set_abiversion(0);
101 // Read the symbols then set up st_other vector.
103 do_read_symbols(Read_symbols_data
*);
105 // The .got2 section shndx.
110 return this->special_
;
115 // The .opd section shndx.
122 return this->special_
;
125 // Init OPD entry arrays.
127 init_opd(size_t opd_size
)
129 size_t count
= this->opd_ent_ndx(opd_size
);
130 this->opd_ent_
.resize(count
);
133 // Return section and offset of function entry for .opd + R_OFF.
135 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
137 size_t ndx
= this->opd_ent_ndx(r_off
);
138 gold_assert(ndx
< this->opd_ent_
.size());
139 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
141 *value
= this->opd_ent_
[ndx
].off
;
142 return this->opd_ent_
[ndx
].shndx
;
145 // Set section and offset of function entry for .opd + R_OFF.
147 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
149 size_t ndx
= this->opd_ent_ndx(r_off
);
150 gold_assert(ndx
< this->opd_ent_
.size());
151 this->opd_ent_
[ndx
].shndx
= shndx
;
152 this->opd_ent_
[ndx
].off
= value
;
155 // Return discard flag for .opd + R_OFF.
157 get_opd_discard(Address r_off
) const
159 size_t ndx
= this->opd_ent_ndx(r_off
);
160 gold_assert(ndx
< this->opd_ent_
.size());
161 return this->opd_ent_
[ndx
].discard
;
164 // Set discard flag for .opd + R_OFF.
166 set_opd_discard(Address r_off
)
168 size_t ndx
= this->opd_ent_ndx(r_off
);
169 gold_assert(ndx
< this->opd_ent_
.size());
170 this->opd_ent_
[ndx
].discard
= true;
175 { return this->opd_valid_
; }
179 { this->opd_valid_
= true; }
181 // Examine .rela.opd to build info about function entry points.
183 scan_opd_relocs(size_t reloc_count
,
184 const unsigned char* prelocs
,
185 const unsigned char* plocal_syms
);
187 // Perform the Sized_relobj_file method, then set up opd info from
190 do_read_relocs(Read_relocs_data
*);
193 do_find_special_sections(Read_symbols_data
* sd
);
195 // Adjust this local symbol value. Return false if the symbol
196 // should be discarded from the output file.
198 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
200 if (size
== 64 && this->opd_shndx() != 0)
203 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
205 if (this->get_opd_discard(lv
->input_value()))
213 { return &this->access_from_map_
; }
215 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
216 // section at DST_OFF.
218 add_reference(Relobj
* src_obj
,
219 unsigned int src_indx
,
220 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
222 Section_id
src_id(src_obj
, src_indx
);
223 this->access_from_map_
[dst_off
].insert(src_id
);
226 // Add a reference to the code section specified by the .opd entry
229 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
231 size_t ndx
= this->opd_ent_ndx(dst_off
);
232 if (ndx
>= this->opd_ent_
.size())
233 this->opd_ent_
.resize(ndx
+ 1);
234 this->opd_ent_
[ndx
].gc_mark
= true;
238 process_gc_mark(Symbol_table
* symtab
)
240 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
241 if (this->opd_ent_
[i
].gc_mark
)
243 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
244 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
248 // Return offset in output GOT section that this object will use
249 // as a TOC pointer. Won't be just a constant with multi-toc support.
251 toc_base_offset() const
255 set_has_small_toc_reloc()
256 { has_small_toc_reloc_
= true; }
259 has_small_toc_reloc() const
260 { return has_small_toc_reloc_
; }
263 set_has_14bit_branch(unsigned int shndx
)
265 if (shndx
>= this->has14_
.size())
266 this->has14_
.resize(shndx
+ 1);
267 this->has14_
[shndx
] = true;
271 has_14bit_branch(unsigned int shndx
) const
272 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
275 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
277 if (shndx
>= this->stub_table_index_
.size())
278 this->stub_table_index_
.resize(shndx
+ 1);
279 this->stub_table_index_
[shndx
] = stub_index
;
282 Stub_table
<size
, big_endian
>*
283 stub_table(unsigned int shndx
)
285 if (shndx
< this->stub_table_index_
.size())
287 Target_powerpc
<size
, big_endian
>* target
288 = static_cast<Target_powerpc
<size
, big_endian
>*>(
289 parameters
->sized_target
<size
, big_endian
>());
290 unsigned int indx
= this->stub_table_index_
[shndx
];
291 gold_assert(indx
< target
->stub_tables().size());
292 return target
->stub_tables()[indx
];
300 this->stub_table_index_
.clear();
305 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
307 // Set ABI version for input and output
309 set_abiversion(int ver
);
312 ppc64_local_entry_offset(const Symbol
* sym
) const
313 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
316 ppc64_local_entry_offset(unsigned int symndx
) const
317 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
328 // Return index into opd_ent_ array for .opd entry at OFF.
329 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
330 // apart when the language doesn't use the last 8-byte word, the
331 // environment pointer. Thus dividing the entry section offset by
332 // 16 will give an index into opd_ent_ that works for either layout
333 // of .opd. (It leaves some elements of the vector unused when .opd
334 // entries are spaced 24 bytes apart, but we don't know the spacing
335 // until relocations are processed, and in any case it is possible
336 // for an object to have some entries spaced 16 bytes apart and
337 // others 24 bytes apart.)
339 opd_ent_ndx(size_t off
) const
342 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
343 unsigned int special_
;
345 // For 64-bit, whether this object uses small model relocs to access
347 bool has_small_toc_reloc_
;
349 // Set at the start of gc_process_relocs, when we know opd_ent_
350 // vector is valid. The flag could be made atomic and set in
351 // do_read_relocs with memory_order_release and then tested with
352 // memory_order_acquire, potentially resulting in fewer entries in
356 // The first 8-byte word of an OPD entry gives the address of the
357 // entry point of the function. Relocatable object files have a
358 // relocation on this word. The following vector records the
359 // section and offset specified by these relocations.
360 std::vector
<Opd_ent
> opd_ent_
;
362 // References made to this object's .opd section when running
363 // gc_process_relocs for another object, before the opd_ent_ vector
364 // is valid for this object.
365 Access_from access_from_map_
;
367 // Whether input section has a 14-bit branch reloc.
368 std::vector
<bool> has14_
;
370 // The stub table to use for a given input section.
371 std::vector
<unsigned int> stub_table_index_
;
374 elfcpp::Elf_Word e_flags_
;
376 // ELF st_other field for local symbols.
377 std::vector
<unsigned char> st_other_
;
380 template<int size
, bool big_endian
>
381 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
384 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
386 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
387 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
388 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
389 opd_shndx_(0), opd_ent_(), e_flags_(ehdr
.get_e_flags())
391 this->set_abiversion(0);
397 // Call Sized_dynobj::do_read_symbols to read the symbols then
398 // read .opd from a dynamic object, filling in opd_ent_ vector,
400 do_read_symbols(Read_symbols_data
*);
402 // The .opd section shndx.
406 return this->opd_shndx_
;
409 // The .opd section address.
413 return this->opd_address_
;
416 // Init OPD entry arrays.
418 init_opd(size_t opd_size
)
420 size_t count
= this->opd_ent_ndx(opd_size
);
421 this->opd_ent_
.resize(count
);
424 // Return section and offset of function entry for .opd + R_OFF.
426 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
428 size_t ndx
= this->opd_ent_ndx(r_off
);
429 gold_assert(ndx
< this->opd_ent_
.size());
430 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
432 *value
= this->opd_ent_
[ndx
].off
;
433 return this->opd_ent_
[ndx
].shndx
;
436 // Set section and offset of function entry for .opd + R_OFF.
438 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
440 size_t ndx
= this->opd_ent_ndx(r_off
);
441 gold_assert(ndx
< this->opd_ent_
.size());
442 this->opd_ent_
[ndx
].shndx
= shndx
;
443 this->opd_ent_
[ndx
].off
= value
;
448 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
450 // Set ABI version for input and output.
452 set_abiversion(int ver
);
455 // Used to specify extent of executable sections.
458 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
459 : start(start_
), len(len_
), shndx(shndx_
)
463 operator<(const Sec_info
& that
) const
464 { return this->start
< that
.start
; }
477 // Return index into opd_ent_ array for .opd entry at OFF.
479 opd_ent_ndx(size_t off
) const
482 // For 64-bit the .opd section shndx and address.
483 unsigned int opd_shndx_
;
484 Address opd_address_
;
486 // The first 8-byte word of an OPD entry gives the address of the
487 // entry point of the function. Records the section and offset
488 // corresponding to the address. Note that in dynamic objects,
489 // offset is *not* relative to the section.
490 std::vector
<Opd_ent
> opd_ent_
;
493 elfcpp::Elf_Word e_flags_
;
496 template<int size
, bool big_endian
>
497 class Target_powerpc
: public Sized_target
<size
, big_endian
>
501 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
502 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
503 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
504 static const Address invalid_address
= static_cast<Address
>(0) - 1;
505 // Offset of tp and dtp pointers from start of TLS block.
506 static const Address tp_offset
= 0x7000;
507 static const Address dtp_offset
= 0x8000;
510 : Sized_target
<size
, big_endian
>(&powerpc_info
),
511 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
512 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
513 tlsld_got_offset_(-1U),
514 stub_tables_(), branch_lookup_table_(), branch_info_(),
515 plt_thread_safe_(false), relax_failed_(false), relax_fail_count_(0),
516 stub_group_size_(0), savres_section_(0)
520 // Process the relocations to determine unreferenced sections for
521 // garbage collection.
523 gc_process_relocs(Symbol_table
* symtab
,
525 Sized_relobj_file
<size
, big_endian
>* object
,
526 unsigned int data_shndx
,
527 unsigned int sh_type
,
528 const unsigned char* prelocs
,
530 Output_section
* output_section
,
531 bool needs_special_offset_handling
,
532 size_t local_symbol_count
,
533 const unsigned char* plocal_symbols
);
535 // Scan the relocations to look for symbol adjustments.
537 scan_relocs(Symbol_table
* symtab
,
539 Sized_relobj_file
<size
, big_endian
>* object
,
540 unsigned int data_shndx
,
541 unsigned int sh_type
,
542 const unsigned char* prelocs
,
544 Output_section
* output_section
,
545 bool needs_special_offset_handling
,
546 size_t local_symbol_count
,
547 const unsigned char* plocal_symbols
);
549 // Map input .toc section to output .got section.
551 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
553 if (size
== 64 && strcmp(name
, ".toc") == 0)
561 // Provide linker defined save/restore functions.
563 define_save_restore_funcs(Layout
*, Symbol_table
*);
565 // No stubs unless a final link.
568 { return !parameters
->options().relocatable(); }
571 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
574 do_plt_fde_location(const Output_data
*, unsigned char*,
575 uint64_t*, off_t
*) const;
577 // Stash info about branches, for stub generation.
579 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
580 unsigned int data_shndx
, Address r_offset
,
581 unsigned int r_type
, unsigned int r_sym
, Address addend
)
583 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
584 this->branch_info_
.push_back(info
);
585 if (r_type
== elfcpp::R_POWERPC_REL14
586 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
587 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
588 ppc_object
->set_has_14bit_branch(data_shndx
);
592 do_define_standard_symbols(Symbol_table
*, Layout
*);
594 // Finalize the sections.
596 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
598 // Return the value to use for a dynamic which requires special
601 do_dynsym_value(const Symbol
*) const;
603 // Return the PLT address to use for a local symbol.
605 do_plt_address_for_local(const Relobj
*, unsigned int) const;
607 // Return the PLT address to use for a global symbol.
609 do_plt_address_for_global(const Symbol
*) const;
611 // Return the offset to use for the GOT_INDX'th got entry which is
612 // for a local tls symbol specified by OBJECT, SYMNDX.
614 do_tls_offset_for_local(const Relobj
* object
,
616 unsigned int got_indx
) const;
618 // Return the offset to use for the GOT_INDX'th got entry which is
619 // for global tls symbol GSYM.
621 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
624 do_function_location(Symbol_location
*) const;
627 do_can_check_for_function_pointers() const
630 // Adjust -fsplit-stack code which calls non-split-stack code.
632 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
633 section_offset_type fnoffset
, section_size_type fnsize
,
634 const unsigned char* prelocs
, size_t reloc_count
,
635 unsigned char* view
, section_size_type view_size
,
636 std::string
* from
, std::string
* to
) const;
638 // Relocate a section.
640 relocate_section(const Relocate_info
<size
, big_endian
>*,
641 unsigned int sh_type
,
642 const unsigned char* prelocs
,
644 Output_section
* output_section
,
645 bool needs_special_offset_handling
,
647 Address view_address
,
648 section_size_type view_size
,
649 const Reloc_symbol_changes
*);
651 // Scan the relocs during a relocatable link.
653 scan_relocatable_relocs(Symbol_table
* symtab
,
655 Sized_relobj_file
<size
, big_endian
>* object
,
656 unsigned int data_shndx
,
657 unsigned int sh_type
,
658 const unsigned char* prelocs
,
660 Output_section
* output_section
,
661 bool needs_special_offset_handling
,
662 size_t local_symbol_count
,
663 const unsigned char* plocal_symbols
,
664 Relocatable_relocs
*);
666 // Scan the relocs for --emit-relocs.
668 emit_relocs_scan(Symbol_table
* symtab
,
670 Sized_relobj_file
<size
, big_endian
>* object
,
671 unsigned int data_shndx
,
672 unsigned int sh_type
,
673 const unsigned char* prelocs
,
675 Output_section
* output_section
,
676 bool needs_special_offset_handling
,
677 size_t local_symbol_count
,
678 const unsigned char* plocal_syms
,
679 Relocatable_relocs
* rr
);
681 // Emit relocations for a section.
683 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
684 unsigned int sh_type
,
685 const unsigned char* prelocs
,
687 Output_section
* output_section
,
688 typename
elfcpp::Elf_types
<size
>::Elf_Off
689 offset_in_output_section
,
691 Address view_address
,
693 unsigned char* reloc_view
,
694 section_size_type reloc_view_size
);
696 // Return whether SYM is defined by the ABI.
698 do_is_defined_by_abi(const Symbol
* sym
) const
700 return strcmp(sym
->name(), "__tls_get_addr") == 0;
703 // Return the size of the GOT section.
707 gold_assert(this->got_
!= NULL
);
708 return this->got_
->data_size();
711 // Get the PLT section.
712 const Output_data_plt_powerpc
<size
, big_endian
>*
715 gold_assert(this->plt_
!= NULL
);
719 // Get the IPLT section.
720 const Output_data_plt_powerpc
<size
, big_endian
>*
723 gold_assert(this->iplt_
!= NULL
);
727 // Get the .glink section.
728 const Output_data_glink
<size
, big_endian
>*
729 glink_section() const
731 gold_assert(this->glink_
!= NULL
);
735 Output_data_glink
<size
, big_endian
>*
738 gold_assert(this->glink_
!= NULL
);
742 bool has_glink() const
743 { return this->glink_
!= NULL
; }
745 // Get the GOT section.
746 const Output_data_got_powerpc
<size
, big_endian
>*
749 gold_assert(this->got_
!= NULL
);
753 // Get the GOT section, creating it if necessary.
754 Output_data_got_powerpc
<size
, big_endian
>*
755 got_section(Symbol_table
*, Layout
*);
758 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
759 const elfcpp::Ehdr
<size
, big_endian
>&);
761 // Return the number of entries in the GOT.
763 got_entry_count() const
765 if (this->got_
== NULL
)
767 return this->got_size() / (size
/ 8);
770 // Return the number of entries in the PLT.
772 plt_entry_count() const;
774 // Return the offset of the first non-reserved PLT entry.
776 first_plt_entry_offset() const
780 if (this->abiversion() >= 2)
785 // Return the size of each PLT entry.
787 plt_entry_size() const
791 if (this->abiversion() >= 2)
796 Output_data_save_res
<size
, big_endian
>*
797 savres_section() const
799 return this->savres_section_
;
802 // Add any special sections for this symbol to the gc work list.
803 // For powerpc64, this adds the code section of a function
806 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
808 // Handle target specific gc actions when adding a gc reference from
809 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
810 // and DST_OFF. For powerpc64, this adds a referenc to the code
811 // section of a function descriptor.
813 do_gc_add_reference(Symbol_table
* symtab
,
815 unsigned int src_shndx
,
817 unsigned int dst_shndx
,
818 Address dst_off
) const;
820 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
823 { return this->stub_tables_
; }
825 const Output_data_brlt_powerpc
<size
, big_endian
>*
827 { return this->brlt_section_
; }
830 add_branch_lookup_table(Address to
)
832 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
833 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
837 find_branch_lookup_table(Address to
)
839 typename
Branch_lookup_table::const_iterator p
840 = this->branch_lookup_table_
.find(to
);
841 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
845 write_branch_lookup_table(unsigned char *oview
)
847 for (typename
Branch_lookup_table::const_iterator p
848 = this->branch_lookup_table_
.begin();
849 p
!= this->branch_lookup_table_
.end();
852 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
857 plt_thread_safe() const
858 { return this->plt_thread_safe_
; }
862 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
865 set_abiversion (int ver
)
867 elfcpp::Elf_Word flags
= this->processor_specific_flags();
868 flags
&= ~elfcpp::EF_PPC64_ABI
;
869 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
870 this->set_processor_specific_flags(flags
);
873 // Offset to to save stack slot
876 { return this->abiversion() < 2 ? 40 : 24; }
892 : tls_get_addr_(NOT_EXPECTED
),
893 relinfo_(NULL
), relnum_(0), r_offset_(0)
898 if (this->tls_get_addr_
!= NOT_EXPECTED
)
905 if (this->relinfo_
!= NULL
)
906 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
907 _("missing expected __tls_get_addr call"));
911 expect_tls_get_addr_call(
912 const Relocate_info
<size
, big_endian
>* relinfo
,
916 this->tls_get_addr_
= EXPECTED
;
917 this->relinfo_
= relinfo
;
918 this->relnum_
= relnum
;
919 this->r_offset_
= r_offset
;
923 expect_tls_get_addr_call()
924 { this->tls_get_addr_
= EXPECTED
; }
927 skip_next_tls_get_addr_call()
928 {this->tls_get_addr_
= SKIP
; }
931 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
933 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
934 || r_type
== elfcpp::R_PPC_PLTREL24
)
936 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
937 Tls_get_addr last_tls
= this->tls_get_addr_
;
938 this->tls_get_addr_
= NOT_EXPECTED
;
939 if (is_tls_call
&& last_tls
!= EXPECTED
)
941 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
950 // What we're up to regarding calls to __tls_get_addr.
951 // On powerpc, the branch and link insn making a call to
952 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
953 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
954 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
955 // The marker relocation always comes first, and has the same
956 // symbol as the reloc on the insn setting up the __tls_get_addr
957 // argument. This ties the arg setup insn with the call insn,
958 // allowing ld to safely optimize away the call. We check that
959 // every call to __tls_get_addr has a marker relocation, and that
960 // every marker relocation is on a call to __tls_get_addr.
961 Tls_get_addr tls_get_addr_
;
962 // Info about the last reloc for error message.
963 const Relocate_info
<size
, big_endian
>* relinfo_
;
968 // The class which scans relocations.
969 class Scan
: protected Track_tls
972 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
975 : Track_tls(), issued_non_pic_error_(false)
979 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
982 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
983 Sized_relobj_file
<size
, big_endian
>* object
,
984 unsigned int data_shndx
,
985 Output_section
* output_section
,
986 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
987 const elfcpp::Sym
<size
, big_endian
>& lsym
,
991 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
992 Sized_relobj_file
<size
, big_endian
>* object
,
993 unsigned int data_shndx
,
994 Output_section
* output_section
,
995 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
999 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1001 Sized_relobj_file
<size
, big_endian
>* relobj
,
1004 const elfcpp::Rela
<size
, big_endian
>& ,
1005 unsigned int r_type
,
1006 const elfcpp::Sym
<size
, big_endian
>&)
1008 // PowerPC64 .opd is not folded, so any identical function text
1009 // may be folded and we'll still keep function addresses distinct.
1010 // That means no reloc is of concern here.
1013 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1014 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1015 if (ppcobj
->abiversion() == 1)
1018 // For 32-bit and ELFv2, conservatively assume anything but calls to
1019 // function code might be taking the address of the function.
1020 return !is_branch_reloc(r_type
);
1024 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1026 Sized_relobj_file
<size
, big_endian
>* relobj
,
1029 const elfcpp::Rela
<size
, big_endian
>& ,
1030 unsigned int r_type
,
1036 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1037 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1038 if (ppcobj
->abiversion() == 1)
1041 return !is_branch_reloc(r_type
);
1045 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1046 Sized_relobj_file
<size
, big_endian
>* object
,
1047 unsigned int r_type
, bool report_err
);
1051 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1052 unsigned int r_type
);
1055 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1056 unsigned int r_type
, Symbol
*);
1059 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1060 Target_powerpc
* target
);
1063 check_non_pic(Relobj
*, unsigned int r_type
);
1065 // Whether we have issued an error about a non-PIC compilation.
1066 bool issued_non_pic_error_
;
1070 symval_for_branch(const Symbol_table
* symtab
,
1071 const Sized_symbol
<size
>* gsym
,
1072 Powerpc_relobj
<size
, big_endian
>* object
,
1073 Address
*value
, unsigned int *dest_shndx
);
1075 // The class which implements relocation.
1076 class Relocate
: protected Track_tls
1079 // Use 'at' branch hints when true, 'y' when false.
1080 // FIXME maybe: set this with an option.
1081 static const bool is_isa_v2
= true;
1087 // Do a relocation. Return false if the caller should not issue
1088 // any warnings about this relocation.
1090 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1091 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1092 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1093 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1097 class Relocate_comdat_behavior
1100 // Decide what the linker should do for relocations that refer to
1101 // discarded comdat sections.
1102 inline Comdat_behavior
1103 get(const char* name
)
1105 gold::Default_comdat_behavior default_behavior
;
1106 Comdat_behavior ret
= default_behavior
.get(name
);
1107 if (ret
== CB_WARNING
)
1110 && (strcmp(name
, ".fixup") == 0
1111 || strcmp(name
, ".got2") == 0))
1114 && (strcmp(name
, ".opd") == 0
1115 || strcmp(name
, ".toc") == 0
1116 || strcmp(name
, ".toc1") == 0))
1123 // Optimize the TLS relocation type based on what we know about the
1124 // symbol. IS_FINAL is true if the final address of this symbol is
1125 // known at link time.
1127 tls::Tls_optimization
1128 optimize_tls_gd(bool is_final
)
1130 // If we are generating a shared library, then we can't do anything
1132 if (parameters
->options().shared())
1133 return tls::TLSOPT_NONE
;
1136 return tls::TLSOPT_TO_IE
;
1137 return tls::TLSOPT_TO_LE
;
1140 tls::Tls_optimization
1143 if (parameters
->options().shared())
1144 return tls::TLSOPT_NONE
;
1146 return tls::TLSOPT_TO_LE
;
1149 tls::Tls_optimization
1150 optimize_tls_ie(bool is_final
)
1152 if (!is_final
|| parameters
->options().shared())
1153 return tls::TLSOPT_NONE
;
1155 return tls::TLSOPT_TO_LE
;
1160 make_glink_section(Layout
*);
1162 // Create the PLT section.
1164 make_plt_section(Symbol_table
*, Layout
*);
1167 make_iplt_section(Symbol_table
*, Layout
*);
1170 make_brlt_section(Layout
*);
1172 // Create a PLT entry for a global symbol.
1174 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1176 // Create a PLT entry for a local IFUNC symbol.
1178 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1179 Sized_relobj_file
<size
, big_endian
>*,
1183 // Create a GOT entry for local dynamic __tls_get_addr.
1185 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1186 Sized_relobj_file
<size
, big_endian
>* object
);
1189 tlsld_got_offset() const
1191 return this->tlsld_got_offset_
;
1194 // Get the dynamic reloc section, creating it if necessary.
1196 rela_dyn_section(Layout
*);
1198 // Similarly, but for ifunc symbols get the one for ifunc.
1200 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1202 // Copy a relocation against a global symbol.
1204 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1205 Sized_relobj_file
<size
, big_endian
>* object
,
1206 unsigned int shndx
, Output_section
* output_section
,
1207 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1209 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1210 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1211 symtab
->get_sized_symbol
<size
>(sym
),
1212 object
, shndx
, output_section
,
1213 r_type
, reloc
.get_r_offset(),
1214 reloc
.get_r_addend(),
1215 this->rela_dyn_section(layout
));
1218 // Look over all the input sections, deciding where to place stubs.
1220 group_sections(Layout
*, const Task
*, bool);
1222 // Sort output sections by address.
1223 struct Sort_sections
1226 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1227 { return sec1
->address() < sec2
->address(); }
1233 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1234 unsigned int data_shndx
,
1236 unsigned int r_type
,
1239 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1240 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1246 // If this branch needs a plt call stub, or a long branch stub, make one.
1248 make_stub(Stub_table
<size
, big_endian
>*,
1249 Stub_table
<size
, big_endian
>*,
1250 Symbol_table
*) const;
1253 // The branch location..
1254 Powerpc_relobj
<size
, big_endian
>* object_
;
1255 unsigned int shndx_
;
1257 // ..and the branch type and destination.
1258 unsigned int r_type_
;
1259 unsigned int r_sym_
;
1263 // Information about this specific target which we pass to the
1264 // general Target structure.
1265 static Target::Target_info powerpc_info
;
1267 // The types of GOT entries needed for this platform.
1268 // These values are exposed to the ABI in an incremental link.
1269 // Do not renumber existing values without changing the version
1270 // number of the .gnu_incremental_inputs section.
1274 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1275 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1276 GOT_TYPE_TPREL
// entry for @got@tprel
1280 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1281 // The PLT section. This is a container for a table of addresses,
1282 // and their relocations. Each address in the PLT has a dynamic
1283 // relocation (R_*_JMP_SLOT) and each address will have a
1284 // corresponding entry in .glink for lazy resolution of the PLT.
1285 // ppc32 initialises the PLT to point at the .glink entry, while
1286 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1287 // linker adds a stub that loads the PLT entry into ctr then
1288 // branches to ctr. There may be more than one stub for each PLT
1289 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1290 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1291 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1292 // The IPLT section. Like plt_, this is a container for a table of
1293 // addresses and their relocations, specifically for STT_GNU_IFUNC
1294 // functions that resolve locally (STT_GNU_IFUNC functions that
1295 // don't resolve locally go in PLT). Unlike plt_, these have no
1296 // entry in .glink for lazy resolution, and the relocation section
1297 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1298 // the relocation section may contain relocations against
1299 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1300 // relocation section will appear at the end of other dynamic
1301 // relocations, so that ld.so applies these relocations after other
1302 // dynamic relocations. In a static executable, the relocation
1303 // section is emitted and marked with __rela_iplt_start and
1304 // __rela_iplt_end symbols.
1305 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1306 // Section holding long branch destinations.
1307 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1308 // The .glink section.
1309 Output_data_glink
<size
, big_endian
>* glink_
;
1310 // The dynamic reloc section.
1311 Reloc_section
* rela_dyn_
;
1312 // Relocs saved to avoid a COPY reloc.
1313 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1314 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1315 unsigned int tlsld_got_offset_
;
1317 Stub_tables stub_tables_
;
1318 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1319 Branch_lookup_table branch_lookup_table_
;
1321 typedef std::vector
<Branch_info
> Branches
;
1322 Branches branch_info_
;
1324 bool plt_thread_safe_
;
1327 int relax_fail_count_
;
1328 int32_t stub_group_size_
;
1330 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1334 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1337 true, // is_big_endian
1338 elfcpp::EM_PPC
, // machine_code
1339 false, // has_make_symbol
1340 false, // has_resolve
1341 false, // has_code_fill
1342 true, // is_default_stack_executable
1343 false, // can_icf_inline_merge_sections
1345 "/usr/lib/ld.so.1", // dynamic_linker
1346 0x10000000, // default_text_segment_address
1347 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1348 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1349 false, // isolate_execinstr
1351 elfcpp::SHN_UNDEF
, // small_common_shndx
1352 elfcpp::SHN_UNDEF
, // large_common_shndx
1353 0, // small_common_section_flags
1354 0, // large_common_section_flags
1355 NULL
, // attributes_section
1356 NULL
, // attributes_vendor
1357 "_start", // entry_symbol_name
1358 32, // hash_entry_size
1362 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1365 false, // is_big_endian
1366 elfcpp::EM_PPC
, // machine_code
1367 false, // has_make_symbol
1368 false, // has_resolve
1369 false, // has_code_fill
1370 true, // is_default_stack_executable
1371 false, // can_icf_inline_merge_sections
1373 "/usr/lib/ld.so.1", // dynamic_linker
1374 0x10000000, // default_text_segment_address
1375 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1376 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1377 false, // isolate_execinstr
1379 elfcpp::SHN_UNDEF
, // small_common_shndx
1380 elfcpp::SHN_UNDEF
, // large_common_shndx
1381 0, // small_common_section_flags
1382 0, // large_common_section_flags
1383 NULL
, // attributes_section
1384 NULL
, // attributes_vendor
1385 "_start", // entry_symbol_name
1386 32, // hash_entry_size
1390 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1393 true, // is_big_endian
1394 elfcpp::EM_PPC64
, // machine_code
1395 false, // has_make_symbol
1396 false, // has_resolve
1397 false, // has_code_fill
1398 true, // is_default_stack_executable
1399 false, // can_icf_inline_merge_sections
1401 "/usr/lib/ld.so.1", // dynamic_linker
1402 0x10000000, // default_text_segment_address
1403 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1404 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1405 false, // isolate_execinstr
1407 elfcpp::SHN_UNDEF
, // small_common_shndx
1408 elfcpp::SHN_UNDEF
, // large_common_shndx
1409 0, // small_common_section_flags
1410 0, // large_common_section_flags
1411 NULL
, // attributes_section
1412 NULL
, // attributes_vendor
1413 "_start", // entry_symbol_name
1414 32, // hash_entry_size
1418 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1421 false, // is_big_endian
1422 elfcpp::EM_PPC64
, // machine_code
1423 false, // has_make_symbol
1424 false, // has_resolve
1425 false, // has_code_fill
1426 true, // is_default_stack_executable
1427 false, // can_icf_inline_merge_sections
1429 "/usr/lib/ld.so.1", // dynamic_linker
1430 0x10000000, // default_text_segment_address
1431 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1432 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1433 false, // isolate_execinstr
1435 elfcpp::SHN_UNDEF
, // small_common_shndx
1436 elfcpp::SHN_UNDEF
, // large_common_shndx
1437 0, // small_common_section_flags
1438 0, // large_common_section_flags
1439 NULL
, // attributes_section
1440 NULL
, // attributes_vendor
1441 "_start", // entry_symbol_name
1442 32, // hash_entry_size
1446 is_branch_reloc(unsigned int r_type
)
1448 return (r_type
== elfcpp::R_POWERPC_REL24
1449 || r_type
== elfcpp::R_PPC_PLTREL24
1450 || r_type
== elfcpp::R_PPC_LOCAL24PC
1451 || r_type
== elfcpp::R_POWERPC_REL14
1452 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1453 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1454 || r_type
== elfcpp::R_POWERPC_ADDR24
1455 || r_type
== elfcpp::R_POWERPC_ADDR14
1456 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1457 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1460 // If INSN is an opcode that may be used with an @tls operand, return
1461 // the transformed insn for TLS optimisation, otherwise return 0. If
1462 // REG is non-zero only match an insn with RB or RA equal to REG.
1464 at_tls_transform(uint32_t insn
, unsigned int reg
)
1466 if ((insn
& (0x3f << 26)) != 31 << 26)
1470 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1471 rtra
= insn
& ((1 << 26) - (1 << 16));
1472 else if (((insn
>> 16) & 0x1f) == reg
)
1473 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1477 if ((insn
& (0x3ff << 1)) == 266 << 1)
1480 else if ((insn
& (0x1f << 1)) == 23 << 1
1481 && ((insn
& (0x1f << 6)) < 14 << 6
1482 || ((insn
& (0x1f << 6)) >= 16 << 6
1483 && (insn
& (0x1f << 6)) < 24 << 6)))
1484 // load and store indexed -> dform
1485 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1486 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1487 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1488 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1489 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1491 insn
= (58 << 26) | 2;
1499 template<int size
, bool big_endian
>
1500 class Powerpc_relocate_functions
1520 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1521 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1522 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1524 template<int valsize
>
1526 has_overflow_signed(Address value
)
1528 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1529 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1530 limit
<<= ((valsize
- 1) >> 1);
1531 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1532 return value
+ limit
> (limit
<< 1) - 1;
1535 template<int valsize
>
1537 has_overflow_unsigned(Address value
)
1539 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1540 limit
<<= ((valsize
- 1) >> 1);
1541 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1542 return value
> (limit
<< 1) - 1;
1545 template<int valsize
>
1547 has_overflow_bitfield(Address value
)
1549 return (has_overflow_unsigned
<valsize
>(value
)
1550 && has_overflow_signed
<valsize
>(value
));
1553 template<int valsize
>
1554 static inline Status
1555 overflowed(Address value
, Overflow_check overflow
)
1557 if (overflow
== CHECK_SIGNED
)
1559 if (has_overflow_signed
<valsize
>(value
))
1560 return STATUS_OVERFLOW
;
1562 else if (overflow
== CHECK_UNSIGNED
)
1564 if (has_overflow_unsigned
<valsize
>(value
))
1565 return STATUS_OVERFLOW
;
1567 else if (overflow
== CHECK_BITFIELD
)
1569 if (has_overflow_bitfield
<valsize
>(value
))
1570 return STATUS_OVERFLOW
;
1575 // Do a simple RELA relocation
1576 template<int fieldsize
, int valsize
>
1577 static inline Status
1578 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1580 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1581 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1582 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1583 return overflowed
<valsize
>(value
, overflow
);
1586 template<int fieldsize
, int valsize
>
1587 static inline Status
1588 rela(unsigned char* view
,
1589 unsigned int right_shift
,
1590 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1592 Overflow_check overflow
)
1594 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1595 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1596 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1597 Valtype reloc
= value
>> right_shift
;
1600 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1601 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1604 // Do a simple RELA relocation, unaligned.
1605 template<int fieldsize
, int valsize
>
1606 static inline Status
1607 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1609 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1610 return overflowed
<valsize
>(value
, overflow
);
1613 template<int fieldsize
, int valsize
>
1614 static inline Status
1615 rela_ua(unsigned char* view
,
1616 unsigned int right_shift
,
1617 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1619 Overflow_check overflow
)
1621 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
1623 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
1624 Valtype reloc
= value
>> right_shift
;
1627 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
1628 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1632 // R_PPC64_ADDR64: (Symbol + Addend)
1634 addr64(unsigned char* view
, Address value
)
1635 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
1637 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1639 addr64_u(unsigned char* view
, Address value
)
1640 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
1642 // R_POWERPC_ADDR32: (Symbol + Addend)
1643 static inline Status
1644 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1645 { return This::template rela
<32,32>(view
, value
, overflow
); }
1647 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1648 static inline Status
1649 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1650 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
1652 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1653 static inline Status
1654 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1656 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
1658 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1659 stat
= STATUS_OVERFLOW
;
1663 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1664 static inline Status
1665 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1666 { return This::template rela
<16,16>(view
, value
, overflow
); }
1668 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1669 static inline Status
1670 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1671 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
1673 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1674 static inline Status
1675 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1677 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
1678 if ((value
& 3) != 0)
1679 stat
= STATUS_OVERFLOW
;
1683 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
1684 static inline Status
1685 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
1687 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
1688 if ((value
& 15) != 0)
1689 stat
= STATUS_OVERFLOW
;
1693 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1695 addr16_hi(unsigned char* view
, Address value
)
1696 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1698 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1700 addr16_ha(unsigned char* view
, Address value
)
1701 { This::addr16_hi(view
, value
+ 0x8000); }
1703 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1705 addr16_hi2(unsigned char* view
, Address value
)
1706 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1708 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1710 addr16_ha2(unsigned char* view
, Address value
)
1711 { This::addr16_hi2(view
, value
+ 0x8000); }
1713 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1715 addr16_hi3(unsigned char* view
, Address value
)
1716 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1718 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1720 addr16_ha3(unsigned char* view
, Address value
)
1721 { This::addr16_hi3(view
, value
+ 0x8000); }
1723 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1724 static inline Status
1725 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1727 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
1728 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1729 stat
= STATUS_OVERFLOW
;
1733 // R_POWERPC_REL16DX_HA
1734 static inline Status
1735 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
1737 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1738 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1739 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1741 value
= static_cast<SignedAddress
>(value
) >> 16;
1742 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1743 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
1744 return overflowed
<16>(value
, overflow
);
1748 // Set ABI version for input and output.
1750 template<int size
, bool big_endian
>
1752 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
1754 this->e_flags_
|= ver
;
1755 if (this->abiversion() != 0)
1757 Target_powerpc
<size
, big_endian
>* target
=
1758 static_cast<Target_powerpc
<size
, big_endian
>*>(
1759 parameters
->sized_target
<size
, big_endian
>());
1760 if (target
->abiversion() == 0)
1761 target
->set_abiversion(this->abiversion());
1762 else if (target
->abiversion() != this->abiversion())
1763 gold_error(_("%s: ABI version %d is not compatible "
1764 "with ABI version %d output"),
1765 this->name().c_str(),
1766 this->abiversion(), target
->abiversion());
1771 // Stash away the index of .got2 or .opd in a relocatable object, if
1772 // such a section exists.
1774 template<int size
, bool big_endian
>
1776 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1777 Read_symbols_data
* sd
)
1779 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1780 const unsigned char* namesu
= sd
->section_names
->data();
1781 const char* names
= reinterpret_cast<const char*>(namesu
);
1782 section_size_type names_size
= sd
->section_names_size
;
1783 const unsigned char* s
;
1785 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1786 size
== 32 ? ".got2" : ".opd",
1787 names
, names_size
, NULL
);
1790 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1791 this->special_
= ndx
;
1794 if (this->abiversion() == 0)
1795 this->set_abiversion(1);
1796 else if (this->abiversion() > 1)
1797 gold_error(_("%s: .opd invalid in abiv%d"),
1798 this->name().c_str(), this->abiversion());
1801 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1804 // Examine .rela.opd to build info about function entry points.
1806 template<int size
, bool big_endian
>
1808 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1810 const unsigned char* prelocs
,
1811 const unsigned char* plocal_syms
)
1815 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1817 const int reloc_size
1818 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1819 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1820 Address expected_off
= 0;
1821 bool regular
= true;
1822 unsigned int opd_ent_size
= 0;
1824 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1826 Reltype
reloc(prelocs
);
1827 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1828 = reloc
.get_r_info();
1829 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1830 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1832 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1833 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1836 if (r_sym
< this->local_symbol_count())
1838 typename
elfcpp::Sym
<size
, big_endian
>
1839 lsym(plocal_syms
+ r_sym
* sym_size
);
1840 shndx
= lsym
.get_st_shndx();
1841 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1842 value
= lsym
.get_st_value();
1845 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1847 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1848 value
+ reloc
.get_r_addend());
1851 expected_off
= reloc
.get_r_offset();
1852 opd_ent_size
= expected_off
;
1854 else if (expected_off
!= reloc
.get_r_offset())
1856 expected_off
+= opd_ent_size
;
1858 else if (r_type
== elfcpp::R_PPC64_TOC
)
1860 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1865 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1866 this->name().c_str(), r_type
);
1870 if (reloc_count
<= 2)
1871 opd_ent_size
= this->section_size(this->opd_shndx());
1872 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1876 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1877 this->name().c_str());
1883 template<int size
, bool big_endian
>
1885 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1887 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1890 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1891 p
!= rd
->relocs
.end();
1894 if (p
->data_shndx
== this->opd_shndx())
1896 uint64_t opd_size
= this->section_size(this->opd_shndx());
1897 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1900 this->init_opd(opd_size
);
1901 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1902 rd
->local_symbols
->data());
1910 // Read the symbols then set up st_other vector.
1912 template<int size
, bool big_endian
>
1914 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1916 this->base_read_symbols(sd
);
1919 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1920 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1921 const unsigned int loccount
= this->do_local_symbol_count();
1924 this->st_other_
.resize(loccount
);
1925 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1926 off_t locsize
= loccount
* sym_size
;
1927 const unsigned int symtab_shndx
= this->symtab_shndx();
1928 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
1929 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
1930 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
1931 locsize
, true, false);
1933 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
1935 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
1936 unsigned char st_other
= sym
.get_st_other();
1937 this->st_other_
[i
] = st_other
;
1938 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1940 if (this->abiversion() == 0)
1941 this->set_abiversion(2);
1942 else if (this->abiversion() < 2)
1943 gold_error(_("%s: local symbol %d has invalid st_other"
1944 " for ABI version 1"),
1945 this->name().c_str(), i
);
1952 template<int size
, bool big_endian
>
1954 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
1956 this->e_flags_
|= ver
;
1957 if (this->abiversion() != 0)
1959 Target_powerpc
<size
, big_endian
>* target
=
1960 static_cast<Target_powerpc
<size
, big_endian
>*>(
1961 parameters
->sized_target
<size
, big_endian
>());
1962 if (target
->abiversion() == 0)
1963 target
->set_abiversion(this->abiversion());
1964 else if (target
->abiversion() != this->abiversion())
1965 gold_error(_("%s: ABI version %d is not compatible "
1966 "with ABI version %d output"),
1967 this->name().c_str(),
1968 this->abiversion(), target
->abiversion());
1973 // Call Sized_dynobj::base_read_symbols to read the symbols then
1974 // read .opd from a dynamic object, filling in opd_ent_ vector,
1976 template<int size
, bool big_endian
>
1978 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1980 this->base_read_symbols(sd
);
1983 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1984 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1985 const unsigned char* namesu
= sd
->section_names
->data();
1986 const char* names
= reinterpret_cast<const char*>(namesu
);
1987 const unsigned char* s
= NULL
;
1988 const unsigned char* opd
;
1989 section_size_type opd_size
;
1991 // Find and read .opd section.
1994 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1995 sd
->section_names_size
,
2000 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2001 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2002 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2004 if (this->abiversion() == 0)
2005 this->set_abiversion(1);
2006 else if (this->abiversion() > 1)
2007 gold_error(_("%s: .opd invalid in abiv%d"),
2008 this->name().c_str(), this->abiversion());
2010 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2011 this->opd_address_
= shdr
.get_sh_addr();
2012 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2013 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2019 // Build set of executable sections.
2020 // Using a set is probably overkill. There is likely to be only
2021 // a few executable sections, typically .init, .text and .fini,
2022 // and they are generally grouped together.
2023 typedef std::set
<Sec_info
> Exec_sections
;
2024 Exec_sections exec_sections
;
2026 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2028 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2029 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2030 && ((shdr
.get_sh_flags()
2031 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2032 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2033 && shdr
.get_sh_size() != 0)
2035 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2036 shdr
.get_sh_size(), i
));
2039 if (exec_sections
.empty())
2042 // Look over the OPD entries. This is complicated by the fact
2043 // that some binaries will use two-word entries while others
2044 // will use the standard three-word entries. In most cases
2045 // the third word (the environment pointer for languages like
2046 // Pascal) is unused and will be zero. If the third word is
2047 // used it should not be pointing into executable sections,
2049 this->init_opd(opd_size
);
2050 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2052 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2053 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2054 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2056 // Chances are that this is the third word of an OPD entry.
2058 typename
Exec_sections::const_iterator e
2059 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2060 if (e
!= exec_sections
.begin())
2063 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2065 // We have an address in an executable section.
2066 // VAL ought to be the function entry, set it up.
2067 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2068 // Skip second word of OPD entry, the TOC pointer.
2072 // If we didn't match any executable sections, we likely
2073 // have a non-zero third word in the OPD entry.
2078 // Set up some symbols.
2080 template<int size
, bool big_endian
>
2082 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2083 Symbol_table
* symtab
,
2088 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2089 // undefined when scanning relocs (and thus requires
2090 // non-relative dynamic relocs). The proper value will be
2092 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2093 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2095 Target_powerpc
<size
, big_endian
>* target
=
2096 static_cast<Target_powerpc
<size
, big_endian
>*>(
2097 parameters
->sized_target
<size
, big_endian
>());
2098 Output_data_got_powerpc
<size
, big_endian
>* got
2099 = target
->got_section(symtab
, layout
);
2100 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2101 Symbol_table::PREDEFINED
,
2105 elfcpp::STV_HIDDEN
, 0,
2109 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2110 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2111 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2113 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2115 = layout
->add_output_section_data(".sdata", 0,
2117 | elfcpp::SHF_WRITE
,
2118 sdata
, ORDER_SMALL_DATA
, false);
2119 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2120 Symbol_table::PREDEFINED
,
2121 os
, 32768, 0, elfcpp::STT_OBJECT
,
2122 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2128 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2129 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2130 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2132 Target_powerpc
<size
, big_endian
>* target
=
2133 static_cast<Target_powerpc
<size
, big_endian
>*>(
2134 parameters
->sized_target
<size
, big_endian
>());
2135 Output_data_got_powerpc
<size
, big_endian
>* got
2136 = target
->got_section(symtab
, layout
);
2137 symtab
->define_in_output_data(".TOC.", NULL
,
2138 Symbol_table::PREDEFINED
,
2142 elfcpp::STV_HIDDEN
, 0,
2148 // Set up PowerPC target specific relobj.
2150 template<int size
, bool big_endian
>
2152 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2153 const std::string
& name
,
2154 Input_file
* input_file
,
2155 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2157 int et
= ehdr
.get_e_type();
2158 // ET_EXEC files are valid input for --just-symbols/-R,
2159 // and we treat them as relocatable objects.
2160 if (et
== elfcpp::ET_REL
2161 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2163 Powerpc_relobj
<size
, big_endian
>* obj
=
2164 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2168 else if (et
== elfcpp::ET_DYN
)
2170 Powerpc_dynobj
<size
, big_endian
>* obj
=
2171 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2177 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2182 template<int size
, bool big_endian
>
2183 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2186 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2187 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2189 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2190 : Output_data_got
<size
, big_endian
>(),
2191 symtab_(symtab
), layout_(layout
),
2192 header_ent_cnt_(size
== 32 ? 3 : 1),
2193 header_index_(size
== 32 ? 0x2000 : 0)
2196 this->set_addralign(256);
2199 // Override all the Output_data_got methods we use so as to first call
2202 add_global(Symbol
* gsym
, unsigned int got_type
)
2204 this->reserve_ent();
2205 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2209 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2211 this->reserve_ent();
2212 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2216 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2217 { return this->add_global_plt(gsym
, got_type
); }
2220 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2221 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2223 this->reserve_ent();
2224 Output_data_got
<size
, big_endian
>::
2225 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2229 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2230 Output_data_reloc_generic
* rel_dyn
,
2231 unsigned int r_type_1
, unsigned int r_type_2
)
2233 this->reserve_ent(2);
2234 Output_data_got
<size
, big_endian
>::
2235 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2239 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2241 this->reserve_ent();
2242 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2247 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2249 this->reserve_ent();
2250 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2255 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2256 { return this->add_local_plt(object
, sym_index
, got_type
); }
2259 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2260 unsigned int got_type
,
2261 Output_data_reloc_generic
* rel_dyn
,
2262 unsigned int r_type
)
2264 this->reserve_ent(2);
2265 Output_data_got
<size
, big_endian
>::
2266 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2270 add_constant(Valtype constant
)
2272 this->reserve_ent();
2273 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2277 add_constant_pair(Valtype c1
, Valtype c2
)
2279 this->reserve_ent(2);
2280 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2283 // Offset of _GLOBAL_OFFSET_TABLE_.
2287 return this->got_offset(this->header_index_
);
2290 // Offset of base used to access the GOT/TOC.
2291 // The got/toc pointer reg will be set to this value.
2293 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2296 return this->g_o_t();
2298 return (this->output_section()->address()
2299 + object
->toc_base_offset()
2303 // Ensure our GOT has a header.
2305 set_final_data_size()
2307 if (this->header_ent_cnt_
!= 0)
2308 this->make_header();
2309 Output_data_got
<size
, big_endian
>::set_final_data_size();
2312 // First word of GOT header needs some values that are not
2313 // handled by Output_data_got so poke them in here.
2314 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2316 do_write(Output_file
* of
)
2319 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2320 val
= this->layout_
->dynamic_section()->address();
2322 val
= this->output_section()->address() + 0x8000;
2323 this->replace_constant(this->header_index_
, val
);
2324 Output_data_got
<size
, big_endian
>::do_write(of
);
2329 reserve_ent(unsigned int cnt
= 1)
2331 if (this->header_ent_cnt_
== 0)
2333 if (this->num_entries() + cnt
> this->header_index_
)
2334 this->make_header();
2340 this->header_ent_cnt_
= 0;
2341 this->header_index_
= this->num_entries();
2344 Output_data_got
<size
, big_endian
>::add_constant(0);
2345 Output_data_got
<size
, big_endian
>::add_constant(0);
2346 Output_data_got
<size
, big_endian
>::add_constant(0);
2348 // Define _GLOBAL_OFFSET_TABLE_ at the header
2349 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2352 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2353 sym
->set_value(this->g_o_t());
2356 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2357 Symbol_table::PREDEFINED
,
2358 this, this->g_o_t(), 0,
2361 elfcpp::STV_HIDDEN
, 0,
2365 Output_data_got
<size
, big_endian
>::add_constant(0);
2368 // Stashed pointers.
2369 Symbol_table
* symtab_
;
2373 unsigned int header_ent_cnt_
;
2374 // GOT header index.
2375 unsigned int header_index_
;
2378 // Get the GOT section, creating it if necessary.
2380 template<int size
, bool big_endian
>
2381 Output_data_got_powerpc
<size
, big_endian
>*
2382 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2385 if (this->got_
== NULL
)
2387 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2390 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2392 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2393 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2394 this->got_
, ORDER_DATA
, false);
2400 // Get the dynamic reloc section, creating it if necessary.
2402 template<int size
, bool big_endian
>
2403 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2404 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2406 if (this->rela_dyn_
== NULL
)
2408 gold_assert(layout
!= NULL
);
2409 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2410 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2411 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2412 ORDER_DYNAMIC_RELOCS
, false);
2414 return this->rela_dyn_
;
2417 // Similarly, but for ifunc symbols get the one for ifunc.
2419 template<int size
, bool big_endian
>
2420 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2421 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2426 return this->rela_dyn_section(layout
);
2428 if (this->iplt_
== NULL
)
2429 this->make_iplt_section(symtab
, layout
);
2430 return this->iplt_
->rel_plt();
2436 // Determine the stub group size. The group size is the absolute
2437 // value of the parameter --stub-group-size. If --stub-group-size
2438 // is passed a negative value, we restrict stubs to be always before
2439 // the stubbed branches.
2440 Stub_control(int32_t size
, bool no_size_errors
)
2441 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
2442 stub14_group_size_(abs(size
) >> 10),
2443 stubs_always_before_branch_(size
< 0),
2444 suppress_size_errors_(no_size_errors
),
2445 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
2449 // Return true iff input section can be handled by current stub
2452 can_add_to_stub_group(Output_section
* o
,
2453 const Output_section::Input_section
* i
,
2456 const Output_section::Input_section
*
2462 { return output_section_
; }
2465 set_output_and_owner(Output_section
* o
,
2466 const Output_section::Input_section
* i
)
2468 this->output_section_
= o
;
2476 FINDING_STUB_SECTION
,
2481 uint32_t stub_group_size_
;
2482 uint32_t stub14_group_size_
;
2483 bool stubs_always_before_branch_
;
2484 bool suppress_size_errors_
;
2485 uint64_t group_end_addr_
;
2486 const Output_section::Input_section
* owner_
;
2487 Output_section
* output_section_
;
2490 // Return true iff input section can be handled by current stub
2494 Stub_control::can_add_to_stub_group(Output_section
* o
,
2495 const Output_section::Input_section
* i
,
2499 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
2500 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2502 uint64_t start_addr
= o
->address();
2505 // .init and .fini sections are pasted together to form a single
2506 // function. We can't be adding stubs in the middle of the function.
2507 this_size
= o
->data_size();
2510 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2511 this_size
= i
->data_size();
2513 uint64_t end_addr
= start_addr
+ this_size
;
2514 bool toobig
= this_size
> group_size
;
2516 if (toobig
&& !this->suppress_size_errors_
)
2517 gold_warning(_("%s:%s exceeds group size"),
2518 i
->relobj()->name().c_str(),
2519 i
->relobj()->section_name(i
->shndx()).c_str());
2521 if (this->state_
!= HAS_STUB_SECTION
2522 && (!whole_sec
|| this->output_section_
!= o
)
2523 && (this->state_
== NO_GROUP
2524 || this->group_end_addr_
- end_addr
< group_size
))
2527 this->output_section_
= o
;
2530 if (this->state_
== NO_GROUP
)
2532 this->state_
= FINDING_STUB_SECTION
;
2533 this->group_end_addr_
= end_addr
;
2535 else if (this->group_end_addr_
- start_addr
< group_size
)
2537 // Adding this section would make the group larger than GROUP_SIZE.
2538 else if (this->state_
== FINDING_STUB_SECTION
2539 && !this->stubs_always_before_branch_
2542 // But wait, there's more! Input sections up to GROUP_SIZE
2543 // bytes before the stub table can be handled by it too.
2544 this->state_
= HAS_STUB_SECTION
;
2545 this->group_end_addr_
= end_addr
;
2549 this->state_
= NO_GROUP
;
2555 // Look over all the input sections, deciding where to place stubs.
2557 template<int size
, bool big_endian
>
2559 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2561 bool no_size_errors
)
2563 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
);
2565 // Group input sections and insert stub table
2566 Stub_table_owner
* table_owner
= NULL
;
2567 std::vector
<Stub_table_owner
*> tables
;
2568 Layout::Section_list section_list
;
2569 layout
->get_executable_sections(§ion_list
);
2570 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2571 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
2572 o
!= section_list
.rend();
2575 typedef Output_section::Input_section_list Input_section_list
;
2576 for (Input_section_list::const_reverse_iterator i
2577 = (*o
)->input_sections().rbegin();
2578 i
!= (*o
)->input_sections().rend();
2581 if (i
->is_input_section()
2582 || i
->is_relaxed_input_section())
2584 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2585 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2586 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2587 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2589 table_owner
->output_section
= stub_control
.output_section();
2590 table_owner
->owner
= stub_control
.owner();
2591 stub_control
.set_output_and_owner(*o
, &*i
);
2594 if (table_owner
== NULL
)
2596 table_owner
= new Stub_table_owner
;
2597 tables
.push_back(table_owner
);
2599 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2603 if (table_owner
!= NULL
)
2605 const Output_section::Input_section
* i
= stub_control
.owner();
2607 if (tables
.size() >= 2 && tables
[tables
.size() - 2]->owner
== i
)
2609 // Corner case. A new stub group was made for the first
2610 // section (last one looked at here) for some reason, but
2611 // the first section is already being used as the owner for
2612 // a stub table for following sections. Force it into that
2616 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2617 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2618 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2622 table_owner
->output_section
= stub_control
.output_section();
2623 table_owner
->owner
= i
;
2626 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
2630 Stub_table
<size
, big_endian
>* stub_table
;
2632 if ((*t
)->owner
->is_input_section())
2633 stub_table
= new Stub_table
<size
, big_endian
>(this,
2634 (*t
)->output_section
,
2636 else if ((*t
)->owner
->is_relaxed_input_section())
2637 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
2638 (*t
)->owner
->relaxed_input_section());
2641 this->stub_tables_
.push_back(stub_table
);
2646 static unsigned long
2647 max_branch_delta (unsigned int r_type
)
2649 if (r_type
== elfcpp::R_POWERPC_REL14
2650 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
2651 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2653 if (r_type
== elfcpp::R_POWERPC_REL24
2654 || r_type
== elfcpp::R_PPC_PLTREL24
2655 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
2660 // If this branch needs a plt call stub, or a long branch stub, make one.
2662 template<int size
, bool big_endian
>
2664 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2665 Stub_table
<size
, big_endian
>* stub_table
,
2666 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2667 Symbol_table
* symtab
) const
2669 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2670 if (sym
!= NULL
&& sym
->is_forwarder())
2671 sym
= symtab
->resolve_forwards(sym
);
2672 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2673 Target_powerpc
<size
, big_endian
>* target
=
2674 static_cast<Target_powerpc
<size
, big_endian
>*>(
2675 parameters
->sized_target
<size
, big_endian
>());
2677 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
2678 : this->object_
->local_has_plt_offset(this->r_sym_
))
2682 && target
->abiversion() >= 2
2683 && !parameters
->options().output_is_position_independent()
2684 && !is_branch_reloc(this->r_type_
))
2685 target
->glink_section()->add_global_entry(gsym
);
2688 if (stub_table
== NULL
)
2689 stub_table
= this->object_
->stub_table(this->shndx_
);
2690 if (stub_table
== NULL
)
2692 // This is a ref from a data section to an ifunc symbol.
2693 stub_table
= ifunc_stub_table
;
2695 gold_assert(stub_table
!= NULL
);
2696 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2697 if (from
!= invalid_address
)
2698 from
+= (this->object_
->output_section(this->shndx_
)->address()
2701 return stub_table
->add_plt_call_entry(from
,
2702 this->object_
, gsym
,
2703 this->r_type_
, this->addend_
);
2705 return stub_table
->add_plt_call_entry(from
,
2706 this->object_
, this->r_sym_
,
2707 this->r_type_
, this->addend_
);
2712 Address max_branch_offset
= max_branch_delta(this->r_type_
);
2713 if (max_branch_offset
== 0)
2715 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2716 gold_assert(from
!= invalid_address
);
2717 from
+= (this->object_
->output_section(this->shndx_
)->address()
2722 switch (gsym
->source())
2724 case Symbol::FROM_OBJECT
:
2726 Object
* symobj
= gsym
->object();
2727 if (symobj
->is_dynamic()
2728 || symobj
->pluginobj() != NULL
)
2731 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2732 if (shndx
== elfcpp::SHN_UNDEF
)
2737 case Symbol::IS_UNDEFINED
:
2743 Symbol_table::Compute_final_value_status status
;
2744 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2745 if (status
!= Symbol_table::CFVS_OK
)
2748 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
2752 const Symbol_value
<size
>* psymval
2753 = this->object_
->local_symbol(this->r_sym_
);
2754 Symbol_value
<size
> symval
;
2755 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2756 typename
ObjType::Compute_final_local_value_status status
2757 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2759 if (status
!= ObjType::CFLV_OK
2760 || !symval
.has_output_value())
2762 to
= symval
.value(this->object_
, 0);
2764 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
2766 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
2767 to
+= this->addend_
;
2768 if (stub_table
== NULL
)
2769 stub_table
= this->object_
->stub_table(this->shndx_
);
2770 if (size
== 64 && target
->abiversion() < 2)
2772 unsigned int dest_shndx
;
2773 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
2777 Address delta
= to
- from
;
2778 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2780 if (stub_table
== NULL
)
2782 gold_warning(_("%s:%s: branch in non-executable section,"
2783 " no long branch stub for you"),
2784 this->object_
->name().c_str(),
2785 this->object_
->section_name(this->shndx_
).c_str());
2788 bool save_res
= (size
== 64
2790 && gsym
->source() == Symbol::IN_OUTPUT_DATA
2791 && gsym
->output_data() == target
->savres_section());
2792 return stub_table
->add_long_branch_entry(this->object_
,
2794 from
, to
, save_res
);
2800 // Relaxation hook. This is where we do stub generation.
2802 template<int size
, bool big_endian
>
2804 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2805 const Input_objects
*,
2806 Symbol_table
* symtab
,
2810 unsigned int prev_brlt_size
= 0;
2814 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
2816 && this->abiversion() < 2
2818 && !parameters
->options().user_set_plt_thread_safe())
2820 static const char* const thread_starter
[] =
2824 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2826 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2827 "mq_notify", "create_timer",
2832 "GOMP_parallel_start",
2833 "GOMP_parallel_loop_static",
2834 "GOMP_parallel_loop_static_start",
2835 "GOMP_parallel_loop_dynamic",
2836 "GOMP_parallel_loop_dynamic_start",
2837 "GOMP_parallel_loop_guided",
2838 "GOMP_parallel_loop_guided_start",
2839 "GOMP_parallel_loop_runtime",
2840 "GOMP_parallel_loop_runtime_start",
2841 "GOMP_parallel_sections",
2842 "GOMP_parallel_sections_start",
2847 if (parameters
->options().shared())
2851 for (unsigned int i
= 0;
2852 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2855 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2856 thread_safe
= (sym
!= NULL
2858 && sym
->in_real_elf());
2864 this->plt_thread_safe_
= thread_safe
;
2869 this->stub_group_size_
= parameters
->options().stub_group_size();
2870 bool no_size_errors
= true;
2871 if (this->stub_group_size_
== 1)
2872 this->stub_group_size_
= 0x1c00000;
2873 else if (this->stub_group_size_
== -1)
2874 this->stub_group_size_
= -0x1e00000;
2876 no_size_errors
= false;
2877 this->group_sections(layout
, task
, no_size_errors
);
2879 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
2881 this->branch_lookup_table_
.clear();
2882 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2883 p
!= this->stub_tables_
.end();
2886 (*p
)->clear_stubs(true);
2888 this->stub_tables_
.clear();
2889 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
2890 gold_info(_("%s: stub group size is too large; retrying with %d"),
2891 program_name
, this->stub_group_size_
);
2892 this->group_sections(layout
, task
, true);
2895 // We need address of stub tables valid for make_stub.
2896 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2897 p
!= this->stub_tables_
.end();
2900 const Powerpc_relobj
<size
, big_endian
>* object
2901 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2902 Address off
= object
->get_output_section_offset((*p
)->shndx());
2903 gold_assert(off
!= invalid_address
);
2904 Output_section
* os
= (*p
)->output_section();
2905 (*p
)->set_address_and_size(os
, off
);
2910 // Clear plt call stubs, long branch stubs and branch lookup table.
2911 prev_brlt_size
= this->branch_lookup_table_
.size();
2912 this->branch_lookup_table_
.clear();
2913 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2914 p
!= this->stub_tables_
.end();
2917 (*p
)->clear_stubs(false);
2921 // Build all the stubs.
2922 this->relax_failed_
= false;
2923 Stub_table
<size
, big_endian
>* ifunc_stub_table
2924 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2925 Stub_table
<size
, big_endian
>* one_stub_table
2926 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2927 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2928 b
!= this->branch_info_
.end();
2931 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
2932 && !this->relax_failed_
)
2934 this->relax_failed_
= true;
2935 this->relax_fail_count_
++;
2936 if (this->relax_fail_count_
< 3)
2941 // Did anything change size?
2942 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2943 bool again
= num_huge_branches
!= prev_brlt_size
;
2944 if (size
== 64 && num_huge_branches
!= 0)
2945 this->make_brlt_section(layout
);
2946 if (size
== 64 && again
)
2947 this->brlt_section_
->set_current_size(num_huge_branches
);
2949 typedef Unordered_set
<Output_section
*> Output_sections
;
2950 Output_sections os_need_update
;
2951 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2952 p
!= this->stub_tables_
.end();
2955 if ((*p
)->size_update())
2958 (*p
)->add_eh_frame(layout
);
2959 os_need_update
.insert((*p
)->output_section());
2963 // Set output section offsets for all input sections in an output
2964 // section that just changed size. Anything past the stubs will
2966 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2967 p
!= os_need_update
.end();
2970 Output_section
* os
= *p
;
2972 typedef Output_section::Input_section_list Input_section_list
;
2973 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2974 i
!= os
->input_sections().end();
2977 off
= align_address(off
, i
->addralign());
2978 if (i
->is_input_section() || i
->is_relaxed_input_section())
2979 i
->relobj()->set_section_offset(i
->shndx(), off
);
2980 if (i
->is_relaxed_input_section())
2982 Stub_table
<size
, big_endian
>* stub_table
2983 = static_cast<Stub_table
<size
, big_endian
>*>(
2984 i
->relaxed_input_section());
2985 off
+= stub_table
->set_address_and_size(os
, off
);
2988 off
+= i
->data_size();
2990 // If .branch_lt is part of this output section, then we have
2991 // just done the offset adjustment.
2992 os
->clear_section_offsets_need_adjustment();
2997 && num_huge_branches
!= 0
2998 && parameters
->options().output_is_position_independent())
3000 // Fill in the BRLT relocs.
3001 this->brlt_section_
->reset_brlt_sizes();
3002 for (typename
Branch_lookup_table::const_iterator p
3003 = this->branch_lookup_table_
.begin();
3004 p
!= this->branch_lookup_table_
.end();
3007 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3009 this->brlt_section_
->finalize_brlt_sizes();
3014 template<int size
, bool big_endian
>
3016 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3017 unsigned char* oview
,
3021 uint64_t address
= plt
->address();
3022 off_t len
= plt
->data_size();
3024 if (plt
== this->glink_
)
3026 // See Output_data_glink::do_write() for glink contents.
3029 gold_assert(parameters
->doing_static_link());
3030 // Static linking may need stubs, to support ifunc and long
3031 // branches. We need to create an output section for
3032 // .eh_frame early in the link process, to have a place to
3033 // attach stub .eh_frame info. We also need to have
3034 // registered a CIE that matches the stub CIE. Both of
3035 // these requirements are satisfied by creating an FDE and
3036 // CIE for .glink, even though static linking will leave
3037 // .glink zero length.
3038 // ??? Hopefully generating an FDE with a zero address range
3039 // won't confuse anything that consumes .eh_frame info.
3041 else if (size
== 64)
3043 // There is one word before __glink_PLTresolve
3047 else if (parameters
->options().output_is_position_independent())
3049 // There are two FDEs for a position independent glink.
3050 // The first covers the branch table, the second
3051 // __glink_PLTresolve at the end of glink.
3052 off_t resolve_size
= this->glink_
->pltresolve_size
;
3053 if (oview
[9] == elfcpp::DW_CFA_nop
)
3054 len
-= resolve_size
;
3057 address
+= len
- resolve_size
;
3064 // Must be a stub table.
3065 const Stub_table
<size
, big_endian
>* stub_table
3066 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3067 uint64_t stub_address
= stub_table
->stub_address();
3068 len
-= stub_address
- address
;
3069 address
= stub_address
;
3072 *paddress
= address
;
3076 // A class to handle the PLT data.
3078 template<int size
, bool big_endian
>
3079 class Output_data_plt_powerpc
: public Output_section_data_build
3082 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3083 size
, big_endian
> Reloc_section
;
3085 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3086 Reloc_section
* plt_rel
,
3088 : Output_section_data_build(size
== 32 ? 4 : 8),
3094 // Add an entry to the PLT.
3099 add_ifunc_entry(Symbol
*);
3102 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3104 // Return the .rela.plt section data.
3111 // Return the number of PLT entries.
3115 if (this->current_data_size() == 0)
3117 return ((this->current_data_size() - this->first_plt_entry_offset())
3118 / this->plt_entry_size());
3123 do_adjust_output_section(Output_section
* os
)
3128 // Write to a map file.
3130 do_print_to_mapfile(Mapfile
* mapfile
) const
3131 { mapfile
->print_output_data(this, this->name_
); }
3134 // Return the offset of the first non-reserved PLT entry.
3136 first_plt_entry_offset() const
3138 // IPLT has no reserved entry.
3139 if (this->name_
[3] == 'I')
3141 return this->targ_
->first_plt_entry_offset();
3144 // Return the size of each PLT entry.
3146 plt_entry_size() const
3148 return this->targ_
->plt_entry_size();
3151 // Write out the PLT data.
3153 do_write(Output_file
*);
3155 // The reloc section.
3156 Reloc_section
* rel_
;
3157 // Allows access to .glink for do_write.
3158 Target_powerpc
<size
, big_endian
>* targ_
;
3159 // What to report in map file.
3163 // Add an entry to the PLT.
3165 template<int size
, bool big_endian
>
3167 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3169 if (!gsym
->has_plt_offset())
3171 section_size_type off
= this->current_data_size();
3173 off
+= this->first_plt_entry_offset();
3174 gsym
->set_plt_offset(off
);
3175 gsym
->set_needs_dynsym_entry();
3176 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3177 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3178 off
+= this->plt_entry_size();
3179 this->set_current_data_size(off
);
3183 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3185 template<int size
, bool big_endian
>
3187 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3189 if (!gsym
->has_plt_offset())
3191 section_size_type off
= this->current_data_size();
3192 gsym
->set_plt_offset(off
);
3193 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3194 if (size
== 64 && this->targ_
->abiversion() < 2)
3195 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3196 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3197 off
+= this->plt_entry_size();
3198 this->set_current_data_size(off
);
3202 // Add an entry for a local ifunc symbol to the IPLT.
3204 template<int size
, bool big_endian
>
3206 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3207 Sized_relobj_file
<size
, big_endian
>* relobj
,
3208 unsigned int local_sym_index
)
3210 if (!relobj
->local_has_plt_offset(local_sym_index
))
3212 section_size_type off
= this->current_data_size();
3213 relobj
->set_local_plt_offset(local_sym_index
, off
);
3214 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3215 if (size
== 64 && this->targ_
->abiversion() < 2)
3216 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3217 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3219 off
+= this->plt_entry_size();
3220 this->set_current_data_size(off
);
3224 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3225 static const uint32_t add_2_2_11
= 0x7c425a14;
3226 static const uint32_t add_2_2_12
= 0x7c426214;
3227 static const uint32_t add_3_3_2
= 0x7c631214;
3228 static const uint32_t add_3_3_13
= 0x7c636a14;
3229 static const uint32_t add_11_0_11
= 0x7d605a14;
3230 static const uint32_t add_11_2_11
= 0x7d625a14;
3231 static const uint32_t add_11_11_2
= 0x7d6b1214;
3232 static const uint32_t addi_0_12
= 0x380c0000;
3233 static const uint32_t addi_2_2
= 0x38420000;
3234 static const uint32_t addi_3_3
= 0x38630000;
3235 static const uint32_t addi_11_11
= 0x396b0000;
3236 static const uint32_t addi_12_1
= 0x39810000;
3237 static const uint32_t addi_12_12
= 0x398c0000;
3238 static const uint32_t addis_0_2
= 0x3c020000;
3239 static const uint32_t addis_0_13
= 0x3c0d0000;
3240 static const uint32_t addis_2_12
= 0x3c4c0000;
3241 static const uint32_t addis_11_2
= 0x3d620000;
3242 static const uint32_t addis_11_11
= 0x3d6b0000;
3243 static const uint32_t addis_11_30
= 0x3d7e0000;
3244 static const uint32_t addis_12_1
= 0x3d810000;
3245 static const uint32_t addis_12_2
= 0x3d820000;
3246 static const uint32_t addis_12_12
= 0x3d8c0000;
3247 static const uint32_t b
= 0x48000000;
3248 static const uint32_t bcl_20_31
= 0x429f0005;
3249 static const uint32_t bctr
= 0x4e800420;
3250 static const uint32_t blr
= 0x4e800020;
3251 static const uint32_t bnectr_p4
= 0x4ce20420;
3252 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
3253 static const uint32_t cmpldi_2_0
= 0x28220000;
3254 static const uint32_t cror_15_15_15
= 0x4def7b82;
3255 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3256 static const uint32_t ld_0_1
= 0xe8010000;
3257 static const uint32_t ld_0_12
= 0xe80c0000;
3258 static const uint32_t ld_2_1
= 0xe8410000;
3259 static const uint32_t ld_2_2
= 0xe8420000;
3260 static const uint32_t ld_2_11
= 0xe84b0000;
3261 static const uint32_t ld_2_12
= 0xe84c0000;
3262 static const uint32_t ld_11_2
= 0xe9620000;
3263 static const uint32_t ld_11_11
= 0xe96b0000;
3264 static const uint32_t ld_12_2
= 0xe9820000;
3265 static const uint32_t ld_12_11
= 0xe98b0000;
3266 static const uint32_t ld_12_12
= 0xe98c0000;
3267 static const uint32_t lfd_0_1
= 0xc8010000;
3268 static const uint32_t li_0_0
= 0x38000000;
3269 static const uint32_t li_12_0
= 0x39800000;
3270 static const uint32_t lis_0
= 0x3c000000;
3271 static const uint32_t lis_2
= 0x3c400000;
3272 static const uint32_t lis_11
= 0x3d600000;
3273 static const uint32_t lis_12
= 0x3d800000;
3274 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3275 static const uint32_t lwz_0_12
= 0x800c0000;
3276 static const uint32_t lwz_11_11
= 0x816b0000;
3277 static const uint32_t lwz_11_30
= 0x817e0000;
3278 static const uint32_t lwz_12_12
= 0x818c0000;
3279 static const uint32_t lwzu_0_12
= 0x840c0000;
3280 static const uint32_t mflr_0
= 0x7c0802a6;
3281 static const uint32_t mflr_11
= 0x7d6802a6;
3282 static const uint32_t mflr_12
= 0x7d8802a6;
3283 static const uint32_t mtctr_0
= 0x7c0903a6;
3284 static const uint32_t mtctr_11
= 0x7d6903a6;
3285 static const uint32_t mtctr_12
= 0x7d8903a6;
3286 static const uint32_t mtlr_0
= 0x7c0803a6;
3287 static const uint32_t mtlr_12
= 0x7d8803a6;
3288 static const uint32_t nop
= 0x60000000;
3289 static const uint32_t ori_0_0_0
= 0x60000000;
3290 static const uint32_t srdi_0_0_2
= 0x7800f082;
3291 static const uint32_t std_0_1
= 0xf8010000;
3292 static const uint32_t std_0_12
= 0xf80c0000;
3293 static const uint32_t std_2_1
= 0xf8410000;
3294 static const uint32_t stfd_0_1
= 0xd8010000;
3295 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3296 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3297 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3298 static const uint32_t xor_2_12_12
= 0x7d826278;
3299 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3301 // Write out the PLT.
3303 template<int size
, bool big_endian
>
3305 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3307 if (size
== 32 && this->name_
[3] != 'I')
3309 const section_size_type offset
= this->offset();
3310 const section_size_type oview_size
3311 = convert_to_section_size_type(this->data_size());
3312 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3313 unsigned char* pov
= oview
;
3314 unsigned char* endpov
= oview
+ oview_size
;
3316 // The address of the .glink branch table
3317 const Output_data_glink
<size
, big_endian
>* glink
3318 = this->targ_
->glink_section();
3319 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3321 while (pov
< endpov
)
3323 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3328 of
->write_output_view(offset
, oview_size
, oview
);
3332 // Create the PLT section.
3334 template<int size
, bool big_endian
>
3336 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3339 if (this->plt_
== NULL
)
3341 if (this->got_
== NULL
)
3342 this->got_section(symtab
, layout
);
3344 if (this->glink_
== NULL
)
3345 make_glink_section(layout
);
3347 // Ensure that .rela.dyn always appears before .rela.plt This is
3348 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3349 // needs to include .rela.plt in its range.
3350 this->rela_dyn_section(layout
);
3352 Reloc_section
* plt_rel
= new Reloc_section(false);
3353 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3354 elfcpp::SHF_ALLOC
, plt_rel
,
3355 ORDER_DYNAMIC_PLT_RELOCS
, false);
3357 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3359 layout
->add_output_section_data(".plt",
3361 ? elfcpp::SHT_PROGBITS
3362 : elfcpp::SHT_NOBITS
),
3363 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3372 // Create the IPLT section.
3374 template<int size
, bool big_endian
>
3376 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3379 if (this->iplt_
== NULL
)
3381 this->make_plt_section(symtab
, layout
);
3383 Reloc_section
* iplt_rel
= new Reloc_section(false);
3384 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3386 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3388 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3392 // A section for huge long branch addresses, similar to plt section.
3394 template<int size
, bool big_endian
>
3395 class Output_data_brlt_powerpc
: public Output_section_data_build
3398 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3399 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3400 size
, big_endian
> Reloc_section
;
3402 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3403 Reloc_section
* brlt_rel
)
3404 : Output_section_data_build(size
== 32 ? 4 : 8),
3412 this->reset_data_size();
3413 this->rel_
->reset_data_size();
3417 finalize_brlt_sizes()
3419 this->finalize_data_size();
3420 this->rel_
->finalize_data_size();
3423 // Add a reloc for an entry in the BRLT.
3425 add_reloc(Address to
, unsigned int off
)
3426 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
3428 // Update section and reloc section size.
3430 set_current_size(unsigned int num_branches
)
3432 this->reset_address_and_file_offset();
3433 this->set_current_data_size(num_branches
* 16);
3434 this->finalize_data_size();
3435 Output_section
* os
= this->output_section();
3436 os
->set_section_offsets_need_adjustment();
3437 if (this->rel_
!= NULL
)
3439 unsigned int reloc_size
3440 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
3441 this->rel_
->reset_address_and_file_offset();
3442 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
3443 this->rel_
->finalize_data_size();
3444 Output_section
* os
= this->rel_
->output_section();
3445 os
->set_section_offsets_need_adjustment();
3451 do_adjust_output_section(Output_section
* os
)
3456 // Write to a map file.
3458 do_print_to_mapfile(Mapfile
* mapfile
) const
3459 { mapfile
->print_output_data(this, "** BRLT"); }
3462 // Write out the BRLT data.
3464 do_write(Output_file
*);
3466 // The reloc section.
3467 Reloc_section
* rel_
;
3468 Target_powerpc
<size
, big_endian
>* targ_
;
3471 // Make the branch lookup table section.
3473 template<int size
, bool big_endian
>
3475 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
3477 if (size
== 64 && this->brlt_section_
== NULL
)
3479 Reloc_section
* brlt_rel
= NULL
;
3480 bool is_pic
= parameters
->options().output_is_position_independent();
3483 // When PIC we can't fill in .branch_lt (like .plt it can be
3484 // a bss style section) but must initialise at runtime via
3485 // dynamic relocats.
3486 this->rela_dyn_section(layout
);
3487 brlt_rel
= new Reloc_section(false);
3488 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3491 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3492 if (this->plt_
&& is_pic
)
3493 this->plt_
->output_section()
3494 ->add_output_section_data(this->brlt_section_
);
3496 layout
->add_output_section_data(".branch_lt",
3497 (is_pic
? elfcpp::SHT_NOBITS
3498 : elfcpp::SHT_PROGBITS
),
3499 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3500 this->brlt_section_
,
3501 (is_pic
? ORDER_SMALL_BSS
3502 : ORDER_SMALL_DATA
),
3507 // Write out .branch_lt when non-PIC.
3509 template<int size
, bool big_endian
>
3511 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3513 if (size
== 64 && !parameters
->options().output_is_position_independent())
3515 const section_size_type offset
= this->offset();
3516 const section_size_type oview_size
3517 = convert_to_section_size_type(this->data_size());
3518 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3520 this->targ_
->write_branch_lookup_table(oview
);
3521 of
->write_output_view(offset
, oview_size
, oview
);
3525 static inline uint32_t
3531 static inline uint32_t
3537 static inline uint32_t
3540 return hi(a
+ 0x8000);
3546 static const unsigned char eh_frame_cie
[12];
3550 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3553 'z', 'R', 0, // Augmentation string.
3554 4, // Code alignment.
3555 0x80 - size
/ 8 , // Data alignment.
3557 1, // Augmentation size.
3558 (elfcpp::DW_EH_PE_pcrel
3559 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3560 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3563 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3564 static const unsigned char glink_eh_frame_fde_64v1
[] =
3566 0, 0, 0, 0, // Replaced with offset to .glink.
3567 0, 0, 0, 0, // Replaced with size of .glink.
3568 0, // Augmentation size.
3569 elfcpp::DW_CFA_advance_loc
+ 1,
3570 elfcpp::DW_CFA_register
, 65, 12,
3571 elfcpp::DW_CFA_advance_loc
+ 4,
3572 elfcpp::DW_CFA_restore_extended
, 65
3575 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3576 static const unsigned char glink_eh_frame_fde_64v2
[] =
3578 0, 0, 0, 0, // Replaced with offset to .glink.
3579 0, 0, 0, 0, // Replaced with size of .glink.
3580 0, // Augmentation size.
3581 elfcpp::DW_CFA_advance_loc
+ 1,
3582 elfcpp::DW_CFA_register
, 65, 0,
3583 elfcpp::DW_CFA_advance_loc
+ 4,
3584 elfcpp::DW_CFA_restore_extended
, 65
3587 // Describe __glink_PLTresolve use of LR, 32-bit version.
3588 static const unsigned char glink_eh_frame_fde_32
[] =
3590 0, 0, 0, 0, // Replaced with offset to .glink.
3591 0, 0, 0, 0, // Replaced with size of .glink.
3592 0, // Augmentation size.
3593 elfcpp::DW_CFA_advance_loc
+ 2,
3594 elfcpp::DW_CFA_register
, 65, 0,
3595 elfcpp::DW_CFA_advance_loc
+ 4,
3596 elfcpp::DW_CFA_restore_extended
, 65
3599 static const unsigned char default_fde
[] =
3601 0, 0, 0, 0, // Replaced with offset to stubs.
3602 0, 0, 0, 0, // Replaced with size of stubs.
3603 0, // Augmentation size.
3604 elfcpp::DW_CFA_nop
, // Pad.
3609 template<bool big_endian
>
3611 write_insn(unsigned char* p
, uint32_t v
)
3613 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3616 // Stub_table holds information about plt and long branch stubs.
3617 // Stubs are built in an area following some input section determined
3618 // by group_sections(). This input section is converted to a relaxed
3619 // input section allowing it to be resized to accommodate the stubs
3621 template<int size
, bool big_endian
>
3622 class Stub_table
: public Output_relaxed_input_section
3625 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3626 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3628 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
3629 Output_section
* output_section
,
3630 const Output_section::Input_section
* owner
)
3631 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
3633 ->section_addralign(owner
->shndx())),
3634 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3635 orig_data_size_(owner
->current_data_size()),
3636 plt_size_(0), last_plt_size_(0),
3637 branch_size_(0), last_branch_size_(0), eh_frame_added_(false),
3638 need_save_res_(false)
3640 this->set_output_section(output_section
);
3642 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3643 new_relaxed
.push_back(this);
3644 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3647 // Add a plt call stub.
3649 add_plt_call_entry(Address
,
3650 const Sized_relobj_file
<size
, big_endian
>*,
3656 add_plt_call_entry(Address
,
3657 const Sized_relobj_file
<size
, big_endian
>*,
3662 // Find a given plt call stub.
3664 find_plt_call_entry(const Symbol
*) const;
3667 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3668 unsigned int) const;
3671 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3677 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3682 // Add a long branch stub.
3684 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3685 unsigned int, Address
, Address
, bool);
3688 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3692 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
3694 Address max_branch_offset
= max_branch_delta(r_type
);
3695 if (max_branch_offset
== 0)
3697 gold_assert(from
!= invalid_address
);
3698 Address loc
= off
+ this->stub_address();
3699 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
3703 clear_stubs(bool all
)
3705 this->plt_call_stubs_
.clear();
3706 this->plt_size_
= 0;
3707 this->long_branch_stubs_
.clear();
3708 this->branch_size_
= 0;
3709 this->need_save_res_
= false;
3712 this->last_plt_size_
= 0;
3713 this->last_branch_size_
= 0;
3718 set_address_and_size(const Output_section
* os
, Address off
)
3720 Address start_off
= off
;
3721 off
+= this->orig_data_size_
;
3722 Address my_size
= this->plt_size_
+ this->branch_size_
;
3723 if (this->need_save_res_
)
3724 my_size
+= this->targ_
->savres_section()->data_size();
3726 off
= align_address(off
, this->stub_align());
3727 // Include original section size and alignment padding in size
3728 my_size
+= off
- start_off
;
3729 this->reset_address_and_file_offset();
3730 this->set_current_data_size(my_size
);
3731 this->set_address_and_file_offset(os
->address() + start_off
,
3732 os
->offset() + start_off
);
3737 stub_address() const
3739 return align_address(this->address() + this->orig_data_size_
,
3740 this->stub_align());
3746 return align_address(this->offset() + this->orig_data_size_
,
3747 this->stub_align());
3752 { return this->plt_size_
; }
3757 Output_section
* os
= this->output_section();
3758 if (os
->addralign() < this->stub_align())
3760 os
->set_addralign(this->stub_align());
3761 // FIXME: get rid of the insane checkpointing.
3762 // We can't increase alignment of the input section to which
3763 // stubs are attached; The input section may be .init which
3764 // is pasted together with other .init sections to form a
3765 // function. Aligning might insert zero padding resulting in
3766 // sigill. However we do need to increase alignment of the
3767 // output section so that the align_address() on offset in
3768 // set_address_and_size() adds the same padding as the
3769 // align_address() on address in stub_address().
3770 // What's more, we need this alignment for the layout done in
3771 // relaxation_loop_body() so that the output section starts at
3772 // a suitably aligned address.
3773 os
->checkpoint_set_addralign(this->stub_align());
3775 if (this->last_plt_size_
!= this->plt_size_
3776 || this->last_branch_size_
!= this->branch_size_
)
3778 this->last_plt_size_
= this->plt_size_
;
3779 this->last_branch_size_
= this->branch_size_
;
3785 // Add .eh_frame info for this stub section. Unlike other linker
3786 // generated .eh_frame this is added late in the link, because we
3787 // only want the .eh_frame info if this particular stub section is
3790 add_eh_frame(Layout
* layout
)
3792 if (!this->eh_frame_added_
)
3794 if (!parameters
->options().ld_generated_unwind_info())
3797 // Since we add stub .eh_frame info late, it must be placed
3798 // after all other linker generated .eh_frame info so that
3799 // merge mapping need not be updated for input sections.
3800 // There is no provision to use a different CIE to that used
3802 if (!this->targ_
->has_glink())
3805 layout
->add_eh_frame_for_plt(this,
3806 Eh_cie
<size
>::eh_frame_cie
,
3807 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3809 sizeof (default_fde
));
3810 this->eh_frame_added_
= true;
3814 Target_powerpc
<size
, big_endian
>*
3820 class Plt_stub_ent_hash
;
3821 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3822 Plt_stub_ent_hash
> Plt_stub_entries
;
3824 // Alignment of stub section.
3830 unsigned int min_align
= 32;
3831 unsigned int user_align
= 1 << parameters
->options().plt_align();
3832 return std::max(user_align
, min_align
);
3835 // Return the plt offset for the given call stub.
3837 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3839 const Symbol
* gsym
= p
->first
.sym_
;
3842 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3843 && gsym
->can_use_relative_reloc(false));
3844 return gsym
->plt_offset();
3849 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3850 unsigned int local_sym_index
= p
->first
.locsym_
;
3851 return relobj
->local_plt_offset(local_sym_index
);
3855 // Size of a given plt call stub.
3857 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3863 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3865 plt_addr
+= this->targ_
->iplt_section()->address();
3867 plt_addr
+= this->targ_
->plt_section()->address();
3868 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3869 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3870 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3871 got_addr
+= ppcobj
->toc_base_offset();
3872 Address off
= plt_addr
- got_addr
;
3873 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
3874 if (this->targ_
->abiversion() < 2)
3876 bool static_chain
= parameters
->options().plt_static_chain();
3877 bool thread_safe
= this->targ_
->plt_thread_safe();
3881 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3883 unsigned int align
= 1 << parameters
->options().plt_align();
3885 bytes
= (bytes
+ align
- 1) & -align
;
3889 // Return long branch stub size.
3891 branch_stub_size(Address to
)
3894 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3895 if (to
- loc
+ (1 << 25) < 2 << 25)
3897 if (size
== 64 || !parameters
->options().output_is_position_independent())
3904 do_write(Output_file
*);
3906 // Plt call stub keys.
3910 Plt_stub_ent(const Symbol
* sym
)
3911 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3914 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3915 unsigned int locsym_index
)
3916 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3919 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3921 unsigned int r_type
,
3923 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3926 this->addend_
= addend
;
3927 else if (parameters
->options().output_is_position_independent()
3928 && r_type
== elfcpp::R_PPC_PLTREL24
)
3930 this->addend_
= addend
;
3931 if (this->addend_
>= 32768)
3932 this->object_
= object
;
3936 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3937 unsigned int locsym_index
,
3938 unsigned int r_type
,
3940 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3943 this->addend_
= addend
;
3944 else if (parameters
->options().output_is_position_independent()
3945 && r_type
== elfcpp::R_PPC_PLTREL24
)
3946 this->addend_
= addend
;
3949 bool operator==(const Plt_stub_ent
& that
) const
3951 return (this->sym_
== that
.sym_
3952 && this->object_
== that
.object_
3953 && this->addend_
== that
.addend_
3954 && this->locsym_
== that
.locsym_
);
3958 const Sized_relobj_file
<size
, big_endian
>* object_
;
3959 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
3960 unsigned int locsym_
;
3963 class Plt_stub_ent_hash
3966 size_t operator()(const Plt_stub_ent
& ent
) const
3968 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
3969 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
3975 // Long branch stub keys.
3976 class Branch_stub_ent
3979 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
,
3980 Address to
, bool save_res
)
3981 : dest_(to
), toc_base_off_(0), save_res_(save_res
)
3984 toc_base_off_
= obj
->toc_base_offset();
3987 bool operator==(const Branch_stub_ent
& that
) const
3989 return (this->dest_
== that
.dest_
3991 || this->toc_base_off_
== that
.toc_base_off_
));
3995 unsigned int toc_base_off_
;
3999 class Branch_stub_ent_hash
4002 size_t operator()(const Branch_stub_ent
& ent
) const
4003 { return ent
.dest_
^ ent
.toc_base_off_
; }
4006 // In a sane world this would be a global.
4007 Target_powerpc
<size
, big_endian
>* targ_
;
4008 // Map sym/object/addend to stub offset.
4009 Plt_stub_entries plt_call_stubs_
;
4010 // Map destination address to stub offset.
4011 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
4012 Branch_stub_ent_hash
> Branch_stub_entries
;
4013 Branch_stub_entries long_branch_stubs_
;
4014 // size of input section
4015 section_size_type orig_data_size_
;
4017 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
4018 // Whether .eh_frame info has been created for this stub section.
4019 bool eh_frame_added_
;
4020 // Set if this stub group needs a copy of out-of-line register
4021 // save/restore functions.
4022 bool need_save_res_
;
4025 // Add a plt call stub, if we do not already have one for this
4026 // sym/object/addend combo.
4028 template<int size
, bool big_endian
>
4030 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4032 const Sized_relobj_file
<size
, big_endian
>* object
,
4034 unsigned int r_type
,
4037 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4038 unsigned int off
= this->plt_size_
;
4039 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4040 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4042 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4043 return this->can_reach_stub(from
, off
, r_type
);
4046 template<int size
, bool big_endian
>
4048 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4050 const Sized_relobj_file
<size
, big_endian
>* object
,
4051 unsigned int locsym_index
,
4052 unsigned int r_type
,
4055 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4056 unsigned int off
= this->plt_size_
;
4057 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4058 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4060 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4061 return this->can_reach_stub(from
, off
, r_type
);
4064 // Find a plt call stub.
4066 template<int size
, bool big_endian
>
4067 typename Stub_table
<size
, big_endian
>::Address
4068 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4069 const Sized_relobj_file
<size
, big_endian
>* object
,
4071 unsigned int r_type
,
4072 Address addend
) const
4074 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4075 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4076 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4079 template<int size
, bool big_endian
>
4080 typename Stub_table
<size
, big_endian
>::Address
4081 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
4083 Plt_stub_ent
ent(gsym
);
4084 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4085 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4088 template<int size
, bool big_endian
>
4089 typename Stub_table
<size
, big_endian
>::Address
4090 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4091 const Sized_relobj_file
<size
, big_endian
>* object
,
4092 unsigned int locsym_index
,
4093 unsigned int r_type
,
4094 Address addend
) const
4096 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4097 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4098 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4101 template<int size
, bool big_endian
>
4102 typename Stub_table
<size
, big_endian
>::Address
4103 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4104 const Sized_relobj_file
<size
, big_endian
>* object
,
4105 unsigned int locsym_index
) const
4107 Plt_stub_ent
ent(object
, locsym_index
);
4108 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4109 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4112 // Add a long branch stub if we don't already have one to given
4115 template<int size
, bool big_endian
>
4117 Stub_table
<size
, big_endian
>::add_long_branch_entry(
4118 const Powerpc_relobj
<size
, big_endian
>* object
,
4119 unsigned int r_type
,
4124 Branch_stub_ent
ent(object
, to
, save_res
);
4125 Address off
= this->branch_size_
;
4126 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
4129 this->need_save_res_
= true;
4132 unsigned int stub_size
= this->branch_stub_size(to
);
4133 this->branch_size_
= off
+ stub_size
;
4134 if (size
== 64 && stub_size
!= 4)
4135 this->targ_
->add_branch_lookup_table(to
);
4138 return this->can_reach_stub(from
, off
, r_type
);
4141 // Find long branch stub offset.
4143 template<int size
, bool big_endian
>
4144 typename Stub_table
<size
, big_endian
>::Address
4145 Stub_table
<size
, big_endian
>::find_long_branch_entry(
4146 const Powerpc_relobj
<size
, big_endian
>* object
,
4149 Branch_stub_ent
ent(object
, to
, false);
4150 typename
Branch_stub_entries::const_iterator p
4151 = this->long_branch_stubs_
.find(ent
);
4152 if (p
== this->long_branch_stubs_
.end())
4153 return invalid_address
;
4154 if (p
->first
.save_res_
)
4155 return to
- this->targ_
->savres_section()->address() + this->branch_size_
;
4159 // A class to handle .glink.
4161 template<int size
, bool big_endian
>
4162 class Output_data_glink
: public Output_section_data
4165 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4166 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4167 static const int pltresolve_size
= 16*4;
4169 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
4170 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
4171 end_branch_table_(), ge_size_(0)
4175 add_eh_frame(Layout
* layout
);
4178 add_global_entry(const Symbol
*);
4181 find_global_entry(const Symbol
*) const;
4184 global_entry_address() const
4186 gold_assert(this->is_data_size_valid());
4187 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4188 return this->address() + global_entry_off
;
4192 // Write to a map file.
4194 do_print_to_mapfile(Mapfile
* mapfile
) const
4195 { mapfile
->print_output_data(this, _("** glink")); }
4199 set_final_data_size();
4203 do_write(Output_file
*);
4205 // Allows access to .got and .plt for do_write.
4206 Target_powerpc
<size
, big_endian
>* targ_
;
4208 // Map sym to stub offset.
4209 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4210 Global_entry_stub_entries global_entry_stubs_
;
4212 unsigned int end_branch_table_
, ge_size_
;
4215 template<int size
, bool big_endian
>
4217 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4219 if (!parameters
->options().ld_generated_unwind_info())
4224 if (this->targ_
->abiversion() < 2)
4225 layout
->add_eh_frame_for_plt(this,
4226 Eh_cie
<64>::eh_frame_cie
,
4227 sizeof (Eh_cie
<64>::eh_frame_cie
),
4228 glink_eh_frame_fde_64v1
,
4229 sizeof (glink_eh_frame_fde_64v1
));
4231 layout
->add_eh_frame_for_plt(this,
4232 Eh_cie
<64>::eh_frame_cie
,
4233 sizeof (Eh_cie
<64>::eh_frame_cie
),
4234 glink_eh_frame_fde_64v2
,
4235 sizeof (glink_eh_frame_fde_64v2
));
4239 // 32-bit .glink can use the default since the CIE return
4240 // address reg, LR, is valid.
4241 layout
->add_eh_frame_for_plt(this,
4242 Eh_cie
<32>::eh_frame_cie
,
4243 sizeof (Eh_cie
<32>::eh_frame_cie
),
4245 sizeof (default_fde
));
4246 // Except where LR is used in a PIC __glink_PLTresolve.
4247 if (parameters
->options().output_is_position_independent())
4248 layout
->add_eh_frame_for_plt(this,
4249 Eh_cie
<32>::eh_frame_cie
,
4250 sizeof (Eh_cie
<32>::eh_frame_cie
),
4251 glink_eh_frame_fde_32
,
4252 sizeof (glink_eh_frame_fde_32
));
4256 template<int size
, bool big_endian
>
4258 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
4260 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
4261 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, this->ge_size_
));
4263 this->ge_size_
+= 16;
4266 template<int size
, bool big_endian
>
4267 typename Output_data_glink
<size
, big_endian
>::Address
4268 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
4270 typename
Global_entry_stub_entries::const_iterator p
4271 = this->global_entry_stubs_
.find(gsym
);
4272 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
4275 template<int size
, bool big_endian
>
4277 Output_data_glink
<size
, big_endian
>::set_final_data_size()
4279 unsigned int count
= this->targ_
->plt_entry_count();
4280 section_size_type total
= 0;
4286 // space for branch table
4287 total
+= 4 * (count
- 1);
4289 total
+= -total
& 15;
4290 total
+= this->pltresolve_size
;
4294 total
+= this->pltresolve_size
;
4296 // space for branch table
4298 if (this->targ_
->abiversion() < 2)
4302 total
+= 4 * (count
- 0x8000);
4306 this->end_branch_table_
= total
;
4307 total
= (total
+ 15) & -16;
4308 total
+= this->ge_size_
;
4310 this->set_data_size(total
);
4313 // Write out plt and long branch stub code.
4315 template<int size
, bool big_endian
>
4317 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
4319 if (this->plt_call_stubs_
.empty()
4320 && this->long_branch_stubs_
.empty())
4323 const section_size_type start_off
= this->offset();
4324 const section_size_type off
= this->stub_offset();
4325 const section_size_type oview_size
=
4326 convert_to_section_size_type(this->data_size() - (off
- start_off
));
4327 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4332 const Output_data_got_powerpc
<size
, big_endian
>* got
4333 = this->targ_
->got_section();
4334 Address got_os_addr
= got
->output_section()->address();
4336 if (!this->plt_call_stubs_
.empty())
4338 // The base address of the .plt section.
4339 Address plt_base
= this->targ_
->plt_section()->address();
4340 Address iplt_base
= invalid_address
;
4342 // Write out plt call stubs.
4343 typename
Plt_stub_entries::const_iterator cs
;
4344 for (cs
= this->plt_call_stubs_
.begin();
4345 cs
!= this->plt_call_stubs_
.end();
4349 Address pltoff
= this->plt_off(cs
, &is_iplt
);
4350 Address plt_addr
= pltoff
;
4353 if (iplt_base
== invalid_address
)
4354 iplt_base
= this->targ_
->iplt_section()->address();
4355 plt_addr
+= iplt_base
;
4358 plt_addr
+= plt_base
;
4359 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4360 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
4361 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
4362 Address off
= plt_addr
- got_addr
;
4364 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
4365 gold_error(_("%s: linkage table error against `%s'"),
4366 cs
->first
.object_
->name().c_str(),
4367 cs
->first
.sym_
->demangled_name().c_str());
4369 bool plt_load_toc
= this->targ_
->abiversion() < 2;
4371 = plt_load_toc
&& parameters
->options().plt_static_chain();
4373 = plt_load_toc
&& this->targ_
->plt_thread_safe();
4374 bool use_fake_dep
= false;
4375 Address cmp_branch_off
= 0;
4378 unsigned int pltindex
4379 = ((pltoff
- this->targ_
->first_plt_entry_offset())
4380 / this->targ_
->plt_entry_size());
4382 = (this->targ_
->glink_section()->pltresolve_size
4384 if (pltindex
> 32768)
4385 glinkoff
+= (pltindex
- 32768) * 4;
4387 = this->targ_
->glink_section()->address() + glinkoff
;
4389 = (this->stub_address() + cs
->second
+ 24
4390 + 4 * (ha(off
) != 0)
4391 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4392 + 4 * static_chain
);
4393 cmp_branch_off
= to
- from
;
4394 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
4397 p
= oview
+ cs
->second
;
4400 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4404 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
4406 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
4411 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
4413 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
4417 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4419 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
4423 write_insn
<big_endian
>(p
, mtctr_12
);
4429 write_insn
<big_endian
>(p
, xor_2_12_12
);
4431 write_insn
<big_endian
>(p
, add_11_11_2
);
4434 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
4438 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
4445 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4447 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
4450 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4452 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
4456 write_insn
<big_endian
>(p
, mtctr_12
);
4462 write_insn
<big_endian
>(p
, xor_11_12_12
);
4464 write_insn
<big_endian
>(p
, add_2_2_11
);
4469 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
4472 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
4476 if (thread_safe
&& !use_fake_dep
)
4478 write_insn
<big_endian
>(p
, cmpldi_2_0
);
4480 write_insn
<big_endian
>(p
, bnectr_p4
);
4482 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
4485 write_insn
<big_endian
>(p
, bctr
);
4489 // Write out long branch stubs.
4490 typename
Branch_stub_entries::const_iterator bs
;
4491 for (bs
= this->long_branch_stubs_
.begin();
4492 bs
!= this->long_branch_stubs_
.end();
4495 if (bs
->first
.save_res_
)
4497 p
= oview
+ this->plt_size_
+ bs
->second
;
4498 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4499 Address delta
= bs
->first
.dest_
- loc
;
4500 if (delta
+ (1 << 25) < 2 << 25)
4501 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4505 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
4506 gold_assert(brlt_addr
!= invalid_address
);
4507 brlt_addr
+= this->targ_
->brlt_section()->address();
4508 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
4509 Address brltoff
= brlt_addr
- got_addr
;
4510 if (ha(brltoff
) == 0)
4512 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
4516 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
4517 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
4519 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4520 write_insn
<big_endian
>(p
, bctr
);
4526 if (!this->plt_call_stubs_
.empty())
4528 // The base address of the .plt section.
4529 Address plt_base
= this->targ_
->plt_section()->address();
4530 Address iplt_base
= invalid_address
;
4531 // The address of _GLOBAL_OFFSET_TABLE_.
4532 Address g_o_t
= invalid_address
;
4534 // Write out plt call stubs.
4535 typename
Plt_stub_entries::const_iterator cs
;
4536 for (cs
= this->plt_call_stubs_
.begin();
4537 cs
!= this->plt_call_stubs_
.end();
4541 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
4544 if (iplt_base
== invalid_address
)
4545 iplt_base
= this->targ_
->iplt_section()->address();
4546 plt_addr
+= iplt_base
;
4549 plt_addr
+= plt_base
;
4551 p
= oview
+ cs
->second
;
4552 if (parameters
->options().output_is_position_independent())
4555 const Powerpc_relobj
<size
, big_endian
>* ppcobj
4556 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
4557 (cs
->first
.object_
));
4558 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
4560 unsigned int got2
= ppcobj
->got2_shndx();
4561 got_addr
= ppcobj
->get_output_section_offset(got2
);
4562 gold_assert(got_addr
!= invalid_address
);
4563 got_addr
+= (ppcobj
->output_section(got2
)->address()
4564 + cs
->first
.addend_
);
4568 if (g_o_t
== invalid_address
)
4570 const Output_data_got_powerpc
<size
, big_endian
>* got
4571 = this->targ_
->got_section();
4572 g_o_t
= got
->address() + got
->g_o_t();
4577 Address off
= plt_addr
- got_addr
;
4580 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
4581 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
4582 write_insn
<big_endian
>(p
+ 8, bctr
);
4586 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
4587 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
4588 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4589 write_insn
<big_endian
>(p
+ 12, bctr
);
4594 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
4595 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
4596 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4597 write_insn
<big_endian
>(p
+ 12, bctr
);
4602 // Write out long branch stubs.
4603 typename
Branch_stub_entries::const_iterator bs
;
4604 for (bs
= this->long_branch_stubs_
.begin();
4605 bs
!= this->long_branch_stubs_
.end();
4608 if (bs
->first
.save_res_
)
4610 p
= oview
+ this->plt_size_
+ bs
->second
;
4611 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4612 Address delta
= bs
->first
.dest_
- loc
;
4613 if (delta
+ (1 << 25) < 2 << 25)
4614 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4615 else if (!parameters
->options().output_is_position_independent())
4617 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
4618 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
4619 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
4620 write_insn
<big_endian
>(p
+ 12, bctr
);
4625 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4626 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4627 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4628 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4629 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4630 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4631 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4632 write_insn
<big_endian
>(p
+ 28, bctr
);
4636 if (this->need_save_res_
)
4638 p
= oview
+ this->plt_size_
+ this->branch_size_
;
4639 memcpy (p
, this->targ_
->savres_section()->contents(),
4640 this->targ_
->savres_section()->data_size());
4644 // Write out .glink.
4646 template<int size
, bool big_endian
>
4648 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4650 const section_size_type off
= this->offset();
4651 const section_size_type oview_size
=
4652 convert_to_section_size_type(this->data_size());
4653 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4656 // The base address of the .plt section.
4657 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4658 Address plt_base
= this->targ_
->plt_section()->address();
4662 if (this->end_branch_table_
!= 0)
4664 // Write pltresolve stub.
4666 Address after_bcl
= this->address() + 16;
4667 Address pltoff
= plt_base
- after_bcl
;
4669 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4671 if (this->targ_
->abiversion() < 2)
4673 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4674 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4675 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4676 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4677 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4678 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4679 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4680 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
4681 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4682 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
4686 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
4687 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4688 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4689 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4690 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
4691 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
4692 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4693 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
4694 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4695 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
4696 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4697 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
4699 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4700 while (p
< oview
+ this->pltresolve_size
)
4701 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4703 // Write lazy link call stubs.
4705 while (p
< oview
+ this->end_branch_table_
)
4707 if (this->targ_
->abiversion() < 2)
4711 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4715 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
4716 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4719 uint32_t branch_off
= 8 - (p
- oview
);
4720 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4725 Address plt_base
= this->targ_
->plt_section()->address();
4726 Address iplt_base
= invalid_address
;
4727 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4728 Address global_entry_base
= this->address() + global_entry_off
;
4729 typename
Global_entry_stub_entries::const_iterator ge
;
4730 for (ge
= this->global_entry_stubs_
.begin();
4731 ge
!= this->global_entry_stubs_
.end();
4734 p
= oview
+ global_entry_off
+ ge
->second
;
4735 Address plt_addr
= ge
->first
->plt_offset();
4736 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
4737 && ge
->first
->can_use_relative_reloc(false))
4739 if (iplt_base
== invalid_address
)
4740 iplt_base
= this->targ_
->iplt_section()->address();
4741 plt_addr
+= iplt_base
;
4744 plt_addr
+= plt_base
;
4745 Address my_addr
= global_entry_base
+ ge
->second
;
4746 Address off
= plt_addr
- my_addr
;
4748 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
4749 gold_error(_("%s: linkage table error against `%s'"),
4750 ge
->first
->object()->name().c_str(),
4751 ge
->first
->demangled_name().c_str());
4753 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
4754 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
4755 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4756 write_insn
<big_endian
>(p
, bctr
);
4761 const Output_data_got_powerpc
<size
, big_endian
>* got
4762 = this->targ_
->got_section();
4763 // The address of _GLOBAL_OFFSET_TABLE_.
4764 Address g_o_t
= got
->address() + got
->g_o_t();
4766 // Write out pltresolve branch table.
4768 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4769 unsigned char* end_p
= oview
+ the_end
;
4770 while (p
< end_p
- 8 * 4)
4771 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4773 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4775 // Write out pltresolve call stub.
4776 if (parameters
->options().output_is_position_independent())
4778 Address res0_off
= 0;
4779 Address after_bcl_off
= the_end
+ 12;
4780 Address bcl_res0
= after_bcl_off
- res0_off
;
4782 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4783 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4784 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4785 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4786 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4787 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4788 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4790 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4792 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4793 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4795 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4796 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4800 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4801 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4803 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4804 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4805 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4806 write_insn
<big_endian
>(p
+ 52, bctr
);
4807 write_insn
<big_endian
>(p
+ 56, nop
);
4808 write_insn
<big_endian
>(p
+ 60, nop
);
4812 Address res0
= this->address();
4814 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4815 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4816 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4817 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4819 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4820 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4821 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4822 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4823 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4824 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4826 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4827 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4828 write_insn
<big_endian
>(p
+ 32, bctr
);
4829 write_insn
<big_endian
>(p
+ 36, nop
);
4830 write_insn
<big_endian
>(p
+ 40, nop
);
4831 write_insn
<big_endian
>(p
+ 44, nop
);
4832 write_insn
<big_endian
>(p
+ 48, nop
);
4833 write_insn
<big_endian
>(p
+ 52, nop
);
4834 write_insn
<big_endian
>(p
+ 56, nop
);
4835 write_insn
<big_endian
>(p
+ 60, nop
);
4840 of
->write_output_view(off
, oview_size
, oview
);
4844 // A class to handle linker generated save/restore functions.
4846 template<int size
, bool big_endian
>
4847 class Output_data_save_res
: public Output_section_data_build
4850 Output_data_save_res(Symbol_table
* symtab
);
4852 const unsigned char*
4859 // Write to a map file.
4861 do_print_to_mapfile(Mapfile
* mapfile
) const
4862 { mapfile
->print_output_data(this, _("** save/restore")); }
4865 do_write(Output_file
*);
4868 // The maximum size of save/restore contents.
4869 static const unsigned int savres_max
= 218*4;
4872 savres_define(Symbol_table
* symtab
,
4874 unsigned int lo
, unsigned int hi
,
4875 unsigned char* write_ent(unsigned char*, int),
4876 unsigned char* write_tail(unsigned char*, int));
4878 unsigned char *contents_
;
4881 template<bool big_endian
>
4882 static unsigned char*
4883 savegpr0(unsigned char* p
, int r
)
4885 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4886 write_insn
<big_endian
>(p
, insn
);
4890 template<bool big_endian
>
4891 static unsigned char*
4892 savegpr0_tail(unsigned char* p
, int r
)
4894 p
= savegpr0
<big_endian
>(p
, r
);
4895 uint32_t insn
= std_0_1
+ 16;
4896 write_insn
<big_endian
>(p
, insn
);
4898 write_insn
<big_endian
>(p
, blr
);
4902 template<bool big_endian
>
4903 static unsigned char*
4904 restgpr0(unsigned char* p
, int r
)
4906 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4907 write_insn
<big_endian
>(p
, insn
);
4911 template<bool big_endian
>
4912 static unsigned char*
4913 restgpr0_tail(unsigned char* p
, int r
)
4915 uint32_t insn
= ld_0_1
+ 16;
4916 write_insn
<big_endian
>(p
, insn
);
4918 p
= restgpr0
<big_endian
>(p
, r
);
4919 write_insn
<big_endian
>(p
, mtlr_0
);
4923 p
= restgpr0
<big_endian
>(p
, 30);
4924 p
= restgpr0
<big_endian
>(p
, 31);
4926 write_insn
<big_endian
>(p
, blr
);
4930 template<bool big_endian
>
4931 static unsigned char*
4932 savegpr1(unsigned char* p
, int r
)
4934 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4935 write_insn
<big_endian
>(p
, insn
);
4939 template<bool big_endian
>
4940 static unsigned char*
4941 savegpr1_tail(unsigned char* p
, int r
)
4943 p
= savegpr1
<big_endian
>(p
, r
);
4944 write_insn
<big_endian
>(p
, blr
);
4948 template<bool big_endian
>
4949 static unsigned char*
4950 restgpr1(unsigned char* p
, int r
)
4952 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4953 write_insn
<big_endian
>(p
, insn
);
4957 template<bool big_endian
>
4958 static unsigned char*
4959 restgpr1_tail(unsigned char* p
, int r
)
4961 p
= restgpr1
<big_endian
>(p
, r
);
4962 write_insn
<big_endian
>(p
, blr
);
4966 template<bool big_endian
>
4967 static unsigned char*
4968 savefpr(unsigned char* p
, int r
)
4970 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4971 write_insn
<big_endian
>(p
, insn
);
4975 template<bool big_endian
>
4976 static unsigned char*
4977 savefpr0_tail(unsigned char* p
, int r
)
4979 p
= savefpr
<big_endian
>(p
, r
);
4980 write_insn
<big_endian
>(p
, std_0_1
+ 16);
4982 write_insn
<big_endian
>(p
, blr
);
4986 template<bool big_endian
>
4987 static unsigned char*
4988 restfpr(unsigned char* p
, int r
)
4990 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4991 write_insn
<big_endian
>(p
, insn
);
4995 template<bool big_endian
>
4996 static unsigned char*
4997 restfpr0_tail(unsigned char* p
, int r
)
4999 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
5001 p
= restfpr
<big_endian
>(p
, r
);
5002 write_insn
<big_endian
>(p
, mtlr_0
);
5006 p
= restfpr
<big_endian
>(p
, 30);
5007 p
= restfpr
<big_endian
>(p
, 31);
5009 write_insn
<big_endian
>(p
, blr
);
5013 template<bool big_endian
>
5014 static unsigned char*
5015 savefpr1_tail(unsigned char* p
, int r
)
5017 p
= savefpr
<big_endian
>(p
, r
);
5018 write_insn
<big_endian
>(p
, blr
);
5022 template<bool big_endian
>
5023 static unsigned char*
5024 restfpr1_tail(unsigned char* p
, int r
)
5026 p
= restfpr
<big_endian
>(p
, r
);
5027 write_insn
<big_endian
>(p
, blr
);
5031 template<bool big_endian
>
5032 static unsigned char*
5033 savevr(unsigned char* p
, int r
)
5035 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5036 write_insn
<big_endian
>(p
, insn
);
5038 insn
= stvx_0_12_0
+ (r
<< 21);
5039 write_insn
<big_endian
>(p
, insn
);
5043 template<bool big_endian
>
5044 static unsigned char*
5045 savevr_tail(unsigned char* p
, int r
)
5047 p
= savevr
<big_endian
>(p
, r
);
5048 write_insn
<big_endian
>(p
, blr
);
5052 template<bool big_endian
>
5053 static unsigned char*
5054 restvr(unsigned char* p
, int r
)
5056 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5057 write_insn
<big_endian
>(p
, insn
);
5059 insn
= lvx_0_12_0
+ (r
<< 21);
5060 write_insn
<big_endian
>(p
, insn
);
5064 template<bool big_endian
>
5065 static unsigned char*
5066 restvr_tail(unsigned char* p
, int r
)
5068 p
= restvr
<big_endian
>(p
, r
);
5069 write_insn
<big_endian
>(p
, blr
);
5074 template<int size
, bool big_endian
>
5075 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
5076 Symbol_table
* symtab
)
5077 : Output_section_data_build(4),
5080 this->savres_define(symtab
,
5081 "_savegpr0_", 14, 31,
5082 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
5083 this->savres_define(symtab
,
5084 "_restgpr0_", 14, 29,
5085 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5086 this->savres_define(symtab
,
5087 "_restgpr0_", 30, 31,
5088 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5089 this->savres_define(symtab
,
5090 "_savegpr1_", 14, 31,
5091 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
5092 this->savres_define(symtab
,
5093 "_restgpr1_", 14, 31,
5094 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
5095 this->savres_define(symtab
,
5096 "_savefpr_", 14, 31,
5097 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
5098 this->savres_define(symtab
,
5099 "_restfpr_", 14, 29,
5100 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5101 this->savres_define(symtab
,
5102 "_restfpr_", 30, 31,
5103 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5104 this->savres_define(symtab
,
5106 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
5107 this->savres_define(symtab
,
5109 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
5110 this->savres_define(symtab
,
5112 savevr
<big_endian
>, savevr_tail
<big_endian
>);
5113 this->savres_define(symtab
,
5115 restvr
<big_endian
>, restvr_tail
<big_endian
>);
5118 template<int size
, bool big_endian
>
5120 Output_data_save_res
<size
, big_endian
>::savres_define(
5121 Symbol_table
* symtab
,
5123 unsigned int lo
, unsigned int hi
,
5124 unsigned char* write_ent(unsigned char*, int),
5125 unsigned char* write_tail(unsigned char*, int))
5127 size_t len
= strlen(name
);
5128 bool writing
= false;
5131 memcpy(sym
, name
, len
);
5134 for (unsigned int i
= lo
; i
<= hi
; i
++)
5136 sym
[len
+ 0] = i
/ 10 + '0';
5137 sym
[len
+ 1] = i
% 10 + '0';
5138 Symbol
* gsym
= symtab
->lookup(sym
);
5139 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
5140 writing
= writing
|| refd
;
5143 if (this->contents_
== NULL
)
5144 this->contents_
= new unsigned char[this->savres_max
];
5146 section_size_type value
= this->current_data_size();
5147 unsigned char* p
= this->contents_
+ value
;
5149 p
= write_ent(p
, i
);
5151 p
= write_tail(p
, i
);
5152 section_size_type cur_size
= p
- this->contents_
;
5153 this->set_current_data_size(cur_size
);
5155 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
5156 this, value
, cur_size
- value
,
5157 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
5158 elfcpp::STV_HIDDEN
, 0, false, false);
5163 // Write out save/restore.
5165 template<int size
, bool big_endian
>
5167 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
5169 const section_size_type off
= this->offset();
5170 const section_size_type oview_size
=
5171 convert_to_section_size_type(this->data_size());
5172 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5173 memcpy(oview
, this->contents_
, oview_size
);
5174 of
->write_output_view(off
, oview_size
, oview
);
5178 // Create the glink section.
5180 template<int size
, bool big_endian
>
5182 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
5184 if (this->glink_
== NULL
)
5186 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
5187 this->glink_
->add_eh_frame(layout
);
5188 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5189 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5190 this->glink_
, ORDER_TEXT
, false);
5194 // Create a PLT entry for a global symbol.
5196 template<int size
, bool big_endian
>
5198 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
5202 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5203 && gsym
->can_use_relative_reloc(false))
5205 if (this->iplt_
== NULL
)
5206 this->make_iplt_section(symtab
, layout
);
5207 this->iplt_
->add_ifunc_entry(gsym
);
5211 if (this->plt_
== NULL
)
5212 this->make_plt_section(symtab
, layout
);
5213 this->plt_
->add_entry(gsym
);
5217 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
5219 template<int size
, bool big_endian
>
5221 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
5222 Symbol_table
* symtab
,
5224 Sized_relobj_file
<size
, big_endian
>* relobj
,
5227 if (this->iplt_
== NULL
)
5228 this->make_iplt_section(symtab
, layout
);
5229 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
5232 // Return the number of entries in the PLT.
5234 template<int size
, bool big_endian
>
5236 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
5238 if (this->plt_
== NULL
)
5240 return this->plt_
->entry_count();
5243 // Create a GOT entry for local dynamic __tls_get_addr calls.
5245 template<int size
, bool big_endian
>
5247 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
5248 Symbol_table
* symtab
,
5250 Sized_relobj_file
<size
, big_endian
>* object
)
5252 if (this->tlsld_got_offset_
== -1U)
5254 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
5255 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
5256 Output_data_got_powerpc
<size
, big_endian
>* got
5257 = this->got_section(symtab
, layout
);
5258 unsigned int got_offset
= got
->add_constant_pair(0, 0);
5259 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
5261 this->tlsld_got_offset_
= got_offset
;
5263 return this->tlsld_got_offset_
;
5266 // Get the Reference_flags for a particular relocation.
5268 template<int size
, bool big_endian
>
5270 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
5271 unsigned int r_type
,
5272 const Target_powerpc
* target
)
5278 case elfcpp::R_POWERPC_NONE
:
5279 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5280 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5281 case elfcpp::R_PPC64_TOC
:
5282 // No symbol reference.
5285 case elfcpp::R_PPC64_ADDR64
:
5286 case elfcpp::R_PPC64_UADDR64
:
5287 case elfcpp::R_POWERPC_ADDR32
:
5288 case elfcpp::R_POWERPC_UADDR32
:
5289 case elfcpp::R_POWERPC_ADDR16
:
5290 case elfcpp::R_POWERPC_UADDR16
:
5291 case elfcpp::R_POWERPC_ADDR16_LO
:
5292 case elfcpp::R_POWERPC_ADDR16_HI
:
5293 case elfcpp::R_POWERPC_ADDR16_HA
:
5294 ref
= Symbol::ABSOLUTE_REF
;
5297 case elfcpp::R_POWERPC_ADDR24
:
5298 case elfcpp::R_POWERPC_ADDR14
:
5299 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5300 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5301 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
5304 case elfcpp::R_PPC64_REL64
:
5305 case elfcpp::R_POWERPC_REL32
:
5306 case elfcpp::R_PPC_LOCAL24PC
:
5307 case elfcpp::R_POWERPC_REL16
:
5308 case elfcpp::R_POWERPC_REL16_LO
:
5309 case elfcpp::R_POWERPC_REL16_HI
:
5310 case elfcpp::R_POWERPC_REL16_HA
:
5311 ref
= Symbol::RELATIVE_REF
;
5314 case elfcpp::R_POWERPC_REL24
:
5315 case elfcpp::R_PPC_PLTREL24
:
5316 case elfcpp::R_POWERPC_REL14
:
5317 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5318 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5319 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
5322 case elfcpp::R_POWERPC_GOT16
:
5323 case elfcpp::R_POWERPC_GOT16_LO
:
5324 case elfcpp::R_POWERPC_GOT16_HI
:
5325 case elfcpp::R_POWERPC_GOT16_HA
:
5326 case elfcpp::R_PPC64_GOT16_DS
:
5327 case elfcpp::R_PPC64_GOT16_LO_DS
:
5328 case elfcpp::R_PPC64_TOC16
:
5329 case elfcpp::R_PPC64_TOC16_LO
:
5330 case elfcpp::R_PPC64_TOC16_HI
:
5331 case elfcpp::R_PPC64_TOC16_HA
:
5332 case elfcpp::R_PPC64_TOC16_DS
:
5333 case elfcpp::R_PPC64_TOC16_LO_DS
:
5334 ref
= Symbol::RELATIVE_REF
;
5337 case elfcpp::R_POWERPC_GOT_TPREL16
:
5338 case elfcpp::R_POWERPC_TLS
:
5339 ref
= Symbol::TLS_REF
;
5342 case elfcpp::R_POWERPC_COPY
:
5343 case elfcpp::R_POWERPC_GLOB_DAT
:
5344 case elfcpp::R_POWERPC_JMP_SLOT
:
5345 case elfcpp::R_POWERPC_RELATIVE
:
5346 case elfcpp::R_POWERPC_DTPMOD
:
5348 // Not expected. We will give an error later.
5352 if (size
== 64 && target
->abiversion() < 2)
5353 ref
|= Symbol::FUNC_DESC_ABI
;
5357 // Report an unsupported relocation against a local symbol.
5359 template<int size
, bool big_endian
>
5361 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
5362 Sized_relobj_file
<size
, big_endian
>* object
,
5363 unsigned int r_type
)
5365 gold_error(_("%s: unsupported reloc %u against local symbol"),
5366 object
->name().c_str(), r_type
);
5369 // We are about to emit a dynamic relocation of type R_TYPE. If the
5370 // dynamic linker does not support it, issue an error.
5372 template<int size
, bool big_endian
>
5374 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
5375 unsigned int r_type
)
5377 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
5379 // These are the relocation types supported by glibc for both 32-bit
5380 // and 64-bit powerpc.
5383 case elfcpp::R_POWERPC_NONE
:
5384 case elfcpp::R_POWERPC_RELATIVE
:
5385 case elfcpp::R_POWERPC_GLOB_DAT
:
5386 case elfcpp::R_POWERPC_DTPMOD
:
5387 case elfcpp::R_POWERPC_DTPREL
:
5388 case elfcpp::R_POWERPC_TPREL
:
5389 case elfcpp::R_POWERPC_JMP_SLOT
:
5390 case elfcpp::R_POWERPC_COPY
:
5391 case elfcpp::R_POWERPC_IRELATIVE
:
5392 case elfcpp::R_POWERPC_ADDR32
:
5393 case elfcpp::R_POWERPC_UADDR32
:
5394 case elfcpp::R_POWERPC_ADDR24
:
5395 case elfcpp::R_POWERPC_ADDR16
:
5396 case elfcpp::R_POWERPC_UADDR16
:
5397 case elfcpp::R_POWERPC_ADDR16_LO
:
5398 case elfcpp::R_POWERPC_ADDR16_HI
:
5399 case elfcpp::R_POWERPC_ADDR16_HA
:
5400 case elfcpp::R_POWERPC_ADDR14
:
5401 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5402 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5403 case elfcpp::R_POWERPC_REL32
:
5404 case elfcpp::R_POWERPC_REL24
:
5405 case elfcpp::R_POWERPC_TPREL16
:
5406 case elfcpp::R_POWERPC_TPREL16_LO
:
5407 case elfcpp::R_POWERPC_TPREL16_HI
:
5408 case elfcpp::R_POWERPC_TPREL16_HA
:
5419 // These are the relocation types supported only on 64-bit.
5420 case elfcpp::R_PPC64_ADDR64
:
5421 case elfcpp::R_PPC64_UADDR64
:
5422 case elfcpp::R_PPC64_JMP_IREL
:
5423 case elfcpp::R_PPC64_ADDR16_DS
:
5424 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5425 case elfcpp::R_PPC64_ADDR16_HIGH
:
5426 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5427 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5428 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5429 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5430 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5431 case elfcpp::R_PPC64_REL64
:
5432 case elfcpp::R_POWERPC_ADDR30
:
5433 case elfcpp::R_PPC64_TPREL16_DS
:
5434 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5435 case elfcpp::R_PPC64_TPREL16_HIGH
:
5436 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5437 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5438 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5439 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5440 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5451 // These are the relocation types supported only on 32-bit.
5452 // ??? glibc ld.so doesn't need to support these.
5453 case elfcpp::R_POWERPC_DTPREL16
:
5454 case elfcpp::R_POWERPC_DTPREL16_LO
:
5455 case elfcpp::R_POWERPC_DTPREL16_HI
:
5456 case elfcpp::R_POWERPC_DTPREL16_HA
:
5464 // This prevents us from issuing more than one error per reloc
5465 // section. But we can still wind up issuing more than one
5466 // error per object file.
5467 if (this->issued_non_pic_error_
)
5469 gold_assert(parameters
->options().output_is_position_independent());
5470 object
->error(_("requires unsupported dynamic reloc; "
5471 "recompile with -fPIC"));
5472 this->issued_non_pic_error_
= true;
5476 // Return whether we need to make a PLT entry for a relocation of the
5477 // given type against a STT_GNU_IFUNC symbol.
5479 template<int size
, bool big_endian
>
5481 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
5482 Target_powerpc
<size
, big_endian
>* target
,
5483 Sized_relobj_file
<size
, big_endian
>* object
,
5484 unsigned int r_type
,
5487 // In non-pic code any reference will resolve to the plt call stub
5488 // for the ifunc symbol.
5489 if ((size
== 32 || target
->abiversion() >= 2)
5490 && !parameters
->options().output_is_position_independent())
5495 // Word size refs from data sections are OK, but don't need a PLT entry.
5496 case elfcpp::R_POWERPC_ADDR32
:
5497 case elfcpp::R_POWERPC_UADDR32
:
5502 case elfcpp::R_PPC64_ADDR64
:
5503 case elfcpp::R_PPC64_UADDR64
:
5508 // GOT refs are good, but also don't need a PLT entry.
5509 case elfcpp::R_POWERPC_GOT16
:
5510 case elfcpp::R_POWERPC_GOT16_LO
:
5511 case elfcpp::R_POWERPC_GOT16_HI
:
5512 case elfcpp::R_POWERPC_GOT16_HA
:
5513 case elfcpp::R_PPC64_GOT16_DS
:
5514 case elfcpp::R_PPC64_GOT16_LO_DS
:
5517 // Function calls are good, and these do need a PLT entry.
5518 case elfcpp::R_POWERPC_ADDR24
:
5519 case elfcpp::R_POWERPC_ADDR14
:
5520 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5521 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5522 case elfcpp::R_POWERPC_REL24
:
5523 case elfcpp::R_PPC_PLTREL24
:
5524 case elfcpp::R_POWERPC_REL14
:
5525 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5526 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5533 // Anything else is a problem.
5534 // If we are building a static executable, the libc startup function
5535 // responsible for applying indirect function relocations is going
5536 // to complain about the reloc type.
5537 // If we are building a dynamic executable, we will have a text
5538 // relocation. The dynamic loader will set the text segment
5539 // writable and non-executable to apply text relocations. So we'll
5540 // segfault when trying to run the indirection function to resolve
5543 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5544 object
->name().c_str(), r_type
);
5548 // Scan a relocation for a local symbol.
5550 template<int size
, bool big_endian
>
5552 Target_powerpc
<size
, big_endian
>::Scan::local(
5553 Symbol_table
* symtab
,
5555 Target_powerpc
<size
, big_endian
>* target
,
5556 Sized_relobj_file
<size
, big_endian
>* object
,
5557 unsigned int data_shndx
,
5558 Output_section
* output_section
,
5559 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5560 unsigned int r_type
,
5561 const elfcpp::Sym
<size
, big_endian
>& lsym
,
5564 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
5566 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5567 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5569 this->expect_tls_get_addr_call();
5570 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5571 if (tls_type
!= tls::TLSOPT_NONE
)
5572 this->skip_next_tls_get_addr_call();
5574 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5575 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5577 this->expect_tls_get_addr_call();
5578 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5579 if (tls_type
!= tls::TLSOPT_NONE
)
5580 this->skip_next_tls_get_addr_call();
5583 Powerpc_relobj
<size
, big_endian
>* ppc_object
5584 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5589 && data_shndx
== ppc_object
->opd_shndx()
5590 && r_type
== elfcpp::R_PPC64_ADDR64
)
5591 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5595 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5596 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
5597 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5599 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5600 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5601 r_type
, r_sym
, reloc
.get_r_addend());
5602 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
5607 case elfcpp::R_POWERPC_NONE
:
5608 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5609 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5610 case elfcpp::R_PPC64_TOCSAVE
:
5611 case elfcpp::R_POWERPC_TLS
:
5612 case elfcpp::R_PPC64_ENTRY
:
5615 case elfcpp::R_PPC64_TOC
:
5617 Output_data_got_powerpc
<size
, big_endian
>* got
5618 = target
->got_section(symtab
, layout
);
5619 if (parameters
->options().output_is_position_independent())
5621 Address off
= reloc
.get_r_offset();
5623 && target
->abiversion() < 2
5624 && data_shndx
== ppc_object
->opd_shndx()
5625 && ppc_object
->get_opd_discard(off
- 8))
5628 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5629 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5630 rela_dyn
->add_output_section_relative(got
->output_section(),
5631 elfcpp::R_POWERPC_RELATIVE
,
5633 object
, data_shndx
, off
,
5634 symobj
->toc_base_offset());
5639 case elfcpp::R_PPC64_ADDR64
:
5640 case elfcpp::R_PPC64_UADDR64
:
5641 case elfcpp::R_POWERPC_ADDR32
:
5642 case elfcpp::R_POWERPC_UADDR32
:
5643 case elfcpp::R_POWERPC_ADDR24
:
5644 case elfcpp::R_POWERPC_ADDR16
:
5645 case elfcpp::R_POWERPC_ADDR16_LO
:
5646 case elfcpp::R_POWERPC_ADDR16_HI
:
5647 case elfcpp::R_POWERPC_ADDR16_HA
:
5648 case elfcpp::R_POWERPC_UADDR16
:
5649 case elfcpp::R_PPC64_ADDR16_HIGH
:
5650 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5651 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5652 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5653 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5654 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5655 case elfcpp::R_PPC64_ADDR16_DS
:
5656 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5657 case elfcpp::R_POWERPC_ADDR14
:
5658 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5659 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5660 // If building a shared library (or a position-independent
5661 // executable), we need to create a dynamic relocation for
5663 if (parameters
->options().output_is_position_independent()
5664 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5666 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5668 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5669 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5670 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
5672 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5673 : elfcpp::R_POWERPC_RELATIVE
);
5674 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5675 output_section
, data_shndx
,
5676 reloc
.get_r_offset(),
5677 reloc
.get_r_addend(), false);
5679 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
5681 check_non_pic(object
, r_type
);
5682 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
5683 data_shndx
, reloc
.get_r_offset(),
5684 reloc
.get_r_addend());
5688 gold_assert(lsym
.get_st_value() == 0);
5689 unsigned int shndx
= lsym
.get_st_shndx();
5691 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
5694 object
->error(_("section symbol %u has bad shndx %u"),
5697 rela_dyn
->add_local_section(object
, shndx
, r_type
,
5698 output_section
, data_shndx
,
5699 reloc
.get_r_offset());
5704 case elfcpp::R_POWERPC_REL24
:
5705 case elfcpp::R_PPC_PLTREL24
:
5706 case elfcpp::R_PPC_LOCAL24PC
:
5707 case elfcpp::R_POWERPC_REL14
:
5708 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5709 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5711 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5712 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5713 reloc
.get_r_addend());
5716 case elfcpp::R_PPC64_REL64
:
5717 case elfcpp::R_POWERPC_REL32
:
5718 case elfcpp::R_POWERPC_REL16
:
5719 case elfcpp::R_POWERPC_REL16_LO
:
5720 case elfcpp::R_POWERPC_REL16_HI
:
5721 case elfcpp::R_POWERPC_REL16_HA
:
5722 case elfcpp::R_POWERPC_REL16DX_HA
:
5723 case elfcpp::R_POWERPC_SECTOFF
:
5724 case elfcpp::R_POWERPC_SECTOFF_LO
:
5725 case elfcpp::R_POWERPC_SECTOFF_HI
:
5726 case elfcpp::R_POWERPC_SECTOFF_HA
:
5727 case elfcpp::R_PPC64_SECTOFF_DS
:
5728 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5729 case elfcpp::R_POWERPC_TPREL16
:
5730 case elfcpp::R_POWERPC_TPREL16_LO
:
5731 case elfcpp::R_POWERPC_TPREL16_HI
:
5732 case elfcpp::R_POWERPC_TPREL16_HA
:
5733 case elfcpp::R_PPC64_TPREL16_DS
:
5734 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5735 case elfcpp::R_PPC64_TPREL16_HIGH
:
5736 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5737 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5738 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5739 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5740 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5741 case elfcpp::R_POWERPC_DTPREL16
:
5742 case elfcpp::R_POWERPC_DTPREL16_LO
:
5743 case elfcpp::R_POWERPC_DTPREL16_HI
:
5744 case elfcpp::R_POWERPC_DTPREL16_HA
:
5745 case elfcpp::R_PPC64_DTPREL16_DS
:
5746 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5747 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5748 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5749 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5750 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5751 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5752 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5753 case elfcpp::R_PPC64_TLSGD
:
5754 case elfcpp::R_PPC64_TLSLD
:
5755 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5758 case elfcpp::R_POWERPC_GOT16
:
5759 case elfcpp::R_POWERPC_GOT16_LO
:
5760 case elfcpp::R_POWERPC_GOT16_HI
:
5761 case elfcpp::R_POWERPC_GOT16_HA
:
5762 case elfcpp::R_PPC64_GOT16_DS
:
5763 case elfcpp::R_PPC64_GOT16_LO_DS
:
5765 // The symbol requires a GOT entry.
5766 Output_data_got_powerpc
<size
, big_endian
>* got
5767 = target
->got_section(symtab
, layout
);
5768 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5770 if (!parameters
->options().output_is_position_independent())
5773 && (size
== 32 || target
->abiversion() >= 2))
5774 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5776 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5778 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5780 // If we are generating a shared object or a pie, this
5781 // symbol's GOT entry will be set by a dynamic relocation.
5783 off
= got
->add_constant(0);
5784 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5786 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5788 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5789 : elfcpp::R_POWERPC_RELATIVE
);
5790 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5791 got
, off
, 0, false);
5796 case elfcpp::R_PPC64_TOC16
:
5797 case elfcpp::R_PPC64_TOC16_LO
:
5798 case elfcpp::R_PPC64_TOC16_HI
:
5799 case elfcpp::R_PPC64_TOC16_HA
:
5800 case elfcpp::R_PPC64_TOC16_DS
:
5801 case elfcpp::R_PPC64_TOC16_LO_DS
:
5802 // We need a GOT section.
5803 target
->got_section(symtab
, layout
);
5806 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5807 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5808 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5809 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5811 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5812 if (tls_type
== tls::TLSOPT_NONE
)
5814 Output_data_got_powerpc
<size
, big_endian
>* got
5815 = target
->got_section(symtab
, layout
);
5816 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5817 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5818 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5819 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5821 else if (tls_type
== tls::TLSOPT_TO_LE
)
5823 // no GOT relocs needed for Local Exec.
5830 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5831 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5832 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5833 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5835 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5836 if (tls_type
== tls::TLSOPT_NONE
)
5837 target
->tlsld_got_offset(symtab
, layout
, object
);
5838 else if (tls_type
== tls::TLSOPT_TO_LE
)
5840 // no GOT relocs needed for Local Exec.
5841 if (parameters
->options().emit_relocs())
5843 Output_section
* os
= layout
->tls_segment()->first_section();
5844 gold_assert(os
!= NULL
);
5845 os
->set_needs_symtab_index();
5853 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5854 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5855 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5856 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5858 Output_data_got_powerpc
<size
, big_endian
>* got
5859 = target
->got_section(symtab
, layout
);
5860 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5861 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5865 case elfcpp::R_POWERPC_GOT_TPREL16
:
5866 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5867 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5868 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5870 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5871 if (tls_type
== tls::TLSOPT_NONE
)
5873 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5874 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5876 Output_data_got_powerpc
<size
, big_endian
>* got
5877 = target
->got_section(symtab
, layout
);
5878 unsigned int off
= got
->add_constant(0);
5879 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5881 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5882 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5883 elfcpp::R_POWERPC_TPREL
,
5887 else if (tls_type
== tls::TLSOPT_TO_LE
)
5889 // no GOT relocs needed for Local Exec.
5897 unsupported_reloc_local(object
, r_type
);
5903 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5904 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5905 case elfcpp::R_POWERPC_GOT_TPREL16
:
5906 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5907 case elfcpp::R_POWERPC_GOT16
:
5908 case elfcpp::R_PPC64_GOT16_DS
:
5909 case elfcpp::R_PPC64_TOC16
:
5910 case elfcpp::R_PPC64_TOC16_DS
:
5911 ppc_object
->set_has_small_toc_reloc();
5917 // Report an unsupported relocation against a global symbol.
5919 template<int size
, bool big_endian
>
5921 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5922 Sized_relobj_file
<size
, big_endian
>* object
,
5923 unsigned int r_type
,
5926 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5927 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
5930 // Scan a relocation for a global symbol.
5932 template<int size
, bool big_endian
>
5934 Target_powerpc
<size
, big_endian
>::Scan::global(
5935 Symbol_table
* symtab
,
5937 Target_powerpc
<size
, big_endian
>* target
,
5938 Sized_relobj_file
<size
, big_endian
>* object
,
5939 unsigned int data_shndx
,
5940 Output_section
* output_section
,
5941 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5942 unsigned int r_type
,
5945 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
5948 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5949 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5951 this->expect_tls_get_addr_call();
5952 const bool final
= gsym
->final_value_is_known();
5953 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5954 if (tls_type
!= tls::TLSOPT_NONE
)
5955 this->skip_next_tls_get_addr_call();
5957 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5958 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5960 this->expect_tls_get_addr_call();
5961 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5962 if (tls_type
!= tls::TLSOPT_NONE
)
5963 this->skip_next_tls_get_addr_call();
5966 Powerpc_relobj
<size
, big_endian
>* ppc_object
5967 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5969 // A STT_GNU_IFUNC symbol may require a PLT entry.
5970 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
5971 bool pushed_ifunc
= false;
5972 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5974 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5975 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5976 reloc
.get_r_addend());
5977 target
->make_plt_entry(symtab
, layout
, gsym
);
5978 pushed_ifunc
= true;
5983 case elfcpp::R_POWERPC_NONE
:
5984 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5985 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5986 case elfcpp::R_PPC_LOCAL24PC
:
5987 case elfcpp::R_POWERPC_TLS
:
5988 case elfcpp::R_PPC64_ENTRY
:
5991 case elfcpp::R_PPC64_TOC
:
5993 Output_data_got_powerpc
<size
, big_endian
>* got
5994 = target
->got_section(symtab
, layout
);
5995 if (parameters
->options().output_is_position_independent())
5997 Address off
= reloc
.get_r_offset();
5999 && data_shndx
== ppc_object
->opd_shndx()
6000 && ppc_object
->get_opd_discard(off
- 8))
6003 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6004 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
6005 if (data_shndx
!= ppc_object
->opd_shndx())
6006 symobj
= static_cast
6007 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6008 rela_dyn
->add_output_section_relative(got
->output_section(),
6009 elfcpp::R_POWERPC_RELATIVE
,
6011 object
, data_shndx
, off
,
6012 symobj
->toc_base_offset());
6017 case elfcpp::R_PPC64_ADDR64
:
6019 && target
->abiversion() < 2
6020 && data_shndx
== ppc_object
->opd_shndx()
6021 && (gsym
->is_defined_in_discarded_section()
6022 || gsym
->object() != object
))
6024 ppc_object
->set_opd_discard(reloc
.get_r_offset());
6028 case elfcpp::R_PPC64_UADDR64
:
6029 case elfcpp::R_POWERPC_ADDR32
:
6030 case elfcpp::R_POWERPC_UADDR32
:
6031 case elfcpp::R_POWERPC_ADDR24
:
6032 case elfcpp::R_POWERPC_ADDR16
:
6033 case elfcpp::R_POWERPC_ADDR16_LO
:
6034 case elfcpp::R_POWERPC_ADDR16_HI
:
6035 case elfcpp::R_POWERPC_ADDR16_HA
:
6036 case elfcpp::R_POWERPC_UADDR16
:
6037 case elfcpp::R_PPC64_ADDR16_HIGH
:
6038 case elfcpp::R_PPC64_ADDR16_HIGHA
:
6039 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6040 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6041 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6042 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6043 case elfcpp::R_PPC64_ADDR16_DS
:
6044 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6045 case elfcpp::R_POWERPC_ADDR14
:
6046 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6047 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6049 // Make a PLT entry if necessary.
6050 if (gsym
->needs_plt_entry())
6052 // Since this is not a PC-relative relocation, we may be
6053 // taking the address of a function. In that case we need to
6054 // set the entry in the dynamic symbol table to the address of
6055 // the PLT call stub.
6056 bool need_ifunc_plt
= false;
6057 if ((size
== 32 || target
->abiversion() >= 2)
6058 && gsym
->is_from_dynobj()
6059 && !parameters
->options().output_is_position_independent())
6061 gsym
->set_needs_dynsym_value();
6062 need_ifunc_plt
= true;
6064 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
6066 target
->push_branch(ppc_object
, data_shndx
,
6067 reloc
.get_r_offset(), r_type
,
6068 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6069 reloc
.get_r_addend());
6070 target
->make_plt_entry(symtab
, layout
, gsym
);
6073 // Make a dynamic relocation if necessary.
6074 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
6075 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
6077 if (!parameters
->options().output_is_position_independent()
6078 && gsym
->may_need_copy_reloc())
6080 target
->copy_reloc(symtab
, layout
, object
,
6081 data_shndx
, output_section
, gsym
, reloc
);
6083 else if ((((size
== 32
6084 && r_type
== elfcpp::R_POWERPC_ADDR32
)
6086 && r_type
== elfcpp::R_PPC64_ADDR64
6087 && target
->abiversion() >= 2))
6088 && gsym
->can_use_relative_reloc(false)
6089 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
6090 && parameters
->options().shared()))
6092 && r_type
== elfcpp::R_PPC64_ADDR64
6093 && target
->abiversion() < 2
6094 && (gsym
->can_use_relative_reloc(false)
6095 || data_shndx
== ppc_object
->opd_shndx())))
6097 Reloc_section
* rela_dyn
6098 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6099 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6100 : elfcpp::R_POWERPC_RELATIVE
);
6101 rela_dyn
->add_symbolless_global_addend(
6102 gsym
, dynrel
, output_section
, object
, data_shndx
,
6103 reloc
.get_r_offset(), reloc
.get_r_addend());
6107 Reloc_section
* rela_dyn
6108 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6109 check_non_pic(object
, r_type
);
6110 rela_dyn
->add_global(gsym
, r_type
, output_section
,
6112 reloc
.get_r_offset(),
6113 reloc
.get_r_addend());
6119 case elfcpp::R_PPC_PLTREL24
:
6120 case elfcpp::R_POWERPC_REL24
:
6123 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6125 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6126 reloc
.get_r_addend());
6127 if (gsym
->needs_plt_entry()
6128 || (!gsym
->final_value_is_known()
6129 && (gsym
->is_undefined()
6130 || gsym
->is_from_dynobj()
6131 || gsym
->is_preemptible())))
6132 target
->make_plt_entry(symtab
, layout
, gsym
);
6136 case elfcpp::R_PPC64_REL64
:
6137 case elfcpp::R_POWERPC_REL32
:
6138 // Make a dynamic relocation if necessary.
6139 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
6141 if (!parameters
->options().output_is_position_independent()
6142 && gsym
->may_need_copy_reloc())
6144 target
->copy_reloc(symtab
, layout
, object
,
6145 data_shndx
, output_section
, gsym
,
6150 Reloc_section
* rela_dyn
6151 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6152 check_non_pic(object
, r_type
);
6153 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
6154 data_shndx
, reloc
.get_r_offset(),
6155 reloc
.get_r_addend());
6160 case elfcpp::R_POWERPC_REL14
:
6161 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6162 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6164 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6165 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6166 reloc
.get_r_addend());
6169 case elfcpp::R_POWERPC_REL16
:
6170 case elfcpp::R_POWERPC_REL16_LO
:
6171 case elfcpp::R_POWERPC_REL16_HI
:
6172 case elfcpp::R_POWERPC_REL16_HA
:
6173 case elfcpp::R_POWERPC_REL16DX_HA
:
6174 case elfcpp::R_POWERPC_SECTOFF
:
6175 case elfcpp::R_POWERPC_SECTOFF_LO
:
6176 case elfcpp::R_POWERPC_SECTOFF_HI
:
6177 case elfcpp::R_POWERPC_SECTOFF_HA
:
6178 case elfcpp::R_PPC64_SECTOFF_DS
:
6179 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6180 case elfcpp::R_POWERPC_TPREL16
:
6181 case elfcpp::R_POWERPC_TPREL16_LO
:
6182 case elfcpp::R_POWERPC_TPREL16_HI
:
6183 case elfcpp::R_POWERPC_TPREL16_HA
:
6184 case elfcpp::R_PPC64_TPREL16_DS
:
6185 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6186 case elfcpp::R_PPC64_TPREL16_HIGH
:
6187 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6188 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6189 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6190 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6191 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6192 case elfcpp::R_POWERPC_DTPREL16
:
6193 case elfcpp::R_POWERPC_DTPREL16_LO
:
6194 case elfcpp::R_POWERPC_DTPREL16_HI
:
6195 case elfcpp::R_POWERPC_DTPREL16_HA
:
6196 case elfcpp::R_PPC64_DTPREL16_DS
:
6197 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6198 case elfcpp::R_PPC64_DTPREL16_HIGH
:
6199 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
6200 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6201 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6202 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6203 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6204 case elfcpp::R_PPC64_TLSGD
:
6205 case elfcpp::R_PPC64_TLSLD
:
6206 case elfcpp::R_PPC64_ADDR64_LOCAL
:
6209 case elfcpp::R_POWERPC_GOT16
:
6210 case elfcpp::R_POWERPC_GOT16_LO
:
6211 case elfcpp::R_POWERPC_GOT16_HI
:
6212 case elfcpp::R_POWERPC_GOT16_HA
:
6213 case elfcpp::R_PPC64_GOT16_DS
:
6214 case elfcpp::R_PPC64_GOT16_LO_DS
:
6216 // The symbol requires a GOT entry.
6217 Output_data_got_powerpc
<size
, big_endian
>* got
;
6219 got
= target
->got_section(symtab
, layout
);
6220 if (gsym
->final_value_is_known())
6223 && (size
== 32 || target
->abiversion() >= 2))
6224 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
6226 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
6228 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
6230 // If we are generating a shared object or a pie, this
6231 // symbol's GOT entry will be set by a dynamic relocation.
6232 unsigned int off
= got
->add_constant(0);
6233 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
6235 Reloc_section
* rela_dyn
6236 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6238 if (gsym
->can_use_relative_reloc(false)
6240 || target
->abiversion() >= 2)
6241 && gsym
->visibility() == elfcpp::STV_PROTECTED
6242 && parameters
->options().shared()))
6244 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6245 : elfcpp::R_POWERPC_RELATIVE
);
6246 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
6250 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
6251 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
6257 case elfcpp::R_PPC64_TOC16
:
6258 case elfcpp::R_PPC64_TOC16_LO
:
6259 case elfcpp::R_PPC64_TOC16_HI
:
6260 case elfcpp::R_PPC64_TOC16_HA
:
6261 case elfcpp::R_PPC64_TOC16_DS
:
6262 case elfcpp::R_PPC64_TOC16_LO_DS
:
6263 // We need a GOT section.
6264 target
->got_section(symtab
, layout
);
6267 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6268 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6269 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6270 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6272 const bool final
= gsym
->final_value_is_known();
6273 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6274 if (tls_type
== tls::TLSOPT_NONE
)
6276 Output_data_got_powerpc
<size
, big_endian
>* got
6277 = target
->got_section(symtab
, layout
);
6278 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6279 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
6280 elfcpp::R_POWERPC_DTPMOD
,
6281 elfcpp::R_POWERPC_DTPREL
);
6283 else if (tls_type
== tls::TLSOPT_TO_IE
)
6285 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6287 Output_data_got_powerpc
<size
, big_endian
>* got
6288 = target
->got_section(symtab
, layout
);
6289 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6290 if (gsym
->is_undefined()
6291 || gsym
->is_from_dynobj())
6293 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6294 elfcpp::R_POWERPC_TPREL
);
6298 unsigned int off
= got
->add_constant(0);
6299 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6300 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6301 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6306 else if (tls_type
== tls::TLSOPT_TO_LE
)
6308 // no GOT relocs needed for Local Exec.
6315 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6316 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6317 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6318 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6320 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6321 if (tls_type
== tls::TLSOPT_NONE
)
6322 target
->tlsld_got_offset(symtab
, layout
, object
);
6323 else if (tls_type
== tls::TLSOPT_TO_LE
)
6325 // no GOT relocs needed for Local Exec.
6326 if (parameters
->options().emit_relocs())
6328 Output_section
* os
= layout
->tls_segment()->first_section();
6329 gold_assert(os
!= NULL
);
6330 os
->set_needs_symtab_index();
6338 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6339 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6340 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6341 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6343 Output_data_got_powerpc
<size
, big_endian
>* got
6344 = target
->got_section(symtab
, layout
);
6345 if (!gsym
->final_value_is_known()
6346 && (gsym
->is_from_dynobj()
6347 || gsym
->is_undefined()
6348 || gsym
->is_preemptible()))
6349 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
6350 target
->rela_dyn_section(layout
),
6351 elfcpp::R_POWERPC_DTPREL
);
6353 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
6357 case elfcpp::R_POWERPC_GOT_TPREL16
:
6358 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6359 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6360 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6362 const bool final
= gsym
->final_value_is_known();
6363 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6364 if (tls_type
== tls::TLSOPT_NONE
)
6366 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6368 Output_data_got_powerpc
<size
, big_endian
>* got
6369 = target
->got_section(symtab
, layout
);
6370 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6371 if (gsym
->is_undefined()
6372 || gsym
->is_from_dynobj())
6374 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6375 elfcpp::R_POWERPC_TPREL
);
6379 unsigned int off
= got
->add_constant(0);
6380 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6381 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6382 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6387 else if (tls_type
== tls::TLSOPT_TO_LE
)
6389 // no GOT relocs needed for Local Exec.
6397 unsupported_reloc_global(object
, r_type
, gsym
);
6403 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6404 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6405 case elfcpp::R_POWERPC_GOT_TPREL16
:
6406 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6407 case elfcpp::R_POWERPC_GOT16
:
6408 case elfcpp::R_PPC64_GOT16_DS
:
6409 case elfcpp::R_PPC64_TOC16
:
6410 case elfcpp::R_PPC64_TOC16_DS
:
6411 ppc_object
->set_has_small_toc_reloc();
6417 // Process relocations for gc.
6419 template<int size
, bool big_endian
>
6421 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
6422 Symbol_table
* symtab
,
6424 Sized_relobj_file
<size
, big_endian
>* object
,
6425 unsigned int data_shndx
,
6427 const unsigned char* prelocs
,
6429 Output_section
* output_section
,
6430 bool needs_special_offset_handling
,
6431 size_t local_symbol_count
,
6432 const unsigned char* plocal_symbols
)
6434 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6435 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
6438 Powerpc_relobj
<size
, big_endian
>* ppc_object
6439 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6441 ppc_object
->set_opd_valid();
6442 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
6444 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
6445 for (p
= ppc_object
->access_from_map()->begin();
6446 p
!= ppc_object
->access_from_map()->end();
6449 Address dst_off
= p
->first
;
6450 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6451 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
6452 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
6454 Relobj
* src_obj
= s
->first
;
6455 unsigned int src_indx
= s
->second
;
6456 symtab
->gc()->add_reference(src_obj
, src_indx
,
6457 ppc_object
, dst_indx
);
6461 ppc_object
->access_from_map()->clear();
6462 ppc_object
->process_gc_mark(symtab
);
6463 // Don't look at .opd relocs as .opd will reference everything.
6467 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
6476 needs_special_offset_handling
,
6481 // Handle target specific gc actions when adding a gc reference from
6482 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6483 // and DST_OFF. For powerpc64, this adds a referenc to the code
6484 // section of a function descriptor.
6486 template<int size
, bool big_endian
>
6488 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
6489 Symbol_table
* symtab
,
6491 unsigned int src_shndx
,
6493 unsigned int dst_shndx
,
6494 Address dst_off
) const
6496 if (size
!= 64 || dst_obj
->is_dynamic())
6499 Powerpc_relobj
<size
, big_endian
>* ppc_object
6500 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
6501 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
6503 if (ppc_object
->opd_valid())
6505 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
6506 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
6510 // If we haven't run scan_opd_relocs, we must delay
6511 // processing this function descriptor reference.
6512 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
6517 // Add any special sections for this symbol to the gc work list.
6518 // For powerpc64, this adds the code section of a function
6521 template<int size
, bool big_endian
>
6523 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
6524 Symbol_table
* symtab
,
6529 Powerpc_relobj
<size
, big_endian
>* ppc_object
6530 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
6532 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6533 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
6535 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
6536 Address dst_off
= gsym
->value();
6537 if (ppc_object
->opd_valid())
6539 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6540 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
6544 ppc_object
->add_gc_mark(dst_off
);
6549 // For a symbol location in .opd, set LOC to the location of the
6552 template<int size
, bool big_endian
>
6554 Target_powerpc
<size
, big_endian
>::do_function_location(
6555 Symbol_location
* loc
) const
6557 if (size
== 64 && loc
->shndx
!= 0)
6559 if (loc
->object
->is_dynamic())
6561 Powerpc_dynobj
<size
, big_endian
>* ppc_object
6562 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
6563 if (loc
->shndx
== ppc_object
->opd_shndx())
6566 Address off
= loc
->offset
- ppc_object
->opd_address();
6567 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
6568 loc
->offset
= dest_off
;
6573 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6574 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
6575 if (loc
->shndx
== ppc_object
->opd_shndx())
6578 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
6579 loc
->offset
= dest_off
;
6585 // FNOFFSET in section SHNDX in OBJECT is the start of a function
6586 // compiled with -fsplit-stack. The function calls non-split-stack
6587 // code. Change the function to ensure it has enough stack space to
6588 // call some random function.
6590 template<int size
, bool big_endian
>
6592 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
6595 section_offset_type fnoffset
,
6596 section_size_type fnsize
,
6597 const unsigned char* prelocs
,
6599 unsigned char* view
,
6600 section_size_type view_size
,
6602 std::string
* to
) const
6604 // 32-bit not supported.
6608 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
6609 prelocs
, reloc_count
, view
, view_size
,
6614 // The function always starts with
6615 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
6616 // addis %r12,%r1,-allocate@ha
6617 // addi %r12,%r12,-allocate@l
6619 // but note that the addis or addi may be replaced with a nop
6621 unsigned char *entry
= view
+ fnoffset
;
6622 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6624 if ((insn
& 0xffff0000) == addis_2_12
)
6626 /* Skip ELFv2 global entry code. */
6628 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6631 unsigned char *pinsn
= entry
;
6633 const uint32_t ld_private_ss
= 0xe80d8fc0;
6634 if (insn
== ld_private_ss
)
6636 int32_t allocate
= 0;
6640 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
6641 if ((insn
& 0xffff0000) == addis_12_1
)
6642 allocate
+= (insn
& 0xffff) << 16;
6643 else if ((insn
& 0xffff0000) == addi_12_1
6644 || (insn
& 0xffff0000) == addi_12_12
)
6645 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
6646 else if (insn
!= nop
)
6649 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
6651 int extra
= parameters
->options().split_stack_adjust_size();
6653 if (allocate
>= 0 || extra
< 0)
6655 object
->error(_("split-stack stack size overflow at "
6656 "section %u offset %0zx"),
6657 shndx
, static_cast<size_t>(fnoffset
));
6661 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
6662 if (insn
!= addis_12_1
)
6664 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6666 insn
= addi_12_12
| (allocate
& 0xffff);
6667 if (insn
!= addi_12_12
)
6669 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6675 insn
= addi_12_1
| (allocate
& 0xffff);
6676 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6679 if (pinsn
!= entry
+ 12)
6680 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
6688 if (!object
->has_no_split_stack())
6689 object
->error(_("failed to match split-stack sequence at "
6690 "section %u offset %0zx"),
6691 shndx
, static_cast<size_t>(fnoffset
));
6695 // Scan relocations for a section.
6697 template<int size
, bool big_endian
>
6699 Target_powerpc
<size
, big_endian
>::scan_relocs(
6700 Symbol_table
* symtab
,
6702 Sized_relobj_file
<size
, big_endian
>* object
,
6703 unsigned int data_shndx
,
6704 unsigned int sh_type
,
6705 const unsigned char* prelocs
,
6707 Output_section
* output_section
,
6708 bool needs_special_offset_handling
,
6709 size_t local_symbol_count
,
6710 const unsigned char* plocal_symbols
)
6712 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6713 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
6716 if (sh_type
== elfcpp::SHT_REL
)
6718 gold_error(_("%s: unsupported REL reloc section"),
6719 object
->name().c_str());
6723 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
6732 needs_special_offset_handling
,
6737 // Functor class for processing the global symbol table.
6738 // Removes symbols defined on discarded opd entries.
6740 template<bool big_endian
>
6741 class Global_symbol_visitor_opd
6744 Global_symbol_visitor_opd()
6748 operator()(Sized_symbol
<64>* sym
)
6750 if (sym
->has_symtab_index()
6751 || sym
->source() != Symbol::FROM_OBJECT
6752 || !sym
->in_real_elf())
6755 if (sym
->object()->is_dynamic())
6758 Powerpc_relobj
<64, big_endian
>* symobj
6759 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
6760 if (symobj
->opd_shndx() == 0)
6764 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6765 if (shndx
== symobj
->opd_shndx()
6766 && symobj
->get_opd_discard(sym
->value()))
6768 sym
->set_undefined();
6769 sym
->set_visibility(elfcpp::STV_DEFAULT
);
6770 sym
->set_is_defined_in_discarded_section();
6771 sym
->set_symtab_index(-1U);
6776 template<int size
, bool big_endian
>
6778 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
6780 Symbol_table
* symtab
)
6784 Output_data_save_res
<size
, big_endian
>* savres
6785 = new Output_data_save_res
<size
, big_endian
>(symtab
);
6786 this->savres_section_
= savres
;
6787 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6788 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6789 savres
, ORDER_TEXT
, false);
6793 // Sort linker created .got section first (for the header), then input
6794 // sections belonging to files using small model code.
6796 template<bool big_endian
>
6797 class Sort_toc_sections
6801 operator()(const Output_section::Input_section
& is1
,
6802 const Output_section::Input_section
& is2
) const
6804 if (!is1
.is_input_section() && is2
.is_input_section())
6807 = (is1
.is_input_section()
6808 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
6809 ->has_small_toc_reloc()));
6811 = (is2
.is_input_section()
6812 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
6813 ->has_small_toc_reloc()));
6814 return small1
&& !small2
;
6818 // Finalize the sections.
6820 template<int size
, bool big_endian
>
6822 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
6824 const Input_objects
*,
6825 Symbol_table
* symtab
)
6827 if (parameters
->doing_static_link())
6829 // At least some versions of glibc elf-init.o have a strong
6830 // reference to __rela_iplt marker syms. A weak ref would be
6832 if (this->iplt_
!= NULL
)
6834 Reloc_section
* rel
= this->iplt_
->rel_plt();
6835 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
6836 Symbol_table::PREDEFINED
, rel
, 0, 0,
6837 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6838 elfcpp::STV_HIDDEN
, 0, false, true);
6839 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
6840 Symbol_table::PREDEFINED
, rel
, 0, 0,
6841 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6842 elfcpp::STV_HIDDEN
, 0, true, true);
6846 symtab
->define_as_constant("__rela_iplt_start", NULL
,
6847 Symbol_table::PREDEFINED
, 0, 0,
6848 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6849 elfcpp::STV_HIDDEN
, 0, true, false);
6850 symtab
->define_as_constant("__rela_iplt_end", NULL
,
6851 Symbol_table::PREDEFINED
, 0, 0,
6852 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6853 elfcpp::STV_HIDDEN
, 0, true, false);
6859 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6860 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6862 if (!parameters
->options().relocatable())
6864 this->define_save_restore_funcs(layout
, symtab
);
6866 // Annoyingly, we need to make these sections now whether or
6867 // not we need them. If we delay until do_relax then we
6868 // need to mess with the relaxation machinery checkpointing.
6869 this->got_section(symtab
, layout
);
6870 this->make_brlt_section(layout
);
6872 if (parameters
->options().toc_sort())
6874 Output_section
* os
= this->got_
->output_section();
6875 if (os
!= NULL
&& os
->input_sections().size() > 1)
6876 std::stable_sort(os
->input_sections().begin(),
6877 os
->input_sections().end(),
6878 Sort_toc_sections
<big_endian
>());
6883 // Fill in some more dynamic tags.
6884 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6887 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6889 : this->plt_
->rel_plt());
6890 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6891 this->rela_dyn_
, true, size
== 32);
6895 if (this->got_
!= NULL
)
6897 this->got_
->finalize_data_size();
6898 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6899 this->got_
, this->got_
->g_o_t());
6904 if (this->glink_
!= NULL
)
6906 this->glink_
->finalize_data_size();
6907 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6909 (this->glink_
->pltresolve_size
6915 // Emit any relocs we saved in an attempt to avoid generating COPY
6917 if (this->copy_relocs_
.any_saved_relocs())
6918 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6921 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6925 ok_lo_toc_insn(uint32_t insn
)
6927 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6928 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6929 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6930 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6931 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6932 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6933 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6934 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6935 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6936 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6937 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6938 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6939 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6940 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6941 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6943 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6944 && ((insn
& 3) == 0 || (insn
& 3) == 3))
6945 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
6948 // Return the value to use for a branch relocation.
6950 template<int size
, bool big_endian
>
6952 Target_powerpc
<size
, big_endian
>::symval_for_branch(
6953 const Symbol_table
* symtab
,
6954 const Sized_symbol
<size
>* gsym
,
6955 Powerpc_relobj
<size
, big_endian
>* object
,
6957 unsigned int *dest_shndx
)
6959 if (size
== 32 || this->abiversion() >= 2)
6963 // If the symbol is defined in an opd section, ie. is a function
6964 // descriptor, use the function descriptor code entry address
6965 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
6967 && gsym
->source() != Symbol::FROM_OBJECT
)
6970 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6971 unsigned int shndx
= symobj
->opd_shndx();
6974 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
6975 if (opd_addr
== invalid_address
)
6977 opd_addr
+= symobj
->output_section_address(shndx
);
6978 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
6981 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
6982 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
6985 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
6986 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
6987 *dest_shndx
= folded
.second
;
6989 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
6990 if (sec_addr
== invalid_address
)
6993 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
6994 *value
= sec_addr
+ sec_off
;
6999 // Perform a relocation.
7001 template<int size
, bool big_endian
>
7003 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
7004 const Relocate_info
<size
, big_endian
>* relinfo
,
7006 Target_powerpc
* target
,
7009 const unsigned char* preloc
,
7010 const Sized_symbol
<size
>* gsym
,
7011 const Symbol_value
<size
>* psymval
,
7012 unsigned char* view
,
7014 section_size_type view_size
)
7019 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
7020 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
7021 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
7023 case Track_tls::NOT_EXPECTED
:
7024 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7025 _("__tls_get_addr call lacks marker reloc"));
7027 case Track_tls::EXPECTED
:
7028 // We have already complained.
7030 case Track_tls::SKIP
:
7032 case Track_tls::NORMAL
:
7036 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
7037 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
7038 typedef typename Reloc_types
<elfcpp::SHT_RELA
,
7039 size
, big_endian
>::Reloc Reltype
;
7040 // Offset from start of insn to d-field reloc.
7041 const int d_offset
= big_endian
? 2 : 0;
7043 Powerpc_relobj
<size
, big_endian
>* const object
7044 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
7046 bool has_stub_value
= false;
7047 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7049 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
7050 : object
->local_has_plt_offset(r_sym
))
7051 && (!psymval
->is_ifunc_symbol()
7052 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
7056 && target
->abiversion() >= 2
7057 && !parameters
->options().output_is_position_independent()
7058 && !is_branch_reloc(r_type
))
7060 Address off
= target
->glink_section()->find_global_entry(gsym
);
7061 if (off
!= invalid_address
)
7063 value
= target
->glink_section()->global_entry_address() + off
;
7064 has_stub_value
= true;
7069 Stub_table
<size
, big_endian
>* stub_table
7070 = object
->stub_table(relinfo
->data_shndx
);
7071 if (stub_table
== NULL
)
7073 // This is a ref from a data section to an ifunc symbol.
7074 if (target
->stub_tables().size() != 0)
7075 stub_table
= target
->stub_tables()[0];
7077 if (stub_table
!= NULL
)
7081 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
7082 rela
.get_r_addend());
7084 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
7085 rela
.get_r_addend());
7086 if (off
!= invalid_address
)
7088 value
= stub_table
->stub_address() + off
;
7089 has_stub_value
= true;
7093 // We don't care too much about bogus debug references to
7094 // non-local functions, but otherwise there had better be a plt
7095 // call stub or global entry stub as appropriate.
7096 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
7099 if (r_type
== elfcpp::R_POWERPC_GOT16
7100 || r_type
== elfcpp::R_POWERPC_GOT16_LO
7101 || r_type
== elfcpp::R_POWERPC_GOT16_HI
7102 || r_type
== elfcpp::R_POWERPC_GOT16_HA
7103 || r_type
== elfcpp::R_PPC64_GOT16_DS
7104 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
7108 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
7109 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
7113 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7114 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
7115 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
7117 value
-= target
->got_section()->got_base_offset(object
);
7119 else if (r_type
== elfcpp::R_PPC64_TOC
)
7121 value
= (target
->got_section()->output_section()->address()
7122 + object
->toc_base_offset());
7124 else if (gsym
!= NULL
7125 && (r_type
== elfcpp::R_POWERPC_REL24
7126 || r_type
== elfcpp::R_PPC_PLTREL24
)
7131 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
7132 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
7133 bool can_plt_call
= false;
7134 if (rela
.get_r_offset() + 8 <= view_size
)
7136 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
7137 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
7140 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
7142 elfcpp::Swap
<32, big_endian
>::
7143 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
7144 can_plt_call
= true;
7149 // If we don't have a branch and link followed by a nop,
7150 // we can't go via the plt because there is no place to
7151 // put a toc restoring instruction.
7152 // Unless we know we won't be returning.
7153 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
7154 can_plt_call
= true;
7158 // g++ as of 20130507 emits self-calls without a
7159 // following nop. This is arguably wrong since we have
7160 // conflicting information. On the one hand a global
7161 // symbol and on the other a local call sequence, but
7162 // don't error for this special case.
7163 // It isn't possible to cheaply verify we have exactly
7164 // such a call. Allow all calls to the same section.
7166 Address code
= value
;
7167 if (gsym
->source() == Symbol::FROM_OBJECT
7168 && gsym
->object() == object
)
7170 unsigned int dest_shndx
= 0;
7171 if (target
->abiversion() < 2)
7173 Address addend
= rela
.get_r_addend();
7174 code
= psymval
->value(object
, addend
);
7175 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7176 &code
, &dest_shndx
);
7179 if (dest_shndx
== 0)
7180 dest_shndx
= gsym
->shndx(&is_ordinary
);
7181 ok
= dest_shndx
== relinfo
->data_shndx
;
7185 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7186 _("call lacks nop, can't restore toc; "
7187 "recompile with -fPIC"));
7193 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7194 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
7195 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
7196 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
7198 // First instruction of a global dynamic sequence, arg setup insn.
7199 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7200 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7201 enum Got_type got_type
= GOT_TYPE_STANDARD
;
7202 if (tls_type
== tls::TLSOPT_NONE
)
7203 got_type
= GOT_TYPE_TLSGD
;
7204 else if (tls_type
== tls::TLSOPT_TO_IE
)
7205 got_type
= GOT_TYPE_TPREL
;
7206 if (got_type
!= GOT_TYPE_STANDARD
)
7210 gold_assert(gsym
->has_got_offset(got_type
));
7211 value
= gsym
->got_offset(got_type
);
7215 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7216 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
7217 value
= object
->local_got_offset(r_sym
, got_type
);
7219 value
-= target
->got_section()->got_base_offset(object
);
7221 if (tls_type
== tls::TLSOPT_TO_IE
)
7223 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7224 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7226 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7227 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7228 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
7230 insn
|= 32 << 26; // lwz
7232 insn
|= 58 << 26; // ld
7233 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7235 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7236 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7238 else if (tls_type
== tls::TLSOPT_TO_LE
)
7240 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7241 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7243 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7244 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7245 insn
&= (1 << 26) - (1 << 21); // extract rt
7250 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7251 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7252 value
= psymval
->value(object
, rela
.get_r_addend());
7256 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7258 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7259 r_type
= elfcpp::R_POWERPC_NONE
;
7263 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7264 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7265 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7266 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7268 // First instruction of a local dynamic sequence, arg setup insn.
7269 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7270 if (tls_type
== tls::TLSOPT_NONE
)
7272 value
= target
->tlsld_got_offset();
7273 value
-= target
->got_section()->got_base_offset(object
);
7277 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7278 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7279 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7281 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7282 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7283 insn
&= (1 << 26) - (1 << 21); // extract rt
7288 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7289 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7294 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7296 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7297 r_type
= elfcpp::R_POWERPC_NONE
;
7301 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
7302 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
7303 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
7304 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
7306 // Accesses relative to a local dynamic sequence address,
7307 // no optimisation here.
7310 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
7311 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
7315 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7316 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
7317 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
7319 value
-= target
->got_section()->got_base_offset(object
);
7321 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7322 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7323 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7324 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
7326 // First instruction of initial exec sequence.
7327 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7328 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7329 if (tls_type
== tls::TLSOPT_NONE
)
7333 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
7334 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
7338 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7339 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
7340 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
7342 value
-= target
->got_section()->got_base_offset(object
);
7346 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7347 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7348 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
7350 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7351 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7352 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
7357 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7358 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7359 value
= psymval
->value(object
, rela
.get_r_addend());
7363 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7365 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7366 r_type
= elfcpp::R_POWERPC_NONE
;
7370 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7371 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7373 // Second instruction of a global dynamic sequence,
7374 // the __tls_get_addr call
7375 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7376 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7377 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7378 if (tls_type
!= tls::TLSOPT_NONE
)
7380 if (tls_type
== tls::TLSOPT_TO_IE
)
7382 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7383 Insn insn
= add_3_3_13
;
7386 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7387 r_type
= elfcpp::R_POWERPC_NONE
;
7391 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7392 Insn insn
= addi_3_3
;
7393 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7394 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7396 value
= psymval
->value(object
, rela
.get_r_addend());
7398 this->skip_next_tls_get_addr_call();
7401 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7402 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7404 // Second instruction of a local dynamic sequence,
7405 // the __tls_get_addr call
7406 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7407 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7408 if (tls_type
== tls::TLSOPT_TO_LE
)
7410 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7411 Insn insn
= addi_3_3
;
7412 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7413 this->skip_next_tls_get_addr_call();
7414 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7419 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7421 // Second instruction of an initial exec sequence
7422 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7423 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7424 if (tls_type
== tls::TLSOPT_TO_LE
)
7426 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7427 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7428 unsigned int reg
= size
== 32 ? 2 : 13;
7429 insn
= at_tls_transform(insn
, reg
);
7430 gold_assert(insn
!= 0);
7431 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7432 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7434 value
= psymval
->value(object
, rela
.get_r_addend());
7437 else if (!has_stub_value
)
7440 if (!(size
== 32 && r_type
== elfcpp::R_PPC_PLTREL24
))
7441 addend
= rela
.get_r_addend();
7442 value
= psymval
->value(object
, addend
);
7443 if (size
== 64 && is_branch_reloc(r_type
))
7445 if (target
->abiversion() >= 2)
7448 value
+= object
->ppc64_local_entry_offset(gsym
);
7450 value
+= object
->ppc64_local_entry_offset(r_sym
);
7454 unsigned int dest_shndx
;
7455 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7456 &value
, &dest_shndx
);
7459 Address max_branch_offset
= max_branch_delta(r_type
);
7460 if (max_branch_offset
!= 0
7461 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
7463 Stub_table
<size
, big_endian
>* stub_table
7464 = object
->stub_table(relinfo
->data_shndx
);
7465 if (stub_table
!= NULL
)
7467 Address off
= stub_table
->find_long_branch_entry(object
, value
);
7468 if (off
!= invalid_address
)
7470 value
= (stub_table
->stub_address() + stub_table
->plt_size()
7472 has_stub_value
= true;
7480 case elfcpp::R_PPC64_REL64
:
7481 case elfcpp::R_POWERPC_REL32
:
7482 case elfcpp::R_POWERPC_REL24
:
7483 case elfcpp::R_PPC_PLTREL24
:
7484 case elfcpp::R_PPC_LOCAL24PC
:
7485 case elfcpp::R_POWERPC_REL16
:
7486 case elfcpp::R_POWERPC_REL16_LO
:
7487 case elfcpp::R_POWERPC_REL16_HI
:
7488 case elfcpp::R_POWERPC_REL16_HA
:
7489 case elfcpp::R_POWERPC_REL16DX_HA
:
7490 case elfcpp::R_POWERPC_REL14
:
7491 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7492 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7496 case elfcpp::R_PPC64_TOC16
:
7497 case elfcpp::R_PPC64_TOC16_LO
:
7498 case elfcpp::R_PPC64_TOC16_HI
:
7499 case elfcpp::R_PPC64_TOC16_HA
:
7500 case elfcpp::R_PPC64_TOC16_DS
:
7501 case elfcpp::R_PPC64_TOC16_LO_DS
:
7502 // Subtract the TOC base address.
7503 value
-= (target
->got_section()->output_section()->address()
7504 + object
->toc_base_offset());
7507 case elfcpp::R_POWERPC_SECTOFF
:
7508 case elfcpp::R_POWERPC_SECTOFF_LO
:
7509 case elfcpp::R_POWERPC_SECTOFF_HI
:
7510 case elfcpp::R_POWERPC_SECTOFF_HA
:
7511 case elfcpp::R_PPC64_SECTOFF_DS
:
7512 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7514 value
-= os
->address();
7517 case elfcpp::R_PPC64_TPREL16_DS
:
7518 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7519 case elfcpp::R_PPC64_TPREL16_HIGH
:
7520 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7522 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7524 case elfcpp::R_POWERPC_TPREL16
:
7525 case elfcpp::R_POWERPC_TPREL16_LO
:
7526 case elfcpp::R_POWERPC_TPREL16_HI
:
7527 case elfcpp::R_POWERPC_TPREL16_HA
:
7528 case elfcpp::R_POWERPC_TPREL
:
7529 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7530 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7531 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7532 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7533 // tls symbol values are relative to tls_segment()->vaddr()
7537 case elfcpp::R_PPC64_DTPREL16_DS
:
7538 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7539 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7540 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7541 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7542 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7544 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7545 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7547 case elfcpp::R_POWERPC_DTPREL16
:
7548 case elfcpp::R_POWERPC_DTPREL16_LO
:
7549 case elfcpp::R_POWERPC_DTPREL16_HI
:
7550 case elfcpp::R_POWERPC_DTPREL16_HA
:
7551 case elfcpp::R_POWERPC_DTPREL
:
7552 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7553 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7554 // tls symbol values are relative to tls_segment()->vaddr()
7555 value
-= dtp_offset
;
7558 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7560 value
+= object
->ppc64_local_entry_offset(gsym
);
7562 value
+= object
->ppc64_local_entry_offset(r_sym
);
7569 Insn branch_bit
= 0;
7572 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7573 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7574 branch_bit
= 1 << 21;
7575 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7576 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7578 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7579 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7582 if (this->is_isa_v2
)
7584 // Set 'a' bit. This is 0b00010 in BO field for branch
7585 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7586 // for branch on CTR insns (BO == 1a00t or 1a01t).
7587 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7589 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7596 // Invert 'y' bit if not the default.
7597 if (static_cast<Signed_address
>(value
) < 0)
7600 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7610 // Multi-instruction sequences that access the TOC can be
7611 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7612 // to nop; addi rb,r2,x;
7618 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7619 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7620 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7621 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7622 case elfcpp::R_POWERPC_GOT16_HA
:
7623 case elfcpp::R_PPC64_TOC16_HA
:
7624 if (parameters
->options().toc_optimize())
7626 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7627 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7628 if ((insn
& ((0x3f << 26) | 0x1f << 16))
7629 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7630 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7631 _("toc optimization is not supported "
7632 "for %#08x instruction"), insn
);
7633 else if (value
+ 0x8000 < 0x10000)
7635 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
7641 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7642 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7643 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7644 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7645 case elfcpp::R_POWERPC_GOT16_LO
:
7646 case elfcpp::R_PPC64_GOT16_LO_DS
:
7647 case elfcpp::R_PPC64_TOC16_LO
:
7648 case elfcpp::R_PPC64_TOC16_LO_DS
:
7649 if (parameters
->options().toc_optimize())
7651 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7652 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7653 if (!ok_lo_toc_insn(insn
))
7654 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7655 _("toc optimization is not supported "
7656 "for %#08x instruction"), insn
);
7657 else if (value
+ 0x8000 < 0x10000)
7659 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
7661 // Transform addic to addi when we change reg.
7662 insn
&= ~((0x3f << 26) | (0x1f << 16));
7663 insn
|= (14u << 26) | (2 << 16);
7667 insn
&= ~(0x1f << 16);
7670 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7675 case elfcpp::R_PPC64_ENTRY
:
7676 value
= (target
->got_section()->output_section()->address()
7677 + object
->toc_base_offset());
7678 if (value
+ 0x80008000 <= 0xffffffff
7679 && !parameters
->options().output_is_position_independent())
7681 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7682 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7683 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
7685 if ((insn1
& ~0xfffc) == ld_2_12
7686 && insn2
== add_2_2_12
)
7688 insn1
= lis_2
+ ha(value
);
7689 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
7690 insn2
= addi_2_2
+ l(value
);
7691 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
7698 if (value
+ 0x80008000 <= 0xffffffff)
7700 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7701 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7702 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
7704 if ((insn1
& ~0xfffc) == ld_2_12
7705 && insn2
== add_2_2_12
)
7707 insn1
= addis_2_12
+ ha(value
);
7708 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
7709 insn2
= addi_2_2
+ l(value
);
7710 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
7717 case elfcpp::R_POWERPC_REL16_LO
:
7718 // If we are generating a non-PIC executable, edit
7719 // 0: addis 2,12,.TOC.-0b@ha
7720 // addi 2,2,.TOC.-0b@l
7721 // used by ELFv2 global entry points to set up r2, to
7724 // if .TOC. is in range. */
7725 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
7728 && target
->abiversion() >= 2
7729 && !parameters
->options().output_is_position_independent()
7730 && rela
.get_r_addend() == d_offset
+ 4
7732 && strcmp(gsym
->name(), ".TOC.") == 0)
7734 const int reloc_size
7735 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
7736 Reltype
prev_rela(preloc
- reloc_size
);
7737 if ((prev_rela
.get_r_info()
7738 == elfcpp::elf_r_info
<size
>(r_sym
,
7739 elfcpp::R_POWERPC_REL16_HA
))
7740 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
7741 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
7743 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7744 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
7745 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7747 if ((insn1
& 0xffff0000) == addis_2_12
7748 && (insn2
& 0xffff0000) == addi_2_2
)
7750 insn1
= lis_2
+ ha(value
+ address
- 4);
7751 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
7752 insn2
= addi_2_2
+ l(value
+ address
- 4);
7753 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
7756 relinfo
->rr
->set_strategy(relnum
- 1,
7757 Relocatable_relocs::RELOC_SPECIAL
);
7758 relinfo
->rr
->set_strategy(relnum
,
7759 Relocatable_relocs::RELOC_SPECIAL
);
7769 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
7770 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
7773 case elfcpp::R_POWERPC_ADDR32
:
7774 case elfcpp::R_POWERPC_UADDR32
:
7776 overflow
= Reloc::CHECK_BITFIELD
;
7779 case elfcpp::R_POWERPC_REL32
:
7780 case elfcpp::R_POWERPC_REL16DX_HA
:
7782 overflow
= Reloc::CHECK_SIGNED
;
7785 case elfcpp::R_POWERPC_UADDR16
:
7786 overflow
= Reloc::CHECK_BITFIELD
;
7789 case elfcpp::R_POWERPC_ADDR16
:
7790 // We really should have three separate relocations,
7791 // one for 16-bit data, one for insns with 16-bit signed fields,
7792 // and one for insns with 16-bit unsigned fields.
7793 overflow
= Reloc::CHECK_BITFIELD
;
7794 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
7795 overflow
= Reloc::CHECK_LOW_INSN
;
7798 case elfcpp::R_POWERPC_ADDR16_HI
:
7799 case elfcpp::R_POWERPC_ADDR16_HA
:
7800 case elfcpp::R_POWERPC_GOT16_HI
:
7801 case elfcpp::R_POWERPC_GOT16_HA
:
7802 case elfcpp::R_POWERPC_PLT16_HI
:
7803 case elfcpp::R_POWERPC_PLT16_HA
:
7804 case elfcpp::R_POWERPC_SECTOFF_HI
:
7805 case elfcpp::R_POWERPC_SECTOFF_HA
:
7806 case elfcpp::R_PPC64_TOC16_HI
:
7807 case elfcpp::R_PPC64_TOC16_HA
:
7808 case elfcpp::R_PPC64_PLTGOT16_HI
:
7809 case elfcpp::R_PPC64_PLTGOT16_HA
:
7810 case elfcpp::R_POWERPC_TPREL16_HI
:
7811 case elfcpp::R_POWERPC_TPREL16_HA
:
7812 case elfcpp::R_POWERPC_DTPREL16_HI
:
7813 case elfcpp::R_POWERPC_DTPREL16_HA
:
7814 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7815 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7816 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7817 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7818 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7819 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7820 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7821 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7822 case elfcpp::R_POWERPC_REL16_HI
:
7823 case elfcpp::R_POWERPC_REL16_HA
:
7825 overflow
= Reloc::CHECK_HIGH_INSN
;
7828 case elfcpp::R_POWERPC_REL16
:
7829 case elfcpp::R_PPC64_TOC16
:
7830 case elfcpp::R_POWERPC_GOT16
:
7831 case elfcpp::R_POWERPC_SECTOFF
:
7832 case elfcpp::R_POWERPC_TPREL16
:
7833 case elfcpp::R_POWERPC_DTPREL16
:
7834 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7835 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7836 case elfcpp::R_POWERPC_GOT_TPREL16
:
7837 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7838 overflow
= Reloc::CHECK_LOW_INSN
;
7841 case elfcpp::R_POWERPC_ADDR24
:
7842 case elfcpp::R_POWERPC_ADDR14
:
7843 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7844 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7845 case elfcpp::R_PPC64_ADDR16_DS
:
7846 case elfcpp::R_POWERPC_REL24
:
7847 case elfcpp::R_PPC_PLTREL24
:
7848 case elfcpp::R_PPC_LOCAL24PC
:
7849 case elfcpp::R_PPC64_TPREL16_DS
:
7850 case elfcpp::R_PPC64_DTPREL16_DS
:
7851 case elfcpp::R_PPC64_TOC16_DS
:
7852 case elfcpp::R_PPC64_GOT16_DS
:
7853 case elfcpp::R_PPC64_SECTOFF_DS
:
7854 case elfcpp::R_POWERPC_REL14
:
7855 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7856 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7857 overflow
= Reloc::CHECK_SIGNED
;
7861 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7864 if (overflow
== Reloc::CHECK_LOW_INSN
7865 || overflow
== Reloc::CHECK_HIGH_INSN
)
7867 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7869 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
7870 overflow
= Reloc::CHECK_BITFIELD
;
7871 else if (overflow
== Reloc::CHECK_LOW_INSN
7872 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
7873 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
7874 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
7875 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
7876 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
7877 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
7878 overflow
= Reloc::CHECK_UNSIGNED
;
7880 overflow
= Reloc::CHECK_SIGNED
;
7883 bool maybe_dq_reloc
= false;
7884 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
7885 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
7888 case elfcpp::R_POWERPC_NONE
:
7889 case elfcpp::R_POWERPC_TLS
:
7890 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7891 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7894 case elfcpp::R_PPC64_ADDR64
:
7895 case elfcpp::R_PPC64_REL64
:
7896 case elfcpp::R_PPC64_TOC
:
7897 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7898 Reloc::addr64(view
, value
);
7901 case elfcpp::R_POWERPC_TPREL
:
7902 case elfcpp::R_POWERPC_DTPREL
:
7904 Reloc::addr64(view
, value
);
7906 status
= Reloc::addr32(view
, value
, overflow
);
7909 case elfcpp::R_PPC64_UADDR64
:
7910 Reloc::addr64_u(view
, value
);
7913 case elfcpp::R_POWERPC_ADDR32
:
7914 status
= Reloc::addr32(view
, value
, overflow
);
7917 case elfcpp::R_POWERPC_REL32
:
7918 case elfcpp::R_POWERPC_UADDR32
:
7919 status
= Reloc::addr32_u(view
, value
, overflow
);
7922 case elfcpp::R_POWERPC_ADDR24
:
7923 case elfcpp::R_POWERPC_REL24
:
7924 case elfcpp::R_PPC_PLTREL24
:
7925 case elfcpp::R_PPC_LOCAL24PC
:
7926 status
= Reloc::addr24(view
, value
, overflow
);
7929 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7930 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7931 case elfcpp::R_POWERPC_GOT_TPREL16
:
7932 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7935 // On ppc64 these are all ds form
7936 maybe_dq_reloc
= true;
7939 case elfcpp::R_POWERPC_ADDR16
:
7940 case elfcpp::R_POWERPC_REL16
:
7941 case elfcpp::R_PPC64_TOC16
:
7942 case elfcpp::R_POWERPC_GOT16
:
7943 case elfcpp::R_POWERPC_SECTOFF
:
7944 case elfcpp::R_POWERPC_TPREL16
:
7945 case elfcpp::R_POWERPC_DTPREL16
:
7946 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7947 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7948 case elfcpp::R_POWERPC_ADDR16_LO
:
7949 case elfcpp::R_POWERPC_REL16_LO
:
7950 case elfcpp::R_PPC64_TOC16_LO
:
7951 case elfcpp::R_POWERPC_GOT16_LO
:
7952 case elfcpp::R_POWERPC_SECTOFF_LO
:
7953 case elfcpp::R_POWERPC_TPREL16_LO
:
7954 case elfcpp::R_POWERPC_DTPREL16_LO
:
7955 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7956 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7958 status
= Reloc::addr16(view
, value
, overflow
);
7960 maybe_dq_reloc
= true;
7963 case elfcpp::R_POWERPC_UADDR16
:
7964 status
= Reloc::addr16_u(view
, value
, overflow
);
7967 case elfcpp::R_PPC64_ADDR16_HIGH
:
7968 case elfcpp::R_PPC64_TPREL16_HIGH
:
7969 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7971 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
7973 case elfcpp::R_POWERPC_ADDR16_HI
:
7974 case elfcpp::R_POWERPC_REL16_HI
:
7975 case elfcpp::R_PPC64_TOC16_HI
:
7976 case elfcpp::R_POWERPC_GOT16_HI
:
7977 case elfcpp::R_POWERPC_SECTOFF_HI
:
7978 case elfcpp::R_POWERPC_TPREL16_HI
:
7979 case elfcpp::R_POWERPC_DTPREL16_HI
:
7980 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7981 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7982 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7983 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7984 Reloc::addr16_hi(view
, value
);
7987 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7988 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7989 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7991 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
7993 case elfcpp::R_POWERPC_ADDR16_HA
:
7994 case elfcpp::R_POWERPC_REL16_HA
:
7995 case elfcpp::R_PPC64_TOC16_HA
:
7996 case elfcpp::R_POWERPC_GOT16_HA
:
7997 case elfcpp::R_POWERPC_SECTOFF_HA
:
7998 case elfcpp::R_POWERPC_TPREL16_HA
:
7999 case elfcpp::R_POWERPC_DTPREL16_HA
:
8000 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8001 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8002 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8003 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8004 Reloc::addr16_ha(view
, value
);
8007 case elfcpp::R_POWERPC_REL16DX_HA
:
8008 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
8011 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8013 // R_PPC_EMB_NADDR16_LO
8015 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8016 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8017 Reloc::addr16_hi2(view
, value
);
8020 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8022 // R_PPC_EMB_NADDR16_HI
8024 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8025 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8026 Reloc::addr16_ha2(view
, value
);
8029 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8031 // R_PPC_EMB_NADDR16_HA
8033 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8034 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8035 Reloc::addr16_hi3(view
, value
);
8038 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8042 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8043 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8044 Reloc::addr16_ha3(view
, value
);
8047 case elfcpp::R_PPC64_DTPREL16_DS
:
8048 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8050 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
8052 case elfcpp::R_PPC64_TPREL16_DS
:
8053 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8055 // R_PPC_TLSGD, R_PPC_TLSLD
8057 case elfcpp::R_PPC64_ADDR16_DS
:
8058 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8059 case elfcpp::R_PPC64_TOC16_DS
:
8060 case elfcpp::R_PPC64_TOC16_LO_DS
:
8061 case elfcpp::R_PPC64_GOT16_DS
:
8062 case elfcpp::R_PPC64_GOT16_LO_DS
:
8063 case elfcpp::R_PPC64_SECTOFF_DS
:
8064 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8065 maybe_dq_reloc
= true;
8068 case elfcpp::R_POWERPC_ADDR14
:
8069 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8070 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8071 case elfcpp::R_POWERPC_REL14
:
8072 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8073 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8074 status
= Reloc::addr14(view
, value
, overflow
);
8077 case elfcpp::R_POWERPC_COPY
:
8078 case elfcpp::R_POWERPC_GLOB_DAT
:
8079 case elfcpp::R_POWERPC_JMP_SLOT
:
8080 case elfcpp::R_POWERPC_RELATIVE
:
8081 case elfcpp::R_POWERPC_DTPMOD
:
8082 case elfcpp::R_PPC64_JMP_IREL
:
8083 case elfcpp::R_POWERPC_IRELATIVE
:
8084 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8085 _("unexpected reloc %u in object file"),
8089 case elfcpp::R_PPC_EMB_SDA21
:
8094 // R_PPC64_TOCSAVE. For the time being this can be ignored.
8098 case elfcpp::R_PPC_EMB_SDA2I16
:
8099 case elfcpp::R_PPC_EMB_SDA2REL
:
8102 // R_PPC64_TLSGD, R_PPC64_TLSLD
8105 case elfcpp::R_POWERPC_PLT32
:
8106 case elfcpp::R_POWERPC_PLTREL32
:
8107 case elfcpp::R_POWERPC_PLT16_LO
:
8108 case elfcpp::R_POWERPC_PLT16_HI
:
8109 case elfcpp::R_POWERPC_PLT16_HA
:
8110 case elfcpp::R_PPC_SDAREL16
:
8111 case elfcpp::R_POWERPC_ADDR30
:
8112 case elfcpp::R_PPC64_PLT64
:
8113 case elfcpp::R_PPC64_PLTREL64
:
8114 case elfcpp::R_PPC64_PLTGOT16
:
8115 case elfcpp::R_PPC64_PLTGOT16_LO
:
8116 case elfcpp::R_PPC64_PLTGOT16_HI
:
8117 case elfcpp::R_PPC64_PLTGOT16_HA
:
8118 case elfcpp::R_PPC64_PLT16_LO_DS
:
8119 case elfcpp::R_PPC64_PLTGOT16_DS
:
8120 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
8121 case elfcpp::R_PPC_EMB_RELSDA
:
8122 case elfcpp::R_PPC_TOC16
:
8125 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8126 _("unsupported reloc %u"),
8134 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8136 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
8137 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
8138 && (insn
& 3) == 1))
8139 status
= Reloc::addr16_dq(view
, value
, overflow
);
8141 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
8142 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
8143 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
8144 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
8145 status
= Reloc::addr16_ds(view
, value
, overflow
);
8147 status
= Reloc::addr16(view
, value
, overflow
);
8150 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
8153 && gsym
->is_undefined()
8154 && is_branch_reloc(r_type
))))
8156 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8157 _("relocation overflow"));
8159 gold_info(_("try relinking with a smaller --stub-group-size"));
8165 // Relocate section data.
8167 template<int size
, bool big_endian
>
8169 Target_powerpc
<size
, big_endian
>::relocate_section(
8170 const Relocate_info
<size
, big_endian
>* relinfo
,
8171 unsigned int sh_type
,
8172 const unsigned char* prelocs
,
8174 Output_section
* output_section
,
8175 bool needs_special_offset_handling
,
8176 unsigned char* view
,
8178 section_size_type view_size
,
8179 const Reloc_symbol_changes
* reloc_symbol_changes
)
8181 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8182 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
8183 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
8184 Powerpc_comdat_behavior
;
8185 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8188 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8190 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
8191 Powerpc_comdat_behavior
, Classify_reloc
>(
8197 needs_special_offset_handling
,
8201 reloc_symbol_changes
);
8204 template<int size
, bool big_endian
>
8205 class Powerpc_scan_relocatable_reloc
8208 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
8210 static const int reloc_size
=
8211 Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
8212 static const int sh_type
= elfcpp::SHT_RELA
;
8214 // Return the symbol referred to by the relocation.
8215 static inline unsigned int
8216 get_r_sym(const Reltype
* reloc
)
8217 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
8219 // Return the type of the relocation.
8220 static inline unsigned int
8221 get_r_type(const Reltype
* reloc
)
8222 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
8224 // Return the strategy to use for a local symbol which is not a
8225 // section symbol, given the relocation type.
8226 inline Relocatable_relocs::Reloc_strategy
8227 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
8229 if (r_type
== 0 && r_sym
== 0)
8230 return Relocatable_relocs::RELOC_DISCARD
;
8231 return Relocatable_relocs::RELOC_COPY
;
8234 // Return the strategy to use for a local symbol which is a section
8235 // symbol, given the relocation type.
8236 inline Relocatable_relocs::Reloc_strategy
8237 local_section_strategy(unsigned int, Relobj
*)
8239 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
8242 // Return the strategy to use for a global symbol, given the
8243 // relocation type, the object, and the symbol index.
8244 inline Relocatable_relocs::Reloc_strategy
8245 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
8247 if (r_type
== elfcpp::R_PPC_PLTREL24
)
8248 return Relocatable_relocs::RELOC_SPECIAL
;
8249 return Relocatable_relocs::RELOC_COPY
;
8253 // Scan the relocs during a relocatable link.
8255 template<int size
, bool big_endian
>
8257 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
8258 Symbol_table
* symtab
,
8260 Sized_relobj_file
<size
, big_endian
>* object
,
8261 unsigned int data_shndx
,
8262 unsigned int sh_type
,
8263 const unsigned char* prelocs
,
8265 Output_section
* output_section
,
8266 bool needs_special_offset_handling
,
8267 size_t local_symbol_count
,
8268 const unsigned char* plocal_symbols
,
8269 Relocatable_relocs
* rr
)
8271 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
8273 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8275 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
8283 needs_special_offset_handling
,
8289 // Scan the relocs for --emit-relocs.
8291 template<int size
, bool big_endian
>
8293 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
8294 Symbol_table
* symtab
,
8296 Sized_relobj_file
<size
, big_endian
>* object
,
8297 unsigned int data_shndx
,
8298 unsigned int sh_type
,
8299 const unsigned char* prelocs
,
8301 Output_section
* output_section
,
8302 bool needs_special_offset_handling
,
8303 size_t local_symbol_count
,
8304 const unsigned char* plocal_syms
,
8305 Relocatable_relocs
* rr
)
8307 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8309 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
8310 Emit_relocs_strategy
;
8312 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8314 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
8322 needs_special_offset_handling
,
8328 // Emit relocations for a section.
8329 // This is a modified version of the function by the same name in
8330 // target-reloc.h. Using relocate_special_relocatable for
8331 // R_PPC_PLTREL24 would require duplication of the entire body of the
8332 // loop, so we may as well duplicate the whole thing.
8334 template<int size
, bool big_endian
>
8336 Target_powerpc
<size
, big_endian
>::relocate_relocs(
8337 const Relocate_info
<size
, big_endian
>* relinfo
,
8338 unsigned int sh_type
,
8339 const unsigned char* prelocs
,
8341 Output_section
* output_section
,
8342 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
8344 Address view_address
,
8346 unsigned char* reloc_view
,
8347 section_size_type reloc_view_size
)
8349 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8351 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
8353 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
8355 const int reloc_size
8356 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
8357 // Offset from start of insn to d-field reloc.
8358 const int d_offset
= big_endian
? 2 : 0;
8360 Powerpc_relobj
<size
, big_endian
>* const object
8361 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
8362 const unsigned int local_count
= object
->local_symbol_count();
8363 unsigned int got2_shndx
= object
->got2_shndx();
8364 Address got2_addend
= 0;
8365 if (got2_shndx
!= 0)
8367 got2_addend
= object
->get_output_section_offset(got2_shndx
);
8368 gold_assert(got2_addend
!= invalid_address
);
8371 unsigned char* pwrite
= reloc_view
;
8372 bool zap_next
= false;
8373 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
8375 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
8376 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
8379 Reltype
reloc(prelocs
);
8380 Reltype_write
reloc_write(pwrite
);
8382 Address offset
= reloc
.get_r_offset();
8383 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
8384 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8385 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
8386 const unsigned int orig_r_sym
= r_sym
;
8387 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
8388 = reloc
.get_r_addend();
8389 const Symbol
* gsym
= NULL
;
8393 // We could arrange to discard these and other relocs for
8394 // tls optimised sequences in the strategy methods, but for
8395 // now do as BFD ld does.
8396 r_type
= elfcpp::R_POWERPC_NONE
;
8400 // Get the new symbol index.
8401 Output_section
* os
= NULL
;
8402 if (r_sym
< local_count
)
8406 case Relocatable_relocs::RELOC_COPY
:
8407 case Relocatable_relocs::RELOC_SPECIAL
:
8410 r_sym
= object
->symtab_index(r_sym
);
8411 gold_assert(r_sym
!= -1U);
8415 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
8417 // We are adjusting a section symbol. We need to find
8418 // the symbol table index of the section symbol for
8419 // the output section corresponding to input section
8420 // in which this symbol is defined.
8421 gold_assert(r_sym
< local_count
);
8423 unsigned int shndx
=
8424 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8425 gold_assert(is_ordinary
);
8426 os
= object
->output_section(shndx
);
8427 gold_assert(os
!= NULL
);
8428 gold_assert(os
->needs_symtab_index());
8429 r_sym
= os
->symtab_index();
8439 gsym
= object
->global_symbol(r_sym
);
8440 gold_assert(gsym
!= NULL
);
8441 if (gsym
->is_forwarder())
8442 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
8444 gold_assert(gsym
->has_symtab_index());
8445 r_sym
= gsym
->symtab_index();
8448 // Get the new offset--the location in the output section where
8449 // this relocation should be applied.
8450 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8451 offset
+= offset_in_output_section
;
8454 section_offset_type sot_offset
=
8455 convert_types
<section_offset_type
, Address
>(offset
);
8456 section_offset_type new_sot_offset
=
8457 output_section
->output_offset(object
, relinfo
->data_shndx
,
8459 gold_assert(new_sot_offset
!= -1);
8460 offset
= new_sot_offset
;
8463 // In an object file, r_offset is an offset within the section.
8464 // In an executable or dynamic object, generated by
8465 // --emit-relocs, r_offset is an absolute address.
8466 if (!parameters
->options().relocatable())
8468 offset
+= view_address
;
8469 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8470 offset
-= offset_in_output_section
;
8473 // Handle the reloc addend based on the strategy.
8474 if (strategy
== Relocatable_relocs::RELOC_COPY
)
8476 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
8478 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
8479 gold_assert(os
!= NULL
);
8480 addend
= psymval
->value(object
, addend
) - os
->address();
8482 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
8486 if (addend
>= 32768)
8487 addend
+= got2_addend
;
8489 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
8491 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
8494 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
8496 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
8497 addend
-= d_offset
+ 4;
8503 if (!parameters
->options().relocatable())
8505 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8506 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
8507 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
8508 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
8510 // First instruction of a global dynamic sequence,
8512 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8513 switch (this->optimize_tls_gd(final
))
8515 case tls::TLSOPT_TO_IE
:
8516 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
8517 - elfcpp::R_POWERPC_GOT_TLSGD16
);
8519 case tls::TLSOPT_TO_LE
:
8520 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8521 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8522 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8525 r_type
= elfcpp::R_POWERPC_NONE
;
8533 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8534 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
8535 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
8536 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
8538 // First instruction of a local dynamic sequence,
8540 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8542 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8543 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
8545 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8546 const Output_section
* os
= relinfo
->layout
->tls_segment()
8548 gold_assert(os
!= NULL
);
8549 gold_assert(os
->needs_symtab_index());
8550 r_sym
= os
->symtab_index();
8551 addend
= dtp_offset
;
8555 r_type
= elfcpp::R_POWERPC_NONE
;
8560 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8561 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
8562 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
8563 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8565 // First instruction of initial exec sequence.
8566 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8567 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8569 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8570 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8571 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8574 r_type
= elfcpp::R_POWERPC_NONE
;
8579 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8580 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8582 // Second instruction of a global dynamic sequence,
8583 // the __tls_get_addr call
8584 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8585 switch (this->optimize_tls_gd(final
))
8587 case tls::TLSOPT_TO_IE
:
8588 r_type
= elfcpp::R_POWERPC_NONE
;
8591 case tls::TLSOPT_TO_LE
:
8592 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8600 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8601 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8603 // Second instruction of a local dynamic sequence,
8604 // the __tls_get_addr call
8605 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8607 const Output_section
* os
= relinfo
->layout
->tls_segment()
8609 gold_assert(os
!= NULL
);
8610 gold_assert(os
->needs_symtab_index());
8611 r_sym
= os
->symtab_index();
8612 addend
= dtp_offset
;
8613 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8618 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8620 // Second instruction of an initial exec sequence
8621 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8622 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8624 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8630 reloc_write
.put_r_offset(offset
);
8631 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
8632 reloc_write
.put_r_addend(addend
);
8634 pwrite
+= reloc_size
;
8637 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
8638 == reloc_view_size
);
8641 // Return the value to use for a dynamic symbol which requires special
8642 // treatment. This is how we support equality comparisons of function
8643 // pointers across shared library boundaries, as described in the
8644 // processor specific ABI supplement.
8646 template<int size
, bool big_endian
>
8648 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8652 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
8653 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8654 p
!= this->stub_tables_
.end();
8657 Address off
= (*p
)->find_plt_call_entry(gsym
);
8658 if (off
!= invalid_address
)
8659 return (*p
)->stub_address() + off
;
8662 else if (this->abiversion() >= 2)
8664 Address off
= this->glink_section()->find_global_entry(gsym
);
8665 if (off
!= invalid_address
)
8666 return this->glink_section()->global_entry_address() + off
;
8671 // Return the PLT address to use for a local symbol.
8672 template<int size
, bool big_endian
>
8674 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
8675 const Relobj
* object
,
8676 unsigned int symndx
) const
8680 const Sized_relobj
<size
, big_endian
>* relobj
8681 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
8682 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8683 p
!= this->stub_tables_
.end();
8686 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
8688 if (off
!= invalid_address
)
8689 return (*p
)->stub_address() + off
;
8695 // Return the PLT address to use for a global symbol.
8696 template<int size
, bool big_endian
>
8698 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
8699 const Symbol
* gsym
) const
8703 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8704 p
!= this->stub_tables_
.end();
8707 Address off
= (*p
)->find_plt_call_entry(gsym
);
8708 if (off
!= invalid_address
)
8709 return (*p
)->stub_address() + off
;
8712 else if (this->abiversion() >= 2)
8714 Address off
= this->glink_section()->find_global_entry(gsym
);
8715 if (off
!= invalid_address
)
8716 return this->glink_section()->global_entry_address() + off
;
8721 // Return the offset to use for the GOT_INDX'th got entry which is
8722 // for a local tls symbol specified by OBJECT, SYMNDX.
8723 template<int size
, bool big_endian
>
8725 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
8726 const Relobj
* object
,
8727 unsigned int symndx
,
8728 unsigned int got_indx
) const
8730 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8731 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
8732 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
8734 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8735 got_type
<= GOT_TYPE_TPREL
;
8736 got_type
= Got_type(got_type
+ 1))
8737 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
8739 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
8740 if (got_type
== GOT_TYPE_TLSGD
)
8742 if (off
== got_indx
* (size
/ 8))
8744 if (got_type
== GOT_TYPE_TPREL
)
8754 // Return the offset to use for the GOT_INDX'th got entry which is
8755 // for global tls symbol GSYM.
8756 template<int size
, bool big_endian
>
8758 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
8760 unsigned int got_indx
) const
8762 if (gsym
->type() == elfcpp::STT_TLS
)
8764 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8765 got_type
<= GOT_TYPE_TPREL
;
8766 got_type
= Got_type(got_type
+ 1))
8767 if (gsym
->has_got_offset(got_type
))
8769 unsigned int off
= gsym
->got_offset(got_type
);
8770 if (got_type
== GOT_TYPE_TLSGD
)
8772 if (off
== got_indx
* (size
/ 8))
8774 if (got_type
== GOT_TYPE_TPREL
)
8784 // The selector for powerpc object files.
8786 template<int size
, bool big_endian
>
8787 class Target_selector_powerpc
: public Target_selector
8790 Target_selector_powerpc()
8791 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
8794 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
8795 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
8797 ? (big_endian
? "elf64ppc" : "elf64lppc")
8798 : (big_endian
? "elf32ppc" : "elf32lppc")))
8802 do_instantiate_target()
8803 { return new Target_powerpc
<size
, big_endian
>(); }
8806 Target_selector_powerpc
<32, true> target_selector_ppc32
;
8807 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
8808 Target_selector_powerpc
<64, true> target_selector_ppc64
;
8809 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
8811 // Instantiate these constants for -O0
8812 template<int size
, bool big_endian
>
8813 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
8814 template<int size
, bool big_endian
>
8815 const typename Output_data_glink
<size
, big_endian
>::Address
8816 Output_data_glink
<size
, big_endian
>::invalid_address
;
8817 template<int size
, bool big_endian
>
8818 const typename Stub_table
<size
, big_endian
>::Address
8819 Stub_table
<size
, big_endian
>::invalid_address
;
8820 template<int size
, bool big_endian
>
8821 const typename Target_powerpc
<size
, big_endian
>::Address
8822 Target_powerpc
<size
, big_endian
>::invalid_address
;
8824 } // End anonymous namespace.