1 // sparc.cc -- sparc target support for gold.
3 // Copyright (C) 2008-2016 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
),
64 elf_machine_(sparc_info
.machine_code
), elf_flags_(0),
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 // Scan the relocs for --emit-relocs.
136 emit_relocs_scan(Symbol_table
* symtab
,
138 Sized_relobj_file
<size
, big_endian
>* object
,
139 unsigned int data_shndx
,
140 unsigned int sh_type
,
141 const unsigned char* prelocs
,
143 Output_section
* output_section
,
144 bool needs_special_offset_handling
,
145 size_t local_symbol_count
,
146 const unsigned char* plocal_syms
,
147 Relocatable_relocs
* rr
);
149 // Emit relocations for a section.
151 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
152 unsigned int sh_type
,
153 const unsigned char* prelocs
,
155 Output_section
* output_section
,
156 typename
elfcpp::Elf_types
<size
>::Elf_Off
157 offset_in_output_section
,
159 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
160 section_size_type view_size
,
161 unsigned char* reloc_view
,
162 section_size_type reloc_view_size
);
164 // Return whether SYM is defined by the ABI.
166 do_is_defined_by_abi(const Symbol
* sym
) const
168 // XXX Really need to support this better...
169 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
172 return strcmp(sym
->name(), "___tls_get_addr") == 0;
175 // Return the PLT address to use for a global symbol.
177 do_plt_address_for_global(const Symbol
* gsym
) const
178 { return this->plt_section()->address_for_global(gsym
); }
181 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
182 { return this->plt_section()->address_for_local(relobj
, symndx
); }
184 // Return whether there is a GOT section.
186 has_got_section() const
187 { return this->got_
!= NULL
; }
189 // Return the size of the GOT section.
193 gold_assert(this->got_
!= NULL
);
194 return this->got_
->data_size();
197 // Return the number of entries in the GOT.
199 got_entry_count() const
201 if (this->got_
== NULL
)
203 return this->got_size() / (size
/ 8);
206 // Return the address of the GOT.
210 if (this->got_
== NULL
)
212 return this->got_
->address();
215 // Return the number of entries in the PLT.
217 plt_entry_count() const;
219 // Return the offset of the first non-reserved PLT entry.
221 first_plt_entry_offset() const;
223 // Return the size of each PLT entry.
225 plt_entry_size() const;
228 // Make an ELF object.
230 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
231 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
234 do_adjust_elf_header(unsigned char* view
, int len
);
238 // The class which scans relocations.
243 : issued_non_pic_error_(false)
247 get_reference_flags(unsigned int r_type
);
250 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
251 Sized_relobj_file
<size
, big_endian
>* object
,
252 unsigned int data_shndx
,
253 Output_section
* output_section
,
254 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
255 const elfcpp::Sym
<size
, big_endian
>& lsym
,
259 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
260 Sized_relobj_file
<size
, big_endian
>* object
,
261 unsigned int data_shndx
,
262 Output_section
* output_section
,
263 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
267 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
269 Sized_relobj_file
<size
, big_endian
>* ,
272 const elfcpp::Rela
<size
, big_endian
>& ,
274 const elfcpp::Sym
<size
, big_endian
>&)
278 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
280 Sized_relobj_file
<size
, big_endian
>* ,
283 const elfcpp::Rela
<size
,
285 unsigned int , Symbol
*)
291 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
292 unsigned int r_type
);
295 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
296 unsigned int r_type
, Symbol
*);
299 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
300 Target_sparc
* target
);
303 check_non_pic(Relobj
*, unsigned int r_type
);
306 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
307 unsigned int r_type
);
309 // Whether we have issued an error about a non-PIC compilation.
310 bool issued_non_pic_error_
;
313 // The class which implements relocation.
318 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
323 if (this->ignore_gd_add_
)
325 // FIXME: This needs to specify the location somehow.
326 gold_error(_("missing expected TLS relocation"));
330 // Do a relocation. Return false if the caller should not issue
331 // any warnings about this relocation.
333 relocate(const Relocate_info
<size
, big_endian
>*, unsigned int,
334 Target_sparc
*, Output_section
*, size_t, const unsigned char*,
335 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
336 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
340 // Do a TLS relocation.
342 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
343 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
344 unsigned int r_type
, const Sized_symbol
<size
>*,
345 const Symbol_value
<size
>*,
347 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
351 relax_call(Target_sparc
<size
, big_endian
>* target
,
353 const elfcpp::Rela
<size
, big_endian
>& rela
,
354 section_size_type view_size
);
356 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
359 // If we hit a reloc at this view address, adjust it back by 4 bytes.
360 unsigned char *reloc_adjust_addr_
;
363 // Get the GOT section, creating it if necessary.
364 Output_data_got
<size
, big_endian
>*
365 got_section(Symbol_table
*, Layout
*);
367 // Create the PLT section.
369 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
371 // Create a PLT entry for a global symbol.
373 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
375 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
377 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
378 Sized_relobj_file
<size
, big_endian
>* relobj
,
379 unsigned int local_sym_index
);
381 // Create a GOT entry for the TLS module index.
383 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
384 Sized_relobj_file
<size
, big_endian
>* object
);
386 // Return the gsym for "__tls_get_addr". Cache if not already
389 tls_get_addr_sym(Symbol_table
* symtab
)
391 if (!this->tls_get_addr_sym_
)
392 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
393 gold_assert(this->tls_get_addr_sym_
);
394 return this->tls_get_addr_sym_
;
397 // Get the PLT section.
398 Output_data_plt_sparc
<size
, big_endian
>*
401 gold_assert(this->plt_
!= NULL
);
405 // Get the dynamic reloc section, creating it if necessary.
407 rela_dyn_section(Layout
*);
409 // Get the section to use for IFUNC relocations.
411 rela_ifunc_section(Layout
*);
413 // Copy a relocation against a global symbol.
415 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
416 Sized_relobj_file
<size
, big_endian
>* object
,
417 unsigned int shndx
, Output_section
* output_section
,
418 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
420 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
421 this->copy_relocs_
.copy_reloc(symtab
, layout
,
422 symtab
->get_sized_symbol
<size
>(sym
),
423 object
, shndx
, output_section
,
424 r_type
, reloc
.get_r_offset(),
425 reloc
.get_r_addend(),
426 this->rela_dyn_section(layout
));
429 // Information about this specific target which we pass to the
430 // general Target structure.
431 static Target::Target_info sparc_info
;
433 // The types of GOT entries needed for this platform.
434 // These values are exposed to the ABI in an incremental link.
435 // Do not renumber existing values without changing the version
436 // number of the .gnu_incremental_inputs section.
439 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
440 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
441 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
445 Output_data_got
<size
, big_endian
>* got_
;
447 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
448 // The dynamic reloc section.
449 Reloc_section
* rela_dyn_
;
450 // The section to use for IFUNC relocs.
451 Reloc_section
* rela_ifunc_
;
452 // Relocs saved to avoid a COPY reloc.
453 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
454 // Offset of the GOT entry for the TLS module index;
455 unsigned int got_mod_index_offset_
;
456 // Cached pointer to __tls_get_addr symbol
457 Symbol
* tls_get_addr_sym_
;
458 // Accumulated elf machine type
459 elfcpp::Elf_Half elf_machine_
;
460 // Accumulated elf header flags
461 elfcpp::Elf_Word elf_flags_
;
462 // Whether elf_flags_ has been set for the first time yet
467 Target::Target_info Target_sparc
<32, true>::sparc_info
=
470 true, // is_big_endian
471 elfcpp::EM_SPARC
, // machine_code
472 false, // has_make_symbol
473 false, // has_resolve
474 false, // has_code_fill
475 true, // is_default_stack_executable
476 false, // can_icf_inline_merge_sections
478 "/usr/lib/ld.so.1", // dynamic_linker
479 0x00010000, // default_text_segment_address
480 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
481 8 * 1024, // common_pagesize (overridable by -z common-page-size)
482 false, // isolate_execinstr
484 elfcpp::SHN_UNDEF
, // small_common_shndx
485 elfcpp::SHN_UNDEF
, // large_common_shndx
486 0, // small_common_section_flags
487 0, // large_common_section_flags
488 NULL
, // attributes_section
489 NULL
, // attributes_vendor
490 "_start", // entry_symbol_name
491 32, // hash_entry_size
495 Target::Target_info Target_sparc
<64, true>::sparc_info
=
498 true, // is_big_endian
499 elfcpp::EM_SPARCV9
, // machine_code
500 false, // has_make_symbol
501 false, // has_resolve
502 false, // has_code_fill
503 true, // is_default_stack_executable
504 false, // can_icf_inline_merge_sections
506 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
507 0x100000, // default_text_segment_address
508 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
509 8 * 1024, // common_pagesize (overridable by -z common-page-size)
510 false, // isolate_execinstr
512 elfcpp::SHN_UNDEF
, // small_common_shndx
513 elfcpp::SHN_UNDEF
, // large_common_shndx
514 0, // small_common_section_flags
515 0, // large_common_section_flags
516 NULL
, // attributes_section
517 NULL
, // attributes_vendor
518 "_start", // entry_symbol_name
519 32, // hash_entry_size
522 // We have to take care here, even when operating in little-endian
523 // mode, sparc instructions are still big endian.
524 template<int size
, bool big_endian
>
525 class Sparc_relocate_functions
528 // Do a simple relocation with the addend in the relocation.
529 template<int valsize
>
531 rela(unsigned char* view
,
532 unsigned int right_shift
,
533 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
534 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
535 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
537 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
538 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
539 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
540 Valtype reloc
= ((value
+ addend
) >> right_shift
);
545 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
548 // Do a simple relocation using a symbol value with the addend in
550 template<int valsize
>
552 rela(unsigned char* view
,
553 unsigned int right_shift
,
554 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
555 const Sized_relobj_file
<size
, big_endian
>* object
,
556 const Symbol_value
<size
>* psymval
,
557 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
559 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
560 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
561 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
562 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
567 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
570 // Do a simple relocation using a symbol value with the addend in
571 // the relocation, unaligned.
572 template<int valsize
>
574 rela_ua(unsigned char* view
,
575 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
576 const Sized_relobj_file
<size
, big_endian
>* object
,
577 const Symbol_value
<size
>* psymval
,
578 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
580 typedef typename
elfcpp::Swap_unaligned
<valsize
,
581 big_endian
>::Valtype Valtype
;
582 unsigned char* wv
= view
;
583 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
584 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
589 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
592 // Do a simple PC relative relocation with a Symbol_value with the
593 // addend in the relocation.
594 template<int valsize
>
596 pcrela(unsigned char* view
,
597 unsigned int right_shift
,
598 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
599 const Sized_relobj_file
<size
, big_endian
>* object
,
600 const Symbol_value
<size
>* psymval
,
601 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
602 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
604 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
605 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
606 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
607 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
613 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
616 template<int valsize
>
618 pcrela_unaligned(unsigned char* view
,
619 const Sized_relobj_file
<size
, big_endian
>* object
,
620 const Symbol_value
<size
>* psymval
,
621 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
622 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
624 typedef typename
elfcpp::Swap_unaligned
<valsize
,
625 big_endian
>::Valtype Valtype
;
626 unsigned char* wv
= view
;
627 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
629 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
632 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
633 typedef Sparc_relocate_functions
<size
, true> This_insn
;
636 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
638 wdisp30(unsigned char* view
,
639 const Sized_relobj_file
<size
, big_endian
>* object
,
640 const Symbol_value
<size
>* psymval
,
641 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
642 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
644 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
645 psymval
, addend
, address
);
648 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
650 wdisp22(unsigned char* view
,
651 const Sized_relobj_file
<size
, big_endian
>* object
,
652 const Symbol_value
<size
>* psymval
,
653 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
654 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
656 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
657 psymval
, addend
, address
);
660 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
662 wdisp19(unsigned char* view
,
663 const Sized_relobj_file
<size
, big_endian
>* object
,
664 const Symbol_value
<size
>* psymval
,
665 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
666 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
668 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
669 psymval
, addend
, address
);
672 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
674 wdisp16(unsigned char* view
,
675 const Sized_relobj_file
<size
, big_endian
>* object
,
676 const Symbol_value
<size
>* psymval
,
677 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
678 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
680 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
681 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
682 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
683 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
686 // The relocation value is split between the low 14 bits,
688 val
&= ~((0x3 << 20) | 0x3fff);
689 reloc
= (((reloc
& 0xc000) << (20 - 14))
690 | (reloc
& 0x3ffff));
692 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
695 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
697 wdisp10(unsigned char* view
,
698 const Sized_relobj_file
<size
, big_endian
>* object
,
699 const Symbol_value
<size
>* psymval
,
700 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
701 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
703 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
704 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
705 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
706 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
709 // The relocation value is split between the low bits 5-12,
710 // and high bits 19-20.
711 val
&= ~((0x3 << 19) | (0xff << 5));
712 reloc
= (((reloc
& 0x300) << (19 - 8))
713 | ((reloc
& 0xff) << (5 - 0)));
715 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
718 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
720 pc22(unsigned char* view
,
721 const Sized_relobj_file
<size
, big_endian
>* object
,
722 const Symbol_value
<size
>* psymval
,
723 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
724 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
726 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
727 psymval
, addend
, address
);
730 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
732 pc10(unsigned char* view
,
733 const Sized_relobj_file
<size
, big_endian
>* object
,
734 const Symbol_value
<size
>* psymval
,
735 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
736 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
738 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
739 psymval
, addend
, address
);
742 // R_SPARC_HI22: (Symbol + Addend) >> 10
744 hi22(unsigned char* view
,
745 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
748 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
751 // R_SPARC_HI22: (Symbol + Addend) >> 10
753 hi22(unsigned char* view
,
754 const Sized_relobj_file
<size
, big_endian
>* object
,
755 const Symbol_value
<size
>* psymval
,
756 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
758 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
761 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
763 pcplt22(unsigned char* view
,
764 const Sized_relobj_file
<size
, big_endian
>* object
,
765 const Symbol_value
<size
>* psymval
,
766 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
767 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
769 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
770 psymval
, addend
, address
);
773 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
775 lo10(unsigned char* view
,
776 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
777 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
779 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
782 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
784 lo10(unsigned char* view
,
785 const Sized_relobj_file
<size
, big_endian
>* object
,
786 const Symbol_value
<size
>* psymval
,
787 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
789 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
792 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
794 lo10(unsigned char* view
,
795 const Sized_relobj_file
<size
, big_endian
>* object
,
796 const Symbol_value
<size
>* psymval
,
797 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
798 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
800 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
801 psymval
, addend
, address
);
804 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
806 olo10(unsigned char* view
,
807 const Sized_relobj_file
<size
, big_endian
>* object
,
808 const Symbol_value
<size
>* psymval
,
809 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
810 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
812 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
813 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
814 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
815 Valtype reloc
= psymval
->value(object
, addend
);
822 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
825 // R_SPARC_22: (Symbol + Addend)
827 rela32_22(unsigned char* view
,
828 const Sized_relobj_file
<size
, big_endian
>* object
,
829 const Symbol_value
<size
>* psymval
,
830 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
832 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
835 // R_SPARC_13: (Symbol + Addend)
837 rela32_13(unsigned char* view
,
838 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
841 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
844 // R_SPARC_13: (Symbol + Addend)
846 rela32_13(unsigned char* view
,
847 const Sized_relobj_file
<size
, big_endian
>* object
,
848 const Symbol_value
<size
>* psymval
,
849 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
851 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
854 // R_SPARC_UA16: (Symbol + Addend)
856 ua16(unsigned char* view
,
857 const Sized_relobj_file
<size
, big_endian
>* object
,
858 const Symbol_value
<size
>* psymval
,
859 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
861 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
864 // R_SPARC_UA32: (Symbol + Addend)
866 ua32(unsigned char* view
,
867 const Sized_relobj_file
<size
, big_endian
>* object
,
868 const Symbol_value
<size
>* psymval
,
869 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
871 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
874 // R_SPARC_UA64: (Symbol + Addend)
876 ua64(unsigned char* view
,
877 const Sized_relobj_file
<size
, big_endian
>* object
,
878 const Symbol_value
<size
>* psymval
,
879 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
881 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
882 object
, psymval
, addend
);
885 // R_SPARC_DISP8: (Symbol + Addend - Address)
887 disp8(unsigned char* view
,
888 const Sized_relobj_file
<size
, big_endian
>* object
,
889 const Symbol_value
<size
>* psymval
,
890 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
891 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
893 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
897 // R_SPARC_DISP16: (Symbol + Addend - Address)
899 disp16(unsigned char* view
,
900 const Sized_relobj_file
<size
, big_endian
>* object
,
901 const Symbol_value
<size
>* psymval
,
902 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
905 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
909 // R_SPARC_DISP32: (Symbol + Addend - Address)
911 disp32(unsigned char* view
,
912 const Sized_relobj_file
<size
, big_endian
>* object
,
913 const Symbol_value
<size
>* psymval
,
914 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
915 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
917 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
921 // R_SPARC_DISP64: (Symbol + Addend - Address)
923 disp64(unsigned char* view
,
924 const Sized_relobj_file
<size
, big_endian
>* object
,
925 const Symbol_value
<size
>* psymval
,
926 elfcpp::Elf_Xword addend
,
927 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
929 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
933 // R_SPARC_H34: (Symbol + Addend) >> 12
935 h34(unsigned char* view
,
936 const Sized_relobj_file
<size
, big_endian
>* object
,
937 const Symbol_value
<size
>* psymval
,
938 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
940 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
943 // R_SPARC_H44: (Symbol + Addend) >> 22
945 h44(unsigned char* view
,
946 const Sized_relobj_file
<size
, big_endian
>* object
,
947 const Symbol_value
<size
>* psymval
,
948 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
950 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
953 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
955 m44(unsigned char* view
,
956 const Sized_relobj_file
<size
, big_endian
>* object
,
957 const Symbol_value
<size
>* psymval
,
958 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
960 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
963 // R_SPARC_L44: (Symbol + Addend) & 0xfff
965 l44(unsigned char* view
,
966 const Sized_relobj_file
<size
, big_endian
>* object
,
967 const Symbol_value
<size
>* psymval
,
968 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
970 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
973 // R_SPARC_HH22: (Symbol + Addend) >> 42
975 hh22(unsigned char* view
,
976 const Sized_relobj_file
<size
, big_endian
>* object
,
977 const Symbol_value
<size
>* psymval
,
978 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
980 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
983 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
985 pc_hh22(unsigned char* view
,
986 const Sized_relobj_file
<size
, big_endian
>* object
,
987 const Symbol_value
<size
>* psymval
,
988 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
989 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
991 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
992 psymval
, addend
, address
);
995 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
997 hm10(unsigned char* view
,
998 const Sized_relobj_file
<size
, big_endian
>* object
,
999 const Symbol_value
<size
>* psymval
,
1000 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1002 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
1005 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
1007 pc_hm10(unsigned char* view
,
1008 const Sized_relobj_file
<size
, big_endian
>* object
,
1009 const Symbol_value
<size
>* psymval
,
1010 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
1011 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
1013 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
1014 psymval
, addend
, address
);
1017 // R_SPARC_11: (Symbol + Addend)
1019 rela32_11(unsigned char* view
,
1020 const Sized_relobj_file
<size
, big_endian
>* object
,
1021 const Symbol_value
<size
>* psymval
,
1022 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1024 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1027 // R_SPARC_10: (Symbol + Addend)
1029 rela32_10(unsigned char* view
,
1030 const Sized_relobj_file
<size
, big_endian
>* object
,
1031 const Symbol_value
<size
>* psymval
,
1032 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1034 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
1037 // R_SPARC_7: (Symbol + Addend)
1039 rela32_7(unsigned char* view
,
1040 const Sized_relobj_file
<size
, big_endian
>* object
,
1041 const Symbol_value
<size
>* psymval
,
1042 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1044 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1047 // R_SPARC_6: (Symbol + Addend)
1049 rela32_6(unsigned char* view
,
1050 const Sized_relobj_file
<size
, big_endian
>* object
,
1051 const Symbol_value
<size
>* psymval
,
1052 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1054 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1057 // R_SPARC_5: (Symbol + Addend)
1059 rela32_5(unsigned char* view
,
1060 const Sized_relobj_file
<size
, big_endian
>* object
,
1061 const Symbol_value
<size
>* psymval
,
1062 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1064 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1067 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1069 ldo_hix22(unsigned char* view
,
1070 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1071 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1073 This_insn::hi22(view
, value
, addend
);
1076 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1078 ldo_lox10(unsigned char* view
,
1079 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1080 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1082 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1083 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1084 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1085 Valtype reloc
= (value
+ addend
);
1090 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1093 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1095 hix22(unsigned char* view
,
1096 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1097 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1099 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1100 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1101 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1102 Valtype reloc
= (value
+ addend
);
1106 reloc
^= ~(Valtype
)0;
1111 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1114 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1116 gdop_hix22(unsigned char* view
,
1117 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
)
1119 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1120 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1121 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1122 int32_t reloc
= static_cast<int32_t>(value
);
1127 reloc
^= ~static_cast<int32_t>(0);
1132 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1135 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1137 hix22(unsigned char* view
,
1138 const Sized_relobj_file
<size
, big_endian
>* object
,
1139 const Symbol_value
<size
>* psymval
,
1140 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1142 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1143 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1144 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1145 Valtype reloc
= psymval
->value(object
, addend
);
1149 reloc
^= ~(Valtype
)0;
1154 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1158 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1160 lox10(unsigned char* view
,
1161 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1162 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1164 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1165 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1166 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1167 Valtype reloc
= (value
+ addend
);
1173 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1176 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1178 gdop_lox10(unsigned char* view
,
1179 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
)
1181 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1182 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1183 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1184 int32_t reloc
= static_cast<int32_t>(value
);
1187 reloc
= (reloc
& 0x3ff) | 0x1c00;
1189 reloc
= (reloc
& 0x3ff);
1192 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1195 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1197 lox10(unsigned char* view
,
1198 const Sized_relobj_file
<size
, big_endian
>* object
,
1199 const Symbol_value
<size
>* psymval
,
1200 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1202 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1203 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1204 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1205 Valtype reloc
= psymval
->value(object
, addend
);
1211 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1215 // Get the GOT section, creating it if necessary.
1217 template<int size
, bool big_endian
>
1218 Output_data_got
<size
, big_endian
>*
1219 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1222 if (this->got_
== NULL
)
1224 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1226 this->got_
= new Output_data_got
<size
, big_endian
>();
1228 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1230 | elfcpp::SHF_WRITE
),
1231 this->got_
, ORDER_RELRO
, true);
1233 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1234 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1235 Symbol_table::PREDEFINED
,
1237 0, 0, elfcpp::STT_OBJECT
,
1239 elfcpp::STV_HIDDEN
, 0,
1246 // Get the dynamic reloc section, creating it if necessary.
1248 template<int size
, bool big_endian
>
1249 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1250 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1252 if (this->rela_dyn_
== NULL
)
1254 gold_assert(layout
!= NULL
);
1255 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1256 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1257 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1258 ORDER_DYNAMIC_RELOCS
, false);
1260 return this->rela_dyn_
;
1263 // Get the section to use for IFUNC relocs, creating it if
1264 // necessary. These go in .rela.dyn, but only after all other dynamic
1265 // relocations. They need to follow the other dynamic relocations so
1266 // that they can refer to global variables initialized by those
1269 template<int size
, bool big_endian
>
1270 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1271 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1273 if (this->rela_ifunc_
== NULL
)
1275 // Make sure we have already created the dynamic reloc section.
1276 this->rela_dyn_section(layout
);
1277 this->rela_ifunc_
= new Reloc_section(false);
1278 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1279 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1280 ORDER_DYNAMIC_RELOCS
, false);
1281 gold_assert(this->rela_dyn_
->output_section()
1282 == this->rela_ifunc_
->output_section());
1284 return this->rela_ifunc_
;
1287 // A class to handle the PLT data.
1289 template<int size
, bool big_endian
>
1290 class Output_data_plt_sparc
: public Output_section_data
1293 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1294 size
, big_endian
> Reloc_section
;
1296 Output_data_plt_sparc(Layout
*);
1298 // Add an entry to the PLT.
1299 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1301 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1303 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1304 Sized_relobj_file
<size
, big_endian
>* relobj
,
1305 unsigned int local_sym_index
);
1307 // Return the .rela.plt section data.
1308 const Reloc_section
* rel_plt() const
1313 // Return where the IFUNC relocations should go.
1315 rela_ifunc(Symbol_table
*, Layout
*);
1318 emit_pending_ifunc_relocs();
1320 // Return whether we created a section for IFUNC relocations.
1322 has_ifunc_section() const
1323 { return this->ifunc_rel_
!= NULL
; }
1325 // Return the number of PLT entries.
1328 { return this->count_
+ this->ifunc_count_
; }
1330 // Return the offset of the first non-reserved PLT entry.
1332 first_plt_entry_offset()
1333 { return 4 * base_plt_entry_size
; }
1335 // Return the size of a PLT entry.
1337 get_plt_entry_size()
1338 { return base_plt_entry_size
; }
1340 // Return the PLT address to use for a global symbol.
1342 address_for_global(const Symbol
*);
1344 // Return the PLT address to use for a local symbol.
1346 address_for_local(const Relobj
*, unsigned int symndx
);
1349 void do_adjust_output_section(Output_section
* os
);
1351 // Write to a map file.
1353 do_print_to_mapfile(Mapfile
* mapfile
) const
1354 { mapfile
->print_output_data(this, _("** PLT")); }
1357 // The size of an entry in the PLT.
1358 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1360 static const unsigned int plt_entries_per_block
= 160;
1361 static const unsigned int plt_insn_chunk_size
= 24;
1362 static const unsigned int plt_pointer_chunk_size
= 8;
1363 static const unsigned int plt_block_size
=
1364 (plt_entries_per_block
1365 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1368 plt_index_to_offset(unsigned int index
)
1370 section_offset_type offset
;
1372 if (size
== 32 || index
< 32768)
1373 offset
= index
* base_plt_entry_size
;
1376 unsigned int ext_index
= index
- 32768;
1378 offset
= (32768 * base_plt_entry_size
)
1379 + ((ext_index
/ plt_entries_per_block
)
1381 + ((ext_index
% plt_entries_per_block
)
1382 * plt_insn_chunk_size
);
1387 // Set the final size.
1389 set_final_data_size()
1391 unsigned int full_count
= this->entry_count() + 4;
1392 unsigned int extra
= (size
== 32 ? 4 : 0);
1393 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1395 return this->set_data_size(sz
);
1398 // Write out the PLT data.
1400 do_write(Output_file
*);
1406 unsigned int plt_index
;
1412 Sized_relobj_file
<size
, big_endian
>* object
;
1413 unsigned int local_sym_index
;
1414 unsigned int plt_index
;
1417 // The reloc section.
1418 Reloc_section
* rel_
;
1419 // The IFUNC relocations, if necessary. These must follow the
1420 // regular relocations.
1421 Reloc_section
* ifunc_rel_
;
1422 // The number of PLT entries.
1423 unsigned int count_
;
1424 // The number of PLT entries for IFUNC symbols.
1425 unsigned int ifunc_count_
;
1426 // Global STT_GNU_IFUNC symbols.
1427 std::vector
<Global_ifunc
> global_ifuncs_
;
1428 // Local STT_GNU_IFUNC symbols.
1429 std::vector
<Local_ifunc
> local_ifuncs_
;
1432 // Define the constants as required by C++ standard.
1434 template<int size
, bool big_endian
>
1435 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1437 template<int size
, bool big_endian
>
1439 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1441 template<int size
, bool big_endian
>
1442 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1444 template<int size
, bool big_endian
>
1446 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1448 template<int size
, bool big_endian
>
1449 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1451 // Create the PLT section. The ordinary .got section is an argument,
1452 // since we need to refer to the start.
1454 template<int size
, bool big_endian
>
1455 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1456 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1457 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1459 this->rel_
= new Reloc_section(false);
1460 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1461 elfcpp::SHF_ALLOC
, this->rel_
,
1462 ORDER_DYNAMIC_PLT_RELOCS
, false);
1465 template<int size
, bool big_endian
>
1467 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1472 // Add an entry to the PLT.
1474 template<int size
, bool big_endian
>
1476 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1480 gold_assert(!gsym
->has_plt_offset());
1482 section_offset_type plt_offset
;
1485 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1486 && gsym
->can_use_relative_reloc(false))
1488 index
= this->ifunc_count_
;
1489 plt_offset
= plt_index_to_offset(index
);
1490 gsym
->set_plt_offset(plt_offset
);
1491 ++this->ifunc_count_
;
1492 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1494 struct Global_ifunc gi
;
1497 gi
.plt_index
= index
;
1498 this->global_ifuncs_
.push_back(gi
);
1502 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1503 gsym
->set_plt_offset(plt_offset
);
1505 gsym
->set_needs_dynsym_entry();
1506 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1510 // Note that we don't need to save the symbol. The contents of the
1511 // PLT are independent of which symbols are used. The symbols only
1512 // appear in the relocations.
1515 template<int size
, bool big_endian
>
1517 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1518 Symbol_table
* symtab
,
1520 Sized_relobj_file
<size
, big_endian
>* relobj
,
1521 unsigned int local_sym_index
)
1523 unsigned int index
= this->ifunc_count_
;
1524 section_offset_type plt_offset
;
1526 plt_offset
= plt_index_to_offset(index
);
1527 ++this->ifunc_count_
;
1529 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1531 struct Local_ifunc li
;
1534 li
.local_sym_index
= local_sym_index
;
1535 li
.plt_index
= index
;
1536 this->local_ifuncs_
.push_back(li
);
1541 // Emit any pending IFUNC plt relocations.
1543 template<int size
, bool big_endian
>
1545 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1547 // Emit any pending IFUNC relocs.
1548 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1549 this->global_ifuncs_
.begin();
1550 p
!= this->global_ifuncs_
.end();
1553 section_offset_type plt_offset
;
1556 index
= this->count_
+ p
->plt_index
+ 4;
1557 plt_offset
= this->plt_index_to_offset(index
);
1558 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1559 this, plt_offset
, 0);
1562 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1563 this->local_ifuncs_
.begin();
1564 p
!= this->local_ifuncs_
.end();
1567 section_offset_type plt_offset
;
1570 index
= this->count_
+ p
->plt_index
+ 4;
1571 plt_offset
= this->plt_index_to_offset(index
);
1572 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1573 elfcpp::R_SPARC_JMP_IREL
,
1574 this, plt_offset
, 0);
1578 // Return where the IFUNC relocations should go in the PLT. These
1579 // follow the non-IFUNC relocations.
1581 template<int size
, bool big_endian
>
1582 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1583 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1584 Symbol_table
* symtab
,
1587 if (this->ifunc_rel_
== NULL
)
1589 this->ifunc_rel_
= new Reloc_section(false);
1590 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1591 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1592 ORDER_DYNAMIC_PLT_RELOCS
, false);
1593 gold_assert(this->ifunc_rel_
->output_section()
1594 == this->rel_
->output_section());
1596 if (parameters
->doing_static_link())
1598 // A statically linked executable will only have a .rel.plt
1599 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1600 // relocs for STT_GNU_IFUNC symbols. The library will use
1601 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1602 // at program startup time.
1603 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1604 Symbol_table::PREDEFINED
,
1605 this->ifunc_rel_
, 0, 0,
1606 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1607 elfcpp::STV_HIDDEN
, 0, false, true);
1608 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1609 Symbol_table::PREDEFINED
,
1610 this->ifunc_rel_
, 0, 0,
1611 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1612 elfcpp::STV_HIDDEN
, 0, true, true);
1615 return this->ifunc_rel_
;
1618 // Return the PLT address to use for a global symbol.
1620 template<int size
, bool big_endian
>
1622 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1624 uint64_t offset
= 0;
1625 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1626 && gsym
->can_use_relative_reloc(false))
1627 offset
= plt_index_to_offset(this->count_
+ 4);
1628 return this->address() + offset
+ gsym
->plt_offset();
1631 // Return the PLT address to use for a local symbol. These are always
1632 // IRELATIVE relocs.
1634 template<int size
, bool big_endian
>
1636 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1637 const Relobj
* object
,
1640 return (this->address()
1641 + plt_index_to_offset(this->count_
+ 4)
1642 + object
->local_plt_offset(r_sym
));
1645 static const unsigned int sparc_nop
= 0x01000000;
1646 static const unsigned int sparc_sethi_g1
= 0x03000000;
1647 static const unsigned int sparc_branch_always
= 0x30800000;
1648 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1649 static const unsigned int sparc_mov
= 0x80100000;
1650 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1651 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1652 static const unsigned int sparc_call_plus_8
= 0x40000002;
1653 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1654 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1655 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1657 // Write out the PLT.
1659 template<int size
, bool big_endian
>
1661 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1663 const off_t offset
= this->offset();
1664 const section_size_type oview_size
=
1665 convert_to_section_size_type(this->data_size());
1666 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1667 unsigned char* pov
= oview
;
1669 memset(pov
, 0, base_plt_entry_size
* 4);
1670 pov
+= this->first_plt_entry_offset();
1672 unsigned int plt_offset
= base_plt_entry_size
* 4;
1673 const unsigned int count
= this->entry_count();
1679 limit
= (count
> 32768 ? 32768 : count
);
1681 for (unsigned int i
= 0; i
< limit
; ++i
)
1683 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1684 sparc_sethi_g1
+ plt_offset
);
1685 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1686 sparc_branch_always_pt
+
1687 (((base_plt_entry_size
-
1688 (plt_offset
+ 4)) >> 2) &
1690 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1691 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1692 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1693 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1694 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1695 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1697 pov
+= base_plt_entry_size
;
1698 plt_offset
+= base_plt_entry_size
;
1703 unsigned int ext_cnt
= count
- 32768;
1704 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1706 for (unsigned int i
= 0; i
< blks
; ++i
)
1708 unsigned int data_off
= (plt_entries_per_block
1709 * plt_insn_chunk_size
) - 4;
1711 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1713 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1715 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1717 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1719 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1720 sparc_ldx_o7_imm_g1
+
1721 (data_off
& 0x1fff));
1722 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1723 sparc_jmpl_o7_g1_g1
);
1724 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1727 elfcpp::Swap
<64, big_endian
>::writeval(
1728 pov
+ 0x4 + data_off
,
1729 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1731 pov
+= plt_insn_chunk_size
;
1736 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1737 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1739 unsigned int data_off
= (sub_blk_cnt
1740 * plt_insn_chunk_size
) - 4;
1742 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1744 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1746 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1748 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1750 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1751 sparc_ldx_o7_imm_g1
+
1752 (data_off
& 0x1fff));
1753 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1754 sparc_jmpl_o7_g1_g1
);
1755 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1758 elfcpp::Swap
<64, big_endian
>::writeval(
1759 pov
+ 0x4 + data_off
,
1760 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1762 pov
+= plt_insn_chunk_size
;
1770 for (unsigned int i
= 0; i
< count
; ++i
)
1772 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1773 sparc_sethi_g1
+ plt_offset
);
1774 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1775 sparc_branch_always
+
1776 (((- (plt_offset
+ 4)) >> 2) &
1778 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1780 pov
+= base_plt_entry_size
;
1781 plt_offset
+= base_plt_entry_size
;
1784 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1788 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1790 of
->write_output_view(offset
, oview_size
, oview
);
1793 // Create the PLT section.
1795 template<int size
, bool big_endian
>
1797 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1800 // Create the GOT sections first.
1801 this->got_section(symtab
, layout
);
1803 // Ensure that .rela.dyn always appears before .rela.plt This is
1804 // necessary due to how, on Sparc and some other targets, .rela.dyn
1805 // needs to include .rela.plt in it's range.
1806 this->rela_dyn_section(layout
);
1808 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1809 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1811 | elfcpp::SHF_EXECINSTR
1812 | elfcpp::SHF_WRITE
),
1813 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1815 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1816 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1817 Symbol_table::PREDEFINED
,
1819 0, 0, elfcpp::STT_OBJECT
,
1821 elfcpp::STV_HIDDEN
, 0,
1825 // Create a PLT entry for a global symbol.
1827 template<int size
, bool big_endian
>
1829 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1833 if (gsym
->has_plt_offset())
1836 if (this->plt_
== NULL
)
1837 this->make_plt_section(symtab
, layout
);
1839 this->plt_
->add_entry(symtab
, layout
, gsym
);
1842 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1844 template<int size
, bool big_endian
>
1846 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1847 Symbol_table
* symtab
,
1849 Sized_relobj_file
<size
, big_endian
>* relobj
,
1850 unsigned int local_sym_index
)
1852 if (relobj
->local_has_plt_offset(local_sym_index
))
1854 if (this->plt_
== NULL
)
1855 this->make_plt_section(symtab
, layout
);
1856 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1859 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1862 // Return the number of entries in the PLT.
1864 template<int size
, bool big_endian
>
1866 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1868 if (this->plt_
== NULL
)
1870 return this->plt_
->entry_count();
1873 // Return the offset of the first non-reserved PLT entry.
1875 template<int size
, bool big_endian
>
1877 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1879 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1882 // Return the size of each PLT entry.
1884 template<int size
, bool big_endian
>
1886 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1888 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1891 // Create a GOT entry for the TLS module index.
1893 template<int size
, bool big_endian
>
1895 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1896 Symbol_table
* symtab
,
1898 Sized_relobj_file
<size
, big_endian
>* object
)
1900 if (this->got_mod_index_offset_
== -1U)
1902 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1903 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1904 Output_data_got
<size
, big_endian
>* got
;
1905 unsigned int got_offset
;
1907 got
= this->got_section(symtab
, layout
);
1908 got_offset
= got
->add_constant(0);
1909 rela_dyn
->add_local(object
, 0,
1911 elfcpp::R_SPARC_TLS_DTPMOD64
:
1912 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1914 got
->add_constant(0);
1915 this->got_mod_index_offset_
= got_offset
;
1917 return this->got_mod_index_offset_
;
1920 // Optimize the TLS relocation type based on what we know about the
1921 // symbol. IS_FINAL is true if the final address of this symbol is
1922 // known at link time.
1924 static tls::Tls_optimization
1925 optimize_tls_reloc(bool is_final
, int r_type
)
1927 // If we are generating a shared library, then we can't do anything
1929 if (parameters
->options().shared())
1930 return tls::TLSOPT_NONE
;
1934 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1935 case elfcpp::R_SPARC_TLS_GD_LO10
:
1936 case elfcpp::R_SPARC_TLS_GD_ADD
:
1937 case elfcpp::R_SPARC_TLS_GD_CALL
:
1938 // These are General-Dynamic which permits fully general TLS
1939 // access. Since we know that we are generating an executable,
1940 // we can convert this to Initial-Exec. If we also know that
1941 // this is a local symbol, we can further switch to Local-Exec.
1943 return tls::TLSOPT_TO_LE
;
1944 return tls::TLSOPT_TO_IE
;
1946 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1947 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1948 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1949 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1950 // This is Local-Dynamic, which refers to a local symbol in the
1951 // dynamic TLS block. Since we know that we generating an
1952 // executable, we can switch to Local-Exec.
1953 return tls::TLSOPT_TO_LE
;
1955 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1956 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1957 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1958 // Another type of Local-Dynamic relocation.
1959 return tls::TLSOPT_TO_LE
;
1961 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1962 case elfcpp::R_SPARC_TLS_IE_LO10
:
1963 case elfcpp::R_SPARC_TLS_IE_LD
:
1964 case elfcpp::R_SPARC_TLS_IE_LDX
:
1965 case elfcpp::R_SPARC_TLS_IE_ADD
:
1966 // These are Initial-Exec relocs which get the thread offset
1967 // from the GOT. If we know that we are linking against the
1968 // local symbol, we can switch to Local-Exec, which links the
1969 // thread offset into the instruction.
1971 return tls::TLSOPT_TO_LE
;
1972 return tls::TLSOPT_NONE
;
1974 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1975 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1976 // When we already have Local-Exec, there is nothing further we
1978 return tls::TLSOPT_NONE
;
1985 // Get the Reference_flags for a particular relocation.
1987 template<int size
, bool big_endian
>
1989 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1994 case elfcpp::R_SPARC_NONE
:
1995 case elfcpp::R_SPARC_REGISTER
:
1996 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1997 case elfcpp::R_SPARC_GNU_VTENTRY
:
1998 // No symbol reference.
2001 case elfcpp::R_SPARC_UA64
:
2002 case elfcpp::R_SPARC_64
:
2003 case elfcpp::R_SPARC_HIX22
:
2004 case elfcpp::R_SPARC_LOX10
:
2005 case elfcpp::R_SPARC_H34
:
2006 case elfcpp::R_SPARC_H44
:
2007 case elfcpp::R_SPARC_M44
:
2008 case elfcpp::R_SPARC_L44
:
2009 case elfcpp::R_SPARC_HH22
:
2010 case elfcpp::R_SPARC_HM10
:
2011 case elfcpp::R_SPARC_LM22
:
2012 case elfcpp::R_SPARC_HI22
:
2013 case elfcpp::R_SPARC_LO10
:
2014 case elfcpp::R_SPARC_OLO10
:
2015 case elfcpp::R_SPARC_UA32
:
2016 case elfcpp::R_SPARC_32
:
2017 case elfcpp::R_SPARC_UA16
:
2018 case elfcpp::R_SPARC_16
:
2019 case elfcpp::R_SPARC_11
:
2020 case elfcpp::R_SPARC_10
:
2021 case elfcpp::R_SPARC_8
:
2022 case elfcpp::R_SPARC_7
:
2023 case elfcpp::R_SPARC_6
:
2024 case elfcpp::R_SPARC_5
:
2025 return Symbol::ABSOLUTE_REF
;
2027 case elfcpp::R_SPARC_DISP8
:
2028 case elfcpp::R_SPARC_DISP16
:
2029 case elfcpp::R_SPARC_DISP32
:
2030 case elfcpp::R_SPARC_DISP64
:
2031 case elfcpp::R_SPARC_PC_HH22
:
2032 case elfcpp::R_SPARC_PC_HM10
:
2033 case elfcpp::R_SPARC_PC_LM22
:
2034 case elfcpp::R_SPARC_PC10
:
2035 case elfcpp::R_SPARC_PC22
:
2036 case elfcpp::R_SPARC_WDISP30
:
2037 case elfcpp::R_SPARC_WDISP22
:
2038 case elfcpp::R_SPARC_WDISP19
:
2039 case elfcpp::R_SPARC_WDISP16
:
2040 case elfcpp::R_SPARC_WDISP10
:
2041 return Symbol::RELATIVE_REF
;
2043 case elfcpp::R_SPARC_PLT64
:
2044 case elfcpp::R_SPARC_PLT32
:
2045 case elfcpp::R_SPARC_HIPLT22
:
2046 case elfcpp::R_SPARC_LOPLT10
:
2047 case elfcpp::R_SPARC_PCPLT10
:
2048 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2050 case elfcpp::R_SPARC_PCPLT32
:
2051 case elfcpp::R_SPARC_PCPLT22
:
2052 case elfcpp::R_SPARC_WPLT30
:
2053 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2055 case elfcpp::R_SPARC_GOTDATA_OP
:
2056 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2057 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2058 case elfcpp::R_SPARC_GOT10
:
2059 case elfcpp::R_SPARC_GOT13
:
2060 case elfcpp::R_SPARC_GOT22
:
2062 return Symbol::ABSOLUTE_REF
;
2064 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2065 case elfcpp::R_SPARC_TLS_GD_LO10
:
2066 case elfcpp::R_SPARC_TLS_GD_ADD
:
2067 case elfcpp::R_SPARC_TLS_GD_CALL
:
2068 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2069 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2070 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2071 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2072 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2073 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2074 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2075 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2076 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2077 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2078 case elfcpp::R_SPARC_TLS_IE_LO10
:
2079 case elfcpp::R_SPARC_TLS_IE_LD
:
2080 case elfcpp::R_SPARC_TLS_IE_LDX
:
2081 case elfcpp::R_SPARC_TLS_IE_ADD
:
2082 return Symbol::TLS_REF
;
2084 case elfcpp::R_SPARC_COPY
:
2085 case elfcpp::R_SPARC_GLOB_DAT
:
2086 case elfcpp::R_SPARC_JMP_SLOT
:
2087 case elfcpp::R_SPARC_JMP_IREL
:
2088 case elfcpp::R_SPARC_RELATIVE
:
2089 case elfcpp::R_SPARC_IRELATIVE
:
2090 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2091 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2092 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2093 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2094 case elfcpp::R_SPARC_TLS_TPOFF64
:
2095 case elfcpp::R_SPARC_TLS_TPOFF32
:
2097 // Not expected. We will give an error later.
2102 // Generate a PLT entry slot for a call to __tls_get_addr
2103 template<int size
, bool big_endian
>
2105 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2107 Target_sparc
<size
, big_endian
>* target
)
2109 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2111 target
->make_plt_entry(symtab
, layout
, gsym
);
2114 // Report an unsupported relocation against a local symbol.
2116 template<int size
, bool big_endian
>
2118 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2119 Sized_relobj_file
<size
, big_endian
>* object
,
2120 unsigned int r_type
)
2122 gold_error(_("%s: unsupported reloc %u against local symbol"),
2123 object
->name().c_str(), r_type
);
2126 // We are about to emit a dynamic relocation of type R_TYPE. If the
2127 // dynamic linker does not support it, issue an error.
2129 template<int size
, bool big_endian
>
2131 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2133 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2139 // These are the relocation types supported by glibc for sparc 64-bit.
2140 case elfcpp::R_SPARC_RELATIVE
:
2141 case elfcpp::R_SPARC_IRELATIVE
:
2142 case elfcpp::R_SPARC_COPY
:
2143 case elfcpp::R_SPARC_64
:
2144 case elfcpp::R_SPARC_GLOB_DAT
:
2145 case elfcpp::R_SPARC_JMP_SLOT
:
2146 case elfcpp::R_SPARC_JMP_IREL
:
2147 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2148 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2149 case elfcpp::R_SPARC_TLS_TPOFF64
:
2150 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2151 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2152 case elfcpp::R_SPARC_8
:
2153 case elfcpp::R_SPARC_16
:
2154 case elfcpp::R_SPARC_DISP8
:
2155 case elfcpp::R_SPARC_DISP16
:
2156 case elfcpp::R_SPARC_DISP32
:
2157 case elfcpp::R_SPARC_WDISP30
:
2158 case elfcpp::R_SPARC_LO10
:
2159 case elfcpp::R_SPARC_HI22
:
2160 case elfcpp::R_SPARC_OLO10
:
2161 case elfcpp::R_SPARC_H34
:
2162 case elfcpp::R_SPARC_H44
:
2163 case elfcpp::R_SPARC_M44
:
2164 case elfcpp::R_SPARC_L44
:
2165 case elfcpp::R_SPARC_HH22
:
2166 case elfcpp::R_SPARC_HM10
:
2167 case elfcpp::R_SPARC_LM22
:
2168 case elfcpp::R_SPARC_UA16
:
2169 case elfcpp::R_SPARC_UA32
:
2170 case elfcpp::R_SPARC_UA64
:
2181 // These are the relocation types supported by glibc for sparc 32-bit.
2182 case elfcpp::R_SPARC_RELATIVE
:
2183 case elfcpp::R_SPARC_IRELATIVE
:
2184 case elfcpp::R_SPARC_COPY
:
2185 case elfcpp::R_SPARC_GLOB_DAT
:
2186 case elfcpp::R_SPARC_32
:
2187 case elfcpp::R_SPARC_JMP_SLOT
:
2188 case elfcpp::R_SPARC_JMP_IREL
:
2189 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2190 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2191 case elfcpp::R_SPARC_TLS_TPOFF32
:
2192 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2193 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2194 case elfcpp::R_SPARC_8
:
2195 case elfcpp::R_SPARC_16
:
2196 case elfcpp::R_SPARC_DISP8
:
2197 case elfcpp::R_SPARC_DISP16
:
2198 case elfcpp::R_SPARC_DISP32
:
2199 case elfcpp::R_SPARC_LO10
:
2200 case elfcpp::R_SPARC_WDISP30
:
2201 case elfcpp::R_SPARC_HI22
:
2202 case elfcpp::R_SPARC_UA16
:
2203 case elfcpp::R_SPARC_UA32
:
2211 // This prevents us from issuing more than one error per reloc
2212 // section. But we can still wind up issuing more than one
2213 // error per object file.
2214 if (this->issued_non_pic_error_
)
2216 gold_assert(parameters
->options().output_is_position_independent());
2217 object
->error(_("requires unsupported dynamic reloc; "
2218 "recompile with -fPIC"));
2219 this->issued_non_pic_error_
= true;
2223 // Return whether we need to make a PLT entry for a relocation of the
2224 // given type against a STT_GNU_IFUNC symbol.
2226 template<int size
, bool big_endian
>
2228 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2229 Sized_relobj_file
<size
, big_endian
>* object
,
2230 unsigned int r_type
)
2232 int flags
= Scan::get_reference_flags(r_type
);
2233 if (flags
& Symbol::TLS_REF
)
2234 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2235 object
->name().c_str(), r_type
);
2239 // Scan a relocation for a local symbol.
2241 template<int size
, bool big_endian
>
2243 Target_sparc
<size
, big_endian
>::Scan::local(
2244 Symbol_table
* symtab
,
2246 Target_sparc
<size
, big_endian
>* target
,
2247 Sized_relobj_file
<size
, big_endian
>* object
,
2248 unsigned int data_shndx
,
2249 Output_section
* output_section
,
2250 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2251 unsigned int r_type
,
2252 const elfcpp::Sym
<size
, big_endian
>& lsym
,
2258 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2259 unsigned int orig_r_type
= r_type
;
2263 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2265 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2266 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2271 case elfcpp::R_SPARC_NONE
:
2272 case elfcpp::R_SPARC_REGISTER
:
2273 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2274 case elfcpp::R_SPARC_GNU_VTENTRY
:
2277 case elfcpp::R_SPARC_64
:
2278 case elfcpp::R_SPARC_32
:
2279 // If building a shared library (or a position-independent
2280 // executable), we need to create a dynamic relocation for
2281 // this location. The relocation applied at link time will
2282 // apply the link-time value, so we flag the location with
2283 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2284 // relocate it easily.
2285 if (parameters
->options().output_is_position_independent())
2287 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2288 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2289 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2290 output_section
, data_shndx
,
2291 reloc
.get_r_offset(),
2292 reloc
.get_r_addend(), is_ifunc
);
2296 case elfcpp::R_SPARC_HIX22
:
2297 case elfcpp::R_SPARC_LOX10
:
2298 case elfcpp::R_SPARC_H34
:
2299 case elfcpp::R_SPARC_H44
:
2300 case elfcpp::R_SPARC_M44
:
2301 case elfcpp::R_SPARC_L44
:
2302 case elfcpp::R_SPARC_HH22
:
2303 case elfcpp::R_SPARC_HM10
:
2304 case elfcpp::R_SPARC_LM22
:
2305 case elfcpp::R_SPARC_UA64
:
2306 case elfcpp::R_SPARC_UA32
:
2307 case elfcpp::R_SPARC_UA16
:
2308 case elfcpp::R_SPARC_HI22
:
2309 case elfcpp::R_SPARC_LO10
:
2310 case elfcpp::R_SPARC_OLO10
:
2311 case elfcpp::R_SPARC_16
:
2312 case elfcpp::R_SPARC_11
:
2313 case elfcpp::R_SPARC_10
:
2314 case elfcpp::R_SPARC_8
:
2315 case elfcpp::R_SPARC_7
:
2316 case elfcpp::R_SPARC_6
:
2317 case elfcpp::R_SPARC_5
:
2318 // If building a shared library (or a position-independent
2319 // executable), we need to create a dynamic relocation for
2321 if (parameters
->options().output_is_position_independent())
2323 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2324 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2326 check_non_pic(object
, r_type
);
2327 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2329 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2330 data_shndx
, reloc
.get_r_offset(),
2331 reloc
.get_r_addend());
2335 gold_assert(lsym
.get_st_value() == 0);
2336 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2337 output_section
, data_shndx
,
2338 reloc
.get_r_offset(),
2339 reloc
.get_r_addend());
2344 case elfcpp::R_SPARC_WDISP30
:
2345 case elfcpp::R_SPARC_WPLT30
:
2346 case elfcpp::R_SPARC_WDISP22
:
2347 case elfcpp::R_SPARC_WDISP19
:
2348 case elfcpp::R_SPARC_WDISP16
:
2349 case elfcpp::R_SPARC_WDISP10
:
2350 case elfcpp::R_SPARC_DISP8
:
2351 case elfcpp::R_SPARC_DISP16
:
2352 case elfcpp::R_SPARC_DISP32
:
2353 case elfcpp::R_SPARC_DISP64
:
2354 case elfcpp::R_SPARC_PC10
:
2355 case elfcpp::R_SPARC_PC22
:
2358 case elfcpp::R_SPARC_GOTDATA_OP
:
2359 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2360 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2361 // We will optimize this into a GOT relative relocation
2362 // and code transform the GOT load into an addition.
2365 case elfcpp::R_SPARC_GOT10
:
2366 case elfcpp::R_SPARC_GOT13
:
2367 case elfcpp::R_SPARC_GOT22
:
2369 // The symbol requires a GOT entry.
2370 Output_data_got
<size
, big_endian
>* got
;
2373 got
= target
->got_section(symtab
, layout
);
2374 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2376 // If we are generating a shared object, we need to add a
2377 // dynamic relocation for this symbol's GOT entry.
2378 if (parameters
->options().output_is_position_independent())
2380 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2382 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2383 unsigned int off
= got
->add_constant(0);
2384 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2385 rela_dyn
->add_local_relative(object
, r_sym
,
2386 elfcpp::R_SPARC_RELATIVE
,
2387 got
, off
, 0, is_ifunc
);
2391 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2395 // These are initial TLS relocs, which are expected when
2397 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2398 case elfcpp::R_SPARC_TLS_GD_LO10
:
2399 case elfcpp::R_SPARC_TLS_GD_ADD
:
2400 case elfcpp::R_SPARC_TLS_GD_CALL
:
2401 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2402 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2403 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2404 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2405 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2406 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2407 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2408 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2409 case elfcpp::R_SPARC_TLS_IE_LO10
:
2410 case elfcpp::R_SPARC_TLS_IE_LD
:
2411 case elfcpp::R_SPARC_TLS_IE_LDX
:
2412 case elfcpp::R_SPARC_TLS_IE_ADD
:
2413 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2414 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2416 bool output_is_shared
= parameters
->options().shared();
2417 const tls::Tls_optimization optimized_type
2418 = optimize_tls_reloc(!output_is_shared
, r_type
);
2421 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2422 case elfcpp::R_SPARC_TLS_GD_LO10
:
2423 case elfcpp::R_SPARC_TLS_GD_ADD
:
2424 case elfcpp::R_SPARC_TLS_GD_CALL
:
2425 if (optimized_type
== tls::TLSOPT_NONE
)
2427 // Create a pair of GOT entries for the module index and
2428 // dtv-relative offset.
2429 Output_data_got
<size
, big_endian
>* got
2430 = target
->got_section(symtab
, layout
);
2431 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2432 unsigned int shndx
= lsym
.get_st_shndx();
2434 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2436 object
->error(_("local symbol %u has bad shndx %u"),
2439 got
->add_local_pair_with_rel(object
, r_sym
,
2440 lsym
.get_st_shndx(),
2442 target
->rela_dyn_section(layout
),
2444 ? elfcpp::R_SPARC_TLS_DTPMOD64
2445 : elfcpp::R_SPARC_TLS_DTPMOD32
));
2446 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2447 generate_tls_call(symtab
, layout
, target
);
2449 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2450 unsupported_reloc_local(object
, r_type
);
2453 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2454 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2455 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2456 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2457 if (optimized_type
== tls::TLSOPT_NONE
)
2459 // Create a GOT entry for the module index.
2460 target
->got_mod_index_entry(symtab
, layout
, object
);
2462 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2463 generate_tls_call(symtab
, layout
, target
);
2465 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2466 unsupported_reloc_local(object
, r_type
);
2469 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2470 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2471 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2474 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2475 case elfcpp::R_SPARC_TLS_IE_LO10
:
2476 case elfcpp::R_SPARC_TLS_IE_LD
:
2477 case elfcpp::R_SPARC_TLS_IE_LDX
:
2478 case elfcpp::R_SPARC_TLS_IE_ADD
:
2479 layout
->set_has_static_tls();
2480 if (optimized_type
== tls::TLSOPT_NONE
)
2482 // Create a GOT entry for the tp-relative offset.
2483 Output_data_got
<size
, big_endian
>* got
2484 = target
->got_section(symtab
, layout
);
2485 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2487 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2489 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2490 unsigned int off
= got
->add_constant(0);
2492 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2494 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2496 elfcpp::R_SPARC_TLS_TPOFF64
:
2497 elfcpp::R_SPARC_TLS_TPOFF32
),
2501 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2502 unsupported_reloc_local(object
, r_type
);
2505 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2506 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2507 layout
->set_has_static_tls();
2508 if (output_is_shared
)
2510 // We need to create a dynamic relocation.
2511 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2512 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2513 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2514 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2515 output_section
, data_shndx
,
2516 reloc
.get_r_offset(), 0);
2523 // These are relocations which should only be seen by the
2524 // dynamic linker, and should never be seen here.
2525 case elfcpp::R_SPARC_COPY
:
2526 case elfcpp::R_SPARC_GLOB_DAT
:
2527 case elfcpp::R_SPARC_JMP_SLOT
:
2528 case elfcpp::R_SPARC_JMP_IREL
:
2529 case elfcpp::R_SPARC_RELATIVE
:
2530 case elfcpp::R_SPARC_IRELATIVE
:
2531 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2532 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2533 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2534 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2535 case elfcpp::R_SPARC_TLS_TPOFF64
:
2536 case elfcpp::R_SPARC_TLS_TPOFF32
:
2537 gold_error(_("%s: unexpected reloc %u in object file"),
2538 object
->name().c_str(), r_type
);
2542 unsupported_reloc_local(object
, r_type
);
2547 // Report an unsupported relocation against a global symbol.
2549 template<int size
, bool big_endian
>
2551 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2552 Sized_relobj_file
<size
, big_endian
>* object
,
2553 unsigned int r_type
,
2556 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2557 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2560 // Scan a relocation for a global symbol.
2562 template<int size
, bool big_endian
>
2564 Target_sparc
<size
, big_endian
>::Scan::global(
2565 Symbol_table
* symtab
,
2567 Target_sparc
<size
, big_endian
>* target
,
2568 Sized_relobj_file
<size
, big_endian
>* object
,
2569 unsigned int data_shndx
,
2570 Output_section
* output_section
,
2571 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2572 unsigned int r_type
,
2575 unsigned int orig_r_type
= r_type
;
2576 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2578 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2579 // section. We check here to avoid creating a dynamic reloc against
2580 // _GLOBAL_OFFSET_TABLE_.
2581 if (!target
->has_got_section()
2582 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2583 target
->got_section(symtab
, layout
);
2587 // A STT_GNU_IFUNC symbol may require a PLT entry.
2589 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2590 target
->make_plt_entry(symtab
, layout
, gsym
);
2594 case elfcpp::R_SPARC_NONE
:
2595 case elfcpp::R_SPARC_REGISTER
:
2596 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2597 case elfcpp::R_SPARC_GNU_VTENTRY
:
2600 case elfcpp::R_SPARC_PLT64
:
2601 case elfcpp::R_SPARC_PLT32
:
2602 case elfcpp::R_SPARC_HIPLT22
:
2603 case elfcpp::R_SPARC_LOPLT10
:
2604 case elfcpp::R_SPARC_PCPLT32
:
2605 case elfcpp::R_SPARC_PCPLT22
:
2606 case elfcpp::R_SPARC_PCPLT10
:
2607 case elfcpp::R_SPARC_WPLT30
:
2608 // If the symbol is fully resolved, this is just a PC32 reloc.
2609 // Otherwise we need a PLT entry.
2610 if (gsym
->final_value_is_known())
2612 // If building a shared library, we can also skip the PLT entry
2613 // if the symbol is defined in the output file and is protected
2615 if (gsym
->is_defined()
2616 && !gsym
->is_from_dynobj()
2617 && !gsym
->is_preemptible())
2619 target
->make_plt_entry(symtab
, layout
, gsym
);
2622 case elfcpp::R_SPARC_DISP8
:
2623 case elfcpp::R_SPARC_DISP16
:
2624 case elfcpp::R_SPARC_DISP32
:
2625 case elfcpp::R_SPARC_DISP64
:
2626 case elfcpp::R_SPARC_PC_HH22
:
2627 case elfcpp::R_SPARC_PC_HM10
:
2628 case elfcpp::R_SPARC_PC_LM22
:
2629 case elfcpp::R_SPARC_PC10
:
2630 case elfcpp::R_SPARC_PC22
:
2631 case elfcpp::R_SPARC_WDISP30
:
2632 case elfcpp::R_SPARC_WDISP22
:
2633 case elfcpp::R_SPARC_WDISP19
:
2634 case elfcpp::R_SPARC_WDISP16
:
2635 case elfcpp::R_SPARC_WDISP10
:
2637 if (gsym
->needs_plt_entry())
2638 target
->make_plt_entry(symtab
, layout
, gsym
);
2639 // Make a dynamic relocation if necessary.
2640 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2642 if (parameters
->options().output_is_executable()
2643 && gsym
->may_need_copy_reloc())
2645 target
->copy_reloc(symtab
, layout
, object
,
2646 data_shndx
, output_section
, gsym
,
2651 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2652 check_non_pic(object
, r_type
);
2653 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2654 data_shndx
, reloc
.get_r_offset(),
2655 reloc
.get_r_addend());
2661 case elfcpp::R_SPARC_UA64
:
2662 case elfcpp::R_SPARC_64
:
2663 case elfcpp::R_SPARC_HIX22
:
2664 case elfcpp::R_SPARC_LOX10
:
2665 case elfcpp::R_SPARC_H34
:
2666 case elfcpp::R_SPARC_H44
:
2667 case elfcpp::R_SPARC_M44
:
2668 case elfcpp::R_SPARC_L44
:
2669 case elfcpp::R_SPARC_HH22
:
2670 case elfcpp::R_SPARC_HM10
:
2671 case elfcpp::R_SPARC_LM22
:
2672 case elfcpp::R_SPARC_HI22
:
2673 case elfcpp::R_SPARC_LO10
:
2674 case elfcpp::R_SPARC_OLO10
:
2675 case elfcpp::R_SPARC_UA32
:
2676 case elfcpp::R_SPARC_32
:
2677 case elfcpp::R_SPARC_UA16
:
2678 case elfcpp::R_SPARC_16
:
2679 case elfcpp::R_SPARC_11
:
2680 case elfcpp::R_SPARC_10
:
2681 case elfcpp::R_SPARC_8
:
2682 case elfcpp::R_SPARC_7
:
2683 case elfcpp::R_SPARC_6
:
2684 case elfcpp::R_SPARC_5
:
2686 // Make a PLT entry if necessary.
2687 if (gsym
->needs_plt_entry())
2689 target
->make_plt_entry(symtab
, layout
, gsym
);
2690 // Since this is not a PC-relative relocation, we may be
2691 // taking the address of a function. In that case we need to
2692 // set the entry in the dynamic symbol table to the address of
2694 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2695 gsym
->set_needs_dynsym_value();
2697 // Make a dynamic relocation if necessary.
2698 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2700 unsigned int r_off
= reloc
.get_r_offset();
2702 // The assembler can sometimes emit unaligned relocations
2703 // for dwarf2 cfi directives.
2706 case elfcpp::R_SPARC_16
:
2708 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2710 case elfcpp::R_SPARC_32
:
2712 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2714 case elfcpp::R_SPARC_64
:
2716 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2718 case elfcpp::R_SPARC_UA16
:
2720 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2722 case elfcpp::R_SPARC_UA32
:
2724 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2726 case elfcpp::R_SPARC_UA64
:
2728 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2732 if (!parameters
->options().output_is_position_independent()
2733 && gsym
->may_need_copy_reloc())
2735 target
->copy_reloc(symtab
, layout
, object
,
2736 data_shndx
, output_section
, gsym
, reloc
);
2738 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2739 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2740 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2741 && gsym
->can_use_relative_reloc(false)
2742 && !gsym
->is_from_dynobj()
2743 && !gsym
->is_undefined()
2744 && !gsym
->is_preemptible())
2746 // Use an IRELATIVE reloc for a locally defined
2747 // STT_GNU_IFUNC symbol. This makes a function
2748 // address in a PIE executable match the address in a
2749 // shared library that it links against.
2750 Reloc_section
* rela_dyn
=
2751 target
->rela_ifunc_section(layout
);
2752 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2753 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2754 output_section
, object
,
2756 reloc
.get_r_offset(),
2757 reloc
.get_r_addend());
2759 else if ((r_type
== elfcpp::R_SPARC_32
2760 || r_type
== elfcpp::R_SPARC_64
)
2761 && gsym
->can_use_relative_reloc(false))
2763 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2764 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2765 output_section
, object
,
2766 data_shndx
, reloc
.get_r_offset(),
2767 reloc
.get_r_addend(), is_ifunc
);
2771 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2773 check_non_pic(object
, r_type
);
2774 if (gsym
->is_from_dynobj()
2775 || gsym
->is_undefined()
2776 || gsym
->is_preemptible())
2777 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2779 reloc
.get_r_offset(),
2780 reloc
.get_r_addend());
2782 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2785 reloc
.get_r_offset(),
2786 reloc
.get_r_addend());
2792 case elfcpp::R_SPARC_GOTDATA_OP
:
2793 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2794 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2795 if (gsym
->is_defined()
2796 && !gsym
->is_from_dynobj()
2797 && !gsym
->is_preemptible()
2800 // We will optimize this into a GOT relative relocation
2801 // and code transform the GOT load into an addition.
2804 case elfcpp::R_SPARC_GOT10
:
2805 case elfcpp::R_SPARC_GOT13
:
2806 case elfcpp::R_SPARC_GOT22
:
2808 // The symbol requires a GOT entry.
2809 Output_data_got
<size
, big_endian
>* got
;
2811 got
= target
->got_section(symtab
, layout
);
2812 if (gsym
->final_value_is_known())
2814 // For a STT_GNU_IFUNC symbol we want the PLT address.
2815 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2816 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2818 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2822 // If this symbol is not fully resolved, we need to add a
2823 // GOT entry with a dynamic relocation.
2824 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2826 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2828 // 1) The symbol may be defined in some other module.
2830 // 2) We are building a shared library and this is a
2831 // protected symbol; using GLOB_DAT means that the dynamic
2832 // linker can use the address of the PLT in the main
2833 // executable when appropriate so that function address
2834 // comparisons work.
2836 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2837 // code, again so that function address comparisons work.
2838 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2839 if (gsym
->is_from_dynobj()
2840 || gsym
->is_undefined()
2841 || gsym
->is_preemptible()
2842 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2843 && parameters
->options().shared())
2844 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2845 && parameters
->options().output_is_position_independent()
2846 && !gsym
->is_forced_local()))
2848 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2850 // If this symbol is forced local, this relocation will
2851 // not work properly. That's because ld.so on sparc
2852 // (and 32-bit powerpc) expects st_value in the r_addend
2853 // of relocations for STB_LOCAL symbols. Curiously the
2854 // BFD linker does not promote global hidden symbols to be
2855 // STB_LOCAL in the dynamic symbol table like Gold does.
2856 gold_assert(!gsym
->is_forced_local());
2857 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2860 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2862 unsigned int off
= got
->add_constant(0);
2864 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2867 // Tell the dynamic linker to use the PLT address
2868 // when resolving relocations.
2869 if (gsym
->is_from_dynobj()
2870 && !parameters
->options().shared())
2871 gsym
->set_needs_dynsym_value();
2873 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2874 got
, off
, 0, is_ifunc
);
2880 // These are initial tls relocs, which are expected when
2882 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2883 case elfcpp::R_SPARC_TLS_GD_LO10
:
2884 case elfcpp::R_SPARC_TLS_GD_ADD
:
2885 case elfcpp::R_SPARC_TLS_GD_CALL
:
2886 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2887 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2888 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2889 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2890 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2891 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2892 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2893 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2894 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2895 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2896 case elfcpp::R_SPARC_TLS_IE_LO10
:
2897 case elfcpp::R_SPARC_TLS_IE_LD
:
2898 case elfcpp::R_SPARC_TLS_IE_LDX
:
2899 case elfcpp::R_SPARC_TLS_IE_ADD
:
2901 const bool is_final
= gsym
->final_value_is_known();
2902 const tls::Tls_optimization optimized_type
2903 = optimize_tls_reloc(is_final
, r_type
);
2906 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2907 case elfcpp::R_SPARC_TLS_GD_LO10
:
2908 case elfcpp::R_SPARC_TLS_GD_ADD
:
2909 case elfcpp::R_SPARC_TLS_GD_CALL
:
2910 if (optimized_type
== tls::TLSOPT_NONE
)
2912 // Create a pair of GOT entries for the module index and
2913 // dtv-relative offset.
2914 Output_data_got
<size
, big_endian
>* got
2915 = target
->got_section(symtab
, layout
);
2916 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2917 target
->rela_dyn_section(layout
),
2919 ? elfcpp::R_SPARC_TLS_DTPMOD64
2920 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2922 ? elfcpp::R_SPARC_TLS_DTPOFF64
2923 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2925 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2926 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2927 generate_tls_call(symtab
, layout
, target
);
2929 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2931 // Create a GOT entry for the tp-relative offset.
2932 Output_data_got
<size
, big_endian
>* got
2933 = target
->got_section(symtab
, layout
);
2934 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2935 target
->rela_dyn_section(layout
),
2937 elfcpp::R_SPARC_TLS_TPOFF64
:
2938 elfcpp::R_SPARC_TLS_TPOFF32
));
2940 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2941 unsupported_reloc_global(object
, r_type
, gsym
);
2944 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2945 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2946 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2947 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2948 if (optimized_type
== tls::TLSOPT_NONE
)
2950 // Create a GOT entry for the module index.
2951 target
->got_mod_index_entry(symtab
, layout
, object
);
2953 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2954 generate_tls_call(symtab
, layout
, target
);
2956 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2957 unsupported_reloc_global(object
, r_type
, gsym
);
2960 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2961 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2962 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2965 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2966 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2967 layout
->set_has_static_tls();
2968 if (parameters
->options().shared())
2970 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2971 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2972 output_section
, object
,
2973 data_shndx
, reloc
.get_r_offset(),
2978 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2979 case elfcpp::R_SPARC_TLS_IE_LO10
:
2980 case elfcpp::R_SPARC_TLS_IE_LD
:
2981 case elfcpp::R_SPARC_TLS_IE_LDX
:
2982 case elfcpp::R_SPARC_TLS_IE_ADD
:
2983 layout
->set_has_static_tls();
2984 if (optimized_type
== tls::TLSOPT_NONE
)
2986 // Create a GOT entry for the tp-relative offset.
2987 Output_data_got
<size
, big_endian
>* got
2988 = target
->got_section(symtab
, layout
);
2989 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2990 target
->rela_dyn_section(layout
),
2992 ? elfcpp::R_SPARC_TLS_TPOFF64
2993 : elfcpp::R_SPARC_TLS_TPOFF32
));
2995 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2996 unsupported_reloc_global(object
, r_type
, gsym
);
3002 // These are relocations which should only be seen by the
3003 // dynamic linker, and should never be seen here.
3004 case elfcpp::R_SPARC_COPY
:
3005 case elfcpp::R_SPARC_GLOB_DAT
:
3006 case elfcpp::R_SPARC_JMP_SLOT
:
3007 case elfcpp::R_SPARC_JMP_IREL
:
3008 case elfcpp::R_SPARC_RELATIVE
:
3009 case elfcpp::R_SPARC_IRELATIVE
:
3010 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3011 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3012 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3013 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3014 case elfcpp::R_SPARC_TLS_TPOFF64
:
3015 case elfcpp::R_SPARC_TLS_TPOFF32
:
3016 gold_error(_("%s: unexpected reloc %u in object file"),
3017 object
->name().c_str(), r_type
);
3021 unsupported_reloc_global(object
, r_type
, gsym
);
3026 // Process relocations for gc.
3028 template<int size
, bool big_endian
>
3030 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3031 Symbol_table
* symtab
,
3033 Sized_relobj_file
<size
, big_endian
>* object
,
3034 unsigned int data_shndx
,
3036 const unsigned char* prelocs
,
3038 Output_section
* output_section
,
3039 bool needs_special_offset_handling
,
3040 size_t local_symbol_count
,
3041 const unsigned char* plocal_symbols
)
3043 typedef Target_sparc
<size
, big_endian
> Sparc
;
3044 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3045 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
3048 gold::gc_process_relocs
<size
, big_endian
, Sparc
, Scan
, Classify_reloc
>(
3057 needs_special_offset_handling
,
3062 // Scan relocations for a section.
3064 template<int size
, bool big_endian
>
3066 Target_sparc
<size
, big_endian
>::scan_relocs(
3067 Symbol_table
* symtab
,
3069 Sized_relobj_file
<size
, big_endian
>* object
,
3070 unsigned int data_shndx
,
3071 unsigned int sh_type
,
3072 const unsigned char* prelocs
,
3074 Output_section
* output_section
,
3075 bool needs_special_offset_handling
,
3076 size_t local_symbol_count
,
3077 const unsigned char* plocal_symbols
)
3079 typedef Target_sparc
<size
, big_endian
> Sparc
;
3080 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
3083 if (sh_type
== elfcpp::SHT_REL
)
3085 gold_error(_("%s: unsupported REL reloc section"),
3086 object
->name().c_str());
3090 gold::scan_relocs
<size
, big_endian
, Sparc
, Scan
, Classify_reloc
>(
3099 needs_special_offset_handling
,
3104 // Finalize the sections.
3106 template<int size
, bool big_endian
>
3108 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3110 const Input_objects
*,
3111 Symbol_table
* symtab
)
3114 this->plt_
->emit_pending_ifunc_relocs();
3116 // Fill in some more dynamic tags.
3117 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3119 : this->plt_
->rel_plt());
3120 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3121 this->rela_dyn_
, true, true);
3123 // Emit any relocs we saved in an attempt to avoid generating COPY
3125 if (this->copy_relocs_
.any_saved_relocs())
3126 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3128 if (parameters
->doing_static_link()
3129 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3131 // If linking statically, make sure that the __rela_iplt symbols
3132 // were defined if necessary, even if we didn't create a PLT.
3133 static const Define_symbol_in_segment syms
[] =
3136 "__rela_iplt_start", // name
3137 elfcpp::PT_LOAD
, // segment_type
3138 elfcpp::PF_W
, // segment_flags_set
3139 elfcpp::PF(0), // segment_flags_clear
3142 elfcpp::STT_NOTYPE
, // type
3143 elfcpp::STB_GLOBAL
, // binding
3144 elfcpp::STV_HIDDEN
, // visibility
3146 Symbol::SEGMENT_START
, // offset_from_base
3150 "__rela_iplt_end", // name
3151 elfcpp::PT_LOAD
, // segment_type
3152 elfcpp::PF_W
, // segment_flags_set
3153 elfcpp::PF(0), // segment_flags_clear
3156 elfcpp::STT_NOTYPE
, // type
3157 elfcpp::STB_GLOBAL
, // binding
3158 elfcpp::STV_HIDDEN
, // visibility
3160 Symbol::SEGMENT_START
, // offset_from_base
3165 symtab
->define_symbols(layout
, 2, syms
,
3166 layout
->script_options()->saw_sections_clause());
3170 // Perform a relocation.
3172 template<int size
, bool big_endian
>
3174 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3175 const Relocate_info
<size
, big_endian
>* relinfo
,
3177 Target_sparc
* target
,
3180 const unsigned char* preloc
,
3181 const Sized_symbol
<size
>* gsym
,
3182 const Symbol_value
<size
>* psymval
,
3183 unsigned char* view
,
3184 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3185 section_size_type view_size
)
3187 const elfcpp::Rela
<size
, big_endian
> rela(preloc
);
3188 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
3189 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3192 if (this->ignore_gd_add_
)
3194 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3195 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3196 _("missing expected TLS relocation"));
3199 this->ignore_gd_add_
= false;
3207 if (this->reloc_adjust_addr_
== view
)
3210 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3211 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3213 // Pick the value to use for symbols defined in shared objects.
3214 Symbol_value
<size
> symval
;
3216 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3218 elfcpp::Elf_Xword value
;
3220 value
= target
->plt_address_for_global(gsym
);
3222 symval
.set_output_value(value
);
3226 else if (gsym
== NULL
&& orig_is_ifunc
)
3228 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3229 if (object
->local_has_plt_offset(r_sym
))
3231 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
));
3236 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3238 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3239 // pointer points to the beginning, not the end, of the table.
3240 // So we just use the plain offset.
3241 unsigned int got_offset
= 0;
3242 bool gdop_valid
= false;
3245 case elfcpp::R_SPARC_GOTDATA_OP
:
3246 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3247 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3248 // If this is local, we did not create a GOT entry because we
3249 // intend to transform this into a GOT relative relocation.
3251 || (gsym
->is_defined()
3252 && !gsym
->is_from_dynobj()
3253 && !gsym
->is_preemptible()
3256 got_offset
= psymval
->value(object
, addend
) - target
->got_address();
3260 case elfcpp::R_SPARC_GOT10
:
3261 case elfcpp::R_SPARC_GOT13
:
3262 case elfcpp::R_SPARC_GOT22
:
3265 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3266 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3270 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3271 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3272 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3282 case elfcpp::R_SPARC_NONE
:
3283 case elfcpp::R_SPARC_REGISTER
:
3284 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3285 case elfcpp::R_SPARC_GNU_VTENTRY
:
3288 case elfcpp::R_SPARC_8
:
3289 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3293 case elfcpp::R_SPARC_16
:
3294 if (rela
.get_r_offset() & 0x1)
3296 // The assembler can sometimes emit unaligned relocations
3297 // for dwarf2 cfi directives.
3298 Reloc::ua16(view
, object
, psymval
, addend
);
3301 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3305 case elfcpp::R_SPARC_32
:
3306 if (!parameters
->options().output_is_position_independent())
3308 if (rela
.get_r_offset() & 0x3)
3310 // The assembler can sometimes emit unaligned relocations
3311 // for dwarf2 cfi directives.
3312 Reloc::ua32(view
, object
, psymval
, addend
);
3315 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3320 case elfcpp::R_SPARC_DISP8
:
3321 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3324 case elfcpp::R_SPARC_DISP16
:
3325 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3328 case elfcpp::R_SPARC_DISP32
:
3329 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3332 case elfcpp::R_SPARC_DISP64
:
3333 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3336 case elfcpp::R_SPARC_WDISP30
:
3337 case elfcpp::R_SPARC_WPLT30
:
3338 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3339 if (target
->may_relax())
3340 relax_call(target
, view
, rela
, view_size
);
3343 case elfcpp::R_SPARC_WDISP22
:
3344 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3347 case elfcpp::R_SPARC_WDISP19
:
3348 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3351 case elfcpp::R_SPARC_WDISP16
:
3352 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3355 case elfcpp::R_SPARC_WDISP10
:
3356 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3359 case elfcpp::R_SPARC_HI22
:
3360 Reloc::hi22(view
, object
, psymval
, addend
);
3363 case elfcpp::R_SPARC_22
:
3364 Reloc::rela32_22(view
, object
, psymval
, addend
);
3367 case elfcpp::R_SPARC_13
:
3368 Reloc::rela32_13(view
, object
, psymval
, addend
);
3371 case elfcpp::R_SPARC_LO10
:
3372 Reloc::lo10(view
, object
, psymval
, addend
);
3375 case elfcpp::R_SPARC_GOT10
:
3376 Reloc::lo10(view
, got_offset
, addend
);
3379 case elfcpp::R_SPARC_GOTDATA_OP
:
3382 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3383 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3386 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3387 val
= elfcpp::Swap
<32, true>::readval(wv
);
3388 val
= 0x80000000 | (val
& 0x3e07c01f);
3389 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3393 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3396 Reloc::gdop_lox10(view
, got_offset
);
3400 case elfcpp::R_SPARC_GOT13
:
3401 Reloc::rela32_13(view
, got_offset
, addend
);
3404 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3407 Reloc::gdop_hix22(view
, got_offset
);
3411 case elfcpp::R_SPARC_GOT22
:
3412 Reloc::hi22(view
, got_offset
, addend
);
3415 case elfcpp::R_SPARC_PC10
:
3416 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3419 case elfcpp::R_SPARC_PC22
:
3420 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3423 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3424 case elfcpp::R_SPARC_UA32
:
3425 Reloc::ua32(view
, object
, psymval
, addend
);
3428 case elfcpp::R_SPARC_PLT64
:
3429 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3433 case elfcpp::R_SPARC_PLT32
:
3434 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3438 case elfcpp::R_SPARC_HIPLT22
:
3439 Reloc::hi22(view
, object
, psymval
, addend
);
3442 case elfcpp::R_SPARC_LOPLT10
:
3443 Reloc::lo10(view
, object
, psymval
, addend
);
3446 case elfcpp::R_SPARC_PCPLT32
:
3447 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3450 case elfcpp::R_SPARC_PCPLT22
:
3451 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3454 case elfcpp::R_SPARC_PCPLT10
:
3455 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3458 case elfcpp::R_SPARC_64
:
3459 if (!parameters
->options().output_is_position_independent())
3461 if (rela
.get_r_offset() & 0x7)
3463 // The assembler can sometimes emit unaligned relocations
3464 // for dwarf2 cfi directives.
3465 Reloc::ua64(view
, object
, psymval
, addend
);
3468 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3473 case elfcpp::R_SPARC_OLO10
:
3475 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3476 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3477 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3481 case elfcpp::R_SPARC_HH22
:
3482 Reloc::hh22(view
, object
, psymval
, addend
);
3485 case elfcpp::R_SPARC_PC_HH22
:
3486 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3489 case elfcpp::R_SPARC_HM10
:
3490 Reloc::hm10(view
, object
, psymval
, addend
);
3493 case elfcpp::R_SPARC_PC_HM10
:
3494 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3497 case elfcpp::R_SPARC_LM22
:
3498 Reloc::hi22(view
, object
, psymval
, addend
);
3501 case elfcpp::R_SPARC_PC_LM22
:
3502 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3505 case elfcpp::R_SPARC_11
:
3506 Reloc::rela32_11(view
, object
, psymval
, addend
);
3509 case elfcpp::R_SPARC_10
:
3510 Reloc::rela32_10(view
, object
, psymval
, addend
);
3513 case elfcpp::R_SPARC_7
:
3514 Reloc::rela32_7(view
, object
, psymval
, addend
);
3517 case elfcpp::R_SPARC_6
:
3518 Reloc::rela32_6(view
, object
, psymval
, addend
);
3521 case elfcpp::R_SPARC_5
:
3522 Reloc::rela32_5(view
, object
, psymval
, addend
);
3525 case elfcpp::R_SPARC_HIX22
:
3526 Reloc::hix22(view
, object
, psymval
, addend
);
3529 case elfcpp::R_SPARC_LOX10
:
3530 Reloc::lox10(view
, object
, psymval
, addend
);
3533 case elfcpp::R_SPARC_H34
:
3534 Reloc::h34(view
, object
, psymval
, addend
);
3537 case elfcpp::R_SPARC_H44
:
3538 Reloc::h44(view
, object
, psymval
, addend
);
3541 case elfcpp::R_SPARC_M44
:
3542 Reloc::m44(view
, object
, psymval
, addend
);
3545 case elfcpp::R_SPARC_L44
:
3546 Reloc::l44(view
, object
, psymval
, addend
);
3549 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3550 case elfcpp::R_SPARC_UA64
:
3551 Reloc::ua64(view
, object
, psymval
, addend
);
3554 case elfcpp::R_SPARC_UA16
:
3555 Reloc::ua16(view
, object
, psymval
, addend
);
3558 case elfcpp::R_SPARC_TLS_GD_HI22
:
3559 case elfcpp::R_SPARC_TLS_GD_LO10
:
3560 case elfcpp::R_SPARC_TLS_GD_ADD
:
3561 case elfcpp::R_SPARC_TLS_GD_CALL
:
3562 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3563 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3564 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3565 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3566 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3567 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3568 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3569 case elfcpp::R_SPARC_TLS_IE_HI22
:
3570 case elfcpp::R_SPARC_TLS_IE_LO10
:
3571 case elfcpp::R_SPARC_TLS_IE_LD
:
3572 case elfcpp::R_SPARC_TLS_IE_LDX
:
3573 case elfcpp::R_SPARC_TLS_IE_ADD
:
3574 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3575 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3576 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3577 r_type
, gsym
, psymval
, view
,
3578 address
, view_size
);
3581 case elfcpp::R_SPARC_COPY
:
3582 case elfcpp::R_SPARC_GLOB_DAT
:
3583 case elfcpp::R_SPARC_JMP_SLOT
:
3584 case elfcpp::R_SPARC_JMP_IREL
:
3585 case elfcpp::R_SPARC_RELATIVE
:
3586 case elfcpp::R_SPARC_IRELATIVE
:
3587 // These are outstanding tls relocs, which are unexpected when
3589 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3590 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3591 case elfcpp::R_SPARC_TLS_TPOFF64
:
3592 case elfcpp::R_SPARC_TLS_TPOFF32
:
3593 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3594 _("unexpected reloc %u in object file"),
3599 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3600 _("unsupported reloc %u"),
3608 // Perform a TLS relocation.
3610 template<int size
, bool big_endian
>
3612 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3613 const Relocate_info
<size
, big_endian
>* relinfo
,
3614 Target_sparc
<size
, big_endian
>* target
,
3616 const elfcpp::Rela
<size
, big_endian
>& rela
,
3617 unsigned int r_type
,
3618 const Sized_symbol
<size
>* gsym
,
3619 const Symbol_value
<size
>* psymval
,
3620 unsigned char* view
,
3621 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3624 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3625 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3626 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3627 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3629 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3630 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3632 const bool is_final
=
3634 ? !parameters
->options().output_is_position_independent()
3635 : gsym
->final_value_is_known());
3636 const tls::Tls_optimization optimized_type
3637 = optimize_tls_reloc(is_final
, r_type
);
3641 case elfcpp::R_SPARC_TLS_GD_HI22
:
3642 case elfcpp::R_SPARC_TLS_GD_LO10
:
3643 case elfcpp::R_SPARC_TLS_GD_ADD
:
3644 case elfcpp::R_SPARC_TLS_GD_CALL
:
3645 if (optimized_type
== tls::TLSOPT_TO_LE
)
3647 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3650 value
-= tls_segment
->memsz();
3654 case elfcpp::R_SPARC_TLS_GD_HI22
:
3655 // TLS_GD_HI22 --> TLS_LE_HIX22
3656 Reloc::hix22(view
, value
, addend
);
3659 case elfcpp::R_SPARC_TLS_GD_LO10
:
3660 // TLS_GD_LO10 --> TLS_LE_LOX10
3661 Reloc::lox10(view
, value
, addend
);
3664 case elfcpp::R_SPARC_TLS_GD_ADD
:
3665 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3666 val
= elfcpp::Swap
<32, true>::readval(wv
);
3667 val
= (val
& ~0x7c000) | 0x1c000;
3668 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3670 case elfcpp::R_SPARC_TLS_GD_CALL
:
3671 // call __tls_get_addr --> nop
3672 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3679 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3680 ? GOT_TYPE_TLS_OFFSET
3681 : GOT_TYPE_TLS_PAIR
);
3684 gold_assert(gsym
->has_got_offset(got_type
));
3685 value
= gsym
->got_offset(got_type
);
3689 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3690 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3691 value
= object
->local_got_offset(r_sym
, got_type
);
3693 if (optimized_type
== tls::TLSOPT_TO_IE
)
3695 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3700 case elfcpp::R_SPARC_TLS_GD_HI22
:
3701 // TLS_GD_HI22 --> TLS_IE_HI22
3702 Reloc::hi22(view
, value
, addend
);
3705 case elfcpp::R_SPARC_TLS_GD_LO10
:
3706 // TLS_GD_LO10 --> TLS_IE_LO10
3707 Reloc::lo10(view
, value
, addend
);
3710 case elfcpp::R_SPARC_TLS_GD_ADD
:
3711 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3712 val
= elfcpp::Swap
<32, true>::readval(wv
);
3719 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3722 case elfcpp::R_SPARC_TLS_GD_CALL
:
3723 // The compiler can put the TLS_GD_ADD instruction
3724 // into the delay slot of the call. If so, we need
3725 // to transpose the two instructions so that the
3726 // new sequence works properly.
3728 // The test we use is if the instruction in the
3729 // delay slot is an add with destination register
3731 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3732 if ((val
& 0x81f80000) == 0x80000000
3733 && ((val
>> 25) & 0x1f) == 0x8)
3740 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3743 this->ignore_gd_add_
= true;
3747 // Even if the delay slot isn't the TLS_GD_ADD
3748 // instruction, we still have to handle the case
3749 // where it sets up %o0 in some other way.
3750 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3752 this->reloc_adjust_addr_
= view
+ 4;
3754 // call __tls_get_addr --> add %g7, %o0, %o0
3755 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3760 else if (optimized_type
== tls::TLSOPT_NONE
)
3764 case elfcpp::R_SPARC_TLS_GD_HI22
:
3765 Reloc::hi22(view
, value
, addend
);
3767 case elfcpp::R_SPARC_TLS_GD_LO10
:
3768 Reloc::lo10(view
, value
, addend
);
3770 case elfcpp::R_SPARC_TLS_GD_ADD
:
3772 case elfcpp::R_SPARC_TLS_GD_CALL
:
3774 Symbol_value
<size
> symval
;
3775 elfcpp::Elf_Xword value
;
3778 tsym
= target
->tls_get_addr_sym_
;
3780 value
= (target
->plt_section()->address() +
3781 tsym
->plt_offset());
3782 symval
.set_output_value(value
);
3783 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3790 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3791 _("unsupported reloc %u"),
3795 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3796 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3797 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3798 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3799 if (optimized_type
== tls::TLSOPT_TO_LE
)
3801 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3805 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3806 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3807 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3808 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3811 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3812 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3817 else if (optimized_type
== tls::TLSOPT_NONE
)
3819 // Relocate the field with the offset of the GOT entry for
3820 // the module index.
3821 unsigned int got_offset
;
3823 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3826 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3827 Reloc::hi22(view
, got_offset
, addend
);
3829 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3830 Reloc::lo10(view
, got_offset
, addend
);
3832 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3834 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3836 Symbol_value
<size
> symval
;
3837 elfcpp::Elf_Xword value
;
3840 tsym
= target
->tls_get_addr_sym_
;
3842 value
= (target
->plt_section()->address() +
3843 tsym
->plt_offset());
3844 symval
.set_output_value(value
);
3845 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3851 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3852 _("unsupported reloc %u"),
3856 // These relocs can appear in debugging sections, in which case
3857 // we won't see the TLS_LDM relocs. The local_dynamic_type
3858 // field tells us this.
3859 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3860 if (optimized_type
== tls::TLSOPT_TO_LE
)
3862 value
-= tls_segment
->memsz();
3863 Reloc::hix22(view
, value
, addend
);
3866 Reloc::ldo_hix22(view
, value
, addend
);
3868 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3869 if (optimized_type
== tls::TLSOPT_TO_LE
)
3871 value
-= tls_segment
->memsz();
3872 Reloc::lox10(view
, value
, addend
);
3875 Reloc::ldo_lox10(view
, value
, addend
);
3877 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3878 if (optimized_type
== tls::TLSOPT_TO_LE
)
3880 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3883 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3884 val
= elfcpp::Swap
<32, true>::readval(wv
);
3885 val
= (val
& ~0x7c000) | 0x1c000;
3886 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3890 // When optimizing IE --> LE, the only relocation that is handled
3891 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3892 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3893 // rs2 and rd are the same.
3894 case elfcpp::R_SPARC_TLS_IE_LD
:
3895 case elfcpp::R_SPARC_TLS_IE_LDX
:
3896 if (optimized_type
== tls::TLSOPT_TO_LE
)
3898 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3899 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3900 Insntype rs2
= val
& 0x1f;
3901 Insntype rd
= (val
>> 25) & 0x1f;
3906 val
= sparc_mov
| (val
& 0x3e00001f);
3908 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3912 case elfcpp::R_SPARC_TLS_IE_HI22
:
3913 case elfcpp::R_SPARC_TLS_IE_LO10
:
3914 if (optimized_type
== tls::TLSOPT_TO_LE
)
3916 value
-= tls_segment
->memsz();
3919 case elfcpp::R_SPARC_TLS_IE_HI22
:
3920 // IE_HI22 --> LE_HIX22
3921 Reloc::hix22(view
, value
, addend
);
3923 case elfcpp::R_SPARC_TLS_IE_LO10
:
3924 // IE_LO10 --> LE_LOX10
3925 Reloc::lox10(view
, value
, addend
);
3930 else if (optimized_type
== tls::TLSOPT_NONE
)
3932 // Relocate the field with the offset of the GOT entry for
3933 // the tp-relative offset of the symbol.
3936 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3937 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3941 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3942 gold_assert(object
->local_has_got_offset(r_sym
,
3943 GOT_TYPE_TLS_OFFSET
));
3944 value
= object
->local_got_offset(r_sym
,
3945 GOT_TYPE_TLS_OFFSET
);
3949 case elfcpp::R_SPARC_TLS_IE_HI22
:
3950 Reloc::hi22(view
, value
, addend
);
3952 case elfcpp::R_SPARC_TLS_IE_LO10
:
3953 Reloc::lo10(view
, value
, addend
);
3958 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3959 _("unsupported reloc %u"),
3963 case elfcpp::R_SPARC_TLS_IE_ADD
:
3964 // This seems to be mainly so that we can find the addition
3965 // instruction if there is one. There doesn't seem to be any
3966 // actual relocation to apply.
3969 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3970 // If we're creating a shared library, a dynamic relocation will
3971 // have been created for this location, so do not apply it now.
3972 if (!parameters
->options().shared())
3974 value
-= tls_segment
->memsz();
3975 Reloc::hix22(view
, value
, addend
);
3979 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3980 // If we're creating a shared library, a dynamic relocation will
3981 // have been created for this location, so do not apply it now.
3982 if (!parameters
->options().shared())
3984 value
-= tls_segment
->memsz();
3985 Reloc::lox10(view
, value
, addend
);
3991 // Relax a call instruction.
3993 template<int size
, bool big_endian
>
3995 Target_sparc
<size
, big_endian
>::Relocate::relax_call(
3996 Target_sparc
<size
, big_endian
>* target
,
3997 unsigned char* view
,
3998 const elfcpp::Rela
<size
, big_endian
>& rela
,
3999 section_size_type view_size
)
4001 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
4002 Insntype
*wv
= reinterpret_cast<Insntype
*>(view
);
4003 Insntype call_insn
, delay_insn
, set_insn
;
4004 uint32_t op3
, reg
, off
;
4006 // This code tries to relax call instructions that meet
4007 // certain criteria.
4009 // The first criteria is that the call must be such that the return
4010 // address which the call writes into %o7 is unused. Two sequences
4011 // meet this criteria, and are used to implement tail calls.
4013 // Leaf function tail call:
4015 // or %o7, %g0, %ANY_REG
4017 // or %ANY_REG, %g0, %o7
4019 // Non-leaf function tail call:
4024 // The second criteria is that the call destination is close. If
4025 // the displacement can fit in a signed 22-bit immediate field of a
4026 // pre-V9 branch, we can do it. If we are generating a 64-bit
4027 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4028 // and the displacement fits in a signed 19-bit immediate field,
4029 // then we can use a V9 branch.
4031 // Make sure the delay instruction can be safely accessed.
4032 if (rela
.get_r_offset() + 8 > view_size
)
4035 call_insn
= elfcpp::Swap
<32, true>::readval(wv
);
4036 delay_insn
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
4038 // Make sure it is really a call instruction.
4039 if (((call_insn
>> 30) & 0x3) != 1)
4042 if (((delay_insn
>> 30) & 0x3) != 2)
4045 // Accept only a restore or an integer arithmetic operation whose
4046 // sole side effect is to write the %o7 register (and perhaps set
4047 // the condition codes, which are considered clobbered across
4050 // For example, we don't want to match a tagged addition or
4051 // subtraction. We also don't want to match something like a
4054 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4055 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4057 op3
= (delay_insn
>> 19) & 0x3f;
4058 reg
= (delay_insn
>> 25) & 0x1f;
4060 && ((op3
& 0x28) != 0 || reg
!= 15))
4063 // For non-restore instructions, make sure %o7 isn't
4068 reg
= (delay_insn
>> 14) & 0x15;
4072 // And if non-immediate, check RS2
4073 if (((delay_insn
>> 13) & 1) == 0)
4075 reg
= (delay_insn
& 0x1f);
4081 // Now check the branch distance. We are called after the
4082 // call has been relocated, so we just have to peek at the
4083 // offset contained in the instruction.
4084 off
= call_insn
& 0x3fffffff;
4085 if ((off
& 0x3fe00000) != 0
4086 && (off
& 0x3fe00000) != 0x3fe00000)
4089 if ((size
== 64 || target
->elf_machine_
== elfcpp::EM_SPARC32PLUS
)
4090 && ((off
& 0x3c0000) == 0
4091 || (off
& 0x3c0000) == 0x3c0000))
4094 call_insn
= 0x10680000 | (off
& 0x07ffff);
4099 call_insn
= 0x10800000 | (off
& 0x3fffff);
4101 elfcpp::Swap
<32, true>::writeval(wv
, call_insn
);
4103 // See if we can NOP out the delay slot instruction. We peek
4104 // at the instruction before the call to make sure we're dealing
4105 // with exactly the:
4107 // or %o7, %g0, %ANY_REG
4109 // or %ANY_REG, %g0, %o7
4111 // case. Otherwise this might be a tricky piece of hand written
4112 // assembler calculating %o7 in some non-trivial way, and therefore
4113 // we can't be sure that NOP'ing out the delay slot is safe.
4115 && rela
.get_r_offset() >= 4)
4117 if ((delay_insn
& ~(0x1f << 14)) != 0x9e100000)
4120 set_insn
= elfcpp::Swap
<32, true>::readval(wv
- 1);
4121 if ((set_insn
& ~(0x1f << 25)) != 0x8013c000)
4124 reg
= (set_insn
>> 25) & 0x1f;
4125 if (reg
== 0 || reg
== 15)
4127 if (reg
!= ((delay_insn
>> 14) & 0x1f))
4130 // All tests pass, nop it out.
4131 elfcpp::Swap
<32, true>::writeval(wv
+ 1, sparc_nop
);
4135 // Relocate section data.
4137 template<int size
, bool big_endian
>
4139 Target_sparc
<size
, big_endian
>::relocate_section(
4140 const Relocate_info
<size
, big_endian
>* relinfo
,
4141 unsigned int sh_type
,
4142 const unsigned char* prelocs
,
4144 Output_section
* output_section
,
4145 bool needs_special_offset_handling
,
4146 unsigned char* view
,
4147 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4148 section_size_type view_size
,
4149 const Reloc_symbol_changes
* reloc_symbol_changes
)
4151 typedef Target_sparc
<size
, big_endian
> Sparc
;
4152 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
4153 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
4156 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4158 gold::relocate_section
<size
, big_endian
, Sparc
, Sparc_relocate
,
4159 gold::Default_comdat_behavior
, Classify_reloc
>(
4165 needs_special_offset_handling
,
4169 reloc_symbol_changes
);
4172 // Scan the relocs during a relocatable link.
4174 template<int size
, bool big_endian
>
4176 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4177 Symbol_table
* symtab
,
4179 Sized_relobj_file
<size
, big_endian
>* object
,
4180 unsigned int data_shndx
,
4181 unsigned int sh_type
,
4182 const unsigned char* prelocs
,
4184 Output_section
* output_section
,
4185 bool needs_special_offset_handling
,
4186 size_t local_symbol_count
,
4187 const unsigned char* plocal_symbols
,
4188 Relocatable_relocs
* rr
)
4190 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
4192 typedef gold::Default_scan_relocatable_relocs
<Classify_reloc
>
4193 Scan_relocatable_relocs
;
4195 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4197 gold::scan_relocatable_relocs
<size
, big_endian
, Scan_relocatable_relocs
>(
4205 needs_special_offset_handling
,
4211 // Scan the relocs for --emit-relocs.
4213 template<int size
, bool big_endian
>
4215 Target_sparc
<size
, big_endian
>::emit_relocs_scan(
4216 Symbol_table
* symtab
,
4218 Sized_relobj_file
<size
, big_endian
>* object
,
4219 unsigned int data_shndx
,
4220 unsigned int sh_type
,
4221 const unsigned char* prelocs
,
4223 Output_section
* output_section
,
4224 bool needs_special_offset_handling
,
4225 size_t local_symbol_count
,
4226 const unsigned char* plocal_syms
,
4227 Relocatable_relocs
* rr
)
4229 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
4231 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
4232 Emit_relocs_strategy
;
4234 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4236 gold::scan_relocatable_relocs
<size
, big_endian
, Emit_relocs_strategy
>(
4244 needs_special_offset_handling
,
4250 // Emit relocations for a section.
4252 template<int size
, bool big_endian
>
4254 Target_sparc
<size
, big_endian
>::relocate_relocs(
4255 const Relocate_info
<size
, big_endian
>* relinfo
,
4256 unsigned int sh_type
,
4257 const unsigned char* prelocs
,
4259 Output_section
* output_section
,
4260 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
4261 unsigned char* view
,
4262 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4263 section_size_type view_size
,
4264 unsigned char* reloc_view
,
4265 section_size_type reloc_view_size
)
4267 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, big_endian
>
4270 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4272 gold::relocate_relocs
<size
, big_endian
, Classify_reloc
>(
4277 offset_in_output_section
,
4285 // Return the value to use for a dynamic which requires special
4286 // treatment. This is how we support equality comparisons of function
4287 // pointers across shared library boundaries, as described in the
4288 // processor specific ABI supplement.
4290 template<int size
, bool big_endian
>
4292 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4294 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4295 return this->plt_section()->address() + gsym
->plt_offset();
4298 // do_make_elf_object to override the same function in the base class.
4299 // We need to use a target-specific sub-class of
4300 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4301 // of the ELF headers. Hence we need to have our own ELF object creation.
4303 template<int size
, bool big_endian
>
4305 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4306 const std::string
& name
,
4307 Input_file
* input_file
,
4308 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4310 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4311 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4312 elfcpp::Elf_Word omm
, mm
;
4316 case elfcpp::EM_SPARC32PLUS
:
4317 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4320 case elfcpp::EM_SPARC
:
4321 case elfcpp::EM_SPARCV9
:
4328 if (!this->elf_flags_set_
)
4330 this->elf_flags_
= flags
;
4331 this->elf_flags_set_
= true;
4335 // Accumulate cpu feature bits.
4336 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4337 | elfcpp::EF_SPARC_SUN_US1
4338 | elfcpp::EF_SPARC_HAL_R1
4339 | elfcpp::EF_SPARC_SUN_US3
));
4341 // Bump the memory model setting to the most restrictive
4342 // one we encounter.
4343 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4344 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4347 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4349 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4350 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4352 else if (mm
== elfcpp::EF_SPARCV9_PSO
4353 && omm
== elfcpp::EF_SPARCV9_RMO
)
4355 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4356 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4361 // Validate that the little-endian flag matches how we've
4362 // been instantiated.
4363 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4366 gold_error(_("%s: little endian elf flag set on BE object"),
4369 gold_error(_("%s: little endian elf flag clear on LE object"),
4373 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4376 // Adjust ELF file header.
4378 template<int size
, bool big_endian
>
4380 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4381 unsigned char* view
,
4384 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4386 oehdr
.put_e_machine(this->elf_machine_
);
4387 oehdr
.put_e_flags(this->elf_flags_
);
4389 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4392 // The selector for sparc object files.
4394 template<int size
, bool big_endian
>
4395 class Target_selector_sparc
: public Target_selector
4398 Target_selector_sparc()
4399 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4400 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4401 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4405 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4410 if (machine
!= elfcpp::EM_SPARCV9
)
4415 if (machine
!= elfcpp::EM_SPARC
4416 && machine
!= elfcpp::EM_SPARC32PLUS
)
4424 return this->instantiate_target();
4428 do_instantiate_target()
4429 { return new Target_sparc
<size
, big_endian
>(); }
4432 Target_selector_sparc
<32, true> target_selector_sparc32
;
4433 Target_selector_sparc
<64, true> target_selector_sparc64
;
4435 } // End anonymous namespace.