1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
),
64 elf_machine_(sparc_info
.machine_code
), elf_flags_(0),
69 // Process the relocations to determine unreferenced sections for
70 // garbage collection.
72 gc_process_relocs(Symbol_table
* symtab
,
74 Sized_relobj_file
<size
, big_endian
>* object
,
75 unsigned int data_shndx
,
77 const unsigned char* prelocs
,
79 Output_section
* output_section
,
80 bool needs_special_offset_handling
,
81 size_t local_symbol_count
,
82 const unsigned char* plocal_symbols
);
84 // Scan the relocations to look for symbol adjustments.
86 scan_relocs(Symbol_table
* symtab
,
88 Sized_relobj_file
<size
, big_endian
>* object
,
89 unsigned int data_shndx
,
91 const unsigned char* prelocs
,
93 Output_section
* output_section
,
94 bool needs_special_offset_handling
,
95 size_t local_symbol_count
,
96 const unsigned char* plocal_symbols
);
97 // Finalize the sections.
99 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
101 // Return the value to use for a dynamic which requires special
104 do_dynsym_value(const Symbol
*) const;
106 // Relocate a section.
108 relocate_section(const Relocate_info
<size
, big_endian
>*,
109 unsigned int sh_type
,
110 const unsigned char* prelocs
,
112 Output_section
* output_section
,
113 bool needs_special_offset_handling
,
115 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
116 section_size_type view_size
,
117 const Reloc_symbol_changes
*);
119 // Scan the relocs during a relocatable link.
121 scan_relocatable_relocs(Symbol_table
* symtab
,
123 Sized_relobj_file
<size
, big_endian
>* object
,
124 unsigned int data_shndx
,
125 unsigned int sh_type
,
126 const unsigned char* prelocs
,
128 Output_section
* output_section
,
129 bool needs_special_offset_handling
,
130 size_t local_symbol_count
,
131 const unsigned char* plocal_symbols
,
132 Relocatable_relocs
*);
134 // Relocate a section during a relocatable link.
136 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
137 unsigned int sh_type
,
138 const unsigned char* prelocs
,
140 Output_section
* output_section
,
141 off_t offset_in_output_section
,
142 const Relocatable_relocs
*,
144 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
145 section_size_type view_size
,
146 unsigned char* reloc_view
,
147 section_size_type reloc_view_size
);
148 // Return whether SYM is defined by the ABI.
150 do_is_defined_by_abi(const Symbol
* sym
) const
152 // XXX Really need to support this better...
153 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
156 return strcmp(sym
->name(), "___tls_get_addr") == 0;
159 // Return the PLT address to use for a global symbol.
161 do_plt_address_for_global(const Symbol
* gsym
) const
162 { return this->plt_section()->address_for_global(gsym
); }
165 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
166 { return this->plt_section()->address_for_local(relobj
, symndx
); }
168 // Return whether there is a GOT section.
170 has_got_section() const
171 { return this->got_
!= NULL
; }
173 // Return the size of the GOT section.
177 gold_assert(this->got_
!= NULL
);
178 return this->got_
->data_size();
181 // Return the number of entries in the GOT.
183 got_entry_count() const
185 if (this->got_
== NULL
)
187 return this->got_size() / (size
/ 8);
190 // Return the address of the GOT.
194 if (this->got_
== NULL
)
196 return this->got_
->address();
199 // Return the number of entries in the PLT.
201 plt_entry_count() const;
203 // Return the offset of the first non-reserved PLT entry.
205 first_plt_entry_offset() const;
207 // Return the size of each PLT entry.
209 plt_entry_size() const;
212 // Make an ELF object.
214 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
215 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
218 do_adjust_elf_header(unsigned char* view
, int len
) const;
222 // The class which scans relocations.
227 : issued_non_pic_error_(false)
231 get_reference_flags(unsigned int r_type
);
234 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
235 Sized_relobj_file
<size
, big_endian
>* object
,
236 unsigned int data_shndx
,
237 Output_section
* output_section
,
238 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
239 const elfcpp::Sym
<size
, big_endian
>& lsym
);
242 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
243 Sized_relobj_file
<size
, big_endian
>* object
,
244 unsigned int data_shndx
,
245 Output_section
* output_section
,
246 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
250 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
252 Sized_relobj_file
<size
, big_endian
>* ,
255 const elfcpp::Rela
<size
, big_endian
>& ,
257 const elfcpp::Sym
<size
, big_endian
>&)
261 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
263 Sized_relobj_file
<size
, big_endian
>* ,
266 const elfcpp::Rela
<size
,
268 unsigned int , Symbol
*)
274 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
275 unsigned int r_type
);
278 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
279 unsigned int r_type
, Symbol
*);
282 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
283 Target_sparc
* target
);
286 check_non_pic(Relobj
*, unsigned int r_type
);
289 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
290 unsigned int r_type
);
292 // Whether we have issued an error about a non-PIC compilation.
293 bool issued_non_pic_error_
;
296 // The class which implements relocation.
301 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
306 if (this->ignore_gd_add_
)
308 // FIXME: This needs to specify the location somehow.
309 gold_error(_("missing expected TLS relocation"));
313 // Do a relocation. Return false if the caller should not issue
314 // any warnings about this relocation.
316 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
317 Output_section
*, size_t relnum
,
318 const elfcpp::Rela
<size
, big_endian
>&,
319 unsigned int r_type
, const Sized_symbol
<size
>*,
320 const Symbol_value
<size
>*,
322 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
326 // Do a TLS relocation.
328 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
329 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
330 unsigned int r_type
, const Sized_symbol
<size
>*,
331 const Symbol_value
<size
>*,
333 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
337 relax_call(Target_sparc
<size
, big_endian
>* target
,
339 const elfcpp::Rela
<size
, big_endian
>& rela
,
340 section_size_type view_size
);
342 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
345 // If we hit a reloc at this view address, adjust it back by 4 bytes.
346 unsigned char *reloc_adjust_addr_
;
349 // A class which returns the size required for a relocation type,
350 // used while scanning relocs during a relocatable link.
351 class Relocatable_size_for_reloc
355 get_size_for_reloc(unsigned int, Relobj
*);
358 // Get the GOT section, creating it if necessary.
359 Output_data_got
<size
, big_endian
>*
360 got_section(Symbol_table
*, Layout
*);
362 // Create the PLT section.
364 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
366 // Create a PLT entry for a global symbol.
368 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
370 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
372 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
373 Sized_relobj_file
<size
, big_endian
>* relobj
,
374 unsigned int local_sym_index
);
376 // Create a GOT entry for the TLS module index.
378 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
379 Sized_relobj_file
<size
, big_endian
>* object
);
381 // Return the gsym for "__tls_get_addr". Cache if not already
384 tls_get_addr_sym(Symbol_table
* symtab
)
386 if (!this->tls_get_addr_sym_
)
387 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
388 gold_assert(this->tls_get_addr_sym_
);
389 return this->tls_get_addr_sym_
;
392 // Get the PLT section.
393 Output_data_plt_sparc
<size
, big_endian
>*
396 gold_assert(this->plt_
!= NULL
);
400 // Get the dynamic reloc section, creating it if necessary.
402 rela_dyn_section(Layout
*);
404 // Get the section to use for IFUNC relocations.
406 rela_ifunc_section(Layout
*);
408 // Copy a relocation against a global symbol.
410 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
411 Sized_relobj_file
<size
, big_endian
>* object
,
412 unsigned int shndx
, Output_section
* output_section
,
413 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
415 this->copy_relocs_
.copy_reloc(symtab
, layout
,
416 symtab
->get_sized_symbol
<size
>(sym
),
417 object
, shndx
, output_section
,
418 reloc
, this->rela_dyn_section(layout
));
421 // Information about this specific target which we pass to the
422 // general Target structure.
423 static Target::Target_info sparc_info
;
425 // The types of GOT entries needed for this platform.
426 // These values are exposed to the ABI in an incremental link.
427 // Do not renumber existing values without changing the version
428 // number of the .gnu_incremental_inputs section.
431 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
432 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
433 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
437 Output_data_got
<size
, big_endian
>* got_
;
439 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
440 // The dynamic reloc section.
441 Reloc_section
* rela_dyn_
;
442 // The section to use for IFUNC relocs.
443 Reloc_section
* rela_ifunc_
;
444 // Relocs saved to avoid a COPY reloc.
445 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
446 // Space for variables copied with a COPY reloc.
447 Output_data_space
* dynbss_
;
448 // Offset of the GOT entry for the TLS module index;
449 unsigned int got_mod_index_offset_
;
450 // Cached pointer to __tls_get_addr symbol
451 Symbol
* tls_get_addr_sym_
;
452 // Accumulated elf machine type
453 elfcpp::Elf_Half elf_machine_
;
454 // Accumulated elf header flags
455 elfcpp::Elf_Word elf_flags_
;
456 // Whether elf_flags_ has been set for the first time yet
461 Target::Target_info Target_sparc
<32, true>::sparc_info
=
464 true, // is_big_endian
465 elfcpp::EM_SPARC
, // machine_code
466 false, // has_make_symbol
467 false, // has_resolve
468 false, // has_code_fill
469 true, // is_default_stack_executable
470 false, // can_icf_inline_merge_sections
472 "/usr/lib/ld.so.1", // dynamic_linker
473 0x00010000, // default_text_segment_address
474 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
475 8 * 1024, // common_pagesize (overridable by -z common-page-size)
476 false, // isolate_execinstr
478 elfcpp::SHN_UNDEF
, // small_common_shndx
479 elfcpp::SHN_UNDEF
, // large_common_shndx
480 0, // small_common_section_flags
481 0, // large_common_section_flags
482 NULL
, // attributes_section
483 NULL
// attributes_vendor
487 Target::Target_info Target_sparc
<64, true>::sparc_info
=
490 true, // is_big_endian
491 elfcpp::EM_SPARCV9
, // machine_code
492 false, // has_make_symbol
493 false, // has_resolve
494 false, // has_code_fill
495 true, // is_default_stack_executable
496 false, // can_icf_inline_merge_sections
498 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
499 0x100000, // default_text_segment_address
500 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
501 8 * 1024, // common_pagesize (overridable by -z common-page-size)
502 false, // isolate_execinstr
504 elfcpp::SHN_UNDEF
, // small_common_shndx
505 elfcpp::SHN_UNDEF
, // large_common_shndx
506 0, // small_common_section_flags
507 0, // large_common_section_flags
508 NULL
, // attributes_section
509 NULL
// attributes_vendor
512 // We have to take care here, even when operating in little-endian
513 // mode, sparc instructions are still big endian.
514 template<int size
, bool big_endian
>
515 class Sparc_relocate_functions
518 // Do a simple relocation with the addend in the relocation.
519 template<int valsize
>
521 rela(unsigned char* view
,
522 unsigned int right_shift
,
523 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
524 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
525 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
527 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
528 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
529 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
530 Valtype reloc
= ((value
+ addend
) >> right_shift
);
535 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
538 // Do a simple relocation using a symbol value with the addend in
540 template<int valsize
>
542 rela(unsigned char* view
,
543 unsigned int right_shift
,
544 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
545 const Sized_relobj_file
<size
, big_endian
>* object
,
546 const Symbol_value
<size
>* psymval
,
547 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
549 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
550 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
551 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
552 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
557 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
560 // Do a simple relocation using a symbol value with the addend in
561 // the relocation, unaligned.
562 template<int valsize
>
564 rela_ua(unsigned char* view
,
565 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
566 const Sized_relobj_file
<size
, big_endian
>* object
,
567 const Symbol_value
<size
>* psymval
,
568 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
570 typedef typename
elfcpp::Swap_unaligned
<valsize
,
571 big_endian
>::Valtype Valtype
;
572 unsigned char* wv
= view
;
573 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
574 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
579 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
582 // Do a simple PC relative relocation with a Symbol_value with the
583 // addend in the relocation.
584 template<int valsize
>
586 pcrela(unsigned char* view
,
587 unsigned int right_shift
,
588 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
589 const Sized_relobj_file
<size
, big_endian
>* object
,
590 const Symbol_value
<size
>* psymval
,
591 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
592 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
594 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
595 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
596 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
597 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
603 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
606 template<int valsize
>
608 pcrela_unaligned(unsigned char* view
,
609 const Sized_relobj_file
<size
, big_endian
>* object
,
610 const Symbol_value
<size
>* psymval
,
611 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
612 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
614 typedef typename
elfcpp::Swap_unaligned
<valsize
,
615 big_endian
>::Valtype Valtype
;
616 unsigned char* wv
= view
;
617 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
619 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
622 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
623 typedef Sparc_relocate_functions
<size
, true> This_insn
;
626 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
628 wdisp30(unsigned char* view
,
629 const Sized_relobj_file
<size
, big_endian
>* object
,
630 const Symbol_value
<size
>* psymval
,
631 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
632 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
634 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
635 psymval
, addend
, address
);
638 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
640 wdisp22(unsigned char* view
,
641 const Sized_relobj_file
<size
, big_endian
>* object
,
642 const Symbol_value
<size
>* psymval
,
643 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
644 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
646 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
647 psymval
, addend
, address
);
650 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
652 wdisp19(unsigned char* view
,
653 const Sized_relobj_file
<size
, big_endian
>* object
,
654 const Symbol_value
<size
>* psymval
,
655 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
656 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
658 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
659 psymval
, addend
, address
);
662 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
664 wdisp16(unsigned char* view
,
665 const Sized_relobj_file
<size
, big_endian
>* object
,
666 const Symbol_value
<size
>* psymval
,
667 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
668 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
670 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
671 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
672 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
673 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
676 // The relocation value is split between the low 14 bits,
678 val
&= ~((0x3 << 20) | 0x3fff);
679 reloc
= (((reloc
& 0xc000) << (20 - 14))
680 | (reloc
& 0x3ffff));
682 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
685 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
687 wdisp10(unsigned char* view
,
688 const Sized_relobj_file
<size
, big_endian
>* object
,
689 const Symbol_value
<size
>* psymval
,
690 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
691 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
693 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
694 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
695 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
696 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
699 // The relocation value is split between the low bits 5-12,
700 // and high bits 19-20.
701 val
&= ~((0x3 << 19) | (0xff << 5));
702 reloc
= (((reloc
& 0x300) << (19 - 8))
703 | ((reloc
& 0xff) << (5 - 0)));
705 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
708 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
710 pc22(unsigned char* view
,
711 const Sized_relobj_file
<size
, big_endian
>* object
,
712 const Symbol_value
<size
>* psymval
,
713 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
714 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
716 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
717 psymval
, addend
, address
);
720 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
722 pc10(unsigned char* view
,
723 const Sized_relobj_file
<size
, big_endian
>* object
,
724 const Symbol_value
<size
>* psymval
,
725 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
726 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
728 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
729 psymval
, addend
, address
);
732 // R_SPARC_HI22: (Symbol + Addend) >> 10
734 hi22(unsigned char* view
,
735 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
736 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
738 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
741 // R_SPARC_HI22: (Symbol + Addend) >> 10
743 hi22(unsigned char* view
,
744 const Sized_relobj_file
<size
, big_endian
>* object
,
745 const Symbol_value
<size
>* psymval
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
748 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
751 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
753 pcplt22(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
,
757 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
759 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
760 psymval
, addend
, address
);
763 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
765 lo10(unsigned char* view
,
766 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
767 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
769 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
772 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
774 lo10(unsigned char* view
,
775 const Sized_relobj_file
<size
, big_endian
>* object
,
776 const Symbol_value
<size
>* psymval
,
777 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
779 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, 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
,
788 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
790 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
791 psymval
, addend
, address
);
794 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
796 olo10(unsigned char* view
,
797 const Sized_relobj_file
<size
, big_endian
>* object
,
798 const Symbol_value
<size
>* psymval
,
799 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
800 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
802 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
803 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
804 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
805 Valtype reloc
= psymval
->value(object
, addend
);
812 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
815 // R_SPARC_22: (Symbol + Addend)
817 rela32_22(unsigned char* view
,
818 const Sized_relobj_file
<size
, big_endian
>* object
,
819 const Symbol_value
<size
>* psymval
,
820 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
822 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
825 // R_SPARC_13: (Symbol + Addend)
827 rela32_13(unsigned char* view
,
828 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
829 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
831 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
834 // R_SPARC_13: (Symbol + Addend)
836 rela32_13(unsigned char* view
,
837 const Sized_relobj_file
<size
, big_endian
>* object
,
838 const Symbol_value
<size
>* psymval
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
841 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
844 // R_SPARC_UA16: (Symbol + Addend)
846 ua16(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::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
854 // R_SPARC_UA32: (Symbol + Addend)
856 ua32(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
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
864 // R_SPARC_UA64: (Symbol + Addend)
866 ua64(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
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
872 object
, psymval
, addend
);
875 // R_SPARC_DISP8: (Symbol + Addend - Address)
877 disp8(unsigned char* view
,
878 const Sized_relobj_file
<size
, big_endian
>* object
,
879 const Symbol_value
<size
>* psymval
,
880 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
881 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
883 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
887 // R_SPARC_DISP16: (Symbol + Addend - Address)
889 disp16(unsigned char* view
,
890 const Sized_relobj_file
<size
, big_endian
>* object
,
891 const Symbol_value
<size
>* psymval
,
892 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
893 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
895 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
899 // R_SPARC_DISP32: (Symbol + Addend - Address)
901 disp32(unsigned char* view
,
902 const Sized_relobj_file
<size
, big_endian
>* object
,
903 const Symbol_value
<size
>* psymval
,
904 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
905 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
907 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
911 // R_SPARC_DISP64: (Symbol + Addend - Address)
913 disp64(unsigned char* view
,
914 const Sized_relobj_file
<size
, big_endian
>* object
,
915 const Symbol_value
<size
>* psymval
,
916 elfcpp::Elf_Xword addend
,
917 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
919 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
923 // R_SPARC_H34: (Symbol + Addend) >> 12
925 h34(unsigned char* view
,
926 const Sized_relobj_file
<size
, big_endian
>* object
,
927 const Symbol_value
<size
>* psymval
,
928 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
930 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
933 // R_SPARC_H44: (Symbol + Addend) >> 22
935 h44(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
, 22, 0x003fffff, object
, psymval
, addend
);
943 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
945 m44(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
, 12, 0x000003ff, object
, psymval
, addend
);
953 // R_SPARC_L44: (Symbol + Addend) & 0xfff
955 l44(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
, 0, 0x00000fff, object
, psymval
, addend
);
963 // R_SPARC_HH22: (Symbol + Addend) >> 42
965 hh22(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
, 42, 0x003fffff, object
, psymval
, addend
);
973 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
975 pc_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
,
979 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
981 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
982 psymval
, addend
, address
);
985 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
987 hm10(unsigned char* view
,
988 const Sized_relobj_file
<size
, big_endian
>* object
,
989 const Symbol_value
<size
>* psymval
,
990 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
992 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
995 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
997 pc_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
,
1001 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
1003 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
1004 psymval
, addend
, address
);
1007 // R_SPARC_11: (Symbol + Addend)
1009 rela32_11(unsigned char* view
,
1010 const Sized_relobj_file
<size
, big_endian
>* object
,
1011 const Symbol_value
<size
>* psymval
,
1012 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1014 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1017 // R_SPARC_10: (Symbol + Addend)
1019 rela32_10(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, 0x000003ff, object
, psymval
, addend
);
1027 // R_SPARC_7: (Symbol + Addend)
1029 rela32_7(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, 0x0000007f, object
, psymval
, addend
);
1037 // R_SPARC_6: (Symbol + Addend)
1039 rela32_6(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, 0x0000003f, object
, psymval
, addend
);
1047 // R_SPARC_5: (Symbol + Addend)
1049 rela32_5(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, 0x0000001f, object
, psymval
, addend
);
1057 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1059 ldo_hix22(unsigned char* view
,
1060 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1061 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1063 This_insn::hi22(view
, value
, addend
);
1066 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1068 ldo_lox10(unsigned char* view
,
1069 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1070 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1072 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1073 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1074 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1075 Valtype reloc
= (value
+ addend
);
1080 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1083 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1085 hix22(unsigned char* view
,
1086 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1087 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1089 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1090 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1091 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1092 Valtype reloc
= (value
+ addend
);
1096 reloc
^= ~(Valtype
)0;
1101 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1104 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1106 gdop_hix22(unsigned char* view
,
1107 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1108 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1110 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1111 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1112 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1113 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1118 reloc
^= ~static_cast<int32_t>(0);
1123 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1126 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1128 hix22(unsigned char* view
,
1129 const Sized_relobj_file
<size
, big_endian
>* object
,
1130 const Symbol_value
<size
>* psymval
,
1131 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1133 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1134 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1135 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1136 Valtype reloc
= psymval
->value(object
, addend
);
1140 reloc
^= ~(Valtype
)0;
1145 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1149 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1151 lox10(unsigned char* view
,
1152 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1153 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1155 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1156 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1157 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1158 Valtype reloc
= (value
+ addend
);
1164 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1167 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1169 gdop_lox10(unsigned char* view
,
1170 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1171 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1173 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1174 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1175 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1176 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1179 reloc
= (reloc
& 0x3ff) | 0x1c00;
1181 reloc
= (reloc
& 0x3ff);
1184 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1187 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1189 lox10(unsigned char* view
,
1190 const Sized_relobj_file
<size
, big_endian
>* object
,
1191 const Symbol_value
<size
>* psymval
,
1192 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1194 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1195 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1196 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1197 Valtype reloc
= psymval
->value(object
, addend
);
1203 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1207 // Get the GOT section, creating it if necessary.
1209 template<int size
, bool big_endian
>
1210 Output_data_got
<size
, big_endian
>*
1211 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1214 if (this->got_
== NULL
)
1216 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1218 this->got_
= new Output_data_got
<size
, big_endian
>();
1220 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1222 | elfcpp::SHF_WRITE
),
1223 this->got_
, ORDER_RELRO
, true);
1225 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1226 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1227 Symbol_table::PREDEFINED
,
1229 0, 0, elfcpp::STT_OBJECT
,
1231 elfcpp::STV_HIDDEN
, 0,
1238 // Get the dynamic reloc section, creating it if necessary.
1240 template<int size
, bool big_endian
>
1241 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1242 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1244 if (this->rela_dyn_
== NULL
)
1246 gold_assert(layout
!= NULL
);
1247 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1248 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1249 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1250 ORDER_DYNAMIC_RELOCS
, false);
1252 return this->rela_dyn_
;
1255 // Get the section to use for IFUNC relocs, creating it if
1256 // necessary. These go in .rela.dyn, but only after all other dynamic
1257 // relocations. They need to follow the other dynamic relocations so
1258 // that they can refer to global variables initialized by those
1261 template<int size
, bool big_endian
>
1262 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1263 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1265 if (this->rela_ifunc_
== NULL
)
1267 // Make sure we have already created the dynamic reloc section.
1268 this->rela_dyn_section(layout
);
1269 this->rela_ifunc_
= new Reloc_section(false);
1270 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1271 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1272 ORDER_DYNAMIC_RELOCS
, false);
1273 gold_assert(this->rela_dyn_
->output_section()
1274 == this->rela_ifunc_
->output_section());
1276 return this->rela_ifunc_
;
1279 // A class to handle the PLT data.
1281 template<int size
, bool big_endian
>
1282 class Output_data_plt_sparc
: public Output_section_data
1285 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1286 size
, big_endian
> Reloc_section
;
1288 Output_data_plt_sparc(Layout
*);
1290 // Add an entry to the PLT.
1291 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1293 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1295 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1296 Sized_relobj_file
<size
, big_endian
>* relobj
,
1297 unsigned int local_sym_index
);
1299 // Return the .rela.plt section data.
1300 const Reloc_section
* rel_plt() const
1305 // Return where the IFUNC relocations should go.
1307 rela_ifunc(Symbol_table
*, Layout
*);
1310 emit_pending_ifunc_relocs();
1312 // Return whether we created a section for IFUNC relocations.
1314 has_ifunc_section() const
1315 { return this->ifunc_rel_
!= NULL
; }
1317 // Return the number of PLT entries.
1320 { return this->count_
+ this->ifunc_count_
; }
1322 // Return the offset of the first non-reserved PLT entry.
1324 first_plt_entry_offset()
1325 { return 4 * base_plt_entry_size
; }
1327 // Return the size of a PLT entry.
1329 get_plt_entry_size()
1330 { return base_plt_entry_size
; }
1332 // Return the PLT address to use for a global symbol.
1334 address_for_global(const Symbol
*);
1336 // Return the PLT address to use for a local symbol.
1338 address_for_local(const Relobj
*, unsigned int symndx
);
1341 void do_adjust_output_section(Output_section
* os
);
1343 // Write to a map file.
1345 do_print_to_mapfile(Mapfile
* mapfile
) const
1346 { mapfile
->print_output_data(this, _("** PLT")); }
1349 // The size of an entry in the PLT.
1350 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1352 static const unsigned int plt_entries_per_block
= 160;
1353 static const unsigned int plt_insn_chunk_size
= 24;
1354 static const unsigned int plt_pointer_chunk_size
= 8;
1355 static const unsigned int plt_block_size
=
1356 (plt_entries_per_block
1357 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1360 plt_index_to_offset(unsigned int index
)
1362 section_offset_type offset
;
1364 if (size
== 32 || index
< 32768)
1365 offset
= index
* base_plt_entry_size
;
1368 unsigned int ext_index
= index
- 32768;
1370 offset
= (32768 * base_plt_entry_size
)
1371 + ((ext_index
/ plt_entries_per_block
)
1373 + ((ext_index
% plt_entries_per_block
)
1374 * plt_insn_chunk_size
);
1379 // Set the final size.
1381 set_final_data_size()
1383 unsigned int full_count
= this->entry_count() + 4;
1384 unsigned int extra
= (size
== 32 ? 4 : 0);
1385 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1387 return this->set_data_size(sz
);
1390 // Write out the PLT data.
1392 do_write(Output_file
*);
1398 unsigned int plt_index
;
1404 Sized_relobj_file
<size
, big_endian
>* object
;
1405 unsigned int local_sym_index
;
1406 unsigned int plt_index
;
1409 // The reloc section.
1410 Reloc_section
* rel_
;
1411 // The IFUNC relocations, if necessary. These must follow the
1412 // regular relocations.
1413 Reloc_section
* ifunc_rel_
;
1414 // The number of PLT entries.
1415 unsigned int count_
;
1416 // The number of PLT entries for IFUNC symbols.
1417 unsigned int ifunc_count_
;
1418 // Global STT_GNU_IFUNC symbols.
1419 std::vector
<Global_ifunc
> global_ifuncs_
;
1420 // Local STT_GNU_IFUNC symbols.
1421 std::vector
<Local_ifunc
> local_ifuncs_
;
1424 // Define the constants as required by C++ standard.
1426 template<int size
, bool big_endian
>
1427 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1429 template<int size
, bool big_endian
>
1431 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1433 template<int size
, bool big_endian
>
1434 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1436 template<int size
, bool big_endian
>
1438 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1440 template<int size
, bool big_endian
>
1441 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1443 // Create the PLT section. The ordinary .got section is an argument,
1444 // since we need to refer to the start.
1446 template<int size
, bool big_endian
>
1447 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1448 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1449 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1451 this->rel_
= new Reloc_section(false);
1452 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1453 elfcpp::SHF_ALLOC
, this->rel_
,
1454 ORDER_DYNAMIC_PLT_RELOCS
, false);
1457 template<int size
, bool big_endian
>
1459 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1464 // Add an entry to the PLT.
1466 template<int size
, bool big_endian
>
1468 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1472 gold_assert(!gsym
->has_plt_offset());
1474 section_offset_type plt_offset
;
1477 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1478 && gsym
->can_use_relative_reloc(false))
1480 index
= this->ifunc_count_
;
1481 plt_offset
= plt_index_to_offset(index
);
1482 gsym
->set_plt_offset(plt_offset
);
1483 ++this->ifunc_count_
;
1484 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1486 struct Global_ifunc gi
;
1489 gi
.plt_index
= index
;
1490 this->global_ifuncs_
.push_back(gi
);
1494 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1495 gsym
->set_plt_offset(plt_offset
);
1497 gsym
->set_needs_dynsym_entry();
1498 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1502 // Note that we don't need to save the symbol. The contents of the
1503 // PLT are independent of which symbols are used. The symbols only
1504 // appear in the relocations.
1507 template<int size
, bool big_endian
>
1509 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1510 Symbol_table
* symtab
,
1512 Sized_relobj_file
<size
, big_endian
>* relobj
,
1513 unsigned int local_sym_index
)
1515 unsigned int index
= this->ifunc_count_
;
1516 section_offset_type plt_offset
;
1518 plt_offset
= plt_index_to_offset(index
);
1519 ++this->ifunc_count_
;
1521 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1523 struct Local_ifunc li
;
1526 li
.local_sym_index
= local_sym_index
;
1527 li
.plt_index
= index
;
1528 this->local_ifuncs_
.push_back(li
);
1533 // Emit any pending IFUNC plt relocations.
1535 template<int size
, bool big_endian
>
1537 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1539 // Emit any pending IFUNC relocs.
1540 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1541 this->global_ifuncs_
.begin();
1542 p
!= this->global_ifuncs_
.end();
1545 section_offset_type plt_offset
;
1548 index
= this->count_
+ p
->plt_index
+ 4;
1549 plt_offset
= this->plt_index_to_offset(index
);
1550 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1551 this, plt_offset
, 0);
1554 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1555 this->local_ifuncs_
.begin();
1556 p
!= this->local_ifuncs_
.end();
1559 section_offset_type plt_offset
;
1562 index
= this->count_
+ p
->plt_index
+ 4;
1563 plt_offset
= this->plt_index_to_offset(index
);
1564 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1565 elfcpp::R_SPARC_JMP_IREL
,
1566 this, plt_offset
, 0);
1570 // Return where the IFUNC relocations should go in the PLT. These
1571 // follow the non-IFUNC relocations.
1573 template<int size
, bool big_endian
>
1574 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1575 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1576 Symbol_table
* symtab
,
1579 if (this->ifunc_rel_
== NULL
)
1581 this->ifunc_rel_
= new Reloc_section(false);
1582 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1583 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1584 ORDER_DYNAMIC_PLT_RELOCS
, false);
1585 gold_assert(this->ifunc_rel_
->output_section()
1586 == this->rel_
->output_section());
1588 if (parameters
->doing_static_link())
1590 // A statically linked executable will only have a .rel.plt
1591 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1592 // relocs for STT_GNU_IFUNC symbols. The library will use
1593 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1594 // at program startup time.
1595 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1596 Symbol_table::PREDEFINED
,
1597 this->ifunc_rel_
, 0, 0,
1598 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1599 elfcpp::STV_HIDDEN
, 0, false, true);
1600 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1601 Symbol_table::PREDEFINED
,
1602 this->ifunc_rel_
, 0, 0,
1603 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1604 elfcpp::STV_HIDDEN
, 0, true, true);
1607 return this->ifunc_rel_
;
1610 // Return the PLT address to use for a global symbol.
1612 template<int size
, bool big_endian
>
1614 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1616 uint64_t offset
= 0;
1617 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1618 && gsym
->can_use_relative_reloc(false))
1619 offset
= plt_index_to_offset(this->count_
+ 4);
1620 return this->address() + offset
;
1623 // Return the PLT address to use for a local symbol. These are always
1624 // IRELATIVE relocs.
1626 template<int size
, bool big_endian
>
1628 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1632 return this->address() + plt_index_to_offset(this->count_
+ 4);
1635 static const unsigned int sparc_nop
= 0x01000000;
1636 static const unsigned int sparc_sethi_g1
= 0x03000000;
1637 static const unsigned int sparc_branch_always
= 0x30800000;
1638 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1639 static const unsigned int sparc_mov
= 0x80100000;
1640 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1641 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1642 static const unsigned int sparc_call_plus_8
= 0x40000002;
1643 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1644 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1645 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1647 // Write out the PLT.
1649 template<int size
, bool big_endian
>
1651 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1653 const off_t offset
= this->offset();
1654 const section_size_type oview_size
=
1655 convert_to_section_size_type(this->data_size());
1656 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1657 unsigned char* pov
= oview
;
1659 memset(pov
, 0, base_plt_entry_size
* 4);
1660 pov
+= this->first_plt_entry_offset();
1662 unsigned int plt_offset
= base_plt_entry_size
* 4;
1663 const unsigned int count
= this->entry_count();
1669 limit
= (count
> 32768 ? 32768 : count
);
1671 for (unsigned int i
= 0; i
< limit
; ++i
)
1673 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1674 sparc_sethi_g1
+ plt_offset
);
1675 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1676 sparc_branch_always_pt
+
1677 (((base_plt_entry_size
-
1678 (plt_offset
+ 4)) >> 2) &
1680 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1681 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1682 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1683 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1684 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1685 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1687 pov
+= base_plt_entry_size
;
1688 plt_offset
+= base_plt_entry_size
;
1693 unsigned int ext_cnt
= count
- 32768;
1694 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1696 for (unsigned int i
= 0; i
< blks
; ++i
)
1698 unsigned int data_off
= (plt_entries_per_block
1699 * plt_insn_chunk_size
) - 4;
1701 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1703 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1705 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1707 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1709 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1710 sparc_ldx_o7_imm_g1
+
1711 (data_off
& 0x1fff));
1712 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1713 sparc_jmpl_o7_g1_g1
);
1714 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1717 elfcpp::Swap
<64, big_endian
>::writeval(
1718 pov
+ 0x4 + data_off
,
1719 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1721 pov
+= plt_insn_chunk_size
;
1726 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1727 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1729 unsigned int data_off
= (sub_blk_cnt
1730 * plt_insn_chunk_size
) - 4;
1732 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1734 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1736 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1738 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1740 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1741 sparc_ldx_o7_imm_g1
+
1742 (data_off
& 0x1fff));
1743 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1744 sparc_jmpl_o7_g1_g1
);
1745 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1748 elfcpp::Swap
<64, big_endian
>::writeval(
1749 pov
+ 0x4 + data_off
,
1750 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1752 pov
+= plt_insn_chunk_size
;
1760 for (unsigned int i
= 0; i
< count
; ++i
)
1762 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1763 sparc_sethi_g1
+ plt_offset
);
1764 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1765 sparc_branch_always
+
1766 (((- (plt_offset
+ 4)) >> 2) &
1768 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1770 pov
+= base_plt_entry_size
;
1771 plt_offset
+= base_plt_entry_size
;
1774 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1778 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1780 of
->write_output_view(offset
, oview_size
, oview
);
1783 // Create the PLT section.
1785 template<int size
, bool big_endian
>
1787 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1790 // Create the GOT sections first.
1791 this->got_section(symtab
, layout
);
1793 // Ensure that .rela.dyn always appears before .rela.plt This is
1794 // necessary due to how, on Sparc and some other targets, .rela.dyn
1795 // needs to include .rela.plt in it's range.
1796 this->rela_dyn_section(layout
);
1798 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1799 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1801 | elfcpp::SHF_EXECINSTR
1802 | elfcpp::SHF_WRITE
),
1803 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1805 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1806 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1807 Symbol_table::PREDEFINED
,
1809 0, 0, elfcpp::STT_OBJECT
,
1811 elfcpp::STV_HIDDEN
, 0,
1815 // Create a PLT entry for a global symbol.
1817 template<int size
, bool big_endian
>
1819 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1823 if (gsym
->has_plt_offset())
1826 if (this->plt_
== NULL
)
1827 this->make_plt_section(symtab
, layout
);
1829 this->plt_
->add_entry(symtab
, layout
, gsym
);
1832 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1834 template<int size
, bool big_endian
>
1836 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1837 Symbol_table
* symtab
,
1839 Sized_relobj_file
<size
, big_endian
>* relobj
,
1840 unsigned int local_sym_index
)
1842 if (relobj
->local_has_plt_offset(local_sym_index
))
1844 if (this->plt_
== NULL
)
1845 this->make_plt_section(symtab
, layout
);
1846 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1849 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1852 // Return the number of entries in the PLT.
1854 template<int size
, bool big_endian
>
1856 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1858 if (this->plt_
== NULL
)
1860 return this->plt_
->entry_count();
1863 // Return the offset of the first non-reserved PLT entry.
1865 template<int size
, bool big_endian
>
1867 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1869 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1872 // Return the size of each PLT entry.
1874 template<int size
, bool big_endian
>
1876 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1878 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1881 // Create a GOT entry for the TLS module index.
1883 template<int size
, bool big_endian
>
1885 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1886 Symbol_table
* symtab
,
1888 Sized_relobj_file
<size
, big_endian
>* object
)
1890 if (this->got_mod_index_offset_
== -1U)
1892 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1893 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1894 Output_data_got
<size
, big_endian
>* got
;
1895 unsigned int got_offset
;
1897 got
= this->got_section(symtab
, layout
);
1898 got_offset
= got
->add_constant(0);
1899 rela_dyn
->add_local(object
, 0,
1901 elfcpp::R_SPARC_TLS_DTPMOD64
:
1902 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1904 got
->add_constant(0);
1905 this->got_mod_index_offset_
= got_offset
;
1907 return this->got_mod_index_offset_
;
1910 // Optimize the TLS relocation type based on what we know about the
1911 // symbol. IS_FINAL is true if the final address of this symbol is
1912 // known at link time.
1914 static tls::Tls_optimization
1915 optimize_tls_reloc(bool is_final
, int r_type
)
1917 // If we are generating a shared library, then we can't do anything
1919 if (parameters
->options().shared())
1920 return tls::TLSOPT_NONE
;
1924 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1925 case elfcpp::R_SPARC_TLS_GD_LO10
:
1926 case elfcpp::R_SPARC_TLS_GD_ADD
:
1927 case elfcpp::R_SPARC_TLS_GD_CALL
:
1928 // These are General-Dynamic which permits fully general TLS
1929 // access. Since we know that we are generating an executable,
1930 // we can convert this to Initial-Exec. If we also know that
1931 // this is a local symbol, we can further switch to Local-Exec.
1933 return tls::TLSOPT_TO_LE
;
1934 return tls::TLSOPT_TO_IE
;
1936 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1937 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1938 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1939 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1940 // This is Local-Dynamic, which refers to a local symbol in the
1941 // dynamic TLS block. Since we know that we generating an
1942 // executable, we can switch to Local-Exec.
1943 return tls::TLSOPT_TO_LE
;
1945 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1946 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1947 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1948 // Another type of Local-Dynamic relocation.
1949 return tls::TLSOPT_TO_LE
;
1951 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1952 case elfcpp::R_SPARC_TLS_IE_LO10
:
1953 case elfcpp::R_SPARC_TLS_IE_LD
:
1954 case elfcpp::R_SPARC_TLS_IE_LDX
:
1955 case elfcpp::R_SPARC_TLS_IE_ADD
:
1956 // These are Initial-Exec relocs which get the thread offset
1957 // from the GOT. If we know that we are linking against the
1958 // local symbol, we can switch to Local-Exec, which links the
1959 // thread offset into the instruction.
1961 return tls::TLSOPT_TO_LE
;
1962 return tls::TLSOPT_NONE
;
1964 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1965 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1966 // When we already have Local-Exec, there is nothing further we
1968 return tls::TLSOPT_NONE
;
1975 // Get the Reference_flags for a particular relocation.
1977 template<int size
, bool big_endian
>
1979 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1984 case elfcpp::R_SPARC_NONE
:
1985 case elfcpp::R_SPARC_REGISTER
:
1986 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1987 case elfcpp::R_SPARC_GNU_VTENTRY
:
1988 // No symbol reference.
1991 case elfcpp::R_SPARC_UA64
:
1992 case elfcpp::R_SPARC_64
:
1993 case elfcpp::R_SPARC_HIX22
:
1994 case elfcpp::R_SPARC_LOX10
:
1995 case elfcpp::R_SPARC_H34
:
1996 case elfcpp::R_SPARC_H44
:
1997 case elfcpp::R_SPARC_M44
:
1998 case elfcpp::R_SPARC_L44
:
1999 case elfcpp::R_SPARC_HH22
:
2000 case elfcpp::R_SPARC_HM10
:
2001 case elfcpp::R_SPARC_LM22
:
2002 case elfcpp::R_SPARC_HI22
:
2003 case elfcpp::R_SPARC_LO10
:
2004 case elfcpp::R_SPARC_OLO10
:
2005 case elfcpp::R_SPARC_UA32
:
2006 case elfcpp::R_SPARC_32
:
2007 case elfcpp::R_SPARC_UA16
:
2008 case elfcpp::R_SPARC_16
:
2009 case elfcpp::R_SPARC_11
:
2010 case elfcpp::R_SPARC_10
:
2011 case elfcpp::R_SPARC_8
:
2012 case elfcpp::R_SPARC_7
:
2013 case elfcpp::R_SPARC_6
:
2014 case elfcpp::R_SPARC_5
:
2015 return Symbol::ABSOLUTE_REF
;
2017 case elfcpp::R_SPARC_DISP8
:
2018 case elfcpp::R_SPARC_DISP16
:
2019 case elfcpp::R_SPARC_DISP32
:
2020 case elfcpp::R_SPARC_DISP64
:
2021 case elfcpp::R_SPARC_PC_HH22
:
2022 case elfcpp::R_SPARC_PC_HM10
:
2023 case elfcpp::R_SPARC_PC_LM22
:
2024 case elfcpp::R_SPARC_PC10
:
2025 case elfcpp::R_SPARC_PC22
:
2026 case elfcpp::R_SPARC_WDISP30
:
2027 case elfcpp::R_SPARC_WDISP22
:
2028 case elfcpp::R_SPARC_WDISP19
:
2029 case elfcpp::R_SPARC_WDISP16
:
2030 case elfcpp::R_SPARC_WDISP10
:
2031 return Symbol::RELATIVE_REF
;
2033 case elfcpp::R_SPARC_PLT64
:
2034 case elfcpp::R_SPARC_PLT32
:
2035 case elfcpp::R_SPARC_HIPLT22
:
2036 case elfcpp::R_SPARC_LOPLT10
:
2037 case elfcpp::R_SPARC_PCPLT10
:
2038 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2040 case elfcpp::R_SPARC_PCPLT32
:
2041 case elfcpp::R_SPARC_PCPLT22
:
2042 case elfcpp::R_SPARC_WPLT30
:
2043 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2045 case elfcpp::R_SPARC_GOTDATA_OP
:
2046 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2047 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2048 case elfcpp::R_SPARC_GOT10
:
2049 case elfcpp::R_SPARC_GOT13
:
2050 case elfcpp::R_SPARC_GOT22
:
2052 return Symbol::ABSOLUTE_REF
;
2054 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2055 case elfcpp::R_SPARC_TLS_GD_LO10
:
2056 case elfcpp::R_SPARC_TLS_GD_ADD
:
2057 case elfcpp::R_SPARC_TLS_GD_CALL
:
2058 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2059 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2060 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2061 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2062 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2063 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2064 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2065 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2066 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2067 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2068 case elfcpp::R_SPARC_TLS_IE_LO10
:
2069 case elfcpp::R_SPARC_TLS_IE_LD
:
2070 case elfcpp::R_SPARC_TLS_IE_LDX
:
2071 case elfcpp::R_SPARC_TLS_IE_ADD
:
2072 return Symbol::TLS_REF
;
2074 case elfcpp::R_SPARC_COPY
:
2075 case elfcpp::R_SPARC_GLOB_DAT
:
2076 case elfcpp::R_SPARC_JMP_SLOT
:
2077 case elfcpp::R_SPARC_JMP_IREL
:
2078 case elfcpp::R_SPARC_RELATIVE
:
2079 case elfcpp::R_SPARC_IRELATIVE
:
2080 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2081 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2082 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2083 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2084 case elfcpp::R_SPARC_TLS_TPOFF64
:
2085 case elfcpp::R_SPARC_TLS_TPOFF32
:
2087 // Not expected. We will give an error later.
2092 // Generate a PLT entry slot for a call to __tls_get_addr
2093 template<int size
, bool big_endian
>
2095 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2097 Target_sparc
<size
, big_endian
>* target
)
2099 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2101 target
->make_plt_entry(symtab
, layout
, gsym
);
2104 // Report an unsupported relocation against a local symbol.
2106 template<int size
, bool big_endian
>
2108 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2109 Sized_relobj_file
<size
, big_endian
>* object
,
2110 unsigned int r_type
)
2112 gold_error(_("%s: unsupported reloc %u against local symbol"),
2113 object
->name().c_str(), r_type
);
2116 // We are about to emit a dynamic relocation of type R_TYPE. If the
2117 // dynamic linker does not support it, issue an error.
2119 template<int size
, bool big_endian
>
2121 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2123 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2129 // These are the relocation types supported by glibc for sparc 64-bit.
2130 case elfcpp::R_SPARC_RELATIVE
:
2131 case elfcpp::R_SPARC_IRELATIVE
:
2132 case elfcpp::R_SPARC_COPY
:
2133 case elfcpp::R_SPARC_64
:
2134 case elfcpp::R_SPARC_GLOB_DAT
:
2135 case elfcpp::R_SPARC_JMP_SLOT
:
2136 case elfcpp::R_SPARC_JMP_IREL
:
2137 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2138 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2139 case elfcpp::R_SPARC_TLS_TPOFF64
:
2140 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2141 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2142 case elfcpp::R_SPARC_8
:
2143 case elfcpp::R_SPARC_16
:
2144 case elfcpp::R_SPARC_DISP8
:
2145 case elfcpp::R_SPARC_DISP16
:
2146 case elfcpp::R_SPARC_DISP32
:
2147 case elfcpp::R_SPARC_WDISP30
:
2148 case elfcpp::R_SPARC_LO10
:
2149 case elfcpp::R_SPARC_HI22
:
2150 case elfcpp::R_SPARC_OLO10
:
2151 case elfcpp::R_SPARC_H34
:
2152 case elfcpp::R_SPARC_H44
:
2153 case elfcpp::R_SPARC_M44
:
2154 case elfcpp::R_SPARC_L44
:
2155 case elfcpp::R_SPARC_HH22
:
2156 case elfcpp::R_SPARC_HM10
:
2157 case elfcpp::R_SPARC_LM22
:
2158 case elfcpp::R_SPARC_UA16
:
2159 case elfcpp::R_SPARC_UA32
:
2160 case elfcpp::R_SPARC_UA64
:
2171 // These are the relocation types supported by glibc for sparc 32-bit.
2172 case elfcpp::R_SPARC_RELATIVE
:
2173 case elfcpp::R_SPARC_IRELATIVE
:
2174 case elfcpp::R_SPARC_COPY
:
2175 case elfcpp::R_SPARC_GLOB_DAT
:
2176 case elfcpp::R_SPARC_32
:
2177 case elfcpp::R_SPARC_JMP_SLOT
:
2178 case elfcpp::R_SPARC_JMP_IREL
:
2179 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2180 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2181 case elfcpp::R_SPARC_TLS_TPOFF32
:
2182 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2183 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2184 case elfcpp::R_SPARC_8
:
2185 case elfcpp::R_SPARC_16
:
2186 case elfcpp::R_SPARC_DISP8
:
2187 case elfcpp::R_SPARC_DISP16
:
2188 case elfcpp::R_SPARC_DISP32
:
2189 case elfcpp::R_SPARC_LO10
:
2190 case elfcpp::R_SPARC_WDISP30
:
2191 case elfcpp::R_SPARC_HI22
:
2192 case elfcpp::R_SPARC_UA16
:
2193 case elfcpp::R_SPARC_UA32
:
2201 // This prevents us from issuing more than one error per reloc
2202 // section. But we can still wind up issuing more than one
2203 // error per object file.
2204 if (this->issued_non_pic_error_
)
2206 gold_assert(parameters
->options().output_is_position_independent());
2207 object
->error(_("requires unsupported dynamic reloc; "
2208 "recompile with -fPIC"));
2209 this->issued_non_pic_error_
= true;
2213 // Return whether we need to make a PLT entry for a relocation of the
2214 // given type against a STT_GNU_IFUNC symbol.
2216 template<int size
, bool big_endian
>
2218 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2219 Sized_relobj_file
<size
, big_endian
>* object
,
2220 unsigned int r_type
)
2222 int flags
= Scan::get_reference_flags(r_type
);
2223 if (flags
& Symbol::TLS_REF
)
2224 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2225 object
->name().c_str(), r_type
);
2229 // Scan a relocation for a local symbol.
2231 template<int size
, bool big_endian
>
2233 Target_sparc
<size
, big_endian
>::Scan::local(
2234 Symbol_table
* symtab
,
2236 Target_sparc
<size
, big_endian
>* target
,
2237 Sized_relobj_file
<size
, big_endian
>* object
,
2238 unsigned int data_shndx
,
2239 Output_section
* output_section
,
2240 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2241 unsigned int r_type
,
2242 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2244 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2245 unsigned int orig_r_type
= r_type
;
2249 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2251 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2252 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2257 case elfcpp::R_SPARC_NONE
:
2258 case elfcpp::R_SPARC_REGISTER
:
2259 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2260 case elfcpp::R_SPARC_GNU_VTENTRY
:
2263 case elfcpp::R_SPARC_64
:
2264 case elfcpp::R_SPARC_32
:
2265 // If building a shared library (or a position-independent
2266 // executable), we need to create a dynamic relocation for
2267 // this location. The relocation applied at link time will
2268 // apply the link-time value, so we flag the location with
2269 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2270 // relocate it easily.
2271 if (parameters
->options().output_is_position_independent())
2273 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2274 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2275 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2276 output_section
, data_shndx
,
2277 reloc
.get_r_offset(),
2278 reloc
.get_r_addend(), is_ifunc
);
2282 case elfcpp::R_SPARC_HIX22
:
2283 case elfcpp::R_SPARC_LOX10
:
2284 case elfcpp::R_SPARC_H34
:
2285 case elfcpp::R_SPARC_H44
:
2286 case elfcpp::R_SPARC_M44
:
2287 case elfcpp::R_SPARC_L44
:
2288 case elfcpp::R_SPARC_HH22
:
2289 case elfcpp::R_SPARC_HM10
:
2290 case elfcpp::R_SPARC_LM22
:
2291 case elfcpp::R_SPARC_UA64
:
2292 case elfcpp::R_SPARC_UA32
:
2293 case elfcpp::R_SPARC_UA16
:
2294 case elfcpp::R_SPARC_HI22
:
2295 case elfcpp::R_SPARC_LO10
:
2296 case elfcpp::R_SPARC_OLO10
:
2297 case elfcpp::R_SPARC_16
:
2298 case elfcpp::R_SPARC_11
:
2299 case elfcpp::R_SPARC_10
:
2300 case elfcpp::R_SPARC_8
:
2301 case elfcpp::R_SPARC_7
:
2302 case elfcpp::R_SPARC_6
:
2303 case elfcpp::R_SPARC_5
:
2304 // If building a shared library (or a position-independent
2305 // executable), we need to create a dynamic relocation for
2307 if (parameters
->options().output_is_position_independent())
2309 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2310 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2312 check_non_pic(object
, r_type
);
2313 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2315 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2316 data_shndx
, reloc
.get_r_offset(),
2317 reloc
.get_r_addend());
2321 gold_assert(lsym
.get_st_value() == 0);
2322 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2323 output_section
, data_shndx
,
2324 reloc
.get_r_offset(),
2325 reloc
.get_r_addend());
2330 case elfcpp::R_SPARC_WDISP30
:
2331 case elfcpp::R_SPARC_WPLT30
:
2332 case elfcpp::R_SPARC_WDISP22
:
2333 case elfcpp::R_SPARC_WDISP19
:
2334 case elfcpp::R_SPARC_WDISP16
:
2335 case elfcpp::R_SPARC_WDISP10
:
2336 case elfcpp::R_SPARC_DISP8
:
2337 case elfcpp::R_SPARC_DISP16
:
2338 case elfcpp::R_SPARC_DISP32
:
2339 case elfcpp::R_SPARC_DISP64
:
2340 case elfcpp::R_SPARC_PC10
:
2341 case elfcpp::R_SPARC_PC22
:
2344 case elfcpp::R_SPARC_GOTDATA_OP
:
2345 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2346 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2347 // We will optimize this into a GOT relative relocation
2348 // and code transform the GOT load into an addition.
2351 case elfcpp::R_SPARC_GOT10
:
2352 case elfcpp::R_SPARC_GOT13
:
2353 case elfcpp::R_SPARC_GOT22
:
2355 // The symbol requires a GOT entry.
2356 Output_data_got
<size
, big_endian
>* got
;
2359 got
= target
->got_section(symtab
, layout
);
2360 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2362 // If we are generating a shared object, we need to add a
2363 // dynamic relocation for this symbol's GOT entry.
2364 if (parameters
->options().output_is_position_independent())
2366 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2368 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2369 unsigned int off
= got
->add_constant(0);
2370 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2371 rela_dyn
->add_local_relative(object
, r_sym
,
2372 elfcpp::R_SPARC_RELATIVE
,
2373 got
, off
, 0, is_ifunc
);
2377 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2381 // These are initial TLS relocs, which are expected when
2383 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2384 case elfcpp::R_SPARC_TLS_GD_LO10
:
2385 case elfcpp::R_SPARC_TLS_GD_ADD
:
2386 case elfcpp::R_SPARC_TLS_GD_CALL
:
2387 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2388 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2389 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2390 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2391 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2392 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2393 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2394 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2395 case elfcpp::R_SPARC_TLS_IE_LO10
:
2396 case elfcpp::R_SPARC_TLS_IE_LD
:
2397 case elfcpp::R_SPARC_TLS_IE_LDX
:
2398 case elfcpp::R_SPARC_TLS_IE_ADD
:
2399 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2400 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2402 bool output_is_shared
= parameters
->options().shared();
2403 const tls::Tls_optimization optimized_type
2404 = optimize_tls_reloc(!output_is_shared
, r_type
);
2407 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2408 case elfcpp::R_SPARC_TLS_GD_LO10
:
2409 case elfcpp::R_SPARC_TLS_GD_ADD
:
2410 case elfcpp::R_SPARC_TLS_GD_CALL
:
2411 if (optimized_type
== tls::TLSOPT_NONE
)
2413 // Create a pair of GOT entries for the module index and
2414 // dtv-relative offset.
2415 Output_data_got
<size
, big_endian
>* got
2416 = target
->got_section(symtab
, layout
);
2417 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2418 unsigned int shndx
= lsym
.get_st_shndx();
2420 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2422 object
->error(_("local symbol %u has bad shndx %u"),
2425 got
->add_local_pair_with_rel(object
, r_sym
,
2426 lsym
.get_st_shndx(),
2428 target
->rela_dyn_section(layout
),
2430 ? elfcpp::R_SPARC_TLS_DTPMOD64
2431 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2433 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2434 generate_tls_call(symtab
, layout
, target
);
2436 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2437 unsupported_reloc_local(object
, r_type
);
2440 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2441 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2442 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2443 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2444 if (optimized_type
== tls::TLSOPT_NONE
)
2446 // Create a GOT entry for the module index.
2447 target
->got_mod_index_entry(symtab
, layout
, object
);
2449 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2450 generate_tls_call(symtab
, layout
, target
);
2452 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2453 unsupported_reloc_local(object
, r_type
);
2456 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2457 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2458 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2461 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2462 case elfcpp::R_SPARC_TLS_IE_LO10
:
2463 case elfcpp::R_SPARC_TLS_IE_LD
:
2464 case elfcpp::R_SPARC_TLS_IE_LDX
:
2465 case elfcpp::R_SPARC_TLS_IE_ADD
:
2466 layout
->set_has_static_tls();
2467 if (optimized_type
== tls::TLSOPT_NONE
)
2469 // Create a GOT entry for the tp-relative offset.
2470 Output_data_got
<size
, big_endian
>* got
2471 = target
->got_section(symtab
, layout
);
2472 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2474 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2476 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2477 unsigned int off
= got
->add_constant(0);
2479 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2481 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2483 elfcpp::R_SPARC_TLS_TPOFF64
:
2484 elfcpp::R_SPARC_TLS_TPOFF32
),
2488 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2489 unsupported_reloc_local(object
, r_type
);
2492 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2493 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2494 layout
->set_has_static_tls();
2495 if (output_is_shared
)
2497 // We need to create a dynamic relocation.
2498 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2499 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2500 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2501 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2502 output_section
, data_shndx
,
2503 reloc
.get_r_offset(), 0);
2510 // These are relocations which should only be seen by the
2511 // dynamic linker, and should never be seen here.
2512 case elfcpp::R_SPARC_COPY
:
2513 case elfcpp::R_SPARC_GLOB_DAT
:
2514 case elfcpp::R_SPARC_JMP_SLOT
:
2515 case elfcpp::R_SPARC_JMP_IREL
:
2516 case elfcpp::R_SPARC_RELATIVE
:
2517 case elfcpp::R_SPARC_IRELATIVE
:
2518 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2519 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2520 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2521 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2522 case elfcpp::R_SPARC_TLS_TPOFF64
:
2523 case elfcpp::R_SPARC_TLS_TPOFF32
:
2524 gold_error(_("%s: unexpected reloc %u in object file"),
2525 object
->name().c_str(), r_type
);
2529 unsupported_reloc_local(object
, r_type
);
2534 // Report an unsupported relocation against a global symbol.
2536 template<int size
, bool big_endian
>
2538 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2539 Sized_relobj_file
<size
, big_endian
>* object
,
2540 unsigned int r_type
,
2543 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2544 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2547 // Scan a relocation for a global symbol.
2549 template<int size
, bool big_endian
>
2551 Target_sparc
<size
, big_endian
>::Scan::global(
2552 Symbol_table
* symtab
,
2554 Target_sparc
<size
, big_endian
>* target
,
2555 Sized_relobj_file
<size
, big_endian
>* object
,
2556 unsigned int data_shndx
,
2557 Output_section
* output_section
,
2558 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2559 unsigned int r_type
,
2562 unsigned int orig_r_type
= r_type
;
2563 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2565 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2566 // section. We check here to avoid creating a dynamic reloc against
2567 // _GLOBAL_OFFSET_TABLE_.
2568 if (!target
->has_got_section()
2569 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2570 target
->got_section(symtab
, layout
);
2574 // A STT_GNU_IFUNC symbol may require a PLT entry.
2576 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2577 target
->make_plt_entry(symtab
, layout
, gsym
);
2581 case elfcpp::R_SPARC_NONE
:
2582 case elfcpp::R_SPARC_REGISTER
:
2583 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2584 case elfcpp::R_SPARC_GNU_VTENTRY
:
2587 case elfcpp::R_SPARC_PLT64
:
2588 case elfcpp::R_SPARC_PLT32
:
2589 case elfcpp::R_SPARC_HIPLT22
:
2590 case elfcpp::R_SPARC_LOPLT10
:
2591 case elfcpp::R_SPARC_PCPLT32
:
2592 case elfcpp::R_SPARC_PCPLT22
:
2593 case elfcpp::R_SPARC_PCPLT10
:
2594 case elfcpp::R_SPARC_WPLT30
:
2595 // If the symbol is fully resolved, this is just a PC32 reloc.
2596 // Otherwise we need a PLT entry.
2597 if (gsym
->final_value_is_known())
2599 // If building a shared library, we can also skip the PLT entry
2600 // if the symbol is defined in the output file and is protected
2602 if (gsym
->is_defined()
2603 && !gsym
->is_from_dynobj()
2604 && !gsym
->is_preemptible())
2606 target
->make_plt_entry(symtab
, layout
, gsym
);
2609 case elfcpp::R_SPARC_DISP8
:
2610 case elfcpp::R_SPARC_DISP16
:
2611 case elfcpp::R_SPARC_DISP32
:
2612 case elfcpp::R_SPARC_DISP64
:
2613 case elfcpp::R_SPARC_PC_HH22
:
2614 case elfcpp::R_SPARC_PC_HM10
:
2615 case elfcpp::R_SPARC_PC_LM22
:
2616 case elfcpp::R_SPARC_PC10
:
2617 case elfcpp::R_SPARC_PC22
:
2618 case elfcpp::R_SPARC_WDISP30
:
2619 case elfcpp::R_SPARC_WDISP22
:
2620 case elfcpp::R_SPARC_WDISP19
:
2621 case elfcpp::R_SPARC_WDISP16
:
2622 case elfcpp::R_SPARC_WDISP10
:
2624 if (gsym
->needs_plt_entry())
2625 target
->make_plt_entry(symtab
, layout
, gsym
);
2626 // Make a dynamic relocation if necessary.
2627 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2629 if (gsym
->may_need_copy_reloc())
2631 target
->copy_reloc(symtab
, layout
, object
,
2632 data_shndx
, output_section
, gsym
,
2637 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2638 check_non_pic(object
, r_type
);
2639 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2640 data_shndx
, reloc
.get_r_offset(),
2641 reloc
.get_r_addend());
2647 case elfcpp::R_SPARC_UA64
:
2648 case elfcpp::R_SPARC_64
:
2649 case elfcpp::R_SPARC_HIX22
:
2650 case elfcpp::R_SPARC_LOX10
:
2651 case elfcpp::R_SPARC_H34
:
2652 case elfcpp::R_SPARC_H44
:
2653 case elfcpp::R_SPARC_M44
:
2654 case elfcpp::R_SPARC_L44
:
2655 case elfcpp::R_SPARC_HH22
:
2656 case elfcpp::R_SPARC_HM10
:
2657 case elfcpp::R_SPARC_LM22
:
2658 case elfcpp::R_SPARC_HI22
:
2659 case elfcpp::R_SPARC_LO10
:
2660 case elfcpp::R_SPARC_OLO10
:
2661 case elfcpp::R_SPARC_UA32
:
2662 case elfcpp::R_SPARC_32
:
2663 case elfcpp::R_SPARC_UA16
:
2664 case elfcpp::R_SPARC_16
:
2665 case elfcpp::R_SPARC_11
:
2666 case elfcpp::R_SPARC_10
:
2667 case elfcpp::R_SPARC_8
:
2668 case elfcpp::R_SPARC_7
:
2669 case elfcpp::R_SPARC_6
:
2670 case elfcpp::R_SPARC_5
:
2672 // Make a PLT entry if necessary.
2673 if (gsym
->needs_plt_entry())
2675 target
->make_plt_entry(symtab
, layout
, gsym
);
2676 // Since this is not a PC-relative relocation, we may be
2677 // taking the address of a function. In that case we need to
2678 // set the entry in the dynamic symbol table to the address of
2680 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2681 gsym
->set_needs_dynsym_value();
2683 // Make a dynamic relocation if necessary.
2684 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2686 unsigned int r_off
= reloc
.get_r_offset();
2688 // The assembler can sometimes emit unaligned relocations
2689 // for dwarf2 cfi directives.
2692 case elfcpp::R_SPARC_16
:
2694 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2696 case elfcpp::R_SPARC_32
:
2698 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2700 case elfcpp::R_SPARC_64
:
2702 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2704 case elfcpp::R_SPARC_UA16
:
2706 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2708 case elfcpp::R_SPARC_UA32
:
2710 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2712 case elfcpp::R_SPARC_UA64
:
2714 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2718 if (gsym
->may_need_copy_reloc())
2720 target
->copy_reloc(symtab
, layout
, object
,
2721 data_shndx
, output_section
, gsym
, reloc
);
2723 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2724 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2725 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2726 && gsym
->can_use_relative_reloc(false)
2727 && !gsym
->is_from_dynobj()
2728 && !gsym
->is_undefined()
2729 && !gsym
->is_preemptible())
2731 // Use an IRELATIVE reloc for a locally defined
2732 // STT_GNU_IFUNC symbol. This makes a function
2733 // address in a PIE executable match the address in a
2734 // shared library that it links against.
2735 Reloc_section
* rela_dyn
=
2736 target
->rela_ifunc_section(layout
);
2737 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2738 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2739 output_section
, object
,
2741 reloc
.get_r_offset(),
2742 reloc
.get_r_addend());
2744 else if ((r_type
== elfcpp::R_SPARC_32
2745 || r_type
== elfcpp::R_SPARC_64
)
2746 && gsym
->can_use_relative_reloc(false))
2748 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2749 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2750 output_section
, object
,
2751 data_shndx
, reloc
.get_r_offset(),
2752 reloc
.get_r_addend(), is_ifunc
);
2756 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2758 check_non_pic(object
, r_type
);
2759 if (gsym
->is_from_dynobj()
2760 || gsym
->is_undefined()
2761 || gsym
->is_preemptible())
2762 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2764 reloc
.get_r_offset(),
2765 reloc
.get_r_addend());
2767 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2770 reloc
.get_r_offset(),
2771 reloc
.get_r_addend());
2777 case elfcpp::R_SPARC_GOTDATA_OP
:
2778 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2779 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2780 if (gsym
->is_defined()
2781 && !gsym
->is_from_dynobj()
2782 && !gsym
->is_preemptible()
2785 // We will optimize this into a GOT relative relocation
2786 // and code transform the GOT load into an addition.
2789 case elfcpp::R_SPARC_GOT10
:
2790 case elfcpp::R_SPARC_GOT13
:
2791 case elfcpp::R_SPARC_GOT22
:
2793 // The symbol requires a GOT entry.
2794 Output_data_got
<size
, big_endian
>* got
;
2796 got
= target
->got_section(symtab
, layout
);
2797 if (gsym
->final_value_is_known())
2799 // For a STT_GNU_IFUNC symbol we want the PLT address.
2800 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2801 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2803 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2807 // If this symbol is not fully resolved, we need to add a
2808 // GOT entry with a dynamic relocation.
2809 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2811 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2813 // 1) The symbol may be defined in some other module.
2815 // 2) We are building a shared library and this is a
2816 // protected symbol; using GLOB_DAT means that the dynamic
2817 // linker can use the address of the PLT in the main
2818 // executable when appropriate so that function address
2819 // comparisons work.
2821 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2822 // code, again so that function address comparisons work.
2823 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2824 if (gsym
->is_from_dynobj()
2825 || gsym
->is_undefined()
2826 || gsym
->is_preemptible()
2827 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2828 && parameters
->options().shared())
2829 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2830 && parameters
->options().output_is_position_independent()
2831 && !gsym
->is_forced_local()))
2833 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2835 // If this symbol is forced local, this relocation will
2836 // not work properly. That's because ld.so on sparc
2837 // (and 32-bit powerpc) expects st_value in the r_addend
2838 // of relocations for STB_LOCAL symbols. Curiously the
2839 // BFD linker does not promote global hidden symbols to be
2840 // STB_LOCAL in the dynamic symbol table like Gold does.
2841 gold_assert(!gsym
->is_forced_local());
2842 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2845 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2847 unsigned int off
= got
->add_constant(0);
2849 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2852 // Tell the dynamic linker to use the PLT address
2853 // when resolving relocations.
2854 if (gsym
->is_from_dynobj()
2855 && !parameters
->options().shared())
2856 gsym
->set_needs_dynsym_value();
2858 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2859 got
, off
, 0, is_ifunc
);
2865 // These are initial tls relocs, which are expected when
2867 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2868 case elfcpp::R_SPARC_TLS_GD_LO10
:
2869 case elfcpp::R_SPARC_TLS_GD_ADD
:
2870 case elfcpp::R_SPARC_TLS_GD_CALL
:
2871 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2872 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2873 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2874 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2875 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2876 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2877 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2878 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2879 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2880 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2881 case elfcpp::R_SPARC_TLS_IE_LO10
:
2882 case elfcpp::R_SPARC_TLS_IE_LD
:
2883 case elfcpp::R_SPARC_TLS_IE_LDX
:
2884 case elfcpp::R_SPARC_TLS_IE_ADD
:
2886 const bool is_final
= gsym
->final_value_is_known();
2887 const tls::Tls_optimization optimized_type
2888 = optimize_tls_reloc(is_final
, r_type
);
2891 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2892 case elfcpp::R_SPARC_TLS_GD_LO10
:
2893 case elfcpp::R_SPARC_TLS_GD_ADD
:
2894 case elfcpp::R_SPARC_TLS_GD_CALL
:
2895 if (optimized_type
== tls::TLSOPT_NONE
)
2897 // Create a pair of GOT entries for the module index and
2898 // dtv-relative offset.
2899 Output_data_got
<size
, big_endian
>* got
2900 = target
->got_section(symtab
, layout
);
2901 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2902 target
->rela_dyn_section(layout
),
2904 ? elfcpp::R_SPARC_TLS_DTPMOD64
2905 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2907 ? elfcpp::R_SPARC_TLS_DTPOFF64
2908 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2910 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2911 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2912 generate_tls_call(symtab
, layout
, target
);
2914 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2916 // Create a GOT entry for the tp-relative offset.
2917 Output_data_got
<size
, big_endian
>* got
2918 = target
->got_section(symtab
, layout
);
2919 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2920 target
->rela_dyn_section(layout
),
2922 elfcpp::R_SPARC_TLS_TPOFF64
:
2923 elfcpp::R_SPARC_TLS_TPOFF32
));
2925 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2926 unsupported_reloc_global(object
, r_type
, gsym
);
2929 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2930 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2931 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2932 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2933 if (optimized_type
== tls::TLSOPT_NONE
)
2935 // Create a GOT entry for the module index.
2936 target
->got_mod_index_entry(symtab
, layout
, object
);
2938 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2939 generate_tls_call(symtab
, layout
, target
);
2941 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2942 unsupported_reloc_global(object
, r_type
, gsym
);
2945 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2946 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2947 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2950 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2951 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2952 layout
->set_has_static_tls();
2953 if (parameters
->options().shared())
2955 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2956 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2957 output_section
, object
,
2958 data_shndx
, reloc
.get_r_offset(),
2963 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2964 case elfcpp::R_SPARC_TLS_IE_LO10
:
2965 case elfcpp::R_SPARC_TLS_IE_LD
:
2966 case elfcpp::R_SPARC_TLS_IE_LDX
:
2967 case elfcpp::R_SPARC_TLS_IE_ADD
:
2968 layout
->set_has_static_tls();
2969 if (optimized_type
== tls::TLSOPT_NONE
)
2971 // Create a GOT entry for the tp-relative offset.
2972 Output_data_got
<size
, big_endian
>* got
2973 = target
->got_section(symtab
, layout
);
2974 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2975 target
->rela_dyn_section(layout
),
2977 ? elfcpp::R_SPARC_TLS_TPOFF64
2978 : elfcpp::R_SPARC_TLS_TPOFF32
));
2980 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2981 unsupported_reloc_global(object
, r_type
, gsym
);
2987 // These are relocations which should only be seen by the
2988 // dynamic linker, and should never be seen here.
2989 case elfcpp::R_SPARC_COPY
:
2990 case elfcpp::R_SPARC_GLOB_DAT
:
2991 case elfcpp::R_SPARC_JMP_SLOT
:
2992 case elfcpp::R_SPARC_JMP_IREL
:
2993 case elfcpp::R_SPARC_RELATIVE
:
2994 case elfcpp::R_SPARC_IRELATIVE
:
2995 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2996 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2997 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2998 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2999 case elfcpp::R_SPARC_TLS_TPOFF64
:
3000 case elfcpp::R_SPARC_TLS_TPOFF32
:
3001 gold_error(_("%s: unexpected reloc %u in object file"),
3002 object
->name().c_str(), r_type
);
3006 unsupported_reloc_global(object
, r_type
, gsym
);
3011 // Process relocations for gc.
3013 template<int size
, bool big_endian
>
3015 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3016 Symbol_table
* symtab
,
3018 Sized_relobj_file
<size
, big_endian
>* object
,
3019 unsigned int data_shndx
,
3021 const unsigned char* prelocs
,
3023 Output_section
* output_section
,
3024 bool needs_special_offset_handling
,
3025 size_t local_symbol_count
,
3026 const unsigned char* plocal_symbols
)
3028 typedef Target_sparc
<size
, big_endian
> Sparc
;
3029 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3031 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
3032 typename
Target_sparc::Relocatable_size_for_reloc
>(
3041 needs_special_offset_handling
,
3046 // Scan relocations for a section.
3048 template<int size
, bool big_endian
>
3050 Target_sparc
<size
, big_endian
>::scan_relocs(
3051 Symbol_table
* symtab
,
3053 Sized_relobj_file
<size
, big_endian
>* object
,
3054 unsigned int data_shndx
,
3055 unsigned int sh_type
,
3056 const unsigned char* prelocs
,
3058 Output_section
* output_section
,
3059 bool needs_special_offset_handling
,
3060 size_t local_symbol_count
,
3061 const unsigned char* plocal_symbols
)
3063 typedef Target_sparc
<size
, big_endian
> Sparc
;
3064 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3066 if (sh_type
== elfcpp::SHT_REL
)
3068 gold_error(_("%s: unsupported REL reloc section"),
3069 object
->name().c_str());
3073 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
3082 needs_special_offset_handling
,
3087 // Finalize the sections.
3089 template<int size
, bool big_endian
>
3091 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3093 const Input_objects
*,
3094 Symbol_table
* symtab
)
3097 this->plt_
->emit_pending_ifunc_relocs();
3099 // Fill in some more dynamic tags.
3100 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3102 : this->plt_
->rel_plt());
3103 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3104 this->rela_dyn_
, true, true);
3106 // Emit any relocs we saved in an attempt to avoid generating COPY
3108 if (this->copy_relocs_
.any_saved_relocs())
3109 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3111 if (parameters
->doing_static_link()
3112 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3114 // If linking statically, make sure that the __rela_iplt symbols
3115 // were defined if necessary, even if we didn't create a PLT.
3116 static const Define_symbol_in_segment syms
[] =
3119 "__rela_iplt_start", // name
3120 elfcpp::PT_LOAD
, // segment_type
3121 elfcpp::PF_W
, // segment_flags_set
3122 elfcpp::PF(0), // segment_flags_clear
3125 elfcpp::STT_NOTYPE
, // type
3126 elfcpp::STB_GLOBAL
, // binding
3127 elfcpp::STV_HIDDEN
, // visibility
3129 Symbol::SEGMENT_START
, // offset_from_base
3133 "__rela_iplt_end", // name
3134 elfcpp::PT_LOAD
, // segment_type
3135 elfcpp::PF_W
, // segment_flags_set
3136 elfcpp::PF(0), // segment_flags_clear
3139 elfcpp::STT_NOTYPE
, // type
3140 elfcpp::STB_GLOBAL
, // binding
3141 elfcpp::STV_HIDDEN
, // visibility
3143 Symbol::SEGMENT_START
, // offset_from_base
3148 symtab
->define_symbols(layout
, 2, syms
,
3149 layout
->script_options()->saw_sections_clause());
3153 // Perform a relocation.
3155 template<int size
, bool big_endian
>
3157 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3158 const Relocate_info
<size
, big_endian
>* relinfo
,
3159 Target_sparc
* target
,
3162 const elfcpp::Rela
<size
, big_endian
>& rela
,
3163 unsigned int r_type
,
3164 const Sized_symbol
<size
>* gsym
,
3165 const Symbol_value
<size
>* psymval
,
3166 unsigned char* view
,
3167 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3168 section_size_type view_size
)
3170 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3173 if (this->ignore_gd_add_
)
3175 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3176 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3177 _("missing expected TLS relocation"));
3180 this->ignore_gd_add_
= false;
3184 if (this->reloc_adjust_addr_
== view
)
3187 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3188 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3190 // Pick the value to use for symbols defined in shared objects.
3191 Symbol_value
<size
> symval
;
3193 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3195 elfcpp::Elf_Xword value
;
3197 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3199 symval
.set_output_value(value
);
3203 else if (gsym
== NULL
&& orig_is_ifunc
)
3205 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3206 if (object
->local_has_plt_offset(r_sym
))
3208 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3209 + object
->local_plt_offset(r_sym
));
3214 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3216 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3217 // pointer points to the beginning, not the end, of the table.
3218 // So we just use the plain offset.
3219 unsigned int got_offset
= 0;
3220 bool gdop_valid
= false;
3223 case elfcpp::R_SPARC_GOTDATA_OP
:
3224 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3225 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3226 // If this is local, we did not create a GOT entry because we
3227 // intend to transform this into a GOT relative relocation.
3229 || (gsym
->is_defined()
3230 && !gsym
->is_from_dynobj()
3231 && !gsym
->is_preemptible()
3234 got_offset
= psymval
->value(object
, 0) - target
->got_address();
3238 case elfcpp::R_SPARC_GOT10
:
3239 case elfcpp::R_SPARC_GOT13
:
3240 case elfcpp::R_SPARC_GOT22
:
3243 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3244 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3248 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3249 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3250 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3260 case elfcpp::R_SPARC_NONE
:
3261 case elfcpp::R_SPARC_REGISTER
:
3262 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3263 case elfcpp::R_SPARC_GNU_VTENTRY
:
3266 case elfcpp::R_SPARC_8
:
3267 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3271 case elfcpp::R_SPARC_16
:
3272 if (rela
.get_r_offset() & 0x1)
3274 // The assembler can sometimes emit unaligned relocations
3275 // for dwarf2 cfi directives.
3276 Reloc::ua16(view
, object
, psymval
, addend
);
3279 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3283 case elfcpp::R_SPARC_32
:
3284 if (!parameters
->options().output_is_position_independent())
3286 if (rela
.get_r_offset() & 0x3)
3288 // The assembler can sometimes emit unaligned relocations
3289 // for dwarf2 cfi directives.
3290 Reloc::ua32(view
, object
, psymval
, addend
);
3293 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3298 case elfcpp::R_SPARC_DISP8
:
3299 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3302 case elfcpp::R_SPARC_DISP16
:
3303 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3306 case elfcpp::R_SPARC_DISP32
:
3307 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3310 case elfcpp::R_SPARC_DISP64
:
3311 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3314 case elfcpp::R_SPARC_WDISP30
:
3315 case elfcpp::R_SPARC_WPLT30
:
3316 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3317 if (target
->may_relax())
3318 relax_call(target
, view
, rela
, view_size
);
3321 case elfcpp::R_SPARC_WDISP22
:
3322 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3325 case elfcpp::R_SPARC_WDISP19
:
3326 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3329 case elfcpp::R_SPARC_WDISP16
:
3330 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3333 case elfcpp::R_SPARC_WDISP10
:
3334 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3337 case elfcpp::R_SPARC_HI22
:
3338 Reloc::hi22(view
, object
, psymval
, addend
);
3341 case elfcpp::R_SPARC_22
:
3342 Reloc::rela32_22(view
, object
, psymval
, addend
);
3345 case elfcpp::R_SPARC_13
:
3346 Reloc::rela32_13(view
, object
, psymval
, addend
);
3349 case elfcpp::R_SPARC_LO10
:
3350 Reloc::lo10(view
, object
, psymval
, addend
);
3353 case elfcpp::R_SPARC_GOT10
:
3354 Reloc::lo10(view
, got_offset
, addend
);
3357 case elfcpp::R_SPARC_GOTDATA_OP
:
3360 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3361 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3364 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3365 val
= elfcpp::Swap
<32, true>::readval(wv
);
3366 val
= 0x80000000 | (val
& 0x3e07c01f);
3367 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3371 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3374 Reloc::gdop_lox10(view
, got_offset
, addend
);
3378 case elfcpp::R_SPARC_GOT13
:
3379 Reloc::rela32_13(view
, got_offset
, addend
);
3382 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3385 Reloc::gdop_hix22(view
, got_offset
, addend
);
3389 case elfcpp::R_SPARC_GOT22
:
3390 Reloc::hi22(view
, got_offset
, addend
);
3393 case elfcpp::R_SPARC_PC10
:
3394 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3397 case elfcpp::R_SPARC_PC22
:
3398 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3401 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3402 case elfcpp::R_SPARC_UA32
:
3403 Reloc::ua32(view
, object
, psymval
, addend
);
3406 case elfcpp::R_SPARC_PLT64
:
3407 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3411 case elfcpp::R_SPARC_PLT32
:
3412 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3416 case elfcpp::R_SPARC_HIPLT22
:
3417 Reloc::hi22(view
, object
, psymval
, addend
);
3420 case elfcpp::R_SPARC_LOPLT10
:
3421 Reloc::lo10(view
, object
, psymval
, addend
);
3424 case elfcpp::R_SPARC_PCPLT32
:
3425 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3428 case elfcpp::R_SPARC_PCPLT22
:
3429 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3432 case elfcpp::R_SPARC_PCPLT10
:
3433 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3436 case elfcpp::R_SPARC_64
:
3437 if (!parameters
->options().output_is_position_independent())
3439 if (rela
.get_r_offset() & 0x7)
3441 // The assembler can sometimes emit unaligned relocations
3442 // for dwarf2 cfi directives.
3443 Reloc::ua64(view
, object
, psymval
, addend
);
3446 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3451 case elfcpp::R_SPARC_OLO10
:
3453 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3454 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3455 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3459 case elfcpp::R_SPARC_HH22
:
3460 Reloc::hh22(view
, object
, psymval
, addend
);
3463 case elfcpp::R_SPARC_PC_HH22
:
3464 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3467 case elfcpp::R_SPARC_HM10
:
3468 Reloc::hm10(view
, object
, psymval
, addend
);
3471 case elfcpp::R_SPARC_PC_HM10
:
3472 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3475 case elfcpp::R_SPARC_LM22
:
3476 Reloc::hi22(view
, object
, psymval
, addend
);
3479 case elfcpp::R_SPARC_PC_LM22
:
3480 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3483 case elfcpp::R_SPARC_11
:
3484 Reloc::rela32_11(view
, object
, psymval
, addend
);
3487 case elfcpp::R_SPARC_10
:
3488 Reloc::rela32_10(view
, object
, psymval
, addend
);
3491 case elfcpp::R_SPARC_7
:
3492 Reloc::rela32_7(view
, object
, psymval
, addend
);
3495 case elfcpp::R_SPARC_6
:
3496 Reloc::rela32_6(view
, object
, psymval
, addend
);
3499 case elfcpp::R_SPARC_5
:
3500 Reloc::rela32_5(view
, object
, psymval
, addend
);
3503 case elfcpp::R_SPARC_HIX22
:
3504 Reloc::hix22(view
, object
, psymval
, addend
);
3507 case elfcpp::R_SPARC_LOX10
:
3508 Reloc::lox10(view
, object
, psymval
, addend
);
3511 case elfcpp::R_SPARC_H34
:
3512 Reloc::h34(view
, object
, psymval
, addend
);
3515 case elfcpp::R_SPARC_H44
:
3516 Reloc::h44(view
, object
, psymval
, addend
);
3519 case elfcpp::R_SPARC_M44
:
3520 Reloc::m44(view
, object
, psymval
, addend
);
3523 case elfcpp::R_SPARC_L44
:
3524 Reloc::l44(view
, object
, psymval
, addend
);
3527 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3528 case elfcpp::R_SPARC_UA64
:
3529 Reloc::ua64(view
, object
, psymval
, addend
);
3532 case elfcpp::R_SPARC_UA16
:
3533 Reloc::ua16(view
, object
, psymval
, addend
);
3536 case elfcpp::R_SPARC_TLS_GD_HI22
:
3537 case elfcpp::R_SPARC_TLS_GD_LO10
:
3538 case elfcpp::R_SPARC_TLS_GD_ADD
:
3539 case elfcpp::R_SPARC_TLS_GD_CALL
:
3540 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3541 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3542 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3543 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3544 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3545 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3546 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3547 case elfcpp::R_SPARC_TLS_IE_HI22
:
3548 case elfcpp::R_SPARC_TLS_IE_LO10
:
3549 case elfcpp::R_SPARC_TLS_IE_LD
:
3550 case elfcpp::R_SPARC_TLS_IE_LDX
:
3551 case elfcpp::R_SPARC_TLS_IE_ADD
:
3552 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3553 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3554 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3555 r_type
, gsym
, psymval
, view
,
3556 address
, view_size
);
3559 case elfcpp::R_SPARC_COPY
:
3560 case elfcpp::R_SPARC_GLOB_DAT
:
3561 case elfcpp::R_SPARC_JMP_SLOT
:
3562 case elfcpp::R_SPARC_JMP_IREL
:
3563 case elfcpp::R_SPARC_RELATIVE
:
3564 case elfcpp::R_SPARC_IRELATIVE
:
3565 // These are outstanding tls relocs, which are unexpected when
3567 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3568 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3569 case elfcpp::R_SPARC_TLS_TPOFF64
:
3570 case elfcpp::R_SPARC_TLS_TPOFF32
:
3571 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3572 _("unexpected reloc %u in object file"),
3577 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3578 _("unsupported reloc %u"),
3586 // Perform a TLS relocation.
3588 template<int size
, bool big_endian
>
3590 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3591 const Relocate_info
<size
, big_endian
>* relinfo
,
3592 Target_sparc
<size
, big_endian
>* target
,
3594 const elfcpp::Rela
<size
, big_endian
>& rela
,
3595 unsigned int r_type
,
3596 const Sized_symbol
<size
>* gsym
,
3597 const Symbol_value
<size
>* psymval
,
3598 unsigned char* view
,
3599 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3602 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3603 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3604 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3605 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3607 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3608 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3610 const bool is_final
=
3612 ? !parameters
->options().output_is_position_independent()
3613 : gsym
->final_value_is_known());
3614 const tls::Tls_optimization optimized_type
3615 = optimize_tls_reloc(is_final
, r_type
);
3619 case elfcpp::R_SPARC_TLS_GD_HI22
:
3620 case elfcpp::R_SPARC_TLS_GD_LO10
:
3621 case elfcpp::R_SPARC_TLS_GD_ADD
:
3622 case elfcpp::R_SPARC_TLS_GD_CALL
:
3623 if (optimized_type
== tls::TLSOPT_TO_LE
)
3625 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3628 value
-= tls_segment
->memsz();
3632 case elfcpp::R_SPARC_TLS_GD_HI22
:
3633 // TLS_GD_HI22 --> TLS_LE_HIX22
3634 Reloc::hix22(view
, value
, addend
);
3637 case elfcpp::R_SPARC_TLS_GD_LO10
:
3638 // TLS_GD_LO10 --> TLS_LE_LOX10
3639 Reloc::lox10(view
, value
, addend
);
3642 case elfcpp::R_SPARC_TLS_GD_ADD
:
3643 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3644 val
= elfcpp::Swap
<32, true>::readval(wv
);
3645 val
= (val
& ~0x7c000) | 0x1c000;
3646 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3648 case elfcpp::R_SPARC_TLS_GD_CALL
:
3649 // call __tls_get_addr --> nop
3650 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3657 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3658 ? GOT_TYPE_TLS_OFFSET
3659 : GOT_TYPE_TLS_PAIR
);
3662 gold_assert(gsym
->has_got_offset(got_type
));
3663 value
= gsym
->got_offset(got_type
);
3667 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3668 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3669 value
= object
->local_got_offset(r_sym
, got_type
);
3671 if (optimized_type
== tls::TLSOPT_TO_IE
)
3673 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3678 case elfcpp::R_SPARC_TLS_GD_HI22
:
3679 // TLS_GD_HI22 --> TLS_IE_HI22
3680 Reloc::hi22(view
, value
, addend
);
3683 case elfcpp::R_SPARC_TLS_GD_LO10
:
3684 // TLS_GD_LO10 --> TLS_IE_LO10
3685 Reloc::lo10(view
, value
, addend
);
3688 case elfcpp::R_SPARC_TLS_GD_ADD
:
3689 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3690 val
= elfcpp::Swap
<32, true>::readval(wv
);
3697 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3700 case elfcpp::R_SPARC_TLS_GD_CALL
:
3701 // The compiler can put the TLS_GD_ADD instruction
3702 // into the delay slot of the call. If so, we need
3703 // to transpose the two instructions so that the
3704 // new sequence works properly.
3706 // The test we use is if the instruction in the
3707 // delay slot is an add with destination register
3709 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3710 if ((val
& 0x81f80000) == 0x80000000
3711 && ((val
>> 25) & 0x1f) == 0x8)
3718 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3721 this->ignore_gd_add_
= true;
3725 // Even if the delay slot isn't the TLS_GD_ADD
3726 // instruction, we still have to handle the case
3727 // where it sets up %o0 in some other way.
3728 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3730 this->reloc_adjust_addr_
= view
+ 4;
3732 // call __tls_get_addr --> add %g7, %o0, %o0
3733 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3738 else if (optimized_type
== tls::TLSOPT_NONE
)
3742 case elfcpp::R_SPARC_TLS_GD_HI22
:
3743 Reloc::hi22(view
, value
, addend
);
3745 case elfcpp::R_SPARC_TLS_GD_LO10
:
3746 Reloc::lo10(view
, value
, addend
);
3748 case elfcpp::R_SPARC_TLS_GD_ADD
:
3750 case elfcpp::R_SPARC_TLS_GD_CALL
:
3752 Symbol_value
<size
> symval
;
3753 elfcpp::Elf_Xword value
;
3756 tsym
= target
->tls_get_addr_sym_
;
3758 value
= (target
->plt_section()->address() +
3759 tsym
->plt_offset());
3760 symval
.set_output_value(value
);
3761 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3768 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3769 _("unsupported reloc %u"),
3773 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3774 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3775 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3776 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3777 if (optimized_type
== tls::TLSOPT_TO_LE
)
3779 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3783 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3784 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3785 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3786 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3789 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3790 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3795 else if (optimized_type
== tls::TLSOPT_NONE
)
3797 // Relocate the field with the offset of the GOT entry for
3798 // the module index.
3799 unsigned int got_offset
;
3801 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3804 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3805 Reloc::hi22(view
, got_offset
, addend
);
3807 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3808 Reloc::lo10(view
, got_offset
, addend
);
3810 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3812 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3814 Symbol_value
<size
> symval
;
3815 elfcpp::Elf_Xword value
;
3818 tsym
= target
->tls_get_addr_sym_
;
3820 value
= (target
->plt_section()->address() +
3821 tsym
->plt_offset());
3822 symval
.set_output_value(value
);
3823 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3829 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3830 _("unsupported reloc %u"),
3834 // These relocs can appear in debugging sections, in which case
3835 // we won't see the TLS_LDM relocs. The local_dynamic_type
3836 // field tells us this.
3837 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3838 if (optimized_type
== tls::TLSOPT_TO_LE
)
3840 value
-= tls_segment
->memsz();
3841 Reloc::hix22(view
, value
, addend
);
3844 Reloc::ldo_hix22(view
, value
, addend
);
3846 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3847 if (optimized_type
== tls::TLSOPT_TO_LE
)
3849 value
-= tls_segment
->memsz();
3850 Reloc::lox10(view
, value
, addend
);
3853 Reloc::ldo_lox10(view
, value
, addend
);
3855 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3856 if (optimized_type
== tls::TLSOPT_TO_LE
)
3858 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3861 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3862 val
= elfcpp::Swap
<32, true>::readval(wv
);
3863 val
= (val
& ~0x7c000) | 0x1c000;
3864 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3868 // When optimizing IE --> LE, the only relocation that is handled
3869 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3870 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3871 // rs2 and rd are the same.
3872 case elfcpp::R_SPARC_TLS_IE_LD
:
3873 case elfcpp::R_SPARC_TLS_IE_LDX
:
3874 if (optimized_type
== tls::TLSOPT_TO_LE
)
3876 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3877 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3878 Insntype rs2
= val
& 0x1f;
3879 Insntype rd
= (val
>> 25) & 0x1f;
3884 val
= sparc_mov
| (val
& 0x3e00001f);
3886 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3890 case elfcpp::R_SPARC_TLS_IE_HI22
:
3891 case elfcpp::R_SPARC_TLS_IE_LO10
:
3892 if (optimized_type
== tls::TLSOPT_TO_LE
)
3894 value
-= tls_segment
->memsz();
3897 case elfcpp::R_SPARC_TLS_IE_HI22
:
3898 // IE_HI22 --> LE_HIX22
3899 Reloc::hix22(view
, value
, addend
);
3901 case elfcpp::R_SPARC_TLS_IE_LO10
:
3902 // IE_LO10 --> LE_LOX10
3903 Reloc::lox10(view
, value
, addend
);
3908 else if (optimized_type
== tls::TLSOPT_NONE
)
3910 // Relocate the field with the offset of the GOT entry for
3911 // the tp-relative offset of the symbol.
3914 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3915 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3919 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3920 gold_assert(object
->local_has_got_offset(r_sym
,
3921 GOT_TYPE_TLS_OFFSET
));
3922 value
= object
->local_got_offset(r_sym
,
3923 GOT_TYPE_TLS_OFFSET
);
3927 case elfcpp::R_SPARC_TLS_IE_HI22
:
3928 Reloc::hi22(view
, value
, addend
);
3930 case elfcpp::R_SPARC_TLS_IE_LO10
:
3931 Reloc::lo10(view
, value
, addend
);
3936 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3937 _("unsupported reloc %u"),
3941 case elfcpp::R_SPARC_TLS_IE_ADD
:
3942 // This seems to be mainly so that we can find the addition
3943 // instruction if there is one. There doesn't seem to be any
3944 // actual relocation to apply.
3947 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3948 // If we're creating a shared library, a dynamic relocation will
3949 // have been created for this location, so do not apply it now.
3950 if (!parameters
->options().shared())
3952 value
-= tls_segment
->memsz();
3953 Reloc::hix22(view
, value
, addend
);
3957 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3958 // If we're creating a shared library, a dynamic relocation will
3959 // have been created for this location, so do not apply it now.
3960 if (!parameters
->options().shared())
3962 value
-= tls_segment
->memsz();
3963 Reloc::lox10(view
, value
, addend
);
3969 // Relax a call instruction.
3971 template<int size
, bool big_endian
>
3973 Target_sparc
<size
, big_endian
>::Relocate::relax_call(
3974 Target_sparc
<size
, big_endian
>* target
,
3975 unsigned char* view
,
3976 const elfcpp::Rela
<size
, big_endian
>& rela
,
3977 section_size_type view_size
)
3979 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3980 Insntype
*wv
= reinterpret_cast<Insntype
*>(view
);
3981 Insntype call_insn
, delay_insn
, set_insn
;
3982 uint32_t op3
, reg
, off
;
3984 // This code tries to relax call instructions that meet
3985 // certain criteria.
3987 // The first criteria is that the call must be such that the return
3988 // address which the call writes into %o7 is unused. Two sequences
3989 // meet this criteria, and are used to implement tail calls.
3991 // Leaf function tail call:
3993 // or %o7, %g0, %ANY_REG
3995 // or %ANY_REG, %g0, %o7
3997 // Non-leaf function tail call:
4002 // The second criteria is that the call destination is close. If
4003 // the displacement can fit in a signed 22-bit immediate field of a
4004 // pre-V9 branch, we can do it. If we are generating a 64-bit
4005 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4006 // and the displacement fits in a signed 19-bit immediate field,
4007 // then we can use a V9 branch.
4009 // Make sure the delay instruction can be safely accessed.
4010 if (rela
.get_r_offset() + 8 > view_size
)
4013 call_insn
= elfcpp::Swap
<32, true>::readval(wv
);
4014 delay_insn
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
4016 // Make sure it is really a call instruction.
4017 if (((call_insn
>> 30) & 0x3) != 1)
4020 if (((delay_insn
>> 30) & 0x3) != 2)
4023 // Accept only a restore or an integer arithmetic operation whose
4024 // sole side effect is to write the %o7 register (and perhaps set
4025 // the condition codes, which are considered clobbered across
4028 // For example, we don't want to match a tagged addition or
4029 // subtraction. We also don't want to match something like a
4032 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4033 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4035 op3
= (delay_insn
>> 19) & 0x3f;
4036 reg
= (delay_insn
>> 25) & 0x1f;
4038 && ((op3
& 0x28) != 0 || reg
!= 15))
4041 // For non-restore instructions, make sure %o7 isn't
4046 reg
= (delay_insn
>> 14) & 0x15;
4050 // And if non-immediate, check RS2
4051 if (((delay_insn
>> 13) & 1) == 0)
4053 reg
= (delay_insn
& 0x1f);
4059 // Now check the branch distance. We are called after the
4060 // call has been relocated, so we just have to peek at the
4061 // offset contained in the instruction.
4062 off
= call_insn
& 0x3fffffff;
4063 if ((off
& 0x3fe00000) != 0
4064 && (off
& 0x3fe00000) != 0x3fe00000)
4067 if ((size
== 64 || target
->elf_machine_
== elfcpp::EM_SPARC32PLUS
)
4068 && ((off
& 0x3c0000) == 0
4069 || (off
& 0x3c0000) == 0x3c0000))
4072 call_insn
= 0x10680000 | (off
& 0x07ffff);
4077 call_insn
= 0x10800000 | (off
& 0x3fffff);
4079 elfcpp::Swap
<32, true>::writeval(wv
, call_insn
);
4081 // See if we can NOP out the delay slot instruction. We peek
4082 // at the instruction before the call to make sure we're dealing
4083 // with exactly the:
4085 // or %o7, %g0, %ANY_REG
4087 // or %ANY_REG, %g0, %o7
4089 // case. Otherwise this might be a tricky piece of hand written
4090 // assembler calculating %o7 in some non-trivial way, and therefore
4091 // we can't be sure that NOP'ing out the delay slot is safe.
4093 && rela
.get_r_offset() >= 4)
4095 if ((delay_insn
& ~(0x1f << 14)) != 0x9e100000)
4098 set_insn
= elfcpp::Swap
<32, true>::readval(wv
- 1);
4099 if ((set_insn
& ~(0x1f << 25)) != 0x8013c000)
4102 reg
= (set_insn
>> 25) & 0x1f;
4103 if (reg
== 0 || reg
== 15)
4105 if (reg
!= ((delay_insn
>> 14) & 0x1f))
4108 // All tests pass, nop it out.
4109 elfcpp::Swap
<32, true>::writeval(wv
+ 1, sparc_nop
);
4113 // Relocate section data.
4115 template<int size
, bool big_endian
>
4117 Target_sparc
<size
, big_endian
>::relocate_section(
4118 const Relocate_info
<size
, big_endian
>* relinfo
,
4119 unsigned int sh_type
,
4120 const unsigned char* prelocs
,
4122 Output_section
* output_section
,
4123 bool needs_special_offset_handling
,
4124 unsigned char* view
,
4125 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4126 section_size_type view_size
,
4127 const Reloc_symbol_changes
* reloc_symbol_changes
)
4129 typedef Target_sparc
<size
, big_endian
> Sparc
;
4130 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
4132 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4134 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
4141 needs_special_offset_handling
,
4145 reloc_symbol_changes
);
4148 // Return the size of a relocation while scanning during a relocatable
4151 template<int size
, bool big_endian
>
4153 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4157 // We are always SHT_RELA, so we should never get here.
4162 // Scan the relocs during a relocatable link.
4164 template<int size
, bool big_endian
>
4166 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4167 Symbol_table
* symtab
,
4169 Sized_relobj_file
<size
, big_endian
>* object
,
4170 unsigned int data_shndx
,
4171 unsigned int sh_type
,
4172 const unsigned char* prelocs
,
4174 Output_section
* output_section
,
4175 bool needs_special_offset_handling
,
4176 size_t local_symbol_count
,
4177 const unsigned char* plocal_symbols
,
4178 Relocatable_relocs
* rr
)
4180 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4182 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4183 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4185 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4186 Scan_relocatable_relocs
>(
4194 needs_special_offset_handling
,
4200 // Relocate a section during a relocatable link.
4202 template<int size
, bool big_endian
>
4204 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
4205 const Relocate_info
<size
, big_endian
>* relinfo
,
4206 unsigned int sh_type
,
4207 const unsigned char* prelocs
,
4209 Output_section
* output_section
,
4210 off_t offset_in_output_section
,
4211 const Relocatable_relocs
* rr
,
4212 unsigned char* view
,
4213 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4214 section_size_type view_size
,
4215 unsigned char* reloc_view
,
4216 section_size_type reloc_view_size
)
4218 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4220 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
4225 offset_in_output_section
,
4234 // Return the value to use for a dynamic which requires special
4235 // treatment. This is how we support equality comparisons of function
4236 // pointers across shared library boundaries, as described in the
4237 // processor specific ABI supplement.
4239 template<int size
, bool big_endian
>
4241 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4243 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4244 return this->plt_section()->address() + gsym
->plt_offset();
4247 // do_make_elf_object to override the same function in the base class.
4248 // We need to use a target-specific sub-class of
4249 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4250 // of the ELF headers. Hence we need to have our own ELF object creation.
4252 template<int size
, bool big_endian
>
4254 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4255 const std::string
& name
,
4256 Input_file
* input_file
,
4257 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4259 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4260 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4261 elfcpp::Elf_Word omm
, mm
;
4265 case elfcpp::EM_SPARC32PLUS
:
4266 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4269 case elfcpp::EM_SPARC
:
4270 case elfcpp::EM_SPARCV9
:
4277 if (!this->elf_flags_set_
)
4279 this->elf_flags_
= flags
;
4280 this->elf_flags_set_
= true;
4284 // Accumulate cpu feature bits.
4285 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4286 | elfcpp::EF_SPARC_SUN_US1
4287 | elfcpp::EF_SPARC_HAL_R1
4288 | elfcpp::EF_SPARC_SUN_US3
));
4290 // Bump the memory model setting to the most restrictive
4291 // one we encounter.
4292 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4293 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4296 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4298 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4299 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4301 else if (mm
== elfcpp::EF_SPARCV9_PSO
4302 && omm
== elfcpp::EF_SPARCV9_RMO
)
4304 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4305 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4310 // Validate that the little-endian flag matches how we've
4311 // been instantiated.
4312 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4315 gold_error(_("%s: little endian elf flag set on BE object"),
4318 gold_error(_("%s: little endian elf flag clear on LE object"),
4322 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4325 // Adjust ELF file header.
4327 template<int size
, bool big_endian
>
4329 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4330 unsigned char* view
,
4333 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4335 oehdr
.put_e_machine(this->elf_machine_
);
4336 oehdr
.put_e_flags(this->elf_flags_
);
4338 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4341 // The selector for sparc object files.
4343 template<int size
, bool big_endian
>
4344 class Target_selector_sparc
: public Target_selector
4347 Target_selector_sparc()
4348 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4349 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4350 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4354 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4359 if (machine
!= elfcpp::EM_SPARCV9
)
4364 if (machine
!= elfcpp::EM_SPARC
4365 && machine
!= elfcpp::EM_SPARC32PLUS
)
4373 return this->instantiate_target();
4377 do_instantiate_target()
4378 { return new Target_sparc
<size
, big_endian
>(); }
4381 Target_selector_sparc
<32, true> target_selector_sparc32
;
4382 Target_selector_sparc
<64, true> target_selector_sparc64
;
4384 } // End anonymous namespace.