1 // sparc.cc -- sparc target support for gold.
3 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size, bool big_endian>
51 class Output_data_plt_sparc;
53 template<int size, bool big_endian>
54 class Target_sparc : public Sized_target<size, big_endian>
57 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
60 : Sized_target<size, big_endian>(&sparc_info),
61 got_(NULL), plt_(NULL), rela_dyn_(NULL), rela_ifunc_(NULL),
62 copy_relocs_(elfcpp::R_SPARC_COPY),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL),
64 elf_machine_(sparc_info.machine_code), elf_flags_(0),
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);
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 unsigned int r_type = elfcpp::elf_r_type<size>(reloc.get_r_info());
419 this->copy_relocs_.copy_reloc(symtab, layout,
420 symtab->get_sized_symbol<size>(sym),
421 object, shndx, output_section,
422 r_type, reloc.get_r_offset(),
423 reloc.get_r_addend(),
424 this->rela_dyn_section(layout));
427 // Information about this specific target which we pass to the
428 // general Target structure.
429 static Target::Target_info sparc_info;
431 // The types of GOT entries needed for this platform.
432 // These values are exposed to the ABI in an incremental link.
433 // Do not renumber existing values without changing the version
434 // number of the .gnu_incremental_inputs section.
437 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
438 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
439 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
443 Output_data_got<size, big_endian>* got_;
445 Output_data_plt_sparc<size, big_endian>* plt_;
446 // The dynamic reloc section.
447 Reloc_section* rela_dyn_;
448 // The section to use for IFUNC relocs.
449 Reloc_section* rela_ifunc_;
450 // Relocs saved to avoid a COPY reloc.
451 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
452 // Offset of the GOT entry for the TLS module index;
453 unsigned int got_mod_index_offset_;
454 // Cached pointer to __tls_get_addr symbol
455 Symbol* tls_get_addr_sym_;
456 // Accumulated elf machine type
457 elfcpp::Elf_Half elf_machine_;
458 // Accumulated elf header flags
459 elfcpp::Elf_Word elf_flags_;
460 // Whether elf_flags_ has been set for the first time yet
465 Target::Target_info Target_sparc<32, true>::sparc_info =
468 true, // is_big_endian
469 elfcpp::EM_SPARC, // machine_code
470 false, // has_make_symbol
471 false, // has_resolve
472 false, // has_code_fill
473 true, // is_default_stack_executable
474 false, // can_icf_inline_merge_sections
476 "/usr/lib/ld.so.1", // dynamic_linker
477 0x00010000, // default_text_segment_address
478 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
479 8 * 1024, // common_pagesize (overridable by -z common-page-size)
480 false, // isolate_execinstr
482 elfcpp::SHN_UNDEF, // small_common_shndx
483 elfcpp::SHN_UNDEF, // large_common_shndx
484 0, // small_common_section_flags
485 0, // large_common_section_flags
486 NULL, // attributes_section
487 NULL, // attributes_vendor
488 "_start", // entry_symbol_name
489 32, // hash_entry_size
493 Target::Target_info Target_sparc<64, true>::sparc_info =
496 true, // is_big_endian
497 elfcpp::EM_SPARCV9, // machine_code
498 false, // has_make_symbol
499 false, // has_resolve
500 false, // has_code_fill
501 true, // is_default_stack_executable
502 false, // can_icf_inline_merge_sections
504 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
505 0x100000, // default_text_segment_address
506 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
507 8 * 1024, // common_pagesize (overridable by -z common-page-size)
508 false, // isolate_execinstr
510 elfcpp::SHN_UNDEF, // small_common_shndx
511 elfcpp::SHN_UNDEF, // large_common_shndx
512 0, // small_common_section_flags
513 0, // large_common_section_flags
514 NULL, // attributes_section
515 NULL, // attributes_vendor
516 "_start", // entry_symbol_name
517 32, // hash_entry_size
520 // We have to take care here, even when operating in little-endian
521 // mode, sparc instructions are still big endian.
522 template<int size, bool big_endian>
523 class Sparc_relocate_functions
526 // Do a simple relocation with the addend in the relocation.
527 template<int valsize>
529 rela(unsigned char* view,
530 unsigned int right_shift,
531 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
532 typename elfcpp::Swap<size, big_endian>::Valtype value,
533 typename elfcpp::Swap<size, big_endian>::Valtype addend)
535 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
536 Valtype* wv = reinterpret_cast<Valtype*>(view);
537 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
538 Valtype reloc = ((value + addend) >> right_shift);
543 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
546 // Do a simple relocation using a symbol value with the addend in
548 template<int valsize>
550 rela(unsigned char* view,
551 unsigned int right_shift,
552 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
553 const Sized_relobj_file<size, big_endian>* object,
554 const Symbol_value<size>* psymval,
555 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
557 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
558 Valtype* wv = reinterpret_cast<Valtype*>(view);
559 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
560 Valtype reloc = (psymval->value(object, addend) >> right_shift);
565 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
568 // Do a simple relocation using a symbol value with the addend in
569 // the relocation, unaligned.
570 template<int valsize>
572 rela_ua(unsigned char* view,
573 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
574 const Sized_relobj_file<size, big_endian>* object,
575 const Symbol_value<size>* psymval,
576 typename elfcpp::Swap<size, big_endian>::Valtype addend)
578 typedef typename elfcpp::Swap_unaligned<valsize,
579 big_endian>::Valtype Valtype;
580 unsigned char* wv = view;
581 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
582 Valtype reloc = (psymval->value(object, addend) >> right_shift);
587 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
590 // Do a simple PC relative relocation with a Symbol_value with the
591 // addend in the relocation.
592 template<int valsize>
594 pcrela(unsigned char* view,
595 unsigned int right_shift,
596 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
597 const Sized_relobj_file<size, big_endian>* object,
598 const Symbol_value<size>* psymval,
599 typename elfcpp::Swap<size, big_endian>::Valtype addend,
600 typename elfcpp::Elf_types<size>::Elf_Addr address)
602 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
603 Valtype* wv = reinterpret_cast<Valtype*>(view);
604 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
605 Valtype reloc = ((psymval->value(object, addend) - address)
611 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
614 template<int valsize>
616 pcrela_unaligned(unsigned char* view,
617 const Sized_relobj_file<size, big_endian>* object,
618 const Symbol_value<size>* psymval,
619 typename elfcpp::Swap<size, big_endian>::Valtype addend,
620 typename elfcpp::Elf_types<size>::Elf_Addr address)
622 typedef typename elfcpp::Swap_unaligned<valsize,
623 big_endian>::Valtype Valtype;
624 unsigned char* wv = view;
625 Valtype reloc = (psymval->value(object, addend) - address);
627 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
630 typedef Sparc_relocate_functions<size, big_endian> This;
631 typedef Sparc_relocate_functions<size, true> This_insn;
634 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
636 wdisp30(unsigned char* view,
637 const Sized_relobj_file<size, big_endian>* object,
638 const Symbol_value<size>* psymval,
639 typename elfcpp::Elf_types<size>::Elf_Addr addend,
640 typename elfcpp::Elf_types<size>::Elf_Addr address)
642 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
643 psymval, addend, address);
646 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
648 wdisp22(unsigned char* view,
649 const Sized_relobj_file<size, big_endian>* object,
650 const Symbol_value<size>* psymval,
651 typename elfcpp::Elf_types<size>::Elf_Addr addend,
652 typename elfcpp::Elf_types<size>::Elf_Addr address)
654 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
655 psymval, addend, address);
658 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
660 wdisp19(unsigned char* view,
661 const Sized_relobj_file<size, big_endian>* object,
662 const Symbol_value<size>* psymval,
663 typename elfcpp::Elf_types<size>::Elf_Addr addend,
664 typename elfcpp::Elf_types<size>::Elf_Addr address)
666 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
667 psymval, addend, address);
670 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
672 wdisp16(unsigned char* view,
673 const Sized_relobj_file<size, big_endian>* object,
674 const Symbol_value<size>* psymval,
675 typename elfcpp::Elf_types<size>::Elf_Addr addend,
676 typename elfcpp::Elf_types<size>::Elf_Addr address)
678 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
679 Valtype* wv = reinterpret_cast<Valtype*>(view);
680 Valtype val = elfcpp::Swap<32, true>::readval(wv);
681 Valtype reloc = ((psymval->value(object, addend) - address)
684 // The relocation value is split between the low 14 bits,
686 val &= ~((0x3 << 20) | 0x3fff);
687 reloc = (((reloc & 0xc000) << (20 - 14))
688 | (reloc & 0x3ffff));
690 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
693 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
695 wdisp10(unsigned char* view,
696 const Sized_relobj_file<size, big_endian>* object,
697 const Symbol_value<size>* psymval,
698 typename elfcpp::Elf_types<size>::Elf_Addr addend,
699 typename elfcpp::Elf_types<size>::Elf_Addr address)
701 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
702 Valtype* wv = reinterpret_cast<Valtype*>(view);
703 Valtype val = elfcpp::Swap<32, true>::readval(wv);
704 Valtype reloc = ((psymval->value(object, addend) - address)
707 // The relocation value is split between the low bits 5-12,
708 // and high bits 19-20.
709 val &= ~((0x3 << 19) | (0xff << 5));
710 reloc = (((reloc & 0x300) << (19 - 8))
711 | ((reloc & 0xff) << (5 - 0)));
713 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
716 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
718 pc22(unsigned char* view,
719 const Sized_relobj_file<size, big_endian>* object,
720 const Symbol_value<size>* psymval,
721 typename elfcpp::Elf_types<size>::Elf_Addr addend,
722 typename elfcpp::Elf_types<size>::Elf_Addr address)
724 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
725 psymval, addend, address);
728 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
730 pc10(unsigned char* view,
731 const Sized_relobj_file<size, big_endian>* object,
732 const Symbol_value<size>* psymval,
733 typename elfcpp::Elf_types<size>::Elf_Addr addend,
734 typename elfcpp::Elf_types<size>::Elf_Addr address)
736 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
737 psymval, addend, address);
740 // R_SPARC_HI22: (Symbol + Addend) >> 10
742 hi22(unsigned char* view,
743 typename elfcpp::Elf_types<size>::Elf_Addr value,
744 typename elfcpp::Elf_types<size>::Elf_Addr addend)
746 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
749 // R_SPARC_HI22: (Symbol + Addend) >> 10
751 hi22(unsigned char* view,
752 const Sized_relobj_file<size, big_endian>* object,
753 const Symbol_value<size>* psymval,
754 typename elfcpp::Elf_types<size>::Elf_Addr addend)
756 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
759 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
761 pcplt22(unsigned char* view,
762 const Sized_relobj_file<size, big_endian>* object,
763 const Symbol_value<size>* psymval,
764 typename elfcpp::Elf_types<size>::Elf_Addr addend,
765 typename elfcpp::Elf_types<size>::Elf_Addr address)
767 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
768 psymval, addend, address);
771 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
773 lo10(unsigned char* view,
774 typename elfcpp::Elf_types<size>::Elf_Addr value,
775 typename elfcpp::Elf_types<size>::Elf_Addr addend)
777 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
780 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
782 lo10(unsigned char* view,
783 const Sized_relobj_file<size, big_endian>* object,
784 const Symbol_value<size>* psymval,
785 typename elfcpp::Elf_types<size>::Elf_Addr addend)
787 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
790 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
792 lo10(unsigned char* view,
793 const Sized_relobj_file<size, big_endian>* object,
794 const Symbol_value<size>* psymval,
795 typename elfcpp::Elf_types<size>::Elf_Addr addend,
796 typename elfcpp::Elf_types<size>::Elf_Addr address)
798 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
799 psymval, addend, address);
802 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
804 olo10(unsigned char* view,
805 const Sized_relobj_file<size, big_endian>* object,
806 const Symbol_value<size>* psymval,
807 typename elfcpp::Elf_types<size>::Elf_Addr addend,
808 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
810 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
811 Valtype* wv = reinterpret_cast<Valtype*>(view);
812 Valtype val = elfcpp::Swap<32, true>::readval(wv);
813 Valtype reloc = psymval->value(object, addend);
820 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
823 // R_SPARC_22: (Symbol + Addend)
825 rela32_22(unsigned char* view,
826 const Sized_relobj_file<size, big_endian>* object,
827 const Symbol_value<size>* psymval,
828 typename elfcpp::Elf_types<size>::Elf_Addr addend)
830 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
833 // R_SPARC_13: (Symbol + Addend)
835 rela32_13(unsigned char* view,
836 typename elfcpp::Elf_types<size>::Elf_Addr value,
837 typename elfcpp::Elf_types<size>::Elf_Addr addend)
839 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
842 // R_SPARC_13: (Symbol + Addend)
844 rela32_13(unsigned char* view,
845 const Sized_relobj_file<size, big_endian>* object,
846 const Symbol_value<size>* psymval,
847 typename elfcpp::Elf_types<size>::Elf_Addr addend)
849 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
852 // R_SPARC_UA16: (Symbol + Addend)
854 ua16(unsigned char* view,
855 const Sized_relobj_file<size, big_endian>* object,
856 const Symbol_value<size>* psymval,
857 typename elfcpp::Elf_types<size>::Elf_Addr addend)
859 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
862 // R_SPARC_UA32: (Symbol + Addend)
864 ua32(unsigned char* view,
865 const Sized_relobj_file<size, big_endian>* object,
866 const Symbol_value<size>* psymval,
867 typename elfcpp::Elf_types<size>::Elf_Addr addend)
869 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
872 // R_SPARC_UA64: (Symbol + Addend)
874 ua64(unsigned char* view,
875 const Sized_relobj_file<size, big_endian>* object,
876 const Symbol_value<size>* psymval,
877 typename elfcpp::Elf_types<size>::Elf_Addr addend)
879 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
880 object, psymval, addend);
883 // R_SPARC_DISP8: (Symbol + Addend - Address)
885 disp8(unsigned char* view,
886 const Sized_relobj_file<size, big_endian>* object,
887 const Symbol_value<size>* psymval,
888 typename elfcpp::Elf_types<size>::Elf_Addr addend,
889 typename elfcpp::Elf_types<size>::Elf_Addr address)
891 This::template pcrela_unaligned<8>(view, object, psymval,
895 // R_SPARC_DISP16: (Symbol + Addend - Address)
897 disp16(unsigned char* view,
898 const Sized_relobj_file<size, big_endian>* object,
899 const Symbol_value<size>* psymval,
900 typename elfcpp::Elf_types<size>::Elf_Addr addend,
901 typename elfcpp::Elf_types<size>::Elf_Addr address)
903 This::template pcrela_unaligned<16>(view, object, psymval,
907 // R_SPARC_DISP32: (Symbol + Addend - Address)
909 disp32(unsigned char* view,
910 const Sized_relobj_file<size, big_endian>* object,
911 const Symbol_value<size>* psymval,
912 typename elfcpp::Elf_types<size>::Elf_Addr addend,
913 typename elfcpp::Elf_types<size>::Elf_Addr address)
915 This::template pcrela_unaligned<32>(view, object, psymval,
919 // R_SPARC_DISP64: (Symbol + Addend - Address)
921 disp64(unsigned char* view,
922 const Sized_relobj_file<size, big_endian>* object,
923 const Symbol_value<size>* psymval,
924 elfcpp::Elf_Xword addend,
925 typename elfcpp::Elf_types<size>::Elf_Addr address)
927 This::template pcrela_unaligned<64>(view, object, psymval,
931 // R_SPARC_H34: (Symbol + Addend) >> 12
933 h34(unsigned char* view,
934 const Sized_relobj_file<size, big_endian>* object,
935 const Symbol_value<size>* psymval,
936 typename elfcpp::Elf_types<size>::Elf_Addr addend)
938 This_insn::template rela<32>(view, 12, 0x003fffff, object, psymval, addend);
941 // R_SPARC_H44: (Symbol + Addend) >> 22
943 h44(unsigned char* view,
944 const Sized_relobj_file<size, big_endian>* object,
945 const Symbol_value<size>* psymval,
946 typename elfcpp::Elf_types<size>::Elf_Addr addend)
948 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
951 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
953 m44(unsigned char* view,
954 const Sized_relobj_file<size, big_endian>* object,
955 const Symbol_value<size>* psymval,
956 typename elfcpp::Elf_types<size>::Elf_Addr addend)
958 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
961 // R_SPARC_L44: (Symbol + Addend) & 0xfff
963 l44(unsigned char* view,
964 const Sized_relobj_file<size, big_endian>* object,
965 const Symbol_value<size>* psymval,
966 typename elfcpp::Elf_types<size>::Elf_Addr addend)
968 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
971 // R_SPARC_HH22: (Symbol + Addend) >> 42
973 hh22(unsigned char* view,
974 const Sized_relobj_file<size, big_endian>* object,
975 const Symbol_value<size>* psymval,
976 typename elfcpp::Elf_types<size>::Elf_Addr addend)
978 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
981 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
983 pc_hh22(unsigned char* view,
984 const Sized_relobj_file<size, big_endian>* object,
985 const Symbol_value<size>* psymval,
986 typename elfcpp::Elf_types<size>::Elf_Addr addend,
987 typename elfcpp::Elf_types<size>::Elf_Addr address)
989 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
990 psymval, addend, address);
993 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
995 hm10(unsigned char* view,
996 const Sized_relobj_file<size, big_endian>* object,
997 const Symbol_value<size>* psymval,
998 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1000 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
1003 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
1005 pc_hm10(unsigned char* view,
1006 const Sized_relobj_file<size, big_endian>* object,
1007 const Symbol_value<size>* psymval,
1008 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1009 typename elfcpp::Elf_types<size>::Elf_Addr address)
1011 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
1012 psymval, addend, address);
1015 // R_SPARC_11: (Symbol + Addend)
1017 rela32_11(unsigned char* view,
1018 const Sized_relobj_file<size, big_endian>* object,
1019 const Symbol_value<size>* psymval,
1020 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1022 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
1025 // R_SPARC_10: (Symbol + Addend)
1027 rela32_10(unsigned char* view,
1028 const Sized_relobj_file<size, big_endian>* object,
1029 const Symbol_value<size>* psymval,
1030 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1032 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
1035 // R_SPARC_7: (Symbol + Addend)
1037 rela32_7(unsigned char* view,
1038 const Sized_relobj_file<size, big_endian>* object,
1039 const Symbol_value<size>* psymval,
1040 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1042 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
1045 // R_SPARC_6: (Symbol + Addend)
1047 rela32_6(unsigned char* view,
1048 const Sized_relobj_file<size, big_endian>* object,
1049 const Symbol_value<size>* psymval,
1050 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1052 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
1055 // R_SPARC_5: (Symbol + Addend)
1057 rela32_5(unsigned char* view,
1058 const Sized_relobj_file<size, big_endian>* object,
1059 const Symbol_value<size>* psymval,
1060 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1062 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
1065 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1067 ldo_hix22(unsigned char* view,
1068 typename elfcpp::Elf_types<size>::Elf_Addr value,
1069 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1071 This_insn::hi22(view, value, addend);
1074 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1076 ldo_lox10(unsigned char* view,
1077 typename elfcpp::Elf_types<size>::Elf_Addr value,
1078 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1080 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1081 Valtype* wv = reinterpret_cast<Valtype*>(view);
1082 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1083 Valtype reloc = (value + addend);
1088 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1091 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1093 hix22(unsigned char* view,
1094 typename elfcpp::Elf_types<size>::Elf_Addr value,
1095 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1097 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1098 Valtype* wv = reinterpret_cast<Valtype*>(view);
1099 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1100 Valtype reloc = (value + addend);
1104 reloc ^= ~(Valtype)0;
1109 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1112 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1114 gdop_hix22(unsigned char* view,
1115 typename elfcpp::Elf_types<size>::Elf_Addr value)
1117 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1118 Valtype* wv = reinterpret_cast<Valtype*>(view);
1119 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1120 int32_t reloc = static_cast<int32_t>(value);
1125 reloc ^= ~static_cast<int32_t>(0);
1130 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1133 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1135 hix22(unsigned char* view,
1136 const Sized_relobj_file<size, big_endian>* object,
1137 const Symbol_value<size>* psymval,
1138 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1140 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1141 Valtype* wv = reinterpret_cast<Valtype*>(view);
1142 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1143 Valtype reloc = psymval->value(object, addend);
1147 reloc ^= ~(Valtype)0;
1152 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1156 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1158 lox10(unsigned char* view,
1159 typename elfcpp::Elf_types<size>::Elf_Addr value,
1160 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1162 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1163 Valtype* wv = reinterpret_cast<Valtype*>(view);
1164 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1165 Valtype reloc = (value + addend);
1171 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1174 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1176 gdop_lox10(unsigned char* view,
1177 typename elfcpp::Elf_types<size>::Elf_Addr value)
1179 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1180 Valtype* wv = reinterpret_cast<Valtype*>(view);
1181 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1182 int32_t reloc = static_cast<int32_t>(value);
1185 reloc = (reloc & 0x3ff) | 0x1c00;
1187 reloc = (reloc & 0x3ff);
1190 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1193 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1195 lox10(unsigned char* view,
1196 const Sized_relobj_file<size, big_endian>* object,
1197 const Symbol_value<size>* psymval,
1198 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1200 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1201 Valtype* wv = reinterpret_cast<Valtype*>(view);
1202 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1203 Valtype reloc = psymval->value(object, addend);
1209 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1213 // Get the GOT section, creating it if necessary.
1215 template<int size, bool big_endian>
1216 Output_data_got<size, big_endian>*
1217 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
1220 if (this->got_ == NULL)
1222 gold_assert(symtab != NULL && layout != NULL);
1224 this->got_ = new Output_data_got<size, big_endian>();
1226 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1228 | elfcpp::SHF_WRITE),
1229 this->got_, ORDER_RELRO, true);
1231 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1232 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1233 Symbol_table::PREDEFINED,
1235 0, 0, elfcpp::STT_OBJECT,
1237 elfcpp::STV_HIDDEN, 0,
1244 // Get the dynamic reloc section, creating it if necessary.
1246 template<int size, bool big_endian>
1247 typename Target_sparc<size, big_endian>::Reloc_section*
1248 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1250 if (this->rela_dyn_ == NULL)
1252 gold_assert(layout != NULL);
1253 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1254 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1255 elfcpp::SHF_ALLOC, this->rela_dyn_,
1256 ORDER_DYNAMIC_RELOCS, false);
1258 return this->rela_dyn_;
1261 // Get the section to use for IFUNC relocs, creating it if
1262 // necessary. These go in .rela.dyn, but only after all other dynamic
1263 // relocations. They need to follow the other dynamic relocations so
1264 // that they can refer to global variables initialized by those
1267 template<int size, bool big_endian>
1268 typename Target_sparc<size, big_endian>::Reloc_section*
1269 Target_sparc<size, big_endian>::rela_ifunc_section(Layout* layout)
1271 if (this->rela_ifunc_ == NULL)
1273 // Make sure we have already created the dynamic reloc section.
1274 this->rela_dyn_section(layout);
1275 this->rela_ifunc_ = new Reloc_section(false);
1276 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1277 elfcpp::SHF_ALLOC, this->rela_ifunc_,
1278 ORDER_DYNAMIC_RELOCS, false);
1279 gold_assert(this->rela_dyn_->output_section()
1280 == this->rela_ifunc_->output_section());
1282 return this->rela_ifunc_;
1285 // A class to handle the PLT data.
1287 template<int size, bool big_endian>
1288 class Output_data_plt_sparc : public Output_section_data
1291 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1292 size, big_endian> Reloc_section;
1294 Output_data_plt_sparc(Layout*);
1296 // Add an entry to the PLT.
1297 void add_entry(Symbol_table* symtab, Layout* layout, Symbol* gsym);
1299 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1301 add_local_ifunc_entry(Symbol_table*, Layout*,
1302 Sized_relobj_file<size, big_endian>* relobj,
1303 unsigned int local_sym_index);
1305 // Return the .rela.plt section data.
1306 const Reloc_section* rel_plt() const
1311 // Return where the IFUNC relocations should go.
1313 rela_ifunc(Symbol_table*, Layout*);
1316 emit_pending_ifunc_relocs();
1318 // Return whether we created a section for IFUNC relocations.
1320 has_ifunc_section() const
1321 { return this->ifunc_rel_ != NULL; }
1323 // Return the number of PLT entries.
1326 { return this->count_ + this->ifunc_count_; }
1328 // Return the offset of the first non-reserved PLT entry.
1330 first_plt_entry_offset()
1331 { return 4 * base_plt_entry_size; }
1333 // Return the size of a PLT entry.
1335 get_plt_entry_size()
1336 { return base_plt_entry_size; }
1338 // Return the PLT address to use for a global symbol.
1340 address_for_global(const Symbol*);
1342 // Return the PLT address to use for a local symbol.
1344 address_for_local(const Relobj*, unsigned int symndx);
1347 void do_adjust_output_section(Output_section* os);
1349 // Write to a map file.
1351 do_print_to_mapfile(Mapfile* mapfile) const
1352 { mapfile->print_output_data(this, _("** PLT")); }
1355 // The size of an entry in the PLT.
1356 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1358 static const unsigned int plt_entries_per_block = 160;
1359 static const unsigned int plt_insn_chunk_size = 24;
1360 static const unsigned int plt_pointer_chunk_size = 8;
1361 static const unsigned int plt_block_size =
1362 (plt_entries_per_block
1363 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1366 plt_index_to_offset(unsigned int index)
1368 section_offset_type offset;
1370 if (size == 32 || index < 32768)
1371 offset = index * base_plt_entry_size;
1374 unsigned int ext_index = index - 32768;
1376 offset = (32768 * base_plt_entry_size)
1377 + ((ext_index / plt_entries_per_block)
1379 + ((ext_index % plt_entries_per_block)
1380 * plt_insn_chunk_size);
1385 // Set the final size.
1387 set_final_data_size()
1389 unsigned int full_count = this->entry_count() + 4;
1390 unsigned int extra = (size == 32 ? 4 : 0);
1391 section_offset_type sz = plt_index_to_offset(full_count) + extra;
1393 return this->set_data_size(sz);
1396 // Write out the PLT data.
1398 do_write(Output_file*);
1404 unsigned int plt_index;
1410 Sized_relobj_file<size, big_endian>* object;
1411 unsigned int local_sym_index;
1412 unsigned int plt_index;
1415 // The reloc section.
1416 Reloc_section* rel_;
1417 // The IFUNC relocations, if necessary. These must follow the
1418 // regular relocations.
1419 Reloc_section* ifunc_rel_;
1420 // The number of PLT entries.
1421 unsigned int count_;
1422 // The number of PLT entries for IFUNC symbols.
1423 unsigned int ifunc_count_;
1424 // Global STT_GNU_IFUNC symbols.
1425 std::vector<Global_ifunc> global_ifuncs_;
1426 // Local STT_GNU_IFUNC symbols.
1427 std::vector<Local_ifunc> local_ifuncs_;
1430 // Define the constants as required by C++ standard.
1432 template<int size, bool big_endian>
1433 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1435 template<int size, bool big_endian>
1437 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1439 template<int size, bool big_endian>
1440 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1442 template<int size, bool big_endian>
1444 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1446 template<int size, bool big_endian>
1447 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1449 // Create the PLT section. The ordinary .got section is an argument,
1450 // since we need to refer to the start.
1452 template<int size, bool big_endian>
1453 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1454 : Output_section_data(size == 32 ? 4 : 8), ifunc_rel_(NULL),
1455 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1457 this->rel_ = new Reloc_section(false);
1458 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1459 elfcpp::SHF_ALLOC, this->rel_,
1460 ORDER_DYNAMIC_PLT_RELOCS, false);
1463 template<int size, bool big_endian>
1465 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1470 // Add an entry to the PLT.
1472 template<int size, bool big_endian>
1474 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol_table* symtab,
1478 gold_assert(!gsym->has_plt_offset());
1480 section_offset_type plt_offset;
1483 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1484 && gsym->can_use_relative_reloc(false))
1486 index = this->ifunc_count_;
1487 plt_offset = plt_index_to_offset(index);
1488 gsym->set_plt_offset(plt_offset);
1489 ++this->ifunc_count_;
1490 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1492 struct Global_ifunc gi;
1495 gi.plt_index = index;
1496 this->global_ifuncs_.push_back(gi);
1500 plt_offset = plt_index_to_offset(this->count_ + 4);
1501 gsym->set_plt_offset(plt_offset);
1503 gsym->set_needs_dynsym_entry();
1504 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1508 // Note that we don't need to save the symbol. The contents of the
1509 // PLT are independent of which symbols are used. The symbols only
1510 // appear in the relocations.
1513 template<int size, bool big_endian>
1515 Output_data_plt_sparc<size, big_endian>::add_local_ifunc_entry(
1516 Symbol_table* symtab,
1518 Sized_relobj_file<size, big_endian>* relobj,
1519 unsigned int local_sym_index)
1521 unsigned int index = this->ifunc_count_;
1522 section_offset_type plt_offset;
1524 plt_offset = plt_index_to_offset(index);
1525 ++this->ifunc_count_;
1527 Reloc_section* rel = this->rela_ifunc(symtab, layout);
1529 struct Local_ifunc li;
1532 li.local_sym_index = local_sym_index;
1533 li.plt_index = index;
1534 this->local_ifuncs_.push_back(li);
1539 // Emit any pending IFUNC plt relocations.
1541 template<int size, bool big_endian>
1543 Output_data_plt_sparc<size, big_endian>::emit_pending_ifunc_relocs()
1545 // Emit any pending IFUNC relocs.
1546 for (typename std::vector<Global_ifunc>::const_iterator p =
1547 this->global_ifuncs_.begin();
1548 p != this->global_ifuncs_.end();
1551 section_offset_type plt_offset;
1554 index = this->count_ + p->plt_index + 4;
1555 plt_offset = this->plt_index_to_offset(index);
1556 p->rel->add_symbolless_global_addend(p->gsym, elfcpp::R_SPARC_JMP_IREL,
1557 this, plt_offset, 0);
1560 for (typename std::vector<Local_ifunc>::const_iterator p =
1561 this->local_ifuncs_.begin();
1562 p != this->local_ifuncs_.end();
1565 section_offset_type plt_offset;
1568 index = this->count_ + p->plt_index + 4;
1569 plt_offset = this->plt_index_to_offset(index);
1570 p->rel->add_symbolless_local_addend(p->object, p->local_sym_index,
1571 elfcpp::R_SPARC_JMP_IREL,
1572 this, plt_offset, 0);
1576 // Return where the IFUNC relocations should go in the PLT. These
1577 // follow the non-IFUNC relocations.
1579 template<int size, bool big_endian>
1580 typename Output_data_plt_sparc<size, big_endian>::Reloc_section*
1581 Output_data_plt_sparc<size, big_endian>::rela_ifunc(
1582 Symbol_table* symtab,
1585 if (this->ifunc_rel_ == NULL)
1587 this->ifunc_rel_ = new Reloc_section(false);
1588 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1589 elfcpp::SHF_ALLOC, this->ifunc_rel_,
1590 ORDER_DYNAMIC_PLT_RELOCS, false);
1591 gold_assert(this->ifunc_rel_->output_section()
1592 == this->rel_->output_section());
1594 if (parameters->doing_static_link())
1596 // A statically linked executable will only have a .rel.plt
1597 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1598 // relocs for STT_GNU_IFUNC symbols. The library will use
1599 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1600 // at program startup time.
1601 symtab->define_in_output_data("__rela_iplt_start", NULL,
1602 Symbol_table::PREDEFINED,
1603 this->ifunc_rel_, 0, 0,
1604 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1605 elfcpp::STV_HIDDEN, 0, false, true);
1606 symtab->define_in_output_data("__rela_iplt_end", NULL,
1607 Symbol_table::PREDEFINED,
1608 this->ifunc_rel_, 0, 0,
1609 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
1610 elfcpp::STV_HIDDEN, 0, true, true);
1613 return this->ifunc_rel_;
1616 // Return the PLT address to use for a global symbol.
1618 template<int size, bool big_endian>
1620 Output_data_plt_sparc<size, big_endian>::address_for_global(const Symbol* gsym)
1622 uint64_t offset = 0;
1623 if (gsym->type() == elfcpp::STT_GNU_IFUNC
1624 && gsym->can_use_relative_reloc(false))
1625 offset = plt_index_to_offset(this->count_ + 4);
1626 return this->address() + offset + gsym->plt_offset();
1629 // Return the PLT address to use for a local symbol. These are always
1630 // IRELATIVE relocs.
1632 template<int size, bool big_endian>
1634 Output_data_plt_sparc<size, big_endian>::address_for_local(
1635 const Relobj* object,
1638 return (this->address()
1639 + plt_index_to_offset(this->count_ + 4)
1640 + object->local_plt_offset(r_sym));
1643 static const unsigned int sparc_nop = 0x01000000;
1644 static const unsigned int sparc_sethi_g1 = 0x03000000;
1645 static const unsigned int sparc_branch_always = 0x30800000;
1646 static const unsigned int sparc_branch_always_pt = 0x30680000;
1647 static const unsigned int sparc_mov = 0x80100000;
1648 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1649 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1650 static const unsigned int sparc_call_plus_8 = 0x40000002;
1651 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1652 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1653 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1655 // Write out the PLT.
1657 template<int size, bool big_endian>
1659 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1661 const off_t offset = this->offset();
1662 const section_size_type oview_size =
1663 convert_to_section_size_type(this->data_size());
1664 unsigned char* const oview = of->get_output_view(offset, oview_size);
1665 unsigned char* pov = oview;
1667 memset(pov, 0, base_plt_entry_size * 4);
1668 pov += this->first_plt_entry_offset();
1670 unsigned int plt_offset = base_plt_entry_size * 4;
1671 const unsigned int count = this->entry_count();
1677 limit = (count > 32768 ? 32768 : count);
1679 for (unsigned int i = 0; i < limit; ++i)
1681 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1682 sparc_sethi_g1 + plt_offset);
1683 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1684 sparc_branch_always_pt +
1685 (((base_plt_entry_size -
1686 (plt_offset + 4)) >> 2) &
1688 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1689 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1690 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1691 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1692 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1693 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1695 pov += base_plt_entry_size;
1696 plt_offset += base_plt_entry_size;
1701 unsigned int ext_cnt = count - 32768;
1702 unsigned int blks = ext_cnt / plt_entries_per_block;
1704 for (unsigned int i = 0; i < blks; ++i)
1706 unsigned int data_off = (plt_entries_per_block
1707 * plt_insn_chunk_size) - 4;
1709 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1711 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1713 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1715 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1717 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1718 sparc_ldx_o7_imm_g1 +
1719 (data_off & 0x1fff));
1720 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1721 sparc_jmpl_o7_g1_g1);
1722 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1725 elfcpp::Swap<64, big_endian>::writeval(
1726 pov + 0x4 + data_off,
1727 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1729 pov += plt_insn_chunk_size;
1734 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1735 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1737 unsigned int data_off = (sub_blk_cnt
1738 * plt_insn_chunk_size) - 4;
1740 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1742 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1744 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1746 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1748 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1749 sparc_ldx_o7_imm_g1 +
1750 (data_off & 0x1fff));
1751 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1752 sparc_jmpl_o7_g1_g1);
1753 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1756 elfcpp::Swap<64, big_endian>::writeval(
1757 pov + 0x4 + data_off,
1758 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1760 pov += plt_insn_chunk_size;
1768 for (unsigned int i = 0; i < count; ++i)
1770 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1771 sparc_sethi_g1 + plt_offset);
1772 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1773 sparc_branch_always +
1774 (((- (plt_offset + 4)) >> 2) &
1776 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1778 pov += base_plt_entry_size;
1779 plt_offset += base_plt_entry_size;
1782 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1786 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1788 of->write_output_view(offset, oview_size, oview);
1791 // Create the PLT section.
1793 template<int size, bool big_endian>
1795 Target_sparc<size, big_endian>::make_plt_section(Symbol_table* symtab,
1798 // Create the GOT sections first.
1799 this->got_section(symtab, layout);
1801 // Ensure that .rela.dyn always appears before .rela.plt This is
1802 // necessary due to how, on Sparc and some other targets, .rela.dyn
1803 // needs to include .rela.plt in it's range.
1804 this->rela_dyn_section(layout);
1806 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1807 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1809 | elfcpp::SHF_EXECINSTR
1810 | elfcpp::SHF_WRITE),
1811 this->plt_, ORDER_NON_RELRO_FIRST, false);
1813 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1814 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1815 Symbol_table::PREDEFINED,
1817 0, 0, elfcpp::STT_OBJECT,
1819 elfcpp::STV_HIDDEN, 0,
1823 // Create a PLT entry for a global symbol.
1825 template<int size, bool big_endian>
1827 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1831 if (gsym->has_plt_offset())
1834 if (this->plt_ == NULL)
1835 this->make_plt_section(symtab, layout);
1837 this->plt_->add_entry(symtab, layout, gsym);
1840 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1842 template<int size, bool big_endian>
1844 Target_sparc<size, big_endian>::make_local_ifunc_plt_entry(
1845 Symbol_table* symtab,
1847 Sized_relobj_file<size, big_endian>* relobj,
1848 unsigned int local_sym_index)
1850 if (relobj->local_has_plt_offset(local_sym_index))
1852 if (this->plt_ == NULL)
1853 this->make_plt_section(symtab, layout);
1854 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
1857 relobj->set_local_plt_offset(local_sym_index, plt_offset);
1860 // Return the number of entries in the PLT.
1862 template<int size, bool big_endian>
1864 Target_sparc<size, big_endian>::plt_entry_count() const
1866 if (this->plt_ == NULL)
1868 return this->plt_->entry_count();
1871 // Return the offset of the first non-reserved PLT entry.
1873 template<int size, bool big_endian>
1875 Target_sparc<size, big_endian>::first_plt_entry_offset() const
1877 return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset();
1880 // Return the size of each PLT entry.
1882 template<int size, bool big_endian>
1884 Target_sparc<size, big_endian>::plt_entry_size() const
1886 return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size();
1889 // Create a GOT entry for the TLS module index.
1891 template<int size, bool big_endian>
1893 Target_sparc<size, big_endian>::got_mod_index_entry(
1894 Symbol_table* symtab,
1896 Sized_relobj_file<size, big_endian>* object)
1898 if (this->got_mod_index_offset_ == -1U)
1900 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1901 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1902 Output_data_got<size, big_endian>* got;
1903 unsigned int got_offset;
1905 got = this->got_section(symtab, layout);
1906 got_offset = got->add_constant(0);
1907 rela_dyn->add_local(object, 0,
1909 elfcpp::R_SPARC_TLS_DTPMOD64 :
1910 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1912 got->add_constant(0);
1913 this->got_mod_index_offset_ = got_offset;
1915 return this->got_mod_index_offset_;
1918 // Optimize the TLS relocation type based on what we know about the
1919 // symbol. IS_FINAL is true if the final address of this symbol is
1920 // known at link time.
1922 static tls::Tls_optimization
1923 optimize_tls_reloc(bool is_final, int r_type)
1925 // If we are generating a shared library, then we can't do anything
1927 if (parameters->options().shared())
1928 return tls::TLSOPT_NONE;
1932 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1933 case elfcpp::R_SPARC_TLS_GD_LO10:
1934 case elfcpp::R_SPARC_TLS_GD_ADD:
1935 case elfcpp::R_SPARC_TLS_GD_CALL:
1936 // These are General-Dynamic which permits fully general TLS
1937 // access. Since we know that we are generating an executable,
1938 // we can convert this to Initial-Exec. If we also know that
1939 // this is a local symbol, we can further switch to Local-Exec.
1941 return tls::TLSOPT_TO_LE;
1942 return tls::TLSOPT_TO_IE;
1944 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1945 case elfcpp::R_SPARC_TLS_LDM_LO10:
1946 case elfcpp::R_SPARC_TLS_LDM_ADD:
1947 case elfcpp::R_SPARC_TLS_LDM_CALL:
1948 // This is Local-Dynamic, which refers to a local symbol in the
1949 // dynamic TLS block. Since we know that we generating an
1950 // executable, we can switch to Local-Exec.
1951 return tls::TLSOPT_TO_LE;
1953 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1954 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1955 case elfcpp::R_SPARC_TLS_LDO_ADD:
1956 // Another type of Local-Dynamic relocation.
1957 return tls::TLSOPT_TO_LE;
1959 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1960 case elfcpp::R_SPARC_TLS_IE_LO10:
1961 case elfcpp::R_SPARC_TLS_IE_LD:
1962 case elfcpp::R_SPARC_TLS_IE_LDX:
1963 case elfcpp::R_SPARC_TLS_IE_ADD:
1964 // These are Initial-Exec relocs which get the thread offset
1965 // from the GOT. If we know that we are linking against the
1966 // local symbol, we can switch to Local-Exec, which links the
1967 // thread offset into the instruction.
1969 return tls::TLSOPT_TO_LE;
1970 return tls::TLSOPT_NONE;
1972 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1973 case elfcpp::R_SPARC_TLS_LE_LOX10:
1974 // When we already have Local-Exec, there is nothing further we
1976 return tls::TLSOPT_NONE;
1983 // Get the Reference_flags for a particular relocation.
1985 template<int size, bool big_endian>
1987 Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
1992 case elfcpp::R_SPARC_NONE:
1993 case elfcpp::R_SPARC_REGISTER:
1994 case elfcpp::R_SPARC_GNU_VTINHERIT:
1995 case elfcpp::R_SPARC_GNU_VTENTRY:
1996 // No symbol reference.
1999 case elfcpp::R_SPARC_UA64:
2000 case elfcpp::R_SPARC_64:
2001 case elfcpp::R_SPARC_HIX22:
2002 case elfcpp::R_SPARC_LOX10:
2003 case elfcpp::R_SPARC_H34:
2004 case elfcpp::R_SPARC_H44:
2005 case elfcpp::R_SPARC_M44:
2006 case elfcpp::R_SPARC_L44:
2007 case elfcpp::R_SPARC_HH22:
2008 case elfcpp::R_SPARC_HM10:
2009 case elfcpp::R_SPARC_LM22:
2010 case elfcpp::R_SPARC_HI22:
2011 case elfcpp::R_SPARC_LO10:
2012 case elfcpp::R_SPARC_OLO10:
2013 case elfcpp::R_SPARC_UA32:
2014 case elfcpp::R_SPARC_32:
2015 case elfcpp::R_SPARC_UA16:
2016 case elfcpp::R_SPARC_16:
2017 case elfcpp::R_SPARC_11:
2018 case elfcpp::R_SPARC_10:
2019 case elfcpp::R_SPARC_8:
2020 case elfcpp::R_SPARC_7:
2021 case elfcpp::R_SPARC_6:
2022 case elfcpp::R_SPARC_5:
2023 return Symbol::ABSOLUTE_REF;
2025 case elfcpp::R_SPARC_DISP8:
2026 case elfcpp::R_SPARC_DISP16:
2027 case elfcpp::R_SPARC_DISP32:
2028 case elfcpp::R_SPARC_DISP64:
2029 case elfcpp::R_SPARC_PC_HH22:
2030 case elfcpp::R_SPARC_PC_HM10:
2031 case elfcpp::R_SPARC_PC_LM22:
2032 case elfcpp::R_SPARC_PC10:
2033 case elfcpp::R_SPARC_PC22:
2034 case elfcpp::R_SPARC_WDISP30:
2035 case elfcpp::R_SPARC_WDISP22:
2036 case elfcpp::R_SPARC_WDISP19:
2037 case elfcpp::R_SPARC_WDISP16:
2038 case elfcpp::R_SPARC_WDISP10:
2039 return Symbol::RELATIVE_REF;
2041 case elfcpp::R_SPARC_PLT64:
2042 case elfcpp::R_SPARC_PLT32:
2043 case elfcpp::R_SPARC_HIPLT22:
2044 case elfcpp::R_SPARC_LOPLT10:
2045 case elfcpp::R_SPARC_PCPLT10:
2046 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
2048 case elfcpp::R_SPARC_PCPLT32:
2049 case elfcpp::R_SPARC_PCPLT22:
2050 case elfcpp::R_SPARC_WPLT30:
2051 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
2053 case elfcpp::R_SPARC_GOTDATA_OP:
2054 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2055 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2056 case elfcpp::R_SPARC_GOT10:
2057 case elfcpp::R_SPARC_GOT13:
2058 case elfcpp::R_SPARC_GOT22:
2060 return Symbol::ABSOLUTE_REF;
2062 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2063 case elfcpp::R_SPARC_TLS_GD_LO10:
2064 case elfcpp::R_SPARC_TLS_GD_ADD:
2065 case elfcpp::R_SPARC_TLS_GD_CALL:
2066 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2067 case elfcpp::R_SPARC_TLS_LDM_LO10:
2068 case elfcpp::R_SPARC_TLS_LDM_ADD:
2069 case elfcpp::R_SPARC_TLS_LDM_CALL:
2070 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2071 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2072 case elfcpp::R_SPARC_TLS_LDO_ADD:
2073 case elfcpp::R_SPARC_TLS_LE_HIX22:
2074 case elfcpp::R_SPARC_TLS_LE_LOX10:
2075 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2076 case elfcpp::R_SPARC_TLS_IE_LO10:
2077 case elfcpp::R_SPARC_TLS_IE_LD:
2078 case elfcpp::R_SPARC_TLS_IE_LDX:
2079 case elfcpp::R_SPARC_TLS_IE_ADD:
2080 return Symbol::TLS_REF;
2082 case elfcpp::R_SPARC_COPY:
2083 case elfcpp::R_SPARC_GLOB_DAT:
2084 case elfcpp::R_SPARC_JMP_SLOT:
2085 case elfcpp::R_SPARC_JMP_IREL:
2086 case elfcpp::R_SPARC_RELATIVE:
2087 case elfcpp::R_SPARC_IRELATIVE:
2088 case elfcpp::R_SPARC_TLS_DTPMOD64:
2089 case elfcpp::R_SPARC_TLS_DTPMOD32:
2090 case elfcpp::R_SPARC_TLS_DTPOFF64:
2091 case elfcpp::R_SPARC_TLS_DTPOFF32:
2092 case elfcpp::R_SPARC_TLS_TPOFF64:
2093 case elfcpp::R_SPARC_TLS_TPOFF32:
2095 // Not expected. We will give an error later.
2100 // Generate a PLT entry slot for a call to __tls_get_addr
2101 template<int size, bool big_endian>
2103 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
2105 Target_sparc<size, big_endian>* target)
2107 Symbol* gsym = target->tls_get_addr_sym(symtab);
2109 target->make_plt_entry(symtab, layout, gsym);
2112 // Report an unsupported relocation against a local symbol.
2114 template<int size, bool big_endian>
2116 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
2117 Sized_relobj_file<size, big_endian>* object,
2118 unsigned int r_type)
2120 gold_error(_("%s: unsupported reloc %u against local symbol"),
2121 object->name().c_str(), r_type);
2124 // We are about to emit a dynamic relocation of type R_TYPE. If the
2125 // dynamic linker does not support it, issue an error.
2127 template<int size, bool big_endian>
2129 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
2131 gold_assert(r_type != elfcpp::R_SPARC_NONE);
2137 // These are the relocation types supported by glibc for sparc 64-bit.
2138 case elfcpp::R_SPARC_RELATIVE:
2139 case elfcpp::R_SPARC_IRELATIVE:
2140 case elfcpp::R_SPARC_COPY:
2141 case elfcpp::R_SPARC_64:
2142 case elfcpp::R_SPARC_GLOB_DAT:
2143 case elfcpp::R_SPARC_JMP_SLOT:
2144 case elfcpp::R_SPARC_JMP_IREL:
2145 case elfcpp::R_SPARC_TLS_DTPMOD64:
2146 case elfcpp::R_SPARC_TLS_DTPOFF64:
2147 case elfcpp::R_SPARC_TLS_TPOFF64:
2148 case elfcpp::R_SPARC_TLS_LE_HIX22:
2149 case elfcpp::R_SPARC_TLS_LE_LOX10:
2150 case elfcpp::R_SPARC_8:
2151 case elfcpp::R_SPARC_16:
2152 case elfcpp::R_SPARC_DISP8:
2153 case elfcpp::R_SPARC_DISP16:
2154 case elfcpp::R_SPARC_DISP32:
2155 case elfcpp::R_SPARC_WDISP30:
2156 case elfcpp::R_SPARC_LO10:
2157 case elfcpp::R_SPARC_HI22:
2158 case elfcpp::R_SPARC_OLO10:
2159 case elfcpp::R_SPARC_H34:
2160 case elfcpp::R_SPARC_H44:
2161 case elfcpp::R_SPARC_M44:
2162 case elfcpp::R_SPARC_L44:
2163 case elfcpp::R_SPARC_HH22:
2164 case elfcpp::R_SPARC_HM10:
2165 case elfcpp::R_SPARC_LM22:
2166 case elfcpp::R_SPARC_UA16:
2167 case elfcpp::R_SPARC_UA32:
2168 case elfcpp::R_SPARC_UA64:
2179 // These are the relocation types supported by glibc for sparc 32-bit.
2180 case elfcpp::R_SPARC_RELATIVE:
2181 case elfcpp::R_SPARC_IRELATIVE:
2182 case elfcpp::R_SPARC_COPY:
2183 case elfcpp::R_SPARC_GLOB_DAT:
2184 case elfcpp::R_SPARC_32:
2185 case elfcpp::R_SPARC_JMP_SLOT:
2186 case elfcpp::R_SPARC_JMP_IREL:
2187 case elfcpp::R_SPARC_TLS_DTPMOD32:
2188 case elfcpp::R_SPARC_TLS_DTPOFF32:
2189 case elfcpp::R_SPARC_TLS_TPOFF32:
2190 case elfcpp::R_SPARC_TLS_LE_HIX22:
2191 case elfcpp::R_SPARC_TLS_LE_LOX10:
2192 case elfcpp::R_SPARC_8:
2193 case elfcpp::R_SPARC_16:
2194 case elfcpp::R_SPARC_DISP8:
2195 case elfcpp::R_SPARC_DISP16:
2196 case elfcpp::R_SPARC_DISP32:
2197 case elfcpp::R_SPARC_LO10:
2198 case elfcpp::R_SPARC_WDISP30:
2199 case elfcpp::R_SPARC_HI22:
2200 case elfcpp::R_SPARC_UA16:
2201 case elfcpp::R_SPARC_UA32:
2209 // This prevents us from issuing more than one error per reloc
2210 // section. But we can still wind up issuing more than one
2211 // error per object file.
2212 if (this->issued_non_pic_error_)
2214 gold_assert(parameters->options().output_is_position_independent());
2215 object->error(_("requires unsupported dynamic reloc; "
2216 "recompile with -fPIC"));
2217 this->issued_non_pic_error_ = true;
2221 // Return whether we need to make a PLT entry for a relocation of the
2222 // given type against a STT_GNU_IFUNC symbol.
2224 template<int size, bool big_endian>
2226 Target_sparc<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
2227 Sized_relobj_file<size, big_endian>* object,
2228 unsigned int r_type)
2230 int flags = Scan::get_reference_flags(r_type);
2231 if (flags & Symbol::TLS_REF)
2232 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2233 object->name().c_str(), r_type);
2237 // Scan a relocation for a local symbol.
2239 template<int size, bool big_endian>
2241 Target_sparc<size, big_endian>::Scan::local(
2242 Symbol_table* symtab,
2244 Target_sparc<size, big_endian>* target,
2245 Sized_relobj_file<size, big_endian>* object,
2246 unsigned int data_shndx,
2247 Output_section* output_section,
2248 const elfcpp::Rela<size, big_endian>& reloc,
2249 unsigned int r_type,
2250 const elfcpp::Sym<size, big_endian>& lsym,
2256 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
2257 unsigned int orig_r_type = r_type;
2261 && this->reloc_needs_plt_for_ifunc(object, r_type))
2263 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2264 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
2269 case elfcpp::R_SPARC_NONE:
2270 case elfcpp::R_SPARC_REGISTER:
2271 case elfcpp::R_SPARC_GNU_VTINHERIT:
2272 case elfcpp::R_SPARC_GNU_VTENTRY:
2275 case elfcpp::R_SPARC_64:
2276 case elfcpp::R_SPARC_32:
2277 // If building a shared library (or a position-independent
2278 // executable), we need to create a dynamic relocation for
2279 // this location. The relocation applied at link time will
2280 // apply the link-time value, so we flag the location with
2281 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2282 // relocate it easily.
2283 if (parameters->options().output_is_position_independent())
2285 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2286 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2287 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
2288 output_section, data_shndx,
2289 reloc.get_r_offset(),
2290 reloc.get_r_addend(), is_ifunc);
2294 case elfcpp::R_SPARC_HIX22:
2295 case elfcpp::R_SPARC_LOX10:
2296 case elfcpp::R_SPARC_H34:
2297 case elfcpp::R_SPARC_H44:
2298 case elfcpp::R_SPARC_M44:
2299 case elfcpp::R_SPARC_L44:
2300 case elfcpp::R_SPARC_HH22:
2301 case elfcpp::R_SPARC_HM10:
2302 case elfcpp::R_SPARC_LM22:
2303 case elfcpp::R_SPARC_UA64:
2304 case elfcpp::R_SPARC_UA32:
2305 case elfcpp::R_SPARC_UA16:
2306 case elfcpp::R_SPARC_HI22:
2307 case elfcpp::R_SPARC_LO10:
2308 case elfcpp::R_SPARC_OLO10:
2309 case elfcpp::R_SPARC_16:
2310 case elfcpp::R_SPARC_11:
2311 case elfcpp::R_SPARC_10:
2312 case elfcpp::R_SPARC_8:
2313 case elfcpp::R_SPARC_7:
2314 case elfcpp::R_SPARC_6:
2315 case elfcpp::R_SPARC_5:
2316 // If building a shared library (or a position-independent
2317 // executable), we need to create a dynamic relocation for
2319 if (parameters->options().output_is_position_independent())
2321 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2322 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2324 check_non_pic(object, r_type);
2325 if (lsym.get_st_type() != elfcpp::STT_SECTION)
2327 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
2328 data_shndx, reloc.get_r_offset(),
2329 reloc.get_r_addend());
2333 gold_assert(lsym.get_st_value() == 0);
2334 rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
2335 output_section, data_shndx,
2336 reloc.get_r_offset(),
2337 reloc.get_r_addend());
2342 case elfcpp::R_SPARC_WDISP30:
2343 case elfcpp::R_SPARC_WPLT30:
2344 case elfcpp::R_SPARC_WDISP22:
2345 case elfcpp::R_SPARC_WDISP19:
2346 case elfcpp::R_SPARC_WDISP16:
2347 case elfcpp::R_SPARC_WDISP10:
2348 case elfcpp::R_SPARC_DISP8:
2349 case elfcpp::R_SPARC_DISP16:
2350 case elfcpp::R_SPARC_DISP32:
2351 case elfcpp::R_SPARC_DISP64:
2352 case elfcpp::R_SPARC_PC10:
2353 case elfcpp::R_SPARC_PC22:
2356 case elfcpp::R_SPARC_GOTDATA_OP:
2357 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2358 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2359 // We will optimize this into a GOT relative relocation
2360 // and code transform the GOT load into an addition.
2363 case elfcpp::R_SPARC_GOT10:
2364 case elfcpp::R_SPARC_GOT13:
2365 case elfcpp::R_SPARC_GOT22:
2367 // The symbol requires a GOT entry.
2368 Output_data_got<size, big_endian>* got;
2371 got = target->got_section(symtab, layout);
2372 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2374 // If we are generating a shared object, we need to add a
2375 // dynamic relocation for this symbol's GOT entry.
2376 if (parameters->options().output_is_position_independent())
2378 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
2380 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2381 unsigned int off = got->add_constant(0);
2382 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
2383 rela_dyn->add_local_relative(object, r_sym,
2384 elfcpp::R_SPARC_RELATIVE,
2385 got, off, 0, is_ifunc);
2389 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
2393 // These are initial TLS relocs, which are expected when
2395 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2396 case elfcpp::R_SPARC_TLS_GD_LO10:
2397 case elfcpp::R_SPARC_TLS_GD_ADD:
2398 case elfcpp::R_SPARC_TLS_GD_CALL:
2399 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2400 case elfcpp::R_SPARC_TLS_LDM_LO10:
2401 case elfcpp::R_SPARC_TLS_LDM_ADD:
2402 case elfcpp::R_SPARC_TLS_LDM_CALL:
2403 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2404 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2405 case elfcpp::R_SPARC_TLS_LDO_ADD:
2406 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2407 case elfcpp::R_SPARC_TLS_IE_LO10:
2408 case elfcpp::R_SPARC_TLS_IE_LD:
2409 case elfcpp::R_SPARC_TLS_IE_LDX:
2410 case elfcpp::R_SPARC_TLS_IE_ADD:
2411 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2412 case elfcpp::R_SPARC_TLS_LE_LOX10:
2414 bool output_is_shared = parameters->options().shared();
2415 const tls::Tls_optimization optimized_type
2416 = optimize_tls_reloc(!output_is_shared, r_type);
2419 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2420 case elfcpp::R_SPARC_TLS_GD_LO10:
2421 case elfcpp::R_SPARC_TLS_GD_ADD:
2422 case elfcpp::R_SPARC_TLS_GD_CALL:
2423 if (optimized_type == tls::TLSOPT_NONE)
2425 // Create a pair of GOT entries for the module index and
2426 // dtv-relative offset.
2427 Output_data_got<size, big_endian>* got
2428 = target->got_section(symtab, layout);
2429 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2430 unsigned int shndx = lsym.get_st_shndx();
2432 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
2434 object->error(_("local symbol %u has bad shndx %u"),
2437 got->add_local_pair_with_rel(object, r_sym,
2438 lsym.get_st_shndx(),
2440 target->rela_dyn_section(layout),
2442 ? elfcpp::R_SPARC_TLS_DTPMOD64
2443 : elfcpp::R_SPARC_TLS_DTPMOD32));
2444 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2445 generate_tls_call(symtab, layout, target);
2447 else if (optimized_type != tls::TLSOPT_TO_LE)
2448 unsupported_reloc_local(object, r_type);
2451 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2452 case elfcpp::R_SPARC_TLS_LDM_LO10:
2453 case elfcpp::R_SPARC_TLS_LDM_ADD:
2454 case elfcpp::R_SPARC_TLS_LDM_CALL:
2455 if (optimized_type == tls::TLSOPT_NONE)
2457 // Create a GOT entry for the module index.
2458 target->got_mod_index_entry(symtab, layout, object);
2460 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2461 generate_tls_call(symtab, layout, target);
2463 else if (optimized_type != tls::TLSOPT_TO_LE)
2464 unsupported_reloc_local(object, r_type);
2467 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2468 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2469 case elfcpp::R_SPARC_TLS_LDO_ADD:
2472 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2473 case elfcpp::R_SPARC_TLS_IE_LO10:
2474 case elfcpp::R_SPARC_TLS_IE_LD:
2475 case elfcpp::R_SPARC_TLS_IE_LDX:
2476 case elfcpp::R_SPARC_TLS_IE_ADD:
2477 layout->set_has_static_tls();
2478 if (optimized_type == tls::TLSOPT_NONE)
2480 // Create a GOT entry for the tp-relative offset.
2481 Output_data_got<size, big_endian>* got
2482 = target->got_section(symtab, layout);
2483 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2485 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
2487 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2488 unsigned int off = got->add_constant(0);
2490 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
2492 rela_dyn->add_symbolless_local_addend(object, r_sym,
2494 elfcpp::R_SPARC_TLS_TPOFF64 :
2495 elfcpp::R_SPARC_TLS_TPOFF32),
2499 else if (optimized_type != tls::TLSOPT_TO_LE)
2500 unsupported_reloc_local(object, r_type);
2503 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2504 case elfcpp::R_SPARC_TLS_LE_LOX10:
2505 layout->set_has_static_tls();
2506 if (output_is_shared)
2508 // We need to create a dynamic relocation.
2509 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2510 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2511 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2512 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
2513 output_section, data_shndx,
2514 reloc.get_r_offset(), 0);
2521 // These are relocations which should only be seen by the
2522 // dynamic linker, and should never be seen here.
2523 case elfcpp::R_SPARC_COPY:
2524 case elfcpp::R_SPARC_GLOB_DAT:
2525 case elfcpp::R_SPARC_JMP_SLOT:
2526 case elfcpp::R_SPARC_JMP_IREL:
2527 case elfcpp::R_SPARC_RELATIVE:
2528 case elfcpp::R_SPARC_IRELATIVE:
2529 case elfcpp::R_SPARC_TLS_DTPMOD64:
2530 case elfcpp::R_SPARC_TLS_DTPMOD32:
2531 case elfcpp::R_SPARC_TLS_DTPOFF64:
2532 case elfcpp::R_SPARC_TLS_DTPOFF32:
2533 case elfcpp::R_SPARC_TLS_TPOFF64:
2534 case elfcpp::R_SPARC_TLS_TPOFF32:
2535 gold_error(_("%s: unexpected reloc %u in object file"),
2536 object->name().c_str(), r_type);
2540 unsupported_reloc_local(object, r_type);
2545 // Report an unsupported relocation against a global symbol.
2547 template<int size, bool big_endian>
2549 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
2550 Sized_relobj_file<size, big_endian>* object,
2551 unsigned int r_type,
2554 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2555 object->name().c_str(), r_type, gsym->demangled_name().c_str());
2558 // Scan a relocation for a global symbol.
2560 template<int size, bool big_endian>
2562 Target_sparc<size, big_endian>::Scan::global(
2563 Symbol_table* symtab,
2565 Target_sparc<size, big_endian>* target,
2566 Sized_relobj_file<size, big_endian>* object,
2567 unsigned int data_shndx,
2568 Output_section* output_section,
2569 const elfcpp::Rela<size, big_endian>& reloc,
2570 unsigned int r_type,
2573 unsigned int orig_r_type = r_type;
2574 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2576 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2577 // section. We check here to avoid creating a dynamic reloc against
2578 // _GLOBAL_OFFSET_TABLE_.
2579 if (!target->has_got_section()
2580 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2581 target->got_section(symtab, layout);
2585 // A STT_GNU_IFUNC symbol may require a PLT entry.
2587 && this->reloc_needs_plt_for_ifunc(object, r_type))
2588 target->make_plt_entry(symtab, layout, gsym);
2592 case elfcpp::R_SPARC_NONE:
2593 case elfcpp::R_SPARC_REGISTER:
2594 case elfcpp::R_SPARC_GNU_VTINHERIT:
2595 case elfcpp::R_SPARC_GNU_VTENTRY:
2598 case elfcpp::R_SPARC_PLT64:
2599 case elfcpp::R_SPARC_PLT32:
2600 case elfcpp::R_SPARC_HIPLT22:
2601 case elfcpp::R_SPARC_LOPLT10:
2602 case elfcpp::R_SPARC_PCPLT32:
2603 case elfcpp::R_SPARC_PCPLT22:
2604 case elfcpp::R_SPARC_PCPLT10:
2605 case elfcpp::R_SPARC_WPLT30:
2606 // If the symbol is fully resolved, this is just a PC32 reloc.
2607 // Otherwise we need a PLT entry.
2608 if (gsym->final_value_is_known())
2610 // If building a shared library, we can also skip the PLT entry
2611 // if the symbol is defined in the output file and is protected
2613 if (gsym->is_defined()
2614 && !gsym->is_from_dynobj()
2615 && !gsym->is_preemptible())
2617 target->make_plt_entry(symtab, layout, gsym);
2620 case elfcpp::R_SPARC_DISP8:
2621 case elfcpp::R_SPARC_DISP16:
2622 case elfcpp::R_SPARC_DISP32:
2623 case elfcpp::R_SPARC_DISP64:
2624 case elfcpp::R_SPARC_PC_HH22:
2625 case elfcpp::R_SPARC_PC_HM10:
2626 case elfcpp::R_SPARC_PC_LM22:
2627 case elfcpp::R_SPARC_PC10:
2628 case elfcpp::R_SPARC_PC22:
2629 case elfcpp::R_SPARC_WDISP30:
2630 case elfcpp::R_SPARC_WDISP22:
2631 case elfcpp::R_SPARC_WDISP19:
2632 case elfcpp::R_SPARC_WDISP16:
2633 case elfcpp::R_SPARC_WDISP10:
2635 if (gsym->needs_plt_entry())
2636 target->make_plt_entry(symtab, layout, gsym);
2637 // Make a dynamic relocation if necessary.
2638 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2640 if (parameters->options().output_is_executable()
2641 && gsym->may_need_copy_reloc())
2643 target->copy_reloc(symtab, layout, object,
2644 data_shndx, output_section, gsym,
2649 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2650 check_non_pic(object, r_type);
2651 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
2652 data_shndx, reloc.get_r_offset(),
2653 reloc.get_r_addend());
2659 case elfcpp::R_SPARC_UA64:
2660 case elfcpp::R_SPARC_64:
2661 case elfcpp::R_SPARC_HIX22:
2662 case elfcpp::R_SPARC_LOX10:
2663 case elfcpp::R_SPARC_H34:
2664 case elfcpp::R_SPARC_H44:
2665 case elfcpp::R_SPARC_M44:
2666 case elfcpp::R_SPARC_L44:
2667 case elfcpp::R_SPARC_HH22:
2668 case elfcpp::R_SPARC_HM10:
2669 case elfcpp::R_SPARC_LM22:
2670 case elfcpp::R_SPARC_HI22:
2671 case elfcpp::R_SPARC_LO10:
2672 case elfcpp::R_SPARC_OLO10:
2673 case elfcpp::R_SPARC_UA32:
2674 case elfcpp::R_SPARC_32:
2675 case elfcpp::R_SPARC_UA16:
2676 case elfcpp::R_SPARC_16:
2677 case elfcpp::R_SPARC_11:
2678 case elfcpp::R_SPARC_10:
2679 case elfcpp::R_SPARC_8:
2680 case elfcpp::R_SPARC_7:
2681 case elfcpp::R_SPARC_6:
2682 case elfcpp::R_SPARC_5:
2684 // Make a PLT entry if necessary.
2685 if (gsym->needs_plt_entry())
2687 target->make_plt_entry(symtab, layout, gsym);
2688 // Since this is not a PC-relative relocation, we may be
2689 // taking the address of a function. In that case we need to
2690 // set the entry in the dynamic symbol table to the address of
2692 if (gsym->is_from_dynobj() && !parameters->options().shared())
2693 gsym->set_needs_dynsym_value();
2695 // Make a dynamic relocation if necessary.
2696 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2698 unsigned int r_off = reloc.get_r_offset();
2700 // The assembler can sometimes emit unaligned relocations
2701 // for dwarf2 cfi directives.
2704 case elfcpp::R_SPARC_16:
2706 orig_r_type = r_type = elfcpp::R_SPARC_UA16;
2708 case elfcpp::R_SPARC_32:
2710 orig_r_type = r_type = elfcpp::R_SPARC_UA32;
2712 case elfcpp::R_SPARC_64:
2714 orig_r_type = r_type = elfcpp::R_SPARC_UA64;
2716 case elfcpp::R_SPARC_UA16:
2718 orig_r_type = r_type = elfcpp::R_SPARC_16;
2720 case elfcpp::R_SPARC_UA32:
2722 orig_r_type = r_type = elfcpp::R_SPARC_32;
2724 case elfcpp::R_SPARC_UA64:
2726 orig_r_type = r_type = elfcpp::R_SPARC_64;
2730 if (!parameters->options().output_is_position_independent()
2731 && gsym->may_need_copy_reloc())
2733 target->copy_reloc(symtab, layout, object,
2734 data_shndx, output_section, gsym, reloc);
2736 else if (((size == 64 && r_type == elfcpp::R_SPARC_64)
2737 || (size == 32 && r_type == elfcpp::R_SPARC_32))
2738 && gsym->type() == elfcpp::STT_GNU_IFUNC
2739 && gsym->can_use_relative_reloc(false)
2740 && !gsym->is_from_dynobj()
2741 && !gsym->is_undefined()
2742 && !gsym->is_preemptible())
2744 // Use an IRELATIVE reloc for a locally defined
2745 // STT_GNU_IFUNC symbol. This makes a function
2746 // address in a PIE executable match the address in a
2747 // shared library that it links against.
2748 Reloc_section* rela_dyn =
2749 target->rela_ifunc_section(layout);
2750 unsigned int r_type = elfcpp::R_SPARC_IRELATIVE;
2751 rela_dyn->add_symbolless_global_addend(gsym, r_type,
2752 output_section, object,
2754 reloc.get_r_offset(),
2755 reloc.get_r_addend());
2757 else if ((r_type == elfcpp::R_SPARC_32
2758 || r_type == elfcpp::R_SPARC_64)
2759 && gsym->can_use_relative_reloc(false))
2761 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2762 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2763 output_section, object,
2764 data_shndx, reloc.get_r_offset(),
2765 reloc.get_r_addend(), is_ifunc);
2769 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2771 check_non_pic(object, r_type);
2772 if (gsym->is_from_dynobj()
2773 || gsym->is_undefined()
2774 || gsym->is_preemptible())
2775 rela_dyn->add_global(gsym, orig_r_type, output_section,
2777 reloc.get_r_offset(),
2778 reloc.get_r_addend());
2780 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2783 reloc.get_r_offset(),
2784 reloc.get_r_addend());
2790 case elfcpp::R_SPARC_GOTDATA_OP:
2791 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2792 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2793 if (gsym->is_defined()
2794 && !gsym->is_from_dynobj()
2795 && !gsym->is_preemptible()
2798 // We will optimize this into a GOT relative relocation
2799 // and code transform the GOT load into an addition.
2802 case elfcpp::R_SPARC_GOT10:
2803 case elfcpp::R_SPARC_GOT13:
2804 case elfcpp::R_SPARC_GOT22:
2806 // The symbol requires a GOT entry.
2807 Output_data_got<size, big_endian>* got;
2809 got = target->got_section(symtab, layout);
2810 if (gsym->final_value_is_known())
2812 // For a STT_GNU_IFUNC symbol we want the PLT address.
2813 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
2814 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
2816 got->add_global(gsym, GOT_TYPE_STANDARD);
2820 // If this symbol is not fully resolved, we need to add a
2821 // GOT entry with a dynamic relocation.
2822 bool is_ifunc = gsym->type() == elfcpp::STT_GNU_IFUNC;
2824 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2826 // 1) The symbol may be defined in some other module.
2828 // 2) We are building a shared library and this is a
2829 // protected symbol; using GLOB_DAT means that the dynamic
2830 // linker can use the address of the PLT in the main
2831 // executable when appropriate so that function address
2832 // comparisons work.
2834 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2835 // code, again so that function address comparisons work.
2836 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2837 if (gsym->is_from_dynobj()
2838 || gsym->is_undefined()
2839 || gsym->is_preemptible()
2840 || (gsym->visibility() == elfcpp::STV_PROTECTED
2841 && parameters->options().shared())
2842 || (gsym->type() == elfcpp::STT_GNU_IFUNC
2843 && parameters->options().output_is_position_independent()
2844 && !gsym->is_forced_local()))
2846 unsigned int r_type = elfcpp::R_SPARC_GLOB_DAT;
2848 // If this symbol is forced local, this relocation will
2849 // not work properly. That's because ld.so on sparc
2850 // (and 32-bit powerpc) expects st_value in the r_addend
2851 // of relocations for STB_LOCAL symbols. Curiously the
2852 // BFD linker does not promote global hidden symbols to be
2853 // STB_LOCAL in the dynamic symbol table like Gold does.
2854 gold_assert(!gsym->is_forced_local());
2855 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
2858 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2860 unsigned int off = got->add_constant(0);
2862 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2865 // Tell the dynamic linker to use the PLT address
2866 // when resolving relocations.
2867 if (gsym->is_from_dynobj()
2868 && !parameters->options().shared())
2869 gsym->set_needs_dynsym_value();
2871 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2872 got, off, 0, is_ifunc);
2878 // These are initial tls relocs, which are expected when
2880 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2881 case elfcpp::R_SPARC_TLS_GD_LO10:
2882 case elfcpp::R_SPARC_TLS_GD_ADD:
2883 case elfcpp::R_SPARC_TLS_GD_CALL:
2884 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2885 case elfcpp::R_SPARC_TLS_LDM_LO10:
2886 case elfcpp::R_SPARC_TLS_LDM_ADD:
2887 case elfcpp::R_SPARC_TLS_LDM_CALL:
2888 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2889 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2890 case elfcpp::R_SPARC_TLS_LDO_ADD:
2891 case elfcpp::R_SPARC_TLS_LE_HIX22:
2892 case elfcpp::R_SPARC_TLS_LE_LOX10:
2893 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2894 case elfcpp::R_SPARC_TLS_IE_LO10:
2895 case elfcpp::R_SPARC_TLS_IE_LD:
2896 case elfcpp::R_SPARC_TLS_IE_LDX:
2897 case elfcpp::R_SPARC_TLS_IE_ADD:
2899 const bool is_final = gsym->final_value_is_known();
2900 const tls::Tls_optimization optimized_type
2901 = optimize_tls_reloc(is_final, r_type);
2904 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2905 case elfcpp::R_SPARC_TLS_GD_LO10:
2906 case elfcpp::R_SPARC_TLS_GD_ADD:
2907 case elfcpp::R_SPARC_TLS_GD_CALL:
2908 if (optimized_type == tls::TLSOPT_NONE)
2910 // Create a pair of GOT entries for the module index and
2911 // dtv-relative offset.
2912 Output_data_got<size, big_endian>* got
2913 = target->got_section(symtab, layout);
2914 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
2915 target->rela_dyn_section(layout),
2917 ? elfcpp::R_SPARC_TLS_DTPMOD64
2918 : elfcpp::R_SPARC_TLS_DTPMOD32),
2920 ? elfcpp::R_SPARC_TLS_DTPOFF64
2921 : elfcpp::R_SPARC_TLS_DTPOFF32));
2923 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2924 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2925 generate_tls_call(symtab, layout, target);
2927 else if (optimized_type == tls::TLSOPT_TO_IE)
2929 // Create a GOT entry for the tp-relative offset.
2930 Output_data_got<size, big_endian>* got
2931 = target->got_section(symtab, layout);
2932 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2933 target->rela_dyn_section(layout),
2935 elfcpp::R_SPARC_TLS_TPOFF64 :
2936 elfcpp::R_SPARC_TLS_TPOFF32));
2938 else if (optimized_type != tls::TLSOPT_TO_LE)
2939 unsupported_reloc_global(object, r_type, gsym);
2942 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2943 case elfcpp::R_SPARC_TLS_LDM_LO10:
2944 case elfcpp::R_SPARC_TLS_LDM_ADD:
2945 case elfcpp::R_SPARC_TLS_LDM_CALL:
2946 if (optimized_type == tls::TLSOPT_NONE)
2948 // Create a GOT entry for the module index.
2949 target->got_mod_index_entry(symtab, layout, object);
2951 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2952 generate_tls_call(symtab, layout, target);
2954 else if (optimized_type != tls::TLSOPT_TO_LE)
2955 unsupported_reloc_global(object, r_type, gsym);
2958 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2959 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2960 case elfcpp::R_SPARC_TLS_LDO_ADD:
2963 case elfcpp::R_SPARC_TLS_LE_HIX22:
2964 case elfcpp::R_SPARC_TLS_LE_LOX10:
2965 layout->set_has_static_tls();
2966 if (parameters->options().shared())
2968 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2969 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2970 output_section, object,
2971 data_shndx, reloc.get_r_offset(),
2976 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2977 case elfcpp::R_SPARC_TLS_IE_LO10:
2978 case elfcpp::R_SPARC_TLS_IE_LD:
2979 case elfcpp::R_SPARC_TLS_IE_LDX:
2980 case elfcpp::R_SPARC_TLS_IE_ADD:
2981 layout->set_has_static_tls();
2982 if (optimized_type == tls::TLSOPT_NONE)
2984 // Create a GOT entry for the tp-relative offset.
2985 Output_data_got<size, big_endian>* got
2986 = target->got_section(symtab, layout);
2987 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
2988 target->rela_dyn_section(layout),
2990 ? elfcpp::R_SPARC_TLS_TPOFF64
2991 : elfcpp::R_SPARC_TLS_TPOFF32));
2993 else if (optimized_type != tls::TLSOPT_TO_LE)
2994 unsupported_reloc_global(object, r_type, gsym);
3000 // These are relocations which should only be seen by the
3001 // dynamic linker, and should never be seen here.
3002 case elfcpp::R_SPARC_COPY:
3003 case elfcpp::R_SPARC_GLOB_DAT:
3004 case elfcpp::R_SPARC_JMP_SLOT:
3005 case elfcpp::R_SPARC_JMP_IREL:
3006 case elfcpp::R_SPARC_RELATIVE:
3007 case elfcpp::R_SPARC_IRELATIVE:
3008 case elfcpp::R_SPARC_TLS_DTPMOD64:
3009 case elfcpp::R_SPARC_TLS_DTPMOD32:
3010 case elfcpp::R_SPARC_TLS_DTPOFF64:
3011 case elfcpp::R_SPARC_TLS_DTPOFF32:
3012 case elfcpp::R_SPARC_TLS_TPOFF64:
3013 case elfcpp::R_SPARC_TLS_TPOFF32:
3014 gold_error(_("%s: unexpected reloc %u in object file"),
3015 object->name().c_str(), r_type);
3019 unsupported_reloc_global(object, r_type, gsym);
3024 // Process relocations for gc.
3026 template<int size, bool big_endian>
3028 Target_sparc<size, big_endian>::gc_process_relocs(
3029 Symbol_table* symtab,
3031 Sized_relobj_file<size, big_endian>* object,
3032 unsigned int data_shndx,
3034 const unsigned char* prelocs,
3036 Output_section* output_section,
3037 bool needs_special_offset_handling,
3038 size_t local_symbol_count,
3039 const unsigned char* plocal_symbols)
3041 typedef Target_sparc<size, big_endian> Sparc;
3042 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3044 gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan,
3045 typename Target_sparc::Relocatable_size_for_reloc>(
3054 needs_special_offset_handling,
3059 // Scan relocations for a section.
3061 template<int size, bool big_endian>
3063 Target_sparc<size, big_endian>::scan_relocs(
3064 Symbol_table* symtab,
3066 Sized_relobj_file<size, big_endian>* object,
3067 unsigned int data_shndx,
3068 unsigned int sh_type,
3069 const unsigned char* prelocs,
3071 Output_section* output_section,
3072 bool needs_special_offset_handling,
3073 size_t local_symbol_count,
3074 const unsigned char* plocal_symbols)
3076 typedef Target_sparc<size, big_endian> Sparc;
3077 typedef typename Target_sparc<size, big_endian>::Scan Scan;
3079 if (sh_type == elfcpp::SHT_REL)
3081 gold_error(_("%s: unsupported REL reloc section"),
3082 object->name().c_str());
3086 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
3095 needs_special_offset_handling,
3100 // Finalize the sections.
3102 template<int size, bool big_endian>
3104 Target_sparc<size, big_endian>::do_finalize_sections(
3106 const Input_objects*,
3107 Symbol_table* symtab)
3110 this->plt_->emit_pending_ifunc_relocs();
3112 // Fill in some more dynamic tags.
3113 const Reloc_section* rel_plt = (this->plt_ == NULL
3115 : this->plt_->rel_plt());
3116 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
3117 this->rela_dyn_, true, true);
3119 // Emit any relocs we saved in an attempt to avoid generating COPY
3121 if (this->copy_relocs_.any_saved_relocs())
3122 this->copy_relocs_.emit(this->rela_dyn_section(layout));
3124 if (parameters->doing_static_link()
3125 && (this->plt_ == NULL || !this->plt_->has_ifunc_section()))
3127 // If linking statically, make sure that the __rela_iplt symbols
3128 // were defined if necessary, even if we didn't create a PLT.
3129 static const Define_symbol_in_segment syms[] =
3132 "__rela_iplt_start", // name
3133 elfcpp::PT_LOAD, // segment_type
3134 elfcpp::PF_W, // segment_flags_set
3135 elfcpp::PF(0), // segment_flags_clear
3138 elfcpp::STT_NOTYPE, // type
3139 elfcpp::STB_GLOBAL, // binding
3140 elfcpp::STV_HIDDEN, // visibility
3142 Symbol::SEGMENT_START, // offset_from_base
3146 "__rela_iplt_end", // name
3147 elfcpp::PT_LOAD, // segment_type
3148 elfcpp::PF_W, // segment_flags_set
3149 elfcpp::PF(0), // segment_flags_clear
3152 elfcpp::STT_NOTYPE, // type
3153 elfcpp::STB_GLOBAL, // binding
3154 elfcpp::STV_HIDDEN, // visibility
3156 Symbol::SEGMENT_START, // offset_from_base
3161 symtab->define_symbols(layout, 2, syms,
3162 layout->script_options()->saw_sections_clause());
3166 // Perform a relocation.
3168 template<int size, bool big_endian>
3170 Target_sparc<size, big_endian>::Relocate::relocate(
3171 const Relocate_info<size, big_endian>* relinfo,
3172 Target_sparc* target,
3175 const elfcpp::Rela<size, big_endian>& rela,
3176 unsigned int r_type,
3177 const Sized_symbol<size>* gsym,
3178 const Symbol_value<size>* psymval,
3179 unsigned char* view,
3180 typename elfcpp::Elf_types<size>::Elf_Addr address,
3181 section_size_type view_size)
3183 bool orig_is_ifunc = psymval->is_ifunc_symbol();
3186 if (this->ignore_gd_add_)
3188 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
3189 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3190 _("missing expected TLS relocation"));
3193 this->ignore_gd_add_ = false;
3201 if (this->reloc_adjust_addr_ == view)
3204 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3205 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3207 // Pick the value to use for symbols defined in shared objects.
3208 Symbol_value<size> symval;
3210 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
3212 elfcpp::Elf_Xword value;
3214 value = target->plt_address_for_global(gsym);
3216 symval.set_output_value(value);
3220 else if (gsym == NULL && orig_is_ifunc)
3222 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3223 if (object->local_has_plt_offset(r_sym))
3225 symval.set_output_value(target->plt_address_for_local(object, r_sym));
3230 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3232 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3233 // pointer points to the beginning, not the end, of the table.
3234 // So we just use the plain offset.
3235 unsigned int got_offset = 0;
3236 bool gdop_valid = false;
3239 case elfcpp::R_SPARC_GOTDATA_OP:
3240 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3241 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3242 // If this is local, we did not create a GOT entry because we
3243 // intend to transform this into a GOT relative relocation.
3245 || (gsym->is_defined()
3246 && !gsym->is_from_dynobj()
3247 && !gsym->is_preemptible()
3250 got_offset = psymval->value(object, addend) - target->got_address();
3254 case elfcpp::R_SPARC_GOT10:
3255 case elfcpp::R_SPARC_GOT13:
3256 case elfcpp::R_SPARC_GOT22:
3259 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
3260 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
3264 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3265 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
3266 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3276 case elfcpp::R_SPARC_NONE:
3277 case elfcpp::R_SPARC_REGISTER:
3278 case elfcpp::R_SPARC_GNU_VTINHERIT:
3279 case elfcpp::R_SPARC_GNU_VTENTRY:
3282 case elfcpp::R_SPARC_8:
3283 Relocate_functions<size, big_endian>::rela8(view, object,
3287 case elfcpp::R_SPARC_16:
3288 if (rela.get_r_offset() & 0x1)
3290 // The assembler can sometimes emit unaligned relocations
3291 // for dwarf2 cfi directives.
3292 Reloc::ua16(view, object, psymval, addend);
3295 Relocate_functions<size, big_endian>::rela16(view, object,
3299 case elfcpp::R_SPARC_32:
3300 if (!parameters->options().output_is_position_independent())
3302 if (rela.get_r_offset() & 0x3)
3304 // The assembler can sometimes emit unaligned relocations
3305 // for dwarf2 cfi directives.
3306 Reloc::ua32(view, object, psymval, addend);
3309 Relocate_functions<size, big_endian>::rela32(view, object,
3314 case elfcpp::R_SPARC_DISP8:
3315 Reloc::disp8(view, object, psymval, addend, address);
3318 case elfcpp::R_SPARC_DISP16:
3319 Reloc::disp16(view, object, psymval, addend, address);
3322 case elfcpp::R_SPARC_DISP32:
3323 Reloc::disp32(view, object, psymval, addend, address);
3326 case elfcpp::R_SPARC_DISP64:
3327 Reloc::disp64(view, object, psymval, addend, address);
3330 case elfcpp::R_SPARC_WDISP30:
3331 case elfcpp::R_SPARC_WPLT30:
3332 Reloc::wdisp30(view, object, psymval, addend, address);
3333 if (target->may_relax())
3334 relax_call(target, view, rela, view_size);
3337 case elfcpp::R_SPARC_WDISP22:
3338 Reloc::wdisp22(view, object, psymval, addend, address);
3341 case elfcpp::R_SPARC_WDISP19:
3342 Reloc::wdisp19(view, object, psymval, addend, address);
3345 case elfcpp::R_SPARC_WDISP16:
3346 Reloc::wdisp16(view, object, psymval, addend, address);
3349 case elfcpp::R_SPARC_WDISP10:
3350 Reloc::wdisp10(view, object, psymval, addend, address);
3353 case elfcpp::R_SPARC_HI22:
3354 Reloc::hi22(view, object, psymval, addend);
3357 case elfcpp::R_SPARC_22:
3358 Reloc::rela32_22(view, object, psymval, addend);
3361 case elfcpp::R_SPARC_13:
3362 Reloc::rela32_13(view, object, psymval, addend);
3365 case elfcpp::R_SPARC_LO10:
3366 Reloc::lo10(view, object, psymval, addend);
3369 case elfcpp::R_SPARC_GOT10:
3370 Reloc::lo10(view, got_offset, addend);
3373 case elfcpp::R_SPARC_GOTDATA_OP:
3376 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3377 Insntype* wv = reinterpret_cast<Insntype*>(view);
3380 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3381 val = elfcpp::Swap<32, true>::readval(wv);
3382 val = 0x80000000 | (val & 0x3e07c01f);
3383 elfcpp::Swap<32, true>::writeval(wv, val);
3387 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
3390 Reloc::gdop_lox10(view, got_offset);
3394 case elfcpp::R_SPARC_GOT13:
3395 Reloc::rela32_13(view, got_offset, addend);
3398 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
3401 Reloc::gdop_hix22(view, got_offset);
3405 case elfcpp::R_SPARC_GOT22:
3406 Reloc::hi22(view, got_offset, addend);
3409 case elfcpp::R_SPARC_PC10:
3410 Reloc::pc10(view, object, psymval, addend, address);
3413 case elfcpp::R_SPARC_PC22:
3414 Reloc::pc22(view, object, psymval, addend, address);
3417 case elfcpp::R_SPARC_TLS_DTPOFF32:
3418 case elfcpp::R_SPARC_UA32:
3419 Reloc::ua32(view, object, psymval, addend);
3422 case elfcpp::R_SPARC_PLT64:
3423 Relocate_functions<size, big_endian>::rela64(view, object,
3427 case elfcpp::R_SPARC_PLT32:
3428 Relocate_functions<size, big_endian>::rela32(view, object,
3432 case elfcpp::R_SPARC_HIPLT22:
3433 Reloc::hi22(view, object, psymval, addend);
3436 case elfcpp::R_SPARC_LOPLT10:
3437 Reloc::lo10(view, object, psymval, addend);
3440 case elfcpp::R_SPARC_PCPLT32:
3441 Reloc::disp32(view, object, psymval, addend, address);
3444 case elfcpp::R_SPARC_PCPLT22:
3445 Reloc::pcplt22(view, object, psymval, addend, address);
3448 case elfcpp::R_SPARC_PCPLT10:
3449 Reloc::lo10(view, object, psymval, addend, address);
3452 case elfcpp::R_SPARC_64:
3453 if (!parameters->options().output_is_position_independent())
3455 if (rela.get_r_offset() & 0x7)
3457 // The assembler can sometimes emit unaligned relocations
3458 // for dwarf2 cfi directives.
3459 Reloc::ua64(view, object, psymval, addend);
3462 Relocate_functions<size, big_endian>::rela64(view, object,
3467 case elfcpp::R_SPARC_OLO10:
3469 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
3470 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
3471 Reloc::olo10(view, object, psymval, addend, addend2);
3475 case elfcpp::R_SPARC_HH22:
3476 Reloc::hh22(view, object, psymval, addend);
3479 case elfcpp::R_SPARC_PC_HH22:
3480 Reloc::pc_hh22(view, object, psymval, addend, address);
3483 case elfcpp::R_SPARC_HM10:
3484 Reloc::hm10(view, object, psymval, addend);
3487 case elfcpp::R_SPARC_PC_HM10:
3488 Reloc::pc_hm10(view, object, psymval, addend, address);
3491 case elfcpp::R_SPARC_LM22:
3492 Reloc::hi22(view, object, psymval, addend);
3495 case elfcpp::R_SPARC_PC_LM22:
3496 Reloc::pcplt22(view, object, psymval, addend, address);
3499 case elfcpp::R_SPARC_11:
3500 Reloc::rela32_11(view, object, psymval, addend);
3503 case elfcpp::R_SPARC_10:
3504 Reloc::rela32_10(view, object, psymval, addend);
3507 case elfcpp::R_SPARC_7:
3508 Reloc::rela32_7(view, object, psymval, addend);
3511 case elfcpp::R_SPARC_6:
3512 Reloc::rela32_6(view, object, psymval, addend);
3515 case elfcpp::R_SPARC_5:
3516 Reloc::rela32_5(view, object, psymval, addend);
3519 case elfcpp::R_SPARC_HIX22:
3520 Reloc::hix22(view, object, psymval, addend);
3523 case elfcpp::R_SPARC_LOX10:
3524 Reloc::lox10(view, object, psymval, addend);
3527 case elfcpp::R_SPARC_H34:
3528 Reloc::h34(view, object, psymval, addend);
3531 case elfcpp::R_SPARC_H44:
3532 Reloc::h44(view, object, psymval, addend);
3535 case elfcpp::R_SPARC_M44:
3536 Reloc::m44(view, object, psymval, addend);
3539 case elfcpp::R_SPARC_L44:
3540 Reloc::l44(view, object, psymval, addend);
3543 case elfcpp::R_SPARC_TLS_DTPOFF64:
3544 case elfcpp::R_SPARC_UA64:
3545 Reloc::ua64(view, object, psymval, addend);
3548 case elfcpp::R_SPARC_UA16:
3549 Reloc::ua16(view, object, psymval, addend);
3552 case elfcpp::R_SPARC_TLS_GD_HI22:
3553 case elfcpp::R_SPARC_TLS_GD_LO10:
3554 case elfcpp::R_SPARC_TLS_GD_ADD:
3555 case elfcpp::R_SPARC_TLS_GD_CALL:
3556 case elfcpp::R_SPARC_TLS_LDM_HI22:
3557 case elfcpp::R_SPARC_TLS_LDM_LO10:
3558 case elfcpp::R_SPARC_TLS_LDM_ADD:
3559 case elfcpp::R_SPARC_TLS_LDM_CALL:
3560 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3561 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3562 case elfcpp::R_SPARC_TLS_LDO_ADD:
3563 case elfcpp::R_SPARC_TLS_IE_HI22:
3564 case elfcpp::R_SPARC_TLS_IE_LO10:
3565 case elfcpp::R_SPARC_TLS_IE_LD:
3566 case elfcpp::R_SPARC_TLS_IE_LDX:
3567 case elfcpp::R_SPARC_TLS_IE_ADD:
3568 case elfcpp::R_SPARC_TLS_LE_HIX22:
3569 case elfcpp::R_SPARC_TLS_LE_LOX10:
3570 this->relocate_tls(relinfo, target, relnum, rela,
3571 r_type, gsym, psymval, view,
3572 address, view_size);
3575 case elfcpp::R_SPARC_COPY:
3576 case elfcpp::R_SPARC_GLOB_DAT:
3577 case elfcpp::R_SPARC_JMP_SLOT:
3578 case elfcpp::R_SPARC_JMP_IREL:
3579 case elfcpp::R_SPARC_RELATIVE:
3580 case elfcpp::R_SPARC_IRELATIVE:
3581 // These are outstanding tls relocs, which are unexpected when
3583 case elfcpp::R_SPARC_TLS_DTPMOD64:
3584 case elfcpp::R_SPARC_TLS_DTPMOD32:
3585 case elfcpp::R_SPARC_TLS_TPOFF64:
3586 case elfcpp::R_SPARC_TLS_TPOFF32:
3587 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3588 _("unexpected reloc %u in object file"),
3593 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3594 _("unsupported reloc %u"),
3602 // Perform a TLS relocation.
3604 template<int size, bool big_endian>
3606 Target_sparc<size, big_endian>::Relocate::relocate_tls(
3607 const Relocate_info<size, big_endian>* relinfo,
3608 Target_sparc<size, big_endian>* target,
3610 const elfcpp::Rela<size, big_endian>& rela,
3611 unsigned int r_type,
3612 const Sized_symbol<size>* gsym,
3613 const Symbol_value<size>* psymval,
3614 unsigned char* view,
3615 typename elfcpp::Elf_types<size>::Elf_Addr address,
3618 Output_segment* tls_segment = relinfo->layout->tls_segment();
3619 typedef Sparc_relocate_functions<size, big_endian> Reloc;
3620 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
3621 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3623 const elfcpp::Elf_Xword addend = rela.get_r_addend();
3624 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
3626 const bool is_final =
3628 ? !parameters->options().output_is_position_independent()
3629 : gsym->final_value_is_known());
3630 const tls::Tls_optimization optimized_type
3631 = optimize_tls_reloc(is_final, r_type);
3635 case elfcpp::R_SPARC_TLS_GD_HI22:
3636 case elfcpp::R_SPARC_TLS_GD_LO10:
3637 case elfcpp::R_SPARC_TLS_GD_ADD:
3638 case elfcpp::R_SPARC_TLS_GD_CALL:
3639 if (optimized_type == tls::TLSOPT_TO_LE)
3641 Insntype* wv = reinterpret_cast<Insntype*>(view);
3644 value -= tls_segment->memsz();
3648 case elfcpp::R_SPARC_TLS_GD_HI22:
3649 // TLS_GD_HI22 --> TLS_LE_HIX22
3650 Reloc::hix22(view, value, addend);
3653 case elfcpp::R_SPARC_TLS_GD_LO10:
3654 // TLS_GD_LO10 --> TLS_LE_LOX10
3655 Reloc::lox10(view, value, addend);
3658 case elfcpp::R_SPARC_TLS_GD_ADD:
3659 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3660 val = elfcpp::Swap<32, true>::readval(wv);
3661 val = (val & ~0x7c000) | 0x1c000;
3662 elfcpp::Swap<32, true>::writeval(wv, val);
3664 case elfcpp::R_SPARC_TLS_GD_CALL:
3665 // call __tls_get_addr --> nop
3666 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3673 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3674 ? GOT_TYPE_TLS_OFFSET
3675 : GOT_TYPE_TLS_PAIR);
3678 gold_assert(gsym->has_got_offset(got_type));
3679 value = gsym->got_offset(got_type);
3683 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3684 gold_assert(object->local_has_got_offset(r_sym, got_type));
3685 value = object->local_got_offset(r_sym, got_type);
3687 if (optimized_type == tls::TLSOPT_TO_IE)
3689 Insntype* wv = reinterpret_cast<Insntype*>(view);
3694 case elfcpp::R_SPARC_TLS_GD_HI22:
3695 // TLS_GD_HI22 --> TLS_IE_HI22
3696 Reloc::hi22(view, value, addend);
3699 case elfcpp::R_SPARC_TLS_GD_LO10:
3700 // TLS_GD_LO10 --> TLS_IE_LO10
3701 Reloc::lo10(view, value, addend);
3704 case elfcpp::R_SPARC_TLS_GD_ADD:
3705 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3706 val = elfcpp::Swap<32, true>::readval(wv);
3713 elfcpp::Swap<32, true>::writeval(wv, val);
3716 case elfcpp::R_SPARC_TLS_GD_CALL:
3717 // The compiler can put the TLS_GD_ADD instruction
3718 // into the delay slot of the call. If so, we need
3719 // to transpose the two instructions so that the
3720 // new sequence works properly.
3722 // The test we use is if the instruction in the
3723 // delay slot is an add with destination register
3725 val = elfcpp::Swap<32, true>::readval(wv + 1);
3726 if ((val & 0x81f80000) == 0x80000000
3727 && ((val >> 25) & 0x1f) == 0x8)
3734 elfcpp::Swap<32, true>::writeval(wv, val);
3737 this->ignore_gd_add_ = true;
3741 // Even if the delay slot isn't the TLS_GD_ADD
3742 // instruction, we still have to handle the case
3743 // where it sets up %o0 in some other way.
3744 elfcpp::Swap<32, true>::writeval(wv, val);
3746 this->reloc_adjust_addr_ = view + 4;
3748 // call __tls_get_addr --> add %g7, %o0, %o0
3749 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
3754 else if (optimized_type == tls::TLSOPT_NONE)
3758 case elfcpp::R_SPARC_TLS_GD_HI22:
3759 Reloc::hi22(view, value, addend);
3761 case elfcpp::R_SPARC_TLS_GD_LO10:
3762 Reloc::lo10(view, value, addend);
3764 case elfcpp::R_SPARC_TLS_GD_ADD:
3766 case elfcpp::R_SPARC_TLS_GD_CALL:
3768 Symbol_value<size> symval;
3769 elfcpp::Elf_Xword value;
3772 tsym = target->tls_get_addr_sym_;
3774 value = (target->plt_section()->address() +
3775 tsym->plt_offset());
3776 symval.set_output_value(value);
3777 Reloc::wdisp30(view, object, &symval, addend, address);
3784 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3785 _("unsupported reloc %u"),
3789 case elfcpp::R_SPARC_TLS_LDM_HI22:
3790 case elfcpp::R_SPARC_TLS_LDM_LO10:
3791 case elfcpp::R_SPARC_TLS_LDM_ADD:
3792 case elfcpp::R_SPARC_TLS_LDM_CALL:
3793 if (optimized_type == tls::TLSOPT_TO_LE)
3795 Insntype* wv = reinterpret_cast<Insntype*>(view);
3799 case elfcpp::R_SPARC_TLS_LDM_HI22:
3800 case elfcpp::R_SPARC_TLS_LDM_LO10:
3801 case elfcpp::R_SPARC_TLS_LDM_ADD:
3802 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3805 case elfcpp::R_SPARC_TLS_LDM_CALL:
3806 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
3811 else if (optimized_type == tls::TLSOPT_NONE)
3813 // Relocate the field with the offset of the GOT entry for
3814 // the module index.
3815 unsigned int got_offset;
3817 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
3820 case elfcpp::R_SPARC_TLS_LDM_HI22:
3821 Reloc::hi22(view, got_offset, addend);
3823 case elfcpp::R_SPARC_TLS_LDM_LO10:
3824 Reloc::lo10(view, got_offset, addend);
3826 case elfcpp::R_SPARC_TLS_LDM_ADD:
3828 case elfcpp::R_SPARC_TLS_LDM_CALL:
3830 Symbol_value<size> symval;
3831 elfcpp::Elf_Xword value;
3834 tsym = target->tls_get_addr_sym_;
3836 value = (target->plt_section()->address() +
3837 tsym->plt_offset());
3838 symval.set_output_value(value);
3839 Reloc::wdisp30(view, object, &symval, addend, address);
3845 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3846 _("unsupported reloc %u"),
3850 // These relocs can appear in debugging sections, in which case
3851 // we won't see the TLS_LDM relocs. The local_dynamic_type
3852 // field tells us this.
3853 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3854 if (optimized_type == tls::TLSOPT_TO_LE)
3856 value -= tls_segment->memsz();
3857 Reloc::hix22(view, value, addend);
3860 Reloc::ldo_hix22(view, value, addend);
3862 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3863 if (optimized_type == tls::TLSOPT_TO_LE)
3865 value -= tls_segment->memsz();
3866 Reloc::lox10(view, value, addend);
3869 Reloc::ldo_lox10(view, value, addend);
3871 case elfcpp::R_SPARC_TLS_LDO_ADD:
3872 if (optimized_type == tls::TLSOPT_TO_LE)
3874 Insntype* wv = reinterpret_cast<Insntype*>(view);
3877 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3878 val = elfcpp::Swap<32, true>::readval(wv);
3879 val = (val & ~0x7c000) | 0x1c000;
3880 elfcpp::Swap<32, true>::writeval(wv, val);
3884 // When optimizing IE --> LE, the only relocation that is handled
3885 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3886 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3887 // rs2 and rd are the same.
3888 case elfcpp::R_SPARC_TLS_IE_LD:
3889 case elfcpp::R_SPARC_TLS_IE_LDX:
3890 if (optimized_type == tls::TLSOPT_TO_LE)
3892 Insntype* wv = reinterpret_cast<Insntype*>(view);
3893 Insntype val = elfcpp::Swap<32, true>::readval(wv);
3894 Insntype rs2 = val & 0x1f;
3895 Insntype rd = (val >> 25) & 0x1f;
3900 val = sparc_mov | (val & 0x3e00001f);
3902 elfcpp::Swap<32, true>::writeval(wv, val);
3906 case elfcpp::R_SPARC_TLS_IE_HI22:
3907 case elfcpp::R_SPARC_TLS_IE_LO10:
3908 if (optimized_type == tls::TLSOPT_TO_LE)
3910 value -= tls_segment->memsz();
3913 case elfcpp::R_SPARC_TLS_IE_HI22:
3914 // IE_HI22 --> LE_HIX22
3915 Reloc::hix22(view, value, addend);
3917 case elfcpp::R_SPARC_TLS_IE_LO10:
3918 // IE_LO10 --> LE_LOX10
3919 Reloc::lox10(view, value, addend);
3924 else if (optimized_type == tls::TLSOPT_NONE)
3926 // Relocate the field with the offset of the GOT entry for
3927 // the tp-relative offset of the symbol.
3930 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3931 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3935 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3936 gold_assert(object->local_has_got_offset(r_sym,
3937 GOT_TYPE_TLS_OFFSET));
3938 value = object->local_got_offset(r_sym,
3939 GOT_TYPE_TLS_OFFSET);
3943 case elfcpp::R_SPARC_TLS_IE_HI22:
3944 Reloc::hi22(view, value, addend);
3946 case elfcpp::R_SPARC_TLS_IE_LO10:
3947 Reloc::lo10(view, value, addend);
3952 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3953 _("unsupported reloc %u"),
3957 case elfcpp::R_SPARC_TLS_IE_ADD:
3958 // This seems to be mainly so that we can find the addition
3959 // instruction if there is one. There doesn't seem to be any
3960 // actual relocation to apply.
3963 case elfcpp::R_SPARC_TLS_LE_HIX22:
3964 // If we're creating a shared library, a dynamic relocation will
3965 // have been created for this location, so do not apply it now.
3966 if (!parameters->options().shared())
3968 value -= tls_segment->memsz();
3969 Reloc::hix22(view, value, addend);
3973 case elfcpp::R_SPARC_TLS_LE_LOX10:
3974 // If we're creating a shared library, a dynamic relocation will
3975 // have been created for this location, so do not apply it now.
3976 if (!parameters->options().shared())
3978 value -= tls_segment->memsz();
3979 Reloc::lox10(view, value, addend);
3985 // Relax a call instruction.
3987 template<int size, bool big_endian>
3989 Target_sparc<size, big_endian>::Relocate::relax_call(
3990 Target_sparc<size, big_endian>* target,
3991 unsigned char* view,
3992 const elfcpp::Rela<size, big_endian>& rela,
3993 section_size_type view_size)
3995 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
3996 Insntype *wv = reinterpret_cast<Insntype*>(view);
3997 Insntype call_insn, delay_insn, set_insn;
3998 uint32_t op3, reg, off;
4000 // This code tries to relax call instructions that meet
4001 // certain criteria.
4003 // The first criteria is that the call must be such that the return
4004 // address which the call writes into %o7 is unused. Two sequences
4005 // meet this criteria, and are used to implement tail calls.
4007 // Leaf function tail call:
4009 // or %o7, %g0, %ANY_REG
4011 // or %ANY_REG, %g0, %o7
4013 // Non-leaf function tail call:
4018 // The second criteria is that the call destination is close. If
4019 // the displacement can fit in a signed 22-bit immediate field of a
4020 // pre-V9 branch, we can do it. If we are generating a 64-bit
4021 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4022 // and the displacement fits in a signed 19-bit immediate field,
4023 // then we can use a V9 branch.
4025 // Make sure the delay instruction can be safely accessed.
4026 if (rela.get_r_offset() + 8 > view_size)
4029 call_insn = elfcpp::Swap<32, true>::readval(wv);
4030 delay_insn = elfcpp::Swap<32, true>::readval(wv + 1);
4032 // Make sure it is really a call instruction.
4033 if (((call_insn >> 30) & 0x3) != 1)
4036 if (((delay_insn >> 30) & 0x3) != 2)
4039 // Accept only a restore or an integer arithmetic operation whose
4040 // sole side effect is to write the %o7 register (and perhaps set
4041 // the condition codes, which are considered clobbered across
4044 // For example, we don't want to match a tagged addition or
4045 // subtraction. We also don't want to match something like a
4048 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4049 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4051 op3 = (delay_insn >> 19) & 0x3f;
4052 reg = (delay_insn >> 25) & 0x1f;
4054 && ((op3 & 0x28) != 0 || reg != 15))
4057 // For non-restore instructions, make sure %o7 isn't
4062 reg = (delay_insn >> 14) & 0x15;
4066 // And if non-immediate, check RS2
4067 if (((delay_insn >> 13) & 1) == 0)
4069 reg = (delay_insn & 0x1f);
4075 // Now check the branch distance. We are called after the
4076 // call has been relocated, so we just have to peek at the
4077 // offset contained in the instruction.
4078 off = call_insn & 0x3fffffff;
4079 if ((off & 0x3fe00000) != 0
4080 && (off & 0x3fe00000) != 0x3fe00000)
4083 if ((size == 64 || target->elf_machine_ == elfcpp::EM_SPARC32PLUS)
4084 && ((off & 0x3c0000) == 0
4085 || (off & 0x3c0000) == 0x3c0000))
4088 call_insn = 0x10680000 | (off & 0x07ffff);
4093 call_insn = 0x10800000 | (off & 0x3fffff);
4095 elfcpp::Swap<32, true>::writeval(wv, call_insn);
4097 // See if we can NOP out the delay slot instruction. We peek
4098 // at the instruction before the call to make sure we're dealing
4099 // with exactly the:
4101 // or %o7, %g0, %ANY_REG
4103 // or %ANY_REG, %g0, %o7
4105 // case. Otherwise this might be a tricky piece of hand written
4106 // assembler calculating %o7 in some non-trivial way, and therefore
4107 // we can't be sure that NOP'ing out the delay slot is safe.
4109 && rela.get_r_offset() >= 4)
4111 if ((delay_insn & ~(0x1f << 14)) != 0x9e100000)
4114 set_insn = elfcpp::Swap<32, true>::readval(wv - 1);
4115 if ((set_insn & ~(0x1f << 25)) != 0x8013c000)
4118 reg = (set_insn >> 25) & 0x1f;
4119 if (reg == 0 || reg == 15)
4121 if (reg != ((delay_insn >> 14) & 0x1f))
4124 // All tests pass, nop it out.
4125 elfcpp::Swap<32, true>::writeval(wv + 1, sparc_nop);
4129 // Relocate section data.
4131 template<int size, bool big_endian>
4133 Target_sparc<size, big_endian>::relocate_section(
4134 const Relocate_info<size, big_endian>* relinfo,
4135 unsigned int sh_type,
4136 const unsigned char* prelocs,
4138 Output_section* output_section,
4139 bool needs_special_offset_handling,
4140 unsigned char* view,
4141 typename elfcpp::Elf_types<size>::Elf_Addr address,
4142 section_size_type view_size,
4143 const Reloc_symbol_changes* reloc_symbol_changes)
4145 typedef Target_sparc<size, big_endian> Sparc;
4146 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
4148 gold_assert(sh_type == elfcpp::SHT_RELA);
4150 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
4151 Sparc_relocate, gold::Default_comdat_behavior>(
4157 needs_special_offset_handling,
4161 reloc_symbol_changes);
4164 // Return the size of a relocation while scanning during a relocatable
4167 template<int size, bool big_endian>
4169 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
4173 // We are always SHT_RELA, so we should never get here.
4178 // Scan the relocs during a relocatable link.
4180 template<int size, bool big_endian>
4182 Target_sparc<size, big_endian>::scan_relocatable_relocs(
4183 Symbol_table* symtab,
4185 Sized_relobj_file<size, big_endian>* object,
4186 unsigned int data_shndx,
4187 unsigned int sh_type,
4188 const unsigned char* prelocs,
4190 Output_section* output_section,
4191 bool needs_special_offset_handling,
4192 size_t local_symbol_count,
4193 const unsigned char* plocal_symbols,
4194 Relocatable_relocs* rr)
4196 gold_assert(sh_type == elfcpp::SHT_RELA);
4198 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4199 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4201 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
4202 Scan_relocatable_relocs>(
4210 needs_special_offset_handling,
4216 // Emit relocations for a section.
4218 template<int size, bool big_endian>
4220 Target_sparc<size, big_endian>::relocate_relocs(
4221 const Relocate_info<size, big_endian>* relinfo,
4222 unsigned int sh_type,
4223 const unsigned char* prelocs,
4225 Output_section* output_section,
4226 typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
4227 const Relocatable_relocs* rr,
4228 unsigned char* view,
4229 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4230 section_size_type view_size,
4231 unsigned char* reloc_view,
4232 section_size_type reloc_view_size)
4234 gold_assert(sh_type == elfcpp::SHT_RELA);
4236 gold::relocate_relocs<size, big_endian, elfcpp::SHT_RELA>(
4241 offset_in_output_section,
4250 // Return the value to use for a dynamic which requires special
4251 // treatment. This is how we support equality comparisons of function
4252 // pointers across shared library boundaries, as described in the
4253 // processor specific ABI supplement.
4255 template<int size, bool big_endian>
4257 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
4259 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4260 return this->plt_section()->address() + gsym->plt_offset();
4263 // do_make_elf_object to override the same function in the base class.
4264 // We need to use a target-specific sub-class of
4265 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4266 // of the ELF headers. Hence we need to have our own ELF object creation.
4268 template<int size, bool big_endian>
4270 Target_sparc<size, big_endian>::do_make_elf_object(
4271 const std::string& name,
4272 Input_file* input_file,
4273 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
4275 elfcpp::Elf_Half machine = ehdr.get_e_machine();
4276 elfcpp::Elf_Word flags = ehdr.get_e_flags();
4277 elfcpp::Elf_Word omm, mm;
4281 case elfcpp::EM_SPARC32PLUS:
4282 this->elf_machine_ = elfcpp::EM_SPARC32PLUS;
4285 case elfcpp::EM_SPARC:
4286 case elfcpp::EM_SPARCV9:
4293 if (!this->elf_flags_set_)
4295 this->elf_flags_ = flags;
4296 this->elf_flags_set_ = true;
4300 // Accumulate cpu feature bits.
4301 this->elf_flags_ |= (flags & (elfcpp::EF_SPARC_32PLUS
4302 | elfcpp::EF_SPARC_SUN_US1
4303 | elfcpp::EF_SPARC_HAL_R1
4304 | elfcpp::EF_SPARC_SUN_US3));
4306 // Bump the memory model setting to the most restrictive
4307 // one we encounter.
4308 omm = (this->elf_flags_ & elfcpp::EF_SPARCV9_MM);
4309 mm = (flags & elfcpp::EF_SPARCV9_MM);
4312 if (mm == elfcpp::EF_SPARCV9_TSO)
4314 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4315 this->elf_flags_ |= elfcpp::EF_SPARCV9_TSO;
4317 else if (mm == elfcpp::EF_SPARCV9_PSO
4318 && omm == elfcpp::EF_SPARCV9_RMO)
4320 this->elf_flags_ &= ~elfcpp::EF_SPARCV9_MM;
4321 this->elf_flags_ |= elfcpp::EF_SPARCV9_PSO;
4326 // Validate that the little-endian flag matches how we've
4327 // been instantiated.
4328 if (!(flags & elfcpp::EF_SPARC_LEDATA) != big_endian)
4331 gold_error(_("%s: little endian elf flag set on BE object"),
4334 gold_error(_("%s: little endian elf flag clear on LE object"),
4338 return Target::do_make_elf_object(name, input_file, offset, ehdr);
4341 // Adjust ELF file header.
4343 template<int size, bool big_endian>
4345 Target_sparc<size, big_endian>::do_adjust_elf_header(
4346 unsigned char* view,
4349 elfcpp::Ehdr_write<size, big_endian> oehdr(view);
4351 oehdr.put_e_machine(this->elf_machine_);
4352 oehdr.put_e_flags(this->elf_flags_);
4354 Sized_target<size, big_endian>::do_adjust_elf_header(view, len);
4357 // The selector for sparc object files.
4359 template<int size, bool big_endian>
4360 class Target_selector_sparc : public Target_selector
4363 Target_selector_sparc()
4364 : Target_selector(elfcpp::EM_NONE, size, big_endian,
4365 (size == 64 ? "elf64-sparc" : "elf32-sparc"),
4366 (size == 64 ? "elf64_sparc" : "elf32_sparc"))
4370 do_recognize(Input_file*, off_t, int machine, int, int)
4375 if (machine != elfcpp::EM_SPARCV9)
4380 if (machine != elfcpp::EM_SPARC
4381 && machine != elfcpp::EM_SPARC32PLUS)
4389 return this->instantiate_target();
4393 do_instantiate_target()
4394 { return new Target_sparc<size, big_endian>(); }
4397 Target_selector_sparc<32, true> target_selector_sparc32;
4398 Target_selector_sparc<64, true> target_selector_sparc64;
4400 } // End anonymous namespace.