1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011 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),
62 copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL)
67 // Process the relocations to determine unreferenced sections for
68 // garbage collection.
70 gc_process_relocs(Symbol_table* symtab,
72 Sized_relobj_file<size, big_endian>* object,
73 unsigned int data_shndx,
75 const unsigned char* prelocs,
77 Output_section* output_section,
78 bool needs_special_offset_handling,
79 size_t local_symbol_count,
80 const unsigned char* plocal_symbols);
82 // Scan the relocations to look for symbol adjustments.
84 scan_relocs(Symbol_table* symtab,
86 Sized_relobj_file<size, big_endian>* object,
87 unsigned int data_shndx,
89 const unsigned char* prelocs,
91 Output_section* output_section,
92 bool needs_special_offset_handling,
93 size_t local_symbol_count,
94 const unsigned char* plocal_symbols);
95 // Finalize the sections.
97 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
99 // Return the value to use for a dynamic which requires special
102 do_dynsym_value(const Symbol*) const;
104 // Relocate a section.
106 relocate_section(const Relocate_info<size, big_endian>*,
107 unsigned int sh_type,
108 const unsigned char* prelocs,
110 Output_section* output_section,
111 bool needs_special_offset_handling,
113 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
114 section_size_type view_size,
115 const Reloc_symbol_changes*);
117 // Scan the relocs during a relocatable link.
119 scan_relocatable_relocs(Symbol_table* symtab,
121 Sized_relobj_file<size, big_endian>* object,
122 unsigned int data_shndx,
123 unsigned int sh_type,
124 const unsigned char* prelocs,
126 Output_section* output_section,
127 bool needs_special_offset_handling,
128 size_t local_symbol_count,
129 const unsigned char* plocal_symbols,
130 Relocatable_relocs*);
132 // Relocate a section during a relocatable link.
134 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
135 unsigned int sh_type,
136 const unsigned char* prelocs,
138 Output_section* output_section,
139 off_t offset_in_output_section,
140 const Relocatable_relocs*,
142 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
143 section_size_type view_size,
144 unsigned char* reloc_view,
145 section_size_type reloc_view_size);
146 // Return whether SYM is defined by the ABI.
148 do_is_defined_by_abi(const Symbol* sym) const
150 // XXX Really need to support this better...
151 if (sym->type() == elfcpp::STT_SPARC_REGISTER)
154 return strcmp(sym->name(), "___tls_get_addr") == 0;
157 // Return whether there is a GOT section.
159 has_got_section() const
160 { return this->got_ != NULL; }
162 // Return the size of the GOT section.
166 gold_assert(this->got_ != NULL);
167 return this->got_->data_size();
170 // Return the number of entries in the GOT.
172 got_entry_count() const
174 if (this->got_ == NULL)
176 return this->got_size() / (size / 8);
179 // Return the number of entries in the PLT.
181 plt_entry_count() const;
183 // Return the offset of the first non-reserved PLT entry.
185 first_plt_entry_offset() const;
187 // Return the size of each PLT entry.
189 plt_entry_size() const;
193 // The class which scans relocations.
198 : issued_non_pic_error_(false)
202 get_reference_flags(unsigned int r_type);
205 local(Symbol_table* symtab, Layout* layout, Target_sparc* target,
206 Sized_relobj_file<size, big_endian>* object,
207 unsigned int data_shndx,
208 Output_section* output_section,
209 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
210 const elfcpp::Sym<size, big_endian>& lsym);
213 global(Symbol_table* symtab, Layout* layout, Target_sparc* target,
214 Sized_relobj_file<size, big_endian>* object,
215 unsigned int data_shndx,
216 Output_section* output_section,
217 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
221 local_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
223 Sized_relobj_file<size, big_endian>* ,
226 const elfcpp::Rela<size, big_endian>& ,
228 const elfcpp::Sym<size, big_endian>&)
232 global_reloc_may_be_function_pointer(Symbol_table* , Layout* ,
234 Sized_relobj_file<size, big_endian>* ,
237 const elfcpp::Rela<size,
239 unsigned int , Symbol*)
245 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
246 unsigned int r_type);
249 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
250 unsigned int r_type, Symbol*);
253 generate_tls_call(Symbol_table* symtab, Layout* layout,
254 Target_sparc* target);
257 check_non_pic(Relobj*, unsigned int r_type);
259 // Whether we have issued an error about a non-PIC compilation.
260 bool issued_non_pic_error_;
263 // The class which implements relocation.
268 : ignore_gd_add_(false)
273 if (this->ignore_gd_add_)
275 // FIXME: This needs to specify the location somehow.
276 gold_error(_("missing expected TLS relocation"));
280 // Do a relocation. Return false if the caller should not issue
281 // any warnings about this relocation.
283 relocate(const Relocate_info<size, big_endian>*, Target_sparc*,
284 Output_section*, size_t relnum,
285 const elfcpp::Rela<size, big_endian>&,
286 unsigned int r_type, const Sized_symbol<size>*,
287 const Symbol_value<size>*,
289 typename elfcpp::Elf_types<size>::Elf_Addr,
293 // Do a TLS relocation.
295 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
296 size_t relnum, const elfcpp::Rela<size, big_endian>&,
297 unsigned int r_type, const Sized_symbol<size>*,
298 const Symbol_value<size>*,
300 typename elfcpp::Elf_types<size>::Elf_Addr,
303 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
307 // A class which returns the size required for a relocation type,
308 // used while scanning relocs during a relocatable link.
309 class Relocatable_size_for_reloc
313 get_size_for_reloc(unsigned int, Relobj*);
316 // Get the GOT section, creating it if necessary.
317 Output_data_got<size, big_endian>*
318 got_section(Symbol_table*, Layout*);
320 // Create a PLT entry for a global symbol.
322 make_plt_entry(Symbol_table*, Layout*, Symbol*);
324 // Create a GOT entry for the TLS module index.
326 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
327 Sized_relobj_file<size, big_endian>* object);
329 // Return the gsym for "__tls_get_addr". Cache if not already
332 tls_get_addr_sym(Symbol_table* symtab)
334 if (!this->tls_get_addr_sym_)
335 this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL);
336 gold_assert(this->tls_get_addr_sym_);
337 return this->tls_get_addr_sym_;
340 // Get the PLT section.
341 const Output_data_plt_sparc<size, big_endian>*
344 gold_assert(this->plt_ != NULL);
348 // Get the dynamic reloc section, creating it if necessary.
350 rela_dyn_section(Layout*);
352 // Copy a relocation against a global symbol.
354 copy_reloc(Symbol_table* symtab, Layout* layout,
355 Sized_relobj_file<size, big_endian>* object,
356 unsigned int shndx, Output_section* output_section,
357 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
359 this->copy_relocs_.copy_reloc(symtab, layout,
360 symtab->get_sized_symbol<size>(sym),
361 object, shndx, output_section,
362 reloc, this->rela_dyn_section(layout));
365 // Information about this specific target which we pass to the
366 // general Target structure.
367 static Target::Target_info sparc_info;
369 // The types of GOT entries needed for this platform.
370 // These values are exposed to the ABI in an incremental link.
371 // Do not renumber existing values without changing the version
372 // number of the .gnu_incremental_inputs section.
375 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
376 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
377 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
381 Output_data_got<size, big_endian>* got_;
383 Output_data_plt_sparc<size, big_endian>* plt_;
384 // The dynamic reloc section.
385 Reloc_section* rela_dyn_;
386 // Relocs saved to avoid a COPY reloc.
387 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
388 // Space for variables copied with a COPY reloc.
389 Output_data_space* dynbss_;
390 // Offset of the GOT entry for the TLS module index;
391 unsigned int got_mod_index_offset_;
392 // Cached pointer to __tls_get_addr symbol
393 Symbol* tls_get_addr_sym_;
397 Target::Target_info Target_sparc<32, true>::sparc_info =
400 true, // is_big_endian
401 elfcpp::EM_SPARC, // machine_code
402 false, // has_make_symbol
403 false, // has_resolve
404 false, // has_code_fill
405 true, // is_default_stack_executable
406 false, // can_icf_inline_merge_sections
408 "/usr/lib/ld.so.1", // dynamic_linker
409 0x00010000, // default_text_segment_address
410 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
411 8 * 1024, // common_pagesize (overridable by -z common-page-size)
412 elfcpp::SHN_UNDEF, // small_common_shndx
413 elfcpp::SHN_UNDEF, // large_common_shndx
414 0, // small_common_section_flags
415 0, // large_common_section_flags
416 NULL, // attributes_section
417 NULL // attributes_vendor
421 Target::Target_info Target_sparc<64, true>::sparc_info =
424 true, // is_big_endian
425 elfcpp::EM_SPARCV9, // machine_code
426 false, // has_make_symbol
427 false, // has_resolve
428 false, // has_code_fill
429 true, // is_default_stack_executable
430 false, // can_icf_inline_merge_sections
432 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
433 0x100000, // default_text_segment_address
434 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
435 8 * 1024, // common_pagesize (overridable by -z common-page-size)
436 elfcpp::SHN_UNDEF, // small_common_shndx
437 elfcpp::SHN_UNDEF, // large_common_shndx
438 0, // small_common_section_flags
439 0, // large_common_section_flags
440 NULL, // attributes_section
441 NULL // attributes_vendor
444 // We have to take care here, even when operating in little-endian
445 // mode, sparc instructions are still big endian.
446 template<int size, bool big_endian>
447 class Sparc_relocate_functions
450 // Do a simple relocation with the addend in the relocation.
451 template<int valsize>
453 rela(unsigned char* view,
454 unsigned int right_shift,
455 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
456 typename elfcpp::Swap<size, big_endian>::Valtype value,
457 typename elfcpp::Swap<size, big_endian>::Valtype addend)
459 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
460 Valtype* wv = reinterpret_cast<Valtype*>(view);
461 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
462 Valtype reloc = ((value + addend) >> right_shift);
467 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
470 // Do a simple relocation using a symbol value with the addend in
472 template<int valsize>
474 rela(unsigned char* view,
475 unsigned int right_shift,
476 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
477 const Sized_relobj_file<size, big_endian>* object,
478 const Symbol_value<size>* psymval,
479 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
481 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
482 Valtype* wv = reinterpret_cast<Valtype*>(view);
483 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
484 Valtype reloc = (psymval->value(object, addend) >> right_shift);
489 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
492 // Do a simple relocation using a symbol value with the addend in
493 // the relocation, unaligned.
494 template<int valsize>
496 rela_ua(unsigned char* view,
497 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
498 const Sized_relobj_file<size, big_endian>* object,
499 const Symbol_value<size>* psymval,
500 typename elfcpp::Swap<size, big_endian>::Valtype addend)
502 typedef typename elfcpp::Swap_unaligned<valsize,
503 big_endian>::Valtype Valtype;
504 unsigned char* wv = view;
505 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
506 Valtype reloc = (psymval->value(object, addend) >> right_shift);
511 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
514 // Do a simple PC relative relocation with a Symbol_value with the
515 // addend in the relocation.
516 template<int valsize>
518 pcrela(unsigned char* view,
519 unsigned int right_shift,
520 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
521 const Sized_relobj_file<size, big_endian>* object,
522 const Symbol_value<size>* psymval,
523 typename elfcpp::Swap<size, big_endian>::Valtype addend,
524 typename elfcpp::Elf_types<size>::Elf_Addr address)
526 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
527 Valtype* wv = reinterpret_cast<Valtype*>(view);
528 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
529 Valtype reloc = ((psymval->value(object, addend) - address)
535 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
538 template<int valsize>
540 pcrela_unaligned(unsigned char* view,
541 const Sized_relobj_file<size, big_endian>* object,
542 const Symbol_value<size>* psymval,
543 typename elfcpp::Swap<size, big_endian>::Valtype addend,
544 typename elfcpp::Elf_types<size>::Elf_Addr address)
546 typedef typename elfcpp::Swap_unaligned<valsize,
547 big_endian>::Valtype Valtype;
548 unsigned char* wv = view;
549 Valtype reloc = (psymval->value(object, addend) - address);
551 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
554 typedef Sparc_relocate_functions<size, big_endian> This;
555 typedef Sparc_relocate_functions<size, true> This_insn;
558 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
560 wdisp30(unsigned char* view,
561 const Sized_relobj_file<size, big_endian>* object,
562 const Symbol_value<size>* psymval,
563 typename elfcpp::Elf_types<size>::Elf_Addr addend,
564 typename elfcpp::Elf_types<size>::Elf_Addr address)
566 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
567 psymval, addend, address);
570 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
572 wdisp22(unsigned char* view,
573 const Sized_relobj_file<size, big_endian>* object,
574 const Symbol_value<size>* psymval,
575 typename elfcpp::Elf_types<size>::Elf_Addr addend,
576 typename elfcpp::Elf_types<size>::Elf_Addr address)
578 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
579 psymval, addend, address);
582 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
584 wdisp19(unsigned char* view,
585 const Sized_relobj_file<size, big_endian>* object,
586 const Symbol_value<size>* psymval,
587 typename elfcpp::Elf_types<size>::Elf_Addr addend,
588 typename elfcpp::Elf_types<size>::Elf_Addr address)
590 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
591 psymval, addend, address);
594 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
596 wdisp16(unsigned char* view,
597 const Sized_relobj_file<size, big_endian>* object,
598 const Symbol_value<size>* psymval,
599 typename elfcpp::Elf_types<size>::Elf_Addr addend,
600 typename elfcpp::Elf_types<size>::Elf_Addr address)
602 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
603 Valtype* wv = reinterpret_cast<Valtype*>(view);
604 Valtype val = elfcpp::Swap<32, true>::readval(wv);
605 Valtype reloc = ((psymval->value(object, addend) - address)
608 // The relocation value is split between the low 14 bits,
610 val &= ~((0x3 << 20) | 0x3fff);
611 reloc = (((reloc & 0xc000) << (20 - 14))
612 | (reloc & 0x3ffff));
614 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
617 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
619 pc22(unsigned char* view,
620 const Sized_relobj_file<size, big_endian>* object,
621 const Symbol_value<size>* psymval,
622 typename elfcpp::Elf_types<size>::Elf_Addr addend,
623 typename elfcpp::Elf_types<size>::Elf_Addr address)
625 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
626 psymval, addend, address);
629 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
631 pc10(unsigned char* view,
632 const Sized_relobj_file<size, big_endian>* object,
633 const Symbol_value<size>* psymval,
634 typename elfcpp::Elf_types<size>::Elf_Addr addend,
635 typename elfcpp::Elf_types<size>::Elf_Addr address)
637 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
638 psymval, addend, address);
641 // R_SPARC_HI22: (Symbol + Addend) >> 10
643 hi22(unsigned char* view,
644 typename elfcpp::Elf_types<size>::Elf_Addr value,
645 typename elfcpp::Elf_types<size>::Elf_Addr addend)
647 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
650 // R_SPARC_HI22: (Symbol + Addend) >> 10
652 hi22(unsigned char* view,
653 const Sized_relobj_file<size, big_endian>* object,
654 const Symbol_value<size>* psymval,
655 typename elfcpp::Elf_types<size>::Elf_Addr addend)
657 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
660 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
662 pcplt22(unsigned char* view,
663 const Sized_relobj_file<size, big_endian>* object,
664 const Symbol_value<size>* psymval,
665 typename elfcpp::Elf_types<size>::Elf_Addr addend,
666 typename elfcpp::Elf_types<size>::Elf_Addr address)
668 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
669 psymval, addend, address);
672 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
674 lo10(unsigned char* view,
675 typename elfcpp::Elf_types<size>::Elf_Addr value,
676 typename elfcpp::Elf_types<size>::Elf_Addr addend)
678 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
681 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
683 lo10(unsigned char* view,
684 const Sized_relobj_file<size, big_endian>* object,
685 const Symbol_value<size>* psymval,
686 typename elfcpp::Elf_types<size>::Elf_Addr addend)
688 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
691 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
693 lo10(unsigned char* view,
694 const Sized_relobj_file<size, big_endian>* object,
695 const Symbol_value<size>* psymval,
696 typename elfcpp::Elf_types<size>::Elf_Addr addend,
697 typename elfcpp::Elf_types<size>::Elf_Addr address)
699 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
700 psymval, addend, address);
703 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
705 olo10(unsigned char* view,
706 const Sized_relobj_file<size, big_endian>* object,
707 const Symbol_value<size>* psymval,
708 typename elfcpp::Elf_types<size>::Elf_Addr addend,
709 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
711 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
712 Valtype* wv = reinterpret_cast<Valtype*>(view);
713 Valtype val = elfcpp::Swap<32, true>::readval(wv);
714 Valtype reloc = psymval->value(object, addend);
721 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
724 // R_SPARC_22: (Symbol + Addend)
726 rela32_22(unsigned char* view,
727 const Sized_relobj_file<size, big_endian>* object,
728 const Symbol_value<size>* psymval,
729 typename elfcpp::Elf_types<size>::Elf_Addr addend)
731 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
734 // R_SPARC_13: (Symbol + Addend)
736 rela32_13(unsigned char* view,
737 typename elfcpp::Elf_types<size>::Elf_Addr value,
738 typename elfcpp::Elf_types<size>::Elf_Addr addend)
740 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
743 // R_SPARC_13: (Symbol + Addend)
745 rela32_13(unsigned char* view,
746 const Sized_relobj_file<size, big_endian>* object,
747 const Symbol_value<size>* psymval,
748 typename elfcpp::Elf_types<size>::Elf_Addr addend)
750 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
753 // R_SPARC_UA16: (Symbol + Addend)
755 ua16(unsigned char* view,
756 const Sized_relobj_file<size, big_endian>* object,
757 const Symbol_value<size>* psymval,
758 typename elfcpp::Elf_types<size>::Elf_Addr addend)
760 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
763 // R_SPARC_UA32: (Symbol + Addend)
765 ua32(unsigned char* view,
766 const Sized_relobj_file<size, big_endian>* object,
767 const Symbol_value<size>* psymval,
768 typename elfcpp::Elf_types<size>::Elf_Addr addend)
770 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
773 // R_SPARC_UA64: (Symbol + Addend)
775 ua64(unsigned char* view,
776 const Sized_relobj_file<size, big_endian>* object,
777 const Symbol_value<size>* psymval,
778 typename elfcpp::Elf_types<size>::Elf_Addr addend)
780 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
781 object, psymval, addend);
784 // R_SPARC_DISP8: (Symbol + Addend - Address)
786 disp8(unsigned char* view,
787 const Sized_relobj_file<size, big_endian>* object,
788 const Symbol_value<size>* psymval,
789 typename elfcpp::Elf_types<size>::Elf_Addr addend,
790 typename elfcpp::Elf_types<size>::Elf_Addr address)
792 This::template pcrela_unaligned<8>(view, object, psymval,
796 // R_SPARC_DISP16: (Symbol + Addend - Address)
798 disp16(unsigned char* view,
799 const Sized_relobj_file<size, big_endian>* object,
800 const Symbol_value<size>* psymval,
801 typename elfcpp::Elf_types<size>::Elf_Addr addend,
802 typename elfcpp::Elf_types<size>::Elf_Addr address)
804 This::template pcrela_unaligned<16>(view, object, psymval,
808 // R_SPARC_DISP32: (Symbol + Addend - Address)
810 disp32(unsigned char* view,
811 const Sized_relobj_file<size, big_endian>* object,
812 const Symbol_value<size>* psymval,
813 typename elfcpp::Elf_types<size>::Elf_Addr addend,
814 typename elfcpp::Elf_types<size>::Elf_Addr address)
816 This::template pcrela_unaligned<32>(view, object, psymval,
820 // R_SPARC_DISP64: (Symbol + Addend - Address)
822 disp64(unsigned char* view,
823 const Sized_relobj_file<size, big_endian>* object,
824 const Symbol_value<size>* psymval,
825 elfcpp::Elf_Xword addend,
826 typename elfcpp::Elf_types<size>::Elf_Addr address)
828 This::template pcrela_unaligned<64>(view, object, psymval,
832 // R_SPARC_H44: (Symbol + Addend) >> 22
834 h44(unsigned char* view,
835 const Sized_relobj_file<size, big_endian>* object,
836 const Symbol_value<size>* psymval,
837 typename elfcpp::Elf_types<size>::Elf_Addr addend)
839 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
842 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
844 m44(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, 12, 0x000003ff, object, psymval, addend);
852 // R_SPARC_L44: (Symbol + Addend) & 0xfff
854 l44(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_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
862 // R_SPARC_HH22: (Symbol + Addend) >> 42
864 hh22(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_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
872 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
874 pc_hh22(unsigned char* view,
875 const Sized_relobj_file<size, big_endian>* object,
876 const Symbol_value<size>* psymval,
877 typename elfcpp::Elf_types<size>::Elf_Addr addend,
878 typename elfcpp::Elf_types<size>::Elf_Addr address)
880 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
881 psymval, addend, address);
884 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
886 hm10(unsigned char* view,
887 const Sized_relobj_file<size, big_endian>* object,
888 const Symbol_value<size>* psymval,
889 typename elfcpp::Elf_types<size>::Elf_Addr addend)
891 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
894 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
896 pc_hm10(unsigned char* view,
897 const Sized_relobj_file<size, big_endian>* object,
898 const Symbol_value<size>* psymval,
899 typename elfcpp::Elf_types<size>::Elf_Addr addend,
900 typename elfcpp::Elf_types<size>::Elf_Addr address)
902 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
903 psymval, addend, address);
906 // R_SPARC_11: (Symbol + Addend)
908 rela32_11(unsigned char* view,
909 const Sized_relobj_file<size, big_endian>* object,
910 const Symbol_value<size>* psymval,
911 typename elfcpp::Elf_types<size>::Elf_Addr addend)
913 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
916 // R_SPARC_10: (Symbol + Addend)
918 rela32_10(unsigned char* view,
919 const Sized_relobj_file<size, big_endian>* object,
920 const Symbol_value<size>* psymval,
921 typename elfcpp::Elf_types<size>::Elf_Addr addend)
923 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
926 // R_SPARC_7: (Symbol + Addend)
928 rela32_7(unsigned char* view,
929 const Sized_relobj_file<size, big_endian>* object,
930 const Symbol_value<size>* psymval,
931 typename elfcpp::Elf_types<size>::Elf_Addr addend)
933 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
936 // R_SPARC_6: (Symbol + Addend)
938 rela32_6(unsigned char* view,
939 const Sized_relobj_file<size, big_endian>* object,
940 const Symbol_value<size>* psymval,
941 typename elfcpp::Elf_types<size>::Elf_Addr addend)
943 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
946 // R_SPARC_5: (Symbol + Addend)
948 rela32_5(unsigned char* view,
949 const Sized_relobj_file<size, big_endian>* object,
950 const Symbol_value<size>* psymval,
951 typename elfcpp::Elf_types<size>::Elf_Addr addend)
953 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
956 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
958 ldo_hix22(unsigned char* view,
959 typename elfcpp::Elf_types<size>::Elf_Addr value,
960 typename elfcpp::Elf_types<size>::Elf_Addr addend)
962 This_insn::hi22(view, value, addend);
965 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
967 ldo_lox10(unsigned char* view,
968 typename elfcpp::Elf_types<size>::Elf_Addr value,
969 typename elfcpp::Elf_types<size>::Elf_Addr addend)
971 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
972 Valtype* wv = reinterpret_cast<Valtype*>(view);
973 Valtype val = elfcpp::Swap<32, true>::readval(wv);
974 Valtype reloc = (value + addend);
979 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
982 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
984 hix22(unsigned char* view,
985 typename elfcpp::Elf_types<size>::Elf_Addr value,
986 typename elfcpp::Elf_types<size>::Elf_Addr addend)
988 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
989 Valtype* wv = reinterpret_cast<Valtype*>(view);
990 Valtype val = elfcpp::Swap<32, true>::readval(wv);
991 Valtype reloc = (value + addend);
995 reloc ^= ~(Valtype)0;
1000 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1003 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1005 hix22(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)
1010 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1011 Valtype* wv = reinterpret_cast<Valtype*>(view);
1012 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1013 Valtype reloc = psymval->value(object, addend);
1017 reloc ^= ~(Valtype)0;
1022 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1026 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1028 lox10(unsigned char* view,
1029 typename elfcpp::Elf_types<size>::Elf_Addr value,
1030 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1032 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1033 Valtype* wv = reinterpret_cast<Valtype*>(view);
1034 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1035 Valtype reloc = (value + addend);
1041 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1044 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1046 lox10(unsigned char* view,
1047 const Sized_relobj_file<size, big_endian>* object,
1048 const Symbol_value<size>* psymval,
1049 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1051 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
1052 Valtype* wv = reinterpret_cast<Valtype*>(view);
1053 Valtype val = elfcpp::Swap<32, true>::readval(wv);
1054 Valtype reloc = psymval->value(object, addend);
1060 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
1064 // Get the GOT section, creating it if necessary.
1066 template<int size, bool big_endian>
1067 Output_data_got<size, big_endian>*
1068 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
1071 if (this->got_ == NULL)
1073 gold_assert(symtab != NULL && layout != NULL);
1075 this->got_ = new Output_data_got<size, big_endian>();
1077 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1079 | elfcpp::SHF_WRITE),
1080 this->got_, ORDER_RELRO, true);
1082 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1083 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1084 Symbol_table::PREDEFINED,
1086 0, 0, elfcpp::STT_OBJECT,
1088 elfcpp::STV_HIDDEN, 0,
1095 // Get the dynamic reloc section, creating it if necessary.
1097 template<int size, bool big_endian>
1098 typename Target_sparc<size, big_endian>::Reloc_section*
1099 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1101 if (this->rela_dyn_ == NULL)
1103 gold_assert(layout != NULL);
1104 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1105 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1106 elfcpp::SHF_ALLOC, this->rela_dyn_,
1107 ORDER_DYNAMIC_RELOCS, false);
1109 return this->rela_dyn_;
1112 // A class to handle the PLT data.
1114 template<int size, bool big_endian>
1115 class Output_data_plt_sparc : public Output_section_data
1118 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1119 size, big_endian> Reloc_section;
1121 Output_data_plt_sparc(Layout*);
1123 // Add an entry to the PLT.
1124 void add_entry(Symbol* gsym);
1126 // Return the .rela.plt section data.
1127 const Reloc_section* rel_plt() const
1132 // Return the number of PLT entries.
1135 { return this->count_; }
1137 // Return the offset of the first non-reserved PLT entry.
1139 first_plt_entry_offset()
1140 { return 4 * base_plt_entry_size; }
1142 // Return the size of a PLT entry.
1144 get_plt_entry_size()
1145 { return base_plt_entry_size; }
1148 void do_adjust_output_section(Output_section* os);
1150 // Write to a map file.
1152 do_print_to_mapfile(Mapfile* mapfile) const
1153 { mapfile->print_output_data(this, _("** PLT")); }
1156 // The size of an entry in the PLT.
1157 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1159 static const unsigned int plt_entries_per_block = 160;
1160 static const unsigned int plt_insn_chunk_size = 24;
1161 static const unsigned int plt_pointer_chunk_size = 8;
1162 static const unsigned int plt_block_size =
1163 (plt_entries_per_block
1164 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1166 // Set the final size.
1168 set_final_data_size()
1170 unsigned int full_count = this->count_ + 4;
1171 unsigned int extra = (size == 32 ? 4 : 0);
1173 if (size == 32 || full_count < 32768)
1174 this->set_data_size((full_count * base_plt_entry_size) + extra);
1177 unsigned int ext_cnt = full_count - 32768;
1179 this->set_data_size((32768 * base_plt_entry_size)
1181 * (plt_insn_chunk_size
1182 + plt_pointer_chunk_size)));
1186 // Write out the PLT data.
1188 do_write(Output_file*);
1190 // The reloc section.
1191 Reloc_section* rel_;
1192 // The number of PLT entries.
1193 unsigned int count_;
1196 // Define the constants as required by C++ standard.
1198 template<int size, bool big_endian>
1199 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1201 template<int size, bool big_endian>
1203 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1205 template<int size, bool big_endian>
1206 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1208 template<int size, bool big_endian>
1210 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1212 template<int size, bool big_endian>
1213 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1215 // Create the PLT section. The ordinary .got section is an argument,
1216 // since we need to refer to the start.
1218 template<int size, bool big_endian>
1219 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1220 : Output_section_data(size == 32 ? 4 : 8), count_(0)
1222 this->rel_ = new Reloc_section(false);
1223 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1224 elfcpp::SHF_ALLOC, this->rel_,
1225 ORDER_DYNAMIC_PLT_RELOCS, false);
1228 template<int size, bool big_endian>
1230 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1235 // Add an entry to the PLT.
1237 template<int size, bool big_endian>
1239 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol* gsym)
1241 gold_assert(!gsym->has_plt_offset());
1243 unsigned int index = this->count_ + 4;
1244 section_offset_type plt_offset;
1246 if (size == 32 || index < 32768)
1247 plt_offset = index * base_plt_entry_size;
1250 unsigned int ext_index = index - 32768;
1252 plt_offset = (32768 * base_plt_entry_size)
1253 + ((ext_index / plt_entries_per_block)
1255 + ((ext_index % plt_entries_per_block)
1256 * plt_insn_chunk_size);
1259 gsym->set_plt_offset(plt_offset);
1263 // Every PLT entry needs a reloc.
1264 gsym->set_needs_dynsym_entry();
1265 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1268 // Note that we don't need to save the symbol. The contents of the
1269 // PLT are independent of which symbols are used. The symbols only
1270 // appear in the relocations.
1273 static const unsigned int sparc_nop = 0x01000000;
1274 static const unsigned int sparc_sethi_g1 = 0x03000000;
1275 static const unsigned int sparc_branch_always = 0x30800000;
1276 static const unsigned int sparc_branch_always_pt = 0x30680000;
1277 static const unsigned int sparc_mov = 0x80100000;
1278 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1279 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1280 static const unsigned int sparc_call_plus_8 = 0x40000002;
1281 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1282 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1283 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1285 // Write out the PLT.
1287 template<int size, bool big_endian>
1289 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1291 const off_t offset = this->offset();
1292 const section_size_type oview_size =
1293 convert_to_section_size_type(this->data_size());
1294 unsigned char* const oview = of->get_output_view(offset, oview_size);
1295 unsigned char* pov = oview;
1297 memset(pov, 0, base_plt_entry_size * 4);
1298 pov += base_plt_entry_size * 4;
1300 unsigned int plt_offset = base_plt_entry_size * 4;
1301 const unsigned int count = this->count_;
1307 limit = (count > 32768 ? 32768 : count);
1309 for (unsigned int i = 0; i < limit; ++i)
1311 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1312 sparc_sethi_g1 + plt_offset);
1313 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1314 sparc_branch_always_pt +
1315 (((base_plt_entry_size -
1316 (plt_offset + 4)) >> 2) &
1318 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1319 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1320 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1321 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1322 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1323 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1325 pov += base_plt_entry_size;
1326 plt_offset += base_plt_entry_size;
1331 unsigned int ext_cnt = count - 32768;
1332 unsigned int blks = ext_cnt / plt_entries_per_block;
1334 for (unsigned int i = 0; i < blks; ++i)
1336 unsigned int data_off = (plt_entries_per_block
1337 * plt_insn_chunk_size) - 4;
1339 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1341 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1343 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1345 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1347 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1348 sparc_ldx_o7_imm_g1 +
1349 (data_off & 0x1fff));
1350 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1351 sparc_jmpl_o7_g1_g1);
1352 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1355 elfcpp::Swap<64, big_endian>::writeval(
1356 pov + 0x4 + data_off,
1357 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1359 pov += plt_insn_chunk_size;
1364 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1365 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1367 unsigned int data_off = (sub_blk_cnt
1368 * plt_insn_chunk_size) - 4;
1370 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1372 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1374 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1376 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1378 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1379 sparc_ldx_o7_imm_g1 +
1380 (data_off & 0x1fff));
1381 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1382 sparc_jmpl_o7_g1_g1);
1383 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1386 elfcpp::Swap<64, big_endian>::writeval(
1387 pov + 0x4 + data_off,
1388 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1390 pov += plt_insn_chunk_size;
1398 for (unsigned int i = 0; i < count; ++i)
1400 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1401 sparc_sethi_g1 + plt_offset);
1402 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1403 sparc_branch_always +
1404 (((- (plt_offset + 4)) >> 2) &
1406 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1408 pov += base_plt_entry_size;
1409 plt_offset += base_plt_entry_size;
1412 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1416 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1418 of->write_output_view(offset, oview_size, oview);
1421 // Create a PLT entry for a global symbol.
1423 template<int size, bool big_endian>
1425 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1429 if (gsym->has_plt_offset())
1432 if (this->plt_ == NULL)
1434 // Create the GOT sections first.
1435 this->got_section(symtab, layout);
1437 // Ensure that .rela.dyn always appears before .rela.plt This is
1438 // necessary due to how, on Sparc and some other targets, .rela.dyn
1439 // needs to include .rela.plt in it's range.
1440 this->rela_dyn_section(layout);
1442 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1443 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1445 | elfcpp::SHF_EXECINSTR
1446 | elfcpp::SHF_WRITE),
1447 this->plt_, ORDER_PLT, false);
1449 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1450 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1451 Symbol_table::PREDEFINED,
1453 0, 0, elfcpp::STT_OBJECT,
1455 elfcpp::STV_HIDDEN, 0,
1459 this->plt_->add_entry(gsym);
1462 // Return the number of entries in the PLT.
1464 template<int size, bool big_endian>
1466 Target_sparc<size, big_endian>::plt_entry_count() const
1468 if (this->plt_ == NULL)
1470 return this->plt_->entry_count();
1473 // Return the offset of the first non-reserved PLT entry.
1475 template<int size, bool big_endian>
1477 Target_sparc<size, big_endian>::first_plt_entry_offset() const
1479 return Output_data_plt_sparc<size, big_endian>::first_plt_entry_offset();
1482 // Return the size of each PLT entry.
1484 template<int size, bool big_endian>
1486 Target_sparc<size, big_endian>::plt_entry_size() const
1488 return Output_data_plt_sparc<size, big_endian>::get_plt_entry_size();
1491 // Create a GOT entry for the TLS module index.
1493 template<int size, bool big_endian>
1495 Target_sparc<size, big_endian>::got_mod_index_entry(
1496 Symbol_table* symtab,
1498 Sized_relobj_file<size, big_endian>* object)
1500 if (this->got_mod_index_offset_ == -1U)
1502 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1503 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1504 Output_data_got<size, big_endian>* got;
1505 unsigned int got_offset;
1507 got = this->got_section(symtab, layout);
1508 got_offset = got->add_constant(0);
1509 rela_dyn->add_local(object, 0,
1511 elfcpp::R_SPARC_TLS_DTPMOD64 :
1512 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1514 got->add_constant(0);
1515 this->got_mod_index_offset_ = got_offset;
1517 return this->got_mod_index_offset_;
1520 // Optimize the TLS relocation type based on what we know about the
1521 // symbol. IS_FINAL is true if the final address of this symbol is
1522 // known at link time.
1524 static tls::Tls_optimization
1525 optimize_tls_reloc(bool is_final, int r_type)
1527 // If we are generating a shared library, then we can't do anything
1529 if (parameters->options().shared())
1530 return tls::TLSOPT_NONE;
1534 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1535 case elfcpp::R_SPARC_TLS_GD_LO10:
1536 case elfcpp::R_SPARC_TLS_GD_ADD:
1537 case elfcpp::R_SPARC_TLS_GD_CALL:
1538 // These are General-Dynamic which permits fully general TLS
1539 // access. Since we know that we are generating an executable,
1540 // we can convert this to Initial-Exec. If we also know that
1541 // this is a local symbol, we can further switch to Local-Exec.
1543 return tls::TLSOPT_TO_LE;
1544 return tls::TLSOPT_TO_IE;
1546 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1547 case elfcpp::R_SPARC_TLS_LDM_LO10:
1548 case elfcpp::R_SPARC_TLS_LDM_ADD:
1549 case elfcpp::R_SPARC_TLS_LDM_CALL:
1550 // This is Local-Dynamic, which refers to a local symbol in the
1551 // dynamic TLS block. Since we know that we generating an
1552 // executable, we can switch to Local-Exec.
1553 return tls::TLSOPT_TO_LE;
1555 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1556 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1557 case elfcpp::R_SPARC_TLS_LDO_ADD:
1558 // Another type of Local-Dynamic relocation.
1559 return tls::TLSOPT_TO_LE;
1561 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1562 case elfcpp::R_SPARC_TLS_IE_LO10:
1563 case elfcpp::R_SPARC_TLS_IE_LD:
1564 case elfcpp::R_SPARC_TLS_IE_LDX:
1565 case elfcpp::R_SPARC_TLS_IE_ADD:
1566 // These are Initial-Exec relocs which get the thread offset
1567 // from the GOT. If we know that we are linking against the
1568 // local symbol, we can switch to Local-Exec, which links the
1569 // thread offset into the instruction.
1571 return tls::TLSOPT_TO_LE;
1572 return tls::TLSOPT_NONE;
1574 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1575 case elfcpp::R_SPARC_TLS_LE_LOX10:
1576 // When we already have Local-Exec, there is nothing further we
1578 return tls::TLSOPT_NONE;
1585 // Get the Reference_flags for a particular relocation.
1587 template<int size, bool big_endian>
1589 Target_sparc<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
1594 case elfcpp::R_SPARC_NONE:
1595 case elfcpp::R_SPARC_REGISTER:
1596 case elfcpp::R_SPARC_GNU_VTINHERIT:
1597 case elfcpp::R_SPARC_GNU_VTENTRY:
1598 // No symbol reference.
1601 case elfcpp::R_SPARC_UA64:
1602 case elfcpp::R_SPARC_64:
1603 case elfcpp::R_SPARC_HIX22:
1604 case elfcpp::R_SPARC_LOX10:
1605 case elfcpp::R_SPARC_H44:
1606 case elfcpp::R_SPARC_M44:
1607 case elfcpp::R_SPARC_L44:
1608 case elfcpp::R_SPARC_HH22:
1609 case elfcpp::R_SPARC_HM10:
1610 case elfcpp::R_SPARC_LM22:
1611 case elfcpp::R_SPARC_HI22:
1612 case elfcpp::R_SPARC_LO10:
1613 case elfcpp::R_SPARC_OLO10:
1614 case elfcpp::R_SPARC_UA32:
1615 case elfcpp::R_SPARC_32:
1616 case elfcpp::R_SPARC_UA16:
1617 case elfcpp::R_SPARC_16:
1618 case elfcpp::R_SPARC_11:
1619 case elfcpp::R_SPARC_10:
1620 case elfcpp::R_SPARC_8:
1621 case elfcpp::R_SPARC_7:
1622 case elfcpp::R_SPARC_6:
1623 case elfcpp::R_SPARC_5:
1624 return Symbol::ABSOLUTE_REF;
1626 case elfcpp::R_SPARC_DISP8:
1627 case elfcpp::R_SPARC_DISP16:
1628 case elfcpp::R_SPARC_DISP32:
1629 case elfcpp::R_SPARC_DISP64:
1630 case elfcpp::R_SPARC_PC_HH22:
1631 case elfcpp::R_SPARC_PC_HM10:
1632 case elfcpp::R_SPARC_PC_LM22:
1633 case elfcpp::R_SPARC_PC10:
1634 case elfcpp::R_SPARC_PC22:
1635 case elfcpp::R_SPARC_WDISP30:
1636 case elfcpp::R_SPARC_WDISP22:
1637 case elfcpp::R_SPARC_WDISP19:
1638 case elfcpp::R_SPARC_WDISP16:
1639 return Symbol::RELATIVE_REF;
1641 case elfcpp::R_SPARC_PLT64:
1642 case elfcpp::R_SPARC_PLT32:
1643 case elfcpp::R_SPARC_HIPLT22:
1644 case elfcpp::R_SPARC_LOPLT10:
1645 case elfcpp::R_SPARC_PCPLT10:
1646 return Symbol::FUNCTION_CALL | Symbol::ABSOLUTE_REF;
1648 case elfcpp::R_SPARC_PCPLT32:
1649 case elfcpp::R_SPARC_PCPLT22:
1650 case elfcpp::R_SPARC_WPLT30:
1651 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
1653 case elfcpp::R_SPARC_GOTDATA_OP:
1654 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
1655 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
1656 case elfcpp::R_SPARC_GOT10:
1657 case elfcpp::R_SPARC_GOT13:
1658 case elfcpp::R_SPARC_GOT22:
1660 return Symbol::ABSOLUTE_REF;
1662 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1663 case elfcpp::R_SPARC_TLS_GD_LO10:
1664 case elfcpp::R_SPARC_TLS_GD_ADD:
1665 case elfcpp::R_SPARC_TLS_GD_CALL:
1666 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1667 case elfcpp::R_SPARC_TLS_LDM_LO10:
1668 case elfcpp::R_SPARC_TLS_LDM_ADD:
1669 case elfcpp::R_SPARC_TLS_LDM_CALL:
1670 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1671 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1672 case elfcpp::R_SPARC_TLS_LDO_ADD:
1673 case elfcpp::R_SPARC_TLS_LE_HIX22:
1674 case elfcpp::R_SPARC_TLS_LE_LOX10:
1675 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1676 case elfcpp::R_SPARC_TLS_IE_LO10:
1677 case elfcpp::R_SPARC_TLS_IE_LD:
1678 case elfcpp::R_SPARC_TLS_IE_LDX:
1679 case elfcpp::R_SPARC_TLS_IE_ADD:
1680 return Symbol::TLS_REF;
1682 case elfcpp::R_SPARC_COPY:
1683 case elfcpp::R_SPARC_GLOB_DAT:
1684 case elfcpp::R_SPARC_JMP_SLOT:
1685 case elfcpp::R_SPARC_RELATIVE:
1686 case elfcpp::R_SPARC_TLS_DTPMOD64:
1687 case elfcpp::R_SPARC_TLS_DTPMOD32:
1688 case elfcpp::R_SPARC_TLS_DTPOFF64:
1689 case elfcpp::R_SPARC_TLS_DTPOFF32:
1690 case elfcpp::R_SPARC_TLS_TPOFF64:
1691 case elfcpp::R_SPARC_TLS_TPOFF32:
1693 // Not expected. We will give an error later.
1698 // Generate a PLT entry slot for a call to __tls_get_addr
1699 template<int size, bool big_endian>
1701 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
1703 Target_sparc<size, big_endian>* target)
1705 Symbol* gsym = target->tls_get_addr_sym(symtab);
1707 target->make_plt_entry(symtab, layout, gsym);
1710 // Report an unsupported relocation against a local symbol.
1712 template<int size, bool big_endian>
1714 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
1715 Sized_relobj_file<size, big_endian>* object,
1716 unsigned int r_type)
1718 gold_error(_("%s: unsupported reloc %u against local symbol"),
1719 object->name().c_str(), r_type);
1722 // We are about to emit a dynamic relocation of type R_TYPE. If the
1723 // dynamic linker does not support it, issue an error.
1725 template<int size, bool big_endian>
1727 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
1729 gold_assert(r_type != elfcpp::R_SPARC_NONE);
1735 // These are the relocation types supported by glibc for sparc 64-bit.
1736 case elfcpp::R_SPARC_RELATIVE:
1737 case elfcpp::R_SPARC_COPY:
1738 case elfcpp::R_SPARC_64:
1739 case elfcpp::R_SPARC_GLOB_DAT:
1740 case elfcpp::R_SPARC_JMP_SLOT:
1741 case elfcpp::R_SPARC_TLS_DTPMOD64:
1742 case elfcpp::R_SPARC_TLS_DTPOFF64:
1743 case elfcpp::R_SPARC_TLS_TPOFF64:
1744 case elfcpp::R_SPARC_TLS_LE_HIX22:
1745 case elfcpp::R_SPARC_TLS_LE_LOX10:
1746 case elfcpp::R_SPARC_8:
1747 case elfcpp::R_SPARC_16:
1748 case elfcpp::R_SPARC_DISP8:
1749 case elfcpp::R_SPARC_DISP16:
1750 case elfcpp::R_SPARC_DISP32:
1751 case elfcpp::R_SPARC_WDISP30:
1752 case elfcpp::R_SPARC_LO10:
1753 case elfcpp::R_SPARC_HI22:
1754 case elfcpp::R_SPARC_OLO10:
1755 case elfcpp::R_SPARC_H44:
1756 case elfcpp::R_SPARC_M44:
1757 case elfcpp::R_SPARC_L44:
1758 case elfcpp::R_SPARC_HH22:
1759 case elfcpp::R_SPARC_HM10:
1760 case elfcpp::R_SPARC_LM22:
1761 case elfcpp::R_SPARC_UA16:
1762 case elfcpp::R_SPARC_UA32:
1763 case elfcpp::R_SPARC_UA64:
1774 // These are the relocation types supported by glibc for sparc 32-bit.
1775 case elfcpp::R_SPARC_RELATIVE:
1776 case elfcpp::R_SPARC_COPY:
1777 case elfcpp::R_SPARC_GLOB_DAT:
1778 case elfcpp::R_SPARC_32:
1779 case elfcpp::R_SPARC_JMP_SLOT:
1780 case elfcpp::R_SPARC_TLS_DTPMOD32:
1781 case elfcpp::R_SPARC_TLS_DTPOFF32:
1782 case elfcpp::R_SPARC_TLS_TPOFF32:
1783 case elfcpp::R_SPARC_TLS_LE_HIX22:
1784 case elfcpp::R_SPARC_TLS_LE_LOX10:
1785 case elfcpp::R_SPARC_8:
1786 case elfcpp::R_SPARC_16:
1787 case elfcpp::R_SPARC_DISP8:
1788 case elfcpp::R_SPARC_DISP16:
1789 case elfcpp::R_SPARC_DISP32:
1790 case elfcpp::R_SPARC_LO10:
1791 case elfcpp::R_SPARC_WDISP30:
1792 case elfcpp::R_SPARC_HI22:
1793 case elfcpp::R_SPARC_UA16:
1794 case elfcpp::R_SPARC_UA32:
1802 // This prevents us from issuing more than one error per reloc
1803 // section. But we can still wind up issuing more than one
1804 // error per object file.
1805 if (this->issued_non_pic_error_)
1807 gold_assert(parameters->options().output_is_position_independent());
1808 object->error(_("requires unsupported dynamic reloc; "
1809 "recompile with -fPIC"));
1810 this->issued_non_pic_error_ = true;
1814 // Scan a relocation for a local symbol.
1816 template<int size, bool big_endian>
1818 Target_sparc<size, big_endian>::Scan::local(
1819 Symbol_table* symtab,
1821 Target_sparc<size, big_endian>* target,
1822 Sized_relobj_file<size, big_endian>* object,
1823 unsigned int data_shndx,
1824 Output_section* output_section,
1825 const elfcpp::Rela<size, big_endian>& reloc,
1826 unsigned int r_type,
1827 const elfcpp::Sym<size, big_endian>& lsym)
1829 unsigned int orig_r_type = r_type;
1834 case elfcpp::R_SPARC_NONE:
1835 case elfcpp::R_SPARC_REGISTER:
1836 case elfcpp::R_SPARC_GNU_VTINHERIT:
1837 case elfcpp::R_SPARC_GNU_VTENTRY:
1840 case elfcpp::R_SPARC_64:
1841 case elfcpp::R_SPARC_32:
1842 // If building a shared library (or a position-independent
1843 // executable), we need to create a dynamic relocation for
1844 // this location. The relocation applied at link time will
1845 // apply the link-time value, so we flag the location with
1846 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1847 // relocate it easily.
1848 if (parameters->options().output_is_position_independent())
1850 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1851 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1852 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
1853 output_section, data_shndx,
1854 reloc.get_r_offset(),
1855 reloc.get_r_addend());
1859 case elfcpp::R_SPARC_HIX22:
1860 case elfcpp::R_SPARC_LOX10:
1861 case elfcpp::R_SPARC_H44:
1862 case elfcpp::R_SPARC_M44:
1863 case elfcpp::R_SPARC_L44:
1864 case elfcpp::R_SPARC_HH22:
1865 case elfcpp::R_SPARC_HM10:
1866 case elfcpp::R_SPARC_LM22:
1867 case elfcpp::R_SPARC_UA64:
1868 case elfcpp::R_SPARC_UA32:
1869 case elfcpp::R_SPARC_UA16:
1870 case elfcpp::R_SPARC_HI22:
1871 case elfcpp::R_SPARC_LO10:
1872 case elfcpp::R_SPARC_OLO10:
1873 case elfcpp::R_SPARC_16:
1874 case elfcpp::R_SPARC_11:
1875 case elfcpp::R_SPARC_10:
1876 case elfcpp::R_SPARC_8:
1877 case elfcpp::R_SPARC_7:
1878 case elfcpp::R_SPARC_6:
1879 case elfcpp::R_SPARC_5:
1880 // If building a shared library (or a position-independent
1881 // executable), we need to create a dynamic relocation for
1883 if (parameters->options().output_is_position_independent())
1885 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1886 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1888 check_non_pic(object, r_type);
1889 if (lsym.get_st_type() != elfcpp::STT_SECTION)
1891 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
1892 data_shndx, reloc.get_r_offset(),
1893 reloc.get_r_addend());
1897 gold_assert(lsym.get_st_value() == 0);
1898 rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
1899 output_section, data_shndx,
1900 reloc.get_r_offset(),
1901 reloc.get_r_addend());
1906 case elfcpp::R_SPARC_WDISP30:
1907 case elfcpp::R_SPARC_WPLT30:
1908 case elfcpp::R_SPARC_WDISP22:
1909 case elfcpp::R_SPARC_WDISP19:
1910 case elfcpp::R_SPARC_WDISP16:
1911 case elfcpp::R_SPARC_DISP8:
1912 case elfcpp::R_SPARC_DISP16:
1913 case elfcpp::R_SPARC_DISP32:
1914 case elfcpp::R_SPARC_DISP64:
1915 case elfcpp::R_SPARC_PC10:
1916 case elfcpp::R_SPARC_PC22:
1919 case elfcpp::R_SPARC_GOTDATA_OP:
1920 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
1921 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
1922 case elfcpp::R_SPARC_GOT10:
1923 case elfcpp::R_SPARC_GOT13:
1924 case elfcpp::R_SPARC_GOT22:
1926 // The symbol requires a GOT entry.
1927 Output_data_got<size, big_endian>* got;
1930 got = target->got_section(symtab, layout);
1931 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1933 // If we are generating a shared object, we need to add a
1934 // dynamic relocation for this symbol's GOT entry.
1935 if (parameters->options().output_is_position_independent())
1937 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
1939 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1942 off = got->add_constant(0);
1943 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
1944 rela_dyn->add_local_relative(object, r_sym,
1945 elfcpp::R_SPARC_RELATIVE,
1950 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
1954 // These are initial TLS relocs, which are expected when
1956 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1957 case elfcpp::R_SPARC_TLS_GD_LO10:
1958 case elfcpp::R_SPARC_TLS_GD_ADD:
1959 case elfcpp::R_SPARC_TLS_GD_CALL:
1960 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
1961 case elfcpp::R_SPARC_TLS_LDM_LO10:
1962 case elfcpp::R_SPARC_TLS_LDM_ADD:
1963 case elfcpp::R_SPARC_TLS_LDM_CALL:
1964 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1965 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1966 case elfcpp::R_SPARC_TLS_LDO_ADD:
1967 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1968 case elfcpp::R_SPARC_TLS_IE_LO10:
1969 case elfcpp::R_SPARC_TLS_IE_LD:
1970 case elfcpp::R_SPARC_TLS_IE_LDX:
1971 case elfcpp::R_SPARC_TLS_IE_ADD:
1972 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1973 case elfcpp::R_SPARC_TLS_LE_LOX10:
1975 bool output_is_shared = parameters->options().shared();
1976 const tls::Tls_optimization optimized_type
1977 = optimize_tls_reloc(!output_is_shared, r_type);
1980 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1981 case elfcpp::R_SPARC_TLS_GD_LO10:
1982 case elfcpp::R_SPARC_TLS_GD_ADD:
1983 case elfcpp::R_SPARC_TLS_GD_CALL:
1984 if (optimized_type == tls::TLSOPT_NONE)
1986 // Create a pair of GOT entries for the module index and
1987 // dtv-relative offset.
1988 Output_data_got<size, big_endian>* got
1989 = target->got_section(symtab, layout);
1990 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1991 unsigned int shndx = lsym.get_st_shndx();
1993 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
1995 object->error(_("local symbol %u has bad shndx %u"),
1998 got->add_local_pair_with_rela(object, r_sym,
1999 lsym.get_st_shndx(),
2001 target->rela_dyn_section(layout),
2003 ? elfcpp::R_SPARC_TLS_DTPMOD64
2004 : elfcpp::R_SPARC_TLS_DTPMOD32),
2006 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2007 generate_tls_call(symtab, layout, target);
2009 else if (optimized_type != tls::TLSOPT_TO_LE)
2010 unsupported_reloc_local(object, r_type);
2013 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
2014 case elfcpp::R_SPARC_TLS_LDM_LO10:
2015 case elfcpp::R_SPARC_TLS_LDM_ADD:
2016 case elfcpp::R_SPARC_TLS_LDM_CALL:
2017 if (optimized_type == tls::TLSOPT_NONE)
2019 // Create a GOT entry for the module index.
2020 target->got_mod_index_entry(symtab, layout, object);
2022 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2023 generate_tls_call(symtab, layout, target);
2025 else if (optimized_type != tls::TLSOPT_TO_LE)
2026 unsupported_reloc_local(object, r_type);
2029 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2030 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2031 case elfcpp::R_SPARC_TLS_LDO_ADD:
2034 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2035 case elfcpp::R_SPARC_TLS_IE_LO10:
2036 case elfcpp::R_SPARC_TLS_IE_LD:
2037 case elfcpp::R_SPARC_TLS_IE_LDX:
2038 case elfcpp::R_SPARC_TLS_IE_ADD:
2039 layout->set_has_static_tls();
2040 if (optimized_type == tls::TLSOPT_NONE)
2042 // Create a GOT entry for the tp-relative offset.
2043 Output_data_got<size, big_endian>* got
2044 = target->got_section(symtab, layout);
2045 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2047 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
2049 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2050 unsigned int off = got->add_constant(0);
2052 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
2054 rela_dyn->add_symbolless_local_addend(object, r_sym,
2056 elfcpp::R_SPARC_TLS_TPOFF64 :
2057 elfcpp::R_SPARC_TLS_TPOFF32),
2061 else if (optimized_type != tls::TLSOPT_TO_LE)
2062 unsupported_reloc_local(object, r_type);
2065 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
2066 case elfcpp::R_SPARC_TLS_LE_LOX10:
2067 layout->set_has_static_tls();
2068 if (output_is_shared)
2070 // We need to create a dynamic relocation.
2071 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
2072 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
2073 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2074 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
2075 output_section, data_shndx,
2076 reloc.get_r_offset(), 0);
2083 // These are relocations which should only be seen by the
2084 // dynamic linker, and should never be seen here.
2085 case elfcpp::R_SPARC_COPY:
2086 case elfcpp::R_SPARC_GLOB_DAT:
2087 case elfcpp::R_SPARC_JMP_SLOT:
2088 case elfcpp::R_SPARC_RELATIVE:
2089 case elfcpp::R_SPARC_TLS_DTPMOD64:
2090 case elfcpp::R_SPARC_TLS_DTPMOD32:
2091 case elfcpp::R_SPARC_TLS_DTPOFF64:
2092 case elfcpp::R_SPARC_TLS_DTPOFF32:
2093 case elfcpp::R_SPARC_TLS_TPOFF64:
2094 case elfcpp::R_SPARC_TLS_TPOFF32:
2095 gold_error(_("%s: unexpected reloc %u in object file"),
2096 object->name().c_str(), r_type);
2100 unsupported_reloc_local(object, r_type);
2105 // Report an unsupported relocation against a global symbol.
2107 template<int size, bool big_endian>
2109 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
2110 Sized_relobj_file<size, big_endian>* object,
2111 unsigned int r_type,
2114 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2115 object->name().c_str(), r_type, gsym->demangled_name().c_str());
2118 // Scan a relocation for a global symbol.
2120 template<int size, bool big_endian>
2122 Target_sparc<size, big_endian>::Scan::global(
2123 Symbol_table* symtab,
2125 Target_sparc<size, big_endian>* target,
2126 Sized_relobj_file<size, big_endian>* object,
2127 unsigned int data_shndx,
2128 Output_section* output_section,
2129 const elfcpp::Rela<size, big_endian>& reloc,
2130 unsigned int r_type,
2133 unsigned int orig_r_type = r_type;
2135 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2136 // section. We check here to avoid creating a dynamic reloc against
2137 // _GLOBAL_OFFSET_TABLE_.
2138 if (!target->has_got_section()
2139 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2140 target->got_section(symtab, layout);
2145 case elfcpp::R_SPARC_NONE:
2146 case elfcpp::R_SPARC_REGISTER:
2147 case elfcpp::R_SPARC_GNU_VTINHERIT:
2148 case elfcpp::R_SPARC_GNU_VTENTRY:
2151 case elfcpp::R_SPARC_PLT64:
2152 case elfcpp::R_SPARC_PLT32:
2153 case elfcpp::R_SPARC_HIPLT22:
2154 case elfcpp::R_SPARC_LOPLT10:
2155 case elfcpp::R_SPARC_PCPLT32:
2156 case elfcpp::R_SPARC_PCPLT22:
2157 case elfcpp::R_SPARC_PCPLT10:
2158 case elfcpp::R_SPARC_WPLT30:
2159 // If the symbol is fully resolved, this is just a PC32 reloc.
2160 // Otherwise we need a PLT entry.
2161 if (gsym->final_value_is_known())
2163 // If building a shared library, we can also skip the PLT entry
2164 // if the symbol is defined in the output file and is protected
2166 if (gsym->is_defined()
2167 && !gsym->is_from_dynobj()
2168 && !gsym->is_preemptible())
2170 target->make_plt_entry(symtab, layout, gsym);
2173 case elfcpp::R_SPARC_DISP8:
2174 case elfcpp::R_SPARC_DISP16:
2175 case elfcpp::R_SPARC_DISP32:
2176 case elfcpp::R_SPARC_DISP64:
2177 case elfcpp::R_SPARC_PC_HH22:
2178 case elfcpp::R_SPARC_PC_HM10:
2179 case elfcpp::R_SPARC_PC_LM22:
2180 case elfcpp::R_SPARC_PC10:
2181 case elfcpp::R_SPARC_PC22:
2182 case elfcpp::R_SPARC_WDISP30:
2183 case elfcpp::R_SPARC_WDISP22:
2184 case elfcpp::R_SPARC_WDISP19:
2185 case elfcpp::R_SPARC_WDISP16:
2187 if (gsym->needs_plt_entry())
2188 target->make_plt_entry(symtab, layout, gsym);
2189 // Make a dynamic relocation if necessary.
2190 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2192 if (gsym->may_need_copy_reloc())
2194 target->copy_reloc(symtab, layout, object,
2195 data_shndx, output_section, gsym,
2200 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2201 check_non_pic(object, r_type);
2202 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
2203 data_shndx, reloc.get_r_offset(),
2204 reloc.get_r_addend());
2210 case elfcpp::R_SPARC_UA64:
2211 case elfcpp::R_SPARC_64:
2212 case elfcpp::R_SPARC_HIX22:
2213 case elfcpp::R_SPARC_LOX10:
2214 case elfcpp::R_SPARC_H44:
2215 case elfcpp::R_SPARC_M44:
2216 case elfcpp::R_SPARC_L44:
2217 case elfcpp::R_SPARC_HH22:
2218 case elfcpp::R_SPARC_HM10:
2219 case elfcpp::R_SPARC_LM22:
2220 case elfcpp::R_SPARC_HI22:
2221 case elfcpp::R_SPARC_LO10:
2222 case elfcpp::R_SPARC_OLO10:
2223 case elfcpp::R_SPARC_UA32:
2224 case elfcpp::R_SPARC_32:
2225 case elfcpp::R_SPARC_UA16:
2226 case elfcpp::R_SPARC_16:
2227 case elfcpp::R_SPARC_11:
2228 case elfcpp::R_SPARC_10:
2229 case elfcpp::R_SPARC_8:
2230 case elfcpp::R_SPARC_7:
2231 case elfcpp::R_SPARC_6:
2232 case elfcpp::R_SPARC_5:
2234 // Make a PLT entry if necessary.
2235 if (gsym->needs_plt_entry())
2237 target->make_plt_entry(symtab, layout, gsym);
2238 // Since this is not a PC-relative relocation, we may be
2239 // taking the address of a function. In that case we need to
2240 // set the entry in the dynamic symbol table to the address of
2242 if (gsym->is_from_dynobj() && !parameters->options().shared())
2243 gsym->set_needs_dynsym_value();
2245 // Make a dynamic relocation if necessary.
2246 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
2248 unsigned int r_off = reloc.get_r_offset();
2250 // The assembler can sometimes emit unaligned relocations
2251 // for dwarf2 cfi directives.
2254 case elfcpp::R_SPARC_16:
2256 orig_r_type = r_type = elfcpp::R_SPARC_UA16;
2258 case elfcpp::R_SPARC_32:
2260 orig_r_type = r_type = elfcpp::R_SPARC_UA32;
2262 case elfcpp::R_SPARC_64:
2264 orig_r_type = r_type = elfcpp::R_SPARC_UA64;
2266 case elfcpp::R_SPARC_UA16:
2268 orig_r_type = r_type = elfcpp::R_SPARC_16;
2270 case elfcpp::R_SPARC_UA32:
2272 orig_r_type = r_type = elfcpp::R_SPARC_32;
2274 case elfcpp::R_SPARC_UA64:
2276 orig_r_type = r_type = elfcpp::R_SPARC_64;
2280 if (gsym->may_need_copy_reloc())
2282 target->copy_reloc(symtab, layout, object,
2283 data_shndx, output_section, gsym, reloc);
2285 else if ((r_type == elfcpp::R_SPARC_32
2286 || r_type == elfcpp::R_SPARC_64)
2287 && gsym->can_use_relative_reloc(false))
2289 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2290 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2291 output_section, object,
2292 data_shndx, reloc.get_r_offset(),
2293 reloc.get_r_addend());
2297 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2299 check_non_pic(object, r_type);
2300 if (gsym->is_from_dynobj()
2301 || gsym->is_undefined()
2302 || gsym->is_preemptible())
2303 rela_dyn->add_global(gsym, orig_r_type, output_section,
2305 reloc.get_r_offset(),
2306 reloc.get_r_addend());
2308 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2311 reloc.get_r_offset(),
2312 reloc.get_r_addend());
2318 case elfcpp::R_SPARC_GOTDATA_OP:
2319 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2320 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2321 case elfcpp::R_SPARC_GOT10:
2322 case elfcpp::R_SPARC_GOT13:
2323 case elfcpp::R_SPARC_GOT22:
2325 // The symbol requires a GOT entry.
2326 Output_data_got<size, big_endian>* got;
2328 got = target->got_section(symtab, layout);
2329 if (gsym->final_value_is_known())
2330 got->add_global(gsym, GOT_TYPE_STANDARD);
2333 // If this symbol is not fully resolved, we need to add a
2334 // dynamic relocation for it.
2335 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2336 if (gsym->is_from_dynobj()
2337 || gsym->is_undefined()
2338 || gsym->is_preemptible())
2339 got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn,
2340 elfcpp::R_SPARC_GLOB_DAT);
2341 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2343 unsigned int off = got->add_constant(0);
2345 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2346 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2353 // These are initial tls relocs, which are expected when
2355 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2356 case elfcpp::R_SPARC_TLS_GD_LO10:
2357 case elfcpp::R_SPARC_TLS_GD_ADD:
2358 case elfcpp::R_SPARC_TLS_GD_CALL:
2359 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2360 case elfcpp::R_SPARC_TLS_LDM_LO10:
2361 case elfcpp::R_SPARC_TLS_LDM_ADD:
2362 case elfcpp::R_SPARC_TLS_LDM_CALL:
2363 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2364 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2365 case elfcpp::R_SPARC_TLS_LDO_ADD:
2366 case elfcpp::R_SPARC_TLS_LE_HIX22:
2367 case elfcpp::R_SPARC_TLS_LE_LOX10:
2368 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2369 case elfcpp::R_SPARC_TLS_IE_LO10:
2370 case elfcpp::R_SPARC_TLS_IE_LD:
2371 case elfcpp::R_SPARC_TLS_IE_LDX:
2372 case elfcpp::R_SPARC_TLS_IE_ADD:
2374 const bool is_final = gsym->final_value_is_known();
2375 const tls::Tls_optimization optimized_type
2376 = optimize_tls_reloc(is_final, r_type);
2379 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2380 case elfcpp::R_SPARC_TLS_GD_LO10:
2381 case elfcpp::R_SPARC_TLS_GD_ADD:
2382 case elfcpp::R_SPARC_TLS_GD_CALL:
2383 if (optimized_type == tls::TLSOPT_NONE)
2385 // Create a pair of GOT entries for the module index and
2386 // dtv-relative offset.
2387 Output_data_got<size, big_endian>* got
2388 = target->got_section(symtab, layout);
2389 got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR,
2390 target->rela_dyn_section(layout),
2392 elfcpp::R_SPARC_TLS_DTPMOD64 :
2393 elfcpp::R_SPARC_TLS_DTPMOD32),
2395 elfcpp::R_SPARC_TLS_DTPOFF64 :
2396 elfcpp::R_SPARC_TLS_DTPOFF32));
2398 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2399 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2400 generate_tls_call(symtab, layout, target);
2402 else if (optimized_type == tls::TLSOPT_TO_IE)
2404 // Create a GOT entry for the tp-relative offset.
2405 Output_data_got<size, big_endian>* got
2406 = target->got_section(symtab, layout);
2407 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2408 target->rela_dyn_section(layout),
2410 elfcpp::R_SPARC_TLS_TPOFF64 :
2411 elfcpp::R_SPARC_TLS_TPOFF32));
2413 else if (optimized_type != tls::TLSOPT_TO_LE)
2414 unsupported_reloc_global(object, r_type, gsym);
2417 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2418 case elfcpp::R_SPARC_TLS_LDM_LO10:
2419 case elfcpp::R_SPARC_TLS_LDM_ADD:
2420 case elfcpp::R_SPARC_TLS_LDM_CALL:
2421 if (optimized_type == tls::TLSOPT_NONE)
2423 // Create a GOT entry for the module index.
2424 target->got_mod_index_entry(symtab, layout, object);
2426 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2427 generate_tls_call(symtab, layout, target);
2429 else if (optimized_type != tls::TLSOPT_TO_LE)
2430 unsupported_reloc_global(object, r_type, gsym);
2433 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2434 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2435 case elfcpp::R_SPARC_TLS_LDO_ADD:
2438 case elfcpp::R_SPARC_TLS_LE_HIX22:
2439 case elfcpp::R_SPARC_TLS_LE_LOX10:
2440 layout->set_has_static_tls();
2441 if (parameters->options().shared())
2443 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2444 rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
2445 output_section, object,
2446 data_shndx, reloc.get_r_offset(),
2451 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2452 case elfcpp::R_SPARC_TLS_IE_LO10:
2453 case elfcpp::R_SPARC_TLS_IE_LD:
2454 case elfcpp::R_SPARC_TLS_IE_LDX:
2455 case elfcpp::R_SPARC_TLS_IE_ADD:
2456 layout->set_has_static_tls();
2457 if (optimized_type == tls::TLSOPT_NONE)
2459 // Create a GOT entry for the tp-relative offset.
2460 Output_data_got<size, big_endian>* got
2461 = target->got_section(symtab, layout);
2462 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2463 target->rela_dyn_section(layout),
2465 elfcpp::R_SPARC_TLS_TPOFF64 :
2466 elfcpp::R_SPARC_TLS_TPOFF32));
2468 else if (optimized_type != tls::TLSOPT_TO_LE)
2469 unsupported_reloc_global(object, r_type, gsym);
2475 // These are relocations which should only be seen by the
2476 // dynamic linker, and should never be seen here.
2477 case elfcpp::R_SPARC_COPY:
2478 case elfcpp::R_SPARC_GLOB_DAT:
2479 case elfcpp::R_SPARC_JMP_SLOT:
2480 case elfcpp::R_SPARC_RELATIVE:
2481 case elfcpp::R_SPARC_TLS_DTPMOD64:
2482 case elfcpp::R_SPARC_TLS_DTPMOD32:
2483 case elfcpp::R_SPARC_TLS_DTPOFF64:
2484 case elfcpp::R_SPARC_TLS_DTPOFF32:
2485 case elfcpp::R_SPARC_TLS_TPOFF64:
2486 case elfcpp::R_SPARC_TLS_TPOFF32:
2487 gold_error(_("%s: unexpected reloc %u in object file"),
2488 object->name().c_str(), r_type);
2492 unsupported_reloc_global(object, r_type, gsym);
2497 // Process relocations for gc.
2499 template<int size, bool big_endian>
2501 Target_sparc<size, big_endian>::gc_process_relocs(
2502 Symbol_table* symtab,
2504 Sized_relobj_file<size, big_endian>* object,
2505 unsigned int data_shndx,
2507 const unsigned char* prelocs,
2509 Output_section* output_section,
2510 bool needs_special_offset_handling,
2511 size_t local_symbol_count,
2512 const unsigned char* plocal_symbols)
2514 typedef Target_sparc<size, big_endian> Sparc;
2515 typedef typename Target_sparc<size, big_endian>::Scan Scan;
2517 gold::gc_process_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan,
2518 typename Target_sparc::Relocatable_size_for_reloc>(
2527 needs_special_offset_handling,
2532 // Scan relocations for a section.
2534 template<int size, bool big_endian>
2536 Target_sparc<size, big_endian>::scan_relocs(
2537 Symbol_table* symtab,
2539 Sized_relobj_file<size, big_endian>* object,
2540 unsigned int data_shndx,
2541 unsigned int sh_type,
2542 const unsigned char* prelocs,
2544 Output_section* output_section,
2545 bool needs_special_offset_handling,
2546 size_t local_symbol_count,
2547 const unsigned char* plocal_symbols)
2549 typedef Target_sparc<size, big_endian> Sparc;
2550 typedef typename Target_sparc<size, big_endian>::Scan Scan;
2552 if (sh_type == elfcpp::SHT_REL)
2554 gold_error(_("%s: unsupported REL reloc section"),
2555 object->name().c_str());
2559 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
2568 needs_special_offset_handling,
2573 // Finalize the sections.
2575 template<int size, bool big_endian>
2577 Target_sparc<size, big_endian>::do_finalize_sections(
2579 const Input_objects*,
2582 // Fill in some more dynamic tags.
2583 const Reloc_section* rel_plt = (this->plt_ == NULL
2585 : this->plt_->rel_plt());
2586 layout->add_target_dynamic_tags(false, this->plt_, rel_plt,
2587 this->rela_dyn_, true, true);
2589 // Emit any relocs we saved in an attempt to avoid generating COPY
2591 if (this->copy_relocs_.any_saved_relocs())
2592 this->copy_relocs_.emit(this->rela_dyn_section(layout));
2595 // Perform a relocation.
2597 template<int size, bool big_endian>
2599 Target_sparc<size, big_endian>::Relocate::relocate(
2600 const Relocate_info<size, big_endian>* relinfo,
2601 Target_sparc* target,
2604 const elfcpp::Rela<size, big_endian>& rela,
2605 unsigned int r_type,
2606 const Sized_symbol<size>* gsym,
2607 const Symbol_value<size>* psymval,
2608 unsigned char* view,
2609 typename elfcpp::Elf_types<size>::Elf_Addr address,
2610 section_size_type view_size)
2614 if (this->ignore_gd_add_)
2616 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
2617 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2618 _("missing expected TLS relocation"));
2621 this->ignore_gd_add_ = false;
2626 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2628 // Pick the value to use for symbols defined in shared objects.
2629 Symbol_value<size> symval;
2631 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
2633 elfcpp::Elf_Xword value;
2635 value = target->plt_section()->address() + gsym->plt_offset();
2637 symval.set_output_value(value);
2642 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
2643 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2645 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2646 // pointer points to the beginning, not the end, of the table.
2647 // So we just use the plain offset.
2648 unsigned int got_offset = 0;
2651 case elfcpp::R_SPARC_GOTDATA_OP:
2652 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2653 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2654 case elfcpp::R_SPARC_GOT10:
2655 case elfcpp::R_SPARC_GOT13:
2656 case elfcpp::R_SPARC_GOT22:
2659 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
2660 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
2664 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2665 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
2666 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
2676 case elfcpp::R_SPARC_NONE:
2677 case elfcpp::R_SPARC_REGISTER:
2678 case elfcpp::R_SPARC_GNU_VTINHERIT:
2679 case elfcpp::R_SPARC_GNU_VTENTRY:
2682 case elfcpp::R_SPARC_8:
2683 Relocate_functions<size, big_endian>::rela8(view, object,
2687 case elfcpp::R_SPARC_16:
2688 if (rela.get_r_offset() & 0x1)
2690 // The assembler can sometimes emit unaligned relocations
2691 // for dwarf2 cfi directives.
2692 Reloc::ua16(view, object, psymval, addend);
2695 Relocate_functions<size, big_endian>::rela16(view, object,
2699 case elfcpp::R_SPARC_32:
2700 if (!parameters->options().output_is_position_independent())
2702 if (rela.get_r_offset() & 0x3)
2704 // The assembler can sometimes emit unaligned relocations
2705 // for dwarf2 cfi directives.
2706 Reloc::ua32(view, object, psymval, addend);
2709 Relocate_functions<size, big_endian>::rela32(view, object,
2714 case elfcpp::R_SPARC_DISP8:
2715 Reloc::disp8(view, object, psymval, addend, address);
2718 case elfcpp::R_SPARC_DISP16:
2719 Reloc::disp16(view, object, psymval, addend, address);
2722 case elfcpp::R_SPARC_DISP32:
2723 Reloc::disp32(view, object, psymval, addend, address);
2726 case elfcpp::R_SPARC_DISP64:
2727 Reloc::disp64(view, object, psymval, addend, address);
2730 case elfcpp::R_SPARC_WDISP30:
2731 case elfcpp::R_SPARC_WPLT30:
2732 Reloc::wdisp30(view, object, psymval, addend, address);
2735 case elfcpp::R_SPARC_WDISP22:
2736 Reloc::wdisp22(view, object, psymval, addend, address);
2739 case elfcpp::R_SPARC_WDISP19:
2740 Reloc::wdisp19(view, object, psymval, addend, address);
2743 case elfcpp::R_SPARC_WDISP16:
2744 Reloc::wdisp16(view, object, psymval, addend, address);
2747 case elfcpp::R_SPARC_HI22:
2748 Reloc::hi22(view, object, psymval, addend);
2751 case elfcpp::R_SPARC_22:
2752 Reloc::rela32_22(view, object, psymval, addend);
2755 case elfcpp::R_SPARC_13:
2756 Reloc::rela32_13(view, object, psymval, addend);
2759 case elfcpp::R_SPARC_LO10:
2760 Reloc::lo10(view, object, psymval, addend);
2763 case elfcpp::R_SPARC_GOT10:
2764 Reloc::lo10(view, got_offset, addend);
2767 case elfcpp::R_SPARC_GOTDATA_OP:
2770 case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
2771 case elfcpp::R_SPARC_GOT13:
2772 Reloc::rela32_13(view, got_offset, addend);
2775 case elfcpp::R_SPARC_GOTDATA_OP_HIX22:
2776 case elfcpp::R_SPARC_GOT22:
2777 Reloc::hi22(view, got_offset, addend);
2780 case elfcpp::R_SPARC_PC10:
2781 Reloc::pc10(view, object, psymval, addend, address);
2784 case elfcpp::R_SPARC_PC22:
2785 Reloc::pc22(view, object, psymval, addend, address);
2788 case elfcpp::R_SPARC_TLS_DTPOFF32:
2789 case elfcpp::R_SPARC_UA32:
2790 Reloc::ua32(view, object, psymval, addend);
2793 case elfcpp::R_SPARC_PLT64:
2794 Relocate_functions<size, big_endian>::rela64(view, object,
2798 case elfcpp::R_SPARC_PLT32:
2799 Relocate_functions<size, big_endian>::rela32(view, object,
2803 case elfcpp::R_SPARC_HIPLT22:
2804 Reloc::hi22(view, object, psymval, addend);
2807 case elfcpp::R_SPARC_LOPLT10:
2808 Reloc::lo10(view, object, psymval, addend);
2811 case elfcpp::R_SPARC_PCPLT32:
2812 Reloc::disp32(view, object, psymval, addend, address);
2815 case elfcpp::R_SPARC_PCPLT22:
2816 Reloc::pcplt22(view, object, psymval, addend, address);
2819 case elfcpp::R_SPARC_PCPLT10:
2820 Reloc::lo10(view, object, psymval, addend, address);
2823 case elfcpp::R_SPARC_64:
2824 if (!parameters->options().output_is_position_independent())
2826 if (rela.get_r_offset() & 0x7)
2828 // The assembler can sometimes emit unaligned relocations
2829 // for dwarf2 cfi directives.
2830 Reloc::ua64(view, object, psymval, addend);
2833 Relocate_functions<size, big_endian>::rela64(view, object,
2838 case elfcpp::R_SPARC_OLO10:
2840 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
2841 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
2842 Reloc::olo10(view, object, psymval, addend, addend2);
2846 case elfcpp::R_SPARC_HH22:
2847 Reloc::hh22(view, object, psymval, addend);
2850 case elfcpp::R_SPARC_PC_HH22:
2851 Reloc::pc_hh22(view, object, psymval, addend, address);
2854 case elfcpp::R_SPARC_HM10:
2855 Reloc::hm10(view, object, psymval, addend);
2858 case elfcpp::R_SPARC_PC_HM10:
2859 Reloc::pc_hm10(view, object, psymval, addend, address);
2862 case elfcpp::R_SPARC_LM22:
2863 Reloc::hi22(view, object, psymval, addend);
2866 case elfcpp::R_SPARC_PC_LM22:
2867 Reloc::pcplt22(view, object, psymval, addend, address);
2870 case elfcpp::R_SPARC_11:
2871 Reloc::rela32_11(view, object, psymval, addend);
2874 case elfcpp::R_SPARC_10:
2875 Reloc::rela32_10(view, object, psymval, addend);
2878 case elfcpp::R_SPARC_7:
2879 Reloc::rela32_7(view, object, psymval, addend);
2882 case elfcpp::R_SPARC_6:
2883 Reloc::rela32_6(view, object, psymval, addend);
2886 case elfcpp::R_SPARC_5:
2887 Reloc::rela32_5(view, object, psymval, addend);
2890 case elfcpp::R_SPARC_HIX22:
2891 Reloc::hix22(view, object, psymval, addend);
2894 case elfcpp::R_SPARC_LOX10:
2895 Reloc::lox10(view, object, psymval, addend);
2898 case elfcpp::R_SPARC_H44:
2899 Reloc::h44(view, object, psymval, addend);
2902 case elfcpp::R_SPARC_M44:
2903 Reloc::m44(view, object, psymval, addend);
2906 case elfcpp::R_SPARC_L44:
2907 Reloc::l44(view, object, psymval, addend);
2910 case elfcpp::R_SPARC_TLS_DTPOFF64:
2911 case elfcpp::R_SPARC_UA64:
2912 Reloc::ua64(view, object, psymval, addend);
2915 case elfcpp::R_SPARC_UA16:
2916 Reloc::ua16(view, object, psymval, addend);
2919 case elfcpp::R_SPARC_TLS_GD_HI22:
2920 case elfcpp::R_SPARC_TLS_GD_LO10:
2921 case elfcpp::R_SPARC_TLS_GD_ADD:
2922 case elfcpp::R_SPARC_TLS_GD_CALL:
2923 case elfcpp::R_SPARC_TLS_LDM_HI22:
2924 case elfcpp::R_SPARC_TLS_LDM_LO10:
2925 case elfcpp::R_SPARC_TLS_LDM_ADD:
2926 case elfcpp::R_SPARC_TLS_LDM_CALL:
2927 case elfcpp::R_SPARC_TLS_LDO_HIX22:
2928 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2929 case elfcpp::R_SPARC_TLS_LDO_ADD:
2930 case elfcpp::R_SPARC_TLS_IE_HI22:
2931 case elfcpp::R_SPARC_TLS_IE_LO10:
2932 case elfcpp::R_SPARC_TLS_IE_LD:
2933 case elfcpp::R_SPARC_TLS_IE_LDX:
2934 case elfcpp::R_SPARC_TLS_IE_ADD:
2935 case elfcpp::R_SPARC_TLS_LE_HIX22:
2936 case elfcpp::R_SPARC_TLS_LE_LOX10:
2937 this->relocate_tls(relinfo, target, relnum, rela,
2938 r_type, gsym, psymval, view,
2939 address, view_size);
2942 case elfcpp::R_SPARC_COPY:
2943 case elfcpp::R_SPARC_GLOB_DAT:
2944 case elfcpp::R_SPARC_JMP_SLOT:
2945 case elfcpp::R_SPARC_RELATIVE:
2946 // These are outstanding tls relocs, which are unexpected when
2948 case elfcpp::R_SPARC_TLS_DTPMOD64:
2949 case elfcpp::R_SPARC_TLS_DTPMOD32:
2950 case elfcpp::R_SPARC_TLS_TPOFF64:
2951 case elfcpp::R_SPARC_TLS_TPOFF32:
2952 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2953 _("unexpected reloc %u in object file"),
2958 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2959 _("unsupported reloc %u"),
2967 // Perform a TLS relocation.
2969 template<int size, bool big_endian>
2971 Target_sparc<size, big_endian>::Relocate::relocate_tls(
2972 const Relocate_info<size, big_endian>* relinfo,
2973 Target_sparc<size, big_endian>* target,
2975 const elfcpp::Rela<size, big_endian>& rela,
2976 unsigned int r_type,
2977 const Sized_symbol<size>* gsym,
2978 const Symbol_value<size>* psymval,
2979 unsigned char* view,
2980 typename elfcpp::Elf_types<size>::Elf_Addr address,
2983 Output_segment* tls_segment = relinfo->layout->tls_segment();
2984 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2985 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
2986 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
2988 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2989 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
2991 const bool is_final =
2993 ? !parameters->options().output_is_position_independent()
2994 : gsym->final_value_is_known());
2995 const tls::Tls_optimization optimized_type
2996 = optimize_tls_reloc(is_final, r_type);
3000 case elfcpp::R_SPARC_TLS_GD_HI22:
3001 case elfcpp::R_SPARC_TLS_GD_LO10:
3002 case elfcpp::R_SPARC_TLS_GD_ADD:
3003 case elfcpp::R_SPARC_TLS_GD_CALL:
3004 if (optimized_type == tls::TLSOPT_TO_LE)
3006 Insntype* wv = reinterpret_cast<Insntype*>(view);
3009 value -= tls_segment->memsz();
3013 case elfcpp::R_SPARC_TLS_GD_HI22:
3014 // TLS_GD_HI22 --> TLS_LE_HIX22
3015 Reloc::hix22(view, value, addend);
3018 case elfcpp::R_SPARC_TLS_GD_LO10:
3019 // TLS_GD_LO10 --> TLS_LE_LOX10
3020 Reloc::lox10(view, value, addend);
3023 case elfcpp::R_SPARC_TLS_GD_ADD:
3024 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3025 val = elfcpp::Swap<32, true>::readval(wv);
3026 val = (val & ~0x7c000) | 0x1c000;
3027 elfcpp::Swap<32, true>::writeval(wv, val);
3029 case elfcpp::R_SPARC_TLS_GD_CALL:
3030 // call __tls_get_addr --> nop
3031 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3038 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
3039 ? GOT_TYPE_TLS_OFFSET
3040 : GOT_TYPE_TLS_PAIR);
3043 gold_assert(gsym->has_got_offset(got_type));
3044 value = gsym->got_offset(got_type);
3048 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3049 gold_assert(object->local_has_got_offset(r_sym, got_type));
3050 value = object->local_got_offset(r_sym, got_type);
3052 if (optimized_type == tls::TLSOPT_TO_IE)
3054 Insntype* wv = reinterpret_cast<Insntype*>(view);
3059 case elfcpp::R_SPARC_TLS_GD_HI22:
3060 // TLS_GD_HI22 --> TLS_IE_HI22
3061 Reloc::hi22(view, value, addend);
3064 case elfcpp::R_SPARC_TLS_GD_LO10:
3065 // TLS_GD_LO10 --> TLS_IE_LO10
3066 Reloc::lo10(view, value, addend);
3069 case elfcpp::R_SPARC_TLS_GD_ADD:
3070 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3071 val = elfcpp::Swap<32, true>::readval(wv);
3078 elfcpp::Swap<32, true>::writeval(wv, val);
3081 case elfcpp::R_SPARC_TLS_GD_CALL:
3082 // The compiler can put the TLS_GD_ADD instruction
3083 // into the delay slot of the call. If so, we need
3084 // to transpose the two instructions so that the
3085 // new sequence works properly.
3087 // The test we use is if the instruction in the
3088 // delay slot is an add with destination register
3090 val = elfcpp::Swap<32, true>::readval(wv + 1);
3091 if ((val & 0x81f80000) == 0x80000000
3092 && ((val >> 25) & 0x1f) == 0x8)
3099 elfcpp::Swap<32, true>::writeval(wv, val);
3102 this->ignore_gd_add_ = true;
3105 // call __tls_get_addr --> add %g7, %o0, %o0
3106 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
3111 else if (optimized_type == tls::TLSOPT_NONE)
3115 case elfcpp::R_SPARC_TLS_GD_HI22:
3116 Reloc::hi22(view, value, addend);
3118 case elfcpp::R_SPARC_TLS_GD_LO10:
3119 Reloc::lo10(view, value, addend);
3121 case elfcpp::R_SPARC_TLS_GD_ADD:
3123 case elfcpp::R_SPARC_TLS_GD_CALL:
3125 Symbol_value<size> symval;
3126 elfcpp::Elf_Xword value;
3129 tsym = target->tls_get_addr_sym_;
3131 value = (target->plt_section()->address() +
3132 tsym->plt_offset());
3133 symval.set_output_value(value);
3134 Reloc::wdisp30(view, object, &symval, addend, address);
3141 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3142 _("unsupported reloc %u"),
3146 case elfcpp::R_SPARC_TLS_LDM_HI22:
3147 case elfcpp::R_SPARC_TLS_LDM_LO10:
3148 case elfcpp::R_SPARC_TLS_LDM_ADD:
3149 case elfcpp::R_SPARC_TLS_LDM_CALL:
3150 if (optimized_type == tls::TLSOPT_TO_LE)
3152 Insntype* wv = reinterpret_cast<Insntype*>(view);
3156 case elfcpp::R_SPARC_TLS_LDM_HI22:
3157 case elfcpp::R_SPARC_TLS_LDM_LO10:
3158 case elfcpp::R_SPARC_TLS_LDM_ADD:
3159 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
3162 case elfcpp::R_SPARC_TLS_LDM_CALL:
3163 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
3168 else if (optimized_type == tls::TLSOPT_NONE)
3170 // Relocate the field with the offset of the GOT entry for
3171 // the module index.
3172 unsigned int got_offset;
3174 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
3177 case elfcpp::R_SPARC_TLS_LDM_HI22:
3178 Reloc::hi22(view, got_offset, addend);
3180 case elfcpp::R_SPARC_TLS_LDM_LO10:
3181 Reloc::lo10(view, got_offset, addend);
3183 case elfcpp::R_SPARC_TLS_LDM_ADD:
3185 case elfcpp::R_SPARC_TLS_LDM_CALL:
3187 Symbol_value<size> symval;
3188 elfcpp::Elf_Xword value;
3191 tsym = target->tls_get_addr_sym_;
3193 value = (target->plt_section()->address() +
3194 tsym->plt_offset());
3195 symval.set_output_value(value);
3196 Reloc::wdisp30(view, object, &symval, addend, address);
3202 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3203 _("unsupported reloc %u"),
3207 // These relocs can appear in debugging sections, in which case
3208 // we won't see the TLS_LDM relocs. The local_dynamic_type
3209 // field tells us this.
3210 case elfcpp::R_SPARC_TLS_LDO_HIX22:
3211 if (optimized_type == tls::TLSOPT_TO_LE)
3213 value -= tls_segment->memsz();
3214 Reloc::hix22(view, value, addend);
3217 Reloc::ldo_hix22(view, value, addend);
3219 case elfcpp::R_SPARC_TLS_LDO_LOX10:
3220 if (optimized_type == tls::TLSOPT_TO_LE)
3222 value -= tls_segment->memsz();
3223 Reloc::lox10(view, value, addend);
3226 Reloc::ldo_lox10(view, value, addend);
3228 case elfcpp::R_SPARC_TLS_LDO_ADD:
3229 if (optimized_type == tls::TLSOPT_TO_LE)
3231 Insntype* wv = reinterpret_cast<Insntype*>(view);
3234 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3235 val = elfcpp::Swap<32, true>::readval(wv);
3236 val = (val & ~0x7c000) | 0x1c000;
3237 elfcpp::Swap<32, true>::writeval(wv, val);
3241 // When optimizing IE --> LE, the only relocation that is handled
3242 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3243 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3244 // rs2 and rd are the same.
3245 case elfcpp::R_SPARC_TLS_IE_LD:
3246 case elfcpp::R_SPARC_TLS_IE_LDX:
3247 if (optimized_type == tls::TLSOPT_TO_LE)
3249 Insntype* wv = reinterpret_cast<Insntype*>(view);
3250 Insntype val = elfcpp::Swap<32, true>::readval(wv);
3251 Insntype rs2 = val & 0x1f;
3252 Insntype rd = (val >> 25) & 0x1f;
3257 val = sparc_mov | (val & 0x3e00001f);
3259 elfcpp::Swap<32, true>::writeval(wv, val);
3263 case elfcpp::R_SPARC_TLS_IE_HI22:
3264 case elfcpp::R_SPARC_TLS_IE_LO10:
3265 if (optimized_type == tls::TLSOPT_TO_LE)
3267 value -= tls_segment->memsz();
3270 case elfcpp::R_SPARC_TLS_IE_HI22:
3271 // IE_HI22 --> LE_HIX22
3272 Reloc::hix22(view, value, addend);
3274 case elfcpp::R_SPARC_TLS_IE_LO10:
3275 // IE_LO10 --> LE_LOX10
3276 Reloc::lox10(view, value, addend);
3281 else if (optimized_type == tls::TLSOPT_NONE)
3283 // Relocate the field with the offset of the GOT entry for
3284 // the tp-relative offset of the symbol.
3287 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
3288 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
3292 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
3293 gold_assert(object->local_has_got_offset(r_sym,
3294 GOT_TYPE_TLS_OFFSET));
3295 value = object->local_got_offset(r_sym,
3296 GOT_TYPE_TLS_OFFSET);
3300 case elfcpp::R_SPARC_TLS_IE_HI22:
3301 Reloc::hi22(view, value, addend);
3303 case elfcpp::R_SPARC_TLS_IE_LO10:
3304 Reloc::lo10(view, value, addend);
3309 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
3310 _("unsupported reloc %u"),
3314 case elfcpp::R_SPARC_TLS_IE_ADD:
3315 // This seems to be mainly so that we can find the addition
3316 // instruction if there is one. There doesn't seem to be any
3317 // actual relocation to apply.
3320 case elfcpp::R_SPARC_TLS_LE_HIX22:
3321 // If we're creating a shared library, a dynamic relocation will
3322 // have been created for this location, so do not apply it now.
3323 if (!parameters->options().shared())
3325 value -= tls_segment->memsz();
3326 Reloc::hix22(view, value, addend);
3330 case elfcpp::R_SPARC_TLS_LE_LOX10:
3331 // If we're creating a shared library, a dynamic relocation will
3332 // have been created for this location, so do not apply it now.
3333 if (!parameters->options().shared())
3335 value -= tls_segment->memsz();
3336 Reloc::lox10(view, value, addend);
3342 // Relocate section data.
3344 template<int size, bool big_endian>
3346 Target_sparc<size, big_endian>::relocate_section(
3347 const Relocate_info<size, big_endian>* relinfo,
3348 unsigned int sh_type,
3349 const unsigned char* prelocs,
3351 Output_section* output_section,
3352 bool needs_special_offset_handling,
3353 unsigned char* view,
3354 typename elfcpp::Elf_types<size>::Elf_Addr address,
3355 section_size_type view_size,
3356 const Reloc_symbol_changes* reloc_symbol_changes)
3358 typedef Target_sparc<size, big_endian> Sparc;
3359 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
3361 gold_assert(sh_type == elfcpp::SHT_RELA);
3363 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
3370 needs_special_offset_handling,
3374 reloc_symbol_changes);
3377 // Return the size of a relocation while scanning during a relocatable
3380 template<int size, bool big_endian>
3382 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
3386 // We are always SHT_RELA, so we should never get here.
3391 // Scan the relocs during a relocatable link.
3393 template<int size, bool big_endian>
3395 Target_sparc<size, big_endian>::scan_relocatable_relocs(
3396 Symbol_table* symtab,
3398 Sized_relobj_file<size, big_endian>* object,
3399 unsigned int data_shndx,
3400 unsigned int sh_type,
3401 const unsigned char* prelocs,
3403 Output_section* output_section,
3404 bool needs_special_offset_handling,
3405 size_t local_symbol_count,
3406 const unsigned char* plocal_symbols,
3407 Relocatable_relocs* rr)
3409 gold_assert(sh_type == elfcpp::SHT_RELA);
3411 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
3412 Relocatable_size_for_reloc> Scan_relocatable_relocs;
3414 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
3415 Scan_relocatable_relocs>(
3423 needs_special_offset_handling,
3429 // Relocate a section during a relocatable link.
3431 template<int size, bool big_endian>
3433 Target_sparc<size, big_endian>::relocate_for_relocatable(
3434 const Relocate_info<size, big_endian>* relinfo,
3435 unsigned int sh_type,
3436 const unsigned char* prelocs,
3438 Output_section* output_section,
3439 off_t offset_in_output_section,
3440 const Relocatable_relocs* rr,
3441 unsigned char* view,
3442 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
3443 section_size_type view_size,
3444 unsigned char* reloc_view,
3445 section_size_type reloc_view_size)
3447 gold_assert(sh_type == elfcpp::SHT_RELA);
3449 gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>(
3454 offset_in_output_section,
3463 // Return the value to use for a dynamic which requires special
3464 // treatment. This is how we support equality comparisons of function
3465 // pointers across shared library boundaries, as described in the
3466 // processor specific ABI supplement.
3468 template<int size, bool big_endian>
3470 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
3472 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
3473 return this->plt_section()->address() + gsym->plt_offset();
3476 // The selector for sparc object files.
3478 template<int size, bool big_endian>
3479 class Target_selector_sparc : public Target_selector
3482 Target_selector_sparc()
3483 : Target_selector(elfcpp::EM_NONE, size, big_endian,
3484 (size == 64 ? "elf64-sparc" : "elf32-sparc"),
3485 (size == 64 ? "elf64_sparc" : "elf32_sparc"))
3488 Target* do_recognize(int machine, int, int)
3493 if (machine != elfcpp::EM_SPARCV9)
3498 if (machine != elfcpp::EM_SPARC
3499 && machine != elfcpp::EM_SPARC32PLUS)
3507 return this->instantiate_target();
3510 Target* do_instantiate_target()
3511 { return new Target_sparc<size, big_endian>(); }
3514 Target_selector_sparc<32, true> target_selector_sparc32;
3515 Target_selector_sparc<64, true> target_selector_sparc64;
3517 } // End anonymous namespace.