1 // sparc.cc -- sparc target support for gold.
3 // Copyright (C) 2008-2016 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),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL),
64 elf_machine_(sparc_info.machine_code), elf_flags_(0),
65 elf_flags_set_(false), register_syms_()
69 // Make a new symbol table entry.
71 make_symbol(const char*, elfcpp::STT, Object*, unsigned int, uint64_t);
73 // Process the relocations to determine unreferenced sections for
74 // garbage collection.
76 gc_process_relocs(Symbol_table* symtab,
78 Sized_relobj_file<size, big_endian>* object,
79 unsigned int data_shndx,
81 const unsigned char* prelocs,
83 Output_section* output_section,
84 bool needs_special_offset_handling,
85 size_t local_symbol_count,
86 const unsigned char* plocal_symbols);
88 // Scan the relocations to look for symbol adjustments.
90 scan_relocs(Symbol_table* symtab,
92 Sized_relobj_file<size, big_endian>* object,
93 unsigned int data_shndx,
95 const unsigned char* prelocs,
97 Output_section* output_section,
98 bool needs_special_offset_handling,
99 size_t local_symbol_count,
100 const unsigned char* plocal_symbols);
101 // Finalize the sections.
103 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
105 // Return the value to use for a dynamic which requires special
108 do_dynsym_value(const Symbol*) const;
110 // Relocate a section.
112 relocate_section(const Relocate_info<size, big_endian>*,
113 unsigned int sh_type,
114 const unsigned char* prelocs,
116 Output_section* output_section,
117 bool needs_special_offset_handling,
119 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
120 section_size_type view_size,
121 const Reloc_symbol_changes*);
123 // Scan the relocs during a relocatable link.
125 scan_relocatable_relocs(Symbol_table* symtab,
127 Sized_relobj_file<size, big_endian>* object,
128 unsigned int data_shndx,
129 unsigned int sh_type,
130 const unsigned char* prelocs,
132 Output_section* output_section,
133 bool needs_special_offset_handling,
134 size_t local_symbol_count,
135 const unsigned char* plocal_symbols,
136 Relocatable_relocs*);
138 // Scan the relocs for --emit-relocs.
140 emit_relocs_scan(Symbol_table* symtab,
142 Sized_relobj_file<size, big_endian>* object,
143 unsigned int data_shndx,
144 unsigned int sh_type,
145 const unsigned char* prelocs,
147 Output_section* output_section,
148 bool needs_special_offset_handling,
149 size_t local_symbol_count,
150 const unsigned char* plocal_syms,
151 Relocatable_relocs* rr);
153 // Emit relocations for a section.
155 relocate_relocs(const Relocate_info<size, big_endian>*,
156 unsigned int sh_type,
157 const unsigned char* prelocs,
159 Output_section* output_section,
160 typename elfcpp::Elf_types<size>::Elf_Off
161 offset_in_output_section,
163 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
164 section_size_type view_size,
165 unsigned char* reloc_view,
166 section_size_type reloc_view_size);
168 // Return whether SYM is defined by the ABI.
170 do_is_defined_by_abi(const Symbol* sym) const
171 { return strcmp(sym->name(), "___tls_get_addr") == 0; }
173 // Return the PLT address to use for a global symbol.
175 do_plt_address_for_global(const Symbol* gsym) const
176 { return this->plt_section()->address_for_global(gsym); }
179 do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
180 { return this->plt_section()->address_for_local(relobj, symndx); }
182 // Return whether there is a GOT section.
184 has_got_section() const
185 { return this->got_ != NULL; }
187 // Return the size of the GOT section.
191 gold_assert(this->got_ != NULL);
192 return this->got_->data_size();
195 // Return the number of entries in the GOT.
197 got_entry_count() const
199 if (this->got_ == NULL)
201 return this->got_size() / (size / 8);
204 // Return the address of the GOT.
208 if (this->got_ == NULL)
210 return this->got_->address();
213 // Return the number of entries in the PLT.
215 plt_entry_count() const;
217 // Return the offset of the first non-reserved PLT entry.
219 first_plt_entry_offset() const;
221 // Return the size of each PLT entry.
223 plt_entry_size() const;
226 // Make an ELF object.
228 do_make_elf_object(const std::string&, Input_file*, off_t,
229 const elfcpp::Ehdr<size, big_endian>& ehdr);
232 do_adjust_elf_header(unsigned char* view, int len);
236 // The class which scans relocations.
241 : issued_non_pic_error_(false)
245 get_reference_flags(unsigned int r_type);
248 local(Symbol_table* symtab, Layout* layout, Target_sparc* target,
249 Sized_relobj_file<size, big_endian>* object,
250 unsigned int data_shndx,
251 Output_section* output_section,
252 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
253 const elfcpp::Sym<size, big_endian>& lsym,
257 global(Symbol_table* symtab, Layout* layout, Target_sparc* target,
258 Sized_relobj_file<size, big_endian>* object,
259 unsigned int data_shndx,
260 Output_section* output_section,
261 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
265 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
267 Sized_relobj_file<size, big_endian>* ,
270 const elfcpp::Rela<size, big_endian>& ,
272 const elfcpp::Sym<size, big_endian>&)
276 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
278 Sized_relobj_file<size, big_endian>* ,
281 const elfcpp::Rela<size,
283 unsigned int , Symbol*)
289 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
290 unsigned int r_type);
293 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
294 unsigned int r_type, Symbol*);
297 generate_tls_call(Symbol_table* symtab, Layout* layout,
298 Target_sparc* target);
301 check_non_pic(Relobj*, unsigned int r_type);
304 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*,
305 unsigned int r_type);
307 // Whether we have issued an error about a non-PIC compilation.
308 bool issued_non_pic_error_;
311 // The class which implements relocation.
316 : ignore_gd_add_(false), reloc_adjust_addr_(NULL)
321 if (this->ignore_gd_add_)
323 // FIXME: This needs to specify the location somehow.
324 gold_error(_("missing expected TLS relocation"));
328 // Do a relocation. Return false if the caller should not issue
329 // any warnings about this relocation.
331 relocate(const Relocate_info<size, big_endian>*, unsigned int,
332 Target_sparc*, Output_section*, size_t, const unsigned char*,
333 const Sized_symbol<size>*, const Symbol_value<size>*,
334 unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
338 // Do a TLS relocation.
340 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
341 size_t relnum, const elfcpp::Rela<size, big_endian>&,
342 unsigned int r_type, const Sized_symbol<size>*,
343 const Symbol_value<size>*,
345 typename elfcpp::Elf_types<size>::Elf_Addr,
349 relax_call(Target_sparc<size, big_endian>* target,
351 const elfcpp::Rela<size, big_endian>& rela,
352 section_size_type view_size);
354 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
357 // If we hit a reloc at this view address, adjust it back by 4 bytes.
358 unsigned char *reloc_adjust_addr_;
361 // Get the GOT section, creating it if necessary.
362 Output_data_got<size, big_endian>*
363 got_section(Symbol_table*, Layout*);
365 // Create the PLT section.
367 make_plt_section(Symbol_table* symtab, Layout* layout);
369 // Create a PLT entry for a global symbol.
371 make_plt_entry(Symbol_table*, Layout*, Symbol*);
373 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
375 make_local_ifunc_plt_entry(Symbol_table*, Layout*,
376 Sized_relobj_file<size, big_endian>* relobj,
377 unsigned int local_sym_index);
379 // Create a GOT entry for the TLS module index.
381 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
382 Sized_relobj_file<size, big_endian>* object);
384 // Return the gsym for "__tls_get_addr". Cache if not already
387 tls_get_addr_sym(Symbol_table* symtab)
389 if (!this->tls_get_addr_sym_)
390 this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL);
391 gold_assert(this->tls_get_addr_sym_);
392 return this->tls_get_addr_sym_;
395 // Get the PLT section.
396 Output_data_plt_sparc<size, big_endian>*
399 gold_assert(this->plt_ != NULL);
403 // Get the dynamic reloc section, creating it if necessary.
405 rela_dyn_section(Layout*);
407 // Get the section to use for IFUNC relocations.
409 rela_ifunc_section(Layout*);
411 // Copy a relocation against a global symbol.
413 copy_reloc(Symbol_table* symtab, Layout* layout,
414 Sized_relobj_file<size, big_endian>* object,
415 unsigned int shndx, Output_section* output_section,
416 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
418 unsigned int r_type = elfcpp::elf_r_type<size>(reloc.get_r_info());
419 this->copy_relocs_.copy_reloc(symtab, layout,
420 symtab->get_sized_symbol<size>(sym),
421 object, shndx, output_section,
422 r_type, reloc.get_r_offset(),
423 reloc.get_r_addend(),
424 this->rela_dyn_section(layout));
427 // Information about this specific target which we pass to the
428 // general Target structure.
429 static Target::Target_info sparc_info;
431 // The types of GOT entries needed for this platform.
432 // These values are exposed to the ABI in an incremental link.
433 // Do not renumber existing values without changing the version
434 // number of the .gnu_incremental_inputs section.
437 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
438 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
439 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
442 struct Register_symbol
445 : name(NULL), shndx(0), obj(NULL)
453 Output_data_got<size, big_endian>* got_;
455 Output_data_plt_sparc<size, big_endian>* plt_;
456 // The dynamic reloc section.
457 Reloc_section* rela_dyn_;
458 // The section to use for IFUNC relocs.
459 Reloc_section* rela_ifunc_;
460 // Relocs saved to avoid a COPY reloc.
461 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
462 // Offset of the GOT entry for the TLS module index;
463 unsigned int got_mod_index_offset_;
464 // Cached pointer to __tls_get_addr symbol
465 Symbol* tls_get_addr_sym_;
466 // Accumulated elf machine type
467 elfcpp::Elf_Half elf_machine_;
468 // Accumulated elf header flags
469 elfcpp::Elf_Word elf_flags_;
470 // Whether elf_flags_ has been set for the first time yet
472 // STT_SPARC_REGISTER symbols (%g2, %g3, %g6, %g7).
473 Register_symbol register_syms_[4];
477 Target::Target_info Target_sparc<32, true>::sparc_info =
480 true, // is_big_endian
481 elfcpp::EM_SPARC, // machine_code
482 false, // has_make_symbol
483 false, // has_resolve
484 false, // has_code_fill
485 true, // is_default_stack_executable
486 false, // can_icf_inline_merge_sections
488 "/usr/lib/ld.so.1", // dynamic_linker
489 0x00010000, // default_text_segment_address
490 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
491 8 * 1024, // common_pagesize (overridable by -z common-page-size)
492 false, // isolate_execinstr
494 elfcpp::SHN_UNDEF, // small_common_shndx
495 elfcpp::SHN_UNDEF, // large_common_shndx
496 0, // small_common_section_flags
497 0, // large_common_section_flags
498 NULL, // attributes_section
499 NULL, // attributes_vendor
500 "_start", // entry_symbol_name
501 32, // hash_entry_size
505 Target::Target_info Target_sparc<64, true>::sparc_info =
508 true, // is_big_endian
509 elfcpp::EM_SPARCV9, // machine_code
510 true, // has_make_symbol
511 false, // has_resolve
512 false, // has_code_fill
513 true, // is_default_stack_executable
514 false, // can_icf_inline_merge_sections
516 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
517 0x100000, // default_text_segment_address
518 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
519 8 * 1024, // common_pagesize (overridable by -z common-page-size)
520 false, // isolate_execinstr
522 elfcpp::SHN_UNDEF, // small_common_shndx
523 elfcpp::SHN_UNDEF, // large_common_shndx
524 0, // small_common_section_flags
525 0, // large_common_section_flags
526 NULL, // attributes_section
527 NULL, // attributes_vendor
528 "_start", // entry_symbol_name
529 32, // hash_entry_size
532 // We have to take care here, even when operating in little-endian
533 // mode, sparc instructions are still big endian.
534 template<int size, bool big_endian>
535 class Sparc_relocate_functions
538 // Do a simple relocation with the addend in the relocation.
539 template<int valsize>
541 rela(unsigned char* view,
542 unsigned int right_shift,
543 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
544 typename elfcpp::Swap<size, big_endian>::Valtype value,
545 typename elfcpp::Swap<size, big_endian>::Valtype addend)
547 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
548 Valtype* wv = reinterpret_cast<Valtype*>(view);
549 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
550 Valtype reloc = ((value + addend) >> right_shift);
555 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
558 // Do a simple relocation using a symbol value with the addend in
560 template<int valsize>
562 rela(unsigned char* view,
563 unsigned int right_shift,
564 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
565 const Sized_relobj_file<size, big_endian>* object,
566 const Symbol_value<size>* psymval,
567 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
569 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
570 Valtype* wv = reinterpret_cast<Valtype*>(view);
571 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
572 Valtype reloc = (psymval->value(object, addend) >> right_shift);
577 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
580 // Do a simple relocation using a symbol value with the addend in
581 // the relocation, unaligned.
582 template<int valsize>
584 rela_ua(unsigned char* view,
585 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
586 const Sized_relobj_file<size, big_endian>* object,
587 const Symbol_value<size>* psymval,
588 typename elfcpp::Swap<size, big_endian>::Valtype addend)
590 typedef typename elfcpp::Swap_unaligned<valsize,
591 big_endian>::Valtype Valtype;
592 unsigned char* wv = view;
593 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
594 Valtype reloc = (psymval->value(object, addend) >> right_shift);
599 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
602 // Do a simple PC relative relocation with a Symbol_value with the
603 // addend in the relocation.
604 template<int valsize>
606 pcrela(unsigned char* view,
607 unsigned int right_shift,
608 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
609 const Sized_relobj_file<size, big_endian>* object,
610 const Symbol_value<size>* psymval,
611 typename elfcpp::Swap<size, big_endian>::Valtype addend,
612 typename elfcpp::Elf_types<size>::Elf_Addr address)
614 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
615 Valtype* wv = reinterpret_cast<Valtype*>(view);
616 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
617 Valtype reloc = ((psymval->value(object, addend) - address)
623 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
626 template<int valsize>
628 pcrela_unaligned(unsigned char* view,
629 const Sized_relobj_file<size, big_endian>* object,
630 const Symbol_value<size>* psymval,
631 typename elfcpp::Swap<size, big_endian>::Valtype addend,
632 typename elfcpp::Elf_types<size>::Elf_Addr address)
634 typedef typename elfcpp::Swap_unaligned<valsize,
635 big_endian>::Valtype Valtype;
636 unsigned char* wv = view;
637 Valtype reloc = (psymval->value(object, addend) - address);
639 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
642 typedef Sparc_relocate_functions<size, big_endian> This;
643 typedef Sparc_relocate_functions<size, true> This_insn;
646 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
648 wdisp30(unsigned char* view,
649 const Sized_relobj_file<size, big_endian>* object,
650 const Symbol_value<size>* psymval,
651 typename elfcpp::Elf_types<size>::Elf_Addr addend,
652 typename elfcpp::Elf_types<size>::Elf_Addr address)
654 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
655 psymval, addend, address);
658 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
660 wdisp22(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 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
667 psymval, addend, address);
670 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
672 wdisp19(unsigned char* view,
673 const Sized_relobj_file<size, big_endian>* object,
674 const Symbol_value<size>* psymval,
675 typename elfcpp::Elf_types<size>::Elf_Addr addend,
676 typename elfcpp::Elf_types<size>::Elf_Addr address)
678 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
679 psymval, addend, address);
682 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
684 wdisp16(unsigned char* view,
685 const Sized_relobj_file<size, big_endian>* object,
686 const Symbol_value<size>* psymval,
687 typename elfcpp::Elf_types<size>::Elf_Addr addend,
688 typename elfcpp::Elf_types<size>::Elf_Addr address)
690 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
691 Valtype* wv = reinterpret_cast<Valtype*>(view);
692 Valtype val = elfcpp::Swap<32, true>::readval(wv);
693 Valtype reloc = ((psymval->value(object, addend) - address)
696 // The relocation value is split between the low 14 bits,
698 val &= ~((0x3 << 20) | 0x3fff);
699 reloc = (((reloc & 0xc000) << (20 - 14))
700 | (reloc & 0x3ffff));
702 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
705 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
707 wdisp10(unsigned char* view,
708 const Sized_relobj_file<size, big_endian>* object,
709 const Symbol_value<size>* psymval,
710 typename elfcpp::Elf_types<size>::Elf_Addr addend,
711 typename elfcpp::Elf_types<size>::Elf_Addr address)
713 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
714 Valtype* wv = reinterpret_cast<Valtype*>(view);
715 Valtype val = elfcpp::Swap<32, true>::readval(wv);
716 Valtype reloc = ((psymval->value(object, addend) - address)
719 // The relocation value is split between the low bits 5-12,
720 // and high bits 19-20.
721 val &= ~((0x3 << 19) | (0xff << 5));
722 reloc = (((reloc & 0x300) << (19 - 8))
723 | ((reloc & 0xff) << (5 - 0)));
725 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
728 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
730 pc22(unsigned char* view,
731 const Sized_relobj_file<size, big_endian>* object,
732 const Symbol_value<size>* psymval,
733 typename elfcpp::Elf_types<size>::Elf_Addr addend,
734 typename elfcpp::Elf_types<size>::Elf_Addr address)
736 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
737 psymval, addend, address);
740 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
742 pc10(unsigned char* view,
743 const Sized_relobj_file<size, big_endian>* object,
744 const Symbol_value<size>* psymval,
745 typename elfcpp::Elf_types<size>::Elf_Addr addend,
746 typename elfcpp::Elf_types<size>::Elf_Addr address)
748 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
749 psymval, addend, address);
752 // R_SPARC_HI22: (Symbol + Addend) >> 10
754 hi22(unsigned char* view,
755 typename elfcpp::Elf_types<size>::Elf_Addr value,
756 typename elfcpp::Elf_types<size>::Elf_Addr addend)
758 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
761 // R_SPARC_HI22: (Symbol + Addend) >> 10
763 hi22(unsigned char* view,
764 const Sized_relobj_file<size, big_endian>* object,
765 const Symbol_value<size>* psymval,
766 typename elfcpp::Elf_types<size>::Elf_Addr addend)
768 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
771 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
773 pcplt22(unsigned char* view,
774 const Sized_relobj_file<size, big_endian>* object,
775 const Symbol_value<size>* psymval,
776 typename elfcpp::Elf_types<size>::Elf_Addr addend,
777 typename elfcpp::Elf_types<size>::Elf_Addr address)
779 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
780 psymval, addend, address);
783 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
785 lo10(unsigned char* view,
786 typename elfcpp::Elf_types<size>::Elf_Addr value,
787 typename elfcpp::Elf_types<size>::Elf_Addr addend)
789 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
792 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
794 lo10(unsigned char* view,
795 const Sized_relobj_file<size, big_endian>* object,
796 const Symbol_value<size>* psymval,
797 typename elfcpp::Elf_types<size>::Elf_Addr addend)
799 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
802 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
804 lo10(unsigned char* view,
805 const Sized_relobj_file<size, big_endian>* object,
806 const Symbol_value<size>* psymval,
807 typename elfcpp::Elf_types<size>::Elf_Addr addend,
808 typename elfcpp::Elf_types<size>::Elf_Addr address)
810 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
811 psymval, addend, address);
814 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
816 olo10(unsigned char* view,
817 const Sized_relobj_file<size, big_endian>* object,
818 const Symbol_value<size>* psymval,
819 typename elfcpp::Elf_types<size>::Elf_Addr addend,
820 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
822 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
823 Valtype* wv = reinterpret_cast<Valtype*>(view);
824 Valtype val = elfcpp::Swap<32, true>::readval(wv);
825 Valtype reloc = psymval->value(object, addend);
832 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
835 // R_SPARC_22: (Symbol + Addend)
837 rela32_22(unsigned char* view,
838 const Sized_relobj_file<size, big_endian>* object,
839 const Symbol_value<size>* psymval,
840 typename elfcpp::Elf_types<size>::Elf_Addr addend)
842 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
845 // R_SPARC_13: (Symbol + Addend)
847 rela32_13(unsigned char* view,
848 typename elfcpp::Elf_types<size>::Elf_Addr value,
849 typename elfcpp::Elf_types<size>::Elf_Addr addend)
851 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
854 // R_SPARC_13: (Symbol + Addend)
856 rela32_13(unsigned char* view,
857 const Sized_relobj_file<size, big_endian>* object,
858 const Symbol_value<size>* psymval,
859 typename elfcpp::Elf_types<size>::Elf_Addr addend)
861 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
864 // R_SPARC_UA16: (Symbol + Addend)
866 ua16(unsigned char* view,
867 const Sized_relobj_file<size, big_endian>* object,
868 const Symbol_value<size>* psymval,
869 typename elfcpp::Elf_types<size>::Elf_Addr addend)
871 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
874 // R_SPARC_UA32: (Symbol + Addend)
876 ua32(unsigned char* view,
877 const Sized_relobj_file<size, big_endian>* object,
878 const Symbol_value<size>* psymval,
879 typename elfcpp::Elf_types<size>::Elf_Addr addend)
881 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
884 // R_SPARC_UA64: (Symbol + Addend)
886 ua64(unsigned char* view,
887 const Sized_relobj_file<size, big_endian>* object,
888 const Symbol_value<size>* psymval,
889 typename elfcpp::Elf_types<size>::Elf_Addr addend)
891 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
892 object, psymval, addend);
895 // R_SPARC_DISP8: (Symbol + Addend - Address)
897 disp8(unsigned char* view,
898 const Sized_relobj_file<size, big_endian>* object,
899 const Symbol_value<size>* psymval,
900 typename elfcpp::Elf_types<size>::Elf_Addr addend,
901 typename elfcpp::Elf_types<size>::Elf_Addr address)
903 This::template pcrela_unaligned<8>(view, object, psymval,
907 // R_SPARC_DISP16: (Symbol + Addend - Address)
909 disp16(unsigned char* view,
910 const Sized_relobj_file<size, big_endian>* object,
911 const Symbol_value<size>* psymval,
912 typename elfcpp::Elf_types<size>::Elf_Addr addend,
913 typename elfcpp::Elf_types<size>::Elf_Addr address)
915 This::template pcrela_unaligned<16>(view, object, psymval,
919 // R_SPARC_DISP32: (Symbol + Addend - Address)
921 disp32(unsigned char* view,
922 const Sized_relobj_file<size, big_endian>* object,
923 const Symbol_value<size>* psymval,
924 typename elfcpp::Elf_types<size>::Elf_Addr addend,
925 typename elfcpp::Elf_types<size>::Elf_Addr address)
927 This::template pcrela_unaligned<32>(view, object, psymval,
931 // R_SPARC_DISP64: (Symbol + Addend - Address)
933 disp64(unsigned char* view,
934 const Sized_relobj_file<size, big_endian>* object,
935 const Symbol_value<size>* psymval,
936 elfcpp::Elf_Xword addend,
937 typename elfcpp::Elf_types<size>::Elf_Addr address)
939 This::template pcrela_unaligned<64>(view, object, psymval,
943 // R_SPARC_H34: (Symbol + Addend) >> 12
945 h34(unsigned char* view,
946 const Sized_relobj_file<size, big_endian>* object,
947 const Symbol_value<size>* psymval,
948 typename elfcpp::Elf_types<size>::Elf_Addr addend)
950 This_insn::template rela<32>(view, 12, 0x003fffff, object, psymval, addend);
953 // R_SPARC_H44: (Symbol + Addend) >> 22
955 h44(unsigned char* view,
956 const Sized_relobj_file<size, big_endian>* object,
957 const Symbol_value<size>* psymval,
958 typename elfcpp::Elf_types<size>::Elf_Addr addend)
960 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
963 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
965 m44(unsigned char* view,
966 const Sized_relobj_file<size, big_endian>* object,
967 const Symbol_value<size>* psymval,
968 typename elfcpp::Elf_types<size>::Elf_Addr addend)
970 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
973 // R_SPARC_L44: (Symbol + Addend) & 0xfff
975 l44(unsigned char* view,
976 const Sized_relobj_file<size, big_endian>* object,
977 const Symbol_value<size>* psymval,
978 typename elfcpp::Elf_types<size>::Elf_Addr addend)
980 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
983 // R_SPARC_HH22: (Symbol + Addend) >> 42
985 hh22(unsigned char* view,
986 const Sized_relobj_file<size, big_endian>* object,
987 const Symbol_value<size>* psymval,
988 typename elfcpp::Elf_types<size>::Elf_Addr addend)
990 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
993 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
995 pc_hh22(unsigned char* view,
996 const Sized_relobj_file<size, big_endian>* object,
997 const Symbol_value<size>* psymval,
998 typename elfcpp::Elf_types<size>::Elf_Addr addend,
999 typename elfcpp::Elf_types<size>::Elf_Addr address)
1001 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
1002 psymval, addend, address);
1005 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
1007 hm10(unsigned char* view,
1008 const Sized_relobj_file<size, big_endian>* object,
1009 const Symbol_value<size>* psymval,
1010 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1012 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
1015 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
1017 pc_hm10(unsigned char* view,
1018 const Sized_relobj_file<size, big_endian>* object,
1019 const Symbol_value<size>* psymval,
1020 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1021 typename elfcpp::Elf_types<size>::Elf_Addr address)
1023 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
1024 psymval, addend, address);
1027 // R_SPARC_11: (Symbol + Addend)
1029 rela32_11(unsigned char* view,
1030 const Sized_relobj_file<size, big_endian>* object,
1031 const Symbol_value<size>* psymval,
1032 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1034 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
1037 // R_SPARC_10: (Symbol + Addend)
1039 rela32_10(unsigned char* view,
1040 const Sized_relobj_file<size, big_endian>* object,
1041 const Symbol_value<size>* psymval,
1042 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1044 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
1047 // R_SPARC_7: (Symbol + Addend)
1049 rela32_7(unsigned char* view,
1050 const Sized_relobj_file<size, big_endian>* object,
1051 const Symbol_value<size>* psymval,
1052 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1054 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
1057 // R_SPARC_6: (Symbol + Addend)
1059 rela32_6(unsigned char* view,
1060 const Sized_relobj_file<size, big_endian>* object,
1061 const Symbol_value<size>* psymval,
1062 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1064 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
1067 // R_SPARC_5: (Symbol + Addend)
1069 rela32_5(unsigned char* view,
1070 const Sized_relobj_file<size, big_endian>* object,
1071 const Symbol_value<size>* psymval,
1072 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1074 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
1077 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1079 ldo_hix22(unsigned char* view,
1080 typename elfcpp::Elf_types<size>::Elf_Addr value,
1081 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1083 This_insn::hi22(view, value, addend);
1086 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1088 ldo_lox10(unsigned char* view,
1089 typename elfcpp::Elf_types<size>::Elf_Addr value,
1090 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1092 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1093 Valtype* wv = reinterpret_cast<Valtype*>(view);
1094 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1095 Valtype reloc = (value + addend);
1100 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1103 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1105 hix22(unsigned char* view,
1106 typename elfcpp::Elf_types<size>::Elf_Addr value,
1107 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1109 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1110 Valtype* wv = reinterpret_cast<Valtype*>(view);
1111 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1112 Valtype reloc = (value + addend);
1116 reloc ^= ~(Valtype)0;
1121 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1124 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1126 gdop_hix22(unsigned char* view,
1127 typename elfcpp::Elf_types<size>::Elf_Addr value)
1129 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1130 Valtype* wv = reinterpret_cast<Valtype*>(view);
1131 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1132 int32_t reloc = static_cast<int32_t>(value);
1137 reloc ^= ~static_cast<int32_t>(0);
1142 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1145 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1147 hix22(unsigned char* view,
1148 const Sized_relobj_file<size, big_endian>* object,
1149 const Symbol_value<size>* psymval,
1150 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1152 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1153 Valtype* wv = reinterpret_cast<Valtype*>(view);
1154 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1155 Valtype reloc = psymval->value(object, addend);
1159 reloc ^= ~(Valtype)0;
1164 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1168 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1170 lox10(unsigned char* view,
1171 typename elfcpp::Elf_types<size>::Elf_Addr value,
1172 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1174 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1175 Valtype* wv = reinterpret_cast<Valtype*>(view);
1176 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1177 Valtype reloc = (value + addend);
1183 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1186 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1188 gdop_lox10(unsigned char* view,
1189 typename elfcpp::Elf_types<size>::Elf_Addr value)
1191 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1192 Valtype* wv = reinterpret_cast<Valtype*>(view);
1193 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1194 int32_t reloc = static_cast<int32_t>(value);
1197 reloc = (reloc & 0x3ff) | 0x1c00;
1199 reloc = (reloc & 0x3ff);
1202 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1205 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1207 lox10(unsigned char* view,
1208 const Sized_relobj_file<size, big_endian>* object,
1209 const Symbol_value<size>* psymval,
1210 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1212 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1213 Valtype* wv = reinterpret_cast<Valtype*>(view);
1214 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1215 Valtype reloc = psymval->value(object, addend);
1221 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1225 // Get the GOT section, creating it if necessary.
1227 template<int size, bool big_endian>
1228 Output_data_got<size, big_endian>*
1229 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
1232 if (this->got_ == NULL)
1234 gold_assert(symtab != NULL && layout != NULL);
1236 this->got_ = new Output_data_got<size, big_endian>();
1238 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1240 | elfcpp::SHF_WRITE),
1241 this->got_, ORDER_RELRO, true);
1243 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1244 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1245 Symbol_table::PREDEFINED,
1247 0, 0, elfcpp::STT_OBJECT,
1249 elfcpp::STV_HIDDEN, 0,
1256 // Get the dynamic reloc section, creating it if necessary.
1258 template<int size, bool big_endian>
1259 typename Target_sparc<size, big_endian>::Reloc_section*
1260 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1262 if (this->rela_dyn_ == NULL)
1264 gold_assert(layout != NULL);
1265 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1266 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1267 elfcpp::SHF_ALLOC, this->rela_dyn_,
1268 ORDER_DYNAMIC_RELOCS, false);
1270 return this->rela_dyn_;
1273 // Get the section to use for IFUNC relocs, creating it if
1274 // necessary. These go in .rela.dyn, but only after all other dynamic
1275 // relocations. They need to follow the other dynamic relocations so
1276 // that they can refer to global variables initialized by those
1279 template<int size, bool big_endian>
1280 typename Target_sparc<size, big_endian>::Reloc_section*
1281 Target_sparc<size, big_endian>::rela_ifunc_section(Layout* layout)
1283 if (this->rela_ifunc_ == NULL)
1285 // Make sure we have already created the dynamic reloc section.
1286 this->rela_dyn_section(layout);
1287 this->rela_ifunc_ = new Reloc_section(false);
1288 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1289 elfcpp::SHF_ALLOC, this->rela_ifunc_,
1290 ORDER_DYNAMIC_RELOCS, false);
1291 gold_assert(this->rela_dyn_->output_section()
1292 == this->rela_ifunc_->output_section());
1294 return this->rela_ifunc_;
1297 // A class to handle the PLT data.
1299 template<int size, bool big_endian>
1300 class Output_data_plt_sparc : public Output_section_data
1303 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1304 size, big_endian> Reloc_section;
1306 Output_data_plt_sparc(Layout*);
1308 // Add an entry to the PLT.
1309 void add_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym);
1311 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1313 add_local_ifunc_entry(Symbol_table*, Layout*,
1314 Sized_relobj_file<size, big_endian>* relobj,
1315 unsigned int local_sym_index);
1317 // Return the .rela.plt section data.
1318 const Reloc_section* rel_plt() const
1323 // Return where the IFUNC relocations should go.
1325 rela_ifunc(Symbol_table*, Layout*);
1328 emit_pending_ifunc_relocs();
1330 // Return whether we created a section for IFUNC relocations.
1332 has_ifunc_section() const
1333 { return this->ifunc_rel_ != NULL; }
1335 // Return the number of PLT entries.
1338 { return this->count_ + this->ifunc_count_; }
1340 // Return the offset of the first non-reserved PLT entry.
1342 first_plt_entry_offset()
1343 { return 4 * base_plt_entry_size; }
1345 // Return the size of a PLT entry.
1347 get_plt_entry_size()
1348 { return base_plt_entry_size; }
1350 // Return the PLT address to use for a global symbol.
1352 address_for_global(const Symbol*);
1354 // Return the PLT address to use for a local symbol.
1356 address_for_local(const Relobj*, unsigned int symndx);
1359 void do_adjust_output_section(Output_section* os);
1361 // Write to a map file.
1363 do_print_to_mapfile(Mapfile* mapfile) const
1364 { mapfile->print_output_data(this, _("** PLT")); }
1367 // The size of an entry in the PLT.
1368 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1370 static const unsigned int plt_entries_per_block = 160;
1371 static const unsigned int plt_insn_chunk_size = 24;
1372 static const unsigned int plt_pointer_chunk_size = 8;
1373 static const unsigned int plt_block_size =
1374 (plt_entries_per_block
1375 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1378 plt_index_to_offset(unsigned int index)
1380 section_offset_type offset;
1382 if (size == 32 || index < 32768)
1383 offset = index * base_plt_entry_size;
1386 unsigned int ext_index = index - 32768;
1388 offset = (32768 * base_plt_entry_size)
1389 + ((ext_index / plt_entries_per_block)
1391 + ((ext_index % plt_entries_per_block)
1392 * plt_insn_chunk_size);
1397 // Set the final size.
1399 set_final_data_size()
1401 unsigned int full_count = this->entry_count() + 4;
1402 unsigned int extra = (size == 32 ? 4 : 0);
1403 section_offset_type sz = plt_index_to_offset(full_count) + extra;
1405 return this->set_data_size(sz);
1408 // Write out the PLT data.
1410 do_write(Output_file*);
1416 unsigned int plt_index;
1422 Sized_relobj_file<size, big_endian>* object;
1423 unsigned int local_sym_index;
1424 unsigned int plt_index;
1427 // The reloc section.
1428 Reloc_section* rel_;
1429 // The IFUNC relocations, if necessary. These must follow the
1430 // regular relocations.
1431 Reloc_section* ifunc_rel_;
1432 // The number of PLT entries.
1433 unsigned int count_;
1434 // The number of PLT entries for IFUNC symbols.
1435 unsigned int ifunc_count_;
1436 // Global STT_GNU_IFUNC symbols.
1437 std::vector<Global_ifunc> global_ifuncs_;
1438 // Local STT_GNU_IFUNC symbols.
1439 std::vector<Local_ifunc> local_ifuncs_;
1442 // Define the constants as required by C++ standard.
1444 template<int size, bool big_endian>
1445 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1447 template<int size, bool big_endian>
1449 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1451 template<int size, bool big_endian>
1452 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1454 template<int size, bool big_endian>
1456 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1458 template<int size, bool big_endian>
1459 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1461 // Create the PLT section. The ordinary .got section is an argument,
1462 // since we need to refer to the start.
1464 template<int size, bool big_endian>
1465 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1466 : Output_section_data(size == 32 ? 4 : 8), ifunc_rel_(NULL),
1467 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1469 this->rel_ = new Reloc_section(false);
1470 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1471 elfcpp::SHF_ALLOC, this->rel_,
1472 ORDER_DYNAMIC_PLT_RELOCS, false);
1475 template<int size, bool big_endian>
1477 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1482 // Add an entry to the PLT.
1484 template<int size, bool big_endian>
1486 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol_table* symtab,
1490 gold_assert(!gsym->has_plt_offset());
1492 section_offset_type plt_offset;
1495 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1496 && gsym->can_use_relative_reloc(false))
1498 index = this->ifunc_count_;
1499 plt_offset = plt_index_to_offset(index);
1500 gsym->set_plt_offset(plt_offset);
1501 ++this->ifunc_count_;
1502 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1504 struct Global_ifunc gi;
1507 gi.plt_index = index;
1508 this->global_ifuncs_.push_back(gi);
1512 plt_offset = plt_index_to_offset(this->count_ + 4);
1513 gsym->set_plt_offset(plt_offset);
1515 gsym->set_needs_dynsym_entry();
1516 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1520 // Note that we don't need to save the symbol. The contents of the
1521 // PLT are independent of which symbols are used. The symbols only
1522 // appear in the relocations.
1525 template<int size, bool big_endian>
1527 Output_data_plt_sparc<size, big_endian>::add_local_ifunc_entry(
1528 Symbol_table* symtab,
1530 Sized_relobj_file<size, big_endian>* relobj,
1531 unsigned int local_sym_index)
1533 unsigned int index = this->ifunc_count_;
1534 section_offset_type plt_offset;
1536 plt_offset = plt_index_to_offset(index);
1537 ++this->ifunc_count_;
1539 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1541 struct Local_ifunc li;
1544 li.local_sym_index = local_sym_index;
1545 li.plt_index = index;
1546 this->local_ifuncs_.push_back(li);
1551 // Emit any pending IFUNC plt relocations.
1553 template<int size, bool big_endian>
1555 Output_data_plt_sparc<size, big_endian>::emit_pending_ifunc_relocs()
1557 // Emit any pending IFUNC relocs.
1558 for (typename std::vector<Global_ifunc>::const_iterator p =
1559 this->global_ifuncs_.begin();
1560 p != this->global_ifuncs_.end();
1563 section_offset_type plt_offset;
1566 index = this->count_ + p->plt_index + 4;
1567 plt_offset = this->plt_index_to_offset(index);
1568 p->rel->add_symbolless_global_addend(p->gsym, elfcpp::R_SPARC_JMP_IREL,
1569 this, plt_offset, 0);
1572 for (typename std::vector<Local_ifunc>::const_iterator p =
1573 this->local_ifuncs_.begin();
1574 p != this->local_ifuncs_.end();
1577 section_offset_type plt_offset;
1580 index = this->count_ + p->plt_index + 4;
1581 plt_offset = this->plt_index_to_offset(index);
1582 p->rel->add_symbolless_local_addend(p->object, p->local_sym_index,
1583 elfcpp::R_SPARC_JMP_IREL,
1584 this, plt_offset, 0);
1588 // Return where the IFUNC relocations should go in the PLT. These
1589 // follow the non-IFUNC relocations.
1591 template<int size, bool big_endian>
1592 typename Output_data_plt_sparc<size, big_endian>::Reloc_section*
1593 Output_data_plt_sparc<size, big_endian>::rela_ifunc(
1594 Symbol_table* symtab,
1597 if (this->ifunc_rel_ == NULL)
1599 this->ifunc_rel_ = new Reloc_section(false);
1600 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1601 elfcpp::SHF_ALLOC, this->ifunc_rel_,
1602 ORDER_DYNAMIC_PLT_RELOCS, false);
1603 gold_assert(this->ifunc_rel_->output_section()
1604 == this->rel_->output_section());
1606 if (parameters->doing_static_link())
1608 // A statically linked executable will only have a .rel.plt
1609 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1610 // relocs for STT_GNU_IFUNC symbols. The library will use
1611 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1612 // at program startup time.
1613 symtab->define_in_output_data("__rela_iplt_start", NULL,
1614 Symbol_table::PREDEFINED,
1615 this->ifunc_rel_, 0, 0,
1616 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1617 elfcpp::STV_HIDDEN, 0, false, true);
1618 symtab->define_in_output_data("__rela_iplt_end", NULL,
1619 Symbol_table::PREDEFINED,
1620 this->ifunc_rel_, 0, 0,
1621 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1622 elfcpp::STV_HIDDEN, 0, true, true);
1625 return this->ifunc_rel_;
1628 // Return the PLT address to use for a global symbol.
1630 template<int size, bool big_endian>
1632 Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
1634 uint64_t offset = 0;
1635 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1636 && gsym->can_use_relative_reloc(false))
1637 offset = plt_index_to_offset(this->count_ + 4);
1638 return this->address() + offset + gsym->plt_offset();
1641 // Return the PLT address to use for a local symbol. These are always
1642 // IRELATIVE relocs.
1644 template<int size, bool big_endian>
1646 Output_data_plt_sparc<size, big_endian>::address_for_local(
1647 const Relobj* object,
1650 return (this->address()
1651 + plt_index_to_offset(this->count_ + 4)
1652 + object->local_plt_offset(r_sym));
1655 static const unsigned int sparc_nop = 0x01000000;
1656 static const unsigned int sparc_sethi_g1 = 0x03000000;
1657 static const unsigned int sparc_branch_always = 0x30800000;
1658 static const unsigned int sparc_branch_always_pt = 0x30680000;
1659 static const unsigned int sparc_mov = 0x80100000;
1660 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1661 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1662 static const unsigned int sparc_call_plus_8 = 0x40000002;
1663 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1664 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1665 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1667 // Write out the PLT.
1669 template<int size, bool big_endian>
1671 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1673 const off_t offset = this->offset();
1674 const section_size_type oview_size =
1675 convert_to_section_size_type(this->data_size());
1676 unsigned char* const oview = of->get_output_view(offset, oview_size);
1677 unsigned char* pov = oview;
1679 memset(pov, 0, base_plt_entry_size * 4);
1680 pov += this->first_plt_entry_offset();
1682 unsigned int plt_offset = base_plt_entry_size * 4;
1683 const unsigned int count = this->entry_count();
1689 limit = (count > 32768 ? 32768 : count);
1691 for (unsigned int i = 0; i < limit; ++i)
1693 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1694 sparc_sethi_g1 + plt_offset);
1695 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1696 sparc_branch_always_pt +
1697 (((base_plt_entry_size -
1698 (plt_offset + 4)) >> 2) &
1700 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1701 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1702 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1703 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1704 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1705 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1707 pov += base_plt_entry_size;
1708 plt_offset += base_plt_entry_size;
1713 unsigned int ext_cnt = count - 32768;
1714 unsigned int blks = ext_cnt / plt_entries_per_block;
1716 for (unsigned int i = 0; i < blks; ++i)
1718 unsigned int data_off = (plt_entries_per_block
1719 * plt_insn_chunk_size) - 4;
1721 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1723 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1725 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1727 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1729 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1730 sparc_ldx_o7_imm_g1 +
1731 (data_off & 0x1fff));
1732 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1733 sparc_jmpl_o7_g1_g1);
1734 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1737 elfcpp::Swap<64, big_endian>::writeval(
1738 pov + 0x4 + data_off,
1739 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1741 pov += plt_insn_chunk_size;
1746 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1747 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1749 unsigned int data_off = (sub_blk_cnt
1750 * plt_insn_chunk_size) - 4;
1752 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1754 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1756 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1758 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1760 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1761 sparc_ldx_o7_imm_g1 +
1762 (data_off & 0x1fff));
1763 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1764 sparc_jmpl_o7_g1_g1);
1765 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1768 elfcpp::Swap<64, big_endian>::writeval(
1769 pov + 0x4 + data_off,
1770 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1772 pov += plt_insn_chunk_size;
1780 for (unsigned int i = 0; i < count; ++i)
1782 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1783 sparc_sethi_g1 + plt_offset);
1784 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1785 sparc_branch_always +
1786 (((- (plt_offset + 4)) >> 2) &
1788 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1790 pov += base_plt_entry_size;
1791 plt_offset += base_plt_entry_size;
1794 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1798 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1800 of->write_output_view(offset, oview_size, oview);
1803 // Create the PLT section.
1805 template<int size, bool big_endian>
1807 Target_sparc<size, big_endian>::make_plt_section(Symbol_table* symtab,
1810 // Create the GOT sections first.
1811 this->got_section(symtab, layout);
1813 // Ensure that .rela.dyn always appears before .rela.plt This is
1814 // necessary due to how, on Sparc and some other targets, .rela.dyn
1815 // needs to include .rela.plt in it's range.
1816 this->rela_dyn_section(layout);
1818 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1819 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1821 | elfcpp::SHF_EXECINSTR
1822 | elfcpp::SHF_WRITE),
1823 this->plt_, ORDER_NON_RELRO_FIRST, false);
1825 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1826 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1827 Symbol_table::PREDEFINED,
1829 0, 0, elfcpp::STT_OBJECT,
1831 elfcpp::STV_HIDDEN, 0,
1835 // Create a PLT entry for a global symbol.
1837 template<int size, bool big_endian>
1839 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1843 if (gsym->has_plt_offset())
1846 if (this->plt_ == NULL)
1847 this->make_plt_section(symtab, layout);
1849 this->plt_->add_entry(symtab, layout, gsym);
1852 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1854 template<int size, bool big_endian>
1856 Target_sparc<size, big_endian>::make_local_ifunc_plt_entry(
1857 Symbol_table* symtab,
1859 Sized_relobj_file<size, big_endian>* relobj,
1860 unsigned int local_sym_index)
1862 if (relobj->local_has_plt_offset(local_sym_index))
1864 if (this->plt_ == NULL)
1865 this->make_plt_section(symtab, layout);
1866 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1869 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1872 // Return the number of entries in the PLT.
1874 template<int size, bool big_endian>
1876 Target_sparc<size, big_endian>::plt_entry_count() const
1878 if (this->plt_ == NULL)
1880 return this->plt_->entry_count();
1883 // Return the offset of the first non-reserved PLT entry.
1885 template<int size, bool big_endian>
1887 Target_sparc<size, big_endian>::first_plt_entry_offset() const
1889 return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset();
1892 // Return the size of each PLT entry.
1894 template<int size, bool big_endian>
1896 Target_sparc<size, big_endian>::plt_entry_size() const
1898 return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size();
1901 // Create a GOT entry for the TLS module index.
1903 template<int size, bool big_endian>
1905 Target_sparc<size, big_endian>::got_mod_index_entry(
1906 Symbol_table* symtab,
1908 Sized_relobj_file<size, big_endian>* object)
1910 if (this->got_mod_index_offset_ == -1U)
1912 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1913 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1914 Output_data_got<size, big_endian>* got;
1915 unsigned int got_offset;
1917 got = this->got_section(symtab, layout);
1918 got_offset = got->add_constant(0);
1919 rela_dyn->add_local(object, 0,
1921 elfcpp::R_SPARC_TLS_DTPMOD64 :
1922 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1924 got->add_constant(0);
1925 this->got_mod_index_offset_ = got_offset;
1927 return this->got_mod_index_offset_;
1930 // Optimize the TLS relocation type based on what we know about the
1931 // symbol. IS_FINAL is true if the final address of this symbol is
1932 // known at link time.
1934 static tls::Tls_optimization
1935 optimize_tls_reloc(bool is_final, int r_type)
1937 // If we are generating a shared library, then we can't do anything
1939 if (parameters->options().shared())
1940 return tls::TLSOPT_NONE;
1944 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1945 case elfcpp::R_SPARC_TLS_GD_LO10:
1946 case elfcpp::R_SPARC_TLS_GD_ADD:
1947 case elfcpp::R_SPARC_TLS_GD_CALL:
1948 // These are General-Dynamic which permits fully general TLS
1949 // access. Since we know that we are generating an executable,
1950 // we can convert this to Initial-Exec. If we also know that
1951 // this is a local symbol, we can further switch to Local-Exec.
1953 return tls::TLSOPT_TO_LE;
1954 return tls::TLSOPT_TO_IE;
1956 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1957 case elfcpp::R_SPARC_TLS_LDM_LO10:
1958 case elfcpp::R_SPARC_TLS_LDM_ADD:
1959 case elfcpp::R_SPARC_TLS_LDM_CALL:
1960 // This is Local-Dynamic, which refers to a local symbol in the
1961 // dynamic TLS block. Since we know that we generating an
1962 // executable, we can switch to Local-Exec.
1963 return tls::TLSOPT_TO_LE;
1965 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1966 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1967 case elfcpp::R_SPARC_TLS_LDO_ADD:
1968 // Another type of Local-Dynamic relocation.
1969 return tls::TLSOPT_TO_LE;
1971 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1972 case elfcpp::R_SPARC_TLS_IE_LO10:
1973 case elfcpp::R_SPARC_TLS_IE_LD:
1974 case elfcpp::R_SPARC_TLS_IE_LDX:
1975 case elfcpp::R_SPARC_TLS_IE_ADD:
1976 // These are Initial-Exec relocs which get the thread offset
1977 // from the GOT. If we know that we are linking against the
1978 // local symbol, we can switch to Local-Exec, which links the
1979 // thread offset into the instruction.
1981 return tls::TLSOPT_TO_LE;
1982 return tls::TLSOPT_NONE;
1984 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1985 case elfcpp::R_SPARC_TLS_LE_LOX10:
1986 // When we already have Local-Exec, there is nothing further we
1988 return tls::TLSOPT_NONE;
1995 // Get the Reference_flags for a particular relocation.
1997 template<int size, bool big_endian>
1999 Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
2004 case elfcpp::R_SPARC_NONE:
2005 case elfcpp::R_SPARC_REGISTER:
2006 case elfcpp::R_SPARC_GNU_VTINHERIT:
2007 case elfcpp::R_SPARC_GNU_VTENTRY:
2008 // No symbol reference.
2011 case elfcpp::R_SPARC_UA64:
2012 case elfcpp::R_SPARC_64:
2013 case elfcpp::R_SPARC_HIX22:
2014 case elfcpp::R_SPARC_LOX10:
2015 case elfcpp::R_SPARC_H34:
2016 case elfcpp::R_SPARC_H44:
2017 case elfcpp::R_SPARC_M44:
2018 case elfcpp::R_SPARC_L44:
2019 case elfcpp::R_SPARC_HH22:
2020 case elfcpp::R_SPARC_HM10:
2021 case elfcpp::R_SPARC_LM22:
2022 case elfcpp::R_SPARC_HI22:
2023 case elfcpp::R_SPARC_LO10:
2024 case elfcpp::R_SPARC_OLO10:
2025 case elfcpp::R_SPARC_UA32:
2026 case elfcpp::R_SPARC_32:
2027 case elfcpp::R_SPARC_UA16:
2028 case elfcpp::R_SPARC_16:
2029 case elfcpp::R_SPARC_11:
2030 case elfcpp::R_SPARC_10:
2031 case elfcpp::R_SPARC_8:
2032 case elfcpp::R_SPARC_7:
2033 case elfcpp::R_SPARC_6:
2034 case elfcpp::R_SPARC_5:
2035 return Symbol::ABSOLUTE_REF;
2037 case elfcpp::R_SPARC_DISP8:
2038 case elfcpp::R_SPARC_DISP16:
2039 case elfcpp::R_SPARC_DISP32:
2040 case elfcpp::R_SPARC_DISP64:
2041 case elfcpp::R_SPARC_PC_HH22:
2042 case elfcpp::R_SPARC_PC_HM10:
2043 case elfcpp::R_SPARC_PC_LM22:
2044 case elfcpp::R_SPARC_PC10:
2045 case elfcpp::R_SPARC_PC22:
2046 case elfcpp::R_SPARC_WDISP30:
2047 case elfcpp::R_SPARC_WDISP22:
2048 case elfcpp::R_SPARC_WDISP19:
2049 case elfcpp::R_SPARC_WDISP16:
2050 case elfcpp::R_SPARC_WDISP10:
2051 return Symbol::RELATIVE_REF;
2053 case elfcpp::R_SPARC_PLT64:
2054 case elfcpp::R_SPARC_PLT32:
2055 case elfcpp::R_SPARC_HIPLT22:
2056 case elfcpp::R_SPARC_LOPLT10:
2057 case elfcpp::R_SPARC_PCPLT10:
2058 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
2060 case elfcpp::R_SPARC_PCPLT32:
2061 case elfcpp::R_SPARC_PCPLT22:
2062 case elfcpp::R_SPARC_WPLT30:
2063 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2065 case elfcpp::R_SPARC_GOTDATA_OP:
2066 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2067 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2068 case elfcpp::R_SPARC_GOT10:
2069 case elfcpp::R_SPARC_GOT13:
2070 case elfcpp::R_SPARC_GOT22:
2072 return Symbol::ABSOLUTE_REF;
2074 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2075 case elfcpp::R_SPARC_TLS_GD_LO10:
2076 case elfcpp::R_SPARC_TLS_GD_ADD:
2077 case elfcpp::R_SPARC_TLS_GD_CALL:
2078 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2079 case elfcpp::R_SPARC_TLS_LDM_LO10:
2080 case elfcpp::R_SPARC_TLS_LDM_ADD:
2081 case elfcpp::R_SPARC_TLS_LDM_CALL:
2082 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2083 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2084 case elfcpp::R_SPARC_TLS_LDO_ADD:
2085 case elfcpp::R_SPARC_TLS_LE_HIX22:
2086 case elfcpp::R_SPARC_TLS_LE_LOX10:
2087 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2088 case elfcpp::R_SPARC_TLS_IE_LO10:
2089 case elfcpp::R_SPARC_TLS_IE_LD:
2090 case elfcpp::R_SPARC_TLS_IE_LDX:
2091 case elfcpp::R_SPARC_TLS_IE_ADD:
2092 return Symbol::TLS_REF;
2094 case elfcpp::R_SPARC_COPY:
2095 case elfcpp::R_SPARC_GLOB_DAT:
2096 case elfcpp::R_SPARC_JMP_SLOT:
2097 case elfcpp::R_SPARC_JMP_IREL:
2098 case elfcpp::R_SPARC_RELATIVE:
2099 case elfcpp::R_SPARC_IRELATIVE:
2100 case elfcpp::R_SPARC_TLS_DTPMOD64:
2101 case elfcpp::R_SPARC_TLS_DTPMOD32:
2102 case elfcpp::R_SPARC_TLS_DTPOFF64:
2103 case elfcpp::R_SPARC_TLS_DTPOFF32:
2104 case elfcpp::R_SPARC_TLS_TPOFF64:
2105 case elfcpp::R_SPARC_TLS_TPOFF32:
2107 // Not expected. We will give an error later.
2112 // Generate a PLT entry slot for a call to __tls_get_addr
2113 template<int size, bool big_endian>
2115 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
2117 Target_sparc<size, big_endian>* target)
2119 Symbol* gsym = target->tls_get_addr_sym(symtab);
2121 target->make_plt_entry(symtab, layout, gsym);
2124 // Report an unsupported relocation against a local symbol.
2126 template<int size, bool big_endian>
2128 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
2129 Sized_relobj_file<size, big_endian>* object,
2130 unsigned int r_type)
2132 gold_error(_("%s: unsupported reloc %u against local symbol"),
2133 object->name().c_str(), r_type);
2136 // We are about to emit a dynamic relocation of type R_TYPE. If the
2137 // dynamic linker does not support it, issue an error.
2139 template<int size, bool big_endian>
2141 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2143 gold_assert(r_type != elfcpp::R_SPARC_NONE);
2149 // These are the relocation types supported by glibc for sparc 64-bit.
2150 case elfcpp::R_SPARC_RELATIVE:
2151 case elfcpp::R_SPARC_IRELATIVE:
2152 case elfcpp::R_SPARC_COPY:
2153 case elfcpp::R_SPARC_64:
2154 case elfcpp::R_SPARC_GLOB_DAT:
2155 case elfcpp::R_SPARC_JMP_SLOT:
2156 case elfcpp::R_SPARC_JMP_IREL:
2157 case elfcpp::R_SPARC_TLS_DTPMOD64:
2158 case elfcpp::R_SPARC_TLS_DTPOFF64:
2159 case elfcpp::R_SPARC_TLS_TPOFF64:
2160 case elfcpp::R_SPARC_TLS_LE_HIX22:
2161 case elfcpp::R_SPARC_TLS_LE_LOX10:
2162 case elfcpp::R_SPARC_8:
2163 case elfcpp::R_SPARC_16:
2164 case elfcpp::R_SPARC_DISP8:
2165 case elfcpp::R_SPARC_DISP16:
2166 case elfcpp::R_SPARC_DISP32:
2167 case elfcpp::R_SPARC_WDISP30:
2168 case elfcpp::R_SPARC_LO10:
2169 case elfcpp::R_SPARC_HI22:
2170 case elfcpp::R_SPARC_OLO10:
2171 case elfcpp::R_SPARC_H34:
2172 case elfcpp::R_SPARC_H44:
2173 case elfcpp::R_SPARC_M44:
2174 case elfcpp::R_SPARC_L44:
2175 case elfcpp::R_SPARC_HH22:
2176 case elfcpp::R_SPARC_HM10:
2177 case elfcpp::R_SPARC_LM22:
2178 case elfcpp::R_SPARC_UA16:
2179 case elfcpp::R_SPARC_UA32:
2180 case elfcpp::R_SPARC_UA64:
2191 // These are the relocation types supported by glibc for sparc 32-bit.
2192 case elfcpp::R_SPARC_RELATIVE:
2193 case elfcpp::R_SPARC_IRELATIVE:
2194 case elfcpp::R_SPARC_COPY:
2195 case elfcpp::R_SPARC_GLOB_DAT:
2196 case elfcpp::R_SPARC_32:
2197 case elfcpp::R_SPARC_JMP_SLOT:
2198 case elfcpp::R_SPARC_JMP_IREL:
2199 case elfcpp::R_SPARC_TLS_DTPMOD32:
2200 case elfcpp::R_SPARC_TLS_DTPOFF32:
2201 case elfcpp::R_SPARC_TLS_TPOFF32:
2202 case elfcpp::R_SPARC_TLS_LE_HIX22:
2203 case elfcpp::R_SPARC_TLS_LE_LOX10:
2204 case elfcpp::R_SPARC_8:
2205 case elfcpp::R_SPARC_16:
2206 case elfcpp::R_SPARC_DISP8:
2207 case elfcpp::R_SPARC_DISP16:
2208 case elfcpp::R_SPARC_DISP32:
2209 case elfcpp::R_SPARC_LO10:
2210 case elfcpp::R_SPARC_WDISP30:
2211 case elfcpp::R_SPARC_HI22:
2212 case elfcpp::R_SPARC_UA16:
2213 case elfcpp::R_SPARC_UA32:
2221 // This prevents us from issuing more than one error per reloc
2222 // section. But we can still wind up issuing more than one
2223 // error per object file.
2224 if (this->issued_non_pic_error_)
2226 gold_assert(parameters->options().output_is_position_independent());
2227 object->error(_("requires unsupported dynamic reloc; "
2228 "recompile with -fPIC"));
2229 this->issued_non_pic_error_ = true;
2233 // Return whether we need to make a PLT entry for a relocation of the
2234 // given type against a STT_GNU_IFUNC symbol.
2236 template<int size, bool big_endian>
2238 Target_sparc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
2239 Sized_relobj_file<size, big_endian>* object,
2240 unsigned int r_type)
2242 int flags = Scan::get_reference_flags(r_type);
2243 if (flags & Symbol::TLS_REF)
2244 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2245 object->name().c_str(), r_type);
2249 // Scan a relocation for a local symbol.
2251 template<int size, bool big_endian>
2253 Target_sparc<size, big_endian>::Scan::local(
2254 Symbol_table* symtab,
2256 Target_sparc<size, big_endian>* target,
2257 Sized_relobj_file<size, big_endian>* object,
2258 unsigned int data_shndx,
2259 Output_section* output_section,
2260 const elfcpp::Rela<size, big_endian>& reloc,
2261 unsigned int r_type,
2262 const elfcpp::Sym<size, big_endian>& lsym,
2268 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2269 unsigned int orig_r_type = r_type;
2273 && this->reloc_needs_plt_for_ifunc(object, r_type))
2275 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2276 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2281 case elfcpp::R_SPARC_NONE:
2282 case elfcpp::R_SPARC_REGISTER:
2283 case elfcpp::R_SPARC_GNU_VTINHERIT:
2284 case elfcpp::R_SPARC_GNU_VTENTRY:
2287 case elfcpp::R_SPARC_64:
2288 case elfcpp::R_SPARC_32:
2289 // If building a shared library (or a position-independent
2290 // executable), we need to create a dynamic relocation for
2291 // this location. The relocation applied at link time will
2292 // apply the link-time value, so we flag the location with
2293 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2294 // relocate it easily.
2295 if (parameters->options().output_is_position_independent())
2297 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2298 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2299 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
2300 output_section, data_shndx,
2301 reloc.get_r_offset(),
2302 reloc.get_r_addend(), is_ifunc);
2306 case elfcpp::R_SPARC_HIX22:
2307 case elfcpp::R_SPARC_LOX10:
2308 case elfcpp::R_SPARC_H34:
2309 case elfcpp::R_SPARC_H44:
2310 case elfcpp::R_SPARC_M44:
2311 case elfcpp::R_SPARC_L44:
2312 case elfcpp::R_SPARC_HH22:
2313 case elfcpp::R_SPARC_HM10:
2314 case elfcpp::R_SPARC_LM22:
2315 case elfcpp::R_SPARC_UA64:
2316 case elfcpp::R_SPARC_UA32:
2317 case elfcpp::R_SPARC_UA16:
2318 case elfcpp::R_SPARC_HI22:
2319 case elfcpp::R_SPARC_LO10:
2320 case elfcpp::R_SPARC_OLO10:
2321 case elfcpp::R_SPARC_16:
2322 case elfcpp::R_SPARC_11:
2323 case elfcpp::R_SPARC_10:
2324 case elfcpp::R_SPARC_8:
2325 case elfcpp::R_SPARC_7:
2326 case elfcpp::R_SPARC_6:
2327 case elfcpp::R_SPARC_5:
2328 // If building a shared library (or a position-independent
2329 // executable), we need to create a dynamic relocation for
2331 if (parameters->options().output_is_position_independent())
2333 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2334 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2336 check_non_pic(object, r_type);
2337 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2339 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
2340 data_shndx, reloc.get_r_offset(),
2341 reloc.get_r_addend());
2345 gold_assert(lsym.get_st_value() == 0);
2346 rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
2347 output_section, data_shndx,
2348 reloc.get_r_offset(),
2349 reloc.get_r_addend());
2354 case elfcpp::R_SPARC_WDISP30:
2355 case elfcpp::R_SPARC_WPLT30:
2356 case elfcpp::R_SPARC_WDISP22:
2357 case elfcpp::R_SPARC_WDISP19:
2358 case elfcpp::R_SPARC_WDISP16:
2359 case elfcpp::R_SPARC_WDISP10:
2360 case elfcpp::R_SPARC_DISP8:
2361 case elfcpp::R_SPARC_DISP16:
2362 case elfcpp::R_SPARC_DISP32:
2363 case elfcpp::R_SPARC_DISP64:
2364 case elfcpp::R_SPARC_PC10:
2365 case elfcpp::R_SPARC_PC22:
2368 case elfcpp::R_SPARC_GOTDATA_OP:
2369 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2370 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2371 // We will optimize this into a GOT relative relocation
2372 // and code transform the GOT load into an addition.
2375 case elfcpp::R_SPARC_GOT10:
2376 case elfcpp::R_SPARC_GOT13:
2377 case elfcpp::R_SPARC_GOT22:
2379 // The symbol requires a GOT entry.
2380 Output_data_got<size, big_endian>* got;
2383 got = target->got_section(symtab, layout);
2384 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2386 // If we are generating a shared object, we need to add a
2387 // dynamic relocation for this symbol's GOT entry.
2388 if (parameters->options().output_is_position_independent())
2390 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
2392 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2393 unsigned int off = got->add_constant(0);
2394 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
2395 rela_dyn->add_local_relative(object, r_sym,
2396 elfcpp::R_SPARC_RELATIVE,
2397 got, off, 0, is_ifunc);
2401 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2405 // These are initial TLS relocs, which are expected when
2407 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2408 case elfcpp::R_SPARC_TLS_GD_LO10:
2409 case elfcpp::R_SPARC_TLS_GD_ADD:
2410 case elfcpp::R_SPARC_TLS_GD_CALL:
2411 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2412 case elfcpp::R_SPARC_TLS_LDM_LO10:
2413 case elfcpp::R_SPARC_TLS_LDM_ADD:
2414 case elfcpp::R_SPARC_TLS_LDM_CALL:
2415 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2416 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2417 case elfcpp::R_SPARC_TLS_LDO_ADD:
2418 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2419 case elfcpp::R_SPARC_TLS_IE_LO10:
2420 case elfcpp::R_SPARC_TLS_IE_LD:
2421 case elfcpp::R_SPARC_TLS_IE_LDX:
2422 case elfcpp::R_SPARC_TLS_IE_ADD:
2423 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2424 case elfcpp::R_SPARC_TLS_LE_LOX10:
2426 bool output_is_shared = parameters->options().shared();
2427 const tls::Tls_optimization optimized_type
2428 = optimize_tls_reloc(!output_is_shared, r_type);
2431 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2432 case elfcpp::R_SPARC_TLS_GD_LO10:
2433 case elfcpp::R_SPARC_TLS_GD_ADD:
2434 case elfcpp::R_SPARC_TLS_GD_CALL:
2435 if (optimized_type == tls::TLSOPT_NONE)
2437 // Create a pair of GOT entries for the module index and
2438 // dtv-relative offset.
2439 Output_data_got<size, big_endian>* got
2440 = target->got_section(symtab, layout);
2441 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2442 unsigned int shndx = lsym.get_st_shndx();
2444 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2446 object->error(_("local symbol %u has bad shndx %u"),
2449 got->add_local_pair_with_rel(object, r_sym,
2450 lsym.get_st_shndx(),
2452 target->rela_dyn_section(layout),
2454 ? elfcpp::R_SPARC_TLS_DTPMOD64
2455 : elfcpp::R_SPARC_TLS_DTPMOD32));
2456 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2457 generate_tls_call(symtab, layout, target);
2459 else if (optimized_type != tls::TLSOPT_TO_LE)
2460 unsupported_reloc_local(object, r_type);
2463 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2464 case elfcpp::R_SPARC_TLS_LDM_LO10:
2465 case elfcpp::R_SPARC_TLS_LDM_ADD:
2466 case elfcpp::R_SPARC_TLS_LDM_CALL:
2467 if (optimized_type == tls::TLSOPT_NONE)
2469 // Create a GOT entry for the module index.
2470 target->got_mod_index_entry(symtab, layout, object);
2472 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2473 generate_tls_call(symtab, layout, target);
2475 else if (optimized_type != tls::TLSOPT_TO_LE)
2476 unsupported_reloc_local(object, r_type);
2479 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2480 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2481 case elfcpp::R_SPARC_TLS_LDO_ADD:
2484 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2485 case elfcpp::R_SPARC_TLS_IE_LO10:
2486 case elfcpp::R_SPARC_TLS_IE_LD:
2487 case elfcpp::R_SPARC_TLS_IE_LDX:
2488 case elfcpp::R_SPARC_TLS_IE_ADD:
2489 layout->set_has_static_tls();
2490 if (optimized_type == tls::TLSOPT_NONE)
2492 // Create a GOT entry for the tp-relative offset.
2493 Output_data_got<size, big_endian>* got
2494 = target->got_section(symtab, layout);
2495 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2497 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
2499 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2500 unsigned int off = got->add_constant(0);
2502 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
2504 rela_dyn->add_symbolless_local_addend(object, r_sym,
2506 elfcpp::R_SPARC_TLS_TPOFF64 :
2507 elfcpp::R_SPARC_TLS_TPOFF32),
2511 else if (optimized_type != tls::TLSOPT_TO_LE)
2512 unsupported_reloc_local(object, r_type);
2515 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2516 case elfcpp::R_SPARC_TLS_LE_LOX10:
2517 layout->set_has_static_tls();
2518 if (output_is_shared)
2520 // We need to create a dynamic relocation.
2521 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2522 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2523 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2524 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
2525 output_section, data_shndx,
2526 reloc.get_r_offset(), 0);
2533 // These are relocations which should only be seen by the
2534 // dynamic linker, and should never be seen here.
2535 case elfcpp::R_SPARC_COPY:
2536 case elfcpp::R_SPARC_GLOB_DAT:
2537 case elfcpp::R_SPARC_JMP_SLOT:
2538 case elfcpp::R_SPARC_JMP_IREL:
2539 case elfcpp::R_SPARC_RELATIVE:
2540 case elfcpp::R_SPARC_IRELATIVE:
2541 case elfcpp::R_SPARC_TLS_DTPMOD64:
2542 case elfcpp::R_SPARC_TLS_DTPMOD32:
2543 case elfcpp::R_SPARC_TLS_DTPOFF64:
2544 case elfcpp::R_SPARC_TLS_DTPOFF32:
2545 case elfcpp::R_SPARC_TLS_TPOFF64:
2546 case elfcpp::R_SPARC_TLS_TPOFF32:
2547 gold_error(_("%s: unexpected reloc %u in object file"),
2548 object->name().c_str(), r_type);
2552 unsupported_reloc_local(object, r_type);
2557 // Report an unsupported relocation against a global symbol.
2559 template<int size, bool big_endian>
2561 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
2562 Sized_relobj_file<size, big_endian>* object,
2563 unsigned int r_type,
2566 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2567 object->name().c_str(), r_type, gsym->demangled_name().c_str());
2570 // Scan a relocation for a global symbol.
2572 template<int size, bool big_endian>
2574 Target_sparc<size, big_endian>::Scan::global(
2575 Symbol_table* symtab,
2577 Target_sparc<size, big_endian>* target,
2578 Sized_relobj_file<size, big_endian>* object,
2579 unsigned int data_shndx,
2580 Output_section* output_section,
2581 const elfcpp::Rela<size, big_endian>& reloc,
2582 unsigned int r_type,
2585 unsigned int orig_r_type = r_type;
2586 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2588 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2589 // section. We check here to avoid creating a dynamic reloc against
2590 // _GLOBAL_OFFSET_TABLE_.
2591 if (!target->has_got_section()
2592 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2593 target->got_section(symtab, layout);
2597 // A STT_GNU_IFUNC symbol may require a PLT entry.
2599 && this->reloc_needs_plt_for_ifunc(object, r_type))
2600 target->make_plt_entry(symtab, layout, gsym);
2604 case elfcpp::R_SPARC_NONE:
2605 case elfcpp::R_SPARC_REGISTER:
2606 case elfcpp::R_SPARC_GNU_VTINHERIT:
2607 case elfcpp::R_SPARC_GNU_VTENTRY:
2610 case elfcpp::R_SPARC_PLT64:
2611 case elfcpp::R_SPARC_PLT32:
2612 case elfcpp::R_SPARC_HIPLT22:
2613 case elfcpp::R_SPARC_LOPLT10:
2614 case elfcpp::R_SPARC_PCPLT32:
2615 case elfcpp::R_SPARC_PCPLT22:
2616 case elfcpp::R_SPARC_PCPLT10:
2617 case elfcpp::R_SPARC_WPLT30:
2618 // If the symbol is fully resolved, this is just a PC32 reloc.
2619 // Otherwise we need a PLT entry.
2620 if (gsym->final_value_is_known())
2622 // If building a shared library, we can also skip the PLT entry
2623 // if the symbol is defined in the output file and is protected
2625 if (gsym->is_defined()
2626 && !gsym->is_from_dynobj()
2627 && !gsym->is_preemptible())
2629 target->make_plt_entry(symtab, layout, gsym);
2632 case elfcpp::R_SPARC_DISP8:
2633 case elfcpp::R_SPARC_DISP16:
2634 case elfcpp::R_SPARC_DISP32:
2635 case elfcpp::R_SPARC_DISP64:
2636 case elfcpp::R_SPARC_PC_HH22:
2637 case elfcpp::R_SPARC_PC_HM10:
2638 case elfcpp::R_SPARC_PC_LM22:
2639 case elfcpp::R_SPARC_PC10:
2640 case elfcpp::R_SPARC_PC22:
2641 case elfcpp::R_SPARC_WDISP30:
2642 case elfcpp::R_SPARC_WDISP22:
2643 case elfcpp::R_SPARC_WDISP19:
2644 case elfcpp::R_SPARC_WDISP16:
2645 case elfcpp::R_SPARC_WDISP10:
2647 if (gsym->needs_plt_entry())
2648 target->make_plt_entry(symtab, layout, gsym);
2649 // Make a dynamic relocation if necessary.
2650 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2652 if (parameters->options().output_is_executable()
2653 && gsym->may_need_copy_reloc())
2655 target->copy_reloc(symtab, layout, object,
2656 data_shndx, output_section, gsym,
2661 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2662 check_non_pic(object, r_type);
2663 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
2664 data_shndx, reloc.get_r_offset(),
2665 reloc.get_r_addend());
2671 case elfcpp::R_SPARC_UA64:
2672 case elfcpp::R_SPARC_64:
2673 case elfcpp::R_SPARC_HIX22:
2674 case elfcpp::R_SPARC_LOX10:
2675 case elfcpp::R_SPARC_H34:
2676 case elfcpp::R_SPARC_H44:
2677 case elfcpp::R_SPARC_M44:
2678 case elfcpp::R_SPARC_L44:
2679 case elfcpp::R_SPARC_HH22:
2680 case elfcpp::R_SPARC_HM10:
2681 case elfcpp::R_SPARC_LM22:
2682 case elfcpp::R_SPARC_HI22:
2683 case elfcpp::R_SPARC_LO10:
2684 case elfcpp::R_SPARC_OLO10:
2685 case elfcpp::R_SPARC_UA32:
2686 case elfcpp::R_SPARC_32:
2687 case elfcpp::R_SPARC_UA16:
2688 case elfcpp::R_SPARC_16:
2689 case elfcpp::R_SPARC_11:
2690 case elfcpp::R_SPARC_10:
2691 case elfcpp::R_SPARC_8:
2692 case elfcpp::R_SPARC_7:
2693 case elfcpp::R_SPARC_6:
2694 case elfcpp::R_SPARC_5:
2696 // Make a PLT entry if necessary.
2697 if (gsym->needs_plt_entry())
2699 target->make_plt_entry(symtab, layout, gsym);
2700 // Since this is not a PC-relative relocation, we may be
2701 // taking the address of a function. In that case we need to
2702 // set the entry in the dynamic symbol table to the address of
2704 if (gsym->is_from_dynobj() && !parameters->options().shared())
2705 gsym->set_needs_dynsym_value();
2707 // Make a dynamic relocation if necessary.
2708 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2710 unsigned int r_off = reloc.get_r_offset();
2712 // The assembler can sometimes emit unaligned relocations
2713 // for dwarf2 cfi directives.
2716 case elfcpp::R_SPARC_16:
2718 orig_r_type = r_type = elfcpp::R_SPARC_UA16;
2720 case elfcpp::R_SPARC_32:
2722 orig_r_type = r_type = elfcpp::R_SPARC_UA32;
2724 case elfcpp::R_SPARC_64:
2726 orig_r_type = r_type = elfcpp::R_SPARC_UA64;
2728 case elfcpp::R_SPARC_UA16:
2730 orig_r_type = r_type = elfcpp::R_SPARC_16;
2732 case elfcpp::R_SPARC_UA32:
2734 orig_r_type = r_type = elfcpp::R_SPARC_32;
2736 case elfcpp::R_SPARC_UA64:
2738 orig_r_type = r_type = elfcpp::R_SPARC_64;
2742 if (!parameters->options().output_is_position_independent()
2743 && gsym->may_need_copy_reloc())
2745 target->copy_reloc(symtab, layout, object,
2746 data_shndx, output_section, gsym, reloc);
2748 else if (((size == 64 && r_type == elfcpp::R_SPARC_64)
2749 || (size == 32 && r_type == elfcpp::R_SPARC_32))
2750 && gsym->type() == elfcpp::STT_GNU_IFUNC
2751 && gsym->can_use_relative_reloc(false)
2752 && !gsym->is_from_dynobj()
2753 && !gsym->is_undefined()
2754 && !gsym->is_preemptible())
2756 // Use an IRELATIVE reloc for a locally defined
2757 // STT_GNU_IFUNC symbol. This makes a function
2758 // address in a PIE executable match the address in a
2759 // shared library that it links against.
2760 Reloc_section* rela_dyn =
2761 target->rela_ifunc_section(layout);
2762 unsigned int r_type = elfcpp::R_SPARC_IRELATIVE;
2763 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2764 output_section, object,
2766 reloc.get_r_offset(),
2767 reloc.get_r_addend());
2769 else if ((r_type == elfcpp::R_SPARC_32
2770 || r_type == elfcpp::R_SPARC_64)
2771 && gsym->can_use_relative_reloc(false))
2773 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2774 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2775 output_section, object,
2776 data_shndx, reloc.get_r_offset(),
2777 reloc.get_r_addend(), is_ifunc);
2781 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2783 check_non_pic(object, r_type);
2784 if (gsym->is_from_dynobj()
2785 || gsym->is_undefined()
2786 || gsym->is_preemptible())
2787 rela_dyn->add_global(gsym, orig_r_type, output_section,
2789 reloc.get_r_offset(),
2790 reloc.get_r_addend());
2792 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2795 reloc.get_r_offset(),
2796 reloc.get_r_addend());
2802 case elfcpp::R_SPARC_GOTDATA_OP:
2803 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2804 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2805 if (gsym->is_defined()
2806 && !gsym->is_from_dynobj()
2807 && !gsym->is_preemptible()
2810 // We will optimize this into a GOT relative relocation
2811 // and code transform the GOT load into an addition.
2814 case elfcpp::R_SPARC_GOT10:
2815 case elfcpp::R_SPARC_GOT13:
2816 case elfcpp::R_SPARC_GOT22:
2818 // The symbol requires a GOT entry.
2819 Output_data_got<size, big_endian>* got;
2821 got = target->got_section(symtab, layout);
2822 if (gsym->final_value_is_known())
2824 // For a STT_GNU_IFUNC symbol we want the PLT address.
2825 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2826 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2828 got->add_global(gsym, GOT_TYPE_STANDARD);
2832 // If this symbol is not fully resolved, we need to add a
2833 // GOT entry with a dynamic relocation.
2834 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2836 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2838 // 1) The symbol may be defined in some other module.
2840 // 2) We are building a shared library and this is a
2841 // protected symbol; using GLOB_DAT means that the dynamic
2842 // linker can use the address of the PLT in the main
2843 // executable when appropriate so that function address
2844 // comparisons work.
2846 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2847 // code, again so that function address comparisons work.
2848 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2849 if (gsym->is_from_dynobj()
2850 || gsym->is_undefined()
2851 || gsym->is_preemptible()
2852 || (gsym->visibility() == elfcpp::STV_PROTECTED
2853 && parameters->options().shared())
2854 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2855 && parameters->options().output_is_position_independent()
2856 && !gsym->is_forced_local()))
2858 unsigned int r_type = elfcpp::R_SPARC_GLOB_DAT;
2860 // If this symbol is forced local, this relocation will
2861 // not work properly. That's because ld.so on sparc
2862 // (and 32-bit powerpc) expects st_value in the r_addend
2863 // of relocations for STB_LOCAL symbols. Curiously the
2864 // BFD linker does not promote global hidden symbols to be
2865 // STB_LOCAL in the dynamic symbol table like Gold does.
2866 gold_assert(!gsym->is_forced_local());
2867 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2870 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2872 unsigned int off = got->add_constant(0);
2874 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2877 // Tell the dynamic linker to use the PLT address
2878 // when resolving relocations.
2879 if (gsym->is_from_dynobj()
2880 && !parameters->options().shared())
2881 gsym->set_needs_dynsym_value();
2883 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2884 got, off, 0, is_ifunc);
2890 // These are initial tls relocs, which are expected when
2892 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2893 case elfcpp::R_SPARC_TLS_GD_LO10:
2894 case elfcpp::R_SPARC_TLS_GD_ADD:
2895 case elfcpp::R_SPARC_TLS_GD_CALL:
2896 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2897 case elfcpp::R_SPARC_TLS_LDM_LO10:
2898 case elfcpp::R_SPARC_TLS_LDM_ADD:
2899 case elfcpp::R_SPARC_TLS_LDM_CALL:
2900 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2901 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2902 case elfcpp::R_SPARC_TLS_LDO_ADD:
2903 case elfcpp::R_SPARC_TLS_LE_HIX22:
2904 case elfcpp::R_SPARC_TLS_LE_LOX10:
2905 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2906 case elfcpp::R_SPARC_TLS_IE_LO10:
2907 case elfcpp::R_SPARC_TLS_IE_LD:
2908 case elfcpp::R_SPARC_TLS_IE_LDX:
2909 case elfcpp::R_SPARC_TLS_IE_ADD:
2911 const bool is_final = gsym->final_value_is_known();
2912 const tls::Tls_optimization optimized_type
2913 = optimize_tls_reloc(is_final, r_type);
2916 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2917 case elfcpp::R_SPARC_TLS_GD_LO10:
2918 case elfcpp::R_SPARC_TLS_GD_ADD:
2919 case elfcpp::R_SPARC_TLS_GD_CALL:
2920 if (optimized_type == tls::TLSOPT_NONE)
2922 // Create a pair of GOT entries for the module index and
2923 // dtv-relative offset.
2924 Output_data_got<size, big_endian>* got
2925 = target->got_section(symtab, layout);
2926 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2927 target->rela_dyn_section(layout),
2929 ? elfcpp::R_SPARC_TLS_DTPMOD64
2930 : elfcpp::R_SPARC_TLS_DTPMOD32),
2932 ? elfcpp::R_SPARC_TLS_DTPOFF64
2933 : elfcpp::R_SPARC_TLS_DTPOFF32));
2935 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2936 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2937 generate_tls_call(symtab, layout, target);
2939 else if (optimized_type == tls::TLSOPT_TO_IE)
2941 // Create a GOT entry for the tp-relative offset.
2942 Output_data_got<size, big_endian>* got
2943 = target->got_section(symtab, layout);
2944 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2945 target->rela_dyn_section(layout),
2947 elfcpp::R_SPARC_TLS_TPOFF64 :
2948 elfcpp::R_SPARC_TLS_TPOFF32));
2950 else if (optimized_type != tls::TLSOPT_TO_LE)
2951 unsupported_reloc_global(object, r_type, gsym);
2954 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2955 case elfcpp::R_SPARC_TLS_LDM_LO10:
2956 case elfcpp::R_SPARC_TLS_LDM_ADD:
2957 case elfcpp::R_SPARC_TLS_LDM_CALL:
2958 if (optimized_type == tls::TLSOPT_NONE)
2960 // Create a GOT entry for the module index.
2961 target->got_mod_index_entry(symtab, layout, object);
2963 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2964 generate_tls_call(symtab, layout, target);
2966 else if (optimized_type != tls::TLSOPT_TO_LE)
2967 unsupported_reloc_global(object, r_type, gsym);
2970 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2971 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2972 case elfcpp::R_SPARC_TLS_LDO_ADD:
2975 case elfcpp::R_SPARC_TLS_LE_HIX22:
2976 case elfcpp::R_SPARC_TLS_LE_LOX10:
2977 layout->set_has_static_tls();
2978 if (parameters->options().shared())
2980 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2981 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2982 output_section, object,
2983 data_shndx, reloc.get_r_offset(),
2988 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2989 case elfcpp::R_SPARC_TLS_IE_LO10:
2990 case elfcpp::R_SPARC_TLS_IE_LD:
2991 case elfcpp::R_SPARC_TLS_IE_LDX:
2992 case elfcpp::R_SPARC_TLS_IE_ADD:
2993 layout->set_has_static_tls();
2994 if (optimized_type == tls::TLSOPT_NONE)
2996 // Create a GOT entry for the tp-relative offset.
2997 Output_data_got<size, big_endian>* got
2998 = target->got_section(symtab, layout);
2999 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
3000 target->rela_dyn_section(layout),
3002 ? elfcpp::R_SPARC_TLS_TPOFF64
3003 : elfcpp::R_SPARC_TLS_TPOFF32));
3005 else if (optimized_type != tls::TLSOPT_TO_LE)
3006 unsupported_reloc_global(object, r_type, gsym);
3012 // These are relocations which should only be seen by the
3013 // dynamic linker, and should never be seen here.
3014 case elfcpp::R_SPARC_COPY:
3015 case elfcpp::R_SPARC_GLOB_DAT:
3016 case elfcpp::R_SPARC_JMP_SLOT:
3017 case elfcpp::R_SPARC_JMP_IREL:
3018 case elfcpp::R_SPARC_RELATIVE:
3019 case elfcpp::R_SPARC_IRELATIVE:
3020 case elfcpp::R_SPARC_TLS_DTPMOD64:
3021 case elfcpp::R_SPARC_TLS_DTPMOD32:
3022 case elfcpp::R_SPARC_TLS_DTPOFF64:
3023 case elfcpp::R_SPARC_TLS_DTPOFF32:
3024 case elfcpp::R_SPARC_TLS_TPOFF64:
3025 case elfcpp::R_SPARC_TLS_TPOFF32:
3026 gold_error(_("%s: unexpected reloc %u in object file"),
3027 object->name().c_str(), r_type);
3031 unsupported_reloc_global(object, r_type, gsym);
3036 // Make a new symbol table entry.
3037 // STT_SPARC_REGISTER symbols require special handling,
3038 // so we intercept these symbols and keep track of them separately.
3039 // We will resolve register symbols here and output them at symbol
3040 // finalization time.
3042 template<int size, bool big_endian>
3044 Target_sparc<size, big_endian>::make_symbol(const char* name,
3050 // REGISTER symbols are used only on SPARC-64.
3051 if (size == 64 && type == elfcpp::STT_SPARC_REGISTER)
3053 // Ignore REGISTER symbols in dynamic objects.
3054 if (object->is_dynamic())
3056 // Only registers 2, 3, 6, and 7 can be declared global.
3067 gold_error(_("%s: only registers %%g[2367] can be declared "
3068 "using STT_REGISTER"),
3069 object->name().c_str());
3072 Register_symbol& rsym = this->register_syms_[reg];
3073 if (rsym.name == NULL)
3081 if (strcmp(rsym.name, name) != 0)
3083 gold_error(_("%s: register %%g%d declared as '%s'; "
3084 "previously declared as '%s' in %s"),
3085 object->name().c_str(),
3086 static_cast<int>(value),
3087 *name ? name : "#scratch",
3088 *rsym.name ? rsym.name : "#scratch",
3089 rsym.obj->name().c_str());
3095 return new Sized_symbol<size>();
3098 // Process relocations for gc.
3100 template<int size, bool big_endian>
3102 Target_sparc<size, big_endian>::gc_process_relocs(
3103 Symbol_table* symtab,
3105 Sized_relobj_file<size, big_endian>* object,
3106 unsigned int data_shndx,
3108 const unsigned char* prelocs,
3110 Output_section* output_section,
3111 bool needs_special_offset_handling,
3112 size_t local_symbol_count,
3113 const unsigned char* plocal_symbols)
3115 typedef Target_sparc<size, big_endian> Sparc;
3116 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3117 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
3120 gold::gc_process_relocs<size, big_endian, Sparc, Scan, Classify_reloc>(
3129 needs_special_offset_handling,
3134 // Scan relocations for a section.
3136 template<int size, bool big_endian>
3138 Target_sparc<size, big_endian>::scan_relocs(
3139 Symbol_table* symtab,
3141 Sized_relobj_file<size, big_endian>* object,
3142 unsigned int data_shndx,
3143 unsigned int sh_type,
3144 const unsigned char* prelocs,
3146 Output_section* output_section,
3147 bool needs_special_offset_handling,
3148 size_t local_symbol_count,
3149 const unsigned char* plocal_symbols)
3151 typedef Target_sparc<size, big_endian> Sparc;
3152 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
3155 if (sh_type == elfcpp::SHT_REL)
3157 gold_error(_("%s: unsupported REL reloc section"),
3158 object->name().c_str());
3162 gold::scan_relocs<size, big_endian, Sparc, Scan, Classify_reloc>(
3171 needs_special_offset_handling,
3176 // Finalize the sections.
3178 template<int size, bool big_endian>
3180 Target_sparc<size, big_endian>::do_finalize_sections(
3182 const Input_objects*,
3183 Symbol_table* symtab)
3186 this->plt_->emit_pending_ifunc_relocs();
3188 // Fill in some more dynamic tags.
3189 const Reloc_section* rel_plt = (this->plt_ == NULL
3191 : this->plt_->rel_plt());
3192 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
3193 this->rela_dyn_, true, true);
3195 // Emit any relocs we saved in an attempt to avoid generating COPY
3197 if (this->copy_relocs_.any_saved_relocs())
3198 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3200 if (parameters->doing_static_link()
3201 && (this->plt_ == NULL || !this->plt_->has_ifunc_section()))
3203 // If linking statically, make sure that the __rela_iplt symbols
3204 // were defined if necessary, even if we didn't create a PLT.
3205 static const Define_symbol_in_segment syms[] =
3208 "__rela_iplt_start", // name
3209 elfcpp::PT_LOAD, // segment_type
3210 elfcpp::PF_W, // segment_flags_set
3211 elfcpp::PF(0), // segment_flags_clear
3214 elfcpp::STT_NOTYPE, // type
3215 elfcpp::STB_GLOBAL, // binding
3216 elfcpp::STV_HIDDEN, // visibility
3218 Symbol::SEGMENT_START, // offset_from_base
3222 "__rela_iplt_end", // name
3223 elfcpp::PT_LOAD, // segment_type
3224 elfcpp::PF_W, // segment_flags_set
3225 elfcpp::PF(0), // segment_flags_clear
3228 elfcpp::STT_NOTYPE, // type
3229 elfcpp::STB_GLOBAL, // binding
3230 elfcpp::STV_HIDDEN, // visibility
3232 Symbol::SEGMENT_START, // offset_from_base
3237 symtab->define_symbols(layout, 2, syms,
3238 layout->script_options()->saw_sections_clause());
3241 for (int reg = 0; reg < 4; ++reg)
3243 Register_symbol& rsym = this->register_syms_[reg];
3244 if (rsym.name != NULL)
3246 int value = reg < 3 ? reg + 2 : reg + 4;
3247 Sized_symbol<size>* sym = new Sized_symbol<size>();
3248 if (rsym.shndx == elfcpp::SHN_UNDEF)
3249 sym->init_undefined(rsym.name, NULL, value,
3250 elfcpp::STT_SPARC_REGISTER, elfcpp::STB_GLOBAL,
3251 elfcpp::STV_DEFAULT, 0);
3253 sym->init_constant(rsym.name, NULL, value, 0,
3254 elfcpp::STT_SPARC_REGISTER, elfcpp::STB_GLOBAL,
3255 elfcpp::STV_DEFAULT, 0, false);
3256 symtab->add_target_global_symbol(sym);
3257 layout->add_target_specific_dynamic_tag(elfcpp::DT_SPARC_REGISTER,
3263 // Perform a relocation.
3265 template<int size, bool big_endian>
3267 Target_sparc<size, big_endian>::Relocate::relocate(
3268 const Relocate_info<size, big_endian>* relinfo,
3270 Target_sparc* target,
3273 const unsigned char* preloc,
3274 const Sized_symbol<size>* gsym,
3275 const Symbol_value<size>* psymval,
3276 unsigned char* view,
3277 typename elfcpp::Elf_types<size>::Elf_Addr address,
3278 section_size_type view_size)
3280 const elfcpp::Rela<size, big_endian> rela(preloc);
3281 unsigned int r_type = elfcpp::elf_r_type<size>(rela.get_r_info());
3282 bool orig_is_ifunc = psymval->is_ifunc_symbol();
3285 if (this->ignore_gd_add_)
3287 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
3288 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3289 _("missing expected TLS relocation"));
3292 this->ignore_gd_add_ = false;
3300 if (this->reloc_adjust_addr_ == view)
3303 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3304 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3306 // Pick the value to use for symbols defined in shared objects.
3307 Symbol_value<size> symval;
3309 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3311 elfcpp::Elf_Xword value;
3313 value = target->plt_address_for_global(gsym);
3315 symval.set_output_value(value);
3319 else if (gsym == NULL && orig_is_ifunc)
3321 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3322 if (object->local_has_plt_offset(r_sym))
3324 symval.set_output_value(target->plt_address_for_local(object, r_sym));
3329 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3331 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3332 // pointer points to the beginning, not the end, of the table.
3333 // So we just use the plain offset.
3334 unsigned int got_offset = 0;
3335 bool gdop_valid = false;
3338 case elfcpp::R_SPARC_GOTDATA_OP:
3339 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3340 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3341 // If this is local, we did not create a GOT entry because we
3342 // intend to transform this into a GOT relative relocation.
3344 || (gsym->is_defined()
3345 && !gsym->is_from_dynobj()
3346 && !gsym->is_preemptible()
3349 got_offset = psymval->value(object, addend) - target->got_address();
3353 case elfcpp::R_SPARC_GOT10:
3354 case elfcpp::R_SPARC_GOT13:
3355 case elfcpp::R_SPARC_GOT22:
3358 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3359 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3363 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3364 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3365 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3375 case elfcpp::R_SPARC_NONE:
3376 case elfcpp::R_SPARC_REGISTER:
3377 case elfcpp::R_SPARC_GNU_VTINHERIT:
3378 case elfcpp::R_SPARC_GNU_VTENTRY:
3381 case elfcpp::R_SPARC_8:
3382 Relocate_functions<size, big_endian>::rela8(view, object,
3386 case elfcpp::R_SPARC_16:
3387 if (rela.get_r_offset() & 0x1)
3389 // The assembler can sometimes emit unaligned relocations
3390 // for dwarf2 cfi directives.
3391 Reloc::ua16(view, object, psymval, addend);
3394 Relocate_functions<size, big_endian>::rela16(view, object,
3398 case elfcpp::R_SPARC_32:
3399 if (!parameters->options().output_is_position_independent())
3401 if (rela.get_r_offset() & 0x3)
3403 // The assembler can sometimes emit unaligned relocations
3404 // for dwarf2 cfi directives.
3405 Reloc::ua32(view, object, psymval, addend);
3408 Relocate_functions<size, big_endian>::rela32(view, object,
3413 case elfcpp::R_SPARC_DISP8:
3414 Reloc::disp8(view, object, psymval, addend, address);
3417 case elfcpp::R_SPARC_DISP16:
3418 Reloc::disp16(view, object, psymval, addend, address);
3421 case elfcpp::R_SPARC_DISP32:
3422 Reloc::disp32(view, object, psymval, addend, address);
3425 case elfcpp::R_SPARC_DISP64:
3426 Reloc::disp64(view, object, psymval, addend, address);
3429 case elfcpp::R_SPARC_WDISP30:
3430 case elfcpp::R_SPARC_WPLT30:
3431 Reloc::wdisp30(view, object, psymval, addend, address);
3432 if (target->may_relax())
3433 relax_call(target, view, rela, view_size);
3436 case elfcpp::R_SPARC_WDISP22:
3437 Reloc::wdisp22(view, object, psymval, addend, address);
3440 case elfcpp::R_SPARC_WDISP19:
3441 Reloc::wdisp19(view, object, psymval, addend, address);
3444 case elfcpp::R_SPARC_WDISP16:
3445 Reloc::wdisp16(view, object, psymval, addend, address);
3448 case elfcpp::R_SPARC_WDISP10:
3449 Reloc::wdisp10(view, object, psymval, addend, address);
3452 case elfcpp::R_SPARC_HI22:
3453 Reloc::hi22(view, object, psymval, addend);
3456 case elfcpp::R_SPARC_22:
3457 Reloc::rela32_22(view, object, psymval, addend);
3460 case elfcpp::R_SPARC_13:
3461 Reloc::rela32_13(view, object, psymval, addend);
3464 case elfcpp::R_SPARC_LO10:
3465 Reloc::lo10(view, object, psymval, addend);
3468 case elfcpp::R_SPARC_GOT10:
3469 Reloc::lo10(view, got_offset, addend);
3472 case elfcpp::R_SPARC_GOTDATA_OP:
3475 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3476 Insntype* wv = reinterpret_cast<Insntype*>(view);
3479 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3480 val = elfcpp::Swap<32, true>::readval(wv);
3481 val = 0x80000000 | (val & 0x3e07c01f);
3482 elfcpp::Swap<32, true>::writeval(wv, val);
3486 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3489 Reloc::gdop_lox10(view, got_offset);
3493 case elfcpp::R_SPARC_GOT13:
3494 Reloc::rela32_13(view, got_offset, addend);
3497 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3500 Reloc::gdop_hix22(view, got_offset);
3504 case elfcpp::R_SPARC_GOT22:
3505 Reloc::hi22(view, got_offset, addend);
3508 case elfcpp::R_SPARC_PC10:
3509 Reloc::pc10(view, object, psymval, addend, address);
3512 case elfcpp::R_SPARC_PC22:
3513 Reloc::pc22(view, object, psymval, addend, address);
3516 case elfcpp::R_SPARC_TLS_DTPOFF32:
3517 case elfcpp::R_SPARC_UA32:
3518 Reloc::ua32(view, object, psymval, addend);
3521 case elfcpp::R_SPARC_PLT64:
3522 Relocate_functions<size, big_endian>::rela64(view, object,
3526 case elfcpp::R_SPARC_PLT32:
3527 Relocate_functions<size, big_endian>::rela32(view, object,
3531 case elfcpp::R_SPARC_HIPLT22:
3532 Reloc::hi22(view, object, psymval, addend);
3535 case elfcpp::R_SPARC_LOPLT10:
3536 Reloc::lo10(view, object, psymval, addend);
3539 case elfcpp::R_SPARC_PCPLT32:
3540 Reloc::disp32(view, object, psymval, addend, address);
3543 case elfcpp::R_SPARC_PCPLT22:
3544 Reloc::pcplt22(view, object, psymval, addend, address);
3547 case elfcpp::R_SPARC_PCPLT10:
3548 Reloc::lo10(view, object, psymval, addend, address);
3551 case elfcpp::R_SPARC_64:
3552 if (!parameters->options().output_is_position_independent())
3554 if (rela.get_r_offset() & 0x7)
3556 // The assembler can sometimes emit unaligned relocations
3557 // for dwarf2 cfi directives.
3558 Reloc::ua64(view, object, psymval, addend);
3561 Relocate_functions<size, big_endian>::rela64(view, object,
3566 case elfcpp::R_SPARC_OLO10:
3568 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
3569 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
3570 Reloc::olo10(view, object, psymval, addend, addend2);
3574 case elfcpp::R_SPARC_HH22:
3575 Reloc::hh22(view, object, psymval, addend);
3578 case elfcpp::R_SPARC_PC_HH22:
3579 Reloc::pc_hh22(view, object, psymval, addend, address);
3582 case elfcpp::R_SPARC_HM10:
3583 Reloc::hm10(view, object, psymval, addend);
3586 case elfcpp::R_SPARC_PC_HM10:
3587 Reloc::pc_hm10(view, object, psymval, addend, address);
3590 case elfcpp::R_SPARC_LM22:
3591 Reloc::hi22(view, object, psymval, addend);
3594 case elfcpp::R_SPARC_PC_LM22:
3595 Reloc::pcplt22(view, object, psymval, addend, address);
3598 case elfcpp::R_SPARC_11:
3599 Reloc::rela32_11(view, object, psymval, addend);
3602 case elfcpp::R_SPARC_10:
3603 Reloc::rela32_10(view, object, psymval, addend);
3606 case elfcpp::R_SPARC_7:
3607 Reloc::rela32_7(view, object, psymval, addend);
3610 case elfcpp::R_SPARC_6:
3611 Reloc::rela32_6(view, object, psymval, addend);
3614 case elfcpp::R_SPARC_5:
3615 Reloc::rela32_5(view, object, psymval, addend);
3618 case elfcpp::R_SPARC_HIX22:
3619 Reloc::hix22(view, object, psymval, addend);
3622 case elfcpp::R_SPARC_LOX10:
3623 Reloc::lox10(view, object, psymval, addend);
3626 case elfcpp::R_SPARC_H34:
3627 Reloc::h34(view, object, psymval, addend);
3630 case elfcpp::R_SPARC_H44:
3631 Reloc::h44(view, object, psymval, addend);
3634 case elfcpp::R_SPARC_M44:
3635 Reloc::m44(view, object, psymval, addend);
3638 case elfcpp::R_SPARC_L44:
3639 Reloc::l44(view, object, psymval, addend);
3642 case elfcpp::R_SPARC_TLS_DTPOFF64:
3643 case elfcpp::R_SPARC_UA64:
3644 Reloc::ua64(view, object, psymval, addend);
3647 case elfcpp::R_SPARC_UA16:
3648 Reloc::ua16(view, object, psymval, addend);
3651 case elfcpp::R_SPARC_TLS_GD_HI22:
3652 case elfcpp::R_SPARC_TLS_GD_LO10:
3653 case elfcpp::R_SPARC_TLS_GD_ADD:
3654 case elfcpp::R_SPARC_TLS_GD_CALL:
3655 case elfcpp::R_SPARC_TLS_LDM_HI22:
3656 case elfcpp::R_SPARC_TLS_LDM_LO10:
3657 case elfcpp::R_SPARC_TLS_LDM_ADD:
3658 case elfcpp::R_SPARC_TLS_LDM_CALL:
3659 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3660 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3661 case elfcpp::R_SPARC_TLS_LDO_ADD:
3662 case elfcpp::R_SPARC_TLS_IE_HI22:
3663 case elfcpp::R_SPARC_TLS_IE_LO10:
3664 case elfcpp::R_SPARC_TLS_IE_LD:
3665 case elfcpp::R_SPARC_TLS_IE_LDX:
3666 case elfcpp::R_SPARC_TLS_IE_ADD:
3667 case elfcpp::R_SPARC_TLS_LE_HIX22:
3668 case elfcpp::R_SPARC_TLS_LE_LOX10:
3669 this->relocate_tls(relinfo, target, relnum, rela,
3670 r_type, gsym, psymval, view,
3671 address, view_size);
3674 case elfcpp::R_SPARC_COPY:
3675 case elfcpp::R_SPARC_GLOB_DAT:
3676 case elfcpp::R_SPARC_JMP_SLOT:
3677 case elfcpp::R_SPARC_JMP_IREL:
3678 case elfcpp::R_SPARC_RELATIVE:
3679 case elfcpp::R_SPARC_IRELATIVE:
3680 // These are outstanding tls relocs, which are unexpected when
3682 case elfcpp::R_SPARC_TLS_DTPMOD64:
3683 case elfcpp::R_SPARC_TLS_DTPMOD32:
3684 case elfcpp::R_SPARC_TLS_TPOFF64:
3685 case elfcpp::R_SPARC_TLS_TPOFF32:
3686 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3687 _("unexpected reloc %u in object file"),
3692 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3693 _("unsupported reloc %u"),
3701 // Perform a TLS relocation.
3703 template<int size, bool big_endian>
3705 Target_sparc<size, big_endian>::Relocate::relocate_tls(
3706 const Relocate_info<size, big_endian>* relinfo,
3707 Target_sparc<size, big_endian>* target,
3709 const elfcpp::Rela<size, big_endian>& rela,
3710 unsigned int r_type,
3711 const Sized_symbol<size>* gsym,
3712 const Symbol_value<size>* psymval,
3713 unsigned char* view,
3714 typename elfcpp::Elf_types<size>::Elf_Addr address,
3717 Output_segment* tls_segment = relinfo->layout->tls_segment();
3718 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3719 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3720 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3722 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3723 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
3725 const bool is_final =
3727 ? !parameters->options().output_is_position_independent()
3728 : gsym->final_value_is_known());
3729 const tls::Tls_optimization optimized_type
3730 = optimize_tls_reloc(is_final, r_type);
3734 case elfcpp::R_SPARC_TLS_GD_HI22:
3735 case elfcpp::R_SPARC_TLS_GD_LO10:
3736 case elfcpp::R_SPARC_TLS_GD_ADD:
3737 case elfcpp::R_SPARC_TLS_GD_CALL:
3738 if (optimized_type == tls::TLSOPT_TO_LE)
3740 Insntype* wv = reinterpret_cast<Insntype*>(view);
3743 value -= tls_segment->memsz();
3747 case elfcpp::R_SPARC_TLS_GD_HI22:
3748 // TLS_GD_HI22 --> TLS_LE_HIX22
3749 Reloc::hix22(view, value, addend);
3752 case elfcpp::R_SPARC_TLS_GD_LO10:
3753 // TLS_GD_LO10 --> TLS_LE_LOX10
3754 Reloc::lox10(view, value, addend);
3757 case elfcpp::R_SPARC_TLS_GD_ADD:
3758 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3759 val = elfcpp::Swap<32, true>::readval(wv);
3760 val = (val & ~0x7c000) | 0x1c000;
3761 elfcpp::Swap<32, true>::writeval(wv, val);
3763 case elfcpp::R_SPARC_TLS_GD_CALL:
3764 // call __tls_get_addr --> nop
3765 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3772 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3773 ? GOT_TYPE_TLS_OFFSET
3774 : GOT_TYPE_TLS_PAIR);
3777 gold_assert(gsym->has_got_offset(got_type));
3778 value = gsym->got_offset(got_type);
3782 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3783 gold_assert(object->local_has_got_offset(r_sym, got_type));
3784 value = object->local_got_offset(r_sym, got_type);
3786 if (optimized_type == tls::TLSOPT_TO_IE)
3788 Insntype* wv = reinterpret_cast<Insntype*>(view);
3793 case elfcpp::R_SPARC_TLS_GD_HI22:
3794 // TLS_GD_HI22 --> TLS_IE_HI22
3795 Reloc::hi22(view, value, addend);
3798 case elfcpp::R_SPARC_TLS_GD_LO10:
3799 // TLS_GD_LO10 --> TLS_IE_LO10
3800 Reloc::lo10(view, value, addend);
3803 case elfcpp::R_SPARC_TLS_GD_ADD:
3804 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3805 val = elfcpp::Swap<32, true>::readval(wv);
3812 elfcpp::Swap<32, true>::writeval(wv, val);
3815 case elfcpp::R_SPARC_TLS_GD_CALL:
3816 // The compiler can put the TLS_GD_ADD instruction
3817 // into the delay slot of the call. If so, we need
3818 // to transpose the two instructions so that the
3819 // new sequence works properly.
3821 // The test we use is if the instruction in the
3822 // delay slot is an add with destination register
3824 val = elfcpp::Swap<32, true>::readval(wv + 1);
3825 if ((val & 0x81f80000) == 0x80000000
3826 && ((val >> 25) & 0x1f) == 0x8)
3833 elfcpp::Swap<32, true>::writeval(wv, val);
3836 this->ignore_gd_add_ = true;
3840 // Even if the delay slot isn't the TLS_GD_ADD
3841 // instruction, we still have to handle the case
3842 // where it sets up %o0 in some other way.
3843 elfcpp::Swap<32, true>::writeval(wv, val);
3845 this->reloc_adjust_addr_ = view + 4;
3847 // call __tls_get_addr --> add %g7, %o0, %o0
3848 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
3853 else if (optimized_type == tls::TLSOPT_NONE)
3857 case elfcpp::R_SPARC_TLS_GD_HI22:
3858 Reloc::hi22(view, value, addend);
3860 case elfcpp::R_SPARC_TLS_GD_LO10:
3861 Reloc::lo10(view, value, addend);
3863 case elfcpp::R_SPARC_TLS_GD_ADD:
3865 case elfcpp::R_SPARC_TLS_GD_CALL:
3867 Symbol_value<size> symval;
3868 elfcpp::Elf_Xword value;
3871 tsym = target->tls_get_addr_sym_;
3873 value = (target->plt_section()->address() +
3874 tsym->plt_offset());
3875 symval.set_output_value(value);
3876 Reloc::wdisp30(view, object, &symval, addend, address);
3883 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3884 _("unsupported reloc %u"),
3888 case elfcpp::R_SPARC_TLS_LDM_HI22:
3889 case elfcpp::R_SPARC_TLS_LDM_LO10:
3890 case elfcpp::R_SPARC_TLS_LDM_ADD:
3891 case elfcpp::R_SPARC_TLS_LDM_CALL:
3892 if (optimized_type == tls::TLSOPT_TO_LE)
3894 Insntype* wv = reinterpret_cast<Insntype*>(view);
3898 case elfcpp::R_SPARC_TLS_LDM_HI22:
3899 case elfcpp::R_SPARC_TLS_LDM_LO10:
3900 case elfcpp::R_SPARC_TLS_LDM_ADD:
3901 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3904 case elfcpp::R_SPARC_TLS_LDM_CALL:
3905 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
3910 else if (optimized_type == tls::TLSOPT_NONE)
3912 // Relocate the field with the offset of the GOT entry for
3913 // the module index.
3914 unsigned int got_offset;
3916 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
3919 case elfcpp::R_SPARC_TLS_LDM_HI22:
3920 Reloc::hi22(view, got_offset, addend);
3922 case elfcpp::R_SPARC_TLS_LDM_LO10:
3923 Reloc::lo10(view, got_offset, addend);
3925 case elfcpp::R_SPARC_TLS_LDM_ADD:
3927 case elfcpp::R_SPARC_TLS_LDM_CALL:
3929 Symbol_value<size> symval;
3930 elfcpp::Elf_Xword value;
3933 tsym = target->tls_get_addr_sym_;
3935 value = (target->plt_section()->address() +
3936 tsym->plt_offset());
3937 symval.set_output_value(value);
3938 Reloc::wdisp30(view, object, &symval, addend, address);
3944 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3945 _("unsupported reloc %u"),
3949 // These relocs can appear in debugging sections, in which case
3950 // we won't see the TLS_LDM relocs. The local_dynamic_type
3951 // field tells us this.
3952 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3953 if (optimized_type == tls::TLSOPT_TO_LE)
3955 value -= tls_segment->memsz();
3956 Reloc::hix22(view, value, addend);
3959 Reloc::ldo_hix22(view, value, addend);
3961 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3962 if (optimized_type == tls::TLSOPT_TO_LE)
3964 value -= tls_segment->memsz();
3965 Reloc::lox10(view, value, addend);
3968 Reloc::ldo_lox10(view, value, addend);
3970 case elfcpp::R_SPARC_TLS_LDO_ADD:
3971 if (optimized_type == tls::TLSOPT_TO_LE)
3973 Insntype* wv = reinterpret_cast<Insntype*>(view);
3976 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3977 val = elfcpp::Swap<32, true>::readval(wv);
3978 val = (val & ~0x7c000) | 0x1c000;
3979 elfcpp::Swap<32, true>::writeval(wv, val);
3983 // When optimizing IE --> LE, the only relocation that is handled
3984 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3985 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3986 // rs2 and rd are the same.
3987 case elfcpp::R_SPARC_TLS_IE_LD:
3988 case elfcpp::R_SPARC_TLS_IE_LDX:
3989 if (optimized_type == tls::TLSOPT_TO_LE)
3991 Insntype* wv = reinterpret_cast<Insntype*>(view);
3992 Insntype val = elfcpp::Swap<32, true>::readval(wv);
3993 Insntype rs2 = val & 0x1f;
3994 Insntype rd = (val >> 25) & 0x1f;
3999 val = sparc_mov | (val & 0x3e00001f);
4001 elfcpp::Swap<32, true>::writeval(wv, val);
4005 case elfcpp::R_SPARC_TLS_IE_HI22:
4006 case elfcpp::R_SPARC_TLS_IE_LO10:
4007 if (optimized_type == tls::TLSOPT_TO_LE)
4009 value -= tls_segment->memsz();
4012 case elfcpp::R_SPARC_TLS_IE_HI22:
4013 // IE_HI22 --> LE_HIX22
4014 Reloc::hix22(view, value, addend);
4016 case elfcpp::R_SPARC_TLS_IE_LO10:
4017 // IE_LO10 --> LE_LOX10
4018 Reloc::lox10(view, value, addend);
4023 else if (optimized_type == tls::TLSOPT_NONE)
4025 // Relocate the field with the offset of the GOT entry for
4026 // the tp-relative offset of the symbol.
4029 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
4030 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
4034 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
4035 gold_assert(object->local_has_got_offset(r_sym,
4036 GOT_TYPE_TLS_OFFSET));
4037 value = object->local_got_offset(r_sym,
4038 GOT_TYPE_TLS_OFFSET);
4042 case elfcpp::R_SPARC_TLS_IE_HI22:
4043 Reloc::hi22(view, value, addend);
4045 case elfcpp::R_SPARC_TLS_IE_LO10:
4046 Reloc::lo10(view, value, addend);
4051 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
4052 _("unsupported reloc %u"),
4056 case elfcpp::R_SPARC_TLS_IE_ADD:
4057 // This seems to be mainly so that we can find the addition
4058 // instruction if there is one. There doesn't seem to be any
4059 // actual relocation to apply.
4062 case elfcpp::R_SPARC_TLS_LE_HIX22:
4063 // If we're creating a shared library, a dynamic relocation will
4064 // have been created for this location, so do not apply it now.
4065 if (!parameters->options().shared())
4067 value -= tls_segment->memsz();
4068 Reloc::hix22(view, value, addend);
4072 case elfcpp::R_SPARC_TLS_LE_LOX10:
4073 // If we're creating a shared library, a dynamic relocation will
4074 // have been created for this location, so do not apply it now.
4075 if (!parameters->options().shared())
4077 value -= tls_segment->memsz();
4078 Reloc::lox10(view, value, addend);
4084 // Relax a call instruction.
4086 template<int size, bool big_endian>
4088 Target_sparc<size, big_endian>::Relocate::relax_call(
4089 Target_sparc<size, big_endian>* target,
4090 unsigned char* view,
4091 const elfcpp::Rela<size, big_endian>& rela,
4092 section_size_type view_size)
4094 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
4095 Insntype *wv = reinterpret_cast<Insntype*>(view);
4096 Insntype call_insn, delay_insn, set_insn;
4097 uint32_t op3, reg, off;
4099 // This code tries to relax call instructions that meet
4100 // certain criteria.
4102 // The first criteria is that the call must be such that the return
4103 // address which the call writes into %o7 is unused. Two sequences
4104 // meet this criteria, and are used to implement tail calls.
4106 // Leaf function tail call:
4108 // or %o7, %g0, %ANY_REG
4110 // or %ANY_REG, %g0, %o7
4112 // Non-leaf function tail call:
4117 // The second criteria is that the call destination is close. If
4118 // the displacement can fit in a signed 22-bit immediate field of a
4119 // pre-V9 branch, we can do it. If we are generating a 64-bit
4120 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4121 // and the displacement fits in a signed 19-bit immediate field,
4122 // then we can use a V9 branch.
4124 // Make sure the delay instruction can be safely accessed.
4125 if (rela.get_r_offset() + 8 > view_size)
4128 call_insn = elfcpp::Swap<32, true>::readval(wv);
4129 delay_insn = elfcpp::Swap<32, true>::readval(wv + 1);
4131 // Make sure it is really a call instruction.
4132 if (((call_insn >> 30) & 0x3) != 1)
4135 if (((delay_insn >> 30) & 0x3) != 2)
4138 // Accept only a restore or an integer arithmetic operation whose
4139 // sole side effect is to write the %o7 register (and perhaps set
4140 // the condition codes, which are considered clobbered across
4143 // For example, we don't want to match a tagged addition or
4144 // subtraction. We also don't want to match something like a
4147 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4148 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4150 op3 = (delay_insn >> 19) & 0x3f;
4151 reg = (delay_insn >> 25) & 0x1f;
4153 && ((op3 & 0x28) != 0 || reg != 15))
4156 // For non-restore instructions, make sure %o7 isn't
4161 reg = (delay_insn >> 14) & 0x15;
4165 // And if non-immediate, check RS2
4166 if (((delay_insn >> 13) & 1) == 0)
4168 reg = (delay_insn & 0x1f);
4174 // Now check the branch distance. We are called after the
4175 // call has been relocated, so we just have to peek at the
4176 // offset contained in the instruction.
4177 off = call_insn & 0x3fffffff;
4178 if ((off & 0x3fe00000) != 0
4179 && (off & 0x3fe00000) != 0x3fe00000)
4182 if ((size == 64 || target->elf_machine_ == elfcpp::EM_SPARC32PLUS)
4183 && ((off & 0x3c0000) == 0
4184 || (off & 0x3c0000) == 0x3c0000))
4187 call_insn = 0x10680000 | (off & 0x07ffff);
4192 call_insn = 0x10800000 | (off & 0x3fffff);
4194 elfcpp::Swap<32, true>::writeval(wv, call_insn);
4196 // See if we can NOP out the delay slot instruction. We peek
4197 // at the instruction before the call to make sure we're dealing
4198 // with exactly the:
4200 // or %o7, %g0, %ANY_REG
4202 // or %ANY_REG, %g0, %o7
4204 // case. Otherwise this might be a tricky piece of hand written
4205 // assembler calculating %o7 in some non-trivial way, and therefore
4206 // we can't be sure that NOP'ing out the delay slot is safe.
4208 && rela.get_r_offset() >= 4)
4210 if ((delay_insn & ~(0x1f << 14)) != 0x9e100000)
4213 set_insn = elfcpp::Swap<32, true>::readval(wv - 1);
4214 if ((set_insn & ~(0x1f << 25)) != 0x8013c000)
4217 reg = (set_insn >> 25) & 0x1f;
4218 if (reg == 0 || reg == 15)
4220 if (reg != ((delay_insn >> 14) & 0x1f))
4223 // All tests pass, nop it out.
4224 elfcpp::Swap<32, true>::writeval(wv + 1, sparc_nop);
4228 // Relocate section data.
4230 template<int size, bool big_endian>
4232 Target_sparc<size, big_endian>::relocate_section(
4233 const Relocate_info<size, big_endian>* relinfo,
4234 unsigned int sh_type,
4235 const unsigned char* prelocs,
4237 Output_section* output_section,
4238 bool needs_special_offset_handling,
4239 unsigned char* view,
4240 typename elfcpp::Elf_types<size>::Elf_Addr address,
4241 section_size_type view_size,
4242 const Reloc_symbol_changes* reloc_symbol_changes)
4244 typedef Target_sparc<size, big_endian> Sparc;
4245 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
4246 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
4249 gold_assert(sh_type == elfcpp::SHT_RELA);
4251 gold::relocate_section<size, big_endian, Sparc, Sparc_relocate,
4252 gold::Default_comdat_behavior, Classify_reloc>(
4258 needs_special_offset_handling,
4262 reloc_symbol_changes);
4265 // Scan the relocs during a relocatable link.
4267 template<int size, bool big_endian>
4269 Target_sparc<size, big_endian>::scan_relocatable_relocs(
4270 Symbol_table* symtab,
4272 Sized_relobj_file<size, big_endian>* object,
4273 unsigned int data_shndx,
4274 unsigned int sh_type,
4275 const unsigned char* prelocs,
4277 Output_section* output_section,
4278 bool needs_special_offset_handling,
4279 size_t local_symbol_count,
4280 const unsigned char* plocal_symbols,
4281 Relocatable_relocs* rr)
4283 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
4285 typedef gold::Default_scan_relocatable_relocs<Classify_reloc>
4286 Scan_relocatable_relocs;
4288 gold_assert(sh_type == elfcpp::SHT_RELA);
4290 gold::scan_relocatable_relocs<size, big_endian, Scan_relocatable_relocs>(
4298 needs_special_offset_handling,
4304 // Scan the relocs for --emit-relocs.
4306 template<int size, bool big_endian>
4308 Target_sparc<size, big_endian>::emit_relocs_scan(
4309 Symbol_table* symtab,
4311 Sized_relobj_file<size, big_endian>* object,
4312 unsigned int data_shndx,
4313 unsigned int sh_type,
4314 const unsigned char* prelocs,
4316 Output_section* output_section,
4317 bool needs_special_offset_handling,
4318 size_t local_symbol_count,
4319 const unsigned char* plocal_syms,
4320 Relocatable_relocs* rr)
4322 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
4324 typedef gold::Default_emit_relocs_strategy<Classify_reloc>
4325 Emit_relocs_strategy;
4327 gold_assert(sh_type == elfcpp::SHT_RELA);
4329 gold::scan_relocatable_relocs<size, big_endian, Emit_relocs_strategy>(
4337 needs_special_offset_handling,
4343 // Emit relocations for a section.
4345 template<int size, bool big_endian>
4347 Target_sparc<size, big_endian>::relocate_relocs(
4348 const Relocate_info<size, big_endian>* relinfo,
4349 unsigned int sh_type,
4350 const unsigned char* prelocs,
4352 Output_section* output_section,
4353 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
4354 unsigned char* view,
4355 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4356 section_size_type view_size,
4357 unsigned char* reloc_view,
4358 section_size_type reloc_view_size)
4360 typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
4363 gold_assert(sh_type == elfcpp::SHT_RELA);
4365 gold::relocate_relocs<size, big_endian, Classify_reloc>(
4370 offset_in_output_section,
4378 // Return the value to use for a dynamic which requires special
4379 // treatment. This is how we support equality comparisons of function
4380 // pointers across shared library boundaries, as described in the
4381 // processor specific ABI supplement.
4383 template<int size, bool big_endian>
4385 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
4387 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4388 return this->plt_section()->address() + gsym->plt_offset();
4391 // do_make_elf_object to override the same function in the base class.
4392 // We need to use a target-specific sub-class of
4393 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4394 // of the ELF headers. Hence we need to have our own ELF object creation.
4396 template<int size, bool big_endian>
4398 Target_sparc<size, big_endian>::do_make_elf_object(
4399 const std::string& name,
4400 Input_file* input_file,
4401 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
4403 elfcpp::Elf_Half machine = ehdr.get_e_machine();
4404 elfcpp::Elf_Word flags = ehdr.get_e_flags();
4405 elfcpp::Elf_Word omm, mm;
4409 case elfcpp::EM_SPARC32PLUS:
4410 this->elf_machine_ = elfcpp::EM_SPARC32PLUS;
4413 case elfcpp::EM_SPARC:
4414 case elfcpp::EM_SPARCV9:
4421 if (!this->elf_flags_set_)
4423 this->elf_flags_ = flags;
4424 this->elf_flags_set_ = true;
4428 // Accumulate cpu feature bits.
4429 this->elf_flags_ |= (flags & (elfcpp::EF_SPARC_32PLUS
4430 | elfcpp::EF_SPARC_SUN_US1
4431 | elfcpp::EF_SPARC_HAL_R1
4432 | elfcpp::EF_SPARC_SUN_US3));
4434 // Bump the memory model setting to the most restrictive
4435 // one we encounter.
4436 omm = (this->elf_flags_ & elfcpp::EF_SPARCV9_MM);
4437 mm = (flags & elfcpp::EF_SPARCV9_MM);
4440 if (mm == elfcpp::EF_SPARCV9_TSO)
4442 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4443 this->elf_flags_ |= elfcpp::EF_SPARCV9_TSO;
4445 else if (mm == elfcpp::EF_SPARCV9_PSO
4446 && omm == elfcpp::EF_SPARCV9_RMO)
4448 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4449 this->elf_flags_ |= elfcpp::EF_SPARCV9_PSO;
4454 // Validate that the little-endian flag matches how we've
4455 // been instantiated.
4456 if (!(flags & elfcpp::EF_SPARC_LEDATA) != big_endian)
4459 gold_error(_("%s: little endian elf flag set on BE object"),
4462 gold_error(_("%s: little endian elf flag clear on LE object"),
4466 return Target::do_make_elf_object(name, input_file, offset, ehdr);
4469 // Adjust ELF file header.
4471 template<int size, bool big_endian>
4473 Target_sparc<size, big_endian>::do_adjust_elf_header(
4474 unsigned char* view,
4477 elfcpp::Ehdr_write<size, big_endian> oehdr(view);
4479 oehdr.put_e_machine(this->elf_machine_);
4480 oehdr.put_e_flags(this->elf_flags_);
4482 Sized_target<size, big_endian>::do_adjust_elf_header(view, len);
4485 // The selector for sparc object files.
4487 template<int size, bool big_endian>
4488 class Target_selector_sparc : public Target_selector
4491 Target_selector_sparc()
4492 : Target_selector(elfcpp::EM_NONE, size, big_endian,
4493 (size == 64 ? "elf64-sparc" : "elf32-sparc"),
4494 (size == 64 ? "elf64_sparc" : "elf32_sparc"))
4498 do_recognize(Input_file*, off_t, int machine, int, int)
4503 if (machine != elfcpp::EM_SPARCV9)
4508 if (machine != elfcpp::EM_SPARC
4509 && machine != elfcpp::EM_SPARC32PLUS)
4517 return this->instantiate_target();
4521 do_instantiate_target()
4522 { return new Target_sparc<size, big_endian>(); }
4525 Target_selector_sparc<32, true> target_selector_sparc32;
4526 Target_selector_sparc<64, true> target_selector_sparc64;
4528 } // End anonymous namespace.