1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
),
64 elf_machine_(sparc_info
.machine_code
), elf_flags_(0),
69 // Process the relocations to determine unreferenced sections for
70 // garbage collection.
72 gc_process_relocs(Symbol_table
* symtab
,
74 Sized_relobj_file
<size
, big_endian
>* object
,
75 unsigned int data_shndx
,
77 const unsigned char* prelocs
,
79 Output_section
* output_section
,
80 bool needs_special_offset_handling
,
81 size_t local_symbol_count
,
82 const unsigned char* plocal_symbols
);
84 // Scan the relocations to look for symbol adjustments.
86 scan_relocs(Symbol_table
* symtab
,
88 Sized_relobj_file
<size
, big_endian
>* object
,
89 unsigned int data_shndx
,
91 const unsigned char* prelocs
,
93 Output_section
* output_section
,
94 bool needs_special_offset_handling
,
95 size_t local_symbol_count
,
96 const unsigned char* plocal_symbols
);
97 // Finalize the sections.
99 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
101 // Return the value to use for a dynamic which requires special
104 do_dynsym_value(const Symbol
*) const;
106 // Relocate a section.
108 relocate_section(const Relocate_info
<size
, big_endian
>*,
109 unsigned int sh_type
,
110 const unsigned char* prelocs
,
112 Output_section
* output_section
,
113 bool needs_special_offset_handling
,
115 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
116 section_size_type view_size
,
117 const Reloc_symbol_changes
*);
119 // Scan the relocs during a relocatable link.
121 scan_relocatable_relocs(Symbol_table
* symtab
,
123 Sized_relobj_file
<size
, big_endian
>* object
,
124 unsigned int data_shndx
,
125 unsigned int sh_type
,
126 const unsigned char* prelocs
,
128 Output_section
* output_section
,
129 bool needs_special_offset_handling
,
130 size_t local_symbol_count
,
131 const unsigned char* plocal_symbols
,
132 Relocatable_relocs
*);
134 // Emit relocations for a section.
136 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
137 unsigned int sh_type
,
138 const unsigned char* prelocs
,
140 Output_section
* output_section
,
141 off_t offset_in_output_section
,
142 const Relocatable_relocs
*,
144 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
145 section_size_type view_size
,
146 unsigned char* reloc_view
,
147 section_size_type reloc_view_size
);
149 // Return whether SYM is defined by the ABI.
151 do_is_defined_by_abi(const Symbol
* sym
) const
153 // XXX Really need to support this better...
154 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
157 return strcmp(sym
->name(), "___tls_get_addr") == 0;
160 // Return the PLT address to use for a global symbol.
162 do_plt_address_for_global(const Symbol
* gsym
) const
163 { return this->plt_section()->address_for_global(gsym
); }
166 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
167 { return this->plt_section()->address_for_local(relobj
, symndx
); }
169 // Return whether there is a GOT section.
171 has_got_section() const
172 { return this->got_
!= NULL
; }
174 // Return the size of the GOT section.
178 gold_assert(this->got_
!= NULL
);
179 return this->got_
->data_size();
182 // Return the number of entries in the GOT.
184 got_entry_count() const
186 if (this->got_
== NULL
)
188 return this->got_size() / (size
/ 8);
191 // Return the address of the GOT.
195 if (this->got_
== NULL
)
197 return this->got_
->address();
200 // Return the number of entries in the PLT.
202 plt_entry_count() const;
204 // Return the offset of the first non-reserved PLT entry.
206 first_plt_entry_offset() const;
208 // Return the size of each PLT entry.
210 plt_entry_size() const;
213 // Make an ELF object.
215 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
216 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
219 do_adjust_elf_header(unsigned char* view
, int len
) const;
223 // The class which scans relocations.
228 : issued_non_pic_error_(false)
232 get_reference_flags(unsigned int r_type
);
235 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
236 Sized_relobj_file
<size
, big_endian
>* object
,
237 unsigned int data_shndx
,
238 Output_section
* output_section
,
239 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
240 const elfcpp::Sym
<size
, big_endian
>& lsym
,
244 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
245 Sized_relobj_file
<size
, big_endian
>* object
,
246 unsigned int data_shndx
,
247 Output_section
* output_section
,
248 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
252 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
254 Sized_relobj_file
<size
, big_endian
>* ,
257 const elfcpp::Rela
<size
, big_endian
>& ,
259 const elfcpp::Sym
<size
, big_endian
>&)
263 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
265 Sized_relobj_file
<size
, big_endian
>* ,
268 const elfcpp::Rela
<size
,
270 unsigned int , Symbol
*)
276 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
277 unsigned int r_type
);
280 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
281 unsigned int r_type
, Symbol
*);
284 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
285 Target_sparc
* target
);
288 check_non_pic(Relobj
*, unsigned int r_type
);
291 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
292 unsigned int r_type
);
294 // Whether we have issued an error about a non-PIC compilation.
295 bool issued_non_pic_error_
;
298 // The class which implements relocation.
303 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
308 if (this->ignore_gd_add_
)
310 // FIXME: This needs to specify the location somehow.
311 gold_error(_("missing expected TLS relocation"));
315 // Do a relocation. Return false if the caller should not issue
316 // any warnings about this relocation.
318 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
319 Output_section
*, size_t relnum
,
320 const elfcpp::Rela
<size
, big_endian
>&,
321 unsigned int r_type
, const Sized_symbol
<size
>*,
322 const Symbol_value
<size
>*,
324 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
328 // Do a TLS relocation.
330 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
331 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
332 unsigned int r_type
, const Sized_symbol
<size
>*,
333 const Symbol_value
<size
>*,
335 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
339 relax_call(Target_sparc
<size
, big_endian
>* target
,
341 const elfcpp::Rela
<size
, big_endian
>& rela
,
342 section_size_type view_size
);
344 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
347 // If we hit a reloc at this view address, adjust it back by 4 bytes.
348 unsigned char *reloc_adjust_addr_
;
351 // A class which returns the size required for a relocation type,
352 // used while scanning relocs during a relocatable link.
353 class Relocatable_size_for_reloc
357 get_size_for_reloc(unsigned int, Relobj
*);
360 // Get the GOT section, creating it if necessary.
361 Output_data_got
<size
, big_endian
>*
362 got_section(Symbol_table
*, Layout
*);
364 // Create the PLT section.
366 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
368 // Create a PLT entry for a global symbol.
370 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
372 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
374 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
375 Sized_relobj_file
<size
, big_endian
>* relobj
,
376 unsigned int local_sym_index
);
378 // Create a GOT entry for the TLS module index.
380 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
381 Sized_relobj_file
<size
, big_endian
>* object
);
383 // Return the gsym for "__tls_get_addr". Cache if not already
386 tls_get_addr_sym(Symbol_table
* symtab
)
388 if (!this->tls_get_addr_sym_
)
389 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
390 gold_assert(this->tls_get_addr_sym_
);
391 return this->tls_get_addr_sym_
;
394 // Get the PLT section.
395 Output_data_plt_sparc
<size
, big_endian
>*
398 gold_assert(this->plt_
!= NULL
);
402 // Get the dynamic reloc section, creating it if necessary.
404 rela_dyn_section(Layout
*);
406 // Get the section to use for IFUNC relocations.
408 rela_ifunc_section(Layout
*);
410 // Copy a relocation against a global symbol.
412 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
413 Sized_relobj_file
<size
, big_endian
>* object
,
414 unsigned int shndx
, Output_section
* output_section
,
415 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
417 this->copy_relocs_
.copy_reloc(symtab
, layout
,
418 symtab
->get_sized_symbol
<size
>(sym
),
419 object
, shndx
, output_section
,
420 reloc
, this->rela_dyn_section(layout
));
423 // Information about this specific target which we pass to the
424 // general Target structure.
425 static Target::Target_info sparc_info
;
427 // The types of GOT entries needed for this platform.
428 // These values are exposed to the ABI in an incremental link.
429 // Do not renumber existing values without changing the version
430 // number of the .gnu_incremental_inputs section.
433 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
434 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
435 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
439 Output_data_got
<size
, big_endian
>* got_
;
441 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
442 // The dynamic reloc section.
443 Reloc_section
* rela_dyn_
;
444 // The section to use for IFUNC relocs.
445 Reloc_section
* rela_ifunc_
;
446 // Relocs saved to avoid a COPY reloc.
447 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
448 // Space for variables copied with a COPY reloc.
449 Output_data_space
* dynbss_
;
450 // Offset of the GOT entry for the TLS module index;
451 unsigned int got_mod_index_offset_
;
452 // Cached pointer to __tls_get_addr symbol
453 Symbol
* tls_get_addr_sym_
;
454 // Accumulated elf machine type
455 elfcpp::Elf_Half elf_machine_
;
456 // Accumulated elf header flags
457 elfcpp::Elf_Word elf_flags_
;
458 // Whether elf_flags_ has been set for the first time yet
463 Target::Target_info Target_sparc
<32, true>::sparc_info
=
466 true, // is_big_endian
467 elfcpp::EM_SPARC
, // machine_code
468 false, // has_make_symbol
469 false, // has_resolve
470 false, // has_code_fill
471 true, // is_default_stack_executable
472 false, // can_icf_inline_merge_sections
474 "/usr/lib/ld.so.1", // dynamic_linker
475 0x00010000, // default_text_segment_address
476 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
477 8 * 1024, // common_pagesize (overridable by -z common-page-size)
478 false, // isolate_execinstr
480 elfcpp::SHN_UNDEF
, // small_common_shndx
481 elfcpp::SHN_UNDEF
, // large_common_shndx
482 0, // small_common_section_flags
483 0, // large_common_section_flags
484 NULL
, // attributes_section
485 NULL
// attributes_vendor
489 Target::Target_info Target_sparc
<64, true>::sparc_info
=
492 true, // is_big_endian
493 elfcpp::EM_SPARCV9
, // machine_code
494 false, // has_make_symbol
495 false, // has_resolve
496 false, // has_code_fill
497 true, // is_default_stack_executable
498 false, // can_icf_inline_merge_sections
500 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
501 0x100000, // default_text_segment_address
502 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
503 8 * 1024, // common_pagesize (overridable by -z common-page-size)
504 false, // isolate_execinstr
506 elfcpp::SHN_UNDEF
, // small_common_shndx
507 elfcpp::SHN_UNDEF
, // large_common_shndx
508 0, // small_common_section_flags
509 0, // large_common_section_flags
510 NULL
, // attributes_section
511 NULL
// attributes_vendor
514 // We have to take care here, even when operating in little-endian
515 // mode, sparc instructions are still big endian.
516 template<int size
, bool big_endian
>
517 class Sparc_relocate_functions
520 // Do a simple relocation with the addend in the relocation.
521 template<int valsize
>
523 rela(unsigned char* view
,
524 unsigned int right_shift
,
525 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
526 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
527 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
529 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
530 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
531 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
532 Valtype reloc
= ((value
+ addend
) >> right_shift
);
537 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
540 // Do a simple relocation using a symbol value with the addend in
542 template<int valsize
>
544 rela(unsigned char* view
,
545 unsigned int right_shift
,
546 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
547 const Sized_relobj_file
<size
, big_endian
>* object
,
548 const Symbol_value
<size
>* psymval
,
549 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
551 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
552 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
553 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
554 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
559 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
562 // Do a simple relocation using a symbol value with the addend in
563 // the relocation, unaligned.
564 template<int valsize
>
566 rela_ua(unsigned char* view
,
567 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
568 const Sized_relobj_file
<size
, big_endian
>* object
,
569 const Symbol_value
<size
>* psymval
,
570 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
572 typedef typename
elfcpp::Swap_unaligned
<valsize
,
573 big_endian
>::Valtype Valtype
;
574 unsigned char* wv
= view
;
575 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
576 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
581 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
584 // Do a simple PC relative relocation with a Symbol_value with the
585 // addend in the relocation.
586 template<int valsize
>
588 pcrela(unsigned char* view
,
589 unsigned int right_shift
,
590 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
591 const Sized_relobj_file
<size
, big_endian
>* object
,
592 const Symbol_value
<size
>* psymval
,
593 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
594 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
596 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
597 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
598 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
599 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
605 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
608 template<int valsize
>
610 pcrela_unaligned(unsigned char* view
,
611 const Sized_relobj_file
<size
, big_endian
>* object
,
612 const Symbol_value
<size
>* psymval
,
613 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
614 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
616 typedef typename
elfcpp::Swap_unaligned
<valsize
,
617 big_endian
>::Valtype Valtype
;
618 unsigned char* wv
= view
;
619 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
621 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
624 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
625 typedef Sparc_relocate_functions
<size
, true> This_insn
;
628 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
630 wdisp30(unsigned char* view
,
631 const Sized_relobj_file
<size
, big_endian
>* object
,
632 const Symbol_value
<size
>* psymval
,
633 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
634 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
636 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
637 psymval
, addend
, address
);
640 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
642 wdisp22(unsigned char* view
,
643 const Sized_relobj_file
<size
, big_endian
>* object
,
644 const Symbol_value
<size
>* psymval
,
645 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
646 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
648 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
649 psymval
, addend
, address
);
652 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
654 wdisp19(unsigned char* view
,
655 const Sized_relobj_file
<size
, big_endian
>* object
,
656 const Symbol_value
<size
>* psymval
,
657 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
658 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
660 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
661 psymval
, addend
, address
);
664 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
666 wdisp16(unsigned char* view
,
667 const Sized_relobj_file
<size
, big_endian
>* object
,
668 const Symbol_value
<size
>* psymval
,
669 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
670 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
672 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
673 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
674 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
675 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
678 // The relocation value is split between the low 14 bits,
680 val
&= ~((0x3 << 20) | 0x3fff);
681 reloc
= (((reloc
& 0xc000) << (20 - 14))
682 | (reloc
& 0x3ffff));
684 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
687 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
689 wdisp10(unsigned char* view
,
690 const Sized_relobj_file
<size
, big_endian
>* object
,
691 const Symbol_value
<size
>* psymval
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
693 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
695 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
696 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
697 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
698 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
701 // The relocation value is split between the low bits 5-12,
702 // and high bits 19-20.
703 val
&= ~((0x3 << 19) | (0xff << 5));
704 reloc
= (((reloc
& 0x300) << (19 - 8))
705 | ((reloc
& 0xff) << (5 - 0)));
707 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
710 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
712 pc22(unsigned char* view
,
713 const Sized_relobj_file
<size
, big_endian
>* object
,
714 const Symbol_value
<size
>* psymval
,
715 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
716 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
718 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
719 psymval
, addend
, address
);
722 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
724 pc10(unsigned char* view
,
725 const Sized_relobj_file
<size
, big_endian
>* object
,
726 const Symbol_value
<size
>* psymval
,
727 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
728 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
730 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
731 psymval
, addend
, address
);
734 // R_SPARC_HI22: (Symbol + Addend) >> 10
736 hi22(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
, 10, 0x003fffff, value
, addend
);
743 // R_SPARC_HI22: (Symbol + Addend) >> 10
745 hi22(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
, 10, 0x003fffff, object
, psymval
, addend
);
753 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
755 pcplt22(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
,
759 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
761 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
762 psymval
, addend
, address
);
765 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
767 lo10(unsigned char* view
,
768 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
769 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
771 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
774 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
776 lo10(unsigned char* view
,
777 const Sized_relobj_file
<size
, big_endian
>* object
,
778 const Symbol_value
<size
>* psymval
,
779 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
781 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
784 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
786 lo10(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_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
793 psymval
, addend
, address
);
796 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
798 olo10(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 addend2
)
804 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
805 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
806 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
807 Valtype reloc
= psymval
->value(object
, addend
);
814 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
817 // R_SPARC_22: (Symbol + Addend)
819 rela32_22(unsigned char* view
,
820 const Sized_relobj_file
<size
, big_endian
>* object
,
821 const Symbol_value
<size
>* psymval
,
822 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
824 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
827 // R_SPARC_13: (Symbol + Addend)
829 rela32_13(unsigned char* view
,
830 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
831 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
833 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
836 // R_SPARC_13: (Symbol + Addend)
838 rela32_13(unsigned char* view
,
839 const Sized_relobj_file
<size
, big_endian
>* object
,
840 const Symbol_value
<size
>* psymval
,
841 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
843 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
846 // R_SPARC_UA16: (Symbol + Addend)
848 ua16(unsigned char* view
,
849 const Sized_relobj_file
<size
, big_endian
>* object
,
850 const Symbol_value
<size
>* psymval
,
851 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
853 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
856 // R_SPARC_UA32: (Symbol + Addend)
858 ua32(unsigned char* view
,
859 const Sized_relobj_file
<size
, big_endian
>* object
,
860 const Symbol_value
<size
>* psymval
,
861 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
863 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
866 // R_SPARC_UA64: (Symbol + Addend)
868 ua64(unsigned char* view
,
869 const Sized_relobj_file
<size
, big_endian
>* object
,
870 const Symbol_value
<size
>* psymval
,
871 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
873 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
874 object
, psymval
, addend
);
877 // R_SPARC_DISP8: (Symbol + Addend - Address)
879 disp8(unsigned char* view
,
880 const Sized_relobj_file
<size
, big_endian
>* object
,
881 const Symbol_value
<size
>* psymval
,
882 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
883 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
885 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
889 // R_SPARC_DISP16: (Symbol + Addend - Address)
891 disp16(unsigned char* view
,
892 const Sized_relobj_file
<size
, big_endian
>* object
,
893 const Symbol_value
<size
>* psymval
,
894 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
895 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
897 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
901 // R_SPARC_DISP32: (Symbol + Addend - Address)
903 disp32(unsigned char* view
,
904 const Sized_relobj_file
<size
, big_endian
>* object
,
905 const Symbol_value
<size
>* psymval
,
906 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
907 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
909 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
913 // R_SPARC_DISP64: (Symbol + Addend - Address)
915 disp64(unsigned char* view
,
916 const Sized_relobj_file
<size
, big_endian
>* object
,
917 const Symbol_value
<size
>* psymval
,
918 elfcpp::Elf_Xword addend
,
919 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
921 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
925 // R_SPARC_H34: (Symbol + Addend) >> 12
927 h34(unsigned char* view
,
928 const Sized_relobj_file
<size
, big_endian
>* object
,
929 const Symbol_value
<size
>* psymval
,
930 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
932 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
935 // R_SPARC_H44: (Symbol + Addend) >> 22
937 h44(unsigned char* view
,
938 const Sized_relobj_file
<size
, big_endian
>* object
,
939 const Symbol_value
<size
>* psymval
,
940 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
942 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
945 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
947 m44(unsigned char* view
,
948 const Sized_relobj_file
<size
, big_endian
>* object
,
949 const Symbol_value
<size
>* psymval
,
950 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
952 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
955 // R_SPARC_L44: (Symbol + Addend) & 0xfff
957 l44(unsigned char* view
,
958 const Sized_relobj_file
<size
, big_endian
>* object
,
959 const Symbol_value
<size
>* psymval
,
960 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
962 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
965 // R_SPARC_HH22: (Symbol + Addend) >> 42
967 hh22(unsigned char* view
,
968 const Sized_relobj_file
<size
, big_endian
>* object
,
969 const Symbol_value
<size
>* psymval
,
970 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
972 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
975 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
977 pc_hh22(unsigned char* view
,
978 const Sized_relobj_file
<size
, big_endian
>* object
,
979 const Symbol_value
<size
>* psymval
,
980 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
981 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
983 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
984 psymval
, addend
, address
);
987 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
989 hm10(unsigned char* view
,
990 const Sized_relobj_file
<size
, big_endian
>* object
,
991 const Symbol_value
<size
>* psymval
,
992 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
994 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
997 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
999 pc_hm10(unsigned char* view
,
1000 const Sized_relobj_file
<size
, big_endian
>* object
,
1001 const Symbol_value
<size
>* psymval
,
1002 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
1003 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
1005 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
1006 psymval
, addend
, address
);
1009 // R_SPARC_11: (Symbol + Addend)
1011 rela32_11(unsigned char* view
,
1012 const Sized_relobj_file
<size
, big_endian
>* object
,
1013 const Symbol_value
<size
>* psymval
,
1014 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1016 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1019 // R_SPARC_10: (Symbol + Addend)
1021 rela32_10(unsigned char* view
,
1022 const Sized_relobj_file
<size
, big_endian
>* object
,
1023 const Symbol_value
<size
>* psymval
,
1024 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1026 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
1029 // R_SPARC_7: (Symbol + Addend)
1031 rela32_7(unsigned char* view
,
1032 const Sized_relobj_file
<size
, big_endian
>* object
,
1033 const Symbol_value
<size
>* psymval
,
1034 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1036 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1039 // R_SPARC_6: (Symbol + Addend)
1041 rela32_6(unsigned char* view
,
1042 const Sized_relobj_file
<size
, big_endian
>* object
,
1043 const Symbol_value
<size
>* psymval
,
1044 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1046 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1049 // R_SPARC_5: (Symbol + Addend)
1051 rela32_5(unsigned char* view
,
1052 const Sized_relobj_file
<size
, big_endian
>* object
,
1053 const Symbol_value
<size
>* psymval
,
1054 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1056 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1059 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1061 ldo_hix22(unsigned char* view
,
1062 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1063 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1065 This_insn::hi22(view
, value
, addend
);
1068 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1070 ldo_lox10(unsigned char* view
,
1071 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1072 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1074 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1075 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1076 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1077 Valtype reloc
= (value
+ addend
);
1082 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1085 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1087 hix22(unsigned char* view
,
1088 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1089 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1091 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1092 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1093 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1094 Valtype reloc
= (value
+ addend
);
1098 reloc
^= ~(Valtype
)0;
1103 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1106 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1108 gdop_hix22(unsigned char* view
,
1109 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1110 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1112 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1113 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1114 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1115 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1120 reloc
^= ~static_cast<int32_t>(0);
1125 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1128 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1130 hix22(unsigned char* view
,
1131 const Sized_relobj_file
<size
, big_endian
>* object
,
1132 const Symbol_value
<size
>* psymval
,
1133 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1135 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1136 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1137 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1138 Valtype reloc
= psymval
->value(object
, addend
);
1142 reloc
^= ~(Valtype
)0;
1147 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1151 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1153 lox10(unsigned char* view
,
1154 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1155 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1157 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1158 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1159 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1160 Valtype reloc
= (value
+ addend
);
1166 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1169 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1171 gdop_lox10(unsigned char* view
,
1172 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1173 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1175 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1176 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1177 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1178 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1181 reloc
= (reloc
& 0x3ff) | 0x1c00;
1183 reloc
= (reloc
& 0x3ff);
1186 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1189 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1191 lox10(unsigned char* view
,
1192 const Sized_relobj_file
<size
, big_endian
>* object
,
1193 const Symbol_value
<size
>* psymval
,
1194 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1196 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1197 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1198 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1199 Valtype reloc
= psymval
->value(object
, addend
);
1205 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1209 // Get the GOT section, creating it if necessary.
1211 template<int size
, bool big_endian
>
1212 Output_data_got
<size
, big_endian
>*
1213 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1216 if (this->got_
== NULL
)
1218 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1220 this->got_
= new Output_data_got
<size
, big_endian
>();
1222 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1224 | elfcpp::SHF_WRITE
),
1225 this->got_
, ORDER_RELRO
, true);
1227 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1228 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1229 Symbol_table::PREDEFINED
,
1231 0, 0, elfcpp::STT_OBJECT
,
1233 elfcpp::STV_HIDDEN
, 0,
1240 // Get the dynamic reloc section, creating it if necessary.
1242 template<int size
, bool big_endian
>
1243 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1244 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1246 if (this->rela_dyn_
== NULL
)
1248 gold_assert(layout
!= NULL
);
1249 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1250 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1251 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1252 ORDER_DYNAMIC_RELOCS
, false);
1254 return this->rela_dyn_
;
1257 // Get the section to use for IFUNC relocs, creating it if
1258 // necessary. These go in .rela.dyn, but only after all other dynamic
1259 // relocations. They need to follow the other dynamic relocations so
1260 // that they can refer to global variables initialized by those
1263 template<int size
, bool big_endian
>
1264 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1265 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1267 if (this->rela_ifunc_
== NULL
)
1269 // Make sure we have already created the dynamic reloc section.
1270 this->rela_dyn_section(layout
);
1271 this->rela_ifunc_
= new Reloc_section(false);
1272 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1273 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1274 ORDER_DYNAMIC_RELOCS
, false);
1275 gold_assert(this->rela_dyn_
->output_section()
1276 == this->rela_ifunc_
->output_section());
1278 return this->rela_ifunc_
;
1281 // A class to handle the PLT data.
1283 template<int size
, bool big_endian
>
1284 class Output_data_plt_sparc
: public Output_section_data
1287 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1288 size
, big_endian
> Reloc_section
;
1290 Output_data_plt_sparc(Layout
*);
1292 // Add an entry to the PLT.
1293 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1295 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1297 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1298 Sized_relobj_file
<size
, big_endian
>* relobj
,
1299 unsigned int local_sym_index
);
1301 // Return the .rela.plt section data.
1302 const Reloc_section
* rel_plt() const
1307 // Return where the IFUNC relocations should go.
1309 rela_ifunc(Symbol_table
*, Layout
*);
1312 emit_pending_ifunc_relocs();
1314 // Return whether we created a section for IFUNC relocations.
1316 has_ifunc_section() const
1317 { return this->ifunc_rel_
!= NULL
; }
1319 // Return the number of PLT entries.
1322 { return this->count_
+ this->ifunc_count_
; }
1324 // Return the offset of the first non-reserved PLT entry.
1326 first_plt_entry_offset()
1327 { return 4 * base_plt_entry_size
; }
1329 // Return the size of a PLT entry.
1331 get_plt_entry_size()
1332 { return base_plt_entry_size
; }
1334 // Return the PLT address to use for a global symbol.
1336 address_for_global(const Symbol
*);
1338 // Return the PLT address to use for a local symbol.
1340 address_for_local(const Relobj
*, unsigned int symndx
);
1343 void do_adjust_output_section(Output_section
* os
);
1345 // Write to a map file.
1347 do_print_to_mapfile(Mapfile
* mapfile
) const
1348 { mapfile
->print_output_data(this, _("** PLT")); }
1351 // The size of an entry in the PLT.
1352 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1354 static const unsigned int plt_entries_per_block
= 160;
1355 static const unsigned int plt_insn_chunk_size
= 24;
1356 static const unsigned int plt_pointer_chunk_size
= 8;
1357 static const unsigned int plt_block_size
=
1358 (plt_entries_per_block
1359 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1362 plt_index_to_offset(unsigned int index
)
1364 section_offset_type offset
;
1366 if (size
== 32 || index
< 32768)
1367 offset
= index
* base_plt_entry_size
;
1370 unsigned int ext_index
= index
- 32768;
1372 offset
= (32768 * base_plt_entry_size
)
1373 + ((ext_index
/ plt_entries_per_block
)
1375 + ((ext_index
% plt_entries_per_block
)
1376 * plt_insn_chunk_size
);
1381 // Set the final size.
1383 set_final_data_size()
1385 unsigned int full_count
= this->entry_count() + 4;
1386 unsigned int extra
= (size
== 32 ? 4 : 0);
1387 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1389 return this->set_data_size(sz
);
1392 // Write out the PLT data.
1394 do_write(Output_file
*);
1400 unsigned int plt_index
;
1406 Sized_relobj_file
<size
, big_endian
>* object
;
1407 unsigned int local_sym_index
;
1408 unsigned int plt_index
;
1411 // The reloc section.
1412 Reloc_section
* rel_
;
1413 // The IFUNC relocations, if necessary. These must follow the
1414 // regular relocations.
1415 Reloc_section
* ifunc_rel_
;
1416 // The number of PLT entries.
1417 unsigned int count_
;
1418 // The number of PLT entries for IFUNC symbols.
1419 unsigned int ifunc_count_
;
1420 // Global STT_GNU_IFUNC symbols.
1421 std::vector
<Global_ifunc
> global_ifuncs_
;
1422 // Local STT_GNU_IFUNC symbols.
1423 std::vector
<Local_ifunc
> local_ifuncs_
;
1426 // Define the constants as required by C++ standard.
1428 template<int size
, bool big_endian
>
1429 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1431 template<int size
, bool big_endian
>
1433 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1435 template<int size
, bool big_endian
>
1436 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1438 template<int size
, bool big_endian
>
1440 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1442 template<int size
, bool big_endian
>
1443 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1445 // Create the PLT section. The ordinary .got section is an argument,
1446 // since we need to refer to the start.
1448 template<int size
, bool big_endian
>
1449 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1450 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1451 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1453 this->rel_
= new Reloc_section(false);
1454 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1455 elfcpp::SHF_ALLOC
, this->rel_
,
1456 ORDER_DYNAMIC_PLT_RELOCS
, false);
1459 template<int size
, bool big_endian
>
1461 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1466 // Add an entry to the PLT.
1468 template<int size
, bool big_endian
>
1470 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1474 gold_assert(!gsym
->has_plt_offset());
1476 section_offset_type plt_offset
;
1479 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1480 && gsym
->can_use_relative_reloc(false))
1482 index
= this->ifunc_count_
;
1483 plt_offset
= plt_index_to_offset(index
);
1484 gsym
->set_plt_offset(plt_offset
);
1485 ++this->ifunc_count_
;
1486 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1488 struct Global_ifunc gi
;
1491 gi
.plt_index
= index
;
1492 this->global_ifuncs_
.push_back(gi
);
1496 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1497 gsym
->set_plt_offset(plt_offset
);
1499 gsym
->set_needs_dynsym_entry();
1500 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1504 // Note that we don't need to save the symbol. The contents of the
1505 // PLT are independent of which symbols are used. The symbols only
1506 // appear in the relocations.
1509 template<int size
, bool big_endian
>
1511 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1512 Symbol_table
* symtab
,
1514 Sized_relobj_file
<size
, big_endian
>* relobj
,
1515 unsigned int local_sym_index
)
1517 unsigned int index
= this->ifunc_count_
;
1518 section_offset_type plt_offset
;
1520 plt_offset
= plt_index_to_offset(index
);
1521 ++this->ifunc_count_
;
1523 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1525 struct Local_ifunc li
;
1528 li
.local_sym_index
= local_sym_index
;
1529 li
.plt_index
= index
;
1530 this->local_ifuncs_
.push_back(li
);
1535 // Emit any pending IFUNC plt relocations.
1537 template<int size
, bool big_endian
>
1539 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1541 // Emit any pending IFUNC relocs.
1542 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1543 this->global_ifuncs_
.begin();
1544 p
!= this->global_ifuncs_
.end();
1547 section_offset_type plt_offset
;
1550 index
= this->count_
+ p
->plt_index
+ 4;
1551 plt_offset
= this->plt_index_to_offset(index
);
1552 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1553 this, plt_offset
, 0);
1556 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1557 this->local_ifuncs_
.begin();
1558 p
!= this->local_ifuncs_
.end();
1561 section_offset_type plt_offset
;
1564 index
= this->count_
+ p
->plt_index
+ 4;
1565 plt_offset
= this->plt_index_to_offset(index
);
1566 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1567 elfcpp::R_SPARC_JMP_IREL
,
1568 this, plt_offset
, 0);
1572 // Return where the IFUNC relocations should go in the PLT. These
1573 // follow the non-IFUNC relocations.
1575 template<int size
, bool big_endian
>
1576 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1577 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1578 Symbol_table
* symtab
,
1581 if (this->ifunc_rel_
== NULL
)
1583 this->ifunc_rel_
= new Reloc_section(false);
1584 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1585 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1586 ORDER_DYNAMIC_PLT_RELOCS
, false);
1587 gold_assert(this->ifunc_rel_
->output_section()
1588 == this->rel_
->output_section());
1590 if (parameters
->doing_static_link())
1592 // A statically linked executable will only have a .rel.plt
1593 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1594 // relocs for STT_GNU_IFUNC symbols. The library will use
1595 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1596 // at program startup time.
1597 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1598 Symbol_table::PREDEFINED
,
1599 this->ifunc_rel_
, 0, 0,
1600 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1601 elfcpp::STV_HIDDEN
, 0, false, true);
1602 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1603 Symbol_table::PREDEFINED
,
1604 this->ifunc_rel_
, 0, 0,
1605 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1606 elfcpp::STV_HIDDEN
, 0, true, true);
1609 return this->ifunc_rel_
;
1612 // Return the PLT address to use for a global symbol.
1614 template<int size
, bool big_endian
>
1616 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1618 uint64_t offset
= 0;
1619 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1620 && gsym
->can_use_relative_reloc(false))
1621 offset
= plt_index_to_offset(this->count_
+ 4);
1622 return this->address() + offset
;
1625 // Return the PLT address to use for a local symbol. These are always
1626 // IRELATIVE relocs.
1628 template<int size
, bool big_endian
>
1630 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1634 return this->address() + plt_index_to_offset(this->count_
+ 4);
1637 static const unsigned int sparc_nop
= 0x01000000;
1638 static const unsigned int sparc_sethi_g1
= 0x03000000;
1639 static const unsigned int sparc_branch_always
= 0x30800000;
1640 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1641 static const unsigned int sparc_mov
= 0x80100000;
1642 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1643 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1644 static const unsigned int sparc_call_plus_8
= 0x40000002;
1645 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1646 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1647 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1649 // Write out the PLT.
1651 template<int size
, bool big_endian
>
1653 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1655 const off_t offset
= this->offset();
1656 const section_size_type oview_size
=
1657 convert_to_section_size_type(this->data_size());
1658 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1659 unsigned char* pov
= oview
;
1661 memset(pov
, 0, base_plt_entry_size
* 4);
1662 pov
+= this->first_plt_entry_offset();
1664 unsigned int plt_offset
= base_plt_entry_size
* 4;
1665 const unsigned int count
= this->entry_count();
1671 limit
= (count
> 32768 ? 32768 : count
);
1673 for (unsigned int i
= 0; i
< limit
; ++i
)
1675 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1676 sparc_sethi_g1
+ plt_offset
);
1677 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1678 sparc_branch_always_pt
+
1679 (((base_plt_entry_size
-
1680 (plt_offset
+ 4)) >> 2) &
1682 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1683 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1684 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1685 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1686 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1687 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1689 pov
+= base_plt_entry_size
;
1690 plt_offset
+= base_plt_entry_size
;
1695 unsigned int ext_cnt
= count
- 32768;
1696 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1698 for (unsigned int i
= 0; i
< blks
; ++i
)
1700 unsigned int data_off
= (plt_entries_per_block
1701 * plt_insn_chunk_size
) - 4;
1703 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1705 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1707 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1709 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1711 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1712 sparc_ldx_o7_imm_g1
+
1713 (data_off
& 0x1fff));
1714 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1715 sparc_jmpl_o7_g1_g1
);
1716 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1719 elfcpp::Swap
<64, big_endian
>::writeval(
1720 pov
+ 0x4 + data_off
,
1721 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1723 pov
+= plt_insn_chunk_size
;
1728 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1729 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1731 unsigned int data_off
= (sub_blk_cnt
1732 * plt_insn_chunk_size
) - 4;
1734 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1736 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1738 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1740 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1742 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1743 sparc_ldx_o7_imm_g1
+
1744 (data_off
& 0x1fff));
1745 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1746 sparc_jmpl_o7_g1_g1
);
1747 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1750 elfcpp::Swap
<64, big_endian
>::writeval(
1751 pov
+ 0x4 + data_off
,
1752 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1754 pov
+= plt_insn_chunk_size
;
1762 for (unsigned int i
= 0; i
< count
; ++i
)
1764 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1765 sparc_sethi_g1
+ plt_offset
);
1766 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1767 sparc_branch_always
+
1768 (((- (plt_offset
+ 4)) >> 2) &
1770 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1772 pov
+= base_plt_entry_size
;
1773 plt_offset
+= base_plt_entry_size
;
1776 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1780 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1782 of
->write_output_view(offset
, oview_size
, oview
);
1785 // Create the PLT section.
1787 template<int size
, bool big_endian
>
1789 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1792 // Create the GOT sections first.
1793 this->got_section(symtab
, layout
);
1795 // Ensure that .rela.dyn always appears before .rela.plt This is
1796 // necessary due to how, on Sparc and some other targets, .rela.dyn
1797 // needs to include .rela.plt in it's range.
1798 this->rela_dyn_section(layout
);
1800 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1801 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1803 | elfcpp::SHF_EXECINSTR
1804 | elfcpp::SHF_WRITE
),
1805 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1807 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1808 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1809 Symbol_table::PREDEFINED
,
1811 0, 0, elfcpp::STT_OBJECT
,
1813 elfcpp::STV_HIDDEN
, 0,
1817 // Create a PLT entry for a global symbol.
1819 template<int size
, bool big_endian
>
1821 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1825 if (gsym
->has_plt_offset())
1828 if (this->plt_
== NULL
)
1829 this->make_plt_section(symtab
, layout
);
1831 this->plt_
->add_entry(symtab
, layout
, gsym
);
1834 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1836 template<int size
, bool big_endian
>
1838 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1839 Symbol_table
* symtab
,
1841 Sized_relobj_file
<size
, big_endian
>* relobj
,
1842 unsigned int local_sym_index
)
1844 if (relobj
->local_has_plt_offset(local_sym_index
))
1846 if (this->plt_
== NULL
)
1847 this->make_plt_section(symtab
, layout
);
1848 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1851 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1854 // Return the number of entries in the PLT.
1856 template<int size
, bool big_endian
>
1858 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1860 if (this->plt_
== NULL
)
1862 return this->plt_
->entry_count();
1865 // Return the offset of the first non-reserved PLT entry.
1867 template<int size
, bool big_endian
>
1869 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1871 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1874 // Return the size of each PLT entry.
1876 template<int size
, bool big_endian
>
1878 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1880 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1883 // Create a GOT entry for the TLS module index.
1885 template<int size
, bool big_endian
>
1887 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1888 Symbol_table
* symtab
,
1890 Sized_relobj_file
<size
, big_endian
>* object
)
1892 if (this->got_mod_index_offset_
== -1U)
1894 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1895 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1896 Output_data_got
<size
, big_endian
>* got
;
1897 unsigned int got_offset
;
1899 got
= this->got_section(symtab
, layout
);
1900 got_offset
= got
->add_constant(0);
1901 rela_dyn
->add_local(object
, 0,
1903 elfcpp::R_SPARC_TLS_DTPMOD64
:
1904 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1906 got
->add_constant(0);
1907 this->got_mod_index_offset_
= got_offset
;
1909 return this->got_mod_index_offset_
;
1912 // Optimize the TLS relocation type based on what we know about the
1913 // symbol. IS_FINAL is true if the final address of this symbol is
1914 // known at link time.
1916 static tls::Tls_optimization
1917 optimize_tls_reloc(bool is_final
, int r_type
)
1919 // If we are generating a shared library, then we can't do anything
1921 if (parameters
->options().shared())
1922 return tls::TLSOPT_NONE
;
1926 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1927 case elfcpp::R_SPARC_TLS_GD_LO10
:
1928 case elfcpp::R_SPARC_TLS_GD_ADD
:
1929 case elfcpp::R_SPARC_TLS_GD_CALL
:
1930 // These are General-Dynamic which permits fully general TLS
1931 // access. Since we know that we are generating an executable,
1932 // we can convert this to Initial-Exec. If we also know that
1933 // this is a local symbol, we can further switch to Local-Exec.
1935 return tls::TLSOPT_TO_LE
;
1936 return tls::TLSOPT_TO_IE
;
1938 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1939 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1940 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1941 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1942 // This is Local-Dynamic, which refers to a local symbol in the
1943 // dynamic TLS block. Since we know that we generating an
1944 // executable, we can switch to Local-Exec.
1945 return tls::TLSOPT_TO_LE
;
1947 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1948 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1949 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1950 // Another type of Local-Dynamic relocation.
1951 return tls::TLSOPT_TO_LE
;
1953 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1954 case elfcpp::R_SPARC_TLS_IE_LO10
:
1955 case elfcpp::R_SPARC_TLS_IE_LD
:
1956 case elfcpp::R_SPARC_TLS_IE_LDX
:
1957 case elfcpp::R_SPARC_TLS_IE_ADD
:
1958 // These are Initial-Exec relocs which get the thread offset
1959 // from the GOT. If we know that we are linking against the
1960 // local symbol, we can switch to Local-Exec, which links the
1961 // thread offset into the instruction.
1963 return tls::TLSOPT_TO_LE
;
1964 return tls::TLSOPT_NONE
;
1966 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1967 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1968 // When we already have Local-Exec, there is nothing further we
1970 return tls::TLSOPT_NONE
;
1977 // Get the Reference_flags for a particular relocation.
1979 template<int size
, bool big_endian
>
1981 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1986 case elfcpp::R_SPARC_NONE
:
1987 case elfcpp::R_SPARC_REGISTER
:
1988 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1989 case elfcpp::R_SPARC_GNU_VTENTRY
:
1990 // No symbol reference.
1993 case elfcpp::R_SPARC_UA64
:
1994 case elfcpp::R_SPARC_64
:
1995 case elfcpp::R_SPARC_HIX22
:
1996 case elfcpp::R_SPARC_LOX10
:
1997 case elfcpp::R_SPARC_H34
:
1998 case elfcpp::R_SPARC_H44
:
1999 case elfcpp::R_SPARC_M44
:
2000 case elfcpp::R_SPARC_L44
:
2001 case elfcpp::R_SPARC_HH22
:
2002 case elfcpp::R_SPARC_HM10
:
2003 case elfcpp::R_SPARC_LM22
:
2004 case elfcpp::R_SPARC_HI22
:
2005 case elfcpp::R_SPARC_LO10
:
2006 case elfcpp::R_SPARC_OLO10
:
2007 case elfcpp::R_SPARC_UA32
:
2008 case elfcpp::R_SPARC_32
:
2009 case elfcpp::R_SPARC_UA16
:
2010 case elfcpp::R_SPARC_16
:
2011 case elfcpp::R_SPARC_11
:
2012 case elfcpp::R_SPARC_10
:
2013 case elfcpp::R_SPARC_8
:
2014 case elfcpp::R_SPARC_7
:
2015 case elfcpp::R_SPARC_6
:
2016 case elfcpp::R_SPARC_5
:
2017 return Symbol::ABSOLUTE_REF
;
2019 case elfcpp::R_SPARC_DISP8
:
2020 case elfcpp::R_SPARC_DISP16
:
2021 case elfcpp::R_SPARC_DISP32
:
2022 case elfcpp::R_SPARC_DISP64
:
2023 case elfcpp::R_SPARC_PC_HH22
:
2024 case elfcpp::R_SPARC_PC_HM10
:
2025 case elfcpp::R_SPARC_PC_LM22
:
2026 case elfcpp::R_SPARC_PC10
:
2027 case elfcpp::R_SPARC_PC22
:
2028 case elfcpp::R_SPARC_WDISP30
:
2029 case elfcpp::R_SPARC_WDISP22
:
2030 case elfcpp::R_SPARC_WDISP19
:
2031 case elfcpp::R_SPARC_WDISP16
:
2032 case elfcpp::R_SPARC_WDISP10
:
2033 return Symbol::RELATIVE_REF
;
2035 case elfcpp::R_SPARC_PLT64
:
2036 case elfcpp::R_SPARC_PLT32
:
2037 case elfcpp::R_SPARC_HIPLT22
:
2038 case elfcpp::R_SPARC_LOPLT10
:
2039 case elfcpp::R_SPARC_PCPLT10
:
2040 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2042 case elfcpp::R_SPARC_PCPLT32
:
2043 case elfcpp::R_SPARC_PCPLT22
:
2044 case elfcpp::R_SPARC_WPLT30
:
2045 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2047 case elfcpp::R_SPARC_GOTDATA_OP
:
2048 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2049 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2050 case elfcpp::R_SPARC_GOT10
:
2051 case elfcpp::R_SPARC_GOT13
:
2052 case elfcpp::R_SPARC_GOT22
:
2054 return Symbol::ABSOLUTE_REF
;
2056 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2057 case elfcpp::R_SPARC_TLS_GD_LO10
:
2058 case elfcpp::R_SPARC_TLS_GD_ADD
:
2059 case elfcpp::R_SPARC_TLS_GD_CALL
:
2060 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2061 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2062 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2063 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2064 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2065 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2066 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2067 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2068 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2069 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2070 case elfcpp::R_SPARC_TLS_IE_LO10
:
2071 case elfcpp::R_SPARC_TLS_IE_LD
:
2072 case elfcpp::R_SPARC_TLS_IE_LDX
:
2073 case elfcpp::R_SPARC_TLS_IE_ADD
:
2074 return Symbol::TLS_REF
;
2076 case elfcpp::R_SPARC_COPY
:
2077 case elfcpp::R_SPARC_GLOB_DAT
:
2078 case elfcpp::R_SPARC_JMP_SLOT
:
2079 case elfcpp::R_SPARC_JMP_IREL
:
2080 case elfcpp::R_SPARC_RELATIVE
:
2081 case elfcpp::R_SPARC_IRELATIVE
:
2082 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2083 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2084 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2085 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2086 case elfcpp::R_SPARC_TLS_TPOFF64
:
2087 case elfcpp::R_SPARC_TLS_TPOFF32
:
2089 // Not expected. We will give an error later.
2094 // Generate a PLT entry slot for a call to __tls_get_addr
2095 template<int size
, bool big_endian
>
2097 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2099 Target_sparc
<size
, big_endian
>* target
)
2101 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2103 target
->make_plt_entry(symtab
, layout
, gsym
);
2106 // Report an unsupported relocation against a local symbol.
2108 template<int size
, bool big_endian
>
2110 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2111 Sized_relobj_file
<size
, big_endian
>* object
,
2112 unsigned int r_type
)
2114 gold_error(_("%s: unsupported reloc %u against local symbol"),
2115 object
->name().c_str(), r_type
);
2118 // We are about to emit a dynamic relocation of type R_TYPE. If the
2119 // dynamic linker does not support it, issue an error.
2121 template<int size
, bool big_endian
>
2123 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2125 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2131 // These are the relocation types supported by glibc for sparc 64-bit.
2132 case elfcpp::R_SPARC_RELATIVE
:
2133 case elfcpp::R_SPARC_IRELATIVE
:
2134 case elfcpp::R_SPARC_COPY
:
2135 case elfcpp::R_SPARC_64
:
2136 case elfcpp::R_SPARC_GLOB_DAT
:
2137 case elfcpp::R_SPARC_JMP_SLOT
:
2138 case elfcpp::R_SPARC_JMP_IREL
:
2139 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2140 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2141 case elfcpp::R_SPARC_TLS_TPOFF64
:
2142 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2143 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2144 case elfcpp::R_SPARC_8
:
2145 case elfcpp::R_SPARC_16
:
2146 case elfcpp::R_SPARC_DISP8
:
2147 case elfcpp::R_SPARC_DISP16
:
2148 case elfcpp::R_SPARC_DISP32
:
2149 case elfcpp::R_SPARC_WDISP30
:
2150 case elfcpp::R_SPARC_LO10
:
2151 case elfcpp::R_SPARC_HI22
:
2152 case elfcpp::R_SPARC_OLO10
:
2153 case elfcpp::R_SPARC_H34
:
2154 case elfcpp::R_SPARC_H44
:
2155 case elfcpp::R_SPARC_M44
:
2156 case elfcpp::R_SPARC_L44
:
2157 case elfcpp::R_SPARC_HH22
:
2158 case elfcpp::R_SPARC_HM10
:
2159 case elfcpp::R_SPARC_LM22
:
2160 case elfcpp::R_SPARC_UA16
:
2161 case elfcpp::R_SPARC_UA32
:
2162 case elfcpp::R_SPARC_UA64
:
2173 // These are the relocation types supported by glibc for sparc 32-bit.
2174 case elfcpp::R_SPARC_RELATIVE
:
2175 case elfcpp::R_SPARC_IRELATIVE
:
2176 case elfcpp::R_SPARC_COPY
:
2177 case elfcpp::R_SPARC_GLOB_DAT
:
2178 case elfcpp::R_SPARC_32
:
2179 case elfcpp::R_SPARC_JMP_SLOT
:
2180 case elfcpp::R_SPARC_JMP_IREL
:
2181 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2182 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2183 case elfcpp::R_SPARC_TLS_TPOFF32
:
2184 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2185 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2186 case elfcpp::R_SPARC_8
:
2187 case elfcpp::R_SPARC_16
:
2188 case elfcpp::R_SPARC_DISP8
:
2189 case elfcpp::R_SPARC_DISP16
:
2190 case elfcpp::R_SPARC_DISP32
:
2191 case elfcpp::R_SPARC_LO10
:
2192 case elfcpp::R_SPARC_WDISP30
:
2193 case elfcpp::R_SPARC_HI22
:
2194 case elfcpp::R_SPARC_UA16
:
2195 case elfcpp::R_SPARC_UA32
:
2203 // This prevents us from issuing more than one error per reloc
2204 // section. But we can still wind up issuing more than one
2205 // error per object file.
2206 if (this->issued_non_pic_error_
)
2208 gold_assert(parameters
->options().output_is_position_independent());
2209 object
->error(_("requires unsupported dynamic reloc; "
2210 "recompile with -fPIC"));
2211 this->issued_non_pic_error_
= true;
2215 // Return whether we need to make a PLT entry for a relocation of the
2216 // given type against a STT_GNU_IFUNC symbol.
2218 template<int size
, bool big_endian
>
2220 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2221 Sized_relobj_file
<size
, big_endian
>* object
,
2222 unsigned int r_type
)
2224 int flags
= Scan::get_reference_flags(r_type
);
2225 if (flags
& Symbol::TLS_REF
)
2226 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2227 object
->name().c_str(), r_type
);
2231 // Scan a relocation for a local symbol.
2233 template<int size
, bool big_endian
>
2235 Target_sparc
<size
, big_endian
>::Scan::local(
2236 Symbol_table
* symtab
,
2238 Target_sparc
<size
, big_endian
>* target
,
2239 Sized_relobj_file
<size
, big_endian
>* object
,
2240 unsigned int data_shndx
,
2241 Output_section
* output_section
,
2242 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2243 unsigned int r_type
,
2244 const elfcpp::Sym
<size
, big_endian
>& lsym
,
2250 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2251 unsigned int orig_r_type
= r_type
;
2255 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2257 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2258 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2263 case elfcpp::R_SPARC_NONE
:
2264 case elfcpp::R_SPARC_REGISTER
:
2265 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2266 case elfcpp::R_SPARC_GNU_VTENTRY
:
2269 case elfcpp::R_SPARC_64
:
2270 case elfcpp::R_SPARC_32
:
2271 // If building a shared library (or a position-independent
2272 // executable), we need to create a dynamic relocation for
2273 // this location. The relocation applied at link time will
2274 // apply the link-time value, so we flag the location with
2275 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2276 // relocate it easily.
2277 if (parameters
->options().output_is_position_independent())
2279 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2280 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2281 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2282 output_section
, data_shndx
,
2283 reloc
.get_r_offset(),
2284 reloc
.get_r_addend(), is_ifunc
);
2288 case elfcpp::R_SPARC_HIX22
:
2289 case elfcpp::R_SPARC_LOX10
:
2290 case elfcpp::R_SPARC_H34
:
2291 case elfcpp::R_SPARC_H44
:
2292 case elfcpp::R_SPARC_M44
:
2293 case elfcpp::R_SPARC_L44
:
2294 case elfcpp::R_SPARC_HH22
:
2295 case elfcpp::R_SPARC_HM10
:
2296 case elfcpp::R_SPARC_LM22
:
2297 case elfcpp::R_SPARC_UA64
:
2298 case elfcpp::R_SPARC_UA32
:
2299 case elfcpp::R_SPARC_UA16
:
2300 case elfcpp::R_SPARC_HI22
:
2301 case elfcpp::R_SPARC_LO10
:
2302 case elfcpp::R_SPARC_OLO10
:
2303 case elfcpp::R_SPARC_16
:
2304 case elfcpp::R_SPARC_11
:
2305 case elfcpp::R_SPARC_10
:
2306 case elfcpp::R_SPARC_8
:
2307 case elfcpp::R_SPARC_7
:
2308 case elfcpp::R_SPARC_6
:
2309 case elfcpp::R_SPARC_5
:
2310 // If building a shared library (or a position-independent
2311 // executable), we need to create a dynamic relocation for
2313 if (parameters
->options().output_is_position_independent())
2315 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2316 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2318 check_non_pic(object
, r_type
);
2319 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2321 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2322 data_shndx
, reloc
.get_r_offset(),
2323 reloc
.get_r_addend());
2327 gold_assert(lsym
.get_st_value() == 0);
2328 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2329 output_section
, data_shndx
,
2330 reloc
.get_r_offset(),
2331 reloc
.get_r_addend());
2336 case elfcpp::R_SPARC_WDISP30
:
2337 case elfcpp::R_SPARC_WPLT30
:
2338 case elfcpp::R_SPARC_WDISP22
:
2339 case elfcpp::R_SPARC_WDISP19
:
2340 case elfcpp::R_SPARC_WDISP16
:
2341 case elfcpp::R_SPARC_WDISP10
:
2342 case elfcpp::R_SPARC_DISP8
:
2343 case elfcpp::R_SPARC_DISP16
:
2344 case elfcpp::R_SPARC_DISP32
:
2345 case elfcpp::R_SPARC_DISP64
:
2346 case elfcpp::R_SPARC_PC10
:
2347 case elfcpp::R_SPARC_PC22
:
2350 case elfcpp::R_SPARC_GOTDATA_OP
:
2351 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2352 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2353 // We will optimize this into a GOT relative relocation
2354 // and code transform the GOT load into an addition.
2357 case elfcpp::R_SPARC_GOT10
:
2358 case elfcpp::R_SPARC_GOT13
:
2359 case elfcpp::R_SPARC_GOT22
:
2361 // The symbol requires a GOT entry.
2362 Output_data_got
<size
, big_endian
>* got
;
2365 got
= target
->got_section(symtab
, layout
);
2366 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2368 // If we are generating a shared object, we need to add a
2369 // dynamic relocation for this symbol's GOT entry.
2370 if (parameters
->options().output_is_position_independent())
2372 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2374 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2375 unsigned int off
= got
->add_constant(0);
2376 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2377 rela_dyn
->add_local_relative(object
, r_sym
,
2378 elfcpp::R_SPARC_RELATIVE
,
2379 got
, off
, 0, is_ifunc
);
2383 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2387 // These are initial TLS relocs, which are expected when
2389 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2390 case elfcpp::R_SPARC_TLS_GD_LO10
:
2391 case elfcpp::R_SPARC_TLS_GD_ADD
:
2392 case elfcpp::R_SPARC_TLS_GD_CALL
:
2393 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2394 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2395 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2396 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2397 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2398 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2399 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2400 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2401 case elfcpp::R_SPARC_TLS_IE_LO10
:
2402 case elfcpp::R_SPARC_TLS_IE_LD
:
2403 case elfcpp::R_SPARC_TLS_IE_LDX
:
2404 case elfcpp::R_SPARC_TLS_IE_ADD
:
2405 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2406 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2408 bool output_is_shared
= parameters
->options().shared();
2409 const tls::Tls_optimization optimized_type
2410 = optimize_tls_reloc(!output_is_shared
, r_type
);
2413 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2414 case elfcpp::R_SPARC_TLS_GD_LO10
:
2415 case elfcpp::R_SPARC_TLS_GD_ADD
:
2416 case elfcpp::R_SPARC_TLS_GD_CALL
:
2417 if (optimized_type
== tls::TLSOPT_NONE
)
2419 // Create a pair of GOT entries for the module index and
2420 // dtv-relative offset.
2421 Output_data_got
<size
, big_endian
>* got
2422 = target
->got_section(symtab
, layout
);
2423 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2424 unsigned int shndx
= lsym
.get_st_shndx();
2426 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2428 object
->error(_("local symbol %u has bad shndx %u"),
2431 got
->add_local_pair_with_rel(object
, r_sym
,
2432 lsym
.get_st_shndx(),
2434 target
->rela_dyn_section(layout
),
2436 ? elfcpp::R_SPARC_TLS_DTPMOD64
2437 : elfcpp::R_SPARC_TLS_DTPMOD32
));
2438 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2439 generate_tls_call(symtab
, layout
, target
);
2441 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2442 unsupported_reloc_local(object
, r_type
);
2445 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2446 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2447 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2448 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2449 if (optimized_type
== tls::TLSOPT_NONE
)
2451 // Create a GOT entry for the module index.
2452 target
->got_mod_index_entry(symtab
, layout
, object
);
2454 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2455 generate_tls_call(symtab
, layout
, target
);
2457 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2458 unsupported_reloc_local(object
, r_type
);
2461 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2462 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2463 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2466 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2467 case elfcpp::R_SPARC_TLS_IE_LO10
:
2468 case elfcpp::R_SPARC_TLS_IE_LD
:
2469 case elfcpp::R_SPARC_TLS_IE_LDX
:
2470 case elfcpp::R_SPARC_TLS_IE_ADD
:
2471 layout
->set_has_static_tls();
2472 if (optimized_type
== tls::TLSOPT_NONE
)
2474 // Create a GOT entry for the tp-relative offset.
2475 Output_data_got
<size
, big_endian
>* got
2476 = target
->got_section(symtab
, layout
);
2477 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2479 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2481 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2482 unsigned int off
= got
->add_constant(0);
2484 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2486 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2488 elfcpp::R_SPARC_TLS_TPOFF64
:
2489 elfcpp::R_SPARC_TLS_TPOFF32
),
2493 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2494 unsupported_reloc_local(object
, r_type
);
2497 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2498 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2499 layout
->set_has_static_tls();
2500 if (output_is_shared
)
2502 // We need to create a dynamic relocation.
2503 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2504 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2505 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2506 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2507 output_section
, data_shndx
,
2508 reloc
.get_r_offset(), 0);
2515 // These are relocations which should only be seen by the
2516 // dynamic linker, and should never be seen here.
2517 case elfcpp::R_SPARC_COPY
:
2518 case elfcpp::R_SPARC_GLOB_DAT
:
2519 case elfcpp::R_SPARC_JMP_SLOT
:
2520 case elfcpp::R_SPARC_JMP_IREL
:
2521 case elfcpp::R_SPARC_RELATIVE
:
2522 case elfcpp::R_SPARC_IRELATIVE
:
2523 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2524 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2525 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2526 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2527 case elfcpp::R_SPARC_TLS_TPOFF64
:
2528 case elfcpp::R_SPARC_TLS_TPOFF32
:
2529 gold_error(_("%s: unexpected reloc %u in object file"),
2530 object
->name().c_str(), r_type
);
2534 unsupported_reloc_local(object
, r_type
);
2539 // Report an unsupported relocation against a global symbol.
2541 template<int size
, bool big_endian
>
2543 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2544 Sized_relobj_file
<size
, big_endian
>* object
,
2545 unsigned int r_type
,
2548 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2549 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2552 // Scan a relocation for a global symbol.
2554 template<int size
, bool big_endian
>
2556 Target_sparc
<size
, big_endian
>::Scan::global(
2557 Symbol_table
* symtab
,
2559 Target_sparc
<size
, big_endian
>* target
,
2560 Sized_relobj_file
<size
, big_endian
>* object
,
2561 unsigned int data_shndx
,
2562 Output_section
* output_section
,
2563 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2564 unsigned int r_type
,
2567 unsigned int orig_r_type
= r_type
;
2568 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2570 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2571 // section. We check here to avoid creating a dynamic reloc against
2572 // _GLOBAL_OFFSET_TABLE_.
2573 if (!target
->has_got_section()
2574 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2575 target
->got_section(symtab
, layout
);
2579 // A STT_GNU_IFUNC symbol may require a PLT entry.
2581 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2582 target
->make_plt_entry(symtab
, layout
, gsym
);
2586 case elfcpp::R_SPARC_NONE
:
2587 case elfcpp::R_SPARC_REGISTER
:
2588 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2589 case elfcpp::R_SPARC_GNU_VTENTRY
:
2592 case elfcpp::R_SPARC_PLT64
:
2593 case elfcpp::R_SPARC_PLT32
:
2594 case elfcpp::R_SPARC_HIPLT22
:
2595 case elfcpp::R_SPARC_LOPLT10
:
2596 case elfcpp::R_SPARC_PCPLT32
:
2597 case elfcpp::R_SPARC_PCPLT22
:
2598 case elfcpp::R_SPARC_PCPLT10
:
2599 case elfcpp::R_SPARC_WPLT30
:
2600 // If the symbol is fully resolved, this is just a PC32 reloc.
2601 // Otherwise we need a PLT entry.
2602 if (gsym
->final_value_is_known())
2604 // If building a shared library, we can also skip the PLT entry
2605 // if the symbol is defined in the output file and is protected
2607 if (gsym
->is_defined()
2608 && !gsym
->is_from_dynobj()
2609 && !gsym
->is_preemptible())
2611 target
->make_plt_entry(symtab
, layout
, gsym
);
2614 case elfcpp::R_SPARC_DISP8
:
2615 case elfcpp::R_SPARC_DISP16
:
2616 case elfcpp::R_SPARC_DISP32
:
2617 case elfcpp::R_SPARC_DISP64
:
2618 case elfcpp::R_SPARC_PC_HH22
:
2619 case elfcpp::R_SPARC_PC_HM10
:
2620 case elfcpp::R_SPARC_PC_LM22
:
2621 case elfcpp::R_SPARC_PC10
:
2622 case elfcpp::R_SPARC_PC22
:
2623 case elfcpp::R_SPARC_WDISP30
:
2624 case elfcpp::R_SPARC_WDISP22
:
2625 case elfcpp::R_SPARC_WDISP19
:
2626 case elfcpp::R_SPARC_WDISP16
:
2627 case elfcpp::R_SPARC_WDISP10
:
2629 if (gsym
->needs_plt_entry())
2630 target
->make_plt_entry(symtab
, layout
, gsym
);
2631 // Make a dynamic relocation if necessary.
2632 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2634 if (gsym
->may_need_copy_reloc())
2636 target
->copy_reloc(symtab
, layout
, object
,
2637 data_shndx
, output_section
, gsym
,
2642 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2643 check_non_pic(object
, r_type
);
2644 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2645 data_shndx
, reloc
.get_r_offset(),
2646 reloc
.get_r_addend());
2652 case elfcpp::R_SPARC_UA64
:
2653 case elfcpp::R_SPARC_64
:
2654 case elfcpp::R_SPARC_HIX22
:
2655 case elfcpp::R_SPARC_LOX10
:
2656 case elfcpp::R_SPARC_H34
:
2657 case elfcpp::R_SPARC_H44
:
2658 case elfcpp::R_SPARC_M44
:
2659 case elfcpp::R_SPARC_L44
:
2660 case elfcpp::R_SPARC_HH22
:
2661 case elfcpp::R_SPARC_HM10
:
2662 case elfcpp::R_SPARC_LM22
:
2663 case elfcpp::R_SPARC_HI22
:
2664 case elfcpp::R_SPARC_LO10
:
2665 case elfcpp::R_SPARC_OLO10
:
2666 case elfcpp::R_SPARC_UA32
:
2667 case elfcpp::R_SPARC_32
:
2668 case elfcpp::R_SPARC_UA16
:
2669 case elfcpp::R_SPARC_16
:
2670 case elfcpp::R_SPARC_11
:
2671 case elfcpp::R_SPARC_10
:
2672 case elfcpp::R_SPARC_8
:
2673 case elfcpp::R_SPARC_7
:
2674 case elfcpp::R_SPARC_6
:
2675 case elfcpp::R_SPARC_5
:
2677 // Make a PLT entry if necessary.
2678 if (gsym
->needs_plt_entry())
2680 target
->make_plt_entry(symtab
, layout
, gsym
);
2681 // Since this is not a PC-relative relocation, we may be
2682 // taking the address of a function. In that case we need to
2683 // set the entry in the dynamic symbol table to the address of
2685 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2686 gsym
->set_needs_dynsym_value();
2688 // Make a dynamic relocation if necessary.
2689 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2691 unsigned int r_off
= reloc
.get_r_offset();
2693 // The assembler can sometimes emit unaligned relocations
2694 // for dwarf2 cfi directives.
2697 case elfcpp::R_SPARC_16
:
2699 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2701 case elfcpp::R_SPARC_32
:
2703 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2705 case elfcpp::R_SPARC_64
:
2707 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2709 case elfcpp::R_SPARC_UA16
:
2711 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2713 case elfcpp::R_SPARC_UA32
:
2715 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2717 case elfcpp::R_SPARC_UA64
:
2719 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2723 if (gsym
->may_need_copy_reloc())
2725 target
->copy_reloc(symtab
, layout
, object
,
2726 data_shndx
, output_section
, gsym
, reloc
);
2728 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2729 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2730 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2731 && gsym
->can_use_relative_reloc(false)
2732 && !gsym
->is_from_dynobj()
2733 && !gsym
->is_undefined()
2734 && !gsym
->is_preemptible())
2736 // Use an IRELATIVE reloc for a locally defined
2737 // STT_GNU_IFUNC symbol. This makes a function
2738 // address in a PIE executable match the address in a
2739 // shared library that it links against.
2740 Reloc_section
* rela_dyn
=
2741 target
->rela_ifunc_section(layout
);
2742 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2743 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2744 output_section
, object
,
2746 reloc
.get_r_offset(),
2747 reloc
.get_r_addend());
2749 else if ((r_type
== elfcpp::R_SPARC_32
2750 || r_type
== elfcpp::R_SPARC_64
)
2751 && gsym
->can_use_relative_reloc(false))
2753 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2754 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2755 output_section
, object
,
2756 data_shndx
, reloc
.get_r_offset(),
2757 reloc
.get_r_addend(), is_ifunc
);
2761 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2763 check_non_pic(object
, r_type
);
2764 if (gsym
->is_from_dynobj()
2765 || gsym
->is_undefined()
2766 || gsym
->is_preemptible())
2767 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2769 reloc
.get_r_offset(),
2770 reloc
.get_r_addend());
2772 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2775 reloc
.get_r_offset(),
2776 reloc
.get_r_addend());
2782 case elfcpp::R_SPARC_GOTDATA_OP
:
2783 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2784 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2785 if (gsym
->is_defined()
2786 && !gsym
->is_from_dynobj()
2787 && !gsym
->is_preemptible()
2790 // We will optimize this into a GOT relative relocation
2791 // and code transform the GOT load into an addition.
2794 case elfcpp::R_SPARC_GOT10
:
2795 case elfcpp::R_SPARC_GOT13
:
2796 case elfcpp::R_SPARC_GOT22
:
2798 // The symbol requires a GOT entry.
2799 Output_data_got
<size
, big_endian
>* got
;
2801 got
= target
->got_section(symtab
, layout
);
2802 if (gsym
->final_value_is_known())
2804 // For a STT_GNU_IFUNC symbol we want the PLT address.
2805 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2806 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2808 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2812 // If this symbol is not fully resolved, we need to add a
2813 // GOT entry with a dynamic relocation.
2814 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2816 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2818 // 1) The symbol may be defined in some other module.
2820 // 2) We are building a shared library and this is a
2821 // protected symbol; using GLOB_DAT means that the dynamic
2822 // linker can use the address of the PLT in the main
2823 // executable when appropriate so that function address
2824 // comparisons work.
2826 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2827 // code, again so that function address comparisons work.
2828 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2829 if (gsym
->is_from_dynobj()
2830 || gsym
->is_undefined()
2831 || gsym
->is_preemptible()
2832 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2833 && parameters
->options().shared())
2834 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2835 && parameters
->options().output_is_position_independent()
2836 && !gsym
->is_forced_local()))
2838 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2840 // If this symbol is forced local, this relocation will
2841 // not work properly. That's because ld.so on sparc
2842 // (and 32-bit powerpc) expects st_value in the r_addend
2843 // of relocations for STB_LOCAL symbols. Curiously the
2844 // BFD linker does not promote global hidden symbols to be
2845 // STB_LOCAL in the dynamic symbol table like Gold does.
2846 gold_assert(!gsym
->is_forced_local());
2847 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2850 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2852 unsigned int off
= got
->add_constant(0);
2854 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2857 // Tell the dynamic linker to use the PLT address
2858 // when resolving relocations.
2859 if (gsym
->is_from_dynobj()
2860 && !parameters
->options().shared())
2861 gsym
->set_needs_dynsym_value();
2863 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2864 got
, off
, 0, is_ifunc
);
2870 // These are initial tls relocs, which are expected when
2872 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2873 case elfcpp::R_SPARC_TLS_GD_LO10
:
2874 case elfcpp::R_SPARC_TLS_GD_ADD
:
2875 case elfcpp::R_SPARC_TLS_GD_CALL
:
2876 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2877 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2878 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2879 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2880 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2881 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2882 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2883 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2884 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2885 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2886 case elfcpp::R_SPARC_TLS_IE_LO10
:
2887 case elfcpp::R_SPARC_TLS_IE_LD
:
2888 case elfcpp::R_SPARC_TLS_IE_LDX
:
2889 case elfcpp::R_SPARC_TLS_IE_ADD
:
2891 const bool is_final
= gsym
->final_value_is_known();
2892 const tls::Tls_optimization optimized_type
2893 = optimize_tls_reloc(is_final
, r_type
);
2896 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2897 case elfcpp::R_SPARC_TLS_GD_LO10
:
2898 case elfcpp::R_SPARC_TLS_GD_ADD
:
2899 case elfcpp::R_SPARC_TLS_GD_CALL
:
2900 if (optimized_type
== tls::TLSOPT_NONE
)
2902 // Create a pair of GOT entries for the module index and
2903 // dtv-relative offset.
2904 Output_data_got
<size
, big_endian
>* got
2905 = target
->got_section(symtab
, layout
);
2906 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2907 target
->rela_dyn_section(layout
),
2909 ? elfcpp::R_SPARC_TLS_DTPMOD64
2910 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2912 ? elfcpp::R_SPARC_TLS_DTPOFF64
2913 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2915 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2916 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2917 generate_tls_call(symtab
, layout
, target
);
2919 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2921 // Create a GOT entry for the tp-relative offset.
2922 Output_data_got
<size
, big_endian
>* got
2923 = target
->got_section(symtab
, layout
);
2924 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2925 target
->rela_dyn_section(layout
),
2927 elfcpp::R_SPARC_TLS_TPOFF64
:
2928 elfcpp::R_SPARC_TLS_TPOFF32
));
2930 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2931 unsupported_reloc_global(object
, r_type
, gsym
);
2934 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2935 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2936 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2937 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2938 if (optimized_type
== tls::TLSOPT_NONE
)
2940 // Create a GOT entry for the module index.
2941 target
->got_mod_index_entry(symtab
, layout
, object
);
2943 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2944 generate_tls_call(symtab
, layout
, target
);
2946 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2947 unsupported_reloc_global(object
, r_type
, gsym
);
2950 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2951 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2952 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2955 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2956 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2957 layout
->set_has_static_tls();
2958 if (parameters
->options().shared())
2960 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2961 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2962 output_section
, object
,
2963 data_shndx
, reloc
.get_r_offset(),
2968 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2969 case elfcpp::R_SPARC_TLS_IE_LO10
:
2970 case elfcpp::R_SPARC_TLS_IE_LD
:
2971 case elfcpp::R_SPARC_TLS_IE_LDX
:
2972 case elfcpp::R_SPARC_TLS_IE_ADD
:
2973 layout
->set_has_static_tls();
2974 if (optimized_type
== tls::TLSOPT_NONE
)
2976 // Create a GOT entry for the tp-relative offset.
2977 Output_data_got
<size
, big_endian
>* got
2978 = target
->got_section(symtab
, layout
);
2979 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2980 target
->rela_dyn_section(layout
),
2982 ? elfcpp::R_SPARC_TLS_TPOFF64
2983 : elfcpp::R_SPARC_TLS_TPOFF32
));
2985 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2986 unsupported_reloc_global(object
, r_type
, gsym
);
2992 // These are relocations which should only be seen by the
2993 // dynamic linker, and should never be seen here.
2994 case elfcpp::R_SPARC_COPY
:
2995 case elfcpp::R_SPARC_GLOB_DAT
:
2996 case elfcpp::R_SPARC_JMP_SLOT
:
2997 case elfcpp::R_SPARC_JMP_IREL
:
2998 case elfcpp::R_SPARC_RELATIVE
:
2999 case elfcpp::R_SPARC_IRELATIVE
:
3000 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3001 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3002 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3003 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3004 case elfcpp::R_SPARC_TLS_TPOFF64
:
3005 case elfcpp::R_SPARC_TLS_TPOFF32
:
3006 gold_error(_("%s: unexpected reloc %u in object file"),
3007 object
->name().c_str(), r_type
);
3011 unsupported_reloc_global(object
, r_type
, gsym
);
3016 // Process relocations for gc.
3018 template<int size
, bool big_endian
>
3020 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3021 Symbol_table
* symtab
,
3023 Sized_relobj_file
<size
, big_endian
>* object
,
3024 unsigned int data_shndx
,
3026 const unsigned char* prelocs
,
3028 Output_section
* output_section
,
3029 bool needs_special_offset_handling
,
3030 size_t local_symbol_count
,
3031 const unsigned char* plocal_symbols
)
3033 typedef Target_sparc
<size
, big_endian
> Sparc
;
3034 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3036 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
3037 typename
Target_sparc::Relocatable_size_for_reloc
>(
3046 needs_special_offset_handling
,
3051 // Scan relocations for a section.
3053 template<int size
, bool big_endian
>
3055 Target_sparc
<size
, big_endian
>::scan_relocs(
3056 Symbol_table
* symtab
,
3058 Sized_relobj_file
<size
, big_endian
>* object
,
3059 unsigned int data_shndx
,
3060 unsigned int sh_type
,
3061 const unsigned char* prelocs
,
3063 Output_section
* output_section
,
3064 bool needs_special_offset_handling
,
3065 size_t local_symbol_count
,
3066 const unsigned char* plocal_symbols
)
3068 typedef Target_sparc
<size
, big_endian
> Sparc
;
3069 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3071 if (sh_type
== elfcpp::SHT_REL
)
3073 gold_error(_("%s: unsupported REL reloc section"),
3074 object
->name().c_str());
3078 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
3087 needs_special_offset_handling
,
3092 // Finalize the sections.
3094 template<int size
, bool big_endian
>
3096 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3098 const Input_objects
*,
3099 Symbol_table
* symtab
)
3102 this->plt_
->emit_pending_ifunc_relocs();
3104 // Fill in some more dynamic tags.
3105 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3107 : this->plt_
->rel_plt());
3108 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3109 this->rela_dyn_
, true, true);
3111 // Emit any relocs we saved in an attempt to avoid generating COPY
3113 if (this->copy_relocs_
.any_saved_relocs())
3114 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3116 if (parameters
->doing_static_link()
3117 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3119 // If linking statically, make sure that the __rela_iplt symbols
3120 // were defined if necessary, even if we didn't create a PLT.
3121 static const Define_symbol_in_segment syms
[] =
3124 "__rela_iplt_start", // name
3125 elfcpp::PT_LOAD
, // segment_type
3126 elfcpp::PF_W
, // segment_flags_set
3127 elfcpp::PF(0), // segment_flags_clear
3130 elfcpp::STT_NOTYPE
, // type
3131 elfcpp::STB_GLOBAL
, // binding
3132 elfcpp::STV_HIDDEN
, // visibility
3134 Symbol::SEGMENT_START
, // offset_from_base
3138 "__rela_iplt_end", // name
3139 elfcpp::PT_LOAD
, // segment_type
3140 elfcpp::PF_W
, // segment_flags_set
3141 elfcpp::PF(0), // segment_flags_clear
3144 elfcpp::STT_NOTYPE
, // type
3145 elfcpp::STB_GLOBAL
, // binding
3146 elfcpp::STV_HIDDEN
, // visibility
3148 Symbol::SEGMENT_START
, // offset_from_base
3153 symtab
->define_symbols(layout
, 2, syms
,
3154 layout
->script_options()->saw_sections_clause());
3158 // Perform a relocation.
3160 template<int size
, bool big_endian
>
3162 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3163 const Relocate_info
<size
, big_endian
>* relinfo
,
3164 Target_sparc
* target
,
3167 const elfcpp::Rela
<size
, big_endian
>& rela
,
3168 unsigned int r_type
,
3169 const Sized_symbol
<size
>* gsym
,
3170 const Symbol_value
<size
>* psymval
,
3171 unsigned char* view
,
3172 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3173 section_size_type view_size
)
3175 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3178 if (this->ignore_gd_add_
)
3180 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3181 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3182 _("missing expected TLS relocation"));
3185 this->ignore_gd_add_
= false;
3189 if (this->reloc_adjust_addr_
== view
)
3192 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3193 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3195 // Pick the value to use for symbols defined in shared objects.
3196 Symbol_value
<size
> symval
;
3198 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3200 elfcpp::Elf_Xword value
;
3202 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3204 symval
.set_output_value(value
);
3208 else if (gsym
== NULL
&& orig_is_ifunc
)
3210 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3211 if (object
->local_has_plt_offset(r_sym
))
3213 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3214 + object
->local_plt_offset(r_sym
));
3219 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3221 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3222 // pointer points to the beginning, not the end, of the table.
3223 // So we just use the plain offset.
3224 unsigned int got_offset
= 0;
3225 bool gdop_valid
= false;
3228 case elfcpp::R_SPARC_GOTDATA_OP
:
3229 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3230 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3231 // If this is local, we did not create a GOT entry because we
3232 // intend to transform this into a GOT relative relocation.
3234 || (gsym
->is_defined()
3235 && !gsym
->is_from_dynobj()
3236 && !gsym
->is_preemptible()
3239 got_offset
= psymval
->value(object
, 0) - target
->got_address();
3243 case elfcpp::R_SPARC_GOT10
:
3244 case elfcpp::R_SPARC_GOT13
:
3245 case elfcpp::R_SPARC_GOT22
:
3248 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3249 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3253 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3254 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3255 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3265 case elfcpp::R_SPARC_NONE
:
3266 case elfcpp::R_SPARC_REGISTER
:
3267 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3268 case elfcpp::R_SPARC_GNU_VTENTRY
:
3271 case elfcpp::R_SPARC_8
:
3272 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3276 case elfcpp::R_SPARC_16
:
3277 if (rela
.get_r_offset() & 0x1)
3279 // The assembler can sometimes emit unaligned relocations
3280 // for dwarf2 cfi directives.
3281 Reloc::ua16(view
, object
, psymval
, addend
);
3284 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3288 case elfcpp::R_SPARC_32
:
3289 if (!parameters
->options().output_is_position_independent())
3291 if (rela
.get_r_offset() & 0x3)
3293 // The assembler can sometimes emit unaligned relocations
3294 // for dwarf2 cfi directives.
3295 Reloc::ua32(view
, object
, psymval
, addend
);
3298 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3303 case elfcpp::R_SPARC_DISP8
:
3304 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3307 case elfcpp::R_SPARC_DISP16
:
3308 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3311 case elfcpp::R_SPARC_DISP32
:
3312 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3315 case elfcpp::R_SPARC_DISP64
:
3316 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3319 case elfcpp::R_SPARC_WDISP30
:
3320 case elfcpp::R_SPARC_WPLT30
:
3321 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3322 if (target
->may_relax())
3323 relax_call(target
, view
, rela
, view_size
);
3326 case elfcpp::R_SPARC_WDISP22
:
3327 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3330 case elfcpp::R_SPARC_WDISP19
:
3331 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3334 case elfcpp::R_SPARC_WDISP16
:
3335 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3338 case elfcpp::R_SPARC_WDISP10
:
3339 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3342 case elfcpp::R_SPARC_HI22
:
3343 Reloc::hi22(view
, object
, psymval
, addend
);
3346 case elfcpp::R_SPARC_22
:
3347 Reloc::rela32_22(view
, object
, psymval
, addend
);
3350 case elfcpp::R_SPARC_13
:
3351 Reloc::rela32_13(view
, object
, psymval
, addend
);
3354 case elfcpp::R_SPARC_LO10
:
3355 Reloc::lo10(view
, object
, psymval
, addend
);
3358 case elfcpp::R_SPARC_GOT10
:
3359 Reloc::lo10(view
, got_offset
, addend
);
3362 case elfcpp::R_SPARC_GOTDATA_OP
:
3365 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3366 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3369 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3370 val
= elfcpp::Swap
<32, true>::readval(wv
);
3371 val
= 0x80000000 | (val
& 0x3e07c01f);
3372 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3376 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3379 Reloc::gdop_lox10(view
, got_offset
, addend
);
3383 case elfcpp::R_SPARC_GOT13
:
3384 Reloc::rela32_13(view
, got_offset
, addend
);
3387 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3390 Reloc::gdop_hix22(view
, got_offset
, addend
);
3394 case elfcpp::R_SPARC_GOT22
:
3395 Reloc::hi22(view
, got_offset
, addend
);
3398 case elfcpp::R_SPARC_PC10
:
3399 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3402 case elfcpp::R_SPARC_PC22
:
3403 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3406 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3407 case elfcpp::R_SPARC_UA32
:
3408 Reloc::ua32(view
, object
, psymval
, addend
);
3411 case elfcpp::R_SPARC_PLT64
:
3412 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3416 case elfcpp::R_SPARC_PLT32
:
3417 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3421 case elfcpp::R_SPARC_HIPLT22
:
3422 Reloc::hi22(view
, object
, psymval
, addend
);
3425 case elfcpp::R_SPARC_LOPLT10
:
3426 Reloc::lo10(view
, object
, psymval
, addend
);
3429 case elfcpp::R_SPARC_PCPLT32
:
3430 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3433 case elfcpp::R_SPARC_PCPLT22
:
3434 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3437 case elfcpp::R_SPARC_PCPLT10
:
3438 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3441 case elfcpp::R_SPARC_64
:
3442 if (!parameters
->options().output_is_position_independent())
3444 if (rela
.get_r_offset() & 0x7)
3446 // The assembler can sometimes emit unaligned relocations
3447 // for dwarf2 cfi directives.
3448 Reloc::ua64(view
, object
, psymval
, addend
);
3451 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3456 case elfcpp::R_SPARC_OLO10
:
3458 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3459 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3460 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3464 case elfcpp::R_SPARC_HH22
:
3465 Reloc::hh22(view
, object
, psymval
, addend
);
3468 case elfcpp::R_SPARC_PC_HH22
:
3469 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3472 case elfcpp::R_SPARC_HM10
:
3473 Reloc::hm10(view
, object
, psymval
, addend
);
3476 case elfcpp::R_SPARC_PC_HM10
:
3477 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3480 case elfcpp::R_SPARC_LM22
:
3481 Reloc::hi22(view
, object
, psymval
, addend
);
3484 case elfcpp::R_SPARC_PC_LM22
:
3485 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3488 case elfcpp::R_SPARC_11
:
3489 Reloc::rela32_11(view
, object
, psymval
, addend
);
3492 case elfcpp::R_SPARC_10
:
3493 Reloc::rela32_10(view
, object
, psymval
, addend
);
3496 case elfcpp::R_SPARC_7
:
3497 Reloc::rela32_7(view
, object
, psymval
, addend
);
3500 case elfcpp::R_SPARC_6
:
3501 Reloc::rela32_6(view
, object
, psymval
, addend
);
3504 case elfcpp::R_SPARC_5
:
3505 Reloc::rela32_5(view
, object
, psymval
, addend
);
3508 case elfcpp::R_SPARC_HIX22
:
3509 Reloc::hix22(view
, object
, psymval
, addend
);
3512 case elfcpp::R_SPARC_LOX10
:
3513 Reloc::lox10(view
, object
, psymval
, addend
);
3516 case elfcpp::R_SPARC_H34
:
3517 Reloc::h34(view
, object
, psymval
, addend
);
3520 case elfcpp::R_SPARC_H44
:
3521 Reloc::h44(view
, object
, psymval
, addend
);
3524 case elfcpp::R_SPARC_M44
:
3525 Reloc::m44(view
, object
, psymval
, addend
);
3528 case elfcpp::R_SPARC_L44
:
3529 Reloc::l44(view
, object
, psymval
, addend
);
3532 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3533 case elfcpp::R_SPARC_UA64
:
3534 Reloc::ua64(view
, object
, psymval
, addend
);
3537 case elfcpp::R_SPARC_UA16
:
3538 Reloc::ua16(view
, object
, psymval
, addend
);
3541 case elfcpp::R_SPARC_TLS_GD_HI22
:
3542 case elfcpp::R_SPARC_TLS_GD_LO10
:
3543 case elfcpp::R_SPARC_TLS_GD_ADD
:
3544 case elfcpp::R_SPARC_TLS_GD_CALL
:
3545 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3546 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3547 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3548 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3549 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3550 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3551 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3552 case elfcpp::R_SPARC_TLS_IE_HI22
:
3553 case elfcpp::R_SPARC_TLS_IE_LO10
:
3554 case elfcpp::R_SPARC_TLS_IE_LD
:
3555 case elfcpp::R_SPARC_TLS_IE_LDX
:
3556 case elfcpp::R_SPARC_TLS_IE_ADD
:
3557 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3558 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3559 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3560 r_type
, gsym
, psymval
, view
,
3561 address
, view_size
);
3564 case elfcpp::R_SPARC_COPY
:
3565 case elfcpp::R_SPARC_GLOB_DAT
:
3566 case elfcpp::R_SPARC_JMP_SLOT
:
3567 case elfcpp::R_SPARC_JMP_IREL
:
3568 case elfcpp::R_SPARC_RELATIVE
:
3569 case elfcpp::R_SPARC_IRELATIVE
:
3570 // These are outstanding tls relocs, which are unexpected when
3572 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3573 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3574 case elfcpp::R_SPARC_TLS_TPOFF64
:
3575 case elfcpp::R_SPARC_TLS_TPOFF32
:
3576 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3577 _("unexpected reloc %u in object file"),
3582 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3583 _("unsupported reloc %u"),
3591 // Perform a TLS relocation.
3593 template<int size
, bool big_endian
>
3595 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3596 const Relocate_info
<size
, big_endian
>* relinfo
,
3597 Target_sparc
<size
, big_endian
>* target
,
3599 const elfcpp::Rela
<size
, big_endian
>& rela
,
3600 unsigned int r_type
,
3601 const Sized_symbol
<size
>* gsym
,
3602 const Symbol_value
<size
>* psymval
,
3603 unsigned char* view
,
3604 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3607 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3608 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3609 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3610 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3612 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3613 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3615 const bool is_final
=
3617 ? !parameters
->options().output_is_position_independent()
3618 : gsym
->final_value_is_known());
3619 const tls::Tls_optimization optimized_type
3620 = optimize_tls_reloc(is_final
, r_type
);
3624 case elfcpp::R_SPARC_TLS_GD_HI22
:
3625 case elfcpp::R_SPARC_TLS_GD_LO10
:
3626 case elfcpp::R_SPARC_TLS_GD_ADD
:
3627 case elfcpp::R_SPARC_TLS_GD_CALL
:
3628 if (optimized_type
== tls::TLSOPT_TO_LE
)
3630 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3633 value
-= tls_segment
->memsz();
3637 case elfcpp::R_SPARC_TLS_GD_HI22
:
3638 // TLS_GD_HI22 --> TLS_LE_HIX22
3639 Reloc::hix22(view
, value
, addend
);
3642 case elfcpp::R_SPARC_TLS_GD_LO10
:
3643 // TLS_GD_LO10 --> TLS_LE_LOX10
3644 Reloc::lox10(view
, value
, addend
);
3647 case elfcpp::R_SPARC_TLS_GD_ADD
:
3648 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3649 val
= elfcpp::Swap
<32, true>::readval(wv
);
3650 val
= (val
& ~0x7c000) | 0x1c000;
3651 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3653 case elfcpp::R_SPARC_TLS_GD_CALL
:
3654 // call __tls_get_addr --> nop
3655 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3662 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3663 ? GOT_TYPE_TLS_OFFSET
3664 : GOT_TYPE_TLS_PAIR
);
3667 gold_assert(gsym
->has_got_offset(got_type
));
3668 value
= gsym
->got_offset(got_type
);
3672 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3673 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3674 value
= object
->local_got_offset(r_sym
, got_type
);
3676 if (optimized_type
== tls::TLSOPT_TO_IE
)
3678 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3683 case elfcpp::R_SPARC_TLS_GD_HI22
:
3684 // TLS_GD_HI22 --> TLS_IE_HI22
3685 Reloc::hi22(view
, value
, addend
);
3688 case elfcpp::R_SPARC_TLS_GD_LO10
:
3689 // TLS_GD_LO10 --> TLS_IE_LO10
3690 Reloc::lo10(view
, value
, addend
);
3693 case elfcpp::R_SPARC_TLS_GD_ADD
:
3694 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3695 val
= elfcpp::Swap
<32, true>::readval(wv
);
3702 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3705 case elfcpp::R_SPARC_TLS_GD_CALL
:
3706 // The compiler can put the TLS_GD_ADD instruction
3707 // into the delay slot of the call. If so, we need
3708 // to transpose the two instructions so that the
3709 // new sequence works properly.
3711 // The test we use is if the instruction in the
3712 // delay slot is an add with destination register
3714 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3715 if ((val
& 0x81f80000) == 0x80000000
3716 && ((val
>> 25) & 0x1f) == 0x8)
3723 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3726 this->ignore_gd_add_
= true;
3730 // Even if the delay slot isn't the TLS_GD_ADD
3731 // instruction, we still have to handle the case
3732 // where it sets up %o0 in some other way.
3733 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3735 this->reloc_adjust_addr_
= view
+ 4;
3737 // call __tls_get_addr --> add %g7, %o0, %o0
3738 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3743 else if (optimized_type
== tls::TLSOPT_NONE
)
3747 case elfcpp::R_SPARC_TLS_GD_HI22
:
3748 Reloc::hi22(view
, value
, addend
);
3750 case elfcpp::R_SPARC_TLS_GD_LO10
:
3751 Reloc::lo10(view
, value
, addend
);
3753 case elfcpp::R_SPARC_TLS_GD_ADD
:
3755 case elfcpp::R_SPARC_TLS_GD_CALL
:
3757 Symbol_value
<size
> symval
;
3758 elfcpp::Elf_Xword value
;
3761 tsym
= target
->tls_get_addr_sym_
;
3763 value
= (target
->plt_section()->address() +
3764 tsym
->plt_offset());
3765 symval
.set_output_value(value
);
3766 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3773 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3774 _("unsupported reloc %u"),
3778 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3779 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3780 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3781 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3782 if (optimized_type
== tls::TLSOPT_TO_LE
)
3784 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3788 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3789 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3790 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3791 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3794 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3795 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3800 else if (optimized_type
== tls::TLSOPT_NONE
)
3802 // Relocate the field with the offset of the GOT entry for
3803 // the module index.
3804 unsigned int got_offset
;
3806 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3809 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3810 Reloc::hi22(view
, got_offset
, addend
);
3812 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3813 Reloc::lo10(view
, got_offset
, addend
);
3815 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3817 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3819 Symbol_value
<size
> symval
;
3820 elfcpp::Elf_Xword value
;
3823 tsym
= target
->tls_get_addr_sym_
;
3825 value
= (target
->plt_section()->address() +
3826 tsym
->plt_offset());
3827 symval
.set_output_value(value
);
3828 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3834 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3835 _("unsupported reloc %u"),
3839 // These relocs can appear in debugging sections, in which case
3840 // we won't see the TLS_LDM relocs. The local_dynamic_type
3841 // field tells us this.
3842 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3843 if (optimized_type
== tls::TLSOPT_TO_LE
)
3845 value
-= tls_segment
->memsz();
3846 Reloc::hix22(view
, value
, addend
);
3849 Reloc::ldo_hix22(view
, value
, addend
);
3851 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3852 if (optimized_type
== tls::TLSOPT_TO_LE
)
3854 value
-= tls_segment
->memsz();
3855 Reloc::lox10(view
, value
, addend
);
3858 Reloc::ldo_lox10(view
, value
, addend
);
3860 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3861 if (optimized_type
== tls::TLSOPT_TO_LE
)
3863 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3866 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3867 val
= elfcpp::Swap
<32, true>::readval(wv
);
3868 val
= (val
& ~0x7c000) | 0x1c000;
3869 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3873 // When optimizing IE --> LE, the only relocation that is handled
3874 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3875 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3876 // rs2 and rd are the same.
3877 case elfcpp::R_SPARC_TLS_IE_LD
:
3878 case elfcpp::R_SPARC_TLS_IE_LDX
:
3879 if (optimized_type
== tls::TLSOPT_TO_LE
)
3881 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3882 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3883 Insntype rs2
= val
& 0x1f;
3884 Insntype rd
= (val
>> 25) & 0x1f;
3889 val
= sparc_mov
| (val
& 0x3e00001f);
3891 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3895 case elfcpp::R_SPARC_TLS_IE_HI22
:
3896 case elfcpp::R_SPARC_TLS_IE_LO10
:
3897 if (optimized_type
== tls::TLSOPT_TO_LE
)
3899 value
-= tls_segment
->memsz();
3902 case elfcpp::R_SPARC_TLS_IE_HI22
:
3903 // IE_HI22 --> LE_HIX22
3904 Reloc::hix22(view
, value
, addend
);
3906 case elfcpp::R_SPARC_TLS_IE_LO10
:
3907 // IE_LO10 --> LE_LOX10
3908 Reloc::lox10(view
, value
, addend
);
3913 else if (optimized_type
== tls::TLSOPT_NONE
)
3915 // Relocate the field with the offset of the GOT entry for
3916 // the tp-relative offset of the symbol.
3919 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3920 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3924 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3925 gold_assert(object
->local_has_got_offset(r_sym
,
3926 GOT_TYPE_TLS_OFFSET
));
3927 value
= object
->local_got_offset(r_sym
,
3928 GOT_TYPE_TLS_OFFSET
);
3932 case elfcpp::R_SPARC_TLS_IE_HI22
:
3933 Reloc::hi22(view
, value
, addend
);
3935 case elfcpp::R_SPARC_TLS_IE_LO10
:
3936 Reloc::lo10(view
, value
, addend
);
3941 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3942 _("unsupported reloc %u"),
3946 case elfcpp::R_SPARC_TLS_IE_ADD
:
3947 // This seems to be mainly so that we can find the addition
3948 // instruction if there is one. There doesn't seem to be any
3949 // actual relocation to apply.
3952 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3953 // If we're creating a shared library, a dynamic relocation will
3954 // have been created for this location, so do not apply it now.
3955 if (!parameters
->options().shared())
3957 value
-= tls_segment
->memsz();
3958 Reloc::hix22(view
, value
, addend
);
3962 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3963 // If we're creating a shared library, a dynamic relocation will
3964 // have been created for this location, so do not apply it now.
3965 if (!parameters
->options().shared())
3967 value
-= tls_segment
->memsz();
3968 Reloc::lox10(view
, value
, addend
);
3974 // Relax a call instruction.
3976 template<int size
, bool big_endian
>
3978 Target_sparc
<size
, big_endian
>::Relocate::relax_call(
3979 Target_sparc
<size
, big_endian
>* target
,
3980 unsigned char* view
,
3981 const elfcpp::Rela
<size
, big_endian
>& rela
,
3982 section_size_type view_size
)
3984 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3985 Insntype
*wv
= reinterpret_cast<Insntype
*>(view
);
3986 Insntype call_insn
, delay_insn
, set_insn
;
3987 uint32_t op3
, reg
, off
;
3989 // This code tries to relax call instructions that meet
3990 // certain criteria.
3992 // The first criteria is that the call must be such that the return
3993 // address which the call writes into %o7 is unused. Two sequences
3994 // meet this criteria, and are used to implement tail calls.
3996 // Leaf function tail call:
3998 // or %o7, %g0, %ANY_REG
4000 // or %ANY_REG, %g0, %o7
4002 // Non-leaf function tail call:
4007 // The second criteria is that the call destination is close. If
4008 // the displacement can fit in a signed 22-bit immediate field of a
4009 // pre-V9 branch, we can do it. If we are generating a 64-bit
4010 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4011 // and the displacement fits in a signed 19-bit immediate field,
4012 // then we can use a V9 branch.
4014 // Make sure the delay instruction can be safely accessed.
4015 if (rela
.get_r_offset() + 8 > view_size
)
4018 call_insn
= elfcpp::Swap
<32, true>::readval(wv
);
4019 delay_insn
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
4021 // Make sure it is really a call instruction.
4022 if (((call_insn
>> 30) & 0x3) != 1)
4025 if (((delay_insn
>> 30) & 0x3) != 2)
4028 // Accept only a restore or an integer arithmetic operation whose
4029 // sole side effect is to write the %o7 register (and perhaps set
4030 // the condition codes, which are considered clobbered across
4033 // For example, we don't want to match a tagged addition or
4034 // subtraction. We also don't want to match something like a
4037 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4038 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4040 op3
= (delay_insn
>> 19) & 0x3f;
4041 reg
= (delay_insn
>> 25) & 0x1f;
4043 && ((op3
& 0x28) != 0 || reg
!= 15))
4046 // For non-restore instructions, make sure %o7 isn't
4051 reg
= (delay_insn
>> 14) & 0x15;
4055 // And if non-immediate, check RS2
4056 if (((delay_insn
>> 13) & 1) == 0)
4058 reg
= (delay_insn
& 0x1f);
4064 // Now check the branch distance. We are called after the
4065 // call has been relocated, so we just have to peek at the
4066 // offset contained in the instruction.
4067 off
= call_insn
& 0x3fffffff;
4068 if ((off
& 0x3fe00000) != 0
4069 && (off
& 0x3fe00000) != 0x3fe00000)
4072 if ((size
== 64 || target
->elf_machine_
== elfcpp::EM_SPARC32PLUS
)
4073 && ((off
& 0x3c0000) == 0
4074 || (off
& 0x3c0000) == 0x3c0000))
4077 call_insn
= 0x10680000 | (off
& 0x07ffff);
4082 call_insn
= 0x10800000 | (off
& 0x3fffff);
4084 elfcpp::Swap
<32, true>::writeval(wv
, call_insn
);
4086 // See if we can NOP out the delay slot instruction. We peek
4087 // at the instruction before the call to make sure we're dealing
4088 // with exactly the:
4090 // or %o7, %g0, %ANY_REG
4092 // or %ANY_REG, %g0, %o7
4094 // case. Otherwise this might be a tricky piece of hand written
4095 // assembler calculating %o7 in some non-trivial way, and therefore
4096 // we can't be sure that NOP'ing out the delay slot is safe.
4098 && rela
.get_r_offset() >= 4)
4100 if ((delay_insn
& ~(0x1f << 14)) != 0x9e100000)
4103 set_insn
= elfcpp::Swap
<32, true>::readval(wv
- 1);
4104 if ((set_insn
& ~(0x1f << 25)) != 0x8013c000)
4107 reg
= (set_insn
>> 25) & 0x1f;
4108 if (reg
== 0 || reg
== 15)
4110 if (reg
!= ((delay_insn
>> 14) & 0x1f))
4113 // All tests pass, nop it out.
4114 elfcpp::Swap
<32, true>::writeval(wv
+ 1, sparc_nop
);
4118 // Relocate section data.
4120 template<int size
, bool big_endian
>
4122 Target_sparc
<size
, big_endian
>::relocate_section(
4123 const Relocate_info
<size
, big_endian
>* relinfo
,
4124 unsigned int sh_type
,
4125 const unsigned char* prelocs
,
4127 Output_section
* output_section
,
4128 bool needs_special_offset_handling
,
4129 unsigned char* view
,
4130 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4131 section_size_type view_size
,
4132 const Reloc_symbol_changes
* reloc_symbol_changes
)
4134 typedef Target_sparc
<size
, big_endian
> Sparc
;
4135 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
4137 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4139 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
4146 needs_special_offset_handling
,
4150 reloc_symbol_changes
);
4153 // Return the size of a relocation while scanning during a relocatable
4156 template<int size
, bool big_endian
>
4158 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4162 // We are always SHT_RELA, so we should never get here.
4167 // Scan the relocs during a relocatable link.
4169 template<int size
, bool big_endian
>
4171 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4172 Symbol_table
* symtab
,
4174 Sized_relobj_file
<size
, big_endian
>* object
,
4175 unsigned int data_shndx
,
4176 unsigned int sh_type
,
4177 const unsigned char* prelocs
,
4179 Output_section
* output_section
,
4180 bool needs_special_offset_handling
,
4181 size_t local_symbol_count
,
4182 const unsigned char* plocal_symbols
,
4183 Relocatable_relocs
* rr
)
4185 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4187 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4188 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4190 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4191 Scan_relocatable_relocs
>(
4199 needs_special_offset_handling
,
4205 // Emit relocations for a section.
4207 template<int size
, bool big_endian
>
4209 Target_sparc
<size
, big_endian
>::relocate_relocs(
4210 const Relocate_info
<size
, big_endian
>* relinfo
,
4211 unsigned int sh_type
,
4212 const unsigned char* prelocs
,
4214 Output_section
* output_section
,
4215 off_t offset_in_output_section
,
4216 const Relocatable_relocs
* rr
,
4217 unsigned char* view
,
4218 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4219 section_size_type view_size
,
4220 unsigned char* reloc_view
,
4221 section_size_type reloc_view_size
)
4223 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4225 gold::relocate_relocs
<size
, big_endian
, elfcpp::SHT_RELA
>(
4230 offset_in_output_section
,
4239 // Return the value to use for a dynamic which requires special
4240 // treatment. This is how we support equality comparisons of function
4241 // pointers across shared library boundaries, as described in the
4242 // processor specific ABI supplement.
4244 template<int size
, bool big_endian
>
4246 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4248 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4249 return this->plt_section()->address() + gsym
->plt_offset();
4252 // do_make_elf_object to override the same function in the base class.
4253 // We need to use a target-specific sub-class of
4254 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4255 // of the ELF headers. Hence we need to have our own ELF object creation.
4257 template<int size
, bool big_endian
>
4259 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4260 const std::string
& name
,
4261 Input_file
* input_file
,
4262 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4264 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4265 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4266 elfcpp::Elf_Word omm
, mm
;
4270 case elfcpp::EM_SPARC32PLUS
:
4271 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4274 case elfcpp::EM_SPARC
:
4275 case elfcpp::EM_SPARCV9
:
4282 if (!this->elf_flags_set_
)
4284 this->elf_flags_
= flags
;
4285 this->elf_flags_set_
= true;
4289 // Accumulate cpu feature bits.
4290 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4291 | elfcpp::EF_SPARC_SUN_US1
4292 | elfcpp::EF_SPARC_HAL_R1
4293 | elfcpp::EF_SPARC_SUN_US3
));
4295 // Bump the memory model setting to the most restrictive
4296 // one we encounter.
4297 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4298 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4301 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4303 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4304 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4306 else if (mm
== elfcpp::EF_SPARCV9_PSO
4307 && omm
== elfcpp::EF_SPARCV9_RMO
)
4309 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4310 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4315 // Validate that the little-endian flag matches how we've
4316 // been instantiated.
4317 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4320 gold_error(_("%s: little endian elf flag set on BE object"),
4323 gold_error(_("%s: little endian elf flag clear on LE object"),
4327 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4330 // Adjust ELF file header.
4332 template<int size
, bool big_endian
>
4334 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4335 unsigned char* view
,
4338 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4340 oehdr
.put_e_machine(this->elf_machine_
);
4341 oehdr
.put_e_flags(this->elf_flags_
);
4343 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4346 // The selector for sparc object files.
4348 template<int size
, bool big_endian
>
4349 class Target_selector_sparc
: public Target_selector
4352 Target_selector_sparc()
4353 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4354 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4355 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4359 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4364 if (machine
!= elfcpp::EM_SPARCV9
)
4369 if (machine
!= elfcpp::EM_SPARC
4370 && machine
!= elfcpp::EM_SPARC32PLUS
)
4378 return this->instantiate_target();
4382 do_instantiate_target()
4383 { return new Target_sparc
<size
, big_endian
>(); }
4386 Target_selector_sparc
<32, true> target_selector_sparc32
;
4387 Target_selector_sparc
<64, true> target_selector_sparc64
;
4389 } // End anonymous namespace.