1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size, bool big_endian>
51 class Output_data_plt_sparc;
53 template<int size, bool big_endian>
54 class Target_sparc : public Sized_target<size, big_endian>
57 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
60 : Sized_target<size, big_endian>(&sparc_info),
61 got_(NULL), plt_(NULL), rela_dyn_(NULL), rela_ifunc_(NULL),
62 copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL),
64 elf_machine_(sparc_info.machine_code), elf_flags_(0),
69 // Process the relocations to determine unreferenced sections for
70 // garbage collection.
72 gc_process_relocs(Symbol_table* symtab,
74 Sized_relobj_file<size, big_endian>* object,
75 unsigned int data_shndx,
77 const unsigned char* prelocs,
79 Output_section* output_section,
80 bool needs_special_offset_handling,
81 size_t local_symbol_count,
82 const unsigned char* plocal_symbols);
84 // Scan the relocations to look for symbol adjustments.
86 scan_relocs(Symbol_table* symtab,
88 Sized_relobj_file<size, big_endian>* object,
89 unsigned int data_shndx,
91 const unsigned char* prelocs,
93 Output_section* output_section,
94 bool needs_special_offset_handling,
95 size_t local_symbol_count,
96 const unsigned char* plocal_symbols);
97 // Finalize the sections.
99 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
101 // Return the value to use for a dynamic which requires special
104 do_dynsym_value(const Symbol*) const;
106 // Relocate a section.
108 relocate_section(const Relocate_info<size, big_endian>*,
109 unsigned int sh_type,
110 const unsigned char* prelocs,
112 Output_section* output_section,
113 bool needs_special_offset_handling,
115 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
116 section_size_type view_size,
117 const Reloc_symbol_changes*);
119 // Scan the relocs during a relocatable link.
121 scan_relocatable_relocs(Symbol_table* symtab,
123 Sized_relobj_file<size, big_endian>* object,
124 unsigned int data_shndx,
125 unsigned int sh_type,
126 const unsigned char* prelocs,
128 Output_section* output_section,
129 bool needs_special_offset_handling,
130 size_t local_symbol_count,
131 const unsigned char* plocal_symbols,
132 Relocatable_relocs*);
134 // Emit relocations for a section.
136 relocate_relocs(const Relocate_info<size, big_endian>*,
137 unsigned int sh_type,
138 const unsigned char* prelocs,
140 Output_section* output_section,
141 typename elfcpp::Elf_types<size>::Elf_Off
142 offset_in_output_section,
143 const Relocatable_relocs*,
145 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
146 section_size_type view_size,
147 unsigned char* reloc_view,
148 section_size_type reloc_view_size);
150 // Return whether SYM is defined by the ABI.
152 do_is_defined_by_abi(const Symbol* sym) const
154 // XXX Really need to support this better...
155 if (sym->type() == elfcpp::STT_SPARC_REGISTER)
158 return strcmp(sym->name(), "___tls_get_addr") == 0;
161 // Return the PLT address to use for a global symbol.
163 do_plt_address_for_global(const Symbol* gsym) const
164 { return this->plt_section()->address_for_global(gsym); }
167 do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
168 { return this->plt_section()->address_for_local(relobj, symndx); }
170 // Return whether there is a GOT section.
172 has_got_section() const
173 { return this->got_ != NULL; }
175 // Return the size of the GOT section.
179 gold_assert(this->got_ != NULL);
180 return this->got_->data_size();
183 // Return the number of entries in the GOT.
185 got_entry_count() const
187 if (this->got_ == NULL)
189 return this->got_size() / (size / 8);
192 // Return the address of the GOT.
196 if (this->got_ == NULL)
198 return this->got_->address();
201 // Return the number of entries in the PLT.
203 plt_entry_count() const;
205 // Return the offset of the first non-reserved PLT entry.
207 first_plt_entry_offset() const;
209 // Return the size of each PLT entry.
211 plt_entry_size() const;
214 // Make an ELF object.
216 do_make_elf_object(const std::string&, Input_file*, off_t,
217 const elfcpp::Ehdr<size, big_endian>& ehdr);
220 do_adjust_elf_header(unsigned char* view, int len) const;
224 // The class which scans relocations.
229 : issued_non_pic_error_(false)
233 get_reference_flags(unsigned int r_type);
236 local(Symbol_table* symtab, Layout* layout, Target_sparc* target,
237 Sized_relobj_file<size, big_endian>* object,
238 unsigned int data_shndx,
239 Output_section* output_section,
240 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
241 const elfcpp::Sym<size, big_endian>& lsym,
245 global(Symbol_table* symtab, Layout* layout, Target_sparc* target,
246 Sized_relobj_file<size, big_endian>* object,
247 unsigned int data_shndx,
248 Output_section* output_section,
249 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
253 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
255 Sized_relobj_file<size, big_endian>* ,
258 const elfcpp::Rela<size, big_endian>& ,
260 const elfcpp::Sym<size, big_endian>&)
264 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
266 Sized_relobj_file<size, big_endian>* ,
269 const elfcpp::Rela<size,
271 unsigned int , Symbol*)
277 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
278 unsigned int r_type);
281 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
282 unsigned int r_type, Symbol*);
285 generate_tls_call(Symbol_table* symtab, Layout* layout,
286 Target_sparc* target);
289 check_non_pic(Relobj*, unsigned int r_type);
292 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*,
293 unsigned int r_type);
295 // Whether we have issued an error about a non-PIC compilation.
296 bool issued_non_pic_error_;
299 // The class which implements relocation.
304 : ignore_gd_add_(false), reloc_adjust_addr_(NULL)
309 if (this->ignore_gd_add_)
311 // FIXME: This needs to specify the location somehow.
312 gold_error(_("missing expected TLS relocation"));
316 // Do a relocation. Return false if the caller should not issue
317 // any warnings about this relocation.
319 relocate(const Relocate_info<size, big_endian>*, Target_sparc*,
320 Output_section*, size_t relnum,
321 const elfcpp::Rela<size, big_endian>&,
322 unsigned int r_type, const Sized_symbol<size>*,
323 const Symbol_value<size>*,
325 typename elfcpp::Elf_types<size>::Elf_Addr,
329 // Do a TLS relocation.
331 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
332 size_t relnum, const elfcpp::Rela<size, big_endian>&,
333 unsigned int r_type, const Sized_symbol<size>*,
334 const Symbol_value<size>*,
336 typename elfcpp::Elf_types<size>::Elf_Addr,
340 relax_call(Target_sparc<size, big_endian>* target,
342 const elfcpp::Rela<size, big_endian>& rela,
343 section_size_type view_size);
345 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
348 // If we hit a reloc at this view address, adjust it back by 4 bytes.
349 unsigned char *reloc_adjust_addr_;
352 // A class which returns the size required for a relocation type,
353 // used while scanning relocs during a relocatable link.
354 class Relocatable_size_for_reloc
358 get_size_for_reloc(unsigned int, Relobj*);
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 this->copy_relocs_.copy_reloc(symtab, layout,
419 symtab->get_sized_symbol<size>(sym),
420 object, shndx, output_section,
421 reloc, this->rela_dyn_section(layout));
424 // Information about this specific target which we pass to the
425 // general Target structure.
426 static Target::Target_info sparc_info;
428 // The types of GOT entries needed for this platform.
429 // These values are exposed to the ABI in an incremental link.
430 // Do not renumber existing values without changing the version
431 // number of the .gnu_incremental_inputs section.
434 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
435 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
436 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
440 Output_data_got<size, big_endian>* got_;
442 Output_data_plt_sparc<size, big_endian>* plt_;
443 // The dynamic reloc section.
444 Reloc_section* rela_dyn_;
445 // The section to use for IFUNC relocs.
446 Reloc_section* rela_ifunc_;
447 // Relocs saved to avoid a COPY reloc.
448 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
449 // Space for variables copied with a COPY reloc.
450 Output_data_space* dynbss_;
451 // Offset of the GOT entry for the TLS module index;
452 unsigned int got_mod_index_offset_;
453 // Cached pointer to __tls_get_addr symbol
454 Symbol* tls_get_addr_sym_;
455 // Accumulated elf machine type
456 elfcpp::Elf_Half elf_machine_;
457 // Accumulated elf header flags
458 elfcpp::Elf_Word elf_flags_;
459 // Whether elf_flags_ has been set for the first time yet
464 Target::Target_info Target_sparc<32, true>::sparc_info =
467 true, // is_big_endian
468 elfcpp::EM_SPARC, // machine_code
469 false, // has_make_symbol
470 false, // has_resolve
471 false, // has_code_fill
472 true, // is_default_stack_executable
473 false, // can_icf_inline_merge_sections
475 "/usr/lib/ld.so.1", // dynamic_linker
476 0x00010000, // default_text_segment_address
477 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
478 8 * 1024, // common_pagesize (overridable by -z common-page-size)
479 false, // isolate_execinstr
481 elfcpp::SHN_UNDEF, // small_common_shndx
482 elfcpp::SHN_UNDEF, // large_common_shndx
483 0, // small_common_section_flags
484 0, // large_common_section_flags
485 NULL, // attributes_section
486 NULL, // attributes_vendor
487 "_start" // entry_symbol_name
491 Target::Target_info Target_sparc<64, true>::sparc_info =
494 true, // is_big_endian
495 elfcpp::EM_SPARCV9, // machine_code
496 false, // has_make_symbol
497 false, // has_resolve
498 false, // has_code_fill
499 true, // is_default_stack_executable
500 false, // can_icf_inline_merge_sections
502 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
503 0x100000, // default_text_segment_address
504 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
505 8 * 1024, // common_pagesize (overridable by -z common-page-size)
506 false, // isolate_execinstr
508 elfcpp::SHN_UNDEF, // small_common_shndx
509 elfcpp::SHN_UNDEF, // large_common_shndx
510 0, // small_common_section_flags
511 0, // large_common_section_flags
512 NULL, // attributes_section
513 NULL, // attributes_vendor
514 "_start" // entry_symbol_name
517 // We have to take care here, even when operating in little-endian
518 // mode, sparc instructions are still big endian.
519 template<int size, bool big_endian>
520 class Sparc_relocate_functions
523 // Do a simple relocation with the addend in the relocation.
524 template<int valsize>
526 rela(unsigned char* view,
527 unsigned int right_shift,
528 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
529 typename elfcpp::Swap<size, big_endian>::Valtype value,
530 typename elfcpp::Swap<size, big_endian>::Valtype addend)
532 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
533 Valtype* wv = reinterpret_cast<Valtype*>(view);
534 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
535 Valtype reloc = ((value + addend) >> right_shift);
540 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
543 // Do a simple relocation using a symbol value with the addend in
545 template<int valsize>
547 rela(unsigned char* view,
548 unsigned int right_shift,
549 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
550 const Sized_relobj_file<size, big_endian>* object,
551 const Symbol_value<size>* psymval,
552 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
554 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
555 Valtype* wv = reinterpret_cast<Valtype*>(view);
556 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
557 Valtype reloc = (psymval->value(object, addend) >> right_shift);
562 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
565 // Do a simple relocation using a symbol value with the addend in
566 // the relocation, unaligned.
567 template<int valsize>
569 rela_ua(unsigned char* view,
570 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
571 const Sized_relobj_file<size, big_endian>* object,
572 const Symbol_value<size>* psymval,
573 typename elfcpp::Swap<size, big_endian>::Valtype addend)
575 typedef typename elfcpp::Swap_unaligned<valsize,
576 big_endian>::Valtype Valtype;
577 unsigned char* wv = view;
578 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
579 Valtype reloc = (psymval->value(object, addend) >> right_shift);
584 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
587 // Do a simple PC relative relocation with a Symbol_value with the
588 // addend in the relocation.
589 template<int valsize>
591 pcrela(unsigned char* view,
592 unsigned int right_shift,
593 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
594 const Sized_relobj_file<size, big_endian>* object,
595 const Symbol_value<size>* psymval,
596 typename elfcpp::Swap<size, big_endian>::Valtype addend,
597 typename elfcpp::Elf_types<size>::Elf_Addr address)
599 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
600 Valtype* wv = reinterpret_cast<Valtype*>(view);
601 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
602 Valtype reloc = ((psymval->value(object, addend) - address)
608 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
611 template<int valsize>
613 pcrela_unaligned(unsigned char* view,
614 const Sized_relobj_file<size, big_endian>* object,
615 const Symbol_value<size>* psymval,
616 typename elfcpp::Swap<size, big_endian>::Valtype addend,
617 typename elfcpp::Elf_types<size>::Elf_Addr address)
619 typedef typename elfcpp::Swap_unaligned<valsize,
620 big_endian>::Valtype Valtype;
621 unsigned char* wv = view;
622 Valtype reloc = (psymval->value(object, addend) - address);
624 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
627 typedef Sparc_relocate_functions<size, big_endian> This;
628 typedef Sparc_relocate_functions<size, true> This_insn;
631 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
633 wdisp30(unsigned char* view,
634 const Sized_relobj_file<size, big_endian>* object,
635 const Symbol_value<size>* psymval,
636 typename elfcpp::Elf_types<size>::Elf_Addr addend,
637 typename elfcpp::Elf_types<size>::Elf_Addr address)
639 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
640 psymval, addend, address);
643 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
645 wdisp22(unsigned char* view,
646 const Sized_relobj_file<size, big_endian>* object,
647 const Symbol_value<size>* psymval,
648 typename elfcpp::Elf_types<size>::Elf_Addr addend,
649 typename elfcpp::Elf_types<size>::Elf_Addr address)
651 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
652 psymval, addend, address);
655 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
657 wdisp19(unsigned char* view,
658 const Sized_relobj_file<size, big_endian>* object,
659 const Symbol_value<size>* psymval,
660 typename elfcpp::Elf_types<size>::Elf_Addr addend,
661 typename elfcpp::Elf_types<size>::Elf_Addr address)
663 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
664 psymval, addend, address);
667 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
669 wdisp16(unsigned char* view,
670 const Sized_relobj_file<size, big_endian>* object,
671 const Symbol_value<size>* psymval,
672 typename elfcpp::Elf_types<size>::Elf_Addr addend,
673 typename elfcpp::Elf_types<size>::Elf_Addr address)
675 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
676 Valtype* wv = reinterpret_cast<Valtype*>(view);
677 Valtype val = elfcpp::Swap<32, true>::readval(wv);
678 Valtype reloc = ((psymval->value(object, addend) - address)
681 // The relocation value is split between the low 14 bits,
683 val &= ~((0x3 << 20) | 0x3fff);
684 reloc = (((reloc & 0xc000) << (20 - 14))
685 | (reloc & 0x3ffff));
687 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
690 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
692 wdisp10(unsigned char* view,
693 const Sized_relobj_file<size, big_endian>* object,
694 const Symbol_value<size>* psymval,
695 typename elfcpp::Elf_types<size>::Elf_Addr addend,
696 typename elfcpp::Elf_types<size>::Elf_Addr address)
698 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
699 Valtype* wv = reinterpret_cast<Valtype*>(view);
700 Valtype val = elfcpp::Swap<32, true>::readval(wv);
701 Valtype reloc = ((psymval->value(object, addend) - address)
704 // The relocation value is split between the low bits 5-12,
705 // and high bits 19-20.
706 val &= ~((0x3 << 19) | (0xff << 5));
707 reloc = (((reloc & 0x300) << (19 - 8))
708 | ((reloc & 0xff) << (5 - 0)));
710 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
713 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
715 pc22(unsigned char* view,
716 const Sized_relobj_file<size, big_endian>* object,
717 const Symbol_value<size>* psymval,
718 typename elfcpp::Elf_types<size>::Elf_Addr addend,
719 typename elfcpp::Elf_types<size>::Elf_Addr address)
721 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
722 psymval, addend, address);
725 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
727 pc10(unsigned char* view,
728 const Sized_relobj_file<size, big_endian>* object,
729 const Symbol_value<size>* psymval,
730 typename elfcpp::Elf_types<size>::Elf_Addr addend,
731 typename elfcpp::Elf_types<size>::Elf_Addr address)
733 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
734 psymval, addend, address);
737 // R_SPARC_HI22: (Symbol + Addend) >> 10
739 hi22(unsigned char* view,
740 typename elfcpp::Elf_types<size>::Elf_Addr value,
741 typename elfcpp::Elf_types<size>::Elf_Addr addend)
743 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
746 // R_SPARC_HI22: (Symbol + Addend) >> 10
748 hi22(unsigned char* view,
749 const Sized_relobj_file<size, big_endian>* object,
750 const Symbol_value<size>* psymval,
751 typename elfcpp::Elf_types<size>::Elf_Addr addend)
753 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
756 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
758 pcplt22(unsigned char* view,
759 const Sized_relobj_file<size, big_endian>* object,
760 const Symbol_value<size>* psymval,
761 typename elfcpp::Elf_types<size>::Elf_Addr addend,
762 typename elfcpp::Elf_types<size>::Elf_Addr address)
764 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
765 psymval, addend, address);
768 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
770 lo10(unsigned char* view,
771 typename elfcpp::Elf_types<size>::Elf_Addr value,
772 typename elfcpp::Elf_types<size>::Elf_Addr addend)
774 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
777 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
779 lo10(unsigned char* view,
780 const Sized_relobj_file<size, big_endian>* object,
781 const Symbol_value<size>* psymval,
782 typename elfcpp::Elf_types<size>::Elf_Addr addend)
784 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
787 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
789 lo10(unsigned char* view,
790 const Sized_relobj_file<size, big_endian>* object,
791 const Symbol_value<size>* psymval,
792 typename elfcpp::Elf_types<size>::Elf_Addr addend,
793 typename elfcpp::Elf_types<size>::Elf_Addr address)
795 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
796 psymval, addend, address);
799 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
801 olo10(unsigned char* view,
802 const Sized_relobj_file<size, big_endian>* object,
803 const Symbol_value<size>* psymval,
804 typename elfcpp::Elf_types<size>::Elf_Addr addend,
805 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
807 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
808 Valtype* wv = reinterpret_cast<Valtype*>(view);
809 Valtype val = elfcpp::Swap<32, true>::readval(wv);
810 Valtype reloc = psymval->value(object, addend);
817 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
820 // R_SPARC_22: (Symbol + Addend)
822 rela32_22(unsigned char* view,
823 const Sized_relobj_file<size, big_endian>* object,
824 const Symbol_value<size>* psymval,
825 typename elfcpp::Elf_types<size>::Elf_Addr addend)
827 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
830 // R_SPARC_13: (Symbol + Addend)
832 rela32_13(unsigned char* view,
833 typename elfcpp::Elf_types<size>::Elf_Addr value,
834 typename elfcpp::Elf_types<size>::Elf_Addr addend)
836 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
839 // R_SPARC_13: (Symbol + Addend)
841 rela32_13(unsigned char* view,
842 const Sized_relobj_file<size, big_endian>* object,
843 const Symbol_value<size>* psymval,
844 typename elfcpp::Elf_types<size>::Elf_Addr addend)
846 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
849 // R_SPARC_UA16: (Symbol + Addend)
851 ua16(unsigned char* view,
852 const Sized_relobj_file<size, big_endian>* object,
853 const Symbol_value<size>* psymval,
854 typename elfcpp::Elf_types<size>::Elf_Addr addend)
856 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
859 // R_SPARC_UA32: (Symbol + Addend)
861 ua32(unsigned char* view,
862 const Sized_relobj_file<size, big_endian>* object,
863 const Symbol_value<size>* psymval,
864 typename elfcpp::Elf_types<size>::Elf_Addr addend)
866 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
869 // R_SPARC_UA64: (Symbol + Addend)
871 ua64(unsigned char* view,
872 const Sized_relobj_file<size, big_endian>* object,
873 const Symbol_value<size>* psymval,
874 typename elfcpp::Elf_types<size>::Elf_Addr addend)
876 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
877 object, psymval, addend);
880 // R_SPARC_DISP8: (Symbol + Addend - Address)
882 disp8(unsigned char* view,
883 const Sized_relobj_file<size, big_endian>* object,
884 const Symbol_value<size>* psymval,
885 typename elfcpp::Elf_types<size>::Elf_Addr addend,
886 typename elfcpp::Elf_types<size>::Elf_Addr address)
888 This::template pcrela_unaligned<8>(view, object, psymval,
892 // R_SPARC_DISP16: (Symbol + Addend - Address)
894 disp16(unsigned char* view,
895 const Sized_relobj_file<size, big_endian>* object,
896 const Symbol_value<size>* psymval,
897 typename elfcpp::Elf_types<size>::Elf_Addr addend,
898 typename elfcpp::Elf_types<size>::Elf_Addr address)
900 This::template pcrela_unaligned<16>(view, object, psymval,
904 // R_SPARC_DISP32: (Symbol + Addend - Address)
906 disp32(unsigned char* view,
907 const Sized_relobj_file<size, big_endian>* object,
908 const Symbol_value<size>* psymval,
909 typename elfcpp::Elf_types<size>::Elf_Addr addend,
910 typename elfcpp::Elf_types<size>::Elf_Addr address)
912 This::template pcrela_unaligned<32>(view, object, psymval,
916 // R_SPARC_DISP64: (Symbol + Addend - Address)
918 disp64(unsigned char* view,
919 const Sized_relobj_file<size, big_endian>* object,
920 const Symbol_value<size>* psymval,
921 elfcpp::Elf_Xword addend,
922 typename elfcpp::Elf_types<size>::Elf_Addr address)
924 This::template pcrela_unaligned<64>(view, object, psymval,
928 // R_SPARC_H34: (Symbol + Addend) >> 12
930 h34(unsigned char* view,
931 const Sized_relobj_file<size, big_endian>* object,
932 const Symbol_value<size>* psymval,
933 typename elfcpp::Elf_types<size>::Elf_Addr addend)
935 This_insn::template rela<32>(view, 12, 0x003fffff, object, psymval, addend);
938 // R_SPARC_H44: (Symbol + Addend) >> 22
940 h44(unsigned char* view,
941 const Sized_relobj_file<size, big_endian>* object,
942 const Symbol_value<size>* psymval,
943 typename elfcpp::Elf_types<size>::Elf_Addr addend)
945 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
948 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
950 m44(unsigned char* view,
951 const Sized_relobj_file<size, big_endian>* object,
952 const Symbol_value<size>* psymval,
953 typename elfcpp::Elf_types<size>::Elf_Addr addend)
955 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
958 // R_SPARC_L44: (Symbol + Addend) & 0xfff
960 l44(unsigned char* view,
961 const Sized_relobj_file<size, big_endian>* object,
962 const Symbol_value<size>* psymval,
963 typename elfcpp::Elf_types<size>::Elf_Addr addend)
965 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
968 // R_SPARC_HH22: (Symbol + Addend) >> 42
970 hh22(unsigned char* view,
971 const Sized_relobj_file<size, big_endian>* object,
972 const Symbol_value<size>* psymval,
973 typename elfcpp::Elf_types<size>::Elf_Addr addend)
975 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
978 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
980 pc_hh22(unsigned char* view,
981 const Sized_relobj_file<size, big_endian>* object,
982 const Symbol_value<size>* psymval,
983 typename elfcpp::Elf_types<size>::Elf_Addr addend,
984 typename elfcpp::Elf_types<size>::Elf_Addr address)
986 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
987 psymval, addend, address);
990 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
992 hm10(unsigned char* view,
993 const Sized_relobj_file<size, big_endian>* object,
994 const Symbol_value<size>* psymval,
995 typename elfcpp::Elf_types<size>::Elf_Addr addend)
997 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
1000 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
1002 pc_hm10(unsigned char* view,
1003 const Sized_relobj_file<size, big_endian>* object,
1004 const Symbol_value<size>* psymval,
1005 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1006 typename elfcpp::Elf_types<size>::Elf_Addr address)
1008 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
1009 psymval, addend, address);
1012 // R_SPARC_11: (Symbol + Addend)
1014 rela32_11(unsigned char* view,
1015 const Sized_relobj_file<size, big_endian>* object,
1016 const Symbol_value<size>* psymval,
1017 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1019 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
1022 // R_SPARC_10: (Symbol + Addend)
1024 rela32_10(unsigned char* view,
1025 const Sized_relobj_file<size, big_endian>* object,
1026 const Symbol_value<size>* psymval,
1027 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1029 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
1032 // R_SPARC_7: (Symbol + Addend)
1034 rela32_7(unsigned char* view,
1035 const Sized_relobj_file<size, big_endian>* object,
1036 const Symbol_value<size>* psymval,
1037 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1039 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
1042 // R_SPARC_6: (Symbol + Addend)
1044 rela32_6(unsigned char* view,
1045 const Sized_relobj_file<size, big_endian>* object,
1046 const Symbol_value<size>* psymval,
1047 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1049 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
1052 // R_SPARC_5: (Symbol + Addend)
1054 rela32_5(unsigned char* view,
1055 const Sized_relobj_file<size, big_endian>* object,
1056 const Symbol_value<size>* psymval,
1057 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1059 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
1062 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1064 ldo_hix22(unsigned char* view,
1065 typename elfcpp::Elf_types<size>::Elf_Addr value,
1066 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1068 This_insn::hi22(view, value, addend);
1071 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1073 ldo_lox10(unsigned char* view,
1074 typename elfcpp::Elf_types<size>::Elf_Addr value,
1075 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1077 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1078 Valtype* wv = reinterpret_cast<Valtype*>(view);
1079 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1080 Valtype reloc = (value + addend);
1085 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1088 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1090 hix22(unsigned char* view,
1091 typename elfcpp::Elf_types<size>::Elf_Addr value,
1092 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1094 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1095 Valtype* wv = reinterpret_cast<Valtype*>(view);
1096 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1097 Valtype reloc = (value + addend);
1101 reloc ^= ~(Valtype)0;
1106 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1109 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1111 gdop_hix22(unsigned char* view,
1112 typename elfcpp::Elf_types<size>::Elf_Addr value,
1113 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1115 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1116 Valtype* wv = reinterpret_cast<Valtype*>(view);
1117 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1118 int32_t reloc = static_cast<int32_t>(value + addend);
1123 reloc ^= ~static_cast<int32_t>(0);
1128 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1131 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1133 hix22(unsigned char* view,
1134 const Sized_relobj_file<size, big_endian>* object,
1135 const Symbol_value<size>* psymval,
1136 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1138 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1139 Valtype* wv = reinterpret_cast<Valtype*>(view);
1140 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1141 Valtype reloc = psymval->value(object, addend);
1145 reloc ^= ~(Valtype)0;
1150 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1154 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1156 lox10(unsigned char* view,
1157 typename elfcpp::Elf_types<size>::Elf_Addr value,
1158 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1160 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1161 Valtype* wv = reinterpret_cast<Valtype*>(view);
1162 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1163 Valtype reloc = (value + addend);
1169 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1172 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1174 gdop_lox10(unsigned char* view,
1175 typename elfcpp::Elf_types<size>::Elf_Addr value,
1176 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1178 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1179 Valtype* wv = reinterpret_cast<Valtype*>(view);
1180 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1181 int32_t reloc = static_cast<int32_t>(value + addend);
1184 reloc = (reloc & 0x3ff) | 0x1c00;
1186 reloc = (reloc & 0x3ff);
1189 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1192 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1194 lox10(unsigned char* view,
1195 const Sized_relobj_file<size, big_endian>* object,
1196 const Symbol_value<size>* psymval,
1197 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1199 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1200 Valtype* wv = reinterpret_cast<Valtype*>(view);
1201 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1202 Valtype reloc = psymval->value(object, addend);
1208 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1212 // Get the GOT section, creating it if necessary.
1214 template<int size, bool big_endian>
1215 Output_data_got<size, big_endian>*
1216 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
1219 if (this->got_ == NULL)
1221 gold_assert(symtab != NULL && layout != NULL);
1223 this->got_ = new Output_data_got<size, big_endian>();
1225 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1227 | elfcpp::SHF_WRITE),
1228 this->got_, ORDER_RELRO, true);
1230 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1231 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1232 Symbol_table::PREDEFINED,
1234 0, 0, elfcpp::STT_OBJECT,
1236 elfcpp::STV_HIDDEN, 0,
1243 // Get the dynamic reloc section, creating it if necessary.
1245 template<int size, bool big_endian>
1246 typename Target_sparc<size, big_endian>::Reloc_section*
1247 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1249 if (this->rela_dyn_ == NULL)
1251 gold_assert(layout != NULL);
1252 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1253 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1254 elfcpp::SHF_ALLOC, this->rela_dyn_,
1255 ORDER_DYNAMIC_RELOCS, false);
1257 return this->rela_dyn_;
1260 // Get the section to use for IFUNC relocs, creating it if
1261 // necessary. These go in .rela.dyn, but only after all other dynamic
1262 // relocations. They need to follow the other dynamic relocations so
1263 // that they can refer to global variables initialized by those
1266 template<int size, bool big_endian>
1267 typename Target_sparc<size, big_endian>::Reloc_section*
1268 Target_sparc<size, big_endian>::rela_ifunc_section(Layout* layout)
1270 if (this->rela_ifunc_ == NULL)
1272 // Make sure we have already created the dynamic reloc section.
1273 this->rela_dyn_section(layout);
1274 this->rela_ifunc_ = new Reloc_section(false);
1275 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1276 elfcpp::SHF_ALLOC, this->rela_ifunc_,
1277 ORDER_DYNAMIC_RELOCS, false);
1278 gold_assert(this->rela_dyn_->output_section()
1279 == this->rela_ifunc_->output_section());
1281 return this->rela_ifunc_;
1284 // A class to handle the PLT data.
1286 template<int size, bool big_endian>
1287 class Output_data_plt_sparc : public Output_section_data
1290 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1291 size, big_endian> Reloc_section;
1293 Output_data_plt_sparc(Layout*);
1295 // Add an entry to the PLT.
1296 void add_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym);
1298 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1300 add_local_ifunc_entry(Symbol_table*, Layout*,
1301 Sized_relobj_file<size, big_endian>* relobj,
1302 unsigned int local_sym_index);
1304 // Return the .rela.plt section data.
1305 const Reloc_section* rel_plt() const
1310 // Return where the IFUNC relocations should go.
1312 rela_ifunc(Symbol_table*, Layout*);
1315 emit_pending_ifunc_relocs();
1317 // Return whether we created a section for IFUNC relocations.
1319 has_ifunc_section() const
1320 { return this->ifunc_rel_ != NULL; }
1322 // Return the number of PLT entries.
1325 { return this->count_ + this->ifunc_count_; }
1327 // Return the offset of the first non-reserved PLT entry.
1329 first_plt_entry_offset()
1330 { return 4 * base_plt_entry_size; }
1332 // Return the size of a PLT entry.
1334 get_plt_entry_size()
1335 { return base_plt_entry_size; }
1337 // Return the PLT address to use for a global symbol.
1339 address_for_global(const Symbol*);
1341 // Return the PLT address to use for a local symbol.
1343 address_for_local(const Relobj*, unsigned int symndx);
1346 void do_adjust_output_section(Output_section* os);
1348 // Write to a map file.
1350 do_print_to_mapfile(Mapfile* mapfile) const
1351 { mapfile->print_output_data(this, _("** PLT")); }
1354 // The size of an entry in the PLT.
1355 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1357 static const unsigned int plt_entries_per_block = 160;
1358 static const unsigned int plt_insn_chunk_size = 24;
1359 static const unsigned int plt_pointer_chunk_size = 8;
1360 static const unsigned int plt_block_size =
1361 (plt_entries_per_block
1362 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1365 plt_index_to_offset(unsigned int index)
1367 section_offset_type offset;
1369 if (size == 32 || index < 32768)
1370 offset = index * base_plt_entry_size;
1373 unsigned int ext_index = index - 32768;
1375 offset = (32768 * base_plt_entry_size)
1376 + ((ext_index / plt_entries_per_block)
1378 + ((ext_index % plt_entries_per_block)
1379 * plt_insn_chunk_size);
1384 // Set the final size.
1386 set_final_data_size()
1388 unsigned int full_count = this->entry_count() + 4;
1389 unsigned int extra = (size == 32 ? 4 : 0);
1390 section_offset_type sz = plt_index_to_offset(full_count) + extra;
1392 return this->set_data_size(sz);
1395 // Write out the PLT data.
1397 do_write(Output_file*);
1403 unsigned int plt_index;
1409 Sized_relobj_file<size, big_endian>* object;
1410 unsigned int local_sym_index;
1411 unsigned int plt_index;
1414 // The reloc section.
1415 Reloc_section* rel_;
1416 // The IFUNC relocations, if necessary. These must follow the
1417 // regular relocations.
1418 Reloc_section* ifunc_rel_;
1419 // The number of PLT entries.
1420 unsigned int count_;
1421 // The number of PLT entries for IFUNC symbols.
1422 unsigned int ifunc_count_;
1423 // Global STT_GNU_IFUNC symbols.
1424 std::vector<Global_ifunc> global_ifuncs_;
1425 // Local STT_GNU_IFUNC symbols.
1426 std::vector<Local_ifunc> local_ifuncs_;
1429 // Define the constants as required by C++ standard.
1431 template<int size, bool big_endian>
1432 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1434 template<int size, bool big_endian>
1436 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1438 template<int size, bool big_endian>
1439 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1441 template<int size, bool big_endian>
1443 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1445 template<int size, bool big_endian>
1446 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1448 // Create the PLT section. The ordinary .got section is an argument,
1449 // since we need to refer to the start.
1451 template<int size, bool big_endian>
1452 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1453 : Output_section_data(size == 32 ? 4 : 8), ifunc_rel_(NULL),
1454 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1456 this->rel_ = new Reloc_section(false);
1457 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1458 elfcpp::SHF_ALLOC, this->rel_,
1459 ORDER_DYNAMIC_PLT_RELOCS, false);
1462 template<int size, bool big_endian>
1464 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1469 // Add an entry to the PLT.
1471 template<int size, bool big_endian>
1473 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol_table* symtab,
1477 gold_assert(!gsym->has_plt_offset());
1479 section_offset_type plt_offset;
1482 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1483 && gsym->can_use_relative_reloc(false))
1485 index = this->ifunc_count_;
1486 plt_offset = plt_index_to_offset(index);
1487 gsym->set_plt_offset(plt_offset);
1488 ++this->ifunc_count_;
1489 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1491 struct Global_ifunc gi;
1494 gi.plt_index = index;
1495 this->global_ifuncs_.push_back(gi);
1499 plt_offset = plt_index_to_offset(this->count_ + 4);
1500 gsym->set_plt_offset(plt_offset);
1502 gsym->set_needs_dynsym_entry();
1503 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1507 // Note that we don't need to save the symbol. The contents of the
1508 // PLT are independent of which symbols are used. The symbols only
1509 // appear in the relocations.
1512 template<int size, bool big_endian>
1514 Output_data_plt_sparc<size, big_endian>::add_local_ifunc_entry(
1515 Symbol_table* symtab,
1517 Sized_relobj_file<size, big_endian>* relobj,
1518 unsigned int local_sym_index)
1520 unsigned int index = this->ifunc_count_;
1521 section_offset_type plt_offset;
1523 plt_offset = plt_index_to_offset(index);
1524 ++this->ifunc_count_;
1526 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1528 struct Local_ifunc li;
1531 li.local_sym_index = local_sym_index;
1532 li.plt_index = index;
1533 this->local_ifuncs_.push_back(li);
1538 // Emit any pending IFUNC plt relocations.
1540 template<int size, bool big_endian>
1542 Output_data_plt_sparc<size, big_endian>::emit_pending_ifunc_relocs()
1544 // Emit any pending IFUNC relocs.
1545 for (typename std::vector<Global_ifunc>::const_iterator p =
1546 this->global_ifuncs_.begin();
1547 p != this->global_ifuncs_.end();
1550 section_offset_type plt_offset;
1553 index = this->count_ + p->plt_index + 4;
1554 plt_offset = this->plt_index_to_offset(index);
1555 p->rel->add_symbolless_global_addend(p->gsym, elfcpp::R_SPARC_JMP_IREL,
1556 this, plt_offset, 0);
1559 for (typename std::vector<Local_ifunc>::const_iterator p =
1560 this->local_ifuncs_.begin();
1561 p != this->local_ifuncs_.end();
1564 section_offset_type plt_offset;
1567 index = this->count_ + p->plt_index + 4;
1568 plt_offset = this->plt_index_to_offset(index);
1569 p->rel->add_symbolless_local_addend(p->object, p->local_sym_index,
1570 elfcpp::R_SPARC_JMP_IREL,
1571 this, plt_offset, 0);
1575 // Return where the IFUNC relocations should go in the PLT. These
1576 // follow the non-IFUNC relocations.
1578 template<int size, bool big_endian>
1579 typename Output_data_plt_sparc<size, big_endian>::Reloc_section*
1580 Output_data_plt_sparc<size, big_endian>::rela_ifunc(
1581 Symbol_table* symtab,
1584 if (this->ifunc_rel_ == NULL)
1586 this->ifunc_rel_ = new Reloc_section(false);
1587 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1588 elfcpp::SHF_ALLOC, this->ifunc_rel_,
1589 ORDER_DYNAMIC_PLT_RELOCS, false);
1590 gold_assert(this->ifunc_rel_->output_section()
1591 == this->rel_->output_section());
1593 if (parameters->doing_static_link())
1595 // A statically linked executable will only have a .rel.plt
1596 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1597 // relocs for STT_GNU_IFUNC symbols. The library will use
1598 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1599 // at program startup time.
1600 symtab->define_in_output_data("__rela_iplt_start", NULL,
1601 Symbol_table::PREDEFINED,
1602 this->ifunc_rel_, 0, 0,
1603 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1604 elfcpp::STV_HIDDEN, 0, false, true);
1605 symtab->define_in_output_data("__rela_iplt_end", NULL,
1606 Symbol_table::PREDEFINED,
1607 this->ifunc_rel_, 0, 0,
1608 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1609 elfcpp::STV_HIDDEN, 0, true, true);
1612 return this->ifunc_rel_;
1615 // Return the PLT address to use for a global symbol.
1617 template<int size, bool big_endian>
1619 Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
1621 uint64_t offset = 0;
1622 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1623 && gsym->can_use_relative_reloc(false))
1624 offset = plt_index_to_offset(this->count_ + 4);
1625 return this->address() + offset + gsym->plt_offset();
1628 // Return the PLT address to use for a local symbol. These are always
1629 // IRELATIVE relocs.
1631 template<int size, bool big_endian>
1633 Output_data_plt_sparc<size, big_endian>::address_for_local(
1634 const Relobj* object,
1637 return (this->address()
1638 + plt_index_to_offset(this->count_ + 4)
1639 + object->local_plt_offset(r_sym));
1642 static const unsigned int sparc_nop = 0x01000000;
1643 static const unsigned int sparc_sethi_g1 = 0x03000000;
1644 static const unsigned int sparc_branch_always = 0x30800000;
1645 static const unsigned int sparc_branch_always_pt = 0x30680000;
1646 static const unsigned int sparc_mov = 0x80100000;
1647 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1648 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1649 static const unsigned int sparc_call_plus_8 = 0x40000002;
1650 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1651 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1652 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1654 // Write out the PLT.
1656 template<int size, bool big_endian>
1658 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1660 const off_t offset = this->offset();
1661 const section_size_type oview_size =
1662 convert_to_section_size_type(this->data_size());
1663 unsigned char* const oview = of->get_output_view(offset, oview_size);
1664 unsigned char* pov = oview;
1666 memset(pov, 0, base_plt_entry_size * 4);
1667 pov += this->first_plt_entry_offset();
1669 unsigned int plt_offset = base_plt_entry_size * 4;
1670 const unsigned int count = this->entry_count();
1676 limit = (count > 32768 ? 32768 : count);
1678 for (unsigned int i = 0; i < limit; ++i)
1680 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1681 sparc_sethi_g1 + plt_offset);
1682 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1683 sparc_branch_always_pt +
1684 (((base_plt_entry_size -
1685 (plt_offset + 4)) >> 2) &
1687 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1688 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1689 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1690 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1691 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1692 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1694 pov += base_plt_entry_size;
1695 plt_offset += base_plt_entry_size;
1700 unsigned int ext_cnt = count - 32768;
1701 unsigned int blks = ext_cnt / plt_entries_per_block;
1703 for (unsigned int i = 0; i < blks; ++i)
1705 unsigned int data_off = (plt_entries_per_block
1706 * plt_insn_chunk_size) - 4;
1708 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1710 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1712 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1714 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1716 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1717 sparc_ldx_o7_imm_g1 +
1718 (data_off & 0x1fff));
1719 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1720 sparc_jmpl_o7_g1_g1);
1721 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1724 elfcpp::Swap<64, big_endian>::writeval(
1725 pov + 0x4 + data_off,
1726 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1728 pov += plt_insn_chunk_size;
1733 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1734 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1736 unsigned int data_off = (sub_blk_cnt
1737 * plt_insn_chunk_size) - 4;
1739 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1741 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1743 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1745 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1747 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1748 sparc_ldx_o7_imm_g1 +
1749 (data_off & 0x1fff));
1750 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1751 sparc_jmpl_o7_g1_g1);
1752 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1755 elfcpp::Swap<64, big_endian>::writeval(
1756 pov + 0x4 + data_off,
1757 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1759 pov += plt_insn_chunk_size;
1767 for (unsigned int i = 0; i < count; ++i)
1769 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1770 sparc_sethi_g1 + plt_offset);
1771 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1772 sparc_branch_always +
1773 (((- (plt_offset + 4)) >> 2) &
1775 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1777 pov += base_plt_entry_size;
1778 plt_offset += base_plt_entry_size;
1781 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1785 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1787 of->write_output_view(offset, oview_size, oview);
1790 // Create the PLT section.
1792 template<int size, bool big_endian>
1794 Target_sparc<size, big_endian>::make_plt_section(Symbol_table* symtab,
1797 // Create the GOT sections first.
1798 this->got_section(symtab, layout);
1800 // Ensure that .rela.dyn always appears before .rela.plt This is
1801 // necessary due to how, on Sparc and some other targets, .rela.dyn
1802 // needs to include .rela.plt in it's range.
1803 this->rela_dyn_section(layout);
1805 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1806 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1808 | elfcpp::SHF_EXECINSTR
1809 | elfcpp::SHF_WRITE),
1810 this->plt_, ORDER_NON_RELRO_FIRST, false);
1812 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1813 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1814 Symbol_table::PREDEFINED,
1816 0, 0, elfcpp::STT_OBJECT,
1818 elfcpp::STV_HIDDEN, 0,
1822 // Create a PLT entry for a global symbol.
1824 template<int size, bool big_endian>
1826 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1830 if (gsym->has_plt_offset())
1833 if (this->plt_ == NULL)
1834 this->make_plt_section(symtab, layout);
1836 this->plt_->add_entry(symtab, layout, gsym);
1839 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1841 template<int size, bool big_endian>
1843 Target_sparc<size, big_endian>::make_local_ifunc_plt_entry(
1844 Symbol_table* symtab,
1846 Sized_relobj_file<size, big_endian>* relobj,
1847 unsigned int local_sym_index)
1849 if (relobj->local_has_plt_offset(local_sym_index))
1851 if (this->plt_ == NULL)
1852 this->make_plt_section(symtab, layout);
1853 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1856 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1859 // Return the number of entries in the PLT.
1861 template<int size, bool big_endian>
1863 Target_sparc<size, big_endian>::plt_entry_count() const
1865 if (this->plt_ == NULL)
1867 return this->plt_->entry_count();
1870 // Return the offset of the first non-reserved PLT entry.
1872 template<int size, bool big_endian>
1874 Target_sparc<size, big_endian>::first_plt_entry_offset() const
1876 return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset();
1879 // Return the size of each PLT entry.
1881 template<int size, bool big_endian>
1883 Target_sparc<size, big_endian>::plt_entry_size() const
1885 return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size();
1888 // Create a GOT entry for the TLS module index.
1890 template<int size, bool big_endian>
1892 Target_sparc<size, big_endian>::got_mod_index_entry(
1893 Symbol_table* symtab,
1895 Sized_relobj_file<size, big_endian>* object)
1897 if (this->got_mod_index_offset_ == -1U)
1899 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1900 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1901 Output_data_got<size, big_endian>* got;
1902 unsigned int got_offset;
1904 got = this->got_section(symtab, layout);
1905 got_offset = got->add_constant(0);
1906 rela_dyn->add_local(object, 0,
1908 elfcpp::R_SPARC_TLS_DTPMOD64 :
1909 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1911 got->add_constant(0);
1912 this->got_mod_index_offset_ = got_offset;
1914 return this->got_mod_index_offset_;
1917 // Optimize the TLS relocation type based on what we know about the
1918 // symbol. IS_FINAL is true if the final address of this symbol is
1919 // known at link time.
1921 static tls::Tls_optimization
1922 optimize_tls_reloc(bool is_final, int r_type)
1924 // If we are generating a shared library, then we can't do anything
1926 if (parameters->options().shared())
1927 return tls::TLSOPT_NONE;
1931 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1932 case elfcpp::R_SPARC_TLS_GD_LO10:
1933 case elfcpp::R_SPARC_TLS_GD_ADD:
1934 case elfcpp::R_SPARC_TLS_GD_CALL:
1935 // These are General-Dynamic which permits fully general TLS
1936 // access. Since we know that we are generating an executable,
1937 // we can convert this to Initial-Exec. If we also know that
1938 // this is a local symbol, we can further switch to Local-Exec.
1940 return tls::TLSOPT_TO_LE;
1941 return tls::TLSOPT_TO_IE;
1943 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1944 case elfcpp::R_SPARC_TLS_LDM_LO10:
1945 case elfcpp::R_SPARC_TLS_LDM_ADD:
1946 case elfcpp::R_SPARC_TLS_LDM_CALL:
1947 // This is Local-Dynamic, which refers to a local symbol in the
1948 // dynamic TLS block. Since we know that we generating an
1949 // executable, we can switch to Local-Exec.
1950 return tls::TLSOPT_TO_LE;
1952 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1953 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1954 case elfcpp::R_SPARC_TLS_LDO_ADD:
1955 // Another type of Local-Dynamic relocation.
1956 return tls::TLSOPT_TO_LE;
1958 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1959 case elfcpp::R_SPARC_TLS_IE_LO10:
1960 case elfcpp::R_SPARC_TLS_IE_LD:
1961 case elfcpp::R_SPARC_TLS_IE_LDX:
1962 case elfcpp::R_SPARC_TLS_IE_ADD:
1963 // These are Initial-Exec relocs which get the thread offset
1964 // from the GOT. If we know that we are linking against the
1965 // local symbol, we can switch to Local-Exec, which links the
1966 // thread offset into the instruction.
1968 return tls::TLSOPT_TO_LE;
1969 return tls::TLSOPT_NONE;
1971 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1972 case elfcpp::R_SPARC_TLS_LE_LOX10:
1973 // When we already have Local-Exec, there is nothing further we
1975 return tls::TLSOPT_NONE;
1982 // Get the Reference_flags for a particular relocation.
1984 template<int size, bool big_endian>
1986 Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
1991 case elfcpp::R_SPARC_NONE:
1992 case elfcpp::R_SPARC_REGISTER:
1993 case elfcpp::R_SPARC_GNU_VTINHERIT:
1994 case elfcpp::R_SPARC_GNU_VTENTRY:
1995 // No symbol reference.
1998 case elfcpp::R_SPARC_UA64:
1999 case elfcpp::R_SPARC_64:
2000 case elfcpp::R_SPARC_HIX22:
2001 case elfcpp::R_SPARC_LOX10:
2002 case elfcpp::R_SPARC_H34:
2003 case elfcpp::R_SPARC_H44:
2004 case elfcpp::R_SPARC_M44:
2005 case elfcpp::R_SPARC_L44:
2006 case elfcpp::R_SPARC_HH22:
2007 case elfcpp::R_SPARC_HM10:
2008 case elfcpp::R_SPARC_LM22:
2009 case elfcpp::R_SPARC_HI22:
2010 case elfcpp::R_SPARC_LO10:
2011 case elfcpp::R_SPARC_OLO10:
2012 case elfcpp::R_SPARC_UA32:
2013 case elfcpp::R_SPARC_32:
2014 case elfcpp::R_SPARC_UA16:
2015 case elfcpp::R_SPARC_16:
2016 case elfcpp::R_SPARC_11:
2017 case elfcpp::R_SPARC_10:
2018 case elfcpp::R_SPARC_8:
2019 case elfcpp::R_SPARC_7:
2020 case elfcpp::R_SPARC_6:
2021 case elfcpp::R_SPARC_5:
2022 return Symbol::ABSOLUTE_REF;
2024 case elfcpp::R_SPARC_DISP8:
2025 case elfcpp::R_SPARC_DISP16:
2026 case elfcpp::R_SPARC_DISP32:
2027 case elfcpp::R_SPARC_DISP64:
2028 case elfcpp::R_SPARC_PC_HH22:
2029 case elfcpp::R_SPARC_PC_HM10:
2030 case elfcpp::R_SPARC_PC_LM22:
2031 case elfcpp::R_SPARC_PC10:
2032 case elfcpp::R_SPARC_PC22:
2033 case elfcpp::R_SPARC_WDISP30:
2034 case elfcpp::R_SPARC_WDISP22:
2035 case elfcpp::R_SPARC_WDISP19:
2036 case elfcpp::R_SPARC_WDISP16:
2037 case elfcpp::R_SPARC_WDISP10:
2038 return Symbol::RELATIVE_REF;
2040 case elfcpp::R_SPARC_PLT64:
2041 case elfcpp::R_SPARC_PLT32:
2042 case elfcpp::R_SPARC_HIPLT22:
2043 case elfcpp::R_SPARC_LOPLT10:
2044 case elfcpp::R_SPARC_PCPLT10:
2045 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
2047 case elfcpp::R_SPARC_PCPLT32:
2048 case elfcpp::R_SPARC_PCPLT22:
2049 case elfcpp::R_SPARC_WPLT30:
2050 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2052 case elfcpp::R_SPARC_GOTDATA_OP:
2053 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2054 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2055 case elfcpp::R_SPARC_GOT10:
2056 case elfcpp::R_SPARC_GOT13:
2057 case elfcpp::R_SPARC_GOT22:
2059 return Symbol::ABSOLUTE_REF;
2061 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2062 case elfcpp::R_SPARC_TLS_GD_LO10:
2063 case elfcpp::R_SPARC_TLS_GD_ADD:
2064 case elfcpp::R_SPARC_TLS_GD_CALL:
2065 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2066 case elfcpp::R_SPARC_TLS_LDM_LO10:
2067 case elfcpp::R_SPARC_TLS_LDM_ADD:
2068 case elfcpp::R_SPARC_TLS_LDM_CALL:
2069 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2070 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2071 case elfcpp::R_SPARC_TLS_LDO_ADD:
2072 case elfcpp::R_SPARC_TLS_LE_HIX22:
2073 case elfcpp::R_SPARC_TLS_LE_LOX10:
2074 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2075 case elfcpp::R_SPARC_TLS_IE_LO10:
2076 case elfcpp::R_SPARC_TLS_IE_LD:
2077 case elfcpp::R_SPARC_TLS_IE_LDX:
2078 case elfcpp::R_SPARC_TLS_IE_ADD:
2079 return Symbol::TLS_REF;
2081 case elfcpp::R_SPARC_COPY:
2082 case elfcpp::R_SPARC_GLOB_DAT:
2083 case elfcpp::R_SPARC_JMP_SLOT:
2084 case elfcpp::R_SPARC_JMP_IREL:
2085 case elfcpp::R_SPARC_RELATIVE:
2086 case elfcpp::R_SPARC_IRELATIVE:
2087 case elfcpp::R_SPARC_TLS_DTPMOD64:
2088 case elfcpp::R_SPARC_TLS_DTPMOD32:
2089 case elfcpp::R_SPARC_TLS_DTPOFF64:
2090 case elfcpp::R_SPARC_TLS_DTPOFF32:
2091 case elfcpp::R_SPARC_TLS_TPOFF64:
2092 case elfcpp::R_SPARC_TLS_TPOFF32:
2094 // Not expected. We will give an error later.
2099 // Generate a PLT entry slot for a call to __tls_get_addr
2100 template<int size, bool big_endian>
2102 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
2104 Target_sparc<size, big_endian>* target)
2106 Symbol* gsym = target->tls_get_addr_sym(symtab);
2108 target->make_plt_entry(symtab, layout, gsym);
2111 // Report an unsupported relocation against a local symbol.
2113 template<int size, bool big_endian>
2115 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
2116 Sized_relobj_file<size, big_endian>* object,
2117 unsigned int r_type)
2119 gold_error(_("%s: unsupported reloc %u against local symbol"),
2120 object->name().c_str(), r_type);
2123 // We are about to emit a dynamic relocation of type R_TYPE. If the
2124 // dynamic linker does not support it, issue an error.
2126 template<int size, bool big_endian>
2128 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2130 gold_assert(r_type != elfcpp::R_SPARC_NONE);
2136 // These are the relocation types supported by glibc for sparc 64-bit.
2137 case elfcpp::R_SPARC_RELATIVE:
2138 case elfcpp::R_SPARC_IRELATIVE:
2139 case elfcpp::R_SPARC_COPY:
2140 case elfcpp::R_SPARC_64:
2141 case elfcpp::R_SPARC_GLOB_DAT:
2142 case elfcpp::R_SPARC_JMP_SLOT:
2143 case elfcpp::R_SPARC_JMP_IREL:
2144 case elfcpp::R_SPARC_TLS_DTPMOD64:
2145 case elfcpp::R_SPARC_TLS_DTPOFF64:
2146 case elfcpp::R_SPARC_TLS_TPOFF64:
2147 case elfcpp::R_SPARC_TLS_LE_HIX22:
2148 case elfcpp::R_SPARC_TLS_LE_LOX10:
2149 case elfcpp::R_SPARC_8:
2150 case elfcpp::R_SPARC_16:
2151 case elfcpp::R_SPARC_DISP8:
2152 case elfcpp::R_SPARC_DISP16:
2153 case elfcpp::R_SPARC_DISP32:
2154 case elfcpp::R_SPARC_WDISP30:
2155 case elfcpp::R_SPARC_LO10:
2156 case elfcpp::R_SPARC_HI22:
2157 case elfcpp::R_SPARC_OLO10:
2158 case elfcpp::R_SPARC_H34:
2159 case elfcpp::R_SPARC_H44:
2160 case elfcpp::R_SPARC_M44:
2161 case elfcpp::R_SPARC_L44:
2162 case elfcpp::R_SPARC_HH22:
2163 case elfcpp::R_SPARC_HM10:
2164 case elfcpp::R_SPARC_LM22:
2165 case elfcpp::R_SPARC_UA16:
2166 case elfcpp::R_SPARC_UA32:
2167 case elfcpp::R_SPARC_UA64:
2178 // These are the relocation types supported by glibc for sparc 32-bit.
2179 case elfcpp::R_SPARC_RELATIVE:
2180 case elfcpp::R_SPARC_IRELATIVE:
2181 case elfcpp::R_SPARC_COPY:
2182 case elfcpp::R_SPARC_GLOB_DAT:
2183 case elfcpp::R_SPARC_32:
2184 case elfcpp::R_SPARC_JMP_SLOT:
2185 case elfcpp::R_SPARC_JMP_IREL:
2186 case elfcpp::R_SPARC_TLS_DTPMOD32:
2187 case elfcpp::R_SPARC_TLS_DTPOFF32:
2188 case elfcpp::R_SPARC_TLS_TPOFF32:
2189 case elfcpp::R_SPARC_TLS_LE_HIX22:
2190 case elfcpp::R_SPARC_TLS_LE_LOX10:
2191 case elfcpp::R_SPARC_8:
2192 case elfcpp::R_SPARC_16:
2193 case elfcpp::R_SPARC_DISP8:
2194 case elfcpp::R_SPARC_DISP16:
2195 case elfcpp::R_SPARC_DISP32:
2196 case elfcpp::R_SPARC_LO10:
2197 case elfcpp::R_SPARC_WDISP30:
2198 case elfcpp::R_SPARC_HI22:
2199 case elfcpp::R_SPARC_UA16:
2200 case elfcpp::R_SPARC_UA32:
2208 // This prevents us from issuing more than one error per reloc
2209 // section. But we can still wind up issuing more than one
2210 // error per object file.
2211 if (this->issued_non_pic_error_)
2213 gold_assert(parameters->options().output_is_position_independent());
2214 object->error(_("requires unsupported dynamic reloc; "
2215 "recompile with -fPIC"));
2216 this->issued_non_pic_error_ = true;
2220 // Return whether we need to make a PLT entry for a relocation of the
2221 // given type against a STT_GNU_IFUNC symbol.
2223 template<int size, bool big_endian>
2225 Target_sparc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
2226 Sized_relobj_file<size, big_endian>* object,
2227 unsigned int r_type)
2229 int flags = Scan::get_reference_flags(r_type);
2230 if (flags & Symbol::TLS_REF)
2231 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2232 object->name().c_str(), r_type);
2236 // Scan a relocation for a local symbol.
2238 template<int size, bool big_endian>
2240 Target_sparc<size, big_endian>::Scan::local(
2241 Symbol_table* symtab,
2243 Target_sparc<size, big_endian>* target,
2244 Sized_relobj_file<size, big_endian>* object,
2245 unsigned int data_shndx,
2246 Output_section* output_section,
2247 const elfcpp::Rela<size, big_endian>& reloc,
2248 unsigned int r_type,
2249 const elfcpp::Sym<size, big_endian>& lsym,
2255 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2256 unsigned int orig_r_type = r_type;
2260 && this->reloc_needs_plt_for_ifunc(object, r_type))
2262 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2263 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2268 case elfcpp::R_SPARC_NONE:
2269 case elfcpp::R_SPARC_REGISTER:
2270 case elfcpp::R_SPARC_GNU_VTINHERIT:
2271 case elfcpp::R_SPARC_GNU_VTENTRY:
2274 case elfcpp::R_SPARC_64:
2275 case elfcpp::R_SPARC_32:
2276 // If building a shared library (or a position-independent
2277 // executable), we need to create a dynamic relocation for
2278 // this location. The relocation applied at link time will
2279 // apply the link-time value, so we flag the location with
2280 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2281 // relocate it easily.
2282 if (parameters->options().output_is_position_independent())
2284 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2285 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2286 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
2287 output_section, data_shndx,
2288 reloc.get_r_offset(),
2289 reloc.get_r_addend(), is_ifunc);
2293 case elfcpp::R_SPARC_HIX22:
2294 case elfcpp::R_SPARC_LOX10:
2295 case elfcpp::R_SPARC_H34:
2296 case elfcpp::R_SPARC_H44:
2297 case elfcpp::R_SPARC_M44:
2298 case elfcpp::R_SPARC_L44:
2299 case elfcpp::R_SPARC_HH22:
2300 case elfcpp::R_SPARC_HM10:
2301 case elfcpp::R_SPARC_LM22:
2302 case elfcpp::R_SPARC_UA64:
2303 case elfcpp::R_SPARC_UA32:
2304 case elfcpp::R_SPARC_UA16:
2305 case elfcpp::R_SPARC_HI22:
2306 case elfcpp::R_SPARC_LO10:
2307 case elfcpp::R_SPARC_OLO10:
2308 case elfcpp::R_SPARC_16:
2309 case elfcpp::R_SPARC_11:
2310 case elfcpp::R_SPARC_10:
2311 case elfcpp::R_SPARC_8:
2312 case elfcpp::R_SPARC_7:
2313 case elfcpp::R_SPARC_6:
2314 case elfcpp::R_SPARC_5:
2315 // If building a shared library (or a position-independent
2316 // executable), we need to create a dynamic relocation for
2318 if (parameters->options().output_is_position_independent())
2320 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2321 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2323 check_non_pic(object, r_type);
2324 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2326 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
2327 data_shndx, reloc.get_r_offset(),
2328 reloc.get_r_addend());
2332 gold_assert(lsym.get_st_value() == 0);
2333 rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
2334 output_section, data_shndx,
2335 reloc.get_r_offset(),
2336 reloc.get_r_addend());
2341 case elfcpp::R_SPARC_WDISP30:
2342 case elfcpp::R_SPARC_WPLT30:
2343 case elfcpp::R_SPARC_WDISP22:
2344 case elfcpp::R_SPARC_WDISP19:
2345 case elfcpp::R_SPARC_WDISP16:
2346 case elfcpp::R_SPARC_WDISP10:
2347 case elfcpp::R_SPARC_DISP8:
2348 case elfcpp::R_SPARC_DISP16:
2349 case elfcpp::R_SPARC_DISP32:
2350 case elfcpp::R_SPARC_DISP64:
2351 case elfcpp::R_SPARC_PC10:
2352 case elfcpp::R_SPARC_PC22:
2355 case elfcpp::R_SPARC_GOTDATA_OP:
2356 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2357 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2358 // We will optimize this into a GOT relative relocation
2359 // and code transform the GOT load into an addition.
2362 case elfcpp::R_SPARC_GOT10:
2363 case elfcpp::R_SPARC_GOT13:
2364 case elfcpp::R_SPARC_GOT22:
2366 // The symbol requires a GOT entry.
2367 Output_data_got<size, big_endian>* got;
2370 got = target->got_section(symtab, layout);
2371 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2373 // If we are generating a shared object, we need to add a
2374 // dynamic relocation for this symbol's GOT entry.
2375 if (parameters->options().output_is_position_independent())
2377 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
2379 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2380 unsigned int off = got->add_constant(0);
2381 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
2382 rela_dyn->add_local_relative(object, r_sym,
2383 elfcpp::R_SPARC_RELATIVE,
2384 got, off, 0, is_ifunc);
2388 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2392 // These are initial TLS relocs, which are expected when
2394 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2395 case elfcpp::R_SPARC_TLS_GD_LO10:
2396 case elfcpp::R_SPARC_TLS_GD_ADD:
2397 case elfcpp::R_SPARC_TLS_GD_CALL:
2398 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2399 case elfcpp::R_SPARC_TLS_LDM_LO10:
2400 case elfcpp::R_SPARC_TLS_LDM_ADD:
2401 case elfcpp::R_SPARC_TLS_LDM_CALL:
2402 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2403 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2404 case elfcpp::R_SPARC_TLS_LDO_ADD:
2405 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2406 case elfcpp::R_SPARC_TLS_IE_LO10:
2407 case elfcpp::R_SPARC_TLS_IE_LD:
2408 case elfcpp::R_SPARC_TLS_IE_LDX:
2409 case elfcpp::R_SPARC_TLS_IE_ADD:
2410 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2411 case elfcpp::R_SPARC_TLS_LE_LOX10:
2413 bool output_is_shared = parameters->options().shared();
2414 const tls::Tls_optimization optimized_type
2415 = optimize_tls_reloc(!output_is_shared, r_type);
2418 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2419 case elfcpp::R_SPARC_TLS_GD_LO10:
2420 case elfcpp::R_SPARC_TLS_GD_ADD:
2421 case elfcpp::R_SPARC_TLS_GD_CALL:
2422 if (optimized_type == tls::TLSOPT_NONE)
2424 // Create a pair of GOT entries for the module index and
2425 // dtv-relative offset.
2426 Output_data_got<size, big_endian>* got
2427 = target->got_section(symtab, layout);
2428 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2429 unsigned int shndx = lsym.get_st_shndx();
2431 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2433 object->error(_("local symbol %u has bad shndx %u"),
2436 got->add_local_pair_with_rel(object, r_sym,
2437 lsym.get_st_shndx(),
2439 target->rela_dyn_section(layout),
2441 ? elfcpp::R_SPARC_TLS_DTPMOD64
2442 : elfcpp::R_SPARC_TLS_DTPMOD32));
2443 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2444 generate_tls_call(symtab, layout, target);
2446 else if (optimized_type != tls::TLSOPT_TO_LE)
2447 unsupported_reloc_local(object, r_type);
2450 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2451 case elfcpp::R_SPARC_TLS_LDM_LO10:
2452 case elfcpp::R_SPARC_TLS_LDM_ADD:
2453 case elfcpp::R_SPARC_TLS_LDM_CALL:
2454 if (optimized_type == tls::TLSOPT_NONE)
2456 // Create a GOT entry for the module index.
2457 target->got_mod_index_entry(symtab, layout, object);
2459 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2460 generate_tls_call(symtab, layout, target);
2462 else if (optimized_type != tls::TLSOPT_TO_LE)
2463 unsupported_reloc_local(object, r_type);
2466 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2467 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2468 case elfcpp::R_SPARC_TLS_LDO_ADD:
2471 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2472 case elfcpp::R_SPARC_TLS_IE_LO10:
2473 case elfcpp::R_SPARC_TLS_IE_LD:
2474 case elfcpp::R_SPARC_TLS_IE_LDX:
2475 case elfcpp::R_SPARC_TLS_IE_ADD:
2476 layout->set_has_static_tls();
2477 if (optimized_type == tls::TLSOPT_NONE)
2479 // Create a GOT entry for the tp-relative offset.
2480 Output_data_got<size, big_endian>* got
2481 = target->got_section(symtab, layout);
2482 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2484 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
2486 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2487 unsigned int off = got->add_constant(0);
2489 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
2491 rela_dyn->add_symbolless_local_addend(object, r_sym,
2493 elfcpp::R_SPARC_TLS_TPOFF64 :
2494 elfcpp::R_SPARC_TLS_TPOFF32),
2498 else if (optimized_type != tls::TLSOPT_TO_LE)
2499 unsupported_reloc_local(object, r_type);
2502 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2503 case elfcpp::R_SPARC_TLS_LE_LOX10:
2504 layout->set_has_static_tls();
2505 if (output_is_shared)
2507 // We need to create a dynamic relocation.
2508 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2509 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2510 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2511 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
2512 output_section, data_shndx,
2513 reloc.get_r_offset(), 0);
2520 // These are relocations which should only be seen by the
2521 // dynamic linker, and should never be seen here.
2522 case elfcpp::R_SPARC_COPY:
2523 case elfcpp::R_SPARC_GLOB_DAT:
2524 case elfcpp::R_SPARC_JMP_SLOT:
2525 case elfcpp::R_SPARC_JMP_IREL:
2526 case elfcpp::R_SPARC_RELATIVE:
2527 case elfcpp::R_SPARC_IRELATIVE:
2528 case elfcpp::R_SPARC_TLS_DTPMOD64:
2529 case elfcpp::R_SPARC_TLS_DTPMOD32:
2530 case elfcpp::R_SPARC_TLS_DTPOFF64:
2531 case elfcpp::R_SPARC_TLS_DTPOFF32:
2532 case elfcpp::R_SPARC_TLS_TPOFF64:
2533 case elfcpp::R_SPARC_TLS_TPOFF32:
2534 gold_error(_("%s: unexpected reloc %u in object file"),
2535 object->name().c_str(), r_type);
2539 unsupported_reloc_local(object, r_type);
2544 // Report an unsupported relocation against a global symbol.
2546 template<int size, bool big_endian>
2548 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
2549 Sized_relobj_file<size, big_endian>* object,
2550 unsigned int r_type,
2553 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2554 object->name().c_str(), r_type, gsym->demangled_name().c_str());
2557 // Scan a relocation for a global symbol.
2559 template<int size, bool big_endian>
2561 Target_sparc<size, big_endian>::Scan::global(
2562 Symbol_table* symtab,
2564 Target_sparc<size, big_endian>* target,
2565 Sized_relobj_file<size, big_endian>* object,
2566 unsigned int data_shndx,
2567 Output_section* output_section,
2568 const elfcpp::Rela<size, big_endian>& reloc,
2569 unsigned int r_type,
2572 unsigned int orig_r_type = r_type;
2573 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2575 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2576 // section. We check here to avoid creating a dynamic reloc against
2577 // _GLOBAL_OFFSET_TABLE_.
2578 if (!target->has_got_section()
2579 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2580 target->got_section(symtab, layout);
2584 // A STT_GNU_IFUNC symbol may require a PLT entry.
2586 && this->reloc_needs_plt_for_ifunc(object, r_type))
2587 target->make_plt_entry(symtab, layout, gsym);
2591 case elfcpp::R_SPARC_NONE:
2592 case elfcpp::R_SPARC_REGISTER:
2593 case elfcpp::R_SPARC_GNU_VTINHERIT:
2594 case elfcpp::R_SPARC_GNU_VTENTRY:
2597 case elfcpp::R_SPARC_PLT64:
2598 case elfcpp::R_SPARC_PLT32:
2599 case elfcpp::R_SPARC_HIPLT22:
2600 case elfcpp::R_SPARC_LOPLT10:
2601 case elfcpp::R_SPARC_PCPLT32:
2602 case elfcpp::R_SPARC_PCPLT22:
2603 case elfcpp::R_SPARC_PCPLT10:
2604 case elfcpp::R_SPARC_WPLT30:
2605 // If the symbol is fully resolved, this is just a PC32 reloc.
2606 // Otherwise we need a PLT entry.
2607 if (gsym->final_value_is_known())
2609 // If building a shared library, we can also skip the PLT entry
2610 // if the symbol is defined in the output file and is protected
2612 if (gsym->is_defined()
2613 && !gsym->is_from_dynobj()
2614 && !gsym->is_preemptible())
2616 target->make_plt_entry(symtab, layout, gsym);
2619 case elfcpp::R_SPARC_DISP8:
2620 case elfcpp::R_SPARC_DISP16:
2621 case elfcpp::R_SPARC_DISP32:
2622 case elfcpp::R_SPARC_DISP64:
2623 case elfcpp::R_SPARC_PC_HH22:
2624 case elfcpp::R_SPARC_PC_HM10:
2625 case elfcpp::R_SPARC_PC_LM22:
2626 case elfcpp::R_SPARC_PC10:
2627 case elfcpp::R_SPARC_PC22:
2628 case elfcpp::R_SPARC_WDISP30:
2629 case elfcpp::R_SPARC_WDISP22:
2630 case elfcpp::R_SPARC_WDISP19:
2631 case elfcpp::R_SPARC_WDISP16:
2632 case elfcpp::R_SPARC_WDISP10:
2634 if (gsym->needs_plt_entry())
2635 target->make_plt_entry(symtab, layout, gsym);
2636 // Make a dynamic relocation if necessary.
2637 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2639 if (gsym->may_need_copy_reloc())
2641 target->copy_reloc(symtab, layout, object,
2642 data_shndx, output_section, gsym,
2647 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2648 check_non_pic(object, r_type);
2649 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
2650 data_shndx, reloc.get_r_offset(),
2651 reloc.get_r_addend());
2657 case elfcpp::R_SPARC_UA64:
2658 case elfcpp::R_SPARC_64:
2659 case elfcpp::R_SPARC_HIX22:
2660 case elfcpp::R_SPARC_LOX10:
2661 case elfcpp::R_SPARC_H34:
2662 case elfcpp::R_SPARC_H44:
2663 case elfcpp::R_SPARC_M44:
2664 case elfcpp::R_SPARC_L44:
2665 case elfcpp::R_SPARC_HH22:
2666 case elfcpp::R_SPARC_HM10:
2667 case elfcpp::R_SPARC_LM22:
2668 case elfcpp::R_SPARC_HI22:
2669 case elfcpp::R_SPARC_LO10:
2670 case elfcpp::R_SPARC_OLO10:
2671 case elfcpp::R_SPARC_UA32:
2672 case elfcpp::R_SPARC_32:
2673 case elfcpp::R_SPARC_UA16:
2674 case elfcpp::R_SPARC_16:
2675 case elfcpp::R_SPARC_11:
2676 case elfcpp::R_SPARC_10:
2677 case elfcpp::R_SPARC_8:
2678 case elfcpp::R_SPARC_7:
2679 case elfcpp::R_SPARC_6:
2680 case elfcpp::R_SPARC_5:
2682 // Make a PLT entry if necessary.
2683 if (gsym->needs_plt_entry())
2685 target->make_plt_entry(symtab, layout, gsym);
2686 // Since this is not a PC-relative relocation, we may be
2687 // taking the address of a function. In that case we need to
2688 // set the entry in the dynamic symbol table to the address of
2690 if (gsym->is_from_dynobj() && !parameters->options().shared())
2691 gsym->set_needs_dynsym_value();
2693 // Make a dynamic relocation if necessary.
2694 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2696 unsigned int r_off = reloc.get_r_offset();
2698 // The assembler can sometimes emit unaligned relocations
2699 // for dwarf2 cfi directives.
2702 case elfcpp::R_SPARC_16:
2704 orig_r_type = r_type = elfcpp::R_SPARC_UA16;
2706 case elfcpp::R_SPARC_32:
2708 orig_r_type = r_type = elfcpp::R_SPARC_UA32;
2710 case elfcpp::R_SPARC_64:
2712 orig_r_type = r_type = elfcpp::R_SPARC_UA64;
2714 case elfcpp::R_SPARC_UA16:
2716 orig_r_type = r_type = elfcpp::R_SPARC_16;
2718 case elfcpp::R_SPARC_UA32:
2720 orig_r_type = r_type = elfcpp::R_SPARC_32;
2722 case elfcpp::R_SPARC_UA64:
2724 orig_r_type = r_type = elfcpp::R_SPARC_64;
2728 if (gsym->may_need_copy_reloc())
2730 target->copy_reloc(symtab, layout, object,
2731 data_shndx, output_section, gsym, reloc);
2733 else if (((size == 64 && r_type == elfcpp::R_SPARC_64)
2734 || (size == 32 && r_type == elfcpp::R_SPARC_32))
2735 && gsym->type() == elfcpp::STT_GNU_IFUNC
2736 && gsym->can_use_relative_reloc(false)
2737 && !gsym->is_from_dynobj()
2738 && !gsym->is_undefined()
2739 && !gsym->is_preemptible())
2741 // Use an IRELATIVE reloc for a locally defined
2742 // STT_GNU_IFUNC symbol. This makes a function
2743 // address in a PIE executable match the address in a
2744 // shared library that it links against.
2745 Reloc_section* rela_dyn =
2746 target->rela_ifunc_section(layout);
2747 unsigned int r_type = elfcpp::R_SPARC_IRELATIVE;
2748 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2749 output_section, object,
2751 reloc.get_r_offset(),
2752 reloc.get_r_addend());
2754 else if ((r_type == elfcpp::R_SPARC_32
2755 || r_type == elfcpp::R_SPARC_64)
2756 && gsym->can_use_relative_reloc(false))
2758 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2759 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2760 output_section, object,
2761 data_shndx, reloc.get_r_offset(),
2762 reloc.get_r_addend(), is_ifunc);
2766 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2768 check_non_pic(object, r_type);
2769 if (gsym->is_from_dynobj()
2770 || gsym->is_undefined()
2771 || gsym->is_preemptible())
2772 rela_dyn->add_global(gsym, orig_r_type, output_section,
2774 reloc.get_r_offset(),
2775 reloc.get_r_addend());
2777 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2780 reloc.get_r_offset(),
2781 reloc.get_r_addend());
2787 case elfcpp::R_SPARC_GOTDATA_OP:
2788 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2789 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2790 if (gsym->is_defined()
2791 && !gsym->is_from_dynobj()
2792 && !gsym->is_preemptible()
2795 // We will optimize this into a GOT relative relocation
2796 // and code transform the GOT load into an addition.
2799 case elfcpp::R_SPARC_GOT10:
2800 case elfcpp::R_SPARC_GOT13:
2801 case elfcpp::R_SPARC_GOT22:
2803 // The symbol requires a GOT entry.
2804 Output_data_got<size, big_endian>* got;
2806 got = target->got_section(symtab, layout);
2807 if (gsym->final_value_is_known())
2809 // For a STT_GNU_IFUNC symbol we want the PLT address.
2810 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2811 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2813 got->add_global(gsym, GOT_TYPE_STANDARD);
2817 // If this symbol is not fully resolved, we need to add a
2818 // GOT entry with a dynamic relocation.
2819 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2821 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2823 // 1) The symbol may be defined in some other module.
2825 // 2) We are building a shared library and this is a
2826 // protected symbol; using GLOB_DAT means that the dynamic
2827 // linker can use the address of the PLT in the main
2828 // executable when appropriate so that function address
2829 // comparisons work.
2831 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2832 // code, again so that function address comparisons work.
2833 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2834 if (gsym->is_from_dynobj()
2835 || gsym->is_undefined()
2836 || gsym->is_preemptible()
2837 || (gsym->visibility() == elfcpp::STV_PROTECTED
2838 && parameters->options().shared())
2839 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2840 && parameters->options().output_is_position_independent()
2841 && !gsym->is_forced_local()))
2843 unsigned int r_type = elfcpp::R_SPARC_GLOB_DAT;
2845 // If this symbol is forced local, this relocation will
2846 // not work properly. That's because ld.so on sparc
2847 // (and 32-bit powerpc) expects st_value in the r_addend
2848 // of relocations for STB_LOCAL symbols. Curiously the
2849 // BFD linker does not promote global hidden symbols to be
2850 // STB_LOCAL in the dynamic symbol table like Gold does.
2851 gold_assert(!gsym->is_forced_local());
2852 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2855 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2857 unsigned int off = got->add_constant(0);
2859 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2862 // Tell the dynamic linker to use the PLT address
2863 // when resolving relocations.
2864 if (gsym->is_from_dynobj()
2865 && !parameters->options().shared())
2866 gsym->set_needs_dynsym_value();
2868 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2869 got, off, 0, is_ifunc);
2875 // These are initial tls relocs, which are expected when
2877 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2878 case elfcpp::R_SPARC_TLS_GD_LO10:
2879 case elfcpp::R_SPARC_TLS_GD_ADD:
2880 case elfcpp::R_SPARC_TLS_GD_CALL:
2881 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2882 case elfcpp::R_SPARC_TLS_LDM_LO10:
2883 case elfcpp::R_SPARC_TLS_LDM_ADD:
2884 case elfcpp::R_SPARC_TLS_LDM_CALL:
2885 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2886 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2887 case elfcpp::R_SPARC_TLS_LDO_ADD:
2888 case elfcpp::R_SPARC_TLS_LE_HIX22:
2889 case elfcpp::R_SPARC_TLS_LE_LOX10:
2890 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2891 case elfcpp::R_SPARC_TLS_IE_LO10:
2892 case elfcpp::R_SPARC_TLS_IE_LD:
2893 case elfcpp::R_SPARC_TLS_IE_LDX:
2894 case elfcpp::R_SPARC_TLS_IE_ADD:
2896 const bool is_final = gsym->final_value_is_known();
2897 const tls::Tls_optimization optimized_type
2898 = optimize_tls_reloc(is_final, r_type);
2901 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2902 case elfcpp::R_SPARC_TLS_GD_LO10:
2903 case elfcpp::R_SPARC_TLS_GD_ADD:
2904 case elfcpp::R_SPARC_TLS_GD_CALL:
2905 if (optimized_type == tls::TLSOPT_NONE)
2907 // Create a pair of GOT entries for the module index and
2908 // dtv-relative offset.
2909 Output_data_got<size, big_endian>* got
2910 = target->got_section(symtab, layout);
2911 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2912 target->rela_dyn_section(layout),
2914 ? elfcpp::R_SPARC_TLS_DTPMOD64
2915 : elfcpp::R_SPARC_TLS_DTPMOD32),
2917 ? elfcpp::R_SPARC_TLS_DTPOFF64
2918 : elfcpp::R_SPARC_TLS_DTPOFF32));
2920 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2921 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2922 generate_tls_call(symtab, layout, target);
2924 else if (optimized_type == tls::TLSOPT_TO_IE)
2926 // Create a GOT entry for the tp-relative offset.
2927 Output_data_got<size, big_endian>* got
2928 = target->got_section(symtab, layout);
2929 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2930 target->rela_dyn_section(layout),
2932 elfcpp::R_SPARC_TLS_TPOFF64 :
2933 elfcpp::R_SPARC_TLS_TPOFF32));
2935 else if (optimized_type != tls::TLSOPT_TO_LE)
2936 unsupported_reloc_global(object, r_type, gsym);
2939 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2940 case elfcpp::R_SPARC_TLS_LDM_LO10:
2941 case elfcpp::R_SPARC_TLS_LDM_ADD:
2942 case elfcpp::R_SPARC_TLS_LDM_CALL:
2943 if (optimized_type == tls::TLSOPT_NONE)
2945 // Create a GOT entry for the module index.
2946 target->got_mod_index_entry(symtab, layout, object);
2948 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2949 generate_tls_call(symtab, layout, target);
2951 else if (optimized_type != tls::TLSOPT_TO_LE)
2952 unsupported_reloc_global(object, r_type, gsym);
2955 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2956 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2957 case elfcpp::R_SPARC_TLS_LDO_ADD:
2960 case elfcpp::R_SPARC_TLS_LE_HIX22:
2961 case elfcpp::R_SPARC_TLS_LE_LOX10:
2962 layout->set_has_static_tls();
2963 if (parameters->options().shared())
2965 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2966 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2967 output_section, object,
2968 data_shndx, reloc.get_r_offset(),
2973 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2974 case elfcpp::R_SPARC_TLS_IE_LO10:
2975 case elfcpp::R_SPARC_TLS_IE_LD:
2976 case elfcpp::R_SPARC_TLS_IE_LDX:
2977 case elfcpp::R_SPARC_TLS_IE_ADD:
2978 layout->set_has_static_tls();
2979 if (optimized_type == tls::TLSOPT_NONE)
2981 // Create a GOT entry for the tp-relative offset.
2982 Output_data_got<size, big_endian>* got
2983 = target->got_section(symtab, layout);
2984 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2985 target->rela_dyn_section(layout),
2987 ? elfcpp::R_SPARC_TLS_TPOFF64
2988 : elfcpp::R_SPARC_TLS_TPOFF32));
2990 else if (optimized_type != tls::TLSOPT_TO_LE)
2991 unsupported_reloc_global(object, r_type, gsym);
2997 // These are relocations which should only be seen by the
2998 // dynamic linker, and should never be seen here.
2999 case elfcpp::R_SPARC_COPY:
3000 case elfcpp::R_SPARC_GLOB_DAT:
3001 case elfcpp::R_SPARC_JMP_SLOT:
3002 case elfcpp::R_SPARC_JMP_IREL:
3003 case elfcpp::R_SPARC_RELATIVE:
3004 case elfcpp::R_SPARC_IRELATIVE:
3005 case elfcpp::R_SPARC_TLS_DTPMOD64:
3006 case elfcpp::R_SPARC_TLS_DTPMOD32:
3007 case elfcpp::R_SPARC_TLS_DTPOFF64:
3008 case elfcpp::R_SPARC_TLS_DTPOFF32:
3009 case elfcpp::R_SPARC_TLS_TPOFF64:
3010 case elfcpp::R_SPARC_TLS_TPOFF32:
3011 gold_error(_("%s: unexpected reloc %u in object file"),
3012 object->name().c_str(), r_type);
3016 unsupported_reloc_global(object, r_type, gsym);
3021 // Process relocations for gc.
3023 template<int size, bool big_endian>
3025 Target_sparc<size, big_endian>::gc_process_relocs(
3026 Symbol_table* symtab,
3028 Sized_relobj_file<size, big_endian>* object,
3029 unsigned int data_shndx,
3031 const unsigned char* prelocs,
3033 Output_section* output_section,
3034 bool needs_special_offset_handling,
3035 size_t local_symbol_count,
3036 const unsigned char* plocal_symbols)
3038 typedef Target_sparc<size, big_endian> Sparc;
3039 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3041 gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan,
3042 typename Target_sparc::Relocatable_size_for_reloc>(
3051 needs_special_offset_handling,
3056 // Scan relocations for a section.
3058 template<int size, bool big_endian>
3060 Target_sparc<size, big_endian>::scan_relocs(
3061 Symbol_table* symtab,
3063 Sized_relobj_file<size, big_endian>* object,
3064 unsigned int data_shndx,
3065 unsigned int sh_type,
3066 const unsigned char* prelocs,
3068 Output_section* output_section,
3069 bool needs_special_offset_handling,
3070 size_t local_symbol_count,
3071 const unsigned char* plocal_symbols)
3073 typedef Target_sparc<size, big_endian> Sparc;
3074 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3076 if (sh_type == elfcpp::SHT_REL)
3078 gold_error(_("%s: unsupported REL reloc section"),
3079 object->name().c_str());
3083 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
3092 needs_special_offset_handling,
3097 // Finalize the sections.
3099 template<int size, bool big_endian>
3101 Target_sparc<size, big_endian>::do_finalize_sections(
3103 const Input_objects*,
3104 Symbol_table* symtab)
3107 this->plt_->emit_pending_ifunc_relocs();
3109 // Fill in some more dynamic tags.
3110 const Reloc_section* rel_plt = (this->plt_ == NULL
3112 : this->plt_->rel_plt());
3113 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
3114 this->rela_dyn_, true, true);
3116 // Emit any relocs we saved in an attempt to avoid generating COPY
3118 if (this->copy_relocs_.any_saved_relocs())
3119 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3121 if (parameters->doing_static_link()
3122 && (this->plt_ == NULL || !this->plt_->has_ifunc_section()))
3124 // If linking statically, make sure that the __rela_iplt symbols
3125 // were defined if necessary, even if we didn't create a PLT.
3126 static const Define_symbol_in_segment syms[] =
3129 "__rela_iplt_start", // name
3130 elfcpp::PT_LOAD, // segment_type
3131 elfcpp::PF_W, // segment_flags_set
3132 elfcpp::PF(0), // segment_flags_clear
3135 elfcpp::STT_NOTYPE, // type
3136 elfcpp::STB_GLOBAL, // binding
3137 elfcpp::STV_HIDDEN, // visibility
3139 Symbol::SEGMENT_START, // offset_from_base
3143 "__rela_iplt_end", // name
3144 elfcpp::PT_LOAD, // segment_type
3145 elfcpp::PF_W, // segment_flags_set
3146 elfcpp::PF(0), // segment_flags_clear
3149 elfcpp::STT_NOTYPE, // type
3150 elfcpp::STB_GLOBAL, // binding
3151 elfcpp::STV_HIDDEN, // visibility
3153 Symbol::SEGMENT_START, // offset_from_base
3158 symtab->define_symbols(layout, 2, syms,
3159 layout->script_options()->saw_sections_clause());
3163 // Perform a relocation.
3165 template<int size, bool big_endian>
3167 Target_sparc<size, big_endian>::Relocate::relocate(
3168 const Relocate_info<size, big_endian>* relinfo,
3169 Target_sparc* target,
3172 const elfcpp::Rela<size, big_endian>& rela,
3173 unsigned int r_type,
3174 const Sized_symbol<size>* gsym,
3175 const Symbol_value<size>* psymval,
3176 unsigned char* view,
3177 typename elfcpp::Elf_types<size>::Elf_Addr address,
3178 section_size_type view_size)
3180 bool orig_is_ifunc = psymval->is_ifunc_symbol();
3183 if (this->ignore_gd_add_)
3185 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
3186 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3187 _("missing expected TLS relocation"));
3190 this->ignore_gd_add_ = false;
3198 if (this->reloc_adjust_addr_ == view)
3201 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3202 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3204 // Pick the value to use for symbols defined in shared objects.
3205 Symbol_value<size> symval;
3207 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3209 elfcpp::Elf_Xword value;
3211 value = target->plt_address_for_global(gsym);
3213 symval.set_output_value(value);
3217 else if (gsym == NULL && orig_is_ifunc)
3219 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3220 if (object->local_has_plt_offset(r_sym))
3222 symval.set_output_value(target->plt_address_for_local(object, r_sym));
3227 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3229 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3230 // pointer points to the beginning, not the end, of the table.
3231 // So we just use the plain offset.
3232 unsigned int got_offset = 0;
3233 bool gdop_valid = false;
3236 case elfcpp::R_SPARC_GOTDATA_OP:
3237 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3238 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3239 // If this is local, we did not create a GOT entry because we
3240 // intend to transform this into a GOT relative relocation.
3242 || (gsym->is_defined()
3243 && !gsym->is_from_dynobj()
3244 && !gsym->is_preemptible()
3247 got_offset = psymval->value(object, 0) - target->got_address();
3251 case elfcpp::R_SPARC_GOT10:
3252 case elfcpp::R_SPARC_GOT13:
3253 case elfcpp::R_SPARC_GOT22:
3256 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3257 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3261 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3262 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3263 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3273 case elfcpp::R_SPARC_NONE:
3274 case elfcpp::R_SPARC_REGISTER:
3275 case elfcpp::R_SPARC_GNU_VTINHERIT:
3276 case elfcpp::R_SPARC_GNU_VTENTRY:
3279 case elfcpp::R_SPARC_8:
3280 Relocate_functions<size, big_endian>::rela8(view, object,
3284 case elfcpp::R_SPARC_16:
3285 if (rela.get_r_offset() & 0x1)
3287 // The assembler can sometimes emit unaligned relocations
3288 // for dwarf2 cfi directives.
3289 Reloc::ua16(view, object, psymval, addend);
3292 Relocate_functions<size, big_endian>::rela16(view, object,
3296 case elfcpp::R_SPARC_32:
3297 if (!parameters->options().output_is_position_independent())
3299 if (rela.get_r_offset() & 0x3)
3301 // The assembler can sometimes emit unaligned relocations
3302 // for dwarf2 cfi directives.
3303 Reloc::ua32(view, object, psymval, addend);
3306 Relocate_functions<size, big_endian>::rela32(view, object,
3311 case elfcpp::R_SPARC_DISP8:
3312 Reloc::disp8(view, object, psymval, addend, address);
3315 case elfcpp::R_SPARC_DISP16:
3316 Reloc::disp16(view, object, psymval, addend, address);
3319 case elfcpp::R_SPARC_DISP32:
3320 Reloc::disp32(view, object, psymval, addend, address);
3323 case elfcpp::R_SPARC_DISP64:
3324 Reloc::disp64(view, object, psymval, addend, address);
3327 case elfcpp::R_SPARC_WDISP30:
3328 case elfcpp::R_SPARC_WPLT30:
3329 Reloc::wdisp30(view, object, psymval, addend, address);
3330 if (target->may_relax())
3331 relax_call(target, view, rela, view_size);
3334 case elfcpp::R_SPARC_WDISP22:
3335 Reloc::wdisp22(view, object, psymval, addend, address);
3338 case elfcpp::R_SPARC_WDISP19:
3339 Reloc::wdisp19(view, object, psymval, addend, address);
3342 case elfcpp::R_SPARC_WDISP16:
3343 Reloc::wdisp16(view, object, psymval, addend, address);
3346 case elfcpp::R_SPARC_WDISP10:
3347 Reloc::wdisp10(view, object, psymval, addend, address);
3350 case elfcpp::R_SPARC_HI22:
3351 Reloc::hi22(view, object, psymval, addend);
3354 case elfcpp::R_SPARC_22:
3355 Reloc::rela32_22(view, object, psymval, addend);
3358 case elfcpp::R_SPARC_13:
3359 Reloc::rela32_13(view, object, psymval, addend);
3362 case elfcpp::R_SPARC_LO10:
3363 Reloc::lo10(view, object, psymval, addend);
3366 case elfcpp::R_SPARC_GOT10:
3367 Reloc::lo10(view, got_offset, addend);
3370 case elfcpp::R_SPARC_GOTDATA_OP:
3373 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3374 Insntype* wv = reinterpret_cast<Insntype*>(view);
3377 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3378 val = elfcpp::Swap<32, true>::readval(wv);
3379 val = 0x80000000 | (val & 0x3e07c01f);
3380 elfcpp::Swap<32, true>::writeval(wv, val);
3384 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3387 Reloc::gdop_lox10(view, got_offset, addend);
3391 case elfcpp::R_SPARC_GOT13:
3392 Reloc::rela32_13(view, got_offset, addend);
3395 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3398 Reloc::gdop_hix22(view, got_offset, addend);
3402 case elfcpp::R_SPARC_GOT22:
3403 Reloc::hi22(view, got_offset, addend);
3406 case elfcpp::R_SPARC_PC10:
3407 Reloc::pc10(view, object, psymval, addend, address);
3410 case elfcpp::R_SPARC_PC22:
3411 Reloc::pc22(view, object, psymval, addend, address);
3414 case elfcpp::R_SPARC_TLS_DTPOFF32:
3415 case elfcpp::R_SPARC_UA32:
3416 Reloc::ua32(view, object, psymval, addend);
3419 case elfcpp::R_SPARC_PLT64:
3420 Relocate_functions<size, big_endian>::rela64(view, object,
3424 case elfcpp::R_SPARC_PLT32:
3425 Relocate_functions<size, big_endian>::rela32(view, object,
3429 case elfcpp::R_SPARC_HIPLT22:
3430 Reloc::hi22(view, object, psymval, addend);
3433 case elfcpp::R_SPARC_LOPLT10:
3434 Reloc::lo10(view, object, psymval, addend);
3437 case elfcpp::R_SPARC_PCPLT32:
3438 Reloc::disp32(view, object, psymval, addend, address);
3441 case elfcpp::R_SPARC_PCPLT22:
3442 Reloc::pcplt22(view, object, psymval, addend, address);
3445 case elfcpp::R_SPARC_PCPLT10:
3446 Reloc::lo10(view, object, psymval, addend, address);
3449 case elfcpp::R_SPARC_64:
3450 if (!parameters->options().output_is_position_independent())
3452 if (rela.get_r_offset() & 0x7)
3454 // The assembler can sometimes emit unaligned relocations
3455 // for dwarf2 cfi directives.
3456 Reloc::ua64(view, object, psymval, addend);
3459 Relocate_functions<size, big_endian>::rela64(view, object,
3464 case elfcpp::R_SPARC_OLO10:
3466 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
3467 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
3468 Reloc::olo10(view, object, psymval, addend, addend2);
3472 case elfcpp::R_SPARC_HH22:
3473 Reloc::hh22(view, object, psymval, addend);
3476 case elfcpp::R_SPARC_PC_HH22:
3477 Reloc::pc_hh22(view, object, psymval, addend, address);
3480 case elfcpp::R_SPARC_HM10:
3481 Reloc::hm10(view, object, psymval, addend);
3484 case elfcpp::R_SPARC_PC_HM10:
3485 Reloc::pc_hm10(view, object, psymval, addend, address);
3488 case elfcpp::R_SPARC_LM22:
3489 Reloc::hi22(view, object, psymval, addend);
3492 case elfcpp::R_SPARC_PC_LM22:
3493 Reloc::pcplt22(view, object, psymval, addend, address);
3496 case elfcpp::R_SPARC_11:
3497 Reloc::rela32_11(view, object, psymval, addend);
3500 case elfcpp::R_SPARC_10:
3501 Reloc::rela32_10(view, object, psymval, addend);
3504 case elfcpp::R_SPARC_7:
3505 Reloc::rela32_7(view, object, psymval, addend);
3508 case elfcpp::R_SPARC_6:
3509 Reloc::rela32_6(view, object, psymval, addend);
3512 case elfcpp::R_SPARC_5:
3513 Reloc::rela32_5(view, object, psymval, addend);
3516 case elfcpp::R_SPARC_HIX22:
3517 Reloc::hix22(view, object, psymval, addend);
3520 case elfcpp::R_SPARC_LOX10:
3521 Reloc::lox10(view, object, psymval, addend);
3524 case elfcpp::R_SPARC_H34:
3525 Reloc::h34(view, object, psymval, addend);
3528 case elfcpp::R_SPARC_H44:
3529 Reloc::h44(view, object, psymval, addend);
3532 case elfcpp::R_SPARC_M44:
3533 Reloc::m44(view, object, psymval, addend);
3536 case elfcpp::R_SPARC_L44:
3537 Reloc::l44(view, object, psymval, addend);
3540 case elfcpp::R_SPARC_TLS_DTPOFF64:
3541 case elfcpp::R_SPARC_UA64:
3542 Reloc::ua64(view, object, psymval, addend);
3545 case elfcpp::R_SPARC_UA16:
3546 Reloc::ua16(view, object, psymval, addend);
3549 case elfcpp::R_SPARC_TLS_GD_HI22:
3550 case elfcpp::R_SPARC_TLS_GD_LO10:
3551 case elfcpp::R_SPARC_TLS_GD_ADD:
3552 case elfcpp::R_SPARC_TLS_GD_CALL:
3553 case elfcpp::R_SPARC_TLS_LDM_HI22:
3554 case elfcpp::R_SPARC_TLS_LDM_LO10:
3555 case elfcpp::R_SPARC_TLS_LDM_ADD:
3556 case elfcpp::R_SPARC_TLS_LDM_CALL:
3557 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3558 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3559 case elfcpp::R_SPARC_TLS_LDO_ADD:
3560 case elfcpp::R_SPARC_TLS_IE_HI22:
3561 case elfcpp::R_SPARC_TLS_IE_LO10:
3562 case elfcpp::R_SPARC_TLS_IE_LD:
3563 case elfcpp::R_SPARC_TLS_IE_LDX:
3564 case elfcpp::R_SPARC_TLS_IE_ADD:
3565 case elfcpp::R_SPARC_TLS_LE_HIX22:
3566 case elfcpp::R_SPARC_TLS_LE_LOX10:
3567 this->relocate_tls(relinfo, target, relnum, rela,
3568 r_type, gsym, psymval, view,
3569 address, view_size);
3572 case elfcpp::R_SPARC_COPY:
3573 case elfcpp::R_SPARC_GLOB_DAT:
3574 case elfcpp::R_SPARC_JMP_SLOT:
3575 case elfcpp::R_SPARC_JMP_IREL:
3576 case elfcpp::R_SPARC_RELATIVE:
3577 case elfcpp::R_SPARC_IRELATIVE:
3578 // These are outstanding tls relocs, which are unexpected when
3580 case elfcpp::R_SPARC_TLS_DTPMOD64:
3581 case elfcpp::R_SPARC_TLS_DTPMOD32:
3582 case elfcpp::R_SPARC_TLS_TPOFF64:
3583 case elfcpp::R_SPARC_TLS_TPOFF32:
3584 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3585 _("unexpected reloc %u in object file"),
3590 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3591 _("unsupported reloc %u"),
3599 // Perform a TLS relocation.
3601 template<int size, bool big_endian>
3603 Target_sparc<size, big_endian>::Relocate::relocate_tls(
3604 const Relocate_info<size, big_endian>* relinfo,
3605 Target_sparc<size, big_endian>* target,
3607 const elfcpp::Rela<size, big_endian>& rela,
3608 unsigned int r_type,
3609 const Sized_symbol<size>* gsym,
3610 const Symbol_value<size>* psymval,
3611 unsigned char* view,
3612 typename elfcpp::Elf_types<size>::Elf_Addr address,
3615 Output_segment* tls_segment = relinfo->layout->tls_segment();
3616 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3617 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3618 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3620 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3621 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
3623 const bool is_final =
3625 ? !parameters->options().output_is_position_independent()
3626 : gsym->final_value_is_known());
3627 const tls::Tls_optimization optimized_type
3628 = optimize_tls_reloc(is_final, r_type);
3632 case elfcpp::R_SPARC_TLS_GD_HI22:
3633 case elfcpp::R_SPARC_TLS_GD_LO10:
3634 case elfcpp::R_SPARC_TLS_GD_ADD:
3635 case elfcpp::R_SPARC_TLS_GD_CALL:
3636 if (optimized_type == tls::TLSOPT_TO_LE)
3638 Insntype* wv = reinterpret_cast<Insntype*>(view);
3641 value -= tls_segment->memsz();
3645 case elfcpp::R_SPARC_TLS_GD_HI22:
3646 // TLS_GD_HI22 --> TLS_LE_HIX22
3647 Reloc::hix22(view, value, addend);
3650 case elfcpp::R_SPARC_TLS_GD_LO10:
3651 // TLS_GD_LO10 --> TLS_LE_LOX10
3652 Reloc::lox10(view, value, addend);
3655 case elfcpp::R_SPARC_TLS_GD_ADD:
3656 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3657 val = elfcpp::Swap<32, true>::readval(wv);
3658 val = (val & ~0x7c000) | 0x1c000;
3659 elfcpp::Swap<32, true>::writeval(wv, val);
3661 case elfcpp::R_SPARC_TLS_GD_CALL:
3662 // call __tls_get_addr --> nop
3663 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3670 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3671 ? GOT_TYPE_TLS_OFFSET
3672 : GOT_TYPE_TLS_PAIR);
3675 gold_assert(gsym->has_got_offset(got_type));
3676 value = gsym->got_offset(got_type);
3680 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3681 gold_assert(object->local_has_got_offset(r_sym, got_type));
3682 value = object->local_got_offset(r_sym, got_type);
3684 if (optimized_type == tls::TLSOPT_TO_IE)
3686 Insntype* wv = reinterpret_cast<Insntype*>(view);
3691 case elfcpp::R_SPARC_TLS_GD_HI22:
3692 // TLS_GD_HI22 --> TLS_IE_HI22
3693 Reloc::hi22(view, value, addend);
3696 case elfcpp::R_SPARC_TLS_GD_LO10:
3697 // TLS_GD_LO10 --> TLS_IE_LO10
3698 Reloc::lo10(view, value, addend);
3701 case elfcpp::R_SPARC_TLS_GD_ADD:
3702 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3703 val = elfcpp::Swap<32, true>::readval(wv);
3710 elfcpp::Swap<32, true>::writeval(wv, val);
3713 case elfcpp::R_SPARC_TLS_GD_CALL:
3714 // The compiler can put the TLS_GD_ADD instruction
3715 // into the delay slot of the call. If so, we need
3716 // to transpose the two instructions so that the
3717 // new sequence works properly.
3719 // The test we use is if the instruction in the
3720 // delay slot is an add with destination register
3722 val = elfcpp::Swap<32, true>::readval(wv + 1);
3723 if ((val & 0x81f80000) == 0x80000000
3724 && ((val >> 25) & 0x1f) == 0x8)
3731 elfcpp::Swap<32, true>::writeval(wv, val);
3734 this->ignore_gd_add_ = true;
3738 // Even if the delay slot isn't the TLS_GD_ADD
3739 // instruction, we still have to handle the case
3740 // where it sets up %o0 in some other way.
3741 elfcpp::Swap<32, true>::writeval(wv, val);
3743 this->reloc_adjust_addr_ = view + 4;
3745 // call __tls_get_addr --> add %g7, %o0, %o0
3746 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
3751 else if (optimized_type == tls::TLSOPT_NONE)
3755 case elfcpp::R_SPARC_TLS_GD_HI22:
3756 Reloc::hi22(view, value, addend);
3758 case elfcpp::R_SPARC_TLS_GD_LO10:
3759 Reloc::lo10(view, value, addend);
3761 case elfcpp::R_SPARC_TLS_GD_ADD:
3763 case elfcpp::R_SPARC_TLS_GD_CALL:
3765 Symbol_value<size> symval;
3766 elfcpp::Elf_Xword value;
3769 tsym = target->tls_get_addr_sym_;
3771 value = (target->plt_section()->address() +
3772 tsym->plt_offset());
3773 symval.set_output_value(value);
3774 Reloc::wdisp30(view, object, &symval, addend, address);
3781 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3782 _("unsupported reloc %u"),
3786 case elfcpp::R_SPARC_TLS_LDM_HI22:
3787 case elfcpp::R_SPARC_TLS_LDM_LO10:
3788 case elfcpp::R_SPARC_TLS_LDM_ADD:
3789 case elfcpp::R_SPARC_TLS_LDM_CALL:
3790 if (optimized_type == tls::TLSOPT_TO_LE)
3792 Insntype* wv = reinterpret_cast<Insntype*>(view);
3796 case elfcpp::R_SPARC_TLS_LDM_HI22:
3797 case elfcpp::R_SPARC_TLS_LDM_LO10:
3798 case elfcpp::R_SPARC_TLS_LDM_ADD:
3799 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3802 case elfcpp::R_SPARC_TLS_LDM_CALL:
3803 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
3808 else if (optimized_type == tls::TLSOPT_NONE)
3810 // Relocate the field with the offset of the GOT entry for
3811 // the module index.
3812 unsigned int got_offset;
3814 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
3817 case elfcpp::R_SPARC_TLS_LDM_HI22:
3818 Reloc::hi22(view, got_offset, addend);
3820 case elfcpp::R_SPARC_TLS_LDM_LO10:
3821 Reloc::lo10(view, got_offset, addend);
3823 case elfcpp::R_SPARC_TLS_LDM_ADD:
3825 case elfcpp::R_SPARC_TLS_LDM_CALL:
3827 Symbol_value<size> symval;
3828 elfcpp::Elf_Xword value;
3831 tsym = target->tls_get_addr_sym_;
3833 value = (target->plt_section()->address() +
3834 tsym->plt_offset());
3835 symval.set_output_value(value);
3836 Reloc::wdisp30(view, object, &symval, addend, address);
3842 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3843 _("unsupported reloc %u"),
3847 // These relocs can appear in debugging sections, in which case
3848 // we won't see the TLS_LDM relocs. The local_dynamic_type
3849 // field tells us this.
3850 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3851 if (optimized_type == tls::TLSOPT_TO_LE)
3853 value -= tls_segment->memsz();
3854 Reloc::hix22(view, value, addend);
3857 Reloc::ldo_hix22(view, value, addend);
3859 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3860 if (optimized_type == tls::TLSOPT_TO_LE)
3862 value -= tls_segment->memsz();
3863 Reloc::lox10(view, value, addend);
3866 Reloc::ldo_lox10(view, value, addend);
3868 case elfcpp::R_SPARC_TLS_LDO_ADD:
3869 if (optimized_type == tls::TLSOPT_TO_LE)
3871 Insntype* wv = reinterpret_cast<Insntype*>(view);
3874 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3875 val = elfcpp::Swap<32, true>::readval(wv);
3876 val = (val & ~0x7c000) | 0x1c000;
3877 elfcpp::Swap<32, true>::writeval(wv, val);
3881 // When optimizing IE --> LE, the only relocation that is handled
3882 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3883 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3884 // rs2 and rd are the same.
3885 case elfcpp::R_SPARC_TLS_IE_LD:
3886 case elfcpp::R_SPARC_TLS_IE_LDX:
3887 if (optimized_type == tls::TLSOPT_TO_LE)
3889 Insntype* wv = reinterpret_cast<Insntype*>(view);
3890 Insntype val = elfcpp::Swap<32, true>::readval(wv);
3891 Insntype rs2 = val & 0x1f;
3892 Insntype rd = (val >> 25) & 0x1f;
3897 val = sparc_mov | (val & 0x3e00001f);
3899 elfcpp::Swap<32, true>::writeval(wv, val);
3903 case elfcpp::R_SPARC_TLS_IE_HI22:
3904 case elfcpp::R_SPARC_TLS_IE_LO10:
3905 if (optimized_type == tls::TLSOPT_TO_LE)
3907 value -= tls_segment->memsz();
3910 case elfcpp::R_SPARC_TLS_IE_HI22:
3911 // IE_HI22 --> LE_HIX22
3912 Reloc::hix22(view, value, addend);
3914 case elfcpp::R_SPARC_TLS_IE_LO10:
3915 // IE_LO10 --> LE_LOX10
3916 Reloc::lox10(view, value, addend);
3921 else if (optimized_type == tls::TLSOPT_NONE)
3923 // Relocate the field with the offset of the GOT entry for
3924 // the tp-relative offset of the symbol.
3927 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3928 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3932 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3933 gold_assert(object->local_has_got_offset(r_sym,
3934 GOT_TYPE_TLS_OFFSET));
3935 value = object->local_got_offset(r_sym,
3936 GOT_TYPE_TLS_OFFSET);
3940 case elfcpp::R_SPARC_TLS_IE_HI22:
3941 Reloc::hi22(view, value, addend);
3943 case elfcpp::R_SPARC_TLS_IE_LO10:
3944 Reloc::lo10(view, value, addend);
3949 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3950 _("unsupported reloc %u"),
3954 case elfcpp::R_SPARC_TLS_IE_ADD:
3955 // This seems to be mainly so that we can find the addition
3956 // instruction if there is one. There doesn't seem to be any
3957 // actual relocation to apply.
3960 case elfcpp::R_SPARC_TLS_LE_HIX22:
3961 // If we're creating a shared library, a dynamic relocation will
3962 // have been created for this location, so do not apply it now.
3963 if (!parameters->options().shared())
3965 value -= tls_segment->memsz();
3966 Reloc::hix22(view, value, addend);
3970 case elfcpp::R_SPARC_TLS_LE_LOX10:
3971 // If we're creating a shared library, a dynamic relocation will
3972 // have been created for this location, so do not apply it now.
3973 if (!parameters->options().shared())
3975 value -= tls_segment->memsz();
3976 Reloc::lox10(view, value, addend);
3982 // Relax a call instruction.
3984 template<int size, bool big_endian>
3986 Target_sparc<size, big_endian>::Relocate::relax_call(
3987 Target_sparc<size, big_endian>* target,
3988 unsigned char* view,
3989 const elfcpp::Rela<size, big_endian>& rela,
3990 section_size_type view_size)
3992 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3993 Insntype *wv = reinterpret_cast<Insntype*>(view);
3994 Insntype call_insn, delay_insn, set_insn;
3995 uint32_t op3, reg, off;
3997 // This code tries to relax call instructions that meet
3998 // certain criteria.
4000 // The first criteria is that the call must be such that the return
4001 // address which the call writes into %o7 is unused. Two sequences
4002 // meet this criteria, and are used to implement tail calls.
4004 // Leaf function tail call:
4006 // or %o7, %g0, %ANY_REG
4008 // or %ANY_REG, %g0, %o7
4010 // Non-leaf function tail call:
4015 // The second criteria is that the call destination is close. If
4016 // the displacement can fit in a signed 22-bit immediate field of a
4017 // pre-V9 branch, we can do it. If we are generating a 64-bit
4018 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4019 // and the displacement fits in a signed 19-bit immediate field,
4020 // then we can use a V9 branch.
4022 // Make sure the delay instruction can be safely accessed.
4023 if (rela.get_r_offset() + 8 > view_size)
4026 call_insn = elfcpp::Swap<32, true>::readval(wv);
4027 delay_insn = elfcpp::Swap<32, true>::readval(wv + 1);
4029 // Make sure it is really a call instruction.
4030 if (((call_insn >> 30) & 0x3) != 1)
4033 if (((delay_insn >> 30) & 0x3) != 2)
4036 // Accept only a restore or an integer arithmetic operation whose
4037 // sole side effect is to write the %o7 register (and perhaps set
4038 // the condition codes, which are considered clobbered across
4041 // For example, we don't want to match a tagged addition or
4042 // subtraction. We also don't want to match something like a
4045 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4046 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4048 op3 = (delay_insn >> 19) & 0x3f;
4049 reg = (delay_insn >> 25) & 0x1f;
4051 && ((op3 & 0x28) != 0 || reg != 15))
4054 // For non-restore instructions, make sure %o7 isn't
4059 reg = (delay_insn >> 14) & 0x15;
4063 // And if non-immediate, check RS2
4064 if (((delay_insn >> 13) & 1) == 0)
4066 reg = (delay_insn & 0x1f);
4072 // Now check the branch distance. We are called after the
4073 // call has been relocated, so we just have to peek at the
4074 // offset contained in the instruction.
4075 off = call_insn & 0x3fffffff;
4076 if ((off & 0x3fe00000) != 0
4077 && (off & 0x3fe00000) != 0x3fe00000)
4080 if ((size == 64 || target->elf_machine_ == elfcpp::EM_SPARC32PLUS)
4081 && ((off & 0x3c0000) == 0
4082 || (off & 0x3c0000) == 0x3c0000))
4085 call_insn = 0x10680000 | (off & 0x07ffff);
4090 call_insn = 0x10800000 | (off & 0x3fffff);
4092 elfcpp::Swap<32, true>::writeval(wv, call_insn);
4094 // See if we can NOP out the delay slot instruction. We peek
4095 // at the instruction before the call to make sure we're dealing
4096 // with exactly the:
4098 // or %o7, %g0, %ANY_REG
4100 // or %ANY_REG, %g0, %o7
4102 // case. Otherwise this might be a tricky piece of hand written
4103 // assembler calculating %o7 in some non-trivial way, and therefore
4104 // we can't be sure that NOP'ing out the delay slot is safe.
4106 && rela.get_r_offset() >= 4)
4108 if ((delay_insn & ~(0x1f << 14)) != 0x9e100000)
4111 set_insn = elfcpp::Swap<32, true>::readval(wv - 1);
4112 if ((set_insn & ~(0x1f << 25)) != 0x8013c000)
4115 reg = (set_insn >> 25) & 0x1f;
4116 if (reg == 0 || reg == 15)
4118 if (reg != ((delay_insn >> 14) & 0x1f))
4121 // All tests pass, nop it out.
4122 elfcpp::Swap<32, true>::writeval(wv + 1, sparc_nop);
4126 // Relocate section data.
4128 template<int size, bool big_endian>
4130 Target_sparc<size, big_endian>::relocate_section(
4131 const Relocate_info<size, big_endian>* relinfo,
4132 unsigned int sh_type,
4133 const unsigned char* prelocs,
4135 Output_section* output_section,
4136 bool needs_special_offset_handling,
4137 unsigned char* view,
4138 typename elfcpp::Elf_types<size>::Elf_Addr address,
4139 section_size_type view_size,
4140 const Reloc_symbol_changes* reloc_symbol_changes)
4142 typedef Target_sparc<size, big_endian> Sparc;
4143 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
4145 gold_assert(sh_type == elfcpp::SHT_RELA);
4147 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
4148 Sparc_relocate, gold::Default_comdat_behavior>(
4154 needs_special_offset_handling,
4158 reloc_symbol_changes);
4161 // Return the size of a relocation while scanning during a relocatable
4164 template<int size, bool big_endian>
4166 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
4170 // We are always SHT_RELA, so we should never get here.
4175 // Scan the relocs during a relocatable link.
4177 template<int size, bool big_endian>
4179 Target_sparc<size, big_endian>::scan_relocatable_relocs(
4180 Symbol_table* symtab,
4182 Sized_relobj_file<size, big_endian>* object,
4183 unsigned int data_shndx,
4184 unsigned int sh_type,
4185 const unsigned char* prelocs,
4187 Output_section* output_section,
4188 bool needs_special_offset_handling,
4189 size_t local_symbol_count,
4190 const unsigned char* plocal_symbols,
4191 Relocatable_relocs* rr)
4193 gold_assert(sh_type == elfcpp::SHT_RELA);
4195 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4196 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4198 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
4199 Scan_relocatable_relocs>(
4207 needs_special_offset_handling,
4213 // Emit relocations for a section.
4215 template<int size, bool big_endian>
4217 Target_sparc<size, big_endian>::relocate_relocs(
4218 const Relocate_info<size, big_endian>* relinfo,
4219 unsigned int sh_type,
4220 const unsigned char* prelocs,
4222 Output_section* output_section,
4223 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
4224 const Relocatable_relocs* rr,
4225 unsigned char* view,
4226 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4227 section_size_type view_size,
4228 unsigned char* reloc_view,
4229 section_size_type reloc_view_size)
4231 gold_assert(sh_type == elfcpp::SHT_RELA);
4233 gold::relocate_relocs<size, big_endian, elfcpp::SHT_RELA>(
4238 offset_in_output_section,
4247 // Return the value to use for a dynamic which requires special
4248 // treatment. This is how we support equality comparisons of function
4249 // pointers across shared library boundaries, as described in the
4250 // processor specific ABI supplement.
4252 template<int size, bool big_endian>
4254 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
4256 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4257 return this->plt_section()->address() + gsym->plt_offset();
4260 // do_make_elf_object to override the same function in the base class.
4261 // We need to use a target-specific sub-class of
4262 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4263 // of the ELF headers. Hence we need to have our own ELF object creation.
4265 template<int size, bool big_endian>
4267 Target_sparc<size, big_endian>::do_make_elf_object(
4268 const std::string& name,
4269 Input_file* input_file,
4270 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
4272 elfcpp::Elf_Half machine = ehdr.get_e_machine();
4273 elfcpp::Elf_Word flags = ehdr.get_e_flags();
4274 elfcpp::Elf_Word omm, mm;
4278 case elfcpp::EM_SPARC32PLUS:
4279 this->elf_machine_ = elfcpp::EM_SPARC32PLUS;
4282 case elfcpp::EM_SPARC:
4283 case elfcpp::EM_SPARCV9:
4290 if (!this->elf_flags_set_)
4292 this->elf_flags_ = flags;
4293 this->elf_flags_set_ = true;
4297 // Accumulate cpu feature bits.
4298 this->elf_flags_ |= (flags & (elfcpp::EF_SPARC_32PLUS
4299 | elfcpp::EF_SPARC_SUN_US1
4300 | elfcpp::EF_SPARC_HAL_R1
4301 | elfcpp::EF_SPARC_SUN_US3));
4303 // Bump the memory model setting to the most restrictive
4304 // one we encounter.
4305 omm = (this->elf_flags_ & elfcpp::EF_SPARCV9_MM);
4306 mm = (flags & elfcpp::EF_SPARCV9_MM);
4309 if (mm == elfcpp::EF_SPARCV9_TSO)
4311 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4312 this->elf_flags_ |= elfcpp::EF_SPARCV9_TSO;
4314 else if (mm == elfcpp::EF_SPARCV9_PSO
4315 && omm == elfcpp::EF_SPARCV9_RMO)
4317 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4318 this->elf_flags_ |= elfcpp::EF_SPARCV9_PSO;
4323 // Validate that the little-endian flag matches how we've
4324 // been instantiated.
4325 if (!(flags & elfcpp::EF_SPARC_LEDATA) != big_endian)
4328 gold_error(_("%s: little endian elf flag set on BE object"),
4331 gold_error(_("%s: little endian elf flag clear on LE object"),
4335 return Target::do_make_elf_object(name, input_file, offset, ehdr);
4338 // Adjust ELF file header.
4340 template<int size, bool big_endian>
4342 Target_sparc<size, big_endian>::do_adjust_elf_header(
4343 unsigned char* view,
4346 elfcpp::Ehdr_write<size, big_endian> oehdr(view);
4348 oehdr.put_e_machine(this->elf_machine_);
4349 oehdr.put_e_flags(this->elf_flags_);
4351 Sized_target<size, big_endian>::do_adjust_elf_header(view, len);
4354 // The selector for sparc object files.
4356 template<int size, bool big_endian>
4357 class Target_selector_sparc : public Target_selector
4360 Target_selector_sparc()
4361 : Target_selector(elfcpp::EM_NONE, size, big_endian,
4362 (size == 64 ? "elf64-sparc" : "elf32-sparc"),
4363 (size == 64 ? "elf64_sparc" : "elf32_sparc"))
4367 do_recognize(Input_file*, off_t, int machine, int, int)
4372 if (machine != elfcpp::EM_SPARCV9)
4377 if (machine != elfcpp::EM_SPARC
4378 && machine != elfcpp::EM_SPARC32PLUS)
4386 return this->instantiate_target();
4390 do_instantiate_target()
4391 { return new Target_sparc<size, big_endian>(); }
4394 Target_selector_sparc<32, true> target_selector_sparc32;
4395 Target_selector_sparc<64, true> target_selector_sparc64;
4397 } // End anonymous namespace.