1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2015 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 unsigned char* view
, section_size_type view_size
,
635 std::string
* from
, std::string
* to
) const;
637 // Relocate a section.
639 relocate_section(const Relocate_info
<size
, big_endian
>*,
640 unsigned int sh_type
,
641 const unsigned char* prelocs
,
643 Output_section
* output_section
,
644 bool needs_special_offset_handling
,
646 Address view_address
,
647 section_size_type view_size
,
648 const Reloc_symbol_changes
*);
650 // Scan the relocs during a relocatable link.
652 scan_relocatable_relocs(Symbol_table
* symtab
,
654 Sized_relobj_file
<size
, big_endian
>* object
,
655 unsigned int data_shndx
,
656 unsigned int sh_type
,
657 const unsigned char* prelocs
,
659 Output_section
* output_section
,
660 bool needs_special_offset_handling
,
661 size_t local_symbol_count
,
662 const unsigned char* plocal_symbols
,
663 Relocatable_relocs
*);
665 // Emit relocations for a section.
667 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
668 unsigned int sh_type
,
669 const unsigned char* prelocs
,
671 Output_section
* output_section
,
672 typename
elfcpp::Elf_types
<size
>::Elf_Off
673 offset_in_output_section
,
674 const Relocatable_relocs
*,
676 Address view_address
,
678 unsigned char* reloc_view
,
679 section_size_type reloc_view_size
);
681 // Return whether SYM is defined by the ABI.
683 do_is_defined_by_abi(const Symbol
* sym
) const
685 return strcmp(sym
->name(), "__tls_get_addr") == 0;
688 // Return the size of the GOT section.
692 gold_assert(this->got_
!= NULL
);
693 return this->got_
->data_size();
696 // Get the PLT section.
697 const Output_data_plt_powerpc
<size
, big_endian
>*
700 gold_assert(this->plt_
!= NULL
);
704 // Get the IPLT section.
705 const Output_data_plt_powerpc
<size
, big_endian
>*
708 gold_assert(this->iplt_
!= NULL
);
712 // Get the .glink section.
713 const Output_data_glink
<size
, big_endian
>*
714 glink_section() const
716 gold_assert(this->glink_
!= NULL
);
720 Output_data_glink
<size
, big_endian
>*
723 gold_assert(this->glink_
!= NULL
);
727 bool has_glink() const
728 { return this->glink_
!= NULL
; }
730 // Get the GOT section.
731 const Output_data_got_powerpc
<size
, big_endian
>*
734 gold_assert(this->got_
!= NULL
);
738 // Get the GOT section, creating it if necessary.
739 Output_data_got_powerpc
<size
, big_endian
>*
740 got_section(Symbol_table
*, Layout
*);
743 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
744 const elfcpp::Ehdr
<size
, big_endian
>&);
746 // Return the number of entries in the GOT.
748 got_entry_count() const
750 if (this->got_
== NULL
)
752 return this->got_size() / (size
/ 8);
755 // Return the number of entries in the PLT.
757 plt_entry_count() const;
759 // Return the offset of the first non-reserved PLT entry.
761 first_plt_entry_offset() const
765 if (this->abiversion() >= 2)
770 // Return the size of each PLT entry.
772 plt_entry_size() const
776 if (this->abiversion() >= 2)
781 Output_data_save_res
<size
, big_endian
>*
782 savres_section() const
784 return this->savres_section_
;
787 // Add any special sections for this symbol to the gc work list.
788 // For powerpc64, this adds the code section of a function
791 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
793 // Handle target specific gc actions when adding a gc reference from
794 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
795 // and DST_OFF. For powerpc64, this adds a referenc to the code
796 // section of a function descriptor.
798 do_gc_add_reference(Symbol_table
* symtab
,
800 unsigned int src_shndx
,
802 unsigned int dst_shndx
,
803 Address dst_off
) const;
805 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
808 { return this->stub_tables_
; }
810 const Output_data_brlt_powerpc
<size
, big_endian
>*
812 { return this->brlt_section_
; }
815 add_branch_lookup_table(Address to
)
817 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
818 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
822 find_branch_lookup_table(Address to
)
824 typename
Branch_lookup_table::const_iterator p
825 = this->branch_lookup_table_
.find(to
);
826 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
830 write_branch_lookup_table(unsigned char *oview
)
832 for (typename
Branch_lookup_table::const_iterator p
833 = this->branch_lookup_table_
.begin();
834 p
!= this->branch_lookup_table_
.end();
837 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
842 plt_thread_safe() const
843 { return this->plt_thread_safe_
; }
847 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
850 set_abiversion (int ver
)
852 elfcpp::Elf_Word flags
= this->processor_specific_flags();
853 flags
&= ~elfcpp::EF_PPC64_ABI
;
854 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
855 this->set_processor_specific_flags(flags
);
858 // Offset to to save stack slot
861 { return this->abiversion() < 2 ? 40 : 24; }
877 : tls_get_addr_(NOT_EXPECTED
),
878 relinfo_(NULL
), relnum_(0), r_offset_(0)
883 if (this->tls_get_addr_
!= NOT_EXPECTED
)
890 if (this->relinfo_
!= NULL
)
891 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
892 _("missing expected __tls_get_addr call"));
896 expect_tls_get_addr_call(
897 const Relocate_info
<size
, big_endian
>* relinfo
,
901 this->tls_get_addr_
= EXPECTED
;
902 this->relinfo_
= relinfo
;
903 this->relnum_
= relnum
;
904 this->r_offset_
= r_offset
;
908 expect_tls_get_addr_call()
909 { this->tls_get_addr_
= EXPECTED
; }
912 skip_next_tls_get_addr_call()
913 {this->tls_get_addr_
= SKIP
; }
916 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
918 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
919 || r_type
== elfcpp::R_PPC_PLTREL24
)
921 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
922 Tls_get_addr last_tls
= this->tls_get_addr_
;
923 this->tls_get_addr_
= NOT_EXPECTED
;
924 if (is_tls_call
&& last_tls
!= EXPECTED
)
926 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
935 // What we're up to regarding calls to __tls_get_addr.
936 // On powerpc, the branch and link insn making a call to
937 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
938 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
939 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
940 // The marker relocation always comes first, and has the same
941 // symbol as the reloc on the insn setting up the __tls_get_addr
942 // argument. This ties the arg setup insn with the call insn,
943 // allowing ld to safely optimize away the call. We check that
944 // every call to __tls_get_addr has a marker relocation, and that
945 // every marker relocation is on a call to __tls_get_addr.
946 Tls_get_addr tls_get_addr_
;
947 // Info about the last reloc for error message.
948 const Relocate_info
<size
, big_endian
>* relinfo_
;
953 // The class which scans relocations.
954 class Scan
: protected Track_tls
957 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
960 : Track_tls(), issued_non_pic_error_(false)
964 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
967 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
968 Sized_relobj_file
<size
, big_endian
>* object
,
969 unsigned int data_shndx
,
970 Output_section
* output_section
,
971 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
972 const elfcpp::Sym
<size
, big_endian
>& lsym
,
976 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
977 Sized_relobj_file
<size
, big_endian
>* object
,
978 unsigned int data_shndx
,
979 Output_section
* output_section
,
980 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
984 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
986 Sized_relobj_file
<size
, big_endian
>* relobj
,
989 const elfcpp::Rela
<size
, big_endian
>& ,
991 const elfcpp::Sym
<size
, big_endian
>&)
993 // PowerPC64 .opd is not folded, so any identical function text
994 // may be folded and we'll still keep function addresses distinct.
995 // That means no reloc is of concern here.
998 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
999 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1000 if (ppcobj
->abiversion() == 1)
1003 // For 32-bit and ELFv2, conservatively assume anything but calls to
1004 // function code might be taking the address of the function.
1005 return !is_branch_reloc(r_type
);
1009 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1011 Sized_relobj_file
<size
, big_endian
>* relobj
,
1014 const elfcpp::Rela
<size
, big_endian
>& ,
1015 unsigned int r_type
,
1021 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1022 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1023 if (ppcobj
->abiversion() == 1)
1026 return !is_branch_reloc(r_type
);
1030 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1031 Sized_relobj_file
<size
, big_endian
>* object
,
1032 unsigned int r_type
, bool report_err
);
1036 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1037 unsigned int r_type
);
1040 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1041 unsigned int r_type
, Symbol
*);
1044 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1045 Target_powerpc
* target
);
1048 check_non_pic(Relobj
*, unsigned int r_type
);
1050 // Whether we have issued an error about a non-PIC compilation.
1051 bool issued_non_pic_error_
;
1055 symval_for_branch(const Symbol_table
* symtab
,
1056 const Sized_symbol
<size
>* gsym
,
1057 Powerpc_relobj
<size
, big_endian
>* object
,
1058 Address
*value
, unsigned int *dest_shndx
);
1060 // The class which implements relocation.
1061 class Relocate
: protected Track_tls
1064 // Use 'at' branch hints when true, 'y' when false.
1065 // FIXME maybe: set this with an option.
1066 static const bool is_isa_v2
= true;
1072 // Do a relocation. Return false if the caller should not issue
1073 // any warnings about this relocation.
1075 relocate(const Relocate_info
<size
, big_endian
>*, Target_powerpc
*,
1076 Output_section
*, size_t relnum
,
1077 const elfcpp::Rela
<size
, big_endian
>&,
1078 unsigned int r_type
, const Sized_symbol
<size
>*,
1079 const Symbol_value
<size
>*,
1081 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1085 class Relocate_comdat_behavior
1088 // Decide what the linker should do for relocations that refer to
1089 // discarded comdat sections.
1090 inline Comdat_behavior
1091 get(const char* name
)
1093 gold::Default_comdat_behavior default_behavior
;
1094 Comdat_behavior ret
= default_behavior
.get(name
);
1095 if (ret
== CB_WARNING
)
1098 && (strcmp(name
, ".fixup") == 0
1099 || strcmp(name
, ".got2") == 0))
1102 && (strcmp(name
, ".opd") == 0
1103 || strcmp(name
, ".toc") == 0
1104 || strcmp(name
, ".toc1") == 0))
1111 // A class which returns the size required for a relocation type,
1112 // used while scanning relocs during a relocatable link.
1113 class Relocatable_size_for_reloc
1117 get_size_for_reloc(unsigned int, Relobj
*)
1124 // Optimize the TLS relocation type based on what we know about the
1125 // symbol. IS_FINAL is true if the final address of this symbol is
1126 // known at link time.
1128 tls::Tls_optimization
1129 optimize_tls_gd(bool is_final
)
1131 // If we are generating a shared library, then we can't do anything
1133 if (parameters
->options().shared())
1134 return tls::TLSOPT_NONE
;
1137 return tls::TLSOPT_TO_IE
;
1138 return tls::TLSOPT_TO_LE
;
1141 tls::Tls_optimization
1144 if (parameters
->options().shared())
1145 return tls::TLSOPT_NONE
;
1147 return tls::TLSOPT_TO_LE
;
1150 tls::Tls_optimization
1151 optimize_tls_ie(bool is_final
)
1153 if (!is_final
|| parameters
->options().shared())
1154 return tls::TLSOPT_NONE
;
1156 return tls::TLSOPT_TO_LE
;
1161 make_glink_section(Layout
*);
1163 // Create the PLT section.
1165 make_plt_section(Symbol_table
*, Layout
*);
1168 make_iplt_section(Symbol_table
*, Layout
*);
1171 make_brlt_section(Layout
*);
1173 // Create a PLT entry for a global symbol.
1175 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1177 // Create a PLT entry for a local IFUNC symbol.
1179 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1180 Sized_relobj_file
<size
, big_endian
>*,
1184 // Create a GOT entry for local dynamic __tls_get_addr.
1186 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1187 Sized_relobj_file
<size
, big_endian
>* object
);
1190 tlsld_got_offset() const
1192 return this->tlsld_got_offset_
;
1195 // Get the dynamic reloc section, creating it if necessary.
1197 rela_dyn_section(Layout
*);
1199 // Similarly, but for ifunc symbols get the one for ifunc.
1201 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1203 // Copy a relocation against a global symbol.
1205 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1206 Sized_relobj_file
<size
, big_endian
>* object
,
1207 unsigned int shndx
, Output_section
* output_section
,
1208 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1210 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1211 symtab
->get_sized_symbol
<size
>(sym
),
1212 object
, shndx
, output_section
,
1213 reloc
, this->rela_dyn_section(layout
));
1216 // Look over all the input sections, deciding where to place stubs.
1218 group_sections(Layout
*, const Task
*, bool);
1220 // Sort output sections by address.
1221 struct Sort_sections
1224 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1225 { return sec1
->address() < sec2
->address(); }
1231 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1232 unsigned int data_shndx
,
1234 unsigned int r_type
,
1237 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1238 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1244 // If this branch needs a plt call stub, or a long branch stub, make one.
1246 make_stub(Stub_table
<size
, big_endian
>*,
1247 Stub_table
<size
, big_endian
>*,
1248 Symbol_table
*) const;
1251 // The branch location..
1252 Powerpc_relobj
<size
, big_endian
>* object_
;
1253 unsigned int shndx_
;
1255 // ..and the branch type and destination.
1256 unsigned int r_type_
;
1257 unsigned int r_sym_
;
1261 // Information about this specific target which we pass to the
1262 // general Target structure.
1263 static Target::Target_info powerpc_info
;
1265 // The types of GOT entries needed for this platform.
1266 // These values are exposed to the ABI in an incremental link.
1267 // Do not renumber existing values without changing the version
1268 // number of the .gnu_incremental_inputs section.
1272 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1273 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1274 GOT_TYPE_TPREL
// entry for @got@tprel
1278 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1279 // The PLT section. This is a container for a table of addresses,
1280 // and their relocations. Each address in the PLT has a dynamic
1281 // relocation (R_*_JMP_SLOT) and each address will have a
1282 // corresponding entry in .glink for lazy resolution of the PLT.
1283 // ppc32 initialises the PLT to point at the .glink entry, while
1284 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1285 // linker adds a stub that loads the PLT entry into ctr then
1286 // branches to ctr. There may be more than one stub for each PLT
1287 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1288 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1289 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1290 // The IPLT section. Like plt_, this is a container for a table of
1291 // addresses and their relocations, specifically for STT_GNU_IFUNC
1292 // functions that resolve locally (STT_GNU_IFUNC functions that
1293 // don't resolve locally go in PLT). Unlike plt_, these have no
1294 // entry in .glink for lazy resolution, and the relocation section
1295 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1296 // the relocation section may contain relocations against
1297 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1298 // relocation section will appear at the end of other dynamic
1299 // relocations, so that ld.so applies these relocations after other
1300 // dynamic relocations. In a static executable, the relocation
1301 // section is emitted and marked with __rela_iplt_start and
1302 // __rela_iplt_end symbols.
1303 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1304 // Section holding long branch destinations.
1305 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1306 // The .glink section.
1307 Output_data_glink
<size
, big_endian
>* glink_
;
1308 // The dynamic reloc section.
1309 Reloc_section
* rela_dyn_
;
1310 // Relocs saved to avoid a COPY reloc.
1311 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1312 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1313 unsigned int tlsld_got_offset_
;
1315 Stub_tables stub_tables_
;
1316 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1317 Branch_lookup_table branch_lookup_table_
;
1319 typedef std::vector
<Branch_info
> Branches
;
1320 Branches branch_info_
;
1322 bool plt_thread_safe_
;
1325 int relax_fail_count_
;
1326 int32_t stub_group_size_
;
1328 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1332 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1335 true, // is_big_endian
1336 elfcpp::EM_PPC
, // machine_code
1337 false, // has_make_symbol
1338 false, // has_resolve
1339 false, // has_code_fill
1340 true, // is_default_stack_executable
1341 false, // can_icf_inline_merge_sections
1343 "/usr/lib/ld.so.1", // dynamic_linker
1344 0x10000000, // default_text_segment_address
1345 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1346 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1347 false, // isolate_execinstr
1349 elfcpp::SHN_UNDEF
, // small_common_shndx
1350 elfcpp::SHN_UNDEF
, // large_common_shndx
1351 0, // small_common_section_flags
1352 0, // large_common_section_flags
1353 NULL
, // attributes_section
1354 NULL
, // attributes_vendor
1355 "_start" // entry_symbol_name
1359 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1362 false, // is_big_endian
1363 elfcpp::EM_PPC
, // machine_code
1364 false, // has_make_symbol
1365 false, // has_resolve
1366 false, // has_code_fill
1367 true, // is_default_stack_executable
1368 false, // can_icf_inline_merge_sections
1370 "/usr/lib/ld.so.1", // dynamic_linker
1371 0x10000000, // default_text_segment_address
1372 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1373 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1374 false, // isolate_execinstr
1376 elfcpp::SHN_UNDEF
, // small_common_shndx
1377 elfcpp::SHN_UNDEF
, // large_common_shndx
1378 0, // small_common_section_flags
1379 0, // large_common_section_flags
1380 NULL
, // attributes_section
1381 NULL
, // attributes_vendor
1382 "_start" // entry_symbol_name
1386 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1389 true, // is_big_endian
1390 elfcpp::EM_PPC64
, // machine_code
1391 false, // has_make_symbol
1392 false, // has_resolve
1393 false, // has_code_fill
1394 true, // is_default_stack_executable
1395 false, // can_icf_inline_merge_sections
1397 "/usr/lib/ld.so.1", // dynamic_linker
1398 0x10000000, // default_text_segment_address
1399 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1400 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1401 false, // isolate_execinstr
1403 elfcpp::SHN_UNDEF
, // small_common_shndx
1404 elfcpp::SHN_UNDEF
, // large_common_shndx
1405 0, // small_common_section_flags
1406 0, // large_common_section_flags
1407 NULL
, // attributes_section
1408 NULL
, // attributes_vendor
1409 "_start" // entry_symbol_name
1413 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1416 false, // is_big_endian
1417 elfcpp::EM_PPC64
, // machine_code
1418 false, // has_make_symbol
1419 false, // has_resolve
1420 false, // has_code_fill
1421 true, // is_default_stack_executable
1422 false, // can_icf_inline_merge_sections
1424 "/usr/lib/ld.so.1", // dynamic_linker
1425 0x10000000, // default_text_segment_address
1426 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1427 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1428 false, // isolate_execinstr
1430 elfcpp::SHN_UNDEF
, // small_common_shndx
1431 elfcpp::SHN_UNDEF
, // large_common_shndx
1432 0, // small_common_section_flags
1433 0, // large_common_section_flags
1434 NULL
, // attributes_section
1435 NULL
, // attributes_vendor
1436 "_start" // entry_symbol_name
1440 is_branch_reloc(unsigned int r_type
)
1442 return (r_type
== elfcpp::R_POWERPC_REL24
1443 || r_type
== elfcpp::R_PPC_PLTREL24
1444 || r_type
== elfcpp::R_PPC_LOCAL24PC
1445 || r_type
== elfcpp::R_POWERPC_REL14
1446 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1447 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1448 || r_type
== elfcpp::R_POWERPC_ADDR24
1449 || r_type
== elfcpp::R_POWERPC_ADDR14
1450 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1451 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1454 // If INSN is an opcode that may be used with an @tls operand, return
1455 // the transformed insn for TLS optimisation, otherwise return 0. If
1456 // REG is non-zero only match an insn with RB or RA equal to REG.
1458 at_tls_transform(uint32_t insn
, unsigned int reg
)
1460 if ((insn
& (0x3f << 26)) != 31 << 26)
1464 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1465 rtra
= insn
& ((1 << 26) - (1 << 16));
1466 else if (((insn
>> 16) & 0x1f) == reg
)
1467 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1471 if ((insn
& (0x3ff << 1)) == 266 << 1)
1474 else if ((insn
& (0x1f << 1)) == 23 << 1
1475 && ((insn
& (0x1f << 6)) < 14 << 6
1476 || ((insn
& (0x1f << 6)) >= 16 << 6
1477 && (insn
& (0x1f << 6)) < 24 << 6)))
1478 // load and store indexed -> dform
1479 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1480 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1481 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1482 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1483 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1485 insn
= (58 << 26) | 2;
1493 template<int size
, bool big_endian
>
1494 class Powerpc_relocate_functions
1514 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1515 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1517 template<int valsize
>
1519 has_overflow_signed(Address value
)
1521 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1522 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1523 limit
<<= ((valsize
- 1) >> 1);
1524 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1525 return value
+ limit
> (limit
<< 1) - 1;
1528 template<int valsize
>
1530 has_overflow_unsigned(Address value
)
1532 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1533 limit
<<= ((valsize
- 1) >> 1);
1534 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1535 return value
> (limit
<< 1) - 1;
1538 template<int valsize
>
1540 has_overflow_bitfield(Address value
)
1542 return (has_overflow_unsigned
<valsize
>(value
)
1543 && has_overflow_signed
<valsize
>(value
));
1546 template<int valsize
>
1547 static inline Status
1548 overflowed(Address value
, Overflow_check overflow
)
1550 if (overflow
== CHECK_SIGNED
)
1552 if (has_overflow_signed
<valsize
>(value
))
1553 return STATUS_OVERFLOW
;
1555 else if (overflow
== CHECK_UNSIGNED
)
1557 if (has_overflow_unsigned
<valsize
>(value
))
1558 return STATUS_OVERFLOW
;
1560 else if (overflow
== CHECK_BITFIELD
)
1562 if (has_overflow_bitfield
<valsize
>(value
))
1563 return STATUS_OVERFLOW
;
1568 // Do a simple RELA relocation
1569 template<int fieldsize
, int valsize
>
1570 static inline Status
1571 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1573 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1574 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1575 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1576 return overflowed
<valsize
>(value
, overflow
);
1579 template<int fieldsize
, int valsize
>
1580 static inline Status
1581 rela(unsigned char* view
,
1582 unsigned int right_shift
,
1583 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1585 Overflow_check overflow
)
1587 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1588 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1589 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1590 Valtype reloc
= value
>> right_shift
;
1593 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1594 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1597 // Do a simple RELA relocation, unaligned.
1598 template<int fieldsize
, int valsize
>
1599 static inline Status
1600 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1602 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1603 return overflowed
<valsize
>(value
, overflow
);
1606 template<int fieldsize
, int valsize
>
1607 static inline Status
1608 rela_ua(unsigned char* view
,
1609 unsigned int right_shift
,
1610 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1612 Overflow_check overflow
)
1614 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
1616 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
1617 Valtype reloc
= value
>> right_shift
;
1620 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
1621 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1625 // R_PPC64_ADDR64: (Symbol + Addend)
1627 addr64(unsigned char* view
, Address value
)
1628 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
1630 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1632 addr64_u(unsigned char* view
, Address value
)
1633 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
1635 // R_POWERPC_ADDR32: (Symbol + Addend)
1636 static inline Status
1637 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1638 { return This::template rela
<32,32>(view
, value
, overflow
); }
1640 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1641 static inline Status
1642 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1643 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
1645 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1646 static inline Status
1647 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1649 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
1651 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1652 stat
= STATUS_OVERFLOW
;
1656 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1657 static inline Status
1658 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1659 { return This::template rela
<16,16>(view
, value
, overflow
); }
1661 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1662 static inline Status
1663 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1664 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
1666 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1667 static inline Status
1668 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1670 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
1671 if ((value
& 3) != 0)
1672 stat
= STATUS_OVERFLOW
;
1676 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1678 addr16_hi(unsigned char* view
, Address value
)
1679 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1681 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1683 addr16_ha(unsigned char* view
, Address value
)
1684 { This::addr16_hi(view
, value
+ 0x8000); }
1686 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1688 addr16_hi2(unsigned char* view
, Address value
)
1689 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1691 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1693 addr16_ha2(unsigned char* view
, Address value
)
1694 { This::addr16_hi2(view
, value
+ 0x8000); }
1696 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1698 addr16_hi3(unsigned char* view
, Address value
)
1699 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1701 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1703 addr16_ha3(unsigned char* view
, Address value
)
1704 { This::addr16_hi3(view
, value
+ 0x8000); }
1706 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1707 static inline Status
1708 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1710 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
1711 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1712 stat
= STATUS_OVERFLOW
;
1717 // Set ABI version for input and output.
1719 template<int size
, bool big_endian
>
1721 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
1723 this->e_flags_
|= ver
;
1724 if (this->abiversion() != 0)
1726 Target_powerpc
<size
, big_endian
>* target
=
1727 static_cast<Target_powerpc
<size
, big_endian
>*>(
1728 parameters
->sized_target
<size
, big_endian
>());
1729 if (target
->abiversion() == 0)
1730 target
->set_abiversion(this->abiversion());
1731 else if (target
->abiversion() != this->abiversion())
1732 gold_error(_("%s: ABI version %d is not compatible "
1733 "with ABI version %d output"),
1734 this->name().c_str(),
1735 this->abiversion(), target
->abiversion());
1740 // Stash away the index of .got2 or .opd in a relocatable object, if
1741 // such a section exists.
1743 template<int size
, bool big_endian
>
1745 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1746 Read_symbols_data
* sd
)
1748 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1749 const unsigned char* namesu
= sd
->section_names
->data();
1750 const char* names
= reinterpret_cast<const char*>(namesu
);
1751 section_size_type names_size
= sd
->section_names_size
;
1752 const unsigned char* s
;
1754 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1755 size
== 32 ? ".got2" : ".opd",
1756 names
, names_size
, NULL
);
1759 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1760 this->special_
= ndx
;
1763 if (this->abiversion() == 0)
1764 this->set_abiversion(1);
1765 else if (this->abiversion() > 1)
1766 gold_error(_("%s: .opd invalid in abiv%d"),
1767 this->name().c_str(), this->abiversion());
1770 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1773 // Examine .rela.opd to build info about function entry points.
1775 template<int size
, bool big_endian
>
1777 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1779 const unsigned char* prelocs
,
1780 const unsigned char* plocal_syms
)
1784 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1786 const int reloc_size
1787 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1788 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1789 Address expected_off
= 0;
1790 bool regular
= true;
1791 unsigned int opd_ent_size
= 0;
1793 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1795 Reltype
reloc(prelocs
);
1796 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1797 = reloc
.get_r_info();
1798 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1799 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1801 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1802 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1805 if (r_sym
< this->local_symbol_count())
1807 typename
elfcpp::Sym
<size
, big_endian
>
1808 lsym(plocal_syms
+ r_sym
* sym_size
);
1809 shndx
= lsym
.get_st_shndx();
1810 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1811 value
= lsym
.get_st_value();
1814 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1816 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1817 value
+ reloc
.get_r_addend());
1820 expected_off
= reloc
.get_r_offset();
1821 opd_ent_size
= expected_off
;
1823 else if (expected_off
!= reloc
.get_r_offset())
1825 expected_off
+= opd_ent_size
;
1827 else if (r_type
== elfcpp::R_PPC64_TOC
)
1829 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1834 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1835 this->name().c_str(), r_type
);
1839 if (reloc_count
<= 2)
1840 opd_ent_size
= this->section_size(this->opd_shndx());
1841 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1845 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1846 this->name().c_str());
1852 template<int size
, bool big_endian
>
1854 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1856 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1859 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1860 p
!= rd
->relocs
.end();
1863 if (p
->data_shndx
== this->opd_shndx())
1865 uint64_t opd_size
= this->section_size(this->opd_shndx());
1866 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1869 this->init_opd(opd_size
);
1870 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1871 rd
->local_symbols
->data());
1879 // Read the symbols then set up st_other vector.
1881 template<int size
, bool big_endian
>
1883 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1885 this->base_read_symbols(sd
);
1888 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1889 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1890 const unsigned int loccount
= this->do_local_symbol_count();
1893 this->st_other_
.resize(loccount
);
1894 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1895 off_t locsize
= loccount
* sym_size
;
1896 const unsigned int symtab_shndx
= this->symtab_shndx();
1897 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
1898 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
1899 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
1900 locsize
, true, false);
1902 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
1904 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
1905 unsigned char st_other
= sym
.get_st_other();
1906 this->st_other_
[i
] = st_other
;
1907 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1909 if (this->abiversion() == 0)
1910 this->set_abiversion(2);
1911 else if (this->abiversion() < 2)
1912 gold_error(_("%s: local symbol %d has invalid st_other"
1913 " for ABI version 1"),
1914 this->name().c_str(), i
);
1921 template<int size
, bool big_endian
>
1923 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
1925 this->e_flags_
|= ver
;
1926 if (this->abiversion() != 0)
1928 Target_powerpc
<size
, big_endian
>* target
=
1929 static_cast<Target_powerpc
<size
, big_endian
>*>(
1930 parameters
->sized_target
<size
, big_endian
>());
1931 if (target
->abiversion() == 0)
1932 target
->set_abiversion(this->abiversion());
1933 else if (target
->abiversion() != this->abiversion())
1934 gold_error(_("%s: ABI version %d is not compatible "
1935 "with ABI version %d output"),
1936 this->name().c_str(),
1937 this->abiversion(), target
->abiversion());
1942 // Call Sized_dynobj::base_read_symbols to read the symbols then
1943 // read .opd from a dynamic object, filling in opd_ent_ vector,
1945 template<int size
, bool big_endian
>
1947 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1949 this->base_read_symbols(sd
);
1952 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1953 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1954 const unsigned char* namesu
= sd
->section_names
->data();
1955 const char* names
= reinterpret_cast<const char*>(namesu
);
1956 const unsigned char* s
= NULL
;
1957 const unsigned char* opd
;
1958 section_size_type opd_size
;
1960 // Find and read .opd section.
1963 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1964 sd
->section_names_size
,
1969 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1970 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1971 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
1973 if (this->abiversion() == 0)
1974 this->set_abiversion(1);
1975 else if (this->abiversion() > 1)
1976 gold_error(_("%s: .opd invalid in abiv%d"),
1977 this->name().c_str(), this->abiversion());
1979 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
1980 this->opd_address_
= shdr
.get_sh_addr();
1981 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
1982 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
1988 // Build set of executable sections.
1989 // Using a set is probably overkill. There is likely to be only
1990 // a few executable sections, typically .init, .text and .fini,
1991 // and they are generally grouped together.
1992 typedef std::set
<Sec_info
> Exec_sections
;
1993 Exec_sections exec_sections
;
1995 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
1997 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
1998 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
1999 && ((shdr
.get_sh_flags()
2000 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2001 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2002 && shdr
.get_sh_size() != 0)
2004 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2005 shdr
.get_sh_size(), i
));
2008 if (exec_sections
.empty())
2011 // Look over the OPD entries. This is complicated by the fact
2012 // that some binaries will use two-word entries while others
2013 // will use the standard three-word entries. In most cases
2014 // the third word (the environment pointer for languages like
2015 // Pascal) is unused and will be zero. If the third word is
2016 // used it should not be pointing into executable sections,
2018 this->init_opd(opd_size
);
2019 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2021 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2022 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2023 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2025 // Chances are that this is the third word of an OPD entry.
2027 typename
Exec_sections::const_iterator e
2028 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2029 if (e
!= exec_sections
.begin())
2032 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2034 // We have an address in an executable section.
2035 // VAL ought to be the function entry, set it up.
2036 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2037 // Skip second word of OPD entry, the TOC pointer.
2041 // If we didn't match any executable sections, we likely
2042 // have a non-zero third word in the OPD entry.
2047 // Set up some symbols.
2049 template<int size
, bool big_endian
>
2051 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2052 Symbol_table
* symtab
,
2057 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2058 // undefined when scanning relocs (and thus requires
2059 // non-relative dynamic relocs). The proper value will be
2061 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2062 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2064 Target_powerpc
<size
, big_endian
>* target
=
2065 static_cast<Target_powerpc
<size
, big_endian
>*>(
2066 parameters
->sized_target
<size
, big_endian
>());
2067 Output_data_got_powerpc
<size
, big_endian
>* got
2068 = target
->got_section(symtab
, layout
);
2069 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2070 Symbol_table::PREDEFINED
,
2074 elfcpp::STV_HIDDEN
, 0,
2078 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2079 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2080 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2082 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2084 = layout
->add_output_section_data(".sdata", 0,
2086 | elfcpp::SHF_WRITE
,
2087 sdata
, ORDER_SMALL_DATA
, false);
2088 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2089 Symbol_table::PREDEFINED
,
2090 os
, 32768, 0, elfcpp::STT_OBJECT
,
2091 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2097 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2098 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2099 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2101 Target_powerpc
<size
, big_endian
>* target
=
2102 static_cast<Target_powerpc
<size
, big_endian
>*>(
2103 parameters
->sized_target
<size
, big_endian
>());
2104 Output_data_got_powerpc
<size
, big_endian
>* got
2105 = target
->got_section(symtab
, layout
);
2106 symtab
->define_in_output_data(".TOC.", NULL
,
2107 Symbol_table::PREDEFINED
,
2111 elfcpp::STV_HIDDEN
, 0,
2117 // Set up PowerPC target specific relobj.
2119 template<int size
, bool big_endian
>
2121 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2122 const std::string
& name
,
2123 Input_file
* input_file
,
2124 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2126 int et
= ehdr
.get_e_type();
2127 // ET_EXEC files are valid input for --just-symbols/-R,
2128 // and we treat them as relocatable objects.
2129 if (et
== elfcpp::ET_REL
2130 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2132 Powerpc_relobj
<size
, big_endian
>* obj
=
2133 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2137 else if (et
== elfcpp::ET_DYN
)
2139 Powerpc_dynobj
<size
, big_endian
>* obj
=
2140 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2146 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2151 template<int size
, bool big_endian
>
2152 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2155 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2156 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2158 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2159 : Output_data_got
<size
, big_endian
>(),
2160 symtab_(symtab
), layout_(layout
),
2161 header_ent_cnt_(size
== 32 ? 3 : 1),
2162 header_index_(size
== 32 ? 0x2000 : 0)
2165 // Override all the Output_data_got methods we use so as to first call
2168 add_global(Symbol
* gsym
, unsigned int got_type
)
2170 this->reserve_ent();
2171 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2175 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2177 this->reserve_ent();
2178 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2182 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2183 { return this->add_global_plt(gsym
, got_type
); }
2186 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2187 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2189 this->reserve_ent();
2190 Output_data_got
<size
, big_endian
>::
2191 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2195 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2196 Output_data_reloc_generic
* rel_dyn
,
2197 unsigned int r_type_1
, unsigned int r_type_2
)
2199 this->reserve_ent(2);
2200 Output_data_got
<size
, big_endian
>::
2201 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2205 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2207 this->reserve_ent();
2208 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2213 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2215 this->reserve_ent();
2216 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2221 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2222 { return this->add_local_plt(object
, sym_index
, got_type
); }
2225 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2226 unsigned int got_type
,
2227 Output_data_reloc_generic
* rel_dyn
,
2228 unsigned int r_type
)
2230 this->reserve_ent(2);
2231 Output_data_got
<size
, big_endian
>::
2232 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2236 add_constant(Valtype constant
)
2238 this->reserve_ent();
2239 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2243 add_constant_pair(Valtype c1
, Valtype c2
)
2245 this->reserve_ent(2);
2246 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2249 // Offset of _GLOBAL_OFFSET_TABLE_.
2253 return this->got_offset(this->header_index_
);
2256 // Offset of base used to access the GOT/TOC.
2257 // The got/toc pointer reg will be set to this value.
2259 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2262 return this->g_o_t();
2264 return (this->output_section()->address()
2265 + object
->toc_base_offset()
2269 // Ensure our GOT has a header.
2271 set_final_data_size()
2273 if (this->header_ent_cnt_
!= 0)
2274 this->make_header();
2275 Output_data_got
<size
, big_endian
>::set_final_data_size();
2278 // First word of GOT header needs some values that are not
2279 // handled by Output_data_got so poke them in here.
2280 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2282 do_write(Output_file
* of
)
2285 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2286 val
= this->layout_
->dynamic_section()->address();
2288 val
= this->output_section()->address() + 0x8000;
2289 this->replace_constant(this->header_index_
, val
);
2290 Output_data_got
<size
, big_endian
>::do_write(of
);
2295 reserve_ent(unsigned int cnt
= 1)
2297 if (this->header_ent_cnt_
== 0)
2299 if (this->num_entries() + cnt
> this->header_index_
)
2300 this->make_header();
2306 this->header_ent_cnt_
= 0;
2307 this->header_index_
= this->num_entries();
2310 Output_data_got
<size
, big_endian
>::add_constant(0);
2311 Output_data_got
<size
, big_endian
>::add_constant(0);
2312 Output_data_got
<size
, big_endian
>::add_constant(0);
2314 // Define _GLOBAL_OFFSET_TABLE_ at the header
2315 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2318 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2319 sym
->set_value(this->g_o_t());
2322 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2323 Symbol_table::PREDEFINED
,
2324 this, this->g_o_t(), 0,
2327 elfcpp::STV_HIDDEN
, 0,
2331 Output_data_got
<size
, big_endian
>::add_constant(0);
2334 // Stashed pointers.
2335 Symbol_table
* symtab_
;
2339 unsigned int header_ent_cnt_
;
2340 // GOT header index.
2341 unsigned int header_index_
;
2344 // Get the GOT section, creating it if necessary.
2346 template<int size
, bool big_endian
>
2347 Output_data_got_powerpc
<size
, big_endian
>*
2348 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2351 if (this->got_
== NULL
)
2353 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2356 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2358 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2359 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2360 this->got_
, ORDER_DATA
, false);
2366 // Get the dynamic reloc section, creating it if necessary.
2368 template<int size
, bool big_endian
>
2369 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2370 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2372 if (this->rela_dyn_
== NULL
)
2374 gold_assert(layout
!= NULL
);
2375 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2376 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2377 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2378 ORDER_DYNAMIC_RELOCS
, false);
2380 return this->rela_dyn_
;
2383 // Similarly, but for ifunc symbols get the one for ifunc.
2385 template<int size
, bool big_endian
>
2386 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2387 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2392 return this->rela_dyn_section(layout
);
2394 if (this->iplt_
== NULL
)
2395 this->make_iplt_section(symtab
, layout
);
2396 return this->iplt_
->rel_plt();
2402 // Determine the stub group size. The group size is the absolute
2403 // value of the parameter --stub-group-size. If --stub-group-size
2404 // is passed a negative value, we restrict stubs to be always before
2405 // the stubbed branches.
2406 Stub_control(int32_t size
, bool no_size_errors
)
2407 : state_(NO_GROUP
), stub_group_size_(abs(size
)),
2408 stub14_group_size_(abs(size
) >> 10),
2409 stubs_always_before_branch_(size
< 0),
2410 suppress_size_errors_(no_size_errors
),
2411 group_end_addr_(0), owner_(NULL
), output_section_(NULL
)
2415 // Return true iff input section can be handled by current stub
2418 can_add_to_stub_group(Output_section
* o
,
2419 const Output_section::Input_section
* i
,
2422 const Output_section::Input_section
*
2428 { return output_section_
; }
2431 set_output_and_owner(Output_section
* o
,
2432 const Output_section::Input_section
* i
)
2434 this->output_section_
= o
;
2442 FINDING_STUB_SECTION
,
2447 uint32_t stub_group_size_
;
2448 uint32_t stub14_group_size_
;
2449 bool stubs_always_before_branch_
;
2450 bool suppress_size_errors_
;
2451 uint64_t group_end_addr_
;
2452 const Output_section::Input_section
* owner_
;
2453 Output_section
* output_section_
;
2456 // Return true iff input section can be handled by current stub
2460 Stub_control::can_add_to_stub_group(Output_section
* o
,
2461 const Output_section::Input_section
* i
,
2465 = has14
? this->stub14_group_size_
: this->stub_group_size_
;
2466 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2468 uint64_t start_addr
= o
->address();
2471 // .init and .fini sections are pasted together to form a single
2472 // function. We can't be adding stubs in the middle of the function.
2473 this_size
= o
->data_size();
2476 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2477 this_size
= i
->data_size();
2479 uint64_t end_addr
= start_addr
+ this_size
;
2480 bool toobig
= this_size
> group_size
;
2482 if (toobig
&& !this->suppress_size_errors_
)
2483 gold_warning(_("%s:%s exceeds group size"),
2484 i
->relobj()->name().c_str(),
2485 i
->relobj()->section_name(i
->shndx()).c_str());
2487 if (this->state_
!= HAS_STUB_SECTION
2488 && (!whole_sec
|| this->output_section_
!= o
)
2489 && (this->state_
== NO_GROUP
2490 || this->group_end_addr_
- end_addr
< group_size
))
2493 this->output_section_
= o
;
2496 if (this->state_
== NO_GROUP
)
2498 this->state_
= FINDING_STUB_SECTION
;
2499 this->group_end_addr_
= end_addr
;
2501 else if (this->group_end_addr_
- start_addr
< group_size
)
2503 // Adding this section would make the group larger than GROUP_SIZE.
2504 else if (this->state_
== FINDING_STUB_SECTION
2505 && !this->stubs_always_before_branch_
2508 // But wait, there's more! Input sections up to GROUP_SIZE
2509 // bytes before the stub table can be handled by it too.
2510 this->state_
= HAS_STUB_SECTION
;
2511 this->group_end_addr_
= end_addr
;
2515 this->state_
= NO_GROUP
;
2521 // Look over all the input sections, deciding where to place stubs.
2523 template<int size
, bool big_endian
>
2525 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2527 bool no_size_errors
)
2529 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
);
2531 // Group input sections and insert stub table
2532 Stub_table_owner
* table_owner
= NULL
;
2533 std::vector
<Stub_table_owner
*> tables
;
2534 Layout::Section_list section_list
;
2535 layout
->get_executable_sections(§ion_list
);
2536 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2537 for (Layout::Section_list::reverse_iterator o
= section_list
.rbegin();
2538 o
!= section_list
.rend();
2541 typedef Output_section::Input_section_list Input_section_list
;
2542 for (Input_section_list::const_reverse_iterator i
2543 = (*o
)->input_sections().rbegin();
2544 i
!= (*o
)->input_sections().rend();
2547 if (i
->is_input_section()
2548 || i
->is_relaxed_input_section())
2550 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2551 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2552 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2553 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2555 table_owner
->output_section
= stub_control
.output_section();
2556 table_owner
->owner
= stub_control
.owner();
2557 stub_control
.set_output_and_owner(*o
, &*i
);
2560 if (table_owner
== NULL
)
2562 table_owner
= new Stub_table_owner
;
2563 tables
.push_back(table_owner
);
2565 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2569 if (table_owner
!= NULL
)
2571 const Output_section::Input_section
* i
= stub_control
.owner();
2573 if (tables
.size() >= 2 && tables
[tables
.size() - 2]->owner
== i
)
2575 // Corner case. A new stub group was made for the first
2576 // section (last one looked at here) for some reason, but
2577 // the first section is already being used as the owner for
2578 // a stub table for following sections. Force it into that
2582 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2583 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2584 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2588 table_owner
->output_section
= stub_control
.output_section();
2589 table_owner
->owner
= i
;
2592 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
2596 Stub_table
<size
, big_endian
>* stub_table
;
2598 if ((*t
)->owner
->is_input_section())
2599 stub_table
= new Stub_table
<size
, big_endian
>(this,
2600 (*t
)->output_section
,
2602 else if ((*t
)->owner
->is_relaxed_input_section())
2603 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
2604 (*t
)->owner
->relaxed_input_section());
2607 this->stub_tables_
.push_back(stub_table
);
2612 static unsigned long
2613 max_branch_delta (unsigned int r_type
)
2615 if (r_type
== elfcpp::R_POWERPC_REL14
2616 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
2617 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2619 if (r_type
== elfcpp::R_POWERPC_REL24
2620 || r_type
== elfcpp::R_PPC_PLTREL24
2621 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
2626 // If this branch needs a plt call stub, or a long branch stub, make one.
2628 template<int size
, bool big_endian
>
2630 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2631 Stub_table
<size
, big_endian
>* stub_table
,
2632 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2633 Symbol_table
* symtab
) const
2635 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2636 if (sym
!= NULL
&& sym
->is_forwarder())
2637 sym
= symtab
->resolve_forwards(sym
);
2638 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2639 Target_powerpc
<size
, big_endian
>* target
=
2640 static_cast<Target_powerpc
<size
, big_endian
>*>(
2641 parameters
->sized_target
<size
, big_endian
>());
2643 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
2644 : this->object_
->local_has_plt_offset(this->r_sym_
))
2648 && target
->abiversion() >= 2
2649 && !parameters
->options().output_is_position_independent()
2650 && !is_branch_reloc(this->r_type_
))
2651 target
->glink_section()->add_global_entry(gsym
);
2654 if (stub_table
== NULL
)
2655 stub_table
= this->object_
->stub_table(this->shndx_
);
2656 if (stub_table
== NULL
)
2658 // This is a ref from a data section to an ifunc symbol.
2659 stub_table
= ifunc_stub_table
;
2661 gold_assert(stub_table
!= NULL
);
2662 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2663 if (from
!= invalid_address
)
2664 from
+= (this->object_
->output_section(this->shndx_
)->address()
2667 return stub_table
->add_plt_call_entry(from
,
2668 this->object_
, gsym
,
2669 this->r_type_
, this->addend_
);
2671 return stub_table
->add_plt_call_entry(from
,
2672 this->object_
, this->r_sym_
,
2673 this->r_type_
, this->addend_
);
2678 Address max_branch_offset
= max_branch_delta(this->r_type_
);
2679 if (max_branch_offset
== 0)
2681 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2682 gold_assert(from
!= invalid_address
);
2683 from
+= (this->object_
->output_section(this->shndx_
)->address()
2688 switch (gsym
->source())
2690 case Symbol::FROM_OBJECT
:
2692 Object
* symobj
= gsym
->object();
2693 if (symobj
->is_dynamic()
2694 || symobj
->pluginobj() != NULL
)
2697 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2698 if (shndx
== elfcpp::SHN_UNDEF
)
2703 case Symbol::IS_UNDEFINED
:
2709 Symbol_table::Compute_final_value_status status
;
2710 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2711 if (status
!= Symbol_table::CFVS_OK
)
2714 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
2718 const Symbol_value
<size
>* psymval
2719 = this->object_
->local_symbol(this->r_sym_
);
2720 Symbol_value
<size
> symval
;
2721 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2722 typename
ObjType::Compute_final_local_value_status status
2723 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2725 if (status
!= ObjType::CFLV_OK
2726 || !symval
.has_output_value())
2728 to
= symval
.value(this->object_
, 0);
2730 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
2732 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
2733 to
+= this->addend_
;
2734 if (stub_table
== NULL
)
2735 stub_table
= this->object_
->stub_table(this->shndx_
);
2736 if (size
== 64 && target
->abiversion() < 2)
2738 unsigned int dest_shndx
;
2739 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
2743 Address delta
= to
- from
;
2744 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2746 if (stub_table
== NULL
)
2748 gold_warning(_("%s:%s: branch in non-executable section,"
2749 " no long branch stub for you"),
2750 this->object_
->name().c_str(),
2751 this->object_
->section_name(this->shndx_
).c_str());
2754 bool save_res
= (size
== 64
2756 && gsym
->source() == Symbol::IN_OUTPUT_DATA
2757 && gsym
->output_data() == target
->savres_section());
2758 return stub_table
->add_long_branch_entry(this->object_
,
2760 from
, to
, save_res
);
2766 // Relaxation hook. This is where we do stub generation.
2768 template<int size
, bool big_endian
>
2770 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2771 const Input_objects
*,
2772 Symbol_table
* symtab
,
2776 unsigned int prev_brlt_size
= 0;
2780 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
2782 && this->abiversion() < 2
2784 && !parameters
->options().user_set_plt_thread_safe())
2786 static const char* const thread_starter
[] =
2790 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2792 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2793 "mq_notify", "create_timer",
2798 "GOMP_parallel_start",
2799 "GOMP_parallel_loop_static",
2800 "GOMP_parallel_loop_static_start",
2801 "GOMP_parallel_loop_dynamic",
2802 "GOMP_parallel_loop_dynamic_start",
2803 "GOMP_parallel_loop_guided",
2804 "GOMP_parallel_loop_guided_start",
2805 "GOMP_parallel_loop_runtime",
2806 "GOMP_parallel_loop_runtime_start",
2807 "GOMP_parallel_sections",
2808 "GOMP_parallel_sections_start",
2813 if (parameters
->options().shared())
2817 for (unsigned int i
= 0;
2818 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2821 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2822 thread_safe
= (sym
!= NULL
2824 && sym
->in_real_elf());
2830 this->plt_thread_safe_
= thread_safe
;
2835 this->stub_group_size_
= parameters
->options().stub_group_size();
2836 bool no_size_errors
= true;
2837 if (this->stub_group_size_
== 1)
2838 this->stub_group_size_
= 0x1c00000;
2839 else if (this->stub_group_size_
== -1)
2840 this->stub_group_size_
= -0x1e00000;
2842 no_size_errors
= false;
2843 this->group_sections(layout
, task
, no_size_errors
);
2845 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
2847 this->branch_lookup_table_
.clear();
2848 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2849 p
!= this->stub_tables_
.end();
2852 (*p
)->clear_stubs(true);
2854 this->stub_tables_
.clear();
2855 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
2856 gold_info(_("%s: stub group size is too large; retrying with %d"),
2857 program_name
, this->stub_group_size_
);
2858 this->group_sections(layout
, task
, true);
2861 // We need address of stub tables valid for make_stub.
2862 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2863 p
!= this->stub_tables_
.end();
2866 const Powerpc_relobj
<size
, big_endian
>* object
2867 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2868 Address off
= object
->get_output_section_offset((*p
)->shndx());
2869 gold_assert(off
!= invalid_address
);
2870 Output_section
* os
= (*p
)->output_section();
2871 (*p
)->set_address_and_size(os
, off
);
2876 // Clear plt call stubs, long branch stubs and branch lookup table.
2877 prev_brlt_size
= this->branch_lookup_table_
.size();
2878 this->branch_lookup_table_
.clear();
2879 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2880 p
!= this->stub_tables_
.end();
2883 (*p
)->clear_stubs(false);
2887 // Build all the stubs.
2888 this->relax_failed_
= false;
2889 Stub_table
<size
, big_endian
>* ifunc_stub_table
2890 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2891 Stub_table
<size
, big_endian
>* one_stub_table
2892 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2893 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2894 b
!= this->branch_info_
.end();
2897 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
2898 && !this->relax_failed_
)
2900 this->relax_failed_
= true;
2901 this->relax_fail_count_
++;
2902 if (this->relax_fail_count_
< 3)
2907 // Did anything change size?
2908 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2909 bool again
= num_huge_branches
!= prev_brlt_size
;
2910 if (size
== 64 && num_huge_branches
!= 0)
2911 this->make_brlt_section(layout
);
2912 if (size
== 64 && again
)
2913 this->brlt_section_
->set_current_size(num_huge_branches
);
2915 typedef Unordered_set
<Output_section
*> Output_sections
;
2916 Output_sections os_need_update
;
2917 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2918 p
!= this->stub_tables_
.end();
2921 if ((*p
)->size_update())
2924 (*p
)->add_eh_frame(layout
);
2925 os_need_update
.insert((*p
)->output_section());
2929 // Set output section offsets for all input sections in an output
2930 // section that just changed size. Anything past the stubs will
2932 for (typename
Output_sections::iterator p
= os_need_update
.begin();
2933 p
!= os_need_update
.end();
2936 Output_section
* os
= *p
;
2938 typedef Output_section::Input_section_list Input_section_list
;
2939 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
2940 i
!= os
->input_sections().end();
2943 off
= align_address(off
, i
->addralign());
2944 if (i
->is_input_section() || i
->is_relaxed_input_section())
2945 i
->relobj()->set_section_offset(i
->shndx(), off
);
2946 if (i
->is_relaxed_input_section())
2948 Stub_table
<size
, big_endian
>* stub_table
2949 = static_cast<Stub_table
<size
, big_endian
>*>(
2950 i
->relaxed_input_section());
2951 off
+= stub_table
->set_address_and_size(os
, off
);
2954 off
+= i
->data_size();
2956 // If .branch_lt is part of this output section, then we have
2957 // just done the offset adjustment.
2958 os
->clear_section_offsets_need_adjustment();
2963 && num_huge_branches
!= 0
2964 && parameters
->options().output_is_position_independent())
2966 // Fill in the BRLT relocs.
2967 this->brlt_section_
->reset_brlt_sizes();
2968 for (typename
Branch_lookup_table::const_iterator p
2969 = this->branch_lookup_table_
.begin();
2970 p
!= this->branch_lookup_table_
.end();
2973 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
2975 this->brlt_section_
->finalize_brlt_sizes();
2980 template<int size
, bool big_endian
>
2982 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
2983 unsigned char* oview
,
2987 uint64_t address
= plt
->address();
2988 off_t len
= plt
->data_size();
2990 if (plt
== this->glink_
)
2992 // See Output_data_glink::do_write() for glink contents.
2995 gold_assert(parameters
->doing_static_link());
2996 // Static linking may need stubs, to support ifunc and long
2997 // branches. We need to create an output section for
2998 // .eh_frame early in the link process, to have a place to
2999 // attach stub .eh_frame info. We also need to have
3000 // registered a CIE that matches the stub CIE. Both of
3001 // these requirements are satisfied by creating an FDE and
3002 // CIE for .glink, even though static linking will leave
3003 // .glink zero length.
3004 // ??? Hopefully generating an FDE with a zero address range
3005 // won't confuse anything that consumes .eh_frame info.
3007 else if (size
== 64)
3009 // There is one word before __glink_PLTresolve
3013 else if (parameters
->options().output_is_position_independent())
3015 // There are two FDEs for a position independent glink.
3016 // The first covers the branch table, the second
3017 // __glink_PLTresolve at the end of glink.
3018 off_t resolve_size
= this->glink_
->pltresolve_size
;
3019 if (oview
[9] == elfcpp::DW_CFA_nop
)
3020 len
-= resolve_size
;
3023 address
+= len
- resolve_size
;
3030 // Must be a stub table.
3031 const Stub_table
<size
, big_endian
>* stub_table
3032 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3033 uint64_t stub_address
= stub_table
->stub_address();
3034 len
-= stub_address
- address
;
3035 address
= stub_address
;
3038 *paddress
= address
;
3042 // A class to handle the PLT data.
3044 template<int size
, bool big_endian
>
3045 class Output_data_plt_powerpc
: public Output_section_data_build
3048 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3049 size
, big_endian
> Reloc_section
;
3051 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3052 Reloc_section
* plt_rel
,
3054 : Output_section_data_build(size
== 32 ? 4 : 8),
3060 // Add an entry to the PLT.
3065 add_ifunc_entry(Symbol
*);
3068 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3070 // Return the .rela.plt section data.
3077 // Return the number of PLT entries.
3081 if (this->current_data_size() == 0)
3083 return ((this->current_data_size() - this->first_plt_entry_offset())
3084 / this->plt_entry_size());
3089 do_adjust_output_section(Output_section
* os
)
3094 // Write to a map file.
3096 do_print_to_mapfile(Mapfile
* mapfile
) const
3097 { mapfile
->print_output_data(this, this->name_
); }
3100 // Return the offset of the first non-reserved PLT entry.
3102 first_plt_entry_offset() const
3104 // IPLT has no reserved entry.
3105 if (this->name_
[3] == 'I')
3107 return this->targ_
->first_plt_entry_offset();
3110 // Return the size of each PLT entry.
3112 plt_entry_size() const
3114 return this->targ_
->plt_entry_size();
3117 // Write out the PLT data.
3119 do_write(Output_file
*);
3121 // The reloc section.
3122 Reloc_section
* rel_
;
3123 // Allows access to .glink for do_write.
3124 Target_powerpc
<size
, big_endian
>* targ_
;
3125 // What to report in map file.
3129 // Add an entry to the PLT.
3131 template<int size
, bool big_endian
>
3133 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3135 if (!gsym
->has_plt_offset())
3137 section_size_type off
= this->current_data_size();
3139 off
+= this->first_plt_entry_offset();
3140 gsym
->set_plt_offset(off
);
3141 gsym
->set_needs_dynsym_entry();
3142 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3143 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3144 off
+= this->plt_entry_size();
3145 this->set_current_data_size(off
);
3149 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3151 template<int size
, bool big_endian
>
3153 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3155 if (!gsym
->has_plt_offset())
3157 section_size_type off
= this->current_data_size();
3158 gsym
->set_plt_offset(off
);
3159 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3160 if (size
== 64 && this->targ_
->abiversion() < 2)
3161 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3162 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3163 off
+= this->plt_entry_size();
3164 this->set_current_data_size(off
);
3168 // Add an entry for a local ifunc symbol to the IPLT.
3170 template<int size
, bool big_endian
>
3172 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3173 Sized_relobj_file
<size
, big_endian
>* relobj
,
3174 unsigned int local_sym_index
)
3176 if (!relobj
->local_has_plt_offset(local_sym_index
))
3178 section_size_type off
= this->current_data_size();
3179 relobj
->set_local_plt_offset(local_sym_index
, off
);
3180 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3181 if (size
== 64 && this->targ_
->abiversion() < 2)
3182 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3183 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3185 off
+= this->plt_entry_size();
3186 this->set_current_data_size(off
);
3190 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3191 static const uint32_t add_2_2_11
= 0x7c425a14;
3192 static const uint32_t add_3_3_2
= 0x7c631214;
3193 static const uint32_t add_3_3_13
= 0x7c636a14;
3194 static const uint32_t add_11_0_11
= 0x7d605a14;
3195 static const uint32_t add_11_2_11
= 0x7d625a14;
3196 static const uint32_t add_11_11_2
= 0x7d6b1214;
3197 static const uint32_t addi_0_12
= 0x380c0000;
3198 static const uint32_t addi_2_2
= 0x38420000;
3199 static const uint32_t addi_3_3
= 0x38630000;
3200 static const uint32_t addi_11_11
= 0x396b0000;
3201 static const uint32_t addi_12_1
= 0x39810000;
3202 static const uint32_t addi_12_12
= 0x398c0000;
3203 static const uint32_t addis_0_2
= 0x3c020000;
3204 static const uint32_t addis_0_13
= 0x3c0d0000;
3205 static const uint32_t addis_2_12
= 0x3c4c0000;
3206 static const uint32_t addis_11_2
= 0x3d620000;
3207 static const uint32_t addis_11_11
= 0x3d6b0000;
3208 static const uint32_t addis_11_30
= 0x3d7e0000;
3209 static const uint32_t addis_12_1
= 0x3d810000;
3210 static const uint32_t addis_12_2
= 0x3d820000;
3211 static const uint32_t addis_12_12
= 0x3d8c0000;
3212 static const uint32_t b
= 0x48000000;
3213 static const uint32_t bcl_20_31
= 0x429f0005;
3214 static const uint32_t bctr
= 0x4e800420;
3215 static const uint32_t blr
= 0x4e800020;
3216 static const uint32_t bnectr_p4
= 0x4ce20420;
3217 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
3218 static const uint32_t cmpldi_2_0
= 0x28220000;
3219 static const uint32_t cror_15_15_15
= 0x4def7b82;
3220 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3221 static const uint32_t ld_0_1
= 0xe8010000;
3222 static const uint32_t ld_0_12
= 0xe80c0000;
3223 static const uint32_t ld_2_1
= 0xe8410000;
3224 static const uint32_t ld_2_2
= 0xe8420000;
3225 static const uint32_t ld_2_11
= 0xe84b0000;
3226 static const uint32_t ld_11_2
= 0xe9620000;
3227 static const uint32_t ld_11_11
= 0xe96b0000;
3228 static const uint32_t ld_12_2
= 0xe9820000;
3229 static const uint32_t ld_12_11
= 0xe98b0000;
3230 static const uint32_t ld_12_12
= 0xe98c0000;
3231 static const uint32_t lfd_0_1
= 0xc8010000;
3232 static const uint32_t li_0_0
= 0x38000000;
3233 static const uint32_t li_12_0
= 0x39800000;
3234 static const uint32_t lis_0
= 0x3c000000;
3235 static const uint32_t lis_11
= 0x3d600000;
3236 static const uint32_t lis_12
= 0x3d800000;
3237 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3238 static const uint32_t lwz_0_12
= 0x800c0000;
3239 static const uint32_t lwz_11_11
= 0x816b0000;
3240 static const uint32_t lwz_11_30
= 0x817e0000;
3241 static const uint32_t lwz_12_12
= 0x818c0000;
3242 static const uint32_t lwzu_0_12
= 0x840c0000;
3243 static const uint32_t mflr_0
= 0x7c0802a6;
3244 static const uint32_t mflr_11
= 0x7d6802a6;
3245 static const uint32_t mflr_12
= 0x7d8802a6;
3246 static const uint32_t mtctr_0
= 0x7c0903a6;
3247 static const uint32_t mtctr_11
= 0x7d6903a6;
3248 static const uint32_t mtctr_12
= 0x7d8903a6;
3249 static const uint32_t mtlr_0
= 0x7c0803a6;
3250 static const uint32_t mtlr_12
= 0x7d8803a6;
3251 static const uint32_t nop
= 0x60000000;
3252 static const uint32_t ori_0_0_0
= 0x60000000;
3253 static const uint32_t srdi_0_0_2
= 0x7800f082;
3254 static const uint32_t std_0_1
= 0xf8010000;
3255 static const uint32_t std_0_12
= 0xf80c0000;
3256 static const uint32_t std_2_1
= 0xf8410000;
3257 static const uint32_t stfd_0_1
= 0xd8010000;
3258 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3259 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3260 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3261 static const uint32_t xor_2_12_12
= 0x7d826278;
3262 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3264 // Write out the PLT.
3266 template<int size
, bool big_endian
>
3268 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3270 if (size
== 32 && this->name_
[3] != 'I')
3272 const section_size_type offset
= this->offset();
3273 const section_size_type oview_size
3274 = convert_to_section_size_type(this->data_size());
3275 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3276 unsigned char* pov
= oview
;
3277 unsigned char* endpov
= oview
+ oview_size
;
3279 // The address of the .glink branch table
3280 const Output_data_glink
<size
, big_endian
>* glink
3281 = this->targ_
->glink_section();
3282 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3284 while (pov
< endpov
)
3286 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3291 of
->write_output_view(offset
, oview_size
, oview
);
3295 // Create the PLT section.
3297 template<int size
, bool big_endian
>
3299 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3302 if (this->plt_
== NULL
)
3304 if (this->got_
== NULL
)
3305 this->got_section(symtab
, layout
);
3307 if (this->glink_
== NULL
)
3308 make_glink_section(layout
);
3310 // Ensure that .rela.dyn always appears before .rela.plt This is
3311 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3312 // needs to include .rela.plt in its range.
3313 this->rela_dyn_section(layout
);
3315 Reloc_section
* plt_rel
= new Reloc_section(false);
3316 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3317 elfcpp::SHF_ALLOC
, plt_rel
,
3318 ORDER_DYNAMIC_PLT_RELOCS
, false);
3320 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3322 layout
->add_output_section_data(".plt",
3324 ? elfcpp::SHT_PROGBITS
3325 : elfcpp::SHT_NOBITS
),
3326 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3335 // Create the IPLT section.
3337 template<int size
, bool big_endian
>
3339 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3342 if (this->iplt_
== NULL
)
3344 this->make_plt_section(symtab
, layout
);
3346 Reloc_section
* iplt_rel
= new Reloc_section(false);
3347 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3349 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3351 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3355 // A section for huge long branch addresses, similar to plt section.
3357 template<int size
, bool big_endian
>
3358 class Output_data_brlt_powerpc
: public Output_section_data_build
3361 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3362 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3363 size
, big_endian
> Reloc_section
;
3365 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3366 Reloc_section
* brlt_rel
)
3367 : Output_section_data_build(size
== 32 ? 4 : 8),
3375 this->reset_data_size();
3376 this->rel_
->reset_data_size();
3380 finalize_brlt_sizes()
3382 this->finalize_data_size();
3383 this->rel_
->finalize_data_size();
3386 // Add a reloc for an entry in the BRLT.
3388 add_reloc(Address to
, unsigned int off
)
3389 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
3391 // Update section and reloc section size.
3393 set_current_size(unsigned int num_branches
)
3395 this->reset_address_and_file_offset();
3396 this->set_current_data_size(num_branches
* 16);
3397 this->finalize_data_size();
3398 Output_section
* os
= this->output_section();
3399 os
->set_section_offsets_need_adjustment();
3400 if (this->rel_
!= NULL
)
3402 unsigned int reloc_size
3403 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
3404 this->rel_
->reset_address_and_file_offset();
3405 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
3406 this->rel_
->finalize_data_size();
3407 Output_section
* os
= this->rel_
->output_section();
3408 os
->set_section_offsets_need_adjustment();
3414 do_adjust_output_section(Output_section
* os
)
3419 // Write to a map file.
3421 do_print_to_mapfile(Mapfile
* mapfile
) const
3422 { mapfile
->print_output_data(this, "** BRLT"); }
3425 // Write out the BRLT data.
3427 do_write(Output_file
*);
3429 // The reloc section.
3430 Reloc_section
* rel_
;
3431 Target_powerpc
<size
, big_endian
>* targ_
;
3434 // Make the branch lookup table section.
3436 template<int size
, bool big_endian
>
3438 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
3440 if (size
== 64 && this->brlt_section_
== NULL
)
3442 Reloc_section
* brlt_rel
= NULL
;
3443 bool is_pic
= parameters
->options().output_is_position_independent();
3446 // When PIC we can't fill in .branch_lt (like .plt it can be
3447 // a bss style section) but must initialise at runtime via
3448 // dynamic relocats.
3449 this->rela_dyn_section(layout
);
3450 brlt_rel
= new Reloc_section(false);
3451 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3454 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3455 if (this->plt_
&& is_pic
)
3456 this->plt_
->output_section()
3457 ->add_output_section_data(this->brlt_section_
);
3459 layout
->add_output_section_data(".branch_lt",
3460 (is_pic
? elfcpp::SHT_NOBITS
3461 : elfcpp::SHT_PROGBITS
),
3462 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3463 this->brlt_section_
,
3464 (is_pic
? ORDER_SMALL_BSS
3465 : ORDER_SMALL_DATA
),
3470 // Write out .branch_lt when non-PIC.
3472 template<int size
, bool big_endian
>
3474 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3476 if (size
== 64 && !parameters
->options().output_is_position_independent())
3478 const section_size_type offset
= this->offset();
3479 const section_size_type oview_size
3480 = convert_to_section_size_type(this->data_size());
3481 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3483 this->targ_
->write_branch_lookup_table(oview
);
3484 of
->write_output_view(offset
, oview_size
, oview
);
3488 static inline uint32_t
3494 static inline uint32_t
3500 static inline uint32_t
3503 return hi(a
+ 0x8000);
3509 static const unsigned char eh_frame_cie
[12];
3513 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3516 'z', 'R', 0, // Augmentation string.
3517 4, // Code alignment.
3518 0x80 - size
/ 8 , // Data alignment.
3520 1, // Augmentation size.
3521 (elfcpp::DW_EH_PE_pcrel
3522 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3523 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3526 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3527 static const unsigned char glink_eh_frame_fde_64v1
[] =
3529 0, 0, 0, 0, // Replaced with offset to .glink.
3530 0, 0, 0, 0, // Replaced with size of .glink.
3531 0, // Augmentation size.
3532 elfcpp::DW_CFA_advance_loc
+ 1,
3533 elfcpp::DW_CFA_register
, 65, 12,
3534 elfcpp::DW_CFA_advance_loc
+ 4,
3535 elfcpp::DW_CFA_restore_extended
, 65
3538 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3539 static const unsigned char glink_eh_frame_fde_64v2
[] =
3541 0, 0, 0, 0, // Replaced with offset to .glink.
3542 0, 0, 0, 0, // Replaced with size of .glink.
3543 0, // Augmentation size.
3544 elfcpp::DW_CFA_advance_loc
+ 1,
3545 elfcpp::DW_CFA_register
, 65, 0,
3546 elfcpp::DW_CFA_advance_loc
+ 4,
3547 elfcpp::DW_CFA_restore_extended
, 65
3550 // Describe __glink_PLTresolve use of LR, 32-bit version.
3551 static const unsigned char glink_eh_frame_fde_32
[] =
3553 0, 0, 0, 0, // Replaced with offset to .glink.
3554 0, 0, 0, 0, // Replaced with size of .glink.
3555 0, // Augmentation size.
3556 elfcpp::DW_CFA_advance_loc
+ 2,
3557 elfcpp::DW_CFA_register
, 65, 0,
3558 elfcpp::DW_CFA_advance_loc
+ 4,
3559 elfcpp::DW_CFA_restore_extended
, 65
3562 static const unsigned char default_fde
[] =
3564 0, 0, 0, 0, // Replaced with offset to stubs.
3565 0, 0, 0, 0, // Replaced with size of stubs.
3566 0, // Augmentation size.
3567 elfcpp::DW_CFA_nop
, // Pad.
3572 template<bool big_endian
>
3574 write_insn(unsigned char* p
, uint32_t v
)
3576 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3579 // Stub_table holds information about plt and long branch stubs.
3580 // Stubs are built in an area following some input section determined
3581 // by group_sections(). This input section is converted to a relaxed
3582 // input section allowing it to be resized to accommodate the stubs
3584 template<int size
, bool big_endian
>
3585 class Stub_table
: public Output_relaxed_input_section
3588 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3589 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3591 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
3592 Output_section
* output_section
,
3593 const Output_section::Input_section
* owner
)
3594 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
3596 ->section_addralign(owner
->shndx())),
3597 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3598 orig_data_size_(owner
->current_data_size()),
3599 plt_size_(0), last_plt_size_(0),
3600 branch_size_(0), last_branch_size_(0), eh_frame_added_(false),
3601 need_save_res_(false)
3603 this->set_output_section(output_section
);
3605 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3606 new_relaxed
.push_back(this);
3607 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3610 // Add a plt call stub.
3612 add_plt_call_entry(Address
,
3613 const Sized_relobj_file
<size
, big_endian
>*,
3619 add_plt_call_entry(Address
,
3620 const Sized_relobj_file
<size
, big_endian
>*,
3625 // Find a given plt call stub.
3627 find_plt_call_entry(const Symbol
*) const;
3630 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3631 unsigned int) const;
3634 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3640 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3645 // Add a long branch stub.
3647 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3648 unsigned int, Address
, Address
, bool);
3651 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3655 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
3657 Address max_branch_offset
= max_branch_delta(r_type
);
3658 if (max_branch_offset
== 0)
3660 gold_assert(from
!= invalid_address
);
3661 Address loc
= off
+ this->stub_address();
3662 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
3666 clear_stubs(bool all
)
3668 this->plt_call_stubs_
.clear();
3669 this->plt_size_
= 0;
3670 this->long_branch_stubs_
.clear();
3671 this->branch_size_
= 0;
3672 this->need_save_res_
= false;
3675 this->last_plt_size_
= 0;
3676 this->last_branch_size_
= 0;
3681 set_address_and_size(const Output_section
* os
, Address off
)
3683 Address start_off
= off
;
3684 off
+= this->orig_data_size_
;
3685 Address my_size
= this->plt_size_
+ this->branch_size_
;
3686 if (this->need_save_res_
)
3687 my_size
+= this->targ_
->savres_section()->data_size();
3689 off
= align_address(off
, this->stub_align());
3690 // Include original section size and alignment padding in size
3691 my_size
+= off
- start_off
;
3692 this->reset_address_and_file_offset();
3693 this->set_current_data_size(my_size
);
3694 this->set_address_and_file_offset(os
->address() + start_off
,
3695 os
->offset() + start_off
);
3700 stub_address() const
3702 return align_address(this->address() + this->orig_data_size_
,
3703 this->stub_align());
3709 return align_address(this->offset() + this->orig_data_size_
,
3710 this->stub_align());
3715 { return this->plt_size_
; }
3720 Output_section
* os
= this->output_section();
3721 if (os
->addralign() < this->stub_align())
3723 os
->set_addralign(this->stub_align());
3724 // FIXME: get rid of the insane checkpointing.
3725 // We can't increase alignment of the input section to which
3726 // stubs are attached; The input section may be .init which
3727 // is pasted together with other .init sections to form a
3728 // function. Aligning might insert zero padding resulting in
3729 // sigill. However we do need to increase alignment of the
3730 // output section so that the align_address() on offset in
3731 // set_address_and_size() adds the same padding as the
3732 // align_address() on address in stub_address().
3733 // What's more, we need this alignment for the layout done in
3734 // relaxation_loop_body() so that the output section starts at
3735 // a suitably aligned address.
3736 os
->checkpoint_set_addralign(this->stub_align());
3738 if (this->last_plt_size_
!= this->plt_size_
3739 || this->last_branch_size_
!= this->branch_size_
)
3741 this->last_plt_size_
= this->plt_size_
;
3742 this->last_branch_size_
= this->branch_size_
;
3748 // Add .eh_frame info for this stub section. Unlike other linker
3749 // generated .eh_frame this is added late in the link, because we
3750 // only want the .eh_frame info if this particular stub section is
3753 add_eh_frame(Layout
* layout
)
3755 if (!this->eh_frame_added_
)
3757 if (!parameters
->options().ld_generated_unwind_info())
3760 // Since we add stub .eh_frame info late, it must be placed
3761 // after all other linker generated .eh_frame info so that
3762 // merge mapping need not be updated for input sections.
3763 // There is no provision to use a different CIE to that used
3765 if (!this->targ_
->has_glink())
3768 layout
->add_eh_frame_for_plt(this,
3769 Eh_cie
<size
>::eh_frame_cie
,
3770 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3772 sizeof (default_fde
));
3773 this->eh_frame_added_
= true;
3777 Target_powerpc
<size
, big_endian
>*
3783 class Plt_stub_ent_hash
;
3784 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3785 Plt_stub_ent_hash
> Plt_stub_entries
;
3787 // Alignment of stub section.
3793 unsigned int min_align
= 32;
3794 unsigned int user_align
= 1 << parameters
->options().plt_align();
3795 return std::max(user_align
, min_align
);
3798 // Return the plt offset for the given call stub.
3800 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3802 const Symbol
* gsym
= p
->first
.sym_
;
3805 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3806 && gsym
->can_use_relative_reloc(false));
3807 return gsym
->plt_offset();
3812 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3813 unsigned int local_sym_index
= p
->first
.locsym_
;
3814 return relobj
->local_plt_offset(local_sym_index
);
3818 // Size of a given plt call stub.
3820 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3826 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3828 plt_addr
+= this->targ_
->iplt_section()->address();
3830 plt_addr
+= this->targ_
->plt_section()->address();
3831 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3832 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3833 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3834 got_addr
+= ppcobj
->toc_base_offset();
3835 Address off
= plt_addr
- got_addr
;
3836 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
3837 if (this->targ_
->abiversion() < 2)
3839 bool static_chain
= parameters
->options().plt_static_chain();
3840 bool thread_safe
= this->targ_
->plt_thread_safe();
3844 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3846 unsigned int align
= 1 << parameters
->options().plt_align();
3848 bytes
= (bytes
+ align
- 1) & -align
;
3852 // Return long branch stub size.
3854 branch_stub_size(Address to
)
3857 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3858 if (to
- loc
+ (1 << 25) < 2 << 25)
3860 if (size
== 64 || !parameters
->options().output_is_position_independent())
3867 do_write(Output_file
*);
3869 // Plt call stub keys.
3873 Plt_stub_ent(const Symbol
* sym
)
3874 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3877 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3878 unsigned int locsym_index
)
3879 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3882 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3884 unsigned int r_type
,
3886 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3889 this->addend_
= addend
;
3890 else if (parameters
->options().output_is_position_independent()
3891 && r_type
== elfcpp::R_PPC_PLTREL24
)
3893 this->addend_
= addend
;
3894 if (this->addend_
>= 32768)
3895 this->object_
= object
;
3899 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3900 unsigned int locsym_index
,
3901 unsigned int r_type
,
3903 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3906 this->addend_
= addend
;
3907 else if (parameters
->options().output_is_position_independent()
3908 && r_type
== elfcpp::R_PPC_PLTREL24
)
3909 this->addend_
= addend
;
3912 bool operator==(const Plt_stub_ent
& that
) const
3914 return (this->sym_
== that
.sym_
3915 && this->object_
== that
.object_
3916 && this->addend_
== that
.addend_
3917 && this->locsym_
== that
.locsym_
);
3921 const Sized_relobj_file
<size
, big_endian
>* object_
;
3922 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
3923 unsigned int locsym_
;
3926 class Plt_stub_ent_hash
3929 size_t operator()(const Plt_stub_ent
& ent
) const
3931 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
3932 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
3938 // Long branch stub keys.
3939 class Branch_stub_ent
3942 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
,
3943 Address to
, bool save_res
)
3944 : dest_(to
), toc_base_off_(0), save_res_(save_res
)
3947 toc_base_off_
= obj
->toc_base_offset();
3950 bool operator==(const Branch_stub_ent
& that
) const
3952 return (this->dest_
== that
.dest_
3954 || this->toc_base_off_
== that
.toc_base_off_
));
3958 unsigned int toc_base_off_
;
3962 class Branch_stub_ent_hash
3965 size_t operator()(const Branch_stub_ent
& ent
) const
3966 { return ent
.dest_
^ ent
.toc_base_off_
; }
3969 // In a sane world this would be a global.
3970 Target_powerpc
<size
, big_endian
>* targ_
;
3971 // Map sym/object/addend to stub offset.
3972 Plt_stub_entries plt_call_stubs_
;
3973 // Map destination address to stub offset.
3974 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
3975 Branch_stub_ent_hash
> Branch_stub_entries
;
3976 Branch_stub_entries long_branch_stubs_
;
3977 // size of input section
3978 section_size_type orig_data_size_
;
3980 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
3981 // Whether .eh_frame info has been created for this stub section.
3982 bool eh_frame_added_
;
3983 // Set if this stub group needs a copy of out-of-line register
3984 // save/restore functions.
3985 bool need_save_res_
;
3988 // Add a plt call stub, if we do not already have one for this
3989 // sym/object/addend combo.
3991 template<int size
, bool big_endian
>
3993 Stub_table
<size
, big_endian
>::add_plt_call_entry(
3995 const Sized_relobj_file
<size
, big_endian
>* object
,
3997 unsigned int r_type
,
4000 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4001 unsigned int off
= this->plt_size_
;
4002 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4003 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4005 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4006 return this->can_reach_stub(from
, off
, r_type
);
4009 template<int size
, bool big_endian
>
4011 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4013 const Sized_relobj_file
<size
, big_endian
>* object
,
4014 unsigned int locsym_index
,
4015 unsigned int r_type
,
4018 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4019 unsigned int off
= this->plt_size_
;
4020 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4021 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4023 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4024 return this->can_reach_stub(from
, off
, r_type
);
4027 // Find a plt call stub.
4029 template<int size
, bool big_endian
>
4030 typename Stub_table
<size
, big_endian
>::Address
4031 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4032 const Sized_relobj_file
<size
, big_endian
>* object
,
4034 unsigned int r_type
,
4035 Address addend
) const
4037 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4038 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4039 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4042 template<int size
, bool big_endian
>
4043 typename Stub_table
<size
, big_endian
>::Address
4044 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
4046 Plt_stub_ent
ent(gsym
);
4047 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4048 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4051 template<int size
, bool big_endian
>
4052 typename Stub_table
<size
, big_endian
>::Address
4053 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4054 const Sized_relobj_file
<size
, big_endian
>* object
,
4055 unsigned int locsym_index
,
4056 unsigned int r_type
,
4057 Address addend
) const
4059 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4060 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4061 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4064 template<int size
, bool big_endian
>
4065 typename Stub_table
<size
, big_endian
>::Address
4066 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4067 const Sized_relobj_file
<size
, big_endian
>* object
,
4068 unsigned int locsym_index
) const
4070 Plt_stub_ent
ent(object
, locsym_index
);
4071 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4072 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4075 // Add a long branch stub if we don't already have one to given
4078 template<int size
, bool big_endian
>
4080 Stub_table
<size
, big_endian
>::add_long_branch_entry(
4081 const Powerpc_relobj
<size
, big_endian
>* object
,
4082 unsigned int r_type
,
4087 Branch_stub_ent
ent(object
, to
, save_res
);
4088 Address off
= this->branch_size_
;
4089 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
4092 this->need_save_res_
= true;
4095 unsigned int stub_size
= this->branch_stub_size(to
);
4096 this->branch_size_
= off
+ stub_size
;
4097 if (size
== 64 && stub_size
!= 4)
4098 this->targ_
->add_branch_lookup_table(to
);
4101 return this->can_reach_stub(from
, off
, r_type
);
4104 // Find long branch stub offset.
4106 template<int size
, bool big_endian
>
4107 typename Stub_table
<size
, big_endian
>::Address
4108 Stub_table
<size
, big_endian
>::find_long_branch_entry(
4109 const Powerpc_relobj
<size
, big_endian
>* object
,
4112 Branch_stub_ent
ent(object
, to
, false);
4113 typename
Branch_stub_entries::const_iterator p
4114 = this->long_branch_stubs_
.find(ent
);
4115 if (p
== this->long_branch_stubs_
.end())
4116 return invalid_address
;
4117 if (p
->first
.save_res_
)
4118 return to
- this->targ_
->savres_section()->address() + this->branch_size_
;
4122 // A class to handle .glink.
4124 template<int size
, bool big_endian
>
4125 class Output_data_glink
: public Output_section_data
4128 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4129 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4130 static const int pltresolve_size
= 16*4;
4132 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
4133 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
4134 end_branch_table_(), ge_size_(0)
4138 add_eh_frame(Layout
* layout
);
4141 add_global_entry(const Symbol
*);
4144 find_global_entry(const Symbol
*) const;
4147 global_entry_address() const
4149 gold_assert(this->is_data_size_valid());
4150 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4151 return this->address() + global_entry_off
;
4155 // Write to a map file.
4157 do_print_to_mapfile(Mapfile
* mapfile
) const
4158 { mapfile
->print_output_data(this, _("** glink")); }
4162 set_final_data_size();
4166 do_write(Output_file
*);
4168 // Allows access to .got and .plt for do_write.
4169 Target_powerpc
<size
, big_endian
>* targ_
;
4171 // Map sym to stub offset.
4172 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4173 Global_entry_stub_entries global_entry_stubs_
;
4175 unsigned int end_branch_table_
, ge_size_
;
4178 template<int size
, bool big_endian
>
4180 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4182 if (!parameters
->options().ld_generated_unwind_info())
4187 if (this->targ_
->abiversion() < 2)
4188 layout
->add_eh_frame_for_plt(this,
4189 Eh_cie
<64>::eh_frame_cie
,
4190 sizeof (Eh_cie
<64>::eh_frame_cie
),
4191 glink_eh_frame_fde_64v1
,
4192 sizeof (glink_eh_frame_fde_64v1
));
4194 layout
->add_eh_frame_for_plt(this,
4195 Eh_cie
<64>::eh_frame_cie
,
4196 sizeof (Eh_cie
<64>::eh_frame_cie
),
4197 glink_eh_frame_fde_64v2
,
4198 sizeof (glink_eh_frame_fde_64v2
));
4202 // 32-bit .glink can use the default since the CIE return
4203 // address reg, LR, is valid.
4204 layout
->add_eh_frame_for_plt(this,
4205 Eh_cie
<32>::eh_frame_cie
,
4206 sizeof (Eh_cie
<32>::eh_frame_cie
),
4208 sizeof (default_fde
));
4209 // Except where LR is used in a PIC __glink_PLTresolve.
4210 if (parameters
->options().output_is_position_independent())
4211 layout
->add_eh_frame_for_plt(this,
4212 Eh_cie
<32>::eh_frame_cie
,
4213 sizeof (Eh_cie
<32>::eh_frame_cie
),
4214 glink_eh_frame_fde_32
,
4215 sizeof (glink_eh_frame_fde_32
));
4219 template<int size
, bool big_endian
>
4221 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
4223 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
4224 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, this->ge_size_
));
4226 this->ge_size_
+= 16;
4229 template<int size
, bool big_endian
>
4230 typename Output_data_glink
<size
, big_endian
>::Address
4231 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
4233 typename
Global_entry_stub_entries::const_iterator p
4234 = this->global_entry_stubs_
.find(gsym
);
4235 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
4238 template<int size
, bool big_endian
>
4240 Output_data_glink
<size
, big_endian
>::set_final_data_size()
4242 unsigned int count
= this->targ_
->plt_entry_count();
4243 section_size_type total
= 0;
4249 // space for branch table
4250 total
+= 4 * (count
- 1);
4252 total
+= -total
& 15;
4253 total
+= this->pltresolve_size
;
4257 total
+= this->pltresolve_size
;
4259 // space for branch table
4261 if (this->targ_
->abiversion() < 2)
4265 total
+= 4 * (count
- 0x8000);
4269 this->end_branch_table_
= total
;
4270 total
= (total
+ 15) & -16;
4271 total
+= this->ge_size_
;
4273 this->set_data_size(total
);
4276 // Write out plt and long branch stub code.
4278 template<int size
, bool big_endian
>
4280 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
4282 if (this->plt_call_stubs_
.empty()
4283 && this->long_branch_stubs_
.empty())
4286 const section_size_type start_off
= this->offset();
4287 const section_size_type off
= this->stub_offset();
4288 const section_size_type oview_size
=
4289 convert_to_section_size_type(this->data_size() - (off
- start_off
));
4290 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4295 const Output_data_got_powerpc
<size
, big_endian
>* got
4296 = this->targ_
->got_section();
4297 Address got_os_addr
= got
->output_section()->address();
4299 if (!this->plt_call_stubs_
.empty())
4301 // The base address of the .plt section.
4302 Address plt_base
= this->targ_
->plt_section()->address();
4303 Address iplt_base
= invalid_address
;
4305 // Write out plt call stubs.
4306 typename
Plt_stub_entries::const_iterator cs
;
4307 for (cs
= this->plt_call_stubs_
.begin();
4308 cs
!= this->plt_call_stubs_
.end();
4312 Address pltoff
= this->plt_off(cs
, &is_iplt
);
4313 Address plt_addr
= pltoff
;
4316 if (iplt_base
== invalid_address
)
4317 iplt_base
= this->targ_
->iplt_section()->address();
4318 plt_addr
+= iplt_base
;
4321 plt_addr
+= plt_base
;
4322 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4323 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
4324 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
4325 Address off
= plt_addr
- got_addr
;
4327 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
4328 gold_error(_("%s: linkage table error against `%s'"),
4329 cs
->first
.object_
->name().c_str(),
4330 cs
->first
.sym_
->demangled_name().c_str());
4332 bool plt_load_toc
= this->targ_
->abiversion() < 2;
4334 = plt_load_toc
&& parameters
->options().plt_static_chain();
4336 = plt_load_toc
&& this->targ_
->plt_thread_safe();
4337 bool use_fake_dep
= false;
4338 Address cmp_branch_off
= 0;
4341 unsigned int pltindex
4342 = ((pltoff
- this->targ_
->first_plt_entry_offset())
4343 / this->targ_
->plt_entry_size());
4345 = (this->targ_
->glink_section()->pltresolve_size
4347 if (pltindex
> 32768)
4348 glinkoff
+= (pltindex
- 32768) * 4;
4350 = this->targ_
->glink_section()->address() + glinkoff
;
4352 = (this->stub_address() + cs
->second
+ 24
4353 + 4 * (ha(off
) != 0)
4354 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4355 + 4 * static_chain
);
4356 cmp_branch_off
= to
- from
;
4357 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
4360 p
= oview
+ cs
->second
;
4363 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4367 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
4369 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
4374 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
4376 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
4380 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4382 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
4386 write_insn
<big_endian
>(p
, mtctr_12
);
4392 write_insn
<big_endian
>(p
, xor_2_12_12
);
4394 write_insn
<big_endian
>(p
, add_11_11_2
);
4397 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
4401 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
4408 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4410 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
4413 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4415 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
4419 write_insn
<big_endian
>(p
, mtctr_12
);
4425 write_insn
<big_endian
>(p
, xor_11_12_12
);
4427 write_insn
<big_endian
>(p
, add_2_2_11
);
4432 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
4435 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
4439 if (thread_safe
&& !use_fake_dep
)
4441 write_insn
<big_endian
>(p
, cmpldi_2_0
);
4443 write_insn
<big_endian
>(p
, bnectr_p4
);
4445 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
4448 write_insn
<big_endian
>(p
, bctr
);
4452 // Write out long branch stubs.
4453 typename
Branch_stub_entries::const_iterator bs
;
4454 for (bs
= this->long_branch_stubs_
.begin();
4455 bs
!= this->long_branch_stubs_
.end();
4458 if (bs
->first
.save_res_
)
4460 p
= oview
+ this->plt_size_
+ bs
->second
;
4461 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4462 Address delta
= bs
->first
.dest_
- loc
;
4463 if (delta
+ (1 << 25) < 2 << 25)
4464 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4468 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
4469 gold_assert(brlt_addr
!= invalid_address
);
4470 brlt_addr
+= this->targ_
->brlt_section()->address();
4471 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
4472 Address brltoff
= brlt_addr
- got_addr
;
4473 if (ha(brltoff
) == 0)
4475 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
4479 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
4480 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
4482 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4483 write_insn
<big_endian
>(p
, bctr
);
4489 if (!this->plt_call_stubs_
.empty())
4491 // The base address of the .plt section.
4492 Address plt_base
= this->targ_
->plt_section()->address();
4493 Address iplt_base
= invalid_address
;
4494 // The address of _GLOBAL_OFFSET_TABLE_.
4495 Address g_o_t
= invalid_address
;
4497 // Write out plt call stubs.
4498 typename
Plt_stub_entries::const_iterator cs
;
4499 for (cs
= this->plt_call_stubs_
.begin();
4500 cs
!= this->plt_call_stubs_
.end();
4504 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
4507 if (iplt_base
== invalid_address
)
4508 iplt_base
= this->targ_
->iplt_section()->address();
4509 plt_addr
+= iplt_base
;
4512 plt_addr
+= plt_base
;
4514 p
= oview
+ cs
->second
;
4515 if (parameters
->options().output_is_position_independent())
4518 const Powerpc_relobj
<size
, big_endian
>* ppcobj
4519 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
4520 (cs
->first
.object_
));
4521 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
4523 unsigned int got2
= ppcobj
->got2_shndx();
4524 got_addr
= ppcobj
->get_output_section_offset(got2
);
4525 gold_assert(got_addr
!= invalid_address
);
4526 got_addr
+= (ppcobj
->output_section(got2
)->address()
4527 + cs
->first
.addend_
);
4531 if (g_o_t
== invalid_address
)
4533 const Output_data_got_powerpc
<size
, big_endian
>* got
4534 = this->targ_
->got_section();
4535 g_o_t
= got
->address() + got
->g_o_t();
4540 Address off
= plt_addr
- got_addr
;
4543 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
4544 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
4545 write_insn
<big_endian
>(p
+ 8, bctr
);
4549 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
4550 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
4551 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4552 write_insn
<big_endian
>(p
+ 12, bctr
);
4557 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
4558 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
4559 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4560 write_insn
<big_endian
>(p
+ 12, bctr
);
4565 // Write out long branch stubs.
4566 typename
Branch_stub_entries::const_iterator bs
;
4567 for (bs
= this->long_branch_stubs_
.begin();
4568 bs
!= this->long_branch_stubs_
.end();
4571 if (bs
->first
.save_res_
)
4573 p
= oview
+ this->plt_size_
+ bs
->second
;
4574 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4575 Address delta
= bs
->first
.dest_
- loc
;
4576 if (delta
+ (1 << 25) < 2 << 25)
4577 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4578 else if (!parameters
->options().output_is_position_independent())
4580 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
4581 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
4582 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
4583 write_insn
<big_endian
>(p
+ 12, bctr
);
4588 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4589 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4590 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4591 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4592 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4593 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4594 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4595 write_insn
<big_endian
>(p
+ 28, bctr
);
4599 if (this->need_save_res_
)
4601 p
= oview
+ this->plt_size_
+ this->branch_size_
;
4602 memcpy (p
, this->targ_
->savres_section()->contents(),
4603 this->targ_
->savres_section()->data_size());
4607 // Write out .glink.
4609 template<int size
, bool big_endian
>
4611 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4613 const section_size_type off
= this->offset();
4614 const section_size_type oview_size
=
4615 convert_to_section_size_type(this->data_size());
4616 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4619 // The base address of the .plt section.
4620 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4621 Address plt_base
= this->targ_
->plt_section()->address();
4625 if (this->end_branch_table_
!= 0)
4627 // Write pltresolve stub.
4629 Address after_bcl
= this->address() + 16;
4630 Address pltoff
= plt_base
- after_bcl
;
4632 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4634 if (this->targ_
->abiversion() < 2)
4636 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4637 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4638 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4639 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4640 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4641 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4642 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4643 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
4644 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4645 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
4649 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
4650 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4651 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4652 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4653 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
4654 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
4655 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4656 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
4657 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4658 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
4659 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4660 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
4662 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4663 while (p
< oview
+ this->pltresolve_size
)
4664 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4666 // Write lazy link call stubs.
4668 while (p
< oview
+ this->end_branch_table_
)
4670 if (this->targ_
->abiversion() < 2)
4674 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4678 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
4679 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4682 uint32_t branch_off
= 8 - (p
- oview
);
4683 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4688 Address plt_base
= this->targ_
->plt_section()->address();
4689 Address iplt_base
= invalid_address
;
4690 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4691 Address global_entry_base
= this->address() + global_entry_off
;
4692 typename
Global_entry_stub_entries::const_iterator ge
;
4693 for (ge
= this->global_entry_stubs_
.begin();
4694 ge
!= this->global_entry_stubs_
.end();
4697 p
= oview
+ global_entry_off
+ ge
->second
;
4698 Address plt_addr
= ge
->first
->plt_offset();
4699 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
4700 && ge
->first
->can_use_relative_reloc(false))
4702 if (iplt_base
== invalid_address
)
4703 iplt_base
= this->targ_
->iplt_section()->address();
4704 plt_addr
+= iplt_base
;
4707 plt_addr
+= plt_base
;
4708 Address my_addr
= global_entry_base
+ ge
->second
;
4709 Address off
= plt_addr
- my_addr
;
4711 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
4712 gold_error(_("%s: linkage table error against `%s'"),
4713 ge
->first
->object()->name().c_str(),
4714 ge
->first
->demangled_name().c_str());
4716 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
4717 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
4718 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4719 write_insn
<big_endian
>(p
, bctr
);
4724 const Output_data_got_powerpc
<size
, big_endian
>* got
4725 = this->targ_
->got_section();
4726 // The address of _GLOBAL_OFFSET_TABLE_.
4727 Address g_o_t
= got
->address() + got
->g_o_t();
4729 // Write out pltresolve branch table.
4731 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4732 unsigned char* end_p
= oview
+ the_end
;
4733 while (p
< end_p
- 8 * 4)
4734 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4736 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4738 // Write out pltresolve call stub.
4739 if (parameters
->options().output_is_position_independent())
4741 Address res0_off
= 0;
4742 Address after_bcl_off
= the_end
+ 12;
4743 Address bcl_res0
= after_bcl_off
- res0_off
;
4745 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4746 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4747 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4748 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4749 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4750 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4751 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4753 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4755 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4756 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4758 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4759 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4763 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4764 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4766 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4767 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4768 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4769 write_insn
<big_endian
>(p
+ 52, bctr
);
4770 write_insn
<big_endian
>(p
+ 56, nop
);
4771 write_insn
<big_endian
>(p
+ 60, nop
);
4775 Address res0
= this->address();
4777 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4778 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4779 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4780 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4782 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4783 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4784 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4785 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4786 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4787 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4789 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4790 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4791 write_insn
<big_endian
>(p
+ 32, bctr
);
4792 write_insn
<big_endian
>(p
+ 36, nop
);
4793 write_insn
<big_endian
>(p
+ 40, nop
);
4794 write_insn
<big_endian
>(p
+ 44, nop
);
4795 write_insn
<big_endian
>(p
+ 48, nop
);
4796 write_insn
<big_endian
>(p
+ 52, nop
);
4797 write_insn
<big_endian
>(p
+ 56, nop
);
4798 write_insn
<big_endian
>(p
+ 60, nop
);
4803 of
->write_output_view(off
, oview_size
, oview
);
4807 // A class to handle linker generated save/restore functions.
4809 template<int size
, bool big_endian
>
4810 class Output_data_save_res
: public Output_section_data_build
4813 Output_data_save_res(Symbol_table
* symtab
);
4815 const unsigned char*
4822 // Write to a map file.
4824 do_print_to_mapfile(Mapfile
* mapfile
) const
4825 { mapfile
->print_output_data(this, _("** save/restore")); }
4828 do_write(Output_file
*);
4831 // The maximum size of save/restore contents.
4832 static const unsigned int savres_max
= 218*4;
4835 savres_define(Symbol_table
* symtab
,
4837 unsigned int lo
, unsigned int hi
,
4838 unsigned char* write_ent(unsigned char*, int),
4839 unsigned char* write_tail(unsigned char*, int));
4841 unsigned char *contents_
;
4844 template<bool big_endian
>
4845 static unsigned char*
4846 savegpr0(unsigned char* p
, int r
)
4848 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4849 write_insn
<big_endian
>(p
, insn
);
4853 template<bool big_endian
>
4854 static unsigned char*
4855 savegpr0_tail(unsigned char* p
, int r
)
4857 p
= savegpr0
<big_endian
>(p
, r
);
4858 uint32_t insn
= std_0_1
+ 16;
4859 write_insn
<big_endian
>(p
, insn
);
4861 write_insn
<big_endian
>(p
, blr
);
4865 template<bool big_endian
>
4866 static unsigned char*
4867 restgpr0(unsigned char* p
, int r
)
4869 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4870 write_insn
<big_endian
>(p
, insn
);
4874 template<bool big_endian
>
4875 static unsigned char*
4876 restgpr0_tail(unsigned char* p
, int r
)
4878 uint32_t insn
= ld_0_1
+ 16;
4879 write_insn
<big_endian
>(p
, insn
);
4881 p
= restgpr0
<big_endian
>(p
, r
);
4882 write_insn
<big_endian
>(p
, mtlr_0
);
4886 p
= restgpr0
<big_endian
>(p
, 30);
4887 p
= restgpr0
<big_endian
>(p
, 31);
4889 write_insn
<big_endian
>(p
, blr
);
4893 template<bool big_endian
>
4894 static unsigned char*
4895 savegpr1(unsigned char* p
, int r
)
4897 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4898 write_insn
<big_endian
>(p
, insn
);
4902 template<bool big_endian
>
4903 static unsigned char*
4904 savegpr1_tail(unsigned char* p
, int r
)
4906 p
= savegpr1
<big_endian
>(p
, r
);
4907 write_insn
<big_endian
>(p
, blr
);
4911 template<bool big_endian
>
4912 static unsigned char*
4913 restgpr1(unsigned char* p
, int r
)
4915 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4916 write_insn
<big_endian
>(p
, insn
);
4920 template<bool big_endian
>
4921 static unsigned char*
4922 restgpr1_tail(unsigned char* p
, int r
)
4924 p
= restgpr1
<big_endian
>(p
, r
);
4925 write_insn
<big_endian
>(p
, blr
);
4929 template<bool big_endian
>
4930 static unsigned char*
4931 savefpr(unsigned char* p
, int r
)
4933 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4934 write_insn
<big_endian
>(p
, insn
);
4938 template<bool big_endian
>
4939 static unsigned char*
4940 savefpr0_tail(unsigned char* p
, int r
)
4942 p
= savefpr
<big_endian
>(p
, r
);
4943 write_insn
<big_endian
>(p
, std_0_1
+ 16);
4945 write_insn
<big_endian
>(p
, blr
);
4949 template<bool big_endian
>
4950 static unsigned char*
4951 restfpr(unsigned char* p
, int r
)
4953 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4954 write_insn
<big_endian
>(p
, insn
);
4958 template<bool big_endian
>
4959 static unsigned char*
4960 restfpr0_tail(unsigned char* p
, int r
)
4962 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
4964 p
= restfpr
<big_endian
>(p
, r
);
4965 write_insn
<big_endian
>(p
, mtlr_0
);
4969 p
= restfpr
<big_endian
>(p
, 30);
4970 p
= restfpr
<big_endian
>(p
, 31);
4972 write_insn
<big_endian
>(p
, blr
);
4976 template<bool big_endian
>
4977 static unsigned char*
4978 savefpr1_tail(unsigned char* p
, int r
)
4980 p
= savefpr
<big_endian
>(p
, r
);
4981 write_insn
<big_endian
>(p
, blr
);
4985 template<bool big_endian
>
4986 static unsigned char*
4987 restfpr1_tail(unsigned char* p
, int r
)
4989 p
= restfpr
<big_endian
>(p
, r
);
4990 write_insn
<big_endian
>(p
, blr
);
4994 template<bool big_endian
>
4995 static unsigned char*
4996 savevr(unsigned char* p
, int r
)
4998 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
4999 write_insn
<big_endian
>(p
, insn
);
5001 insn
= stvx_0_12_0
+ (r
<< 21);
5002 write_insn
<big_endian
>(p
, insn
);
5006 template<bool big_endian
>
5007 static unsigned char*
5008 savevr_tail(unsigned char* p
, int r
)
5010 p
= savevr
<big_endian
>(p
, r
);
5011 write_insn
<big_endian
>(p
, blr
);
5015 template<bool big_endian
>
5016 static unsigned char*
5017 restvr(unsigned char* p
, int r
)
5019 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5020 write_insn
<big_endian
>(p
, insn
);
5022 insn
= lvx_0_12_0
+ (r
<< 21);
5023 write_insn
<big_endian
>(p
, insn
);
5027 template<bool big_endian
>
5028 static unsigned char*
5029 restvr_tail(unsigned char* p
, int r
)
5031 p
= restvr
<big_endian
>(p
, r
);
5032 write_insn
<big_endian
>(p
, blr
);
5037 template<int size
, bool big_endian
>
5038 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
5039 Symbol_table
* symtab
)
5040 : Output_section_data_build(4),
5043 this->savres_define(symtab
,
5044 "_savegpr0_", 14, 31,
5045 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
5046 this->savres_define(symtab
,
5047 "_restgpr0_", 14, 29,
5048 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5049 this->savres_define(symtab
,
5050 "_restgpr0_", 30, 31,
5051 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5052 this->savres_define(symtab
,
5053 "_savegpr1_", 14, 31,
5054 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
5055 this->savres_define(symtab
,
5056 "_restgpr1_", 14, 31,
5057 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
5058 this->savres_define(symtab
,
5059 "_savefpr_", 14, 31,
5060 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
5061 this->savres_define(symtab
,
5062 "_restfpr_", 14, 29,
5063 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5064 this->savres_define(symtab
,
5065 "_restfpr_", 30, 31,
5066 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5067 this->savres_define(symtab
,
5069 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
5070 this->savres_define(symtab
,
5072 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
5073 this->savres_define(symtab
,
5075 savevr
<big_endian
>, savevr_tail
<big_endian
>);
5076 this->savres_define(symtab
,
5078 restvr
<big_endian
>, restvr_tail
<big_endian
>);
5081 template<int size
, bool big_endian
>
5083 Output_data_save_res
<size
, big_endian
>::savres_define(
5084 Symbol_table
* symtab
,
5086 unsigned int lo
, unsigned int hi
,
5087 unsigned char* write_ent(unsigned char*, int),
5088 unsigned char* write_tail(unsigned char*, int))
5090 size_t len
= strlen(name
);
5091 bool writing
= false;
5094 memcpy(sym
, name
, len
);
5097 for (unsigned int i
= lo
; i
<= hi
; i
++)
5099 sym
[len
+ 0] = i
/ 10 + '0';
5100 sym
[len
+ 1] = i
% 10 + '0';
5101 Symbol
* gsym
= symtab
->lookup(sym
);
5102 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
5103 writing
= writing
|| refd
;
5106 if (this->contents_
== NULL
)
5107 this->contents_
= new unsigned char[this->savres_max
];
5109 section_size_type value
= this->current_data_size();
5110 unsigned char* p
= this->contents_
+ value
;
5112 p
= write_ent(p
, i
);
5114 p
= write_tail(p
, i
);
5115 section_size_type cur_size
= p
- this->contents_
;
5116 this->set_current_data_size(cur_size
);
5118 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
5119 this, value
, cur_size
- value
,
5120 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
5121 elfcpp::STV_HIDDEN
, 0, false, false);
5126 // Write out save/restore.
5128 template<int size
, bool big_endian
>
5130 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
5132 const section_size_type off
= this->offset();
5133 const section_size_type oview_size
=
5134 convert_to_section_size_type(this->data_size());
5135 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5136 memcpy(oview
, this->contents_
, oview_size
);
5137 of
->write_output_view(off
, oview_size
, oview
);
5141 // Create the glink section.
5143 template<int size
, bool big_endian
>
5145 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
5147 if (this->glink_
== NULL
)
5149 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
5150 this->glink_
->add_eh_frame(layout
);
5151 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5152 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5153 this->glink_
, ORDER_TEXT
, false);
5157 // Create a PLT entry for a global symbol.
5159 template<int size
, bool big_endian
>
5161 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
5165 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5166 && gsym
->can_use_relative_reloc(false))
5168 if (this->iplt_
== NULL
)
5169 this->make_iplt_section(symtab
, layout
);
5170 this->iplt_
->add_ifunc_entry(gsym
);
5174 if (this->plt_
== NULL
)
5175 this->make_plt_section(symtab
, layout
);
5176 this->plt_
->add_entry(gsym
);
5180 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
5182 template<int size
, bool big_endian
>
5184 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
5185 Symbol_table
* symtab
,
5187 Sized_relobj_file
<size
, big_endian
>* relobj
,
5190 if (this->iplt_
== NULL
)
5191 this->make_iplt_section(symtab
, layout
);
5192 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
5195 // Return the number of entries in the PLT.
5197 template<int size
, bool big_endian
>
5199 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
5201 if (this->plt_
== NULL
)
5203 return this->plt_
->entry_count();
5206 // Create a GOT entry for local dynamic __tls_get_addr calls.
5208 template<int size
, bool big_endian
>
5210 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
5211 Symbol_table
* symtab
,
5213 Sized_relobj_file
<size
, big_endian
>* object
)
5215 if (this->tlsld_got_offset_
== -1U)
5217 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
5218 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
5219 Output_data_got_powerpc
<size
, big_endian
>* got
5220 = this->got_section(symtab
, layout
);
5221 unsigned int got_offset
= got
->add_constant_pair(0, 0);
5222 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
5224 this->tlsld_got_offset_
= got_offset
;
5226 return this->tlsld_got_offset_
;
5229 // Get the Reference_flags for a particular relocation.
5231 template<int size
, bool big_endian
>
5233 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
5234 unsigned int r_type
,
5235 const Target_powerpc
* target
)
5241 case elfcpp::R_POWERPC_NONE
:
5242 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5243 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5244 case elfcpp::R_PPC64_TOC
:
5245 // No symbol reference.
5248 case elfcpp::R_PPC64_ADDR64
:
5249 case elfcpp::R_PPC64_UADDR64
:
5250 case elfcpp::R_POWERPC_ADDR32
:
5251 case elfcpp::R_POWERPC_UADDR32
:
5252 case elfcpp::R_POWERPC_ADDR16
:
5253 case elfcpp::R_POWERPC_UADDR16
:
5254 case elfcpp::R_POWERPC_ADDR16_LO
:
5255 case elfcpp::R_POWERPC_ADDR16_HI
:
5256 case elfcpp::R_POWERPC_ADDR16_HA
:
5257 ref
= Symbol::ABSOLUTE_REF
;
5260 case elfcpp::R_POWERPC_ADDR24
:
5261 case elfcpp::R_POWERPC_ADDR14
:
5262 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5263 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5264 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
5267 case elfcpp::R_PPC64_REL64
:
5268 case elfcpp::R_POWERPC_REL32
:
5269 case elfcpp::R_PPC_LOCAL24PC
:
5270 case elfcpp::R_POWERPC_REL16
:
5271 case elfcpp::R_POWERPC_REL16_LO
:
5272 case elfcpp::R_POWERPC_REL16_HI
:
5273 case elfcpp::R_POWERPC_REL16_HA
:
5274 ref
= Symbol::RELATIVE_REF
;
5277 case elfcpp::R_POWERPC_REL24
:
5278 case elfcpp::R_PPC_PLTREL24
:
5279 case elfcpp::R_POWERPC_REL14
:
5280 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5281 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5282 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
5285 case elfcpp::R_POWERPC_GOT16
:
5286 case elfcpp::R_POWERPC_GOT16_LO
:
5287 case elfcpp::R_POWERPC_GOT16_HI
:
5288 case elfcpp::R_POWERPC_GOT16_HA
:
5289 case elfcpp::R_PPC64_GOT16_DS
:
5290 case elfcpp::R_PPC64_GOT16_LO_DS
:
5291 case elfcpp::R_PPC64_TOC16
:
5292 case elfcpp::R_PPC64_TOC16_LO
:
5293 case elfcpp::R_PPC64_TOC16_HI
:
5294 case elfcpp::R_PPC64_TOC16_HA
:
5295 case elfcpp::R_PPC64_TOC16_DS
:
5296 case elfcpp::R_PPC64_TOC16_LO_DS
:
5298 ref
= Symbol::ABSOLUTE_REF
;
5301 case elfcpp::R_POWERPC_GOT_TPREL16
:
5302 case elfcpp::R_POWERPC_TLS
:
5303 ref
= Symbol::TLS_REF
;
5306 case elfcpp::R_POWERPC_COPY
:
5307 case elfcpp::R_POWERPC_GLOB_DAT
:
5308 case elfcpp::R_POWERPC_JMP_SLOT
:
5309 case elfcpp::R_POWERPC_RELATIVE
:
5310 case elfcpp::R_POWERPC_DTPMOD
:
5312 // Not expected. We will give an error later.
5316 if (size
== 64 && target
->abiversion() < 2)
5317 ref
|= Symbol::FUNC_DESC_ABI
;
5321 // Report an unsupported relocation against a local symbol.
5323 template<int size
, bool big_endian
>
5325 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
5326 Sized_relobj_file
<size
, big_endian
>* object
,
5327 unsigned int r_type
)
5329 gold_error(_("%s: unsupported reloc %u against local symbol"),
5330 object
->name().c_str(), r_type
);
5333 // We are about to emit a dynamic relocation of type R_TYPE. If the
5334 // dynamic linker does not support it, issue an error.
5336 template<int size
, bool big_endian
>
5338 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
5339 unsigned int r_type
)
5341 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
5343 // These are the relocation types supported by glibc for both 32-bit
5344 // and 64-bit powerpc.
5347 case elfcpp::R_POWERPC_NONE
:
5348 case elfcpp::R_POWERPC_RELATIVE
:
5349 case elfcpp::R_POWERPC_GLOB_DAT
:
5350 case elfcpp::R_POWERPC_DTPMOD
:
5351 case elfcpp::R_POWERPC_DTPREL
:
5352 case elfcpp::R_POWERPC_TPREL
:
5353 case elfcpp::R_POWERPC_JMP_SLOT
:
5354 case elfcpp::R_POWERPC_COPY
:
5355 case elfcpp::R_POWERPC_IRELATIVE
:
5356 case elfcpp::R_POWERPC_ADDR32
:
5357 case elfcpp::R_POWERPC_UADDR32
:
5358 case elfcpp::R_POWERPC_ADDR24
:
5359 case elfcpp::R_POWERPC_ADDR16
:
5360 case elfcpp::R_POWERPC_UADDR16
:
5361 case elfcpp::R_POWERPC_ADDR16_LO
:
5362 case elfcpp::R_POWERPC_ADDR16_HI
:
5363 case elfcpp::R_POWERPC_ADDR16_HA
:
5364 case elfcpp::R_POWERPC_ADDR14
:
5365 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5366 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5367 case elfcpp::R_POWERPC_REL32
:
5368 case elfcpp::R_POWERPC_REL24
:
5369 case elfcpp::R_POWERPC_TPREL16
:
5370 case elfcpp::R_POWERPC_TPREL16_LO
:
5371 case elfcpp::R_POWERPC_TPREL16_HI
:
5372 case elfcpp::R_POWERPC_TPREL16_HA
:
5383 // These are the relocation types supported only on 64-bit.
5384 case elfcpp::R_PPC64_ADDR64
:
5385 case elfcpp::R_PPC64_UADDR64
:
5386 case elfcpp::R_PPC64_JMP_IREL
:
5387 case elfcpp::R_PPC64_ADDR16_DS
:
5388 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5389 case elfcpp::R_PPC64_ADDR16_HIGH
:
5390 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5391 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5392 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5393 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5394 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5395 case elfcpp::R_PPC64_REL64
:
5396 case elfcpp::R_POWERPC_ADDR30
:
5397 case elfcpp::R_PPC64_TPREL16_DS
:
5398 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5399 case elfcpp::R_PPC64_TPREL16_HIGH
:
5400 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5401 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5402 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5403 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5404 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5415 // These are the relocation types supported only on 32-bit.
5416 // ??? glibc ld.so doesn't need to support these.
5417 case elfcpp::R_POWERPC_DTPREL16
:
5418 case elfcpp::R_POWERPC_DTPREL16_LO
:
5419 case elfcpp::R_POWERPC_DTPREL16_HI
:
5420 case elfcpp::R_POWERPC_DTPREL16_HA
:
5428 // This prevents us from issuing more than one error per reloc
5429 // section. But we can still wind up issuing more than one
5430 // error per object file.
5431 if (this->issued_non_pic_error_
)
5433 gold_assert(parameters
->options().output_is_position_independent());
5434 object
->error(_("requires unsupported dynamic reloc; "
5435 "recompile with -fPIC"));
5436 this->issued_non_pic_error_
= true;
5440 // Return whether we need to make a PLT entry for a relocation of the
5441 // given type against a STT_GNU_IFUNC symbol.
5443 template<int size
, bool big_endian
>
5445 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
5446 Target_powerpc
<size
, big_endian
>* target
,
5447 Sized_relobj_file
<size
, big_endian
>* object
,
5448 unsigned int r_type
,
5451 // In non-pic code any reference will resolve to the plt call stub
5452 // for the ifunc symbol.
5453 if ((size
== 32 || target
->abiversion() >= 2)
5454 && !parameters
->options().output_is_position_independent())
5459 // Word size refs from data sections are OK, but don't need a PLT entry.
5460 case elfcpp::R_POWERPC_ADDR32
:
5461 case elfcpp::R_POWERPC_UADDR32
:
5466 case elfcpp::R_PPC64_ADDR64
:
5467 case elfcpp::R_PPC64_UADDR64
:
5472 // GOT refs are good, but also don't need a PLT entry.
5473 case elfcpp::R_POWERPC_GOT16
:
5474 case elfcpp::R_POWERPC_GOT16_LO
:
5475 case elfcpp::R_POWERPC_GOT16_HI
:
5476 case elfcpp::R_POWERPC_GOT16_HA
:
5477 case elfcpp::R_PPC64_GOT16_DS
:
5478 case elfcpp::R_PPC64_GOT16_LO_DS
:
5481 // Function calls are good, and these do need a PLT entry.
5482 case elfcpp::R_POWERPC_ADDR24
:
5483 case elfcpp::R_POWERPC_ADDR14
:
5484 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5485 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5486 case elfcpp::R_POWERPC_REL24
:
5487 case elfcpp::R_PPC_PLTREL24
:
5488 case elfcpp::R_POWERPC_REL14
:
5489 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5490 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5497 // Anything else is a problem.
5498 // If we are building a static executable, the libc startup function
5499 // responsible for applying indirect function relocations is going
5500 // to complain about the reloc type.
5501 // If we are building a dynamic executable, we will have a text
5502 // relocation. The dynamic loader will set the text segment
5503 // writable and non-executable to apply text relocations. So we'll
5504 // segfault when trying to run the indirection function to resolve
5507 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5508 object
->name().c_str(), r_type
);
5512 // Scan a relocation for a local symbol.
5514 template<int size
, bool big_endian
>
5516 Target_powerpc
<size
, big_endian
>::Scan::local(
5517 Symbol_table
* symtab
,
5519 Target_powerpc
<size
, big_endian
>* target
,
5520 Sized_relobj_file
<size
, big_endian
>* object
,
5521 unsigned int data_shndx
,
5522 Output_section
* output_section
,
5523 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5524 unsigned int r_type
,
5525 const elfcpp::Sym
<size
, big_endian
>& lsym
,
5528 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
5530 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5531 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5533 this->expect_tls_get_addr_call();
5534 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5535 if (tls_type
!= tls::TLSOPT_NONE
)
5536 this->skip_next_tls_get_addr_call();
5538 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5539 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5541 this->expect_tls_get_addr_call();
5542 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5543 if (tls_type
!= tls::TLSOPT_NONE
)
5544 this->skip_next_tls_get_addr_call();
5547 Powerpc_relobj
<size
, big_endian
>* ppc_object
5548 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5553 && data_shndx
== ppc_object
->opd_shndx()
5554 && r_type
== elfcpp::R_PPC64_ADDR64
)
5555 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5559 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5560 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
5561 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5563 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5564 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5565 r_type
, r_sym
, reloc
.get_r_addend());
5566 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
5571 case elfcpp::R_POWERPC_NONE
:
5572 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5573 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5574 case elfcpp::R_PPC64_TOCSAVE
:
5575 case elfcpp::R_POWERPC_TLS
:
5578 case elfcpp::R_PPC64_TOC
:
5580 Output_data_got_powerpc
<size
, big_endian
>* got
5581 = target
->got_section(symtab
, layout
);
5582 if (parameters
->options().output_is_position_independent())
5584 Address off
= reloc
.get_r_offset();
5586 && target
->abiversion() < 2
5587 && data_shndx
== ppc_object
->opd_shndx()
5588 && ppc_object
->get_opd_discard(off
- 8))
5591 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5592 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5593 rela_dyn
->add_output_section_relative(got
->output_section(),
5594 elfcpp::R_POWERPC_RELATIVE
,
5596 object
, data_shndx
, off
,
5597 symobj
->toc_base_offset());
5602 case elfcpp::R_PPC64_ADDR64
:
5603 case elfcpp::R_PPC64_UADDR64
:
5604 case elfcpp::R_POWERPC_ADDR32
:
5605 case elfcpp::R_POWERPC_UADDR32
:
5606 case elfcpp::R_POWERPC_ADDR24
:
5607 case elfcpp::R_POWERPC_ADDR16
:
5608 case elfcpp::R_POWERPC_ADDR16_LO
:
5609 case elfcpp::R_POWERPC_ADDR16_HI
:
5610 case elfcpp::R_POWERPC_ADDR16_HA
:
5611 case elfcpp::R_POWERPC_UADDR16
:
5612 case elfcpp::R_PPC64_ADDR16_HIGH
:
5613 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5614 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5615 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5616 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5617 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5618 case elfcpp::R_PPC64_ADDR16_DS
:
5619 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5620 case elfcpp::R_POWERPC_ADDR14
:
5621 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5622 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5623 // If building a shared library (or a position-independent
5624 // executable), we need to create a dynamic relocation for
5626 if (parameters
->options().output_is_position_independent()
5627 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5629 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5631 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5632 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5633 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
5635 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5636 : elfcpp::R_POWERPC_RELATIVE
);
5637 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5638 output_section
, data_shndx
,
5639 reloc
.get_r_offset(),
5640 reloc
.get_r_addend(), false);
5642 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
5644 check_non_pic(object
, r_type
);
5645 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
5646 data_shndx
, reloc
.get_r_offset(),
5647 reloc
.get_r_addend());
5651 gold_assert(lsym
.get_st_value() == 0);
5652 unsigned int shndx
= lsym
.get_st_shndx();
5654 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
5657 object
->error(_("section symbol %u has bad shndx %u"),
5660 rela_dyn
->add_local_section(object
, shndx
, r_type
,
5661 output_section
, data_shndx
,
5662 reloc
.get_r_offset());
5667 case elfcpp::R_POWERPC_REL24
:
5668 case elfcpp::R_PPC_PLTREL24
:
5669 case elfcpp::R_PPC_LOCAL24PC
:
5670 case elfcpp::R_POWERPC_REL14
:
5671 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5672 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5674 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5675 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5676 reloc
.get_r_addend());
5679 case elfcpp::R_PPC64_REL64
:
5680 case elfcpp::R_POWERPC_REL32
:
5681 case elfcpp::R_POWERPC_REL16
:
5682 case elfcpp::R_POWERPC_REL16_LO
:
5683 case elfcpp::R_POWERPC_REL16_HI
:
5684 case elfcpp::R_POWERPC_REL16_HA
:
5685 case elfcpp::R_POWERPC_SECTOFF
:
5686 case elfcpp::R_POWERPC_SECTOFF_LO
:
5687 case elfcpp::R_POWERPC_SECTOFF_HI
:
5688 case elfcpp::R_POWERPC_SECTOFF_HA
:
5689 case elfcpp::R_PPC64_SECTOFF_DS
:
5690 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5691 case elfcpp::R_POWERPC_TPREL16
:
5692 case elfcpp::R_POWERPC_TPREL16_LO
:
5693 case elfcpp::R_POWERPC_TPREL16_HI
:
5694 case elfcpp::R_POWERPC_TPREL16_HA
:
5695 case elfcpp::R_PPC64_TPREL16_DS
:
5696 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5697 case elfcpp::R_PPC64_TPREL16_HIGH
:
5698 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5699 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5700 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5701 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5702 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5703 case elfcpp::R_POWERPC_DTPREL16
:
5704 case elfcpp::R_POWERPC_DTPREL16_LO
:
5705 case elfcpp::R_POWERPC_DTPREL16_HI
:
5706 case elfcpp::R_POWERPC_DTPREL16_HA
:
5707 case elfcpp::R_PPC64_DTPREL16_DS
:
5708 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5709 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5710 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5711 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5712 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5713 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5714 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5715 case elfcpp::R_PPC64_TLSGD
:
5716 case elfcpp::R_PPC64_TLSLD
:
5717 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5720 case elfcpp::R_POWERPC_GOT16
:
5721 case elfcpp::R_POWERPC_GOT16_LO
:
5722 case elfcpp::R_POWERPC_GOT16_HI
:
5723 case elfcpp::R_POWERPC_GOT16_HA
:
5724 case elfcpp::R_PPC64_GOT16_DS
:
5725 case elfcpp::R_PPC64_GOT16_LO_DS
:
5727 // The symbol requires a GOT entry.
5728 Output_data_got_powerpc
<size
, big_endian
>* got
5729 = target
->got_section(symtab
, layout
);
5730 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5732 if (!parameters
->options().output_is_position_independent())
5735 && (size
== 32 || target
->abiversion() >= 2))
5736 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5738 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5740 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5742 // If we are generating a shared object or a pie, this
5743 // symbol's GOT entry will be set by a dynamic relocation.
5745 off
= got
->add_constant(0);
5746 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5748 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5750 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5751 : elfcpp::R_POWERPC_RELATIVE
);
5752 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5753 got
, off
, 0, false);
5758 case elfcpp::R_PPC64_TOC16
:
5759 case elfcpp::R_PPC64_TOC16_LO
:
5760 case elfcpp::R_PPC64_TOC16_HI
:
5761 case elfcpp::R_PPC64_TOC16_HA
:
5762 case elfcpp::R_PPC64_TOC16_DS
:
5763 case elfcpp::R_PPC64_TOC16_LO_DS
:
5764 // We need a GOT section.
5765 target
->got_section(symtab
, layout
);
5768 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5769 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5770 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5771 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5773 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5774 if (tls_type
== tls::TLSOPT_NONE
)
5776 Output_data_got_powerpc
<size
, big_endian
>* got
5777 = target
->got_section(symtab
, layout
);
5778 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5779 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5780 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5781 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5783 else if (tls_type
== tls::TLSOPT_TO_LE
)
5785 // no GOT relocs needed for Local Exec.
5792 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5793 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5794 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5795 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5797 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5798 if (tls_type
== tls::TLSOPT_NONE
)
5799 target
->tlsld_got_offset(symtab
, layout
, object
);
5800 else if (tls_type
== tls::TLSOPT_TO_LE
)
5802 // no GOT relocs needed for Local Exec.
5803 if (parameters
->options().emit_relocs())
5805 Output_section
* os
= layout
->tls_segment()->first_section();
5806 gold_assert(os
!= NULL
);
5807 os
->set_needs_symtab_index();
5815 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5816 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5817 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5818 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5820 Output_data_got_powerpc
<size
, big_endian
>* got
5821 = target
->got_section(symtab
, layout
);
5822 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5823 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5827 case elfcpp::R_POWERPC_GOT_TPREL16
:
5828 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5829 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5830 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5832 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5833 if (tls_type
== tls::TLSOPT_NONE
)
5835 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5836 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5838 Output_data_got_powerpc
<size
, big_endian
>* got
5839 = target
->got_section(symtab
, layout
);
5840 unsigned int off
= got
->add_constant(0);
5841 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5843 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5844 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5845 elfcpp::R_POWERPC_TPREL
,
5849 else if (tls_type
== tls::TLSOPT_TO_LE
)
5851 // no GOT relocs needed for Local Exec.
5859 unsupported_reloc_local(object
, r_type
);
5865 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5866 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5867 case elfcpp::R_POWERPC_GOT_TPREL16
:
5868 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5869 case elfcpp::R_POWERPC_GOT16
:
5870 case elfcpp::R_PPC64_GOT16_DS
:
5871 case elfcpp::R_PPC64_TOC16
:
5872 case elfcpp::R_PPC64_TOC16_DS
:
5873 ppc_object
->set_has_small_toc_reloc();
5879 // Report an unsupported relocation against a global symbol.
5881 template<int size
, bool big_endian
>
5883 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5884 Sized_relobj_file
<size
, big_endian
>* object
,
5885 unsigned int r_type
,
5888 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5889 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
5892 // Scan a relocation for a global symbol.
5894 template<int size
, bool big_endian
>
5896 Target_powerpc
<size
, big_endian
>::Scan::global(
5897 Symbol_table
* symtab
,
5899 Target_powerpc
<size
, big_endian
>* target
,
5900 Sized_relobj_file
<size
, big_endian
>* object
,
5901 unsigned int data_shndx
,
5902 Output_section
* output_section
,
5903 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5904 unsigned int r_type
,
5907 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
5910 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5911 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5913 this->expect_tls_get_addr_call();
5914 const bool final
= gsym
->final_value_is_known();
5915 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
5916 if (tls_type
!= tls::TLSOPT_NONE
)
5917 this->skip_next_tls_get_addr_call();
5919 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5920 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5922 this->expect_tls_get_addr_call();
5923 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5924 if (tls_type
!= tls::TLSOPT_NONE
)
5925 this->skip_next_tls_get_addr_call();
5928 Powerpc_relobj
<size
, big_endian
>* ppc_object
5929 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5931 // A STT_GNU_IFUNC symbol may require a PLT entry.
5932 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
5933 bool pushed_ifunc
= false;
5934 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5936 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5937 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5938 reloc
.get_r_addend());
5939 target
->make_plt_entry(symtab
, layout
, gsym
);
5940 pushed_ifunc
= true;
5945 case elfcpp::R_POWERPC_NONE
:
5946 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5947 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5948 case elfcpp::R_PPC_LOCAL24PC
:
5949 case elfcpp::R_POWERPC_TLS
:
5952 case elfcpp::R_PPC64_TOC
:
5954 Output_data_got_powerpc
<size
, big_endian
>* got
5955 = target
->got_section(symtab
, layout
);
5956 if (parameters
->options().output_is_position_independent())
5958 Address off
= reloc
.get_r_offset();
5960 && data_shndx
== ppc_object
->opd_shndx()
5961 && ppc_object
->get_opd_discard(off
- 8))
5964 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5965 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5966 if (data_shndx
!= ppc_object
->opd_shndx())
5967 symobj
= static_cast
5968 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
5969 rela_dyn
->add_output_section_relative(got
->output_section(),
5970 elfcpp::R_POWERPC_RELATIVE
,
5972 object
, data_shndx
, off
,
5973 symobj
->toc_base_offset());
5978 case elfcpp::R_PPC64_ADDR64
:
5980 && target
->abiversion() < 2
5981 && data_shndx
== ppc_object
->opd_shndx()
5982 && (gsym
->is_defined_in_discarded_section()
5983 || gsym
->object() != object
))
5985 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5989 case elfcpp::R_PPC64_UADDR64
:
5990 case elfcpp::R_POWERPC_ADDR32
:
5991 case elfcpp::R_POWERPC_UADDR32
:
5992 case elfcpp::R_POWERPC_ADDR24
:
5993 case elfcpp::R_POWERPC_ADDR16
:
5994 case elfcpp::R_POWERPC_ADDR16_LO
:
5995 case elfcpp::R_POWERPC_ADDR16_HI
:
5996 case elfcpp::R_POWERPC_ADDR16_HA
:
5997 case elfcpp::R_POWERPC_UADDR16
:
5998 case elfcpp::R_PPC64_ADDR16_HIGH
:
5999 case elfcpp::R_PPC64_ADDR16_HIGHA
:
6000 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6001 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6002 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6003 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6004 case elfcpp::R_PPC64_ADDR16_DS
:
6005 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6006 case elfcpp::R_POWERPC_ADDR14
:
6007 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6008 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6010 // Make a PLT entry if necessary.
6011 if (gsym
->needs_plt_entry())
6013 // Since this is not a PC-relative relocation, we may be
6014 // taking the address of a function. In that case we need to
6015 // set the entry in the dynamic symbol table to the address of
6016 // the PLT call stub.
6017 bool need_ifunc_plt
= false;
6018 if ((size
== 32 || target
->abiversion() >= 2)
6019 && gsym
->is_from_dynobj()
6020 && !parameters
->options().output_is_position_independent())
6022 gsym
->set_needs_dynsym_value();
6023 need_ifunc_plt
= true;
6025 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
6027 target
->push_branch(ppc_object
, data_shndx
,
6028 reloc
.get_r_offset(), r_type
,
6029 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6030 reloc
.get_r_addend());
6031 target
->make_plt_entry(symtab
, layout
, gsym
);
6034 // Make a dynamic relocation if necessary.
6035 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
6036 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
6038 if (!parameters
->options().output_is_position_independent()
6039 && gsym
->may_need_copy_reloc())
6041 target
->copy_reloc(symtab
, layout
, object
,
6042 data_shndx
, output_section
, gsym
, reloc
);
6044 else if ((((size
== 32
6045 && r_type
== elfcpp::R_POWERPC_ADDR32
)
6047 && r_type
== elfcpp::R_PPC64_ADDR64
6048 && target
->abiversion() >= 2))
6049 && gsym
->can_use_relative_reloc(false)
6050 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
6051 && parameters
->options().shared()))
6053 && r_type
== elfcpp::R_PPC64_ADDR64
6054 && target
->abiversion() < 2
6055 && (gsym
->can_use_relative_reloc(false)
6056 || data_shndx
== ppc_object
->opd_shndx())))
6058 Reloc_section
* rela_dyn
6059 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6060 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6061 : elfcpp::R_POWERPC_RELATIVE
);
6062 rela_dyn
->add_symbolless_global_addend(
6063 gsym
, dynrel
, output_section
, object
, data_shndx
,
6064 reloc
.get_r_offset(), reloc
.get_r_addend());
6068 Reloc_section
* rela_dyn
6069 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6070 check_non_pic(object
, r_type
);
6071 rela_dyn
->add_global(gsym
, r_type
, output_section
,
6073 reloc
.get_r_offset(),
6074 reloc
.get_r_addend());
6080 case elfcpp::R_PPC_PLTREL24
:
6081 case elfcpp::R_POWERPC_REL24
:
6084 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6086 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6087 reloc
.get_r_addend());
6088 if (gsym
->needs_plt_entry()
6089 || (!gsym
->final_value_is_known()
6090 && (gsym
->is_undefined()
6091 || gsym
->is_from_dynobj()
6092 || gsym
->is_preemptible())))
6093 target
->make_plt_entry(symtab
, layout
, gsym
);
6097 case elfcpp::R_PPC64_REL64
:
6098 case elfcpp::R_POWERPC_REL32
:
6099 // Make a dynamic relocation if necessary.
6100 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
6102 if (!parameters
->options().output_is_position_independent()
6103 && gsym
->may_need_copy_reloc())
6105 target
->copy_reloc(symtab
, layout
, object
,
6106 data_shndx
, output_section
, gsym
,
6111 Reloc_section
* rela_dyn
6112 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6113 check_non_pic(object
, r_type
);
6114 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
6115 data_shndx
, reloc
.get_r_offset(),
6116 reloc
.get_r_addend());
6121 case elfcpp::R_POWERPC_REL14
:
6122 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6123 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6125 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6126 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6127 reloc
.get_r_addend());
6130 case elfcpp::R_POWERPC_REL16
:
6131 case elfcpp::R_POWERPC_REL16_LO
:
6132 case elfcpp::R_POWERPC_REL16_HI
:
6133 case elfcpp::R_POWERPC_REL16_HA
:
6134 case elfcpp::R_POWERPC_SECTOFF
:
6135 case elfcpp::R_POWERPC_SECTOFF_LO
:
6136 case elfcpp::R_POWERPC_SECTOFF_HI
:
6137 case elfcpp::R_POWERPC_SECTOFF_HA
:
6138 case elfcpp::R_PPC64_SECTOFF_DS
:
6139 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6140 case elfcpp::R_POWERPC_TPREL16
:
6141 case elfcpp::R_POWERPC_TPREL16_LO
:
6142 case elfcpp::R_POWERPC_TPREL16_HI
:
6143 case elfcpp::R_POWERPC_TPREL16_HA
:
6144 case elfcpp::R_PPC64_TPREL16_DS
:
6145 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6146 case elfcpp::R_PPC64_TPREL16_HIGH
:
6147 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6148 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6149 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6150 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6151 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6152 case elfcpp::R_POWERPC_DTPREL16
:
6153 case elfcpp::R_POWERPC_DTPREL16_LO
:
6154 case elfcpp::R_POWERPC_DTPREL16_HI
:
6155 case elfcpp::R_POWERPC_DTPREL16_HA
:
6156 case elfcpp::R_PPC64_DTPREL16_DS
:
6157 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6158 case elfcpp::R_PPC64_DTPREL16_HIGH
:
6159 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
6160 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6161 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6162 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6163 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6164 case elfcpp::R_PPC64_TLSGD
:
6165 case elfcpp::R_PPC64_TLSLD
:
6166 case elfcpp::R_PPC64_ADDR64_LOCAL
:
6169 case elfcpp::R_POWERPC_GOT16
:
6170 case elfcpp::R_POWERPC_GOT16_LO
:
6171 case elfcpp::R_POWERPC_GOT16_HI
:
6172 case elfcpp::R_POWERPC_GOT16_HA
:
6173 case elfcpp::R_PPC64_GOT16_DS
:
6174 case elfcpp::R_PPC64_GOT16_LO_DS
:
6176 // The symbol requires a GOT entry.
6177 Output_data_got_powerpc
<size
, big_endian
>* got
;
6179 got
= target
->got_section(symtab
, layout
);
6180 if (gsym
->final_value_is_known())
6183 && (size
== 32 || target
->abiversion() >= 2))
6184 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
6186 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
6188 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
6190 // If we are generating a shared object or a pie, this
6191 // symbol's GOT entry will be set by a dynamic relocation.
6192 unsigned int off
= got
->add_constant(0);
6193 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
6195 Reloc_section
* rela_dyn
6196 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6198 if (gsym
->can_use_relative_reloc(false)
6200 || target
->abiversion() >= 2)
6201 && gsym
->visibility() == elfcpp::STV_PROTECTED
6202 && parameters
->options().shared()))
6204 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6205 : elfcpp::R_POWERPC_RELATIVE
);
6206 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
6210 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
6211 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
6217 case elfcpp::R_PPC64_TOC16
:
6218 case elfcpp::R_PPC64_TOC16_LO
:
6219 case elfcpp::R_PPC64_TOC16_HI
:
6220 case elfcpp::R_PPC64_TOC16_HA
:
6221 case elfcpp::R_PPC64_TOC16_DS
:
6222 case elfcpp::R_PPC64_TOC16_LO_DS
:
6223 // We need a GOT section.
6224 target
->got_section(symtab
, layout
);
6227 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6228 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6229 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6230 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6232 const bool final
= gsym
->final_value_is_known();
6233 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6234 if (tls_type
== tls::TLSOPT_NONE
)
6236 Output_data_got_powerpc
<size
, big_endian
>* got
6237 = target
->got_section(symtab
, layout
);
6238 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6239 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
6240 elfcpp::R_POWERPC_DTPMOD
,
6241 elfcpp::R_POWERPC_DTPREL
);
6243 else if (tls_type
== tls::TLSOPT_TO_IE
)
6245 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6247 Output_data_got_powerpc
<size
, big_endian
>* got
6248 = target
->got_section(symtab
, layout
);
6249 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6250 if (gsym
->is_undefined()
6251 || gsym
->is_from_dynobj())
6253 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6254 elfcpp::R_POWERPC_TPREL
);
6258 unsigned int off
= got
->add_constant(0);
6259 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6260 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6261 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6266 else if (tls_type
== tls::TLSOPT_TO_LE
)
6268 // no GOT relocs needed for Local Exec.
6275 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6276 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6277 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6278 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6280 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6281 if (tls_type
== tls::TLSOPT_NONE
)
6282 target
->tlsld_got_offset(symtab
, layout
, object
);
6283 else if (tls_type
== tls::TLSOPT_TO_LE
)
6285 // no GOT relocs needed for Local Exec.
6286 if (parameters
->options().emit_relocs())
6288 Output_section
* os
= layout
->tls_segment()->first_section();
6289 gold_assert(os
!= NULL
);
6290 os
->set_needs_symtab_index();
6298 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6299 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6300 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6301 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6303 Output_data_got_powerpc
<size
, big_endian
>* got
6304 = target
->got_section(symtab
, layout
);
6305 if (!gsym
->final_value_is_known()
6306 && (gsym
->is_from_dynobj()
6307 || gsym
->is_undefined()
6308 || gsym
->is_preemptible()))
6309 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
6310 target
->rela_dyn_section(layout
),
6311 elfcpp::R_POWERPC_DTPREL
);
6313 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
6317 case elfcpp::R_POWERPC_GOT_TPREL16
:
6318 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6319 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6320 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6322 const bool final
= gsym
->final_value_is_known();
6323 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6324 if (tls_type
== tls::TLSOPT_NONE
)
6326 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6328 Output_data_got_powerpc
<size
, big_endian
>* got
6329 = target
->got_section(symtab
, layout
);
6330 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6331 if (gsym
->is_undefined()
6332 || gsym
->is_from_dynobj())
6334 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6335 elfcpp::R_POWERPC_TPREL
);
6339 unsigned int off
= got
->add_constant(0);
6340 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6341 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6342 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6347 else if (tls_type
== tls::TLSOPT_TO_LE
)
6349 // no GOT relocs needed for Local Exec.
6357 unsupported_reloc_global(object
, r_type
, gsym
);
6363 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6364 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6365 case elfcpp::R_POWERPC_GOT_TPREL16
:
6366 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6367 case elfcpp::R_POWERPC_GOT16
:
6368 case elfcpp::R_PPC64_GOT16_DS
:
6369 case elfcpp::R_PPC64_TOC16
:
6370 case elfcpp::R_PPC64_TOC16_DS
:
6371 ppc_object
->set_has_small_toc_reloc();
6377 // Process relocations for gc.
6379 template<int size
, bool big_endian
>
6381 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
6382 Symbol_table
* symtab
,
6384 Sized_relobj_file
<size
, big_endian
>* object
,
6385 unsigned int data_shndx
,
6387 const unsigned char* prelocs
,
6389 Output_section
* output_section
,
6390 bool needs_special_offset_handling
,
6391 size_t local_symbol_count
,
6392 const unsigned char* plocal_symbols
)
6394 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6395 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6396 Powerpc_relobj
<size
, big_endian
>* ppc_object
6397 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6399 ppc_object
->set_opd_valid();
6400 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
6402 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
6403 for (p
= ppc_object
->access_from_map()->begin();
6404 p
!= ppc_object
->access_from_map()->end();
6407 Address dst_off
= p
->first
;
6408 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6409 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
6410 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
6412 Relobj
* src_obj
= s
->first
;
6413 unsigned int src_indx
= s
->second
;
6414 symtab
->gc()->add_reference(src_obj
, src_indx
,
6415 ppc_object
, dst_indx
);
6419 ppc_object
->access_from_map()->clear();
6420 ppc_object
->process_gc_mark(symtab
);
6421 // Don't look at .opd relocs as .opd will reference everything.
6425 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
,
6426 typename
Target_powerpc::Relocatable_size_for_reloc
>(
6435 needs_special_offset_handling
,
6440 // Handle target specific gc actions when adding a gc reference from
6441 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6442 // and DST_OFF. For powerpc64, this adds a referenc to the code
6443 // section of a function descriptor.
6445 template<int size
, bool big_endian
>
6447 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
6448 Symbol_table
* symtab
,
6450 unsigned int src_shndx
,
6452 unsigned int dst_shndx
,
6453 Address dst_off
) const
6455 if (size
!= 64 || dst_obj
->is_dynamic())
6458 Powerpc_relobj
<size
, big_endian
>* ppc_object
6459 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
6460 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
6462 if (ppc_object
->opd_valid())
6464 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
6465 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
6469 // If we haven't run scan_opd_relocs, we must delay
6470 // processing this function descriptor reference.
6471 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
6476 // Add any special sections for this symbol to the gc work list.
6477 // For powerpc64, this adds the code section of a function
6480 template<int size
, bool big_endian
>
6482 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
6483 Symbol_table
* symtab
,
6488 Powerpc_relobj
<size
, big_endian
>* ppc_object
6489 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
6491 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6492 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
6494 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
6495 Address dst_off
= gsym
->value();
6496 if (ppc_object
->opd_valid())
6498 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6499 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
6503 ppc_object
->add_gc_mark(dst_off
);
6508 // For a symbol location in .opd, set LOC to the location of the
6511 template<int size
, bool big_endian
>
6513 Target_powerpc
<size
, big_endian
>::do_function_location(
6514 Symbol_location
* loc
) const
6516 if (size
== 64 && loc
->shndx
!= 0)
6518 if (loc
->object
->is_dynamic())
6520 Powerpc_dynobj
<size
, big_endian
>* ppc_object
6521 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
6522 if (loc
->shndx
== ppc_object
->opd_shndx())
6525 Address off
= loc
->offset
- ppc_object
->opd_address();
6526 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
6527 loc
->offset
= dest_off
;
6532 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6533 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
6534 if (loc
->shndx
== ppc_object
->opd_shndx())
6537 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
6538 loc
->offset
= dest_off
;
6544 // FNOFFSET in section SHNDX in OBJECT is the start of a function
6545 // compiled with -fsplit-stack. The function calls non-split-stack
6546 // code. Change the function to ensure it has enough stack space to
6547 // call some random function.
6549 template<int size
, bool big_endian
>
6551 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
6554 section_offset_type fnoffset
,
6555 section_size_type fnsize
,
6556 unsigned char* view
,
6557 section_size_type view_size
,
6559 std::string
* to
) const
6561 // 32-bit not supported.
6565 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
6566 view
, view_size
, from
, to
);
6570 // The function always starts with
6571 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
6572 // addis %r12,%r1,-allocate@ha
6573 // addi %r12,%r12,-allocate@l
6575 // but note that the addis or addi may be replaced with a nop
6577 unsigned char *entry
= view
+ fnoffset
;
6578 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6580 if ((insn
& 0xffff0000) == addis_2_12
)
6582 /* Skip ELFv2 global entry code. */
6584 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6587 unsigned char *pinsn
= entry
;
6589 const uint32_t ld_private_ss
= 0xe80d8fc0;
6590 if (insn
== ld_private_ss
)
6592 int32_t allocate
= 0;
6596 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
6597 if ((insn
& 0xffff0000) == addis_12_1
)
6598 allocate
+= (insn
& 0xffff) << 16;
6599 else if ((insn
& 0xffff0000) == addi_12_1
6600 || (insn
& 0xffff0000) == addi_12_12
)
6601 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
6602 else if (insn
!= nop
)
6605 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
6607 int extra
= parameters
->options().split_stack_adjust_size();
6609 if (allocate
>= 0 || extra
< 0)
6611 object
->error(_("split-stack stack size overflow at "
6612 "section %u offset %0zx"),
6613 shndx
, static_cast<size_t>(fnoffset
));
6617 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
6618 if (insn
!= addis_12_1
)
6620 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6622 insn
= addi_12_12
| (allocate
& 0xffff);
6623 if (insn
!= addi_12_12
)
6625 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6631 insn
= addi_12_1
| (allocate
& 0xffff);
6632 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6635 if (pinsn
!= entry
+ 12)
6636 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
6644 if (!object
->has_no_split_stack())
6645 object
->error(_("failed to match split-stack sequence at "
6646 "section %u offset %0zx"),
6647 shndx
, static_cast<size_t>(fnoffset
));
6651 // Scan relocations for a section.
6653 template<int size
, bool big_endian
>
6655 Target_powerpc
<size
, big_endian
>::scan_relocs(
6656 Symbol_table
* symtab
,
6658 Sized_relobj_file
<size
, big_endian
>* object
,
6659 unsigned int data_shndx
,
6660 unsigned int sh_type
,
6661 const unsigned char* prelocs
,
6663 Output_section
* output_section
,
6664 bool needs_special_offset_handling
,
6665 size_t local_symbol_count
,
6666 const unsigned char* plocal_symbols
)
6668 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6669 typedef typename Target_powerpc
<size
, big_endian
>::Scan Scan
;
6671 if (sh_type
== elfcpp::SHT_REL
)
6673 gold_error(_("%s: unsupported REL reloc section"),
6674 object
->name().c_str());
6678 gold::scan_relocs
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
, Scan
>(
6687 needs_special_offset_handling
,
6692 // Functor class for processing the global symbol table.
6693 // Removes symbols defined on discarded opd entries.
6695 template<bool big_endian
>
6696 class Global_symbol_visitor_opd
6699 Global_symbol_visitor_opd()
6703 operator()(Sized_symbol
<64>* sym
)
6705 if (sym
->has_symtab_index()
6706 || sym
->source() != Symbol::FROM_OBJECT
6707 || !sym
->in_real_elf())
6710 if (sym
->object()->is_dynamic())
6713 Powerpc_relobj
<64, big_endian
>* symobj
6714 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
6715 if (symobj
->opd_shndx() == 0)
6719 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6720 if (shndx
== symobj
->opd_shndx()
6721 && symobj
->get_opd_discard(sym
->value()))
6723 sym
->set_undefined();
6724 sym
->set_visibility(elfcpp::STV_DEFAULT
);
6725 sym
->set_is_defined_in_discarded_section();
6726 sym
->set_symtab_index(-1U);
6731 template<int size
, bool big_endian
>
6733 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
6735 Symbol_table
* symtab
)
6739 Output_data_save_res
<size
, big_endian
>* savres
6740 = new Output_data_save_res
<size
, big_endian
>(symtab
);
6741 this->savres_section_
= savres
;
6742 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6743 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6744 savres
, ORDER_TEXT
, false);
6748 // Sort linker created .got section first (for the header), then input
6749 // sections belonging to files using small model code.
6751 template<bool big_endian
>
6752 class Sort_toc_sections
6756 operator()(const Output_section::Input_section
& is1
,
6757 const Output_section::Input_section
& is2
) const
6759 if (!is1
.is_input_section() && is2
.is_input_section())
6762 = (is1
.is_input_section()
6763 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
6764 ->has_small_toc_reloc()));
6766 = (is2
.is_input_section()
6767 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
6768 ->has_small_toc_reloc()));
6769 return small1
&& !small2
;
6773 // Finalize the sections.
6775 template<int size
, bool big_endian
>
6777 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
6779 const Input_objects
*,
6780 Symbol_table
* symtab
)
6782 if (parameters
->doing_static_link())
6784 // At least some versions of glibc elf-init.o have a strong
6785 // reference to __rela_iplt marker syms. A weak ref would be
6787 if (this->iplt_
!= NULL
)
6789 Reloc_section
* rel
= this->iplt_
->rel_plt();
6790 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
6791 Symbol_table::PREDEFINED
, rel
, 0, 0,
6792 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6793 elfcpp::STV_HIDDEN
, 0, false, true);
6794 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
6795 Symbol_table::PREDEFINED
, rel
, 0, 0,
6796 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6797 elfcpp::STV_HIDDEN
, 0, true, true);
6801 symtab
->define_as_constant("__rela_iplt_start", NULL
,
6802 Symbol_table::PREDEFINED
, 0, 0,
6803 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6804 elfcpp::STV_HIDDEN
, 0, true, false);
6805 symtab
->define_as_constant("__rela_iplt_end", NULL
,
6806 Symbol_table::PREDEFINED
, 0, 0,
6807 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6808 elfcpp::STV_HIDDEN
, 0, true, false);
6814 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6815 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6817 if (!parameters
->options().relocatable())
6819 this->define_save_restore_funcs(layout
, symtab
);
6821 // Annoyingly, we need to make these sections now whether or
6822 // not we need them. If we delay until do_relax then we
6823 // need to mess with the relaxation machinery checkpointing.
6824 this->got_section(symtab
, layout
);
6825 this->make_brlt_section(layout
);
6827 if (parameters
->options().toc_sort())
6829 Output_section
* os
= this->got_
->output_section();
6830 if (os
!= NULL
&& os
->input_sections().size() > 1)
6831 std::stable_sort(os
->input_sections().begin(),
6832 os
->input_sections().end(),
6833 Sort_toc_sections
<big_endian
>());
6838 // Fill in some more dynamic tags.
6839 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6842 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6844 : this->plt_
->rel_plt());
6845 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6846 this->rela_dyn_
, true, size
== 32);
6850 if (this->got_
!= NULL
)
6852 this->got_
->finalize_data_size();
6853 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6854 this->got_
, this->got_
->g_o_t());
6859 if (this->glink_
!= NULL
)
6861 this->glink_
->finalize_data_size();
6862 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6864 (this->glink_
->pltresolve_size
6870 // Emit any relocs we saved in an attempt to avoid generating COPY
6872 if (this->copy_relocs_
.any_saved_relocs())
6873 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6876 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6880 ok_lo_toc_insn(uint32_t insn
)
6882 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
6883 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
6884 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
6885 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
6886 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
6887 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
6888 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
6889 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
6890 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
6891 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
6892 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
6893 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
6894 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
6895 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
6896 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6898 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
6899 && ((insn
& 3) == 0 || (insn
& 3) == 3))
6900 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
6903 // Return the value to use for a branch relocation.
6905 template<int size
, bool big_endian
>
6907 Target_powerpc
<size
, big_endian
>::symval_for_branch(
6908 const Symbol_table
* symtab
,
6909 const Sized_symbol
<size
>* gsym
,
6910 Powerpc_relobj
<size
, big_endian
>* object
,
6912 unsigned int *dest_shndx
)
6914 if (size
== 32 || this->abiversion() >= 2)
6918 // If the symbol is defined in an opd section, ie. is a function
6919 // descriptor, use the function descriptor code entry address
6920 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
6922 && gsym
->source() != Symbol::FROM_OBJECT
)
6925 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6926 unsigned int shndx
= symobj
->opd_shndx();
6929 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
6930 if (opd_addr
== invalid_address
)
6932 opd_addr
+= symobj
->output_section_address(shndx
);
6933 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
6936 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
6937 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
6940 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
6941 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
6942 *dest_shndx
= folded
.second
;
6944 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
6945 if (sec_addr
== invalid_address
)
6948 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
6949 *value
= sec_addr
+ sec_off
;
6954 // Perform a relocation.
6956 template<int size
, bool big_endian
>
6958 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
6959 const Relocate_info
<size
, big_endian
>* relinfo
,
6960 Target_powerpc
* target
,
6963 const elfcpp::Rela
<size
, big_endian
>& rela
,
6964 unsigned int r_type
,
6965 const Sized_symbol
<size
>* gsym
,
6966 const Symbol_value
<size
>* psymval
,
6967 unsigned char* view
,
6969 section_size_type view_size
)
6974 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
6976 case Track_tls::NOT_EXPECTED
:
6977 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
6978 _("__tls_get_addr call lacks marker reloc"));
6980 case Track_tls::EXPECTED
:
6981 // We have already complained.
6983 case Track_tls::SKIP
:
6985 case Track_tls::NORMAL
:
6989 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
6990 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
6991 Powerpc_relobj
<size
, big_endian
>* const object
6992 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
6994 bool has_stub_value
= false;
6995 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
6997 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
6998 : object
->local_has_plt_offset(r_sym
))
6999 && (!psymval
->is_ifunc_symbol()
7000 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
7004 && target
->abiversion() >= 2
7005 && !parameters
->options().output_is_position_independent()
7006 && !is_branch_reloc(r_type
))
7008 Address off
= target
->glink_section()->find_global_entry(gsym
);
7009 if (off
!= invalid_address
)
7011 value
= target
->glink_section()->global_entry_address() + off
;
7012 has_stub_value
= true;
7017 Stub_table
<size
, big_endian
>* stub_table
7018 = object
->stub_table(relinfo
->data_shndx
);
7019 if (stub_table
== NULL
)
7021 // This is a ref from a data section to an ifunc symbol.
7022 if (target
->stub_tables().size() != 0)
7023 stub_table
= target
->stub_tables()[0];
7025 if (stub_table
!= NULL
)
7029 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
7030 rela
.get_r_addend());
7032 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
7033 rela
.get_r_addend());
7034 if (off
!= invalid_address
)
7036 value
= stub_table
->stub_address() + off
;
7037 has_stub_value
= true;
7041 // We don't care too much about bogus debug references to
7042 // non-local functions, but otherwise there had better be a plt
7043 // call stub or global entry stub as appropriate.
7044 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
7047 if (r_type
== elfcpp::R_POWERPC_GOT16
7048 || r_type
== elfcpp::R_POWERPC_GOT16_LO
7049 || r_type
== elfcpp::R_POWERPC_GOT16_HI
7050 || r_type
== elfcpp::R_POWERPC_GOT16_HA
7051 || r_type
== elfcpp::R_PPC64_GOT16_DS
7052 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
7056 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
7057 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
7061 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7062 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
7063 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
7065 value
-= target
->got_section()->got_base_offset(object
);
7067 else if (r_type
== elfcpp::R_PPC64_TOC
)
7069 value
= (target
->got_section()->output_section()->address()
7070 + object
->toc_base_offset());
7072 else if (gsym
!= NULL
7073 && (r_type
== elfcpp::R_POWERPC_REL24
7074 || r_type
== elfcpp::R_PPC_PLTREL24
)
7079 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
7080 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
7081 bool can_plt_call
= false;
7082 if (rela
.get_r_offset() + 8 <= view_size
)
7084 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
7085 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
7088 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
7090 elfcpp::Swap
<32, big_endian
>::
7091 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
7092 can_plt_call
= true;
7097 // If we don't have a branch and link followed by a nop,
7098 // we can't go via the plt because there is no place to
7099 // put a toc restoring instruction.
7100 // Unless we know we won't be returning.
7101 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
7102 can_plt_call
= true;
7106 // g++ as of 20130507 emits self-calls without a
7107 // following nop. This is arguably wrong since we have
7108 // conflicting information. On the one hand a global
7109 // symbol and on the other a local call sequence, but
7110 // don't error for this special case.
7111 // It isn't possible to cheaply verify we have exactly
7112 // such a call. Allow all calls to the same section.
7114 Address code
= value
;
7115 if (gsym
->source() == Symbol::FROM_OBJECT
7116 && gsym
->object() == object
)
7118 unsigned int dest_shndx
= 0;
7119 if (target
->abiversion() < 2)
7121 Address addend
= rela
.get_r_addend();
7122 code
= psymval
->value(object
, addend
);
7123 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7124 &code
, &dest_shndx
);
7127 if (dest_shndx
== 0)
7128 dest_shndx
= gsym
->shndx(&is_ordinary
);
7129 ok
= dest_shndx
== relinfo
->data_shndx
;
7133 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7134 _("call lacks nop, can't restore toc; "
7135 "recompile with -fPIC"));
7141 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7142 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
7143 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
7144 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
7146 // First instruction of a global dynamic sequence, arg setup insn.
7147 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7148 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7149 enum Got_type got_type
= GOT_TYPE_STANDARD
;
7150 if (tls_type
== tls::TLSOPT_NONE
)
7151 got_type
= GOT_TYPE_TLSGD
;
7152 else if (tls_type
== tls::TLSOPT_TO_IE
)
7153 got_type
= GOT_TYPE_TPREL
;
7154 if (got_type
!= GOT_TYPE_STANDARD
)
7158 gold_assert(gsym
->has_got_offset(got_type
));
7159 value
= gsym
->got_offset(got_type
);
7163 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7164 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
7165 value
= object
->local_got_offset(r_sym
, got_type
);
7167 value
-= target
->got_section()->got_base_offset(object
);
7169 if (tls_type
== tls::TLSOPT_TO_IE
)
7171 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7172 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7174 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7175 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7176 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
7178 insn
|= 32 << 26; // lwz
7180 insn
|= 58 << 26; // ld
7181 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7183 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7184 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7186 else if (tls_type
== tls::TLSOPT_TO_LE
)
7188 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7189 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7191 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7192 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7193 insn
&= (1 << 26) - (1 << 21); // extract rt
7198 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7199 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7200 value
= psymval
->value(object
, rela
.get_r_addend());
7204 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7206 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7207 r_type
= elfcpp::R_POWERPC_NONE
;
7211 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7212 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7213 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7214 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7216 // First instruction of a local dynamic sequence, arg setup insn.
7217 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7218 if (tls_type
== tls::TLSOPT_NONE
)
7220 value
= target
->tlsld_got_offset();
7221 value
-= target
->got_section()->got_base_offset(object
);
7225 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7226 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7227 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7229 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7230 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7231 insn
&= (1 << 26) - (1 << 21); // extract rt
7236 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7237 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7242 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7244 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7245 r_type
= elfcpp::R_POWERPC_NONE
;
7249 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
7250 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
7251 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
7252 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
7254 // Accesses relative to a local dynamic sequence address,
7255 // no optimisation here.
7258 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
7259 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
7263 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7264 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
7265 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
7267 value
-= target
->got_section()->got_base_offset(object
);
7269 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7270 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7271 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7272 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
7274 // First instruction of initial exec sequence.
7275 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7276 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7277 if (tls_type
== tls::TLSOPT_NONE
)
7281 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
7282 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
7286 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7287 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
7288 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
7290 value
-= target
->got_section()->got_base_offset(object
);
7294 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7295 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7296 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
7298 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7299 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7300 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
7305 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7306 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7307 value
= psymval
->value(object
, rela
.get_r_addend());
7311 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7313 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7314 r_type
= elfcpp::R_POWERPC_NONE
;
7318 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7319 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7321 // Second instruction of a global dynamic sequence,
7322 // the __tls_get_addr call
7323 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7324 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7325 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7326 if (tls_type
!= tls::TLSOPT_NONE
)
7328 if (tls_type
== tls::TLSOPT_TO_IE
)
7330 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7331 Insn insn
= add_3_3_13
;
7334 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7335 r_type
= elfcpp::R_POWERPC_NONE
;
7339 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7340 Insn insn
= addi_3_3
;
7341 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7342 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7343 view
+= 2 * big_endian
;
7344 value
= psymval
->value(object
, rela
.get_r_addend());
7346 this->skip_next_tls_get_addr_call();
7349 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7350 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7352 // Second instruction of a local dynamic sequence,
7353 // the __tls_get_addr call
7354 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7355 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7356 if (tls_type
== tls::TLSOPT_TO_LE
)
7358 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7359 Insn insn
= addi_3_3
;
7360 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7361 this->skip_next_tls_get_addr_call();
7362 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7363 view
+= 2 * big_endian
;
7367 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7369 // Second instruction of an initial exec sequence
7370 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7371 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7372 if (tls_type
== tls::TLSOPT_TO_LE
)
7374 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7375 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7376 unsigned int reg
= size
== 32 ? 2 : 13;
7377 insn
= at_tls_transform(insn
, reg
);
7378 gold_assert(insn
!= 0);
7379 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7380 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7381 view
+= 2 * big_endian
;
7382 value
= psymval
->value(object
, rela
.get_r_addend());
7385 else if (!has_stub_value
)
7388 if (!(size
== 32 && r_type
== elfcpp::R_PPC_PLTREL24
))
7389 addend
= rela
.get_r_addend();
7390 value
= psymval
->value(object
, addend
);
7391 if (size
== 64 && is_branch_reloc(r_type
))
7393 if (target
->abiversion() >= 2)
7396 value
+= object
->ppc64_local_entry_offset(gsym
);
7398 value
+= object
->ppc64_local_entry_offset(r_sym
);
7402 unsigned int dest_shndx
;
7403 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7404 &value
, &dest_shndx
);
7407 Address max_branch_offset
= max_branch_delta(r_type
);
7408 if (max_branch_offset
!= 0
7409 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
7411 Stub_table
<size
, big_endian
>* stub_table
7412 = object
->stub_table(relinfo
->data_shndx
);
7413 if (stub_table
!= NULL
)
7415 Address off
= stub_table
->find_long_branch_entry(object
, value
);
7416 if (off
!= invalid_address
)
7418 value
= (stub_table
->stub_address() + stub_table
->plt_size()
7420 has_stub_value
= true;
7428 case elfcpp::R_PPC64_REL64
:
7429 case elfcpp::R_POWERPC_REL32
:
7430 case elfcpp::R_POWERPC_REL24
:
7431 case elfcpp::R_PPC_PLTREL24
:
7432 case elfcpp::R_PPC_LOCAL24PC
:
7433 case elfcpp::R_POWERPC_REL16
:
7434 case elfcpp::R_POWERPC_REL16_LO
:
7435 case elfcpp::R_POWERPC_REL16_HI
:
7436 case elfcpp::R_POWERPC_REL16_HA
:
7437 case elfcpp::R_POWERPC_REL14
:
7438 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7439 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7443 case elfcpp::R_PPC64_TOC16
:
7444 case elfcpp::R_PPC64_TOC16_LO
:
7445 case elfcpp::R_PPC64_TOC16_HI
:
7446 case elfcpp::R_PPC64_TOC16_HA
:
7447 case elfcpp::R_PPC64_TOC16_DS
:
7448 case elfcpp::R_PPC64_TOC16_LO_DS
:
7449 // Subtract the TOC base address.
7450 value
-= (target
->got_section()->output_section()->address()
7451 + object
->toc_base_offset());
7454 case elfcpp::R_POWERPC_SECTOFF
:
7455 case elfcpp::R_POWERPC_SECTOFF_LO
:
7456 case elfcpp::R_POWERPC_SECTOFF_HI
:
7457 case elfcpp::R_POWERPC_SECTOFF_HA
:
7458 case elfcpp::R_PPC64_SECTOFF_DS
:
7459 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7461 value
-= os
->address();
7464 case elfcpp::R_PPC64_TPREL16_DS
:
7465 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7466 case elfcpp::R_PPC64_TPREL16_HIGH
:
7467 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7469 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7471 case elfcpp::R_POWERPC_TPREL16
:
7472 case elfcpp::R_POWERPC_TPREL16_LO
:
7473 case elfcpp::R_POWERPC_TPREL16_HI
:
7474 case elfcpp::R_POWERPC_TPREL16_HA
:
7475 case elfcpp::R_POWERPC_TPREL
:
7476 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7477 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7478 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7479 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7480 // tls symbol values are relative to tls_segment()->vaddr()
7484 case elfcpp::R_PPC64_DTPREL16_DS
:
7485 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7486 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7487 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7488 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7489 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7491 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7492 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7494 case elfcpp::R_POWERPC_DTPREL16
:
7495 case elfcpp::R_POWERPC_DTPREL16_LO
:
7496 case elfcpp::R_POWERPC_DTPREL16_HI
:
7497 case elfcpp::R_POWERPC_DTPREL16_HA
:
7498 case elfcpp::R_POWERPC_DTPREL
:
7499 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7500 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7501 // tls symbol values are relative to tls_segment()->vaddr()
7502 value
-= dtp_offset
;
7505 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7507 value
+= object
->ppc64_local_entry_offset(gsym
);
7509 value
+= object
->ppc64_local_entry_offset(r_sym
);
7516 Insn branch_bit
= 0;
7519 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7520 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7521 branch_bit
= 1 << 21;
7522 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7523 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7525 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7526 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7529 if (this->is_isa_v2
)
7531 // Set 'a' bit. This is 0b00010 in BO field for branch
7532 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7533 // for branch on CTR insns (BO == 1a00t or 1a01t).
7534 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7536 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7543 // Invert 'y' bit if not the default.
7544 if (static_cast<Signed_address
>(value
) < 0)
7547 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7557 // Multi-instruction sequences that access the TOC can be
7558 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7559 // to nop; addi rb,r2,x;
7565 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7566 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7567 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7568 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7569 case elfcpp::R_POWERPC_GOT16_HA
:
7570 case elfcpp::R_PPC64_TOC16_HA
:
7571 if (parameters
->options().toc_optimize())
7573 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7574 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7575 if ((insn
& ((0x3f << 26) | 0x1f << 16))
7576 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7577 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7578 _("toc optimization is not supported "
7579 "for %#08x instruction"), insn
);
7580 else if (value
+ 0x8000 < 0x10000)
7582 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
7588 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7589 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7590 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7591 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7592 case elfcpp::R_POWERPC_GOT16_LO
:
7593 case elfcpp::R_PPC64_GOT16_LO_DS
:
7594 case elfcpp::R_PPC64_TOC16_LO
:
7595 case elfcpp::R_PPC64_TOC16_LO_DS
:
7596 if (parameters
->options().toc_optimize())
7598 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7599 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7600 if (!ok_lo_toc_insn(insn
))
7601 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7602 _("toc optimization is not supported "
7603 "for %#08x instruction"), insn
);
7604 else if (value
+ 0x8000 < 0x10000)
7606 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
7608 // Transform addic to addi when we change reg.
7609 insn
&= ~((0x3f << 26) | (0x1f << 16));
7610 insn
|= (14u << 26) | (2 << 16);
7614 insn
&= ~(0x1f << 16);
7617 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7624 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
7625 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
7628 case elfcpp::R_POWERPC_ADDR32
:
7629 case elfcpp::R_POWERPC_UADDR32
:
7631 overflow
= Reloc::CHECK_BITFIELD
;
7634 case elfcpp::R_POWERPC_REL32
:
7636 overflow
= Reloc::CHECK_SIGNED
;
7639 case elfcpp::R_POWERPC_UADDR16
:
7640 overflow
= Reloc::CHECK_BITFIELD
;
7643 case elfcpp::R_POWERPC_ADDR16
:
7644 // We really should have three separate relocations,
7645 // one for 16-bit data, one for insns with 16-bit signed fields,
7646 // and one for insns with 16-bit unsigned fields.
7647 overflow
= Reloc::CHECK_BITFIELD
;
7648 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
7649 overflow
= Reloc::CHECK_LOW_INSN
;
7652 case elfcpp::R_POWERPC_ADDR16_HI
:
7653 case elfcpp::R_POWERPC_ADDR16_HA
:
7654 case elfcpp::R_POWERPC_GOT16_HI
:
7655 case elfcpp::R_POWERPC_GOT16_HA
:
7656 case elfcpp::R_POWERPC_PLT16_HI
:
7657 case elfcpp::R_POWERPC_PLT16_HA
:
7658 case elfcpp::R_POWERPC_SECTOFF_HI
:
7659 case elfcpp::R_POWERPC_SECTOFF_HA
:
7660 case elfcpp::R_PPC64_TOC16_HI
:
7661 case elfcpp::R_PPC64_TOC16_HA
:
7662 case elfcpp::R_PPC64_PLTGOT16_HI
:
7663 case elfcpp::R_PPC64_PLTGOT16_HA
:
7664 case elfcpp::R_POWERPC_TPREL16_HI
:
7665 case elfcpp::R_POWERPC_TPREL16_HA
:
7666 case elfcpp::R_POWERPC_DTPREL16_HI
:
7667 case elfcpp::R_POWERPC_DTPREL16_HA
:
7668 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7669 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7670 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7671 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7672 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7673 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7674 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7675 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7676 case elfcpp::R_POWERPC_REL16_HI
:
7677 case elfcpp::R_POWERPC_REL16_HA
:
7679 overflow
= Reloc::CHECK_HIGH_INSN
;
7682 case elfcpp::R_POWERPC_REL16
:
7683 case elfcpp::R_PPC64_TOC16
:
7684 case elfcpp::R_POWERPC_GOT16
:
7685 case elfcpp::R_POWERPC_SECTOFF
:
7686 case elfcpp::R_POWERPC_TPREL16
:
7687 case elfcpp::R_POWERPC_DTPREL16
:
7688 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7689 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7690 case elfcpp::R_POWERPC_GOT_TPREL16
:
7691 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7692 overflow
= Reloc::CHECK_LOW_INSN
;
7695 case elfcpp::R_POWERPC_ADDR24
:
7696 case elfcpp::R_POWERPC_ADDR14
:
7697 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7698 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7699 case elfcpp::R_PPC64_ADDR16_DS
:
7700 case elfcpp::R_POWERPC_REL24
:
7701 case elfcpp::R_PPC_PLTREL24
:
7702 case elfcpp::R_PPC_LOCAL24PC
:
7703 case elfcpp::R_PPC64_TPREL16_DS
:
7704 case elfcpp::R_PPC64_DTPREL16_DS
:
7705 case elfcpp::R_PPC64_TOC16_DS
:
7706 case elfcpp::R_PPC64_GOT16_DS
:
7707 case elfcpp::R_PPC64_SECTOFF_DS
:
7708 case elfcpp::R_POWERPC_REL14
:
7709 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7710 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7711 overflow
= Reloc::CHECK_SIGNED
;
7715 if (overflow
== Reloc::CHECK_LOW_INSN
7716 || overflow
== Reloc::CHECK_HIGH_INSN
)
7718 Insn
* iview
= reinterpret_cast<Insn
*>(view
- 2 * big_endian
);
7719 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7721 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
7722 overflow
= Reloc::CHECK_BITFIELD
;
7723 else if (overflow
== Reloc::CHECK_LOW_INSN
7724 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
7725 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
7726 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
7727 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
7728 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
7729 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
7730 overflow
= Reloc::CHECK_UNSIGNED
;
7732 overflow
= Reloc::CHECK_SIGNED
;
7735 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
7736 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
7739 case elfcpp::R_POWERPC_NONE
:
7740 case elfcpp::R_POWERPC_TLS
:
7741 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7742 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7745 case elfcpp::R_PPC64_ADDR64
:
7746 case elfcpp::R_PPC64_REL64
:
7747 case elfcpp::R_PPC64_TOC
:
7748 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7749 Reloc::addr64(view
, value
);
7752 case elfcpp::R_POWERPC_TPREL
:
7753 case elfcpp::R_POWERPC_DTPREL
:
7755 Reloc::addr64(view
, value
);
7757 status
= Reloc::addr32(view
, value
, overflow
);
7760 case elfcpp::R_PPC64_UADDR64
:
7761 Reloc::addr64_u(view
, value
);
7764 case elfcpp::R_POWERPC_ADDR32
:
7765 status
= Reloc::addr32(view
, value
, overflow
);
7768 case elfcpp::R_POWERPC_REL32
:
7769 case elfcpp::R_POWERPC_UADDR32
:
7770 status
= Reloc::addr32_u(view
, value
, overflow
);
7773 case elfcpp::R_POWERPC_ADDR24
:
7774 case elfcpp::R_POWERPC_REL24
:
7775 case elfcpp::R_PPC_PLTREL24
:
7776 case elfcpp::R_PPC_LOCAL24PC
:
7777 status
= Reloc::addr24(view
, value
, overflow
);
7780 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7781 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7782 case elfcpp::R_POWERPC_GOT_TPREL16
:
7783 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7786 // On ppc64 these are all ds form
7787 status
= Reloc::addr16_ds(view
, value
, overflow
);
7790 case elfcpp::R_POWERPC_ADDR16
:
7791 case elfcpp::R_POWERPC_REL16
:
7792 case elfcpp::R_PPC64_TOC16
:
7793 case elfcpp::R_POWERPC_GOT16
:
7794 case elfcpp::R_POWERPC_SECTOFF
:
7795 case elfcpp::R_POWERPC_TPREL16
:
7796 case elfcpp::R_POWERPC_DTPREL16
:
7797 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7798 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7799 case elfcpp::R_POWERPC_ADDR16_LO
:
7800 case elfcpp::R_POWERPC_REL16_LO
:
7801 case elfcpp::R_PPC64_TOC16_LO
:
7802 case elfcpp::R_POWERPC_GOT16_LO
:
7803 case elfcpp::R_POWERPC_SECTOFF_LO
:
7804 case elfcpp::R_POWERPC_TPREL16_LO
:
7805 case elfcpp::R_POWERPC_DTPREL16_LO
:
7806 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7807 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7808 status
= Reloc::addr16(view
, value
, overflow
);
7811 case elfcpp::R_POWERPC_UADDR16
:
7812 status
= Reloc::addr16_u(view
, value
, overflow
);
7815 case elfcpp::R_PPC64_ADDR16_HIGH
:
7816 case elfcpp::R_PPC64_TPREL16_HIGH
:
7817 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7819 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
7821 case elfcpp::R_POWERPC_ADDR16_HI
:
7822 case elfcpp::R_POWERPC_REL16_HI
:
7823 case elfcpp::R_PPC64_TOC16_HI
:
7824 case elfcpp::R_POWERPC_GOT16_HI
:
7825 case elfcpp::R_POWERPC_SECTOFF_HI
:
7826 case elfcpp::R_POWERPC_TPREL16_HI
:
7827 case elfcpp::R_POWERPC_DTPREL16_HI
:
7828 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7829 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7830 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7831 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7832 Reloc::addr16_hi(view
, value
);
7835 case elfcpp::R_PPC64_ADDR16_HIGHA
:
7836 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7837 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7839 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
7841 case elfcpp::R_POWERPC_ADDR16_HA
:
7842 case elfcpp::R_POWERPC_REL16_HA
:
7843 case elfcpp::R_PPC64_TOC16_HA
:
7844 case elfcpp::R_POWERPC_GOT16_HA
:
7845 case elfcpp::R_POWERPC_SECTOFF_HA
:
7846 case elfcpp::R_POWERPC_TPREL16_HA
:
7847 case elfcpp::R_POWERPC_DTPREL16_HA
:
7848 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7849 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7850 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7851 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7852 Reloc::addr16_ha(view
, value
);
7855 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7857 // R_PPC_EMB_NADDR16_LO
7859 case elfcpp::R_PPC64_ADDR16_HIGHER
:
7860 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7861 Reloc::addr16_hi2(view
, value
);
7864 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7866 // R_PPC_EMB_NADDR16_HI
7868 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
7869 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7870 Reloc::addr16_ha2(view
, value
);
7873 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7875 // R_PPC_EMB_NADDR16_HA
7877 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
7878 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7879 Reloc::addr16_hi3(view
, value
);
7882 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7886 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
7887 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7888 Reloc::addr16_ha3(view
, value
);
7891 case elfcpp::R_PPC64_DTPREL16_DS
:
7892 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7894 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
7896 case elfcpp::R_PPC64_TPREL16_DS
:
7897 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7899 // R_PPC_TLSGD, R_PPC_TLSLD
7901 case elfcpp::R_PPC64_ADDR16_DS
:
7902 case elfcpp::R_PPC64_ADDR16_LO_DS
:
7903 case elfcpp::R_PPC64_TOC16_DS
:
7904 case elfcpp::R_PPC64_TOC16_LO_DS
:
7905 case elfcpp::R_PPC64_GOT16_DS
:
7906 case elfcpp::R_PPC64_GOT16_LO_DS
:
7907 case elfcpp::R_PPC64_SECTOFF_DS
:
7908 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7909 status
= Reloc::addr16_ds(view
, value
, overflow
);
7912 case elfcpp::R_POWERPC_ADDR14
:
7913 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7914 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7915 case elfcpp::R_POWERPC_REL14
:
7916 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7917 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7918 status
= Reloc::addr14(view
, value
, overflow
);
7921 case elfcpp::R_POWERPC_COPY
:
7922 case elfcpp::R_POWERPC_GLOB_DAT
:
7923 case elfcpp::R_POWERPC_JMP_SLOT
:
7924 case elfcpp::R_POWERPC_RELATIVE
:
7925 case elfcpp::R_POWERPC_DTPMOD
:
7926 case elfcpp::R_PPC64_JMP_IREL
:
7927 case elfcpp::R_POWERPC_IRELATIVE
:
7928 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7929 _("unexpected reloc %u in object file"),
7933 case elfcpp::R_PPC_EMB_SDA21
:
7938 // R_PPC64_TOCSAVE. For the time being this can be ignored.
7942 case elfcpp::R_PPC_EMB_SDA2I16
:
7943 case elfcpp::R_PPC_EMB_SDA2REL
:
7946 // R_PPC64_TLSGD, R_PPC64_TLSLD
7949 case elfcpp::R_POWERPC_PLT32
:
7950 case elfcpp::R_POWERPC_PLTREL32
:
7951 case elfcpp::R_POWERPC_PLT16_LO
:
7952 case elfcpp::R_POWERPC_PLT16_HI
:
7953 case elfcpp::R_POWERPC_PLT16_HA
:
7954 case elfcpp::R_PPC_SDAREL16
:
7955 case elfcpp::R_POWERPC_ADDR30
:
7956 case elfcpp::R_PPC64_PLT64
:
7957 case elfcpp::R_PPC64_PLTREL64
:
7958 case elfcpp::R_PPC64_PLTGOT16
:
7959 case elfcpp::R_PPC64_PLTGOT16_LO
:
7960 case elfcpp::R_PPC64_PLTGOT16_HI
:
7961 case elfcpp::R_PPC64_PLTGOT16_HA
:
7962 case elfcpp::R_PPC64_PLT16_LO_DS
:
7963 case elfcpp::R_PPC64_PLTGOT16_DS
:
7964 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
7965 case elfcpp::R_PPC_EMB_RELSDA
:
7966 case elfcpp::R_PPC_TOC16
:
7969 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7970 _("unsupported reloc %u"),
7974 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
7977 && gsym
->is_undefined()
7978 && is_branch_reloc(r_type
))))
7980 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7981 _("relocation overflow"));
7983 gold_info(_("try relinking with a smaller --stub-group-size"));
7989 // Relocate section data.
7991 template<int size
, bool big_endian
>
7993 Target_powerpc
<size
, big_endian
>::relocate_section(
7994 const Relocate_info
<size
, big_endian
>* relinfo
,
7995 unsigned int sh_type
,
7996 const unsigned char* prelocs
,
7998 Output_section
* output_section
,
7999 bool needs_special_offset_handling
,
8000 unsigned char* view
,
8002 section_size_type view_size
,
8003 const Reloc_symbol_changes
* reloc_symbol_changes
)
8005 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8006 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
8007 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
8008 Powerpc_comdat_behavior
;
8010 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8012 gold::relocate_section
<size
, big_endian
, Powerpc
, elfcpp::SHT_RELA
,
8013 Powerpc_relocate
, Powerpc_comdat_behavior
>(
8019 needs_special_offset_handling
,
8023 reloc_symbol_changes
);
8026 class Powerpc_scan_relocatable_reloc
8029 // Return the strategy to use for a local symbol which is not a
8030 // section symbol, given the relocation type.
8031 inline Relocatable_relocs::Reloc_strategy
8032 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
8034 if (r_type
== 0 && r_sym
== 0)
8035 return Relocatable_relocs::RELOC_DISCARD
;
8036 return Relocatable_relocs::RELOC_COPY
;
8039 // Return the strategy to use for a local symbol which is a section
8040 // symbol, given the relocation type.
8041 inline Relocatable_relocs::Reloc_strategy
8042 local_section_strategy(unsigned int, Relobj
*)
8044 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
8047 // Return the strategy to use for a global symbol, given the
8048 // relocation type, the object, and the symbol index.
8049 inline Relocatable_relocs::Reloc_strategy
8050 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
8052 if (r_type
== elfcpp::R_PPC_PLTREL24
)
8053 return Relocatable_relocs::RELOC_SPECIAL
;
8054 return Relocatable_relocs::RELOC_COPY
;
8058 // Scan the relocs during a relocatable link.
8060 template<int size
, bool big_endian
>
8062 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
8063 Symbol_table
* symtab
,
8065 Sized_relobj_file
<size
, big_endian
>* object
,
8066 unsigned int data_shndx
,
8067 unsigned int sh_type
,
8068 const unsigned char* prelocs
,
8070 Output_section
* output_section
,
8071 bool needs_special_offset_handling
,
8072 size_t local_symbol_count
,
8073 const unsigned char* plocal_symbols
,
8074 Relocatable_relocs
* rr
)
8076 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8078 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
8079 Powerpc_scan_relocatable_reloc
>(
8087 needs_special_offset_handling
,
8093 // Emit relocations for a section.
8094 // This is a modified version of the function by the same name in
8095 // target-reloc.h. Using relocate_special_relocatable for
8096 // R_PPC_PLTREL24 would require duplication of the entire body of the
8097 // loop, so we may as well duplicate the whole thing.
8099 template<int size
, bool big_endian
>
8101 Target_powerpc
<size
, big_endian
>::relocate_relocs(
8102 const Relocate_info
<size
, big_endian
>* relinfo
,
8103 unsigned int sh_type
,
8104 const unsigned char* prelocs
,
8106 Output_section
* output_section
,
8107 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
8108 const Relocatable_relocs
* rr
,
8110 Address view_address
,
8112 unsigned char* reloc_view
,
8113 section_size_type reloc_view_size
)
8115 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8117 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
8119 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
8121 const int reloc_size
8122 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
8124 Powerpc_relobj
<size
, big_endian
>* const object
8125 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
8126 const unsigned int local_count
= object
->local_symbol_count();
8127 unsigned int got2_shndx
= object
->got2_shndx();
8128 Address got2_addend
= 0;
8129 if (got2_shndx
!= 0)
8131 got2_addend
= object
->get_output_section_offset(got2_shndx
);
8132 gold_assert(got2_addend
!= invalid_address
);
8135 unsigned char* pwrite
= reloc_view
;
8136 bool zap_next
= false;
8137 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
8139 Relocatable_relocs::Reloc_strategy strategy
= rr
->strategy(i
);
8140 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
8143 Reltype
reloc(prelocs
);
8144 Reltype_write
reloc_write(pwrite
);
8146 Address offset
= reloc
.get_r_offset();
8147 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
8148 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8149 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
8150 const unsigned int orig_r_sym
= r_sym
;
8151 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
8152 = reloc
.get_r_addend();
8153 const Symbol
* gsym
= NULL
;
8157 // We could arrange to discard these and other relocs for
8158 // tls optimised sequences in the strategy methods, but for
8159 // now do as BFD ld does.
8160 r_type
= elfcpp::R_POWERPC_NONE
;
8164 // Get the new symbol index.
8165 Output_section
* os
= NULL
;
8166 if (r_sym
< local_count
)
8170 case Relocatable_relocs::RELOC_COPY
:
8171 case Relocatable_relocs::RELOC_SPECIAL
:
8174 r_sym
= object
->symtab_index(r_sym
);
8175 gold_assert(r_sym
!= -1U);
8179 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
8181 // We are adjusting a section symbol. We need to find
8182 // the symbol table index of the section symbol for
8183 // the output section corresponding to input section
8184 // in which this symbol is defined.
8185 gold_assert(r_sym
< local_count
);
8187 unsigned int shndx
=
8188 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8189 gold_assert(is_ordinary
);
8190 os
= object
->output_section(shndx
);
8191 gold_assert(os
!= NULL
);
8192 gold_assert(os
->needs_symtab_index());
8193 r_sym
= os
->symtab_index();
8203 gsym
= object
->global_symbol(r_sym
);
8204 gold_assert(gsym
!= NULL
);
8205 if (gsym
->is_forwarder())
8206 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
8208 gold_assert(gsym
->has_symtab_index());
8209 r_sym
= gsym
->symtab_index();
8212 // Get the new offset--the location in the output section where
8213 // this relocation should be applied.
8214 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8215 offset
+= offset_in_output_section
;
8218 section_offset_type sot_offset
=
8219 convert_types
<section_offset_type
, Address
>(offset
);
8220 section_offset_type new_sot_offset
=
8221 output_section
->output_offset(object
, relinfo
->data_shndx
,
8223 gold_assert(new_sot_offset
!= -1);
8224 offset
= new_sot_offset
;
8227 // In an object file, r_offset is an offset within the section.
8228 // In an executable or dynamic object, generated by
8229 // --emit-relocs, r_offset is an absolute address.
8230 if (!parameters
->options().relocatable())
8232 offset
+= view_address
;
8233 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8234 offset
-= offset_in_output_section
;
8237 // Handle the reloc addend based on the strategy.
8238 if (strategy
== Relocatable_relocs::RELOC_COPY
)
8240 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
8242 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
8243 gold_assert(os
!= NULL
);
8244 addend
= psymval
->value(object
, addend
) - os
->address();
8246 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
8248 if (addend
>= 32768)
8249 addend
+= got2_addend
;
8254 if (!parameters
->options().relocatable())
8256 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8257 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
8258 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
8259 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
8261 // First instruction of a global dynamic sequence,
8263 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8264 switch (this->optimize_tls_gd(final
))
8266 case tls::TLSOPT_TO_IE
:
8267 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
8268 - elfcpp::R_POWERPC_GOT_TLSGD16
);
8270 case tls::TLSOPT_TO_LE
:
8271 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8272 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8273 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8276 r_type
= elfcpp::R_POWERPC_NONE
;
8277 offset
-= 2 * big_endian
;
8284 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8285 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
8286 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
8287 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
8289 // First instruction of a local dynamic sequence,
8291 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8293 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8294 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
8296 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8297 const Output_section
* os
= relinfo
->layout
->tls_segment()
8299 gold_assert(os
!= NULL
);
8300 gold_assert(os
->needs_symtab_index());
8301 r_sym
= os
->symtab_index();
8302 addend
= dtp_offset
;
8306 r_type
= elfcpp::R_POWERPC_NONE
;
8307 offset
-= 2 * big_endian
;
8311 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8312 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
8313 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
8314 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8316 // First instruction of initial exec sequence.
8317 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8318 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8320 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8321 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8322 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8325 r_type
= elfcpp::R_POWERPC_NONE
;
8326 offset
-= 2 * big_endian
;
8330 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8331 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8333 // Second instruction of a global dynamic sequence,
8334 // the __tls_get_addr call
8335 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8336 switch (this->optimize_tls_gd(final
))
8338 case tls::TLSOPT_TO_IE
:
8339 r_type
= elfcpp::R_POWERPC_NONE
;
8342 case tls::TLSOPT_TO_LE
:
8343 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8344 offset
+= 2 * big_endian
;
8351 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8352 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8354 // Second instruction of a local dynamic sequence,
8355 // the __tls_get_addr call
8356 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8358 const Output_section
* os
= relinfo
->layout
->tls_segment()
8360 gold_assert(os
!= NULL
);
8361 gold_assert(os
->needs_symtab_index());
8362 r_sym
= os
->symtab_index();
8363 addend
= dtp_offset
;
8364 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8365 offset
+= 2 * big_endian
;
8369 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8371 // Second instruction of an initial exec sequence
8372 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8373 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8375 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8376 offset
+= 2 * big_endian
;
8381 reloc_write
.put_r_offset(offset
);
8382 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
8383 reloc_write
.put_r_addend(addend
);
8385 pwrite
+= reloc_size
;
8388 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
8389 == reloc_view_size
);
8392 // Return the value to use for a dynamic symbol which requires special
8393 // treatment. This is how we support equality comparisons of function
8394 // pointers across shared library boundaries, as described in the
8395 // processor specific ABI supplement.
8397 template<int size
, bool big_endian
>
8399 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8403 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
8404 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8405 p
!= this->stub_tables_
.end();
8408 Address off
= (*p
)->find_plt_call_entry(gsym
);
8409 if (off
!= invalid_address
)
8410 return (*p
)->stub_address() + off
;
8413 else if (this->abiversion() >= 2)
8415 Address off
= this->glink_section()->find_global_entry(gsym
);
8416 if (off
!= invalid_address
)
8417 return this->glink_section()->global_entry_address() + off
;
8422 // Return the PLT address to use for a local symbol.
8423 template<int size
, bool big_endian
>
8425 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
8426 const Relobj
* object
,
8427 unsigned int symndx
) const
8431 const Sized_relobj
<size
, big_endian
>* relobj
8432 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
8433 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8434 p
!= this->stub_tables_
.end();
8437 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
8439 if (off
!= invalid_address
)
8440 return (*p
)->stub_address() + off
;
8446 // Return the PLT address to use for a global symbol.
8447 template<int size
, bool big_endian
>
8449 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
8450 const Symbol
* gsym
) const
8454 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8455 p
!= this->stub_tables_
.end();
8458 Address off
= (*p
)->find_plt_call_entry(gsym
);
8459 if (off
!= invalid_address
)
8460 return (*p
)->stub_address() + off
;
8463 else if (this->abiversion() >= 2)
8465 Address off
= this->glink_section()->find_global_entry(gsym
);
8466 if (off
!= invalid_address
)
8467 return this->glink_section()->global_entry_address() + off
;
8472 // Return the offset to use for the GOT_INDX'th got entry which is
8473 // for a local tls symbol specified by OBJECT, SYMNDX.
8474 template<int size
, bool big_endian
>
8476 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
8477 const Relobj
* object
,
8478 unsigned int symndx
,
8479 unsigned int got_indx
) const
8481 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8482 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
8483 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
8485 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8486 got_type
<= GOT_TYPE_TPREL
;
8487 got_type
= Got_type(got_type
+ 1))
8488 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
8490 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
8491 if (got_type
== GOT_TYPE_TLSGD
)
8493 if (off
== got_indx
* (size
/ 8))
8495 if (got_type
== GOT_TYPE_TPREL
)
8505 // Return the offset to use for the GOT_INDX'th got entry which is
8506 // for global tls symbol GSYM.
8507 template<int size
, bool big_endian
>
8509 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
8511 unsigned int got_indx
) const
8513 if (gsym
->type() == elfcpp::STT_TLS
)
8515 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8516 got_type
<= GOT_TYPE_TPREL
;
8517 got_type
= Got_type(got_type
+ 1))
8518 if (gsym
->has_got_offset(got_type
))
8520 unsigned int off
= gsym
->got_offset(got_type
);
8521 if (got_type
== GOT_TYPE_TLSGD
)
8523 if (off
== got_indx
* (size
/ 8))
8525 if (got_type
== GOT_TYPE_TPREL
)
8535 // The selector for powerpc object files.
8537 template<int size
, bool big_endian
>
8538 class Target_selector_powerpc
: public Target_selector
8541 Target_selector_powerpc()
8542 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
8545 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
8546 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
8548 ? (big_endian
? "elf64ppc" : "elf64lppc")
8549 : (big_endian
? "elf32ppc" : "elf32lppc")))
8553 do_instantiate_target()
8554 { return new Target_powerpc
<size
, big_endian
>(); }
8557 Target_selector_powerpc
<32, true> target_selector_ppc32
;
8558 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
8559 Target_selector_powerpc
<64, true> target_selector_ppc64
;
8560 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
8562 // Instantiate these constants for -O0
8563 template<int size
, bool big_endian
>
8564 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
8565 template<int size
, bool big_endian
>
8566 const typename Output_data_glink
<size
, big_endian
>::Address
8567 Output_data_glink
<size
, big_endian
>::invalid_address
;
8568 template<int size
, bool big_endian
>
8569 const typename Stub_table
<size
, big_endian
>::Address
8570 Stub_table
<size
, big_endian
>::invalid_address
;
8571 template<int size
, bool big_endian
>
8572 const typename Target_powerpc
<size
, big_endian
>::Address
8573 Target_powerpc
<size
, big_endian
>::invalid_address
;
8575 } // End anonymous namespace.