1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright (C) 2008-2016 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_powerpc
;
53 template<int size
, bool big_endian
>
54 class Output_data_brlt_powerpc
;
56 template<int size
, bool big_endian
>
57 class Output_data_got_powerpc
;
59 template<int size
, bool big_endian
>
60 class Output_data_glink
;
62 template<int size
, bool big_endian
>
65 template<int size
, bool big_endian
>
66 class Output_data_save_res
;
68 template<int size
, bool big_endian
>
71 struct Stub_table_owner
74 : output_section(NULL
), owner(NULL
)
77 Output_section
* output_section
;
78 const Output_section::Input_section
* owner
;
82 is_branch_reloc(unsigned int r_type
);
84 template<int size
, bool big_endian
>
85 class Powerpc_relobj
: public Sized_relobj_file
<size
, big_endian
>
88 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
89 typedef Unordered_set
<Section_id
, Section_id_hash
> Section_refs
;
90 typedef Unordered_map
<Address
, Section_refs
> Access_from
;
92 Powerpc_relobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
93 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
94 : Sized_relobj_file
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
95 special_(0), has_small_toc_reloc_(false), opd_valid_(false),
96 opd_ent_(), access_from_map_(), has14_(), stub_table_index_(),
97 e_flags_(ehdr
.get_e_flags()), st_other_()
99 this->set_abiversion(0);
105 // Read the symbols then set up st_other vector.
107 do_read_symbols(Read_symbols_data
*);
109 // The .got2 section shndx.
114 return this->special_
;
119 // The .opd section shndx.
126 return this->special_
;
129 // Init OPD entry arrays.
131 init_opd(size_t opd_size
)
133 size_t count
= this->opd_ent_ndx(opd_size
);
134 this->opd_ent_
.resize(count
);
137 // Return section and offset of function entry for .opd + R_OFF.
139 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
141 size_t ndx
= this->opd_ent_ndx(r_off
);
142 gold_assert(ndx
< this->opd_ent_
.size());
143 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
145 *value
= this->opd_ent_
[ndx
].off
;
146 return this->opd_ent_
[ndx
].shndx
;
149 // Set section and offset of function entry for .opd + R_OFF.
151 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
153 size_t ndx
= this->opd_ent_ndx(r_off
);
154 gold_assert(ndx
< this->opd_ent_
.size());
155 this->opd_ent_
[ndx
].shndx
= shndx
;
156 this->opd_ent_
[ndx
].off
= value
;
159 // Return discard flag for .opd + R_OFF.
161 get_opd_discard(Address r_off
) const
163 size_t ndx
= this->opd_ent_ndx(r_off
);
164 gold_assert(ndx
< this->opd_ent_
.size());
165 return this->opd_ent_
[ndx
].discard
;
168 // Set discard flag for .opd + R_OFF.
170 set_opd_discard(Address r_off
)
172 size_t ndx
= this->opd_ent_ndx(r_off
);
173 gold_assert(ndx
< this->opd_ent_
.size());
174 this->opd_ent_
[ndx
].discard
= true;
179 { return this->opd_valid_
; }
183 { this->opd_valid_
= true; }
185 // Examine .rela.opd to build info about function entry points.
187 scan_opd_relocs(size_t reloc_count
,
188 const unsigned char* prelocs
,
189 const unsigned char* plocal_syms
);
191 // Perform the Sized_relobj_file method, then set up opd info from
194 do_read_relocs(Read_relocs_data
*);
197 do_find_special_sections(Read_symbols_data
* sd
);
199 // Adjust this local symbol value. Return false if the symbol
200 // should be discarded from the output file.
202 do_adjust_local_symbol(Symbol_value
<size
>* lv
) const
204 if (size
== 64 && this->opd_shndx() != 0)
207 if (lv
->input_shndx(&is_ordinary
) != this->opd_shndx())
209 if (this->get_opd_discard(lv
->input_value()))
217 { return &this->access_from_map_
; }
219 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
220 // section at DST_OFF.
222 add_reference(Relobj
* src_obj
,
223 unsigned int src_indx
,
224 typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
226 Section_id
src_id(src_obj
, src_indx
);
227 this->access_from_map_
[dst_off
].insert(src_id
);
230 // Add a reference to the code section specified by the .opd entry
233 add_gc_mark(typename
elfcpp::Elf_types
<size
>::Elf_Addr dst_off
)
235 size_t ndx
= this->opd_ent_ndx(dst_off
);
236 if (ndx
>= this->opd_ent_
.size())
237 this->opd_ent_
.resize(ndx
+ 1);
238 this->opd_ent_
[ndx
].gc_mark
= true;
242 process_gc_mark(Symbol_table
* symtab
)
244 for (size_t i
= 0; i
< this->opd_ent_
.size(); i
++)
245 if (this->opd_ent_
[i
].gc_mark
)
247 unsigned int shndx
= this->opd_ent_
[i
].shndx
;
248 symtab
->gc()->worklist().push_back(Section_id(this, shndx
));
252 // Return offset in output GOT section that this object will use
253 // as a TOC pointer. Won't be just a constant with multi-toc support.
255 toc_base_offset() const
259 set_has_small_toc_reloc()
260 { has_small_toc_reloc_
= true; }
263 has_small_toc_reloc() const
264 { return has_small_toc_reloc_
; }
267 set_has_14bit_branch(unsigned int shndx
)
269 if (shndx
>= this->has14_
.size())
270 this->has14_
.resize(shndx
+ 1);
271 this->has14_
[shndx
] = true;
275 has_14bit_branch(unsigned int shndx
) const
276 { return shndx
< this->has14_
.size() && this->has14_
[shndx
]; }
279 set_stub_table(unsigned int shndx
, unsigned int stub_index
)
281 if (shndx
>= this->stub_table_index_
.size())
282 this->stub_table_index_
.resize(shndx
+ 1, -1);
283 this->stub_table_index_
[shndx
] = stub_index
;
286 Stub_table
<size
, big_endian
>*
287 stub_table(unsigned int shndx
)
289 if (shndx
< this->stub_table_index_
.size())
291 Target_powerpc
<size
, big_endian
>* target
292 = static_cast<Target_powerpc
<size
, big_endian
>*>(
293 parameters
->sized_target
<size
, big_endian
>());
294 unsigned int indx
= this->stub_table_index_
[shndx
];
295 gold_assert(indx
< target
->stub_tables().size());
296 return target
->stub_tables()[indx
];
304 this->stub_table_index_
.clear();
309 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
311 // Set ABI version for input and output
313 set_abiversion(int ver
);
316 ppc64_local_entry_offset(const Symbol
* sym
) const
317 { return elfcpp::ppc64_decode_local_entry(sym
->nonvis() >> 3); }
320 ppc64_local_entry_offset(unsigned int symndx
) const
321 { return elfcpp::ppc64_decode_local_entry(this->st_other_
[symndx
] >> 5); }
332 // Return index into opd_ent_ array for .opd entry at OFF.
333 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
334 // apart when the language doesn't use the last 8-byte word, the
335 // environment pointer. Thus dividing the entry section offset by
336 // 16 will give an index into opd_ent_ that works for either layout
337 // of .opd. (It leaves some elements of the vector unused when .opd
338 // entries are spaced 24 bytes apart, but we don't know the spacing
339 // until relocations are processed, and in any case it is possible
340 // for an object to have some entries spaced 16 bytes apart and
341 // others 24 bytes apart.)
343 opd_ent_ndx(size_t off
) const
346 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
347 unsigned int special_
;
349 // For 64-bit, whether this object uses small model relocs to access
351 bool has_small_toc_reloc_
;
353 // Set at the start of gc_process_relocs, when we know opd_ent_
354 // vector is valid. The flag could be made atomic and set in
355 // do_read_relocs with memory_order_release and then tested with
356 // memory_order_acquire, potentially resulting in fewer entries in
360 // The first 8-byte word of an OPD entry gives the address of the
361 // entry point of the function. Relocatable object files have a
362 // relocation on this word. The following vector records the
363 // section and offset specified by these relocations.
364 std::vector
<Opd_ent
> opd_ent_
;
366 // References made to this object's .opd section when running
367 // gc_process_relocs for another object, before the opd_ent_ vector
368 // is valid for this object.
369 Access_from access_from_map_
;
371 // Whether input section has a 14-bit branch reloc.
372 std::vector
<bool> has14_
;
374 // The stub table to use for a given input section.
375 std::vector
<unsigned int> stub_table_index_
;
378 elfcpp::Elf_Word e_flags_
;
380 // ELF st_other field for local symbols.
381 std::vector
<unsigned char> st_other_
;
384 template<int size
, bool big_endian
>
385 class Powerpc_dynobj
: public Sized_dynobj
<size
, big_endian
>
388 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
390 Powerpc_dynobj(const std::string
& name
, Input_file
* input_file
, off_t offset
,
391 const typename
elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
392 : Sized_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
),
393 opd_shndx_(0), opd_ent_(), e_flags_(ehdr
.get_e_flags())
395 this->set_abiversion(0);
401 // Call Sized_dynobj::do_read_symbols to read the symbols then
402 // read .opd from a dynamic object, filling in opd_ent_ vector,
404 do_read_symbols(Read_symbols_data
*);
406 // The .opd section shndx.
410 return this->opd_shndx_
;
413 // The .opd section address.
417 return this->opd_address_
;
420 // Init OPD entry arrays.
422 init_opd(size_t opd_size
)
424 size_t count
= this->opd_ent_ndx(opd_size
);
425 this->opd_ent_
.resize(count
);
428 // Return section and offset of function entry for .opd + R_OFF.
430 get_opd_ent(Address r_off
, Address
* value
= NULL
) const
432 size_t ndx
= this->opd_ent_ndx(r_off
);
433 gold_assert(ndx
< this->opd_ent_
.size());
434 gold_assert(this->opd_ent_
[ndx
].shndx
!= 0);
436 *value
= this->opd_ent_
[ndx
].off
;
437 return this->opd_ent_
[ndx
].shndx
;
440 // Set section and offset of function entry for .opd + R_OFF.
442 set_opd_ent(Address r_off
, unsigned int shndx
, Address value
)
444 size_t ndx
= this->opd_ent_ndx(r_off
);
445 gold_assert(ndx
< this->opd_ent_
.size());
446 this->opd_ent_
[ndx
].shndx
= shndx
;
447 this->opd_ent_
[ndx
].off
= value
;
452 { return this->e_flags_
& elfcpp::EF_PPC64_ABI
; }
454 // Set ABI version for input and output.
456 set_abiversion(int ver
);
459 // Used to specify extent of executable sections.
462 Sec_info(Address start_
, Address len_
, unsigned int shndx_
)
463 : start(start_
), len(len_
), shndx(shndx_
)
467 operator<(const Sec_info
& that
) const
468 { return this->start
< that
.start
; }
481 // Return index into opd_ent_ array for .opd entry at OFF.
483 opd_ent_ndx(size_t off
) const
486 // For 64-bit the .opd section shndx and address.
487 unsigned int opd_shndx_
;
488 Address opd_address_
;
490 // The first 8-byte word of an OPD entry gives the address of the
491 // entry point of the function. Records the section and offset
492 // corresponding to the address. Note that in dynamic objects,
493 // offset is *not* relative to the section.
494 std::vector
<Opd_ent
> opd_ent_
;
497 elfcpp::Elf_Word e_flags_
;
500 template<int size
, bool big_endian
>
501 class Target_powerpc
: public Sized_target
<size
, big_endian
>
505 Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
506 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
507 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Signed_address
;
508 static const Address invalid_address
= static_cast<Address
>(0) - 1;
509 // Offset of tp and dtp pointers from start of TLS block.
510 static const Address tp_offset
= 0x7000;
511 static const Address dtp_offset
= 0x8000;
514 : Sized_target
<size
, big_endian
>(&powerpc_info
),
515 got_(NULL
), plt_(NULL
), iplt_(NULL
), brlt_section_(NULL
),
516 glink_(NULL
), rela_dyn_(NULL
), copy_relocs_(elfcpp::R_POWERPC_COPY
),
517 tlsld_got_offset_(-1U),
518 stub_tables_(), branch_lookup_table_(), branch_info_(),
519 plt_thread_safe_(false), relax_failed_(false), relax_fail_count_(0),
520 stub_group_size_(0), savres_section_(0)
524 // Process the relocations to determine unreferenced sections for
525 // garbage collection.
527 gc_process_relocs(Symbol_table
* symtab
,
529 Sized_relobj_file
<size
, big_endian
>* object
,
530 unsigned int data_shndx
,
531 unsigned int sh_type
,
532 const unsigned char* prelocs
,
534 Output_section
* output_section
,
535 bool needs_special_offset_handling
,
536 size_t local_symbol_count
,
537 const unsigned char* plocal_symbols
);
539 // Scan the relocations to look for symbol adjustments.
541 scan_relocs(Symbol_table
* symtab
,
543 Sized_relobj_file
<size
, big_endian
>* object
,
544 unsigned int data_shndx
,
545 unsigned int sh_type
,
546 const unsigned char* prelocs
,
548 Output_section
* output_section
,
549 bool needs_special_offset_handling
,
550 size_t local_symbol_count
,
551 const unsigned char* plocal_symbols
);
553 // Map input .toc section to output .got section.
555 do_output_section_name(const Relobj
*, const char* name
, size_t* plen
) const
557 if (size
== 64 && strcmp(name
, ".toc") == 0)
565 // Provide linker defined save/restore functions.
567 define_save_restore_funcs(Layout
*, Symbol_table
*);
569 // No stubs unless a final link.
572 { return !parameters
->options().relocatable(); }
575 do_relax(int, const Input_objects
*, Symbol_table
*, Layout
*, const Task
*);
578 do_plt_fde_location(const Output_data
*, unsigned char*,
579 uint64_t*, off_t
*) const;
581 // Stash info about branches, for stub generation.
583 push_branch(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
584 unsigned int data_shndx
, Address r_offset
,
585 unsigned int r_type
, unsigned int r_sym
, Address addend
)
587 Branch_info
info(ppc_object
, data_shndx
, r_offset
, r_type
, r_sym
, addend
);
588 this->branch_info_
.push_back(info
);
589 if (r_type
== elfcpp::R_POWERPC_REL14
590 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
591 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
592 ppc_object
->set_has_14bit_branch(data_shndx
);
596 do_define_standard_symbols(Symbol_table
*, Layout
*);
598 // Finalize the sections.
600 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
602 // Return the value to use for a dynamic which requires special
605 do_dynsym_value(const Symbol
*) const;
607 // Return the PLT address to use for a local symbol.
609 do_plt_address_for_local(const Relobj
*, unsigned int) const;
611 // Return the PLT address to use for a global symbol.
613 do_plt_address_for_global(const Symbol
*) const;
615 // Return the offset to use for the GOT_INDX'th got entry which is
616 // for a local tls symbol specified by OBJECT, SYMNDX.
618 do_tls_offset_for_local(const Relobj
* object
,
620 unsigned int got_indx
) const;
622 // Return the offset to use for the GOT_INDX'th got entry which is
623 // for global tls symbol GSYM.
625 do_tls_offset_for_global(Symbol
* gsym
, unsigned int got_indx
) const;
628 do_function_location(Symbol_location
*) const;
631 do_can_check_for_function_pointers() const
634 // Adjust -fsplit-stack code which calls non-split-stack code.
636 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
637 section_offset_type fnoffset
, section_size_type fnsize
,
638 const unsigned char* prelocs
, size_t reloc_count
,
639 unsigned char* view
, section_size_type view_size
,
640 std::string
* from
, std::string
* to
) const;
642 // Relocate a section.
644 relocate_section(const Relocate_info
<size
, big_endian
>*,
645 unsigned int sh_type
,
646 const unsigned char* prelocs
,
648 Output_section
* output_section
,
649 bool needs_special_offset_handling
,
651 Address view_address
,
652 section_size_type view_size
,
653 const Reloc_symbol_changes
*);
655 // Scan the relocs during a relocatable link.
657 scan_relocatable_relocs(Symbol_table
* symtab
,
659 Sized_relobj_file
<size
, big_endian
>* object
,
660 unsigned int data_shndx
,
661 unsigned int sh_type
,
662 const unsigned char* prelocs
,
664 Output_section
* output_section
,
665 bool needs_special_offset_handling
,
666 size_t local_symbol_count
,
667 const unsigned char* plocal_symbols
,
668 Relocatable_relocs
*);
670 // Scan the relocs for --emit-relocs.
672 emit_relocs_scan(Symbol_table
* symtab
,
674 Sized_relobj_file
<size
, big_endian
>* object
,
675 unsigned int data_shndx
,
676 unsigned int sh_type
,
677 const unsigned char* prelocs
,
679 Output_section
* output_section
,
680 bool needs_special_offset_handling
,
681 size_t local_symbol_count
,
682 const unsigned char* plocal_syms
,
683 Relocatable_relocs
* rr
);
685 // Emit relocations for a section.
687 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
688 unsigned int sh_type
,
689 const unsigned char* prelocs
,
691 Output_section
* output_section
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Off
693 offset_in_output_section
,
695 Address view_address
,
697 unsigned char* reloc_view
,
698 section_size_type reloc_view_size
);
700 // Return whether SYM is defined by the ABI.
702 do_is_defined_by_abi(const Symbol
* sym
) const
704 return strcmp(sym
->name(), "__tls_get_addr") == 0;
707 // Return the size of the GOT section.
711 gold_assert(this->got_
!= NULL
);
712 return this->got_
->data_size();
715 // Get the PLT section.
716 const Output_data_plt_powerpc
<size
, big_endian
>*
719 gold_assert(this->plt_
!= NULL
);
723 // Get the IPLT section.
724 const Output_data_plt_powerpc
<size
, big_endian
>*
727 gold_assert(this->iplt_
!= NULL
);
731 // Get the .glink section.
732 const Output_data_glink
<size
, big_endian
>*
733 glink_section() const
735 gold_assert(this->glink_
!= NULL
);
739 Output_data_glink
<size
, big_endian
>*
742 gold_assert(this->glink_
!= NULL
);
746 bool has_glink() const
747 { return this->glink_
!= NULL
; }
749 // Get the GOT section.
750 const Output_data_got_powerpc
<size
, big_endian
>*
753 gold_assert(this->got_
!= NULL
);
757 // Get the GOT section, creating it if necessary.
758 Output_data_got_powerpc
<size
, big_endian
>*
759 got_section(Symbol_table
*, Layout
*);
762 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
763 const elfcpp::Ehdr
<size
, big_endian
>&);
765 // Return the number of entries in the GOT.
767 got_entry_count() const
769 if (this->got_
== NULL
)
771 return this->got_size() / (size
/ 8);
774 // Return the number of entries in the PLT.
776 plt_entry_count() const;
778 // Return the offset of the first non-reserved PLT entry.
780 first_plt_entry_offset() const
784 if (this->abiversion() >= 2)
789 // Return the size of each PLT entry.
791 plt_entry_size() const
795 if (this->abiversion() >= 2)
800 Output_data_save_res
<size
, big_endian
>*
801 savres_section() const
803 return this->savres_section_
;
806 // Add any special sections for this symbol to the gc work list.
807 // For powerpc64, this adds the code section of a function
810 do_gc_mark_symbol(Symbol_table
* symtab
, Symbol
* sym
) const;
812 // Handle target specific gc actions when adding a gc reference from
813 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
814 // and DST_OFF. For powerpc64, this adds a referenc to the code
815 // section of a function descriptor.
817 do_gc_add_reference(Symbol_table
* symtab
,
819 unsigned int src_shndx
,
821 unsigned int dst_shndx
,
822 Address dst_off
) const;
824 typedef std::vector
<Stub_table
<size
, big_endian
>*> Stub_tables
;
827 { return this->stub_tables_
; }
829 const Output_data_brlt_powerpc
<size
, big_endian
>*
831 { return this->brlt_section_
; }
834 add_branch_lookup_table(Address to
)
836 unsigned int off
= this->branch_lookup_table_
.size() * (size
/ 8);
837 this->branch_lookup_table_
.insert(std::make_pair(to
, off
));
841 find_branch_lookup_table(Address to
)
843 typename
Branch_lookup_table::const_iterator p
844 = this->branch_lookup_table_
.find(to
);
845 return p
== this->branch_lookup_table_
.end() ? invalid_address
: p
->second
;
849 write_branch_lookup_table(unsigned char *oview
)
851 for (typename
Branch_lookup_table::const_iterator p
852 = this->branch_lookup_table_
.begin();
853 p
!= this->branch_lookup_table_
.end();
856 elfcpp::Swap
<size
, big_endian
>::writeval(oview
+ p
->second
, p
->first
);
861 plt_thread_safe() const
862 { return this->plt_thread_safe_
; }
866 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI
; }
869 set_abiversion (int ver
)
871 elfcpp::Elf_Word flags
= this->processor_specific_flags();
872 flags
&= ~elfcpp::EF_PPC64_ABI
;
873 flags
|= ver
& elfcpp::EF_PPC64_ABI
;
874 this->set_processor_specific_flags(flags
);
877 // Offset to to save stack slot
880 { return this->abiversion() < 2 ? 40 : 24; }
896 : tls_get_addr_(NOT_EXPECTED
),
897 relinfo_(NULL
), relnum_(0), r_offset_(0)
902 if (this->tls_get_addr_
!= NOT_EXPECTED
)
909 if (this->relinfo_
!= NULL
)
910 gold_error_at_location(this->relinfo_
, this->relnum_
, this->r_offset_
,
911 _("missing expected __tls_get_addr call"));
915 expect_tls_get_addr_call(
916 const Relocate_info
<size
, big_endian
>* relinfo
,
920 this->tls_get_addr_
= EXPECTED
;
921 this->relinfo_
= relinfo
;
922 this->relnum_
= relnum
;
923 this->r_offset_
= r_offset
;
927 expect_tls_get_addr_call()
928 { this->tls_get_addr_
= EXPECTED
; }
931 skip_next_tls_get_addr_call()
932 {this->tls_get_addr_
= SKIP
; }
935 maybe_skip_tls_get_addr_call(unsigned int r_type
, const Symbol
* gsym
)
937 bool is_tls_call
= ((r_type
== elfcpp::R_POWERPC_REL24
938 || r_type
== elfcpp::R_PPC_PLTREL24
)
940 && strcmp(gsym
->name(), "__tls_get_addr") == 0);
941 Tls_get_addr last_tls
= this->tls_get_addr_
;
942 this->tls_get_addr_
= NOT_EXPECTED
;
943 if (is_tls_call
&& last_tls
!= EXPECTED
)
945 else if (!is_tls_call
&& last_tls
!= NOT_EXPECTED
)
954 // What we're up to regarding calls to __tls_get_addr.
955 // On powerpc, the branch and link insn making a call to
956 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
957 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
958 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
959 // The marker relocation always comes first, and has the same
960 // symbol as the reloc on the insn setting up the __tls_get_addr
961 // argument. This ties the arg setup insn with the call insn,
962 // allowing ld to safely optimize away the call. We check that
963 // every call to __tls_get_addr has a marker relocation, and that
964 // every marker relocation is on a call to __tls_get_addr.
965 Tls_get_addr tls_get_addr_
;
966 // Info about the last reloc for error message.
967 const Relocate_info
<size
, big_endian
>* relinfo_
;
972 // The class which scans relocations.
973 class Scan
: protected Track_tls
976 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
979 : Track_tls(), issued_non_pic_error_(false)
983 get_reference_flags(unsigned int r_type
, const Target_powerpc
* target
);
986 local(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
987 Sized_relobj_file
<size
, big_endian
>* object
,
988 unsigned int data_shndx
,
989 Output_section
* output_section
,
990 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
991 const elfcpp::Sym
<size
, big_endian
>& lsym
,
995 global(Symbol_table
* symtab
, Layout
* layout
, Target_powerpc
* target
,
996 Sized_relobj_file
<size
, big_endian
>* object
,
997 unsigned int data_shndx
,
998 Output_section
* output_section
,
999 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
1003 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1005 Sized_relobj_file
<size
, big_endian
>* relobj
,
1008 const elfcpp::Rela
<size
, big_endian
>& ,
1009 unsigned int r_type
,
1010 const elfcpp::Sym
<size
, big_endian
>&)
1012 // PowerPC64 .opd is not folded, so any identical function text
1013 // may be folded and we'll still keep function addresses distinct.
1014 // That means no reloc is of concern here.
1017 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1018 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1019 if (ppcobj
->abiversion() == 1)
1022 // For 32-bit and ELFv2, conservatively assume anything but calls to
1023 // function code might be taking the address of the function.
1024 return !is_branch_reloc(r_type
);
1028 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
1030 Sized_relobj_file
<size
, big_endian
>* relobj
,
1033 const elfcpp::Rela
<size
, big_endian
>& ,
1034 unsigned int r_type
,
1040 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
1041 <Powerpc_relobj
<size
, big_endian
>*>(relobj
);
1042 if (ppcobj
->abiversion() == 1)
1045 return !is_branch_reloc(r_type
);
1049 reloc_needs_plt_for_ifunc(Target_powerpc
<size
, big_endian
>* target
,
1050 Sized_relobj_file
<size
, big_endian
>* object
,
1051 unsigned int r_type
, bool report_err
);
1055 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
1056 unsigned int r_type
);
1059 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
1060 unsigned int r_type
, Symbol
*);
1063 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
1064 Target_powerpc
* target
);
1067 check_non_pic(Relobj
*, unsigned int r_type
);
1069 // Whether we have issued an error about a non-PIC compilation.
1070 bool issued_non_pic_error_
;
1074 symval_for_branch(const Symbol_table
* symtab
,
1075 const Sized_symbol
<size
>* gsym
,
1076 Powerpc_relobj
<size
, big_endian
>* object
,
1077 Address
*value
, unsigned int *dest_shndx
);
1079 // The class which implements relocation.
1080 class Relocate
: protected Track_tls
1083 // Use 'at' branch hints when true, 'y' when false.
1084 // FIXME maybe: set this with an option.
1085 static const bool is_isa_v2
= true;
1091 // Do a relocation. Return false if the caller should not issue
1092 // any warnings about this relocation.
1094 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
1095 Target_powerpc
*, Output_section
*, size_t, const unsigned char*,
1096 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
1097 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1101 class Relocate_comdat_behavior
1104 // Decide what the linker should do for relocations that refer to
1105 // discarded comdat sections.
1106 inline Comdat_behavior
1107 get(const char* name
)
1109 gold::Default_comdat_behavior default_behavior
;
1110 Comdat_behavior ret
= default_behavior
.get(name
);
1111 if (ret
== CB_WARNING
)
1114 && (strcmp(name
, ".fixup") == 0
1115 || strcmp(name
, ".got2") == 0))
1118 && (strcmp(name
, ".opd") == 0
1119 || strcmp(name
, ".toc") == 0
1120 || strcmp(name
, ".toc1") == 0))
1127 // Optimize the TLS relocation type based on what we know about the
1128 // symbol. IS_FINAL is true if the final address of this symbol is
1129 // known at link time.
1131 tls::Tls_optimization
1132 optimize_tls_gd(bool is_final
)
1134 // If we are generating a shared library, then we can't do anything
1136 if (parameters
->options().shared())
1137 return tls::TLSOPT_NONE
;
1140 return tls::TLSOPT_TO_IE
;
1141 return tls::TLSOPT_TO_LE
;
1144 tls::Tls_optimization
1147 if (parameters
->options().shared())
1148 return tls::TLSOPT_NONE
;
1150 return tls::TLSOPT_TO_LE
;
1153 tls::Tls_optimization
1154 optimize_tls_ie(bool is_final
)
1156 if (!is_final
|| parameters
->options().shared())
1157 return tls::TLSOPT_NONE
;
1159 return tls::TLSOPT_TO_LE
;
1164 make_glink_section(Layout
*);
1166 // Create the PLT section.
1168 make_plt_section(Symbol_table
*, Layout
*);
1171 make_iplt_section(Symbol_table
*, Layout
*);
1174 make_brlt_section(Layout
*);
1176 // Create a PLT entry for a global symbol.
1178 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1180 // Create a PLT entry for a local IFUNC symbol.
1182 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1183 Sized_relobj_file
<size
, big_endian
>*,
1187 // Create a GOT entry for local dynamic __tls_get_addr.
1189 tlsld_got_offset(Symbol_table
* symtab
, Layout
* layout
,
1190 Sized_relobj_file
<size
, big_endian
>* object
);
1193 tlsld_got_offset() const
1195 return this->tlsld_got_offset_
;
1198 // Get the dynamic reloc section, creating it if necessary.
1200 rela_dyn_section(Layout
*);
1202 // Similarly, but for ifunc symbols get the one for ifunc.
1204 rela_dyn_section(Symbol_table
*, Layout
*, bool for_ifunc
);
1206 // Copy a relocation against a global symbol.
1208 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1209 Sized_relobj_file
<size
, big_endian
>* object
,
1210 unsigned int shndx
, Output_section
* output_section
,
1211 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
1213 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1214 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1215 symtab
->get_sized_symbol
<size
>(sym
),
1216 object
, shndx
, output_section
,
1217 r_type
, reloc
.get_r_offset(),
1218 reloc
.get_r_addend(),
1219 this->rela_dyn_section(layout
));
1222 // Look over all the input sections, deciding where to place stubs.
1224 group_sections(Layout
*, const Task
*, bool);
1226 // Sort output sections by address.
1227 struct Sort_sections
1230 operator()(const Output_section
* sec1
, const Output_section
* sec2
)
1231 { return sec1
->address() < sec2
->address(); }
1237 Branch_info(Powerpc_relobj
<size
, big_endian
>* ppc_object
,
1238 unsigned int data_shndx
,
1240 unsigned int r_type
,
1243 : object_(ppc_object
), shndx_(data_shndx
), offset_(r_offset
),
1244 r_type_(r_type
), r_sym_(r_sym
), addend_(addend
)
1250 // If this branch needs a plt call stub, or a long branch stub, make one.
1252 make_stub(Stub_table
<size
, big_endian
>*,
1253 Stub_table
<size
, big_endian
>*,
1254 Symbol_table
*) const;
1257 // The branch location..
1258 Powerpc_relobj
<size
, big_endian
>* object_
;
1259 unsigned int shndx_
;
1261 // ..and the branch type and destination.
1262 unsigned int r_type_
;
1263 unsigned int r_sym_
;
1267 // Information about this specific target which we pass to the
1268 // general Target structure.
1269 static Target::Target_info powerpc_info
;
1271 // The types of GOT entries needed for this platform.
1272 // These values are exposed to the ABI in an incremental link.
1273 // Do not renumber existing values without changing the version
1274 // number of the .gnu_incremental_inputs section.
1278 GOT_TYPE_TLSGD
, // double entry for @got@tlsgd
1279 GOT_TYPE_DTPREL
, // entry for @got@dtprel
1280 GOT_TYPE_TPREL
// entry for @got@tprel
1284 Output_data_got_powerpc
<size
, big_endian
>* got_
;
1285 // The PLT section. This is a container for a table of addresses,
1286 // and their relocations. Each address in the PLT has a dynamic
1287 // relocation (R_*_JMP_SLOT) and each address will have a
1288 // corresponding entry in .glink for lazy resolution of the PLT.
1289 // ppc32 initialises the PLT to point at the .glink entry, while
1290 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1291 // linker adds a stub that loads the PLT entry into ctr then
1292 // branches to ctr. There may be more than one stub for each PLT
1293 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1294 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1295 Output_data_plt_powerpc
<size
, big_endian
>* plt_
;
1296 // The IPLT section. Like plt_, this is a container for a table of
1297 // addresses and their relocations, specifically for STT_GNU_IFUNC
1298 // functions that resolve locally (STT_GNU_IFUNC functions that
1299 // don't resolve locally go in PLT). Unlike plt_, these have no
1300 // entry in .glink for lazy resolution, and the relocation section
1301 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1302 // the relocation section may contain relocations against
1303 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1304 // relocation section will appear at the end of other dynamic
1305 // relocations, so that ld.so applies these relocations after other
1306 // dynamic relocations. In a static executable, the relocation
1307 // section is emitted and marked with __rela_iplt_start and
1308 // __rela_iplt_end symbols.
1309 Output_data_plt_powerpc
<size
, big_endian
>* iplt_
;
1310 // Section holding long branch destinations.
1311 Output_data_brlt_powerpc
<size
, big_endian
>* brlt_section_
;
1312 // The .glink section.
1313 Output_data_glink
<size
, big_endian
>* glink_
;
1314 // The dynamic reloc section.
1315 Reloc_section
* rela_dyn_
;
1316 // Relocs saved to avoid a COPY reloc.
1317 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
1318 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1319 unsigned int tlsld_got_offset_
;
1321 Stub_tables stub_tables_
;
1322 typedef Unordered_map
<Address
, unsigned int> Branch_lookup_table
;
1323 Branch_lookup_table branch_lookup_table_
;
1325 typedef std::vector
<Branch_info
> Branches
;
1326 Branches branch_info_
;
1328 bool plt_thread_safe_
;
1331 int relax_fail_count_
;
1332 int32_t stub_group_size_
;
1334 Output_data_save_res
<size
, big_endian
> *savres_section_
;
1338 Target::Target_info Target_powerpc
<32, true>::powerpc_info
=
1341 true, // is_big_endian
1342 elfcpp::EM_PPC
, // machine_code
1343 false, // has_make_symbol
1344 false, // has_resolve
1345 false, // has_code_fill
1346 true, // is_default_stack_executable
1347 false, // can_icf_inline_merge_sections
1349 "/usr/lib/ld.so.1", // dynamic_linker
1350 0x10000000, // default_text_segment_address
1351 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1352 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1353 false, // isolate_execinstr
1355 elfcpp::SHN_UNDEF
, // small_common_shndx
1356 elfcpp::SHN_UNDEF
, // large_common_shndx
1357 0, // small_common_section_flags
1358 0, // large_common_section_flags
1359 NULL
, // attributes_section
1360 NULL
, // attributes_vendor
1361 "_start", // entry_symbol_name
1362 32, // hash_entry_size
1366 Target::Target_info Target_powerpc
<32, false>::powerpc_info
=
1369 false, // is_big_endian
1370 elfcpp::EM_PPC
, // machine_code
1371 false, // has_make_symbol
1372 false, // has_resolve
1373 false, // has_code_fill
1374 true, // is_default_stack_executable
1375 false, // can_icf_inline_merge_sections
1377 "/usr/lib/ld.so.1", // dynamic_linker
1378 0x10000000, // default_text_segment_address
1379 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1380 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1381 false, // isolate_execinstr
1383 elfcpp::SHN_UNDEF
, // small_common_shndx
1384 elfcpp::SHN_UNDEF
, // large_common_shndx
1385 0, // small_common_section_flags
1386 0, // large_common_section_flags
1387 NULL
, // attributes_section
1388 NULL
, // attributes_vendor
1389 "_start", // entry_symbol_name
1390 32, // hash_entry_size
1394 Target::Target_info Target_powerpc
<64, true>::powerpc_info
=
1397 true, // is_big_endian
1398 elfcpp::EM_PPC64
, // machine_code
1399 false, // has_make_symbol
1400 false, // has_resolve
1401 false, // has_code_fill
1402 true, // is_default_stack_executable
1403 false, // can_icf_inline_merge_sections
1405 "/usr/lib/ld.so.1", // dynamic_linker
1406 0x10000000, // default_text_segment_address
1407 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1408 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1409 false, // isolate_execinstr
1411 elfcpp::SHN_UNDEF
, // small_common_shndx
1412 elfcpp::SHN_UNDEF
, // large_common_shndx
1413 0, // small_common_section_flags
1414 0, // large_common_section_flags
1415 NULL
, // attributes_section
1416 NULL
, // attributes_vendor
1417 "_start", // entry_symbol_name
1418 32, // hash_entry_size
1422 Target::Target_info Target_powerpc
<64, false>::powerpc_info
=
1425 false, // is_big_endian
1426 elfcpp::EM_PPC64
, // machine_code
1427 false, // has_make_symbol
1428 false, // has_resolve
1429 false, // has_code_fill
1430 true, // is_default_stack_executable
1431 false, // can_icf_inline_merge_sections
1433 "/usr/lib/ld.so.1", // dynamic_linker
1434 0x10000000, // default_text_segment_address
1435 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1436 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1437 false, // isolate_execinstr
1439 elfcpp::SHN_UNDEF
, // small_common_shndx
1440 elfcpp::SHN_UNDEF
, // large_common_shndx
1441 0, // small_common_section_flags
1442 0, // large_common_section_flags
1443 NULL
, // attributes_section
1444 NULL
, // attributes_vendor
1445 "_start", // entry_symbol_name
1446 32, // hash_entry_size
1450 is_branch_reloc(unsigned int r_type
)
1452 return (r_type
== elfcpp::R_POWERPC_REL24
1453 || r_type
== elfcpp::R_PPC_PLTREL24
1454 || r_type
== elfcpp::R_PPC_LOCAL24PC
1455 || r_type
== elfcpp::R_POWERPC_REL14
1456 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
1457 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
1458 || r_type
== elfcpp::R_POWERPC_ADDR24
1459 || r_type
== elfcpp::R_POWERPC_ADDR14
1460 || r_type
== elfcpp::R_POWERPC_ADDR14_BRTAKEN
1461 || r_type
== elfcpp::R_POWERPC_ADDR14_BRNTAKEN
);
1464 // If INSN is an opcode that may be used with an @tls operand, return
1465 // the transformed insn for TLS optimisation, otherwise return 0. If
1466 // REG is non-zero only match an insn with RB or RA equal to REG.
1468 at_tls_transform(uint32_t insn
, unsigned int reg
)
1470 if ((insn
& (0x3f << 26)) != 31 << 26)
1474 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
1475 rtra
= insn
& ((1 << 26) - (1 << 16));
1476 else if (((insn
>> 16) & 0x1f) == reg
)
1477 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
1481 if ((insn
& (0x3ff << 1)) == 266 << 1)
1484 else if ((insn
& (0x1f << 1)) == 23 << 1
1485 && ((insn
& (0x1f << 6)) < 14 << 6
1486 || ((insn
& (0x1f << 6)) >= 16 << 6
1487 && (insn
& (0x1f << 6)) < 24 << 6)))
1488 // load and store indexed -> dform
1489 insn
= (32 | ((insn
>> 6) & 0x1f)) << 26;
1490 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1491 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1492 insn
= ((58 | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
1493 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1495 insn
= (58 << 26) | 2;
1503 template<int size
, bool big_endian
>
1504 class Powerpc_relocate_functions
1524 typedef Powerpc_relocate_functions
<size
, big_endian
> This
;
1525 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
1526 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword SignedAddress
;
1528 template<int valsize
>
1530 has_overflow_signed(Address value
)
1532 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1533 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1534 limit
<<= ((valsize
- 1) >> 1);
1535 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1536 return value
+ limit
> (limit
<< 1) - 1;
1539 template<int valsize
>
1541 has_overflow_unsigned(Address value
)
1543 Address limit
= static_cast<Address
>(1) << ((valsize
- 1) >> 1);
1544 limit
<<= ((valsize
- 1) >> 1);
1545 limit
<<= ((valsize
- 1) - 2 * ((valsize
- 1) >> 1));
1546 return value
> (limit
<< 1) - 1;
1549 template<int valsize
>
1551 has_overflow_bitfield(Address value
)
1553 return (has_overflow_unsigned
<valsize
>(value
)
1554 && has_overflow_signed
<valsize
>(value
));
1557 template<int valsize
>
1558 static inline Status
1559 overflowed(Address value
, Overflow_check overflow
)
1561 if (overflow
== CHECK_SIGNED
)
1563 if (has_overflow_signed
<valsize
>(value
))
1564 return STATUS_OVERFLOW
;
1566 else if (overflow
== CHECK_UNSIGNED
)
1568 if (has_overflow_unsigned
<valsize
>(value
))
1569 return STATUS_OVERFLOW
;
1571 else if (overflow
== CHECK_BITFIELD
)
1573 if (has_overflow_bitfield
<valsize
>(value
))
1574 return STATUS_OVERFLOW
;
1579 // Do a simple RELA relocation
1580 template<int fieldsize
, int valsize
>
1581 static inline Status
1582 rela(unsigned char* view
, Address value
, Overflow_check overflow
)
1584 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1585 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1586 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, value
);
1587 return overflowed
<valsize
>(value
, overflow
);
1590 template<int fieldsize
, int valsize
>
1591 static inline Status
1592 rela(unsigned char* view
,
1593 unsigned int right_shift
,
1594 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1596 Overflow_check overflow
)
1598 typedef typename
elfcpp::Swap
<fieldsize
, big_endian
>::Valtype Valtype
;
1599 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1600 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(wv
);
1601 Valtype reloc
= value
>> right_shift
;
1604 elfcpp::Swap
<fieldsize
, big_endian
>::writeval(wv
, val
| reloc
);
1605 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1608 // Do a simple RELA relocation, unaligned.
1609 template<int fieldsize
, int valsize
>
1610 static inline Status
1611 rela_ua(unsigned char* view
, Address value
, Overflow_check overflow
)
1613 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, value
);
1614 return overflowed
<valsize
>(value
, overflow
);
1617 template<int fieldsize
, int valsize
>
1618 static inline Status
1619 rela_ua(unsigned char* view
,
1620 unsigned int right_shift
,
1621 typename
elfcpp::Valtype_base
<fieldsize
>::Valtype dst_mask
,
1623 Overflow_check overflow
)
1625 typedef typename
elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::Valtype
1627 Valtype val
= elfcpp::Swap
<fieldsize
, big_endian
>::readval(view
);
1628 Valtype reloc
= value
>> right_shift
;
1631 elfcpp::Swap_unaligned
<fieldsize
, big_endian
>::writeval(view
, val
| reloc
);
1632 return overflowed
<valsize
>(value
>> right_shift
, overflow
);
1636 // R_PPC64_ADDR64: (Symbol + Addend)
1638 addr64(unsigned char* view
, Address value
)
1639 { This::template rela
<64,64>(view
, value
, CHECK_NONE
); }
1641 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1643 addr64_u(unsigned char* view
, Address value
)
1644 { This::template rela_ua
<64,64>(view
, value
, CHECK_NONE
); }
1646 // R_POWERPC_ADDR32: (Symbol + Addend)
1647 static inline Status
1648 addr32(unsigned char* view
, Address value
, Overflow_check overflow
)
1649 { return This::template rela
<32,32>(view
, value
, overflow
); }
1651 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1652 static inline Status
1653 addr32_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1654 { return This::template rela_ua
<32,32>(view
, value
, overflow
); }
1656 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1657 static inline Status
1658 addr24(unsigned char* view
, Address value
, Overflow_check overflow
)
1660 Status stat
= This::template rela
<32,26>(view
, 0, 0x03fffffc,
1662 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1663 stat
= STATUS_OVERFLOW
;
1667 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1668 static inline Status
1669 addr16(unsigned char* view
, Address value
, Overflow_check overflow
)
1670 { return This::template rela
<16,16>(view
, value
, overflow
); }
1672 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1673 static inline Status
1674 addr16_u(unsigned char* view
, Address value
, Overflow_check overflow
)
1675 { return This::template rela_ua
<16,16>(view
, value
, overflow
); }
1677 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1678 static inline Status
1679 addr16_ds(unsigned char* view
, Address value
, Overflow_check overflow
)
1681 Status stat
= This::template rela
<16,16>(view
, 0, 0xfffc, value
, overflow
);
1682 if ((value
& 3) != 0)
1683 stat
= STATUS_OVERFLOW
;
1687 // R_POWERPC_ADDR16_DQ: (Symbol + Addend) & 0xfff0
1688 static inline Status
1689 addr16_dq(unsigned char* view
, Address value
, Overflow_check overflow
)
1691 Status stat
= This::template rela
<16,16>(view
, 0, 0xfff0, value
, overflow
);
1692 if ((value
& 15) != 0)
1693 stat
= STATUS_OVERFLOW
;
1697 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1699 addr16_hi(unsigned char* view
, Address value
)
1700 { This::template rela
<16,16>(view
, 16, 0xffff, value
, CHECK_NONE
); }
1702 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1704 addr16_ha(unsigned char* view
, Address value
)
1705 { This::addr16_hi(view
, value
+ 0x8000); }
1707 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1709 addr16_hi2(unsigned char* view
, Address value
)
1710 { This::template rela
<16,16>(view
, 32, 0xffff, value
, CHECK_NONE
); }
1712 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1714 addr16_ha2(unsigned char* view
, Address value
)
1715 { This::addr16_hi2(view
, value
+ 0x8000); }
1717 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1719 addr16_hi3(unsigned char* view
, Address value
)
1720 { This::template rela
<16,16>(view
, 48, 0xffff, value
, CHECK_NONE
); }
1722 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1724 addr16_ha3(unsigned char* view
, Address value
)
1725 { This::addr16_hi3(view
, value
+ 0x8000); }
1727 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1728 static inline Status
1729 addr14(unsigned char* view
, Address value
, Overflow_check overflow
)
1731 Status stat
= This::template rela
<32,16>(view
, 0, 0xfffc, value
, overflow
);
1732 if (overflow
!= CHECK_NONE
&& (value
& 3) != 0)
1733 stat
= STATUS_OVERFLOW
;
1737 // R_POWERPC_REL16DX_HA
1738 static inline Status
1739 addr16dx_ha(unsigned char *view
, Address value
, Overflow_check overflow
)
1741 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
1742 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1743 Valtype val
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
1745 value
= static_cast<SignedAddress
>(value
) >> 16;
1746 val
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1747 elfcpp::Swap
<32, big_endian
>::writeval(wv
, val
);
1748 return overflowed
<16>(value
, overflow
);
1752 // Set ABI version for input and output.
1754 template<int size
, bool big_endian
>
1756 Powerpc_relobj
<size
, big_endian
>::set_abiversion(int ver
)
1758 this->e_flags_
|= ver
;
1759 if (this->abiversion() != 0)
1761 Target_powerpc
<size
, big_endian
>* target
=
1762 static_cast<Target_powerpc
<size
, big_endian
>*>(
1763 parameters
->sized_target
<size
, big_endian
>());
1764 if (target
->abiversion() == 0)
1765 target
->set_abiversion(this->abiversion());
1766 else if (target
->abiversion() != this->abiversion())
1767 gold_error(_("%s: ABI version %d is not compatible "
1768 "with ABI version %d output"),
1769 this->name().c_str(),
1770 this->abiversion(), target
->abiversion());
1775 // Stash away the index of .got2 or .opd in a relocatable object, if
1776 // such a section exists.
1778 template<int size
, bool big_endian
>
1780 Powerpc_relobj
<size
, big_endian
>::do_find_special_sections(
1781 Read_symbols_data
* sd
)
1783 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1784 const unsigned char* namesu
= sd
->section_names
->data();
1785 const char* names
= reinterpret_cast<const char*>(namesu
);
1786 section_size_type names_size
= sd
->section_names_size
;
1787 const unsigned char* s
;
1789 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
,
1790 size
== 32 ? ".got2" : ".opd",
1791 names
, names_size
, NULL
);
1794 unsigned int ndx
= (s
- pshdrs
) / elfcpp::Elf_sizes
<size
>::shdr_size
;
1795 this->special_
= ndx
;
1798 if (this->abiversion() == 0)
1799 this->set_abiversion(1);
1800 else if (this->abiversion() > 1)
1801 gold_error(_("%s: .opd invalid in abiv%d"),
1802 this->name().c_str(), this->abiversion());
1805 return Sized_relobj_file
<size
, big_endian
>::do_find_special_sections(sd
);
1808 // Examine .rela.opd to build info about function entry points.
1810 template<int size
, bool big_endian
>
1812 Powerpc_relobj
<size
, big_endian
>::scan_opd_relocs(
1814 const unsigned char* prelocs
,
1815 const unsigned char* plocal_syms
)
1819 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
1821 const int reloc_size
1822 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
1823 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1824 Address expected_off
= 0;
1825 bool regular
= true;
1826 unsigned int opd_ent_size
= 0;
1828 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
1830 Reltype
reloc(prelocs
);
1831 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
1832 = reloc
.get_r_info();
1833 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
1834 if (r_type
== elfcpp::R_PPC64_ADDR64
)
1836 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
1837 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
1840 if (r_sym
< this->local_symbol_count())
1842 typename
elfcpp::Sym
<size
, big_endian
>
1843 lsym(plocal_syms
+ r_sym
* sym_size
);
1844 shndx
= lsym
.get_st_shndx();
1845 shndx
= this->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1846 value
= lsym
.get_st_value();
1849 shndx
= this->symbol_section_and_value(r_sym
, &value
,
1851 this->set_opd_ent(reloc
.get_r_offset(), shndx
,
1852 value
+ reloc
.get_r_addend());
1855 expected_off
= reloc
.get_r_offset();
1856 opd_ent_size
= expected_off
;
1858 else if (expected_off
!= reloc
.get_r_offset())
1860 expected_off
+= opd_ent_size
;
1862 else if (r_type
== elfcpp::R_PPC64_TOC
)
1864 if (expected_off
- opd_ent_size
+ 8 != reloc
.get_r_offset())
1869 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1870 this->name().c_str(), r_type
);
1874 if (reloc_count
<= 2)
1875 opd_ent_size
= this->section_size(this->opd_shndx());
1876 if (opd_ent_size
!= 24 && opd_ent_size
!= 16)
1880 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1881 this->name().c_str());
1887 template<int size
, bool big_endian
>
1889 Powerpc_relobj
<size
, big_endian
>::do_read_relocs(Read_relocs_data
* rd
)
1891 Sized_relobj_file
<size
, big_endian
>::do_read_relocs(rd
);
1894 for (Read_relocs_data::Relocs_list::iterator p
= rd
->relocs
.begin();
1895 p
!= rd
->relocs
.end();
1898 if (p
->data_shndx
== this->opd_shndx())
1900 uint64_t opd_size
= this->section_size(this->opd_shndx());
1901 gold_assert(opd_size
== static_cast<size_t>(opd_size
));
1904 this->init_opd(opd_size
);
1905 this->scan_opd_relocs(p
->reloc_count
, p
->contents
->data(),
1906 rd
->local_symbols
->data());
1914 // Read the symbols then set up st_other vector.
1916 template<int size
, bool big_endian
>
1918 Powerpc_relobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1920 this->base_read_symbols(sd
);
1923 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1924 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1925 const unsigned int loccount
= this->do_local_symbol_count();
1928 this->st_other_
.resize(loccount
);
1929 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1930 off_t locsize
= loccount
* sym_size
;
1931 const unsigned int symtab_shndx
= this->symtab_shndx();
1932 const unsigned char *psymtab
= pshdrs
+ symtab_shndx
* shdr_size
;
1933 typename
elfcpp::Shdr
<size
, big_endian
> shdr(psymtab
);
1934 const unsigned char* psyms
= this->get_view(shdr
.get_sh_offset(),
1935 locsize
, true, false);
1937 for (unsigned int i
= 1; i
< loccount
; ++i
, psyms
+= sym_size
)
1939 elfcpp::Sym
<size
, big_endian
> sym(psyms
);
1940 unsigned char st_other
= sym
.get_st_other();
1941 this->st_other_
[i
] = st_other
;
1942 if ((st_other
& elfcpp::STO_PPC64_LOCAL_MASK
) != 0)
1944 if (this->abiversion() == 0)
1945 this->set_abiversion(2);
1946 else if (this->abiversion() < 2)
1947 gold_error(_("%s: local symbol %d has invalid st_other"
1948 " for ABI version 1"),
1949 this->name().c_str(), i
);
1956 template<int size
, bool big_endian
>
1958 Powerpc_dynobj
<size
, big_endian
>::set_abiversion(int ver
)
1960 this->e_flags_
|= ver
;
1961 if (this->abiversion() != 0)
1963 Target_powerpc
<size
, big_endian
>* target
=
1964 static_cast<Target_powerpc
<size
, big_endian
>*>(
1965 parameters
->sized_target
<size
, big_endian
>());
1966 if (target
->abiversion() == 0)
1967 target
->set_abiversion(this->abiversion());
1968 else if (target
->abiversion() != this->abiversion())
1969 gold_error(_("%s: ABI version %d is not compatible "
1970 "with ABI version %d output"),
1971 this->name().c_str(),
1972 this->abiversion(), target
->abiversion());
1977 // Call Sized_dynobj::base_read_symbols to read the symbols then
1978 // read .opd from a dynamic object, filling in opd_ent_ vector,
1980 template<int size
, bool big_endian
>
1982 Powerpc_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
* sd
)
1984 this->base_read_symbols(sd
);
1987 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
1988 const unsigned char* const pshdrs
= sd
->section_headers
->data();
1989 const unsigned char* namesu
= sd
->section_names
->data();
1990 const char* names
= reinterpret_cast<const char*>(namesu
);
1991 const unsigned char* s
= NULL
;
1992 const unsigned char* opd
;
1993 section_size_type opd_size
;
1995 // Find and read .opd section.
1998 s
= this->template find_shdr
<size
, big_endian
>(pshdrs
, ".opd", names
,
1999 sd
->section_names_size
,
2004 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2005 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2006 && (shdr
.get_sh_flags() & elfcpp::SHF_ALLOC
) != 0)
2008 if (this->abiversion() == 0)
2009 this->set_abiversion(1);
2010 else if (this->abiversion() > 1)
2011 gold_error(_("%s: .opd invalid in abiv%d"),
2012 this->name().c_str(), this->abiversion());
2014 this->opd_shndx_
= (s
- pshdrs
) / shdr_size
;
2015 this->opd_address_
= shdr
.get_sh_addr();
2016 opd_size
= convert_to_section_size_type(shdr
.get_sh_size());
2017 opd
= this->get_view(shdr
.get_sh_offset(), opd_size
,
2023 // Build set of executable sections.
2024 // Using a set is probably overkill. There is likely to be only
2025 // a few executable sections, typically .init, .text and .fini,
2026 // and they are generally grouped together.
2027 typedef std::set
<Sec_info
> Exec_sections
;
2028 Exec_sections exec_sections
;
2030 for (unsigned int i
= 1; i
< this->shnum(); ++i
, s
+= shdr_size
)
2032 typename
elfcpp::Shdr
<size
, big_endian
> shdr(s
);
2033 if (shdr
.get_sh_type() == elfcpp::SHT_PROGBITS
2034 && ((shdr
.get_sh_flags()
2035 & (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2036 == (elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
))
2037 && shdr
.get_sh_size() != 0)
2039 exec_sections
.insert(Sec_info(shdr
.get_sh_addr(),
2040 shdr
.get_sh_size(), i
));
2043 if (exec_sections
.empty())
2046 // Look over the OPD entries. This is complicated by the fact
2047 // that some binaries will use two-word entries while others
2048 // will use the standard three-word entries. In most cases
2049 // the third word (the environment pointer for languages like
2050 // Pascal) is unused and will be zero. If the third word is
2051 // used it should not be pointing into executable sections,
2053 this->init_opd(opd_size
);
2054 for (const unsigned char* p
= opd
; p
< opd
+ opd_size
; p
+= 8)
2056 typedef typename
elfcpp::Swap
<64, big_endian
>::Valtype Valtype
;
2057 const Valtype
* valp
= reinterpret_cast<const Valtype
*>(p
);
2058 Valtype val
= elfcpp::Swap
<64, big_endian
>::readval(valp
);
2060 // Chances are that this is the third word of an OPD entry.
2062 typename
Exec_sections::const_iterator e
2063 = exec_sections
.upper_bound(Sec_info(val
, 0, 0));
2064 if (e
!= exec_sections
.begin())
2067 if (e
->start
<= val
&& val
< e
->start
+ e
->len
)
2069 // We have an address in an executable section.
2070 // VAL ought to be the function entry, set it up.
2071 this->set_opd_ent(p
- opd
, e
->shndx
, val
);
2072 // Skip second word of OPD entry, the TOC pointer.
2076 // If we didn't match any executable sections, we likely
2077 // have a non-zero third word in the OPD entry.
2082 // Set up some symbols.
2084 template<int size
, bool big_endian
>
2086 Target_powerpc
<size
, big_endian
>::do_define_standard_symbols(
2087 Symbol_table
* symtab
,
2092 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2093 // undefined when scanning relocs (and thus requires
2094 // non-relative dynamic relocs). The proper value will be
2096 Symbol
*gotsym
= symtab
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2097 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2099 Target_powerpc
<size
, big_endian
>* target
=
2100 static_cast<Target_powerpc
<size
, big_endian
>*>(
2101 parameters
->sized_target
<size
, big_endian
>());
2102 Output_data_got_powerpc
<size
, big_endian
>* got
2103 = target
->got_section(symtab
, layout
);
2104 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2105 Symbol_table::PREDEFINED
,
2109 elfcpp::STV_HIDDEN
, 0,
2113 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2114 Symbol
*sdasym
= symtab
->lookup("_SDA_BASE_", NULL
);
2115 if (sdasym
!= NULL
&& sdasym
->is_undefined())
2117 Output_data_space
* sdata
= new Output_data_space(4, "** sdata");
2119 = layout
->add_output_section_data(".sdata", 0,
2121 | elfcpp::SHF_WRITE
,
2122 sdata
, ORDER_SMALL_DATA
, false);
2123 symtab
->define_in_output_data("_SDA_BASE_", NULL
,
2124 Symbol_table::PREDEFINED
,
2125 os
, 32768, 0, elfcpp::STT_OBJECT
,
2126 elfcpp::STB_LOCAL
, elfcpp::STV_HIDDEN
,
2132 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2133 Symbol
*gotsym
= symtab
->lookup(".TOC.", NULL
);
2134 if (gotsym
!= NULL
&& gotsym
->is_undefined())
2136 Target_powerpc
<size
, big_endian
>* target
=
2137 static_cast<Target_powerpc
<size
, big_endian
>*>(
2138 parameters
->sized_target
<size
, big_endian
>());
2139 Output_data_got_powerpc
<size
, big_endian
>* got
2140 = target
->got_section(symtab
, layout
);
2141 symtab
->define_in_output_data(".TOC.", NULL
,
2142 Symbol_table::PREDEFINED
,
2146 elfcpp::STV_HIDDEN
, 0,
2152 // Set up PowerPC target specific relobj.
2154 template<int size
, bool big_endian
>
2156 Target_powerpc
<size
, big_endian
>::do_make_elf_object(
2157 const std::string
& name
,
2158 Input_file
* input_file
,
2159 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
2161 int et
= ehdr
.get_e_type();
2162 // ET_EXEC files are valid input for --just-symbols/-R,
2163 // and we treat them as relocatable objects.
2164 if (et
== elfcpp::ET_REL
2165 || (et
== elfcpp::ET_EXEC
&& input_file
->just_symbols()))
2167 Powerpc_relobj
<size
, big_endian
>* obj
=
2168 new Powerpc_relobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2172 else if (et
== elfcpp::ET_DYN
)
2174 Powerpc_dynobj
<size
, big_endian
>* obj
=
2175 new Powerpc_dynobj
<size
, big_endian
>(name
, input_file
, offset
, ehdr
);
2181 gold_error(_("%s: unsupported ELF file type %d"), name
.c_str(), et
);
2186 template<int size
, bool big_endian
>
2187 class Output_data_got_powerpc
: public Output_data_got
<size
, big_endian
>
2190 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Valtype
;
2191 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Rela_dyn
;
2193 Output_data_got_powerpc(Symbol_table
* symtab
, Layout
* layout
)
2194 : Output_data_got
<size
, big_endian
>(),
2195 symtab_(symtab
), layout_(layout
),
2196 header_ent_cnt_(size
== 32 ? 3 : 1),
2197 header_index_(size
== 32 ? 0x2000 : 0)
2200 this->set_addralign(256);
2203 // Override all the Output_data_got methods we use so as to first call
2206 add_global(Symbol
* gsym
, unsigned int got_type
)
2208 this->reserve_ent();
2209 return Output_data_got
<size
, big_endian
>::add_global(gsym
, got_type
);
2213 add_global_plt(Symbol
* gsym
, unsigned int got_type
)
2215 this->reserve_ent();
2216 return Output_data_got
<size
, big_endian
>::add_global_plt(gsym
, got_type
);
2220 add_global_tls(Symbol
* gsym
, unsigned int got_type
)
2221 { return this->add_global_plt(gsym
, got_type
); }
2224 add_global_with_rel(Symbol
* gsym
, unsigned int got_type
,
2225 Output_data_reloc_generic
* rel_dyn
, unsigned int r_type
)
2227 this->reserve_ent();
2228 Output_data_got
<size
, big_endian
>::
2229 add_global_with_rel(gsym
, got_type
, rel_dyn
, r_type
);
2233 add_global_pair_with_rel(Symbol
* gsym
, unsigned int got_type
,
2234 Output_data_reloc_generic
* rel_dyn
,
2235 unsigned int r_type_1
, unsigned int r_type_2
)
2237 this->reserve_ent(2);
2238 Output_data_got
<size
, big_endian
>::
2239 add_global_pair_with_rel(gsym
, got_type
, rel_dyn
, r_type_1
, r_type_2
);
2243 add_local(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2245 this->reserve_ent();
2246 return Output_data_got
<size
, big_endian
>::add_local(object
, sym_index
,
2251 add_local_plt(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2253 this->reserve_ent();
2254 return Output_data_got
<size
, big_endian
>::add_local_plt(object
, sym_index
,
2259 add_local_tls(Relobj
* object
, unsigned int sym_index
, unsigned int got_type
)
2260 { return this->add_local_plt(object
, sym_index
, got_type
); }
2263 add_local_tls_pair(Relobj
* object
, unsigned int sym_index
,
2264 unsigned int got_type
,
2265 Output_data_reloc_generic
* rel_dyn
,
2266 unsigned int r_type
)
2268 this->reserve_ent(2);
2269 Output_data_got
<size
, big_endian
>::
2270 add_local_tls_pair(object
, sym_index
, got_type
, rel_dyn
, r_type
);
2274 add_constant(Valtype constant
)
2276 this->reserve_ent();
2277 return Output_data_got
<size
, big_endian
>::add_constant(constant
);
2281 add_constant_pair(Valtype c1
, Valtype c2
)
2283 this->reserve_ent(2);
2284 return Output_data_got
<size
, big_endian
>::add_constant_pair(c1
, c2
);
2287 // Offset of _GLOBAL_OFFSET_TABLE_.
2291 return this->got_offset(this->header_index_
);
2294 // Offset of base used to access the GOT/TOC.
2295 // The got/toc pointer reg will be set to this value.
2297 got_base_offset(const Powerpc_relobj
<size
, big_endian
>* object
) const
2300 return this->g_o_t();
2302 return (this->output_section()->address()
2303 + object
->toc_base_offset()
2307 // Ensure our GOT has a header.
2309 set_final_data_size()
2311 if (this->header_ent_cnt_
!= 0)
2312 this->make_header();
2313 Output_data_got
<size
, big_endian
>::set_final_data_size();
2316 // First word of GOT header needs some values that are not
2317 // handled by Output_data_got so poke them in here.
2318 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2320 do_write(Output_file
* of
)
2323 if (size
== 32 && this->layout_
->dynamic_data() != NULL
)
2324 val
= this->layout_
->dynamic_section()->address();
2326 val
= this->output_section()->address() + 0x8000;
2327 this->replace_constant(this->header_index_
, val
);
2328 Output_data_got
<size
, big_endian
>::do_write(of
);
2333 reserve_ent(unsigned int cnt
= 1)
2335 if (this->header_ent_cnt_
== 0)
2337 if (this->num_entries() + cnt
> this->header_index_
)
2338 this->make_header();
2344 this->header_ent_cnt_
= 0;
2345 this->header_index_
= this->num_entries();
2348 Output_data_got
<size
, big_endian
>::add_constant(0);
2349 Output_data_got
<size
, big_endian
>::add_constant(0);
2350 Output_data_got
<size
, big_endian
>::add_constant(0);
2352 // Define _GLOBAL_OFFSET_TABLE_ at the header
2353 Symbol
*gotsym
= this->symtab_
->lookup("_GLOBAL_OFFSET_TABLE_", NULL
);
2356 Sized_symbol
<size
>* sym
= static_cast<Sized_symbol
<size
>*>(gotsym
);
2357 sym
->set_value(this->g_o_t());
2360 this->symtab_
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2361 Symbol_table::PREDEFINED
,
2362 this, this->g_o_t(), 0,
2365 elfcpp::STV_HIDDEN
, 0,
2369 Output_data_got
<size
, big_endian
>::add_constant(0);
2372 // Stashed pointers.
2373 Symbol_table
* symtab_
;
2377 unsigned int header_ent_cnt_
;
2378 // GOT header index.
2379 unsigned int header_index_
;
2382 // Get the GOT section, creating it if necessary.
2384 template<int size
, bool big_endian
>
2385 Output_data_got_powerpc
<size
, big_endian
>*
2386 Target_powerpc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
2389 if (this->got_
== NULL
)
2391 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
2394 = new Output_data_got_powerpc
<size
, big_endian
>(symtab
, layout
);
2396 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2397 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2398 this->got_
, ORDER_DATA
, false);
2404 // Get the dynamic reloc section, creating it if necessary.
2406 template<int size
, bool big_endian
>
2407 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2408 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
2410 if (this->rela_dyn_
== NULL
)
2412 gold_assert(layout
!= NULL
);
2413 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
2414 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
2415 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
2416 ORDER_DYNAMIC_RELOCS
, false);
2418 return this->rela_dyn_
;
2421 // Similarly, but for ifunc symbols get the one for ifunc.
2423 template<int size
, bool big_endian
>
2424 typename Target_powerpc
<size
, big_endian
>::Reloc_section
*
2425 Target_powerpc
<size
, big_endian
>::rela_dyn_section(Symbol_table
* symtab
,
2430 return this->rela_dyn_section(layout
);
2432 if (this->iplt_
== NULL
)
2433 this->make_iplt_section(symtab
, layout
);
2434 return this->iplt_
->rel_plt();
2440 // Determine the stub group size. The group size is the absolute
2441 // value of the parameter --stub-group-size. If --stub-group-size
2442 // is passed a negative value, we restrict stubs to be always after
2443 // the stubbed branches.
2444 Stub_control(int32_t size
, bool no_size_errors
, bool multi_os
)
2445 : stub_group_size_(abs(size
)), stubs_always_after_branch_(size
< 0),
2446 suppress_size_errors_(no_size_errors
), multi_os_(multi_os
),
2447 state_(NO_GROUP
), group_size_(0), group_start_addr_(0),
2448 owner_(NULL
), output_section_(NULL
)
2452 // Return true iff input section can be handled by current stub
2455 can_add_to_stub_group(Output_section
* o
,
2456 const Output_section::Input_section
* i
,
2459 const Output_section::Input_section
*
2465 { return output_section_
; }
2468 set_output_and_owner(Output_section
* o
,
2469 const Output_section::Input_section
* i
)
2471 this->output_section_
= o
;
2480 // Adding group sections before the stubs.
2481 FINDING_STUB_SECTION
,
2482 // Adding group sections after the stubs.
2486 uint32_t stub_group_size_
;
2487 bool stubs_always_after_branch_
;
2488 bool suppress_size_errors_
;
2489 // True if a stub group can serve multiple output sections.
2492 // Current max size of group. Starts at stub_group_size_ but is
2493 // reduced to stub_group_size_/1024 on seeing a section with
2494 // external conditional branches.
2495 uint32_t group_size_
;
2496 uint64_t group_start_addr_
;
2497 // owner_ and output_section_ specify the section to which stubs are
2498 // attached. The stubs are placed at the end of this section.
2499 const Output_section::Input_section
* owner_
;
2500 Output_section
* output_section_
;
2503 // Return true iff input section can be handled by current stub
2504 // group. Sections are presented to this function in order,
2505 // so the first section is the head of the group.
2508 Stub_control::can_add_to_stub_group(Output_section
* o
,
2509 const Output_section::Input_section
* i
,
2512 bool whole_sec
= o
->order() == ORDER_INIT
|| o
->order() == ORDER_FINI
;
2514 uint64_t start_addr
= o
->address();
2517 // .init and .fini sections are pasted together to form a single
2518 // function. We can't be adding stubs in the middle of the function.
2519 this_size
= o
->data_size();
2522 start_addr
+= i
->relobj()->output_section_offset(i
->shndx());
2523 this_size
= i
->data_size();
2526 uint64_t end_addr
= start_addr
+ this_size
;
2527 uint32_t group_size
= this->stub_group_size_
;
2529 this->group_size_
= group_size
= group_size
>> 10;
2531 if (this_size
> group_size
&& !this->suppress_size_errors_
)
2532 gold_warning(_("%s:%s exceeds group size"),
2533 i
->relobj()->name().c_str(),
2534 i
->relobj()->section_name(i
->shndx()).c_str());
2536 gold_debug(DEBUG_TARGET
, "maybe add%s %s:%s size=%#llx total=%#llx",
2537 has14
? " 14bit" : "",
2538 i
->relobj()->name().c_str(),
2539 i
->relobj()->section_name(i
->shndx()).c_str(),
2540 (long long) this_size
,
2541 (this->state_
== NO_GROUP
2543 : (long long) end_addr
- this->group_start_addr_
));
2545 if (this->state_
== NO_GROUP
)
2547 // Only here on very first use of Stub_control
2549 this->output_section_
= o
;
2550 this->state_
= FINDING_STUB_SECTION
;
2551 this->group_size_
= group_size
;
2552 this->group_start_addr_
= start_addr
;
2555 else if (!this->multi_os_
&& this->output_section_
!= o
)
2557 else if (this->state_
== HAS_STUB_SECTION
)
2559 // Can we add this section, which is after the stubs, to the
2561 if (end_addr
- this->group_start_addr_
<= this->group_size_
)
2564 else if (this->state_
== FINDING_STUB_SECTION
)
2566 if ((whole_sec
&& this->output_section_
== o
)
2567 || end_addr
- this->group_start_addr_
<= this->group_size_
)
2569 // Stubs are added at the end of "owner_".
2571 this->output_section_
= o
;
2574 // The group before the stubs has reached maximum size.
2575 // Now see about adding sections after the stubs to the
2576 // group. If the current section has a 14-bit branch and
2577 // the group before the stubs exceeds group_size_ (because
2578 // they didn't have 14-bit branches), don't add sections
2579 // after the stubs: The size of stubs for such a large
2580 // group may exceed the reach of a 14-bit branch.
2581 if (!this->stubs_always_after_branch_
2582 && this_size
<= this->group_size_
2583 && start_addr
- this->group_start_addr_
<= this->group_size_
)
2585 gold_debug(DEBUG_TARGET
, "adding after stubs");
2586 this->state_
= HAS_STUB_SECTION
;
2587 this->group_start_addr_
= start_addr
;
2594 gold_debug(DEBUG_TARGET
,
2595 !this->multi_os_
&& this->output_section_
!= o
2596 ? "nope, new output section\n"
2597 : "nope, didn't fit\n");
2599 // The section fails to fit in the current group. Set up a few
2600 // things for the next group. owner_ and output_section_ will be
2601 // set later after we've retrieved those values for the current
2603 this->state_
= FINDING_STUB_SECTION
;
2604 this->group_size_
= group_size
;
2605 this->group_start_addr_
= start_addr
;
2609 // Look over all the input sections, deciding where to place stubs.
2611 template<int size
, bool big_endian
>
2613 Target_powerpc
<size
, big_endian
>::group_sections(Layout
* layout
,
2615 bool no_size_errors
)
2617 Stub_control
stub_control(this->stub_group_size_
, no_size_errors
,
2618 parameters
->options().stub_group_multi());
2620 // Group input sections and insert stub table
2621 Stub_table_owner
* table_owner
= NULL
;
2622 std::vector
<Stub_table_owner
*> tables
;
2623 Layout::Section_list section_list
;
2624 layout
->get_executable_sections(§ion_list
);
2625 std::stable_sort(section_list
.begin(), section_list
.end(), Sort_sections());
2626 for (Layout::Section_list::iterator o
= section_list
.begin();
2627 o
!= section_list
.end();
2630 typedef Output_section::Input_section_list Input_section_list
;
2631 for (Input_section_list::const_iterator i
2632 = (*o
)->input_sections().begin();
2633 i
!= (*o
)->input_sections().end();
2636 if (i
->is_input_section()
2637 || i
->is_relaxed_input_section())
2639 Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
2640 <Powerpc_relobj
<size
, big_endian
>*>(i
->relobj());
2641 bool has14
= ppcobj
->has_14bit_branch(i
->shndx());
2642 if (!stub_control
.can_add_to_stub_group(*o
, &*i
, has14
))
2644 table_owner
->output_section
= stub_control
.output_section();
2645 table_owner
->owner
= stub_control
.owner();
2646 stub_control
.set_output_and_owner(*o
, &*i
);
2649 if (table_owner
== NULL
)
2651 table_owner
= new Stub_table_owner
;
2652 tables
.push_back(table_owner
);
2654 ppcobj
->set_stub_table(i
->shndx(), tables
.size() - 1);
2658 if (table_owner
!= NULL
)
2660 table_owner
->output_section
= stub_control
.output_section();
2661 table_owner
->owner
= stub_control
.owner();;
2663 for (typename
std::vector
<Stub_table_owner
*>::iterator t
= tables
.begin();
2667 Stub_table
<size
, big_endian
>* stub_table
;
2669 if ((*t
)->owner
->is_input_section())
2670 stub_table
= new Stub_table
<size
, big_endian
>(this,
2671 (*t
)->output_section
,
2673 else if ((*t
)->owner
->is_relaxed_input_section())
2674 stub_table
= static_cast<Stub_table
<size
, big_endian
>*>(
2675 (*t
)->owner
->relaxed_input_section());
2678 this->stub_tables_
.push_back(stub_table
);
2683 static unsigned long
2684 max_branch_delta (unsigned int r_type
)
2686 if (r_type
== elfcpp::R_POWERPC_REL14
2687 || r_type
== elfcpp::R_POWERPC_REL14_BRTAKEN
2688 || r_type
== elfcpp::R_POWERPC_REL14_BRNTAKEN
)
2690 if (r_type
== elfcpp::R_POWERPC_REL24
2691 || r_type
== elfcpp::R_PPC_PLTREL24
2692 || r_type
== elfcpp::R_PPC_LOCAL24PC
)
2697 // If this branch needs a plt call stub, or a long branch stub, make one.
2699 template<int size
, bool big_endian
>
2701 Target_powerpc
<size
, big_endian
>::Branch_info::make_stub(
2702 Stub_table
<size
, big_endian
>* stub_table
,
2703 Stub_table
<size
, big_endian
>* ifunc_stub_table
,
2704 Symbol_table
* symtab
) const
2706 Symbol
* sym
= this->object_
->global_symbol(this->r_sym_
);
2707 if (sym
!= NULL
&& sym
->is_forwarder())
2708 sym
= symtab
->resolve_forwards(sym
);
2709 const Sized_symbol
<size
>* gsym
= static_cast<const Sized_symbol
<size
>*>(sym
);
2710 Target_powerpc
<size
, big_endian
>* target
=
2711 static_cast<Target_powerpc
<size
, big_endian
>*>(
2712 parameters
->sized_target
<size
, big_endian
>());
2716 ? gsym
->use_plt_offset(Scan::get_reference_flags(this->r_type_
, target
))
2717 : this->object_
->local_has_plt_offset(this->r_sym_
))
2721 && target
->abiversion() >= 2
2722 && !parameters
->options().output_is_position_independent()
2723 && !is_branch_reloc(this->r_type_
))
2724 target
->glink_section()->add_global_entry(gsym
);
2727 if (stub_table
== NULL
)
2728 stub_table
= this->object_
->stub_table(this->shndx_
);
2729 if (stub_table
== NULL
)
2731 // This is a ref from a data section to an ifunc symbol.
2732 stub_table
= ifunc_stub_table
;
2734 gold_assert(stub_table
!= NULL
);
2735 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2736 if (from
!= invalid_address
)
2737 from
+= (this->object_
->output_section(this->shndx_
)->address()
2740 ok
= stub_table
->add_plt_call_entry(from
,
2741 this->object_
, gsym
,
2742 this->r_type_
, this->addend_
);
2744 ok
= stub_table
->add_plt_call_entry(from
,
2745 this->object_
, this->r_sym_
,
2746 this->r_type_
, this->addend_
);
2751 Address max_branch_offset
= max_branch_delta(this->r_type_
);
2752 if (max_branch_offset
== 0)
2754 Address from
= this->object_
->get_output_section_offset(this->shndx_
);
2755 gold_assert(from
!= invalid_address
);
2756 from
+= (this->object_
->output_section(this->shndx_
)->address()
2761 switch (gsym
->source())
2763 case Symbol::FROM_OBJECT
:
2765 Object
* symobj
= gsym
->object();
2766 if (symobj
->is_dynamic()
2767 || symobj
->pluginobj() != NULL
)
2770 unsigned int shndx
= gsym
->shndx(&is_ordinary
);
2771 if (shndx
== elfcpp::SHN_UNDEF
)
2776 case Symbol::IS_UNDEFINED
:
2782 Symbol_table::Compute_final_value_status status
;
2783 to
= symtab
->compute_final_value
<size
>(gsym
, &status
);
2784 if (status
!= Symbol_table::CFVS_OK
)
2787 to
+= this->object_
->ppc64_local_entry_offset(gsym
);
2791 const Symbol_value
<size
>* psymval
2792 = this->object_
->local_symbol(this->r_sym_
);
2793 Symbol_value
<size
> symval
;
2794 if (psymval
->is_section_symbol())
2795 symval
.set_is_section_symbol();
2796 typedef Sized_relobj_file
<size
, big_endian
> ObjType
;
2797 typename
ObjType::Compute_final_local_value_status status
2798 = this->object_
->compute_final_local_value(this->r_sym_
, psymval
,
2800 if (status
!= ObjType::CFLV_OK
2801 || !symval
.has_output_value())
2803 to
= symval
.value(this->object_
, 0);
2805 to
+= this->object_
->ppc64_local_entry_offset(this->r_sym_
);
2807 if (!(size
== 32 && this->r_type_
== elfcpp::R_PPC_PLTREL24
))
2808 to
+= this->addend_
;
2809 if (stub_table
== NULL
)
2810 stub_table
= this->object_
->stub_table(this->shndx_
);
2811 if (size
== 64 && target
->abiversion() < 2)
2813 unsigned int dest_shndx
;
2814 if (!target
->symval_for_branch(symtab
, gsym
, this->object_
,
2818 Address delta
= to
- from
;
2819 if (delta
+ max_branch_offset
>= 2 * max_branch_offset
)
2821 if (stub_table
== NULL
)
2823 gold_warning(_("%s:%s: branch in non-executable section,"
2824 " no long branch stub for you"),
2825 this->object_
->name().c_str(),
2826 this->object_
->section_name(this->shndx_
).c_str());
2829 bool save_res
= (size
== 64
2831 && gsym
->source() == Symbol::IN_OUTPUT_DATA
2832 && gsym
->output_data() == target
->savres_section());
2833 ok
= stub_table
->add_long_branch_entry(this->object_
,
2835 from
, to
, save_res
);
2839 gold_debug(DEBUG_TARGET
,
2840 "branch at %s:%s+%#lx\n"
2841 "can't reach stub attached to %s:%s",
2842 this->object_
->name().c_str(),
2843 this->object_
->section_name(this->shndx_
).c_str(),
2844 (unsigned long) this->offset_
,
2845 stub_table
->relobj()->name().c_str(),
2846 stub_table
->relobj()->section_name(stub_table
->shndx()).c_str());
2851 // Relaxation hook. This is where we do stub generation.
2853 template<int size
, bool big_endian
>
2855 Target_powerpc
<size
, big_endian
>::do_relax(int pass
,
2856 const Input_objects
*,
2857 Symbol_table
* symtab
,
2861 unsigned int prev_brlt_size
= 0;
2865 = this->abiversion() < 2 && parameters
->options().plt_thread_safe();
2867 && this->abiversion() < 2
2869 && !parameters
->options().user_set_plt_thread_safe())
2871 static const char* const thread_starter
[] =
2875 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2877 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2878 "mq_notify", "create_timer",
2883 "GOMP_parallel_start",
2884 "GOMP_parallel_loop_static",
2885 "GOMP_parallel_loop_static_start",
2886 "GOMP_parallel_loop_dynamic",
2887 "GOMP_parallel_loop_dynamic_start",
2888 "GOMP_parallel_loop_guided",
2889 "GOMP_parallel_loop_guided_start",
2890 "GOMP_parallel_loop_runtime",
2891 "GOMP_parallel_loop_runtime_start",
2892 "GOMP_parallel_sections",
2893 "GOMP_parallel_sections_start",
2898 if (parameters
->options().shared())
2902 for (unsigned int i
= 0;
2903 i
< sizeof(thread_starter
) / sizeof(thread_starter
[0]);
2906 Symbol
* sym
= symtab
->lookup(thread_starter
[i
], NULL
);
2907 thread_safe
= (sym
!= NULL
2909 && sym
->in_real_elf());
2915 this->plt_thread_safe_
= thread_safe
;
2920 this->stub_group_size_
= parameters
->options().stub_group_size();
2921 bool no_size_errors
= true;
2922 if (this->stub_group_size_
== 1)
2923 this->stub_group_size_
= 0x1c00000;
2924 else if (this->stub_group_size_
== -1)
2925 this->stub_group_size_
= -0x1e00000;
2927 no_size_errors
= false;
2928 this->group_sections(layout
, task
, no_size_errors
);
2930 else if (this->relax_failed_
&& this->relax_fail_count_
< 3)
2932 this->branch_lookup_table_
.clear();
2933 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2934 p
!= this->stub_tables_
.end();
2937 (*p
)->clear_stubs(true);
2939 this->stub_tables_
.clear();
2940 this->stub_group_size_
= this->stub_group_size_
/ 4 * 3;
2941 gold_info(_("%s: stub group size is too large; retrying with %#x"),
2942 program_name
, this->stub_group_size_
);
2943 this->group_sections(layout
, task
, true);
2946 // We need address of stub tables valid for make_stub.
2947 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2948 p
!= this->stub_tables_
.end();
2951 const Powerpc_relobj
<size
, big_endian
>* object
2952 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>((*p
)->relobj());
2953 Address off
= object
->get_output_section_offset((*p
)->shndx());
2954 gold_assert(off
!= invalid_address
);
2955 Output_section
* os
= (*p
)->output_section();
2956 (*p
)->set_address_and_size(os
, off
);
2961 // Clear plt call stubs, long branch stubs and branch lookup table.
2962 prev_brlt_size
= this->branch_lookup_table_
.size();
2963 this->branch_lookup_table_
.clear();
2964 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
2965 p
!= this->stub_tables_
.end();
2968 (*p
)->clear_stubs(false);
2972 // Build all the stubs.
2973 this->relax_failed_
= false;
2974 Stub_table
<size
, big_endian
>* ifunc_stub_table
2975 = this->stub_tables_
.size() == 0 ? NULL
: this->stub_tables_
[0];
2976 Stub_table
<size
, big_endian
>* one_stub_table
2977 = this->stub_tables_
.size() != 1 ? NULL
: ifunc_stub_table
;
2978 for (typename
Branches::const_iterator b
= this->branch_info_
.begin();
2979 b
!= this->branch_info_
.end();
2982 if (!b
->make_stub(one_stub_table
, ifunc_stub_table
, symtab
)
2983 && !this->relax_failed_
)
2985 this->relax_failed_
= true;
2986 this->relax_fail_count_
++;
2987 if (this->relax_fail_count_
< 3)
2992 // Did anything change size?
2993 unsigned int num_huge_branches
= this->branch_lookup_table_
.size();
2994 bool again
= num_huge_branches
!= prev_brlt_size
;
2995 if (size
== 64 && num_huge_branches
!= 0)
2996 this->make_brlt_section(layout
);
2997 if (size
== 64 && again
)
2998 this->brlt_section_
->set_current_size(num_huge_branches
);
3000 typedef Unordered_set
<Output_section
*> Output_sections
;
3001 Output_sections os_need_update
;
3002 for (typename
Stub_tables::iterator p
= this->stub_tables_
.begin();
3003 p
!= this->stub_tables_
.end();
3006 if ((*p
)->size_update())
3009 (*p
)->add_eh_frame(layout
);
3010 os_need_update
.insert((*p
)->output_section());
3014 // Set output section offsets for all input sections in an output
3015 // section that just changed size. Anything past the stubs will
3017 for (typename
Output_sections::iterator p
= os_need_update
.begin();
3018 p
!= os_need_update
.end();
3021 Output_section
* os
= *p
;
3023 typedef Output_section::Input_section_list Input_section_list
;
3024 for (Input_section_list::const_iterator i
= os
->input_sections().begin();
3025 i
!= os
->input_sections().end();
3028 off
= align_address(off
, i
->addralign());
3029 if (i
->is_input_section() || i
->is_relaxed_input_section())
3030 i
->relobj()->set_section_offset(i
->shndx(), off
);
3031 if (i
->is_relaxed_input_section())
3033 Stub_table
<size
, big_endian
>* stub_table
3034 = static_cast<Stub_table
<size
, big_endian
>*>(
3035 i
->relaxed_input_section());
3036 Address stub_table_size
= stub_table
->set_address_and_size(os
, off
);
3037 off
+= stub_table_size
;
3038 // After a few iterations, set current stub table size
3039 // as min size threshold, so later stub tables can only
3042 stub_table
->set_min_size_threshold(stub_table_size
);
3045 off
+= i
->data_size();
3047 // If .branch_lt is part of this output section, then we have
3048 // just done the offset adjustment.
3049 os
->clear_section_offsets_need_adjustment();
3054 && num_huge_branches
!= 0
3055 && parameters
->options().output_is_position_independent())
3057 // Fill in the BRLT relocs.
3058 this->brlt_section_
->reset_brlt_sizes();
3059 for (typename
Branch_lookup_table::const_iterator p
3060 = this->branch_lookup_table_
.begin();
3061 p
!= this->branch_lookup_table_
.end();
3064 this->brlt_section_
->add_reloc(p
->first
, p
->second
);
3066 this->brlt_section_
->finalize_brlt_sizes();
3071 template<int size
, bool big_endian
>
3073 Target_powerpc
<size
, big_endian
>::do_plt_fde_location(const Output_data
* plt
,
3074 unsigned char* oview
,
3078 uint64_t address
= plt
->address();
3079 off_t len
= plt
->data_size();
3081 if (plt
== this->glink_
)
3083 // See Output_data_glink::do_write() for glink contents.
3086 gold_assert(parameters
->doing_static_link());
3087 // Static linking may need stubs, to support ifunc and long
3088 // branches. We need to create an output section for
3089 // .eh_frame early in the link process, to have a place to
3090 // attach stub .eh_frame info. We also need to have
3091 // registered a CIE that matches the stub CIE. Both of
3092 // these requirements are satisfied by creating an FDE and
3093 // CIE for .glink, even though static linking will leave
3094 // .glink zero length.
3095 // ??? Hopefully generating an FDE with a zero address range
3096 // won't confuse anything that consumes .eh_frame info.
3098 else if (size
== 64)
3100 // There is one word before __glink_PLTresolve
3104 else if (parameters
->options().output_is_position_independent())
3106 // There are two FDEs for a position independent glink.
3107 // The first covers the branch table, the second
3108 // __glink_PLTresolve at the end of glink.
3109 off_t resolve_size
= this->glink_
->pltresolve_size
;
3110 if (oview
[9] == elfcpp::DW_CFA_nop
)
3111 len
-= resolve_size
;
3114 address
+= len
- resolve_size
;
3121 // Must be a stub table.
3122 const Stub_table
<size
, big_endian
>* stub_table
3123 = static_cast<const Stub_table
<size
, big_endian
>*>(plt
);
3124 uint64_t stub_address
= stub_table
->stub_address();
3125 len
-= stub_address
- address
;
3126 address
= stub_address
;
3129 *paddress
= address
;
3133 // A class to handle the PLT data.
3135 template<int size
, bool big_endian
>
3136 class Output_data_plt_powerpc
: public Output_section_data_build
3139 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3140 size
, big_endian
> Reloc_section
;
3142 Output_data_plt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3143 Reloc_section
* plt_rel
,
3145 : Output_section_data_build(size
== 32 ? 4 : 8),
3151 // Add an entry to the PLT.
3156 add_ifunc_entry(Symbol
*);
3159 add_local_ifunc_entry(Sized_relobj_file
<size
, big_endian
>*, unsigned int);
3161 // Return the .rela.plt section data.
3168 // Return the number of PLT entries.
3172 if (this->current_data_size() == 0)
3174 return ((this->current_data_size() - this->first_plt_entry_offset())
3175 / this->plt_entry_size());
3180 do_adjust_output_section(Output_section
* os
)
3185 // Write to a map file.
3187 do_print_to_mapfile(Mapfile
* mapfile
) const
3188 { mapfile
->print_output_data(this, this->name_
); }
3191 // Return the offset of the first non-reserved PLT entry.
3193 first_plt_entry_offset() const
3195 // IPLT has no reserved entry.
3196 if (this->name_
[3] == 'I')
3198 return this->targ_
->first_plt_entry_offset();
3201 // Return the size of each PLT entry.
3203 plt_entry_size() const
3205 return this->targ_
->plt_entry_size();
3208 // Write out the PLT data.
3210 do_write(Output_file
*);
3212 // The reloc section.
3213 Reloc_section
* rel_
;
3214 // Allows access to .glink for do_write.
3215 Target_powerpc
<size
, big_endian
>* targ_
;
3216 // What to report in map file.
3220 // Add an entry to the PLT.
3222 template<int size
, bool big_endian
>
3224 Output_data_plt_powerpc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
3226 if (!gsym
->has_plt_offset())
3228 section_size_type off
= this->current_data_size();
3230 off
+= this->first_plt_entry_offset();
3231 gsym
->set_plt_offset(off
);
3232 gsym
->set_needs_dynsym_entry();
3233 unsigned int dynrel
= elfcpp::R_POWERPC_JMP_SLOT
;
3234 this->rel_
->add_global(gsym
, dynrel
, this, off
, 0);
3235 off
+= this->plt_entry_size();
3236 this->set_current_data_size(off
);
3240 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3242 template<int size
, bool big_endian
>
3244 Output_data_plt_powerpc
<size
, big_endian
>::add_ifunc_entry(Symbol
* gsym
)
3246 if (!gsym
->has_plt_offset())
3248 section_size_type off
= this->current_data_size();
3249 gsym
->set_plt_offset(off
);
3250 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3251 if (size
== 64 && this->targ_
->abiversion() < 2)
3252 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3253 this->rel_
->add_symbolless_global_addend(gsym
, dynrel
, this, off
, 0);
3254 off
+= this->plt_entry_size();
3255 this->set_current_data_size(off
);
3259 // Add an entry for a local ifunc symbol to the IPLT.
3261 template<int size
, bool big_endian
>
3263 Output_data_plt_powerpc
<size
, big_endian
>::add_local_ifunc_entry(
3264 Sized_relobj_file
<size
, big_endian
>* relobj
,
3265 unsigned int local_sym_index
)
3267 if (!relobj
->local_has_plt_offset(local_sym_index
))
3269 section_size_type off
= this->current_data_size();
3270 relobj
->set_local_plt_offset(local_sym_index
, off
);
3271 unsigned int dynrel
= elfcpp::R_POWERPC_IRELATIVE
;
3272 if (size
== 64 && this->targ_
->abiversion() < 2)
3273 dynrel
= elfcpp::R_PPC64_JMP_IREL
;
3274 this->rel_
->add_symbolless_local_addend(relobj
, local_sym_index
, dynrel
,
3276 off
+= this->plt_entry_size();
3277 this->set_current_data_size(off
);
3281 static const uint32_t add_0_11_11
= 0x7c0b5a14;
3282 static const uint32_t add_2_2_11
= 0x7c425a14;
3283 static const uint32_t add_2_2_12
= 0x7c426214;
3284 static const uint32_t add_3_3_2
= 0x7c631214;
3285 static const uint32_t add_3_3_13
= 0x7c636a14;
3286 static const uint32_t add_11_0_11
= 0x7d605a14;
3287 static const uint32_t add_11_2_11
= 0x7d625a14;
3288 static const uint32_t add_11_11_2
= 0x7d6b1214;
3289 static const uint32_t addi_0_12
= 0x380c0000;
3290 static const uint32_t addi_2_2
= 0x38420000;
3291 static const uint32_t addi_3_3
= 0x38630000;
3292 static const uint32_t addi_11_11
= 0x396b0000;
3293 static const uint32_t addi_12_1
= 0x39810000;
3294 static const uint32_t addi_12_12
= 0x398c0000;
3295 static const uint32_t addis_0_2
= 0x3c020000;
3296 static const uint32_t addis_0_13
= 0x3c0d0000;
3297 static const uint32_t addis_2_12
= 0x3c4c0000;
3298 static const uint32_t addis_11_2
= 0x3d620000;
3299 static const uint32_t addis_11_11
= 0x3d6b0000;
3300 static const uint32_t addis_11_30
= 0x3d7e0000;
3301 static const uint32_t addis_12_1
= 0x3d810000;
3302 static const uint32_t addis_12_2
= 0x3d820000;
3303 static const uint32_t addis_12_12
= 0x3d8c0000;
3304 static const uint32_t b
= 0x48000000;
3305 static const uint32_t bcl_20_31
= 0x429f0005;
3306 static const uint32_t bctr
= 0x4e800420;
3307 static const uint32_t blr
= 0x4e800020;
3308 static const uint32_t bnectr_p4
= 0x4ce20420;
3309 static const uint32_t cmpld_7_12_0
= 0x7fac0040;
3310 static const uint32_t cmpldi_2_0
= 0x28220000;
3311 static const uint32_t cror_15_15_15
= 0x4def7b82;
3312 static const uint32_t cror_31_31_31
= 0x4ffffb82;
3313 static const uint32_t ld_0_1
= 0xe8010000;
3314 static const uint32_t ld_0_12
= 0xe80c0000;
3315 static const uint32_t ld_2_1
= 0xe8410000;
3316 static const uint32_t ld_2_2
= 0xe8420000;
3317 static const uint32_t ld_2_11
= 0xe84b0000;
3318 static const uint32_t ld_2_12
= 0xe84c0000;
3319 static const uint32_t ld_11_2
= 0xe9620000;
3320 static const uint32_t ld_11_11
= 0xe96b0000;
3321 static const uint32_t ld_12_2
= 0xe9820000;
3322 static const uint32_t ld_12_11
= 0xe98b0000;
3323 static const uint32_t ld_12_12
= 0xe98c0000;
3324 static const uint32_t lfd_0_1
= 0xc8010000;
3325 static const uint32_t li_0_0
= 0x38000000;
3326 static const uint32_t li_12_0
= 0x39800000;
3327 static const uint32_t lis_0
= 0x3c000000;
3328 static const uint32_t lis_2
= 0x3c400000;
3329 static const uint32_t lis_11
= 0x3d600000;
3330 static const uint32_t lis_12
= 0x3d800000;
3331 static const uint32_t lvx_0_12_0
= 0x7c0c00ce;
3332 static const uint32_t lwz_0_12
= 0x800c0000;
3333 static const uint32_t lwz_11_11
= 0x816b0000;
3334 static const uint32_t lwz_11_30
= 0x817e0000;
3335 static const uint32_t lwz_12_12
= 0x818c0000;
3336 static const uint32_t lwzu_0_12
= 0x840c0000;
3337 static const uint32_t mflr_0
= 0x7c0802a6;
3338 static const uint32_t mflr_11
= 0x7d6802a6;
3339 static const uint32_t mflr_12
= 0x7d8802a6;
3340 static const uint32_t mtctr_0
= 0x7c0903a6;
3341 static const uint32_t mtctr_11
= 0x7d6903a6;
3342 static const uint32_t mtctr_12
= 0x7d8903a6;
3343 static const uint32_t mtlr_0
= 0x7c0803a6;
3344 static const uint32_t mtlr_12
= 0x7d8803a6;
3345 static const uint32_t nop
= 0x60000000;
3346 static const uint32_t ori_0_0_0
= 0x60000000;
3347 static const uint32_t srdi_0_0_2
= 0x7800f082;
3348 static const uint32_t std_0_1
= 0xf8010000;
3349 static const uint32_t std_0_12
= 0xf80c0000;
3350 static const uint32_t std_2_1
= 0xf8410000;
3351 static const uint32_t stfd_0_1
= 0xd8010000;
3352 static const uint32_t stvx_0_12_0
= 0x7c0c01ce;
3353 static const uint32_t sub_11_11_12
= 0x7d6c5850;
3354 static const uint32_t sub_12_12_11
= 0x7d8b6050;
3355 static const uint32_t xor_2_12_12
= 0x7d826278;
3356 static const uint32_t xor_11_12_12
= 0x7d8b6278;
3358 // Write out the PLT.
3360 template<int size
, bool big_endian
>
3362 Output_data_plt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3364 if (size
== 32 && this->name_
[3] != 'I')
3366 const section_size_type offset
= this->offset();
3367 const section_size_type oview_size
3368 = convert_to_section_size_type(this->data_size());
3369 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3370 unsigned char* pov
= oview
;
3371 unsigned char* endpov
= oview
+ oview_size
;
3373 // The address of the .glink branch table
3374 const Output_data_glink
<size
, big_endian
>* glink
3375 = this->targ_
->glink_section();
3376 elfcpp::Elf_types
<32>::Elf_Addr branch_tab
= glink
->address();
3378 while (pov
< endpov
)
3380 elfcpp::Swap
<32, big_endian
>::writeval(pov
, branch_tab
);
3385 of
->write_output_view(offset
, oview_size
, oview
);
3389 // Create the PLT section.
3391 template<int size
, bool big_endian
>
3393 Target_powerpc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
3396 if (this->plt_
== NULL
)
3398 if (this->got_
== NULL
)
3399 this->got_section(symtab
, layout
);
3401 if (this->glink_
== NULL
)
3402 make_glink_section(layout
);
3404 // Ensure that .rela.dyn always appears before .rela.plt This is
3405 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3406 // needs to include .rela.plt in its range.
3407 this->rela_dyn_section(layout
);
3409 Reloc_section
* plt_rel
= new Reloc_section(false);
3410 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
3411 elfcpp::SHF_ALLOC
, plt_rel
,
3412 ORDER_DYNAMIC_PLT_RELOCS
, false);
3414 = new Output_data_plt_powerpc
<size
, big_endian
>(this, plt_rel
,
3416 layout
->add_output_section_data(".plt",
3418 ? elfcpp::SHT_PROGBITS
3419 : elfcpp::SHT_NOBITS
),
3420 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3429 // Create the IPLT section.
3431 template<int size
, bool big_endian
>
3433 Target_powerpc
<size
, big_endian
>::make_iplt_section(Symbol_table
* symtab
,
3436 if (this->iplt_
== NULL
)
3438 this->make_plt_section(symtab
, layout
);
3440 Reloc_section
* iplt_rel
= new Reloc_section(false);
3441 this->rela_dyn_
->output_section()->add_output_section_data(iplt_rel
);
3443 = new Output_data_plt_powerpc
<size
, big_endian
>(this, iplt_rel
,
3445 this->plt_
->output_section()->add_output_section_data(this->iplt_
);
3449 // A section for huge long branch addresses, similar to plt section.
3451 template<int size
, bool big_endian
>
3452 class Output_data_brlt_powerpc
: public Output_section_data_build
3455 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3456 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
3457 size
, big_endian
> Reloc_section
;
3459 Output_data_brlt_powerpc(Target_powerpc
<size
, big_endian
>* targ
,
3460 Reloc_section
* brlt_rel
)
3461 : Output_section_data_build(size
== 32 ? 4 : 8),
3469 this->reset_data_size();
3470 this->rel_
->reset_data_size();
3474 finalize_brlt_sizes()
3476 this->finalize_data_size();
3477 this->rel_
->finalize_data_size();
3480 // Add a reloc for an entry in the BRLT.
3482 add_reloc(Address to
, unsigned int off
)
3483 { this->rel_
->add_relative(elfcpp::R_POWERPC_RELATIVE
, this, off
, to
); }
3485 // Update section and reloc section size.
3487 set_current_size(unsigned int num_branches
)
3489 this->reset_address_and_file_offset();
3490 this->set_current_data_size(num_branches
* 16);
3491 this->finalize_data_size();
3492 Output_section
* os
= this->output_section();
3493 os
->set_section_offsets_need_adjustment();
3494 if (this->rel_
!= NULL
)
3496 unsigned int reloc_size
3497 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
3498 this->rel_
->reset_address_and_file_offset();
3499 this->rel_
->set_current_data_size(num_branches
* reloc_size
);
3500 this->rel_
->finalize_data_size();
3501 Output_section
* os
= this->rel_
->output_section();
3502 os
->set_section_offsets_need_adjustment();
3508 do_adjust_output_section(Output_section
* os
)
3513 // Write to a map file.
3515 do_print_to_mapfile(Mapfile
* mapfile
) const
3516 { mapfile
->print_output_data(this, "** BRLT"); }
3519 // Write out the BRLT data.
3521 do_write(Output_file
*);
3523 // The reloc section.
3524 Reloc_section
* rel_
;
3525 Target_powerpc
<size
, big_endian
>* targ_
;
3528 // Make the branch lookup table section.
3530 template<int size
, bool big_endian
>
3532 Target_powerpc
<size
, big_endian
>::make_brlt_section(Layout
* layout
)
3534 if (size
== 64 && this->brlt_section_
== NULL
)
3536 Reloc_section
* brlt_rel
= NULL
;
3537 bool is_pic
= parameters
->options().output_is_position_independent();
3540 // When PIC we can't fill in .branch_lt (like .plt it can be
3541 // a bss style section) but must initialise at runtime via
3542 // dynamic relocats.
3543 this->rela_dyn_section(layout
);
3544 brlt_rel
= new Reloc_section(false);
3545 this->rela_dyn_
->output_section()->add_output_section_data(brlt_rel
);
3548 = new Output_data_brlt_powerpc
<size
, big_endian
>(this, brlt_rel
);
3549 if (this->plt_
&& is_pic
)
3550 this->plt_
->output_section()
3551 ->add_output_section_data(this->brlt_section_
);
3553 layout
->add_output_section_data(".branch_lt",
3554 (is_pic
? elfcpp::SHT_NOBITS
3555 : elfcpp::SHT_PROGBITS
),
3556 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
3557 this->brlt_section_
,
3558 (is_pic
? ORDER_SMALL_BSS
3559 : ORDER_SMALL_DATA
),
3564 // Write out .branch_lt when non-PIC.
3566 template<int size
, bool big_endian
>
3568 Output_data_brlt_powerpc
<size
, big_endian
>::do_write(Output_file
* of
)
3570 if (size
== 64 && !parameters
->options().output_is_position_independent())
3572 const section_size_type offset
= this->offset();
3573 const section_size_type oview_size
3574 = convert_to_section_size_type(this->data_size());
3575 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
3577 this->targ_
->write_branch_lookup_table(oview
);
3578 of
->write_output_view(offset
, oview_size
, oview
);
3582 static inline uint32_t
3588 static inline uint32_t
3594 static inline uint32_t
3597 return hi(a
+ 0x8000);
3603 static const unsigned char eh_frame_cie
[12];
3607 const unsigned char Eh_cie
<size
>::eh_frame_cie
[] =
3610 'z', 'R', 0, // Augmentation string.
3611 4, // Code alignment.
3612 0x80 - size
/ 8 , // Data alignment.
3614 1, // Augmentation size.
3615 (elfcpp::DW_EH_PE_pcrel
3616 | elfcpp::DW_EH_PE_sdata4
), // FDE encoding.
3617 elfcpp::DW_CFA_def_cfa
, 1, 0 // def_cfa: r1 offset 0.
3620 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3621 static const unsigned char glink_eh_frame_fde_64v1
[] =
3623 0, 0, 0, 0, // Replaced with offset to .glink.
3624 0, 0, 0, 0, // Replaced with size of .glink.
3625 0, // Augmentation size.
3626 elfcpp::DW_CFA_advance_loc
+ 1,
3627 elfcpp::DW_CFA_register
, 65, 12,
3628 elfcpp::DW_CFA_advance_loc
+ 4,
3629 elfcpp::DW_CFA_restore_extended
, 65
3632 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3633 static const unsigned char glink_eh_frame_fde_64v2
[] =
3635 0, 0, 0, 0, // Replaced with offset to .glink.
3636 0, 0, 0, 0, // Replaced with size of .glink.
3637 0, // Augmentation size.
3638 elfcpp::DW_CFA_advance_loc
+ 1,
3639 elfcpp::DW_CFA_register
, 65, 0,
3640 elfcpp::DW_CFA_advance_loc
+ 4,
3641 elfcpp::DW_CFA_restore_extended
, 65
3644 // Describe __glink_PLTresolve use of LR, 32-bit version.
3645 static const unsigned char glink_eh_frame_fde_32
[] =
3647 0, 0, 0, 0, // Replaced with offset to .glink.
3648 0, 0, 0, 0, // Replaced with size of .glink.
3649 0, // Augmentation size.
3650 elfcpp::DW_CFA_advance_loc
+ 2,
3651 elfcpp::DW_CFA_register
, 65, 0,
3652 elfcpp::DW_CFA_advance_loc
+ 4,
3653 elfcpp::DW_CFA_restore_extended
, 65
3656 static const unsigned char default_fde
[] =
3658 0, 0, 0, 0, // Replaced with offset to stubs.
3659 0, 0, 0, 0, // Replaced with size of stubs.
3660 0, // Augmentation size.
3661 elfcpp::DW_CFA_nop
, // Pad.
3666 template<bool big_endian
>
3668 write_insn(unsigned char* p
, uint32_t v
)
3670 elfcpp::Swap
<32, big_endian
>::writeval(p
, v
);
3673 // Stub_table holds information about plt and long branch stubs.
3674 // Stubs are built in an area following some input section determined
3675 // by group_sections(). This input section is converted to a relaxed
3676 // input section allowing it to be resized to accommodate the stubs
3678 template<int size
, bool big_endian
>
3679 class Stub_table
: public Output_relaxed_input_section
3682 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
3683 static const Address invalid_address
= static_cast<Address
>(0) - 1;
3685 Stub_table(Target_powerpc
<size
, big_endian
>* targ
,
3686 Output_section
* output_section
,
3687 const Output_section::Input_section
* owner
)
3688 : Output_relaxed_input_section(owner
->relobj(), owner
->shndx(),
3690 ->section_addralign(owner
->shndx())),
3691 targ_(targ
), plt_call_stubs_(), long_branch_stubs_(),
3692 orig_data_size_(owner
->current_data_size()),
3693 plt_size_(0), last_plt_size_(0),
3694 branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
3695 eh_frame_added_(false), need_save_res_(false)
3697 this->set_output_section(output_section
);
3699 std::vector
<Output_relaxed_input_section
*> new_relaxed
;
3700 new_relaxed
.push_back(this);
3701 output_section
->convert_input_sections_to_relaxed_sections(new_relaxed
);
3704 // Add a plt call stub.
3706 add_plt_call_entry(Address
,
3707 const Sized_relobj_file
<size
, big_endian
>*,
3713 add_plt_call_entry(Address
,
3714 const Sized_relobj_file
<size
, big_endian
>*,
3719 // Find a given plt call stub.
3721 find_plt_call_entry(const Symbol
*) const;
3724 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3725 unsigned int) const;
3728 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3734 find_plt_call_entry(const Sized_relobj_file
<size
, big_endian
>*,
3739 // Add a long branch stub.
3741 add_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3742 unsigned int, Address
, Address
, bool);
3745 find_long_branch_entry(const Powerpc_relobj
<size
, big_endian
>*,
3749 can_reach_stub(Address from
, unsigned int off
, unsigned int r_type
)
3751 Address max_branch_offset
= max_branch_delta(r_type
);
3752 if (max_branch_offset
== 0)
3754 gold_assert(from
!= invalid_address
);
3755 Address loc
= off
+ this->stub_address();
3756 return loc
- from
+ max_branch_offset
< 2 * max_branch_offset
;
3760 clear_stubs(bool all
)
3762 this->plt_call_stubs_
.clear();
3763 this->plt_size_
= 0;
3764 this->long_branch_stubs_
.clear();
3765 this->branch_size_
= 0;
3766 this->need_save_res_
= false;
3769 this->last_plt_size_
= 0;
3770 this->last_branch_size_
= 0;
3775 set_address_and_size(const Output_section
* os
, Address off
)
3777 Address start_off
= off
;
3778 off
+= this->orig_data_size_
;
3779 Address my_size
= this->plt_size_
+ this->branch_size_
;
3780 if (this->need_save_res_
)
3781 my_size
+= this->targ_
->savres_section()->data_size();
3783 off
= align_address(off
, this->stub_align());
3784 // Include original section size and alignment padding in size
3785 my_size
+= off
- start_off
;
3786 // Ensure new size is always larger than min size
3787 // threshold. Alignment requirement is included in "my_size", so
3788 // increase "my_size" does not invalidate alignment.
3789 if (my_size
< this->min_size_threshold_
)
3790 my_size
= this->min_size_threshold_
;
3791 this->reset_address_and_file_offset();
3792 this->set_current_data_size(my_size
);
3793 this->set_address_and_file_offset(os
->address() + start_off
,
3794 os
->offset() + start_off
);
3799 stub_address() const
3801 return align_address(this->address() + this->orig_data_size_
,
3802 this->stub_align());
3808 return align_address(this->offset() + this->orig_data_size_
,
3809 this->stub_align());
3814 { return this->plt_size_
; }
3816 void set_min_size_threshold(Address min_size
)
3817 { this->min_size_threshold_
= min_size
; }
3822 Output_section
* os
= this->output_section();
3823 if (os
->addralign() < this->stub_align())
3825 os
->set_addralign(this->stub_align());
3826 // FIXME: get rid of the insane checkpointing.
3827 // We can't increase alignment of the input section to which
3828 // stubs are attached; The input section may be .init which
3829 // is pasted together with other .init sections to form a
3830 // function. Aligning might insert zero padding resulting in
3831 // sigill. However we do need to increase alignment of the
3832 // output section so that the align_address() on offset in
3833 // set_address_and_size() adds the same padding as the
3834 // align_address() on address in stub_address().
3835 // What's more, we need this alignment for the layout done in
3836 // relaxation_loop_body() so that the output section starts at
3837 // a suitably aligned address.
3838 os
->checkpoint_set_addralign(this->stub_align());
3840 if (this->last_plt_size_
!= this->plt_size_
3841 || this->last_branch_size_
!= this->branch_size_
)
3843 this->last_plt_size_
= this->plt_size_
;
3844 this->last_branch_size_
= this->branch_size_
;
3850 // Add .eh_frame info for this stub section. Unlike other linker
3851 // generated .eh_frame this is added late in the link, because we
3852 // only want the .eh_frame info if this particular stub section is
3855 add_eh_frame(Layout
* layout
)
3857 if (!this->eh_frame_added_
)
3859 if (!parameters
->options().ld_generated_unwind_info())
3862 // Since we add stub .eh_frame info late, it must be placed
3863 // after all other linker generated .eh_frame info so that
3864 // merge mapping need not be updated for input sections.
3865 // There is no provision to use a different CIE to that used
3867 if (!this->targ_
->has_glink())
3870 layout
->add_eh_frame_for_plt(this,
3871 Eh_cie
<size
>::eh_frame_cie
,
3872 sizeof (Eh_cie
<size
>::eh_frame_cie
),
3874 sizeof (default_fde
));
3875 this->eh_frame_added_
= true;
3879 Target_powerpc
<size
, big_endian
>*
3885 class Plt_stub_ent_hash
;
3886 typedef Unordered_map
<Plt_stub_ent
, unsigned int,
3887 Plt_stub_ent_hash
> Plt_stub_entries
;
3889 // Alignment of stub section.
3895 unsigned int min_align
= 32;
3896 unsigned int user_align
= 1 << parameters
->options().plt_align();
3897 return std::max(user_align
, min_align
);
3900 // Return the plt offset for the given call stub.
3902 plt_off(typename
Plt_stub_entries::const_iterator p
, bool* is_iplt
) const
3904 const Symbol
* gsym
= p
->first
.sym_
;
3907 *is_iplt
= (gsym
->type() == elfcpp::STT_GNU_IFUNC
3908 && gsym
->can_use_relative_reloc(false));
3909 return gsym
->plt_offset();
3914 const Sized_relobj_file
<size
, big_endian
>* relobj
= p
->first
.object_
;
3915 unsigned int local_sym_index
= p
->first
.locsym_
;
3916 return relobj
->local_plt_offset(local_sym_index
);
3920 // Size of a given plt call stub.
3922 plt_call_size(typename
Plt_stub_entries::const_iterator p
) const
3928 Address plt_addr
= this->plt_off(p
, &is_iplt
);
3930 plt_addr
+= this->targ_
->iplt_section()->address();
3932 plt_addr
+= this->targ_
->plt_section()->address();
3933 Address got_addr
= this->targ_
->got_section()->output_section()->address();
3934 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
3935 <const Powerpc_relobj
<size
, big_endian
>*>(p
->first
.object_
);
3936 got_addr
+= ppcobj
->toc_base_offset();
3937 Address off
= plt_addr
- got_addr
;
3938 unsigned int bytes
= 4 * 4 + 4 * (ha(off
) != 0);
3939 if (this->targ_
->abiversion() < 2)
3941 bool static_chain
= parameters
->options().plt_static_chain();
3942 bool thread_safe
= this->targ_
->plt_thread_safe();
3946 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
)));
3948 unsigned int align
= 1 << parameters
->options().plt_align();
3950 bytes
= (bytes
+ align
- 1) & -align
;
3954 // Return long branch stub size.
3956 branch_stub_size(Address to
)
3959 = this->stub_address() + this->last_plt_size_
+ this->branch_size_
;
3960 if (to
- loc
+ (1 << 25) < 2 << 25)
3962 if (size
== 64 || !parameters
->options().output_is_position_independent())
3969 do_write(Output_file
*);
3971 // Plt call stub keys.
3975 Plt_stub_ent(const Symbol
* sym
)
3976 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3979 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3980 unsigned int locsym_index
)
3981 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
3984 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
3986 unsigned int r_type
,
3988 : sym_(sym
), object_(0), addend_(0), locsym_(0)
3991 this->addend_
= addend
;
3992 else if (parameters
->options().output_is_position_independent()
3993 && r_type
== elfcpp::R_PPC_PLTREL24
)
3995 this->addend_
= addend
;
3996 if (this->addend_
>= 32768)
3997 this->object_
= object
;
4001 Plt_stub_ent(const Sized_relobj_file
<size
, big_endian
>* object
,
4002 unsigned int locsym_index
,
4003 unsigned int r_type
,
4005 : sym_(NULL
), object_(object
), addend_(0), locsym_(locsym_index
)
4008 this->addend_
= addend
;
4009 else if (parameters
->options().output_is_position_independent()
4010 && r_type
== elfcpp::R_PPC_PLTREL24
)
4011 this->addend_
= addend
;
4014 bool operator==(const Plt_stub_ent
& that
) const
4016 return (this->sym_
== that
.sym_
4017 && this->object_
== that
.object_
4018 && this->addend_
== that
.addend_
4019 && this->locsym_
== that
.locsym_
);
4023 const Sized_relobj_file
<size
, big_endian
>* object_
;
4024 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend_
;
4025 unsigned int locsym_
;
4028 class Plt_stub_ent_hash
4031 size_t operator()(const Plt_stub_ent
& ent
) const
4033 return (reinterpret_cast<uintptr_t>(ent
.sym_
)
4034 ^ reinterpret_cast<uintptr_t>(ent
.object_
)
4040 // Long branch stub keys.
4041 class Branch_stub_ent
4044 Branch_stub_ent(const Powerpc_relobj
<size
, big_endian
>* obj
,
4045 Address to
, bool save_res
)
4046 : dest_(to
), toc_base_off_(0), save_res_(save_res
)
4049 toc_base_off_
= obj
->toc_base_offset();
4052 bool operator==(const Branch_stub_ent
& that
) const
4054 return (this->dest_
== that
.dest_
4056 || this->toc_base_off_
== that
.toc_base_off_
));
4060 unsigned int toc_base_off_
;
4064 class Branch_stub_ent_hash
4067 size_t operator()(const Branch_stub_ent
& ent
) const
4068 { return ent
.dest_
^ ent
.toc_base_off_
; }
4071 // In a sane world this would be a global.
4072 Target_powerpc
<size
, big_endian
>* targ_
;
4073 // Map sym/object/addend to stub offset.
4074 Plt_stub_entries plt_call_stubs_
;
4075 // Map destination address to stub offset.
4076 typedef Unordered_map
<Branch_stub_ent
, unsigned int,
4077 Branch_stub_ent_hash
> Branch_stub_entries
;
4078 Branch_stub_entries long_branch_stubs_
;
4079 // size of input section
4080 section_size_type orig_data_size_
;
4082 section_size_type plt_size_
, last_plt_size_
, branch_size_
, last_branch_size_
;
4083 // Some rare cases cause (PR/20529) fluctuation in stub table
4084 // size, which leads to an endless relax loop. This is to be fixed
4085 // by, after the first few iterations, allowing only increase of
4086 // stub table size. This variable sets the minimal possible size of
4087 // a stub table, it is zero for the first few iterations, then
4088 // increases monotonically.
4089 Address min_size_threshold_
;
4090 // Whether .eh_frame info has been created for this stub section.
4091 bool eh_frame_added_
;
4092 // Set if this stub group needs a copy of out-of-line register
4093 // save/restore functions.
4094 bool need_save_res_
;
4097 // Add a plt call stub, if we do not already have one for this
4098 // sym/object/addend combo.
4100 template<int size
, bool big_endian
>
4102 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4104 const Sized_relobj_file
<size
, big_endian
>* object
,
4106 unsigned int r_type
,
4109 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4110 unsigned int off
= this->plt_size_
;
4111 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4112 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4114 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4115 return this->can_reach_stub(from
, off
, r_type
);
4118 template<int size
, bool big_endian
>
4120 Stub_table
<size
, big_endian
>::add_plt_call_entry(
4122 const Sized_relobj_file
<size
, big_endian
>* object
,
4123 unsigned int locsym_index
,
4124 unsigned int r_type
,
4127 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4128 unsigned int off
= this->plt_size_
;
4129 std::pair
<typename
Plt_stub_entries::iterator
, bool> p
4130 = this->plt_call_stubs_
.insert(std::make_pair(ent
, off
));
4132 this->plt_size_
= off
+ this->plt_call_size(p
.first
);
4133 return this->can_reach_stub(from
, off
, r_type
);
4136 // Find a plt call stub.
4138 template<int size
, bool big_endian
>
4139 typename Stub_table
<size
, big_endian
>::Address
4140 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4141 const Sized_relobj_file
<size
, big_endian
>* object
,
4143 unsigned int r_type
,
4144 Address addend
) const
4146 Plt_stub_ent
ent(object
, gsym
, r_type
, addend
);
4147 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4148 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4151 template<int size
, bool big_endian
>
4152 typename Stub_table
<size
, big_endian
>::Address
4153 Stub_table
<size
, big_endian
>::find_plt_call_entry(const Symbol
* gsym
) const
4155 Plt_stub_ent
ent(gsym
);
4156 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4157 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4160 template<int size
, bool big_endian
>
4161 typename Stub_table
<size
, big_endian
>::Address
4162 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4163 const Sized_relobj_file
<size
, big_endian
>* object
,
4164 unsigned int locsym_index
,
4165 unsigned int r_type
,
4166 Address addend
) const
4168 Plt_stub_ent
ent(object
, locsym_index
, r_type
, addend
);
4169 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4170 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4173 template<int size
, bool big_endian
>
4174 typename Stub_table
<size
, big_endian
>::Address
4175 Stub_table
<size
, big_endian
>::find_plt_call_entry(
4176 const Sized_relobj_file
<size
, big_endian
>* object
,
4177 unsigned int locsym_index
) const
4179 Plt_stub_ent
ent(object
, locsym_index
);
4180 typename
Plt_stub_entries::const_iterator p
= this->plt_call_stubs_
.find(ent
);
4181 return p
== this->plt_call_stubs_
.end() ? invalid_address
: p
->second
;
4184 // Add a long branch stub if we don't already have one to given
4187 template<int size
, bool big_endian
>
4189 Stub_table
<size
, big_endian
>::add_long_branch_entry(
4190 const Powerpc_relobj
<size
, big_endian
>* object
,
4191 unsigned int r_type
,
4196 Branch_stub_ent
ent(object
, to
, save_res
);
4197 Address off
= this->branch_size_
;
4198 if (this->long_branch_stubs_
.insert(std::make_pair(ent
, off
)).second
)
4201 this->need_save_res_
= true;
4204 unsigned int stub_size
= this->branch_stub_size(to
);
4205 this->branch_size_
= off
+ stub_size
;
4206 if (size
== 64 && stub_size
!= 4)
4207 this->targ_
->add_branch_lookup_table(to
);
4210 return this->can_reach_stub(from
, off
, r_type
);
4213 // Find long branch stub offset.
4215 template<int size
, bool big_endian
>
4216 typename Stub_table
<size
, big_endian
>::Address
4217 Stub_table
<size
, big_endian
>::find_long_branch_entry(
4218 const Powerpc_relobj
<size
, big_endian
>* object
,
4221 Branch_stub_ent
ent(object
, to
, false);
4222 typename
Branch_stub_entries::const_iterator p
4223 = this->long_branch_stubs_
.find(ent
);
4224 if (p
== this->long_branch_stubs_
.end())
4225 return invalid_address
;
4226 if (p
->first
.save_res_
)
4227 return to
- this->targ_
->savres_section()->address() + this->branch_size_
;
4231 // A class to handle .glink.
4233 template<int size
, bool big_endian
>
4234 class Output_data_glink
: public Output_section_data
4237 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4238 static const Address invalid_address
= static_cast<Address
>(0) - 1;
4239 static const int pltresolve_size
= 16*4;
4241 Output_data_glink(Target_powerpc
<size
, big_endian
>* targ
)
4242 : Output_section_data(16), targ_(targ
), global_entry_stubs_(),
4243 end_branch_table_(), ge_size_(0)
4247 add_eh_frame(Layout
* layout
);
4250 add_global_entry(const Symbol
*);
4253 find_global_entry(const Symbol
*) const;
4256 global_entry_address() const
4258 gold_assert(this->is_data_size_valid());
4259 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4260 return this->address() + global_entry_off
;
4264 // Write to a map file.
4266 do_print_to_mapfile(Mapfile
* mapfile
) const
4267 { mapfile
->print_output_data(this, _("** glink")); }
4271 set_final_data_size();
4275 do_write(Output_file
*);
4277 // Allows access to .got and .plt for do_write.
4278 Target_powerpc
<size
, big_endian
>* targ_
;
4280 // Map sym to stub offset.
4281 typedef Unordered_map
<const Symbol
*, unsigned int> Global_entry_stub_entries
;
4282 Global_entry_stub_entries global_entry_stubs_
;
4284 unsigned int end_branch_table_
, ge_size_
;
4287 template<int size
, bool big_endian
>
4289 Output_data_glink
<size
, big_endian
>::add_eh_frame(Layout
* layout
)
4291 if (!parameters
->options().ld_generated_unwind_info())
4296 if (this->targ_
->abiversion() < 2)
4297 layout
->add_eh_frame_for_plt(this,
4298 Eh_cie
<64>::eh_frame_cie
,
4299 sizeof (Eh_cie
<64>::eh_frame_cie
),
4300 glink_eh_frame_fde_64v1
,
4301 sizeof (glink_eh_frame_fde_64v1
));
4303 layout
->add_eh_frame_for_plt(this,
4304 Eh_cie
<64>::eh_frame_cie
,
4305 sizeof (Eh_cie
<64>::eh_frame_cie
),
4306 glink_eh_frame_fde_64v2
,
4307 sizeof (glink_eh_frame_fde_64v2
));
4311 // 32-bit .glink can use the default since the CIE return
4312 // address reg, LR, is valid.
4313 layout
->add_eh_frame_for_plt(this,
4314 Eh_cie
<32>::eh_frame_cie
,
4315 sizeof (Eh_cie
<32>::eh_frame_cie
),
4317 sizeof (default_fde
));
4318 // Except where LR is used in a PIC __glink_PLTresolve.
4319 if (parameters
->options().output_is_position_independent())
4320 layout
->add_eh_frame_for_plt(this,
4321 Eh_cie
<32>::eh_frame_cie
,
4322 sizeof (Eh_cie
<32>::eh_frame_cie
),
4323 glink_eh_frame_fde_32
,
4324 sizeof (glink_eh_frame_fde_32
));
4328 template<int size
, bool big_endian
>
4330 Output_data_glink
<size
, big_endian
>::add_global_entry(const Symbol
* gsym
)
4332 std::pair
<typename
Global_entry_stub_entries::iterator
, bool> p
4333 = this->global_entry_stubs_
.insert(std::make_pair(gsym
, this->ge_size_
));
4335 this->ge_size_
+= 16;
4338 template<int size
, bool big_endian
>
4339 typename Output_data_glink
<size
, big_endian
>::Address
4340 Output_data_glink
<size
, big_endian
>::find_global_entry(const Symbol
* gsym
) const
4342 typename
Global_entry_stub_entries::const_iterator p
4343 = this->global_entry_stubs_
.find(gsym
);
4344 return p
== this->global_entry_stubs_
.end() ? invalid_address
: p
->second
;
4347 template<int size
, bool big_endian
>
4349 Output_data_glink
<size
, big_endian
>::set_final_data_size()
4351 unsigned int count
= this->targ_
->plt_entry_count();
4352 section_size_type total
= 0;
4358 // space for branch table
4359 total
+= 4 * (count
- 1);
4361 total
+= -total
& 15;
4362 total
+= this->pltresolve_size
;
4366 total
+= this->pltresolve_size
;
4368 // space for branch table
4370 if (this->targ_
->abiversion() < 2)
4374 total
+= 4 * (count
- 0x8000);
4378 this->end_branch_table_
= total
;
4379 total
= (total
+ 15) & -16;
4380 total
+= this->ge_size_
;
4382 this->set_data_size(total
);
4385 // Write out plt and long branch stub code.
4387 template<int size
, bool big_endian
>
4389 Stub_table
<size
, big_endian
>::do_write(Output_file
* of
)
4391 if (this->plt_call_stubs_
.empty()
4392 && this->long_branch_stubs_
.empty())
4395 const section_size_type start_off
= this->offset();
4396 const section_size_type off
= this->stub_offset();
4397 const section_size_type oview_size
=
4398 convert_to_section_size_type(this->data_size() - (off
- start_off
));
4399 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4404 const Output_data_got_powerpc
<size
, big_endian
>* got
4405 = this->targ_
->got_section();
4406 Address got_os_addr
= got
->output_section()->address();
4408 if (!this->plt_call_stubs_
.empty())
4410 // The base address of the .plt section.
4411 Address plt_base
= this->targ_
->plt_section()->address();
4412 Address iplt_base
= invalid_address
;
4414 // Write out plt call stubs.
4415 typename
Plt_stub_entries::const_iterator cs
;
4416 for (cs
= this->plt_call_stubs_
.begin();
4417 cs
!= this->plt_call_stubs_
.end();
4421 Address pltoff
= this->plt_off(cs
, &is_iplt
);
4422 Address plt_addr
= pltoff
;
4425 if (iplt_base
== invalid_address
)
4426 iplt_base
= this->targ_
->iplt_section()->address();
4427 plt_addr
+= iplt_base
;
4430 plt_addr
+= plt_base
;
4431 const Powerpc_relobj
<size
, big_endian
>* ppcobj
= static_cast
4432 <const Powerpc_relobj
<size
, big_endian
>*>(cs
->first
.object_
);
4433 Address got_addr
= got_os_addr
+ ppcobj
->toc_base_offset();
4434 Address off
= plt_addr
- got_addr
;
4436 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
4437 gold_error(_("%s: linkage table error against `%s'"),
4438 cs
->first
.object_
->name().c_str(),
4439 cs
->first
.sym_
->demangled_name().c_str());
4441 bool plt_load_toc
= this->targ_
->abiversion() < 2;
4443 = plt_load_toc
&& parameters
->options().plt_static_chain();
4445 = plt_load_toc
&& this->targ_
->plt_thread_safe();
4446 bool use_fake_dep
= false;
4447 Address cmp_branch_off
= 0;
4450 unsigned int pltindex
4451 = ((pltoff
- this->targ_
->first_plt_entry_offset())
4452 / this->targ_
->plt_entry_size());
4454 = (this->targ_
->glink_section()->pltresolve_size
4456 if (pltindex
> 32768)
4457 glinkoff
+= (pltindex
- 32768) * 4;
4459 = this->targ_
->glink_section()->address() + glinkoff
;
4461 = (this->stub_address() + cs
->second
+ 24
4462 + 4 * (ha(off
) != 0)
4463 + 4 * (ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4464 + 4 * static_chain
);
4465 cmp_branch_off
= to
- from
;
4466 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
4469 p
= oview
+ cs
->second
;
4472 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4476 write_insn
<big_endian
>(p
, addis_11_2
+ ha(off
));
4478 write_insn
<big_endian
>(p
, ld_12_11
+ l(off
));
4483 write_insn
<big_endian
>(p
, addis_12_2
+ ha(off
));
4485 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
));
4489 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4491 write_insn
<big_endian
>(p
, addi_11_11
+ l(off
));
4495 write_insn
<big_endian
>(p
, mtctr_12
);
4501 write_insn
<big_endian
>(p
, xor_2_12_12
);
4503 write_insn
<big_endian
>(p
, add_11_11_2
);
4506 write_insn
<big_endian
>(p
, ld_2_11
+ l(off
+ 8));
4510 write_insn
<big_endian
>(p
, ld_11_11
+ l(off
+ 16));
4517 write_insn
<big_endian
>(p
, std_2_1
+ this->targ_
->stk_toc());
4519 write_insn
<big_endian
>(p
, ld_12_2
+ l(off
));
4522 && ha(off
+ 8 + 8 * static_chain
) != ha(off
))
4524 write_insn
<big_endian
>(p
, addi_2_2
+ l(off
));
4528 write_insn
<big_endian
>(p
, mtctr_12
);
4534 write_insn
<big_endian
>(p
, xor_11_12_12
);
4536 write_insn
<big_endian
>(p
, add_2_2_11
);
4541 write_insn
<big_endian
>(p
, ld_11_2
+ l(off
+ 16));
4544 write_insn
<big_endian
>(p
, ld_2_2
+ l(off
+ 8));
4548 if (thread_safe
&& !use_fake_dep
)
4550 write_insn
<big_endian
>(p
, cmpldi_2_0
);
4552 write_insn
<big_endian
>(p
, bnectr_p4
);
4554 write_insn
<big_endian
>(p
, b
| (cmp_branch_off
& 0x3fffffc));
4557 write_insn
<big_endian
>(p
, bctr
);
4561 // Write out long branch stubs.
4562 typename
Branch_stub_entries::const_iterator bs
;
4563 for (bs
= this->long_branch_stubs_
.begin();
4564 bs
!= this->long_branch_stubs_
.end();
4567 if (bs
->first
.save_res_
)
4569 p
= oview
+ this->plt_size_
+ bs
->second
;
4570 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4571 Address delta
= bs
->first
.dest_
- loc
;
4572 if (delta
+ (1 << 25) < 2 << 25)
4573 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4577 = this->targ_
->find_branch_lookup_table(bs
->first
.dest_
);
4578 gold_assert(brlt_addr
!= invalid_address
);
4579 brlt_addr
+= this->targ_
->brlt_section()->address();
4580 Address got_addr
= got_os_addr
+ bs
->first
.toc_base_off_
;
4581 Address brltoff
= brlt_addr
- got_addr
;
4582 if (ha(brltoff
) == 0)
4584 write_insn
<big_endian
>(p
, ld_12_2
+ l(brltoff
)), p
+= 4;
4588 write_insn
<big_endian
>(p
, addis_12_2
+ ha(brltoff
)), p
+= 4;
4589 write_insn
<big_endian
>(p
, ld_12_12
+ l(brltoff
)), p
+= 4;
4591 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4592 write_insn
<big_endian
>(p
, bctr
);
4598 if (!this->plt_call_stubs_
.empty())
4600 // The base address of the .plt section.
4601 Address plt_base
= this->targ_
->plt_section()->address();
4602 Address iplt_base
= invalid_address
;
4603 // The address of _GLOBAL_OFFSET_TABLE_.
4604 Address g_o_t
= invalid_address
;
4606 // Write out plt call stubs.
4607 typename
Plt_stub_entries::const_iterator cs
;
4608 for (cs
= this->plt_call_stubs_
.begin();
4609 cs
!= this->plt_call_stubs_
.end();
4613 Address plt_addr
= this->plt_off(cs
, &is_iplt
);
4616 if (iplt_base
== invalid_address
)
4617 iplt_base
= this->targ_
->iplt_section()->address();
4618 plt_addr
+= iplt_base
;
4621 plt_addr
+= plt_base
;
4623 p
= oview
+ cs
->second
;
4624 if (parameters
->options().output_is_position_independent())
4627 const Powerpc_relobj
<size
, big_endian
>* ppcobj
4628 = (static_cast<const Powerpc_relobj
<size
, big_endian
>*>
4629 (cs
->first
.object_
));
4630 if (ppcobj
!= NULL
&& cs
->first
.addend_
>= 32768)
4632 unsigned int got2
= ppcobj
->got2_shndx();
4633 got_addr
= ppcobj
->get_output_section_offset(got2
);
4634 gold_assert(got_addr
!= invalid_address
);
4635 got_addr
+= (ppcobj
->output_section(got2
)->address()
4636 + cs
->first
.addend_
);
4640 if (g_o_t
== invalid_address
)
4642 const Output_data_got_powerpc
<size
, big_endian
>* got
4643 = this->targ_
->got_section();
4644 g_o_t
= got
->address() + got
->g_o_t();
4649 Address off
= plt_addr
- got_addr
;
4652 write_insn
<big_endian
>(p
+ 0, lwz_11_30
+ l(off
));
4653 write_insn
<big_endian
>(p
+ 4, mtctr_11
);
4654 write_insn
<big_endian
>(p
+ 8, bctr
);
4658 write_insn
<big_endian
>(p
+ 0, addis_11_30
+ ha(off
));
4659 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(off
));
4660 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4661 write_insn
<big_endian
>(p
+ 12, bctr
);
4666 write_insn
<big_endian
>(p
+ 0, lis_11
+ ha(plt_addr
));
4667 write_insn
<big_endian
>(p
+ 4, lwz_11_11
+ l(plt_addr
));
4668 write_insn
<big_endian
>(p
+ 8, mtctr_11
);
4669 write_insn
<big_endian
>(p
+ 12, bctr
);
4674 // Write out long branch stubs.
4675 typename
Branch_stub_entries::const_iterator bs
;
4676 for (bs
= this->long_branch_stubs_
.begin();
4677 bs
!= this->long_branch_stubs_
.end();
4680 if (bs
->first
.save_res_
)
4682 p
= oview
+ this->plt_size_
+ bs
->second
;
4683 Address loc
= this->stub_address() + this->plt_size_
+ bs
->second
;
4684 Address delta
= bs
->first
.dest_
- loc
;
4685 if (delta
+ (1 << 25) < 2 << 25)
4686 write_insn
<big_endian
>(p
, b
| (delta
& 0x3fffffc));
4687 else if (!parameters
->options().output_is_position_independent())
4689 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(bs
->first
.dest_
));
4690 write_insn
<big_endian
>(p
+ 4, addi_12_12
+ l(bs
->first
.dest_
));
4691 write_insn
<big_endian
>(p
+ 8, mtctr_12
);
4692 write_insn
<big_endian
>(p
+ 12, bctr
);
4697 write_insn
<big_endian
>(p
+ 0, mflr_0
);
4698 write_insn
<big_endian
>(p
+ 4, bcl_20_31
);
4699 write_insn
<big_endian
>(p
+ 8, mflr_12
);
4700 write_insn
<big_endian
>(p
+ 12, addis_12_12
+ ha(delta
));
4701 write_insn
<big_endian
>(p
+ 16, addi_12_12
+ l(delta
));
4702 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4703 write_insn
<big_endian
>(p
+ 24, mtctr_12
);
4704 write_insn
<big_endian
>(p
+ 28, bctr
);
4708 if (this->need_save_res_
)
4710 p
= oview
+ this->plt_size_
+ this->branch_size_
;
4711 memcpy (p
, this->targ_
->savres_section()->contents(),
4712 this->targ_
->savres_section()->data_size());
4716 // Write out .glink.
4718 template<int size
, bool big_endian
>
4720 Output_data_glink
<size
, big_endian
>::do_write(Output_file
* of
)
4722 const section_size_type off
= this->offset();
4723 const section_size_type oview_size
=
4724 convert_to_section_size_type(this->data_size());
4725 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
4728 // The base address of the .plt section.
4729 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
4730 Address plt_base
= this->targ_
->plt_section()->address();
4734 if (this->end_branch_table_
!= 0)
4736 // Write pltresolve stub.
4738 Address after_bcl
= this->address() + 16;
4739 Address pltoff
= plt_base
- after_bcl
;
4741 elfcpp::Swap
<64, big_endian
>::writeval(p
, pltoff
), p
+= 8;
4743 if (this->targ_
->abiversion() < 2)
4745 write_insn
<big_endian
>(p
, mflr_12
), p
+= 4;
4746 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4747 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4748 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4749 write_insn
<big_endian
>(p
, mtlr_12
), p
+= 4;
4750 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4751 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4752 write_insn
<big_endian
>(p
, ld_2_11
+ 8), p
+= 4;
4753 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4754 write_insn
<big_endian
>(p
, ld_11_11
+ 16), p
+= 4;
4758 write_insn
<big_endian
>(p
, mflr_0
), p
+= 4;
4759 write_insn
<big_endian
>(p
, bcl_20_31
), p
+= 4;
4760 write_insn
<big_endian
>(p
, mflr_11
), p
+= 4;
4761 write_insn
<big_endian
>(p
, ld_2_11
+ l(-16)), p
+= 4;
4762 write_insn
<big_endian
>(p
, mtlr_0
), p
+= 4;
4763 write_insn
<big_endian
>(p
, sub_12_12_11
), p
+= 4;
4764 write_insn
<big_endian
>(p
, add_11_2_11
), p
+= 4;
4765 write_insn
<big_endian
>(p
, addi_0_12
+ l(-48)), p
+= 4;
4766 write_insn
<big_endian
>(p
, ld_12_11
+ 0), p
+= 4;
4767 write_insn
<big_endian
>(p
, srdi_0_0_2
), p
+= 4;
4768 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4769 write_insn
<big_endian
>(p
, ld_11_11
+ 8), p
+= 4;
4771 write_insn
<big_endian
>(p
, bctr
), p
+= 4;
4772 while (p
< oview
+ this->pltresolve_size
)
4773 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4775 // Write lazy link call stubs.
4777 while (p
< oview
+ this->end_branch_table_
)
4779 if (this->targ_
->abiversion() < 2)
4783 write_insn
<big_endian
>(p
, li_0_0
+ indx
), p
+= 4;
4787 write_insn
<big_endian
>(p
, lis_0
+ hi(indx
)), p
+= 4;
4788 write_insn
<big_endian
>(p
, ori_0_0_0
+ l(indx
)), p
+= 4;
4791 uint32_t branch_off
= 8 - (p
- oview
);
4792 write_insn
<big_endian
>(p
, b
+ (branch_off
& 0x3fffffc)), p
+= 4;
4797 Address plt_base
= this->targ_
->plt_section()->address();
4798 Address iplt_base
= invalid_address
;
4799 unsigned int global_entry_off
= (this->end_branch_table_
+ 15) & -16;
4800 Address global_entry_base
= this->address() + global_entry_off
;
4801 typename
Global_entry_stub_entries::const_iterator ge
;
4802 for (ge
= this->global_entry_stubs_
.begin();
4803 ge
!= this->global_entry_stubs_
.end();
4806 p
= oview
+ global_entry_off
+ ge
->second
;
4807 Address plt_addr
= ge
->first
->plt_offset();
4808 if (ge
->first
->type() == elfcpp::STT_GNU_IFUNC
4809 && ge
->first
->can_use_relative_reloc(false))
4811 if (iplt_base
== invalid_address
)
4812 iplt_base
= this->targ_
->iplt_section()->address();
4813 plt_addr
+= iplt_base
;
4816 plt_addr
+= plt_base
;
4817 Address my_addr
= global_entry_base
+ ge
->second
;
4818 Address off
= plt_addr
- my_addr
;
4820 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
4821 gold_error(_("%s: linkage table error against `%s'"),
4822 ge
->first
->object()->name().c_str(),
4823 ge
->first
->demangled_name().c_str());
4825 write_insn
<big_endian
>(p
, addis_12_12
+ ha(off
)), p
+= 4;
4826 write_insn
<big_endian
>(p
, ld_12_12
+ l(off
)), p
+= 4;
4827 write_insn
<big_endian
>(p
, mtctr_12
), p
+= 4;
4828 write_insn
<big_endian
>(p
, bctr
);
4833 const Output_data_got_powerpc
<size
, big_endian
>* got
4834 = this->targ_
->got_section();
4835 // The address of _GLOBAL_OFFSET_TABLE_.
4836 Address g_o_t
= got
->address() + got
->g_o_t();
4838 // Write out pltresolve branch table.
4840 unsigned int the_end
= oview_size
- this->pltresolve_size
;
4841 unsigned char* end_p
= oview
+ the_end
;
4842 while (p
< end_p
- 8 * 4)
4843 write_insn
<big_endian
>(p
, b
+ end_p
- p
), p
+= 4;
4845 write_insn
<big_endian
>(p
, nop
), p
+= 4;
4847 // Write out pltresolve call stub.
4848 if (parameters
->options().output_is_position_independent())
4850 Address res0_off
= 0;
4851 Address after_bcl_off
= the_end
+ 12;
4852 Address bcl_res0
= after_bcl_off
- res0_off
;
4854 write_insn
<big_endian
>(p
+ 0, addis_11_11
+ ha(bcl_res0
));
4855 write_insn
<big_endian
>(p
+ 4, mflr_0
);
4856 write_insn
<big_endian
>(p
+ 8, bcl_20_31
);
4857 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(bcl_res0
));
4858 write_insn
<big_endian
>(p
+ 16, mflr_12
);
4859 write_insn
<big_endian
>(p
+ 20, mtlr_0
);
4860 write_insn
<big_endian
>(p
+ 24, sub_11_11_12
);
4862 Address got_bcl
= g_o_t
+ 4 - (after_bcl_off
+ this->address());
4864 write_insn
<big_endian
>(p
+ 28, addis_12_12
+ ha(got_bcl
));
4865 if (ha(got_bcl
) == ha(got_bcl
+ 4))
4867 write_insn
<big_endian
>(p
+ 32, lwz_0_12
+ l(got_bcl
));
4868 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ l(got_bcl
+ 4));
4872 write_insn
<big_endian
>(p
+ 32, lwzu_0_12
+ l(got_bcl
));
4873 write_insn
<big_endian
>(p
+ 36, lwz_12_12
+ 4);
4875 write_insn
<big_endian
>(p
+ 40, mtctr_0
);
4876 write_insn
<big_endian
>(p
+ 44, add_0_11_11
);
4877 write_insn
<big_endian
>(p
+ 48, add_11_0_11
);
4878 write_insn
<big_endian
>(p
+ 52, bctr
);
4879 write_insn
<big_endian
>(p
+ 56, nop
);
4880 write_insn
<big_endian
>(p
+ 60, nop
);
4884 Address res0
= this->address();
4886 write_insn
<big_endian
>(p
+ 0, lis_12
+ ha(g_o_t
+ 4));
4887 write_insn
<big_endian
>(p
+ 4, addis_11_11
+ ha(-res0
));
4888 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4889 write_insn
<big_endian
>(p
+ 8, lwz_0_12
+ l(g_o_t
+ 4));
4891 write_insn
<big_endian
>(p
+ 8, lwzu_0_12
+ l(g_o_t
+ 4));
4892 write_insn
<big_endian
>(p
+ 12, addi_11_11
+ l(-res0
));
4893 write_insn
<big_endian
>(p
+ 16, mtctr_0
);
4894 write_insn
<big_endian
>(p
+ 20, add_0_11_11
);
4895 if (ha(g_o_t
+ 4) == ha(g_o_t
+ 8))
4896 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ l(g_o_t
+ 8));
4898 write_insn
<big_endian
>(p
+ 24, lwz_12_12
+ 4);
4899 write_insn
<big_endian
>(p
+ 28, add_11_0_11
);
4900 write_insn
<big_endian
>(p
+ 32, bctr
);
4901 write_insn
<big_endian
>(p
+ 36, nop
);
4902 write_insn
<big_endian
>(p
+ 40, nop
);
4903 write_insn
<big_endian
>(p
+ 44, nop
);
4904 write_insn
<big_endian
>(p
+ 48, nop
);
4905 write_insn
<big_endian
>(p
+ 52, nop
);
4906 write_insn
<big_endian
>(p
+ 56, nop
);
4907 write_insn
<big_endian
>(p
+ 60, nop
);
4912 of
->write_output_view(off
, oview_size
, oview
);
4916 // A class to handle linker generated save/restore functions.
4918 template<int size
, bool big_endian
>
4919 class Output_data_save_res
: public Output_section_data_build
4922 Output_data_save_res(Symbol_table
* symtab
);
4924 const unsigned char*
4931 // Write to a map file.
4933 do_print_to_mapfile(Mapfile
* mapfile
) const
4934 { mapfile
->print_output_data(this, _("** save/restore")); }
4937 do_write(Output_file
*);
4940 // The maximum size of save/restore contents.
4941 static const unsigned int savres_max
= 218*4;
4944 savres_define(Symbol_table
* symtab
,
4946 unsigned int lo
, unsigned int hi
,
4947 unsigned char* write_ent(unsigned char*, int),
4948 unsigned char* write_tail(unsigned char*, int));
4950 unsigned char *contents_
;
4953 template<bool big_endian
>
4954 static unsigned char*
4955 savegpr0(unsigned char* p
, int r
)
4957 uint32_t insn
= std_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4958 write_insn
<big_endian
>(p
, insn
);
4962 template<bool big_endian
>
4963 static unsigned char*
4964 savegpr0_tail(unsigned char* p
, int r
)
4966 p
= savegpr0
<big_endian
>(p
, r
);
4967 uint32_t insn
= std_0_1
+ 16;
4968 write_insn
<big_endian
>(p
, insn
);
4970 write_insn
<big_endian
>(p
, blr
);
4974 template<bool big_endian
>
4975 static unsigned char*
4976 restgpr0(unsigned char* p
, int r
)
4978 uint32_t insn
= ld_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
4979 write_insn
<big_endian
>(p
, insn
);
4983 template<bool big_endian
>
4984 static unsigned char*
4985 restgpr0_tail(unsigned char* p
, int r
)
4987 uint32_t insn
= ld_0_1
+ 16;
4988 write_insn
<big_endian
>(p
, insn
);
4990 p
= restgpr0
<big_endian
>(p
, r
);
4991 write_insn
<big_endian
>(p
, mtlr_0
);
4995 p
= restgpr0
<big_endian
>(p
, 30);
4996 p
= restgpr0
<big_endian
>(p
, 31);
4998 write_insn
<big_endian
>(p
, blr
);
5002 template<bool big_endian
>
5003 static unsigned char*
5004 savegpr1(unsigned char* p
, int r
)
5006 uint32_t insn
= std_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5007 write_insn
<big_endian
>(p
, insn
);
5011 template<bool big_endian
>
5012 static unsigned char*
5013 savegpr1_tail(unsigned char* p
, int r
)
5015 p
= savegpr1
<big_endian
>(p
, r
);
5016 write_insn
<big_endian
>(p
, blr
);
5020 template<bool big_endian
>
5021 static unsigned char*
5022 restgpr1(unsigned char* p
, int r
)
5024 uint32_t insn
= ld_0_12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5025 write_insn
<big_endian
>(p
, insn
);
5029 template<bool big_endian
>
5030 static unsigned char*
5031 restgpr1_tail(unsigned char* p
, int r
)
5033 p
= restgpr1
<big_endian
>(p
, r
);
5034 write_insn
<big_endian
>(p
, blr
);
5038 template<bool big_endian
>
5039 static unsigned char*
5040 savefpr(unsigned char* p
, int r
)
5042 uint32_t insn
= stfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5043 write_insn
<big_endian
>(p
, insn
);
5047 template<bool big_endian
>
5048 static unsigned char*
5049 savefpr0_tail(unsigned char* p
, int r
)
5051 p
= savefpr
<big_endian
>(p
, r
);
5052 write_insn
<big_endian
>(p
, std_0_1
+ 16);
5054 write_insn
<big_endian
>(p
, blr
);
5058 template<bool big_endian
>
5059 static unsigned char*
5060 restfpr(unsigned char* p
, int r
)
5062 uint32_t insn
= lfd_0_1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8;
5063 write_insn
<big_endian
>(p
, insn
);
5067 template<bool big_endian
>
5068 static unsigned char*
5069 restfpr0_tail(unsigned char* p
, int r
)
5071 write_insn
<big_endian
>(p
, ld_0_1
+ 16);
5073 p
= restfpr
<big_endian
>(p
, r
);
5074 write_insn
<big_endian
>(p
, mtlr_0
);
5078 p
= restfpr
<big_endian
>(p
, 30);
5079 p
= restfpr
<big_endian
>(p
, 31);
5081 write_insn
<big_endian
>(p
, blr
);
5085 template<bool big_endian
>
5086 static unsigned char*
5087 savefpr1_tail(unsigned char* p
, int r
)
5089 p
= savefpr
<big_endian
>(p
, r
);
5090 write_insn
<big_endian
>(p
, blr
);
5094 template<bool big_endian
>
5095 static unsigned char*
5096 restfpr1_tail(unsigned char* p
, int r
)
5098 p
= restfpr
<big_endian
>(p
, r
);
5099 write_insn
<big_endian
>(p
, blr
);
5103 template<bool big_endian
>
5104 static unsigned char*
5105 savevr(unsigned char* p
, int r
)
5107 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5108 write_insn
<big_endian
>(p
, insn
);
5110 insn
= stvx_0_12_0
+ (r
<< 21);
5111 write_insn
<big_endian
>(p
, insn
);
5115 template<bool big_endian
>
5116 static unsigned char*
5117 savevr_tail(unsigned char* p
, int r
)
5119 p
= savevr
<big_endian
>(p
, r
);
5120 write_insn
<big_endian
>(p
, blr
);
5124 template<bool big_endian
>
5125 static unsigned char*
5126 restvr(unsigned char* p
, int r
)
5128 uint32_t insn
= li_12_0
+ (1 << 16) - (32 - r
) * 16;
5129 write_insn
<big_endian
>(p
, insn
);
5131 insn
= lvx_0_12_0
+ (r
<< 21);
5132 write_insn
<big_endian
>(p
, insn
);
5136 template<bool big_endian
>
5137 static unsigned char*
5138 restvr_tail(unsigned char* p
, int r
)
5140 p
= restvr
<big_endian
>(p
, r
);
5141 write_insn
<big_endian
>(p
, blr
);
5146 template<int size
, bool big_endian
>
5147 Output_data_save_res
<size
, big_endian
>::Output_data_save_res(
5148 Symbol_table
* symtab
)
5149 : Output_section_data_build(4),
5152 this->savres_define(symtab
,
5153 "_savegpr0_", 14, 31,
5154 savegpr0
<big_endian
>, savegpr0_tail
<big_endian
>);
5155 this->savres_define(symtab
,
5156 "_restgpr0_", 14, 29,
5157 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5158 this->savres_define(symtab
,
5159 "_restgpr0_", 30, 31,
5160 restgpr0
<big_endian
>, restgpr0_tail
<big_endian
>);
5161 this->savres_define(symtab
,
5162 "_savegpr1_", 14, 31,
5163 savegpr1
<big_endian
>, savegpr1_tail
<big_endian
>);
5164 this->savres_define(symtab
,
5165 "_restgpr1_", 14, 31,
5166 restgpr1
<big_endian
>, restgpr1_tail
<big_endian
>);
5167 this->savres_define(symtab
,
5168 "_savefpr_", 14, 31,
5169 savefpr
<big_endian
>, savefpr0_tail
<big_endian
>);
5170 this->savres_define(symtab
,
5171 "_restfpr_", 14, 29,
5172 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5173 this->savres_define(symtab
,
5174 "_restfpr_", 30, 31,
5175 restfpr
<big_endian
>, restfpr0_tail
<big_endian
>);
5176 this->savres_define(symtab
,
5178 savefpr
<big_endian
>, savefpr1_tail
<big_endian
>);
5179 this->savres_define(symtab
,
5181 restfpr
<big_endian
>, restfpr1_tail
<big_endian
>);
5182 this->savres_define(symtab
,
5184 savevr
<big_endian
>, savevr_tail
<big_endian
>);
5185 this->savres_define(symtab
,
5187 restvr
<big_endian
>, restvr_tail
<big_endian
>);
5190 template<int size
, bool big_endian
>
5192 Output_data_save_res
<size
, big_endian
>::savres_define(
5193 Symbol_table
* symtab
,
5195 unsigned int lo
, unsigned int hi
,
5196 unsigned char* write_ent(unsigned char*, int),
5197 unsigned char* write_tail(unsigned char*, int))
5199 size_t len
= strlen(name
);
5200 bool writing
= false;
5203 memcpy(sym
, name
, len
);
5206 for (unsigned int i
= lo
; i
<= hi
; i
++)
5208 sym
[len
+ 0] = i
/ 10 + '0';
5209 sym
[len
+ 1] = i
% 10 + '0';
5210 Symbol
* gsym
= symtab
->lookup(sym
);
5211 bool refd
= gsym
!= NULL
&& gsym
->is_undefined();
5212 writing
= writing
|| refd
;
5215 if (this->contents_
== NULL
)
5216 this->contents_
= new unsigned char[this->savres_max
];
5218 section_size_type value
= this->current_data_size();
5219 unsigned char* p
= this->contents_
+ value
;
5221 p
= write_ent(p
, i
);
5223 p
= write_tail(p
, i
);
5224 section_size_type cur_size
= p
- this->contents_
;
5225 this->set_current_data_size(cur_size
);
5227 symtab
->define_in_output_data(sym
, NULL
, Symbol_table::PREDEFINED
,
5228 this, value
, cur_size
- value
,
5229 elfcpp::STT_FUNC
, elfcpp::STB_GLOBAL
,
5230 elfcpp::STV_HIDDEN
, 0, false, false);
5235 // Write out save/restore.
5237 template<int size
, bool big_endian
>
5239 Output_data_save_res
<size
, big_endian
>::do_write(Output_file
* of
)
5241 const section_size_type off
= this->offset();
5242 const section_size_type oview_size
=
5243 convert_to_section_size_type(this->data_size());
5244 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
5245 memcpy(oview
, this->contents_
, oview_size
);
5246 of
->write_output_view(off
, oview_size
, oview
);
5250 // Create the glink section.
5252 template<int size
, bool big_endian
>
5254 Target_powerpc
<size
, big_endian
>::make_glink_section(Layout
* layout
)
5256 if (this->glink_
== NULL
)
5258 this->glink_
= new Output_data_glink
<size
, big_endian
>(this);
5259 this->glink_
->add_eh_frame(layout
);
5260 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
5261 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
5262 this->glink_
, ORDER_TEXT
, false);
5266 // Create a PLT entry for a global symbol.
5268 template<int size
, bool big_endian
>
5270 Target_powerpc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
5274 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
5275 && gsym
->can_use_relative_reloc(false))
5277 if (this->iplt_
== NULL
)
5278 this->make_iplt_section(symtab
, layout
);
5279 this->iplt_
->add_ifunc_entry(gsym
);
5283 if (this->plt_
== NULL
)
5284 this->make_plt_section(symtab
, layout
);
5285 this->plt_
->add_entry(gsym
);
5289 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
5291 template<int size
, bool big_endian
>
5293 Target_powerpc
<size
, big_endian
>::make_local_ifunc_plt_entry(
5294 Symbol_table
* symtab
,
5296 Sized_relobj_file
<size
, big_endian
>* relobj
,
5299 if (this->iplt_
== NULL
)
5300 this->make_iplt_section(symtab
, layout
);
5301 this->iplt_
->add_local_ifunc_entry(relobj
, r_sym
);
5304 // Return the number of entries in the PLT.
5306 template<int size
, bool big_endian
>
5308 Target_powerpc
<size
, big_endian
>::plt_entry_count() const
5310 if (this->plt_
== NULL
)
5312 return this->plt_
->entry_count();
5315 // Create a GOT entry for local dynamic __tls_get_addr calls.
5317 template<int size
, bool big_endian
>
5319 Target_powerpc
<size
, big_endian
>::tlsld_got_offset(
5320 Symbol_table
* symtab
,
5322 Sized_relobj_file
<size
, big_endian
>* object
)
5324 if (this->tlsld_got_offset_
== -1U)
5326 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
5327 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
5328 Output_data_got_powerpc
<size
, big_endian
>* got
5329 = this->got_section(symtab
, layout
);
5330 unsigned int got_offset
= got
->add_constant_pair(0, 0);
5331 rela_dyn
->add_local(object
, 0, elfcpp::R_POWERPC_DTPMOD
, got
,
5333 this->tlsld_got_offset_
= got_offset
;
5335 return this->tlsld_got_offset_
;
5338 // Get the Reference_flags for a particular relocation.
5340 template<int size
, bool big_endian
>
5342 Target_powerpc
<size
, big_endian
>::Scan::get_reference_flags(
5343 unsigned int r_type
,
5344 const Target_powerpc
* target
)
5350 case elfcpp::R_POWERPC_NONE
:
5351 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5352 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5353 case elfcpp::R_PPC64_TOC
:
5354 // No symbol reference.
5357 case elfcpp::R_PPC64_ADDR64
:
5358 case elfcpp::R_PPC64_UADDR64
:
5359 case elfcpp::R_POWERPC_ADDR32
:
5360 case elfcpp::R_POWERPC_UADDR32
:
5361 case elfcpp::R_POWERPC_ADDR16
:
5362 case elfcpp::R_POWERPC_UADDR16
:
5363 case elfcpp::R_POWERPC_ADDR16_LO
:
5364 case elfcpp::R_POWERPC_ADDR16_HI
:
5365 case elfcpp::R_POWERPC_ADDR16_HA
:
5366 ref
= Symbol::ABSOLUTE_REF
;
5369 case elfcpp::R_POWERPC_ADDR24
:
5370 case elfcpp::R_POWERPC_ADDR14
:
5371 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5372 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5373 ref
= Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
5376 case elfcpp::R_PPC64_REL64
:
5377 case elfcpp::R_POWERPC_REL32
:
5378 case elfcpp::R_PPC_LOCAL24PC
:
5379 case elfcpp::R_POWERPC_REL16
:
5380 case elfcpp::R_POWERPC_REL16_LO
:
5381 case elfcpp::R_POWERPC_REL16_HI
:
5382 case elfcpp::R_POWERPC_REL16_HA
:
5383 ref
= Symbol::RELATIVE_REF
;
5386 case elfcpp::R_POWERPC_REL24
:
5387 case elfcpp::R_PPC_PLTREL24
:
5388 case elfcpp::R_POWERPC_REL14
:
5389 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5390 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5391 ref
= Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
5394 case elfcpp::R_POWERPC_GOT16
:
5395 case elfcpp::R_POWERPC_GOT16_LO
:
5396 case elfcpp::R_POWERPC_GOT16_HI
:
5397 case elfcpp::R_POWERPC_GOT16_HA
:
5398 case elfcpp::R_PPC64_GOT16_DS
:
5399 case elfcpp::R_PPC64_GOT16_LO_DS
:
5400 case elfcpp::R_PPC64_TOC16
:
5401 case elfcpp::R_PPC64_TOC16_LO
:
5402 case elfcpp::R_PPC64_TOC16_HI
:
5403 case elfcpp::R_PPC64_TOC16_HA
:
5404 case elfcpp::R_PPC64_TOC16_DS
:
5405 case elfcpp::R_PPC64_TOC16_LO_DS
:
5406 ref
= Symbol::RELATIVE_REF
;
5409 case elfcpp::R_POWERPC_GOT_TPREL16
:
5410 case elfcpp::R_POWERPC_TLS
:
5411 ref
= Symbol::TLS_REF
;
5414 case elfcpp::R_POWERPC_COPY
:
5415 case elfcpp::R_POWERPC_GLOB_DAT
:
5416 case elfcpp::R_POWERPC_JMP_SLOT
:
5417 case elfcpp::R_POWERPC_RELATIVE
:
5418 case elfcpp::R_POWERPC_DTPMOD
:
5420 // Not expected. We will give an error later.
5424 if (size
== 64 && target
->abiversion() < 2)
5425 ref
|= Symbol::FUNC_DESC_ABI
;
5429 // Report an unsupported relocation against a local symbol.
5431 template<int size
, bool big_endian
>
5433 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_local(
5434 Sized_relobj_file
<size
, big_endian
>* object
,
5435 unsigned int r_type
)
5437 gold_error(_("%s: unsupported reloc %u against local symbol"),
5438 object
->name().c_str(), r_type
);
5441 // We are about to emit a dynamic relocation of type R_TYPE. If the
5442 // dynamic linker does not support it, issue an error.
5444 template<int size
, bool big_endian
>
5446 Target_powerpc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
,
5447 unsigned int r_type
)
5449 gold_assert(r_type
!= elfcpp::R_POWERPC_NONE
);
5451 // These are the relocation types supported by glibc for both 32-bit
5452 // and 64-bit powerpc.
5455 case elfcpp::R_POWERPC_NONE
:
5456 case elfcpp::R_POWERPC_RELATIVE
:
5457 case elfcpp::R_POWERPC_GLOB_DAT
:
5458 case elfcpp::R_POWERPC_DTPMOD
:
5459 case elfcpp::R_POWERPC_DTPREL
:
5460 case elfcpp::R_POWERPC_TPREL
:
5461 case elfcpp::R_POWERPC_JMP_SLOT
:
5462 case elfcpp::R_POWERPC_COPY
:
5463 case elfcpp::R_POWERPC_IRELATIVE
:
5464 case elfcpp::R_POWERPC_ADDR32
:
5465 case elfcpp::R_POWERPC_UADDR32
:
5466 case elfcpp::R_POWERPC_ADDR24
:
5467 case elfcpp::R_POWERPC_ADDR16
:
5468 case elfcpp::R_POWERPC_UADDR16
:
5469 case elfcpp::R_POWERPC_ADDR16_LO
:
5470 case elfcpp::R_POWERPC_ADDR16_HI
:
5471 case elfcpp::R_POWERPC_ADDR16_HA
:
5472 case elfcpp::R_POWERPC_ADDR14
:
5473 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5474 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5475 case elfcpp::R_POWERPC_REL32
:
5476 case elfcpp::R_POWERPC_REL24
:
5477 case elfcpp::R_POWERPC_TPREL16
:
5478 case elfcpp::R_POWERPC_TPREL16_LO
:
5479 case elfcpp::R_POWERPC_TPREL16_HI
:
5480 case elfcpp::R_POWERPC_TPREL16_HA
:
5491 // These are the relocation types supported only on 64-bit.
5492 case elfcpp::R_PPC64_ADDR64
:
5493 case elfcpp::R_PPC64_UADDR64
:
5494 case elfcpp::R_PPC64_JMP_IREL
:
5495 case elfcpp::R_PPC64_ADDR16_DS
:
5496 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5497 case elfcpp::R_PPC64_ADDR16_HIGH
:
5498 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5499 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5500 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5501 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5502 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5503 case elfcpp::R_PPC64_REL64
:
5504 case elfcpp::R_POWERPC_ADDR30
:
5505 case elfcpp::R_PPC64_TPREL16_DS
:
5506 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5507 case elfcpp::R_PPC64_TPREL16_HIGH
:
5508 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5509 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5510 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5511 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5512 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5523 // These are the relocation types supported only on 32-bit.
5524 // ??? glibc ld.so doesn't need to support these.
5525 case elfcpp::R_POWERPC_DTPREL16
:
5526 case elfcpp::R_POWERPC_DTPREL16_LO
:
5527 case elfcpp::R_POWERPC_DTPREL16_HI
:
5528 case elfcpp::R_POWERPC_DTPREL16_HA
:
5536 // This prevents us from issuing more than one error per reloc
5537 // section. But we can still wind up issuing more than one
5538 // error per object file.
5539 if (this->issued_non_pic_error_
)
5541 gold_assert(parameters
->options().output_is_position_independent());
5542 object
->error(_("requires unsupported dynamic reloc; "
5543 "recompile with -fPIC"));
5544 this->issued_non_pic_error_
= true;
5548 // Return whether we need to make a PLT entry for a relocation of the
5549 // given type against a STT_GNU_IFUNC symbol.
5551 template<int size
, bool big_endian
>
5553 Target_powerpc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
5554 Target_powerpc
<size
, big_endian
>* target
,
5555 Sized_relobj_file
<size
, big_endian
>* object
,
5556 unsigned int r_type
,
5559 // In non-pic code any reference will resolve to the plt call stub
5560 // for the ifunc symbol.
5561 if ((size
== 32 || target
->abiversion() >= 2)
5562 && !parameters
->options().output_is_position_independent())
5567 // Word size refs from data sections are OK, but don't need a PLT entry.
5568 case elfcpp::R_POWERPC_ADDR32
:
5569 case elfcpp::R_POWERPC_UADDR32
:
5574 case elfcpp::R_PPC64_ADDR64
:
5575 case elfcpp::R_PPC64_UADDR64
:
5580 // GOT refs are good, but also don't need a PLT entry.
5581 case elfcpp::R_POWERPC_GOT16
:
5582 case elfcpp::R_POWERPC_GOT16_LO
:
5583 case elfcpp::R_POWERPC_GOT16_HI
:
5584 case elfcpp::R_POWERPC_GOT16_HA
:
5585 case elfcpp::R_PPC64_GOT16_DS
:
5586 case elfcpp::R_PPC64_GOT16_LO_DS
:
5589 // Function calls are good, and these do need a PLT entry.
5590 case elfcpp::R_POWERPC_ADDR24
:
5591 case elfcpp::R_POWERPC_ADDR14
:
5592 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5593 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5594 case elfcpp::R_POWERPC_REL24
:
5595 case elfcpp::R_PPC_PLTREL24
:
5596 case elfcpp::R_POWERPC_REL14
:
5597 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5598 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5605 // Anything else is a problem.
5606 // If we are building a static executable, the libc startup function
5607 // responsible for applying indirect function relocations is going
5608 // to complain about the reloc type.
5609 // If we are building a dynamic executable, we will have a text
5610 // relocation. The dynamic loader will set the text segment
5611 // writable and non-executable to apply text relocations. So we'll
5612 // segfault when trying to run the indirection function to resolve
5615 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5616 object
->name().c_str(), r_type
);
5620 // Scan a relocation for a local symbol.
5622 template<int size
, bool big_endian
>
5624 Target_powerpc
<size
, big_endian
>::Scan::local(
5625 Symbol_table
* symtab
,
5627 Target_powerpc
<size
, big_endian
>* target
,
5628 Sized_relobj_file
<size
, big_endian
>* object
,
5629 unsigned int data_shndx
,
5630 Output_section
* output_section
,
5631 const elfcpp::Rela
<size
, big_endian
>& reloc
,
5632 unsigned int r_type
,
5633 const elfcpp::Sym
<size
, big_endian
>& lsym
,
5636 this->maybe_skip_tls_get_addr_call(r_type
, NULL
);
5638 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
5639 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
5641 this->expect_tls_get_addr_call();
5642 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5643 if (tls_type
!= tls::TLSOPT_NONE
)
5644 this->skip_next_tls_get_addr_call();
5646 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
5647 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
5649 this->expect_tls_get_addr_call();
5650 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5651 if (tls_type
!= tls::TLSOPT_NONE
)
5652 this->skip_next_tls_get_addr_call();
5655 Powerpc_relobj
<size
, big_endian
>* ppc_object
5656 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
5661 && data_shndx
== ppc_object
->opd_shndx()
5662 && r_type
== elfcpp::R_PPC64_ADDR64
)
5663 ppc_object
->set_opd_discard(reloc
.get_r_offset());
5667 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5668 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
5669 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
5671 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5672 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5673 r_type
, r_sym
, reloc
.get_r_addend());
5674 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
5679 case elfcpp::R_POWERPC_NONE
:
5680 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
5681 case elfcpp::R_POWERPC_GNU_VTENTRY
:
5682 case elfcpp::R_PPC64_TOCSAVE
:
5683 case elfcpp::R_POWERPC_TLS
:
5684 case elfcpp::R_PPC64_ENTRY
:
5687 case elfcpp::R_PPC64_TOC
:
5689 Output_data_got_powerpc
<size
, big_endian
>* got
5690 = target
->got_section(symtab
, layout
);
5691 if (parameters
->options().output_is_position_independent())
5693 Address off
= reloc
.get_r_offset();
5695 && target
->abiversion() < 2
5696 && data_shndx
== ppc_object
->opd_shndx()
5697 && ppc_object
->get_opd_discard(off
- 8))
5700 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5701 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
5702 rela_dyn
->add_output_section_relative(got
->output_section(),
5703 elfcpp::R_POWERPC_RELATIVE
,
5705 object
, data_shndx
, off
,
5706 symobj
->toc_base_offset());
5711 case elfcpp::R_PPC64_ADDR64
:
5712 case elfcpp::R_PPC64_UADDR64
:
5713 case elfcpp::R_POWERPC_ADDR32
:
5714 case elfcpp::R_POWERPC_UADDR32
:
5715 case elfcpp::R_POWERPC_ADDR24
:
5716 case elfcpp::R_POWERPC_ADDR16
:
5717 case elfcpp::R_POWERPC_ADDR16_LO
:
5718 case elfcpp::R_POWERPC_ADDR16_HI
:
5719 case elfcpp::R_POWERPC_ADDR16_HA
:
5720 case elfcpp::R_POWERPC_UADDR16
:
5721 case elfcpp::R_PPC64_ADDR16_HIGH
:
5722 case elfcpp::R_PPC64_ADDR16_HIGHA
:
5723 case elfcpp::R_PPC64_ADDR16_HIGHER
:
5724 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
5725 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
5726 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
5727 case elfcpp::R_PPC64_ADDR16_DS
:
5728 case elfcpp::R_PPC64_ADDR16_LO_DS
:
5729 case elfcpp::R_POWERPC_ADDR14
:
5730 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
5731 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
5732 // If building a shared library (or a position-independent
5733 // executable), we need to create a dynamic relocation for
5735 if (parameters
->options().output_is_position_independent()
5736 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
5738 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5740 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5741 if ((size
== 32 && r_type
== elfcpp::R_POWERPC_ADDR32
)
5742 || (size
== 64 && r_type
== elfcpp::R_PPC64_ADDR64
))
5744 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5745 : elfcpp::R_POWERPC_RELATIVE
);
5746 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5747 output_section
, data_shndx
,
5748 reloc
.get_r_offset(),
5749 reloc
.get_r_addend(), false);
5751 else if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
5753 check_non_pic(object
, r_type
);
5754 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
5755 data_shndx
, reloc
.get_r_offset(),
5756 reloc
.get_r_addend());
5760 gold_assert(lsym
.get_st_value() == 0);
5761 unsigned int shndx
= lsym
.get_st_shndx();
5763 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
5766 object
->error(_("section symbol %u has bad shndx %u"),
5769 rela_dyn
->add_local_section(object
, shndx
, r_type
,
5770 output_section
, data_shndx
,
5771 reloc
.get_r_offset());
5776 case elfcpp::R_POWERPC_REL24
:
5777 case elfcpp::R_PPC_PLTREL24
:
5778 case elfcpp::R_PPC_LOCAL24PC
:
5779 case elfcpp::R_POWERPC_REL14
:
5780 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
5781 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
5783 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
5784 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
5785 reloc
.get_r_addend());
5788 case elfcpp::R_PPC64_REL64
:
5789 case elfcpp::R_POWERPC_REL32
:
5790 case elfcpp::R_POWERPC_REL16
:
5791 case elfcpp::R_POWERPC_REL16_LO
:
5792 case elfcpp::R_POWERPC_REL16_HI
:
5793 case elfcpp::R_POWERPC_REL16_HA
:
5794 case elfcpp::R_POWERPC_REL16DX_HA
:
5795 case elfcpp::R_POWERPC_SECTOFF
:
5796 case elfcpp::R_POWERPC_SECTOFF_LO
:
5797 case elfcpp::R_POWERPC_SECTOFF_HI
:
5798 case elfcpp::R_POWERPC_SECTOFF_HA
:
5799 case elfcpp::R_PPC64_SECTOFF_DS
:
5800 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
5801 case elfcpp::R_POWERPC_TPREL16
:
5802 case elfcpp::R_POWERPC_TPREL16_LO
:
5803 case elfcpp::R_POWERPC_TPREL16_HI
:
5804 case elfcpp::R_POWERPC_TPREL16_HA
:
5805 case elfcpp::R_PPC64_TPREL16_DS
:
5806 case elfcpp::R_PPC64_TPREL16_LO_DS
:
5807 case elfcpp::R_PPC64_TPREL16_HIGH
:
5808 case elfcpp::R_PPC64_TPREL16_HIGHA
:
5809 case elfcpp::R_PPC64_TPREL16_HIGHER
:
5810 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
5811 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
5812 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
5813 case elfcpp::R_POWERPC_DTPREL16
:
5814 case elfcpp::R_POWERPC_DTPREL16_LO
:
5815 case elfcpp::R_POWERPC_DTPREL16_HI
:
5816 case elfcpp::R_POWERPC_DTPREL16_HA
:
5817 case elfcpp::R_PPC64_DTPREL16_DS
:
5818 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
5819 case elfcpp::R_PPC64_DTPREL16_HIGH
:
5820 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
5821 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
5822 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
5823 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
5824 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
5825 case elfcpp::R_PPC64_TLSGD
:
5826 case elfcpp::R_PPC64_TLSLD
:
5827 case elfcpp::R_PPC64_ADDR64_LOCAL
:
5830 case elfcpp::R_POWERPC_GOT16
:
5831 case elfcpp::R_POWERPC_GOT16_LO
:
5832 case elfcpp::R_POWERPC_GOT16_HI
:
5833 case elfcpp::R_POWERPC_GOT16_HA
:
5834 case elfcpp::R_PPC64_GOT16_DS
:
5835 case elfcpp::R_PPC64_GOT16_LO_DS
:
5837 // The symbol requires a GOT entry.
5838 Output_data_got_powerpc
<size
, big_endian
>* got
5839 = target
->got_section(symtab
, layout
);
5840 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5842 if (!parameters
->options().output_is_position_independent())
5845 && (size
== 32 || target
->abiversion() >= 2))
5846 got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
5848 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
5850 else if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
5852 // If we are generating a shared object or a pie, this
5853 // symbol's GOT entry will be set by a dynamic relocation.
5855 off
= got
->add_constant(0);
5856 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
5858 Reloc_section
* rela_dyn
= target
->rela_dyn_section(symtab
, layout
,
5860 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
5861 : elfcpp::R_POWERPC_RELATIVE
);
5862 rela_dyn
->add_local_relative(object
, r_sym
, dynrel
,
5863 got
, off
, 0, false);
5868 case elfcpp::R_PPC64_TOC16
:
5869 case elfcpp::R_PPC64_TOC16_LO
:
5870 case elfcpp::R_PPC64_TOC16_HI
:
5871 case elfcpp::R_PPC64_TOC16_HA
:
5872 case elfcpp::R_PPC64_TOC16_DS
:
5873 case elfcpp::R_PPC64_TOC16_LO_DS
:
5874 // We need a GOT section.
5875 target
->got_section(symtab
, layout
);
5878 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5879 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
5880 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
5881 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
5883 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(true);
5884 if (tls_type
== tls::TLSOPT_NONE
)
5886 Output_data_got_powerpc
<size
, big_endian
>* got
5887 = target
->got_section(symtab
, layout
);
5888 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5889 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5890 got
->add_local_tls_pair(object
, r_sym
, GOT_TYPE_TLSGD
,
5891 rela_dyn
, elfcpp::R_POWERPC_DTPMOD
);
5893 else if (tls_type
== tls::TLSOPT_TO_LE
)
5895 // no GOT relocs needed for Local Exec.
5902 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5903 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
5904 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
5905 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
5907 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
5908 if (tls_type
== tls::TLSOPT_NONE
)
5909 target
->tlsld_got_offset(symtab
, layout
, object
);
5910 else if (tls_type
== tls::TLSOPT_TO_LE
)
5912 // no GOT relocs needed for Local Exec.
5913 if (parameters
->options().emit_relocs())
5915 Output_section
* os
= layout
->tls_segment()->first_section();
5916 gold_assert(os
!= NULL
);
5917 os
->set_needs_symtab_index();
5925 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5926 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
5927 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
5928 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
5930 Output_data_got_powerpc
<size
, big_endian
>* got
5931 = target
->got_section(symtab
, layout
);
5932 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5933 got
->add_local_tls(object
, r_sym
, GOT_TYPE_DTPREL
);
5937 case elfcpp::R_POWERPC_GOT_TPREL16
:
5938 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
5939 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
5940 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
5942 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(true);
5943 if (tls_type
== tls::TLSOPT_NONE
)
5945 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
5946 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
))
5948 Output_data_got_powerpc
<size
, big_endian
>* got
5949 = target
->got_section(symtab
, layout
);
5950 unsigned int off
= got
->add_constant(0);
5951 object
->set_local_got_offset(r_sym
, GOT_TYPE_TPREL
, off
);
5953 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
5954 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
5955 elfcpp::R_POWERPC_TPREL
,
5959 else if (tls_type
== tls::TLSOPT_TO_LE
)
5961 // no GOT relocs needed for Local Exec.
5969 unsupported_reloc_local(object
, r_type
);
5975 case elfcpp::R_POWERPC_GOT_TLSLD16
:
5976 case elfcpp::R_POWERPC_GOT_TLSGD16
:
5977 case elfcpp::R_POWERPC_GOT_TPREL16
:
5978 case elfcpp::R_POWERPC_GOT_DTPREL16
:
5979 case elfcpp::R_POWERPC_GOT16
:
5980 case elfcpp::R_PPC64_GOT16_DS
:
5981 case elfcpp::R_PPC64_TOC16
:
5982 case elfcpp::R_PPC64_TOC16_DS
:
5983 ppc_object
->set_has_small_toc_reloc();
5989 // Report an unsupported relocation against a global symbol.
5991 template<int size
, bool big_endian
>
5993 Target_powerpc
<size
, big_endian
>::Scan::unsupported_reloc_global(
5994 Sized_relobj_file
<size
, big_endian
>* object
,
5995 unsigned int r_type
,
5998 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5999 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
6002 // Scan a relocation for a global symbol.
6004 template<int size
, bool big_endian
>
6006 Target_powerpc
<size
, big_endian
>::Scan::global(
6007 Symbol_table
* symtab
,
6009 Target_powerpc
<size
, big_endian
>* target
,
6010 Sized_relobj_file
<size
, big_endian
>* object
,
6011 unsigned int data_shndx
,
6012 Output_section
* output_section
,
6013 const elfcpp::Rela
<size
, big_endian
>& reloc
,
6014 unsigned int r_type
,
6017 if (this->maybe_skip_tls_get_addr_call(r_type
, gsym
) == Track_tls::SKIP
)
6020 if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
6021 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
6023 this->expect_tls_get_addr_call();
6024 const bool final
= gsym
->final_value_is_known();
6025 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6026 if (tls_type
!= tls::TLSOPT_NONE
)
6027 this->skip_next_tls_get_addr_call();
6029 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
6030 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
6032 this->expect_tls_get_addr_call();
6033 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6034 if (tls_type
!= tls::TLSOPT_NONE
)
6035 this->skip_next_tls_get_addr_call();
6038 Powerpc_relobj
<size
, big_endian
>* ppc_object
6039 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6041 // A STT_GNU_IFUNC symbol may require a PLT entry.
6042 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
6043 bool pushed_ifunc
= false;
6044 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(target
, object
, r_type
, true))
6046 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6047 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6048 reloc
.get_r_addend());
6049 target
->make_plt_entry(symtab
, layout
, gsym
);
6050 pushed_ifunc
= true;
6055 case elfcpp::R_POWERPC_NONE
:
6056 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
6057 case elfcpp::R_POWERPC_GNU_VTENTRY
:
6058 case elfcpp::R_PPC_LOCAL24PC
:
6059 case elfcpp::R_POWERPC_TLS
:
6060 case elfcpp::R_PPC64_ENTRY
:
6063 case elfcpp::R_PPC64_TOC
:
6065 Output_data_got_powerpc
<size
, big_endian
>* got
6066 = target
->got_section(symtab
, layout
);
6067 if (parameters
->options().output_is_position_independent())
6069 Address off
= reloc
.get_r_offset();
6071 && data_shndx
== ppc_object
->opd_shndx()
6072 && ppc_object
->get_opd_discard(off
- 8))
6075 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6076 Powerpc_relobj
<size
, big_endian
>* symobj
= ppc_object
;
6077 if (data_shndx
!= ppc_object
->opd_shndx())
6078 symobj
= static_cast
6079 <Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
6080 rela_dyn
->add_output_section_relative(got
->output_section(),
6081 elfcpp::R_POWERPC_RELATIVE
,
6083 object
, data_shndx
, off
,
6084 symobj
->toc_base_offset());
6089 case elfcpp::R_PPC64_ADDR64
:
6091 && target
->abiversion() < 2
6092 && data_shndx
== ppc_object
->opd_shndx()
6093 && (gsym
->is_defined_in_discarded_section()
6094 || gsym
->object() != object
))
6096 ppc_object
->set_opd_discard(reloc
.get_r_offset());
6100 case elfcpp::R_PPC64_UADDR64
:
6101 case elfcpp::R_POWERPC_ADDR32
:
6102 case elfcpp::R_POWERPC_UADDR32
:
6103 case elfcpp::R_POWERPC_ADDR24
:
6104 case elfcpp::R_POWERPC_ADDR16
:
6105 case elfcpp::R_POWERPC_ADDR16_LO
:
6106 case elfcpp::R_POWERPC_ADDR16_HI
:
6107 case elfcpp::R_POWERPC_ADDR16_HA
:
6108 case elfcpp::R_POWERPC_UADDR16
:
6109 case elfcpp::R_PPC64_ADDR16_HIGH
:
6110 case elfcpp::R_PPC64_ADDR16_HIGHA
:
6111 case elfcpp::R_PPC64_ADDR16_HIGHER
:
6112 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
6113 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
6114 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
6115 case elfcpp::R_PPC64_ADDR16_DS
:
6116 case elfcpp::R_PPC64_ADDR16_LO_DS
:
6117 case elfcpp::R_POWERPC_ADDR14
:
6118 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
6119 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
6121 // Make a PLT entry if necessary.
6122 if (gsym
->needs_plt_entry())
6124 // Since this is not a PC-relative relocation, we may be
6125 // taking the address of a function. In that case we need to
6126 // set the entry in the dynamic symbol table to the address of
6127 // the PLT call stub.
6128 bool need_ifunc_plt
= false;
6129 if ((size
== 32 || target
->abiversion() >= 2)
6130 && gsym
->is_from_dynobj()
6131 && !parameters
->options().output_is_position_independent())
6133 gsym
->set_needs_dynsym_value();
6134 need_ifunc_plt
= true;
6136 if (!is_ifunc
|| (!pushed_ifunc
&& need_ifunc_plt
))
6138 target
->push_branch(ppc_object
, data_shndx
,
6139 reloc
.get_r_offset(), r_type
,
6140 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6141 reloc
.get_r_addend());
6142 target
->make_plt_entry(symtab
, layout
, gsym
);
6145 // Make a dynamic relocation if necessary.
6146 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
))
6147 || (size
== 64 && is_ifunc
&& target
->abiversion() < 2))
6149 if (!parameters
->options().output_is_position_independent()
6150 && gsym
->may_need_copy_reloc())
6152 target
->copy_reloc(symtab
, layout
, object
,
6153 data_shndx
, output_section
, gsym
, reloc
);
6155 else if ((((size
== 32
6156 && r_type
== elfcpp::R_POWERPC_ADDR32
)
6158 && r_type
== elfcpp::R_PPC64_ADDR64
6159 && target
->abiversion() >= 2))
6160 && gsym
->can_use_relative_reloc(false)
6161 && !(gsym
->visibility() == elfcpp::STV_PROTECTED
6162 && parameters
->options().shared()))
6164 && r_type
== elfcpp::R_PPC64_ADDR64
6165 && target
->abiversion() < 2
6166 && (gsym
->can_use_relative_reloc(false)
6167 || data_shndx
== ppc_object
->opd_shndx())))
6169 Reloc_section
* rela_dyn
6170 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6171 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6172 : elfcpp::R_POWERPC_RELATIVE
);
6173 rela_dyn
->add_symbolless_global_addend(
6174 gsym
, dynrel
, output_section
, object
, data_shndx
,
6175 reloc
.get_r_offset(), reloc
.get_r_addend());
6179 Reloc_section
* rela_dyn
6180 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6181 check_non_pic(object
, r_type
);
6182 rela_dyn
->add_global(gsym
, r_type
, output_section
,
6184 reloc
.get_r_offset(),
6185 reloc
.get_r_addend());
6191 case elfcpp::R_PPC_PLTREL24
:
6192 case elfcpp::R_POWERPC_REL24
:
6195 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6197 elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6198 reloc
.get_r_addend());
6199 if (gsym
->needs_plt_entry()
6200 || (!gsym
->final_value_is_known()
6201 && (gsym
->is_undefined()
6202 || gsym
->is_from_dynobj()
6203 || gsym
->is_preemptible())))
6204 target
->make_plt_entry(symtab
, layout
, gsym
);
6208 case elfcpp::R_PPC64_REL64
:
6209 case elfcpp::R_POWERPC_REL32
:
6210 // Make a dynamic relocation if necessary.
6211 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
, target
)))
6213 if (!parameters
->options().output_is_position_independent()
6214 && gsym
->may_need_copy_reloc())
6216 target
->copy_reloc(symtab
, layout
, object
,
6217 data_shndx
, output_section
, gsym
,
6222 Reloc_section
* rela_dyn
6223 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6224 check_non_pic(object
, r_type
);
6225 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
6226 data_shndx
, reloc
.get_r_offset(),
6227 reloc
.get_r_addend());
6232 case elfcpp::R_POWERPC_REL14
:
6233 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
6234 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
6236 target
->push_branch(ppc_object
, data_shndx
, reloc
.get_r_offset(),
6237 r_type
, elfcpp::elf_r_sym
<size
>(reloc
.get_r_info()),
6238 reloc
.get_r_addend());
6241 case elfcpp::R_POWERPC_REL16
:
6242 case elfcpp::R_POWERPC_REL16_LO
:
6243 case elfcpp::R_POWERPC_REL16_HI
:
6244 case elfcpp::R_POWERPC_REL16_HA
:
6245 case elfcpp::R_POWERPC_REL16DX_HA
:
6246 case elfcpp::R_POWERPC_SECTOFF
:
6247 case elfcpp::R_POWERPC_SECTOFF_LO
:
6248 case elfcpp::R_POWERPC_SECTOFF_HI
:
6249 case elfcpp::R_POWERPC_SECTOFF_HA
:
6250 case elfcpp::R_PPC64_SECTOFF_DS
:
6251 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
6252 case elfcpp::R_POWERPC_TPREL16
:
6253 case elfcpp::R_POWERPC_TPREL16_LO
:
6254 case elfcpp::R_POWERPC_TPREL16_HI
:
6255 case elfcpp::R_POWERPC_TPREL16_HA
:
6256 case elfcpp::R_PPC64_TPREL16_DS
:
6257 case elfcpp::R_PPC64_TPREL16_LO_DS
:
6258 case elfcpp::R_PPC64_TPREL16_HIGH
:
6259 case elfcpp::R_PPC64_TPREL16_HIGHA
:
6260 case elfcpp::R_PPC64_TPREL16_HIGHER
:
6261 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
6262 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
6263 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
6264 case elfcpp::R_POWERPC_DTPREL16
:
6265 case elfcpp::R_POWERPC_DTPREL16_LO
:
6266 case elfcpp::R_POWERPC_DTPREL16_HI
:
6267 case elfcpp::R_POWERPC_DTPREL16_HA
:
6268 case elfcpp::R_PPC64_DTPREL16_DS
:
6269 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
6270 case elfcpp::R_PPC64_DTPREL16_HIGH
:
6271 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
6272 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
6273 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
6274 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
6275 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
6276 case elfcpp::R_PPC64_TLSGD
:
6277 case elfcpp::R_PPC64_TLSLD
:
6278 case elfcpp::R_PPC64_ADDR64_LOCAL
:
6281 case elfcpp::R_POWERPC_GOT16
:
6282 case elfcpp::R_POWERPC_GOT16_LO
:
6283 case elfcpp::R_POWERPC_GOT16_HI
:
6284 case elfcpp::R_POWERPC_GOT16_HA
:
6285 case elfcpp::R_PPC64_GOT16_DS
:
6286 case elfcpp::R_PPC64_GOT16_LO_DS
:
6288 // The symbol requires a GOT entry.
6289 Output_data_got_powerpc
<size
, big_endian
>* got
;
6291 got
= target
->got_section(symtab
, layout
);
6292 if (gsym
->final_value_is_known())
6295 && (size
== 32 || target
->abiversion() >= 2))
6296 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
6298 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
6300 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
6302 // If we are generating a shared object or a pie, this
6303 // symbol's GOT entry will be set by a dynamic relocation.
6304 unsigned int off
= got
->add_constant(0);
6305 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
6307 Reloc_section
* rela_dyn
6308 = target
->rela_dyn_section(symtab
, layout
, is_ifunc
);
6310 if (gsym
->can_use_relative_reloc(false)
6312 || target
->abiversion() >= 2)
6313 && gsym
->visibility() == elfcpp::STV_PROTECTED
6314 && parameters
->options().shared()))
6316 unsigned int dynrel
= (is_ifunc
? elfcpp::R_POWERPC_IRELATIVE
6317 : elfcpp::R_POWERPC_RELATIVE
);
6318 rela_dyn
->add_global_relative(gsym
, dynrel
, got
, off
, 0, false);
6322 unsigned int dynrel
= elfcpp::R_POWERPC_GLOB_DAT
;
6323 rela_dyn
->add_global(gsym
, dynrel
, got
, off
, 0);
6329 case elfcpp::R_PPC64_TOC16
:
6330 case elfcpp::R_PPC64_TOC16_LO
:
6331 case elfcpp::R_PPC64_TOC16_HI
:
6332 case elfcpp::R_PPC64_TOC16_HA
:
6333 case elfcpp::R_PPC64_TOC16_DS
:
6334 case elfcpp::R_PPC64_TOC16_LO_DS
:
6335 // We need a GOT section.
6336 target
->got_section(symtab
, layout
);
6339 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6340 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
6341 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
6342 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
6344 const bool final
= gsym
->final_value_is_known();
6345 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
6346 if (tls_type
== tls::TLSOPT_NONE
)
6348 Output_data_got_powerpc
<size
, big_endian
>* got
6349 = target
->got_section(symtab
, layout
);
6350 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6351 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLSGD
, rela_dyn
,
6352 elfcpp::R_POWERPC_DTPMOD
,
6353 elfcpp::R_POWERPC_DTPREL
);
6355 else if (tls_type
== tls::TLSOPT_TO_IE
)
6357 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6359 Output_data_got_powerpc
<size
, big_endian
>* got
6360 = target
->got_section(symtab
, layout
);
6361 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6362 if (gsym
->is_undefined()
6363 || gsym
->is_from_dynobj())
6365 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6366 elfcpp::R_POWERPC_TPREL
);
6370 unsigned int off
= got
->add_constant(0);
6371 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6372 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6373 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6378 else if (tls_type
== tls::TLSOPT_TO_LE
)
6380 // no GOT relocs needed for Local Exec.
6387 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6388 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
6389 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
6390 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
6392 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
6393 if (tls_type
== tls::TLSOPT_NONE
)
6394 target
->tlsld_got_offset(symtab
, layout
, object
);
6395 else if (tls_type
== tls::TLSOPT_TO_LE
)
6397 // no GOT relocs needed for Local Exec.
6398 if (parameters
->options().emit_relocs())
6400 Output_section
* os
= layout
->tls_segment()->first_section();
6401 gold_assert(os
!= NULL
);
6402 os
->set_needs_symtab_index();
6410 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6411 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
6412 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
6413 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
6415 Output_data_got_powerpc
<size
, big_endian
>* got
6416 = target
->got_section(symtab
, layout
);
6417 if (!gsym
->final_value_is_known()
6418 && (gsym
->is_from_dynobj()
6419 || gsym
->is_undefined()
6420 || gsym
->is_preemptible()))
6421 got
->add_global_with_rel(gsym
, GOT_TYPE_DTPREL
,
6422 target
->rela_dyn_section(layout
),
6423 elfcpp::R_POWERPC_DTPREL
);
6425 got
->add_global_tls(gsym
, GOT_TYPE_DTPREL
);
6429 case elfcpp::R_POWERPC_GOT_TPREL16
:
6430 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
6431 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
6432 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
6434 const bool final
= gsym
->final_value_is_known();
6435 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
6436 if (tls_type
== tls::TLSOPT_NONE
)
6438 if (!gsym
->has_got_offset(GOT_TYPE_TPREL
))
6440 Output_data_got_powerpc
<size
, big_endian
>* got
6441 = target
->got_section(symtab
, layout
);
6442 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
6443 if (gsym
->is_undefined()
6444 || gsym
->is_from_dynobj())
6446 got
->add_global_with_rel(gsym
, GOT_TYPE_TPREL
, rela_dyn
,
6447 elfcpp::R_POWERPC_TPREL
);
6451 unsigned int off
= got
->add_constant(0);
6452 gsym
->set_got_offset(GOT_TYPE_TPREL
, off
);
6453 unsigned int dynrel
= elfcpp::R_POWERPC_TPREL
;
6454 rela_dyn
->add_symbolless_global_addend(gsym
, dynrel
,
6459 else if (tls_type
== tls::TLSOPT_TO_LE
)
6461 // no GOT relocs needed for Local Exec.
6469 unsupported_reloc_global(object
, r_type
, gsym
);
6475 case elfcpp::R_POWERPC_GOT_TLSLD16
:
6476 case elfcpp::R_POWERPC_GOT_TLSGD16
:
6477 case elfcpp::R_POWERPC_GOT_TPREL16
:
6478 case elfcpp::R_POWERPC_GOT_DTPREL16
:
6479 case elfcpp::R_POWERPC_GOT16
:
6480 case elfcpp::R_PPC64_GOT16_DS
:
6481 case elfcpp::R_PPC64_TOC16
:
6482 case elfcpp::R_PPC64_TOC16_DS
:
6483 ppc_object
->set_has_small_toc_reloc();
6489 // Process relocations for gc.
6491 template<int size
, bool big_endian
>
6493 Target_powerpc
<size
, big_endian
>::gc_process_relocs(
6494 Symbol_table
* symtab
,
6496 Sized_relobj_file
<size
, big_endian
>* object
,
6497 unsigned int data_shndx
,
6499 const unsigned char* prelocs
,
6501 Output_section
* output_section
,
6502 bool needs_special_offset_handling
,
6503 size_t local_symbol_count
,
6504 const unsigned char* plocal_symbols
)
6506 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6507 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
6510 Powerpc_relobj
<size
, big_endian
>* ppc_object
6511 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(object
);
6513 ppc_object
->set_opd_valid();
6514 if (size
== 64 && data_shndx
== ppc_object
->opd_shndx())
6516 typename Powerpc_relobj
<size
, big_endian
>::Access_from::iterator p
;
6517 for (p
= ppc_object
->access_from_map()->begin();
6518 p
!= ppc_object
->access_from_map()->end();
6521 Address dst_off
= p
->first
;
6522 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6523 typename Powerpc_relobj
<size
, big_endian
>::Section_refs::iterator s
;
6524 for (s
= p
->second
.begin(); s
!= p
->second
.end(); ++s
)
6526 Relobj
* src_obj
= s
->first
;
6527 unsigned int src_indx
= s
->second
;
6528 symtab
->gc()->add_reference(src_obj
, src_indx
,
6529 ppc_object
, dst_indx
);
6533 ppc_object
->access_from_map()->clear();
6534 ppc_object
->process_gc_mark(symtab
);
6535 // Don't look at .opd relocs as .opd will reference everything.
6539 gold::gc_process_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
6548 needs_special_offset_handling
,
6553 // Handle target specific gc actions when adding a gc reference from
6554 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6555 // and DST_OFF. For powerpc64, this adds a referenc to the code
6556 // section of a function descriptor.
6558 template<int size
, bool big_endian
>
6560 Target_powerpc
<size
, big_endian
>::do_gc_add_reference(
6561 Symbol_table
* symtab
,
6563 unsigned int src_shndx
,
6565 unsigned int dst_shndx
,
6566 Address dst_off
) const
6568 if (size
!= 64 || dst_obj
->is_dynamic())
6571 Powerpc_relobj
<size
, big_endian
>* ppc_object
6572 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(dst_obj
);
6573 if (dst_shndx
!= 0 && dst_shndx
== ppc_object
->opd_shndx())
6575 if (ppc_object
->opd_valid())
6577 dst_shndx
= ppc_object
->get_opd_ent(dst_off
);
6578 symtab
->gc()->add_reference(src_obj
, src_shndx
, dst_obj
, dst_shndx
);
6582 // If we haven't run scan_opd_relocs, we must delay
6583 // processing this function descriptor reference.
6584 ppc_object
->add_reference(src_obj
, src_shndx
, dst_off
);
6589 // Add any special sections for this symbol to the gc work list.
6590 // For powerpc64, this adds the code section of a function
6593 template<int size
, bool big_endian
>
6595 Target_powerpc
<size
, big_endian
>::do_gc_mark_symbol(
6596 Symbol_table
* symtab
,
6601 Powerpc_relobj
<size
, big_endian
>* ppc_object
6602 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(sym
->object());
6604 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6605 if (is_ordinary
&& shndx
!= 0 && shndx
== ppc_object
->opd_shndx())
6607 Sized_symbol
<size
>* gsym
= symtab
->get_sized_symbol
<size
>(sym
);
6608 Address dst_off
= gsym
->value();
6609 if (ppc_object
->opd_valid())
6611 unsigned int dst_indx
= ppc_object
->get_opd_ent(dst_off
);
6612 symtab
->gc()->worklist().push_back(Section_id(ppc_object
,
6616 ppc_object
->add_gc_mark(dst_off
);
6621 // For a symbol location in .opd, set LOC to the location of the
6624 template<int size
, bool big_endian
>
6626 Target_powerpc
<size
, big_endian
>::do_function_location(
6627 Symbol_location
* loc
) const
6629 if (size
== 64 && loc
->shndx
!= 0)
6631 if (loc
->object
->is_dynamic())
6633 Powerpc_dynobj
<size
, big_endian
>* ppc_object
6634 = static_cast<Powerpc_dynobj
<size
, big_endian
>*>(loc
->object
);
6635 if (loc
->shndx
== ppc_object
->opd_shndx())
6638 Address off
= loc
->offset
- ppc_object
->opd_address();
6639 loc
->shndx
= ppc_object
->get_opd_ent(off
, &dest_off
);
6640 loc
->offset
= dest_off
;
6645 const Powerpc_relobj
<size
, big_endian
>* ppc_object
6646 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(loc
->object
);
6647 if (loc
->shndx
== ppc_object
->opd_shndx())
6650 loc
->shndx
= ppc_object
->get_opd_ent(loc
->offset
, &dest_off
);
6651 loc
->offset
= dest_off
;
6657 // FNOFFSET in section SHNDX in OBJECT is the start of a function
6658 // compiled with -fsplit-stack. The function calls non-split-stack
6659 // code. Change the function to ensure it has enough stack space to
6660 // call some random function.
6662 template<int size
, bool big_endian
>
6664 Target_powerpc
<size
, big_endian
>::do_calls_non_split(
6667 section_offset_type fnoffset
,
6668 section_size_type fnsize
,
6669 const unsigned char* prelocs
,
6671 unsigned char* view
,
6672 section_size_type view_size
,
6674 std::string
* to
) const
6676 // 32-bit not supported.
6680 Target::do_calls_non_split(object
, shndx
, fnoffset
, fnsize
,
6681 prelocs
, reloc_count
, view
, view_size
,
6686 // The function always starts with
6687 // ld %r0,-0x7000-64(%r13) # tcbhead_t.__private_ss
6688 // addis %r12,%r1,-allocate@ha
6689 // addi %r12,%r12,-allocate@l
6691 // but note that the addis or addi may be replaced with a nop
6693 unsigned char *entry
= view
+ fnoffset
;
6694 uint32_t insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6696 if ((insn
& 0xffff0000) == addis_2_12
)
6698 /* Skip ELFv2 global entry code. */
6700 insn
= elfcpp::Swap
<32, big_endian
>::readval(entry
);
6703 unsigned char *pinsn
= entry
;
6705 const uint32_t ld_private_ss
= 0xe80d8fc0;
6706 if (insn
== ld_private_ss
)
6708 int32_t allocate
= 0;
6712 insn
= elfcpp::Swap
<32, big_endian
>::readval(pinsn
);
6713 if ((insn
& 0xffff0000) == addis_12_1
)
6714 allocate
+= (insn
& 0xffff) << 16;
6715 else if ((insn
& 0xffff0000) == addi_12_1
6716 || (insn
& 0xffff0000) == addi_12_12
)
6717 allocate
+= ((insn
& 0xffff) ^ 0x8000) - 0x8000;
6718 else if (insn
!= nop
)
6721 if (insn
== cmpld_7_12_0
&& pinsn
== entry
+ 12)
6723 int extra
= parameters
->options().split_stack_adjust_size();
6725 if (allocate
>= 0 || extra
< 0)
6727 object
->error(_("split-stack stack size overflow at "
6728 "section %u offset %0zx"),
6729 shndx
, static_cast<size_t>(fnoffset
));
6733 insn
= addis_12_1
| (((allocate
+ 0x8000) >> 16) & 0xffff);
6734 if (insn
!= addis_12_1
)
6736 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6738 insn
= addi_12_12
| (allocate
& 0xffff);
6739 if (insn
!= addi_12_12
)
6741 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6747 insn
= addi_12_1
| (allocate
& 0xffff);
6748 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, insn
);
6751 if (pinsn
!= entry
+ 12)
6752 elfcpp::Swap
<32, big_endian
>::writeval(pinsn
, nop
);
6760 if (!object
->has_no_split_stack())
6761 object
->error(_("failed to match split-stack sequence at "
6762 "section %u offset %0zx"),
6763 shndx
, static_cast<size_t>(fnoffset
));
6767 // Scan relocations for a section.
6769 template<int size
, bool big_endian
>
6771 Target_powerpc
<size
, big_endian
>::scan_relocs(
6772 Symbol_table
* symtab
,
6774 Sized_relobj_file
<size
, big_endian
>* object
,
6775 unsigned int data_shndx
,
6776 unsigned int sh_type
,
6777 const unsigned char* prelocs
,
6779 Output_section
* output_section
,
6780 bool needs_special_offset_handling
,
6781 size_t local_symbol_count
,
6782 const unsigned char* plocal_symbols
)
6784 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
6785 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
6788 if (sh_type
== elfcpp::SHT_REL
)
6790 gold_error(_("%s: unsupported REL reloc section"),
6791 object
->name().c_str());
6795 gold::scan_relocs
<size
, big_endian
, Powerpc
, Scan
, Classify_reloc
>(
6804 needs_special_offset_handling
,
6809 // Functor class for processing the global symbol table.
6810 // Removes symbols defined on discarded opd entries.
6812 template<bool big_endian
>
6813 class Global_symbol_visitor_opd
6816 Global_symbol_visitor_opd()
6820 operator()(Sized_symbol
<64>* sym
)
6822 if (sym
->has_symtab_index()
6823 || sym
->source() != Symbol::FROM_OBJECT
6824 || !sym
->in_real_elf())
6827 if (sym
->object()->is_dynamic())
6830 Powerpc_relobj
<64, big_endian
>* symobj
6831 = static_cast<Powerpc_relobj
<64, big_endian
>*>(sym
->object());
6832 if (symobj
->opd_shndx() == 0)
6836 unsigned int shndx
= sym
->shndx(&is_ordinary
);
6837 if (shndx
== symobj
->opd_shndx()
6838 && symobj
->get_opd_discard(sym
->value()))
6840 sym
->set_undefined();
6841 sym
->set_visibility(elfcpp::STV_DEFAULT
);
6842 sym
->set_is_defined_in_discarded_section();
6843 sym
->set_symtab_index(-1U);
6848 template<int size
, bool big_endian
>
6850 Target_powerpc
<size
, big_endian
>::define_save_restore_funcs(
6852 Symbol_table
* symtab
)
6856 Output_data_save_res
<size
, big_endian
>* savres
6857 = new Output_data_save_res
<size
, big_endian
>(symtab
);
6858 this->savres_section_
= savres
;
6859 layout
->add_output_section_data(".text", elfcpp::SHT_PROGBITS
,
6860 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
6861 savres
, ORDER_TEXT
, false);
6865 // Sort linker created .got section first (for the header), then input
6866 // sections belonging to files using small model code.
6868 template<bool big_endian
>
6869 class Sort_toc_sections
6873 operator()(const Output_section::Input_section
& is1
,
6874 const Output_section::Input_section
& is2
) const
6876 if (!is1
.is_input_section() && is2
.is_input_section())
6879 = (is1
.is_input_section()
6880 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is1
.relobj())
6881 ->has_small_toc_reloc()));
6883 = (is2
.is_input_section()
6884 && (static_cast<const Powerpc_relobj
<64, big_endian
>*>(is2
.relobj())
6885 ->has_small_toc_reloc()));
6886 return small1
&& !small2
;
6890 // Finalize the sections.
6892 template<int size
, bool big_endian
>
6894 Target_powerpc
<size
, big_endian
>::do_finalize_sections(
6896 const Input_objects
*,
6897 Symbol_table
* symtab
)
6899 if (parameters
->doing_static_link())
6901 // At least some versions of glibc elf-init.o have a strong
6902 // reference to __rela_iplt marker syms. A weak ref would be
6904 if (this->iplt_
!= NULL
)
6906 Reloc_section
* rel
= this->iplt_
->rel_plt();
6907 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
6908 Symbol_table::PREDEFINED
, rel
, 0, 0,
6909 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6910 elfcpp::STV_HIDDEN
, 0, false, true);
6911 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
6912 Symbol_table::PREDEFINED
, rel
, 0, 0,
6913 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6914 elfcpp::STV_HIDDEN
, 0, true, true);
6918 symtab
->define_as_constant("__rela_iplt_start", NULL
,
6919 Symbol_table::PREDEFINED
, 0, 0,
6920 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6921 elfcpp::STV_HIDDEN
, 0, true, false);
6922 symtab
->define_as_constant("__rela_iplt_end", NULL
,
6923 Symbol_table::PREDEFINED
, 0, 0,
6924 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
6925 elfcpp::STV_HIDDEN
, 0, true, false);
6931 typedef Global_symbol_visitor_opd
<big_endian
> Symbol_visitor
;
6932 symtab
->for_all_symbols
<64, Symbol_visitor
>(Symbol_visitor());
6934 if (!parameters
->options().relocatable())
6936 this->define_save_restore_funcs(layout
, symtab
);
6938 // Annoyingly, we need to make these sections now whether or
6939 // not we need them. If we delay until do_relax then we
6940 // need to mess with the relaxation machinery checkpointing.
6941 this->got_section(symtab
, layout
);
6942 this->make_brlt_section(layout
);
6944 if (parameters
->options().toc_sort())
6946 Output_section
* os
= this->got_
->output_section();
6947 if (os
!= NULL
&& os
->input_sections().size() > 1)
6948 std::stable_sort(os
->input_sections().begin(),
6949 os
->input_sections().end(),
6950 Sort_toc_sections
<big_endian
>());
6955 // Fill in some more dynamic tags.
6956 Output_data_dynamic
* odyn
= layout
->dynamic_data();
6959 const Reloc_section
* rel_plt
= (this->plt_
== NULL
6961 : this->plt_
->rel_plt());
6962 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
6963 this->rela_dyn_
, true, size
== 32);
6967 if (this->got_
!= NULL
)
6969 this->got_
->finalize_data_size();
6970 odyn
->add_section_plus_offset(elfcpp::DT_PPC_GOT
,
6971 this->got_
, this->got_
->g_o_t());
6976 if (this->glink_
!= NULL
)
6978 this->glink_
->finalize_data_size();
6979 odyn
->add_section_plus_offset(elfcpp::DT_PPC64_GLINK
,
6981 (this->glink_
->pltresolve_size
6987 // Emit any relocs we saved in an attempt to avoid generating COPY
6989 if (this->copy_relocs_
.any_saved_relocs())
6990 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
6993 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6997 ok_lo_toc_insn(uint32_t insn
)
6999 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
7000 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7001 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7002 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7003 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7004 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7005 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7006 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7007 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7008 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7009 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7010 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7011 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7012 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7013 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
7015 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
7016 && ((insn
& 3) == 0 || (insn
& 3) == 3))
7017 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
7020 // Return the value to use for a branch relocation.
7022 template<int size
, bool big_endian
>
7024 Target_powerpc
<size
, big_endian
>::symval_for_branch(
7025 const Symbol_table
* symtab
,
7026 const Sized_symbol
<size
>* gsym
,
7027 Powerpc_relobj
<size
, big_endian
>* object
,
7029 unsigned int *dest_shndx
)
7031 if (size
== 32 || this->abiversion() >= 2)
7035 // If the symbol is defined in an opd section, ie. is a function
7036 // descriptor, use the function descriptor code entry address
7037 Powerpc_relobj
<size
, big_endian
>* symobj
= object
;
7039 && gsym
->source() != Symbol::FROM_OBJECT
)
7042 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(gsym
->object());
7043 unsigned int shndx
= symobj
->opd_shndx();
7046 Address opd_addr
= symobj
->get_output_section_offset(shndx
);
7047 if (opd_addr
== invalid_address
)
7049 opd_addr
+= symobj
->output_section_address(shndx
);
7050 if (*value
>= opd_addr
&& *value
< opd_addr
+ symobj
->section_size(shndx
))
7053 *dest_shndx
= symobj
->get_opd_ent(*value
- opd_addr
, &sec_off
);
7054 if (symtab
->is_section_folded(symobj
, *dest_shndx
))
7057 = symtab
->icf()->get_folded_section(symobj
, *dest_shndx
);
7058 symobj
= static_cast<Powerpc_relobj
<size
, big_endian
>*>(folded
.first
);
7059 *dest_shndx
= folded
.second
;
7061 Address sec_addr
= symobj
->get_output_section_offset(*dest_shndx
);
7062 if (sec_addr
== invalid_address
)
7065 sec_addr
+= symobj
->output_section(*dest_shndx
)->address();
7066 *value
= sec_addr
+ sec_off
;
7071 // Perform a relocation.
7073 template<int size
, bool big_endian
>
7075 Target_powerpc
<size
, big_endian
>::Relocate::relocate(
7076 const Relocate_info
<size
, big_endian
>* relinfo
,
7078 Target_powerpc
* target
,
7081 const unsigned char* preloc
,
7082 const Sized_symbol
<size
>* gsym
,
7083 const Symbol_value
<size
>* psymval
,
7084 unsigned char* view
,
7086 section_size_type view_size
)
7091 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
7092 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
7093 switch (this->maybe_skip_tls_get_addr_call(r_type
, gsym
))
7095 case Track_tls::NOT_EXPECTED
:
7096 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7097 _("__tls_get_addr call lacks marker reloc"));
7099 case Track_tls::EXPECTED
:
7100 // We have already complained.
7102 case Track_tls::SKIP
:
7104 case Track_tls::NORMAL
:
7108 typedef Powerpc_relocate_functions
<size
, big_endian
> Reloc
;
7109 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Insn
;
7110 typedef typename Reloc_types
<elfcpp::SHT_RELA
,
7111 size
, big_endian
>::Reloc Reltype
;
7112 // Offset from start of insn to d-field reloc.
7113 const int d_offset
= big_endian
? 2 : 0;
7115 Powerpc_relobj
<size
, big_endian
>* const object
7116 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
7118 bool has_stub_value
= false;
7119 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7121 ? gsym
->use_plt_offset(Scan::get_reference_flags(r_type
, target
))
7122 : object
->local_has_plt_offset(r_sym
))
7123 && (!psymval
->is_ifunc_symbol()
7124 || Scan::reloc_needs_plt_for_ifunc(target
, object
, r_type
, false)))
7128 && target
->abiversion() >= 2
7129 && !parameters
->options().output_is_position_independent()
7130 && !is_branch_reloc(r_type
))
7132 Address off
= target
->glink_section()->find_global_entry(gsym
);
7133 if (off
!= invalid_address
)
7135 value
= target
->glink_section()->global_entry_address() + off
;
7136 has_stub_value
= true;
7141 Stub_table
<size
, big_endian
>* stub_table
7142 = object
->stub_table(relinfo
->data_shndx
);
7143 if (stub_table
== NULL
)
7145 // This is a ref from a data section to an ifunc symbol.
7146 if (target
->stub_tables().size() != 0)
7147 stub_table
= target
->stub_tables()[0];
7149 if (stub_table
!= NULL
)
7153 off
= stub_table
->find_plt_call_entry(object
, gsym
, r_type
,
7154 rela
.get_r_addend());
7156 off
= stub_table
->find_plt_call_entry(object
, r_sym
, r_type
,
7157 rela
.get_r_addend());
7158 if (off
!= invalid_address
)
7160 value
= stub_table
->stub_address() + off
;
7161 has_stub_value
= true;
7165 // We don't care too much about bogus debug references to
7166 // non-local functions, but otherwise there had better be a plt
7167 // call stub or global entry stub as appropriate.
7168 gold_assert(has_stub_value
|| !(os
->flags() & elfcpp::SHF_ALLOC
));
7171 if (r_type
== elfcpp::R_POWERPC_GOT16
7172 || r_type
== elfcpp::R_POWERPC_GOT16_LO
7173 || r_type
== elfcpp::R_POWERPC_GOT16_HI
7174 || r_type
== elfcpp::R_POWERPC_GOT16_HA
7175 || r_type
== elfcpp::R_PPC64_GOT16_DS
7176 || r_type
== elfcpp::R_PPC64_GOT16_LO_DS
)
7180 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
7181 value
= gsym
->got_offset(GOT_TYPE_STANDARD
);
7185 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7186 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
7187 value
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
7189 value
-= target
->got_section()->got_base_offset(object
);
7191 else if (r_type
== elfcpp::R_PPC64_TOC
)
7193 value
= (target
->got_section()->output_section()->address()
7194 + object
->toc_base_offset());
7196 else if (gsym
!= NULL
7197 && (r_type
== elfcpp::R_POWERPC_REL24
7198 || r_type
== elfcpp::R_PPC_PLTREL24
)
7203 typedef typename
elfcpp::Swap
<32, big_endian
>::Valtype Valtype
;
7204 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
7205 bool can_plt_call
= false;
7206 if (rela
.get_r_offset() + 8 <= view_size
)
7208 Valtype insn
= elfcpp::Swap
<32, big_endian
>::readval(wv
);
7209 Valtype insn2
= elfcpp::Swap
<32, big_endian
>::readval(wv
+ 1);
7212 || insn2
== cror_15_15_15
|| insn2
== cror_31_31_31
))
7214 elfcpp::Swap
<32, big_endian
>::
7215 writeval(wv
+ 1, ld_2_1
+ target
->stk_toc());
7216 can_plt_call
= true;
7221 // If we don't have a branch and link followed by a nop,
7222 // we can't go via the plt because there is no place to
7223 // put a toc restoring instruction.
7224 // Unless we know we won't be returning.
7225 if (strcmp(gsym
->name(), "__libc_start_main") == 0)
7226 can_plt_call
= true;
7230 // g++ as of 20130507 emits self-calls without a
7231 // following nop. This is arguably wrong since we have
7232 // conflicting information. On the one hand a global
7233 // symbol and on the other a local call sequence, but
7234 // don't error for this special case.
7235 // It isn't possible to cheaply verify we have exactly
7236 // such a call. Allow all calls to the same section.
7238 Address code
= value
;
7239 if (gsym
->source() == Symbol::FROM_OBJECT
7240 && gsym
->object() == object
)
7242 unsigned int dest_shndx
= 0;
7243 if (target
->abiversion() < 2)
7245 Address addend
= rela
.get_r_addend();
7246 code
= psymval
->value(object
, addend
);
7247 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7248 &code
, &dest_shndx
);
7251 if (dest_shndx
== 0)
7252 dest_shndx
= gsym
->shndx(&is_ordinary
);
7253 ok
= dest_shndx
== relinfo
->data_shndx
;
7257 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7258 _("call lacks nop, can't restore toc; "
7259 "recompile with -fPIC"));
7265 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7266 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
7267 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
7268 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
7270 // First instruction of a global dynamic sequence, arg setup insn.
7271 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7272 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7273 enum Got_type got_type
= GOT_TYPE_STANDARD
;
7274 if (tls_type
== tls::TLSOPT_NONE
)
7275 got_type
= GOT_TYPE_TLSGD
;
7276 else if (tls_type
== tls::TLSOPT_TO_IE
)
7277 got_type
= GOT_TYPE_TPREL
;
7278 if (got_type
!= GOT_TYPE_STANDARD
)
7282 gold_assert(gsym
->has_got_offset(got_type
));
7283 value
= gsym
->got_offset(got_type
);
7287 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7288 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
7289 value
= object
->local_got_offset(r_sym
, got_type
);
7291 value
-= target
->got_section()->got_base_offset(object
);
7293 if (tls_type
== tls::TLSOPT_TO_IE
)
7295 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7296 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7298 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7299 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7300 insn
&= (1 << 26) - (1 << 16); // extract rt,ra from addi
7302 insn
|= 32 << 26; // lwz
7304 insn
|= 58 << 26; // ld
7305 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7307 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
7308 - elfcpp::R_POWERPC_GOT_TLSGD16
);
7310 else if (tls_type
== tls::TLSOPT_TO_LE
)
7312 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
7313 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
7315 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7316 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7317 insn
&= (1 << 26) - (1 << 21); // extract rt
7322 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7323 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7324 value
= psymval
->value(object
, rela
.get_r_addend());
7328 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7330 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7331 r_type
= elfcpp::R_POWERPC_NONE
;
7335 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7336 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
7337 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
7338 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
7340 // First instruction of a local dynamic sequence, arg setup insn.
7341 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7342 if (tls_type
== tls::TLSOPT_NONE
)
7344 value
= target
->tlsld_got_offset();
7345 value
-= target
->got_section()->got_base_offset(object
);
7349 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7350 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
7351 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
7353 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7354 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7355 insn
&= (1 << 26) - (1 << 21); // extract rt
7360 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7361 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7366 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7368 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7369 r_type
= elfcpp::R_POWERPC_NONE
;
7373 else if (r_type
== elfcpp::R_POWERPC_GOT_DTPREL16
7374 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_LO
7375 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HI
7376 || r_type
== elfcpp::R_POWERPC_GOT_DTPREL16_HA
)
7378 // Accesses relative to a local dynamic sequence address,
7379 // no optimisation here.
7382 gold_assert(gsym
->has_got_offset(GOT_TYPE_DTPREL
));
7383 value
= gsym
->got_offset(GOT_TYPE_DTPREL
);
7387 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7388 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_DTPREL
));
7389 value
= object
->local_got_offset(r_sym
, GOT_TYPE_DTPREL
);
7391 value
-= target
->got_section()->got_base_offset(object
);
7393 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7394 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
7395 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
7396 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
7398 // First instruction of initial exec sequence.
7399 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7400 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7401 if (tls_type
== tls::TLSOPT_NONE
)
7405 gold_assert(gsym
->has_got_offset(GOT_TYPE_TPREL
));
7406 value
= gsym
->got_offset(GOT_TYPE_TPREL
);
7410 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
7411 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_TPREL
));
7412 value
= object
->local_got_offset(r_sym
, GOT_TYPE_TPREL
);
7414 value
-= target
->got_section()->got_base_offset(object
);
7418 gold_assert(tls_type
== tls::TLSOPT_TO_LE
);
7419 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
7420 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
7422 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7423 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7424 insn
&= (1 << 26) - (1 << 21); // extract rt from ld
7429 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7430 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
7431 value
= psymval
->value(object
, rela
.get_r_addend());
7435 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7437 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7438 r_type
= elfcpp::R_POWERPC_NONE
;
7442 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
7443 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
7445 // Second instruction of a global dynamic sequence,
7446 // the __tls_get_addr call
7447 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7448 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7449 const tls::Tls_optimization tls_type
= target
->optimize_tls_gd(final
);
7450 if (tls_type
!= tls::TLSOPT_NONE
)
7452 if (tls_type
== tls::TLSOPT_TO_IE
)
7454 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7455 Insn insn
= add_3_3_13
;
7458 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7459 r_type
= elfcpp::R_POWERPC_NONE
;
7463 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7464 Insn insn
= addi_3_3
;
7465 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7466 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7468 value
= psymval
->value(object
, rela
.get_r_addend());
7470 this->skip_next_tls_get_addr_call();
7473 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
7474 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
7476 // Second instruction of a local dynamic sequence,
7477 // the __tls_get_addr call
7478 this->expect_tls_get_addr_call(relinfo
, relnum
, rela
.get_r_offset());
7479 const tls::Tls_optimization tls_type
= target
->optimize_tls_ld();
7480 if (tls_type
== tls::TLSOPT_TO_LE
)
7482 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7483 Insn insn
= addi_3_3
;
7484 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7485 this->skip_next_tls_get_addr_call();
7486 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7491 else if (r_type
== elfcpp::R_POWERPC_TLS
)
7493 // Second instruction of an initial exec sequence
7494 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
7495 const tls::Tls_optimization tls_type
= target
->optimize_tls_ie(final
);
7496 if (tls_type
== tls::TLSOPT_TO_LE
)
7498 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7499 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7500 unsigned int reg
= size
== 32 ? 2 : 13;
7501 insn
= at_tls_transform(insn
, reg
);
7502 gold_assert(insn
!= 0);
7503 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7504 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
7506 value
= psymval
->value(object
, rela
.get_r_addend());
7509 else if (!has_stub_value
)
7512 if (!(size
== 32 && r_type
== elfcpp::R_PPC_PLTREL24
))
7513 addend
= rela
.get_r_addend();
7514 value
= psymval
->value(object
, addend
);
7515 if (size
== 64 && is_branch_reloc(r_type
))
7517 if (target
->abiversion() >= 2)
7520 value
+= object
->ppc64_local_entry_offset(gsym
);
7522 value
+= object
->ppc64_local_entry_offset(r_sym
);
7526 unsigned int dest_shndx
;
7527 target
->symval_for_branch(relinfo
->symtab
, gsym
, object
,
7528 &value
, &dest_shndx
);
7531 Address max_branch_offset
= max_branch_delta(r_type
);
7532 if (max_branch_offset
!= 0
7533 && value
- address
+ max_branch_offset
>= 2 * max_branch_offset
)
7535 Stub_table
<size
, big_endian
>* stub_table
7536 = object
->stub_table(relinfo
->data_shndx
);
7537 if (stub_table
!= NULL
)
7539 Address off
= stub_table
->find_long_branch_entry(object
, value
);
7540 if (off
!= invalid_address
)
7542 value
= (stub_table
->stub_address() + stub_table
->plt_size()
7544 has_stub_value
= true;
7552 case elfcpp::R_PPC64_REL64
:
7553 case elfcpp::R_POWERPC_REL32
:
7554 case elfcpp::R_POWERPC_REL24
:
7555 case elfcpp::R_PPC_PLTREL24
:
7556 case elfcpp::R_PPC_LOCAL24PC
:
7557 case elfcpp::R_POWERPC_REL16
:
7558 case elfcpp::R_POWERPC_REL16_LO
:
7559 case elfcpp::R_POWERPC_REL16_HI
:
7560 case elfcpp::R_POWERPC_REL16_HA
:
7561 case elfcpp::R_POWERPC_REL16DX_HA
:
7562 case elfcpp::R_POWERPC_REL14
:
7563 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7564 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7568 case elfcpp::R_PPC64_TOC16
:
7569 case elfcpp::R_PPC64_TOC16_LO
:
7570 case elfcpp::R_PPC64_TOC16_HI
:
7571 case elfcpp::R_PPC64_TOC16_HA
:
7572 case elfcpp::R_PPC64_TOC16_DS
:
7573 case elfcpp::R_PPC64_TOC16_LO_DS
:
7574 // Subtract the TOC base address.
7575 value
-= (target
->got_section()->output_section()->address()
7576 + object
->toc_base_offset());
7579 case elfcpp::R_POWERPC_SECTOFF
:
7580 case elfcpp::R_POWERPC_SECTOFF_LO
:
7581 case elfcpp::R_POWERPC_SECTOFF_HI
:
7582 case elfcpp::R_POWERPC_SECTOFF_HA
:
7583 case elfcpp::R_PPC64_SECTOFF_DS
:
7584 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
7586 value
-= os
->address();
7589 case elfcpp::R_PPC64_TPREL16_DS
:
7590 case elfcpp::R_PPC64_TPREL16_LO_DS
:
7591 case elfcpp::R_PPC64_TPREL16_HIGH
:
7592 case elfcpp::R_PPC64_TPREL16_HIGHA
:
7594 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7597 case elfcpp::R_POWERPC_TPREL16
:
7598 case elfcpp::R_POWERPC_TPREL16_LO
:
7599 case elfcpp::R_POWERPC_TPREL16_HI
:
7600 case elfcpp::R_POWERPC_TPREL16_HA
:
7601 case elfcpp::R_POWERPC_TPREL
:
7602 case elfcpp::R_PPC64_TPREL16_HIGHER
:
7603 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
7604 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
7605 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
7606 // tls symbol values are relative to tls_segment()->vaddr()
7610 case elfcpp::R_PPC64_DTPREL16_DS
:
7611 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
7612 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
7613 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
7614 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
7615 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
7617 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7618 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7621 case elfcpp::R_POWERPC_DTPREL16
:
7622 case elfcpp::R_POWERPC_DTPREL16_LO
:
7623 case elfcpp::R_POWERPC_DTPREL16_HI
:
7624 case elfcpp::R_POWERPC_DTPREL16_HA
:
7625 case elfcpp::R_POWERPC_DTPREL
:
7626 case elfcpp::R_PPC64_DTPREL16_HIGH
:
7627 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
7628 // tls symbol values are relative to tls_segment()->vaddr()
7629 value
-= dtp_offset
;
7632 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7634 value
+= object
->ppc64_local_entry_offset(gsym
);
7636 value
+= object
->ppc64_local_entry_offset(r_sym
);
7643 Insn branch_bit
= 0;
7646 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7647 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7648 branch_bit
= 1 << 21;
7650 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7651 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7653 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7654 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7657 if (this->is_isa_v2
)
7659 // Set 'a' bit. This is 0b00010 in BO field for branch
7660 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7661 // for branch on CTR insns (BO == 1a00t or 1a01t).
7662 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7664 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7671 // Invert 'y' bit if not the default.
7672 if (static_cast<Signed_address
>(value
) < 0)
7675 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7685 // Multi-instruction sequences that access the TOC can be
7686 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7687 // to nop; addi rb,r2,x;
7693 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7694 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7695 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7696 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7697 case elfcpp::R_POWERPC_GOT16_HA
:
7698 case elfcpp::R_PPC64_TOC16_HA
:
7699 if (parameters
->options().toc_optimize())
7701 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7702 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7703 if ((insn
& ((0x3f << 26) | 0x1f << 16))
7704 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7705 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7706 _("toc optimization is not supported "
7707 "for %#08x instruction"), insn
);
7708 else if (value
+ 0x8000 < 0x10000)
7710 elfcpp::Swap
<32, big_endian
>::writeval(iview
, nop
);
7716 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
7717 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
7718 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
7719 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
7720 case elfcpp::R_POWERPC_GOT16_LO
:
7721 case elfcpp::R_PPC64_GOT16_LO_DS
:
7722 case elfcpp::R_PPC64_TOC16_LO
:
7723 case elfcpp::R_PPC64_TOC16_LO_DS
:
7724 if (parameters
->options().toc_optimize())
7726 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7727 Insn insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7728 if (!ok_lo_toc_insn(insn
))
7729 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
7730 _("toc optimization is not supported "
7731 "for %#08x instruction"), insn
);
7732 else if (value
+ 0x8000 < 0x10000)
7734 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
7736 // Transform addic to addi when we change reg.
7737 insn
&= ~((0x3f << 26) | (0x1f << 16));
7738 insn
|= (14u << 26) | (2 << 16);
7742 insn
&= ~(0x1f << 16);
7745 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn
);
7750 case elfcpp::R_PPC64_ENTRY
:
7751 value
= (target
->got_section()->output_section()->address()
7752 + object
->toc_base_offset());
7753 if (value
+ 0x80008000 <= 0xffffffff
7754 && !parameters
->options().output_is_position_independent())
7756 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7757 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7758 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
7760 if ((insn1
& ~0xfffc) == ld_2_12
7761 && insn2
== add_2_2_12
)
7763 insn1
= lis_2
+ ha(value
);
7764 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
7765 insn2
= addi_2_2
+ l(value
);
7766 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
7773 if (value
+ 0x80008000 <= 0xffffffff)
7775 Insn
* iview
= reinterpret_cast<Insn
*>(view
);
7776 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7777 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
+ 1);
7779 if ((insn1
& ~0xfffc) == ld_2_12
7780 && insn2
== add_2_2_12
)
7782 insn1
= addis_2_12
+ ha(value
);
7783 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn1
);
7784 insn2
= addi_2_2
+ l(value
);
7785 elfcpp::Swap
<32, big_endian
>::writeval(iview
+ 1, insn2
);
7792 case elfcpp::R_POWERPC_REL16_LO
:
7793 // If we are generating a non-PIC executable, edit
7794 // 0: addis 2,12,.TOC.-0b@ha
7795 // addi 2,2,.TOC.-0b@l
7796 // used by ELFv2 global entry points to set up r2, to
7799 // if .TOC. is in range. */
7800 if (value
+ address
- 4 + 0x80008000 <= 0xffffffff
7803 && target
->abiversion() >= 2
7804 && !parameters
->options().output_is_position_independent()
7805 && rela
.get_r_addend() == d_offset
+ 4
7807 && strcmp(gsym
->name(), ".TOC.") == 0)
7809 const int reloc_size
7810 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
7811 Reltype
prev_rela(preloc
- reloc_size
);
7812 if ((prev_rela
.get_r_info()
7813 == elfcpp::elf_r_info
<size
>(r_sym
,
7814 elfcpp::R_POWERPC_REL16_HA
))
7815 && prev_rela
.get_r_offset() + 4 == rela
.get_r_offset()
7816 && prev_rela
.get_r_addend() + 4 == rela
.get_r_addend())
7818 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7819 Insn insn1
= elfcpp::Swap
<32, big_endian
>::readval(iview
- 1);
7820 Insn insn2
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7822 if ((insn1
& 0xffff0000) == addis_2_12
7823 && (insn2
& 0xffff0000) == addi_2_2
)
7825 insn1
= lis_2
+ ha(value
+ address
- 4);
7826 elfcpp::Swap
<32, big_endian
>::writeval(iview
- 1, insn1
);
7827 insn2
= addi_2_2
+ l(value
+ address
- 4);
7828 elfcpp::Swap
<32, big_endian
>::writeval(iview
, insn2
);
7831 relinfo
->rr
->set_strategy(relnum
- 1,
7832 Relocatable_relocs::RELOC_SPECIAL
);
7833 relinfo
->rr
->set_strategy(relnum
,
7834 Relocatable_relocs::RELOC_SPECIAL
);
7844 typename
Reloc::Overflow_check overflow
= Reloc::CHECK_NONE
;
7845 elfcpp::Shdr
<size
, big_endian
> shdr(relinfo
->data_shdr
);
7848 case elfcpp::R_POWERPC_ADDR32
:
7849 case elfcpp::R_POWERPC_UADDR32
:
7851 overflow
= Reloc::CHECK_BITFIELD
;
7854 case elfcpp::R_POWERPC_REL32
:
7855 case elfcpp::R_POWERPC_REL16DX_HA
:
7857 overflow
= Reloc::CHECK_SIGNED
;
7860 case elfcpp::R_POWERPC_UADDR16
:
7861 overflow
= Reloc::CHECK_BITFIELD
;
7864 case elfcpp::R_POWERPC_ADDR16
:
7865 // We really should have three separate relocations,
7866 // one for 16-bit data, one for insns with 16-bit signed fields,
7867 // and one for insns with 16-bit unsigned fields.
7868 overflow
= Reloc::CHECK_BITFIELD
;
7869 if ((shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0)
7870 overflow
= Reloc::CHECK_LOW_INSN
;
7873 case elfcpp::R_POWERPC_ADDR16_HI
:
7874 case elfcpp::R_POWERPC_ADDR16_HA
:
7875 case elfcpp::R_POWERPC_GOT16_HI
:
7876 case elfcpp::R_POWERPC_GOT16_HA
:
7877 case elfcpp::R_POWERPC_PLT16_HI
:
7878 case elfcpp::R_POWERPC_PLT16_HA
:
7879 case elfcpp::R_POWERPC_SECTOFF_HI
:
7880 case elfcpp::R_POWERPC_SECTOFF_HA
:
7881 case elfcpp::R_PPC64_TOC16_HI
:
7882 case elfcpp::R_PPC64_TOC16_HA
:
7883 case elfcpp::R_PPC64_PLTGOT16_HI
:
7884 case elfcpp::R_PPC64_PLTGOT16_HA
:
7885 case elfcpp::R_POWERPC_TPREL16_HI
:
7886 case elfcpp::R_POWERPC_TPREL16_HA
:
7887 case elfcpp::R_POWERPC_DTPREL16_HI
:
7888 case elfcpp::R_POWERPC_DTPREL16_HA
:
7889 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
7890 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
7891 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
7892 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
7893 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
7894 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
7895 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
7896 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
7897 case elfcpp::R_POWERPC_REL16_HI
:
7898 case elfcpp::R_POWERPC_REL16_HA
:
7900 overflow
= Reloc::CHECK_HIGH_INSN
;
7903 case elfcpp::R_POWERPC_REL16
:
7904 case elfcpp::R_PPC64_TOC16
:
7905 case elfcpp::R_POWERPC_GOT16
:
7906 case elfcpp::R_POWERPC_SECTOFF
:
7907 case elfcpp::R_POWERPC_TPREL16
:
7908 case elfcpp::R_POWERPC_DTPREL16
:
7909 case elfcpp::R_POWERPC_GOT_TLSGD16
:
7910 case elfcpp::R_POWERPC_GOT_TLSLD16
:
7911 case elfcpp::R_POWERPC_GOT_TPREL16
:
7912 case elfcpp::R_POWERPC_GOT_DTPREL16
:
7913 overflow
= Reloc::CHECK_LOW_INSN
;
7916 case elfcpp::R_POWERPC_ADDR24
:
7917 case elfcpp::R_POWERPC_ADDR14
:
7918 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
7919 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
7920 case elfcpp::R_PPC64_ADDR16_DS
:
7921 case elfcpp::R_POWERPC_REL24
:
7922 case elfcpp::R_PPC_PLTREL24
:
7923 case elfcpp::R_PPC_LOCAL24PC
:
7924 case elfcpp::R_PPC64_TPREL16_DS
:
7925 case elfcpp::R_PPC64_DTPREL16_DS
:
7926 case elfcpp::R_PPC64_TOC16_DS
:
7927 case elfcpp::R_PPC64_GOT16_DS
:
7928 case elfcpp::R_PPC64_SECTOFF_DS
:
7929 case elfcpp::R_POWERPC_REL14
:
7930 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
7931 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
7932 overflow
= Reloc::CHECK_SIGNED
;
7936 Insn
* iview
= reinterpret_cast<Insn
*>(view
- d_offset
);
7939 if (overflow
== Reloc::CHECK_LOW_INSN
7940 || overflow
== Reloc::CHECK_HIGH_INSN
)
7942 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
7944 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
7945 overflow
= Reloc::CHECK_BITFIELD
;
7946 else if (overflow
== Reloc::CHECK_LOW_INSN
7947 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
7948 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
7949 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
7950 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
7951 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
7952 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
7953 overflow
= Reloc::CHECK_UNSIGNED
;
7955 overflow
= Reloc::CHECK_SIGNED
;
7958 bool maybe_dq_reloc
= false;
7959 typename Powerpc_relocate_functions
<size
, big_endian
>::Status status
7960 = Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
;
7963 case elfcpp::R_POWERPC_NONE
:
7964 case elfcpp::R_POWERPC_TLS
:
7965 case elfcpp::R_POWERPC_GNU_VTINHERIT
:
7966 case elfcpp::R_POWERPC_GNU_VTENTRY
:
7969 case elfcpp::R_PPC64_ADDR64
:
7970 case elfcpp::R_PPC64_REL64
:
7971 case elfcpp::R_PPC64_TOC
:
7972 case elfcpp::R_PPC64_ADDR64_LOCAL
:
7973 Reloc::addr64(view
, value
);
7976 case elfcpp::R_POWERPC_TPREL
:
7977 case elfcpp::R_POWERPC_DTPREL
:
7979 Reloc::addr64(view
, value
);
7981 status
= Reloc::addr32(view
, value
, overflow
);
7984 case elfcpp::R_PPC64_UADDR64
:
7985 Reloc::addr64_u(view
, value
);
7988 case elfcpp::R_POWERPC_ADDR32
:
7989 status
= Reloc::addr32(view
, value
, overflow
);
7992 case elfcpp::R_POWERPC_REL32
:
7993 case elfcpp::R_POWERPC_UADDR32
:
7994 status
= Reloc::addr32_u(view
, value
, overflow
);
7997 case elfcpp::R_POWERPC_ADDR24
:
7998 case elfcpp::R_POWERPC_REL24
:
7999 case elfcpp::R_PPC_PLTREL24
:
8000 case elfcpp::R_PPC_LOCAL24PC
:
8001 status
= Reloc::addr24(view
, value
, overflow
);
8004 case elfcpp::R_POWERPC_GOT_DTPREL16
:
8005 case elfcpp::R_POWERPC_GOT_DTPREL16_LO
:
8006 case elfcpp::R_POWERPC_GOT_TPREL16
:
8007 case elfcpp::R_POWERPC_GOT_TPREL16_LO
:
8010 // On ppc64 these are all ds form
8011 maybe_dq_reloc
= true;
8015 case elfcpp::R_POWERPC_ADDR16
:
8016 case elfcpp::R_POWERPC_REL16
:
8017 case elfcpp::R_PPC64_TOC16
:
8018 case elfcpp::R_POWERPC_GOT16
:
8019 case elfcpp::R_POWERPC_SECTOFF
:
8020 case elfcpp::R_POWERPC_TPREL16
:
8021 case elfcpp::R_POWERPC_DTPREL16
:
8022 case elfcpp::R_POWERPC_GOT_TLSGD16
:
8023 case elfcpp::R_POWERPC_GOT_TLSLD16
:
8024 case elfcpp::R_POWERPC_ADDR16_LO
:
8025 case elfcpp::R_POWERPC_REL16_LO
:
8026 case elfcpp::R_PPC64_TOC16_LO
:
8027 case elfcpp::R_POWERPC_GOT16_LO
:
8028 case elfcpp::R_POWERPC_SECTOFF_LO
:
8029 case elfcpp::R_POWERPC_TPREL16_LO
:
8030 case elfcpp::R_POWERPC_DTPREL16_LO
:
8031 case elfcpp::R_POWERPC_GOT_TLSGD16_LO
:
8032 case elfcpp::R_POWERPC_GOT_TLSLD16_LO
:
8034 status
= Reloc::addr16(view
, value
, overflow
);
8036 maybe_dq_reloc
= true;
8039 case elfcpp::R_POWERPC_UADDR16
:
8040 status
= Reloc::addr16_u(view
, value
, overflow
);
8043 case elfcpp::R_PPC64_ADDR16_HIGH
:
8044 case elfcpp::R_PPC64_TPREL16_HIGH
:
8045 case elfcpp::R_PPC64_DTPREL16_HIGH
:
8047 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
8050 case elfcpp::R_POWERPC_ADDR16_HI
:
8051 case elfcpp::R_POWERPC_REL16_HI
:
8052 case elfcpp::R_PPC64_TOC16_HI
:
8053 case elfcpp::R_POWERPC_GOT16_HI
:
8054 case elfcpp::R_POWERPC_SECTOFF_HI
:
8055 case elfcpp::R_POWERPC_TPREL16_HI
:
8056 case elfcpp::R_POWERPC_DTPREL16_HI
:
8057 case elfcpp::R_POWERPC_GOT_TLSGD16_HI
:
8058 case elfcpp::R_POWERPC_GOT_TLSLD16_HI
:
8059 case elfcpp::R_POWERPC_GOT_TPREL16_HI
:
8060 case elfcpp::R_POWERPC_GOT_DTPREL16_HI
:
8061 Reloc::addr16_hi(view
, value
);
8064 case elfcpp::R_PPC64_ADDR16_HIGHA
:
8065 case elfcpp::R_PPC64_TPREL16_HIGHA
:
8066 case elfcpp::R_PPC64_DTPREL16_HIGHA
:
8068 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
8071 case elfcpp::R_POWERPC_ADDR16_HA
:
8072 case elfcpp::R_POWERPC_REL16_HA
:
8073 case elfcpp::R_PPC64_TOC16_HA
:
8074 case elfcpp::R_POWERPC_GOT16_HA
:
8075 case elfcpp::R_POWERPC_SECTOFF_HA
:
8076 case elfcpp::R_POWERPC_TPREL16_HA
:
8077 case elfcpp::R_POWERPC_DTPREL16_HA
:
8078 case elfcpp::R_POWERPC_GOT_TLSGD16_HA
:
8079 case elfcpp::R_POWERPC_GOT_TLSLD16_HA
:
8080 case elfcpp::R_POWERPC_GOT_TPREL16_HA
:
8081 case elfcpp::R_POWERPC_GOT_DTPREL16_HA
:
8082 Reloc::addr16_ha(view
, value
);
8085 case elfcpp::R_POWERPC_REL16DX_HA
:
8086 status
= Reloc::addr16dx_ha(view
, value
, overflow
);
8089 case elfcpp::R_PPC64_DTPREL16_HIGHER
:
8091 // R_PPC_EMB_NADDR16_LO
8094 case elfcpp::R_PPC64_ADDR16_HIGHER
:
8095 case elfcpp::R_PPC64_TPREL16_HIGHER
:
8096 Reloc::addr16_hi2(view
, value
);
8099 case elfcpp::R_PPC64_DTPREL16_HIGHERA
:
8101 // R_PPC_EMB_NADDR16_HI
8104 case elfcpp::R_PPC64_ADDR16_HIGHERA
:
8105 case elfcpp::R_PPC64_TPREL16_HIGHERA
:
8106 Reloc::addr16_ha2(view
, value
);
8109 case elfcpp::R_PPC64_DTPREL16_HIGHEST
:
8111 // R_PPC_EMB_NADDR16_HA
8114 case elfcpp::R_PPC64_ADDR16_HIGHEST
:
8115 case elfcpp::R_PPC64_TPREL16_HIGHEST
:
8116 Reloc::addr16_hi3(view
, value
);
8119 case elfcpp::R_PPC64_DTPREL16_HIGHESTA
:
8124 case elfcpp::R_PPC64_ADDR16_HIGHESTA
:
8125 case elfcpp::R_PPC64_TPREL16_HIGHESTA
:
8126 Reloc::addr16_ha3(view
, value
);
8129 case elfcpp::R_PPC64_DTPREL16_DS
:
8130 case elfcpp::R_PPC64_DTPREL16_LO_DS
:
8132 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
8135 case elfcpp::R_PPC64_TPREL16_DS
:
8136 case elfcpp::R_PPC64_TPREL16_LO_DS
:
8138 // R_PPC_TLSGD, R_PPC_TLSLD
8141 case elfcpp::R_PPC64_ADDR16_DS
:
8142 case elfcpp::R_PPC64_ADDR16_LO_DS
:
8143 case elfcpp::R_PPC64_TOC16_DS
:
8144 case elfcpp::R_PPC64_TOC16_LO_DS
:
8145 case elfcpp::R_PPC64_GOT16_DS
:
8146 case elfcpp::R_PPC64_GOT16_LO_DS
:
8147 case elfcpp::R_PPC64_SECTOFF_DS
:
8148 case elfcpp::R_PPC64_SECTOFF_LO_DS
:
8149 maybe_dq_reloc
= true;
8152 case elfcpp::R_POWERPC_ADDR14
:
8153 case elfcpp::R_POWERPC_ADDR14_BRTAKEN
:
8154 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN
:
8155 case elfcpp::R_POWERPC_REL14
:
8156 case elfcpp::R_POWERPC_REL14_BRTAKEN
:
8157 case elfcpp::R_POWERPC_REL14_BRNTAKEN
:
8158 status
= Reloc::addr14(view
, value
, overflow
);
8161 case elfcpp::R_POWERPC_COPY
:
8162 case elfcpp::R_POWERPC_GLOB_DAT
:
8163 case elfcpp::R_POWERPC_JMP_SLOT
:
8164 case elfcpp::R_POWERPC_RELATIVE
:
8165 case elfcpp::R_POWERPC_DTPMOD
:
8166 case elfcpp::R_PPC64_JMP_IREL
:
8167 case elfcpp::R_POWERPC_IRELATIVE
:
8168 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8169 _("unexpected reloc %u in object file"),
8173 case elfcpp::R_PPC_EMB_SDA21
:
8178 // R_PPC64_TOCSAVE. For the time being this can be ignored.
8182 case elfcpp::R_PPC_EMB_SDA2I16
:
8183 case elfcpp::R_PPC_EMB_SDA2REL
:
8186 // R_PPC64_TLSGD, R_PPC64_TLSLD
8189 case elfcpp::R_POWERPC_PLT32
:
8190 case elfcpp::R_POWERPC_PLTREL32
:
8191 case elfcpp::R_POWERPC_PLT16_LO
:
8192 case elfcpp::R_POWERPC_PLT16_HI
:
8193 case elfcpp::R_POWERPC_PLT16_HA
:
8194 case elfcpp::R_PPC_SDAREL16
:
8195 case elfcpp::R_POWERPC_ADDR30
:
8196 case elfcpp::R_PPC64_PLT64
:
8197 case elfcpp::R_PPC64_PLTREL64
:
8198 case elfcpp::R_PPC64_PLTGOT16
:
8199 case elfcpp::R_PPC64_PLTGOT16_LO
:
8200 case elfcpp::R_PPC64_PLTGOT16_HI
:
8201 case elfcpp::R_PPC64_PLTGOT16_HA
:
8202 case elfcpp::R_PPC64_PLT16_LO_DS
:
8203 case elfcpp::R_PPC64_PLTGOT16_DS
:
8204 case elfcpp::R_PPC64_PLTGOT16_LO_DS
:
8205 case elfcpp::R_PPC_EMB_RELSDA
:
8206 case elfcpp::R_PPC_TOC16
:
8209 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8210 _("unsupported reloc %u"),
8218 insn
= elfcpp::Swap
<32, big_endian
>::readval(iview
);
8220 if ((insn
& (0x3f << 26)) == 56u << 26 /* lq */
8221 || ((insn
& (0x3f << 26)) == (61u << 26) /* lxv, stxv */
8222 && (insn
& 3) == 1))
8223 status
= Reloc::addr16_dq(view
, value
, overflow
);
8225 || (insn
& (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
8226 || (insn
& (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
8227 || (insn
& (0x3f << 26)) == 57u << 26 /* lfdp */
8228 || (insn
& (0x3f << 26)) == 61u << 26 /* stfdp */)
8229 status
= Reloc::addr16_ds(view
, value
, overflow
);
8231 status
= Reloc::addr16(view
, value
, overflow
);
8234 if (status
!= Powerpc_relocate_functions
<size
, big_endian
>::STATUS_OK
8237 && gsym
->is_undefined()
8238 && is_branch_reloc(r_type
))))
8240 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
8241 _("relocation overflow"));
8243 gold_info(_("try relinking with a smaller --stub-group-size"));
8249 // Relocate section data.
8251 template<int size
, bool big_endian
>
8253 Target_powerpc
<size
, big_endian
>::relocate_section(
8254 const Relocate_info
<size
, big_endian
>* relinfo
,
8255 unsigned int sh_type
,
8256 const unsigned char* prelocs
,
8258 Output_section
* output_section
,
8259 bool needs_special_offset_handling
,
8260 unsigned char* view
,
8262 section_size_type view_size
,
8263 const Reloc_symbol_changes
* reloc_symbol_changes
)
8265 typedef Target_powerpc
<size
, big_endian
> Powerpc
;
8266 typedef typename Target_powerpc
<size
, big_endian
>::Relocate Powerpc_relocate
;
8267 typedef typename Target_powerpc
<size
, big_endian
>::Relocate_comdat_behavior
8268 Powerpc_comdat_behavior
;
8269 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8272 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8274 gold::relocate_section
<size
, big_endian
, Powerpc
, Powerpc_relocate
,
8275 Powerpc_comdat_behavior
, Classify_reloc
>(
8281 needs_special_offset_handling
,
8285 reloc_symbol_changes
);
8288 template<int size
, bool big_endian
>
8289 class Powerpc_scan_relocatable_reloc
8292 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
8294 static const int reloc_size
=
8295 Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
8296 static const int sh_type
= elfcpp::SHT_RELA
;
8298 // Return the symbol referred to by the relocation.
8299 static inline unsigned int
8300 get_r_sym(const Reltype
* reloc
)
8301 { return elfcpp::elf_r_sym
<size
>(reloc
->get_r_info()); }
8303 // Return the type of the relocation.
8304 static inline unsigned int
8305 get_r_type(const Reltype
* reloc
)
8306 { return elfcpp::elf_r_type
<size
>(reloc
->get_r_info()); }
8308 // Return the strategy to use for a local symbol which is not a
8309 // section symbol, given the relocation type.
8310 inline Relocatable_relocs::Reloc_strategy
8311 local_non_section_strategy(unsigned int r_type
, Relobj
*, unsigned int r_sym
)
8313 if (r_type
== 0 && r_sym
== 0)
8314 return Relocatable_relocs::RELOC_DISCARD
;
8315 return Relocatable_relocs::RELOC_COPY
;
8318 // Return the strategy to use for a local symbol which is a section
8319 // symbol, given the relocation type.
8320 inline Relocatable_relocs::Reloc_strategy
8321 local_section_strategy(unsigned int, Relobj
*)
8323 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
;
8326 // Return the strategy to use for a global symbol, given the
8327 // relocation type, the object, and the symbol index.
8328 inline Relocatable_relocs::Reloc_strategy
8329 global_strategy(unsigned int r_type
, Relobj
*, unsigned int)
8331 if (r_type
== elfcpp::R_PPC_PLTREL24
)
8332 return Relocatable_relocs::RELOC_SPECIAL
;
8333 return Relocatable_relocs::RELOC_COPY
;
8337 // Scan the relocs during a relocatable link.
8339 template<int size
, bool big_endian
>
8341 Target_powerpc
<size
, big_endian
>::scan_relocatable_relocs(
8342 Symbol_table
* symtab
,
8344 Sized_relobj_file
<size
, big_endian
>* object
,
8345 unsigned int data_shndx
,
8346 unsigned int sh_type
,
8347 const unsigned char* prelocs
,
8349 Output_section
* output_section
,
8350 bool needs_special_offset_handling
,
8351 size_t local_symbol_count
,
8352 const unsigned char* plocal_symbols
,
8353 Relocatable_relocs
* rr
)
8355 typedef Powerpc_scan_relocatable_reloc
<size
, big_endian
> Scan_strategy
;
8357 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8359 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_strategy
>(
8367 needs_special_offset_handling
,
8373 // Scan the relocs for --emit-relocs.
8375 template<int size
, bool big_endian
>
8377 Target_powerpc
<size
, big_endian
>::emit_relocs_scan(
8378 Symbol_table
* symtab
,
8380 Sized_relobj_file
<size
, big_endian
>* object
,
8381 unsigned int data_shndx
,
8382 unsigned int sh_type
,
8383 const unsigned char* prelocs
,
8385 Output_section
* output_section
,
8386 bool needs_special_offset_handling
,
8387 size_t local_symbol_count
,
8388 const unsigned char* plocal_syms
,
8389 Relocatable_relocs
* rr
)
8391 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
8393 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
8394 Emit_relocs_strategy
;
8396 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8398 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
8406 needs_special_offset_handling
,
8412 // Emit relocations for a section.
8413 // This is a modified version of the function by the same name in
8414 // target-reloc.h. Using relocate_special_relocatable for
8415 // R_PPC_PLTREL24 would require duplication of the entire body of the
8416 // loop, so we may as well duplicate the whole thing.
8418 template<int size
, bool big_endian
>
8420 Target_powerpc
<size
, big_endian
>::relocate_relocs(
8421 const Relocate_info
<size
, big_endian
>* relinfo
,
8422 unsigned int sh_type
,
8423 const unsigned char* prelocs
,
8425 Output_section
* output_section
,
8426 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
8428 Address view_address
,
8430 unsigned char* reloc_view
,
8431 section_size_type reloc_view_size
)
8433 gold_assert(sh_type
== elfcpp::SHT_RELA
);
8435 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc
8437 typedef typename Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::Reloc_write
8439 const int reloc_size
8440 = Reloc_types
<elfcpp::SHT_RELA
, size
, big_endian
>::reloc_size
;
8441 // Offset from start of insn to d-field reloc.
8442 const int d_offset
= big_endian
? 2 : 0;
8444 Powerpc_relobj
<size
, big_endian
>* const object
8445 = static_cast<Powerpc_relobj
<size
, big_endian
>*>(relinfo
->object
);
8446 const unsigned int local_count
= object
->local_symbol_count();
8447 unsigned int got2_shndx
= object
->got2_shndx();
8448 Address got2_addend
= 0;
8449 if (got2_shndx
!= 0)
8451 got2_addend
= object
->get_output_section_offset(got2_shndx
);
8452 gold_assert(got2_addend
!= invalid_address
);
8455 unsigned char* pwrite
= reloc_view
;
8456 bool zap_next
= false;
8457 for (size_t i
= 0; i
< reloc_count
; ++i
, prelocs
+= reloc_size
)
8459 Relocatable_relocs::Reloc_strategy strategy
= relinfo
->rr
->strategy(i
);
8460 if (strategy
== Relocatable_relocs::RELOC_DISCARD
)
8463 Reltype
reloc(prelocs
);
8464 Reltype_write
reloc_write(pwrite
);
8466 Address offset
= reloc
.get_r_offset();
8467 typename
elfcpp::Elf_types
<size
>::Elf_WXword r_info
= reloc
.get_r_info();
8468 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(r_info
);
8469 unsigned int r_type
= elfcpp::elf_r_type
<size
>(r_info
);
8470 const unsigned int orig_r_sym
= r_sym
;
8471 typename
elfcpp::Elf_types
<size
>::Elf_Swxword addend
8472 = reloc
.get_r_addend();
8473 const Symbol
* gsym
= NULL
;
8477 // We could arrange to discard these and other relocs for
8478 // tls optimised sequences in the strategy methods, but for
8479 // now do as BFD ld does.
8480 r_type
= elfcpp::R_POWERPC_NONE
;
8484 // Get the new symbol index.
8485 Output_section
* os
= NULL
;
8486 if (r_sym
< local_count
)
8490 case Relocatable_relocs::RELOC_COPY
:
8491 case Relocatable_relocs::RELOC_SPECIAL
:
8494 r_sym
= object
->symtab_index(r_sym
);
8495 gold_assert(r_sym
!= -1U);
8499 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
:
8501 // We are adjusting a section symbol. We need to find
8502 // the symbol table index of the section symbol for
8503 // the output section corresponding to input section
8504 // in which this symbol is defined.
8505 gold_assert(r_sym
< local_count
);
8507 unsigned int shndx
=
8508 object
->local_symbol_input_shndx(r_sym
, &is_ordinary
);
8509 gold_assert(is_ordinary
);
8510 os
= object
->output_section(shndx
);
8511 gold_assert(os
!= NULL
);
8512 gold_assert(os
->needs_symtab_index());
8513 r_sym
= os
->symtab_index();
8523 gsym
= object
->global_symbol(r_sym
);
8524 gold_assert(gsym
!= NULL
);
8525 if (gsym
->is_forwarder())
8526 gsym
= relinfo
->symtab
->resolve_forwards(gsym
);
8528 gold_assert(gsym
->has_symtab_index());
8529 r_sym
= gsym
->symtab_index();
8532 // Get the new offset--the location in the output section where
8533 // this relocation should be applied.
8534 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8535 offset
+= offset_in_output_section
;
8538 section_offset_type sot_offset
=
8539 convert_types
<section_offset_type
, Address
>(offset
);
8540 section_offset_type new_sot_offset
=
8541 output_section
->output_offset(object
, relinfo
->data_shndx
,
8543 gold_assert(new_sot_offset
!= -1);
8544 offset
= new_sot_offset
;
8547 // In an object file, r_offset is an offset within the section.
8548 // In an executable or dynamic object, generated by
8549 // --emit-relocs, r_offset is an absolute address.
8550 if (!parameters
->options().relocatable())
8552 offset
+= view_address
;
8553 if (static_cast<Address
>(offset_in_output_section
) != invalid_address
)
8554 offset
-= offset_in_output_section
;
8557 // Handle the reloc addend based on the strategy.
8558 if (strategy
== Relocatable_relocs::RELOC_COPY
)
8560 else if (strategy
== Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA
)
8562 const Symbol_value
<size
>* psymval
= object
->local_symbol(orig_r_sym
);
8563 gold_assert(os
!= NULL
);
8564 addend
= psymval
->value(object
, addend
) - os
->address();
8566 else if (strategy
== Relocatable_relocs::RELOC_SPECIAL
)
8570 if (addend
>= 32768)
8571 addend
+= got2_addend
;
8573 else if (r_type
== elfcpp::R_POWERPC_REL16_HA
)
8575 r_type
= elfcpp::R_POWERPC_ADDR16_HA
;
8578 else if (r_type
== elfcpp::R_POWERPC_REL16_LO
)
8580 r_type
= elfcpp::R_POWERPC_ADDR16_LO
;
8581 addend
-= d_offset
+ 4;
8587 if (!parameters
->options().relocatable())
8589 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8590 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
8591 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HI
8592 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_HA
)
8594 // First instruction of a global dynamic sequence,
8596 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8597 switch (this->optimize_tls_gd(final
))
8599 case tls::TLSOPT_TO_IE
:
8600 r_type
+= (elfcpp::R_POWERPC_GOT_TPREL16
8601 - elfcpp::R_POWERPC_GOT_TLSGD16
);
8603 case tls::TLSOPT_TO_LE
:
8604 if (r_type
== elfcpp::R_POWERPC_GOT_TLSGD16
8605 || r_type
== elfcpp::R_POWERPC_GOT_TLSGD16_LO
)
8606 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8609 r_type
= elfcpp::R_POWERPC_NONE
;
8617 else if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8618 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
8619 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HI
8620 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_HA
)
8622 // First instruction of a local dynamic sequence,
8624 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8626 if (r_type
== elfcpp::R_POWERPC_GOT_TLSLD16
8627 || r_type
== elfcpp::R_POWERPC_GOT_TLSLD16_LO
)
8629 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8630 const Output_section
* os
= relinfo
->layout
->tls_segment()
8632 gold_assert(os
!= NULL
);
8633 gold_assert(os
->needs_symtab_index());
8634 r_sym
= os
->symtab_index();
8635 addend
= dtp_offset
;
8639 r_type
= elfcpp::R_POWERPC_NONE
;
8644 else if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8645 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
8646 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HI
8647 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_HA
)
8649 // First instruction of initial exec sequence.
8650 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8651 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8653 if (r_type
== elfcpp::R_POWERPC_GOT_TPREL16
8654 || r_type
== elfcpp::R_POWERPC_GOT_TPREL16_LO
)
8655 r_type
= elfcpp::R_POWERPC_TPREL16_HA
;
8658 r_type
= elfcpp::R_POWERPC_NONE
;
8663 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSGD
)
8664 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSGD
))
8666 // Second instruction of a global dynamic sequence,
8667 // the __tls_get_addr call
8668 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8669 switch (this->optimize_tls_gd(final
))
8671 case tls::TLSOPT_TO_IE
:
8672 r_type
= elfcpp::R_POWERPC_NONE
;
8675 case tls::TLSOPT_TO_LE
:
8676 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8684 else if ((size
== 64 && r_type
== elfcpp::R_PPC64_TLSLD
)
8685 || (size
== 32 && r_type
== elfcpp::R_PPC_TLSLD
))
8687 // Second instruction of a local dynamic sequence,
8688 // the __tls_get_addr call
8689 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE
)
8691 const Output_section
* os
= relinfo
->layout
->tls_segment()
8693 gold_assert(os
!= NULL
);
8694 gold_assert(os
->needs_symtab_index());
8695 r_sym
= os
->symtab_index();
8696 addend
= dtp_offset
;
8697 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8702 else if (r_type
== elfcpp::R_POWERPC_TLS
)
8704 // Second instruction of an initial exec sequence
8705 const bool final
= gsym
== NULL
|| gsym
->final_value_is_known();
8706 if (this->optimize_tls_ie(final
) == tls::TLSOPT_TO_LE
)
8708 r_type
= elfcpp::R_POWERPC_TPREL16_LO
;
8714 reloc_write
.put_r_offset(offset
);
8715 reloc_write
.put_r_info(elfcpp::elf_r_info
<size
>(r_sym
, r_type
));
8716 reloc_write
.put_r_addend(addend
);
8718 pwrite
+= reloc_size
;
8721 gold_assert(static_cast<section_size_type
>(pwrite
- reloc_view
)
8722 == reloc_view_size
);
8725 // Return the value to use for a dynamic symbol which requires special
8726 // treatment. This is how we support equality comparisons of function
8727 // pointers across shared library boundaries, as described in the
8728 // processor specific ABI supplement.
8730 template<int size
, bool big_endian
>
8732 Target_powerpc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
8736 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
8737 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8738 p
!= this->stub_tables_
.end();
8741 Address off
= (*p
)->find_plt_call_entry(gsym
);
8742 if (off
!= invalid_address
)
8743 return (*p
)->stub_address() + off
;
8746 else if (this->abiversion() >= 2)
8748 Address off
= this->glink_section()->find_global_entry(gsym
);
8749 if (off
!= invalid_address
)
8750 return this->glink_section()->global_entry_address() + off
;
8755 // Return the PLT address to use for a local symbol.
8756 template<int size
, bool big_endian
>
8758 Target_powerpc
<size
, big_endian
>::do_plt_address_for_local(
8759 const Relobj
* object
,
8760 unsigned int symndx
) const
8764 const Sized_relobj
<size
, big_endian
>* relobj
8765 = static_cast<const Sized_relobj
<size
, big_endian
>*>(object
);
8766 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8767 p
!= this->stub_tables_
.end();
8770 Address off
= (*p
)->find_plt_call_entry(relobj
->sized_relobj(),
8772 if (off
!= invalid_address
)
8773 return (*p
)->stub_address() + off
;
8779 // Return the PLT address to use for a global symbol.
8780 template<int size
, bool big_endian
>
8782 Target_powerpc
<size
, big_endian
>::do_plt_address_for_global(
8783 const Symbol
* gsym
) const
8787 for (typename
Stub_tables::const_iterator p
= this->stub_tables_
.begin();
8788 p
!= this->stub_tables_
.end();
8791 Address off
= (*p
)->find_plt_call_entry(gsym
);
8792 if (off
!= invalid_address
)
8793 return (*p
)->stub_address() + off
;
8796 else if (this->abiversion() >= 2)
8798 Address off
= this->glink_section()->find_global_entry(gsym
);
8799 if (off
!= invalid_address
)
8800 return this->glink_section()->global_entry_address() + off
;
8805 // Return the offset to use for the GOT_INDX'th got entry which is
8806 // for a local tls symbol specified by OBJECT, SYMNDX.
8807 template<int size
, bool big_endian
>
8809 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_local(
8810 const Relobj
* object
,
8811 unsigned int symndx
,
8812 unsigned int got_indx
) const
8814 const Powerpc_relobj
<size
, big_endian
>* ppc_object
8815 = static_cast<const Powerpc_relobj
<size
, big_endian
>*>(object
);
8816 if (ppc_object
->local_symbol(symndx
)->is_tls_symbol())
8818 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8819 got_type
<= GOT_TYPE_TPREL
;
8820 got_type
= Got_type(got_type
+ 1))
8821 if (ppc_object
->local_has_got_offset(symndx
, got_type
))
8823 unsigned int off
= ppc_object
->local_got_offset(symndx
, got_type
);
8824 if (got_type
== GOT_TYPE_TLSGD
)
8826 if (off
== got_indx
* (size
/ 8))
8828 if (got_type
== GOT_TYPE_TPREL
)
8838 // Return the offset to use for the GOT_INDX'th got entry which is
8839 // for global tls symbol GSYM.
8840 template<int size
, bool big_endian
>
8842 Target_powerpc
<size
, big_endian
>::do_tls_offset_for_global(
8844 unsigned int got_indx
) const
8846 if (gsym
->type() == elfcpp::STT_TLS
)
8848 for (Got_type got_type
= GOT_TYPE_TLSGD
;
8849 got_type
<= GOT_TYPE_TPREL
;
8850 got_type
= Got_type(got_type
+ 1))
8851 if (gsym
->has_got_offset(got_type
))
8853 unsigned int off
= gsym
->got_offset(got_type
);
8854 if (got_type
== GOT_TYPE_TLSGD
)
8856 if (off
== got_indx
* (size
/ 8))
8858 if (got_type
== GOT_TYPE_TPREL
)
8868 // The selector for powerpc object files.
8870 template<int size
, bool big_endian
>
8871 class Target_selector_powerpc
: public Target_selector
8874 Target_selector_powerpc()
8875 : Target_selector(size
== 64 ? elfcpp::EM_PPC64
: elfcpp::EM_PPC
,
8878 ? (big_endian
? "elf64-powerpc" : "elf64-powerpcle")
8879 : (big_endian
? "elf32-powerpc" : "elf32-powerpcle")),
8881 ? (big_endian
? "elf64ppc" : "elf64lppc")
8882 : (big_endian
? "elf32ppc" : "elf32lppc")))
8886 do_instantiate_target()
8887 { return new Target_powerpc
<size
, big_endian
>(); }
8890 Target_selector_powerpc
<32, true> target_selector_ppc32
;
8891 Target_selector_powerpc
<32, false> target_selector_ppc32le
;
8892 Target_selector_powerpc
<64, true> target_selector_ppc64
;
8893 Target_selector_powerpc
<64, false> target_selector_ppc64le
;
8895 // Instantiate these constants for -O0
8896 template<int size
, bool big_endian
>
8897 const int Output_data_glink
<size
, big_endian
>::pltresolve_size
;
8898 template<int size
, bool big_endian
>
8899 const typename Output_data_glink
<size
, big_endian
>::Address
8900 Output_data_glink
<size
, big_endian
>::invalid_address
;
8901 template<int size
, bool big_endian
>
8902 const typename Stub_table
<size
, big_endian
>::Address
8903 Stub_table
<size
, big_endian
>::invalid_address
;
8904 template<int size
, bool big_endian
>
8905 const typename Target_powerpc
<size
, big_endian
>::Address
8906 Target_powerpc
<size
, big_endian
>::invalid_address
;
8908 } // End anonymous namespace.