1 // powerpc.cc -- powerpc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>
5 // and David Edelsohn <edelsohn@gnu.org>
7 // This file is part of gold.
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size, bool big_endian>
51 class Output_data_plt_powerpc;
53 template<int size, bool big_endian>
54 class Output_data_brlt_powerpc;
56 template<int size, bool big_endian>
57 class Output_data_got_powerpc;
59 template<int size, bool big_endian>
60 class Output_data_glink;
62 template<int size, bool big_endian>
66 is_branch_reloc(unsigned int r_type);
68 template<int size, bool big_endian>
69 class Powerpc_relobj : public Sized_relobj_file<size, big_endian>
72 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
73 typedef Unordered_set<Section_id, Section_id_hash> Section_refs;
74 typedef Unordered_map<Address, Section_refs> Access_from;
76 Powerpc_relobj(const std::string& name, Input_file* input_file, off_t offset,
77 const typename elfcpp::Ehdr<size, big_endian>& ehdr)
78 : Sized_relobj_file<size, big_endian>(name, input_file, offset, ehdr),
79 special_(0), has_small_toc_reloc_(false), opd_valid_(false),
80 opd_ent_(), access_from_map_(), has14_(), stub_table_(),
81 e_flags_(ehdr.get_e_flags()), st_other_()
83 this->set_abiversion(0);
89 // Read the symbols then set up st_other vector.
91 do_read_symbols(Read_symbols_data*);
93 // The .got2 section shndx.
98 return this->special_;
103 // The .opd section shndx.
110 return this->special_;
113 // Init OPD entry arrays.
115 init_opd(size_t opd_size)
117 size_t count = this->opd_ent_ndx(opd_size);
118 this->opd_ent_.resize(count);
121 // Return section and offset of function entry for .opd + R_OFF.
123 get_opd_ent(Address r_off, Address* value = NULL) const
125 size_t ndx = this->opd_ent_ndx(r_off);
126 gold_assert(ndx < this->opd_ent_.size());
127 gold_assert(this->opd_ent_[ndx].shndx != 0);
129 *value = this->opd_ent_[ndx].off;
130 return this->opd_ent_[ndx].shndx;
133 // Set section and offset of function entry for .opd + R_OFF.
135 set_opd_ent(Address r_off, unsigned int shndx, Address value)
137 size_t ndx = this->opd_ent_ndx(r_off);
138 gold_assert(ndx < this->opd_ent_.size());
139 this->opd_ent_[ndx].shndx = shndx;
140 this->opd_ent_[ndx].off = value;
143 // Return discard flag for .opd + R_OFF.
145 get_opd_discard(Address r_off) const
147 size_t ndx = this->opd_ent_ndx(r_off);
148 gold_assert(ndx < this->opd_ent_.size());
149 return this->opd_ent_[ndx].discard;
152 // Set discard flag for .opd + R_OFF.
154 set_opd_discard(Address r_off)
156 size_t ndx = this->opd_ent_ndx(r_off);
157 gold_assert(ndx < this->opd_ent_.size());
158 this->opd_ent_[ndx].discard = true;
163 { return this->opd_valid_; }
167 { this->opd_valid_ = true; }
169 // Examine .rela.opd to build info about function entry points.
171 scan_opd_relocs(size_t reloc_count,
172 const unsigned char* prelocs,
173 const unsigned char* plocal_syms);
175 // Perform the Sized_relobj_file method, then set up opd info from
178 do_read_relocs(Read_relocs_data*);
181 do_find_special_sections(Read_symbols_data* sd);
183 // Adjust this local symbol value. Return false if the symbol
184 // should be discarded from the output file.
186 do_adjust_local_symbol(Symbol_value<size>* lv) const
188 if (size == 64 && this->opd_shndx() != 0)
191 if (lv->input_shndx(&is_ordinary) != this->opd_shndx())
193 if (this->get_opd_discard(lv->input_value()))
201 { return &this->access_from_map_; }
203 // Add a reference from SRC_OBJ, SRC_INDX to this object's .opd
204 // section at DST_OFF.
206 add_reference(Object* src_obj,
207 unsigned int src_indx,
208 typename elfcpp::Elf_types<size>::Elf_Addr dst_off)
210 Section_id src_id(src_obj, src_indx);
211 this->access_from_map_[dst_off].insert(src_id);
214 // Add a reference to the code section specified by the .opd entry
217 add_gc_mark(typename elfcpp::Elf_types<size>::Elf_Addr dst_off)
219 size_t ndx = this->opd_ent_ndx(dst_off);
220 if (ndx >= this->opd_ent_.size())
221 this->opd_ent_.resize(ndx + 1);
222 this->opd_ent_[ndx].gc_mark = true;
226 process_gc_mark(Symbol_table* symtab)
228 for (size_t i = 0; i < this->opd_ent_.size(); i++)
229 if (this->opd_ent_[i].gc_mark)
231 unsigned int shndx = this->opd_ent_[i].shndx;
232 symtab->gc()->worklist().push(Section_id(this, shndx));
236 // Return offset in output GOT section that this object will use
237 // as a TOC pointer. Won't be just a constant with multi-toc support.
239 toc_base_offset() const
243 set_has_small_toc_reloc()
244 { has_small_toc_reloc_ = true; }
247 has_small_toc_reloc() const
248 { return has_small_toc_reloc_; }
251 set_has_14bit_branch(unsigned int shndx)
253 if (shndx >= this->has14_.size())
254 this->has14_.resize(shndx + 1);
255 this->has14_[shndx] = true;
259 has_14bit_branch(unsigned int shndx) const
260 { return shndx < this->has14_.size() && this->has14_[shndx]; }
263 set_stub_table(unsigned int shndx, Stub_table<size, big_endian>* stub_table)
265 if (shndx >= this->stub_table_.size())
266 this->stub_table_.resize(shndx + 1);
267 this->stub_table_[shndx] = stub_table;
270 Stub_table<size, big_endian>*
271 stub_table(unsigned int shndx)
273 if (shndx < this->stub_table_.size())
274 return this->stub_table_[shndx];
280 { return this->e_flags_ & elfcpp::EF_PPC64_ABI; }
282 // Set ABI version for input and output
284 set_abiversion(int ver);
287 ppc64_local_entry_offset(const Symbol* sym) const
288 { return elfcpp::ppc64_decode_local_entry(sym->nonvis() >> 3); }
291 ppc64_local_entry_offset(unsigned int symndx) const
292 { return elfcpp::ppc64_decode_local_entry(this->st_other_[symndx] >> 5); }
303 // Return index into opd_ent_ array for .opd entry at OFF.
304 // .opd entries are 24 bytes long, but they can be spaced 16 bytes
305 // apart when the language doesn't use the last 8-byte word, the
306 // environment pointer. Thus dividing the entry section offset by
307 // 16 will give an index into opd_ent_ that works for either layout
308 // of .opd. (It leaves some elements of the vector unused when .opd
309 // entries are spaced 24 bytes apart, but we don't know the spacing
310 // until relocations are processed, and in any case it is possible
311 // for an object to have some entries spaced 16 bytes apart and
312 // others 24 bytes apart.)
314 opd_ent_ndx(size_t off) const
317 // For 32-bit the .got2 section shdnx, for 64-bit the .opd section shndx.
318 unsigned int special_;
320 // For 64-bit, whether this object uses small model relocs to access
322 bool has_small_toc_reloc_;
324 // Set at the start of gc_process_relocs, when we know opd_ent_
325 // vector is valid. The flag could be made atomic and set in
326 // do_read_relocs with memory_order_release and then tested with
327 // memory_order_acquire, potentially resulting in fewer entries in
331 // The first 8-byte word of an OPD entry gives the address of the
332 // entry point of the function. Relocatable object files have a
333 // relocation on this word. The following vector records the
334 // section and offset specified by these relocations.
335 std::vector<Opd_ent> opd_ent_;
337 // References made to this object's .opd section when running
338 // gc_process_relocs for another object, before the opd_ent_ vector
339 // is valid for this object.
340 Access_from access_from_map_;
342 // Whether input section has a 14-bit branch reloc.
343 std::vector<bool> has14_;
345 // The stub table to use for a given input section.
346 std::vector<Stub_table<size, big_endian>*> stub_table_;
349 elfcpp::Elf_Word e_flags_;
351 // ELF st_other field for local symbols.
352 std::vector<unsigned char> st_other_;
355 template<int size, bool big_endian>
356 class Powerpc_dynobj : public Sized_dynobj<size, big_endian>
359 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
361 Powerpc_dynobj(const std::string& name, Input_file* input_file, off_t offset,
362 const typename elfcpp::Ehdr<size, big_endian>& ehdr)
363 : Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr),
364 opd_shndx_(0), opd_ent_(), e_flags_(ehdr.get_e_flags())
366 this->set_abiversion(0);
372 // Call Sized_dynobj::do_read_symbols to read the symbols then
373 // read .opd from a dynamic object, filling in opd_ent_ vector,
375 do_read_symbols(Read_symbols_data*);
377 // The .opd section shndx.
381 return this->opd_shndx_;
384 // The .opd section address.
388 return this->opd_address_;
391 // Init OPD entry arrays.
393 init_opd(size_t opd_size)
395 size_t count = this->opd_ent_ndx(opd_size);
396 this->opd_ent_.resize(count);
399 // Return section and offset of function entry for .opd + R_OFF.
401 get_opd_ent(Address r_off, Address* value = NULL) const
403 size_t ndx = this->opd_ent_ndx(r_off);
404 gold_assert(ndx < this->opd_ent_.size());
405 gold_assert(this->opd_ent_[ndx].shndx != 0);
407 *value = this->opd_ent_[ndx].off;
408 return this->opd_ent_[ndx].shndx;
411 // Set section and offset of function entry for .opd + R_OFF.
413 set_opd_ent(Address r_off, unsigned int shndx, Address value)
415 size_t ndx = this->opd_ent_ndx(r_off);
416 gold_assert(ndx < this->opd_ent_.size());
417 this->opd_ent_[ndx].shndx = shndx;
418 this->opd_ent_[ndx].off = value;
423 { return this->e_flags_ & elfcpp::EF_PPC64_ABI; }
425 // Set ABI version for input and output.
427 set_abiversion(int ver);
430 // Used to specify extent of executable sections.
433 Sec_info(Address start_, Address len_, unsigned int shndx_)
434 : start(start_), len(len_), shndx(shndx_)
438 operator<(const Sec_info& that) const
439 { return this->start < that.start; }
452 // Return index into opd_ent_ array for .opd entry at OFF.
454 opd_ent_ndx(size_t off) const
457 // For 64-bit the .opd section shndx and address.
458 unsigned int opd_shndx_;
459 Address opd_address_;
461 // The first 8-byte word of an OPD entry gives the address of the
462 // entry point of the function. Records the section and offset
463 // corresponding to the address. Note that in dynamic objects,
464 // offset is *not* relative to the section.
465 std::vector<Opd_ent> opd_ent_;
468 elfcpp::Elf_Word e_flags_;
471 template<int size, bool big_endian>
472 class Target_powerpc : public Sized_target<size, big_endian>
476 Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
477 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
478 typedef typename elfcpp::Elf_types<size>::Elf_Swxword Signed_address;
479 static const Address invalid_address = static_cast<Address>(0) - 1;
480 // Offset of tp and dtp pointers from start of TLS block.
481 static const Address tp_offset = 0x7000;
482 static const Address dtp_offset = 0x8000;
485 : Sized_target<size, big_endian>(&powerpc_info),
486 got_(NULL), plt_(NULL), iplt_(NULL), brlt_section_(NULL),
487 glink_(NULL), rela_dyn_(NULL), copy_relocs_(elfcpp::R_POWERPC_COPY),
488 tlsld_got_offset_(-1U),
489 stub_tables_(), branch_lookup_table_(), branch_info_(),
490 plt_thread_safe_(false)
494 // Process the relocations to determine unreferenced sections for
495 // garbage collection.
497 gc_process_relocs(Symbol_table* symtab,
499 Sized_relobj_file<size, big_endian>* object,
500 unsigned int data_shndx,
501 unsigned int sh_type,
502 const unsigned char* prelocs,
504 Output_section* output_section,
505 bool needs_special_offset_handling,
506 size_t local_symbol_count,
507 const unsigned char* plocal_symbols);
509 // Scan the relocations to look for symbol adjustments.
511 scan_relocs(Symbol_table* symtab,
513 Sized_relobj_file<size, big_endian>* object,
514 unsigned int data_shndx,
515 unsigned int sh_type,
516 const unsigned char* prelocs,
518 Output_section* output_section,
519 bool needs_special_offset_handling,
520 size_t local_symbol_count,
521 const unsigned char* plocal_symbols);
523 // Map input .toc section to output .got section.
525 do_output_section_name(const Relobj*, const char* name, size_t* plen) const
527 if (size == 64 && strcmp(name, ".toc") == 0)
535 // Provide linker defined save/restore functions.
537 define_save_restore_funcs(Layout*, Symbol_table*);
539 // No stubs unless a final link.
542 { return !parameters->options().relocatable(); }
545 do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*);
548 do_plt_fde_location(const Output_data*, unsigned char*,
549 uint64_t*, off_t*) const;
551 // Stash info about branches, for stub generation.
553 push_branch(Powerpc_relobj<size, big_endian>* ppc_object,
554 unsigned int data_shndx, Address r_offset,
555 unsigned int r_type, unsigned int r_sym, Address addend)
557 Branch_info info(ppc_object, data_shndx, r_offset, r_type, r_sym, addend);
558 this->branch_info_.push_back(info);
559 if (r_type == elfcpp::R_POWERPC_REL14
560 || r_type == elfcpp::R_POWERPC_REL14_BRTAKEN
561 || r_type == elfcpp::R_POWERPC_REL14_BRNTAKEN)
562 ppc_object->set_has_14bit_branch(data_shndx);
565 Stub_table<size, big_endian>*
569 do_define_standard_symbols(Symbol_table*, Layout*);
571 // Finalize the sections.
573 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
575 // Return the value to use for a dynamic which requires special
578 do_dynsym_value(const Symbol*) const;
580 // Return the PLT address to use for a local symbol.
582 do_plt_address_for_local(const Relobj*, unsigned int) const;
584 // Return the PLT address to use for a global symbol.
586 do_plt_address_for_global(const Symbol*) const;
588 // Return the offset to use for the GOT_INDX'th got entry which is
589 // for a local tls symbol specified by OBJECT, SYMNDX.
591 do_tls_offset_for_local(const Relobj* object,
593 unsigned int got_indx) const;
595 // Return the offset to use for the GOT_INDX'th got entry which is
596 // for global tls symbol GSYM.
598 do_tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const;
601 do_function_location(Symbol_location*) const;
604 do_can_check_for_function_pointers() const
607 // Relocate a section.
609 relocate_section(const Relocate_info<size, big_endian>*,
610 unsigned int sh_type,
611 const unsigned char* prelocs,
613 Output_section* output_section,
614 bool needs_special_offset_handling,
616 Address view_address,
617 section_size_type view_size,
618 const Reloc_symbol_changes*);
620 // Scan the relocs during a relocatable link.
622 scan_relocatable_relocs(Symbol_table* symtab,
624 Sized_relobj_file<size, big_endian>* object,
625 unsigned int data_shndx,
626 unsigned int sh_type,
627 const unsigned char* prelocs,
629 Output_section* output_section,
630 bool needs_special_offset_handling,
631 size_t local_symbol_count,
632 const unsigned char* plocal_symbols,
633 Relocatable_relocs*);
635 // Emit relocations for a section.
637 relocate_relocs(const Relocate_info<size, big_endian>*,
638 unsigned int sh_type,
639 const unsigned char* prelocs,
641 Output_section* output_section,
642 typename elfcpp::Elf_types<size>::Elf_Off
643 offset_in_output_section,
644 const Relocatable_relocs*,
646 Address view_address,
648 unsigned char* reloc_view,
649 section_size_type reloc_view_size);
651 // Return whether SYM is defined by the ABI.
653 do_is_defined_by_abi(const Symbol* sym) const
655 return strcmp(sym->name(), "__tls_get_addr") == 0;
658 // Return the size of the GOT section.
662 gold_assert(this->got_ != NULL);
663 return this->got_->data_size();
666 // Get the PLT section.
667 const Output_data_plt_powerpc<size, big_endian>*
670 gold_assert(this->plt_ != NULL);
674 // Get the IPLT section.
675 const Output_data_plt_powerpc<size, big_endian>*
678 gold_assert(this->iplt_ != NULL);
682 // Get the .glink section.
683 const Output_data_glink<size, big_endian>*
684 glink_section() const
686 gold_assert(this->glink_ != NULL);
690 bool has_glink() const
691 { return this->glink_ != NULL; }
693 // Get the GOT section.
694 const Output_data_got_powerpc<size, big_endian>*
697 gold_assert(this->got_ != NULL);
701 // Get the GOT section, creating it if necessary.
702 Output_data_got_powerpc<size, big_endian>*
703 got_section(Symbol_table*, Layout*);
706 do_make_elf_object(const std::string&, Input_file*, off_t,
707 const elfcpp::Ehdr<size, big_endian>&);
709 // Return the number of entries in the GOT.
711 got_entry_count() const
713 if (this->got_ == NULL)
715 return this->got_size() / (size / 8);
718 // Return the number of entries in the PLT.
720 plt_entry_count() const;
722 // Return the offset of the first non-reserved PLT entry.
724 first_plt_entry_offset() const
728 if (this->abiversion() >= 2)
733 // Return the size of each PLT entry.
735 plt_entry_size() const
739 if (this->abiversion() >= 2)
744 // Add any special sections for this symbol to the gc work list.
745 // For powerpc64, this adds the code section of a function
748 do_gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const;
750 // Handle target specific gc actions when adding a gc reference from
751 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
752 // and DST_OFF. For powerpc64, this adds a referenc to the code
753 // section of a function descriptor.
755 do_gc_add_reference(Symbol_table* symtab,
757 unsigned int src_shndx,
759 unsigned int dst_shndx,
760 Address dst_off) const;
762 typedef std::vector<Stub_table<size, big_endian>*> Stub_tables;
765 { return this->stub_tables_; }
767 const Output_data_brlt_powerpc<size, big_endian>*
769 { return this->brlt_section_; }
772 add_branch_lookup_table(Address to)
774 unsigned int off = this->branch_lookup_table_.size() * (size / 8);
775 this->branch_lookup_table_.insert(std::make_pair(to, off));
779 find_branch_lookup_table(Address to)
781 typename Branch_lookup_table::const_iterator p
782 = this->branch_lookup_table_.find(to);
783 return p == this->branch_lookup_table_.end() ? invalid_address : p->second;
787 write_branch_lookup_table(unsigned char *oview)
789 for (typename Branch_lookup_table::const_iterator p
790 = this->branch_lookup_table_.begin();
791 p != this->branch_lookup_table_.end();
794 elfcpp::Swap<size, big_endian>::writeval(oview + p->second, p->first);
799 plt_thread_safe() const
800 { return this->plt_thread_safe_; }
804 { return this->processor_specific_flags() & elfcpp::EF_PPC64_ABI; }
807 set_abiversion (int ver)
809 elfcpp::Elf_Word flags = this->processor_specific_flags();
810 flags &= ~elfcpp::EF_PPC64_ABI;
811 flags |= ver & elfcpp::EF_PPC64_ABI;
812 this->set_processor_specific_flags(flags);
815 // Offset to to save stack slot
818 { return this->abiversion() < 2 ? 40 : 24; }
834 : tls_get_addr_(NOT_EXPECTED),
835 relinfo_(NULL), relnum_(0), r_offset_(0)
840 if (this->tls_get_addr_ != NOT_EXPECTED)
847 if (this->relinfo_ != NULL)
848 gold_error_at_location(this->relinfo_, this->relnum_, this->r_offset_,
849 _("missing expected __tls_get_addr call"));
853 expect_tls_get_addr_call(
854 const Relocate_info<size, big_endian>* relinfo,
858 this->tls_get_addr_ = EXPECTED;
859 this->relinfo_ = relinfo;
860 this->relnum_ = relnum;
861 this->r_offset_ = r_offset;
865 expect_tls_get_addr_call()
866 { this->tls_get_addr_ = EXPECTED; }
869 skip_next_tls_get_addr_call()
870 {this->tls_get_addr_ = SKIP; }
873 maybe_skip_tls_get_addr_call(unsigned int r_type, const Symbol* gsym)
875 bool is_tls_call = ((r_type == elfcpp::R_POWERPC_REL24
876 || r_type == elfcpp::R_PPC_PLTREL24)
878 && strcmp(gsym->name(), "__tls_get_addr") == 0);
879 Tls_get_addr last_tls = this->tls_get_addr_;
880 this->tls_get_addr_ = NOT_EXPECTED;
881 if (is_tls_call && last_tls != EXPECTED)
883 else if (!is_tls_call && last_tls != NOT_EXPECTED)
892 // What we're up to regarding calls to __tls_get_addr.
893 // On powerpc, the branch and link insn making a call to
894 // __tls_get_addr is marked with a relocation, R_PPC64_TLSGD,
895 // R_PPC64_TLSLD, R_PPC_TLSGD or R_PPC_TLSLD, in addition to the
896 // usual R_POWERPC_REL24 or R_PPC_PLTREL25 relocation on a call.
897 // The marker relocation always comes first, and has the same
898 // symbol as the reloc on the insn setting up the __tls_get_addr
899 // argument. This ties the arg setup insn with the call insn,
900 // allowing ld to safely optimize away the call. We check that
901 // every call to __tls_get_addr has a marker relocation, and that
902 // every marker relocation is on a call to __tls_get_addr.
903 Tls_get_addr tls_get_addr_;
904 // Info about the last reloc for error message.
905 const Relocate_info<size, big_endian>* relinfo_;
910 // The class which scans relocations.
911 class Scan : protected Track_tls
914 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
917 : Track_tls(), issued_non_pic_error_(false)
921 get_reference_flags(unsigned int r_type);
924 local(Symbol_table* symtab, Layout* layout, Target_powerpc* target,
925 Sized_relobj_file<size, big_endian>* object,
926 unsigned int data_shndx,
927 Output_section* output_section,
928 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
929 const elfcpp::Sym<size, big_endian>& lsym,
933 global(Symbol_table* symtab, Layout* layout, Target_powerpc* target,
934 Sized_relobj_file<size, big_endian>* object,
935 unsigned int data_shndx,
936 Output_section* output_section,
937 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
941 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
943 Sized_relobj_file<size, big_endian>* ,
946 const elfcpp::Rela<size, big_endian>& ,
948 const elfcpp::Sym<size, big_endian>&)
950 // PowerPC64 .opd is not folded, so any identical function text
951 // may be folded and we'll still keep function addresses distinct.
952 // That means no reloc is of concern here.
955 // For 32-bit, conservatively assume anything but calls to
956 // function code might be taking the address of the function.
957 return !is_branch_reloc(r_type);
961 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
963 Sized_relobj_file<size, big_endian>* ,
966 const elfcpp::Rela<size, big_endian>& ,
973 return !is_branch_reloc(r_type);
977 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>* object,
978 unsigned int r_type, bool report_err);
982 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
983 unsigned int r_type);
986 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
987 unsigned int r_type, Symbol*);
990 generate_tls_call(Symbol_table* symtab, Layout* layout,
991 Target_powerpc* target);
994 check_non_pic(Relobj*, unsigned int r_type);
996 // Whether we have issued an error about a non-PIC compilation.
997 bool issued_non_pic_error_;
1001 symval_for_branch(const Symbol_table* symtab, Address value,
1002 const Sized_symbol<size>* gsym,
1003 Powerpc_relobj<size, big_endian>* object,
1004 unsigned int *dest_shndx);
1006 // The class which implements relocation.
1007 class Relocate : protected Track_tls
1010 // Use 'at' branch hints when true, 'y' when false.
1011 // FIXME maybe: set this with an option.
1012 static const bool is_isa_v2 = true;
1018 // Do a relocation. Return false if the caller should not issue
1019 // any warnings about this relocation.
1021 relocate(const Relocate_info<size, big_endian>*, Target_powerpc*,
1022 Output_section*, size_t relnum,
1023 const elfcpp::Rela<size, big_endian>&,
1024 unsigned int r_type, const Sized_symbol<size>*,
1025 const Symbol_value<size>*,
1027 typename elfcpp::Elf_types<size>::Elf_Addr,
1031 class Relocate_comdat_behavior
1034 // Decide what the linker should do for relocations that refer to
1035 // discarded comdat sections.
1036 inline Comdat_behavior
1037 get(const char* name)
1039 gold::Default_comdat_behavior default_behavior;
1040 Comdat_behavior ret = default_behavior.get(name);
1041 if (ret == CB_WARNING)
1044 && (strcmp(name, ".fixup") == 0
1045 || strcmp(name, ".got2") == 0))
1048 && (strcmp(name, ".opd") == 0
1049 || strcmp(name, ".toc") == 0
1050 || strcmp(name, ".toc1") == 0))
1057 // A class which returns the size required for a relocation type,
1058 // used while scanning relocs during a relocatable link.
1059 class Relocatable_size_for_reloc
1063 get_size_for_reloc(unsigned int, Relobj*)
1070 // Optimize the TLS relocation type based on what we know about the
1071 // symbol. IS_FINAL is true if the final address of this symbol is
1072 // known at link time.
1074 tls::Tls_optimization
1075 optimize_tls_gd(bool is_final)
1077 // If we are generating a shared library, then we can't do anything
1079 if (parameters->options().shared())
1080 return tls::TLSOPT_NONE;
1083 return tls::TLSOPT_TO_IE;
1084 return tls::TLSOPT_TO_LE;
1087 tls::Tls_optimization
1090 if (parameters->options().shared())
1091 return tls::TLSOPT_NONE;
1093 return tls::TLSOPT_TO_LE;
1096 tls::Tls_optimization
1097 optimize_tls_ie(bool is_final)
1099 if (!is_final || parameters->options().shared())
1100 return tls::TLSOPT_NONE;
1102 return tls::TLSOPT_TO_LE;
1107 make_glink_section(Layout*);
1109 // Create the PLT section.
1111 make_plt_section(Symbol_table*, Layout*);
1114 make_iplt_section(Symbol_table*, Layout*);
1117 make_brlt_section(Layout*);
1119 // Create a PLT entry for a global symbol.
1121 make_plt_entry(Symbol_table*, Layout*, Symbol*);
1123 // Create a PLT entry for a local IFUNC symbol.
1125 make_local_ifunc_plt_entry(Symbol_table*, Layout*,
1126 Sized_relobj_file<size, big_endian>*,
1130 // Create a GOT entry for local dynamic __tls_get_addr.
1132 tlsld_got_offset(Symbol_table* symtab, Layout* layout,
1133 Sized_relobj_file<size, big_endian>* object);
1136 tlsld_got_offset() const
1138 return this->tlsld_got_offset_;
1141 // Get the dynamic reloc section, creating it if necessary.
1143 rela_dyn_section(Layout*);
1145 // Similarly, but for ifunc symbols get the one for ifunc.
1147 rela_dyn_section(Symbol_table*, Layout*, bool for_ifunc);
1149 // Copy a relocation against a global symbol.
1151 copy_reloc(Symbol_table* symtab, Layout* layout,
1152 Sized_relobj_file<size, big_endian>* object,
1153 unsigned int shndx, Output_section* output_section,
1154 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
1156 this->copy_relocs_.copy_reloc(symtab, layout,
1157 symtab->get_sized_symbol<size>(sym),
1158 object, shndx, output_section,
1159 reloc, this->rela_dyn_section(layout));
1162 // Look over all the input sections, deciding where to place stubs.
1164 group_sections(Layout*, const Task*);
1166 // Sort output sections by address.
1167 struct Sort_sections
1170 operator()(const Output_section* sec1, const Output_section* sec2)
1171 { return sec1->address() < sec2->address(); }
1177 Branch_info(Powerpc_relobj<size, big_endian>* ppc_object,
1178 unsigned int data_shndx,
1180 unsigned int r_type,
1183 : object_(ppc_object), shndx_(data_shndx), offset_(r_offset),
1184 r_type_(r_type), r_sym_(r_sym), addend_(addend)
1190 // If this branch needs a plt call stub, or a long branch stub, make one.
1192 make_stub(Stub_table<size, big_endian>*,
1193 Stub_table<size, big_endian>*,
1194 Symbol_table*) const;
1197 // The branch location..
1198 Powerpc_relobj<size, big_endian>* object_;
1199 unsigned int shndx_;
1201 // ..and the branch type and destination.
1202 unsigned int r_type_;
1203 unsigned int r_sym_;
1207 // Information about this specific target which we pass to the
1208 // general Target structure.
1209 static Target::Target_info powerpc_info;
1211 // The types of GOT entries needed for this platform.
1212 // These values are exposed to the ABI in an incremental link.
1213 // Do not renumber existing values without changing the version
1214 // number of the .gnu_incremental_inputs section.
1218 GOT_TYPE_TLSGD, // double entry for @got@tlsgd
1219 GOT_TYPE_DTPREL, // entry for @got@dtprel
1220 GOT_TYPE_TPREL // entry for @got@tprel
1224 Output_data_got_powerpc<size, big_endian>* got_;
1225 // The PLT section. This is a container for a table of addresses,
1226 // and their relocations. Each address in the PLT has a dynamic
1227 // relocation (R_*_JMP_SLOT) and each address will have a
1228 // corresponding entry in .glink for lazy resolution of the PLT.
1229 // ppc32 initialises the PLT to point at the .glink entry, while
1230 // ppc64 leaves this to ld.so. To make a call via the PLT, the
1231 // linker adds a stub that loads the PLT entry into ctr then
1232 // branches to ctr. There may be more than one stub for each PLT
1233 // entry. DT_JMPREL points at the first PLT dynamic relocation and
1234 // DT_PLTRELSZ gives the total size of PLT dynamic relocations.
1235 Output_data_plt_powerpc<size, big_endian>* plt_;
1236 // The IPLT section. Like plt_, this is a container for a table of
1237 // addresses and their relocations, specifically for STT_GNU_IFUNC
1238 // functions that resolve locally (STT_GNU_IFUNC functions that
1239 // don't resolve locally go in PLT). Unlike plt_, these have no
1240 // entry in .glink for lazy resolution, and the relocation section
1241 // does not have a 1-1 correspondence with IPLT addresses. In fact,
1242 // the relocation section may contain relocations against
1243 // STT_GNU_IFUNC symbols at locations outside of IPLT. The
1244 // relocation section will appear at the end of other dynamic
1245 // relocations, so that ld.so applies these relocations after other
1246 // dynamic relocations. In a static executable, the relocation
1247 // section is emitted and marked with __rela_iplt_start and
1248 // __rela_iplt_end symbols.
1249 Output_data_plt_powerpc<size, big_endian>* iplt_;
1250 // Section holding long branch destinations.
1251 Output_data_brlt_powerpc<size, big_endian>* brlt_section_;
1252 // The .glink section.
1253 Output_data_glink<size, big_endian>* glink_;
1254 // The dynamic reloc section.
1255 Reloc_section* rela_dyn_;
1256 // Relocs saved to avoid a COPY reloc.
1257 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
1258 // Offset of the GOT entry for local dynamic __tls_get_addr calls.
1259 unsigned int tlsld_got_offset_;
1261 Stub_tables stub_tables_;
1262 typedef Unordered_map<Address, unsigned int> Branch_lookup_table;
1263 Branch_lookup_table branch_lookup_table_;
1265 typedef std::vector<Branch_info> Branches;
1266 Branches branch_info_;
1268 bool plt_thread_safe_;
1272 Target::Target_info Target_powerpc<32, true>::powerpc_info =
1275 true, // is_big_endian
1276 elfcpp::EM_PPC, // machine_code
1277 false, // has_make_symbol
1278 false, // has_resolve
1279 false, // has_code_fill
1280 true, // is_default_stack_executable
1281 false, // can_icf_inline_merge_sections
1283 "/usr/lib/ld.so.1", // dynamic_linker
1284 0x10000000, // default_text_segment_address
1285 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1286 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1287 false, // isolate_execinstr
1289 elfcpp::SHN_UNDEF, // small_common_shndx
1290 elfcpp::SHN_UNDEF, // large_common_shndx
1291 0, // small_common_section_flags
1292 0, // large_common_section_flags
1293 NULL, // attributes_section
1294 NULL, // attributes_vendor
1295 "_start" // entry_symbol_name
1299 Target::Target_info Target_powerpc<32, false>::powerpc_info =
1302 false, // is_big_endian
1303 elfcpp::EM_PPC, // machine_code
1304 false, // has_make_symbol
1305 false, // has_resolve
1306 false, // has_code_fill
1307 true, // is_default_stack_executable
1308 false, // can_icf_inline_merge_sections
1310 "/usr/lib/ld.so.1", // dynamic_linker
1311 0x10000000, // default_text_segment_address
1312 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1313 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1314 false, // isolate_execinstr
1316 elfcpp::SHN_UNDEF, // small_common_shndx
1317 elfcpp::SHN_UNDEF, // large_common_shndx
1318 0, // small_common_section_flags
1319 0, // large_common_section_flags
1320 NULL, // attributes_section
1321 NULL, // attributes_vendor
1322 "_start" // entry_symbol_name
1326 Target::Target_info Target_powerpc<64, true>::powerpc_info =
1329 true, // is_big_endian
1330 elfcpp::EM_PPC64, // machine_code
1331 false, // has_make_symbol
1332 false, // has_resolve
1333 false, // has_code_fill
1334 true, // is_default_stack_executable
1335 false, // can_icf_inline_merge_sections
1337 "/usr/lib/ld.so.1", // dynamic_linker
1338 0x10000000, // default_text_segment_address
1339 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1340 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1341 false, // isolate_execinstr
1343 elfcpp::SHN_UNDEF, // small_common_shndx
1344 elfcpp::SHN_UNDEF, // large_common_shndx
1345 0, // small_common_section_flags
1346 0, // large_common_section_flags
1347 NULL, // attributes_section
1348 NULL, // attributes_vendor
1349 "_start" // entry_symbol_name
1353 Target::Target_info Target_powerpc<64, false>::powerpc_info =
1356 false, // is_big_endian
1357 elfcpp::EM_PPC64, // machine_code
1358 false, // has_make_symbol
1359 false, // has_resolve
1360 false, // has_code_fill
1361 true, // is_default_stack_executable
1362 false, // can_icf_inline_merge_sections
1364 "/usr/lib/ld.so.1", // dynamic_linker
1365 0x10000000, // default_text_segment_address
1366 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
1367 4 * 1024, // common_pagesize (overridable by -z common-page-size)
1368 false, // isolate_execinstr
1370 elfcpp::SHN_UNDEF, // small_common_shndx
1371 elfcpp::SHN_UNDEF, // large_common_shndx
1372 0, // small_common_section_flags
1373 0, // large_common_section_flags
1374 NULL, // attributes_section
1375 NULL, // attributes_vendor
1376 "_start" // entry_symbol_name
1380 is_branch_reloc(unsigned int r_type)
1382 return (r_type == elfcpp::R_POWERPC_REL24
1383 || r_type == elfcpp::R_PPC_PLTREL24
1384 || r_type == elfcpp::R_PPC_LOCAL24PC
1385 || r_type == elfcpp::R_POWERPC_REL14
1386 || r_type == elfcpp::R_POWERPC_REL14_BRTAKEN
1387 || r_type == elfcpp::R_POWERPC_REL14_BRNTAKEN
1388 || r_type == elfcpp::R_POWERPC_ADDR24
1389 || r_type == elfcpp::R_POWERPC_ADDR14
1390 || r_type == elfcpp::R_POWERPC_ADDR14_BRTAKEN
1391 || r_type == elfcpp::R_POWERPC_ADDR14_BRNTAKEN);
1394 // If INSN is an opcode that may be used with an @tls operand, return
1395 // the transformed insn for TLS optimisation, otherwise return 0. If
1396 // REG is non-zero only match an insn with RB or RA equal to REG.
1398 at_tls_transform(uint32_t insn, unsigned int reg)
1400 if ((insn & (0x3f << 26)) != 31 << 26)
1404 if (reg == 0 || ((insn >> 11) & 0x1f) == reg)
1405 rtra = insn & ((1 << 26) - (1 << 16));
1406 else if (((insn >> 16) & 0x1f) == reg)
1407 rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5);
1411 if ((insn & (0x3ff << 1)) == 266 << 1)
1414 else if ((insn & (0x1f << 1)) == 23 << 1
1415 && ((insn & (0x1f << 6)) < 14 << 6
1416 || ((insn & (0x1f << 6)) >= 16 << 6
1417 && (insn & (0x1f << 6)) < 24 << 6)))
1418 // load and store indexed -> dform
1419 insn = (32 | ((insn >> 6) & 0x1f)) << 26;
1420 else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
1421 // ldx, ldux, stdx, stdux -> ld, ldu, std, stdu
1422 insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1);
1423 else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
1425 insn = (58 << 26) | 2;
1432 // Modified version of symtab.h class Symbol member
1433 // Given a direct absolute or pc-relative static relocation against
1434 // the global symbol, this function returns whether a dynamic relocation
1439 needs_dynamic_reloc(const Symbol* gsym, int flags)
1441 // No dynamic relocations in a static link!
1442 if (parameters->doing_static_link())
1445 // A reference to an undefined symbol from an executable should be
1446 // statically resolved to 0, and does not need a dynamic relocation.
1447 // This matches gnu ld behavior.
1448 if (gsym->is_undefined() && !parameters->options().shared())
1451 // A reference to an absolute symbol does not need a dynamic relocation.
1452 if (gsym->is_absolute())
1455 // An absolute reference within a position-independent output file
1456 // will need a dynamic relocation.
1457 if ((flags & Symbol::ABSOLUTE_REF)
1458 && parameters->options().output_is_position_independent())
1461 // A function call that can branch to a local PLT entry does not need
1462 // a dynamic relocation.
1463 if ((flags & Symbol::FUNCTION_CALL) && gsym->has_plt_offset())
1466 // A reference to any PLT entry in a non-position-independent executable
1467 // does not need a dynamic relocation.
1468 // Except due to having function descriptors on powerpc64 we don't define
1469 // functions to their plt code in an executable, so this doesn't apply.
1471 && !parameters->options().output_is_position_independent()
1472 && gsym->has_plt_offset())
1475 // A reference to a symbol defined in a dynamic object or to a
1476 // symbol that is preemptible will need a dynamic relocation.
1477 if (gsym->is_from_dynobj()
1478 || gsym->is_undefined()
1479 || gsym->is_preemptible())
1482 // For all other cases, return FALSE.
1486 // Modified version of symtab.h class Symbol member
1487 // Whether we should use the PLT offset associated with a symbol for
1488 // a relocation. FLAGS is a set of Reference_flags.
1492 use_plt_offset(const Symbol* gsym, int flags)
1494 // If the symbol doesn't have a PLT offset, then naturally we
1495 // don't want to use it.
1496 if (!gsym->has_plt_offset())
1499 // For a STT_GNU_IFUNC symbol we always have to use the PLT entry.
1500 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
1503 // If we are going to generate a dynamic relocation, then we will
1504 // wind up using that, so no need to use the PLT entry.
1505 if (needs_dynamic_reloc<size>(gsym, flags))
1508 // If the symbol is from a dynamic object, we need to use the PLT
1510 if (gsym->is_from_dynobj())
1513 // If we are generating a shared object, and this symbol is
1514 // undefined or preemptible, we need to use the PLT entry.
1515 if (parameters->options().shared()
1516 && (gsym->is_undefined() || gsym->is_preemptible()))
1519 // If this is a call to a weak undefined symbol, we need to use
1520 // the PLT entry; the symbol may be defined by a library loaded
1522 if ((flags & Symbol::FUNCTION_CALL) && gsym->is_weak_undefined())
1525 // Otherwise we can use the regular definition.
1529 template<int size, bool big_endian>
1530 class Powerpc_relocate_functions
1547 typedef Powerpc_relocate_functions<size, big_endian> This;
1548 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
1550 template<int valsize>
1552 has_overflow_signed(Address value)
1554 // limit = 1 << (valsize - 1) without shift count exceeding size of type
1555 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
1556 limit <<= ((valsize - 1) >> 1);
1557 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
1558 return value + limit > (limit << 1) - 1;
1561 template<int valsize>
1563 has_overflow_bitfield(Address value)
1565 Address limit = static_cast<Address>(1) << ((valsize - 1) >> 1);
1566 limit <<= ((valsize - 1) >> 1);
1567 limit <<= ((valsize - 1) - 2 * ((valsize - 1) >> 1));
1568 return value > (limit << 1) - 1 && value + limit > (limit << 1) - 1;
1571 template<int valsize>
1572 static inline Status
1573 overflowed(Address value, Overflow_check overflow)
1575 if (overflow == CHECK_SIGNED)
1577 if (has_overflow_signed<valsize>(value))
1578 return STATUS_OVERFLOW;
1580 else if (overflow == CHECK_BITFIELD)
1582 if (has_overflow_bitfield<valsize>(value))
1583 return STATUS_OVERFLOW;
1588 // Do a simple RELA relocation
1589 template<int valsize>
1590 static inline Status
1591 rela(unsigned char* view, Address value, Overflow_check overflow)
1593 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
1594 Valtype* wv = reinterpret_cast<Valtype*>(view);
1595 elfcpp::Swap<valsize, big_endian>::writeval(wv, value);
1596 return overflowed<valsize>(value, overflow);
1599 template<int valsize>
1600 static inline Status
1601 rela(unsigned char* view,
1602 unsigned int right_shift,
1603 typename elfcpp::Valtype_base<valsize>::Valtype dst_mask,
1605 Overflow_check overflow)
1607 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
1608 Valtype* wv = reinterpret_cast<Valtype*>(view);
1609 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
1610 Valtype reloc = value >> right_shift;
1613 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
1614 return overflowed<valsize>(value >> right_shift, overflow);
1617 // Do a simple RELA relocation, unaligned.
1618 template<int valsize>
1619 static inline Status
1620 rela_ua(unsigned char* view, Address value, Overflow_check overflow)
1622 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(view, value);
1623 return overflowed<valsize>(value, overflow);
1626 template<int valsize>
1627 static inline Status
1628 rela_ua(unsigned char* view,
1629 unsigned int right_shift,
1630 typename elfcpp::Valtype_base<valsize>::Valtype dst_mask,
1632 Overflow_check overflow)
1634 typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
1636 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(view);
1637 Valtype reloc = value >> right_shift;
1640 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(view, val | reloc);
1641 return overflowed<valsize>(value >> right_shift, overflow);
1645 // R_PPC64_ADDR64: (Symbol + Addend)
1647 addr64(unsigned char* view, Address value)
1648 { This::template rela<64>(view, value, CHECK_NONE); }
1650 // R_PPC64_UADDR64: (Symbol + Addend) unaligned
1652 addr64_u(unsigned char* view, Address value)
1653 { This::template rela_ua<64>(view, value, CHECK_NONE); }
1655 // R_POWERPC_ADDR32: (Symbol + Addend)
1656 static inline Status
1657 addr32(unsigned char* view, Address value, Overflow_check overflow)
1658 { return This::template rela<32>(view, value, overflow); }
1660 // R_POWERPC_UADDR32: (Symbol + Addend) unaligned
1661 static inline Status
1662 addr32_u(unsigned char* view, Address value, Overflow_check overflow)
1663 { return This::template rela_ua<32>(view, value, overflow); }
1665 // R_POWERPC_ADDR24: (Symbol + Addend) & 0x3fffffc
1666 static inline Status
1667 addr24(unsigned char* view, Address value, Overflow_check overflow)
1669 Status stat = This::template rela<32>(view, 0, 0x03fffffc, value, overflow);
1670 if (overflow != CHECK_NONE && (value & 3) != 0)
1671 stat = STATUS_OVERFLOW;
1675 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff
1676 static inline Status
1677 addr16(unsigned char* view, Address value, Overflow_check overflow)
1678 { return This::template rela<16>(view, value, overflow); }
1680 // R_POWERPC_ADDR16: (Symbol + Addend) & 0xffff, unaligned
1681 static inline Status
1682 addr16_u(unsigned char* view, Address value, Overflow_check overflow)
1683 { return This::template rela_ua<16>(view, value, overflow); }
1685 // R_POWERPC_ADDR16_DS: (Symbol + Addend) & 0xfffc
1686 static inline Status
1687 addr16_ds(unsigned char* view, Address value, Overflow_check overflow)
1689 Status stat = This::template rela<16>(view, 0, 0xfffc, value, overflow);
1690 if (overflow != CHECK_NONE && (value & 3) != 0)
1691 stat = STATUS_OVERFLOW;
1695 // R_POWERPC_ADDR16_HI: ((Symbol + Addend) >> 16) & 0xffff
1697 addr16_hi(unsigned char* view, Address value)
1698 { This::template rela<16>(view, 16, 0xffff, value, CHECK_NONE); }
1700 // R_POWERPC_ADDR16_HA: ((Symbol + Addend + 0x8000) >> 16) & 0xffff
1702 addr16_ha(unsigned char* view, Address value)
1703 { This::addr16_hi(view, value + 0x8000); }
1705 // R_POWERPC_ADDR16_HIGHER: ((Symbol + Addend) >> 32) & 0xffff
1707 addr16_hi2(unsigned char* view, Address value)
1708 { This::template rela<16>(view, 32, 0xffff, value, CHECK_NONE); }
1710 // R_POWERPC_ADDR16_HIGHERA: ((Symbol + Addend + 0x8000) >> 32) & 0xffff
1712 addr16_ha2(unsigned char* view, Address value)
1713 { This::addr16_hi2(view, value + 0x8000); }
1715 // R_POWERPC_ADDR16_HIGHEST: ((Symbol + Addend) >> 48) & 0xffff
1717 addr16_hi3(unsigned char* view, Address value)
1718 { This::template rela<16>(view, 48, 0xffff, value, CHECK_NONE); }
1720 // R_POWERPC_ADDR16_HIGHESTA: ((Symbol + Addend + 0x8000) >> 48) & 0xffff
1722 addr16_ha3(unsigned char* view, Address value)
1723 { This::addr16_hi3(view, value + 0x8000); }
1725 // R_POWERPC_ADDR14: (Symbol + Addend) & 0xfffc
1726 static inline Status
1727 addr14(unsigned char* view, Address value, Overflow_check overflow)
1729 Status stat = This::template rela<32>(view, 0, 0xfffc, value, overflow);
1730 if (overflow != CHECK_NONE && (value & 3) != 0)
1731 stat = STATUS_OVERFLOW;
1736 // Set ABI version for input and output.
1738 template<int size, bool big_endian>
1740 Powerpc_relobj<size, big_endian>::set_abiversion(int ver)
1742 this->e_flags_ |= ver;
1743 if (this->abiversion() != 0)
1745 Target_powerpc<size, big_endian>* target =
1746 static_cast<Target_powerpc<size, big_endian>*>(
1747 parameters->sized_target<size, big_endian>());
1748 if (target->abiversion() == 0)
1749 target->set_abiversion(this->abiversion());
1750 else if (target->abiversion() != this->abiversion())
1751 gold_error(_("%s: ABI version %d is not compatible "
1752 "with ABI version %d output"),
1753 this->name().c_str(),
1754 this->abiversion(), target->abiversion());
1759 // Stash away the index of .got2 or .opd in a relocatable object, if
1760 // such a section exists.
1762 template<int size, bool big_endian>
1764 Powerpc_relobj<size, big_endian>::do_find_special_sections(
1765 Read_symbols_data* sd)
1767 const unsigned char* const pshdrs = sd->section_headers->data();
1768 const unsigned char* namesu = sd->section_names->data();
1769 const char* names = reinterpret_cast<const char*>(namesu);
1770 section_size_type names_size = sd->section_names_size;
1771 const unsigned char* s;
1773 s = this->template find_shdr<size, big_endian>(pshdrs,
1774 size == 32 ? ".got2" : ".opd",
1775 names, names_size, NULL);
1778 unsigned int ndx = (s - pshdrs) / elfcpp::Elf_sizes<size>::shdr_size;
1779 this->special_ = ndx;
1782 if (this->abiversion() == 0)
1783 this->set_abiversion(1);
1784 else if (this->abiversion() > 1)
1785 gold_error(_("%s: .opd invalid in abiv%d"),
1786 this->name().c_str(), this->abiversion());
1789 return Sized_relobj_file<size, big_endian>::do_find_special_sections(sd);
1792 // Examine .rela.opd to build info about function entry points.
1794 template<int size, bool big_endian>
1796 Powerpc_relobj<size, big_endian>::scan_opd_relocs(
1798 const unsigned char* prelocs,
1799 const unsigned char* plocal_syms)
1803 typedef typename Reloc_types<elfcpp::SHT_RELA, size, big_endian>::Reloc
1805 const int reloc_size
1806 = Reloc_types<elfcpp::SHT_RELA, size, big_endian>::reloc_size;
1807 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1808 Address expected_off = 0;
1809 bool regular = true;
1810 unsigned int opd_ent_size = 0;
1812 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
1814 Reltype reloc(prelocs);
1815 typename elfcpp::Elf_types<size>::Elf_WXword r_info
1816 = reloc.get_r_info();
1817 unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
1818 if (r_type == elfcpp::R_PPC64_ADDR64)
1820 unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
1821 typename elfcpp::Elf_types<size>::Elf_Addr value;
1824 if (r_sym < this->local_symbol_count())
1826 typename elfcpp::Sym<size, big_endian>
1827 lsym(plocal_syms + r_sym * sym_size);
1828 shndx = lsym.get_st_shndx();
1829 shndx = this->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
1830 value = lsym.get_st_value();
1833 shndx = this->symbol_section_and_value(r_sym, &value,
1835 this->set_opd_ent(reloc.get_r_offset(), shndx,
1836 value + reloc.get_r_addend());
1839 expected_off = reloc.get_r_offset();
1840 opd_ent_size = expected_off;
1842 else if (expected_off != reloc.get_r_offset())
1844 expected_off += opd_ent_size;
1846 else if (r_type == elfcpp::R_PPC64_TOC)
1848 if (expected_off - opd_ent_size + 8 != reloc.get_r_offset())
1853 gold_warning(_("%s: unexpected reloc type %u in .opd section"),
1854 this->name().c_str(), r_type);
1858 if (reloc_count <= 2)
1859 opd_ent_size = this->section_size(this->opd_shndx());
1860 if (opd_ent_size != 24 && opd_ent_size != 16)
1864 gold_warning(_("%s: .opd is not a regular array of opd entries"),
1865 this->name().c_str());
1871 template<int size, bool big_endian>
1873 Powerpc_relobj<size, big_endian>::do_read_relocs(Read_relocs_data* rd)
1875 Sized_relobj_file<size, big_endian>::do_read_relocs(rd);
1878 for (Read_relocs_data::Relocs_list::iterator p = rd->relocs.begin();
1879 p != rd->relocs.end();
1882 if (p->data_shndx == this->opd_shndx())
1884 uint64_t opd_size = this->section_size(this->opd_shndx());
1885 gold_assert(opd_size == static_cast<size_t>(opd_size));
1888 this->init_opd(opd_size);
1889 this->scan_opd_relocs(p->reloc_count, p->contents->data(),
1890 rd->local_symbols->data());
1898 // Read the symbols then set up st_other vector.
1900 template<int size, bool big_endian>
1902 Powerpc_relobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
1904 Sized_relobj_file<size, big_endian>::do_read_symbols(sd);
1907 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
1908 const unsigned char* const pshdrs = sd->section_headers->data();
1909 const unsigned int loccount = this->do_local_symbol_count();
1912 this->st_other_.resize(loccount);
1913 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1914 off_t locsize = loccount * sym_size;
1915 const unsigned int symtab_shndx = this->symtab_shndx();
1916 const unsigned char *psymtab = pshdrs + symtab_shndx * shdr_size;
1917 typename elfcpp::Shdr<size, big_endian> shdr(psymtab);
1918 const unsigned char* psyms = this->get_view(shdr.get_sh_offset(),
1919 locsize, true, false);
1921 for (unsigned int i = 1; i < loccount; ++i, psyms += sym_size)
1923 elfcpp::Sym<size, big_endian> sym(psyms);
1924 unsigned char st_other = sym.get_st_other();
1925 this->st_other_[i] = st_other;
1926 if ((st_other & elfcpp::STO_PPC64_LOCAL_MASK) != 0)
1928 if (this->abiversion() == 0)
1929 this->set_abiversion(2);
1930 else if (this->abiversion() < 2)
1931 gold_error(_("%s: local symbol %d has invalid st_other"
1932 " for ABI version 1"),
1933 this->name().c_str(), i);
1940 template<int size, bool big_endian>
1942 Powerpc_dynobj<size, big_endian>::set_abiversion(int ver)
1944 this->e_flags_ |= ver;
1945 if (this->abiversion() != 0)
1947 Target_powerpc<size, big_endian>* target =
1948 static_cast<Target_powerpc<size, big_endian>*>(
1949 parameters->sized_target<size, big_endian>());
1950 if (target->abiversion() == 0)
1951 target->set_abiversion(this->abiversion());
1952 else if (target->abiversion() != this->abiversion())
1953 gold_error(_("%s: ABI version %d is not compatible "
1954 "with ABI version %d output"),
1955 this->name().c_str(),
1956 this->abiversion(), target->abiversion());
1961 // Call Sized_dynobj::do_read_symbols to read the symbols then
1962 // read .opd from a dynamic object, filling in opd_ent_ vector,
1964 template<int size, bool big_endian>
1966 Powerpc_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data* sd)
1968 Sized_dynobj<size, big_endian>::do_read_symbols(sd);
1971 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
1972 const unsigned char* const pshdrs = sd->section_headers->data();
1973 const unsigned char* namesu = sd->section_names->data();
1974 const char* names = reinterpret_cast<const char*>(namesu);
1975 const unsigned char* s = NULL;
1976 const unsigned char* opd;
1977 section_size_type opd_size;
1979 // Find and read .opd section.
1982 s = this->template find_shdr<size, big_endian>(pshdrs, ".opd", names,
1983 sd->section_names_size,
1988 typename elfcpp::Shdr<size, big_endian> shdr(s);
1989 if (shdr.get_sh_type() == elfcpp::SHT_PROGBITS
1990 && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0)
1992 if (this->abiversion() == 0)
1993 this->set_abiversion(1);
1994 else if (this->abiversion() > 1)
1995 gold_error(_("%s: .opd invalid in abiv%d"),
1996 this->name().c_str(), this->abiversion());
1998 this->opd_shndx_ = (s - pshdrs) / shdr_size;
1999 this->opd_address_ = shdr.get_sh_addr();
2000 opd_size = convert_to_section_size_type(shdr.get_sh_size());
2001 opd = this->get_view(shdr.get_sh_offset(), opd_size,
2007 // Build set of executable sections.
2008 // Using a set is probably overkill. There is likely to be only
2009 // a few executable sections, typically .init, .text and .fini,
2010 // and they are generally grouped together.
2011 typedef std::set<Sec_info> Exec_sections;
2012 Exec_sections exec_sections;
2014 for (unsigned int i = 1; i < this->shnum(); ++i, s += shdr_size)
2016 typename elfcpp::Shdr<size, big_endian> shdr(s);
2017 if (shdr.get_sh_type() == elfcpp::SHT_PROGBITS
2018 && ((shdr.get_sh_flags()
2019 & (elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR))
2020 == (elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR))
2021 && shdr.get_sh_size() != 0)
2023 exec_sections.insert(Sec_info(shdr.get_sh_addr(),
2024 shdr.get_sh_size(), i));
2027 if (exec_sections.empty())
2030 // Look over the OPD entries. This is complicated by the fact
2031 // that some binaries will use two-word entries while others
2032 // will use the standard three-word entries. In most cases
2033 // the third word (the environment pointer for languages like
2034 // Pascal) is unused and will be zero. If the third word is
2035 // used it should not be pointing into executable sections,
2037 this->init_opd(opd_size);
2038 for (const unsigned char* p = opd; p < opd + opd_size; p += 8)
2040 typedef typename elfcpp::Swap<64, big_endian>::Valtype Valtype;
2041 const Valtype* valp = reinterpret_cast<const Valtype*>(p);
2042 Valtype val = elfcpp::Swap<64, big_endian>::readval(valp);
2044 // Chances are that this is the third word of an OPD entry.
2046 typename Exec_sections::const_iterator e
2047 = exec_sections.upper_bound(Sec_info(val, 0, 0));
2048 if (e != exec_sections.begin())
2051 if (e->start <= val && val < e->start + e->len)
2053 // We have an address in an executable section.
2054 // VAL ought to be the function entry, set it up.
2055 this->set_opd_ent(p - opd, e->shndx, val);
2056 // Skip second word of OPD entry, the TOC pointer.
2060 // If we didn't match any executable sections, we likely
2061 // have a non-zero third word in the OPD entry.
2066 // Set up some symbols.
2068 template<int size, bool big_endian>
2070 Target_powerpc<size, big_endian>::do_define_standard_symbols(
2071 Symbol_table* symtab,
2076 // Define _GLOBAL_OFFSET_TABLE_ to ensure it isn't seen as
2077 // undefined when scanning relocs (and thus requires
2078 // non-relative dynamic relocs). The proper value will be
2080 Symbol *gotsym = symtab->lookup("_GLOBAL_OFFSET_TABLE_", NULL);
2081 if (gotsym != NULL && gotsym->is_undefined())
2083 Target_powerpc<size, big_endian>* target =
2084 static_cast<Target_powerpc<size, big_endian>*>(
2085 parameters->sized_target<size, big_endian>());
2086 Output_data_got_powerpc<size, big_endian>* got
2087 = target->got_section(symtab, layout);
2088 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
2089 Symbol_table::PREDEFINED,
2093 elfcpp::STV_HIDDEN, 0,
2097 // Define _SDA_BASE_ at the start of the .sdata section + 32768.
2098 Symbol *sdasym = symtab->lookup("_SDA_BASE_", NULL);
2099 if (sdasym != NULL && sdasym->is_undefined())
2101 Output_data_space* sdata = new Output_data_space(4, "** sdata");
2103 = layout->add_output_section_data(".sdata", 0,
2105 | elfcpp::SHF_WRITE,
2106 sdata, ORDER_SMALL_DATA, false);
2107 symtab->define_in_output_data("_SDA_BASE_", NULL,
2108 Symbol_table::PREDEFINED,
2109 os, 32768, 0, elfcpp::STT_OBJECT,
2110 elfcpp::STB_LOCAL, elfcpp::STV_HIDDEN,
2116 // Define .TOC. as for 32-bit _GLOBAL_OFFSET_TABLE_
2117 Symbol *gotsym = symtab->lookup(".TOC.", NULL);
2118 if (gotsym != NULL && gotsym->is_undefined())
2120 Target_powerpc<size, big_endian>* target =
2121 static_cast<Target_powerpc<size, big_endian>*>(
2122 parameters->sized_target<size, big_endian>());
2123 Output_data_got_powerpc<size, big_endian>* got
2124 = target->got_section(symtab, layout);
2125 symtab->define_in_output_data(".TOC.", NULL,
2126 Symbol_table::PREDEFINED,
2130 elfcpp::STV_HIDDEN, 0,
2136 // Set up PowerPC target specific relobj.
2138 template<int size, bool big_endian>
2140 Target_powerpc<size, big_endian>::do_make_elf_object(
2141 const std::string& name,
2142 Input_file* input_file,
2143 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
2145 int et = ehdr.get_e_type();
2146 // ET_EXEC files are valid input for --just-symbols/-R,
2147 // and we treat them as relocatable objects.
2148 if (et == elfcpp::ET_REL
2149 || (et == elfcpp::ET_EXEC && input_file->just_symbols()))
2151 Powerpc_relobj<size, big_endian>* obj =
2152 new Powerpc_relobj<size, big_endian>(name, input_file, offset, ehdr);
2156 else if (et == elfcpp::ET_DYN)
2158 Powerpc_dynobj<size, big_endian>* obj =
2159 new Powerpc_dynobj<size, big_endian>(name, input_file, offset, ehdr);
2165 gold_error(_("%s: unsupported ELF file type %d"), name.c_str(), et);
2170 template<int size, bool big_endian>
2171 class Output_data_got_powerpc : public Output_data_got<size, big_endian>
2174 typedef typename elfcpp::Elf_types<size>::Elf_Addr Valtype;
2175 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Rela_dyn;
2177 Output_data_got_powerpc(Symbol_table* symtab, Layout* layout)
2178 : Output_data_got<size, big_endian>(),
2179 symtab_(symtab), layout_(layout),
2180 header_ent_cnt_(size == 32 ? 3 : 1),
2181 header_index_(size == 32 ? 0x2000 : 0)
2184 // Override all the Output_data_got methods we use so as to first call
2187 add_global(Symbol* gsym, unsigned int got_type)
2189 this->reserve_ent();
2190 return Output_data_got<size, big_endian>::add_global(gsym, got_type);
2194 add_global_plt(Symbol* gsym, unsigned int got_type)
2196 this->reserve_ent();
2197 return Output_data_got<size, big_endian>::add_global_plt(gsym, got_type);
2201 add_global_tls(Symbol* gsym, unsigned int got_type)
2202 { return this->add_global_plt(gsym, got_type); }
2205 add_global_with_rel(Symbol* gsym, unsigned int got_type,
2206 Output_data_reloc_generic* rel_dyn, unsigned int r_type)
2208 this->reserve_ent();
2209 Output_data_got<size, big_endian>::
2210 add_global_with_rel(gsym, got_type, rel_dyn, r_type);
2214 add_global_pair_with_rel(Symbol* gsym, unsigned int got_type,
2215 Output_data_reloc_generic* rel_dyn,
2216 unsigned int r_type_1, unsigned int r_type_2)
2218 this->reserve_ent(2);
2219 Output_data_got<size, big_endian>::
2220 add_global_pair_with_rel(gsym, got_type, rel_dyn, r_type_1, r_type_2);
2224 add_local(Relobj* object, unsigned int sym_index, unsigned int got_type)
2226 this->reserve_ent();
2227 return Output_data_got<size, big_endian>::add_local(object, sym_index,
2232 add_local_plt(Relobj* object, unsigned int sym_index, unsigned int got_type)
2234 this->reserve_ent();
2235 return Output_data_got<size, big_endian>::add_local_plt(object, sym_index,
2240 add_local_tls(Relobj* object, unsigned int sym_index, unsigned int got_type)
2241 { return this->add_local_plt(object, sym_index, got_type); }
2244 add_local_tls_pair(Relobj* object, unsigned int sym_index,
2245 unsigned int got_type,
2246 Output_data_reloc_generic* rel_dyn,
2247 unsigned int r_type)
2249 this->reserve_ent(2);
2250 Output_data_got<size, big_endian>::
2251 add_local_tls_pair(object, sym_index, got_type, rel_dyn, r_type);
2255 add_constant(Valtype constant)
2257 this->reserve_ent();
2258 return Output_data_got<size, big_endian>::add_constant(constant);
2262 add_constant_pair(Valtype c1, Valtype c2)
2264 this->reserve_ent(2);
2265 return Output_data_got<size, big_endian>::add_constant_pair(c1, c2);
2268 // Offset of _GLOBAL_OFFSET_TABLE_.
2272 return this->got_offset(this->header_index_);
2275 // Offset of base used to access the GOT/TOC.
2276 // The got/toc pointer reg will be set to this value.
2278 got_base_offset(const Powerpc_relobj<size, big_endian>* object) const
2281 return this->g_o_t();
2283 return (this->output_section()->address()
2284 + object->toc_base_offset()
2288 // Ensure our GOT has a header.
2290 set_final_data_size()
2292 if (this->header_ent_cnt_ != 0)
2293 this->make_header();
2294 Output_data_got<size, big_endian>::set_final_data_size();
2297 // First word of GOT header needs some values that are not
2298 // handled by Output_data_got so poke them in here.
2299 // For 32-bit, address of .dynamic, for 64-bit, address of TOCbase.
2301 do_write(Output_file* of)
2304 if (size == 32 && this->layout_->dynamic_data() != NULL)
2305 val = this->layout_->dynamic_section()->address();
2307 val = this->output_section()->address() + 0x8000;
2308 this->replace_constant(this->header_index_, val);
2309 Output_data_got<size, big_endian>::do_write(of);
2314 reserve_ent(unsigned int cnt = 1)
2316 if (this->header_ent_cnt_ == 0)
2318 if (this->num_entries() + cnt > this->header_index_)
2319 this->make_header();
2325 this->header_ent_cnt_ = 0;
2326 this->header_index_ = this->num_entries();
2329 Output_data_got<size, big_endian>::add_constant(0);
2330 Output_data_got<size, big_endian>::add_constant(0);
2331 Output_data_got<size, big_endian>::add_constant(0);
2333 // Define _GLOBAL_OFFSET_TABLE_ at the header
2334 Symbol *gotsym = this->symtab_->lookup("_GLOBAL_OFFSET_TABLE_", NULL);
2337 Sized_symbol<size>* sym = static_cast<Sized_symbol<size>*>(gotsym);
2338 sym->set_value(this->g_o_t());
2341 this->symtab_->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
2342 Symbol_table::PREDEFINED,
2343 this, this->g_o_t(), 0,
2346 elfcpp::STV_HIDDEN, 0,
2350 Output_data_got<size, big_endian>::add_constant(0);
2353 // Stashed pointers.
2354 Symbol_table* symtab_;
2358 unsigned int header_ent_cnt_;
2359 // GOT header index.
2360 unsigned int header_index_;
2363 // Get the GOT section, creating it if necessary.
2365 template<int size, bool big_endian>
2366 Output_data_got_powerpc<size, big_endian>*
2367 Target_powerpc<size, big_endian>::got_section(Symbol_table* symtab,
2370 if (this->got_ == NULL)
2372 gold_assert(symtab != NULL && layout != NULL);
2375 = new Output_data_got_powerpc<size, big_endian>(symtab, layout);
2377 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
2378 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
2379 this->got_, ORDER_DATA, false);
2385 // Get the dynamic reloc section, creating it if necessary.
2387 template<int size, bool big_endian>
2388 typename Target_powerpc<size, big_endian>::Reloc_section*
2389 Target_powerpc<size, big_endian>::rela_dyn_section(Layout* layout)
2391 if (this->rela_dyn_ == NULL)
2393 gold_assert(layout != NULL);
2394 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
2395 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
2396 elfcpp::SHF_ALLOC, this->rela_dyn_,
2397 ORDER_DYNAMIC_RELOCS, false);
2399 return this->rela_dyn_;
2402 // Similarly, but for ifunc symbols get the one for ifunc.
2404 template<int size, bool big_endian>
2405 typename Target_powerpc<size, big_endian>::Reloc_section*
2406 Target_powerpc<size, big_endian>::rela_dyn_section(Symbol_table* symtab,
2411 return this->rela_dyn_section(layout);
2413 if (this->iplt_ == NULL)
2414 this->make_iplt_section(symtab, layout);
2415 return this->iplt_->rel_plt();
2421 // Determine the stub group size. The group size is the absolute
2422 // value of the parameter --stub-group-size. If --stub-group-size
2423 // is passed a negative value, we restrict stubs to be always before
2424 // the stubbed branches.
2425 Stub_control(int32_t size)
2426 : state_(NO_GROUP), stub_group_size_(abs(size)),
2427 stub14_group_size_(abs(size)),
2428 stubs_always_before_branch_(size < 0), suppress_size_errors_(false),
2429 group_end_addr_(0), owner_(NULL), output_section_(NULL)
2431 if (stub_group_size_ == 1)
2434 if (stubs_always_before_branch_)
2436 stub_group_size_ = 0x1e00000;
2437 stub14_group_size_ = 0x7800;
2441 stub_group_size_ = 0x1c00000;
2442 stub14_group_size_ = 0x7000;
2444 suppress_size_errors_ = true;
2448 // Return true iff input section can be handled by current stub
2451 can_add_to_stub_group(Output_section* o,
2452 const Output_section::Input_section* i,
2455 const Output_section::Input_section*
2461 { return output_section_; }
2467 FINDING_STUB_SECTION,
2472 uint32_t stub_group_size_;
2473 uint32_t stub14_group_size_;
2474 bool stubs_always_before_branch_;
2475 bool suppress_size_errors_;
2476 uint64_t group_end_addr_;
2477 const Output_section::Input_section* owner_;
2478 Output_section* output_section_;
2481 // Return true iff input section can be handled by current stub
2485 Stub_control::can_add_to_stub_group(Output_section* o,
2486 const Output_section::Input_section* i,
2490 = has14 ? this->stub14_group_size_ : this->stub_group_size_;
2491 bool whole_sec = o->order() == ORDER_INIT || o->order() == ORDER_FINI;
2493 uint64_t start_addr = o->address();
2496 // .init and .fini sections are pasted together to form a single
2497 // function. We can't be adding stubs in the middle of the function.
2498 this_size = o->data_size();
2501 start_addr += i->relobj()->output_section_offset(i->shndx());
2502 this_size = i->data_size();
2504 uint64_t end_addr = start_addr + this_size;
2505 bool toobig = this_size > group_size;
2507 if (toobig && !this->suppress_size_errors_)
2508 gold_warning(_("%s:%s exceeds group size"),
2509 i->relobj()->name().c_str(),
2510 i->relobj()->section_name(i->shndx()).c_str());
2512 if (this->state_ != HAS_STUB_SECTION
2513 && (!whole_sec || this->output_section_ != o)
2514 && (this->state_ == NO_GROUP
2515 || this->group_end_addr_ - end_addr < group_size))
2518 this->output_section_ = o;
2521 if (this->state_ == NO_GROUP)
2523 this->state_ = FINDING_STUB_SECTION;
2524 this->group_end_addr_ = end_addr;
2526 else if (this->group_end_addr_ - start_addr < group_size)
2528 // Adding this section would make the group larger than GROUP_SIZE.
2529 else if (this->state_ == FINDING_STUB_SECTION
2530 && !this->stubs_always_before_branch_
2533 // But wait, there's more! Input sections up to GROUP_SIZE
2534 // bytes before the stub table can be handled by it too.
2535 this->state_ = HAS_STUB_SECTION;
2536 this->group_end_addr_ = end_addr;
2540 this->state_ = NO_GROUP;
2546 // Look over all the input sections, deciding where to place stubs.
2548 template<int size, bool big_endian>
2550 Target_powerpc<size, big_endian>::group_sections(Layout* layout,
2553 Stub_control stub_control(parameters->options().stub_group_size());
2555 // Group input sections and insert stub table
2556 Stub_table<size, big_endian>* stub_table = NULL;
2557 Layout::Section_list section_list;
2558 layout->get_executable_sections(§ion_list);
2559 std::stable_sort(section_list.begin(), section_list.end(), Sort_sections());
2560 for (Layout::Section_list::reverse_iterator o = section_list.rbegin();
2561 o != section_list.rend();
2564 typedef Output_section::Input_section_list Input_section_list;
2565 for (Input_section_list::const_reverse_iterator i
2566 = (*o)->input_sections().rbegin();
2567 i != (*o)->input_sections().rend();
2570 if (i->is_input_section())
2572 Powerpc_relobj<size, big_endian>* ppcobj = static_cast
2573 <Powerpc_relobj<size, big_endian>*>(i->relobj());
2574 bool has14 = ppcobj->has_14bit_branch(i->shndx());
2575 if (!stub_control.can_add_to_stub_group(*o, &*i, has14))
2577 stub_table->init(stub_control.owner(),
2578 stub_control.output_section());
2581 if (stub_table == NULL)
2582 stub_table = this->new_stub_table();
2583 ppcobj->set_stub_table(i->shndx(), stub_table);
2587 if (stub_table != NULL)
2589 const Output_section::Input_section* i = stub_control.owner();
2590 if (!i->is_input_section())
2592 // Corner case. A new stub group was made for the first
2593 // section (last one looked at here) for some reason, but
2594 // the first section is already being used as the owner for
2595 // a stub table for following sections. Force it into that
2597 gold_assert(this->stub_tables_.size() >= 2);
2598 this->stub_tables_.pop_back();
2600 Powerpc_relobj<size, big_endian>* ppcobj = static_cast
2601 <Powerpc_relobj<size, big_endian>*>(i->relobj());
2602 ppcobj->set_stub_table(i->shndx(), this->stub_tables_.back());
2605 stub_table->init(i, stub_control.output_section());
2609 // If this branch needs a plt call stub, or a long branch stub, make one.
2611 template<int size, bool big_endian>
2613 Target_powerpc<size, big_endian>::Branch_info::make_stub(
2614 Stub_table<size, big_endian>* stub_table,
2615 Stub_table<size, big_endian>* ifunc_stub_table,
2616 Symbol_table* symtab) const
2618 Symbol* sym = this->object_->global_symbol(this->r_sym_);
2619 if (sym != NULL && sym->is_forwarder())
2620 sym = symtab->resolve_forwards(sym);
2621 const Sized_symbol<size>* gsym = static_cast<const Sized_symbol<size>*>(sym);
2623 ? use_plt_offset<size>(gsym, Scan::get_reference_flags(this->r_type_))
2624 : this->object_->local_has_plt_offset(this->r_sym_))
2626 if (stub_table == NULL)
2627 stub_table = this->object_->stub_table(this->shndx_);
2628 if (stub_table == NULL)
2630 // This is a ref from a data section to an ifunc symbol.
2631 stub_table = ifunc_stub_table;
2633 gold_assert(stub_table != NULL);
2635 stub_table->add_plt_call_entry(this->object_, gsym,
2636 this->r_type_, this->addend_);
2638 stub_table->add_plt_call_entry(this->object_, this->r_sym_,
2639 this->r_type_, this->addend_);
2643 unsigned long max_branch_offset;
2644 if (this->r_type_ == elfcpp::R_POWERPC_REL14
2645 || this->r_type_ == elfcpp::R_POWERPC_REL14_BRTAKEN
2646 || this->r_type_ == elfcpp::R_POWERPC_REL14_BRNTAKEN)
2647 max_branch_offset = 1 << 15;
2648 else if (this->r_type_ == elfcpp::R_POWERPC_REL24
2649 || this->r_type_ == elfcpp::R_PPC_PLTREL24
2650 || this->r_type_ == elfcpp::R_PPC_LOCAL24PC)
2651 max_branch_offset = 1 << 25;
2654 Address from = this->object_->get_output_section_offset(this->shndx_);
2655 gold_assert(from != invalid_address);
2656 from += (this->object_->output_section(this->shndx_)->address()
2661 switch (gsym->source())
2663 case Symbol::FROM_OBJECT:
2665 Object* symobj = gsym->object();
2666 if (symobj->is_dynamic()
2667 || symobj->pluginobj() != NULL)
2670 unsigned int shndx = gsym->shndx(&is_ordinary);
2671 if (shndx == elfcpp::SHN_UNDEF)
2676 case Symbol::IS_UNDEFINED:
2682 Symbol_table::Compute_final_value_status status;
2683 to = symtab->compute_final_value<size>(gsym, &status);
2684 if (status != Symbol_table::CFVS_OK)
2686 to += this->object_->ppc64_local_entry_offset(gsym);
2690 const Symbol_value<size>* psymval
2691 = this->object_->local_symbol(this->r_sym_);
2692 Symbol_value<size> symval;
2693 typedef Sized_relobj_file<size, big_endian> ObjType;
2694 typename ObjType::Compute_final_local_value_status status
2695 = this->object_->compute_final_local_value(this->r_sym_, psymval,
2697 if (status != ObjType::CFLV_OK
2698 || !symval.has_output_value())
2700 to = symval.value(this->object_, 0);
2701 to += this->object_->ppc64_local_entry_offset(this->r_sym_);
2703 to += this->addend_;
2704 if (stub_table == NULL)
2705 stub_table = this->object_->stub_table(this->shndx_);
2706 if (size == 64 && is_branch_reloc(this->r_type_))
2708 unsigned int dest_shndx;
2709 Target_powerpc<size, big_endian>* target =
2710 static_cast<Target_powerpc<size, big_endian>*>(
2711 parameters->sized_target<size, big_endian>());
2712 to = target->symval_for_branch(symtab, to, gsym,
2713 this->object_, &dest_shndx);
2715 Address delta = to - from;
2716 if (delta + max_branch_offset >= 2 * max_branch_offset)
2718 if (stub_table == NULL)
2720 gold_warning(_("%s:%s: branch in non-executable section,"
2721 " no long branch stub for you"),
2722 this->object_->name().c_str(),
2723 this->object_->section_name(this->shndx_).c_str());
2726 stub_table->add_long_branch_entry(this->object_, to);
2731 // Relaxation hook. This is where we do stub generation.
2733 template<int size, bool big_endian>
2735 Target_powerpc<size, big_endian>::do_relax(int pass,
2736 const Input_objects*,
2737 Symbol_table* symtab,
2741 unsigned int prev_brlt_size = 0;
2745 = this->abiversion() < 2 && parameters->options().plt_thread_safe();
2747 && this->abiversion() < 2
2749 && !parameters->options().user_set_plt_thread_safe())
2751 static const char* const thread_starter[] =
2755 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
2757 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
2758 "mq_notify", "create_timer",
2762 "GOMP_parallel_start",
2763 "GOMP_parallel_loop_static_start",
2764 "GOMP_parallel_loop_dynamic_start",
2765 "GOMP_parallel_loop_guided_start",
2766 "GOMP_parallel_loop_runtime_start",
2767 "GOMP_parallel_sections_start",
2770 if (parameters->options().shared())
2774 for (unsigned int i = 0;
2775 i < sizeof(thread_starter) / sizeof(thread_starter[0]);
2778 Symbol* sym = symtab->lookup(thread_starter[i], NULL);
2779 thread_safe = (sym != NULL
2781 && sym->in_real_elf());
2787 this->plt_thread_safe_ = thread_safe;
2788 this->group_sections(layout, task);
2791 // We need address of stub tables valid for make_stub.
2792 for (typename Stub_tables::iterator p = this->stub_tables_.begin();
2793 p != this->stub_tables_.end();
2796 const Powerpc_relobj<size, big_endian>* object
2797 = static_cast<const Powerpc_relobj<size, big_endian>*>((*p)->relobj());
2798 Address off = object->get_output_section_offset((*p)->shndx());
2799 gold_assert(off != invalid_address);
2800 Output_section* os = (*p)->output_section();
2801 (*p)->set_address_and_size(os, off);
2806 // Clear plt call stubs, long branch stubs and branch lookup table.
2807 prev_brlt_size = this->branch_lookup_table_.size();
2808 this->branch_lookup_table_.clear();
2809 for (typename Stub_tables::iterator p = this->stub_tables_.begin();
2810 p != this->stub_tables_.end();
2813 (*p)->clear_stubs();
2817 // Build all the stubs.
2818 Stub_table<size, big_endian>* ifunc_stub_table
2819 = this->stub_tables_.size() == 0 ? NULL : this->stub_tables_[0];
2820 Stub_table<size, big_endian>* one_stub_table
2821 = this->stub_tables_.size() != 1 ? NULL : ifunc_stub_table;
2822 for (typename Branches::const_iterator b = this->branch_info_.begin();
2823 b != this->branch_info_.end();
2826 b->make_stub(one_stub_table, ifunc_stub_table, symtab);
2829 // Did anything change size?
2830 unsigned int num_huge_branches = this->branch_lookup_table_.size();
2831 bool again = num_huge_branches != prev_brlt_size;
2832 if (size == 64 && num_huge_branches != 0)
2833 this->make_brlt_section(layout);
2834 if (size == 64 && again)
2835 this->brlt_section_->set_current_size(num_huge_branches);
2837 typedef Unordered_set<Output_section*> Output_sections;
2838 Output_sections os_need_update;
2839 for (typename Stub_tables::iterator p = this->stub_tables_.begin();
2840 p != this->stub_tables_.end();
2843 if ((*p)->size_update())
2846 (*p)->add_eh_frame(layout);
2847 os_need_update.insert((*p)->output_section());
2851 // Set output section offsets for all input sections in an output
2852 // section that just changed size. Anything past the stubs will
2854 for (typename Output_sections::iterator p = os_need_update.begin();
2855 p != os_need_update.end();
2858 Output_section* os = *p;
2860 typedef Output_section::Input_section_list Input_section_list;
2861 for (Input_section_list::const_iterator i = os->input_sections().begin();
2862 i != os->input_sections().end();
2865 off = align_address(off, i->addralign());
2866 if (i->is_input_section() || i->is_relaxed_input_section())
2867 i->relobj()->set_section_offset(i->shndx(), off);
2868 if (i->is_relaxed_input_section())
2870 Stub_table<size, big_endian>* stub_table
2871 = static_cast<Stub_table<size, big_endian>*>(
2872 i->relaxed_input_section());
2873 off += stub_table->set_address_and_size(os, off);
2876 off += i->data_size();
2878 // If .branch_lt is part of this output section, then we have
2879 // just done the offset adjustment.
2880 os->clear_section_offsets_need_adjustment();
2885 && num_huge_branches != 0
2886 && parameters->options().output_is_position_independent())
2888 // Fill in the BRLT relocs.
2889 this->brlt_section_->reset_brlt_sizes();
2890 for (typename Branch_lookup_table::const_iterator p
2891 = this->branch_lookup_table_.begin();
2892 p != this->branch_lookup_table_.end();
2895 this->brlt_section_->add_reloc(p->first, p->second);
2897 this->brlt_section_->finalize_brlt_sizes();
2902 template<int size, bool big_endian>
2904 Target_powerpc<size, big_endian>::do_plt_fde_location(const Output_data* plt,
2905 unsigned char* oview,
2909 uint64_t address = plt->address();
2910 off_t len = plt->data_size();
2912 if (plt == this->glink_)
2914 // See Output_data_glink::do_write() for glink contents.
2917 // There is one word before __glink_PLTresolve
2921 else if (parameters->options().output_is_position_independent())
2923 // There are two FDEs for a position independent glink.
2924 // The first covers the branch table, the second
2925 // __glink_PLTresolve at the end of glink.
2926 off_t resolve_size = this->glink_->pltresolve_size;
2928 len -= resolve_size;
2931 address += len - resolve_size;
2938 // Must be a stub table.
2939 const Stub_table<size, big_endian>* stub_table
2940 = static_cast<const Stub_table<size, big_endian>*>(plt);
2941 uint64_t stub_address = stub_table->stub_address();
2942 len -= stub_address - address;
2943 address = stub_address;
2946 *paddress = address;
2950 // A class to handle the PLT data.
2952 template<int size, bool big_endian>
2953 class Output_data_plt_powerpc : public Output_section_data_build
2956 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
2957 size, big_endian> Reloc_section;
2959 Output_data_plt_powerpc(Target_powerpc<size, big_endian>* targ,
2960 Reloc_section* plt_rel,
2962 : Output_section_data_build(size == 32 ? 4 : 8),
2968 // Add an entry to the PLT.
2973 add_ifunc_entry(Symbol*);
2976 add_local_ifunc_entry(Sized_relobj_file<size, big_endian>*, unsigned int);
2978 // Return the .rela.plt section data.
2985 // Return the number of PLT entries.
2989 if (this->current_data_size() == 0)
2991 return ((this->current_data_size() - this->first_plt_entry_offset())
2992 / this->plt_entry_size());
2997 do_adjust_output_section(Output_section* os)
3002 // Write to a map file.
3004 do_print_to_mapfile(Mapfile* mapfile) const
3005 { mapfile->print_output_data(this, this->name_); }
3008 // Return the offset of the first non-reserved PLT entry.
3010 first_plt_entry_offset() const
3012 // IPLT has no reserved entry.
3013 if (this->name_[3] == 'I')
3015 return this->targ_->first_plt_entry_offset();
3018 // Return the size of each PLT entry.
3020 plt_entry_size() const
3022 return this->targ_->plt_entry_size();
3025 // Write out the PLT data.
3027 do_write(Output_file*);
3029 // The reloc section.
3030 Reloc_section* rel_;
3031 // Allows access to .glink for do_write.
3032 Target_powerpc<size, big_endian>* targ_;
3033 // What to report in map file.
3037 // Add an entry to the PLT.
3039 template<int size, bool big_endian>
3041 Output_data_plt_powerpc<size, big_endian>::add_entry(Symbol* gsym)
3043 if (!gsym->has_plt_offset())
3045 section_size_type off = this->current_data_size();
3047 off += this->first_plt_entry_offset();
3048 gsym->set_plt_offset(off);
3049 gsym->set_needs_dynsym_entry();
3050 unsigned int dynrel = elfcpp::R_POWERPC_JMP_SLOT;
3051 this->rel_->add_global(gsym, dynrel, this, off, 0);
3052 off += this->plt_entry_size();
3053 this->set_current_data_size(off);
3057 // Add an entry for a global ifunc symbol that resolves locally, to the IPLT.
3059 template<int size, bool big_endian>
3061 Output_data_plt_powerpc<size, big_endian>::add_ifunc_entry(Symbol* gsym)
3063 if (!gsym->has_plt_offset())
3065 section_size_type off = this->current_data_size();
3066 gsym->set_plt_offset(off);
3067 unsigned int dynrel = elfcpp::R_POWERPC_IRELATIVE;
3068 if (size == 64 && this->targ_->abiversion() < 2)
3069 dynrel = elfcpp::R_PPC64_JMP_IREL;
3070 this->rel_->add_symbolless_global_addend(gsym, dynrel, this, off, 0);
3071 off += this->plt_entry_size();
3072 this->set_current_data_size(off);
3076 // Add an entry for a local ifunc symbol to the IPLT.
3078 template<int size, bool big_endian>
3080 Output_data_plt_powerpc<size, big_endian>::add_local_ifunc_entry(
3081 Sized_relobj_file<size, big_endian>* relobj,
3082 unsigned int local_sym_index)
3084 if (!relobj->local_has_plt_offset(local_sym_index))
3086 section_size_type off = this->current_data_size();
3087 relobj->set_local_plt_offset(local_sym_index, off);
3088 unsigned int dynrel = elfcpp::R_POWERPC_IRELATIVE;
3089 if (size == 64 && this->targ_->abiversion() < 2)
3090 dynrel = elfcpp::R_PPC64_JMP_IREL;
3091 this->rel_->add_symbolless_local_addend(relobj, local_sym_index, dynrel,
3093 off += this->plt_entry_size();
3094 this->set_current_data_size(off);
3098 static const uint32_t add_0_11_11 = 0x7c0b5a14;
3099 static const uint32_t add_2_2_11 = 0x7c425a14;
3100 static const uint32_t add_3_3_2 = 0x7c631214;
3101 static const uint32_t add_3_3_13 = 0x7c636a14;
3102 static const uint32_t add_11_0_11 = 0x7d605a14;
3103 static const uint32_t add_11_2_11 = 0x7d625a14;
3104 static const uint32_t add_11_11_2 = 0x7d6b1214;
3105 static const uint32_t addi_0_12 = 0x380c0000;
3106 static const uint32_t addi_2_2 = 0x38420000;
3107 static const uint32_t addi_3_3 = 0x38630000;
3108 static const uint32_t addi_11_11 = 0x396b0000;
3109 static const uint32_t addi_12_12 = 0x398c0000;
3110 static const uint32_t addis_0_2 = 0x3c020000;
3111 static const uint32_t addis_0_13 = 0x3c0d0000;
3112 static const uint32_t addis_3_2 = 0x3c620000;
3113 static const uint32_t addis_3_13 = 0x3c6d0000;
3114 static const uint32_t addis_11_2 = 0x3d620000;
3115 static const uint32_t addis_11_11 = 0x3d6b0000;
3116 static const uint32_t addis_11_30 = 0x3d7e0000;
3117 static const uint32_t addis_12_12 = 0x3d8c0000;
3118 static const uint32_t b = 0x48000000;
3119 static const uint32_t bcl_20_31 = 0x429f0005;
3120 static const uint32_t bctr = 0x4e800420;
3121 static const uint32_t blr = 0x4e800020;
3122 static const uint32_t bnectr_p4 = 0x4ce20420;
3123 static const uint32_t cmpldi_2_0 = 0x28220000;
3124 static const uint32_t cror_15_15_15 = 0x4def7b82;
3125 static const uint32_t cror_31_31_31 = 0x4ffffb82;
3126 static const uint32_t ld_0_1 = 0xe8010000;
3127 static const uint32_t ld_0_12 = 0xe80c0000;
3128 static const uint32_t ld_2_1 = 0xe8410000;
3129 static const uint32_t ld_2_2 = 0xe8420000;
3130 static const uint32_t ld_2_11 = 0xe84b0000;
3131 static const uint32_t ld_11_2 = 0xe9620000;
3132 static const uint32_t ld_11_11 = 0xe96b0000;
3133 static const uint32_t ld_12_2 = 0xe9820000;
3134 static const uint32_t ld_12_11 = 0xe98b0000;
3135 static const uint32_t lfd_0_1 = 0xc8010000;
3136 static const uint32_t li_0_0 = 0x38000000;
3137 static const uint32_t li_12_0 = 0x39800000;
3138 static const uint32_t lis_0_0 = 0x3c000000;
3139 static const uint32_t lis_11 = 0x3d600000;
3140 static const uint32_t lis_12 = 0x3d800000;
3141 static const uint32_t lvx_0_12_0 = 0x7c0c00ce;
3142 static const uint32_t lwz_0_12 = 0x800c0000;
3143 static const uint32_t lwz_11_11 = 0x816b0000;
3144 static const uint32_t lwz_11_30 = 0x817e0000;
3145 static const uint32_t lwz_12_12 = 0x818c0000;
3146 static const uint32_t lwzu_0_12 = 0x840c0000;
3147 static const uint32_t mflr_0 = 0x7c0802a6;
3148 static const uint32_t mflr_11 = 0x7d6802a6;
3149 static const uint32_t mflr_12 = 0x7d8802a6;
3150 static const uint32_t mtctr_0 = 0x7c0903a6;
3151 static const uint32_t mtctr_11 = 0x7d6903a6;
3152 static const uint32_t mtctr_12 = 0x7d8903a6;
3153 static const uint32_t mtlr_0 = 0x7c0803a6;
3154 static const uint32_t mtlr_12 = 0x7d8803a6;
3155 static const uint32_t nop = 0x60000000;
3156 static const uint32_t ori_0_0_0 = 0x60000000;
3157 static const uint32_t srdi_0_0_2 = 0x7800f082;
3158 static const uint32_t std_0_1 = 0xf8010000;
3159 static const uint32_t std_0_12 = 0xf80c0000;
3160 static const uint32_t std_2_1 = 0xf8410000;
3161 static const uint32_t stfd_0_1 = 0xd8010000;
3162 static const uint32_t stvx_0_12_0 = 0x7c0c01ce;
3163 static const uint32_t sub_11_11_12 = 0x7d6c5850;
3164 static const uint32_t sub_12_12_11 = 0x7d8b6050;
3165 static const uint32_t xor_2_12_12 = 0x7d826278;
3166 static const uint32_t xor_11_12_12 = 0x7d8b6278;
3168 // Write out the PLT.
3170 template<int size, bool big_endian>
3172 Output_data_plt_powerpc<size, big_endian>::do_write(Output_file* of)
3174 if (size == 32 && this->name_[3] != 'I')
3176 const section_size_type offset = this->offset();
3177 const section_size_type oview_size
3178 = convert_to_section_size_type(this->data_size());
3179 unsigned char* const oview = of->get_output_view(offset, oview_size);
3180 unsigned char* pov = oview;
3181 unsigned char* endpov = oview + oview_size;
3183 // The address of the .glink branch table
3184 const Output_data_glink<size, big_endian>* glink
3185 = this->targ_->glink_section();
3186 elfcpp::Elf_types<32>::Elf_Addr branch_tab = glink->address();
3188 while (pov < endpov)
3190 elfcpp::Swap<32, big_endian>::writeval(pov, branch_tab);
3195 of->write_output_view(offset, oview_size, oview);
3199 // Create the PLT section.
3201 template<int size, bool big_endian>
3203 Target_powerpc<size, big_endian>::make_plt_section(Symbol_table* symtab,
3206 if (this->plt_ == NULL)
3208 if (this->got_ == NULL)
3209 this->got_section(symtab, layout);
3211 if (this->glink_ == NULL)
3212 make_glink_section(layout);
3214 // Ensure that .rela.dyn always appears before .rela.plt This is
3215 // necessary due to how, on PowerPC and some other targets, .rela.dyn
3216 // needs to include .rela.plt in its range.
3217 this->rela_dyn_section(layout);
3219 Reloc_section* plt_rel = new Reloc_section(false);
3220 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
3221 elfcpp::SHF_ALLOC, plt_rel,
3222 ORDER_DYNAMIC_PLT_RELOCS, false);
3224 = new Output_data_plt_powerpc<size, big_endian>(this, plt_rel,
3226 layout->add_output_section_data(".plt",
3228 ? elfcpp::SHT_PROGBITS
3229 : elfcpp::SHT_NOBITS),
3230 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
3239 // Create the IPLT section.
3241 template<int size, bool big_endian>
3243 Target_powerpc<size, big_endian>::make_iplt_section(Symbol_table* symtab,
3246 if (this->iplt_ == NULL)
3248 this->make_plt_section(symtab, layout);
3250 Reloc_section* iplt_rel = new Reloc_section(false);
3251 this->rela_dyn_->output_section()->add_output_section_data(iplt_rel);
3253 = new Output_data_plt_powerpc<size, big_endian>(this, iplt_rel,
3255 this->plt_->output_section()->add_output_section_data(this->iplt_);
3259 // A section for huge long branch addresses, similar to plt section.
3261 template<int size, bool big_endian>
3262 class Output_data_brlt_powerpc : public Output_section_data_build
3265 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
3266 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
3267 size, big_endian> Reloc_section;
3269 Output_data_brlt_powerpc(Target_powerpc<size, big_endian>* targ,
3270 Reloc_section* brlt_rel)
3271 : Output_section_data_build(size == 32 ? 4 : 8),
3279 this->reset_data_size();
3280 this->rel_->reset_data_size();
3284 finalize_brlt_sizes()
3286 this->finalize_data_size();
3287 this->rel_->finalize_data_size();
3290 // Add a reloc for an entry in the BRLT.
3292 add_reloc(Address to, unsigned int off)
3293 { this->rel_->add_relative(elfcpp::R_POWERPC_RELATIVE, this, off, to); }
3295 // Update section and reloc section size.
3297 set_current_size(unsigned int num_branches)
3299 this->reset_address_and_file_offset();
3300 this->set_current_data_size(num_branches * 16);
3301 this->finalize_data_size();
3302 Output_section* os = this->output_section();
3303 os->set_section_offsets_need_adjustment();
3304 if (this->rel_ != NULL)
3306 unsigned int reloc_size
3307 = Reloc_types<elfcpp::SHT_RELA, size, big_endian>::reloc_size;
3308 this->rel_->reset_address_and_file_offset();
3309 this->rel_->set_current_data_size(num_branches * reloc_size);
3310 this->rel_->finalize_data_size();
3311 Output_section* os = this->rel_->output_section();
3312 os->set_section_offsets_need_adjustment();
3318 do_adjust_output_section(Output_section* os)
3323 // Write to a map file.
3325 do_print_to_mapfile(Mapfile* mapfile) const
3326 { mapfile->print_output_data(this, "** BRLT"); }
3329 // Write out the BRLT data.
3331 do_write(Output_file*);
3333 // The reloc section.
3334 Reloc_section* rel_;
3335 Target_powerpc<size, big_endian>* targ_;
3338 // Make the branch lookup table section.
3340 template<int size, bool big_endian>
3342 Target_powerpc<size, big_endian>::make_brlt_section(Layout* layout)
3344 if (size == 64 && this->brlt_section_ == NULL)
3346 Reloc_section* brlt_rel = NULL;
3347 bool is_pic = parameters->options().output_is_position_independent();
3350 // When PIC we can't fill in .branch_lt (like .plt it can be
3351 // a bss style section) but must initialise at runtime via
3352 // dynamic relocats.
3353 this->rela_dyn_section(layout);
3354 brlt_rel = new Reloc_section(false);
3355 this->rela_dyn_->output_section()->add_output_section_data(brlt_rel);
3358 = new Output_data_brlt_powerpc<size, big_endian>(this, brlt_rel);
3359 if (this->plt_ && is_pic)
3360 this->plt_->output_section()
3361 ->add_output_section_data(this->brlt_section_);
3363 layout->add_output_section_data(".branch_lt",
3364 (is_pic ? elfcpp::SHT_NOBITS
3365 : elfcpp::SHT_PROGBITS),
3366 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
3367 this->brlt_section_,
3368 (is_pic ? ORDER_SMALL_BSS
3369 : ORDER_SMALL_DATA),
3374 // Write out .branch_lt when non-PIC.
3376 template<int size, bool big_endian>
3378 Output_data_brlt_powerpc<size, big_endian>::do_write(Output_file* of)
3380 if (size == 64 && !parameters->options().output_is_position_independent())
3382 const section_size_type offset = this->offset();
3383 const section_size_type oview_size
3384 = convert_to_section_size_type(this->data_size());
3385 unsigned char* const oview = of->get_output_view(offset, oview_size);
3387 this->targ_->write_branch_lookup_table(oview);
3388 of->write_output_view(offset, oview_size, oview);
3392 static inline uint32_t
3398 static inline uint32_t
3404 static inline uint32_t
3407 return hi(a + 0x8000);
3413 static const unsigned char eh_frame_cie[12];
3417 const unsigned char Eh_cie<size>::eh_frame_cie[] =
3420 'z', 'R', 0, // Augmentation string.
3421 4, // Code alignment.
3422 0x80 - size / 8 , // Data alignment.
3424 1, // Augmentation size.
3425 (elfcpp::DW_EH_PE_pcrel
3426 | elfcpp::DW_EH_PE_sdata4), // FDE encoding.
3427 elfcpp::DW_CFA_def_cfa, 1, 0 // def_cfa: r1 offset 0.
3430 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv1.
3431 static const unsigned char glink_eh_frame_fde_64v1[] =
3433 0, 0, 0, 0, // Replaced with offset to .glink.
3434 0, 0, 0, 0, // Replaced with size of .glink.
3435 0, // Augmentation size.
3436 elfcpp::DW_CFA_advance_loc + 1,
3437 elfcpp::DW_CFA_register, 65, 12,
3438 elfcpp::DW_CFA_advance_loc + 4,
3439 elfcpp::DW_CFA_restore_extended, 65
3442 // Describe __glink_PLTresolve use of LR, 64-bit version ABIv2.
3443 static const unsigned char glink_eh_frame_fde_64v2[] =
3445 0, 0, 0, 0, // Replaced with offset to .glink.
3446 0, 0, 0, 0, // Replaced with size of .glink.
3447 0, // Augmentation size.
3448 elfcpp::DW_CFA_advance_loc + 1,
3449 elfcpp::DW_CFA_register, 65, 0,
3450 elfcpp::DW_CFA_advance_loc + 4,
3451 elfcpp::DW_CFA_restore_extended, 65
3454 // Describe __glink_PLTresolve use of LR, 32-bit version.
3455 static const unsigned char glink_eh_frame_fde_32[] =
3457 0, 0, 0, 0, // Replaced with offset to .glink.
3458 0, 0, 0, 0, // Replaced with size of .glink.
3459 0, // Augmentation size.
3460 elfcpp::DW_CFA_advance_loc + 2,
3461 elfcpp::DW_CFA_register, 65, 0,
3462 elfcpp::DW_CFA_advance_loc + 4,
3463 elfcpp::DW_CFA_restore_extended, 65
3466 static const unsigned char default_fde[] =
3468 0, 0, 0, 0, // Replaced with offset to stubs.
3469 0, 0, 0, 0, // Replaced with size of stubs.
3470 0, // Augmentation size.
3471 elfcpp::DW_CFA_nop, // Pad.
3476 template<bool big_endian>
3478 write_insn(unsigned char* p, uint32_t v)
3480 elfcpp::Swap<32, big_endian>::writeval(p, v);
3483 // Stub_table holds information about plt and long branch stubs.
3484 // Stubs are built in an area following some input section determined
3485 // by group_sections(). This input section is converted to a relaxed
3486 // input section allowing it to be resized to accommodate the stubs
3488 template<int size, bool big_endian>
3489 class Stub_table : public Output_relaxed_input_section
3492 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
3493 static const Address invalid_address = static_cast<Address>(0) - 1;
3495 Stub_table(Target_powerpc<size, big_endian>* targ)
3496 : Output_relaxed_input_section(NULL, 0, 0),
3497 targ_(targ), plt_call_stubs_(), long_branch_stubs_(),
3498 orig_data_size_(0), plt_size_(0), last_plt_size_(0),
3499 branch_size_(0), last_branch_size_(0), eh_frame_added_(false)
3502 // Delayed Output_relaxed_input_section init.
3504 init(const Output_section::Input_section*, Output_section*);
3506 // Add a plt call stub.
3508 add_plt_call_entry(const Sized_relobj_file<size, big_endian>*,
3514 add_plt_call_entry(const Sized_relobj_file<size, big_endian>*,
3519 // Find a given plt call stub.
3521 find_plt_call_entry(const Symbol*) const;
3524 find_plt_call_entry(const Sized_relobj_file<size, big_endian>*,
3525 unsigned int) const;
3528 find_plt_call_entry(const Sized_relobj_file<size, big_endian>*,
3534 find_plt_call_entry(const Sized_relobj_file<size, big_endian>*,
3539 // Add a long branch stub.
3541 add_long_branch_entry(const Powerpc_relobj<size, big_endian>*, Address);
3544 find_long_branch_entry(const Powerpc_relobj<size, big_endian>*,
3550 this->plt_call_stubs_.clear();
3551 this->plt_size_ = 0;
3552 this->long_branch_stubs_.clear();
3553 this->branch_size_ = 0;
3557 set_address_and_size(const Output_section* os, Address off)
3559 Address start_off = off;
3560 off += this->orig_data_size_;
3561 Address my_size = this->plt_size_ + this->branch_size_;
3563 off = align_address(off, this->stub_align());
3564 // Include original section size and alignment padding in size
3565 my_size += off - start_off;
3566 this->reset_address_and_file_offset();
3567 this->set_current_data_size(my_size);
3568 this->set_address_and_file_offset(os->address() + start_off,
3569 os->offset() + start_off);
3574 stub_address() const
3576 return align_address(this->address() + this->orig_data_size_,
3577 this->stub_align());
3583 return align_address(this->offset() + this->orig_data_size_,
3584 this->stub_align());
3589 { return this->plt_size_; }
3594 Output_section* os = this->output_section();
3595 if (os->addralign() < this->stub_align())
3597 os->set_addralign(this->stub_align());
3598 // FIXME: get rid of the insane checkpointing.
3599 // We can't increase alignment of the input section to which
3600 // stubs are attached; The input section may be .init which
3601 // is pasted together with other .init sections to form a
3602 // function. Aligning might insert zero padding resulting in
3603 // sigill. However we do need to increase alignment of the
3604 // output section so that the align_address() on offset in
3605 // set_address_and_size() adds the same padding as the
3606 // align_address() on address in stub_address().
3607 // What's more, we need this alignment for the layout done in
3608 // relaxation_loop_body() so that the output section starts at
3609 // a suitably aligned address.
3610 os->checkpoint_set_addralign(this->stub_align());
3612 if (this->last_plt_size_ != this->plt_size_
3613 || this->last_branch_size_ != this->branch_size_)
3615 this->last_plt_size_ = this->plt_size_;
3616 this->last_branch_size_ = this->branch_size_;
3622 // Add .eh_frame info for this stub section. Unlike other linker
3623 // generated .eh_frame this is added late in the link, because we
3624 // only want the .eh_frame info if this particular stub section is
3627 add_eh_frame(Layout* layout)
3629 if (!this->eh_frame_added_)
3631 if (!parameters->options().ld_generated_unwind_info())
3634 // Since we add stub .eh_frame info late, it must be placed
3635 // after all other linker generated .eh_frame info so that
3636 // merge mapping need not be updated for input sections.
3637 // There is no provision to use a different CIE to that used
3639 if (!this->targ_->has_glink())
3642 layout->add_eh_frame_for_plt(this,
3643 Eh_cie<size>::eh_frame_cie,
3644 sizeof (Eh_cie<size>::eh_frame_cie),
3646 sizeof (default_fde));
3647 this->eh_frame_added_ = true;
3651 Target_powerpc<size, big_endian>*
3657 class Plt_stub_ent_hash;
3658 typedef Unordered_map<Plt_stub_ent, unsigned int,
3659 Plt_stub_ent_hash> Plt_stub_entries;
3661 // Alignment of stub section.
3667 unsigned int min_align = 32;
3668 unsigned int user_align = 1 << parameters->options().plt_align();
3669 return std::max(user_align, min_align);
3672 // Return the plt offset for the given call stub.
3674 plt_off(typename Plt_stub_entries::const_iterator p, bool* is_iplt) const
3676 const Symbol* gsym = p->first.sym_;
3679 *is_iplt = (gsym->type() == elfcpp::STT_GNU_IFUNC
3680 && gsym->can_use_relative_reloc(false));
3681 return gsym->plt_offset();
3686 const Sized_relobj_file<size, big_endian>* relobj = p->first.object_;
3687 unsigned int local_sym_index = p->first.locsym_;
3688 return relobj->local_plt_offset(local_sym_index);
3692 // Size of a given plt call stub.
3694 plt_call_size(typename Plt_stub_entries::const_iterator p) const
3700 Address plt_addr = this->plt_off(p, &is_iplt);
3702 plt_addr += this->targ_->iplt_section()->address();
3704 plt_addr += this->targ_->plt_section()->address();
3705 Address got_addr = this->targ_->got_section()->output_section()->address();
3706 const Powerpc_relobj<size, big_endian>* ppcobj = static_cast
3707 <const Powerpc_relobj<size, big_endian>*>(p->first.object_);
3708 got_addr += ppcobj->toc_base_offset();
3709 Address off = plt_addr - got_addr;
3710 unsigned int bytes = 4 * 4 + 4 * (ha(off) != 0);
3711 if (this->targ_->abiversion() < 2)
3713 bool static_chain = parameters->options().plt_static_chain();
3714 bool thread_safe = this->targ_->plt_thread_safe();
3718 + 4 * (ha(off + 8 + 8 * static_chain) != ha(off)));
3720 unsigned int align = 1 << parameters->options().plt_align();
3722 bytes = (bytes + align - 1) & -align;
3726 // Return long branch stub size.
3728 branch_stub_size(Address to)
3731 = this->stub_address() + this->last_plt_size_ + this->branch_size_;
3732 if (to - loc + (1 << 25) < 2 << 25)
3734 if (size == 64 || !parameters->options().output_is_position_independent())
3741 do_write(Output_file*);
3743 // Plt call stub keys.
3747 Plt_stub_ent(const Symbol* sym)
3748 : sym_(sym), object_(0), addend_(0), locsym_(0)
3751 Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
3752 unsigned int locsym_index)
3753 : sym_(NULL), object_(object), addend_(0), locsym_(locsym_index)
3756 Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
3758 unsigned int r_type,
3760 : sym_(sym), object_(0), addend_(0), locsym_(0)
3763 this->addend_ = addend;
3764 else if (parameters->options().output_is_position_independent()
3765 && r_type == elfcpp::R_PPC_PLTREL24)
3767 this->addend_ = addend;
3768 if (this->addend_ >= 32768)
3769 this->object_ = object;
3773 Plt_stub_ent(const Sized_relobj_file<size, big_endian>* object,
3774 unsigned int locsym_index,
3775 unsigned int r_type,
3777 : sym_(NULL), object_(object), addend_(0), locsym_(locsym_index)
3780 this->addend_ = addend;
3781 else if (parameters->options().output_is_position_independent()
3782 && r_type == elfcpp::R_PPC_PLTREL24)
3783 this->addend_ = addend;
3786 bool operator==(const Plt_stub_ent& that) const
3788 return (this->sym_ == that.sym_
3789 && this->object_ == that.object_
3790 && this->addend_ == that.addend_
3791 && this->locsym_ == that.locsym_);
3795 const Sized_relobj_file<size, big_endian>* object_;
3796 typename elfcpp::Elf_types<size>::Elf_Addr addend_;
3797 unsigned int locsym_;
3800 class Plt_stub_ent_hash
3803 size_t operator()(const Plt_stub_ent& ent) const
3805 return (reinterpret_cast<uintptr_t>(ent.sym_)
3806 ^ reinterpret_cast<uintptr_t>(ent.object_)
3812 // Long branch stub keys.
3813 class Branch_stub_ent
3816 Branch_stub_ent(const Powerpc_relobj<size, big_endian>* obj, Address to)
3817 : dest_(to), toc_base_off_(0)
3820 toc_base_off_ = obj->toc_base_offset();
3823 bool operator==(const Branch_stub_ent& that) const
3825 return (this->dest_ == that.dest_
3827 || this->toc_base_off_ == that.toc_base_off_));
3831 unsigned int toc_base_off_;
3834 class Branch_stub_ent_hash
3837 size_t operator()(const Branch_stub_ent& ent) const
3838 { return ent.dest_ ^ ent.toc_base_off_; }
3841 // In a sane world this would be a global.
3842 Target_powerpc<size, big_endian>* targ_;
3843 // Map sym/object/addend to stub offset.
3844 Plt_stub_entries plt_call_stubs_;
3845 // Map destination address to stub offset.
3846 typedef Unordered_map<Branch_stub_ent, unsigned int,
3847 Branch_stub_ent_hash> Branch_stub_entries;
3848 Branch_stub_entries long_branch_stubs_;
3849 // size of input section
3850 section_size_type orig_data_size_;
3852 section_size_type plt_size_, last_plt_size_, branch_size_, last_branch_size_;
3853 // Whether .eh_frame info has been created for this stub section.
3854 bool eh_frame_added_;
3857 // Make a new stub table, and record.
3859 template<int size, bool big_endian>
3860 Stub_table<size, big_endian>*
3861 Target_powerpc<size, big_endian>::new_stub_table()
3863 Stub_table<size, big_endian>* stub_table
3864 = new Stub_table<size, big_endian>(this);
3865 this->stub_tables_.push_back(stub_table);
3869 // Delayed stub table initialisation, because we create the stub table
3870 // before we know to which section it will be attached.
3872 template<int size, bool big_endian>
3874 Stub_table<size, big_endian>::init(
3875 const Output_section::Input_section* owner,
3876 Output_section* output_section)
3878 this->set_relobj(owner->relobj());
3879 this->set_shndx(owner->shndx());
3880 this->set_addralign(this->relobj()->section_addralign(this->shndx()));
3881 this->set_output_section(output_section);
3882 this->orig_data_size_ = owner->current_data_size();
3884 std::vector<Output_relaxed_input_section*> new_relaxed;
3885 new_relaxed.push_back(this);
3886 output_section->convert_input_sections_to_relaxed_sections(new_relaxed);
3889 // Add a plt call stub, if we do not already have one for this
3890 // sym/object/addend combo.
3892 template<int size, bool big_endian>
3894 Stub_table<size, big_endian>::add_plt_call_entry(
3895 const Sized_relobj_file<size, big_endian>* object,
3897 unsigned int r_type,
3900 Plt_stub_ent ent(object, gsym, r_type, addend);
3901 Address off = this->plt_size_;
3902 std::pair<typename Plt_stub_entries::iterator, bool> p
3903 = this->plt_call_stubs_.insert(std::make_pair(ent, off));
3905 this->plt_size_ = off + this->plt_call_size(p.first);
3908 template<int size, bool big_endian>
3910 Stub_table<size, big_endian>::add_plt_call_entry(
3911 const Sized_relobj_file<size, big_endian>* object,
3912 unsigned int locsym_index,
3913 unsigned int r_type,
3916 Plt_stub_ent ent(object, locsym_index, r_type, addend);
3917 Address off = this->plt_size_;
3918 std::pair<typename Plt_stub_entries::iterator, bool> p
3919 = this->plt_call_stubs_.insert(std::make_pair(ent, off));
3921 this->plt_size_ = off + this->plt_call_size(p.first);
3924 // Find a plt call stub.
3926 template<int size, bool big_endian>
3927 typename Stub_table<size, big_endian>::Address
3928 Stub_table<size, big_endian>::find_plt_call_entry(
3929 const Sized_relobj_file<size, big_endian>* object,
3931 unsigned int r_type,
3932 Address addend) const
3934 Plt_stub_ent ent(object, gsym, r_type, addend);
3935 typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
3936 return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
3939 template<int size, bool big_endian>
3940 typename Stub_table<size, big_endian>::Address
3941 Stub_table<size, big_endian>::find_plt_call_entry(const Symbol* gsym) const
3943 Plt_stub_ent ent(gsym);
3944 typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
3945 return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
3948 template<int size, bool big_endian>
3949 typename Stub_table<size, big_endian>::Address
3950 Stub_table<size, big_endian>::find_plt_call_entry(
3951 const Sized_relobj_file<size, big_endian>* object,
3952 unsigned int locsym_index,
3953 unsigned int r_type,
3954 Address addend) const
3956 Plt_stub_ent ent(object, locsym_index, r_type, addend);
3957 typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
3958 return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
3961 template<int size, bool big_endian>
3962 typename Stub_table<size, big_endian>::Address
3963 Stub_table<size, big_endian>::find_plt_call_entry(
3964 const Sized_relobj_file<size, big_endian>* object,
3965 unsigned int locsym_index) const
3967 Plt_stub_ent ent(object, locsym_index);
3968 typename Plt_stub_entries::const_iterator p = this->plt_call_stubs_.find(ent);
3969 return p == this->plt_call_stubs_.end() ? invalid_address : p->second;
3972 // Add a long branch stub if we don't already have one to given
3975 template<int size, bool big_endian>
3977 Stub_table<size, big_endian>::add_long_branch_entry(
3978 const Powerpc_relobj<size, big_endian>* object,
3981 Branch_stub_ent ent(object, to);
3982 Address off = this->branch_size_;
3983 if (this->long_branch_stubs_.insert(std::make_pair(ent, off)).second)
3985 unsigned int stub_size = this->branch_stub_size(to);
3986 this->branch_size_ = off + stub_size;
3987 if (size == 64 && stub_size != 4)
3988 this->targ_->add_branch_lookup_table(to);
3992 // Find long branch stub.
3994 template<int size, bool big_endian>
3995 typename Stub_table<size, big_endian>::Address
3996 Stub_table<size, big_endian>::find_long_branch_entry(
3997 const Powerpc_relobj<size, big_endian>* object,
4000 Branch_stub_ent ent(object, to);
4001 typename Branch_stub_entries::const_iterator p
4002 = this->long_branch_stubs_.find(ent);
4003 return p == this->long_branch_stubs_.end() ? invalid_address : p->second;
4006 // A class to handle .glink.
4008 template<int size, bool big_endian>
4009 class Output_data_glink : public Output_section_data
4012 static const int pltresolve_size = 16*4;
4014 Output_data_glink(Target_powerpc<size, big_endian>* targ)
4015 : Output_section_data(16), targ_(targ)
4019 add_eh_frame(Layout* layout)
4021 if (!parameters->options().ld_generated_unwind_info())
4026 if (this->targ_->abiversion() < 2)
4027 layout->add_eh_frame_for_plt(this,
4028 Eh_cie<64>::eh_frame_cie,
4029 sizeof (Eh_cie<64>::eh_frame_cie),
4030 glink_eh_frame_fde_64v1,
4031 sizeof (glink_eh_frame_fde_64v1));
4033 layout->add_eh_frame_for_plt(this,
4034 Eh_cie<64>::eh_frame_cie,
4035 sizeof (Eh_cie<64>::eh_frame_cie),
4036 glink_eh_frame_fde_64v2,
4037 sizeof (glink_eh_frame_fde_64v2));
4041 // 32-bit .glink can use the default since the CIE return
4042 // address reg, LR, is valid.
4043 layout->add_eh_frame_for_plt(this,
4044 Eh_cie<32>::eh_frame_cie,
4045 sizeof (Eh_cie<32>::eh_frame_cie),
4047 sizeof (default_fde));
4048 // Except where LR is used in a PIC __glink_PLTresolve.
4049 if (parameters->options().output_is_position_independent())
4050 layout->add_eh_frame_for_plt(this,
4051 Eh_cie<32>::eh_frame_cie,
4052 sizeof (Eh_cie<32>::eh_frame_cie),
4053 glink_eh_frame_fde_32,
4054 sizeof (glink_eh_frame_fde_32));
4059 // Write to a map file.
4061 do_print_to_mapfile(Mapfile* mapfile) const
4062 { mapfile->print_output_data(this, _("** glink")); }
4066 set_final_data_size();
4070 do_write(Output_file*);
4072 // Allows access to .got and .plt for do_write.
4073 Target_powerpc<size, big_endian>* targ_;
4076 template<int size, bool big_endian>
4078 Output_data_glink<size, big_endian>::set_final_data_size()
4080 unsigned int count = this->targ_->plt_entry_count();
4081 section_size_type total = 0;
4087 // space for branch table
4088 total += 4 * (count - 1);
4090 total += -total & 15;
4091 total += this->pltresolve_size;
4095 total += this->pltresolve_size;
4097 // space for branch table
4099 if (this->targ_->abiversion() < 2)
4103 total += 4 * (count - 0x8000);
4108 this->set_data_size(total);
4111 // Write out plt and long branch stub code.
4113 template<int size, bool big_endian>
4115 Stub_table<size, big_endian>::do_write(Output_file* of)
4117 if (this->plt_call_stubs_.empty()
4118 && this->long_branch_stubs_.empty())
4121 const section_size_type start_off = this->offset();
4122 const section_size_type off = this->stub_offset();
4123 const section_size_type oview_size =
4124 convert_to_section_size_type(this->data_size() - (off - start_off));
4125 unsigned char* const oview = of->get_output_view(off, oview_size);
4130 const Output_data_got_powerpc<size, big_endian>* got
4131 = this->targ_->got_section();
4132 Address got_os_addr = got->output_section()->address();
4134 if (!this->plt_call_stubs_.empty())
4136 // The base address of the .plt section.
4137 Address plt_base = this->targ_->plt_section()->address();
4138 Address iplt_base = invalid_address;
4140 // Write out plt call stubs.
4141 typename Plt_stub_entries::const_iterator cs;
4142 for (cs = this->plt_call_stubs_.begin();
4143 cs != this->plt_call_stubs_.end();
4147 Address pltoff = this->plt_off(cs, &is_iplt);
4148 Address plt_addr = pltoff;
4151 if (iplt_base == invalid_address)
4152 iplt_base = this->targ_->iplt_section()->address();
4153 plt_addr += iplt_base;
4156 plt_addr += plt_base;
4157 const Powerpc_relobj<size, big_endian>* ppcobj = static_cast
4158 <const Powerpc_relobj<size, big_endian>*>(cs->first.object_);
4159 Address got_addr = got_os_addr + ppcobj->toc_base_offset();
4160 Address off = plt_addr - got_addr;
4162 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
4163 gold_error(_("%s: linkage table error against `%s'"),
4164 cs->first.object_->name().c_str(),
4165 cs->first.sym_->demangled_name().c_str());
4167 bool plt_load_toc = this->targ_->abiversion() < 2;
4169 = plt_load_toc && parameters->options().plt_static_chain();
4171 = plt_load_toc && this->targ_->plt_thread_safe();
4172 bool use_fake_dep = false;
4173 Address cmp_branch_off = 0;
4176 unsigned int pltindex
4177 = ((pltoff - this->targ_->first_plt_entry_offset())
4178 / this->targ_->plt_entry_size());
4180 = (this->targ_->glink_section()->pltresolve_size
4182 if (pltindex > 32768)
4183 glinkoff += (pltindex - 32768) * 4;
4185 = this->targ_->glink_section()->address() + glinkoff;
4187 = (this->stub_address() + cs->second + 24
4188 + 4 * (ha(off) != 0)
4189 + 4 * (ha(off + 8 + 8 * static_chain) != ha(off))
4190 + 4 * static_chain);
4191 cmp_branch_off = to - from;
4192 use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
4195 p = oview + cs->second;
4198 write_insn<big_endian>(p, std_2_1 + this->targ_->stk_toc());
4200 write_insn<big_endian>(p, addis_11_2 + ha(off));
4202 write_insn<big_endian>(p, ld_12_11 + l(off));
4205 && ha(off + 8 + 8 * static_chain) != ha(off))
4207 write_insn<big_endian>(p, addi_11_11 + l(off));
4211 write_insn<big_endian>(p, mtctr_12);
4217 write_insn<big_endian>(p, xor_2_12_12);
4219 write_insn<big_endian>(p, add_11_11_2);
4222 write_insn<big_endian>(p, ld_2_11 + l(off + 8));
4226 write_insn<big_endian>(p, ld_11_11 + l(off + 16));
4233 write_insn<big_endian>(p, std_2_1 + this->targ_->stk_toc());
4235 write_insn<big_endian>(p, ld_12_2 + l(off));
4238 && ha(off + 8 + 8 * static_chain) != ha(off))
4240 write_insn<big_endian>(p, addi_2_2 + l(off));
4244 write_insn<big_endian>(p, mtctr_12);
4250 write_insn<big_endian>(p, xor_11_12_12);
4252 write_insn<big_endian>(p, add_2_2_11);
4257 write_insn<big_endian>(p, ld_11_2 + l(off + 16));
4260 write_insn<big_endian>(p, ld_2_2 + l(off + 8));
4264 if (thread_safe && !use_fake_dep)
4266 write_insn<big_endian>(p, cmpldi_2_0);
4268 write_insn<big_endian>(p, bnectr_p4);
4270 write_insn<big_endian>(p, b | (cmp_branch_off & 0x3fffffc));
4273 write_insn<big_endian>(p, bctr);
4277 // Write out long branch stubs.
4278 typename Branch_stub_entries::const_iterator bs;
4279 for (bs = this->long_branch_stubs_.begin();
4280 bs != this->long_branch_stubs_.end();
4283 p = oview + this->plt_size_ + bs->second;
4284 Address loc = this->stub_address() + this->plt_size_ + bs->second;
4285 Address delta = bs->first.dest_ - loc;
4286 if (delta + (1 << 25) < 2 << 25)
4287 write_insn<big_endian>(p, b | (delta & 0x3fffffc));
4291 = this->targ_->find_branch_lookup_table(bs->first.dest_);
4292 gold_assert(brlt_addr != invalid_address);
4293 brlt_addr += this->targ_->brlt_section()->address();
4294 Address got_addr = got_os_addr + bs->first.toc_base_off_;
4295 Address brltoff = brlt_addr - got_addr;
4296 if (ha(brltoff) == 0)
4298 write_insn<big_endian>(p, ld_12_2 + l(brltoff)), p += 4;
4302 write_insn<big_endian>(p, addis_11_2 + ha(brltoff)), p += 4;
4303 write_insn<big_endian>(p, ld_12_11 + l(brltoff)), p += 4;
4305 write_insn<big_endian>(p, mtctr_12), p += 4;
4306 write_insn<big_endian>(p, bctr);
4312 if (!this->plt_call_stubs_.empty())
4314 // The base address of the .plt section.
4315 Address plt_base = this->targ_->plt_section()->address();
4316 Address iplt_base = invalid_address;
4317 // The address of _GLOBAL_OFFSET_TABLE_.
4318 Address g_o_t = invalid_address;
4320 // Write out plt call stubs.
4321 typename Plt_stub_entries::const_iterator cs;
4322 for (cs = this->plt_call_stubs_.begin();
4323 cs != this->plt_call_stubs_.end();
4327 Address plt_addr = this->plt_off(cs, &is_iplt);
4330 if (iplt_base == invalid_address)
4331 iplt_base = this->targ_->iplt_section()->address();
4332 plt_addr += iplt_base;
4335 plt_addr += plt_base;
4337 p = oview + cs->second;
4338 if (parameters->options().output_is_position_independent())
4341 const Powerpc_relobj<size, big_endian>* ppcobj
4342 = (static_cast<const Powerpc_relobj<size, big_endian>*>
4343 (cs->first.object_));
4344 if (ppcobj != NULL && cs->first.addend_ >= 32768)
4346 unsigned int got2 = ppcobj->got2_shndx();
4347 got_addr = ppcobj->get_output_section_offset(got2);
4348 gold_assert(got_addr != invalid_address);
4349 got_addr += (ppcobj->output_section(got2)->address()
4350 + cs->first.addend_);
4354 if (g_o_t == invalid_address)
4356 const Output_data_got_powerpc<size, big_endian>* got
4357 = this->targ_->got_section();
4358 g_o_t = got->address() + got->g_o_t();
4363 Address off = plt_addr - got_addr;
4366 write_insn<big_endian>(p + 0, lwz_11_30 + l(off));
4367 write_insn<big_endian>(p + 4, mtctr_11);
4368 write_insn<big_endian>(p + 8, bctr);
4372 write_insn<big_endian>(p + 0, addis_11_30 + ha(off));
4373 write_insn<big_endian>(p + 4, lwz_11_11 + l(off));
4374 write_insn<big_endian>(p + 8, mtctr_11);
4375 write_insn<big_endian>(p + 12, bctr);
4380 write_insn<big_endian>(p + 0, lis_11 + ha(plt_addr));
4381 write_insn<big_endian>(p + 4, lwz_11_11 + l(plt_addr));
4382 write_insn<big_endian>(p + 8, mtctr_11);
4383 write_insn<big_endian>(p + 12, bctr);
4388 // Write out long branch stubs.
4389 typename Branch_stub_entries::const_iterator bs;
4390 for (bs = this->long_branch_stubs_.begin();
4391 bs != this->long_branch_stubs_.end();
4394 p = oview + this->plt_size_ + bs->second;
4395 Address loc = this->stub_address() + this->plt_size_ + bs->second;
4396 Address delta = bs->first.dest_ - loc;
4397 if (delta + (1 << 25) < 2 << 25)
4398 write_insn<big_endian>(p, b | (delta & 0x3fffffc));
4399 else if (!parameters->options().output_is_position_independent())
4401 write_insn<big_endian>(p + 0, lis_12 + ha(bs->first.dest_));
4402 write_insn<big_endian>(p + 4, addi_12_12 + l(bs->first.dest_));
4403 write_insn<big_endian>(p + 8, mtctr_12);
4404 write_insn<big_endian>(p + 12, bctr);
4409 write_insn<big_endian>(p + 0, mflr_0);
4410 write_insn<big_endian>(p + 4, bcl_20_31);
4411 write_insn<big_endian>(p + 8, mflr_12);
4412 write_insn<big_endian>(p + 12, addis_12_12 + ha(delta));
4413 write_insn<big_endian>(p + 16, addi_12_12 + l(delta));
4414 write_insn<big_endian>(p + 20, mtlr_0);
4415 write_insn<big_endian>(p + 24, mtctr_12);
4416 write_insn<big_endian>(p + 28, bctr);
4422 // Write out .glink.
4424 template<int size, bool big_endian>
4426 Output_data_glink<size, big_endian>::do_write(Output_file* of)
4428 const section_size_type off = this->offset();
4429 const section_size_type oview_size =
4430 convert_to_section_size_type(this->data_size());
4431 unsigned char* const oview = of->get_output_view(off, oview_size);
4434 // The base address of the .plt section.
4435 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
4436 Address plt_base = this->targ_->plt_section()->address();
4440 // Write pltresolve stub.
4442 Address after_bcl = this->address() + 16;
4443 Address pltoff = plt_base - after_bcl;
4445 elfcpp::Swap<64, big_endian>::writeval(p, pltoff), p += 8;
4447 if (this->targ_->abiversion() < 2)
4449 write_insn<big_endian>(p, mflr_12), p += 4;
4450 write_insn<big_endian>(p, bcl_20_31), p += 4;
4451 write_insn<big_endian>(p, mflr_11), p += 4;
4452 write_insn<big_endian>(p, ld_2_11 + l(-16)), p += 4;
4453 write_insn<big_endian>(p, mtlr_12), p += 4;
4454 write_insn<big_endian>(p, add_11_2_11), p += 4;
4455 write_insn<big_endian>(p, ld_12_11 + 0), p += 4;
4456 write_insn<big_endian>(p, ld_2_11 + 8), p += 4;
4457 write_insn<big_endian>(p, mtctr_12), p += 4;
4458 write_insn<big_endian>(p, ld_11_11 + 16), p += 4;
4462 write_insn<big_endian>(p, mflr_0), p += 4;
4463 write_insn<big_endian>(p, bcl_20_31), p += 4;
4464 write_insn<big_endian>(p, mflr_11), p += 4;
4465 write_insn<big_endian>(p, ld_2_11 + l(-16)), p += 4;
4466 write_insn<big_endian>(p, mtlr_0), p += 4;
4467 write_insn<big_endian>(p, sub_12_12_11), p += 4;
4468 write_insn<big_endian>(p, add_11_2_11), p += 4;
4469 write_insn<big_endian>(p, addi_0_12 + l(-48)), p += 4;
4470 write_insn<big_endian>(p, ld_12_11 + 0), p += 4;
4471 write_insn<big_endian>(p, srdi_0_0_2), p += 4;
4472 write_insn<big_endian>(p, mtctr_12), p += 4;
4473 write_insn<big_endian>(p, ld_11_11 + 8), p += 4;
4475 write_insn<big_endian>(p, bctr), p += 4;
4476 while (p < oview + this->pltresolve_size)
4477 write_insn<big_endian>(p, nop), p += 4;
4479 // Write lazy link call stubs.
4481 while (p < oview + oview_size)
4483 if (this->targ_->abiversion() < 2)
4487 write_insn<big_endian>(p, li_0_0 + indx), p += 4;
4491 write_insn<big_endian>(p, lis_0_0 + hi(indx)), p += 4;
4492 write_insn<big_endian>(p, ori_0_0_0 + l(indx)), p += 4;
4495 uint32_t branch_off = 8 - (p - oview);
4496 write_insn<big_endian>(p, b + (branch_off & 0x3fffffc)), p += 4;
4502 const Output_data_got_powerpc<size, big_endian>* got
4503 = this->targ_->got_section();
4504 // The address of _GLOBAL_OFFSET_TABLE_.
4505 Address g_o_t = got->address() + got->g_o_t();
4507 // Write out pltresolve branch table.
4509 unsigned int the_end = oview_size - this->pltresolve_size;
4510 unsigned char* end_p = oview + the_end;
4511 while (p < end_p - 8 * 4)
4512 write_insn<big_endian>(p, b + end_p - p), p += 4;
4514 write_insn<big_endian>(p, nop), p += 4;
4516 // Write out pltresolve call stub.
4517 if (parameters->options().output_is_position_independent())
4519 Address res0_off = 0;
4520 Address after_bcl_off = the_end + 12;
4521 Address bcl_res0 = after_bcl_off - res0_off;
4523 write_insn<big_endian>(p + 0, addis_11_11 + ha(bcl_res0));
4524 write_insn<big_endian>(p + 4, mflr_0);
4525 write_insn<big_endian>(p + 8, bcl_20_31);
4526 write_insn<big_endian>(p + 12, addi_11_11 + l(bcl_res0));
4527 write_insn<big_endian>(p + 16, mflr_12);
4528 write_insn<big_endian>(p + 20, mtlr_0);
4529 write_insn<big_endian>(p + 24, sub_11_11_12);
4531 Address got_bcl = g_o_t + 4 - (after_bcl_off + this->address());
4533 write_insn<big_endian>(p + 28, addis_12_12 + ha(got_bcl));
4534 if (ha(got_bcl) == ha(got_bcl + 4))
4536 write_insn<big_endian>(p + 32, lwz_0_12 + l(got_bcl));
4537 write_insn<big_endian>(p + 36, lwz_12_12 + l(got_bcl + 4));
4541 write_insn<big_endian>(p + 32, lwzu_0_12 + l(got_bcl));
4542 write_insn<big_endian>(p + 36, lwz_12_12 + 4);
4544 write_insn<big_endian>(p + 40, mtctr_0);
4545 write_insn<big_endian>(p + 44, add_0_11_11);
4546 write_insn<big_endian>(p + 48, add_11_0_11);
4547 write_insn<big_endian>(p + 52, bctr);
4548 write_insn<big_endian>(p + 56, nop);
4549 write_insn<big_endian>(p + 60, nop);
4553 Address res0 = this->address();
4555 write_insn<big_endian>(p + 0, lis_12 + ha(g_o_t + 4));
4556 write_insn<big_endian>(p + 4, addis_11_11 + ha(-res0));
4557 if (ha(g_o_t + 4) == ha(g_o_t + 8))
4558 write_insn<big_endian>(p + 8, lwz_0_12 + l(g_o_t + 4));
4560 write_insn<big_endian>(p + 8, lwzu_0_12 + l(g_o_t + 4));
4561 write_insn<big_endian>(p + 12, addi_11_11 + l(-res0));
4562 write_insn<big_endian>(p + 16, mtctr_0);
4563 write_insn<big_endian>(p + 20, add_0_11_11);
4564 if (ha(g_o_t + 4) == ha(g_o_t + 8))
4565 write_insn<big_endian>(p + 24, lwz_12_12 + l(g_o_t + 8));
4567 write_insn<big_endian>(p + 24, lwz_12_12 + 4);
4568 write_insn<big_endian>(p + 28, add_11_0_11);
4569 write_insn<big_endian>(p + 32, bctr);
4570 write_insn<big_endian>(p + 36, nop);
4571 write_insn<big_endian>(p + 40, nop);
4572 write_insn<big_endian>(p + 44, nop);
4573 write_insn<big_endian>(p + 48, nop);
4574 write_insn<big_endian>(p + 52, nop);
4575 write_insn<big_endian>(p + 56, nop);
4576 write_insn<big_endian>(p + 60, nop);
4581 of->write_output_view(off, oview_size, oview);
4585 // A class to handle linker generated save/restore functions.
4587 template<int size, bool big_endian>
4588 class Output_data_save_res : public Output_section_data_build
4591 Output_data_save_res(Symbol_table* symtab);
4594 // Write to a map file.
4596 do_print_to_mapfile(Mapfile* mapfile) const
4597 { mapfile->print_output_data(this, _("** save/restore")); }
4600 do_write(Output_file*);
4603 // The maximum size of save/restore contents.
4604 static const unsigned int savres_max = 218*4;
4607 savres_define(Symbol_table* symtab,
4609 unsigned int lo, unsigned int hi,
4610 unsigned char* write_ent(unsigned char*, int),
4611 unsigned char* write_tail(unsigned char*, int));
4613 unsigned char *contents_;
4616 template<bool big_endian>
4617 static unsigned char*
4618 savegpr0(unsigned char* p, int r)
4620 uint32_t insn = std_0_1 + (r << 21) + (1 << 16) - (32 - r) * 8;
4621 write_insn<big_endian>(p, insn);
4625 template<bool big_endian>
4626 static unsigned char*
4627 savegpr0_tail(unsigned char* p, int r)
4629 p = savegpr0<big_endian>(p, r);
4630 uint32_t insn = std_0_1 + 16;
4631 write_insn<big_endian>(p, insn);
4633 write_insn<big_endian>(p, blr);
4637 template<bool big_endian>
4638 static unsigned char*
4639 restgpr0(unsigned char* p, int r)
4641 uint32_t insn = ld_0_1 + (r << 21) + (1 << 16) - (32 - r) * 8;
4642 write_insn<big_endian>(p, insn);
4646 template<bool big_endian>
4647 static unsigned char*
4648 restgpr0_tail(unsigned char* p, int r)
4650 uint32_t insn = ld_0_1 + 16;
4651 write_insn<big_endian>(p, insn);
4653 p = restgpr0<big_endian>(p, r);
4654 write_insn<big_endian>(p, mtlr_0);
4658 p = restgpr0<big_endian>(p, 30);
4659 p = restgpr0<big_endian>(p, 31);
4661 write_insn<big_endian>(p, blr);
4665 template<bool big_endian>
4666 static unsigned char*
4667 savegpr1(unsigned char* p, int r)
4669 uint32_t insn = std_0_12 + (r << 21) + (1 << 16) - (32 - r) * 8;
4670 write_insn<big_endian>(p, insn);
4674 template<bool big_endian>
4675 static unsigned char*
4676 savegpr1_tail(unsigned char* p, int r)
4678 p = savegpr1<big_endian>(p, r);
4679 write_insn<big_endian>(p, blr);
4683 template<bool big_endian>
4684 static unsigned char*
4685 restgpr1(unsigned char* p, int r)
4687 uint32_t insn = ld_0_12 + (r << 21) + (1 << 16) - (32 - r) * 8;
4688 write_insn<big_endian>(p, insn);
4692 template<bool big_endian>
4693 static unsigned char*
4694 restgpr1_tail(unsigned char* p, int r)
4696 p = restgpr1<big_endian>(p, r);
4697 write_insn<big_endian>(p, blr);
4701 template<bool big_endian>
4702 static unsigned char*
4703 savefpr(unsigned char* p, int r)
4705 uint32_t insn = stfd_0_1 + (r << 21) + (1 << 16) - (32 - r) * 8;
4706 write_insn<big_endian>(p, insn);
4710 template<bool big_endian>
4711 static unsigned char*
4712 savefpr0_tail(unsigned char* p, int r)
4714 p = savefpr<big_endian>(p, r);
4715 write_insn<big_endian>(p, std_0_1 + 16);
4717 write_insn<big_endian>(p, blr);
4721 template<bool big_endian>
4722 static unsigned char*
4723 restfpr(unsigned char* p, int r)
4725 uint32_t insn = lfd_0_1 + (r << 21) + (1 << 16) - (32 - r) * 8;
4726 write_insn<big_endian>(p, insn);
4730 template<bool big_endian>
4731 static unsigned char*
4732 restfpr0_tail(unsigned char* p, int r)
4734 write_insn<big_endian>(p, ld_0_1 + 16);
4736 p = restfpr<big_endian>(p, r);
4737 write_insn<big_endian>(p, mtlr_0);
4741 p = restfpr<big_endian>(p, 30);
4742 p = restfpr<big_endian>(p, 31);
4744 write_insn<big_endian>(p, blr);
4748 template<bool big_endian>
4749 static unsigned char*
4750 savefpr1_tail(unsigned char* p, int r)
4752 p = savefpr<big_endian>(p, r);
4753 write_insn<big_endian>(p, blr);
4757 template<bool big_endian>
4758 static unsigned char*
4759 restfpr1_tail(unsigned char* p, int r)
4761 p = restfpr<big_endian>(p, r);
4762 write_insn<big_endian>(p, blr);
4766 template<bool big_endian>
4767 static unsigned char*
4768 savevr(unsigned char* p, int r)
4770 uint32_t insn = li_12_0 + (1 << 16) - (32 - r) * 16;
4771 write_insn<big_endian>(p, insn);
4773 insn = stvx_0_12_0 + (r << 21);
4774 write_insn<big_endian>(p, insn);
4778 template<bool big_endian>
4779 static unsigned char*
4780 savevr_tail(unsigned char* p, int r)
4782 p = savevr<big_endian>(p, r);
4783 write_insn<big_endian>(p, blr);
4787 template<bool big_endian>
4788 static unsigned char*
4789 restvr(unsigned char* p, int r)
4791 uint32_t insn = li_12_0 + (1 << 16) - (32 - r) * 16;
4792 write_insn<big_endian>(p, insn);
4794 insn = lvx_0_12_0 + (r << 21);
4795 write_insn<big_endian>(p, insn);
4799 template<bool big_endian>
4800 static unsigned char*
4801 restvr_tail(unsigned char* p, int r)
4803 p = restvr<big_endian>(p, r);
4804 write_insn<big_endian>(p, blr);
4809 template<int size, bool big_endian>
4810 Output_data_save_res<size, big_endian>::Output_data_save_res(
4811 Symbol_table* symtab)
4812 : Output_section_data_build(4),
4815 this->savres_define(symtab,
4816 "_savegpr0_", 14, 31,
4817 savegpr0<big_endian>, savegpr0_tail<big_endian>);
4818 this->savres_define(symtab,
4819 "_restgpr0_", 14, 29,
4820 restgpr0<big_endian>, restgpr0_tail<big_endian>);
4821 this->savres_define(symtab,
4822 "_restgpr0_", 30, 31,
4823 restgpr0<big_endian>, restgpr0_tail<big_endian>);
4824 this->savres_define(symtab,
4825 "_savegpr1_", 14, 31,
4826 savegpr1<big_endian>, savegpr1_tail<big_endian>);
4827 this->savres_define(symtab,
4828 "_restgpr1_", 14, 31,
4829 restgpr1<big_endian>, restgpr1_tail<big_endian>);
4830 this->savres_define(symtab,
4831 "_savefpr_", 14, 31,
4832 savefpr<big_endian>, savefpr0_tail<big_endian>);
4833 this->savres_define(symtab,
4834 "_restfpr_", 14, 29,
4835 restfpr<big_endian>, restfpr0_tail<big_endian>);
4836 this->savres_define(symtab,
4837 "_restfpr_", 30, 31,
4838 restfpr<big_endian>, restfpr0_tail<big_endian>);
4839 this->savres_define(symtab,
4841 savefpr<big_endian>, savefpr1_tail<big_endian>);
4842 this->savres_define(symtab,
4844 restfpr<big_endian>, restfpr1_tail<big_endian>);
4845 this->savres_define(symtab,
4847 savevr<big_endian>, savevr_tail<big_endian>);
4848 this->savres_define(symtab,
4850 restvr<big_endian>, restvr_tail<big_endian>);
4853 template<int size, bool big_endian>
4855 Output_data_save_res<size, big_endian>::savres_define(
4856 Symbol_table* symtab,
4858 unsigned int lo, unsigned int hi,
4859 unsigned char* write_ent(unsigned char*, int),
4860 unsigned char* write_tail(unsigned char*, int))
4862 size_t len = strlen(name);
4863 bool writing = false;
4866 memcpy(sym, name, len);
4869 for (unsigned int i = lo; i <= hi; i++)
4871 sym[len + 0] = i / 10 + '0';
4872 sym[len + 1] = i % 10 + '0';
4873 Symbol* gsym = symtab->lookup(sym);
4874 bool refd = gsym != NULL && gsym->is_undefined();
4875 writing = writing || refd;
4878 if (this->contents_ == NULL)
4879 this->contents_ = new unsigned char[this->savres_max];
4881 section_size_type value = this->current_data_size();
4882 unsigned char* p = this->contents_ + value;
4884 p = write_ent(p, i);
4886 p = write_tail(p, i);
4887 section_size_type cur_size = p - this->contents_;
4888 this->set_current_data_size(cur_size);
4890 symtab->define_in_output_data(sym, NULL, Symbol_table::PREDEFINED,
4891 this, value, cur_size - value,
4892 elfcpp::STT_FUNC, elfcpp::STB_GLOBAL,
4893 elfcpp::STV_HIDDEN, 0, false, false);
4898 // Write out save/restore.
4900 template<int size, bool big_endian>
4902 Output_data_save_res<size, big_endian>::do_write(Output_file* of)
4904 const section_size_type off = this->offset();
4905 const section_size_type oview_size =
4906 convert_to_section_size_type(this->data_size());
4907 unsigned char* const oview = of->get_output_view(off, oview_size);
4908 memcpy(oview, this->contents_, oview_size);
4909 of->write_output_view(off, oview_size, oview);
4913 // Create the glink section.
4915 template<int size, bool big_endian>
4917 Target_powerpc<size, big_endian>::make_glink_section(Layout* layout)
4919 if (this->glink_ == NULL)
4921 this->glink_ = new Output_data_glink<size, big_endian>(this);
4922 this->glink_->add_eh_frame(layout);
4923 layout->add_output_section_data(".text", elfcpp::SHT_PROGBITS,
4924 elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
4925 this->glink_, ORDER_TEXT, false);
4929 // Create a PLT entry for a global symbol.
4931 template<int size, bool big_endian>
4933 Target_powerpc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
4937 if (gsym->type() == elfcpp::STT_GNU_IFUNC
4938 && gsym->can_use_relative_reloc(false))
4940 if (this->iplt_ == NULL)
4941 this->make_iplt_section(symtab, layout);
4942 this->iplt_->add_ifunc_entry(gsym);
4946 if (this->plt_ == NULL)
4947 this->make_plt_section(symtab, layout);
4948 this->plt_->add_entry(gsym);
4952 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
4954 template<int size, bool big_endian>
4956 Target_powerpc<size, big_endian>::make_local_ifunc_plt_entry(
4957 Symbol_table* symtab,
4959 Sized_relobj_file<size, big_endian>* relobj,
4962 if (this->iplt_ == NULL)
4963 this->make_iplt_section(symtab, layout);
4964 this->iplt_->add_local_ifunc_entry(relobj, r_sym);
4967 // Return the number of entries in the PLT.
4969 template<int size, bool big_endian>
4971 Target_powerpc<size, big_endian>::plt_entry_count() const
4973 if (this->plt_ == NULL)
4975 return this->plt_->entry_count();
4978 // Create a GOT entry for local dynamic __tls_get_addr calls.
4980 template<int size, bool big_endian>
4982 Target_powerpc<size, big_endian>::tlsld_got_offset(
4983 Symbol_table* symtab,
4985 Sized_relobj_file<size, big_endian>* object)
4987 if (this->tlsld_got_offset_ == -1U)
4989 gold_assert(symtab != NULL && layout != NULL && object != NULL);
4990 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
4991 Output_data_got_powerpc<size, big_endian>* got
4992 = this->got_section(symtab, layout);
4993 unsigned int got_offset = got->add_constant_pair(0, 0);
4994 rela_dyn->add_local(object, 0, elfcpp::R_POWERPC_DTPMOD, got,
4996 this->tlsld_got_offset_ = got_offset;
4998 return this->tlsld_got_offset_;
5001 // Get the Reference_flags for a particular relocation.
5003 template<int size, bool big_endian>
5005 Target_powerpc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
5009 case elfcpp::R_POWERPC_NONE:
5010 case elfcpp::R_POWERPC_GNU_VTINHERIT:
5011 case elfcpp::R_POWERPC_GNU_VTENTRY:
5012 case elfcpp::R_PPC64_TOC:
5013 // No symbol reference.
5016 case elfcpp::R_PPC64_ADDR64:
5017 case elfcpp::R_PPC64_UADDR64:
5018 case elfcpp::R_POWERPC_ADDR32:
5019 case elfcpp::R_POWERPC_UADDR32:
5020 case elfcpp::R_POWERPC_ADDR16:
5021 case elfcpp::R_POWERPC_UADDR16:
5022 case elfcpp::R_POWERPC_ADDR16_LO:
5023 case elfcpp::R_POWERPC_ADDR16_HI:
5024 case elfcpp::R_POWERPC_ADDR16_HA:
5025 return Symbol::ABSOLUTE_REF;
5027 case elfcpp::R_POWERPC_ADDR24:
5028 case elfcpp::R_POWERPC_ADDR14:
5029 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
5030 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
5031 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
5033 case elfcpp::R_PPC64_REL64:
5034 case elfcpp::R_POWERPC_REL32:
5035 case elfcpp::R_PPC_LOCAL24PC:
5036 case elfcpp::R_POWERPC_REL16:
5037 case elfcpp::R_POWERPC_REL16_LO:
5038 case elfcpp::R_POWERPC_REL16_HI:
5039 case elfcpp::R_POWERPC_REL16_HA:
5040 return Symbol::RELATIVE_REF;
5042 case elfcpp::R_POWERPC_REL24:
5043 case elfcpp::R_PPC_PLTREL24:
5044 case elfcpp::R_POWERPC_REL14:
5045 case elfcpp::R_POWERPC_REL14_BRTAKEN:
5046 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
5047 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
5049 case elfcpp::R_POWERPC_GOT16:
5050 case elfcpp::R_POWERPC_GOT16_LO:
5051 case elfcpp::R_POWERPC_GOT16_HI:
5052 case elfcpp::R_POWERPC_GOT16_HA:
5053 case elfcpp::R_PPC64_GOT16_DS:
5054 case elfcpp::R_PPC64_GOT16_LO_DS:
5055 case elfcpp::R_PPC64_TOC16:
5056 case elfcpp::R_PPC64_TOC16_LO:
5057 case elfcpp::R_PPC64_TOC16_HI:
5058 case elfcpp::R_PPC64_TOC16_HA:
5059 case elfcpp::R_PPC64_TOC16_DS:
5060 case elfcpp::R_PPC64_TOC16_LO_DS:
5062 return Symbol::ABSOLUTE_REF;
5064 case elfcpp::R_POWERPC_GOT_TPREL16:
5065 case elfcpp::R_POWERPC_TLS:
5066 return Symbol::TLS_REF;
5068 case elfcpp::R_POWERPC_COPY:
5069 case elfcpp::R_POWERPC_GLOB_DAT:
5070 case elfcpp::R_POWERPC_JMP_SLOT:
5071 case elfcpp::R_POWERPC_RELATIVE:
5072 case elfcpp::R_POWERPC_DTPMOD:
5074 // Not expected. We will give an error later.
5079 // Report an unsupported relocation against a local symbol.
5081 template<int size, bool big_endian>
5083 Target_powerpc<size, big_endian>::Scan::unsupported_reloc_local(
5084 Sized_relobj_file<size, big_endian>* object,
5085 unsigned int r_type)
5087 gold_error(_("%s: unsupported reloc %u against local symbol"),
5088 object->name().c_str(), r_type);
5091 // We are about to emit a dynamic relocation of type R_TYPE. If the
5092 // dynamic linker does not support it, issue an error.
5094 template<int size, bool big_endian>
5096 Target_powerpc<size, big_endian>::Scan::check_non_pic(Relobj* object,
5097 unsigned int r_type)
5099 gold_assert(r_type != elfcpp::R_POWERPC_NONE);
5101 // These are the relocation types supported by glibc for both 32-bit
5102 // and 64-bit powerpc.
5105 case elfcpp::R_POWERPC_NONE:
5106 case elfcpp::R_POWERPC_RELATIVE:
5107 case elfcpp::R_POWERPC_GLOB_DAT:
5108 case elfcpp::R_POWERPC_DTPMOD:
5109 case elfcpp::R_POWERPC_DTPREL:
5110 case elfcpp::R_POWERPC_TPREL:
5111 case elfcpp::R_POWERPC_JMP_SLOT:
5112 case elfcpp::R_POWERPC_COPY:
5113 case elfcpp::R_POWERPC_IRELATIVE:
5114 case elfcpp::R_POWERPC_ADDR32:
5115 case elfcpp::R_POWERPC_UADDR32:
5116 case elfcpp::R_POWERPC_ADDR24:
5117 case elfcpp::R_POWERPC_ADDR16:
5118 case elfcpp::R_POWERPC_UADDR16:
5119 case elfcpp::R_POWERPC_ADDR16_LO:
5120 case elfcpp::R_POWERPC_ADDR16_HI:
5121 case elfcpp::R_POWERPC_ADDR16_HA:
5122 case elfcpp::R_POWERPC_ADDR14:
5123 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
5124 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
5125 case elfcpp::R_POWERPC_REL32:
5126 case elfcpp::R_POWERPC_REL24:
5127 case elfcpp::R_POWERPC_TPREL16:
5128 case elfcpp::R_POWERPC_TPREL16_LO:
5129 case elfcpp::R_POWERPC_TPREL16_HI:
5130 case elfcpp::R_POWERPC_TPREL16_HA:
5141 // These are the relocation types supported only on 64-bit.
5142 case elfcpp::R_PPC64_ADDR64:
5143 case elfcpp::R_PPC64_UADDR64:
5144 case elfcpp::R_PPC64_JMP_IREL:
5145 case elfcpp::R_PPC64_ADDR16_DS:
5146 case elfcpp::R_PPC64_ADDR16_LO_DS:
5147 case elfcpp::R_PPC64_ADDR16_HIGH:
5148 case elfcpp::R_PPC64_ADDR16_HIGHA:
5149 case elfcpp::R_PPC64_ADDR16_HIGHER:
5150 case elfcpp::R_PPC64_ADDR16_HIGHEST:
5151 case elfcpp::R_PPC64_ADDR16_HIGHERA:
5152 case elfcpp::R_PPC64_ADDR16_HIGHESTA:
5153 case elfcpp::R_PPC64_REL64:
5154 case elfcpp::R_POWERPC_ADDR30:
5155 case elfcpp::R_PPC64_TPREL16_DS:
5156 case elfcpp::R_PPC64_TPREL16_LO_DS:
5157 case elfcpp::R_PPC64_TPREL16_HIGH:
5158 case elfcpp::R_PPC64_TPREL16_HIGHA:
5159 case elfcpp::R_PPC64_TPREL16_HIGHER:
5160 case elfcpp::R_PPC64_TPREL16_HIGHEST:
5161 case elfcpp::R_PPC64_TPREL16_HIGHERA:
5162 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
5173 // These are the relocation types supported only on 32-bit.
5174 // ??? glibc ld.so doesn't need to support these.
5175 case elfcpp::R_POWERPC_DTPREL16:
5176 case elfcpp::R_POWERPC_DTPREL16_LO:
5177 case elfcpp::R_POWERPC_DTPREL16_HI:
5178 case elfcpp::R_POWERPC_DTPREL16_HA:
5186 // This prevents us from issuing more than one error per reloc
5187 // section. But we can still wind up issuing more than one
5188 // error per object file.
5189 if (this->issued_non_pic_error_)
5191 gold_assert(parameters->options().output_is_position_independent());
5192 object->error(_("requires unsupported dynamic reloc; "
5193 "recompile with -fPIC"));
5194 this->issued_non_pic_error_ = true;
5198 // Return whether we need to make a PLT entry for a relocation of the
5199 // given type against a STT_GNU_IFUNC symbol.
5201 template<int size, bool big_endian>
5203 Target_powerpc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
5204 Sized_relobj_file<size, big_endian>* object,
5205 unsigned int r_type,
5208 // In non-pic code any reference will resolve to the plt call stub
5209 // for the ifunc symbol.
5210 if (size == 32 && !parameters->options().output_is_position_independent())
5215 // Word size refs from data sections are OK, but don't need a PLT entry.
5216 case elfcpp::R_POWERPC_ADDR32:
5217 case elfcpp::R_POWERPC_UADDR32:
5222 case elfcpp::R_PPC64_ADDR64:
5223 case elfcpp::R_PPC64_UADDR64:
5228 // GOT refs are good, but also don't need a PLT entry.
5229 case elfcpp::R_POWERPC_GOT16:
5230 case elfcpp::R_POWERPC_GOT16_LO:
5231 case elfcpp::R_POWERPC_GOT16_HI:
5232 case elfcpp::R_POWERPC_GOT16_HA:
5233 case elfcpp::R_PPC64_GOT16_DS:
5234 case elfcpp::R_PPC64_GOT16_LO_DS:
5237 // Function calls are good, and these do need a PLT entry.
5238 case elfcpp::R_POWERPC_ADDR24:
5239 case elfcpp::R_POWERPC_ADDR14:
5240 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
5241 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
5242 case elfcpp::R_POWERPC_REL24:
5243 case elfcpp::R_PPC_PLTREL24:
5244 case elfcpp::R_POWERPC_REL14:
5245 case elfcpp::R_POWERPC_REL14_BRTAKEN:
5246 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
5253 // Anything else is a problem.
5254 // If we are building a static executable, the libc startup function
5255 // responsible for applying indirect function relocations is going
5256 // to complain about the reloc type.
5257 // If we are building a dynamic executable, we will have a text
5258 // relocation. The dynamic loader will set the text segment
5259 // writable and non-executable to apply text relocations. So we'll
5260 // segfault when trying to run the indirection function to resolve
5263 gold_error(_("%s: unsupported reloc %u for IFUNC symbol"),
5264 object->name().c_str(), r_type);
5268 // Scan a relocation for a local symbol.
5270 template<int size, bool big_endian>
5272 Target_powerpc<size, big_endian>::Scan::local(
5273 Symbol_table* symtab,
5275 Target_powerpc<size, big_endian>* target,
5276 Sized_relobj_file<size, big_endian>* object,
5277 unsigned int data_shndx,
5278 Output_section* output_section,
5279 const elfcpp::Rela<size, big_endian>& reloc,
5280 unsigned int r_type,
5281 const elfcpp::Sym<size, big_endian>& lsym,
5284 this->maybe_skip_tls_get_addr_call(r_type, NULL);
5286 if ((size == 64 && r_type == elfcpp::R_PPC64_TLSGD)
5287 || (size == 32 && r_type == elfcpp::R_PPC_TLSGD))
5289 this->expect_tls_get_addr_call();
5290 const tls::Tls_optimization tls_type = target->optimize_tls_gd(true);
5291 if (tls_type != tls::TLSOPT_NONE)
5292 this->skip_next_tls_get_addr_call();
5294 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSLD)
5295 || (size == 32 && r_type == elfcpp::R_PPC_TLSLD))
5297 this->expect_tls_get_addr_call();
5298 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
5299 if (tls_type != tls::TLSOPT_NONE)
5300 this->skip_next_tls_get_addr_call();
5303 Powerpc_relobj<size, big_endian>* ppc_object
5304 = static_cast<Powerpc_relobj<size, big_endian>*>(object);
5309 && data_shndx == ppc_object->opd_shndx()
5310 && r_type == elfcpp::R_PPC64_ADDR64)
5311 ppc_object->set_opd_discard(reloc.get_r_offset());
5315 // A local STT_GNU_IFUNC symbol may require a PLT entry.
5316 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
5317 if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type, true))
5319 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5320 target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(),
5321 r_type, r_sym, reloc.get_r_addend());
5322 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
5327 case elfcpp::R_POWERPC_NONE:
5328 case elfcpp::R_POWERPC_GNU_VTINHERIT:
5329 case elfcpp::R_POWERPC_GNU_VTENTRY:
5330 case elfcpp::R_PPC64_TOCSAVE:
5331 case elfcpp::R_POWERPC_TLS:
5334 case elfcpp::R_PPC64_TOC:
5336 Output_data_got_powerpc<size, big_endian>* got
5337 = target->got_section(symtab, layout);
5338 if (parameters->options().output_is_position_independent())
5340 Address off = reloc.get_r_offset();
5342 && data_shndx == ppc_object->opd_shndx()
5343 && ppc_object->get_opd_discard(off - 8))
5346 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5347 Powerpc_relobj<size, big_endian>* symobj = ppc_object;
5348 rela_dyn->add_output_section_relative(got->output_section(),
5349 elfcpp::R_POWERPC_RELATIVE,
5351 object, data_shndx, off,
5352 symobj->toc_base_offset());
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_ADDR24:
5362 case elfcpp::R_POWERPC_ADDR16:
5363 case elfcpp::R_POWERPC_ADDR16_LO:
5364 case elfcpp::R_POWERPC_ADDR16_HI:
5365 case elfcpp::R_POWERPC_ADDR16_HA:
5366 case elfcpp::R_POWERPC_UADDR16:
5367 case elfcpp::R_PPC64_ADDR16_HIGH:
5368 case elfcpp::R_PPC64_ADDR16_HIGHA:
5369 case elfcpp::R_PPC64_ADDR16_HIGHER:
5370 case elfcpp::R_PPC64_ADDR16_HIGHERA:
5371 case elfcpp::R_PPC64_ADDR16_HIGHEST:
5372 case elfcpp::R_PPC64_ADDR16_HIGHESTA:
5373 case elfcpp::R_PPC64_ADDR16_DS:
5374 case elfcpp::R_PPC64_ADDR16_LO_DS:
5375 case elfcpp::R_POWERPC_ADDR14:
5376 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
5377 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
5378 // If building a shared library (or a position-independent
5379 // executable), we need to create a dynamic relocation for
5381 if (parameters->options().output_is_position_independent()
5382 || (size == 64 && is_ifunc))
5384 Reloc_section* rela_dyn = target->rela_dyn_section(symtab, layout,
5386 if ((size == 32 && r_type == elfcpp::R_POWERPC_ADDR32)
5387 || (size == 64 && r_type == elfcpp::R_PPC64_ADDR64))
5389 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5390 unsigned int dynrel = (is_ifunc ? elfcpp::R_POWERPC_IRELATIVE
5391 : elfcpp::R_POWERPC_RELATIVE);
5392 rela_dyn->add_local_relative(object, r_sym, dynrel,
5393 output_section, data_shndx,
5394 reloc.get_r_offset(),
5395 reloc.get_r_addend(), false);
5399 check_non_pic(object, r_type);
5400 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5401 rela_dyn->add_local(object, r_sym, r_type, output_section,
5402 data_shndx, reloc.get_r_offset(),
5403 reloc.get_r_addend());
5408 case elfcpp::R_POWERPC_REL24:
5409 case elfcpp::R_PPC_PLTREL24:
5410 case elfcpp::R_PPC_LOCAL24PC:
5411 case elfcpp::R_POWERPC_REL14:
5412 case elfcpp::R_POWERPC_REL14_BRTAKEN:
5413 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
5415 target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(),
5416 r_type, elfcpp::elf_r_sym<size>(reloc.get_r_info()),
5417 reloc.get_r_addend());
5420 case elfcpp::R_PPC64_REL64:
5421 case elfcpp::R_POWERPC_REL32:
5422 case elfcpp::R_POWERPC_REL16:
5423 case elfcpp::R_POWERPC_REL16_LO:
5424 case elfcpp::R_POWERPC_REL16_HI:
5425 case elfcpp::R_POWERPC_REL16_HA:
5426 case elfcpp::R_POWERPC_SECTOFF:
5427 case elfcpp::R_POWERPC_SECTOFF_LO:
5428 case elfcpp::R_POWERPC_SECTOFF_HI:
5429 case elfcpp::R_POWERPC_SECTOFF_HA:
5430 case elfcpp::R_PPC64_SECTOFF_DS:
5431 case elfcpp::R_PPC64_SECTOFF_LO_DS:
5432 case elfcpp::R_POWERPC_TPREL16:
5433 case elfcpp::R_POWERPC_TPREL16_LO:
5434 case elfcpp::R_POWERPC_TPREL16_HI:
5435 case elfcpp::R_POWERPC_TPREL16_HA:
5436 case elfcpp::R_PPC64_TPREL16_DS:
5437 case elfcpp::R_PPC64_TPREL16_LO_DS:
5438 case elfcpp::R_PPC64_TPREL16_HIGH:
5439 case elfcpp::R_PPC64_TPREL16_HIGHA:
5440 case elfcpp::R_PPC64_TPREL16_HIGHER:
5441 case elfcpp::R_PPC64_TPREL16_HIGHERA:
5442 case elfcpp::R_PPC64_TPREL16_HIGHEST:
5443 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
5444 case elfcpp::R_POWERPC_DTPREL16:
5445 case elfcpp::R_POWERPC_DTPREL16_LO:
5446 case elfcpp::R_POWERPC_DTPREL16_HI:
5447 case elfcpp::R_POWERPC_DTPREL16_HA:
5448 case elfcpp::R_PPC64_DTPREL16_DS:
5449 case elfcpp::R_PPC64_DTPREL16_LO_DS:
5450 case elfcpp::R_PPC64_DTPREL16_HIGH:
5451 case elfcpp::R_PPC64_DTPREL16_HIGHA:
5452 case elfcpp::R_PPC64_DTPREL16_HIGHER:
5453 case elfcpp::R_PPC64_DTPREL16_HIGHERA:
5454 case elfcpp::R_PPC64_DTPREL16_HIGHEST:
5455 case elfcpp::R_PPC64_DTPREL16_HIGHESTA:
5456 case elfcpp::R_PPC64_TLSGD:
5457 case elfcpp::R_PPC64_TLSLD:
5460 case elfcpp::R_POWERPC_GOT16:
5461 case elfcpp::R_POWERPC_GOT16_LO:
5462 case elfcpp::R_POWERPC_GOT16_HI:
5463 case elfcpp::R_POWERPC_GOT16_HA:
5464 case elfcpp::R_PPC64_GOT16_DS:
5465 case elfcpp::R_PPC64_GOT16_LO_DS:
5467 // The symbol requires a GOT entry.
5468 Output_data_got_powerpc<size, big_endian>* got
5469 = target->got_section(symtab, layout);
5470 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5472 if (!parameters->options().output_is_position_independent())
5474 if (size == 32 && is_ifunc)
5475 got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
5477 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
5479 else if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
5481 // If we are generating a shared object or a pie, this
5482 // symbol's GOT entry will be set by a dynamic relocation.
5484 off = got->add_constant(0);
5485 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
5487 Reloc_section* rela_dyn = target->rela_dyn_section(symtab, layout,
5489 unsigned int dynrel = (is_ifunc ? elfcpp::R_POWERPC_IRELATIVE
5490 : elfcpp::R_POWERPC_RELATIVE);
5491 rela_dyn->add_local_relative(object, r_sym, dynrel,
5492 got, off, 0, false);
5497 case elfcpp::R_PPC64_TOC16:
5498 case elfcpp::R_PPC64_TOC16_LO:
5499 case elfcpp::R_PPC64_TOC16_HI:
5500 case elfcpp::R_PPC64_TOC16_HA:
5501 case elfcpp::R_PPC64_TOC16_DS:
5502 case elfcpp::R_PPC64_TOC16_LO_DS:
5503 // We need a GOT section.
5504 target->got_section(symtab, layout);
5507 case elfcpp::R_POWERPC_GOT_TLSGD16:
5508 case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
5509 case elfcpp::R_POWERPC_GOT_TLSGD16_HI:
5510 case elfcpp::R_POWERPC_GOT_TLSGD16_HA:
5512 const tls::Tls_optimization tls_type = target->optimize_tls_gd(true);
5513 if (tls_type == tls::TLSOPT_NONE)
5515 Output_data_got_powerpc<size, big_endian>* got
5516 = target->got_section(symtab, layout);
5517 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5518 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5519 got->add_local_tls_pair(object, r_sym, GOT_TYPE_TLSGD,
5520 rela_dyn, elfcpp::R_POWERPC_DTPMOD);
5522 else if (tls_type == tls::TLSOPT_TO_LE)
5524 // no GOT relocs needed for Local Exec.
5531 case elfcpp::R_POWERPC_GOT_TLSLD16:
5532 case elfcpp::R_POWERPC_GOT_TLSLD16_LO:
5533 case elfcpp::R_POWERPC_GOT_TLSLD16_HI:
5534 case elfcpp::R_POWERPC_GOT_TLSLD16_HA:
5536 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
5537 if (tls_type == tls::TLSOPT_NONE)
5538 target->tlsld_got_offset(symtab, layout, object);
5539 else if (tls_type == tls::TLSOPT_TO_LE)
5541 // no GOT relocs needed for Local Exec.
5542 if (parameters->options().emit_relocs())
5544 Output_section* os = layout->tls_segment()->first_section();
5545 gold_assert(os != NULL);
5546 os->set_needs_symtab_index();
5554 case elfcpp::R_POWERPC_GOT_DTPREL16:
5555 case elfcpp::R_POWERPC_GOT_DTPREL16_LO:
5556 case elfcpp::R_POWERPC_GOT_DTPREL16_HI:
5557 case elfcpp::R_POWERPC_GOT_DTPREL16_HA:
5559 Output_data_got_powerpc<size, big_endian>* got
5560 = target->got_section(symtab, layout);
5561 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5562 got->add_local_tls(object, r_sym, GOT_TYPE_DTPREL);
5566 case elfcpp::R_POWERPC_GOT_TPREL16:
5567 case elfcpp::R_POWERPC_GOT_TPREL16_LO:
5568 case elfcpp::R_POWERPC_GOT_TPREL16_HI:
5569 case elfcpp::R_POWERPC_GOT_TPREL16_HA:
5571 const tls::Tls_optimization tls_type = target->optimize_tls_ie(true);
5572 if (tls_type == tls::TLSOPT_NONE)
5574 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
5575 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TPREL))
5577 Output_data_got_powerpc<size, big_endian>* got
5578 = target->got_section(symtab, layout);
5579 unsigned int off = got->add_constant(0);
5580 object->set_local_got_offset(r_sym, GOT_TYPE_TPREL, off);
5582 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5583 rela_dyn->add_symbolless_local_addend(object, r_sym,
5584 elfcpp::R_POWERPC_TPREL,
5588 else if (tls_type == tls::TLSOPT_TO_LE)
5590 // no GOT relocs needed for Local Exec.
5598 unsupported_reloc_local(object, r_type);
5604 case elfcpp::R_POWERPC_GOT_TLSLD16:
5605 case elfcpp::R_POWERPC_GOT_TLSGD16:
5606 case elfcpp::R_POWERPC_GOT_TPREL16:
5607 case elfcpp::R_POWERPC_GOT_DTPREL16:
5608 case elfcpp::R_POWERPC_GOT16:
5609 case elfcpp::R_PPC64_GOT16_DS:
5610 case elfcpp::R_PPC64_TOC16:
5611 case elfcpp::R_PPC64_TOC16_DS:
5612 ppc_object->set_has_small_toc_reloc();
5618 // Report an unsupported relocation against a global symbol.
5620 template<int size, bool big_endian>
5622 Target_powerpc<size, big_endian>::Scan::unsupported_reloc_global(
5623 Sized_relobj_file<size, big_endian>* object,
5624 unsigned int r_type,
5627 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
5628 object->name().c_str(), r_type, gsym->demangled_name().c_str());
5631 // Scan a relocation for a global symbol.
5633 template<int size, bool big_endian>
5635 Target_powerpc<size, big_endian>::Scan::global(
5636 Symbol_table* symtab,
5638 Target_powerpc<size, big_endian>* target,
5639 Sized_relobj_file<size, big_endian>* object,
5640 unsigned int data_shndx,
5641 Output_section* output_section,
5642 const elfcpp::Rela<size, big_endian>& reloc,
5643 unsigned int r_type,
5646 if (this->maybe_skip_tls_get_addr_call(r_type, gsym) == Track_tls::SKIP)
5649 if ((size == 64 && r_type == elfcpp::R_PPC64_TLSGD)
5650 || (size == 32 && r_type == elfcpp::R_PPC_TLSGD))
5652 this->expect_tls_get_addr_call();
5653 const bool final = gsym->final_value_is_known();
5654 const tls::Tls_optimization tls_type = target->optimize_tls_gd(final);
5655 if (tls_type != tls::TLSOPT_NONE)
5656 this->skip_next_tls_get_addr_call();
5658 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSLD)
5659 || (size == 32 && r_type == elfcpp::R_PPC_TLSLD))
5661 this->expect_tls_get_addr_call();
5662 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
5663 if (tls_type != tls::TLSOPT_NONE)
5664 this->skip_next_tls_get_addr_call();
5667 Powerpc_relobj<size, big_endian>* ppc_object
5668 = static_cast<Powerpc_relobj<size, big_endian>*>(object);
5670 // A STT_GNU_IFUNC symbol may require a PLT entry.
5671 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
5672 if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type, true))
5674 target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(),
5675 r_type, elfcpp::elf_r_sym<size>(reloc.get_r_info()),
5676 reloc.get_r_addend());
5677 target->make_plt_entry(symtab, layout, gsym);
5682 case elfcpp::R_POWERPC_NONE:
5683 case elfcpp::R_POWERPC_GNU_VTINHERIT:
5684 case elfcpp::R_POWERPC_GNU_VTENTRY:
5685 case elfcpp::R_PPC_LOCAL24PC:
5686 case elfcpp::R_POWERPC_TLS:
5689 case elfcpp::R_PPC64_TOC:
5691 Output_data_got_powerpc<size, big_endian>* got
5692 = target->got_section(symtab, layout);
5693 if (parameters->options().output_is_position_independent())
5695 Address off = reloc.get_r_offset();
5697 && data_shndx == ppc_object->opd_shndx()
5698 && ppc_object->get_opd_discard(off - 8))
5701 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5702 Powerpc_relobj<size, big_endian>* symobj = ppc_object;
5703 if (data_shndx != ppc_object->opd_shndx())
5704 symobj = static_cast
5705 <Powerpc_relobj<size, big_endian>*>(gsym->object());
5706 rela_dyn->add_output_section_relative(got->output_section(),
5707 elfcpp::R_POWERPC_RELATIVE,
5709 object, data_shndx, off,
5710 symobj->toc_base_offset());
5715 case elfcpp::R_PPC64_ADDR64:
5717 && data_shndx == ppc_object->opd_shndx()
5718 && (gsym->is_defined_in_discarded_section()
5719 || gsym->object() != object))
5721 ppc_object->set_opd_discard(reloc.get_r_offset());
5725 case elfcpp::R_PPC64_UADDR64:
5726 case elfcpp::R_POWERPC_ADDR32:
5727 case elfcpp::R_POWERPC_UADDR32:
5728 case elfcpp::R_POWERPC_ADDR24:
5729 case elfcpp::R_POWERPC_ADDR16:
5730 case elfcpp::R_POWERPC_ADDR16_LO:
5731 case elfcpp::R_POWERPC_ADDR16_HI:
5732 case elfcpp::R_POWERPC_ADDR16_HA:
5733 case elfcpp::R_POWERPC_UADDR16:
5734 case elfcpp::R_PPC64_ADDR16_HIGH:
5735 case elfcpp::R_PPC64_ADDR16_HIGHA:
5736 case elfcpp::R_PPC64_ADDR16_HIGHER:
5737 case elfcpp::R_PPC64_ADDR16_HIGHERA:
5738 case elfcpp::R_PPC64_ADDR16_HIGHEST:
5739 case elfcpp::R_PPC64_ADDR16_HIGHESTA:
5740 case elfcpp::R_PPC64_ADDR16_DS:
5741 case elfcpp::R_PPC64_ADDR16_LO_DS:
5742 case elfcpp::R_POWERPC_ADDR14:
5743 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
5744 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
5746 // Make a PLT entry if necessary.
5747 if (gsym->needs_plt_entry())
5751 target->push_branch(ppc_object, data_shndx,
5752 reloc.get_r_offset(), r_type,
5753 elfcpp::elf_r_sym<size>(reloc.get_r_info()),
5754 reloc.get_r_addend());
5755 target->make_plt_entry(symtab, layout, gsym);
5757 // Since this is not a PC-relative relocation, we may be
5758 // taking the address of a function. In that case we need to
5759 // set the entry in the dynamic symbol table to the address of
5760 // the PLT call stub.
5762 && gsym->is_from_dynobj()
5763 && !parameters->options().output_is_position_independent())
5764 gsym->set_needs_dynsym_value();
5766 // Make a dynamic relocation if necessary.
5767 if (needs_dynamic_reloc<size>(gsym, Scan::get_reference_flags(r_type))
5768 || (size == 64 && is_ifunc))
5770 if (gsym->may_need_copy_reloc())
5772 target->copy_reloc(symtab, layout, object,
5773 data_shndx, output_section, gsym, reloc);
5775 else if ((size == 32
5776 && r_type == elfcpp::R_POWERPC_ADDR32
5777 && gsym->can_use_relative_reloc(false)
5778 && !(gsym->visibility() == elfcpp::STV_PROTECTED
5779 && parameters->options().shared()))
5781 && r_type == elfcpp::R_PPC64_ADDR64
5782 && (gsym->can_use_relative_reloc(false)
5783 || data_shndx == ppc_object->opd_shndx())))
5785 Reloc_section* rela_dyn
5786 = target->rela_dyn_section(symtab, layout, is_ifunc);
5787 unsigned int dynrel = (is_ifunc ? elfcpp::R_POWERPC_IRELATIVE
5788 : elfcpp::R_POWERPC_RELATIVE);
5789 rela_dyn->add_symbolless_global_addend(
5790 gsym, dynrel, output_section, object, data_shndx,
5791 reloc.get_r_offset(), reloc.get_r_addend());
5795 Reloc_section* rela_dyn
5796 = target->rela_dyn_section(symtab, layout, is_ifunc);
5797 check_non_pic(object, r_type);
5798 rela_dyn->add_global(gsym, r_type, output_section,
5800 reloc.get_r_offset(),
5801 reloc.get_r_addend());
5807 case elfcpp::R_PPC_PLTREL24:
5808 case elfcpp::R_POWERPC_REL24:
5811 target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(),
5813 elfcpp::elf_r_sym<size>(reloc.get_r_info()),
5814 reloc.get_r_addend());
5815 if (gsym->needs_plt_entry()
5816 || (!gsym->final_value_is_known()
5817 && (gsym->is_undefined()
5818 || gsym->is_from_dynobj()
5819 || gsym->is_preemptible())))
5820 target->make_plt_entry(symtab, layout, gsym);
5824 case elfcpp::R_PPC64_REL64:
5825 case elfcpp::R_POWERPC_REL32:
5826 // Make a dynamic relocation if necessary.
5827 if (needs_dynamic_reloc<size>(gsym, Scan::get_reference_flags(r_type)))
5829 if (gsym->may_need_copy_reloc())
5831 target->copy_reloc(symtab, layout, object,
5832 data_shndx, output_section, gsym,
5837 Reloc_section* rela_dyn
5838 = target->rela_dyn_section(symtab, layout, is_ifunc);
5839 check_non_pic(object, r_type);
5840 rela_dyn->add_global(gsym, r_type, output_section, object,
5841 data_shndx, reloc.get_r_offset(),
5842 reloc.get_r_addend());
5847 case elfcpp::R_POWERPC_REL14:
5848 case elfcpp::R_POWERPC_REL14_BRTAKEN:
5849 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
5851 target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(),
5852 r_type, elfcpp::elf_r_sym<size>(reloc.get_r_info()),
5853 reloc.get_r_addend());
5856 case elfcpp::R_POWERPC_REL16:
5857 case elfcpp::R_POWERPC_REL16_LO:
5858 case elfcpp::R_POWERPC_REL16_HI:
5859 case elfcpp::R_POWERPC_REL16_HA:
5860 case elfcpp::R_POWERPC_SECTOFF:
5861 case elfcpp::R_POWERPC_SECTOFF_LO:
5862 case elfcpp::R_POWERPC_SECTOFF_HI:
5863 case elfcpp::R_POWERPC_SECTOFF_HA:
5864 case elfcpp::R_PPC64_SECTOFF_DS:
5865 case elfcpp::R_PPC64_SECTOFF_LO_DS:
5866 case elfcpp::R_POWERPC_TPREL16:
5867 case elfcpp::R_POWERPC_TPREL16_LO:
5868 case elfcpp::R_POWERPC_TPREL16_HI:
5869 case elfcpp::R_POWERPC_TPREL16_HA:
5870 case elfcpp::R_PPC64_TPREL16_DS:
5871 case elfcpp::R_PPC64_TPREL16_LO_DS:
5872 case elfcpp::R_PPC64_TPREL16_HIGH:
5873 case elfcpp::R_PPC64_TPREL16_HIGHA:
5874 case elfcpp::R_PPC64_TPREL16_HIGHER:
5875 case elfcpp::R_PPC64_TPREL16_HIGHERA:
5876 case elfcpp::R_PPC64_TPREL16_HIGHEST:
5877 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
5878 case elfcpp::R_POWERPC_DTPREL16:
5879 case elfcpp::R_POWERPC_DTPREL16_LO:
5880 case elfcpp::R_POWERPC_DTPREL16_HI:
5881 case elfcpp::R_POWERPC_DTPREL16_HA:
5882 case elfcpp::R_PPC64_DTPREL16_DS:
5883 case elfcpp::R_PPC64_DTPREL16_LO_DS:
5884 case elfcpp::R_PPC64_DTPREL16_HIGH:
5885 case elfcpp::R_PPC64_DTPREL16_HIGHA:
5886 case elfcpp::R_PPC64_DTPREL16_HIGHER:
5887 case elfcpp::R_PPC64_DTPREL16_HIGHERA:
5888 case elfcpp::R_PPC64_DTPREL16_HIGHEST:
5889 case elfcpp::R_PPC64_DTPREL16_HIGHESTA:
5890 case elfcpp::R_PPC64_TLSGD:
5891 case elfcpp::R_PPC64_TLSLD:
5894 case elfcpp::R_POWERPC_GOT16:
5895 case elfcpp::R_POWERPC_GOT16_LO:
5896 case elfcpp::R_POWERPC_GOT16_HI:
5897 case elfcpp::R_POWERPC_GOT16_HA:
5898 case elfcpp::R_PPC64_GOT16_DS:
5899 case elfcpp::R_PPC64_GOT16_LO_DS:
5901 // The symbol requires a GOT entry.
5902 Output_data_got_powerpc<size, big_endian>* got;
5904 got = target->got_section(symtab, layout);
5905 if (gsym->final_value_is_known())
5907 if (size == 32 && is_ifunc)
5908 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
5910 got->add_global(gsym, GOT_TYPE_STANDARD);
5912 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
5914 // If we are generating a shared object or a pie, this
5915 // symbol's GOT entry will be set by a dynamic relocation.
5916 unsigned int off = got->add_constant(0);
5917 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
5919 Reloc_section* rela_dyn
5920 = target->rela_dyn_section(symtab, layout, is_ifunc);
5922 if (gsym->can_use_relative_reloc(false)
5924 && gsym->visibility() == elfcpp::STV_PROTECTED
5925 && parameters->options().shared()))
5927 unsigned int dynrel = (is_ifunc ? elfcpp::R_POWERPC_IRELATIVE
5928 : elfcpp::R_POWERPC_RELATIVE);
5929 rela_dyn->add_global_relative(gsym, dynrel, got, off, 0, false);
5933 unsigned int dynrel = elfcpp::R_POWERPC_GLOB_DAT;
5934 rela_dyn->add_global(gsym, dynrel, got, off, 0);
5940 case elfcpp::R_PPC64_TOC16:
5941 case elfcpp::R_PPC64_TOC16_LO:
5942 case elfcpp::R_PPC64_TOC16_HI:
5943 case elfcpp::R_PPC64_TOC16_HA:
5944 case elfcpp::R_PPC64_TOC16_DS:
5945 case elfcpp::R_PPC64_TOC16_LO_DS:
5946 // We need a GOT section.
5947 target->got_section(symtab, layout);
5950 case elfcpp::R_POWERPC_GOT_TLSGD16:
5951 case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
5952 case elfcpp::R_POWERPC_GOT_TLSGD16_HI:
5953 case elfcpp::R_POWERPC_GOT_TLSGD16_HA:
5955 const bool final = gsym->final_value_is_known();
5956 const tls::Tls_optimization tls_type = target->optimize_tls_gd(final);
5957 if (tls_type == tls::TLSOPT_NONE)
5959 Output_data_got_powerpc<size, big_endian>* got
5960 = target->got_section(symtab, layout);
5961 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5962 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLSGD, rela_dyn,
5963 elfcpp::R_POWERPC_DTPMOD,
5964 elfcpp::R_POWERPC_DTPREL);
5966 else if (tls_type == tls::TLSOPT_TO_IE)
5968 if (!gsym->has_got_offset(GOT_TYPE_TPREL))
5970 Output_data_got_powerpc<size, big_endian>* got
5971 = target->got_section(symtab, layout);
5972 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
5973 if (gsym->is_undefined()
5974 || gsym->is_from_dynobj())
5976 got->add_global_with_rel(gsym, GOT_TYPE_TPREL, rela_dyn,
5977 elfcpp::R_POWERPC_TPREL);
5981 unsigned int off = got->add_constant(0);
5982 gsym->set_got_offset(GOT_TYPE_TPREL, off);
5983 unsigned int dynrel = elfcpp::R_POWERPC_TPREL;
5984 rela_dyn->add_symbolless_global_addend(gsym, dynrel,
5989 else if (tls_type == tls::TLSOPT_TO_LE)
5991 // no GOT relocs needed for Local Exec.
5998 case elfcpp::R_POWERPC_GOT_TLSLD16:
5999 case elfcpp::R_POWERPC_GOT_TLSLD16_LO:
6000 case elfcpp::R_POWERPC_GOT_TLSLD16_HI:
6001 case elfcpp::R_POWERPC_GOT_TLSLD16_HA:
6003 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
6004 if (tls_type == tls::TLSOPT_NONE)
6005 target->tlsld_got_offset(symtab, layout, object);
6006 else if (tls_type == tls::TLSOPT_TO_LE)
6008 // no GOT relocs needed for Local Exec.
6009 if (parameters->options().emit_relocs())
6011 Output_section* os = layout->tls_segment()->first_section();
6012 gold_assert(os != NULL);
6013 os->set_needs_symtab_index();
6021 case elfcpp::R_POWERPC_GOT_DTPREL16:
6022 case elfcpp::R_POWERPC_GOT_DTPREL16_LO:
6023 case elfcpp::R_POWERPC_GOT_DTPREL16_HI:
6024 case elfcpp::R_POWERPC_GOT_DTPREL16_HA:
6026 Output_data_got_powerpc<size, big_endian>* got
6027 = target->got_section(symtab, layout);
6028 if (!gsym->final_value_is_known()
6029 && (gsym->is_from_dynobj()
6030 || gsym->is_undefined()
6031 || gsym->is_preemptible()))
6032 got->add_global_with_rel(gsym, GOT_TYPE_DTPREL,
6033 target->rela_dyn_section(layout),
6034 elfcpp::R_POWERPC_DTPREL);
6036 got->add_global_tls(gsym, GOT_TYPE_DTPREL);
6040 case elfcpp::R_POWERPC_GOT_TPREL16:
6041 case elfcpp::R_POWERPC_GOT_TPREL16_LO:
6042 case elfcpp::R_POWERPC_GOT_TPREL16_HI:
6043 case elfcpp::R_POWERPC_GOT_TPREL16_HA:
6045 const bool final = gsym->final_value_is_known();
6046 const tls::Tls_optimization tls_type = target->optimize_tls_ie(final);
6047 if (tls_type == tls::TLSOPT_NONE)
6049 if (!gsym->has_got_offset(GOT_TYPE_TPREL))
6051 Output_data_got_powerpc<size, big_endian>* got
6052 = target->got_section(symtab, layout);
6053 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
6054 if (gsym->is_undefined()
6055 || gsym->is_from_dynobj())
6057 got->add_global_with_rel(gsym, GOT_TYPE_TPREL, rela_dyn,
6058 elfcpp::R_POWERPC_TPREL);
6062 unsigned int off = got->add_constant(0);
6063 gsym->set_got_offset(GOT_TYPE_TPREL, off);
6064 unsigned int dynrel = elfcpp::R_POWERPC_TPREL;
6065 rela_dyn->add_symbolless_global_addend(gsym, dynrel,
6070 else if (tls_type == tls::TLSOPT_TO_LE)
6072 // no GOT relocs needed for Local Exec.
6080 unsupported_reloc_global(object, r_type, gsym);
6086 case elfcpp::R_POWERPC_GOT_TLSLD16:
6087 case elfcpp::R_POWERPC_GOT_TLSGD16:
6088 case elfcpp::R_POWERPC_GOT_TPREL16:
6089 case elfcpp::R_POWERPC_GOT_DTPREL16:
6090 case elfcpp::R_POWERPC_GOT16:
6091 case elfcpp::R_PPC64_GOT16_DS:
6092 case elfcpp::R_PPC64_TOC16:
6093 case elfcpp::R_PPC64_TOC16_DS:
6094 ppc_object->set_has_small_toc_reloc();
6100 // Process relocations for gc.
6102 template<int size, bool big_endian>
6104 Target_powerpc<size, big_endian>::gc_process_relocs(
6105 Symbol_table* symtab,
6107 Sized_relobj_file<size, big_endian>* object,
6108 unsigned int data_shndx,
6110 const unsigned char* prelocs,
6112 Output_section* output_section,
6113 bool needs_special_offset_handling,
6114 size_t local_symbol_count,
6115 const unsigned char* plocal_symbols)
6117 typedef Target_powerpc<size, big_endian> Powerpc;
6118 typedef typename Target_powerpc<size, big_endian>::Scan Scan;
6119 Powerpc_relobj<size, big_endian>* ppc_object
6120 = static_cast<Powerpc_relobj<size, big_endian>*>(object);
6122 ppc_object->set_opd_valid();
6123 if (size == 64 && data_shndx == ppc_object->opd_shndx())
6125 typename Powerpc_relobj<size, big_endian>::Access_from::iterator p;
6126 for (p = ppc_object->access_from_map()->begin();
6127 p != ppc_object->access_from_map()->end();
6130 Address dst_off = p->first;
6131 unsigned int dst_indx = ppc_object->get_opd_ent(dst_off);
6132 typename Powerpc_relobj<size, big_endian>::Section_refs::iterator s;
6133 for (s = p->second.begin(); s != p->second.end(); ++s)
6135 Object* src_obj = s->first;
6136 unsigned int src_indx = s->second;
6137 symtab->gc()->add_reference(src_obj, src_indx,
6138 ppc_object, dst_indx);
6142 ppc_object->access_from_map()->clear();
6143 ppc_object->process_gc_mark(symtab);
6144 // Don't look at .opd relocs as .opd will reference everything.
6148 gold::gc_process_relocs<size, big_endian, Powerpc, elfcpp::SHT_RELA, Scan,
6149 typename Target_powerpc::Relocatable_size_for_reloc>(
6158 needs_special_offset_handling,
6163 // Handle target specific gc actions when adding a gc reference from
6164 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
6165 // and DST_OFF. For powerpc64, this adds a referenc to the code
6166 // section of a function descriptor.
6168 template<int size, bool big_endian>
6170 Target_powerpc<size, big_endian>::do_gc_add_reference(
6171 Symbol_table* symtab,
6173 unsigned int src_shndx,
6175 unsigned int dst_shndx,
6176 Address dst_off) const
6178 if (size != 64 || dst_obj->is_dynamic())
6181 Powerpc_relobj<size, big_endian>* ppc_object
6182 = static_cast<Powerpc_relobj<size, big_endian>*>(dst_obj);
6183 if (dst_shndx != 0 && dst_shndx == ppc_object->opd_shndx())
6185 if (ppc_object->opd_valid())
6187 dst_shndx = ppc_object->get_opd_ent(dst_off);
6188 symtab->gc()->add_reference(src_obj, src_shndx, dst_obj, dst_shndx);
6192 // If we haven't run scan_opd_relocs, we must delay
6193 // processing this function descriptor reference.
6194 ppc_object->add_reference(src_obj, src_shndx, dst_off);
6199 // Add any special sections for this symbol to the gc work list.
6200 // For powerpc64, this adds the code section of a function
6203 template<int size, bool big_endian>
6205 Target_powerpc<size, big_endian>::do_gc_mark_symbol(
6206 Symbol_table* symtab,
6211 Powerpc_relobj<size, big_endian>* ppc_object
6212 = static_cast<Powerpc_relobj<size, big_endian>*>(sym->object());
6214 unsigned int shndx = sym->shndx(&is_ordinary);
6215 if (is_ordinary && shndx != 0 && shndx == ppc_object->opd_shndx())
6217 Sized_symbol<size>* gsym = symtab->get_sized_symbol<size>(sym);
6218 Address dst_off = gsym->value();
6219 if (ppc_object->opd_valid())
6221 unsigned int dst_indx = ppc_object->get_opd_ent(dst_off);
6222 symtab->gc()->worklist().push(Section_id(ppc_object, dst_indx));
6225 ppc_object->add_gc_mark(dst_off);
6230 // For a symbol location in .opd, set LOC to the location of the
6233 template<int size, bool big_endian>
6235 Target_powerpc<size, big_endian>::do_function_location(
6236 Symbol_location* loc) const
6238 if (size == 64 && loc->shndx != 0)
6240 if (loc->object->is_dynamic())
6242 Powerpc_dynobj<size, big_endian>* ppc_object
6243 = static_cast<Powerpc_dynobj<size, big_endian>*>(loc->object);
6244 if (loc->shndx == ppc_object->opd_shndx())
6247 Address off = loc->offset - ppc_object->opd_address();
6248 loc->shndx = ppc_object->get_opd_ent(off, &dest_off);
6249 loc->offset = dest_off;
6254 const Powerpc_relobj<size, big_endian>* ppc_object
6255 = static_cast<const Powerpc_relobj<size, big_endian>*>(loc->object);
6256 if (loc->shndx == ppc_object->opd_shndx())
6259 loc->shndx = ppc_object->get_opd_ent(loc->offset, &dest_off);
6260 loc->offset = dest_off;
6266 // Scan relocations for a section.
6268 template<int size, bool big_endian>
6270 Target_powerpc<size, big_endian>::scan_relocs(
6271 Symbol_table* symtab,
6273 Sized_relobj_file<size, big_endian>* object,
6274 unsigned int data_shndx,
6275 unsigned int sh_type,
6276 const unsigned char* prelocs,
6278 Output_section* output_section,
6279 bool needs_special_offset_handling,
6280 size_t local_symbol_count,
6281 const unsigned char* plocal_symbols)
6283 typedef Target_powerpc<size, big_endian> Powerpc;
6284 typedef typename Target_powerpc<size, big_endian>::Scan Scan;
6286 if (sh_type == elfcpp::SHT_REL)
6288 gold_error(_("%s: unsupported REL reloc section"),
6289 object->name().c_str());
6293 gold::scan_relocs<size, big_endian, Powerpc, elfcpp::SHT_RELA, Scan>(
6302 needs_special_offset_handling,
6307 // Functor class for processing the global symbol table.
6308 // Removes symbols defined on discarded opd entries.
6310 template<bool big_endian>
6311 class Global_symbol_visitor_opd
6314 Global_symbol_visitor_opd()
6318 operator()(Sized_symbol<64>* sym)
6320 if (sym->has_symtab_index()
6321 || sym->source() != Symbol::FROM_OBJECT
6322 || !sym->in_real_elf())
6325 if (sym->object()->is_dynamic())
6328 Powerpc_relobj<64, big_endian>* symobj
6329 = static_cast<Powerpc_relobj<64, big_endian>*>(sym->object());
6330 if (symobj->opd_shndx() == 0)
6334 unsigned int shndx = sym->shndx(&is_ordinary);
6335 if (shndx == symobj->opd_shndx()
6336 && symobj->get_opd_discard(sym->value()))
6337 sym->set_symtab_index(-1U);
6341 template<int size, bool big_endian>
6343 Target_powerpc<size, big_endian>::define_save_restore_funcs(
6345 Symbol_table* symtab)
6349 Output_data_save_res<64, big_endian>* savres
6350 = new Output_data_save_res<64, big_endian>(symtab);
6351 layout->add_output_section_data(".text", elfcpp::SHT_PROGBITS,
6352 elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
6353 savres, ORDER_TEXT, false);
6357 // Sort linker created .got section first (for the header), then input
6358 // sections belonging to files using small model code.
6360 template<bool big_endian>
6361 class Sort_toc_sections
6365 operator()(const Output_section::Input_section& is1,
6366 const Output_section::Input_section& is2) const
6368 if (!is1.is_input_section() && is2.is_input_section())
6371 = (is1.is_input_section()
6372 && (static_cast<const Powerpc_relobj<64, big_endian>*>(is1.relobj())
6373 ->has_small_toc_reloc()));
6375 = (is2.is_input_section()
6376 && (static_cast<const Powerpc_relobj<64, big_endian>*>(is2.relobj())
6377 ->has_small_toc_reloc()));
6378 return small1 && !small2;
6382 // Finalize the sections.
6384 template<int size, bool big_endian>
6386 Target_powerpc<size, big_endian>::do_finalize_sections(
6388 const Input_objects*,
6389 Symbol_table* symtab)
6391 if (parameters->doing_static_link())
6393 // At least some versions of glibc elf-init.o have a strong
6394 // reference to __rela_iplt marker syms. A weak ref would be
6396 if (this->iplt_ != NULL)
6398 Reloc_section* rel = this->iplt_->rel_plt();
6399 symtab->define_in_output_data("__rela_iplt_start", NULL,
6400 Symbol_table::PREDEFINED, rel, 0, 0,
6401 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
6402 elfcpp::STV_HIDDEN, 0, false, true);
6403 symtab->define_in_output_data("__rela_iplt_end", NULL,
6404 Symbol_table::PREDEFINED, rel, 0, 0,
6405 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
6406 elfcpp::STV_HIDDEN, 0, true, true);
6410 symtab->define_as_constant("__rela_iplt_start", NULL,
6411 Symbol_table::PREDEFINED, 0, 0,
6412 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
6413 elfcpp::STV_HIDDEN, 0, true, false);
6414 symtab->define_as_constant("__rela_iplt_end", NULL,
6415 Symbol_table::PREDEFINED, 0, 0,
6416 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
6417 elfcpp::STV_HIDDEN, 0, true, false);
6423 typedef Global_symbol_visitor_opd<big_endian> Symbol_visitor;
6424 symtab->for_all_symbols<64, Symbol_visitor>(Symbol_visitor());
6426 if (!parameters->options().relocatable())
6428 this->define_save_restore_funcs(layout, symtab);
6430 // Annoyingly, we need to make these sections now whether or
6431 // not we need them. If we delay until do_relax then we
6432 // need to mess with the relaxation machinery checkpointing.
6433 this->got_section(symtab, layout);
6434 this->make_brlt_section(layout);
6436 if (parameters->options().toc_sort())
6438 Output_section* os = this->got_->output_section();
6439 if (os != NULL && os->input_sections().size() > 1)
6440 std::stable_sort(os->input_sections().begin(),
6441 os->input_sections().end(),
6442 Sort_toc_sections<big_endian>());
6447 // Fill in some more dynamic tags.
6448 Output_data_dynamic* odyn = layout->dynamic_data();
6451 const Reloc_section* rel_plt = (this->plt_ == NULL
6453 : this->plt_->rel_plt());
6454 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
6455 this->rela_dyn_, true, size == 32);
6459 if (this->got_ != NULL)
6461 this->got_->finalize_data_size();
6462 odyn->add_section_plus_offset(elfcpp::DT_PPC_GOT,
6463 this->got_, this->got_->g_o_t());
6468 if (this->glink_ != NULL)
6470 this->glink_->finalize_data_size();
6471 odyn->add_section_plus_offset(elfcpp::DT_PPC64_GLINK,
6473 (this->glink_->pltresolve_size
6479 // Emit any relocs we saved in an attempt to avoid generating COPY
6481 if (this->copy_relocs_.any_saved_relocs())
6482 this->copy_relocs_.emit(this->rela_dyn_section(layout));
6485 // Return TRUE iff INSN is one we expect on a _LO variety toc/got
6489 ok_lo_toc_insn(uint32_t insn)
6491 return ((insn & (0x3f << 26)) == 14u << 26 /* addi */
6492 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
6493 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
6494 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
6495 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
6496 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
6497 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
6498 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
6499 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
6500 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
6501 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
6502 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
6503 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
6504 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
6505 || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6507 || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
6508 && ((insn & 3) == 0 || (insn & 3) == 3))
6509 || (insn & (0x3f << 26)) == 12u << 26 /* addic */);
6512 // Return the value to use for a branch relocation.
6514 template<int size, bool big_endian>
6515 typename Target_powerpc<size, big_endian>::Address
6516 Target_powerpc<size, big_endian>::symval_for_branch(
6517 const Symbol_table* symtab,
6519 const Sized_symbol<size>* gsym,
6520 Powerpc_relobj<size, big_endian>* object,
6521 unsigned int *dest_shndx)
6527 // If the symbol is defined in an opd section, ie. is a function
6528 // descriptor, use the function descriptor code entry address
6529 Powerpc_relobj<size, big_endian>* symobj = object;
6531 && gsym->source() != Symbol::FROM_OBJECT)
6534 symobj = static_cast<Powerpc_relobj<size, big_endian>*>(gsym->object());
6535 unsigned int shndx = symobj->opd_shndx();
6538 Address opd_addr = symobj->get_output_section_offset(shndx);
6539 if (opd_addr == invalid_address)
6541 opd_addr += symobj->output_section_address(shndx);
6542 if (value >= opd_addr && value < opd_addr + symobj->section_size(shndx))
6545 *dest_shndx = symobj->get_opd_ent(value - opd_addr, &sec_off);
6546 if (symtab->is_section_folded(symobj, *dest_shndx))
6549 = symtab->icf()->get_folded_section(symobj, *dest_shndx);
6550 symobj = static_cast<Powerpc_relobj<size, big_endian>*>(folded.first);
6551 *dest_shndx = folded.second;
6553 Address sec_addr = symobj->get_output_section_offset(*dest_shndx);
6554 gold_assert(sec_addr != invalid_address);
6555 sec_addr += symobj->output_section(*dest_shndx)->address();
6556 value = sec_addr + sec_off;
6561 // Perform a relocation.
6563 template<int size, bool big_endian>
6565 Target_powerpc<size, big_endian>::Relocate::relocate(
6566 const Relocate_info<size, big_endian>* relinfo,
6567 Target_powerpc* target,
6570 const elfcpp::Rela<size, big_endian>& rela,
6571 unsigned int r_type,
6572 const Sized_symbol<size>* gsym,
6573 const Symbol_value<size>* psymval,
6574 unsigned char* view,
6576 section_size_type view_size)
6581 switch (this->maybe_skip_tls_get_addr_call(r_type, gsym))
6583 case Track_tls::NOT_EXPECTED:
6584 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
6585 _("__tls_get_addr call lacks marker reloc"));
6587 case Track_tls::EXPECTED:
6588 // We have already complained.
6590 case Track_tls::SKIP:
6592 case Track_tls::NORMAL:
6596 typedef Powerpc_relocate_functions<size, big_endian> Reloc;
6597 typedef typename elfcpp::Swap<32, big_endian>::Valtype Insn;
6598 Powerpc_relobj<size, big_endian>* const object
6599 = static_cast<Powerpc_relobj<size, big_endian>*>(relinfo->object);
6601 bool has_plt_value = false;
6602 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
6604 ? use_plt_offset<size>(gsym, Scan::get_reference_flags(r_type))
6605 : object->local_has_plt_offset(r_sym))
6606 && (!psymval->is_ifunc_symbol()
6607 || Scan::reloc_needs_plt_for_ifunc(object, r_type, false)))
6609 Stub_table<size, big_endian>* stub_table
6610 = object->stub_table(relinfo->data_shndx);
6611 if (stub_table == NULL)
6613 // This is a ref from a data section to an ifunc symbol.
6614 if (target->stub_tables().size() != 0)
6615 stub_table = target->stub_tables()[0];
6617 gold_assert(stub_table != NULL);
6620 off = stub_table->find_plt_call_entry(object, gsym, r_type,
6621 rela.get_r_addend());
6623 off = stub_table->find_plt_call_entry(object, r_sym, r_type,
6624 rela.get_r_addend());
6625 gold_assert(off != invalid_address);
6626 value = stub_table->stub_address() + off;
6627 has_plt_value = true;
6630 if (r_type == elfcpp::R_POWERPC_GOT16
6631 || r_type == elfcpp::R_POWERPC_GOT16_LO
6632 || r_type == elfcpp::R_POWERPC_GOT16_HI
6633 || r_type == elfcpp::R_POWERPC_GOT16_HA
6634 || r_type == elfcpp::R_PPC64_GOT16_DS
6635 || r_type == elfcpp::R_PPC64_GOT16_LO_DS)
6639 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
6640 value = gsym->got_offset(GOT_TYPE_STANDARD);
6644 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
6645 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
6646 value = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
6648 value -= target->got_section()->got_base_offset(object);
6650 else if (r_type == elfcpp::R_PPC64_TOC)
6652 value = (target->got_section()->output_section()->address()
6653 + object->toc_base_offset());
6655 else if (gsym != NULL
6656 && (r_type == elfcpp::R_POWERPC_REL24
6657 || r_type == elfcpp::R_PPC_PLTREL24)
6662 typedef typename elfcpp::Swap<32, big_endian>::Valtype Valtype;
6663 Valtype* wv = reinterpret_cast<Valtype*>(view);
6664 bool can_plt_call = false;
6665 if (rela.get_r_offset() + 8 <= view_size)
6667 Valtype insn = elfcpp::Swap<32, big_endian>::readval(wv);
6668 Valtype insn2 = elfcpp::Swap<32, big_endian>::readval(wv + 1);
6671 || insn2 == cror_15_15_15 || insn2 == cror_31_31_31))
6673 elfcpp::Swap<32, big_endian>::
6674 writeval(wv + 1, ld_2_1 + target->stk_toc());
6675 can_plt_call = true;
6680 // If we don't have a branch and link followed by a nop,
6681 // we can't go via the plt because there is no place to
6682 // put a toc restoring instruction.
6683 // Unless we know we won't be returning.
6684 if (strcmp(gsym->name(), "__libc_start_main") == 0)
6685 can_plt_call = true;
6689 // g++ as of 20130507 emits self-calls without a
6690 // following nop. This is arguably wrong since we have
6691 // conflicting information. On the one hand a global
6692 // symbol and on the other a local call sequence, but
6693 // don't error for this special case.
6694 // It isn't possible to cheaply verify we have exactly
6695 // such a call. Allow all calls to the same section.
6697 Address code = value;
6698 if (gsym->source() == Symbol::FROM_OBJECT
6699 && gsym->object() == object)
6701 Address addend = rela.get_r_addend();
6702 unsigned int dest_shndx;
6703 Address opdent = psymval->value(object, addend);
6704 code = target->symval_for_branch(relinfo->symtab, opdent,
6705 gsym, object, &dest_shndx);
6707 if (dest_shndx == 0)
6708 dest_shndx = gsym->shndx(&is_ordinary);
6709 ok = dest_shndx == relinfo->data_shndx;
6713 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
6714 _("call lacks nop, can't restore toc; "
6715 "recompile with -fPIC"));
6721 else if (r_type == elfcpp::R_POWERPC_GOT_TLSGD16
6722 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO
6723 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_HI
6724 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_HA)
6726 // First instruction of a global dynamic sequence, arg setup insn.
6727 const bool final = gsym == NULL || gsym->final_value_is_known();
6728 const tls::Tls_optimization tls_type = target->optimize_tls_gd(final);
6729 enum Got_type got_type = GOT_TYPE_STANDARD;
6730 if (tls_type == tls::TLSOPT_NONE)
6731 got_type = GOT_TYPE_TLSGD;
6732 else if (tls_type == tls::TLSOPT_TO_IE)
6733 got_type = GOT_TYPE_TPREL;
6734 if (got_type != GOT_TYPE_STANDARD)
6738 gold_assert(gsym->has_got_offset(got_type));
6739 value = gsym->got_offset(got_type);
6743 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
6744 gold_assert(object->local_has_got_offset(r_sym, got_type));
6745 value = object->local_got_offset(r_sym, got_type);
6747 value -= target->got_section()->got_base_offset(object);
6749 if (tls_type == tls::TLSOPT_TO_IE)
6751 if (r_type == elfcpp::R_POWERPC_GOT_TLSGD16
6752 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO)
6754 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6755 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
6756 insn &= (1 << 26) - (1 << 16); // extract rt,ra from addi
6758 insn |= 32 << 26; // lwz
6760 insn |= 58 << 26; // ld
6761 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6763 r_type += (elfcpp::R_POWERPC_GOT_TPREL16
6764 - elfcpp::R_POWERPC_GOT_TLSGD16);
6766 else if (tls_type == tls::TLSOPT_TO_LE)
6768 if (r_type == elfcpp::R_POWERPC_GOT_TLSGD16
6769 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO)
6771 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6772 Insn insn = addis_3_13;
6775 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6776 r_type = elfcpp::R_POWERPC_TPREL16_HA;
6777 value = psymval->value(object, rela.get_r_addend());
6781 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6783 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6784 r_type = elfcpp::R_POWERPC_NONE;
6788 else if (r_type == elfcpp::R_POWERPC_GOT_TLSLD16
6789 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_LO
6790 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_HI
6791 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_HA)
6793 // First instruction of a local dynamic sequence, arg setup insn.
6794 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
6795 if (tls_type == tls::TLSOPT_NONE)
6797 value = target->tlsld_got_offset();
6798 value -= target->got_section()->got_base_offset(object);
6802 gold_assert(tls_type == tls::TLSOPT_TO_LE);
6803 if (r_type == elfcpp::R_POWERPC_GOT_TLSLD16
6804 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_LO)
6806 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6807 Insn insn = addis_3_13;
6810 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6811 r_type = elfcpp::R_POWERPC_TPREL16_HA;
6816 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6818 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6819 r_type = elfcpp::R_POWERPC_NONE;
6823 else if (r_type == elfcpp::R_POWERPC_GOT_DTPREL16
6824 || r_type == elfcpp::R_POWERPC_GOT_DTPREL16_LO
6825 || r_type == elfcpp::R_POWERPC_GOT_DTPREL16_HI
6826 || r_type == elfcpp::R_POWERPC_GOT_DTPREL16_HA)
6828 // Accesses relative to a local dynamic sequence address,
6829 // no optimisation here.
6832 gold_assert(gsym->has_got_offset(GOT_TYPE_DTPREL));
6833 value = gsym->got_offset(GOT_TYPE_DTPREL);
6837 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
6838 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_DTPREL));
6839 value = object->local_got_offset(r_sym, GOT_TYPE_DTPREL);
6841 value -= target->got_section()->got_base_offset(object);
6843 else if (r_type == elfcpp::R_POWERPC_GOT_TPREL16
6844 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_LO
6845 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_HI
6846 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_HA)
6848 // First instruction of initial exec sequence.
6849 const bool final = gsym == NULL || gsym->final_value_is_known();
6850 const tls::Tls_optimization tls_type = target->optimize_tls_ie(final);
6851 if (tls_type == tls::TLSOPT_NONE)
6855 gold_assert(gsym->has_got_offset(GOT_TYPE_TPREL));
6856 value = gsym->got_offset(GOT_TYPE_TPREL);
6860 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
6861 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_TPREL));
6862 value = object->local_got_offset(r_sym, GOT_TYPE_TPREL);
6864 value -= target->got_section()->got_base_offset(object);
6868 gold_assert(tls_type == tls::TLSOPT_TO_LE);
6869 if (r_type == elfcpp::R_POWERPC_GOT_TPREL16
6870 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_LO)
6872 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6873 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
6874 insn &= (1 << 26) - (1 << 21); // extract rt from ld
6879 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6880 r_type = elfcpp::R_POWERPC_TPREL16_HA;
6881 value = psymval->value(object, rela.get_r_addend());
6885 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
6887 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6888 r_type = elfcpp::R_POWERPC_NONE;
6892 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSGD)
6893 || (size == 32 && r_type == elfcpp::R_PPC_TLSGD))
6895 // Second instruction of a global dynamic sequence,
6896 // the __tls_get_addr call
6897 this->expect_tls_get_addr_call(relinfo, relnum, rela.get_r_offset());
6898 const bool final = gsym == NULL || gsym->final_value_is_known();
6899 const tls::Tls_optimization tls_type = target->optimize_tls_gd(final);
6900 if (tls_type != tls::TLSOPT_NONE)
6902 if (tls_type == tls::TLSOPT_TO_IE)
6904 Insn* iview = reinterpret_cast<Insn*>(view);
6905 Insn insn = add_3_3_13;
6908 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6909 r_type = elfcpp::R_POWERPC_NONE;
6913 Insn* iview = reinterpret_cast<Insn*>(view);
6914 Insn insn = addi_3_3;
6915 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6916 r_type = elfcpp::R_POWERPC_TPREL16_LO;
6917 view += 2 * big_endian;
6918 value = psymval->value(object, rela.get_r_addend());
6920 this->skip_next_tls_get_addr_call();
6923 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSLD)
6924 || (size == 32 && r_type == elfcpp::R_PPC_TLSLD))
6926 // Second instruction of a local dynamic sequence,
6927 // the __tls_get_addr call
6928 this->expect_tls_get_addr_call(relinfo, relnum, rela.get_r_offset());
6929 const tls::Tls_optimization tls_type = target->optimize_tls_ld();
6930 if (tls_type == tls::TLSOPT_TO_LE)
6932 Insn* iview = reinterpret_cast<Insn*>(view);
6933 Insn insn = addi_3_3;
6934 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6935 this->skip_next_tls_get_addr_call();
6936 r_type = elfcpp::R_POWERPC_TPREL16_LO;
6937 view += 2 * big_endian;
6941 else if (r_type == elfcpp::R_POWERPC_TLS)
6943 // Second instruction of an initial exec sequence
6944 const bool final = gsym == NULL || gsym->final_value_is_known();
6945 const tls::Tls_optimization tls_type = target->optimize_tls_ie(final);
6946 if (tls_type == tls::TLSOPT_TO_LE)
6948 Insn* iview = reinterpret_cast<Insn*>(view);
6949 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
6950 unsigned int reg = size == 32 ? 2 : 13;
6951 insn = at_tls_transform(insn, reg);
6952 gold_assert(insn != 0);
6953 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
6954 r_type = elfcpp::R_POWERPC_TPREL16_LO;
6955 view += 2 * big_endian;
6956 value = psymval->value(object, rela.get_r_addend());
6959 else if (!has_plt_value)
6962 unsigned int dest_shndx;
6963 if (r_type != elfcpp::R_PPC_PLTREL24)
6964 addend = rela.get_r_addend();
6965 value = psymval->value(object, addend);
6967 value += object->ppc64_local_entry_offset(gsym);
6969 value += object->ppc64_local_entry_offset(r_sym);
6970 if (size == 64 && is_branch_reloc(r_type))
6971 value = target->symval_for_branch(relinfo->symtab, value,
6972 gsym, object, &dest_shndx);
6973 unsigned int max_branch_offset = 0;
6974 if (r_type == elfcpp::R_POWERPC_REL24
6975 || r_type == elfcpp::R_PPC_PLTREL24
6976 || r_type == elfcpp::R_PPC_LOCAL24PC)
6977 max_branch_offset = 1 << 25;
6978 else if (r_type == elfcpp::R_POWERPC_REL14
6979 || r_type == elfcpp::R_POWERPC_REL14_BRTAKEN
6980 || r_type == elfcpp::R_POWERPC_REL14_BRNTAKEN)
6981 max_branch_offset = 1 << 15;
6982 if (max_branch_offset != 0
6983 && value - address + max_branch_offset >= 2 * max_branch_offset)
6985 Stub_table<size, big_endian>* stub_table
6986 = object->stub_table(relinfo->data_shndx);
6987 if (stub_table != NULL)
6989 Address off = stub_table->find_long_branch_entry(object, value);
6990 if (off != invalid_address)
6991 value = (stub_table->stub_address() + stub_table->plt_size()
6999 case elfcpp::R_PPC64_REL64:
7000 case elfcpp::R_POWERPC_REL32:
7001 case elfcpp::R_POWERPC_REL24:
7002 case elfcpp::R_PPC_PLTREL24:
7003 case elfcpp::R_PPC_LOCAL24PC:
7004 case elfcpp::R_POWERPC_REL16:
7005 case elfcpp::R_POWERPC_REL16_LO:
7006 case elfcpp::R_POWERPC_REL16_HI:
7007 case elfcpp::R_POWERPC_REL16_HA:
7008 case elfcpp::R_POWERPC_REL14:
7009 case elfcpp::R_POWERPC_REL14_BRTAKEN:
7010 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
7014 case elfcpp::R_PPC64_TOC16:
7015 case elfcpp::R_PPC64_TOC16_LO:
7016 case elfcpp::R_PPC64_TOC16_HI:
7017 case elfcpp::R_PPC64_TOC16_HA:
7018 case elfcpp::R_PPC64_TOC16_DS:
7019 case elfcpp::R_PPC64_TOC16_LO_DS:
7020 // Subtract the TOC base address.
7021 value -= (target->got_section()->output_section()->address()
7022 + object->toc_base_offset());
7025 case elfcpp::R_POWERPC_SECTOFF:
7026 case elfcpp::R_POWERPC_SECTOFF_LO:
7027 case elfcpp::R_POWERPC_SECTOFF_HI:
7028 case elfcpp::R_POWERPC_SECTOFF_HA:
7029 case elfcpp::R_PPC64_SECTOFF_DS:
7030 case elfcpp::R_PPC64_SECTOFF_LO_DS:
7032 value -= os->address();
7035 case elfcpp::R_PPC64_TPREL16_DS:
7036 case elfcpp::R_PPC64_TPREL16_LO_DS:
7037 case elfcpp::R_PPC64_TPREL16_HIGH:
7038 case elfcpp::R_PPC64_TPREL16_HIGHA:
7040 // R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
7042 case elfcpp::R_POWERPC_TPREL16:
7043 case elfcpp::R_POWERPC_TPREL16_LO:
7044 case elfcpp::R_POWERPC_TPREL16_HI:
7045 case elfcpp::R_POWERPC_TPREL16_HA:
7046 case elfcpp::R_POWERPC_TPREL:
7047 case elfcpp::R_PPC64_TPREL16_HIGHER:
7048 case elfcpp::R_PPC64_TPREL16_HIGHERA:
7049 case elfcpp::R_PPC64_TPREL16_HIGHEST:
7050 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
7051 // tls symbol values are relative to tls_segment()->vaddr()
7055 case elfcpp::R_PPC64_DTPREL16_DS:
7056 case elfcpp::R_PPC64_DTPREL16_LO_DS:
7057 case elfcpp::R_PPC64_DTPREL16_HIGHER:
7058 case elfcpp::R_PPC64_DTPREL16_HIGHERA:
7059 case elfcpp::R_PPC64_DTPREL16_HIGHEST:
7060 case elfcpp::R_PPC64_DTPREL16_HIGHESTA:
7062 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
7063 // R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
7065 case elfcpp::R_POWERPC_DTPREL16:
7066 case elfcpp::R_POWERPC_DTPREL16_LO:
7067 case elfcpp::R_POWERPC_DTPREL16_HI:
7068 case elfcpp::R_POWERPC_DTPREL16_HA:
7069 case elfcpp::R_POWERPC_DTPREL:
7070 case elfcpp::R_PPC64_DTPREL16_HIGH:
7071 case elfcpp::R_PPC64_DTPREL16_HIGHA:
7072 // tls symbol values are relative to tls_segment()->vaddr()
7073 value -= dtp_offset;
7080 Insn branch_bit = 0;
7083 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
7084 case elfcpp::R_POWERPC_REL14_BRTAKEN:
7085 branch_bit = 1 << 21;
7086 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
7087 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
7089 Insn* iview = reinterpret_cast<Insn*>(view);
7090 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
7093 if (this->is_isa_v2)
7095 // Set 'a' bit. This is 0b00010 in BO field for branch
7096 // on CR(BI) insns (BO == 001at or 011at), and 0b01000
7097 // for branch on CTR insns (BO == 1a00t or 1a01t).
7098 if ((insn & (0x14 << 21)) == (0x04 << 21))
7100 else if ((insn & (0x14 << 21)) == (0x10 << 21))
7107 // Invert 'y' bit if not the default.
7108 if (static_cast<Signed_address>(value) < 0)
7111 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
7121 // Multi-instruction sequences that access the TOC can be
7122 // optimized, eg. addis ra,r2,0; addi rb,ra,x;
7123 // to nop; addi rb,r2,x;
7129 case elfcpp::R_POWERPC_GOT_TLSLD16_HA:
7130 case elfcpp::R_POWERPC_GOT_TLSGD16_HA:
7131 case elfcpp::R_POWERPC_GOT_TPREL16_HA:
7132 case elfcpp::R_POWERPC_GOT_DTPREL16_HA:
7133 case elfcpp::R_POWERPC_GOT16_HA:
7134 case elfcpp::R_PPC64_TOC16_HA:
7135 if (parameters->options().toc_optimize())
7137 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
7138 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
7139 if ((insn & ((0x3f << 26) | 0x1f << 16))
7140 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */)
7141 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
7142 _("toc optimization is not supported "
7143 "for %#08x instruction"), insn);
7144 else if (value + 0x8000 < 0x10000)
7146 elfcpp::Swap<32, big_endian>::writeval(iview, nop);
7152 case elfcpp::R_POWERPC_GOT_TLSLD16_LO:
7153 case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
7154 case elfcpp::R_POWERPC_GOT_TPREL16_LO:
7155 case elfcpp::R_POWERPC_GOT_DTPREL16_LO:
7156 case elfcpp::R_POWERPC_GOT16_LO:
7157 case elfcpp::R_PPC64_GOT16_LO_DS:
7158 case elfcpp::R_PPC64_TOC16_LO:
7159 case elfcpp::R_PPC64_TOC16_LO_DS:
7160 if (parameters->options().toc_optimize())
7162 Insn* iview = reinterpret_cast<Insn*>(view - 2 * big_endian);
7163 Insn insn = elfcpp::Swap<32, big_endian>::readval(iview);
7164 if (!ok_lo_toc_insn(insn))
7165 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
7166 _("toc optimization is not supported "
7167 "for %#08x instruction"), insn);
7168 else if (value + 0x8000 < 0x10000)
7170 if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
7172 // Transform addic to addi when we change reg.
7173 insn &= ~((0x3f << 26) | (0x1f << 16));
7174 insn |= (14u << 26) | (2 << 16);
7178 insn &= ~(0x1f << 16);
7181 elfcpp::Swap<32, big_endian>::writeval(iview, insn);
7188 typename Reloc::Overflow_check overflow = Reloc::CHECK_NONE;
7191 case elfcpp::R_POWERPC_ADDR32:
7192 case elfcpp::R_POWERPC_UADDR32:
7194 overflow = Reloc::CHECK_BITFIELD;
7197 case elfcpp::R_POWERPC_REL32:
7199 overflow = Reloc::CHECK_SIGNED;
7202 case elfcpp::R_POWERPC_ADDR24:
7203 case elfcpp::R_POWERPC_ADDR16:
7204 case elfcpp::R_POWERPC_UADDR16:
7205 case elfcpp::R_PPC64_ADDR16_DS:
7206 case elfcpp::R_POWERPC_ADDR14:
7207 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
7208 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
7209 overflow = Reloc::CHECK_BITFIELD;
7212 case elfcpp::R_POWERPC_ADDR16_HI:
7213 case elfcpp::R_POWERPC_ADDR16_HA:
7214 case elfcpp::R_POWERPC_GOT16_HI:
7215 case elfcpp::R_POWERPC_GOT16_HA:
7216 case elfcpp::R_POWERPC_PLT16_HI:
7217 case elfcpp::R_POWERPC_PLT16_HA:
7218 case elfcpp::R_POWERPC_SECTOFF_HI:
7219 case elfcpp::R_POWERPC_SECTOFF_HA:
7220 case elfcpp::R_PPC64_TOC16_HI:
7221 case elfcpp::R_PPC64_TOC16_HA:
7222 case elfcpp::R_PPC64_PLTGOT16_HI:
7223 case elfcpp::R_PPC64_PLTGOT16_HA:
7224 case elfcpp::R_POWERPC_TPREL16_HI:
7225 case elfcpp::R_POWERPC_TPREL16_HA:
7226 case elfcpp::R_POWERPC_DTPREL16_HI:
7227 case elfcpp::R_POWERPC_DTPREL16_HA:
7228 case elfcpp::R_POWERPC_GOT_TLSGD16_HI:
7229 case elfcpp::R_POWERPC_GOT_TLSGD16_HA:
7230 case elfcpp::R_POWERPC_GOT_TLSLD16_HI:
7231 case elfcpp::R_POWERPC_GOT_TLSLD16_HA:
7232 case elfcpp::R_POWERPC_GOT_TPREL16_HI:
7233 case elfcpp::R_POWERPC_GOT_TPREL16_HA:
7234 case elfcpp::R_POWERPC_GOT_DTPREL16_HI:
7235 case elfcpp::R_POWERPC_GOT_DTPREL16_HA:
7236 case elfcpp::R_POWERPC_REL16_HI:
7237 case elfcpp::R_POWERPC_REL16_HA:
7240 case elfcpp::R_POWERPC_REL24:
7241 case elfcpp::R_PPC_PLTREL24:
7242 case elfcpp::R_PPC_LOCAL24PC:
7243 case elfcpp::R_POWERPC_REL16:
7244 case elfcpp::R_PPC64_TOC16:
7245 case elfcpp::R_POWERPC_GOT16:
7246 case elfcpp::R_POWERPC_SECTOFF:
7247 case elfcpp::R_POWERPC_TPREL16:
7248 case elfcpp::R_POWERPC_DTPREL16:
7249 case elfcpp::R_PPC64_TPREL16_DS:
7250 case elfcpp::R_PPC64_DTPREL16_DS:
7251 case elfcpp::R_PPC64_TOC16_DS:
7252 case elfcpp::R_PPC64_GOT16_DS:
7253 case elfcpp::R_PPC64_SECTOFF_DS:
7254 case elfcpp::R_POWERPC_REL14:
7255 case elfcpp::R_POWERPC_REL14_BRTAKEN:
7256 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
7257 case elfcpp::R_POWERPC_GOT_TLSGD16:
7258 case elfcpp::R_POWERPC_GOT_TLSLD16:
7259 case elfcpp::R_POWERPC_GOT_TPREL16:
7260 case elfcpp::R_POWERPC_GOT_DTPREL16:
7261 overflow = Reloc::CHECK_SIGNED;
7265 typename Powerpc_relocate_functions<size, big_endian>::Status status
7266 = Powerpc_relocate_functions<size, big_endian>::STATUS_OK;
7269 case elfcpp::R_POWERPC_NONE:
7270 case elfcpp::R_POWERPC_TLS:
7271 case elfcpp::R_POWERPC_GNU_VTINHERIT:
7272 case elfcpp::R_POWERPC_GNU_VTENTRY:
7275 case elfcpp::R_PPC64_ADDR64:
7276 case elfcpp::R_PPC64_REL64:
7277 case elfcpp::R_PPC64_TOC:
7278 Reloc::addr64(view, value);
7281 case elfcpp::R_POWERPC_TPREL:
7282 case elfcpp::R_POWERPC_DTPREL:
7284 Reloc::addr64(view, value);
7286 status = Reloc::addr32(view, value, overflow);
7289 case elfcpp::R_PPC64_UADDR64:
7290 Reloc::addr64_u(view, value);
7293 case elfcpp::R_POWERPC_ADDR32:
7294 status = Reloc::addr32(view, value, overflow);
7297 case elfcpp::R_POWERPC_REL32:
7298 case elfcpp::R_POWERPC_UADDR32:
7299 status = Reloc::addr32_u(view, value, overflow);
7302 case elfcpp::R_POWERPC_ADDR24:
7303 case elfcpp::R_POWERPC_REL24:
7304 case elfcpp::R_PPC_PLTREL24:
7305 case elfcpp::R_PPC_LOCAL24PC:
7306 status = Reloc::addr24(view, value, overflow);
7309 case elfcpp::R_POWERPC_GOT_DTPREL16:
7310 case elfcpp::R_POWERPC_GOT_DTPREL16_LO:
7313 status = Reloc::addr16_ds(view, value, overflow);
7316 case elfcpp::R_POWERPC_ADDR16:
7317 case elfcpp::R_POWERPC_REL16:
7318 case elfcpp::R_PPC64_TOC16:
7319 case elfcpp::R_POWERPC_GOT16:
7320 case elfcpp::R_POWERPC_SECTOFF:
7321 case elfcpp::R_POWERPC_TPREL16:
7322 case elfcpp::R_POWERPC_DTPREL16:
7323 case elfcpp::R_POWERPC_GOT_TLSGD16:
7324 case elfcpp::R_POWERPC_GOT_TLSLD16:
7325 case elfcpp::R_POWERPC_GOT_TPREL16:
7326 case elfcpp::R_POWERPC_ADDR16_LO:
7327 case elfcpp::R_POWERPC_REL16_LO:
7328 case elfcpp::R_PPC64_TOC16_LO:
7329 case elfcpp::R_POWERPC_GOT16_LO:
7330 case elfcpp::R_POWERPC_SECTOFF_LO:
7331 case elfcpp::R_POWERPC_TPREL16_LO:
7332 case elfcpp::R_POWERPC_DTPREL16_LO:
7333 case elfcpp::R_POWERPC_GOT_TLSGD16_LO:
7334 case elfcpp::R_POWERPC_GOT_TLSLD16_LO:
7335 case elfcpp::R_POWERPC_GOT_TPREL16_LO:
7336 status = Reloc::addr16(view, value, overflow);
7339 case elfcpp::R_POWERPC_UADDR16:
7340 status = Reloc::addr16_u(view, value, overflow);
7343 case elfcpp::R_PPC64_ADDR16_HIGH:
7344 case elfcpp::R_PPC64_TPREL16_HIGH:
7345 case elfcpp::R_PPC64_DTPREL16_HIGH:
7347 // R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
7349 case elfcpp::R_POWERPC_ADDR16_HI:
7350 case elfcpp::R_POWERPC_REL16_HI:
7351 case elfcpp::R_PPC64_TOC16_HI:
7352 case elfcpp::R_POWERPC_GOT16_HI:
7353 case elfcpp::R_POWERPC_SECTOFF_HI:
7354 case elfcpp::R_POWERPC_TPREL16_HI:
7355 case elfcpp::R_POWERPC_DTPREL16_HI:
7356 case elfcpp::R_POWERPC_GOT_TLSGD16_HI:
7357 case elfcpp::R_POWERPC_GOT_TLSLD16_HI:
7358 case elfcpp::R_POWERPC_GOT_TPREL16_HI:
7359 case elfcpp::R_POWERPC_GOT_DTPREL16_HI:
7360 Reloc::addr16_hi(view, value);
7363 case elfcpp::R_PPC64_ADDR16_HIGHA:
7364 case elfcpp::R_PPC64_TPREL16_HIGHA:
7365 case elfcpp::R_PPC64_DTPREL16_HIGHA:
7367 // R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
7369 case elfcpp::R_POWERPC_ADDR16_HA:
7370 case elfcpp::R_POWERPC_REL16_HA:
7371 case elfcpp::R_PPC64_TOC16_HA:
7372 case elfcpp::R_POWERPC_GOT16_HA:
7373 case elfcpp::R_POWERPC_SECTOFF_HA:
7374 case elfcpp::R_POWERPC_TPREL16_HA:
7375 case elfcpp::R_POWERPC_DTPREL16_HA:
7376 case elfcpp::R_POWERPC_GOT_TLSGD16_HA:
7377 case elfcpp::R_POWERPC_GOT_TLSLD16_HA:
7378 case elfcpp::R_POWERPC_GOT_TPREL16_HA:
7379 case elfcpp::R_POWERPC_GOT_DTPREL16_HA:
7380 Reloc::addr16_ha(view, value);
7383 case elfcpp::R_PPC64_DTPREL16_HIGHER:
7385 // R_PPC_EMB_NADDR16_LO
7387 case elfcpp::R_PPC64_ADDR16_HIGHER:
7388 case elfcpp::R_PPC64_TPREL16_HIGHER:
7389 Reloc::addr16_hi2(view, value);
7392 case elfcpp::R_PPC64_DTPREL16_HIGHERA:
7394 // R_PPC_EMB_NADDR16_HI
7396 case elfcpp::R_PPC64_ADDR16_HIGHERA:
7397 case elfcpp::R_PPC64_TPREL16_HIGHERA:
7398 Reloc::addr16_ha2(view, value);
7401 case elfcpp::R_PPC64_DTPREL16_HIGHEST:
7403 // R_PPC_EMB_NADDR16_HA
7405 case elfcpp::R_PPC64_ADDR16_HIGHEST:
7406 case elfcpp::R_PPC64_TPREL16_HIGHEST:
7407 Reloc::addr16_hi3(view, value);
7410 case elfcpp::R_PPC64_DTPREL16_HIGHESTA:
7414 case elfcpp::R_PPC64_ADDR16_HIGHESTA:
7415 case elfcpp::R_PPC64_TPREL16_HIGHESTA:
7416 Reloc::addr16_ha3(view, value);
7419 case elfcpp::R_PPC64_DTPREL16_DS:
7420 case elfcpp::R_PPC64_DTPREL16_LO_DS:
7422 // R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
7424 case elfcpp::R_PPC64_TPREL16_DS:
7425 case elfcpp::R_PPC64_TPREL16_LO_DS:
7427 // R_PPC_TLSGD, R_PPC_TLSLD
7429 case elfcpp::R_PPC64_ADDR16_DS:
7430 case elfcpp::R_PPC64_ADDR16_LO_DS:
7431 case elfcpp::R_PPC64_TOC16_DS:
7432 case elfcpp::R_PPC64_TOC16_LO_DS:
7433 case elfcpp::R_PPC64_GOT16_DS:
7434 case elfcpp::R_PPC64_GOT16_LO_DS:
7435 case elfcpp::R_PPC64_SECTOFF_DS:
7436 case elfcpp::R_PPC64_SECTOFF_LO_DS:
7437 status = Reloc::addr16_ds(view, value, overflow);
7440 case elfcpp::R_POWERPC_ADDR14:
7441 case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
7442 case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
7443 case elfcpp::R_POWERPC_REL14:
7444 case elfcpp::R_POWERPC_REL14_BRTAKEN:
7445 case elfcpp::R_POWERPC_REL14_BRNTAKEN:
7446 status = Reloc::addr14(view, value, overflow);
7449 case elfcpp::R_POWERPC_COPY:
7450 case elfcpp::R_POWERPC_GLOB_DAT:
7451 case elfcpp::R_POWERPC_JMP_SLOT:
7452 case elfcpp::R_POWERPC_RELATIVE:
7453 case elfcpp::R_POWERPC_DTPMOD:
7454 case elfcpp::R_PPC64_JMP_IREL:
7455 case elfcpp::R_POWERPC_IRELATIVE:
7456 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
7457 _("unexpected reloc %u in object file"),
7461 case elfcpp::R_PPC_EMB_SDA21:
7466 // R_PPC64_TOCSAVE. For the time being this can be ignored.
7470 case elfcpp::R_PPC_EMB_SDA2I16:
7471 case elfcpp::R_PPC_EMB_SDA2REL:
7474 // R_PPC64_TLSGD, R_PPC64_TLSLD
7477 case elfcpp::R_POWERPC_PLT32:
7478 case elfcpp::R_POWERPC_PLTREL32:
7479 case elfcpp::R_POWERPC_PLT16_LO:
7480 case elfcpp::R_POWERPC_PLT16_HI:
7481 case elfcpp::R_POWERPC_PLT16_HA:
7482 case elfcpp::R_PPC_SDAREL16:
7483 case elfcpp::R_POWERPC_ADDR30:
7484 case elfcpp::R_PPC64_PLT64:
7485 case elfcpp::R_PPC64_PLTREL64:
7486 case elfcpp::R_PPC64_PLTGOT16:
7487 case elfcpp::R_PPC64_PLTGOT16_LO:
7488 case elfcpp::R_PPC64_PLTGOT16_HI:
7489 case elfcpp::R_PPC64_PLTGOT16_HA:
7490 case elfcpp::R_PPC64_PLT16_LO_DS:
7491 case elfcpp::R_PPC64_PLTGOT16_DS:
7492 case elfcpp::R_PPC64_PLTGOT16_LO_DS:
7493 case elfcpp::R_PPC_EMB_RELSDA:
7494 case elfcpp::R_PPC_TOC16:
7497 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
7498 _("unsupported reloc %u"),
7502 if (status != Powerpc_relocate_functions<size, big_endian>::STATUS_OK)
7503 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
7504 _("relocation overflow"));
7509 // Relocate section data.
7511 template<int size, bool big_endian>
7513 Target_powerpc<size, big_endian>::relocate_section(
7514 const Relocate_info<size, big_endian>* relinfo,
7515 unsigned int sh_type,
7516 const unsigned char* prelocs,
7518 Output_section* output_section,
7519 bool needs_special_offset_handling,
7520 unsigned char* view,
7522 section_size_type view_size,
7523 const Reloc_symbol_changes* reloc_symbol_changes)
7525 typedef Target_powerpc<size, big_endian> Powerpc;
7526 typedef typename Target_powerpc<size, big_endian>::Relocate Powerpc_relocate;
7527 typedef typename Target_powerpc<size, big_endian>::Relocate_comdat_behavior
7528 Powerpc_comdat_behavior;
7530 gold_assert(sh_type == elfcpp::SHT_RELA);
7532 gold::relocate_section<size, big_endian, Powerpc, elfcpp::SHT_RELA,
7533 Powerpc_relocate, Powerpc_comdat_behavior>(
7539 needs_special_offset_handling,
7543 reloc_symbol_changes);
7546 class Powerpc_scan_relocatable_reloc
7549 // Return the strategy to use for a local symbol which is not a
7550 // section symbol, given the relocation type.
7551 inline Relocatable_relocs::Reloc_strategy
7552 local_non_section_strategy(unsigned int r_type, Relobj*, unsigned int r_sym)
7554 if (r_type == 0 && r_sym == 0)
7555 return Relocatable_relocs::RELOC_DISCARD;
7556 return Relocatable_relocs::RELOC_COPY;
7559 // Return the strategy to use for a local symbol which is a section
7560 // symbol, given the relocation type.
7561 inline Relocatable_relocs::Reloc_strategy
7562 local_section_strategy(unsigned int, Relobj*)
7564 return Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA;
7567 // Return the strategy to use for a global symbol, given the
7568 // relocation type, the object, and the symbol index.
7569 inline Relocatable_relocs::Reloc_strategy
7570 global_strategy(unsigned int r_type, Relobj*, unsigned int)
7572 if (r_type == elfcpp::R_PPC_PLTREL24)
7573 return Relocatable_relocs::RELOC_SPECIAL;
7574 return Relocatable_relocs::RELOC_COPY;
7578 // Scan the relocs during a relocatable link.
7580 template<int size, bool big_endian>
7582 Target_powerpc<size, big_endian>::scan_relocatable_relocs(
7583 Symbol_table* symtab,
7585 Sized_relobj_file<size, big_endian>* object,
7586 unsigned int data_shndx,
7587 unsigned int sh_type,
7588 const unsigned char* prelocs,
7590 Output_section* output_section,
7591 bool needs_special_offset_handling,
7592 size_t local_symbol_count,
7593 const unsigned char* plocal_symbols,
7594 Relocatable_relocs* rr)
7596 gold_assert(sh_type == elfcpp::SHT_RELA);
7598 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
7599 Powerpc_scan_relocatable_reloc>(
7607 needs_special_offset_handling,
7613 // Emit relocations for a section.
7614 // This is a modified version of the function by the same name in
7615 // target-reloc.h. Using relocate_special_relocatable for
7616 // R_PPC_PLTREL24 would require duplication of the entire body of the
7617 // loop, so we may as well duplicate the whole thing.
7619 template<int size, bool big_endian>
7621 Target_powerpc<size, big_endian>::relocate_relocs(
7622 const Relocate_info<size, big_endian>* relinfo,
7623 unsigned int sh_type,
7624 const unsigned char* prelocs,
7626 Output_section* output_section,
7627 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
7628 const Relocatable_relocs* rr,
7630 Address view_address,
7632 unsigned char* reloc_view,
7633 section_size_type reloc_view_size)
7635 gold_assert(sh_type == elfcpp::SHT_RELA);
7637 typedef typename Reloc_types<elfcpp::SHT_RELA, size, big_endian>::Reloc
7639 typedef typename Reloc_types<elfcpp::SHT_RELA, size, big_endian>::Reloc_write
7641 const int reloc_size
7642 = Reloc_types<elfcpp::SHT_RELA, size, big_endian>::reloc_size;
7644 Powerpc_relobj<size, big_endian>* const object
7645 = static_cast<Powerpc_relobj<size, big_endian>*>(relinfo->object);
7646 const unsigned int local_count = object->local_symbol_count();
7647 unsigned int got2_shndx = object->got2_shndx();
7648 Address got2_addend = 0;
7649 if (got2_shndx != 0)
7651 got2_addend = object->get_output_section_offset(got2_shndx);
7652 gold_assert(got2_addend != invalid_address);
7655 unsigned char* pwrite = reloc_view;
7656 bool zap_next = false;
7657 for (size_t i = 0; i < reloc_count; ++i, prelocs += reloc_size)
7659 Relocatable_relocs::Reloc_strategy strategy = rr->strategy(i);
7660 if (strategy == Relocatable_relocs::RELOC_DISCARD)
7663 Reltype reloc(prelocs);
7664 Reltype_write reloc_write(pwrite);
7666 Address offset = reloc.get_r_offset();
7667 typename elfcpp::Elf_types<size>::Elf_WXword r_info = reloc.get_r_info();
7668 unsigned int r_sym = elfcpp::elf_r_sym<size>(r_info);
7669 unsigned int r_type = elfcpp::elf_r_type<size>(r_info);
7670 const unsigned int orig_r_sym = r_sym;
7671 typename elfcpp::Elf_types<size>::Elf_Swxword addend
7672 = reloc.get_r_addend();
7673 const Symbol* gsym = NULL;
7677 // We could arrange to discard these and other relocs for
7678 // tls optimised sequences in the strategy methods, but for
7679 // now do as BFD ld does.
7680 r_type = elfcpp::R_POWERPC_NONE;
7684 // Get the new symbol index.
7685 if (r_sym < local_count)
7689 case Relocatable_relocs::RELOC_COPY:
7690 case Relocatable_relocs::RELOC_SPECIAL:
7693 r_sym = object->symtab_index(r_sym);
7694 gold_assert(r_sym != -1U);
7698 case Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA:
7700 // We are adjusting a section symbol. We need to find
7701 // the symbol table index of the section symbol for
7702 // the output section corresponding to input section
7703 // in which this symbol is defined.
7704 gold_assert(r_sym < local_count);
7706 unsigned int shndx =
7707 object->local_symbol_input_shndx(r_sym, &is_ordinary);
7708 gold_assert(is_ordinary);
7709 Output_section* os = object->output_section(shndx);
7710 gold_assert(os != NULL);
7711 gold_assert(os->needs_symtab_index());
7712 r_sym = os->symtab_index();
7722 gsym = object->global_symbol(r_sym);
7723 gold_assert(gsym != NULL);
7724 if (gsym->is_forwarder())
7725 gsym = relinfo->symtab->resolve_forwards(gsym);
7727 gold_assert(gsym->has_symtab_index());
7728 r_sym = gsym->symtab_index();
7731 // Get the new offset--the location in the output section where
7732 // this relocation should be applied.
7733 if (static_cast<Address>(offset_in_output_section) != invalid_address)
7734 offset += offset_in_output_section;
7737 section_offset_type sot_offset =
7738 convert_types<section_offset_type, Address>(offset);
7739 section_offset_type new_sot_offset =
7740 output_section->output_offset(object, relinfo->data_shndx,
7742 gold_assert(new_sot_offset != -1);
7743 offset = new_sot_offset;
7746 // In an object file, r_offset is an offset within the section.
7747 // In an executable or dynamic object, generated by
7748 // --emit-relocs, r_offset is an absolute address.
7749 if (!parameters->options().relocatable())
7751 offset += view_address;
7752 if (static_cast<Address>(offset_in_output_section) != invalid_address)
7753 offset -= offset_in_output_section;
7756 // Handle the reloc addend based on the strategy.
7757 if (strategy == Relocatable_relocs::RELOC_COPY)
7759 else if (strategy == Relocatable_relocs::RELOC_ADJUST_FOR_SECTION_RELA)
7761 const Symbol_value<size>* psymval = object->local_symbol(orig_r_sym);
7762 addend = psymval->value(object, addend);
7764 else if (strategy == Relocatable_relocs::RELOC_SPECIAL)
7766 if (addend >= 32768)
7767 addend += got2_addend;
7772 if (!parameters->options().relocatable())
7774 if (r_type == elfcpp::R_POWERPC_GOT_TLSGD16
7775 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO
7776 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_HI
7777 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_HA)
7779 // First instruction of a global dynamic sequence,
7781 const bool final = gsym == NULL || gsym->final_value_is_known();
7782 switch (this->optimize_tls_gd(final))
7784 case tls::TLSOPT_TO_IE:
7785 r_type += (elfcpp::R_POWERPC_GOT_TPREL16
7786 - elfcpp::R_POWERPC_GOT_TLSGD16);
7788 case tls::TLSOPT_TO_LE:
7789 if (r_type == elfcpp::R_POWERPC_GOT_TLSGD16
7790 || r_type == elfcpp::R_POWERPC_GOT_TLSGD16_LO)
7791 r_type = elfcpp::R_POWERPC_TPREL16_HA;
7794 r_type = elfcpp::R_POWERPC_NONE;
7795 offset -= 2 * big_endian;
7802 else if (r_type == elfcpp::R_POWERPC_GOT_TLSLD16
7803 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_LO
7804 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_HI
7805 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_HA)
7807 // First instruction of a local dynamic sequence,
7809 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE)
7811 if (r_type == elfcpp::R_POWERPC_GOT_TLSLD16
7812 || r_type == elfcpp::R_POWERPC_GOT_TLSLD16_LO)
7814 r_type = elfcpp::R_POWERPC_TPREL16_HA;
7815 const Output_section* os = relinfo->layout->tls_segment()
7817 gold_assert(os != NULL);
7818 gold_assert(os->needs_symtab_index());
7819 r_sym = os->symtab_index();
7820 addend = dtp_offset;
7824 r_type = elfcpp::R_POWERPC_NONE;
7825 offset -= 2 * big_endian;
7829 else if (r_type == elfcpp::R_POWERPC_GOT_TPREL16
7830 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_LO
7831 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_HI
7832 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_HA)
7834 // First instruction of initial exec sequence.
7835 const bool final = gsym == NULL || gsym->final_value_is_known();
7836 if (this->optimize_tls_ie(final) == tls::TLSOPT_TO_LE)
7838 if (r_type == elfcpp::R_POWERPC_GOT_TPREL16
7839 || r_type == elfcpp::R_POWERPC_GOT_TPREL16_LO)
7840 r_type = elfcpp::R_POWERPC_TPREL16_HA;
7843 r_type = elfcpp::R_POWERPC_NONE;
7844 offset -= 2 * big_endian;
7848 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSGD)
7849 || (size == 32 && r_type == elfcpp::R_PPC_TLSGD))
7851 // Second instruction of a global dynamic sequence,
7852 // the __tls_get_addr call
7853 const bool final = gsym == NULL || gsym->final_value_is_known();
7854 switch (this->optimize_tls_gd(final))
7856 case tls::TLSOPT_TO_IE:
7857 r_type = elfcpp::R_POWERPC_NONE;
7860 case tls::TLSOPT_TO_LE:
7861 r_type = elfcpp::R_POWERPC_TPREL16_LO;
7862 offset += 2 * big_endian;
7869 else if ((size == 64 && r_type == elfcpp::R_PPC64_TLSLD)
7870 || (size == 32 && r_type == elfcpp::R_PPC_TLSLD))
7872 // Second instruction of a local dynamic sequence,
7873 // the __tls_get_addr call
7874 if (this->optimize_tls_ld() == tls::TLSOPT_TO_LE)
7876 const Output_section* os = relinfo->layout->tls_segment()
7878 gold_assert(os != NULL);
7879 gold_assert(os->needs_symtab_index());
7880 r_sym = os->symtab_index();
7881 addend = dtp_offset;
7882 r_type = elfcpp::R_POWERPC_TPREL16_LO;
7883 offset += 2 * big_endian;
7887 else if (r_type == elfcpp::R_POWERPC_TLS)
7889 // Second instruction of an initial exec sequence
7890 const bool final = gsym == NULL || gsym->final_value_is_known();
7891 if (this->optimize_tls_ie(final) == tls::TLSOPT_TO_LE)
7893 r_type = elfcpp::R_POWERPC_TPREL16_LO;
7894 offset += 2 * big_endian;
7899 reloc_write.put_r_offset(offset);
7900 reloc_write.put_r_info(elfcpp::elf_r_info<size>(r_sym, r_type));
7901 reloc_write.put_r_addend(addend);
7903 pwrite += reloc_size;
7906 gold_assert(static_cast<section_size_type>(pwrite - reloc_view)
7907 == reloc_view_size);
7910 // Return the value to use for a dynamic symbol which requires special
7911 // treatment. This is how we support equality comparisons of function
7912 // pointers across shared library boundaries, as described in the
7913 // processor specific ABI supplement.
7915 template<int size, bool big_endian>
7917 Target_powerpc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
7921 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
7922 for (typename Stub_tables::const_iterator p = this->stub_tables_.begin();
7923 p != this->stub_tables_.end();
7926 Address off = (*p)->find_plt_call_entry(gsym);
7927 if (off != invalid_address)
7928 return (*p)->stub_address() + off;
7934 // Return the PLT address to use for a local symbol.
7935 template<int size, bool big_endian>
7937 Target_powerpc<size, big_endian>::do_plt_address_for_local(
7938 const Relobj* object,
7939 unsigned int symndx) const
7943 const Sized_relobj<size, big_endian>* relobj
7944 = static_cast<const Sized_relobj<size, big_endian>*>(object);
7945 for (typename Stub_tables::const_iterator p = this->stub_tables_.begin();
7946 p != this->stub_tables_.end();
7949 Address off = (*p)->find_plt_call_entry(relobj->sized_relobj(),
7951 if (off != invalid_address)
7952 return (*p)->stub_address() + off;
7958 // Return the PLT address to use for a global symbol.
7959 template<int size, bool big_endian>
7961 Target_powerpc<size, big_endian>::do_plt_address_for_global(
7962 const Symbol* gsym) const
7966 for (typename Stub_tables::const_iterator p = this->stub_tables_.begin();
7967 p != this->stub_tables_.end();
7970 Address off = (*p)->find_plt_call_entry(gsym);
7971 if (off != invalid_address)
7972 return (*p)->stub_address() + off;
7978 // Return the offset to use for the GOT_INDX'th got entry which is
7979 // for a local tls symbol specified by OBJECT, SYMNDX.
7980 template<int size, bool big_endian>
7982 Target_powerpc<size, big_endian>::do_tls_offset_for_local(
7983 const Relobj* object,
7984 unsigned int symndx,
7985 unsigned int got_indx) const
7987 const Powerpc_relobj<size, big_endian>* ppc_object
7988 = static_cast<const Powerpc_relobj<size, big_endian>*>(object);
7989 if (ppc_object->local_symbol(symndx)->is_tls_symbol())
7991 for (Got_type got_type = GOT_TYPE_TLSGD;
7992 got_type <= GOT_TYPE_TPREL;
7993 got_type = Got_type(got_type + 1))
7994 if (ppc_object->local_has_got_offset(symndx, got_type))
7996 unsigned int off = ppc_object->local_got_offset(symndx, got_type);
7997 if (got_type == GOT_TYPE_TLSGD)
7999 if (off == got_indx * (size / 8))
8001 if (got_type == GOT_TYPE_TPREL)
8011 // Return the offset to use for the GOT_INDX'th got entry which is
8012 // for global tls symbol GSYM.
8013 template<int size, bool big_endian>
8015 Target_powerpc<size, big_endian>::do_tls_offset_for_global(
8017 unsigned int got_indx) const
8019 if (gsym->type() == elfcpp::STT_TLS)
8021 for (Got_type got_type = GOT_TYPE_TLSGD;
8022 got_type <= GOT_TYPE_TPREL;
8023 got_type = Got_type(got_type + 1))
8024 if (gsym->has_got_offset(got_type))
8026 unsigned int off = gsym->got_offset(got_type);
8027 if (got_type == GOT_TYPE_TLSGD)
8029 if (off == got_indx * (size / 8))
8031 if (got_type == GOT_TYPE_TPREL)
8041 // The selector for powerpc object files.
8043 template<int size, bool big_endian>
8044 class Target_selector_powerpc : public Target_selector
8047 Target_selector_powerpc()
8048 : Target_selector(size == 64 ? elfcpp::EM_PPC64 : elfcpp::EM_PPC,
8051 ? (big_endian ? "elf64-powerpc" : "elf64-powerpcle")
8052 : (big_endian ? "elf32-powerpc" : "elf32-powerpcle")),
8054 ? (big_endian ? "elf64ppc" : "elf64lppc")
8055 : (big_endian ? "elf32ppc" : "elf32lppc")))
8059 do_instantiate_target()
8060 { return new Target_powerpc<size, big_endian>(); }
8063 Target_selector_powerpc<32, true> target_selector_ppc32;
8064 Target_selector_powerpc<32, false> target_selector_ppc32le;
8065 Target_selector_powerpc<64, true> target_selector_ppc64;
8066 Target_selector_powerpc<64, false> target_selector_ppc64le;
8068 // Instantiate these constants for -O0
8069 template<int size, bool big_endian>
8070 const int Output_data_glink<size, big_endian>::pltresolve_size;
8071 template<int size, bool big_endian>
8072 const typename Stub_table<size, big_endian>::Address
8073 Stub_table<size, big_endian>::invalid_address;
8074 template<int size, bool big_endian>
8075 const typename Target_powerpc<size, big_endian>::Address
8076 Target_powerpc<size, big_endian>::invalid_address;
8078 } // End anonymous namespace.