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 elfcpp::SHN_UNDEF
, // small_common_shndx
477 elfcpp::SHN_UNDEF
, // large_common_shndx
478 0, // small_common_section_flags
479 0, // large_common_section_flags
480 NULL
, // attributes_section
481 NULL
// attributes_vendor
485 Target::Target_info Target_sparc
<64, true>::sparc_info
=
488 true, // is_big_endian
489 elfcpp::EM_SPARCV9
, // machine_code
490 false, // has_make_symbol
491 false, // has_resolve
492 false, // has_code_fill
493 true, // is_default_stack_executable
494 false, // can_icf_inline_merge_sections
496 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
497 0x100000, // default_text_segment_address
498 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
499 8 * 1024, // common_pagesize (overridable by -z common-page-size)
500 elfcpp::SHN_UNDEF
, // small_common_shndx
501 elfcpp::SHN_UNDEF
, // large_common_shndx
502 0, // small_common_section_flags
503 0, // large_common_section_flags
504 NULL
, // attributes_section
505 NULL
// attributes_vendor
508 // We have to take care here, even when operating in little-endian
509 // mode, sparc instructions are still big endian.
510 template<int size
, bool big_endian
>
511 class Sparc_relocate_functions
514 // Do a simple relocation with the addend in the relocation.
515 template<int valsize
>
517 rela(unsigned char* view
,
518 unsigned int right_shift
,
519 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
520 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
521 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
523 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
524 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
525 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
526 Valtype reloc
= ((value
+ addend
) >> right_shift
);
531 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
534 // Do a simple relocation using a symbol value with the addend in
536 template<int valsize
>
538 rela(unsigned char* view
,
539 unsigned int right_shift
,
540 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
541 const Sized_relobj_file
<size
, big_endian
>* object
,
542 const Symbol_value
<size
>* psymval
,
543 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
545 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
546 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
547 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
548 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
553 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
556 // Do a simple relocation using a symbol value with the addend in
557 // the relocation, unaligned.
558 template<int valsize
>
560 rela_ua(unsigned char* view
,
561 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
562 const Sized_relobj_file
<size
, big_endian
>* object
,
563 const Symbol_value
<size
>* psymval
,
564 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
566 typedef typename
elfcpp::Swap_unaligned
<valsize
,
567 big_endian
>::Valtype Valtype
;
568 unsigned char* wv
= view
;
569 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
570 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
575 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
578 // Do a simple PC relative relocation with a Symbol_value with the
579 // addend in the relocation.
580 template<int valsize
>
582 pcrela(unsigned char* view
,
583 unsigned int right_shift
,
584 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
585 const Sized_relobj_file
<size
, big_endian
>* object
,
586 const Symbol_value
<size
>* psymval
,
587 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
588 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
590 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
591 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
592 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
593 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
599 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
602 template<int valsize
>
604 pcrela_unaligned(unsigned char* view
,
605 const Sized_relobj_file
<size
, big_endian
>* object
,
606 const Symbol_value
<size
>* psymval
,
607 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
608 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
610 typedef typename
elfcpp::Swap_unaligned
<valsize
,
611 big_endian
>::Valtype Valtype
;
612 unsigned char* wv
= view
;
613 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
615 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
618 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
619 typedef Sparc_relocate_functions
<size
, true> This_insn
;
622 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
624 wdisp30(unsigned char* view
,
625 const Sized_relobj_file
<size
, big_endian
>* object
,
626 const Symbol_value
<size
>* psymval
,
627 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
628 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
630 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
631 psymval
, addend
, address
);
634 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
636 wdisp22(unsigned char* view
,
637 const Sized_relobj_file
<size
, big_endian
>* object
,
638 const Symbol_value
<size
>* psymval
,
639 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
640 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
642 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
643 psymval
, addend
, address
);
646 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
648 wdisp19(unsigned char* view
,
649 const Sized_relobj_file
<size
, big_endian
>* object
,
650 const Symbol_value
<size
>* psymval
,
651 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
652 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
654 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
655 psymval
, addend
, address
);
658 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
660 wdisp16(unsigned char* view
,
661 const Sized_relobj_file
<size
, big_endian
>* object
,
662 const Symbol_value
<size
>* psymval
,
663 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
664 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
666 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
667 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
668 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
669 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
672 // The relocation value is split between the low 14 bits,
674 val
&= ~((0x3 << 20) | 0x3fff);
675 reloc
= (((reloc
& 0xc000) << (20 - 14))
676 | (reloc
& 0x3ffff));
678 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
681 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
683 wdisp10(unsigned char* view
,
684 const Sized_relobj_file
<size
, big_endian
>* object
,
685 const Symbol_value
<size
>* psymval
,
686 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
687 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
689 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
690 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
691 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
692 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
695 // The relocation value is split between the low bits 5-12,
696 // and high bits 19-20.
697 val
&= ~((0x3 << 19) | (0xff << 5));
698 reloc
= (((reloc
& 0x300) << (19 - 8))
699 | ((reloc
& 0xff) << (5 - 0)));
701 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
704 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
706 pc22(unsigned char* view
,
707 const Sized_relobj_file
<size
, big_endian
>* object
,
708 const Symbol_value
<size
>* psymval
,
709 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
710 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
712 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
713 psymval
, addend
, address
);
716 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
718 pc10(unsigned char* view
,
719 const Sized_relobj_file
<size
, big_endian
>* object
,
720 const Symbol_value
<size
>* psymval
,
721 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
722 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
724 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
725 psymval
, addend
, address
);
728 // R_SPARC_HI22: (Symbol + Addend) >> 10
730 hi22(unsigned char* view
,
731 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
732 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
734 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
737 // R_SPARC_HI22: (Symbol + Addend) >> 10
739 hi22(unsigned char* view
,
740 const Sized_relobj_file
<size
, big_endian
>* object
,
741 const Symbol_value
<size
>* psymval
,
742 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
744 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
747 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
749 pcplt22(unsigned char* view
,
750 const Sized_relobj_file
<size
, big_endian
>* object
,
751 const Symbol_value
<size
>* psymval
,
752 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
753 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
755 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
756 psymval
, addend
, address
);
759 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
761 lo10(unsigned char* view
,
762 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
763 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
765 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
768 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
770 lo10(unsigned char* view
,
771 const Sized_relobj_file
<size
, big_endian
>* object
,
772 const Symbol_value
<size
>* psymval
,
773 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
775 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
778 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
780 lo10(unsigned char* view
,
781 const Sized_relobj_file
<size
, big_endian
>* object
,
782 const Symbol_value
<size
>* psymval
,
783 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
784 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
786 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
787 psymval
, addend
, address
);
790 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
792 olo10(unsigned char* view
,
793 const Sized_relobj_file
<size
, big_endian
>* object
,
794 const Symbol_value
<size
>* psymval
,
795 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
796 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
798 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
799 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
800 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
801 Valtype reloc
= psymval
->value(object
, addend
);
808 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
811 // R_SPARC_22: (Symbol + Addend)
813 rela32_22(unsigned char* view
,
814 const Sized_relobj_file
<size
, big_endian
>* object
,
815 const Symbol_value
<size
>* psymval
,
816 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
818 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
821 // R_SPARC_13: (Symbol + Addend)
823 rela32_13(unsigned char* view
,
824 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
825 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
827 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
830 // R_SPARC_13: (Symbol + Addend)
832 rela32_13(unsigned char* view
,
833 const Sized_relobj_file
<size
, big_endian
>* object
,
834 const Symbol_value
<size
>* psymval
,
835 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
837 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
840 // R_SPARC_UA16: (Symbol + Addend)
842 ua16(unsigned char* view
,
843 const Sized_relobj_file
<size
, big_endian
>* object
,
844 const Symbol_value
<size
>* psymval
,
845 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
847 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
850 // R_SPARC_UA32: (Symbol + Addend)
852 ua32(unsigned char* view
,
853 const Sized_relobj_file
<size
, big_endian
>* object
,
854 const Symbol_value
<size
>* psymval
,
855 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
857 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
860 // R_SPARC_UA64: (Symbol + Addend)
862 ua64(unsigned char* view
,
863 const Sized_relobj_file
<size
, big_endian
>* object
,
864 const Symbol_value
<size
>* psymval
,
865 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
867 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
868 object
, psymval
, addend
);
871 // R_SPARC_DISP8: (Symbol + Addend - Address)
873 disp8(unsigned char* view
,
874 const Sized_relobj_file
<size
, big_endian
>* object
,
875 const Symbol_value
<size
>* psymval
,
876 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
877 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
879 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
883 // R_SPARC_DISP16: (Symbol + Addend - Address)
885 disp16(unsigned char* view
,
886 const Sized_relobj_file
<size
, big_endian
>* object
,
887 const Symbol_value
<size
>* psymval
,
888 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
889 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
891 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
895 // R_SPARC_DISP32: (Symbol + Addend - Address)
897 disp32(unsigned char* view
,
898 const Sized_relobj_file
<size
, big_endian
>* object
,
899 const Symbol_value
<size
>* psymval
,
900 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
901 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
903 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
907 // R_SPARC_DISP64: (Symbol + Addend - Address)
909 disp64(unsigned char* view
,
910 const Sized_relobj_file
<size
, big_endian
>* object
,
911 const Symbol_value
<size
>* psymval
,
912 elfcpp::Elf_Xword addend
,
913 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
915 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
919 // R_SPARC_H34: (Symbol + Addend) >> 12
921 h34(unsigned char* view
,
922 const Sized_relobj_file
<size
, big_endian
>* object
,
923 const Symbol_value
<size
>* psymval
,
924 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
926 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
929 // R_SPARC_H44: (Symbol + Addend) >> 22
931 h44(unsigned char* view
,
932 const Sized_relobj_file
<size
, big_endian
>* object
,
933 const Symbol_value
<size
>* psymval
,
934 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
936 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
939 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
941 m44(unsigned char* view
,
942 const Sized_relobj_file
<size
, big_endian
>* object
,
943 const Symbol_value
<size
>* psymval
,
944 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
946 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
949 // R_SPARC_L44: (Symbol + Addend) & 0xfff
951 l44(unsigned char* view
,
952 const Sized_relobj_file
<size
, big_endian
>* object
,
953 const Symbol_value
<size
>* psymval
,
954 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
956 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
959 // R_SPARC_HH22: (Symbol + Addend) >> 42
961 hh22(unsigned char* view
,
962 const Sized_relobj_file
<size
, big_endian
>* object
,
963 const Symbol_value
<size
>* psymval
,
964 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
966 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
969 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
971 pc_hh22(unsigned char* view
,
972 const Sized_relobj_file
<size
, big_endian
>* object
,
973 const Symbol_value
<size
>* psymval
,
974 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
975 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
977 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
978 psymval
, addend
, address
);
981 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
983 hm10(unsigned char* view
,
984 const Sized_relobj_file
<size
, big_endian
>* object
,
985 const Symbol_value
<size
>* psymval
,
986 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
988 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
991 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
993 pc_hm10(unsigned char* view
,
994 const Sized_relobj_file
<size
, big_endian
>* object
,
995 const Symbol_value
<size
>* psymval
,
996 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
997 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
999 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
1000 psymval
, addend
, address
);
1003 // R_SPARC_11: (Symbol + Addend)
1005 rela32_11(unsigned char* view
,
1006 const Sized_relobj_file
<size
, big_endian
>* object
,
1007 const Symbol_value
<size
>* psymval
,
1008 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1010 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1013 // R_SPARC_10: (Symbol + Addend)
1015 rela32_10(unsigned char* view
,
1016 const Sized_relobj_file
<size
, big_endian
>* object
,
1017 const Symbol_value
<size
>* psymval
,
1018 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1020 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
1023 // R_SPARC_7: (Symbol + Addend)
1025 rela32_7(unsigned char* view
,
1026 const Sized_relobj_file
<size
, big_endian
>* object
,
1027 const Symbol_value
<size
>* psymval
,
1028 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1030 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1033 // R_SPARC_6: (Symbol + Addend)
1035 rela32_6(unsigned char* view
,
1036 const Sized_relobj_file
<size
, big_endian
>* object
,
1037 const Symbol_value
<size
>* psymval
,
1038 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1040 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1043 // R_SPARC_5: (Symbol + Addend)
1045 rela32_5(unsigned char* view
,
1046 const Sized_relobj_file
<size
, big_endian
>* object
,
1047 const Symbol_value
<size
>* psymval
,
1048 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1050 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1053 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1055 ldo_hix22(unsigned char* view
,
1056 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1057 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1059 This_insn::hi22(view
, value
, addend
);
1062 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1064 ldo_lox10(unsigned char* view
,
1065 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1066 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1068 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1069 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1070 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1071 Valtype reloc
= (value
+ addend
);
1076 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1079 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1081 hix22(unsigned char* view
,
1082 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1083 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1085 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1086 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1087 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1088 Valtype reloc
= (value
+ addend
);
1092 reloc
^= ~(Valtype
)0;
1097 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1100 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1102 gdop_hix22(unsigned char* view
,
1103 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1104 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1106 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1107 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1108 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1109 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1114 reloc
^= ~static_cast<int32_t>(0);
1119 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1122 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1124 hix22(unsigned char* view
,
1125 const Sized_relobj_file
<size
, big_endian
>* object
,
1126 const Symbol_value
<size
>* psymval
,
1127 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1129 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1130 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1131 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1132 Valtype reloc
= psymval
->value(object
, addend
);
1136 reloc
^= ~(Valtype
)0;
1141 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1145 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1147 lox10(unsigned char* view
,
1148 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1149 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1151 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1152 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1153 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1154 Valtype reloc
= (value
+ addend
);
1160 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1163 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1165 gdop_lox10(unsigned char* view
,
1166 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1167 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1169 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1170 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1171 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1172 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1175 reloc
= (reloc
& 0x3ff) | 0x1c00;
1177 reloc
= (reloc
& 0x3ff);
1180 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1183 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1185 lox10(unsigned char* view
,
1186 const Sized_relobj_file
<size
, big_endian
>* object
,
1187 const Symbol_value
<size
>* psymval
,
1188 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1190 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1191 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1192 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1193 Valtype reloc
= psymval
->value(object
, addend
);
1199 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1203 // Get the GOT section, creating it if necessary.
1205 template<int size
, bool big_endian
>
1206 Output_data_got
<size
, big_endian
>*
1207 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1210 if (this->got_
== NULL
)
1212 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1214 this->got_
= new Output_data_got
<size
, big_endian
>();
1216 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1218 | elfcpp::SHF_WRITE
),
1219 this->got_
, ORDER_RELRO
, true);
1221 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1222 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1223 Symbol_table::PREDEFINED
,
1225 0, 0, elfcpp::STT_OBJECT
,
1227 elfcpp::STV_HIDDEN
, 0,
1234 // Get the dynamic reloc section, creating it if necessary.
1236 template<int size
, bool big_endian
>
1237 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1238 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1240 if (this->rela_dyn_
== NULL
)
1242 gold_assert(layout
!= NULL
);
1243 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1244 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1245 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1246 ORDER_DYNAMIC_RELOCS
, false);
1248 return this->rela_dyn_
;
1251 // Get the section to use for IFUNC relocs, creating it if
1252 // necessary. These go in .rela.dyn, but only after all other dynamic
1253 // relocations. They need to follow the other dynamic relocations so
1254 // that they can refer to global variables initialized by those
1257 template<int size
, bool big_endian
>
1258 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1259 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1261 if (this->rela_ifunc_
== NULL
)
1263 // Make sure we have already created the dynamic reloc section.
1264 this->rela_dyn_section(layout
);
1265 this->rela_ifunc_
= new Reloc_section(false);
1266 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1267 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1268 ORDER_DYNAMIC_RELOCS
, false);
1269 gold_assert(this->rela_dyn_
->output_section()
1270 == this->rela_ifunc_
->output_section());
1272 return this->rela_ifunc_
;
1275 // A class to handle the PLT data.
1277 template<int size
, bool big_endian
>
1278 class Output_data_plt_sparc
: public Output_section_data
1281 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1282 size
, big_endian
> Reloc_section
;
1284 Output_data_plt_sparc(Layout
*);
1286 // Add an entry to the PLT.
1287 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1289 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1291 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1292 Sized_relobj_file
<size
, big_endian
>* relobj
,
1293 unsigned int local_sym_index
);
1295 // Return the .rela.plt section data.
1296 const Reloc_section
* rel_plt() const
1301 // Return where the IFUNC relocations should go.
1303 rela_ifunc(Symbol_table
*, Layout
*);
1306 emit_pending_ifunc_relocs();
1308 // Return whether we created a section for IFUNC relocations.
1310 has_ifunc_section() const
1311 { return this->ifunc_rel_
!= NULL
; }
1313 // Return the number of PLT entries.
1316 { return this->count_
+ this->ifunc_count_
; }
1318 // Return the offset of the first non-reserved PLT entry.
1320 first_plt_entry_offset()
1321 { return 4 * base_plt_entry_size
; }
1323 // Return the size of a PLT entry.
1325 get_plt_entry_size()
1326 { return base_plt_entry_size
; }
1328 // Return the PLT address to use for a global symbol.
1330 address_for_global(const Symbol
*);
1332 // Return the PLT address to use for a local symbol.
1334 address_for_local(const Relobj
*, unsigned int symndx
);
1337 void do_adjust_output_section(Output_section
* os
);
1339 // Write to a map file.
1341 do_print_to_mapfile(Mapfile
* mapfile
) const
1342 { mapfile
->print_output_data(this, _("** PLT")); }
1345 // The size of an entry in the PLT.
1346 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1348 static const unsigned int plt_entries_per_block
= 160;
1349 static const unsigned int plt_insn_chunk_size
= 24;
1350 static const unsigned int plt_pointer_chunk_size
= 8;
1351 static const unsigned int plt_block_size
=
1352 (plt_entries_per_block
1353 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1356 plt_index_to_offset(unsigned int index
)
1358 section_offset_type offset
;
1360 if (size
== 32 || index
< 32768)
1361 offset
= index
* base_plt_entry_size
;
1364 unsigned int ext_index
= index
- 32768;
1366 offset
= (32768 * base_plt_entry_size
)
1367 + ((ext_index
/ plt_entries_per_block
)
1369 + ((ext_index
% plt_entries_per_block
)
1370 * plt_insn_chunk_size
);
1375 // Set the final size.
1377 set_final_data_size()
1379 unsigned int full_count
= this->entry_count() + 4;
1380 unsigned int extra
= (size
== 32 ? 4 : 0);
1381 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1383 return this->set_data_size(sz
);
1386 // Write out the PLT data.
1388 do_write(Output_file
*);
1394 unsigned int plt_index
;
1400 Sized_relobj_file
<size
, big_endian
>* object
;
1401 unsigned int local_sym_index
;
1402 unsigned int plt_index
;
1405 // The reloc section.
1406 Reloc_section
* rel_
;
1407 // The IFUNC relocations, if necessary. These must follow the
1408 // regular relocations.
1409 Reloc_section
* ifunc_rel_
;
1410 // The number of PLT entries.
1411 unsigned int count_
;
1412 // The number of PLT entries for IFUNC symbols.
1413 unsigned int ifunc_count_
;
1414 // Global STT_GNU_IFUNC symbols.
1415 std::vector
<Global_ifunc
> global_ifuncs_
;
1416 // Local STT_GNU_IFUNC symbols.
1417 std::vector
<Local_ifunc
> local_ifuncs_
;
1420 // Define the constants as required by C++ standard.
1422 template<int size
, bool big_endian
>
1423 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1425 template<int size
, bool big_endian
>
1427 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1429 template<int size
, bool big_endian
>
1430 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1432 template<int size
, bool big_endian
>
1434 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1436 template<int size
, bool big_endian
>
1437 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1439 // Create the PLT section. The ordinary .got section is an argument,
1440 // since we need to refer to the start.
1442 template<int size
, bool big_endian
>
1443 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1444 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1445 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1447 this->rel_
= new Reloc_section(false);
1448 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1449 elfcpp::SHF_ALLOC
, this->rel_
,
1450 ORDER_DYNAMIC_PLT_RELOCS
, false);
1453 template<int size
, bool big_endian
>
1455 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1460 // Add an entry to the PLT.
1462 template<int size
, bool big_endian
>
1464 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1468 gold_assert(!gsym
->has_plt_offset());
1470 section_offset_type plt_offset
;
1473 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1474 && gsym
->can_use_relative_reloc(false))
1476 index
= this->ifunc_count_
;
1477 plt_offset
= plt_index_to_offset(index
);
1478 gsym
->set_plt_offset(plt_offset
);
1479 ++this->ifunc_count_
;
1480 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1482 struct Global_ifunc gi
;
1485 gi
.plt_index
= index
;
1486 this->global_ifuncs_
.push_back(gi
);
1490 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1491 gsym
->set_plt_offset(plt_offset
);
1493 gsym
->set_needs_dynsym_entry();
1494 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1498 // Note that we don't need to save the symbol. The contents of the
1499 // PLT are independent of which symbols are used. The symbols only
1500 // appear in the relocations.
1503 template<int size
, bool big_endian
>
1505 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1506 Symbol_table
* symtab
,
1508 Sized_relobj_file
<size
, big_endian
>* relobj
,
1509 unsigned int local_sym_index
)
1511 unsigned int index
= this->ifunc_count_
;
1512 section_offset_type plt_offset
;
1514 plt_offset
= plt_index_to_offset(index
);
1515 ++this->ifunc_count_
;
1517 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1519 struct Local_ifunc li
;
1522 li
.local_sym_index
= local_sym_index
;
1523 li
.plt_index
= index
;
1524 this->local_ifuncs_
.push_back(li
);
1529 // Emit any pending IFUNC plt relocations.
1531 template<int size
, bool big_endian
>
1533 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1535 // Emit any pending IFUNC relocs.
1536 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1537 this->global_ifuncs_
.begin();
1538 p
!= this->global_ifuncs_
.end();
1541 section_offset_type plt_offset
;
1544 index
= this->count_
+ p
->plt_index
+ 4;
1545 plt_offset
= this->plt_index_to_offset(index
);
1546 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1547 this, plt_offset
, 0);
1550 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1551 this->local_ifuncs_
.begin();
1552 p
!= this->local_ifuncs_
.end();
1555 section_offset_type plt_offset
;
1558 index
= this->count_
+ p
->plt_index
+ 4;
1559 plt_offset
= this->plt_index_to_offset(index
);
1560 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1561 elfcpp::R_SPARC_JMP_IREL
,
1562 this, plt_offset
, 0);
1566 // Return where the IFUNC relocations should go in the PLT. These
1567 // follow the non-IFUNC relocations.
1569 template<int size
, bool big_endian
>
1570 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1571 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1572 Symbol_table
* symtab
,
1575 if (this->ifunc_rel_
== NULL
)
1577 this->ifunc_rel_
= new Reloc_section(false);
1578 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1579 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1580 ORDER_DYNAMIC_PLT_RELOCS
, false);
1581 gold_assert(this->ifunc_rel_
->output_section()
1582 == this->rel_
->output_section());
1584 if (parameters
->doing_static_link())
1586 // A statically linked executable will only have a .rel.plt
1587 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1588 // relocs for STT_GNU_IFUNC symbols. The library will use
1589 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1590 // at program startup time.
1591 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1592 Symbol_table::PREDEFINED
,
1593 this->ifunc_rel_
, 0, 0,
1594 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1595 elfcpp::STV_HIDDEN
, 0, false, true);
1596 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1597 Symbol_table::PREDEFINED
,
1598 this->ifunc_rel_
, 0, 0,
1599 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1600 elfcpp::STV_HIDDEN
, 0, true, true);
1603 return this->ifunc_rel_
;
1606 // Return the PLT address to use for a global symbol.
1608 template<int size
, bool big_endian
>
1610 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1612 uint64_t offset
= 0;
1613 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1614 && gsym
->can_use_relative_reloc(false))
1615 offset
= plt_index_to_offset(this->count_
+ 4);
1616 return this->address() + offset
;
1619 // Return the PLT address to use for a local symbol. These are always
1620 // IRELATIVE relocs.
1622 template<int size
, bool big_endian
>
1624 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1628 return this->address() + plt_index_to_offset(this->count_
+ 4);
1631 static const unsigned int sparc_nop
= 0x01000000;
1632 static const unsigned int sparc_sethi_g1
= 0x03000000;
1633 static const unsigned int sparc_branch_always
= 0x30800000;
1634 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1635 static const unsigned int sparc_mov
= 0x80100000;
1636 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1637 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1638 static const unsigned int sparc_call_plus_8
= 0x40000002;
1639 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1640 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1641 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1643 // Write out the PLT.
1645 template<int size
, bool big_endian
>
1647 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1649 const off_t offset
= this->offset();
1650 const section_size_type oview_size
=
1651 convert_to_section_size_type(this->data_size());
1652 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1653 unsigned char* pov
= oview
;
1655 memset(pov
, 0, base_plt_entry_size
* 4);
1656 pov
+= this->first_plt_entry_offset();
1658 unsigned int plt_offset
= base_plt_entry_size
* 4;
1659 const unsigned int count
= this->entry_count();
1665 limit
= (count
> 32768 ? 32768 : count
);
1667 for (unsigned int i
= 0; i
< limit
; ++i
)
1669 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1670 sparc_sethi_g1
+ plt_offset
);
1671 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1672 sparc_branch_always_pt
+
1673 (((base_plt_entry_size
-
1674 (plt_offset
+ 4)) >> 2) &
1676 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1677 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1678 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1679 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1680 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1681 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1683 pov
+= base_plt_entry_size
;
1684 plt_offset
+= base_plt_entry_size
;
1689 unsigned int ext_cnt
= count
- 32768;
1690 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1692 for (unsigned int i
= 0; i
< blks
; ++i
)
1694 unsigned int data_off
= (plt_entries_per_block
1695 * plt_insn_chunk_size
) - 4;
1697 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1699 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1701 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1703 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1705 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1706 sparc_ldx_o7_imm_g1
+
1707 (data_off
& 0x1fff));
1708 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1709 sparc_jmpl_o7_g1_g1
);
1710 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1713 elfcpp::Swap
<64, big_endian
>::writeval(
1714 pov
+ 0x4 + data_off
,
1715 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1717 pov
+= plt_insn_chunk_size
;
1722 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1723 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1725 unsigned int data_off
= (sub_blk_cnt
1726 * plt_insn_chunk_size
) - 4;
1728 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1730 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1732 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1734 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1736 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1737 sparc_ldx_o7_imm_g1
+
1738 (data_off
& 0x1fff));
1739 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1740 sparc_jmpl_o7_g1_g1
);
1741 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1744 elfcpp::Swap
<64, big_endian
>::writeval(
1745 pov
+ 0x4 + data_off
,
1746 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1748 pov
+= plt_insn_chunk_size
;
1756 for (unsigned int i
= 0; i
< count
; ++i
)
1758 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1759 sparc_sethi_g1
+ plt_offset
);
1760 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1761 sparc_branch_always
+
1762 (((- (plt_offset
+ 4)) >> 2) &
1764 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1766 pov
+= base_plt_entry_size
;
1767 plt_offset
+= base_plt_entry_size
;
1770 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1774 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1776 of
->write_output_view(offset
, oview_size
, oview
);
1779 // Create the PLT section.
1781 template<int size
, bool big_endian
>
1783 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1786 // Create the GOT sections first.
1787 this->got_section(symtab
, layout
);
1789 // Ensure that .rela.dyn always appears before .rela.plt This is
1790 // necessary due to how, on Sparc and some other targets, .rela.dyn
1791 // needs to include .rela.plt in it's range.
1792 this->rela_dyn_section(layout
);
1794 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1795 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1797 | elfcpp::SHF_EXECINSTR
1798 | elfcpp::SHF_WRITE
),
1799 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1801 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1802 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1803 Symbol_table::PREDEFINED
,
1805 0, 0, elfcpp::STT_OBJECT
,
1807 elfcpp::STV_HIDDEN
, 0,
1811 // Create a PLT entry for a global symbol.
1813 template<int size
, bool big_endian
>
1815 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1819 if (gsym
->has_plt_offset())
1822 if (this->plt_
== NULL
)
1823 this->make_plt_section(symtab
, layout
);
1825 this->plt_
->add_entry(symtab
, layout
, gsym
);
1828 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1830 template<int size
, bool big_endian
>
1832 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1833 Symbol_table
* symtab
,
1835 Sized_relobj_file
<size
, big_endian
>* relobj
,
1836 unsigned int local_sym_index
)
1838 if (relobj
->local_has_plt_offset(local_sym_index
))
1840 if (this->plt_
== NULL
)
1841 this->make_plt_section(symtab
, layout
);
1842 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1845 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1848 // Return the number of entries in the PLT.
1850 template<int size
, bool big_endian
>
1852 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1854 if (this->plt_
== NULL
)
1856 return this->plt_
->entry_count();
1859 // Return the offset of the first non-reserved PLT entry.
1861 template<int size
, bool big_endian
>
1863 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1865 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1868 // Return the size of each PLT entry.
1870 template<int size
, bool big_endian
>
1872 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1874 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1877 // Create a GOT entry for the TLS module index.
1879 template<int size
, bool big_endian
>
1881 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1882 Symbol_table
* symtab
,
1884 Sized_relobj_file
<size
, big_endian
>* object
)
1886 if (this->got_mod_index_offset_
== -1U)
1888 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1889 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1890 Output_data_got
<size
, big_endian
>* got
;
1891 unsigned int got_offset
;
1893 got
= this->got_section(symtab
, layout
);
1894 got_offset
= got
->add_constant(0);
1895 rela_dyn
->add_local(object
, 0,
1897 elfcpp::R_SPARC_TLS_DTPMOD64
:
1898 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1900 got
->add_constant(0);
1901 this->got_mod_index_offset_
= got_offset
;
1903 return this->got_mod_index_offset_
;
1906 // Optimize the TLS relocation type based on what we know about the
1907 // symbol. IS_FINAL is true if the final address of this symbol is
1908 // known at link time.
1910 static tls::Tls_optimization
1911 optimize_tls_reloc(bool is_final
, int r_type
)
1913 // If we are generating a shared library, then we can't do anything
1915 if (parameters
->options().shared())
1916 return tls::TLSOPT_NONE
;
1920 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1921 case elfcpp::R_SPARC_TLS_GD_LO10
:
1922 case elfcpp::R_SPARC_TLS_GD_ADD
:
1923 case elfcpp::R_SPARC_TLS_GD_CALL
:
1924 // These are General-Dynamic which permits fully general TLS
1925 // access. Since we know that we are generating an executable,
1926 // we can convert this to Initial-Exec. If we also know that
1927 // this is a local symbol, we can further switch to Local-Exec.
1929 return tls::TLSOPT_TO_LE
;
1930 return tls::TLSOPT_TO_IE
;
1932 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1933 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1934 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1935 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1936 // This is Local-Dynamic, which refers to a local symbol in the
1937 // dynamic TLS block. Since we know that we generating an
1938 // executable, we can switch to Local-Exec.
1939 return tls::TLSOPT_TO_LE
;
1941 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1942 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1943 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1944 // Another type of Local-Dynamic relocation.
1945 return tls::TLSOPT_TO_LE
;
1947 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1948 case elfcpp::R_SPARC_TLS_IE_LO10
:
1949 case elfcpp::R_SPARC_TLS_IE_LD
:
1950 case elfcpp::R_SPARC_TLS_IE_LDX
:
1951 case elfcpp::R_SPARC_TLS_IE_ADD
:
1952 // These are Initial-Exec relocs which get the thread offset
1953 // from the GOT. If we know that we are linking against the
1954 // local symbol, we can switch to Local-Exec, which links the
1955 // thread offset into the instruction.
1957 return tls::TLSOPT_TO_LE
;
1958 return tls::TLSOPT_NONE
;
1960 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1961 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1962 // When we already have Local-Exec, there is nothing further we
1964 return tls::TLSOPT_NONE
;
1971 // Get the Reference_flags for a particular relocation.
1973 template<int size
, bool big_endian
>
1975 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1980 case elfcpp::R_SPARC_NONE
:
1981 case elfcpp::R_SPARC_REGISTER
:
1982 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1983 case elfcpp::R_SPARC_GNU_VTENTRY
:
1984 // No symbol reference.
1987 case elfcpp::R_SPARC_UA64
:
1988 case elfcpp::R_SPARC_64
:
1989 case elfcpp::R_SPARC_HIX22
:
1990 case elfcpp::R_SPARC_LOX10
:
1991 case elfcpp::R_SPARC_H34
:
1992 case elfcpp::R_SPARC_H44
:
1993 case elfcpp::R_SPARC_M44
:
1994 case elfcpp::R_SPARC_L44
:
1995 case elfcpp::R_SPARC_HH22
:
1996 case elfcpp::R_SPARC_HM10
:
1997 case elfcpp::R_SPARC_LM22
:
1998 case elfcpp::R_SPARC_HI22
:
1999 case elfcpp::R_SPARC_LO10
:
2000 case elfcpp::R_SPARC_OLO10
:
2001 case elfcpp::R_SPARC_UA32
:
2002 case elfcpp::R_SPARC_32
:
2003 case elfcpp::R_SPARC_UA16
:
2004 case elfcpp::R_SPARC_16
:
2005 case elfcpp::R_SPARC_11
:
2006 case elfcpp::R_SPARC_10
:
2007 case elfcpp::R_SPARC_8
:
2008 case elfcpp::R_SPARC_7
:
2009 case elfcpp::R_SPARC_6
:
2010 case elfcpp::R_SPARC_5
:
2011 return Symbol::ABSOLUTE_REF
;
2013 case elfcpp::R_SPARC_DISP8
:
2014 case elfcpp::R_SPARC_DISP16
:
2015 case elfcpp::R_SPARC_DISP32
:
2016 case elfcpp::R_SPARC_DISP64
:
2017 case elfcpp::R_SPARC_PC_HH22
:
2018 case elfcpp::R_SPARC_PC_HM10
:
2019 case elfcpp::R_SPARC_PC_LM22
:
2020 case elfcpp::R_SPARC_PC10
:
2021 case elfcpp::R_SPARC_PC22
:
2022 case elfcpp::R_SPARC_WDISP30
:
2023 case elfcpp::R_SPARC_WDISP22
:
2024 case elfcpp::R_SPARC_WDISP19
:
2025 case elfcpp::R_SPARC_WDISP16
:
2026 case elfcpp::R_SPARC_WDISP10
:
2027 return Symbol::RELATIVE_REF
;
2029 case elfcpp::R_SPARC_PLT64
:
2030 case elfcpp::R_SPARC_PLT32
:
2031 case elfcpp::R_SPARC_HIPLT22
:
2032 case elfcpp::R_SPARC_LOPLT10
:
2033 case elfcpp::R_SPARC_PCPLT10
:
2034 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2036 case elfcpp::R_SPARC_PCPLT32
:
2037 case elfcpp::R_SPARC_PCPLT22
:
2038 case elfcpp::R_SPARC_WPLT30
:
2039 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2041 case elfcpp::R_SPARC_GOTDATA_OP
:
2042 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2043 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2044 case elfcpp::R_SPARC_GOT10
:
2045 case elfcpp::R_SPARC_GOT13
:
2046 case elfcpp::R_SPARC_GOT22
:
2048 return Symbol::ABSOLUTE_REF
;
2050 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2051 case elfcpp::R_SPARC_TLS_GD_LO10
:
2052 case elfcpp::R_SPARC_TLS_GD_ADD
:
2053 case elfcpp::R_SPARC_TLS_GD_CALL
:
2054 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2055 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2056 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2057 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2058 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2059 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2060 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2061 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2062 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2063 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2064 case elfcpp::R_SPARC_TLS_IE_LO10
:
2065 case elfcpp::R_SPARC_TLS_IE_LD
:
2066 case elfcpp::R_SPARC_TLS_IE_LDX
:
2067 case elfcpp::R_SPARC_TLS_IE_ADD
:
2068 return Symbol::TLS_REF
;
2070 case elfcpp::R_SPARC_COPY
:
2071 case elfcpp::R_SPARC_GLOB_DAT
:
2072 case elfcpp::R_SPARC_JMP_SLOT
:
2073 case elfcpp::R_SPARC_JMP_IREL
:
2074 case elfcpp::R_SPARC_RELATIVE
:
2075 case elfcpp::R_SPARC_IRELATIVE
:
2076 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2077 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2078 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2079 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2080 case elfcpp::R_SPARC_TLS_TPOFF64
:
2081 case elfcpp::R_SPARC_TLS_TPOFF32
:
2083 // Not expected. We will give an error later.
2088 // Generate a PLT entry slot for a call to __tls_get_addr
2089 template<int size
, bool big_endian
>
2091 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2093 Target_sparc
<size
, big_endian
>* target
)
2095 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2097 target
->make_plt_entry(symtab
, layout
, gsym
);
2100 // Report an unsupported relocation against a local symbol.
2102 template<int size
, bool big_endian
>
2104 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2105 Sized_relobj_file
<size
, big_endian
>* object
,
2106 unsigned int r_type
)
2108 gold_error(_("%s: unsupported reloc %u against local symbol"),
2109 object
->name().c_str(), r_type
);
2112 // We are about to emit a dynamic relocation of type R_TYPE. If the
2113 // dynamic linker does not support it, issue an error.
2115 template<int size
, bool big_endian
>
2117 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2119 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2125 // These are the relocation types supported by glibc for sparc 64-bit.
2126 case elfcpp::R_SPARC_RELATIVE
:
2127 case elfcpp::R_SPARC_IRELATIVE
:
2128 case elfcpp::R_SPARC_COPY
:
2129 case elfcpp::R_SPARC_64
:
2130 case elfcpp::R_SPARC_GLOB_DAT
:
2131 case elfcpp::R_SPARC_JMP_SLOT
:
2132 case elfcpp::R_SPARC_JMP_IREL
:
2133 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2134 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2135 case elfcpp::R_SPARC_TLS_TPOFF64
:
2136 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2137 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2138 case elfcpp::R_SPARC_8
:
2139 case elfcpp::R_SPARC_16
:
2140 case elfcpp::R_SPARC_DISP8
:
2141 case elfcpp::R_SPARC_DISP16
:
2142 case elfcpp::R_SPARC_DISP32
:
2143 case elfcpp::R_SPARC_WDISP30
:
2144 case elfcpp::R_SPARC_LO10
:
2145 case elfcpp::R_SPARC_HI22
:
2146 case elfcpp::R_SPARC_OLO10
:
2147 case elfcpp::R_SPARC_H34
:
2148 case elfcpp::R_SPARC_H44
:
2149 case elfcpp::R_SPARC_M44
:
2150 case elfcpp::R_SPARC_L44
:
2151 case elfcpp::R_SPARC_HH22
:
2152 case elfcpp::R_SPARC_HM10
:
2153 case elfcpp::R_SPARC_LM22
:
2154 case elfcpp::R_SPARC_UA16
:
2155 case elfcpp::R_SPARC_UA32
:
2156 case elfcpp::R_SPARC_UA64
:
2167 // These are the relocation types supported by glibc for sparc 32-bit.
2168 case elfcpp::R_SPARC_RELATIVE
:
2169 case elfcpp::R_SPARC_IRELATIVE
:
2170 case elfcpp::R_SPARC_COPY
:
2171 case elfcpp::R_SPARC_GLOB_DAT
:
2172 case elfcpp::R_SPARC_32
:
2173 case elfcpp::R_SPARC_JMP_SLOT
:
2174 case elfcpp::R_SPARC_JMP_IREL
:
2175 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2176 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2177 case elfcpp::R_SPARC_TLS_TPOFF32
:
2178 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2179 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2180 case elfcpp::R_SPARC_8
:
2181 case elfcpp::R_SPARC_16
:
2182 case elfcpp::R_SPARC_DISP8
:
2183 case elfcpp::R_SPARC_DISP16
:
2184 case elfcpp::R_SPARC_DISP32
:
2185 case elfcpp::R_SPARC_LO10
:
2186 case elfcpp::R_SPARC_WDISP30
:
2187 case elfcpp::R_SPARC_HI22
:
2188 case elfcpp::R_SPARC_UA16
:
2189 case elfcpp::R_SPARC_UA32
:
2197 // This prevents us from issuing more than one error per reloc
2198 // section. But we can still wind up issuing more than one
2199 // error per object file.
2200 if (this->issued_non_pic_error_
)
2202 gold_assert(parameters
->options().output_is_position_independent());
2203 object
->error(_("requires unsupported dynamic reloc; "
2204 "recompile with -fPIC"));
2205 this->issued_non_pic_error_
= true;
2209 // Return whether we need to make a PLT entry for a relocation of the
2210 // given type against a STT_GNU_IFUNC symbol.
2212 template<int size
, bool big_endian
>
2214 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2215 Sized_relobj_file
<size
, big_endian
>* object
,
2216 unsigned int r_type
)
2218 int flags
= Scan::get_reference_flags(r_type
);
2219 if (flags
& Symbol::TLS_REF
)
2220 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2221 object
->name().c_str(), r_type
);
2225 // Scan a relocation for a local symbol.
2227 template<int size
, bool big_endian
>
2229 Target_sparc
<size
, big_endian
>::Scan::local(
2230 Symbol_table
* symtab
,
2232 Target_sparc
<size
, big_endian
>* target
,
2233 Sized_relobj_file
<size
, big_endian
>* object
,
2234 unsigned int data_shndx
,
2235 Output_section
* output_section
,
2236 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2237 unsigned int r_type
,
2238 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2240 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2241 unsigned int orig_r_type
= r_type
;
2245 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2247 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2248 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2253 case elfcpp::R_SPARC_NONE
:
2254 case elfcpp::R_SPARC_REGISTER
:
2255 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2256 case elfcpp::R_SPARC_GNU_VTENTRY
:
2259 case elfcpp::R_SPARC_64
:
2260 case elfcpp::R_SPARC_32
:
2261 // If building a shared library (or a position-independent
2262 // executable), we need to create a dynamic relocation for
2263 // this location. The relocation applied at link time will
2264 // apply the link-time value, so we flag the location with
2265 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2266 // relocate it easily.
2267 if (parameters
->options().output_is_position_independent())
2269 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2270 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2271 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2272 output_section
, data_shndx
,
2273 reloc
.get_r_offset(),
2274 reloc
.get_r_addend(), is_ifunc
);
2278 case elfcpp::R_SPARC_HIX22
:
2279 case elfcpp::R_SPARC_LOX10
:
2280 case elfcpp::R_SPARC_H34
:
2281 case elfcpp::R_SPARC_H44
:
2282 case elfcpp::R_SPARC_M44
:
2283 case elfcpp::R_SPARC_L44
:
2284 case elfcpp::R_SPARC_HH22
:
2285 case elfcpp::R_SPARC_HM10
:
2286 case elfcpp::R_SPARC_LM22
:
2287 case elfcpp::R_SPARC_UA64
:
2288 case elfcpp::R_SPARC_UA32
:
2289 case elfcpp::R_SPARC_UA16
:
2290 case elfcpp::R_SPARC_HI22
:
2291 case elfcpp::R_SPARC_LO10
:
2292 case elfcpp::R_SPARC_OLO10
:
2293 case elfcpp::R_SPARC_16
:
2294 case elfcpp::R_SPARC_11
:
2295 case elfcpp::R_SPARC_10
:
2296 case elfcpp::R_SPARC_8
:
2297 case elfcpp::R_SPARC_7
:
2298 case elfcpp::R_SPARC_6
:
2299 case elfcpp::R_SPARC_5
:
2300 // If building a shared library (or a position-independent
2301 // executable), we need to create a dynamic relocation for
2303 if (parameters
->options().output_is_position_independent())
2305 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2306 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2308 check_non_pic(object
, r_type
);
2309 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2311 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2312 data_shndx
, reloc
.get_r_offset(),
2313 reloc
.get_r_addend());
2317 gold_assert(lsym
.get_st_value() == 0);
2318 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2319 output_section
, data_shndx
,
2320 reloc
.get_r_offset(),
2321 reloc
.get_r_addend());
2326 case elfcpp::R_SPARC_WDISP30
:
2327 case elfcpp::R_SPARC_WPLT30
:
2328 case elfcpp::R_SPARC_WDISP22
:
2329 case elfcpp::R_SPARC_WDISP19
:
2330 case elfcpp::R_SPARC_WDISP16
:
2331 case elfcpp::R_SPARC_WDISP10
:
2332 case elfcpp::R_SPARC_DISP8
:
2333 case elfcpp::R_SPARC_DISP16
:
2334 case elfcpp::R_SPARC_DISP32
:
2335 case elfcpp::R_SPARC_DISP64
:
2336 case elfcpp::R_SPARC_PC10
:
2337 case elfcpp::R_SPARC_PC22
:
2340 case elfcpp::R_SPARC_GOTDATA_OP
:
2341 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2342 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2343 // We will optimize this into a GOT relative relocation
2344 // and code transform the GOT load into an addition.
2347 case elfcpp::R_SPARC_GOT10
:
2348 case elfcpp::R_SPARC_GOT13
:
2349 case elfcpp::R_SPARC_GOT22
:
2351 // The symbol requires a GOT entry.
2352 Output_data_got
<size
, big_endian
>* got
;
2355 got
= target
->got_section(symtab
, layout
);
2356 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2358 // If we are generating a shared object, we need to add a
2359 // dynamic relocation for this symbol's GOT entry.
2360 if (parameters
->options().output_is_position_independent())
2362 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2364 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2365 unsigned int off
= got
->add_constant(0);
2366 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2367 rela_dyn
->add_local_relative(object
, r_sym
,
2368 elfcpp::R_SPARC_RELATIVE
,
2369 got
, off
, 0, is_ifunc
);
2373 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2377 // These are initial TLS relocs, which are expected when
2379 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2380 case elfcpp::R_SPARC_TLS_GD_LO10
:
2381 case elfcpp::R_SPARC_TLS_GD_ADD
:
2382 case elfcpp::R_SPARC_TLS_GD_CALL
:
2383 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2384 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2385 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2386 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2387 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2388 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2389 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2390 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2391 case elfcpp::R_SPARC_TLS_IE_LO10
:
2392 case elfcpp::R_SPARC_TLS_IE_LD
:
2393 case elfcpp::R_SPARC_TLS_IE_LDX
:
2394 case elfcpp::R_SPARC_TLS_IE_ADD
:
2395 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2396 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2398 bool output_is_shared
= parameters
->options().shared();
2399 const tls::Tls_optimization optimized_type
2400 = optimize_tls_reloc(!output_is_shared
, r_type
);
2403 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2404 case elfcpp::R_SPARC_TLS_GD_LO10
:
2405 case elfcpp::R_SPARC_TLS_GD_ADD
:
2406 case elfcpp::R_SPARC_TLS_GD_CALL
:
2407 if (optimized_type
== tls::TLSOPT_NONE
)
2409 // Create a pair of GOT entries for the module index and
2410 // dtv-relative offset.
2411 Output_data_got
<size
, big_endian
>* got
2412 = target
->got_section(symtab
, layout
);
2413 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2414 unsigned int shndx
= lsym
.get_st_shndx();
2416 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2418 object
->error(_("local symbol %u has bad shndx %u"),
2421 got
->add_local_pair_with_rel(object
, r_sym
,
2422 lsym
.get_st_shndx(),
2424 target
->rela_dyn_section(layout
),
2426 ? elfcpp::R_SPARC_TLS_DTPMOD64
2427 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2429 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2430 generate_tls_call(symtab
, layout
, target
);
2432 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2433 unsupported_reloc_local(object
, r_type
);
2436 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2437 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2438 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2439 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2440 if (optimized_type
== tls::TLSOPT_NONE
)
2442 // Create a GOT entry for the module index.
2443 target
->got_mod_index_entry(symtab
, layout
, object
);
2445 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2446 generate_tls_call(symtab
, layout
, target
);
2448 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2449 unsupported_reloc_local(object
, r_type
);
2452 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2453 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2454 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2457 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2458 case elfcpp::R_SPARC_TLS_IE_LO10
:
2459 case elfcpp::R_SPARC_TLS_IE_LD
:
2460 case elfcpp::R_SPARC_TLS_IE_LDX
:
2461 case elfcpp::R_SPARC_TLS_IE_ADD
:
2462 layout
->set_has_static_tls();
2463 if (optimized_type
== tls::TLSOPT_NONE
)
2465 // Create a GOT entry for the tp-relative offset.
2466 Output_data_got
<size
, big_endian
>* got
2467 = target
->got_section(symtab
, layout
);
2468 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2470 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2472 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2473 unsigned int off
= got
->add_constant(0);
2475 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2477 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2479 elfcpp::R_SPARC_TLS_TPOFF64
:
2480 elfcpp::R_SPARC_TLS_TPOFF32
),
2484 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2485 unsupported_reloc_local(object
, r_type
);
2488 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2489 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2490 layout
->set_has_static_tls();
2491 if (output_is_shared
)
2493 // We need to create a dynamic relocation.
2494 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2495 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2496 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2497 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2498 output_section
, data_shndx
,
2499 reloc
.get_r_offset(), 0);
2506 // These are relocations which should only be seen by the
2507 // dynamic linker, and should never be seen here.
2508 case elfcpp::R_SPARC_COPY
:
2509 case elfcpp::R_SPARC_GLOB_DAT
:
2510 case elfcpp::R_SPARC_JMP_SLOT
:
2511 case elfcpp::R_SPARC_JMP_IREL
:
2512 case elfcpp::R_SPARC_RELATIVE
:
2513 case elfcpp::R_SPARC_IRELATIVE
:
2514 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2515 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2516 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2517 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2518 case elfcpp::R_SPARC_TLS_TPOFF64
:
2519 case elfcpp::R_SPARC_TLS_TPOFF32
:
2520 gold_error(_("%s: unexpected reloc %u in object file"),
2521 object
->name().c_str(), r_type
);
2525 unsupported_reloc_local(object
, r_type
);
2530 // Report an unsupported relocation against a global symbol.
2532 template<int size
, bool big_endian
>
2534 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2535 Sized_relobj_file
<size
, big_endian
>* object
,
2536 unsigned int r_type
,
2539 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2540 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2543 // Scan a relocation for a global symbol.
2545 template<int size
, bool big_endian
>
2547 Target_sparc
<size
, big_endian
>::Scan::global(
2548 Symbol_table
* symtab
,
2550 Target_sparc
<size
, big_endian
>* target
,
2551 Sized_relobj_file
<size
, big_endian
>* object
,
2552 unsigned int data_shndx
,
2553 Output_section
* output_section
,
2554 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2555 unsigned int r_type
,
2558 unsigned int orig_r_type
= r_type
;
2559 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2561 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2562 // section. We check here to avoid creating a dynamic reloc against
2563 // _GLOBAL_OFFSET_TABLE_.
2564 if (!target
->has_got_section()
2565 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2566 target
->got_section(symtab
, layout
);
2570 // A STT_GNU_IFUNC symbol may require a PLT entry.
2572 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2573 target
->make_plt_entry(symtab
, layout
, gsym
);
2577 case elfcpp::R_SPARC_NONE
:
2578 case elfcpp::R_SPARC_REGISTER
:
2579 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2580 case elfcpp::R_SPARC_GNU_VTENTRY
:
2583 case elfcpp::R_SPARC_PLT64
:
2584 case elfcpp::R_SPARC_PLT32
:
2585 case elfcpp::R_SPARC_HIPLT22
:
2586 case elfcpp::R_SPARC_LOPLT10
:
2587 case elfcpp::R_SPARC_PCPLT32
:
2588 case elfcpp::R_SPARC_PCPLT22
:
2589 case elfcpp::R_SPARC_PCPLT10
:
2590 case elfcpp::R_SPARC_WPLT30
:
2591 // If the symbol is fully resolved, this is just a PC32 reloc.
2592 // Otherwise we need a PLT entry.
2593 if (gsym
->final_value_is_known())
2595 // If building a shared library, we can also skip the PLT entry
2596 // if the symbol is defined in the output file and is protected
2598 if (gsym
->is_defined()
2599 && !gsym
->is_from_dynobj()
2600 && !gsym
->is_preemptible())
2602 target
->make_plt_entry(symtab
, layout
, gsym
);
2605 case elfcpp::R_SPARC_DISP8
:
2606 case elfcpp::R_SPARC_DISP16
:
2607 case elfcpp::R_SPARC_DISP32
:
2608 case elfcpp::R_SPARC_DISP64
:
2609 case elfcpp::R_SPARC_PC_HH22
:
2610 case elfcpp::R_SPARC_PC_HM10
:
2611 case elfcpp::R_SPARC_PC_LM22
:
2612 case elfcpp::R_SPARC_PC10
:
2613 case elfcpp::R_SPARC_PC22
:
2614 case elfcpp::R_SPARC_WDISP30
:
2615 case elfcpp::R_SPARC_WDISP22
:
2616 case elfcpp::R_SPARC_WDISP19
:
2617 case elfcpp::R_SPARC_WDISP16
:
2618 case elfcpp::R_SPARC_WDISP10
:
2620 if (gsym
->needs_plt_entry())
2621 target
->make_plt_entry(symtab
, layout
, gsym
);
2622 // Make a dynamic relocation if necessary.
2623 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2625 if (gsym
->may_need_copy_reloc())
2627 target
->copy_reloc(symtab
, layout
, object
,
2628 data_shndx
, output_section
, gsym
,
2633 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2634 check_non_pic(object
, r_type
);
2635 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2636 data_shndx
, reloc
.get_r_offset(),
2637 reloc
.get_r_addend());
2643 case elfcpp::R_SPARC_UA64
:
2644 case elfcpp::R_SPARC_64
:
2645 case elfcpp::R_SPARC_HIX22
:
2646 case elfcpp::R_SPARC_LOX10
:
2647 case elfcpp::R_SPARC_H34
:
2648 case elfcpp::R_SPARC_H44
:
2649 case elfcpp::R_SPARC_M44
:
2650 case elfcpp::R_SPARC_L44
:
2651 case elfcpp::R_SPARC_HH22
:
2652 case elfcpp::R_SPARC_HM10
:
2653 case elfcpp::R_SPARC_LM22
:
2654 case elfcpp::R_SPARC_HI22
:
2655 case elfcpp::R_SPARC_LO10
:
2656 case elfcpp::R_SPARC_OLO10
:
2657 case elfcpp::R_SPARC_UA32
:
2658 case elfcpp::R_SPARC_32
:
2659 case elfcpp::R_SPARC_UA16
:
2660 case elfcpp::R_SPARC_16
:
2661 case elfcpp::R_SPARC_11
:
2662 case elfcpp::R_SPARC_10
:
2663 case elfcpp::R_SPARC_8
:
2664 case elfcpp::R_SPARC_7
:
2665 case elfcpp::R_SPARC_6
:
2666 case elfcpp::R_SPARC_5
:
2668 // Make a PLT entry if necessary.
2669 if (gsym
->needs_plt_entry())
2671 target
->make_plt_entry(symtab
, layout
, gsym
);
2672 // Since this is not a PC-relative relocation, we may be
2673 // taking the address of a function. In that case we need to
2674 // set the entry in the dynamic symbol table to the address of
2676 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2677 gsym
->set_needs_dynsym_value();
2679 // Make a dynamic relocation if necessary.
2680 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2682 unsigned int r_off
= reloc
.get_r_offset();
2684 // The assembler can sometimes emit unaligned relocations
2685 // for dwarf2 cfi directives.
2688 case elfcpp::R_SPARC_16
:
2690 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2692 case elfcpp::R_SPARC_32
:
2694 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2696 case elfcpp::R_SPARC_64
:
2698 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2700 case elfcpp::R_SPARC_UA16
:
2702 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2704 case elfcpp::R_SPARC_UA32
:
2706 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2708 case elfcpp::R_SPARC_UA64
:
2710 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2714 if (gsym
->may_need_copy_reloc())
2716 target
->copy_reloc(symtab
, layout
, object
,
2717 data_shndx
, output_section
, gsym
, reloc
);
2719 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2720 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2721 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2722 && gsym
->can_use_relative_reloc(false)
2723 && !gsym
->is_from_dynobj()
2724 && !gsym
->is_undefined()
2725 && !gsym
->is_preemptible())
2727 // Use an IRELATIVE reloc for a locally defined
2728 // STT_GNU_IFUNC symbol. This makes a function
2729 // address in a PIE executable match the address in a
2730 // shared library that it links against.
2731 Reloc_section
* rela_dyn
=
2732 target
->rela_ifunc_section(layout
);
2733 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2734 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2735 output_section
, object
,
2737 reloc
.get_r_offset(),
2738 reloc
.get_r_addend());
2740 else if ((r_type
== elfcpp::R_SPARC_32
2741 || r_type
== elfcpp::R_SPARC_64
)
2742 && gsym
->can_use_relative_reloc(false))
2744 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2745 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2746 output_section
, object
,
2747 data_shndx
, reloc
.get_r_offset(),
2748 reloc
.get_r_addend(), is_ifunc
);
2752 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2754 check_non_pic(object
, r_type
);
2755 if (gsym
->is_from_dynobj()
2756 || gsym
->is_undefined()
2757 || gsym
->is_preemptible())
2758 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2760 reloc
.get_r_offset(),
2761 reloc
.get_r_addend());
2763 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2766 reloc
.get_r_offset(),
2767 reloc
.get_r_addend());
2773 case elfcpp::R_SPARC_GOTDATA_OP
:
2774 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2775 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2776 if (gsym
->is_defined()
2777 && !gsym
->is_from_dynobj()
2778 && !gsym
->is_preemptible()
2781 // We will optimize this into a GOT relative relocation
2782 // and code transform the GOT load into an addition.
2785 case elfcpp::R_SPARC_GOT10
:
2786 case elfcpp::R_SPARC_GOT13
:
2787 case elfcpp::R_SPARC_GOT22
:
2789 // The symbol requires a GOT entry.
2790 Output_data_got
<size
, big_endian
>* got
;
2792 got
= target
->got_section(symtab
, layout
);
2793 if (gsym
->final_value_is_known())
2795 // For a STT_GNU_IFUNC symbol we want the PLT address.
2796 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2797 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2799 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2803 // If this symbol is not fully resolved, we need to add a
2804 // GOT entry with a dynamic relocation.
2805 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2807 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2809 // 1) The symbol may be defined in some other module.
2811 // 2) We are building a shared library and this is a
2812 // protected symbol; using GLOB_DAT means that the dynamic
2813 // linker can use the address of the PLT in the main
2814 // executable when appropriate so that function address
2815 // comparisons work.
2817 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2818 // code, again so that function address comparisons work.
2819 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2820 if (gsym
->is_from_dynobj()
2821 || gsym
->is_undefined()
2822 || gsym
->is_preemptible()
2823 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2824 && parameters
->options().shared())
2825 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2826 && parameters
->options().output_is_position_independent()
2827 && !gsym
->is_forced_local()))
2829 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2831 // If this symbol is forced local, this relocation will
2832 // not work properly. That's because ld.so on sparc
2833 // (and 32-bit powerpc) expects st_value in the r_addend
2834 // of relocations for STB_LOCAL symbols. Curiously the
2835 // BFD linker does not promote global hidden symbols to be
2836 // STB_LOCAL in the dynamic symbol table like Gold does.
2837 gold_assert(!gsym
->is_forced_local());
2838 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2841 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2843 unsigned int off
= got
->add_constant(0);
2845 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2848 // Tell the dynamic linker to use the PLT address
2849 // when resolving relocations.
2850 if (gsym
->is_from_dynobj()
2851 && !parameters
->options().shared())
2852 gsym
->set_needs_dynsym_value();
2854 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2855 got
, off
, 0, is_ifunc
);
2861 // These are initial tls relocs, which are expected when
2863 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2864 case elfcpp::R_SPARC_TLS_GD_LO10
:
2865 case elfcpp::R_SPARC_TLS_GD_ADD
:
2866 case elfcpp::R_SPARC_TLS_GD_CALL
:
2867 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2868 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2869 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2870 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2871 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2872 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2873 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2874 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2875 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2876 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2877 case elfcpp::R_SPARC_TLS_IE_LO10
:
2878 case elfcpp::R_SPARC_TLS_IE_LD
:
2879 case elfcpp::R_SPARC_TLS_IE_LDX
:
2880 case elfcpp::R_SPARC_TLS_IE_ADD
:
2882 const bool is_final
= gsym
->final_value_is_known();
2883 const tls::Tls_optimization optimized_type
2884 = optimize_tls_reloc(is_final
, r_type
);
2887 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2888 case elfcpp::R_SPARC_TLS_GD_LO10
:
2889 case elfcpp::R_SPARC_TLS_GD_ADD
:
2890 case elfcpp::R_SPARC_TLS_GD_CALL
:
2891 if (optimized_type
== tls::TLSOPT_NONE
)
2893 // Create a pair of GOT entries for the module index and
2894 // dtv-relative offset.
2895 Output_data_got
<size
, big_endian
>* got
2896 = target
->got_section(symtab
, layout
);
2897 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2898 target
->rela_dyn_section(layout
),
2900 ? elfcpp::R_SPARC_TLS_DTPMOD64
2901 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2903 ? elfcpp::R_SPARC_TLS_DTPOFF64
2904 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2906 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2907 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2908 generate_tls_call(symtab
, layout
, target
);
2910 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2912 // Create a GOT entry for the tp-relative offset.
2913 Output_data_got
<size
, big_endian
>* got
2914 = target
->got_section(symtab
, layout
);
2915 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2916 target
->rela_dyn_section(layout
),
2918 elfcpp::R_SPARC_TLS_TPOFF64
:
2919 elfcpp::R_SPARC_TLS_TPOFF32
));
2921 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2922 unsupported_reloc_global(object
, r_type
, gsym
);
2925 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2926 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2927 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2928 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2929 if (optimized_type
== tls::TLSOPT_NONE
)
2931 // Create a GOT entry for the module index.
2932 target
->got_mod_index_entry(symtab
, layout
, object
);
2934 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2935 generate_tls_call(symtab
, layout
, target
);
2937 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2938 unsupported_reloc_global(object
, r_type
, gsym
);
2941 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2942 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2943 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2946 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2947 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2948 layout
->set_has_static_tls();
2949 if (parameters
->options().shared())
2951 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2952 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2953 output_section
, object
,
2954 data_shndx
, reloc
.get_r_offset(),
2959 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2960 case elfcpp::R_SPARC_TLS_IE_LO10
:
2961 case elfcpp::R_SPARC_TLS_IE_LD
:
2962 case elfcpp::R_SPARC_TLS_IE_LDX
:
2963 case elfcpp::R_SPARC_TLS_IE_ADD
:
2964 layout
->set_has_static_tls();
2965 if (optimized_type
== tls::TLSOPT_NONE
)
2967 // Create a GOT entry for the tp-relative offset.
2968 Output_data_got
<size
, big_endian
>* got
2969 = target
->got_section(symtab
, layout
);
2970 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2971 target
->rela_dyn_section(layout
),
2973 ? elfcpp::R_SPARC_TLS_TPOFF64
2974 : elfcpp::R_SPARC_TLS_TPOFF32
));
2976 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2977 unsupported_reloc_global(object
, r_type
, gsym
);
2983 // These are relocations which should only be seen by the
2984 // dynamic linker, and should never be seen here.
2985 case elfcpp::R_SPARC_COPY
:
2986 case elfcpp::R_SPARC_GLOB_DAT
:
2987 case elfcpp::R_SPARC_JMP_SLOT
:
2988 case elfcpp::R_SPARC_JMP_IREL
:
2989 case elfcpp::R_SPARC_RELATIVE
:
2990 case elfcpp::R_SPARC_IRELATIVE
:
2991 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2992 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2993 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2994 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2995 case elfcpp::R_SPARC_TLS_TPOFF64
:
2996 case elfcpp::R_SPARC_TLS_TPOFF32
:
2997 gold_error(_("%s: unexpected reloc %u in object file"),
2998 object
->name().c_str(), r_type
);
3002 unsupported_reloc_global(object
, r_type
, gsym
);
3007 // Process relocations for gc.
3009 template<int size
, bool big_endian
>
3011 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3012 Symbol_table
* symtab
,
3014 Sized_relobj_file
<size
, big_endian
>* object
,
3015 unsigned int data_shndx
,
3017 const unsigned char* prelocs
,
3019 Output_section
* output_section
,
3020 bool needs_special_offset_handling
,
3021 size_t local_symbol_count
,
3022 const unsigned char* plocal_symbols
)
3024 typedef Target_sparc
<size
, big_endian
> Sparc
;
3025 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3027 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
3028 typename
Target_sparc::Relocatable_size_for_reloc
>(
3037 needs_special_offset_handling
,
3042 // Scan relocations for a section.
3044 template<int size
, bool big_endian
>
3046 Target_sparc
<size
, big_endian
>::scan_relocs(
3047 Symbol_table
* symtab
,
3049 Sized_relobj_file
<size
, big_endian
>* object
,
3050 unsigned int data_shndx
,
3051 unsigned int sh_type
,
3052 const unsigned char* prelocs
,
3054 Output_section
* output_section
,
3055 bool needs_special_offset_handling
,
3056 size_t local_symbol_count
,
3057 const unsigned char* plocal_symbols
)
3059 typedef Target_sparc
<size
, big_endian
> Sparc
;
3060 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3062 if (sh_type
== elfcpp::SHT_REL
)
3064 gold_error(_("%s: unsupported REL reloc section"),
3065 object
->name().c_str());
3069 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
3078 needs_special_offset_handling
,
3083 // Finalize the sections.
3085 template<int size
, bool big_endian
>
3087 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3089 const Input_objects
*,
3090 Symbol_table
* symtab
)
3093 this->plt_
->emit_pending_ifunc_relocs();
3095 // Fill in some more dynamic tags.
3096 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3098 : this->plt_
->rel_plt());
3099 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3100 this->rela_dyn_
, true, true);
3102 // Emit any relocs we saved in an attempt to avoid generating COPY
3104 if (this->copy_relocs_
.any_saved_relocs())
3105 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3107 if (parameters
->doing_static_link()
3108 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3110 // If linking statically, make sure that the __rela_iplt symbols
3111 // were defined if necessary, even if we didn't create a PLT.
3112 static const Define_symbol_in_segment syms
[] =
3115 "__rela_iplt_start", // name
3116 elfcpp::PT_LOAD
, // segment_type
3117 elfcpp::PF_W
, // segment_flags_set
3118 elfcpp::PF(0), // segment_flags_clear
3121 elfcpp::STT_NOTYPE
, // type
3122 elfcpp::STB_GLOBAL
, // binding
3123 elfcpp::STV_HIDDEN
, // visibility
3125 Symbol::SEGMENT_START
, // offset_from_base
3129 "__rela_iplt_end", // name
3130 elfcpp::PT_LOAD
, // segment_type
3131 elfcpp::PF_W
, // segment_flags_set
3132 elfcpp::PF(0), // segment_flags_clear
3135 elfcpp::STT_NOTYPE
, // type
3136 elfcpp::STB_GLOBAL
, // binding
3137 elfcpp::STV_HIDDEN
, // visibility
3139 Symbol::SEGMENT_START
, // offset_from_base
3144 symtab
->define_symbols(layout
, 2, syms
,
3145 layout
->script_options()->saw_sections_clause());
3149 // Perform a relocation.
3151 template<int size
, bool big_endian
>
3153 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3154 const Relocate_info
<size
, big_endian
>* relinfo
,
3155 Target_sparc
* target
,
3158 const elfcpp::Rela
<size
, big_endian
>& rela
,
3159 unsigned int r_type
,
3160 const Sized_symbol
<size
>* gsym
,
3161 const Symbol_value
<size
>* psymval
,
3162 unsigned char* view
,
3163 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3164 section_size_type view_size
)
3166 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3169 if (this->ignore_gd_add_
)
3171 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3172 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3173 _("missing expected TLS relocation"));
3176 this->ignore_gd_add_
= false;
3180 if (this->reloc_adjust_addr_
== view
)
3183 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3184 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3186 // Pick the value to use for symbols defined in shared objects.
3187 Symbol_value
<size
> symval
;
3189 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3191 elfcpp::Elf_Xword value
;
3193 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3195 symval
.set_output_value(value
);
3199 else if (gsym
== NULL
&& orig_is_ifunc
)
3201 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3202 if (object
->local_has_plt_offset(r_sym
))
3204 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3205 + object
->local_plt_offset(r_sym
));
3210 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3212 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3213 // pointer points to the beginning, not the end, of the table.
3214 // So we just use the plain offset.
3215 unsigned int got_offset
= 0;
3216 bool gdop_valid
= false;
3219 case elfcpp::R_SPARC_GOTDATA_OP
:
3220 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3221 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3222 // If this is local, we did not create a GOT entry because we
3223 // intend to transform this into a GOT relative relocation.
3225 || (gsym
->is_defined()
3226 && !gsym
->is_from_dynobj()
3227 && !gsym
->is_preemptible()
3230 got_offset
= psymval
->value(object
, 0) - target
->got_address();
3234 case elfcpp::R_SPARC_GOT10
:
3235 case elfcpp::R_SPARC_GOT13
:
3236 case elfcpp::R_SPARC_GOT22
:
3239 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3240 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3244 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3245 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3246 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3256 case elfcpp::R_SPARC_NONE
:
3257 case elfcpp::R_SPARC_REGISTER
:
3258 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3259 case elfcpp::R_SPARC_GNU_VTENTRY
:
3262 case elfcpp::R_SPARC_8
:
3263 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3267 case elfcpp::R_SPARC_16
:
3268 if (rela
.get_r_offset() & 0x1)
3270 // The assembler can sometimes emit unaligned relocations
3271 // for dwarf2 cfi directives.
3272 Reloc::ua16(view
, object
, psymval
, addend
);
3275 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3279 case elfcpp::R_SPARC_32
:
3280 if (!parameters
->options().output_is_position_independent())
3282 if (rela
.get_r_offset() & 0x3)
3284 // The assembler can sometimes emit unaligned relocations
3285 // for dwarf2 cfi directives.
3286 Reloc::ua32(view
, object
, psymval
, addend
);
3289 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3294 case elfcpp::R_SPARC_DISP8
:
3295 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3298 case elfcpp::R_SPARC_DISP16
:
3299 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3302 case elfcpp::R_SPARC_DISP32
:
3303 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3306 case elfcpp::R_SPARC_DISP64
:
3307 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3310 case elfcpp::R_SPARC_WDISP30
:
3311 case elfcpp::R_SPARC_WPLT30
:
3312 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3313 if (target
->may_relax())
3314 relax_call(target
, view
, rela
, view_size
);
3317 case elfcpp::R_SPARC_WDISP22
:
3318 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3321 case elfcpp::R_SPARC_WDISP19
:
3322 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3325 case elfcpp::R_SPARC_WDISP16
:
3326 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3329 case elfcpp::R_SPARC_WDISP10
:
3330 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3333 case elfcpp::R_SPARC_HI22
:
3334 Reloc::hi22(view
, object
, psymval
, addend
);
3337 case elfcpp::R_SPARC_22
:
3338 Reloc::rela32_22(view
, object
, psymval
, addend
);
3341 case elfcpp::R_SPARC_13
:
3342 Reloc::rela32_13(view
, object
, psymval
, addend
);
3345 case elfcpp::R_SPARC_LO10
:
3346 Reloc::lo10(view
, object
, psymval
, addend
);
3349 case elfcpp::R_SPARC_GOT10
:
3350 Reloc::lo10(view
, got_offset
, addend
);
3353 case elfcpp::R_SPARC_GOTDATA_OP
:
3356 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3357 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3360 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3361 val
= elfcpp::Swap
<32, true>::readval(wv
);
3362 val
= 0x80000000 | (val
& 0x3e07c01f);
3363 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3367 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3370 Reloc::gdop_lox10(view
, got_offset
, addend
);
3374 case elfcpp::R_SPARC_GOT13
:
3375 Reloc::rela32_13(view
, got_offset
, addend
);
3378 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3381 Reloc::gdop_hix22(view
, got_offset
, addend
);
3385 case elfcpp::R_SPARC_GOT22
:
3386 Reloc::hi22(view
, got_offset
, addend
);
3389 case elfcpp::R_SPARC_PC10
:
3390 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3393 case elfcpp::R_SPARC_PC22
:
3394 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3397 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3398 case elfcpp::R_SPARC_UA32
:
3399 Reloc::ua32(view
, object
, psymval
, addend
);
3402 case elfcpp::R_SPARC_PLT64
:
3403 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3407 case elfcpp::R_SPARC_PLT32
:
3408 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3412 case elfcpp::R_SPARC_HIPLT22
:
3413 Reloc::hi22(view
, object
, psymval
, addend
);
3416 case elfcpp::R_SPARC_LOPLT10
:
3417 Reloc::lo10(view
, object
, psymval
, addend
);
3420 case elfcpp::R_SPARC_PCPLT32
:
3421 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3424 case elfcpp::R_SPARC_PCPLT22
:
3425 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3428 case elfcpp::R_SPARC_PCPLT10
:
3429 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3432 case elfcpp::R_SPARC_64
:
3433 if (!parameters
->options().output_is_position_independent())
3435 if (rela
.get_r_offset() & 0x7)
3437 // The assembler can sometimes emit unaligned relocations
3438 // for dwarf2 cfi directives.
3439 Reloc::ua64(view
, object
, psymval
, addend
);
3442 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3447 case elfcpp::R_SPARC_OLO10
:
3449 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3450 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3451 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3455 case elfcpp::R_SPARC_HH22
:
3456 Reloc::hh22(view
, object
, psymval
, addend
);
3459 case elfcpp::R_SPARC_PC_HH22
:
3460 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3463 case elfcpp::R_SPARC_HM10
:
3464 Reloc::hm10(view
, object
, psymval
, addend
);
3467 case elfcpp::R_SPARC_PC_HM10
:
3468 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3471 case elfcpp::R_SPARC_LM22
:
3472 Reloc::hi22(view
, object
, psymval
, addend
);
3475 case elfcpp::R_SPARC_PC_LM22
:
3476 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3479 case elfcpp::R_SPARC_11
:
3480 Reloc::rela32_11(view
, object
, psymval
, addend
);
3483 case elfcpp::R_SPARC_10
:
3484 Reloc::rela32_10(view
, object
, psymval
, addend
);
3487 case elfcpp::R_SPARC_7
:
3488 Reloc::rela32_7(view
, object
, psymval
, addend
);
3491 case elfcpp::R_SPARC_6
:
3492 Reloc::rela32_6(view
, object
, psymval
, addend
);
3495 case elfcpp::R_SPARC_5
:
3496 Reloc::rela32_5(view
, object
, psymval
, addend
);
3499 case elfcpp::R_SPARC_HIX22
:
3500 Reloc::hix22(view
, object
, psymval
, addend
);
3503 case elfcpp::R_SPARC_LOX10
:
3504 Reloc::lox10(view
, object
, psymval
, addend
);
3507 case elfcpp::R_SPARC_H34
:
3508 Reloc::h34(view
, object
, psymval
, addend
);
3511 case elfcpp::R_SPARC_H44
:
3512 Reloc::h44(view
, object
, psymval
, addend
);
3515 case elfcpp::R_SPARC_M44
:
3516 Reloc::m44(view
, object
, psymval
, addend
);
3519 case elfcpp::R_SPARC_L44
:
3520 Reloc::l44(view
, object
, psymval
, addend
);
3523 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3524 case elfcpp::R_SPARC_UA64
:
3525 Reloc::ua64(view
, object
, psymval
, addend
);
3528 case elfcpp::R_SPARC_UA16
:
3529 Reloc::ua16(view
, object
, psymval
, addend
);
3532 case elfcpp::R_SPARC_TLS_GD_HI22
:
3533 case elfcpp::R_SPARC_TLS_GD_LO10
:
3534 case elfcpp::R_SPARC_TLS_GD_ADD
:
3535 case elfcpp::R_SPARC_TLS_GD_CALL
:
3536 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3537 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3538 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3539 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3540 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3541 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3542 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3543 case elfcpp::R_SPARC_TLS_IE_HI22
:
3544 case elfcpp::R_SPARC_TLS_IE_LO10
:
3545 case elfcpp::R_SPARC_TLS_IE_LD
:
3546 case elfcpp::R_SPARC_TLS_IE_LDX
:
3547 case elfcpp::R_SPARC_TLS_IE_ADD
:
3548 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3549 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3550 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3551 r_type
, gsym
, psymval
, view
,
3552 address
, view_size
);
3555 case elfcpp::R_SPARC_COPY
:
3556 case elfcpp::R_SPARC_GLOB_DAT
:
3557 case elfcpp::R_SPARC_JMP_SLOT
:
3558 case elfcpp::R_SPARC_JMP_IREL
:
3559 case elfcpp::R_SPARC_RELATIVE
:
3560 case elfcpp::R_SPARC_IRELATIVE
:
3561 // These are outstanding tls relocs, which are unexpected when
3563 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3564 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3565 case elfcpp::R_SPARC_TLS_TPOFF64
:
3566 case elfcpp::R_SPARC_TLS_TPOFF32
:
3567 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3568 _("unexpected reloc %u in object file"),
3573 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3574 _("unsupported reloc %u"),
3582 // Perform a TLS relocation.
3584 template<int size
, bool big_endian
>
3586 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3587 const Relocate_info
<size
, big_endian
>* relinfo
,
3588 Target_sparc
<size
, big_endian
>* target
,
3590 const elfcpp::Rela
<size
, big_endian
>& rela
,
3591 unsigned int r_type
,
3592 const Sized_symbol
<size
>* gsym
,
3593 const Symbol_value
<size
>* psymval
,
3594 unsigned char* view
,
3595 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3598 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3599 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3600 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3601 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3603 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3604 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3606 const bool is_final
=
3608 ? !parameters
->options().output_is_position_independent()
3609 : gsym
->final_value_is_known());
3610 const tls::Tls_optimization optimized_type
3611 = optimize_tls_reloc(is_final
, r_type
);
3615 case elfcpp::R_SPARC_TLS_GD_HI22
:
3616 case elfcpp::R_SPARC_TLS_GD_LO10
:
3617 case elfcpp::R_SPARC_TLS_GD_ADD
:
3618 case elfcpp::R_SPARC_TLS_GD_CALL
:
3619 if (optimized_type
== tls::TLSOPT_TO_LE
)
3621 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3624 value
-= tls_segment
->memsz();
3628 case elfcpp::R_SPARC_TLS_GD_HI22
:
3629 // TLS_GD_HI22 --> TLS_LE_HIX22
3630 Reloc::hix22(view
, value
, addend
);
3633 case elfcpp::R_SPARC_TLS_GD_LO10
:
3634 // TLS_GD_LO10 --> TLS_LE_LOX10
3635 Reloc::lox10(view
, value
, addend
);
3638 case elfcpp::R_SPARC_TLS_GD_ADD
:
3639 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3640 val
= elfcpp::Swap
<32, true>::readval(wv
);
3641 val
= (val
& ~0x7c000) | 0x1c000;
3642 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3644 case elfcpp::R_SPARC_TLS_GD_CALL
:
3645 // call __tls_get_addr --> nop
3646 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3653 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3654 ? GOT_TYPE_TLS_OFFSET
3655 : GOT_TYPE_TLS_PAIR
);
3658 gold_assert(gsym
->has_got_offset(got_type
));
3659 value
= gsym
->got_offset(got_type
);
3663 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3664 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3665 value
= object
->local_got_offset(r_sym
, got_type
);
3667 if (optimized_type
== tls::TLSOPT_TO_IE
)
3669 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3674 case elfcpp::R_SPARC_TLS_GD_HI22
:
3675 // TLS_GD_HI22 --> TLS_IE_HI22
3676 Reloc::hi22(view
, value
, addend
);
3679 case elfcpp::R_SPARC_TLS_GD_LO10
:
3680 // TLS_GD_LO10 --> TLS_IE_LO10
3681 Reloc::lo10(view
, value
, addend
);
3684 case elfcpp::R_SPARC_TLS_GD_ADD
:
3685 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3686 val
= elfcpp::Swap
<32, true>::readval(wv
);
3693 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3696 case elfcpp::R_SPARC_TLS_GD_CALL
:
3697 // The compiler can put the TLS_GD_ADD instruction
3698 // into the delay slot of the call. If so, we need
3699 // to transpose the two instructions so that the
3700 // new sequence works properly.
3702 // The test we use is if the instruction in the
3703 // delay slot is an add with destination register
3705 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3706 if ((val
& 0x81f80000) == 0x80000000
3707 && ((val
>> 25) & 0x1f) == 0x8)
3714 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3717 this->ignore_gd_add_
= true;
3721 // Even if the delay slot isn't the TLS_GD_ADD
3722 // instruction, we still have to handle the case
3723 // where it sets up %o0 in some other way.
3724 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3726 this->reloc_adjust_addr_
= view
+ 4;
3728 // call __tls_get_addr --> add %g7, %o0, %o0
3729 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3734 else if (optimized_type
== tls::TLSOPT_NONE
)
3738 case elfcpp::R_SPARC_TLS_GD_HI22
:
3739 Reloc::hi22(view
, value
, addend
);
3741 case elfcpp::R_SPARC_TLS_GD_LO10
:
3742 Reloc::lo10(view
, value
, addend
);
3744 case elfcpp::R_SPARC_TLS_GD_ADD
:
3746 case elfcpp::R_SPARC_TLS_GD_CALL
:
3748 Symbol_value
<size
> symval
;
3749 elfcpp::Elf_Xword value
;
3752 tsym
= target
->tls_get_addr_sym_
;
3754 value
= (target
->plt_section()->address() +
3755 tsym
->plt_offset());
3756 symval
.set_output_value(value
);
3757 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3764 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3765 _("unsupported reloc %u"),
3769 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3770 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3771 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3772 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3773 if (optimized_type
== tls::TLSOPT_TO_LE
)
3775 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3779 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3780 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3781 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3782 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3785 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3786 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3791 else if (optimized_type
== tls::TLSOPT_NONE
)
3793 // Relocate the field with the offset of the GOT entry for
3794 // the module index.
3795 unsigned int got_offset
;
3797 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3800 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3801 Reloc::hi22(view
, got_offset
, addend
);
3803 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3804 Reloc::lo10(view
, got_offset
, addend
);
3806 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3808 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3810 Symbol_value
<size
> symval
;
3811 elfcpp::Elf_Xword value
;
3814 tsym
= target
->tls_get_addr_sym_
;
3816 value
= (target
->plt_section()->address() +
3817 tsym
->plt_offset());
3818 symval
.set_output_value(value
);
3819 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3825 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3826 _("unsupported reloc %u"),
3830 // These relocs can appear in debugging sections, in which case
3831 // we won't see the TLS_LDM relocs. The local_dynamic_type
3832 // field tells us this.
3833 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3834 if (optimized_type
== tls::TLSOPT_TO_LE
)
3836 value
-= tls_segment
->memsz();
3837 Reloc::hix22(view
, value
, addend
);
3840 Reloc::ldo_hix22(view
, value
, addend
);
3842 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3843 if (optimized_type
== tls::TLSOPT_TO_LE
)
3845 value
-= tls_segment
->memsz();
3846 Reloc::lox10(view
, value
, addend
);
3849 Reloc::ldo_lox10(view
, value
, addend
);
3851 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3852 if (optimized_type
== tls::TLSOPT_TO_LE
)
3854 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3857 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3858 val
= elfcpp::Swap
<32, true>::readval(wv
);
3859 val
= (val
& ~0x7c000) | 0x1c000;
3860 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3864 // When optimizing IE --> LE, the only relocation that is handled
3865 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3866 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3867 // rs2 and rd are the same.
3868 case elfcpp::R_SPARC_TLS_IE_LD
:
3869 case elfcpp::R_SPARC_TLS_IE_LDX
:
3870 if (optimized_type
== tls::TLSOPT_TO_LE
)
3872 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3873 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3874 Insntype rs2
= val
& 0x1f;
3875 Insntype rd
= (val
>> 25) & 0x1f;
3880 val
= sparc_mov
| (val
& 0x3e00001f);
3882 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3886 case elfcpp::R_SPARC_TLS_IE_HI22
:
3887 case elfcpp::R_SPARC_TLS_IE_LO10
:
3888 if (optimized_type
== tls::TLSOPT_TO_LE
)
3890 value
-= tls_segment
->memsz();
3893 case elfcpp::R_SPARC_TLS_IE_HI22
:
3894 // IE_HI22 --> LE_HIX22
3895 Reloc::hix22(view
, value
, addend
);
3897 case elfcpp::R_SPARC_TLS_IE_LO10
:
3898 // IE_LO10 --> LE_LOX10
3899 Reloc::lox10(view
, value
, addend
);
3904 else if (optimized_type
== tls::TLSOPT_NONE
)
3906 // Relocate the field with the offset of the GOT entry for
3907 // the tp-relative offset of the symbol.
3910 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3911 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3915 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3916 gold_assert(object
->local_has_got_offset(r_sym
,
3917 GOT_TYPE_TLS_OFFSET
));
3918 value
= object
->local_got_offset(r_sym
,
3919 GOT_TYPE_TLS_OFFSET
);
3923 case elfcpp::R_SPARC_TLS_IE_HI22
:
3924 Reloc::hi22(view
, value
, addend
);
3926 case elfcpp::R_SPARC_TLS_IE_LO10
:
3927 Reloc::lo10(view
, value
, addend
);
3932 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3933 _("unsupported reloc %u"),
3937 case elfcpp::R_SPARC_TLS_IE_ADD
:
3938 // This seems to be mainly so that we can find the addition
3939 // instruction if there is one. There doesn't seem to be any
3940 // actual relocation to apply.
3943 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3944 // If we're creating a shared library, a dynamic relocation will
3945 // have been created for this location, so do not apply it now.
3946 if (!parameters
->options().shared())
3948 value
-= tls_segment
->memsz();
3949 Reloc::hix22(view
, value
, addend
);
3953 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3954 // If we're creating a shared library, a dynamic relocation will
3955 // have been created for this location, so do not apply it now.
3956 if (!parameters
->options().shared())
3958 value
-= tls_segment
->memsz();
3959 Reloc::lox10(view
, value
, addend
);
3965 // Relax a call instruction.
3967 template<int size
, bool big_endian
>
3969 Target_sparc
<size
, big_endian
>::Relocate::relax_call(
3970 Target_sparc
<size
, big_endian
>* target
,
3971 unsigned char* view
,
3972 const elfcpp::Rela
<size
, big_endian
>& rela
,
3973 section_size_type view_size
)
3975 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3976 Insntype
*wv
= reinterpret_cast<Insntype
*>(view
);
3977 Insntype call_insn
, delay_insn
, set_insn
;
3978 uint32_t op3
, reg
, off
;
3980 // This code tries to relax call instructions that meet
3981 // certain criteria.
3983 // The first criteria is that the call must be such that the return
3984 // address which the call writes into %o7 is unused. Two sequences
3985 // meet this criteria, and are used to implement tail calls.
3987 // Leaf function tail call:
3989 // or %o7, %g0, %ANY_REG
3991 // or %ANY_REG, %g0, %o7
3993 // Non-leaf function tail call:
3998 // The second criteria is that the call destination is close. If
3999 // the displacement can fit in a signed 22-bit immediate field of a
4000 // pre-V9 branch, we can do it. If we are generating a 64-bit
4001 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4002 // and the displacement fits in a signed 19-bit immediate field,
4003 // then we can use a V9 branch.
4005 // Make sure the delay instruction can be safely accessed.
4006 if (rela
.get_r_offset() + 8 > view_size
)
4009 call_insn
= elfcpp::Swap
<32, true>::readval(wv
);
4010 delay_insn
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
4012 // Make sure it is really a call instruction.
4013 if (((call_insn
>> 30) & 0x3) != 1)
4016 if (((delay_insn
>> 30) & 0x3) != 2)
4019 // Accept only a restore or an integer arithmetic operation whose
4020 // sole side effect is to write the %o7 register (and perhaps set
4021 // the condition codes, which are considered clobbered across
4024 // For example, we don't want to match a tagged addition or
4025 // subtraction. We also don't want to match something like a
4028 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4029 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4031 op3
= (delay_insn
>> 19) & 0x3f;
4032 reg
= (delay_insn
>> 25) & 0x1f;
4034 && ((op3
& 0x28) != 0 || reg
!= 15))
4037 // For non-restore instructions, make sure %o7 isn't
4042 reg
= (delay_insn
>> 14) & 0x15;
4046 // And if non-immediate, check RS2
4047 if (((delay_insn
>> 13) & 1) == 0)
4049 reg
= (delay_insn
& 0x1f);
4055 // Now check the branch distance. We are called after the
4056 // call has been relocated, so we just have to peek at the
4057 // offset contained in the instruction.
4058 off
= call_insn
& 0x3fffffff;
4059 if ((off
& 0x3fe00000) != 0
4060 && (off
& 0x3fe00000) != 0x3fe00000)
4063 if ((size
== 64 || target
->elf_machine_
== elfcpp::EM_SPARC32PLUS
)
4064 && ((off
& 0x3c0000) == 0
4065 || (off
& 0x3c0000) == 0x3c0000))
4068 call_insn
= 0x10680000 | (off
& 0x07ffff);
4073 call_insn
= 0x10800000 | (off
& 0x3fffff);
4075 elfcpp::Swap
<32, true>::writeval(wv
, call_insn
);
4077 // See if we can NOP out the delay slot instruction. We peek
4078 // at the instruction before the call to make sure we're dealing
4079 // with exactly the:
4081 // or %o7, %g0, %ANY_REG
4083 // or %ANY_REG, %g0, %o7
4085 // case. Otherwise this might be a tricky piece of hand written
4086 // assembler calculating %o7 in some non-trivial way, and therefore
4087 // we can't be sure that NOP'ing out the delay slot is safe.
4089 && rela
.get_r_offset() >= 4)
4091 if ((delay_insn
& ~(0x1f << 14)) != 0x9e100000)
4094 set_insn
= elfcpp::Swap
<32, true>::readval(wv
- 1);
4095 if ((set_insn
& ~(0x1f << 25)) != 0x8013c000)
4098 reg
= (set_insn
>> 25) & 0x1f;
4099 if (reg
== 0 || reg
== 15)
4101 if (reg
!= ((delay_insn
>> 14) & 0x1f))
4104 // All tests pass, nop it out.
4105 elfcpp::Swap
<32, true>::writeval(wv
+ 1, sparc_nop
);
4109 // Relocate section data.
4111 template<int size
, bool big_endian
>
4113 Target_sparc
<size
, big_endian
>::relocate_section(
4114 const Relocate_info
<size
, big_endian
>* relinfo
,
4115 unsigned int sh_type
,
4116 const unsigned char* prelocs
,
4118 Output_section
* output_section
,
4119 bool needs_special_offset_handling
,
4120 unsigned char* view
,
4121 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4122 section_size_type view_size
,
4123 const Reloc_symbol_changes
* reloc_symbol_changes
)
4125 typedef Target_sparc
<size
, big_endian
> Sparc
;
4126 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
4128 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4130 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
4137 needs_special_offset_handling
,
4141 reloc_symbol_changes
);
4144 // Return the size of a relocation while scanning during a relocatable
4147 template<int size
, bool big_endian
>
4149 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4153 // We are always SHT_RELA, so we should never get here.
4158 // Scan the relocs during a relocatable link.
4160 template<int size
, bool big_endian
>
4162 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4163 Symbol_table
* symtab
,
4165 Sized_relobj_file
<size
, big_endian
>* object
,
4166 unsigned int data_shndx
,
4167 unsigned int sh_type
,
4168 const unsigned char* prelocs
,
4170 Output_section
* output_section
,
4171 bool needs_special_offset_handling
,
4172 size_t local_symbol_count
,
4173 const unsigned char* plocal_symbols
,
4174 Relocatable_relocs
* rr
)
4176 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4178 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4179 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4181 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4182 Scan_relocatable_relocs
>(
4190 needs_special_offset_handling
,
4196 // Relocate a section during a relocatable link.
4198 template<int size
, bool big_endian
>
4200 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
4201 const Relocate_info
<size
, big_endian
>* relinfo
,
4202 unsigned int sh_type
,
4203 const unsigned char* prelocs
,
4205 Output_section
* output_section
,
4206 off_t offset_in_output_section
,
4207 const Relocatable_relocs
* rr
,
4208 unsigned char* view
,
4209 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4210 section_size_type view_size
,
4211 unsigned char* reloc_view
,
4212 section_size_type reloc_view_size
)
4214 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4216 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
4221 offset_in_output_section
,
4230 // Return the value to use for a dynamic which requires special
4231 // treatment. This is how we support equality comparisons of function
4232 // pointers across shared library boundaries, as described in the
4233 // processor specific ABI supplement.
4235 template<int size
, bool big_endian
>
4237 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4239 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4240 return this->plt_section()->address() + gsym
->plt_offset();
4243 // do_make_elf_object to override the same function in the base class.
4244 // We need to use a target-specific sub-class of
4245 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4246 // of the ELF headers. Hence we need to have our own ELF object creation.
4248 template<int size
, bool big_endian
>
4250 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4251 const std::string
& name
,
4252 Input_file
* input_file
,
4253 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4255 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4256 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4257 elfcpp::Elf_Word omm
, mm
;
4261 case elfcpp::EM_SPARC32PLUS
:
4262 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4265 case elfcpp::EM_SPARC
:
4266 case elfcpp::EM_SPARCV9
:
4273 if (!this->elf_flags_set_
)
4275 this->elf_flags_
= flags
;
4276 this->elf_flags_set_
= true;
4280 // Accumulate cpu feature bits.
4281 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4282 | elfcpp::EF_SPARC_SUN_US1
4283 | elfcpp::EF_SPARC_HAL_R1
4284 | elfcpp::EF_SPARC_SUN_US3
));
4286 // Bump the memory model setting to the most restrictive
4287 // one we encounter.
4288 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4289 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4292 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4294 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4295 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4297 else if (mm
== elfcpp::EF_SPARCV9_PSO
4298 && omm
== elfcpp::EF_SPARCV9_RMO
)
4300 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4301 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4306 // Validate that the little-endian flag matches how we've
4307 // been instantiated.
4308 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4311 gold_error(_("%s: little endian elf flag set on BE object"),
4314 gold_error(_("%s: little endian elf flag clear on LE object"),
4318 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4321 // Adjust ELF file header.
4323 template<int size
, bool big_endian
>
4325 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4326 unsigned char* view
,
4329 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4331 oehdr
.put_e_machine(this->elf_machine_
);
4332 oehdr
.put_e_flags(this->elf_flags_
);
4334 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4337 // The selector for sparc object files.
4339 template<int size
, bool big_endian
>
4340 class Target_selector_sparc
: public Target_selector
4343 Target_selector_sparc()
4344 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4345 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4346 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4349 Target
* do_recognize(int machine
, int, int)
4354 if (machine
!= elfcpp::EM_SPARCV9
)
4359 if (machine
!= elfcpp::EM_SPARC
4360 && machine
!= elfcpp::EM_SPARC32PLUS
)
4368 return this->instantiate_target();
4371 Target
* do_instantiate_target()
4372 { return new Target_sparc
<size
, big_endian
>(); }
4375 Target_selector_sparc
<32, true> target_selector_sparc32
;
4376 Target_selector_sparc
<64, true> target_selector_sparc64
;
4378 } // End anonymous namespace.