1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // 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_sparc;
53 template<int size, bool big_endian>
54 class Target_sparc : public Sized_target<size, big_endian>
57 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
60 : Sized_target<size, big_endian>(&sparc_info),
61 got_(NULL), plt_(NULL), rela_dyn_(NULL), rela_ifunc_(NULL),
62 copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL)
67 // Process the relocations to determine unreferenced sections for
68 // garbage collection.
70 gc_process_relocs(Symbol_table* symtab,
72 Sized_relobj_file<size, big_endian>* object,
73 unsigned int data_shndx,
75 const unsigned char* prelocs,
77 Output_section* output_section,
78 bool needs_special_offset_handling,
79 size_t local_symbol_count,
80 const unsigned char* plocal_symbols);
82 // Scan the relocations to look for symbol adjustments.
84 scan_relocs(Symbol_table* symtab,
86 Sized_relobj_file<size, big_endian>* object,
87 unsigned int data_shndx,
89 const unsigned char* prelocs,
91 Output_section* output_section,
92 bool needs_special_offset_handling,
93 size_t local_symbol_count,
94 const unsigned char* plocal_symbols);
95 // Finalize the sections.
97 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
99 // Return the value to use for a dynamic which requires special
102 do_dynsym_value(const Symbol*) const;
104 // Relocate a section.
106 relocate_section(const Relocate_info<size, big_endian>*,
107 unsigned int sh_type,
108 const unsigned char* prelocs,
110 Output_section* output_section,
111 bool needs_special_offset_handling,
113 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
114 section_size_type view_size,
115 const Reloc_symbol_changes*);
117 // Scan the relocs during a relocatable link.
119 scan_relocatable_relocs(Symbol_table* symtab,
121 Sized_relobj_file<size, big_endian>* object,
122 unsigned int data_shndx,
123 unsigned int sh_type,
124 const unsigned char* prelocs,
126 Output_section* output_section,
127 bool needs_special_offset_handling,
128 size_t local_symbol_count,
129 const unsigned char* plocal_symbols,
130 Relocatable_relocs*);
132 // Relocate a section during a relocatable link.
134 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
135 unsigned int sh_type,
136 const unsigned char* prelocs,
138 Output_section* output_section,
139 off_t offset_in_output_section,
140 const Relocatable_relocs*,
142 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
143 section_size_type view_size,
144 unsigned char* reloc_view,
145 section_size_type reloc_view_size);
146 // Return whether SYM is defined by the ABI.
148 do_is_defined_by_abi(const Symbol* sym) const
150 // XXX Really need to support this better...
151 if (sym->type() == elfcpp::STT_SPARC_REGISTER)
154 return strcmp(sym->name(), "___tls_get_addr") == 0;
157 // Return the PLT address to use for a global symbol.
159 do_plt_address_for_global(const Symbol* gsym) const
160 { return this->plt_section()->address_for_global(gsym); }
163 do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
164 { return this->plt_section()->address_for_local(relobj, symndx); }
166 // Return whether there is a GOT section.
168 has_got_section() const
169 { return this->got_ != NULL; }
171 // Return the size of the GOT section.
175 gold_assert(this->got_ != NULL);
176 return this->got_->data_size();
179 // Return the number of entries in the GOT.
181 got_entry_count() const
183 if (this->got_ == NULL)
185 return this->got_size() / (size / 8);
188 // Return the address of the GOT.
192 if (this->got_ == NULL)
194 return this->got_->address();
197 // Return the number of entries in the PLT.
199 plt_entry_count() const;
201 // Return the offset of the first non-reserved PLT entry.
203 first_plt_entry_offset() const;
205 // Return the size of each PLT entry.
207 plt_entry_size() const;
211 // The class which scans relocations.
216 : issued_non_pic_error_(false)
220 get_reference_flags(unsigned int r_type);
223 local(Symbol_table* symtab, Layout* layout, Target_sparc* target,
224 Sized_relobj_file<size, big_endian>* object,
225 unsigned int data_shndx,
226 Output_section* output_section,
227 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
228 const elfcpp::Sym<size, big_endian>& lsym);
231 global(Symbol_table* symtab, Layout* layout, Target_sparc* target,
232 Sized_relobj_file<size, big_endian>* object,
233 unsigned int data_shndx,
234 Output_section* output_section,
235 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
239 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
241 Sized_relobj_file<size, big_endian>* ,
244 const elfcpp::Rela<size, big_endian>& ,
246 const elfcpp::Sym<size, big_endian>&)
250 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
252 Sized_relobj_file<size, big_endian>* ,
255 const elfcpp::Rela<size,
257 unsigned int , Symbol*)
263 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
264 unsigned int r_type);
267 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
268 unsigned int r_type, Symbol*);
271 generate_tls_call(Symbol_table* symtab, Layout* layout,
272 Target_sparc* target);
275 check_non_pic(Relobj*, unsigned int r_type);
278 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*,
279 unsigned int r_type);
281 // Whether we have issued an error about a non-PIC compilation.
282 bool issued_non_pic_error_;
285 // The class which implements relocation.
290 : ignore_gd_add_(false), reloc_adjust_addr_(NULL)
295 if (this->ignore_gd_add_)
297 // FIXME: This needs to specify the location somehow.
298 gold_error(_("missing expected TLS relocation"));
302 // Do a relocation. Return false if the caller should not issue
303 // any warnings about this relocation.
305 relocate(const Relocate_info<size, big_endian>*, Target_sparc*,
306 Output_section*, size_t relnum,
307 const elfcpp::Rela<size, big_endian>&,
308 unsigned int r_type, const Sized_symbol<size>*,
309 const Symbol_value<size>*,
311 typename elfcpp::Elf_types<size>::Elf_Addr,
315 // Do a TLS relocation.
317 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
318 size_t relnum, const elfcpp::Rela<size, big_endian>&,
319 unsigned int r_type, const Sized_symbol<size>*,
320 const Symbol_value<size>*,
322 typename elfcpp::Elf_types<size>::Elf_Addr,
325 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
328 // If we hit a reloc at this view address, adjust it back by 4 bytes.
329 unsigned char *reloc_adjust_addr_;
332 // A class which returns the size required for a relocation type,
333 // used while scanning relocs during a relocatable link.
334 class Relocatable_size_for_reloc
338 get_size_for_reloc(unsigned int, Relobj*);
341 // Get the GOT section, creating it if necessary.
342 Output_data_got<size, big_endian>*
343 got_section(Symbol_table*, Layout*);
345 // Create the PLT section.
347 make_plt_section(Symbol_table* symtab, Layout* layout);
349 // Create a PLT entry for a global symbol.
351 make_plt_entry(Symbol_table*, Layout*, Symbol*);
353 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
355 make_local_ifunc_plt_entry(Symbol_table*, Layout*,
356 Sized_relobj_file<size, big_endian>* relobj,
357 unsigned int local_sym_index);
359 // Create a GOT entry for the TLS module index.
361 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
362 Sized_relobj_file<size, big_endian>* object);
364 // Return the gsym for "__tls_get_addr". Cache if not already
367 tls_get_addr_sym(Symbol_table* symtab)
369 if (!this->tls_get_addr_sym_)
370 this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL);
371 gold_assert(this->tls_get_addr_sym_);
372 return this->tls_get_addr_sym_;
375 // Get the PLT section.
376 Output_data_plt_sparc<size, big_endian>*
379 gold_assert(this->plt_ != NULL);
383 // Get the dynamic reloc section, creating it if necessary.
385 rela_dyn_section(Layout*);
387 // Get the section to use for IFUNC relocations.
389 rela_ifunc_section(Layout*);
391 // Copy a relocation against a global symbol.
393 copy_reloc(Symbol_table* symtab, Layout* layout,
394 Sized_relobj_file<size, big_endian>* object,
395 unsigned int shndx, Output_section* output_section,
396 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
398 this->copy_relocs_.copy_reloc(symtab, layout,
399 symtab->get_sized_symbol<size>(sym),
400 object, shndx, output_section,
401 reloc, this->rela_dyn_section(layout));
404 // Information about this specific target which we pass to the
405 // general Target structure.
406 static Target::Target_info sparc_info;
408 // The types of GOT entries needed for this platform.
409 // These values are exposed to the ABI in an incremental link.
410 // Do not renumber existing values without changing the version
411 // number of the .gnu_incremental_inputs section.
414 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
415 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
416 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
420 Output_data_got<size, big_endian>* got_;
422 Output_data_plt_sparc<size, big_endian>* plt_;
423 // The dynamic reloc section.
424 Reloc_section* rela_dyn_;
425 // The section to use for IFUNC relocs.
426 Reloc_section* rela_ifunc_;
427 // Relocs saved to avoid a COPY reloc.
428 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
429 // Space for variables copied with a COPY reloc.
430 Output_data_space* dynbss_;
431 // Offset of the GOT entry for the TLS module index;
432 unsigned int got_mod_index_offset_;
433 // Cached pointer to __tls_get_addr symbol
434 Symbol* tls_get_addr_sym_;
438 Target::Target_info Target_sparc<32, true>::sparc_info =
441 true, // is_big_endian
442 elfcpp::EM_SPARC, // machine_code
443 false, // has_make_symbol
444 false, // has_resolve
445 false, // has_code_fill
446 true, // is_default_stack_executable
447 false, // can_icf_inline_merge_sections
449 "/usr/lib/ld.so.1", // dynamic_linker
450 0x00010000, // default_text_segment_address
451 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
452 8 * 1024, // common_pagesize (overridable by -z common-page-size)
453 elfcpp::SHN_UNDEF, // small_common_shndx
454 elfcpp::SHN_UNDEF, // large_common_shndx
455 0, // small_common_section_flags
456 0, // large_common_section_flags
457 NULL, // attributes_section
458 NULL // attributes_vendor
462 Target::Target_info Target_sparc<64, true>::sparc_info =
465 true, // is_big_endian
466 elfcpp::EM_SPARCV9, // machine_code
467 false, // has_make_symbol
468 false, // has_resolve
469 false, // has_code_fill
470 true, // is_default_stack_executable
471 false, // can_icf_inline_merge_sections
473 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
474 0x100000, // default_text_segment_address
475 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
476 8 * 1024, // common_pagesize (overridable by -z common-page-size)
477 elfcpp::SHN_UNDEF, // small_common_shndx
478 elfcpp::SHN_UNDEF, // large_common_shndx
479 0, // small_common_section_flags
480 0, // large_common_section_flags
481 NULL, // attributes_section
482 NULL // attributes_vendor
485 // We have to take care here, even when operating in little-endian
486 // mode, sparc instructions are still big endian.
487 template<int size, bool big_endian>
488 class Sparc_relocate_functions
491 // Do a simple relocation with the addend in the relocation.
492 template<int valsize>
494 rela(unsigned char* view,
495 unsigned int right_shift,
496 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
497 typename elfcpp::Swap<size, big_endian>::Valtype value,
498 typename elfcpp::Swap<size, big_endian>::Valtype addend)
500 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
501 Valtype* wv = reinterpret_cast<Valtype*>(view);
502 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
503 Valtype reloc = ((value + addend) >> right_shift);
508 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
511 // Do a simple relocation using a symbol value with the addend in
513 template<int valsize>
515 rela(unsigned char* view,
516 unsigned int right_shift,
517 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
518 const Sized_relobj_file<size, big_endian>* object,
519 const Symbol_value<size>* psymval,
520 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
522 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
523 Valtype* wv = reinterpret_cast<Valtype*>(view);
524 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
525 Valtype reloc = (psymval->value(object, addend) >> right_shift);
530 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
533 // Do a simple relocation using a symbol value with the addend in
534 // the relocation, unaligned.
535 template<int valsize>
537 rela_ua(unsigned char* view,
538 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
539 const Sized_relobj_file<size, big_endian>* object,
540 const Symbol_value<size>* psymval,
541 typename elfcpp::Swap<size, big_endian>::Valtype addend)
543 typedef typename elfcpp::Swap_unaligned<valsize,
544 big_endian>::Valtype Valtype;
545 unsigned char* wv = view;
546 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
547 Valtype reloc = (psymval->value(object, addend) >> right_shift);
552 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
555 // Do a simple PC relative relocation with a Symbol_value with the
556 // addend in the relocation.
557 template<int valsize>
559 pcrela(unsigned char* view,
560 unsigned int right_shift,
561 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
562 const Sized_relobj_file<size, big_endian>* object,
563 const Symbol_value<size>* psymval,
564 typename elfcpp::Swap<size, big_endian>::Valtype addend,
565 typename elfcpp::Elf_types<size>::Elf_Addr address)
567 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
568 Valtype* wv = reinterpret_cast<Valtype*>(view);
569 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
570 Valtype reloc = ((psymval->value(object, addend) - address)
576 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
579 template<int valsize>
581 pcrela_unaligned(unsigned char* view,
582 const Sized_relobj_file<size, big_endian>* object,
583 const Symbol_value<size>* psymval,
584 typename elfcpp::Swap<size, big_endian>::Valtype addend,
585 typename elfcpp::Elf_types<size>::Elf_Addr address)
587 typedef typename elfcpp::Swap_unaligned<valsize,
588 big_endian>::Valtype Valtype;
589 unsigned char* wv = view;
590 Valtype reloc = (psymval->value(object, addend) - address);
592 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
595 typedef Sparc_relocate_functions<size, big_endian> This;
596 typedef Sparc_relocate_functions<size, true> This_insn;
599 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
601 wdisp30(unsigned char* view,
602 const Sized_relobj_file<size, big_endian>* object,
603 const Symbol_value<size>* psymval,
604 typename elfcpp::Elf_types<size>::Elf_Addr addend,
605 typename elfcpp::Elf_types<size>::Elf_Addr address)
607 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
608 psymval, addend, address);
611 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
613 wdisp22(unsigned char* view,
614 const Sized_relobj_file<size, big_endian>* object,
615 const Symbol_value<size>* psymval,
616 typename elfcpp::Elf_types<size>::Elf_Addr addend,
617 typename elfcpp::Elf_types<size>::Elf_Addr address)
619 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
620 psymval, addend, address);
623 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
625 wdisp19(unsigned char* view,
626 const Sized_relobj_file<size, big_endian>* object,
627 const Symbol_value<size>* psymval,
628 typename elfcpp::Elf_types<size>::Elf_Addr addend,
629 typename elfcpp::Elf_types<size>::Elf_Addr address)
631 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
632 psymval, addend, address);
635 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
637 wdisp16(unsigned char* view,
638 const Sized_relobj_file<size, big_endian>* object,
639 const Symbol_value<size>* psymval,
640 typename elfcpp::Elf_types<size>::Elf_Addr addend,
641 typename elfcpp::Elf_types<size>::Elf_Addr address)
643 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
644 Valtype* wv = reinterpret_cast<Valtype*>(view);
645 Valtype val = elfcpp::Swap<32, true>::readval(wv);
646 Valtype reloc = ((psymval->value(object, addend) - address)
649 // The relocation value is split between the low 14 bits,
651 val &= ~((0x3 << 20) | 0x3fff);
652 reloc = (((reloc & 0xc000) << (20 - 14))
653 | (reloc & 0x3ffff));
655 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
658 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
660 wdisp10(unsigned char* view,
661 const Sized_relobj_file<size, big_endian>* object,
662 const Symbol_value<size>* psymval,
663 typename elfcpp::Elf_types<size>::Elf_Addr addend,
664 typename elfcpp::Elf_types<size>::Elf_Addr address)
666 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
667 Valtype* wv = reinterpret_cast<Valtype*>(view);
668 Valtype val = elfcpp::Swap<32, true>::readval(wv);
669 Valtype reloc = ((psymval->value(object, addend) - address)
672 // The relocation value is split between the low bits 5-12,
673 // and high bits 19-20.
674 val &= ~((0x3 << 19) | (0xff << 5));
675 reloc = (((reloc & 0x300) << (19 - 8))
676 | ((reloc & 0xff) << (5 - 0)));
678 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
681 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
683 pc22(unsigned char* view,
684 const Sized_relobj_file<size, big_endian>* object,
685 const Symbol_value<size>* psymval,
686 typename elfcpp::Elf_types<size>::Elf_Addr addend,
687 typename elfcpp::Elf_types<size>::Elf_Addr address)
689 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
690 psymval, addend, address);
693 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
695 pc10(unsigned char* view,
696 const Sized_relobj_file<size, big_endian>* object,
697 const Symbol_value<size>* psymval,
698 typename elfcpp::Elf_types<size>::Elf_Addr addend,
699 typename elfcpp::Elf_types<size>::Elf_Addr address)
701 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
702 psymval, addend, address);
705 // R_SPARC_HI22: (Symbol + Addend) >> 10
707 hi22(unsigned char* view,
708 typename elfcpp::Elf_types<size>::Elf_Addr value,
709 typename elfcpp::Elf_types<size>::Elf_Addr addend)
711 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
714 // R_SPARC_HI22: (Symbol + Addend) >> 10
716 hi22(unsigned char* view,
717 const Sized_relobj_file<size, big_endian>* object,
718 const Symbol_value<size>* psymval,
719 typename elfcpp::Elf_types<size>::Elf_Addr addend)
721 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
724 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
726 pcplt22(unsigned char* view,
727 const Sized_relobj_file<size, big_endian>* object,
728 const Symbol_value<size>* psymval,
729 typename elfcpp::Elf_types<size>::Elf_Addr addend,
730 typename elfcpp::Elf_types<size>::Elf_Addr address)
732 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
733 psymval, addend, address);
736 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
738 lo10(unsigned char* view,
739 typename elfcpp::Elf_types<size>::Elf_Addr value,
740 typename elfcpp::Elf_types<size>::Elf_Addr addend)
742 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
745 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
747 lo10(unsigned char* view,
748 const Sized_relobj_file<size, big_endian>* object,
749 const Symbol_value<size>* psymval,
750 typename elfcpp::Elf_types<size>::Elf_Addr addend)
752 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
755 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
757 lo10(unsigned char* view,
758 const Sized_relobj_file<size, big_endian>* object,
759 const Symbol_value<size>* psymval,
760 typename elfcpp::Elf_types<size>::Elf_Addr addend,
761 typename elfcpp::Elf_types<size>::Elf_Addr address)
763 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
764 psymval, addend, address);
767 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
769 olo10(unsigned char* view,
770 const Sized_relobj_file<size, big_endian>* object,
771 const Symbol_value<size>* psymval,
772 typename elfcpp::Elf_types<size>::Elf_Addr addend,
773 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
775 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
776 Valtype* wv = reinterpret_cast<Valtype*>(view);
777 Valtype val = elfcpp::Swap<32, true>::readval(wv);
778 Valtype reloc = psymval->value(object, addend);
785 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
788 // R_SPARC_22: (Symbol + Addend)
790 rela32_22(unsigned char* view,
791 const Sized_relobj_file<size, big_endian>* object,
792 const Symbol_value<size>* psymval,
793 typename elfcpp::Elf_types<size>::Elf_Addr addend)
795 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
798 // R_SPARC_13: (Symbol + Addend)
800 rela32_13(unsigned char* view,
801 typename elfcpp::Elf_types<size>::Elf_Addr value,
802 typename elfcpp::Elf_types<size>::Elf_Addr addend)
804 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
807 // R_SPARC_13: (Symbol + Addend)
809 rela32_13(unsigned char* view,
810 const Sized_relobj_file<size, big_endian>* object,
811 const Symbol_value<size>* psymval,
812 typename elfcpp::Elf_types<size>::Elf_Addr addend)
814 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
817 // R_SPARC_UA16: (Symbol + Addend)
819 ua16(unsigned char* view,
820 const Sized_relobj_file<size, big_endian>* object,
821 const Symbol_value<size>* psymval,
822 typename elfcpp::Elf_types<size>::Elf_Addr addend)
824 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
827 // R_SPARC_UA32: (Symbol + Addend)
829 ua32(unsigned char* view,
830 const Sized_relobj_file<size, big_endian>* object,
831 const Symbol_value<size>* psymval,
832 typename elfcpp::Elf_types<size>::Elf_Addr addend)
834 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
837 // R_SPARC_UA64: (Symbol + Addend)
839 ua64(unsigned char* view,
840 const Sized_relobj_file<size, big_endian>* object,
841 const Symbol_value<size>* psymval,
842 typename elfcpp::Elf_types<size>::Elf_Addr addend)
844 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
845 object, psymval, addend);
848 // R_SPARC_DISP8: (Symbol + Addend - Address)
850 disp8(unsigned char* view,
851 const Sized_relobj_file<size, big_endian>* object,
852 const Symbol_value<size>* psymval,
853 typename elfcpp::Elf_types<size>::Elf_Addr addend,
854 typename elfcpp::Elf_types<size>::Elf_Addr address)
856 This::template pcrela_unaligned<8>(view, object, psymval,
860 // R_SPARC_DISP16: (Symbol + Addend - Address)
862 disp16(unsigned char* view,
863 const Sized_relobj_file<size, big_endian>* object,
864 const Symbol_value<size>* psymval,
865 typename elfcpp::Elf_types<size>::Elf_Addr addend,
866 typename elfcpp::Elf_types<size>::Elf_Addr address)
868 This::template pcrela_unaligned<16>(view, object, psymval,
872 // R_SPARC_DISP32: (Symbol + Addend - Address)
874 disp32(unsigned char* view,
875 const Sized_relobj_file<size, big_endian>* object,
876 const Symbol_value<size>* psymval,
877 typename elfcpp::Elf_types<size>::Elf_Addr addend,
878 typename elfcpp::Elf_types<size>::Elf_Addr address)
880 This::template pcrela_unaligned<32>(view, object, psymval,
884 // R_SPARC_DISP64: (Symbol + Addend - Address)
886 disp64(unsigned char* view,
887 const Sized_relobj_file<size, big_endian>* object,
888 const Symbol_value<size>* psymval,
889 elfcpp::Elf_Xword addend,
890 typename elfcpp::Elf_types<size>::Elf_Addr address)
892 This::template pcrela_unaligned<64>(view, object, psymval,
896 // R_SPARC_H34: (Symbol + Addend) >> 12
898 h34(unsigned char* view,
899 const Sized_relobj_file<size, big_endian>* object,
900 const Symbol_value<size>* psymval,
901 typename elfcpp::Elf_types<size>::Elf_Addr addend)
903 This_insn::template rela<32>(view, 12, 0x003fffff, object, psymval, addend);
906 // R_SPARC_H44: (Symbol + Addend) >> 22
908 h44(unsigned char* view,
909 const Sized_relobj_file<size, big_endian>* object,
910 const Symbol_value<size>* psymval,
911 typename elfcpp::Elf_types<size>::Elf_Addr addend)
913 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
916 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
918 m44(unsigned char* view,
919 const Sized_relobj_file<size, big_endian>* object,
920 const Symbol_value<size>* psymval,
921 typename elfcpp::Elf_types<size>::Elf_Addr addend)
923 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
926 // R_SPARC_L44: (Symbol + Addend) & 0xfff
928 l44(unsigned char* view,
929 const Sized_relobj_file<size, big_endian>* object,
930 const Symbol_value<size>* psymval,
931 typename elfcpp::Elf_types<size>::Elf_Addr addend)
933 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
936 // R_SPARC_HH22: (Symbol + Addend) >> 42
938 hh22(unsigned char* view,
939 const Sized_relobj_file<size, big_endian>* object,
940 const Symbol_value<size>* psymval,
941 typename elfcpp::Elf_types<size>::Elf_Addr addend)
943 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
946 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
948 pc_hh22(unsigned char* view,
949 const Sized_relobj_file<size, big_endian>* object,
950 const Symbol_value<size>* psymval,
951 typename elfcpp::Elf_types<size>::Elf_Addr addend,
952 typename elfcpp::Elf_types<size>::Elf_Addr address)
954 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
955 psymval, addend, address);
958 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
960 hm10(unsigned char* view,
961 const Sized_relobj_file<size, big_endian>* object,
962 const Symbol_value<size>* psymval,
963 typename elfcpp::Elf_types<size>::Elf_Addr addend)
965 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
968 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
970 pc_hm10(unsigned char* view,
971 const Sized_relobj_file<size, big_endian>* object,
972 const Symbol_value<size>* psymval,
973 typename elfcpp::Elf_types<size>::Elf_Addr addend,
974 typename elfcpp::Elf_types<size>::Elf_Addr address)
976 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
977 psymval, addend, address);
980 // R_SPARC_11: (Symbol + Addend)
982 rela32_11(unsigned char* view,
983 const Sized_relobj_file<size, big_endian>* object,
984 const Symbol_value<size>* psymval,
985 typename elfcpp::Elf_types<size>::Elf_Addr addend)
987 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
990 // R_SPARC_10: (Symbol + Addend)
992 rela32_10(unsigned char* view,
993 const Sized_relobj_file<size, big_endian>* object,
994 const Symbol_value<size>* psymval,
995 typename elfcpp::Elf_types<size>::Elf_Addr addend)
997 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
1000 // R_SPARC_7: (Symbol + Addend)
1002 rela32_7(unsigned char* view,
1003 const Sized_relobj_file<size, big_endian>* object,
1004 const Symbol_value<size>* psymval,
1005 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1007 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
1010 // R_SPARC_6: (Symbol + Addend)
1012 rela32_6(unsigned char* view,
1013 const Sized_relobj_file<size, big_endian>* object,
1014 const Symbol_value<size>* psymval,
1015 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1017 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
1020 // R_SPARC_5: (Symbol + Addend)
1022 rela32_5(unsigned char* view,
1023 const Sized_relobj_file<size, big_endian>* object,
1024 const Symbol_value<size>* psymval,
1025 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1027 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
1030 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1032 ldo_hix22(unsigned char* view,
1033 typename elfcpp::Elf_types<size>::Elf_Addr value,
1034 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1036 This_insn::hi22(view, value, addend);
1039 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1041 ldo_lox10(unsigned char* view,
1042 typename elfcpp::Elf_types<size>::Elf_Addr value,
1043 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1045 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1046 Valtype* wv = reinterpret_cast<Valtype*>(view);
1047 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1048 Valtype reloc = (value + addend);
1053 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1056 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1058 hix22(unsigned char* view,
1059 typename elfcpp::Elf_types<size>::Elf_Addr value,
1060 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1062 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1063 Valtype* wv = reinterpret_cast<Valtype*>(view);
1064 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1065 Valtype reloc = (value + addend);
1069 reloc ^= ~(Valtype)0;
1074 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1077 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1079 gdop_hix22(unsigned char* view,
1080 typename elfcpp::Elf_types<size>::Elf_Addr value,
1081 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1083 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1084 Valtype* wv = reinterpret_cast<Valtype*>(view);
1085 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1086 int32_t reloc = static_cast<int32_t>(value + addend);
1091 reloc ^= ~static_cast<int32_t>(0);
1096 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1099 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1101 hix22(unsigned char* view,
1102 const Sized_relobj_file<size, big_endian>* object,
1103 const Symbol_value<size>* psymval,
1104 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1106 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1107 Valtype* wv = reinterpret_cast<Valtype*>(view);
1108 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1109 Valtype reloc = psymval->value(object, addend);
1113 reloc ^= ~(Valtype)0;
1118 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1122 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1124 lox10(unsigned char* view,
1125 typename elfcpp::Elf_types<size>::Elf_Addr value,
1126 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1128 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1129 Valtype* wv = reinterpret_cast<Valtype*>(view);
1130 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1131 Valtype reloc = (value + addend);
1137 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1140 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1142 gdop_lox10(unsigned char* view,
1143 typename elfcpp::Elf_types<size>::Elf_Addr value,
1144 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1146 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1147 Valtype* wv = reinterpret_cast<Valtype*>(view);
1148 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1149 int32_t reloc = static_cast<int32_t>(value + addend);
1152 reloc = (reloc & 0x3ff) | 0x1c00;
1154 reloc = (reloc & 0x3ff);
1157 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1160 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1162 lox10(unsigned char* view,
1163 const Sized_relobj_file<size, big_endian>* object,
1164 const Symbol_value<size>* psymval,
1165 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1167 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1168 Valtype* wv = reinterpret_cast<Valtype*>(view);
1169 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1170 Valtype reloc = psymval->value(object, addend);
1176 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1180 // Get the GOT section, creating it if necessary.
1182 template<int size, bool big_endian>
1183 Output_data_got<size, big_endian>*
1184 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
1187 if (this->got_ == NULL)
1189 gold_assert(symtab != NULL && layout != NULL);
1191 this->got_ = new Output_data_got<size, big_endian>();
1193 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1195 | elfcpp::SHF_WRITE),
1196 this->got_, ORDER_RELRO, true);
1198 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1199 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1200 Symbol_table::PREDEFINED,
1202 0, 0, elfcpp::STT_OBJECT,
1204 elfcpp::STV_HIDDEN, 0,
1211 // Get the dynamic reloc section, creating it if necessary.
1213 template<int size, bool big_endian>
1214 typename Target_sparc<size, big_endian>::Reloc_section*
1215 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1217 if (this->rela_dyn_ == NULL)
1219 gold_assert(layout != NULL);
1220 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1221 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1222 elfcpp::SHF_ALLOC, this->rela_dyn_,
1223 ORDER_DYNAMIC_RELOCS, false);
1225 return this->rela_dyn_;
1228 // Get the section to use for IFUNC relocs, creating it if
1229 // necessary. These go in .rela.dyn, but only after all other dynamic
1230 // relocations. They need to follow the other dynamic relocations so
1231 // that they can refer to global variables initialized by those
1234 template<int size, bool big_endian>
1235 typename Target_sparc<size, big_endian>::Reloc_section*
1236 Target_sparc<size, big_endian>::rela_ifunc_section(Layout* layout)
1238 if (this->rela_ifunc_ == NULL)
1240 // Make sure we have already created the dynamic reloc section.
1241 this->rela_dyn_section(layout);
1242 this->rela_ifunc_ = new Reloc_section(false);
1243 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1244 elfcpp::SHF_ALLOC, this->rela_ifunc_,
1245 ORDER_DYNAMIC_RELOCS, false);
1246 gold_assert(this->rela_dyn_->output_section()
1247 == this->rela_ifunc_->output_section());
1249 return this->rela_ifunc_;
1252 // A class to handle the PLT data.
1254 template<int size, bool big_endian>
1255 class Output_data_plt_sparc : public Output_section_data
1258 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1259 size, big_endian> Reloc_section;
1261 Output_data_plt_sparc(Layout*);
1263 // Add an entry to the PLT.
1264 void add_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym);
1266 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1268 add_local_ifunc_entry(Symbol_table*, Layout*,
1269 Sized_relobj_file<size, big_endian>* relobj,
1270 unsigned int local_sym_index);
1272 // Return the .rela.plt section data.
1273 const Reloc_section* rel_plt() const
1278 // Return where the IFUNC relocations should go.
1280 rela_ifunc(Symbol_table*, Layout*);
1283 emit_pending_ifunc_relocs();
1285 // Return whether we created a section for IFUNC relocations.
1287 has_ifunc_section() const
1288 { return this->ifunc_rel_ != NULL; }
1290 // Return the number of PLT entries.
1293 { return this->count_ + this->ifunc_count_; }
1295 // Return the offset of the first non-reserved PLT entry.
1297 first_plt_entry_offset()
1298 { return 4 * base_plt_entry_size; }
1300 // Return the size of a PLT entry.
1302 get_plt_entry_size()
1303 { return base_plt_entry_size; }
1305 // Return the PLT address to use for a global symbol.
1307 address_for_global(const Symbol*);
1309 // Return the PLT address to use for a local symbol.
1311 address_for_local(const Relobj*, unsigned int symndx);
1314 void do_adjust_output_section(Output_section* os);
1316 // Write to a map file.
1318 do_print_to_mapfile(Mapfile* mapfile) const
1319 { mapfile->print_output_data(this, _("** PLT")); }
1322 // The size of an entry in the PLT.
1323 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1325 static const unsigned int plt_entries_per_block = 160;
1326 static const unsigned int plt_insn_chunk_size = 24;
1327 static const unsigned int plt_pointer_chunk_size = 8;
1328 static const unsigned int plt_block_size =
1329 (plt_entries_per_block
1330 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1333 plt_index_to_offset(unsigned int index)
1335 section_offset_type offset;
1337 if (size == 32 || index < 32768)
1338 offset = index * base_plt_entry_size;
1341 unsigned int ext_index = index - 32768;
1343 offset = (32768 * base_plt_entry_size)
1344 + ((ext_index / plt_entries_per_block)
1346 + ((ext_index % plt_entries_per_block)
1347 * plt_insn_chunk_size);
1352 // Set the final size.
1354 set_final_data_size()
1356 unsigned int full_count = this->entry_count() + 4;
1357 unsigned int extra = (size == 32 ? 4 : 0);
1358 section_offset_type sz = plt_index_to_offset(full_count) + extra;
1360 return this->set_data_size(sz);
1363 // Write out the PLT data.
1365 do_write(Output_file*);
1371 unsigned int plt_index;
1377 Sized_relobj_file<size, big_endian>* object;
1378 unsigned int local_sym_index;
1379 unsigned int plt_index;
1382 // The reloc section.
1383 Reloc_section* rel_;
1384 // The IFUNC relocations, if necessary. These must follow the
1385 // regular relocations.
1386 Reloc_section* ifunc_rel_;
1387 // The number of PLT entries.
1388 unsigned int count_;
1389 // The number of PLT entries for IFUNC symbols.
1390 unsigned int ifunc_count_;
1391 // Global STT_GNU_IFUNC symbols.
1392 std::vector<Global_ifunc> global_ifuncs_;
1393 // Local STT_GNU_IFUNC symbols.
1394 std::vector<Local_ifunc> local_ifuncs_;
1397 // Define the constants as required by C++ standard.
1399 template<int size, bool big_endian>
1400 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1402 template<int size, bool big_endian>
1404 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1406 template<int size, bool big_endian>
1407 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1409 template<int size, bool big_endian>
1411 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1413 template<int size, bool big_endian>
1414 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1416 // Create the PLT section. The ordinary .got section is an argument,
1417 // since we need to refer to the start.
1419 template<int size, bool big_endian>
1420 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1421 : Output_section_data(size == 32 ? 4 : 8), ifunc_rel_(NULL),
1422 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1424 this->rel_ = new Reloc_section(false);
1425 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1426 elfcpp::SHF_ALLOC, this->rel_,
1427 ORDER_DYNAMIC_PLT_RELOCS, false);
1430 template<int size, bool big_endian>
1432 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1437 // Add an entry to the PLT.
1439 template<int size, bool big_endian>
1441 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol_table* symtab,
1445 gold_assert(!gsym->has_plt_offset());
1447 section_offset_type plt_offset;
1450 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1451 && gsym->can_use_relative_reloc(false))
1453 index = this->ifunc_count_;
1454 plt_offset = plt_index_to_offset(index);
1455 gsym->set_plt_offset(plt_offset);
1456 ++this->ifunc_count_;
1457 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1459 struct Global_ifunc gi;
1462 gi.plt_index = index;
1463 this->global_ifuncs_.push_back(gi);
1467 plt_offset = plt_index_to_offset(this->count_ + 4);
1468 gsym->set_plt_offset(plt_offset);
1470 gsym->set_needs_dynsym_entry();
1471 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1475 // Note that we don't need to save the symbol. The contents of the
1476 // PLT are independent of which symbols are used. The symbols only
1477 // appear in the relocations.
1480 template<int size, bool big_endian>
1482 Output_data_plt_sparc<size, big_endian>::add_local_ifunc_entry(
1483 Symbol_table* symtab,
1485 Sized_relobj_file<size, big_endian>* relobj,
1486 unsigned int local_sym_index)
1488 unsigned int index = this->ifunc_count_;
1489 section_offset_type plt_offset;
1491 plt_offset = plt_index_to_offset(index);
1492 ++this->ifunc_count_;
1494 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1496 struct Local_ifunc li;
1499 li.local_sym_index = local_sym_index;
1500 li.plt_index = index;
1501 this->local_ifuncs_.push_back(li);
1506 // Emit any pending IFUNC plt relocations.
1508 template<int size, bool big_endian>
1510 Output_data_plt_sparc<size, big_endian>::emit_pending_ifunc_relocs()
1512 // Emit any pending IFUNC relocs.
1513 for (typename std::vector<Global_ifunc>::const_iterator p =
1514 this->global_ifuncs_.begin();
1515 p != this->global_ifuncs_.end();
1518 section_offset_type plt_offset;
1521 index = this->count_ + p->plt_index + 4;
1522 plt_offset = this->plt_index_to_offset(index);
1523 p->rel->add_symbolless_global_addend(p->gsym, elfcpp::R_SPARC_JMP_IREL,
1524 this, plt_offset, 0);
1527 for (typename std::vector<Local_ifunc>::const_iterator p =
1528 this->local_ifuncs_.begin();
1529 p != this->local_ifuncs_.end();
1532 section_offset_type plt_offset;
1535 index = this->count_ + p->plt_index + 4;
1536 plt_offset = this->plt_index_to_offset(index);
1537 p->rel->add_symbolless_local_addend(p->object, p->local_sym_index,
1538 elfcpp::R_SPARC_JMP_IREL,
1539 this, plt_offset, 0);
1543 // Return where the IFUNC relocations should go in the PLT. These
1544 // follow the non-IFUNC relocations.
1546 template<int size, bool big_endian>
1547 typename Output_data_plt_sparc<size, big_endian>::Reloc_section*
1548 Output_data_plt_sparc<size, big_endian>::rela_ifunc(
1549 Symbol_table* symtab,
1552 if (this->ifunc_rel_ == NULL)
1554 this->ifunc_rel_ = new Reloc_section(false);
1555 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1556 elfcpp::SHF_ALLOC, this->ifunc_rel_,
1557 ORDER_DYNAMIC_PLT_RELOCS, false);
1558 gold_assert(this->ifunc_rel_->output_section()
1559 == this->rel_->output_section());
1561 if (parameters->doing_static_link())
1563 // A statically linked executable will only have a .rel.plt
1564 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1565 // relocs for STT_GNU_IFUNC symbols. The library will use
1566 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1567 // at program startup time.
1568 symtab->define_in_output_data("__rela_iplt_start", NULL,
1569 Symbol_table::PREDEFINED,
1570 this->ifunc_rel_, 0, 0,
1571 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1572 elfcpp::STV_HIDDEN, 0, false, true);
1573 symtab->define_in_output_data("__rela_iplt_end", NULL,
1574 Symbol_table::PREDEFINED,
1575 this->ifunc_rel_, 0, 0,
1576 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1577 elfcpp::STV_HIDDEN, 0, true, true);
1580 return this->ifunc_rel_;
1583 // Return the PLT address to use for a global symbol.
1585 template<int size, bool big_endian>
1587 Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
1589 uint64_t offset = 0;
1590 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1591 && gsym->can_use_relative_reloc(false))
1592 offset = plt_index_to_offset(this->count_ + 4);
1593 return this->address() + offset;
1596 // Return the PLT address to use for a local symbol. These are always
1597 // IRELATIVE relocs.
1599 template<int size, bool big_endian>
1601 Output_data_plt_sparc<size, big_endian>::address_for_local(
1605 return this->address() + plt_index_to_offset(this->count_ + 4);
1608 static const unsigned int sparc_nop = 0x01000000;
1609 static const unsigned int sparc_sethi_g1 = 0x03000000;
1610 static const unsigned int sparc_branch_always = 0x30800000;
1611 static const unsigned int sparc_branch_always_pt = 0x30680000;
1612 static const unsigned int sparc_mov = 0x80100000;
1613 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1614 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1615 static const unsigned int sparc_call_plus_8 = 0x40000002;
1616 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1617 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1618 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1620 // Write out the PLT.
1622 template<int size, bool big_endian>
1624 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1626 const off_t offset = this->offset();
1627 const section_size_type oview_size =
1628 convert_to_section_size_type(this->data_size());
1629 unsigned char* const oview = of->get_output_view(offset, oview_size);
1630 unsigned char* pov = oview;
1632 memset(pov, 0, base_plt_entry_size * 4);
1633 pov += this->first_plt_entry_offset();
1635 unsigned int plt_offset = base_plt_entry_size * 4;
1636 const unsigned int count = this->entry_count();
1642 limit = (count > 32768 ? 32768 : count);
1644 for (unsigned int i = 0; i < limit; ++i)
1646 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1647 sparc_sethi_g1 + plt_offset);
1648 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1649 sparc_branch_always_pt +
1650 (((base_plt_entry_size -
1651 (plt_offset + 4)) >> 2) &
1653 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1654 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1655 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1656 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1657 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1658 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1660 pov += base_plt_entry_size;
1661 plt_offset += base_plt_entry_size;
1666 unsigned int ext_cnt = count - 32768;
1667 unsigned int blks = ext_cnt / plt_entries_per_block;
1669 for (unsigned int i = 0; i < blks; ++i)
1671 unsigned int data_off = (plt_entries_per_block
1672 * plt_insn_chunk_size) - 4;
1674 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1676 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1678 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1680 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1682 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1683 sparc_ldx_o7_imm_g1 +
1684 (data_off & 0x1fff));
1685 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1686 sparc_jmpl_o7_g1_g1);
1687 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1690 elfcpp::Swap<64, big_endian>::writeval(
1691 pov + 0x4 + data_off,
1692 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1694 pov += plt_insn_chunk_size;
1699 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1700 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1702 unsigned int data_off = (sub_blk_cnt
1703 * plt_insn_chunk_size) - 4;
1705 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1707 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1709 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1711 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1713 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1714 sparc_ldx_o7_imm_g1 +
1715 (data_off & 0x1fff));
1716 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1717 sparc_jmpl_o7_g1_g1);
1718 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1721 elfcpp::Swap<64, big_endian>::writeval(
1722 pov + 0x4 + data_off,
1723 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1725 pov += plt_insn_chunk_size;
1733 for (unsigned int i = 0; i < count; ++i)
1735 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1736 sparc_sethi_g1 + plt_offset);
1737 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1738 sparc_branch_always +
1739 (((- (plt_offset + 4)) >> 2) &
1741 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1743 pov += base_plt_entry_size;
1744 plt_offset += base_plt_entry_size;
1747 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1751 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1753 of->write_output_view(offset, oview_size, oview);
1756 // Create the PLT section.
1758 template<int size, bool big_endian>
1760 Target_sparc<size, big_endian>::make_plt_section(Symbol_table* symtab,
1763 // Create the GOT sections first.
1764 this->got_section(symtab, layout);
1766 // Ensure that .rela.dyn always appears before .rela.plt This is
1767 // necessary due to how, on Sparc and some other targets, .rela.dyn
1768 // needs to include .rela.plt in it's range.
1769 this->rela_dyn_section(layout);
1771 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1772 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1774 | elfcpp::SHF_EXECINSTR
1775 | elfcpp::SHF_WRITE),
1776 this->plt_, ORDER_NON_RELRO_FIRST, false);
1778 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1779 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1780 Symbol_table::PREDEFINED,
1782 0, 0, elfcpp::STT_OBJECT,
1784 elfcpp::STV_HIDDEN, 0,
1788 // Create a PLT entry for a global symbol.
1790 template<int size, bool big_endian>
1792 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1796 if (gsym->has_plt_offset())
1799 if (this->plt_ == NULL)
1800 this->make_plt_section(symtab, layout);
1802 this->plt_->add_entry(symtab, layout, gsym);
1805 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1807 template<int size, bool big_endian>
1809 Target_sparc<size, big_endian>::make_local_ifunc_plt_entry(
1810 Symbol_table* symtab,
1812 Sized_relobj_file<size, big_endian>* relobj,
1813 unsigned int local_sym_index)
1815 if (relobj->local_has_plt_offset(local_sym_index))
1817 if (this->plt_ == NULL)
1818 this->make_plt_section(symtab, layout);
1819 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1822 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1825 // Return the number of entries in the PLT.
1827 template<int size, bool big_endian>
1829 Target_sparc<size, big_endian>::plt_entry_count() const
1831 if (this->plt_ == NULL)
1833 return this->plt_->entry_count();
1836 // Return the offset of the first non-reserved PLT entry.
1838 template<int size, bool big_endian>
1840 Target_sparc<size, big_endian>::first_plt_entry_offset() const
1842 return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset();
1845 // Return the size of each PLT entry.
1847 template<int size, bool big_endian>
1849 Target_sparc<size, big_endian>::plt_entry_size() const
1851 return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size();
1854 // Create a GOT entry for the TLS module index.
1856 template<int size, bool big_endian>
1858 Target_sparc<size, big_endian>::got_mod_index_entry(
1859 Symbol_table* symtab,
1861 Sized_relobj_file<size, big_endian>* object)
1863 if (this->got_mod_index_offset_ == -1U)
1865 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1866 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1867 Output_data_got<size, big_endian>* got;
1868 unsigned int got_offset;
1870 got = this->got_section(symtab, layout);
1871 got_offset = got->add_constant(0);
1872 rela_dyn->add_local(object, 0,
1874 elfcpp::R_SPARC_TLS_DTPMOD64 :
1875 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1877 got->add_constant(0);
1878 this->got_mod_index_offset_ = got_offset;
1880 return this->got_mod_index_offset_;
1883 // Optimize the TLS relocation type based on what we know about the
1884 // symbol. IS_FINAL is true if the final address of this symbol is
1885 // known at link time.
1887 static tls::Tls_optimization
1888 optimize_tls_reloc(bool is_final, int r_type)
1890 // If we are generating a shared library, then we can't do anything
1892 if (parameters->options().shared())
1893 return tls::TLSOPT_NONE;
1897 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1898 case elfcpp::R_SPARC_TLS_GD_LO10:
1899 case elfcpp::R_SPARC_TLS_GD_ADD:
1900 case elfcpp::R_SPARC_TLS_GD_CALL:
1901 // These are General-Dynamic which permits fully general TLS
1902 // access. Since we know that we are generating an executable,
1903 // we can convert this to Initial-Exec. If we also know that
1904 // this is a local symbol, we can further switch to Local-Exec.
1906 return tls::TLSOPT_TO_LE;
1907 return tls::TLSOPT_TO_IE;
1909 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1910 case elfcpp::R_SPARC_TLS_LDM_LO10:
1911 case elfcpp::R_SPARC_TLS_LDM_ADD:
1912 case elfcpp::R_SPARC_TLS_LDM_CALL:
1913 // This is Local-Dynamic, which refers to a local symbol in the
1914 // dynamic TLS block. Since we know that we generating an
1915 // executable, we can switch to Local-Exec.
1916 return tls::TLSOPT_TO_LE;
1918 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1919 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1920 case elfcpp::R_SPARC_TLS_LDO_ADD:
1921 // Another type of Local-Dynamic relocation.
1922 return tls::TLSOPT_TO_LE;
1924 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1925 case elfcpp::R_SPARC_TLS_IE_LO10:
1926 case elfcpp::R_SPARC_TLS_IE_LD:
1927 case elfcpp::R_SPARC_TLS_IE_LDX:
1928 case elfcpp::R_SPARC_TLS_IE_ADD:
1929 // These are Initial-Exec relocs which get the thread offset
1930 // from the GOT. If we know that we are linking against the
1931 // local symbol, we can switch to Local-Exec, which links the
1932 // thread offset into the instruction.
1934 return tls::TLSOPT_TO_LE;
1935 return tls::TLSOPT_NONE;
1937 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1938 case elfcpp::R_SPARC_TLS_LE_LOX10:
1939 // When we already have Local-Exec, there is nothing further we
1941 return tls::TLSOPT_NONE;
1948 // Get the Reference_flags for a particular relocation.
1950 template<int size, bool big_endian>
1952 Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
1957 case elfcpp::R_SPARC_NONE:
1958 case elfcpp::R_SPARC_REGISTER:
1959 case elfcpp::R_SPARC_GNU_VTINHERIT:
1960 case elfcpp::R_SPARC_GNU_VTENTRY:
1961 // No symbol reference.
1964 case elfcpp::R_SPARC_UA64:
1965 case elfcpp::R_SPARC_64:
1966 case elfcpp::R_SPARC_HIX22:
1967 case elfcpp::R_SPARC_LOX10:
1968 case elfcpp::R_SPARC_H34:
1969 case elfcpp::R_SPARC_H44:
1970 case elfcpp::R_SPARC_M44:
1971 case elfcpp::R_SPARC_L44:
1972 case elfcpp::R_SPARC_HH22:
1973 case elfcpp::R_SPARC_HM10:
1974 case elfcpp::R_SPARC_LM22:
1975 case elfcpp::R_SPARC_HI22:
1976 case elfcpp::R_SPARC_LO10:
1977 case elfcpp::R_SPARC_OLO10:
1978 case elfcpp::R_SPARC_UA32:
1979 case elfcpp::R_SPARC_32:
1980 case elfcpp::R_SPARC_UA16:
1981 case elfcpp::R_SPARC_16:
1982 case elfcpp::R_SPARC_11:
1983 case elfcpp::R_SPARC_10:
1984 case elfcpp::R_SPARC_8:
1985 case elfcpp::R_SPARC_7:
1986 case elfcpp::R_SPARC_6:
1987 case elfcpp::R_SPARC_5:
1988 return Symbol::ABSOLUTE_REF;
1990 case elfcpp::R_SPARC_DISP8:
1991 case elfcpp::R_SPARC_DISP16:
1992 case elfcpp::R_SPARC_DISP32:
1993 case elfcpp::R_SPARC_DISP64:
1994 case elfcpp::R_SPARC_PC_HH22:
1995 case elfcpp::R_SPARC_PC_HM10:
1996 case elfcpp::R_SPARC_PC_LM22:
1997 case elfcpp::R_SPARC_PC10:
1998 case elfcpp::R_SPARC_PC22:
1999 case elfcpp::R_SPARC_WDISP30:
2000 case elfcpp::R_SPARC_WDISP22:
2001 case elfcpp::R_SPARC_WDISP19:
2002 case elfcpp::R_SPARC_WDISP16:
2003 case elfcpp::R_SPARC_WDISP10:
2004 return Symbol::RELATIVE_REF;
2006 case elfcpp::R_SPARC_PLT64:
2007 case elfcpp::R_SPARC_PLT32:
2008 case elfcpp::R_SPARC_HIPLT22:
2009 case elfcpp::R_SPARC_LOPLT10:
2010 case elfcpp::R_SPARC_PCPLT10:
2011 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
2013 case elfcpp::R_SPARC_PCPLT32:
2014 case elfcpp::R_SPARC_PCPLT22:
2015 case elfcpp::R_SPARC_WPLT30:
2016 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2018 case elfcpp::R_SPARC_GOTDATA_OP:
2019 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2020 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2021 case elfcpp::R_SPARC_GOT10:
2022 case elfcpp::R_SPARC_GOT13:
2023 case elfcpp::R_SPARC_GOT22:
2025 return Symbol::ABSOLUTE_REF;
2027 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2028 case elfcpp::R_SPARC_TLS_GD_LO10:
2029 case elfcpp::R_SPARC_TLS_GD_ADD:
2030 case elfcpp::R_SPARC_TLS_GD_CALL:
2031 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2032 case elfcpp::R_SPARC_TLS_LDM_LO10:
2033 case elfcpp::R_SPARC_TLS_LDM_ADD:
2034 case elfcpp::R_SPARC_TLS_LDM_CALL:
2035 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2036 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2037 case elfcpp::R_SPARC_TLS_LDO_ADD:
2038 case elfcpp::R_SPARC_TLS_LE_HIX22:
2039 case elfcpp::R_SPARC_TLS_LE_LOX10:
2040 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2041 case elfcpp::R_SPARC_TLS_IE_LO10:
2042 case elfcpp::R_SPARC_TLS_IE_LD:
2043 case elfcpp::R_SPARC_TLS_IE_LDX:
2044 case elfcpp::R_SPARC_TLS_IE_ADD:
2045 return Symbol::TLS_REF;
2047 case elfcpp::R_SPARC_COPY:
2048 case elfcpp::R_SPARC_GLOB_DAT:
2049 case elfcpp::R_SPARC_JMP_SLOT:
2050 case elfcpp::R_SPARC_JMP_IREL:
2051 case elfcpp::R_SPARC_RELATIVE:
2052 case elfcpp::R_SPARC_IRELATIVE:
2053 case elfcpp::R_SPARC_TLS_DTPMOD64:
2054 case elfcpp::R_SPARC_TLS_DTPMOD32:
2055 case elfcpp::R_SPARC_TLS_DTPOFF64:
2056 case elfcpp::R_SPARC_TLS_DTPOFF32:
2057 case elfcpp::R_SPARC_TLS_TPOFF64:
2058 case elfcpp::R_SPARC_TLS_TPOFF32:
2060 // Not expected. We will give an error later.
2065 // Generate a PLT entry slot for a call to __tls_get_addr
2066 template<int size, bool big_endian>
2068 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
2070 Target_sparc<size, big_endian>* target)
2072 Symbol* gsym = target->tls_get_addr_sym(symtab);
2074 target->make_plt_entry(symtab, layout, gsym);
2077 // Report an unsupported relocation against a local symbol.
2079 template<int size, bool big_endian>
2081 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
2082 Sized_relobj_file<size, big_endian>* object,
2083 unsigned int r_type)
2085 gold_error(_("%s: unsupported reloc %u against local symbol"),
2086 object->name().c_str(), r_type);
2089 // We are about to emit a dynamic relocation of type R_TYPE. If the
2090 // dynamic linker does not support it, issue an error.
2092 template<int size, bool big_endian>
2094 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2096 gold_assert(r_type != elfcpp::R_SPARC_NONE);
2102 // These are the relocation types supported by glibc for sparc 64-bit.
2103 case elfcpp::R_SPARC_RELATIVE:
2104 case elfcpp::R_SPARC_IRELATIVE:
2105 case elfcpp::R_SPARC_COPY:
2106 case elfcpp::R_SPARC_64:
2107 case elfcpp::R_SPARC_GLOB_DAT:
2108 case elfcpp::R_SPARC_JMP_SLOT:
2109 case elfcpp::R_SPARC_JMP_IREL:
2110 case elfcpp::R_SPARC_TLS_DTPMOD64:
2111 case elfcpp::R_SPARC_TLS_DTPOFF64:
2112 case elfcpp::R_SPARC_TLS_TPOFF64:
2113 case elfcpp::R_SPARC_TLS_LE_HIX22:
2114 case elfcpp::R_SPARC_TLS_LE_LOX10:
2115 case elfcpp::R_SPARC_8:
2116 case elfcpp::R_SPARC_16:
2117 case elfcpp::R_SPARC_DISP8:
2118 case elfcpp::R_SPARC_DISP16:
2119 case elfcpp::R_SPARC_DISP32:
2120 case elfcpp::R_SPARC_WDISP30:
2121 case elfcpp::R_SPARC_LO10:
2122 case elfcpp::R_SPARC_HI22:
2123 case elfcpp::R_SPARC_OLO10:
2124 case elfcpp::R_SPARC_H34:
2125 case elfcpp::R_SPARC_H44:
2126 case elfcpp::R_SPARC_M44:
2127 case elfcpp::R_SPARC_L44:
2128 case elfcpp::R_SPARC_HH22:
2129 case elfcpp::R_SPARC_HM10:
2130 case elfcpp::R_SPARC_LM22:
2131 case elfcpp::R_SPARC_UA16:
2132 case elfcpp::R_SPARC_UA32:
2133 case elfcpp::R_SPARC_UA64:
2144 // These are the relocation types supported by glibc for sparc 32-bit.
2145 case elfcpp::R_SPARC_RELATIVE:
2146 case elfcpp::R_SPARC_IRELATIVE:
2147 case elfcpp::R_SPARC_COPY:
2148 case elfcpp::R_SPARC_GLOB_DAT:
2149 case elfcpp::R_SPARC_32:
2150 case elfcpp::R_SPARC_JMP_SLOT:
2151 case elfcpp::R_SPARC_JMP_IREL:
2152 case elfcpp::R_SPARC_TLS_DTPMOD32:
2153 case elfcpp::R_SPARC_TLS_DTPOFF32:
2154 case elfcpp::R_SPARC_TLS_TPOFF32:
2155 case elfcpp::R_SPARC_TLS_LE_HIX22:
2156 case elfcpp::R_SPARC_TLS_LE_LOX10:
2157 case elfcpp::R_SPARC_8:
2158 case elfcpp::R_SPARC_16:
2159 case elfcpp::R_SPARC_DISP8:
2160 case elfcpp::R_SPARC_DISP16:
2161 case elfcpp::R_SPARC_DISP32:
2162 case elfcpp::R_SPARC_LO10:
2163 case elfcpp::R_SPARC_WDISP30:
2164 case elfcpp::R_SPARC_HI22:
2165 case elfcpp::R_SPARC_UA16:
2166 case elfcpp::R_SPARC_UA32:
2174 // This prevents us from issuing more than one error per reloc
2175 // section. But we can still wind up issuing more than one
2176 // error per object file.
2177 if (this->issued_non_pic_error_)
2179 gold_assert(parameters->options().output_is_position_independent());
2180 object->error(_("requires unsupported dynamic reloc; "
2181 "recompile with -fPIC"));
2182 this->issued_non_pic_error_ = true;
2186 // Return whether we need to make a PLT entry for a relocation of the
2187 // given type against a STT_GNU_IFUNC symbol.
2189 template<int size, bool big_endian>
2191 Target_sparc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
2192 Sized_relobj_file<size, big_endian>* object,
2193 unsigned int r_type)
2195 int flags = Scan::get_reference_flags(r_type);
2196 if (flags & Symbol::TLS_REF)
2197 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2198 object->name().c_str(), r_type);
2202 // Scan a relocation for a local symbol.
2204 template<int size, bool big_endian>
2206 Target_sparc<size, big_endian>::Scan::local(
2207 Symbol_table* symtab,
2209 Target_sparc<size, big_endian>* target,
2210 Sized_relobj_file<size, big_endian>* object,
2211 unsigned int data_shndx,
2212 Output_section* output_section,
2213 const elfcpp::Rela<size, big_endian>& reloc,
2214 unsigned int r_type,
2215 const elfcpp::Sym<size, big_endian>& lsym)
2217 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2218 unsigned int orig_r_type = r_type;
2222 && this->reloc_needs_plt_for_ifunc(object, r_type))
2224 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2225 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2230 case elfcpp::R_SPARC_NONE:
2231 case elfcpp::R_SPARC_REGISTER:
2232 case elfcpp::R_SPARC_GNU_VTINHERIT:
2233 case elfcpp::R_SPARC_GNU_VTENTRY:
2236 case elfcpp::R_SPARC_64:
2237 case elfcpp::R_SPARC_32:
2238 // If building a shared library (or a position-independent
2239 // executable), we need to create a dynamic relocation for
2240 // this location. The relocation applied at link time will
2241 // apply the link-time value, so we flag the location with
2242 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2243 // relocate it easily.
2244 if (parameters->options().output_is_position_independent())
2246 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2247 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2248 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
2249 output_section, data_shndx,
2250 reloc.get_r_offset(),
2251 reloc.get_r_addend(), is_ifunc);
2255 case elfcpp::R_SPARC_HIX22:
2256 case elfcpp::R_SPARC_LOX10:
2257 case elfcpp::R_SPARC_H34:
2258 case elfcpp::R_SPARC_H44:
2259 case elfcpp::R_SPARC_M44:
2260 case elfcpp::R_SPARC_L44:
2261 case elfcpp::R_SPARC_HH22:
2262 case elfcpp::R_SPARC_HM10:
2263 case elfcpp::R_SPARC_LM22:
2264 case elfcpp::R_SPARC_UA64:
2265 case elfcpp::R_SPARC_UA32:
2266 case elfcpp::R_SPARC_UA16:
2267 case elfcpp::R_SPARC_HI22:
2268 case elfcpp::R_SPARC_LO10:
2269 case elfcpp::R_SPARC_OLO10:
2270 case elfcpp::R_SPARC_16:
2271 case elfcpp::R_SPARC_11:
2272 case elfcpp::R_SPARC_10:
2273 case elfcpp::R_SPARC_8:
2274 case elfcpp::R_SPARC_7:
2275 case elfcpp::R_SPARC_6:
2276 case elfcpp::R_SPARC_5:
2277 // If building a shared library (or a position-independent
2278 // executable), we need to create a dynamic relocation for
2280 if (parameters->options().output_is_position_independent())
2282 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2283 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2285 check_non_pic(object, r_type);
2286 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2288 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
2289 data_shndx, reloc.get_r_offset(),
2290 reloc.get_r_addend());
2294 gold_assert(lsym.get_st_value() == 0);
2295 rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
2296 output_section, data_shndx,
2297 reloc.get_r_offset(),
2298 reloc.get_r_addend());
2303 case elfcpp::R_SPARC_WDISP30:
2304 case elfcpp::R_SPARC_WPLT30:
2305 case elfcpp::R_SPARC_WDISP22:
2306 case elfcpp::R_SPARC_WDISP19:
2307 case elfcpp::R_SPARC_WDISP16:
2308 case elfcpp::R_SPARC_WDISP10:
2309 case elfcpp::R_SPARC_DISP8:
2310 case elfcpp::R_SPARC_DISP16:
2311 case elfcpp::R_SPARC_DISP32:
2312 case elfcpp::R_SPARC_DISP64:
2313 case elfcpp::R_SPARC_PC10:
2314 case elfcpp::R_SPARC_PC22:
2317 case elfcpp::R_SPARC_GOTDATA_OP:
2318 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2319 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2320 // We will optimize this into a GOT relative relocation
2321 // and code transform the GOT load into an addition.
2324 case elfcpp::R_SPARC_GOT10:
2325 case elfcpp::R_SPARC_GOT13:
2326 case elfcpp::R_SPARC_GOT22:
2328 // The symbol requires a GOT entry.
2329 Output_data_got<size, big_endian>* got;
2332 got = target->got_section(symtab, layout);
2333 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2335 // If we are generating a shared object, we need to add a
2336 // dynamic relocation for this symbol's GOT entry.
2337 if (parameters->options().output_is_position_independent())
2339 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
2341 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2342 unsigned int off = got->add_constant(0);
2343 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
2344 rela_dyn->add_local_relative(object, r_sym,
2345 elfcpp::R_SPARC_RELATIVE,
2346 got, off, 0, is_ifunc);
2350 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2354 // These are initial TLS relocs, which are expected when
2356 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2357 case elfcpp::R_SPARC_TLS_GD_LO10:
2358 case elfcpp::R_SPARC_TLS_GD_ADD:
2359 case elfcpp::R_SPARC_TLS_GD_CALL:
2360 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2361 case elfcpp::R_SPARC_TLS_LDM_LO10:
2362 case elfcpp::R_SPARC_TLS_LDM_ADD:
2363 case elfcpp::R_SPARC_TLS_LDM_CALL:
2364 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2365 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2366 case elfcpp::R_SPARC_TLS_LDO_ADD:
2367 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2368 case elfcpp::R_SPARC_TLS_IE_LO10:
2369 case elfcpp::R_SPARC_TLS_IE_LD:
2370 case elfcpp::R_SPARC_TLS_IE_LDX:
2371 case elfcpp::R_SPARC_TLS_IE_ADD:
2372 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2373 case elfcpp::R_SPARC_TLS_LE_LOX10:
2375 bool output_is_shared = parameters->options().shared();
2376 const tls::Tls_optimization optimized_type
2377 = optimize_tls_reloc(!output_is_shared, r_type);
2380 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2381 case elfcpp::R_SPARC_TLS_GD_LO10:
2382 case elfcpp::R_SPARC_TLS_GD_ADD:
2383 case elfcpp::R_SPARC_TLS_GD_CALL:
2384 if (optimized_type == tls::TLSOPT_NONE)
2386 // Create a pair of GOT entries for the module index and
2387 // dtv-relative offset.
2388 Output_data_got<size, big_endian>* got
2389 = target->got_section(symtab, layout);
2390 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2391 unsigned int shndx = lsym.get_st_shndx();
2393 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2395 object->error(_("local symbol %u has bad shndx %u"),
2398 got->add_local_pair_with_rel(object, r_sym,
2399 lsym.get_st_shndx(),
2401 target->rela_dyn_section(layout),
2403 ? elfcpp::R_SPARC_TLS_DTPMOD64
2404 : elfcpp::R_SPARC_TLS_DTPMOD32),
2406 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2407 generate_tls_call(symtab, layout, target);
2409 else if (optimized_type != tls::TLSOPT_TO_LE)
2410 unsupported_reloc_local(object, r_type);
2413 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2414 case elfcpp::R_SPARC_TLS_LDM_LO10:
2415 case elfcpp::R_SPARC_TLS_LDM_ADD:
2416 case elfcpp::R_SPARC_TLS_LDM_CALL:
2417 if (optimized_type == tls::TLSOPT_NONE)
2419 // Create a GOT entry for the module index.
2420 target->got_mod_index_entry(symtab, layout, object);
2422 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2423 generate_tls_call(symtab, layout, target);
2425 else if (optimized_type != tls::TLSOPT_TO_LE)
2426 unsupported_reloc_local(object, r_type);
2429 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2430 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2431 case elfcpp::R_SPARC_TLS_LDO_ADD:
2434 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2435 case elfcpp::R_SPARC_TLS_IE_LO10:
2436 case elfcpp::R_SPARC_TLS_IE_LD:
2437 case elfcpp::R_SPARC_TLS_IE_LDX:
2438 case elfcpp::R_SPARC_TLS_IE_ADD:
2439 layout->set_has_static_tls();
2440 if (optimized_type == tls::TLSOPT_NONE)
2442 // Create a GOT entry for the tp-relative offset.
2443 Output_data_got<size, big_endian>* got
2444 = target->got_section(symtab, layout);
2445 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2447 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
2449 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2450 unsigned int off = got->add_constant(0);
2452 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
2454 rela_dyn->add_symbolless_local_addend(object, r_sym,
2456 elfcpp::R_SPARC_TLS_TPOFF64 :
2457 elfcpp::R_SPARC_TLS_TPOFF32),
2461 else if (optimized_type != tls::TLSOPT_TO_LE)
2462 unsupported_reloc_local(object, r_type);
2465 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2466 case elfcpp::R_SPARC_TLS_LE_LOX10:
2467 layout->set_has_static_tls();
2468 if (output_is_shared)
2470 // We need to create a dynamic relocation.
2471 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2472 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2473 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2474 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
2475 output_section, data_shndx,
2476 reloc.get_r_offset(), 0);
2483 // These are relocations which should only be seen by the
2484 // dynamic linker, and should never be seen here.
2485 case elfcpp::R_SPARC_COPY:
2486 case elfcpp::R_SPARC_GLOB_DAT:
2487 case elfcpp::R_SPARC_JMP_SLOT:
2488 case elfcpp::R_SPARC_JMP_IREL:
2489 case elfcpp::R_SPARC_RELATIVE:
2490 case elfcpp::R_SPARC_IRELATIVE:
2491 case elfcpp::R_SPARC_TLS_DTPMOD64:
2492 case elfcpp::R_SPARC_TLS_DTPMOD32:
2493 case elfcpp::R_SPARC_TLS_DTPOFF64:
2494 case elfcpp::R_SPARC_TLS_DTPOFF32:
2495 case elfcpp::R_SPARC_TLS_TPOFF64:
2496 case elfcpp::R_SPARC_TLS_TPOFF32:
2497 gold_error(_("%s: unexpected reloc %u in object file"),
2498 object->name().c_str(), r_type);
2502 unsupported_reloc_local(object, r_type);
2507 // Report an unsupported relocation against a global symbol.
2509 template<int size, bool big_endian>
2511 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
2512 Sized_relobj_file<size, big_endian>* object,
2513 unsigned int r_type,
2516 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2517 object->name().c_str(), r_type, gsym->demangled_name().c_str());
2520 // Scan a relocation for a global symbol.
2522 template<int size, bool big_endian>
2524 Target_sparc<size, big_endian>::Scan::global(
2525 Symbol_table* symtab,
2527 Target_sparc<size, big_endian>* target,
2528 Sized_relobj_file<size, big_endian>* object,
2529 unsigned int data_shndx,
2530 Output_section* output_section,
2531 const elfcpp::Rela<size, big_endian>& reloc,
2532 unsigned int r_type,
2535 unsigned int orig_r_type = r_type;
2536 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2538 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2539 // section. We check here to avoid creating a dynamic reloc against
2540 // _GLOBAL_OFFSET_TABLE_.
2541 if (!target->has_got_section()
2542 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2543 target->got_section(symtab, layout);
2547 // A STT_GNU_IFUNC symbol may require a PLT entry.
2549 && this->reloc_needs_plt_for_ifunc(object, r_type))
2550 target->make_plt_entry(symtab, layout, gsym);
2554 case elfcpp::R_SPARC_NONE:
2555 case elfcpp::R_SPARC_REGISTER:
2556 case elfcpp::R_SPARC_GNU_VTINHERIT:
2557 case elfcpp::R_SPARC_GNU_VTENTRY:
2560 case elfcpp::R_SPARC_PLT64:
2561 case elfcpp::R_SPARC_PLT32:
2562 case elfcpp::R_SPARC_HIPLT22:
2563 case elfcpp::R_SPARC_LOPLT10:
2564 case elfcpp::R_SPARC_PCPLT32:
2565 case elfcpp::R_SPARC_PCPLT22:
2566 case elfcpp::R_SPARC_PCPLT10:
2567 case elfcpp::R_SPARC_WPLT30:
2568 // If the symbol is fully resolved, this is just a PC32 reloc.
2569 // Otherwise we need a PLT entry.
2570 if (gsym->final_value_is_known())
2572 // If building a shared library, we can also skip the PLT entry
2573 // if the symbol is defined in the output file and is protected
2575 if (gsym->is_defined()
2576 && !gsym->is_from_dynobj()
2577 && !gsym->is_preemptible())
2579 target->make_plt_entry(symtab, layout, gsym);
2582 case elfcpp::R_SPARC_DISP8:
2583 case elfcpp::R_SPARC_DISP16:
2584 case elfcpp::R_SPARC_DISP32:
2585 case elfcpp::R_SPARC_DISP64:
2586 case elfcpp::R_SPARC_PC_HH22:
2587 case elfcpp::R_SPARC_PC_HM10:
2588 case elfcpp::R_SPARC_PC_LM22:
2589 case elfcpp::R_SPARC_PC10:
2590 case elfcpp::R_SPARC_PC22:
2591 case elfcpp::R_SPARC_WDISP30:
2592 case elfcpp::R_SPARC_WDISP22:
2593 case elfcpp::R_SPARC_WDISP19:
2594 case elfcpp::R_SPARC_WDISP16:
2595 case elfcpp::R_SPARC_WDISP10:
2597 if (gsym->needs_plt_entry())
2598 target->make_plt_entry(symtab, layout, gsym);
2599 // Make a dynamic relocation if necessary.
2600 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2602 if (gsym->may_need_copy_reloc())
2604 target->copy_reloc(symtab, layout, object,
2605 data_shndx, output_section, gsym,
2610 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2611 check_non_pic(object, r_type);
2612 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
2613 data_shndx, reloc.get_r_offset(),
2614 reloc.get_r_addend());
2620 case elfcpp::R_SPARC_UA64:
2621 case elfcpp::R_SPARC_64:
2622 case elfcpp::R_SPARC_HIX22:
2623 case elfcpp::R_SPARC_LOX10:
2624 case elfcpp::R_SPARC_H34:
2625 case elfcpp::R_SPARC_H44:
2626 case elfcpp::R_SPARC_M44:
2627 case elfcpp::R_SPARC_L44:
2628 case elfcpp::R_SPARC_HH22:
2629 case elfcpp::R_SPARC_HM10:
2630 case elfcpp::R_SPARC_LM22:
2631 case elfcpp::R_SPARC_HI22:
2632 case elfcpp::R_SPARC_LO10:
2633 case elfcpp::R_SPARC_OLO10:
2634 case elfcpp::R_SPARC_UA32:
2635 case elfcpp::R_SPARC_32:
2636 case elfcpp::R_SPARC_UA16:
2637 case elfcpp::R_SPARC_16:
2638 case elfcpp::R_SPARC_11:
2639 case elfcpp::R_SPARC_10:
2640 case elfcpp::R_SPARC_8:
2641 case elfcpp::R_SPARC_7:
2642 case elfcpp::R_SPARC_6:
2643 case elfcpp::R_SPARC_5:
2645 // Make a PLT entry if necessary.
2646 if (gsym->needs_plt_entry())
2648 target->make_plt_entry(symtab, layout, gsym);
2649 // Since this is not a PC-relative relocation, we may be
2650 // taking the address of a function. In that case we need to
2651 // set the entry in the dynamic symbol table to the address of
2653 if (gsym->is_from_dynobj() && !parameters->options().shared())
2654 gsym->set_needs_dynsym_value();
2656 // Make a dynamic relocation if necessary.
2657 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2659 unsigned int r_off = reloc.get_r_offset();
2661 // The assembler can sometimes emit unaligned relocations
2662 // for dwarf2 cfi directives.
2665 case elfcpp::R_SPARC_16:
2667 orig_r_type = r_type = elfcpp::R_SPARC_UA16;
2669 case elfcpp::R_SPARC_32:
2671 orig_r_type = r_type = elfcpp::R_SPARC_UA32;
2673 case elfcpp::R_SPARC_64:
2675 orig_r_type = r_type = elfcpp::R_SPARC_UA64;
2677 case elfcpp::R_SPARC_UA16:
2679 orig_r_type = r_type = elfcpp::R_SPARC_16;
2681 case elfcpp::R_SPARC_UA32:
2683 orig_r_type = r_type = elfcpp::R_SPARC_32;
2685 case elfcpp::R_SPARC_UA64:
2687 orig_r_type = r_type = elfcpp::R_SPARC_64;
2691 if (gsym->may_need_copy_reloc())
2693 target->copy_reloc(symtab, layout, object,
2694 data_shndx, output_section, gsym, reloc);
2696 else if (((size == 64 && r_type == elfcpp::R_SPARC_64)
2697 || (size == 32 && r_type == elfcpp::R_SPARC_32))
2698 && gsym->type() == elfcpp::STT_GNU_IFUNC
2699 && gsym->can_use_relative_reloc(false)
2700 && !gsym->is_from_dynobj()
2701 && !gsym->is_undefined()
2702 && !gsym->is_preemptible())
2704 // Use an IRELATIVE reloc for a locally defined
2705 // STT_GNU_IFUNC symbol. This makes a function
2706 // address in a PIE executable match the address in a
2707 // shared library that it links against.
2708 Reloc_section* rela_dyn =
2709 target->rela_ifunc_section(layout);
2710 unsigned int r_type = elfcpp::R_SPARC_IRELATIVE;
2711 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2712 output_section, object,
2714 reloc.get_r_offset(),
2715 reloc.get_r_addend());
2717 else if ((r_type == elfcpp::R_SPARC_32
2718 || r_type == elfcpp::R_SPARC_64)
2719 && gsym->can_use_relative_reloc(false))
2721 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2722 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2723 output_section, object,
2724 data_shndx, reloc.get_r_offset(),
2725 reloc.get_r_addend(), is_ifunc);
2729 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2731 check_non_pic(object, r_type);
2732 if (gsym->is_from_dynobj()
2733 || gsym->is_undefined()
2734 || gsym->is_preemptible())
2735 rela_dyn->add_global(gsym, orig_r_type, output_section,
2737 reloc.get_r_offset(),
2738 reloc.get_r_addend());
2740 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2743 reloc.get_r_offset(),
2744 reloc.get_r_addend());
2750 case elfcpp::R_SPARC_GOTDATA_OP:
2751 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2752 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2753 if (gsym->is_defined()
2754 && !gsym->is_from_dynobj()
2755 && !gsym->is_preemptible()
2758 // We will optimize this into a GOT relative relocation
2759 // and code transform the GOT load into an addition.
2762 case elfcpp::R_SPARC_GOT10:
2763 case elfcpp::R_SPARC_GOT13:
2764 case elfcpp::R_SPARC_GOT22:
2766 // The symbol requires a GOT entry.
2767 Output_data_got<size, big_endian>* got;
2769 got = target->got_section(symtab, layout);
2770 if (gsym->final_value_is_known())
2772 // For a STT_GNU_IFUNC symbol we want the PLT address.
2773 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2774 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2776 got->add_global(gsym, GOT_TYPE_STANDARD);
2780 // If this symbol is not fully resolved, we need to add a
2781 // GOT entry with a dynamic relocation.
2782 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2784 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2786 // 1) The symbol may be defined in some other module.
2788 // 2) We are building a shared library and this is a
2789 // protected symbol; using GLOB_DAT means that the dynamic
2790 // linker can use the address of the PLT in the main
2791 // executable when appropriate so that function address
2792 // comparisons work.
2794 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2795 // code, again so that function address comparisons work.
2796 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2797 if (gsym->is_from_dynobj()
2798 || gsym->is_undefined()
2799 || gsym->is_preemptible()
2800 || (gsym->visibility() == elfcpp::STV_PROTECTED
2801 && parameters->options().shared())
2802 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2803 && parameters->options().output_is_position_independent()
2804 && !gsym->is_forced_local()))
2806 unsigned int r_type = elfcpp::R_SPARC_GLOB_DAT;
2808 // If this symbol is forced local, this relocation will
2809 // not work properly. That's because ld.so on sparc
2810 // (and 32-bit powerpc) expects st_value in the r_addend
2811 // of relocations for STB_LOCAL symbols. Curiously the
2812 // BFD linker does not promote global hidden symbols to be
2813 // STB_LOCAL in the dynamic symbol table like Gold does.
2814 gold_assert(!gsym->is_forced_local());
2815 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2818 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2820 unsigned int off = got->add_constant(0);
2822 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2825 // Tell the dynamic linker to use the PLT address
2826 // when resolving relocations.
2827 if (gsym->is_from_dynobj()
2828 && !parameters->options().shared())
2829 gsym->set_needs_dynsym_value();
2831 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2832 got, off, 0, is_ifunc);
2838 // These are initial tls relocs, which are expected when
2840 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2841 case elfcpp::R_SPARC_TLS_GD_LO10:
2842 case elfcpp::R_SPARC_TLS_GD_ADD:
2843 case elfcpp::R_SPARC_TLS_GD_CALL:
2844 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2845 case elfcpp::R_SPARC_TLS_LDM_LO10:
2846 case elfcpp::R_SPARC_TLS_LDM_ADD:
2847 case elfcpp::R_SPARC_TLS_LDM_CALL:
2848 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2849 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2850 case elfcpp::R_SPARC_TLS_LDO_ADD:
2851 case elfcpp::R_SPARC_TLS_LE_HIX22:
2852 case elfcpp::R_SPARC_TLS_LE_LOX10:
2853 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2854 case elfcpp::R_SPARC_TLS_IE_LO10:
2855 case elfcpp::R_SPARC_TLS_IE_LD:
2856 case elfcpp::R_SPARC_TLS_IE_LDX:
2857 case elfcpp::R_SPARC_TLS_IE_ADD:
2859 const bool is_final = gsym->final_value_is_known();
2860 const tls::Tls_optimization optimized_type
2861 = optimize_tls_reloc(is_final, r_type);
2864 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2865 case elfcpp::R_SPARC_TLS_GD_LO10:
2866 case elfcpp::R_SPARC_TLS_GD_ADD:
2867 case elfcpp::R_SPARC_TLS_GD_CALL:
2868 if (optimized_type == tls::TLSOPT_NONE)
2870 // Create a pair of GOT entries for the module index and
2871 // dtv-relative offset.
2872 Output_data_got<size, big_endian>* got
2873 = target->got_section(symtab, layout);
2874 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2875 target->rela_dyn_section(layout),
2877 ? elfcpp::R_SPARC_TLS_DTPMOD64
2878 : elfcpp::R_SPARC_TLS_DTPMOD32),
2880 ? elfcpp::R_SPARC_TLS_DTPOFF64
2881 : elfcpp::R_SPARC_TLS_DTPOFF32));
2883 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2884 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2885 generate_tls_call(symtab, layout, target);
2887 else if (optimized_type == tls::TLSOPT_TO_IE)
2889 // Create a GOT entry for the tp-relative offset.
2890 Output_data_got<size, big_endian>* got
2891 = target->got_section(symtab, layout);
2892 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2893 target->rela_dyn_section(layout),
2895 elfcpp::R_SPARC_TLS_TPOFF64 :
2896 elfcpp::R_SPARC_TLS_TPOFF32));
2898 else if (optimized_type != tls::TLSOPT_TO_LE)
2899 unsupported_reloc_global(object, r_type, gsym);
2902 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2903 case elfcpp::R_SPARC_TLS_LDM_LO10:
2904 case elfcpp::R_SPARC_TLS_LDM_ADD:
2905 case elfcpp::R_SPARC_TLS_LDM_CALL:
2906 if (optimized_type == tls::TLSOPT_NONE)
2908 // Create a GOT entry for the module index.
2909 target->got_mod_index_entry(symtab, layout, object);
2911 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2912 generate_tls_call(symtab, layout, target);
2914 else if (optimized_type != tls::TLSOPT_TO_LE)
2915 unsupported_reloc_global(object, r_type, gsym);
2918 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2919 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2920 case elfcpp::R_SPARC_TLS_LDO_ADD:
2923 case elfcpp::R_SPARC_TLS_LE_HIX22:
2924 case elfcpp::R_SPARC_TLS_LE_LOX10:
2925 layout->set_has_static_tls();
2926 if (parameters->options().shared())
2928 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2929 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2930 output_section, object,
2931 data_shndx, reloc.get_r_offset(),
2936 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2937 case elfcpp::R_SPARC_TLS_IE_LO10:
2938 case elfcpp::R_SPARC_TLS_IE_LD:
2939 case elfcpp::R_SPARC_TLS_IE_LDX:
2940 case elfcpp::R_SPARC_TLS_IE_ADD:
2941 layout->set_has_static_tls();
2942 if (optimized_type == tls::TLSOPT_NONE)
2944 // Create a GOT entry for the tp-relative offset.
2945 Output_data_got<size, big_endian>* got
2946 = target->got_section(symtab, layout);
2947 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2948 target->rela_dyn_section(layout),
2950 ? elfcpp::R_SPARC_TLS_TPOFF64
2951 : elfcpp::R_SPARC_TLS_TPOFF32));
2953 else if (optimized_type != tls::TLSOPT_TO_LE)
2954 unsupported_reloc_global(object, r_type, gsym);
2960 // These are relocations which should only be seen by the
2961 // dynamic linker, and should never be seen here.
2962 case elfcpp::R_SPARC_COPY:
2963 case elfcpp::R_SPARC_GLOB_DAT:
2964 case elfcpp::R_SPARC_JMP_SLOT:
2965 case elfcpp::R_SPARC_JMP_IREL:
2966 case elfcpp::R_SPARC_RELATIVE:
2967 case elfcpp::R_SPARC_IRELATIVE:
2968 case elfcpp::R_SPARC_TLS_DTPMOD64:
2969 case elfcpp::R_SPARC_TLS_DTPMOD32:
2970 case elfcpp::R_SPARC_TLS_DTPOFF64:
2971 case elfcpp::R_SPARC_TLS_DTPOFF32:
2972 case elfcpp::R_SPARC_TLS_TPOFF64:
2973 case elfcpp::R_SPARC_TLS_TPOFF32:
2974 gold_error(_("%s: unexpected reloc %u in object file"),
2975 object->name().c_str(), r_type);
2979 unsupported_reloc_global(object, r_type, gsym);
2984 // Process relocations for gc.
2986 template<int size, bool big_endian>
2988 Target_sparc<size, big_endian>::gc_process_relocs(
2989 Symbol_table* symtab,
2991 Sized_relobj_file<size, big_endian>* object,
2992 unsigned int data_shndx,
2994 const unsigned char* prelocs,
2996 Output_section* output_section,
2997 bool needs_special_offset_handling,
2998 size_t local_symbol_count,
2999 const unsigned char* plocal_symbols)
3001 typedef Target_sparc<size, big_endian> Sparc;
3002 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3004 gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan,
3005 typename Target_sparc::Relocatable_size_for_reloc>(
3014 needs_special_offset_handling,
3019 // Scan relocations for a section.
3021 template<int size, bool big_endian>
3023 Target_sparc<size, big_endian>::scan_relocs(
3024 Symbol_table* symtab,
3026 Sized_relobj_file<size, big_endian>* object,
3027 unsigned int data_shndx,
3028 unsigned int sh_type,
3029 const unsigned char* prelocs,
3031 Output_section* output_section,
3032 bool needs_special_offset_handling,
3033 size_t local_symbol_count,
3034 const unsigned char* plocal_symbols)
3036 typedef Target_sparc<size, big_endian> Sparc;
3037 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3039 if (sh_type == elfcpp::SHT_REL)
3041 gold_error(_("%s: unsupported REL reloc section"),
3042 object->name().c_str());
3046 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
3055 needs_special_offset_handling,
3060 // Finalize the sections.
3062 template<int size, bool big_endian>
3064 Target_sparc<size, big_endian>::do_finalize_sections(
3066 const Input_objects*,
3067 Symbol_table* symtab)
3070 this->plt_->emit_pending_ifunc_relocs();
3072 // Fill in some more dynamic tags.
3073 const Reloc_section* rel_plt = (this->plt_ == NULL
3075 : this->plt_->rel_plt());
3076 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
3077 this->rela_dyn_, true, true);
3079 // Emit any relocs we saved in an attempt to avoid generating COPY
3081 if (this->copy_relocs_.any_saved_relocs())
3082 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3084 if (parameters->doing_static_link()
3085 && (this->plt_ == NULL || !this->plt_->has_ifunc_section()))
3087 // If linking statically, make sure that the __rela_iplt symbols
3088 // were defined if necessary, even if we didn't create a PLT.
3089 static const Define_symbol_in_segment syms[] =
3092 "__rela_iplt_start", // name
3093 elfcpp::PT_LOAD, // segment_type
3094 elfcpp::PF_W, // segment_flags_set
3095 elfcpp::PF(0), // segment_flags_clear
3098 elfcpp::STT_NOTYPE, // type
3099 elfcpp::STB_GLOBAL, // binding
3100 elfcpp::STV_HIDDEN, // visibility
3102 Symbol::SEGMENT_START, // offset_from_base
3106 "__rela_iplt_end", // name
3107 elfcpp::PT_LOAD, // segment_type
3108 elfcpp::PF_W, // segment_flags_set
3109 elfcpp::PF(0), // segment_flags_clear
3112 elfcpp::STT_NOTYPE, // type
3113 elfcpp::STB_GLOBAL, // binding
3114 elfcpp::STV_HIDDEN, // visibility
3116 Symbol::SEGMENT_START, // offset_from_base
3121 symtab->define_symbols(layout, 2, syms,
3122 layout->script_options()->saw_sections_clause());
3126 // Perform a relocation.
3128 template<int size, bool big_endian>
3130 Target_sparc<size, big_endian>::Relocate::relocate(
3131 const Relocate_info<size, big_endian>* relinfo,
3132 Target_sparc* target,
3135 const elfcpp::Rela<size, big_endian>& rela,
3136 unsigned int r_type,
3137 const Sized_symbol<size>* gsym,
3138 const Symbol_value<size>* psymval,
3139 unsigned char* view,
3140 typename elfcpp::Elf_types<size>::Elf_Addr address,
3141 section_size_type view_size)
3143 bool orig_is_ifunc = psymval->is_ifunc_symbol();
3146 if (this->ignore_gd_add_)
3148 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
3149 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3150 _("missing expected TLS relocation"));
3153 this->ignore_gd_add_ = false;
3157 if (this->reloc_adjust_addr_ == view)
3160 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3161 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3163 // Pick the value to use for symbols defined in shared objects.
3164 Symbol_value<size> symval;
3166 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3168 elfcpp::Elf_Xword value;
3170 value = target->plt_address_for_global(gsym) + gsym->plt_offset();
3172 symval.set_output_value(value);
3176 else if (gsym == NULL && orig_is_ifunc)
3178 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3179 if (object->local_has_plt_offset(r_sym))
3181 symval.set_output_value(target->plt_address_for_local(object, r_sym)
3182 + object->local_plt_offset(r_sym));
3187 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3189 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3190 // pointer points to the beginning, not the end, of the table.
3191 // So we just use the plain offset.
3192 unsigned int got_offset = 0;
3193 bool gdop_valid = false;
3196 case elfcpp::R_SPARC_GOTDATA_OP:
3197 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3198 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3199 // If this is local, we did not create a GOT entry because we
3200 // intend to transform this into a GOT relative relocation.
3202 || (gsym->is_defined()
3203 && !gsym->is_from_dynobj()
3204 && !gsym->is_preemptible()
3207 got_offset = psymval->value(object, 0) - target->got_address();
3211 case elfcpp::R_SPARC_GOT10:
3212 case elfcpp::R_SPARC_GOT13:
3213 case elfcpp::R_SPARC_GOT22:
3216 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3217 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3221 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3222 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3223 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3233 case elfcpp::R_SPARC_NONE:
3234 case elfcpp::R_SPARC_REGISTER:
3235 case elfcpp::R_SPARC_GNU_VTINHERIT:
3236 case elfcpp::R_SPARC_GNU_VTENTRY:
3239 case elfcpp::R_SPARC_8:
3240 Relocate_functions<size, big_endian>::rela8(view, object,
3244 case elfcpp::R_SPARC_16:
3245 if (rela.get_r_offset() & 0x1)
3247 // The assembler can sometimes emit unaligned relocations
3248 // for dwarf2 cfi directives.
3249 Reloc::ua16(view, object, psymval, addend);
3252 Relocate_functions<size, big_endian>::rela16(view, object,
3256 case elfcpp::R_SPARC_32:
3257 if (!parameters->options().output_is_position_independent())
3259 if (rela.get_r_offset() & 0x3)
3261 // The assembler can sometimes emit unaligned relocations
3262 // for dwarf2 cfi directives.
3263 Reloc::ua32(view, object, psymval, addend);
3266 Relocate_functions<size, big_endian>::rela32(view, object,
3271 case elfcpp::R_SPARC_DISP8:
3272 Reloc::disp8(view, object, psymval, addend, address);
3275 case elfcpp::R_SPARC_DISP16:
3276 Reloc::disp16(view, object, psymval, addend, address);
3279 case elfcpp::R_SPARC_DISP32:
3280 Reloc::disp32(view, object, psymval, addend, address);
3283 case elfcpp::R_SPARC_DISP64:
3284 Reloc::disp64(view, object, psymval, addend, address);
3287 case elfcpp::R_SPARC_WDISP30:
3288 case elfcpp::R_SPARC_WPLT30:
3289 Reloc::wdisp30(view, object, psymval, addend, address);
3292 case elfcpp::R_SPARC_WDISP22:
3293 Reloc::wdisp22(view, object, psymval, addend, address);
3296 case elfcpp::R_SPARC_WDISP19:
3297 Reloc::wdisp19(view, object, psymval, addend, address);
3300 case elfcpp::R_SPARC_WDISP16:
3301 Reloc::wdisp16(view, object, psymval, addend, address);
3304 case elfcpp::R_SPARC_WDISP10:
3305 Reloc::wdisp10(view, object, psymval, addend, address);
3308 case elfcpp::R_SPARC_HI22:
3309 Reloc::hi22(view, object, psymval, addend);
3312 case elfcpp::R_SPARC_22:
3313 Reloc::rela32_22(view, object, psymval, addend);
3316 case elfcpp::R_SPARC_13:
3317 Reloc::rela32_13(view, object, psymval, addend);
3320 case elfcpp::R_SPARC_LO10:
3321 Reloc::lo10(view, object, psymval, addend);
3324 case elfcpp::R_SPARC_GOT10:
3325 Reloc::lo10(view, got_offset, addend);
3328 case elfcpp::R_SPARC_GOTDATA_OP:
3331 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3332 Insntype* wv = reinterpret_cast<Insntype*>(view);
3335 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3336 val = elfcpp::Swap<32, true>::readval(wv);
3337 val = 0x80000000 | (val & 0x3e07c01f);
3338 elfcpp::Swap<32, true>::writeval(wv, val);
3342 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3345 Reloc::gdop_lox10(view, got_offset, addend);
3349 case elfcpp::R_SPARC_GOT13:
3350 Reloc::rela32_13(view, got_offset, addend);
3353 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3356 Reloc::gdop_hix22(view, got_offset, addend);
3360 case elfcpp::R_SPARC_GOT22:
3361 Reloc::hi22(view, got_offset, addend);
3364 case elfcpp::R_SPARC_PC10:
3365 Reloc::pc10(view, object, psymval, addend, address);
3368 case elfcpp::R_SPARC_PC22:
3369 Reloc::pc22(view, object, psymval, addend, address);
3372 case elfcpp::R_SPARC_TLS_DTPOFF32:
3373 case elfcpp::R_SPARC_UA32:
3374 Reloc::ua32(view, object, psymval, addend);
3377 case elfcpp::R_SPARC_PLT64:
3378 Relocate_functions<size, big_endian>::rela64(view, object,
3382 case elfcpp::R_SPARC_PLT32:
3383 Relocate_functions<size, big_endian>::rela32(view, object,
3387 case elfcpp::R_SPARC_HIPLT22:
3388 Reloc::hi22(view, object, psymval, addend);
3391 case elfcpp::R_SPARC_LOPLT10:
3392 Reloc::lo10(view, object, psymval, addend);
3395 case elfcpp::R_SPARC_PCPLT32:
3396 Reloc::disp32(view, object, psymval, addend, address);
3399 case elfcpp::R_SPARC_PCPLT22:
3400 Reloc::pcplt22(view, object, psymval, addend, address);
3403 case elfcpp::R_SPARC_PCPLT10:
3404 Reloc::lo10(view, object, psymval, addend, address);
3407 case elfcpp::R_SPARC_64:
3408 if (!parameters->options().output_is_position_independent())
3410 if (rela.get_r_offset() & 0x7)
3412 // The assembler can sometimes emit unaligned relocations
3413 // for dwarf2 cfi directives.
3414 Reloc::ua64(view, object, psymval, addend);
3417 Relocate_functions<size, big_endian>::rela64(view, object,
3422 case elfcpp::R_SPARC_OLO10:
3424 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
3425 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
3426 Reloc::olo10(view, object, psymval, addend, addend2);
3430 case elfcpp::R_SPARC_HH22:
3431 Reloc::hh22(view, object, psymval, addend);
3434 case elfcpp::R_SPARC_PC_HH22:
3435 Reloc::pc_hh22(view, object, psymval, addend, address);
3438 case elfcpp::R_SPARC_HM10:
3439 Reloc::hm10(view, object, psymval, addend);
3442 case elfcpp::R_SPARC_PC_HM10:
3443 Reloc::pc_hm10(view, object, psymval, addend, address);
3446 case elfcpp::R_SPARC_LM22:
3447 Reloc::hi22(view, object, psymval, addend);
3450 case elfcpp::R_SPARC_PC_LM22:
3451 Reloc::pcplt22(view, object, psymval, addend, address);
3454 case elfcpp::R_SPARC_11:
3455 Reloc::rela32_11(view, object, psymval, addend);
3458 case elfcpp::R_SPARC_10:
3459 Reloc::rela32_10(view, object, psymval, addend);
3462 case elfcpp::R_SPARC_7:
3463 Reloc::rela32_7(view, object, psymval, addend);
3466 case elfcpp::R_SPARC_6:
3467 Reloc::rela32_6(view, object, psymval, addend);
3470 case elfcpp::R_SPARC_5:
3471 Reloc::rela32_5(view, object, psymval, addend);
3474 case elfcpp::R_SPARC_HIX22:
3475 Reloc::hix22(view, object, psymval, addend);
3478 case elfcpp::R_SPARC_LOX10:
3479 Reloc::lox10(view, object, psymval, addend);
3482 case elfcpp::R_SPARC_H34:
3483 Reloc::h34(view, object, psymval, addend);
3486 case elfcpp::R_SPARC_H44:
3487 Reloc::h44(view, object, psymval, addend);
3490 case elfcpp::R_SPARC_M44:
3491 Reloc::m44(view, object, psymval, addend);
3494 case elfcpp::R_SPARC_L44:
3495 Reloc::l44(view, object, psymval, addend);
3498 case elfcpp::R_SPARC_TLS_DTPOFF64:
3499 case elfcpp::R_SPARC_UA64:
3500 Reloc::ua64(view, object, psymval, addend);
3503 case elfcpp::R_SPARC_UA16:
3504 Reloc::ua16(view, object, psymval, addend);
3507 case elfcpp::R_SPARC_TLS_GD_HI22:
3508 case elfcpp::R_SPARC_TLS_GD_LO10:
3509 case elfcpp::R_SPARC_TLS_GD_ADD:
3510 case elfcpp::R_SPARC_TLS_GD_CALL:
3511 case elfcpp::R_SPARC_TLS_LDM_HI22:
3512 case elfcpp::R_SPARC_TLS_LDM_LO10:
3513 case elfcpp::R_SPARC_TLS_LDM_ADD:
3514 case elfcpp::R_SPARC_TLS_LDM_CALL:
3515 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3516 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3517 case elfcpp::R_SPARC_TLS_LDO_ADD:
3518 case elfcpp::R_SPARC_TLS_IE_HI22:
3519 case elfcpp::R_SPARC_TLS_IE_LO10:
3520 case elfcpp::R_SPARC_TLS_IE_LD:
3521 case elfcpp::R_SPARC_TLS_IE_LDX:
3522 case elfcpp::R_SPARC_TLS_IE_ADD:
3523 case elfcpp::R_SPARC_TLS_LE_HIX22:
3524 case elfcpp::R_SPARC_TLS_LE_LOX10:
3525 this->relocate_tls(relinfo, target, relnum, rela,
3526 r_type, gsym, psymval, view,
3527 address, view_size);
3530 case elfcpp::R_SPARC_COPY:
3531 case elfcpp::R_SPARC_GLOB_DAT:
3532 case elfcpp::R_SPARC_JMP_SLOT:
3533 case elfcpp::R_SPARC_JMP_IREL:
3534 case elfcpp::R_SPARC_RELATIVE:
3535 case elfcpp::R_SPARC_IRELATIVE:
3536 // These are outstanding tls relocs, which are unexpected when
3538 case elfcpp::R_SPARC_TLS_DTPMOD64:
3539 case elfcpp::R_SPARC_TLS_DTPMOD32:
3540 case elfcpp::R_SPARC_TLS_TPOFF64:
3541 case elfcpp::R_SPARC_TLS_TPOFF32:
3542 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3543 _("unexpected reloc %u in object file"),
3548 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3549 _("unsupported reloc %u"),
3557 // Perform a TLS relocation.
3559 template<int size, bool big_endian>
3561 Target_sparc<size, big_endian>::Relocate::relocate_tls(
3562 const Relocate_info<size, big_endian>* relinfo,
3563 Target_sparc<size, big_endian>* target,
3565 const elfcpp::Rela<size, big_endian>& rela,
3566 unsigned int r_type,
3567 const Sized_symbol<size>* gsym,
3568 const Symbol_value<size>* psymval,
3569 unsigned char* view,
3570 typename elfcpp::Elf_types<size>::Elf_Addr address,
3573 Output_segment* tls_segment = relinfo->layout->tls_segment();
3574 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3575 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3576 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3578 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3579 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
3581 const bool is_final =
3583 ? !parameters->options().output_is_position_independent()
3584 : gsym->final_value_is_known());
3585 const tls::Tls_optimization optimized_type
3586 = optimize_tls_reloc(is_final, r_type);
3590 case elfcpp::R_SPARC_TLS_GD_HI22:
3591 case elfcpp::R_SPARC_TLS_GD_LO10:
3592 case elfcpp::R_SPARC_TLS_GD_ADD:
3593 case elfcpp::R_SPARC_TLS_GD_CALL:
3594 if (optimized_type == tls::TLSOPT_TO_LE)
3596 Insntype* wv = reinterpret_cast<Insntype*>(view);
3599 value -= tls_segment->memsz();
3603 case elfcpp::R_SPARC_TLS_GD_HI22:
3604 // TLS_GD_HI22 --> TLS_LE_HIX22
3605 Reloc::hix22(view, value, addend);
3608 case elfcpp::R_SPARC_TLS_GD_LO10:
3609 // TLS_GD_LO10 --> TLS_LE_LOX10
3610 Reloc::lox10(view, value, addend);
3613 case elfcpp::R_SPARC_TLS_GD_ADD:
3614 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3615 val = elfcpp::Swap<32, true>::readval(wv);
3616 val = (val & ~0x7c000) | 0x1c000;
3617 elfcpp::Swap<32, true>::writeval(wv, val);
3619 case elfcpp::R_SPARC_TLS_GD_CALL:
3620 // call __tls_get_addr --> nop
3621 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3628 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3629 ? GOT_TYPE_TLS_OFFSET
3630 : GOT_TYPE_TLS_PAIR);
3633 gold_assert(gsym->has_got_offset(got_type));
3634 value = gsym->got_offset(got_type);
3638 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3639 gold_assert(object->local_has_got_offset(r_sym, got_type));
3640 value = object->local_got_offset(r_sym, got_type);
3642 if (optimized_type == tls::TLSOPT_TO_IE)
3644 Insntype* wv = reinterpret_cast<Insntype*>(view);
3649 case elfcpp::R_SPARC_TLS_GD_HI22:
3650 // TLS_GD_HI22 --> TLS_IE_HI22
3651 Reloc::hi22(view, value, addend);
3654 case elfcpp::R_SPARC_TLS_GD_LO10:
3655 // TLS_GD_LO10 --> TLS_IE_LO10
3656 Reloc::lo10(view, value, addend);
3659 case elfcpp::R_SPARC_TLS_GD_ADD:
3660 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3661 val = elfcpp::Swap<32, true>::readval(wv);
3668 elfcpp::Swap<32, true>::writeval(wv, val);
3671 case elfcpp::R_SPARC_TLS_GD_CALL:
3672 // The compiler can put the TLS_GD_ADD instruction
3673 // into the delay slot of the call. If so, we need
3674 // to transpose the two instructions so that the
3675 // new sequence works properly.
3677 // The test we use is if the instruction in the
3678 // delay slot is an add with destination register
3680 val = elfcpp::Swap<32, true>::readval(wv + 1);
3681 if ((val & 0x81f80000) == 0x80000000
3682 && ((val >> 25) & 0x1f) == 0x8)
3689 elfcpp::Swap<32, true>::writeval(wv, val);
3692 this->ignore_gd_add_ = true;
3696 // Even if the delay slot isn't the TLS_GD_ADD
3697 // instruction, we still have to handle the case
3698 // where it sets up %o0 in some other way.
3699 elfcpp::Swap<32, true>::writeval(wv, val);
3701 this->reloc_adjust_addr_ = view + 4;
3703 // call __tls_get_addr --> add %g7, %o0, %o0
3704 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
3709 else if (optimized_type == tls::TLSOPT_NONE)
3713 case elfcpp::R_SPARC_TLS_GD_HI22:
3714 Reloc::hi22(view, value, addend);
3716 case elfcpp::R_SPARC_TLS_GD_LO10:
3717 Reloc::lo10(view, value, addend);
3719 case elfcpp::R_SPARC_TLS_GD_ADD:
3721 case elfcpp::R_SPARC_TLS_GD_CALL:
3723 Symbol_value<size> symval;
3724 elfcpp::Elf_Xword value;
3727 tsym = target->tls_get_addr_sym_;
3729 value = (target->plt_section()->address() +
3730 tsym->plt_offset());
3731 symval.set_output_value(value);
3732 Reloc::wdisp30(view, object, &symval, addend, address);
3739 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3740 _("unsupported reloc %u"),
3744 case elfcpp::R_SPARC_TLS_LDM_HI22:
3745 case elfcpp::R_SPARC_TLS_LDM_LO10:
3746 case elfcpp::R_SPARC_TLS_LDM_ADD:
3747 case elfcpp::R_SPARC_TLS_LDM_CALL:
3748 if (optimized_type == tls::TLSOPT_TO_LE)
3750 Insntype* wv = reinterpret_cast<Insntype*>(view);
3754 case elfcpp::R_SPARC_TLS_LDM_HI22:
3755 case elfcpp::R_SPARC_TLS_LDM_LO10:
3756 case elfcpp::R_SPARC_TLS_LDM_ADD:
3757 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3760 case elfcpp::R_SPARC_TLS_LDM_CALL:
3761 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
3766 else if (optimized_type == tls::TLSOPT_NONE)
3768 // Relocate the field with the offset of the GOT entry for
3769 // the module index.
3770 unsigned int got_offset;
3772 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
3775 case elfcpp::R_SPARC_TLS_LDM_HI22:
3776 Reloc::hi22(view, got_offset, addend);
3778 case elfcpp::R_SPARC_TLS_LDM_LO10:
3779 Reloc::lo10(view, got_offset, addend);
3781 case elfcpp::R_SPARC_TLS_LDM_ADD:
3783 case elfcpp::R_SPARC_TLS_LDM_CALL:
3785 Symbol_value<size> symval;
3786 elfcpp::Elf_Xword value;
3789 tsym = target->tls_get_addr_sym_;
3791 value = (target->plt_section()->address() +
3792 tsym->plt_offset());
3793 symval.set_output_value(value);
3794 Reloc::wdisp30(view, object, &symval, addend, address);
3800 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3801 _("unsupported reloc %u"),
3805 // These relocs can appear in debugging sections, in which case
3806 // we won't see the TLS_LDM relocs. The local_dynamic_type
3807 // field tells us this.
3808 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3809 if (optimized_type == tls::TLSOPT_TO_LE)
3811 value -= tls_segment->memsz();
3812 Reloc::hix22(view, value, addend);
3815 Reloc::ldo_hix22(view, value, addend);
3817 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3818 if (optimized_type == tls::TLSOPT_TO_LE)
3820 value -= tls_segment->memsz();
3821 Reloc::lox10(view, value, addend);
3824 Reloc::ldo_lox10(view, value, addend);
3826 case elfcpp::R_SPARC_TLS_LDO_ADD:
3827 if (optimized_type == tls::TLSOPT_TO_LE)
3829 Insntype* wv = reinterpret_cast<Insntype*>(view);
3832 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3833 val = elfcpp::Swap<32, true>::readval(wv);
3834 val = (val & ~0x7c000) | 0x1c000;
3835 elfcpp::Swap<32, true>::writeval(wv, val);
3839 // When optimizing IE --> LE, the only relocation that is handled
3840 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3841 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3842 // rs2 and rd are the same.
3843 case elfcpp::R_SPARC_TLS_IE_LD:
3844 case elfcpp::R_SPARC_TLS_IE_LDX:
3845 if (optimized_type == tls::TLSOPT_TO_LE)
3847 Insntype* wv = reinterpret_cast<Insntype*>(view);
3848 Insntype val = elfcpp::Swap<32, true>::readval(wv);
3849 Insntype rs2 = val & 0x1f;
3850 Insntype rd = (val >> 25) & 0x1f;
3855 val = sparc_mov | (val & 0x3e00001f);
3857 elfcpp::Swap<32, true>::writeval(wv, val);
3861 case elfcpp::R_SPARC_TLS_IE_HI22:
3862 case elfcpp::R_SPARC_TLS_IE_LO10:
3863 if (optimized_type == tls::TLSOPT_TO_LE)
3865 value -= tls_segment->memsz();
3868 case elfcpp::R_SPARC_TLS_IE_HI22:
3869 // IE_HI22 --> LE_HIX22
3870 Reloc::hix22(view, value, addend);
3872 case elfcpp::R_SPARC_TLS_IE_LO10:
3873 // IE_LO10 --> LE_LOX10
3874 Reloc::lox10(view, value, addend);
3879 else if (optimized_type == tls::TLSOPT_NONE)
3881 // Relocate the field with the offset of the GOT entry for
3882 // the tp-relative offset of the symbol.
3885 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3886 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3890 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3891 gold_assert(object->local_has_got_offset(r_sym,
3892 GOT_TYPE_TLS_OFFSET));
3893 value = object->local_got_offset(r_sym,
3894 GOT_TYPE_TLS_OFFSET);
3898 case elfcpp::R_SPARC_TLS_IE_HI22:
3899 Reloc::hi22(view, value, addend);
3901 case elfcpp::R_SPARC_TLS_IE_LO10:
3902 Reloc::lo10(view, value, addend);
3907 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3908 _("unsupported reloc %u"),
3912 case elfcpp::R_SPARC_TLS_IE_ADD:
3913 // This seems to be mainly so that we can find the addition
3914 // instruction if there is one. There doesn't seem to be any
3915 // actual relocation to apply.
3918 case elfcpp::R_SPARC_TLS_LE_HIX22:
3919 // If we're creating a shared library, a dynamic relocation will
3920 // have been created for this location, so do not apply it now.
3921 if (!parameters->options().shared())
3923 value -= tls_segment->memsz();
3924 Reloc::hix22(view, value, addend);
3928 case elfcpp::R_SPARC_TLS_LE_LOX10:
3929 // If we're creating a shared library, a dynamic relocation will
3930 // have been created for this location, so do not apply it now.
3931 if (!parameters->options().shared())
3933 value -= tls_segment->memsz();
3934 Reloc::lox10(view, value, addend);
3940 // Relocate section data.
3942 template<int size, bool big_endian>
3944 Target_sparc<size, big_endian>::relocate_section(
3945 const Relocate_info<size, big_endian>* relinfo,
3946 unsigned int sh_type,
3947 const unsigned char* prelocs,
3949 Output_section* output_section,
3950 bool needs_special_offset_handling,
3951 unsigned char* view,
3952 typename elfcpp::Elf_types<size>::Elf_Addr address,
3953 section_size_type view_size,
3954 const Reloc_symbol_changes* reloc_symbol_changes)
3956 typedef Target_sparc<size, big_endian> Sparc;
3957 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
3959 gold_assert(sh_type == elfcpp::SHT_RELA);
3961 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
3968 needs_special_offset_handling,
3972 reloc_symbol_changes);
3975 // Return the size of a relocation while scanning during a relocatable
3978 template<int size, bool big_endian>
3980 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
3984 // We are always SHT_RELA, so we should never get here.
3989 // Scan the relocs during a relocatable link.
3991 template<int size, bool big_endian>
3993 Target_sparc<size, big_endian>::scan_relocatable_relocs(
3994 Symbol_table* symtab,
3996 Sized_relobj_file<size, big_endian>* object,
3997 unsigned int data_shndx,
3998 unsigned int sh_type,
3999 const unsigned char* prelocs,
4001 Output_section* output_section,
4002 bool needs_special_offset_handling,
4003 size_t local_symbol_count,
4004 const unsigned char* plocal_symbols,
4005 Relocatable_relocs* rr)
4007 gold_assert(sh_type == elfcpp::SHT_RELA);
4009 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4010 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4012 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
4013 Scan_relocatable_relocs>(
4021 needs_special_offset_handling,
4027 // Relocate a section during a relocatable link.
4029 template<int size, bool big_endian>
4031 Target_sparc<size, big_endian>::relocate_for_relocatable(
4032 const Relocate_info<size, big_endian>* relinfo,
4033 unsigned int sh_type,
4034 const unsigned char* prelocs,
4036 Output_section* output_section,
4037 off_t offset_in_output_section,
4038 const Relocatable_relocs* rr,
4039 unsigned char* view,
4040 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4041 section_size_type view_size,
4042 unsigned char* reloc_view,
4043 section_size_type reloc_view_size)
4045 gold_assert(sh_type == elfcpp::SHT_RELA);
4047 gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>(
4052 offset_in_output_section,
4061 // Return the value to use for a dynamic which requires special
4062 // treatment. This is how we support equality comparisons of function
4063 // pointers across shared library boundaries, as described in the
4064 // processor specific ABI supplement.
4066 template<int size, bool big_endian>
4068 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
4070 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4071 return this->plt_section()->address() + gsym->plt_offset();
4074 // The selector for sparc object files.
4076 template<int size, bool big_endian>
4077 class Target_selector_sparc : public Target_selector
4080 Target_selector_sparc()
4081 : Target_selector(elfcpp::EM_NONE, size, big_endian,
4082 (size == 64 ? "elf64-sparc" : "elf32-sparc"),
4083 (size == 64 ? "elf64_sparc" : "elf32_sparc"))
4086 Target* do_recognize(int machine, int, int)
4091 if (machine != elfcpp::EM_SPARCV9)
4096 if (machine != elfcpp::EM_SPARC
4097 && machine != elfcpp::EM_SPARC32PLUS)
4105 return this->instantiate_target();
4108 Target* do_instantiate_target()
4109 { return new Target_sparc<size, big_endian>(); }
4112 Target_selector_sparc<32, true> target_selector_sparc32;
4113 Target_selector_sparc<64, true> target_selector_sparc64;
4115 } // End anonymous namespace.