1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
),
64 elf_machine_(sparc_info
.machine_code
), elf_flags_(0),
69 // Process the relocations to determine unreferenced sections for
70 // garbage collection.
72 gc_process_relocs(Symbol_table
* symtab
,
74 Sized_relobj_file
<size
, big_endian
>* object
,
75 unsigned int data_shndx
,
77 const unsigned char* prelocs
,
79 Output_section
* output_section
,
80 bool needs_special_offset_handling
,
81 size_t local_symbol_count
,
82 const unsigned char* plocal_symbols
);
84 // Scan the relocations to look for symbol adjustments.
86 scan_relocs(Symbol_table
* symtab
,
88 Sized_relobj_file
<size
, big_endian
>* object
,
89 unsigned int data_shndx
,
91 const unsigned char* prelocs
,
93 Output_section
* output_section
,
94 bool needs_special_offset_handling
,
95 size_t local_symbol_count
,
96 const unsigned char* plocal_symbols
);
97 // Finalize the sections.
99 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
101 // Return the value to use for a dynamic which requires special
104 do_dynsym_value(const Symbol
*) const;
106 // Relocate a section.
108 relocate_section(const Relocate_info
<size
, big_endian
>*,
109 unsigned int sh_type
,
110 const unsigned char* prelocs
,
112 Output_section
* output_section
,
113 bool needs_special_offset_handling
,
115 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
116 section_size_type view_size
,
117 const Reloc_symbol_changes
*);
119 // Scan the relocs during a relocatable link.
121 scan_relocatable_relocs(Symbol_table
* symtab
,
123 Sized_relobj_file
<size
, big_endian
>* object
,
124 unsigned int data_shndx
,
125 unsigned int sh_type
,
126 const unsigned char* prelocs
,
128 Output_section
* output_section
,
129 bool needs_special_offset_handling
,
130 size_t local_symbol_count
,
131 const unsigned char* plocal_symbols
,
132 Relocatable_relocs
*);
134 // Emit relocations for a section.
136 relocate_relocs(const Relocate_info
<size
, big_endian
>*,
137 unsigned int sh_type
,
138 const unsigned char* prelocs
,
140 Output_section
* output_section
,
141 off_t offset_in_output_section
,
142 const Relocatable_relocs
*,
144 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
145 section_size_type view_size
,
146 unsigned char* reloc_view
,
147 section_size_type reloc_view_size
);
149 // Return whether SYM is defined by the ABI.
151 do_is_defined_by_abi(const Symbol
* sym
) const
153 // XXX Really need to support this better...
154 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
157 return strcmp(sym
->name(), "___tls_get_addr") == 0;
160 // Return the PLT address to use for a global symbol.
162 do_plt_address_for_global(const Symbol
* gsym
) const
163 { return this->plt_section()->address_for_global(gsym
); }
166 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
167 { return this->plt_section()->address_for_local(relobj
, symndx
); }
169 // Return whether there is a GOT section.
171 has_got_section() const
172 { return this->got_
!= NULL
; }
174 // Return the size of the GOT section.
178 gold_assert(this->got_
!= NULL
);
179 return this->got_
->data_size();
182 // Return the number of entries in the GOT.
184 got_entry_count() const
186 if (this->got_
== NULL
)
188 return this->got_size() / (size
/ 8);
191 // Return the address of the GOT.
195 if (this->got_
== NULL
)
197 return this->got_
->address();
200 // Return the number of entries in the PLT.
202 plt_entry_count() const;
204 // Return the offset of the first non-reserved PLT entry.
206 first_plt_entry_offset() const;
208 // Return the size of each PLT entry.
210 plt_entry_size() const;
213 // Make an ELF object.
215 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
216 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
219 do_adjust_elf_header(unsigned char* view
, int len
) const;
223 // The class which scans relocations.
228 : issued_non_pic_error_(false)
232 get_reference_flags(unsigned int r_type
);
235 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
236 Sized_relobj_file
<size
, big_endian
>* object
,
237 unsigned int data_shndx
,
238 Output_section
* output_section
,
239 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
240 const elfcpp::Sym
<size
, big_endian
>& lsym
);
243 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
244 Sized_relobj_file
<size
, big_endian
>* object
,
245 unsigned int data_shndx
,
246 Output_section
* output_section
,
247 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
251 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
253 Sized_relobj_file
<size
, big_endian
>* ,
256 const elfcpp::Rela
<size
, big_endian
>& ,
258 const elfcpp::Sym
<size
, big_endian
>&)
262 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
264 Sized_relobj_file
<size
, big_endian
>* ,
267 const elfcpp::Rela
<size
,
269 unsigned int , Symbol
*)
275 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
276 unsigned int r_type
);
279 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
280 unsigned int r_type
, Symbol
*);
283 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
284 Target_sparc
* target
);
287 check_non_pic(Relobj
*, unsigned int r_type
);
290 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
291 unsigned int r_type
);
293 // Whether we have issued an error about a non-PIC compilation.
294 bool issued_non_pic_error_
;
297 // The class which implements relocation.
302 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
307 if (this->ignore_gd_add_
)
309 // FIXME: This needs to specify the location somehow.
310 gold_error(_("missing expected TLS relocation"));
314 // Do a relocation. Return false if the caller should not issue
315 // any warnings about this relocation.
317 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
318 Output_section
*, size_t relnum
,
319 const elfcpp::Rela
<size
, big_endian
>&,
320 unsigned int r_type
, const Sized_symbol
<size
>*,
321 const Symbol_value
<size
>*,
323 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
327 // Do a TLS relocation.
329 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
330 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
331 unsigned int r_type
, const Sized_symbol
<size
>*,
332 const Symbol_value
<size
>*,
334 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
338 relax_call(Target_sparc
<size
, big_endian
>* target
,
340 const elfcpp::Rela
<size
, big_endian
>& rela
,
341 section_size_type view_size
);
343 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
346 // If we hit a reloc at this view address, adjust it back by 4 bytes.
347 unsigned char *reloc_adjust_addr_
;
350 // A class which returns the size required for a relocation type,
351 // used while scanning relocs during a relocatable link.
352 class Relocatable_size_for_reloc
356 get_size_for_reloc(unsigned int, Relobj
*);
359 // Get the GOT section, creating it if necessary.
360 Output_data_got
<size
, big_endian
>*
361 got_section(Symbol_table
*, Layout
*);
363 // Create the PLT section.
365 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
367 // Create a PLT entry for a global symbol.
369 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
371 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
373 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
374 Sized_relobj_file
<size
, big_endian
>* relobj
,
375 unsigned int local_sym_index
);
377 // Create a GOT entry for the TLS module index.
379 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
380 Sized_relobj_file
<size
, big_endian
>* object
);
382 // Return the gsym for "__tls_get_addr". Cache if not already
385 tls_get_addr_sym(Symbol_table
* symtab
)
387 if (!this->tls_get_addr_sym_
)
388 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
389 gold_assert(this->tls_get_addr_sym_
);
390 return this->tls_get_addr_sym_
;
393 // Get the PLT section.
394 Output_data_plt_sparc
<size
, big_endian
>*
397 gold_assert(this->plt_
!= NULL
);
401 // Get the dynamic reloc section, creating it if necessary.
403 rela_dyn_section(Layout
*);
405 // Get the section to use for IFUNC relocations.
407 rela_ifunc_section(Layout
*);
409 // Copy a relocation against a global symbol.
411 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
412 Sized_relobj_file
<size
, big_endian
>* object
,
413 unsigned int shndx
, Output_section
* output_section
,
414 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
416 this->copy_relocs_
.copy_reloc(symtab
, layout
,
417 symtab
->get_sized_symbol
<size
>(sym
),
418 object
, shndx
, output_section
,
419 reloc
, this->rela_dyn_section(layout
));
422 // Information about this specific target which we pass to the
423 // general Target structure.
424 static Target::Target_info sparc_info
;
426 // The types of GOT entries needed for this platform.
427 // These values are exposed to the ABI in an incremental link.
428 // Do not renumber existing values without changing the version
429 // number of the .gnu_incremental_inputs section.
432 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
433 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
434 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
438 Output_data_got
<size
, big_endian
>* got_
;
440 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
441 // The dynamic reloc section.
442 Reloc_section
* rela_dyn_
;
443 // The section to use for IFUNC relocs.
444 Reloc_section
* rela_ifunc_
;
445 // Relocs saved to avoid a COPY reloc.
446 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
447 // Space for variables copied with a COPY reloc.
448 Output_data_space
* dynbss_
;
449 // Offset of the GOT entry for the TLS module index;
450 unsigned int got_mod_index_offset_
;
451 // Cached pointer to __tls_get_addr symbol
452 Symbol
* tls_get_addr_sym_
;
453 // Accumulated elf machine type
454 elfcpp::Elf_Half elf_machine_
;
455 // Accumulated elf header flags
456 elfcpp::Elf_Word elf_flags_
;
457 // Whether elf_flags_ has been set for the first time yet
462 Target::Target_info Target_sparc
<32, true>::sparc_info
=
465 true, // is_big_endian
466 elfcpp::EM_SPARC
, // machine_code
467 false, // has_make_symbol
468 false, // has_resolve
469 false, // has_code_fill
470 true, // is_default_stack_executable
471 false, // can_icf_inline_merge_sections
473 "/usr/lib/ld.so.1", // dynamic_linker
474 0x00010000, // default_text_segment_address
475 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
476 8 * 1024, // common_pagesize (overridable by -z common-page-size)
477 false, // isolate_execinstr
479 elfcpp::SHN_UNDEF
, // small_common_shndx
480 elfcpp::SHN_UNDEF
, // large_common_shndx
481 0, // small_common_section_flags
482 0, // large_common_section_flags
483 NULL
, // attributes_section
484 NULL
// attributes_vendor
488 Target::Target_info Target_sparc
<64, true>::sparc_info
=
491 true, // is_big_endian
492 elfcpp::EM_SPARCV9
, // machine_code
493 false, // has_make_symbol
494 false, // has_resolve
495 false, // has_code_fill
496 true, // is_default_stack_executable
497 false, // can_icf_inline_merge_sections
499 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
500 0x100000, // default_text_segment_address
501 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
502 8 * 1024, // common_pagesize (overridable by -z common-page-size)
503 false, // isolate_execinstr
505 elfcpp::SHN_UNDEF
, // small_common_shndx
506 elfcpp::SHN_UNDEF
, // large_common_shndx
507 0, // small_common_section_flags
508 0, // large_common_section_flags
509 NULL
, // attributes_section
510 NULL
// attributes_vendor
513 // We have to take care here, even when operating in little-endian
514 // mode, sparc instructions are still big endian.
515 template<int size
, bool big_endian
>
516 class Sparc_relocate_functions
519 // Do a simple relocation with the addend in the relocation.
520 template<int valsize
>
522 rela(unsigned char* view
,
523 unsigned int right_shift
,
524 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
525 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
526 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
528 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
529 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
530 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
531 Valtype reloc
= ((value
+ addend
) >> right_shift
);
536 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
539 // Do a simple relocation using a symbol value with the addend in
541 template<int valsize
>
543 rela(unsigned char* view
,
544 unsigned int right_shift
,
545 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
546 const Sized_relobj_file
<size
, big_endian
>* object
,
547 const Symbol_value
<size
>* psymval
,
548 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
550 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
551 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
552 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
553 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
558 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
561 // Do a simple relocation using a symbol value with the addend in
562 // the relocation, unaligned.
563 template<int valsize
>
565 rela_ua(unsigned char* view
,
566 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
567 const Sized_relobj_file
<size
, big_endian
>* object
,
568 const Symbol_value
<size
>* psymval
,
569 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
571 typedef typename
elfcpp::Swap_unaligned
<valsize
,
572 big_endian
>::Valtype Valtype
;
573 unsigned char* wv
= view
;
574 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
575 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
580 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
583 // Do a simple PC relative relocation with a Symbol_value with the
584 // addend in the relocation.
585 template<int valsize
>
587 pcrela(unsigned char* view
,
588 unsigned int right_shift
,
589 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
590 const Sized_relobj_file
<size
, big_endian
>* object
,
591 const Symbol_value
<size
>* psymval
,
592 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
593 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
595 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
596 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
597 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
598 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
604 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
607 template<int valsize
>
609 pcrela_unaligned(unsigned char* view
,
610 const Sized_relobj_file
<size
, big_endian
>* object
,
611 const Symbol_value
<size
>* psymval
,
612 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
613 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
615 typedef typename
elfcpp::Swap_unaligned
<valsize
,
616 big_endian
>::Valtype Valtype
;
617 unsigned char* wv
= view
;
618 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
620 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
623 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
624 typedef Sparc_relocate_functions
<size
, true> This_insn
;
627 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
629 wdisp30(unsigned char* view
,
630 const Sized_relobj_file
<size
, big_endian
>* object
,
631 const Symbol_value
<size
>* psymval
,
632 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
633 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
635 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
636 psymval
, addend
, address
);
639 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
641 wdisp22(unsigned char* view
,
642 const Sized_relobj_file
<size
, big_endian
>* object
,
643 const Symbol_value
<size
>* psymval
,
644 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
645 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
647 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
648 psymval
, addend
, address
);
651 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
653 wdisp19(unsigned char* view
,
654 const Sized_relobj_file
<size
, big_endian
>* object
,
655 const Symbol_value
<size
>* psymval
,
656 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
657 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
659 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
660 psymval
, addend
, address
);
663 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
665 wdisp16(unsigned char* view
,
666 const Sized_relobj_file
<size
, big_endian
>* object
,
667 const Symbol_value
<size
>* psymval
,
668 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
669 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
671 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
672 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
673 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
674 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
677 // The relocation value is split between the low 14 bits,
679 val
&= ~((0x3 << 20) | 0x3fff);
680 reloc
= (((reloc
& 0xc000) << (20 - 14))
681 | (reloc
& 0x3ffff));
683 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
686 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
688 wdisp10(unsigned char* view
,
689 const Sized_relobj_file
<size
, big_endian
>* object
,
690 const Symbol_value
<size
>* psymval
,
691 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
694 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
695 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
696 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
697 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
700 // The relocation value is split between the low bits 5-12,
701 // and high bits 19-20.
702 val
&= ~((0x3 << 19) | (0xff << 5));
703 reloc
= (((reloc
& 0x300) << (19 - 8))
704 | ((reloc
& 0xff) << (5 - 0)));
706 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
709 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
711 pc22(unsigned char* view
,
712 const Sized_relobj_file
<size
, big_endian
>* object
,
713 const Symbol_value
<size
>* psymval
,
714 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
715 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
717 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
718 psymval
, addend
, address
);
721 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
723 pc10(unsigned char* view
,
724 const Sized_relobj_file
<size
, big_endian
>* object
,
725 const Symbol_value
<size
>* psymval
,
726 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
727 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
729 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
730 psymval
, addend
, address
);
733 // R_SPARC_HI22: (Symbol + Addend) >> 10
735 hi22(unsigned char* view
,
736 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
737 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
739 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
742 // R_SPARC_HI22: (Symbol + Addend) >> 10
744 hi22(unsigned char* view
,
745 const Sized_relobj_file
<size
, big_endian
>* object
,
746 const Symbol_value
<size
>* psymval
,
747 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
749 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
752 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
754 pcplt22(unsigned char* view
,
755 const Sized_relobj_file
<size
, big_endian
>* object
,
756 const Symbol_value
<size
>* psymval
,
757 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
758 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
760 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
761 psymval
, addend
, address
);
764 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
766 lo10(unsigned char* view
,
767 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
768 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
770 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
773 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
775 lo10(unsigned char* view
,
776 const Sized_relobj_file
<size
, big_endian
>* object
,
777 const Symbol_value
<size
>* psymval
,
778 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
780 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
783 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
785 lo10(unsigned char* view
,
786 const Sized_relobj_file
<size
, big_endian
>* object
,
787 const Symbol_value
<size
>* psymval
,
788 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
789 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
791 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
792 psymval
, addend
, address
);
795 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
797 olo10(unsigned char* view
,
798 const Sized_relobj_file
<size
, big_endian
>* object
,
799 const Symbol_value
<size
>* psymval
,
800 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
801 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
803 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
804 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
805 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
806 Valtype reloc
= psymval
->value(object
, addend
);
813 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
816 // R_SPARC_22: (Symbol + Addend)
818 rela32_22(unsigned char* view
,
819 const Sized_relobj_file
<size
, big_endian
>* object
,
820 const Symbol_value
<size
>* psymval
,
821 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
823 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
826 // R_SPARC_13: (Symbol + Addend)
828 rela32_13(unsigned char* view
,
829 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
830 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
832 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
835 // R_SPARC_13: (Symbol + Addend)
837 rela32_13(unsigned char* view
,
838 const Sized_relobj_file
<size
, big_endian
>* object
,
839 const Symbol_value
<size
>* psymval
,
840 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
842 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
845 // R_SPARC_UA16: (Symbol + Addend)
847 ua16(unsigned char* view
,
848 const Sized_relobj_file
<size
, big_endian
>* object
,
849 const Symbol_value
<size
>* psymval
,
850 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
852 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
855 // R_SPARC_UA32: (Symbol + Addend)
857 ua32(unsigned char* view
,
858 const Sized_relobj_file
<size
, big_endian
>* object
,
859 const Symbol_value
<size
>* psymval
,
860 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
862 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
865 // R_SPARC_UA64: (Symbol + Addend)
867 ua64(unsigned char* view
,
868 const Sized_relobj_file
<size
, big_endian
>* object
,
869 const Symbol_value
<size
>* psymval
,
870 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
872 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
873 object
, psymval
, addend
);
876 // R_SPARC_DISP8: (Symbol + Addend - Address)
878 disp8(unsigned char* view
,
879 const Sized_relobj_file
<size
, big_endian
>* object
,
880 const Symbol_value
<size
>* psymval
,
881 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
882 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
884 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
888 // R_SPARC_DISP16: (Symbol + Addend - Address)
890 disp16(unsigned char* view
,
891 const Sized_relobj_file
<size
, big_endian
>* object
,
892 const Symbol_value
<size
>* psymval
,
893 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
894 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
896 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
900 // R_SPARC_DISP32: (Symbol + Addend - Address)
902 disp32(unsigned char* view
,
903 const Sized_relobj_file
<size
, big_endian
>* object
,
904 const Symbol_value
<size
>* psymval
,
905 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
906 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
908 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
912 // R_SPARC_DISP64: (Symbol + Addend - Address)
914 disp64(unsigned char* view
,
915 const Sized_relobj_file
<size
, big_endian
>* object
,
916 const Symbol_value
<size
>* psymval
,
917 elfcpp::Elf_Xword addend
,
918 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
920 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
924 // R_SPARC_H34: (Symbol + Addend) >> 12
926 h34(unsigned char* view
,
927 const Sized_relobj_file
<size
, big_endian
>* object
,
928 const Symbol_value
<size
>* psymval
,
929 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
931 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
934 // R_SPARC_H44: (Symbol + Addend) >> 22
936 h44(unsigned char* view
,
937 const Sized_relobj_file
<size
, big_endian
>* object
,
938 const Symbol_value
<size
>* psymval
,
939 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
941 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
944 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
946 m44(unsigned char* view
,
947 const Sized_relobj_file
<size
, big_endian
>* object
,
948 const Symbol_value
<size
>* psymval
,
949 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
951 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
954 // R_SPARC_L44: (Symbol + Addend) & 0xfff
956 l44(unsigned char* view
,
957 const Sized_relobj_file
<size
, big_endian
>* object
,
958 const Symbol_value
<size
>* psymval
,
959 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
961 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
964 // R_SPARC_HH22: (Symbol + Addend) >> 42
966 hh22(unsigned char* view
,
967 const Sized_relobj_file
<size
, big_endian
>* object
,
968 const Symbol_value
<size
>* psymval
,
969 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
971 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
974 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
976 pc_hh22(unsigned char* view
,
977 const Sized_relobj_file
<size
, big_endian
>* object
,
978 const Symbol_value
<size
>* psymval
,
979 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
980 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
982 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
983 psymval
, addend
, address
);
986 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
988 hm10(unsigned char* view
,
989 const Sized_relobj_file
<size
, big_endian
>* object
,
990 const Symbol_value
<size
>* psymval
,
991 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
993 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
996 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
998 pc_hm10(unsigned char* view
,
999 const Sized_relobj_file
<size
, big_endian
>* object
,
1000 const Symbol_value
<size
>* psymval
,
1001 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
1002 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
1004 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
1005 psymval
, addend
, address
);
1008 // R_SPARC_11: (Symbol + Addend)
1010 rela32_11(unsigned char* view
,
1011 const Sized_relobj_file
<size
, big_endian
>* object
,
1012 const Symbol_value
<size
>* psymval
,
1013 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1015 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1018 // R_SPARC_10: (Symbol + Addend)
1020 rela32_10(unsigned char* view
,
1021 const Sized_relobj_file
<size
, big_endian
>* object
,
1022 const Symbol_value
<size
>* psymval
,
1023 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1025 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
1028 // R_SPARC_7: (Symbol + Addend)
1030 rela32_7(unsigned char* view
,
1031 const Sized_relobj_file
<size
, big_endian
>* object
,
1032 const Symbol_value
<size
>* psymval
,
1033 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1035 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1038 // R_SPARC_6: (Symbol + Addend)
1040 rela32_6(unsigned char* view
,
1041 const Sized_relobj_file
<size
, big_endian
>* object
,
1042 const Symbol_value
<size
>* psymval
,
1043 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1045 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1048 // R_SPARC_5: (Symbol + Addend)
1050 rela32_5(unsigned char* view
,
1051 const Sized_relobj_file
<size
, big_endian
>* object
,
1052 const Symbol_value
<size
>* psymval
,
1053 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1055 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1058 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1060 ldo_hix22(unsigned char* view
,
1061 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1062 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1064 This_insn::hi22(view
, value
, addend
);
1067 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1069 ldo_lox10(unsigned char* view
,
1070 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1071 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1073 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1074 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1075 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1076 Valtype reloc
= (value
+ addend
);
1081 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1084 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1086 hix22(unsigned char* view
,
1087 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1088 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1090 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1091 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1092 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1093 Valtype reloc
= (value
+ addend
);
1097 reloc
^= ~(Valtype
)0;
1102 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1105 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1107 gdop_hix22(unsigned char* view
,
1108 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1109 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1111 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1112 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1113 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1114 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1119 reloc
^= ~static_cast<int32_t>(0);
1124 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1127 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1129 hix22(unsigned char* view
,
1130 const Sized_relobj_file
<size
, big_endian
>* object
,
1131 const Symbol_value
<size
>* psymval
,
1132 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1134 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1135 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1136 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1137 Valtype reloc
= psymval
->value(object
, addend
);
1141 reloc
^= ~(Valtype
)0;
1146 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1150 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1152 lox10(unsigned char* view
,
1153 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1154 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1156 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1157 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1158 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1159 Valtype reloc
= (value
+ addend
);
1165 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1168 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1170 gdop_lox10(unsigned char* view
,
1171 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1172 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1174 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1175 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1176 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1177 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1180 reloc
= (reloc
& 0x3ff) | 0x1c00;
1182 reloc
= (reloc
& 0x3ff);
1185 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1188 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1190 lox10(unsigned char* view
,
1191 const Sized_relobj_file
<size
, big_endian
>* object
,
1192 const Symbol_value
<size
>* psymval
,
1193 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1195 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1196 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1197 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1198 Valtype reloc
= psymval
->value(object
, addend
);
1204 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1208 // Get the GOT section, creating it if necessary.
1210 template<int size
, bool big_endian
>
1211 Output_data_got
<size
, big_endian
>*
1212 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1215 if (this->got_
== NULL
)
1217 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1219 this->got_
= new Output_data_got
<size
, big_endian
>();
1221 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1223 | elfcpp::SHF_WRITE
),
1224 this->got_
, ORDER_RELRO
, true);
1226 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1227 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1228 Symbol_table::PREDEFINED
,
1230 0, 0, elfcpp::STT_OBJECT
,
1232 elfcpp::STV_HIDDEN
, 0,
1239 // Get the dynamic reloc section, creating it if necessary.
1241 template<int size
, bool big_endian
>
1242 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1243 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1245 if (this->rela_dyn_
== NULL
)
1247 gold_assert(layout
!= NULL
);
1248 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1249 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1250 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1251 ORDER_DYNAMIC_RELOCS
, false);
1253 return this->rela_dyn_
;
1256 // Get the section to use for IFUNC relocs, creating it if
1257 // necessary. These go in .rela.dyn, but only after all other dynamic
1258 // relocations. They need to follow the other dynamic relocations so
1259 // that they can refer to global variables initialized by those
1262 template<int size
, bool big_endian
>
1263 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1264 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1266 if (this->rela_ifunc_
== NULL
)
1268 // Make sure we have already created the dynamic reloc section.
1269 this->rela_dyn_section(layout
);
1270 this->rela_ifunc_
= new Reloc_section(false);
1271 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1272 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1273 ORDER_DYNAMIC_RELOCS
, false);
1274 gold_assert(this->rela_dyn_
->output_section()
1275 == this->rela_ifunc_
->output_section());
1277 return this->rela_ifunc_
;
1280 // A class to handle the PLT data.
1282 template<int size
, bool big_endian
>
1283 class Output_data_plt_sparc
: public Output_section_data
1286 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1287 size
, big_endian
> Reloc_section
;
1289 Output_data_plt_sparc(Layout
*);
1291 // Add an entry to the PLT.
1292 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1294 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1296 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1297 Sized_relobj_file
<size
, big_endian
>* relobj
,
1298 unsigned int local_sym_index
);
1300 // Return the .rela.plt section data.
1301 const Reloc_section
* rel_plt() const
1306 // Return where the IFUNC relocations should go.
1308 rela_ifunc(Symbol_table
*, Layout
*);
1311 emit_pending_ifunc_relocs();
1313 // Return whether we created a section for IFUNC relocations.
1315 has_ifunc_section() const
1316 { return this->ifunc_rel_
!= NULL
; }
1318 // Return the number of PLT entries.
1321 { return this->count_
+ this->ifunc_count_
; }
1323 // Return the offset of the first non-reserved PLT entry.
1325 first_plt_entry_offset()
1326 { return 4 * base_plt_entry_size
; }
1328 // Return the size of a PLT entry.
1330 get_plt_entry_size()
1331 { return base_plt_entry_size
; }
1333 // Return the PLT address to use for a global symbol.
1335 address_for_global(const Symbol
*);
1337 // Return the PLT address to use for a local symbol.
1339 address_for_local(const Relobj
*, unsigned int symndx
);
1342 void do_adjust_output_section(Output_section
* os
);
1344 // Write to a map file.
1346 do_print_to_mapfile(Mapfile
* mapfile
) const
1347 { mapfile
->print_output_data(this, _("** PLT")); }
1350 // The size of an entry in the PLT.
1351 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1353 static const unsigned int plt_entries_per_block
= 160;
1354 static const unsigned int plt_insn_chunk_size
= 24;
1355 static const unsigned int plt_pointer_chunk_size
= 8;
1356 static const unsigned int plt_block_size
=
1357 (plt_entries_per_block
1358 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1361 plt_index_to_offset(unsigned int index
)
1363 section_offset_type offset
;
1365 if (size
== 32 || index
< 32768)
1366 offset
= index
* base_plt_entry_size
;
1369 unsigned int ext_index
= index
- 32768;
1371 offset
= (32768 * base_plt_entry_size
)
1372 + ((ext_index
/ plt_entries_per_block
)
1374 + ((ext_index
% plt_entries_per_block
)
1375 * plt_insn_chunk_size
);
1380 // Set the final size.
1382 set_final_data_size()
1384 unsigned int full_count
= this->entry_count() + 4;
1385 unsigned int extra
= (size
== 32 ? 4 : 0);
1386 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1388 return this->set_data_size(sz
);
1391 // Write out the PLT data.
1393 do_write(Output_file
*);
1399 unsigned int plt_index
;
1405 Sized_relobj_file
<size
, big_endian
>* object
;
1406 unsigned int local_sym_index
;
1407 unsigned int plt_index
;
1410 // The reloc section.
1411 Reloc_section
* rel_
;
1412 // The IFUNC relocations, if necessary. These must follow the
1413 // regular relocations.
1414 Reloc_section
* ifunc_rel_
;
1415 // The number of PLT entries.
1416 unsigned int count_
;
1417 // The number of PLT entries for IFUNC symbols.
1418 unsigned int ifunc_count_
;
1419 // Global STT_GNU_IFUNC symbols.
1420 std::vector
<Global_ifunc
> global_ifuncs_
;
1421 // Local STT_GNU_IFUNC symbols.
1422 std::vector
<Local_ifunc
> local_ifuncs_
;
1425 // Define the constants as required by C++ standard.
1427 template<int size
, bool big_endian
>
1428 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1430 template<int size
, bool big_endian
>
1432 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1434 template<int size
, bool big_endian
>
1435 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1437 template<int size
, bool big_endian
>
1439 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1441 template<int size
, bool big_endian
>
1442 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1444 // Create the PLT section. The ordinary .got section is an argument,
1445 // since we need to refer to the start.
1447 template<int size
, bool big_endian
>
1448 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1449 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1450 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1452 this->rel_
= new Reloc_section(false);
1453 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1454 elfcpp::SHF_ALLOC
, this->rel_
,
1455 ORDER_DYNAMIC_PLT_RELOCS
, false);
1458 template<int size
, bool big_endian
>
1460 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1465 // Add an entry to the PLT.
1467 template<int size
, bool big_endian
>
1469 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1473 gold_assert(!gsym
->has_plt_offset());
1475 section_offset_type plt_offset
;
1478 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1479 && gsym
->can_use_relative_reloc(false))
1481 index
= this->ifunc_count_
;
1482 plt_offset
= plt_index_to_offset(index
);
1483 gsym
->set_plt_offset(plt_offset
);
1484 ++this->ifunc_count_
;
1485 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1487 struct Global_ifunc gi
;
1490 gi
.plt_index
= index
;
1491 this->global_ifuncs_
.push_back(gi
);
1495 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1496 gsym
->set_plt_offset(plt_offset
);
1498 gsym
->set_needs_dynsym_entry();
1499 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1503 // Note that we don't need to save the symbol. The contents of the
1504 // PLT are independent of which symbols are used. The symbols only
1505 // appear in the relocations.
1508 template<int size
, bool big_endian
>
1510 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1511 Symbol_table
* symtab
,
1513 Sized_relobj_file
<size
, big_endian
>* relobj
,
1514 unsigned int local_sym_index
)
1516 unsigned int index
= this->ifunc_count_
;
1517 section_offset_type plt_offset
;
1519 plt_offset
= plt_index_to_offset(index
);
1520 ++this->ifunc_count_
;
1522 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1524 struct Local_ifunc li
;
1527 li
.local_sym_index
= local_sym_index
;
1528 li
.plt_index
= index
;
1529 this->local_ifuncs_
.push_back(li
);
1534 // Emit any pending IFUNC plt relocations.
1536 template<int size
, bool big_endian
>
1538 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1540 // Emit any pending IFUNC relocs.
1541 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1542 this->global_ifuncs_
.begin();
1543 p
!= this->global_ifuncs_
.end();
1546 section_offset_type plt_offset
;
1549 index
= this->count_
+ p
->plt_index
+ 4;
1550 plt_offset
= this->plt_index_to_offset(index
);
1551 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1552 this, plt_offset
, 0);
1555 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1556 this->local_ifuncs_
.begin();
1557 p
!= this->local_ifuncs_
.end();
1560 section_offset_type plt_offset
;
1563 index
= this->count_
+ p
->plt_index
+ 4;
1564 plt_offset
= this->plt_index_to_offset(index
);
1565 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1566 elfcpp::R_SPARC_JMP_IREL
,
1567 this, plt_offset
, 0);
1571 // Return where the IFUNC relocations should go in the PLT. These
1572 // follow the non-IFUNC relocations.
1574 template<int size
, bool big_endian
>
1575 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1576 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1577 Symbol_table
* symtab
,
1580 if (this->ifunc_rel_
== NULL
)
1582 this->ifunc_rel_
= new Reloc_section(false);
1583 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1584 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1585 ORDER_DYNAMIC_PLT_RELOCS
, false);
1586 gold_assert(this->ifunc_rel_
->output_section()
1587 == this->rel_
->output_section());
1589 if (parameters
->doing_static_link())
1591 // A statically linked executable will only have a .rel.plt
1592 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1593 // relocs for STT_GNU_IFUNC symbols. The library will use
1594 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1595 // at program startup time.
1596 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1597 Symbol_table::PREDEFINED
,
1598 this->ifunc_rel_
, 0, 0,
1599 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1600 elfcpp::STV_HIDDEN
, 0, false, true);
1601 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1602 Symbol_table::PREDEFINED
,
1603 this->ifunc_rel_
, 0, 0,
1604 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1605 elfcpp::STV_HIDDEN
, 0, true, true);
1608 return this->ifunc_rel_
;
1611 // Return the PLT address to use for a global symbol.
1613 template<int size
, bool big_endian
>
1615 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1617 uint64_t offset
= 0;
1618 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1619 && gsym
->can_use_relative_reloc(false))
1620 offset
= plt_index_to_offset(this->count_
+ 4);
1621 return this->address() + offset
;
1624 // Return the PLT address to use for a local symbol. These are always
1625 // IRELATIVE relocs.
1627 template<int size
, bool big_endian
>
1629 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1633 return this->address() + plt_index_to_offset(this->count_
+ 4);
1636 static const unsigned int sparc_nop
= 0x01000000;
1637 static const unsigned int sparc_sethi_g1
= 0x03000000;
1638 static const unsigned int sparc_branch_always
= 0x30800000;
1639 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1640 static const unsigned int sparc_mov
= 0x80100000;
1641 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1642 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1643 static const unsigned int sparc_call_plus_8
= 0x40000002;
1644 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1645 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1646 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1648 // Write out the PLT.
1650 template<int size
, bool big_endian
>
1652 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1654 const off_t offset
= this->offset();
1655 const section_size_type oview_size
=
1656 convert_to_section_size_type(this->data_size());
1657 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1658 unsigned char* pov
= oview
;
1660 memset(pov
, 0, base_plt_entry_size
* 4);
1661 pov
+= this->first_plt_entry_offset();
1663 unsigned int plt_offset
= base_plt_entry_size
* 4;
1664 const unsigned int count
= this->entry_count();
1670 limit
= (count
> 32768 ? 32768 : count
);
1672 for (unsigned int i
= 0; i
< limit
; ++i
)
1674 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1675 sparc_sethi_g1
+ plt_offset
);
1676 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1677 sparc_branch_always_pt
+
1678 (((base_plt_entry_size
-
1679 (plt_offset
+ 4)) >> 2) &
1681 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1682 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1683 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1684 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1685 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1686 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1688 pov
+= base_plt_entry_size
;
1689 plt_offset
+= base_plt_entry_size
;
1694 unsigned int ext_cnt
= count
- 32768;
1695 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1697 for (unsigned int i
= 0; i
< blks
; ++i
)
1699 unsigned int data_off
= (plt_entries_per_block
1700 * plt_insn_chunk_size
) - 4;
1702 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1704 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1706 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1708 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1710 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1711 sparc_ldx_o7_imm_g1
+
1712 (data_off
& 0x1fff));
1713 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1714 sparc_jmpl_o7_g1_g1
);
1715 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1718 elfcpp::Swap
<64, big_endian
>::writeval(
1719 pov
+ 0x4 + data_off
,
1720 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1722 pov
+= plt_insn_chunk_size
;
1727 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1728 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1730 unsigned int data_off
= (sub_blk_cnt
1731 * plt_insn_chunk_size
) - 4;
1733 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1735 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1737 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1739 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1741 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1742 sparc_ldx_o7_imm_g1
+
1743 (data_off
& 0x1fff));
1744 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1745 sparc_jmpl_o7_g1_g1
);
1746 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1749 elfcpp::Swap
<64, big_endian
>::writeval(
1750 pov
+ 0x4 + data_off
,
1751 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1753 pov
+= plt_insn_chunk_size
;
1761 for (unsigned int i
= 0; i
< count
; ++i
)
1763 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1764 sparc_sethi_g1
+ plt_offset
);
1765 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1766 sparc_branch_always
+
1767 (((- (plt_offset
+ 4)) >> 2) &
1769 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1771 pov
+= base_plt_entry_size
;
1772 plt_offset
+= base_plt_entry_size
;
1775 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1779 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1781 of
->write_output_view(offset
, oview_size
, oview
);
1784 // Create the PLT section.
1786 template<int size
, bool big_endian
>
1788 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1791 // Create the GOT sections first.
1792 this->got_section(symtab
, layout
);
1794 // Ensure that .rela.dyn always appears before .rela.plt This is
1795 // necessary due to how, on Sparc and some other targets, .rela.dyn
1796 // needs to include .rela.plt in it's range.
1797 this->rela_dyn_section(layout
);
1799 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1800 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1802 | elfcpp::SHF_EXECINSTR
1803 | elfcpp::SHF_WRITE
),
1804 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1806 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1807 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1808 Symbol_table::PREDEFINED
,
1810 0, 0, elfcpp::STT_OBJECT
,
1812 elfcpp::STV_HIDDEN
, 0,
1816 // Create a PLT entry for a global symbol.
1818 template<int size
, bool big_endian
>
1820 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1824 if (gsym
->has_plt_offset())
1827 if (this->plt_
== NULL
)
1828 this->make_plt_section(symtab
, layout
);
1830 this->plt_
->add_entry(symtab
, layout
, gsym
);
1833 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1835 template<int size
, bool big_endian
>
1837 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1838 Symbol_table
* symtab
,
1840 Sized_relobj_file
<size
, big_endian
>* relobj
,
1841 unsigned int local_sym_index
)
1843 if (relobj
->local_has_plt_offset(local_sym_index
))
1845 if (this->plt_
== NULL
)
1846 this->make_plt_section(symtab
, layout
);
1847 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1850 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1853 // Return the number of entries in the PLT.
1855 template<int size
, bool big_endian
>
1857 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1859 if (this->plt_
== NULL
)
1861 return this->plt_
->entry_count();
1864 // Return the offset of the first non-reserved PLT entry.
1866 template<int size
, bool big_endian
>
1868 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1870 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1873 // Return the size of each PLT entry.
1875 template<int size
, bool big_endian
>
1877 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1879 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1882 // Create a GOT entry for the TLS module index.
1884 template<int size
, bool big_endian
>
1886 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1887 Symbol_table
* symtab
,
1889 Sized_relobj_file
<size
, big_endian
>* object
)
1891 if (this->got_mod_index_offset_
== -1U)
1893 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1894 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1895 Output_data_got
<size
, big_endian
>* got
;
1896 unsigned int got_offset
;
1898 got
= this->got_section(symtab
, layout
);
1899 got_offset
= got
->add_constant(0);
1900 rela_dyn
->add_local(object
, 0,
1902 elfcpp::R_SPARC_TLS_DTPMOD64
:
1903 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1905 got
->add_constant(0);
1906 this->got_mod_index_offset_
= got_offset
;
1908 return this->got_mod_index_offset_
;
1911 // Optimize the TLS relocation type based on what we know about the
1912 // symbol. IS_FINAL is true if the final address of this symbol is
1913 // known at link time.
1915 static tls::Tls_optimization
1916 optimize_tls_reloc(bool is_final
, int r_type
)
1918 // If we are generating a shared library, then we can't do anything
1920 if (parameters
->options().shared())
1921 return tls::TLSOPT_NONE
;
1925 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1926 case elfcpp::R_SPARC_TLS_GD_LO10
:
1927 case elfcpp::R_SPARC_TLS_GD_ADD
:
1928 case elfcpp::R_SPARC_TLS_GD_CALL
:
1929 // These are General-Dynamic which permits fully general TLS
1930 // access. Since we know that we are generating an executable,
1931 // we can convert this to Initial-Exec. If we also know that
1932 // this is a local symbol, we can further switch to Local-Exec.
1934 return tls::TLSOPT_TO_LE
;
1935 return tls::TLSOPT_TO_IE
;
1937 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1938 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1939 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1940 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1941 // This is Local-Dynamic, which refers to a local symbol in the
1942 // dynamic TLS block. Since we know that we generating an
1943 // executable, we can switch to Local-Exec.
1944 return tls::TLSOPT_TO_LE
;
1946 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1947 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1948 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1949 // Another type of Local-Dynamic relocation.
1950 return tls::TLSOPT_TO_LE
;
1952 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1953 case elfcpp::R_SPARC_TLS_IE_LO10
:
1954 case elfcpp::R_SPARC_TLS_IE_LD
:
1955 case elfcpp::R_SPARC_TLS_IE_LDX
:
1956 case elfcpp::R_SPARC_TLS_IE_ADD
:
1957 // These are Initial-Exec relocs which get the thread offset
1958 // from the GOT. If we know that we are linking against the
1959 // local symbol, we can switch to Local-Exec, which links the
1960 // thread offset into the instruction.
1962 return tls::TLSOPT_TO_LE
;
1963 return tls::TLSOPT_NONE
;
1965 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1966 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1967 // When we already have Local-Exec, there is nothing further we
1969 return tls::TLSOPT_NONE
;
1976 // Get the Reference_flags for a particular relocation.
1978 template<int size
, bool big_endian
>
1980 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1985 case elfcpp::R_SPARC_NONE
:
1986 case elfcpp::R_SPARC_REGISTER
:
1987 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1988 case elfcpp::R_SPARC_GNU_VTENTRY
:
1989 // No symbol reference.
1992 case elfcpp::R_SPARC_UA64
:
1993 case elfcpp::R_SPARC_64
:
1994 case elfcpp::R_SPARC_HIX22
:
1995 case elfcpp::R_SPARC_LOX10
:
1996 case elfcpp::R_SPARC_H34
:
1997 case elfcpp::R_SPARC_H44
:
1998 case elfcpp::R_SPARC_M44
:
1999 case elfcpp::R_SPARC_L44
:
2000 case elfcpp::R_SPARC_HH22
:
2001 case elfcpp::R_SPARC_HM10
:
2002 case elfcpp::R_SPARC_LM22
:
2003 case elfcpp::R_SPARC_HI22
:
2004 case elfcpp::R_SPARC_LO10
:
2005 case elfcpp::R_SPARC_OLO10
:
2006 case elfcpp::R_SPARC_UA32
:
2007 case elfcpp::R_SPARC_32
:
2008 case elfcpp::R_SPARC_UA16
:
2009 case elfcpp::R_SPARC_16
:
2010 case elfcpp::R_SPARC_11
:
2011 case elfcpp::R_SPARC_10
:
2012 case elfcpp::R_SPARC_8
:
2013 case elfcpp::R_SPARC_7
:
2014 case elfcpp::R_SPARC_6
:
2015 case elfcpp::R_SPARC_5
:
2016 return Symbol::ABSOLUTE_REF
;
2018 case elfcpp::R_SPARC_DISP8
:
2019 case elfcpp::R_SPARC_DISP16
:
2020 case elfcpp::R_SPARC_DISP32
:
2021 case elfcpp::R_SPARC_DISP64
:
2022 case elfcpp::R_SPARC_PC_HH22
:
2023 case elfcpp::R_SPARC_PC_HM10
:
2024 case elfcpp::R_SPARC_PC_LM22
:
2025 case elfcpp::R_SPARC_PC10
:
2026 case elfcpp::R_SPARC_PC22
:
2027 case elfcpp::R_SPARC_WDISP30
:
2028 case elfcpp::R_SPARC_WDISP22
:
2029 case elfcpp::R_SPARC_WDISP19
:
2030 case elfcpp::R_SPARC_WDISP16
:
2031 case elfcpp::R_SPARC_WDISP10
:
2032 return Symbol::RELATIVE_REF
;
2034 case elfcpp::R_SPARC_PLT64
:
2035 case elfcpp::R_SPARC_PLT32
:
2036 case elfcpp::R_SPARC_HIPLT22
:
2037 case elfcpp::R_SPARC_LOPLT10
:
2038 case elfcpp::R_SPARC_PCPLT10
:
2039 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2041 case elfcpp::R_SPARC_PCPLT32
:
2042 case elfcpp::R_SPARC_PCPLT22
:
2043 case elfcpp::R_SPARC_WPLT30
:
2044 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2046 case elfcpp::R_SPARC_GOTDATA_OP
:
2047 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2048 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2049 case elfcpp::R_SPARC_GOT10
:
2050 case elfcpp::R_SPARC_GOT13
:
2051 case elfcpp::R_SPARC_GOT22
:
2053 return Symbol::ABSOLUTE_REF
;
2055 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2056 case elfcpp::R_SPARC_TLS_GD_LO10
:
2057 case elfcpp::R_SPARC_TLS_GD_ADD
:
2058 case elfcpp::R_SPARC_TLS_GD_CALL
:
2059 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2060 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2061 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2062 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2063 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2064 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2065 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2066 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2067 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2068 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2069 case elfcpp::R_SPARC_TLS_IE_LO10
:
2070 case elfcpp::R_SPARC_TLS_IE_LD
:
2071 case elfcpp::R_SPARC_TLS_IE_LDX
:
2072 case elfcpp::R_SPARC_TLS_IE_ADD
:
2073 return Symbol::TLS_REF
;
2075 case elfcpp::R_SPARC_COPY
:
2076 case elfcpp::R_SPARC_GLOB_DAT
:
2077 case elfcpp::R_SPARC_JMP_SLOT
:
2078 case elfcpp::R_SPARC_JMP_IREL
:
2079 case elfcpp::R_SPARC_RELATIVE
:
2080 case elfcpp::R_SPARC_IRELATIVE
:
2081 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2082 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2083 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2084 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2085 case elfcpp::R_SPARC_TLS_TPOFF64
:
2086 case elfcpp::R_SPARC_TLS_TPOFF32
:
2088 // Not expected. We will give an error later.
2093 // Generate a PLT entry slot for a call to __tls_get_addr
2094 template<int size
, bool big_endian
>
2096 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2098 Target_sparc
<size
, big_endian
>* target
)
2100 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2102 target
->make_plt_entry(symtab
, layout
, gsym
);
2105 // Report an unsupported relocation against a local symbol.
2107 template<int size
, bool big_endian
>
2109 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2110 Sized_relobj_file
<size
, big_endian
>* object
,
2111 unsigned int r_type
)
2113 gold_error(_("%s: unsupported reloc %u against local symbol"),
2114 object
->name().c_str(), r_type
);
2117 // We are about to emit a dynamic relocation of type R_TYPE. If the
2118 // dynamic linker does not support it, issue an error.
2120 template<int size
, bool big_endian
>
2122 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2124 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2130 // These are the relocation types supported by glibc for sparc 64-bit.
2131 case elfcpp::R_SPARC_RELATIVE
:
2132 case elfcpp::R_SPARC_IRELATIVE
:
2133 case elfcpp::R_SPARC_COPY
:
2134 case elfcpp::R_SPARC_64
:
2135 case elfcpp::R_SPARC_GLOB_DAT
:
2136 case elfcpp::R_SPARC_JMP_SLOT
:
2137 case elfcpp::R_SPARC_JMP_IREL
:
2138 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2139 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2140 case elfcpp::R_SPARC_TLS_TPOFF64
:
2141 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2142 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2143 case elfcpp::R_SPARC_8
:
2144 case elfcpp::R_SPARC_16
:
2145 case elfcpp::R_SPARC_DISP8
:
2146 case elfcpp::R_SPARC_DISP16
:
2147 case elfcpp::R_SPARC_DISP32
:
2148 case elfcpp::R_SPARC_WDISP30
:
2149 case elfcpp::R_SPARC_LO10
:
2150 case elfcpp::R_SPARC_HI22
:
2151 case elfcpp::R_SPARC_OLO10
:
2152 case elfcpp::R_SPARC_H34
:
2153 case elfcpp::R_SPARC_H44
:
2154 case elfcpp::R_SPARC_M44
:
2155 case elfcpp::R_SPARC_L44
:
2156 case elfcpp::R_SPARC_HH22
:
2157 case elfcpp::R_SPARC_HM10
:
2158 case elfcpp::R_SPARC_LM22
:
2159 case elfcpp::R_SPARC_UA16
:
2160 case elfcpp::R_SPARC_UA32
:
2161 case elfcpp::R_SPARC_UA64
:
2172 // These are the relocation types supported by glibc for sparc 32-bit.
2173 case elfcpp::R_SPARC_RELATIVE
:
2174 case elfcpp::R_SPARC_IRELATIVE
:
2175 case elfcpp::R_SPARC_COPY
:
2176 case elfcpp::R_SPARC_GLOB_DAT
:
2177 case elfcpp::R_SPARC_32
:
2178 case elfcpp::R_SPARC_JMP_SLOT
:
2179 case elfcpp::R_SPARC_JMP_IREL
:
2180 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2181 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2182 case elfcpp::R_SPARC_TLS_TPOFF32
:
2183 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2184 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2185 case elfcpp::R_SPARC_8
:
2186 case elfcpp::R_SPARC_16
:
2187 case elfcpp::R_SPARC_DISP8
:
2188 case elfcpp::R_SPARC_DISP16
:
2189 case elfcpp::R_SPARC_DISP32
:
2190 case elfcpp::R_SPARC_LO10
:
2191 case elfcpp::R_SPARC_WDISP30
:
2192 case elfcpp::R_SPARC_HI22
:
2193 case elfcpp::R_SPARC_UA16
:
2194 case elfcpp::R_SPARC_UA32
:
2202 // This prevents us from issuing more than one error per reloc
2203 // section. But we can still wind up issuing more than one
2204 // error per object file.
2205 if (this->issued_non_pic_error_
)
2207 gold_assert(parameters
->options().output_is_position_independent());
2208 object
->error(_("requires unsupported dynamic reloc; "
2209 "recompile with -fPIC"));
2210 this->issued_non_pic_error_
= true;
2214 // Return whether we need to make a PLT entry for a relocation of the
2215 // given type against a STT_GNU_IFUNC symbol.
2217 template<int size
, bool big_endian
>
2219 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2220 Sized_relobj_file
<size
, big_endian
>* object
,
2221 unsigned int r_type
)
2223 int flags
= Scan::get_reference_flags(r_type
);
2224 if (flags
& Symbol::TLS_REF
)
2225 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2226 object
->name().c_str(), r_type
);
2230 // Scan a relocation for a local symbol.
2232 template<int size
, bool big_endian
>
2234 Target_sparc
<size
, big_endian
>::Scan::local(
2235 Symbol_table
* symtab
,
2237 Target_sparc
<size
, big_endian
>* target
,
2238 Sized_relobj_file
<size
, big_endian
>* object
,
2239 unsigned int data_shndx
,
2240 Output_section
* output_section
,
2241 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2242 unsigned int r_type
,
2243 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2245 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2246 unsigned int orig_r_type
= r_type
;
2250 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2252 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2253 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2258 case elfcpp::R_SPARC_NONE
:
2259 case elfcpp::R_SPARC_REGISTER
:
2260 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2261 case elfcpp::R_SPARC_GNU_VTENTRY
:
2264 case elfcpp::R_SPARC_64
:
2265 case elfcpp::R_SPARC_32
:
2266 // If building a shared library (or a position-independent
2267 // executable), we need to create a dynamic relocation for
2268 // this location. The relocation applied at link time will
2269 // apply the link-time value, so we flag the location with
2270 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2271 // relocate it easily.
2272 if (parameters
->options().output_is_position_independent())
2274 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2275 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2276 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2277 output_section
, data_shndx
,
2278 reloc
.get_r_offset(),
2279 reloc
.get_r_addend(), is_ifunc
);
2283 case elfcpp::R_SPARC_HIX22
:
2284 case elfcpp::R_SPARC_LOX10
:
2285 case elfcpp::R_SPARC_H34
:
2286 case elfcpp::R_SPARC_H44
:
2287 case elfcpp::R_SPARC_M44
:
2288 case elfcpp::R_SPARC_L44
:
2289 case elfcpp::R_SPARC_HH22
:
2290 case elfcpp::R_SPARC_HM10
:
2291 case elfcpp::R_SPARC_LM22
:
2292 case elfcpp::R_SPARC_UA64
:
2293 case elfcpp::R_SPARC_UA32
:
2294 case elfcpp::R_SPARC_UA16
:
2295 case elfcpp::R_SPARC_HI22
:
2296 case elfcpp::R_SPARC_LO10
:
2297 case elfcpp::R_SPARC_OLO10
:
2298 case elfcpp::R_SPARC_16
:
2299 case elfcpp::R_SPARC_11
:
2300 case elfcpp::R_SPARC_10
:
2301 case elfcpp::R_SPARC_8
:
2302 case elfcpp::R_SPARC_7
:
2303 case elfcpp::R_SPARC_6
:
2304 case elfcpp::R_SPARC_5
:
2305 // If building a shared library (or a position-independent
2306 // executable), we need to create a dynamic relocation for
2308 if (parameters
->options().output_is_position_independent())
2310 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2311 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2313 check_non_pic(object
, r_type
);
2314 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2316 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2317 data_shndx
, reloc
.get_r_offset(),
2318 reloc
.get_r_addend());
2322 gold_assert(lsym
.get_st_value() == 0);
2323 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2324 output_section
, data_shndx
,
2325 reloc
.get_r_offset(),
2326 reloc
.get_r_addend());
2331 case elfcpp::R_SPARC_WDISP30
:
2332 case elfcpp::R_SPARC_WPLT30
:
2333 case elfcpp::R_SPARC_WDISP22
:
2334 case elfcpp::R_SPARC_WDISP19
:
2335 case elfcpp::R_SPARC_WDISP16
:
2336 case elfcpp::R_SPARC_WDISP10
:
2337 case elfcpp::R_SPARC_DISP8
:
2338 case elfcpp::R_SPARC_DISP16
:
2339 case elfcpp::R_SPARC_DISP32
:
2340 case elfcpp::R_SPARC_DISP64
:
2341 case elfcpp::R_SPARC_PC10
:
2342 case elfcpp::R_SPARC_PC22
:
2345 case elfcpp::R_SPARC_GOTDATA_OP
:
2346 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2347 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2348 // We will optimize this into a GOT relative relocation
2349 // and code transform the GOT load into an addition.
2352 case elfcpp::R_SPARC_GOT10
:
2353 case elfcpp::R_SPARC_GOT13
:
2354 case elfcpp::R_SPARC_GOT22
:
2356 // The symbol requires a GOT entry.
2357 Output_data_got
<size
, big_endian
>* got
;
2360 got
= target
->got_section(symtab
, layout
);
2361 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2363 // If we are generating a shared object, we need to add a
2364 // dynamic relocation for this symbol's GOT entry.
2365 if (parameters
->options().output_is_position_independent())
2367 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2369 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2370 unsigned int off
= got
->add_constant(0);
2371 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2372 rela_dyn
->add_local_relative(object
, r_sym
,
2373 elfcpp::R_SPARC_RELATIVE
,
2374 got
, off
, 0, is_ifunc
);
2378 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2382 // These are initial TLS relocs, which are expected when
2384 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2385 case elfcpp::R_SPARC_TLS_GD_LO10
:
2386 case elfcpp::R_SPARC_TLS_GD_ADD
:
2387 case elfcpp::R_SPARC_TLS_GD_CALL
:
2388 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2389 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2390 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2391 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2392 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2393 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2394 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2395 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2396 case elfcpp::R_SPARC_TLS_IE_LO10
:
2397 case elfcpp::R_SPARC_TLS_IE_LD
:
2398 case elfcpp::R_SPARC_TLS_IE_LDX
:
2399 case elfcpp::R_SPARC_TLS_IE_ADD
:
2400 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2401 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2403 bool output_is_shared
= parameters
->options().shared();
2404 const tls::Tls_optimization optimized_type
2405 = optimize_tls_reloc(!output_is_shared
, r_type
);
2408 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2409 case elfcpp::R_SPARC_TLS_GD_LO10
:
2410 case elfcpp::R_SPARC_TLS_GD_ADD
:
2411 case elfcpp::R_SPARC_TLS_GD_CALL
:
2412 if (optimized_type
== tls::TLSOPT_NONE
)
2414 // Create a pair of GOT entries for the module index and
2415 // dtv-relative offset.
2416 Output_data_got
<size
, big_endian
>* got
2417 = target
->got_section(symtab
, layout
);
2418 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2419 unsigned int shndx
= lsym
.get_st_shndx();
2421 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2423 object
->error(_("local symbol %u has bad shndx %u"),
2426 got
->add_local_pair_with_rel(object
, r_sym
,
2427 lsym
.get_st_shndx(),
2429 target
->rela_dyn_section(layout
),
2431 ? elfcpp::R_SPARC_TLS_DTPMOD64
2432 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2434 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2435 generate_tls_call(symtab
, layout
, target
);
2437 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2438 unsupported_reloc_local(object
, r_type
);
2441 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2442 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2443 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2444 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2445 if (optimized_type
== tls::TLSOPT_NONE
)
2447 // Create a GOT entry for the module index.
2448 target
->got_mod_index_entry(symtab
, layout
, object
);
2450 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2451 generate_tls_call(symtab
, layout
, target
);
2453 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2454 unsupported_reloc_local(object
, r_type
);
2457 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2458 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2459 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2462 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2463 case elfcpp::R_SPARC_TLS_IE_LO10
:
2464 case elfcpp::R_SPARC_TLS_IE_LD
:
2465 case elfcpp::R_SPARC_TLS_IE_LDX
:
2466 case elfcpp::R_SPARC_TLS_IE_ADD
:
2467 layout
->set_has_static_tls();
2468 if (optimized_type
== tls::TLSOPT_NONE
)
2470 // Create a GOT entry for the tp-relative offset.
2471 Output_data_got
<size
, big_endian
>* got
2472 = target
->got_section(symtab
, layout
);
2473 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2475 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2477 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2478 unsigned int off
= got
->add_constant(0);
2480 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2482 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2484 elfcpp::R_SPARC_TLS_TPOFF64
:
2485 elfcpp::R_SPARC_TLS_TPOFF32
),
2489 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2490 unsupported_reloc_local(object
, r_type
);
2493 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2494 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2495 layout
->set_has_static_tls();
2496 if (output_is_shared
)
2498 // We need to create a dynamic relocation.
2499 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2500 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2501 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2502 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2503 output_section
, data_shndx
,
2504 reloc
.get_r_offset(), 0);
2511 // These are relocations which should only be seen by the
2512 // dynamic linker, and should never be seen here.
2513 case elfcpp::R_SPARC_COPY
:
2514 case elfcpp::R_SPARC_GLOB_DAT
:
2515 case elfcpp::R_SPARC_JMP_SLOT
:
2516 case elfcpp::R_SPARC_JMP_IREL
:
2517 case elfcpp::R_SPARC_RELATIVE
:
2518 case elfcpp::R_SPARC_IRELATIVE
:
2519 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2520 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2521 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2522 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2523 case elfcpp::R_SPARC_TLS_TPOFF64
:
2524 case elfcpp::R_SPARC_TLS_TPOFF32
:
2525 gold_error(_("%s: unexpected reloc %u in object file"),
2526 object
->name().c_str(), r_type
);
2530 unsupported_reloc_local(object
, r_type
);
2535 // Report an unsupported relocation against a global symbol.
2537 template<int size
, bool big_endian
>
2539 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2540 Sized_relobj_file
<size
, big_endian
>* object
,
2541 unsigned int r_type
,
2544 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2545 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2548 // Scan a relocation for a global symbol.
2550 template<int size
, bool big_endian
>
2552 Target_sparc
<size
, big_endian
>::Scan::global(
2553 Symbol_table
* symtab
,
2555 Target_sparc
<size
, big_endian
>* target
,
2556 Sized_relobj_file
<size
, big_endian
>* object
,
2557 unsigned int data_shndx
,
2558 Output_section
* output_section
,
2559 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2560 unsigned int r_type
,
2563 unsigned int orig_r_type
= r_type
;
2564 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2566 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2567 // section. We check here to avoid creating a dynamic reloc against
2568 // _GLOBAL_OFFSET_TABLE_.
2569 if (!target
->has_got_section()
2570 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2571 target
->got_section(symtab
, layout
);
2575 // A STT_GNU_IFUNC symbol may require a PLT entry.
2577 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2578 target
->make_plt_entry(symtab
, layout
, gsym
);
2582 case elfcpp::R_SPARC_NONE
:
2583 case elfcpp::R_SPARC_REGISTER
:
2584 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2585 case elfcpp::R_SPARC_GNU_VTENTRY
:
2588 case elfcpp::R_SPARC_PLT64
:
2589 case elfcpp::R_SPARC_PLT32
:
2590 case elfcpp::R_SPARC_HIPLT22
:
2591 case elfcpp::R_SPARC_LOPLT10
:
2592 case elfcpp::R_SPARC_PCPLT32
:
2593 case elfcpp::R_SPARC_PCPLT22
:
2594 case elfcpp::R_SPARC_PCPLT10
:
2595 case elfcpp::R_SPARC_WPLT30
:
2596 // If the symbol is fully resolved, this is just a PC32 reloc.
2597 // Otherwise we need a PLT entry.
2598 if (gsym
->final_value_is_known())
2600 // If building a shared library, we can also skip the PLT entry
2601 // if the symbol is defined in the output file and is protected
2603 if (gsym
->is_defined()
2604 && !gsym
->is_from_dynobj()
2605 && !gsym
->is_preemptible())
2607 target
->make_plt_entry(symtab
, layout
, gsym
);
2610 case elfcpp::R_SPARC_DISP8
:
2611 case elfcpp::R_SPARC_DISP16
:
2612 case elfcpp::R_SPARC_DISP32
:
2613 case elfcpp::R_SPARC_DISP64
:
2614 case elfcpp::R_SPARC_PC_HH22
:
2615 case elfcpp::R_SPARC_PC_HM10
:
2616 case elfcpp::R_SPARC_PC_LM22
:
2617 case elfcpp::R_SPARC_PC10
:
2618 case elfcpp::R_SPARC_PC22
:
2619 case elfcpp::R_SPARC_WDISP30
:
2620 case elfcpp::R_SPARC_WDISP22
:
2621 case elfcpp::R_SPARC_WDISP19
:
2622 case elfcpp::R_SPARC_WDISP16
:
2623 case elfcpp::R_SPARC_WDISP10
:
2625 if (gsym
->needs_plt_entry())
2626 target
->make_plt_entry(symtab
, layout
, gsym
);
2627 // Make a dynamic relocation if necessary.
2628 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2630 if (gsym
->may_need_copy_reloc())
2632 target
->copy_reloc(symtab
, layout
, object
,
2633 data_shndx
, output_section
, gsym
,
2638 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2639 check_non_pic(object
, r_type
);
2640 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2641 data_shndx
, reloc
.get_r_offset(),
2642 reloc
.get_r_addend());
2648 case elfcpp::R_SPARC_UA64
:
2649 case elfcpp::R_SPARC_64
:
2650 case elfcpp::R_SPARC_HIX22
:
2651 case elfcpp::R_SPARC_LOX10
:
2652 case elfcpp::R_SPARC_H34
:
2653 case elfcpp::R_SPARC_H44
:
2654 case elfcpp::R_SPARC_M44
:
2655 case elfcpp::R_SPARC_L44
:
2656 case elfcpp::R_SPARC_HH22
:
2657 case elfcpp::R_SPARC_HM10
:
2658 case elfcpp::R_SPARC_LM22
:
2659 case elfcpp::R_SPARC_HI22
:
2660 case elfcpp::R_SPARC_LO10
:
2661 case elfcpp::R_SPARC_OLO10
:
2662 case elfcpp::R_SPARC_UA32
:
2663 case elfcpp::R_SPARC_32
:
2664 case elfcpp::R_SPARC_UA16
:
2665 case elfcpp::R_SPARC_16
:
2666 case elfcpp::R_SPARC_11
:
2667 case elfcpp::R_SPARC_10
:
2668 case elfcpp::R_SPARC_8
:
2669 case elfcpp::R_SPARC_7
:
2670 case elfcpp::R_SPARC_6
:
2671 case elfcpp::R_SPARC_5
:
2673 // Make a PLT entry if necessary.
2674 if (gsym
->needs_plt_entry())
2676 target
->make_plt_entry(symtab
, layout
, gsym
);
2677 // Since this is not a PC-relative relocation, we may be
2678 // taking the address of a function. In that case we need to
2679 // set the entry in the dynamic symbol table to the address of
2681 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2682 gsym
->set_needs_dynsym_value();
2684 // Make a dynamic relocation if necessary.
2685 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2687 unsigned int r_off
= reloc
.get_r_offset();
2689 // The assembler can sometimes emit unaligned relocations
2690 // for dwarf2 cfi directives.
2693 case elfcpp::R_SPARC_16
:
2695 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2697 case elfcpp::R_SPARC_32
:
2699 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2701 case elfcpp::R_SPARC_64
:
2703 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2705 case elfcpp::R_SPARC_UA16
:
2707 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2709 case elfcpp::R_SPARC_UA32
:
2711 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2713 case elfcpp::R_SPARC_UA64
:
2715 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2719 if (gsym
->may_need_copy_reloc())
2721 target
->copy_reloc(symtab
, layout
, object
,
2722 data_shndx
, output_section
, gsym
, reloc
);
2724 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2725 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2726 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2727 && gsym
->can_use_relative_reloc(false)
2728 && !gsym
->is_from_dynobj()
2729 && !gsym
->is_undefined()
2730 && !gsym
->is_preemptible())
2732 // Use an IRELATIVE reloc for a locally defined
2733 // STT_GNU_IFUNC symbol. This makes a function
2734 // address in a PIE executable match the address in a
2735 // shared library that it links against.
2736 Reloc_section
* rela_dyn
=
2737 target
->rela_ifunc_section(layout
);
2738 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2739 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2740 output_section
, object
,
2742 reloc
.get_r_offset(),
2743 reloc
.get_r_addend());
2745 else if ((r_type
== elfcpp::R_SPARC_32
2746 || r_type
== elfcpp::R_SPARC_64
)
2747 && gsym
->can_use_relative_reloc(false))
2749 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2750 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2751 output_section
, object
,
2752 data_shndx
, reloc
.get_r_offset(),
2753 reloc
.get_r_addend(), is_ifunc
);
2757 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2759 check_non_pic(object
, r_type
);
2760 if (gsym
->is_from_dynobj()
2761 || gsym
->is_undefined()
2762 || gsym
->is_preemptible())
2763 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2765 reloc
.get_r_offset(),
2766 reloc
.get_r_addend());
2768 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2771 reloc
.get_r_offset(),
2772 reloc
.get_r_addend());
2778 case elfcpp::R_SPARC_GOTDATA_OP
:
2779 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2780 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2781 if (gsym
->is_defined()
2782 && !gsym
->is_from_dynobj()
2783 && !gsym
->is_preemptible()
2786 // We will optimize this into a GOT relative relocation
2787 // and code transform the GOT load into an addition.
2790 case elfcpp::R_SPARC_GOT10
:
2791 case elfcpp::R_SPARC_GOT13
:
2792 case elfcpp::R_SPARC_GOT22
:
2794 // The symbol requires a GOT entry.
2795 Output_data_got
<size
, big_endian
>* got
;
2797 got
= target
->got_section(symtab
, layout
);
2798 if (gsym
->final_value_is_known())
2800 // For a STT_GNU_IFUNC symbol we want the PLT address.
2801 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2802 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2804 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2808 // If this symbol is not fully resolved, we need to add a
2809 // GOT entry with a dynamic relocation.
2810 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2812 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2814 // 1) The symbol may be defined in some other module.
2816 // 2) We are building a shared library and this is a
2817 // protected symbol; using GLOB_DAT means that the dynamic
2818 // linker can use the address of the PLT in the main
2819 // executable when appropriate so that function address
2820 // comparisons work.
2822 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2823 // code, again so that function address comparisons work.
2824 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2825 if (gsym
->is_from_dynobj()
2826 || gsym
->is_undefined()
2827 || gsym
->is_preemptible()
2828 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2829 && parameters
->options().shared())
2830 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2831 && parameters
->options().output_is_position_independent()
2832 && !gsym
->is_forced_local()))
2834 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2836 // If this symbol is forced local, this relocation will
2837 // not work properly. That's because ld.so on sparc
2838 // (and 32-bit powerpc) expects st_value in the r_addend
2839 // of relocations for STB_LOCAL symbols. Curiously the
2840 // BFD linker does not promote global hidden symbols to be
2841 // STB_LOCAL in the dynamic symbol table like Gold does.
2842 gold_assert(!gsym
->is_forced_local());
2843 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2846 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2848 unsigned int off
= got
->add_constant(0);
2850 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2853 // Tell the dynamic linker to use the PLT address
2854 // when resolving relocations.
2855 if (gsym
->is_from_dynobj()
2856 && !parameters
->options().shared())
2857 gsym
->set_needs_dynsym_value();
2859 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2860 got
, off
, 0, is_ifunc
);
2866 // These are initial tls relocs, which are expected when
2868 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2869 case elfcpp::R_SPARC_TLS_GD_LO10
:
2870 case elfcpp::R_SPARC_TLS_GD_ADD
:
2871 case elfcpp::R_SPARC_TLS_GD_CALL
:
2872 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2873 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2874 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2875 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2876 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2877 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2878 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2879 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2880 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2881 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2882 case elfcpp::R_SPARC_TLS_IE_LO10
:
2883 case elfcpp::R_SPARC_TLS_IE_LD
:
2884 case elfcpp::R_SPARC_TLS_IE_LDX
:
2885 case elfcpp::R_SPARC_TLS_IE_ADD
:
2887 const bool is_final
= gsym
->final_value_is_known();
2888 const tls::Tls_optimization optimized_type
2889 = optimize_tls_reloc(is_final
, r_type
);
2892 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2893 case elfcpp::R_SPARC_TLS_GD_LO10
:
2894 case elfcpp::R_SPARC_TLS_GD_ADD
:
2895 case elfcpp::R_SPARC_TLS_GD_CALL
:
2896 if (optimized_type
== tls::TLSOPT_NONE
)
2898 // Create a pair of GOT entries for the module index and
2899 // dtv-relative offset.
2900 Output_data_got
<size
, big_endian
>* got
2901 = target
->got_section(symtab
, layout
);
2902 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2903 target
->rela_dyn_section(layout
),
2905 ? elfcpp::R_SPARC_TLS_DTPMOD64
2906 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2908 ? elfcpp::R_SPARC_TLS_DTPOFF64
2909 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2911 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2912 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2913 generate_tls_call(symtab
, layout
, target
);
2915 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2917 // Create a GOT entry for the tp-relative offset.
2918 Output_data_got
<size
, big_endian
>* got
2919 = target
->got_section(symtab
, layout
);
2920 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2921 target
->rela_dyn_section(layout
),
2923 elfcpp::R_SPARC_TLS_TPOFF64
:
2924 elfcpp::R_SPARC_TLS_TPOFF32
));
2926 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2927 unsupported_reloc_global(object
, r_type
, gsym
);
2930 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2931 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2932 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2933 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2934 if (optimized_type
== tls::TLSOPT_NONE
)
2936 // Create a GOT entry for the module index.
2937 target
->got_mod_index_entry(symtab
, layout
, object
);
2939 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2940 generate_tls_call(symtab
, layout
, target
);
2942 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2943 unsupported_reloc_global(object
, r_type
, gsym
);
2946 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2947 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2948 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2951 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2952 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2953 layout
->set_has_static_tls();
2954 if (parameters
->options().shared())
2956 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2957 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2958 output_section
, object
,
2959 data_shndx
, reloc
.get_r_offset(),
2964 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2965 case elfcpp::R_SPARC_TLS_IE_LO10
:
2966 case elfcpp::R_SPARC_TLS_IE_LD
:
2967 case elfcpp::R_SPARC_TLS_IE_LDX
:
2968 case elfcpp::R_SPARC_TLS_IE_ADD
:
2969 layout
->set_has_static_tls();
2970 if (optimized_type
== tls::TLSOPT_NONE
)
2972 // Create a GOT entry for the tp-relative offset.
2973 Output_data_got
<size
, big_endian
>* got
2974 = target
->got_section(symtab
, layout
);
2975 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2976 target
->rela_dyn_section(layout
),
2978 ? elfcpp::R_SPARC_TLS_TPOFF64
2979 : elfcpp::R_SPARC_TLS_TPOFF32
));
2981 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2982 unsupported_reloc_global(object
, r_type
, gsym
);
2988 // These are relocations which should only be seen by the
2989 // dynamic linker, and should never be seen here.
2990 case elfcpp::R_SPARC_COPY
:
2991 case elfcpp::R_SPARC_GLOB_DAT
:
2992 case elfcpp::R_SPARC_JMP_SLOT
:
2993 case elfcpp::R_SPARC_JMP_IREL
:
2994 case elfcpp::R_SPARC_RELATIVE
:
2995 case elfcpp::R_SPARC_IRELATIVE
:
2996 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2997 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2998 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2999 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3000 case elfcpp::R_SPARC_TLS_TPOFF64
:
3001 case elfcpp::R_SPARC_TLS_TPOFF32
:
3002 gold_error(_("%s: unexpected reloc %u in object file"),
3003 object
->name().c_str(), r_type
);
3007 unsupported_reloc_global(object
, r_type
, gsym
);
3012 // Process relocations for gc.
3014 template<int size
, bool big_endian
>
3016 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3017 Symbol_table
* symtab
,
3019 Sized_relobj_file
<size
, big_endian
>* object
,
3020 unsigned int data_shndx
,
3022 const unsigned char* prelocs
,
3024 Output_section
* output_section
,
3025 bool needs_special_offset_handling
,
3026 size_t local_symbol_count
,
3027 const unsigned char* plocal_symbols
)
3029 typedef Target_sparc
<size
, big_endian
> Sparc
;
3030 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3032 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
3033 typename
Target_sparc::Relocatable_size_for_reloc
>(
3042 needs_special_offset_handling
,
3047 // Scan relocations for a section.
3049 template<int size
, bool big_endian
>
3051 Target_sparc
<size
, big_endian
>::scan_relocs(
3052 Symbol_table
* symtab
,
3054 Sized_relobj_file
<size
, big_endian
>* object
,
3055 unsigned int data_shndx
,
3056 unsigned int sh_type
,
3057 const unsigned char* prelocs
,
3059 Output_section
* output_section
,
3060 bool needs_special_offset_handling
,
3061 size_t local_symbol_count
,
3062 const unsigned char* plocal_symbols
)
3064 typedef Target_sparc
<size
, big_endian
> Sparc
;
3065 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3067 if (sh_type
== elfcpp::SHT_REL
)
3069 gold_error(_("%s: unsupported REL reloc section"),
3070 object
->name().c_str());
3074 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
3083 needs_special_offset_handling
,
3088 // Finalize the sections.
3090 template<int size
, bool big_endian
>
3092 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3094 const Input_objects
*,
3095 Symbol_table
* symtab
)
3098 this->plt_
->emit_pending_ifunc_relocs();
3100 // Fill in some more dynamic tags.
3101 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3103 : this->plt_
->rel_plt());
3104 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3105 this->rela_dyn_
, true, true);
3107 // Emit any relocs we saved in an attempt to avoid generating COPY
3109 if (this->copy_relocs_
.any_saved_relocs())
3110 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3112 if (parameters
->doing_static_link()
3113 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3115 // If linking statically, make sure that the __rela_iplt symbols
3116 // were defined if necessary, even if we didn't create a PLT.
3117 static const Define_symbol_in_segment syms
[] =
3120 "__rela_iplt_start", // name
3121 elfcpp::PT_LOAD
, // segment_type
3122 elfcpp::PF_W
, // segment_flags_set
3123 elfcpp::PF(0), // segment_flags_clear
3126 elfcpp::STT_NOTYPE
, // type
3127 elfcpp::STB_GLOBAL
, // binding
3128 elfcpp::STV_HIDDEN
, // visibility
3130 Symbol::SEGMENT_START
, // offset_from_base
3134 "__rela_iplt_end", // name
3135 elfcpp::PT_LOAD
, // segment_type
3136 elfcpp::PF_W
, // segment_flags_set
3137 elfcpp::PF(0), // segment_flags_clear
3140 elfcpp::STT_NOTYPE
, // type
3141 elfcpp::STB_GLOBAL
, // binding
3142 elfcpp::STV_HIDDEN
, // visibility
3144 Symbol::SEGMENT_START
, // offset_from_base
3149 symtab
->define_symbols(layout
, 2, syms
,
3150 layout
->script_options()->saw_sections_clause());
3154 // Perform a relocation.
3156 template<int size
, bool big_endian
>
3158 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3159 const Relocate_info
<size
, big_endian
>* relinfo
,
3160 Target_sparc
* target
,
3163 const elfcpp::Rela
<size
, big_endian
>& rela
,
3164 unsigned int r_type
,
3165 const Sized_symbol
<size
>* gsym
,
3166 const Symbol_value
<size
>* psymval
,
3167 unsigned char* view
,
3168 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3169 section_size_type view_size
)
3171 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3174 if (this->ignore_gd_add_
)
3176 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3177 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3178 _("missing expected TLS relocation"));
3181 this->ignore_gd_add_
= false;
3185 if (this->reloc_adjust_addr_
== view
)
3188 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3189 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3191 // Pick the value to use for symbols defined in shared objects.
3192 Symbol_value
<size
> symval
;
3194 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3196 elfcpp::Elf_Xword value
;
3198 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3200 symval
.set_output_value(value
);
3204 else if (gsym
== NULL
&& orig_is_ifunc
)
3206 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3207 if (object
->local_has_plt_offset(r_sym
))
3209 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3210 + object
->local_plt_offset(r_sym
));
3215 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3217 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3218 // pointer points to the beginning, not the end, of the table.
3219 // So we just use the plain offset.
3220 unsigned int got_offset
= 0;
3221 bool gdop_valid
= false;
3224 case elfcpp::R_SPARC_GOTDATA_OP
:
3225 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3226 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3227 // If this is local, we did not create a GOT entry because we
3228 // intend to transform this into a GOT relative relocation.
3230 || (gsym
->is_defined()
3231 && !gsym
->is_from_dynobj()
3232 && !gsym
->is_preemptible()
3235 got_offset
= psymval
->value(object
, 0) - target
->got_address();
3239 case elfcpp::R_SPARC_GOT10
:
3240 case elfcpp::R_SPARC_GOT13
:
3241 case elfcpp::R_SPARC_GOT22
:
3244 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3245 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3249 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3250 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3251 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3261 case elfcpp::R_SPARC_NONE
:
3262 case elfcpp::R_SPARC_REGISTER
:
3263 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3264 case elfcpp::R_SPARC_GNU_VTENTRY
:
3267 case elfcpp::R_SPARC_8
:
3268 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3272 case elfcpp::R_SPARC_16
:
3273 if (rela
.get_r_offset() & 0x1)
3275 // The assembler can sometimes emit unaligned relocations
3276 // for dwarf2 cfi directives.
3277 Reloc::ua16(view
, object
, psymval
, addend
);
3280 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3284 case elfcpp::R_SPARC_32
:
3285 if (!parameters
->options().output_is_position_independent())
3287 if (rela
.get_r_offset() & 0x3)
3289 // The assembler can sometimes emit unaligned relocations
3290 // for dwarf2 cfi directives.
3291 Reloc::ua32(view
, object
, psymval
, addend
);
3294 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3299 case elfcpp::R_SPARC_DISP8
:
3300 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3303 case elfcpp::R_SPARC_DISP16
:
3304 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3307 case elfcpp::R_SPARC_DISP32
:
3308 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3311 case elfcpp::R_SPARC_DISP64
:
3312 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3315 case elfcpp::R_SPARC_WDISP30
:
3316 case elfcpp::R_SPARC_WPLT30
:
3317 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3318 if (target
->may_relax())
3319 relax_call(target
, view
, rela
, view_size
);
3322 case elfcpp::R_SPARC_WDISP22
:
3323 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3326 case elfcpp::R_SPARC_WDISP19
:
3327 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3330 case elfcpp::R_SPARC_WDISP16
:
3331 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3334 case elfcpp::R_SPARC_WDISP10
:
3335 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3338 case elfcpp::R_SPARC_HI22
:
3339 Reloc::hi22(view
, object
, psymval
, addend
);
3342 case elfcpp::R_SPARC_22
:
3343 Reloc::rela32_22(view
, object
, psymval
, addend
);
3346 case elfcpp::R_SPARC_13
:
3347 Reloc::rela32_13(view
, object
, psymval
, addend
);
3350 case elfcpp::R_SPARC_LO10
:
3351 Reloc::lo10(view
, object
, psymval
, addend
);
3354 case elfcpp::R_SPARC_GOT10
:
3355 Reloc::lo10(view
, got_offset
, addend
);
3358 case elfcpp::R_SPARC_GOTDATA_OP
:
3361 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3362 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3365 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3366 val
= elfcpp::Swap
<32, true>::readval(wv
);
3367 val
= 0x80000000 | (val
& 0x3e07c01f);
3368 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3372 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3375 Reloc::gdop_lox10(view
, got_offset
, addend
);
3379 case elfcpp::R_SPARC_GOT13
:
3380 Reloc::rela32_13(view
, got_offset
, addend
);
3383 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3386 Reloc::gdop_hix22(view
, got_offset
, addend
);
3390 case elfcpp::R_SPARC_GOT22
:
3391 Reloc::hi22(view
, got_offset
, addend
);
3394 case elfcpp::R_SPARC_PC10
:
3395 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3398 case elfcpp::R_SPARC_PC22
:
3399 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3402 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3403 case elfcpp::R_SPARC_UA32
:
3404 Reloc::ua32(view
, object
, psymval
, addend
);
3407 case elfcpp::R_SPARC_PLT64
:
3408 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3412 case elfcpp::R_SPARC_PLT32
:
3413 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3417 case elfcpp::R_SPARC_HIPLT22
:
3418 Reloc::hi22(view
, object
, psymval
, addend
);
3421 case elfcpp::R_SPARC_LOPLT10
:
3422 Reloc::lo10(view
, object
, psymval
, addend
);
3425 case elfcpp::R_SPARC_PCPLT32
:
3426 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3429 case elfcpp::R_SPARC_PCPLT22
:
3430 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3433 case elfcpp::R_SPARC_PCPLT10
:
3434 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3437 case elfcpp::R_SPARC_64
:
3438 if (!parameters
->options().output_is_position_independent())
3440 if (rela
.get_r_offset() & 0x7)
3442 // The assembler can sometimes emit unaligned relocations
3443 // for dwarf2 cfi directives.
3444 Reloc::ua64(view
, object
, psymval
, addend
);
3447 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3452 case elfcpp::R_SPARC_OLO10
:
3454 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3455 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3456 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3460 case elfcpp::R_SPARC_HH22
:
3461 Reloc::hh22(view
, object
, psymval
, addend
);
3464 case elfcpp::R_SPARC_PC_HH22
:
3465 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3468 case elfcpp::R_SPARC_HM10
:
3469 Reloc::hm10(view
, object
, psymval
, addend
);
3472 case elfcpp::R_SPARC_PC_HM10
:
3473 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3476 case elfcpp::R_SPARC_LM22
:
3477 Reloc::hi22(view
, object
, psymval
, addend
);
3480 case elfcpp::R_SPARC_PC_LM22
:
3481 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3484 case elfcpp::R_SPARC_11
:
3485 Reloc::rela32_11(view
, object
, psymval
, addend
);
3488 case elfcpp::R_SPARC_10
:
3489 Reloc::rela32_10(view
, object
, psymval
, addend
);
3492 case elfcpp::R_SPARC_7
:
3493 Reloc::rela32_7(view
, object
, psymval
, addend
);
3496 case elfcpp::R_SPARC_6
:
3497 Reloc::rela32_6(view
, object
, psymval
, addend
);
3500 case elfcpp::R_SPARC_5
:
3501 Reloc::rela32_5(view
, object
, psymval
, addend
);
3504 case elfcpp::R_SPARC_HIX22
:
3505 Reloc::hix22(view
, object
, psymval
, addend
);
3508 case elfcpp::R_SPARC_LOX10
:
3509 Reloc::lox10(view
, object
, psymval
, addend
);
3512 case elfcpp::R_SPARC_H34
:
3513 Reloc::h34(view
, object
, psymval
, addend
);
3516 case elfcpp::R_SPARC_H44
:
3517 Reloc::h44(view
, object
, psymval
, addend
);
3520 case elfcpp::R_SPARC_M44
:
3521 Reloc::m44(view
, object
, psymval
, addend
);
3524 case elfcpp::R_SPARC_L44
:
3525 Reloc::l44(view
, object
, psymval
, addend
);
3528 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3529 case elfcpp::R_SPARC_UA64
:
3530 Reloc::ua64(view
, object
, psymval
, addend
);
3533 case elfcpp::R_SPARC_UA16
:
3534 Reloc::ua16(view
, object
, psymval
, addend
);
3537 case elfcpp::R_SPARC_TLS_GD_HI22
:
3538 case elfcpp::R_SPARC_TLS_GD_LO10
:
3539 case elfcpp::R_SPARC_TLS_GD_ADD
:
3540 case elfcpp::R_SPARC_TLS_GD_CALL
:
3541 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3542 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3543 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3544 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3545 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3546 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3547 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3548 case elfcpp::R_SPARC_TLS_IE_HI22
:
3549 case elfcpp::R_SPARC_TLS_IE_LO10
:
3550 case elfcpp::R_SPARC_TLS_IE_LD
:
3551 case elfcpp::R_SPARC_TLS_IE_LDX
:
3552 case elfcpp::R_SPARC_TLS_IE_ADD
:
3553 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3554 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3555 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3556 r_type
, gsym
, psymval
, view
,
3557 address
, view_size
);
3560 case elfcpp::R_SPARC_COPY
:
3561 case elfcpp::R_SPARC_GLOB_DAT
:
3562 case elfcpp::R_SPARC_JMP_SLOT
:
3563 case elfcpp::R_SPARC_JMP_IREL
:
3564 case elfcpp::R_SPARC_RELATIVE
:
3565 case elfcpp::R_SPARC_IRELATIVE
:
3566 // These are outstanding tls relocs, which are unexpected when
3568 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3569 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3570 case elfcpp::R_SPARC_TLS_TPOFF64
:
3571 case elfcpp::R_SPARC_TLS_TPOFF32
:
3572 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3573 _("unexpected reloc %u in object file"),
3578 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3579 _("unsupported reloc %u"),
3587 // Perform a TLS relocation.
3589 template<int size
, bool big_endian
>
3591 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3592 const Relocate_info
<size
, big_endian
>* relinfo
,
3593 Target_sparc
<size
, big_endian
>* target
,
3595 const elfcpp::Rela
<size
, big_endian
>& rela
,
3596 unsigned int r_type
,
3597 const Sized_symbol
<size
>* gsym
,
3598 const Symbol_value
<size
>* psymval
,
3599 unsigned char* view
,
3600 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3603 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3604 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3605 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3606 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3608 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3609 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3611 const bool is_final
=
3613 ? !parameters
->options().output_is_position_independent()
3614 : gsym
->final_value_is_known());
3615 const tls::Tls_optimization optimized_type
3616 = optimize_tls_reloc(is_final
, r_type
);
3620 case elfcpp::R_SPARC_TLS_GD_HI22
:
3621 case elfcpp::R_SPARC_TLS_GD_LO10
:
3622 case elfcpp::R_SPARC_TLS_GD_ADD
:
3623 case elfcpp::R_SPARC_TLS_GD_CALL
:
3624 if (optimized_type
== tls::TLSOPT_TO_LE
)
3626 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3629 value
-= tls_segment
->memsz();
3633 case elfcpp::R_SPARC_TLS_GD_HI22
:
3634 // TLS_GD_HI22 --> TLS_LE_HIX22
3635 Reloc::hix22(view
, value
, addend
);
3638 case elfcpp::R_SPARC_TLS_GD_LO10
:
3639 // TLS_GD_LO10 --> TLS_LE_LOX10
3640 Reloc::lox10(view
, value
, addend
);
3643 case elfcpp::R_SPARC_TLS_GD_ADD
:
3644 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3645 val
= elfcpp::Swap
<32, true>::readval(wv
);
3646 val
= (val
& ~0x7c000) | 0x1c000;
3647 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3649 case elfcpp::R_SPARC_TLS_GD_CALL
:
3650 // call __tls_get_addr --> nop
3651 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3658 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3659 ? GOT_TYPE_TLS_OFFSET
3660 : GOT_TYPE_TLS_PAIR
);
3663 gold_assert(gsym
->has_got_offset(got_type
));
3664 value
= gsym
->got_offset(got_type
);
3668 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3669 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3670 value
= object
->local_got_offset(r_sym
, got_type
);
3672 if (optimized_type
== tls::TLSOPT_TO_IE
)
3674 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3679 case elfcpp::R_SPARC_TLS_GD_HI22
:
3680 // TLS_GD_HI22 --> TLS_IE_HI22
3681 Reloc::hi22(view
, value
, addend
);
3684 case elfcpp::R_SPARC_TLS_GD_LO10
:
3685 // TLS_GD_LO10 --> TLS_IE_LO10
3686 Reloc::lo10(view
, value
, addend
);
3689 case elfcpp::R_SPARC_TLS_GD_ADD
:
3690 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3691 val
= elfcpp::Swap
<32, true>::readval(wv
);
3698 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3701 case elfcpp::R_SPARC_TLS_GD_CALL
:
3702 // The compiler can put the TLS_GD_ADD instruction
3703 // into the delay slot of the call. If so, we need
3704 // to transpose the two instructions so that the
3705 // new sequence works properly.
3707 // The test we use is if the instruction in the
3708 // delay slot is an add with destination register
3710 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3711 if ((val
& 0x81f80000) == 0x80000000
3712 && ((val
>> 25) & 0x1f) == 0x8)
3719 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3722 this->ignore_gd_add_
= true;
3726 // Even if the delay slot isn't the TLS_GD_ADD
3727 // instruction, we still have to handle the case
3728 // where it sets up %o0 in some other way.
3729 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3731 this->reloc_adjust_addr_
= view
+ 4;
3733 // call __tls_get_addr --> add %g7, %o0, %o0
3734 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3739 else if (optimized_type
== tls::TLSOPT_NONE
)
3743 case elfcpp::R_SPARC_TLS_GD_HI22
:
3744 Reloc::hi22(view
, value
, addend
);
3746 case elfcpp::R_SPARC_TLS_GD_LO10
:
3747 Reloc::lo10(view
, value
, addend
);
3749 case elfcpp::R_SPARC_TLS_GD_ADD
:
3751 case elfcpp::R_SPARC_TLS_GD_CALL
:
3753 Symbol_value
<size
> symval
;
3754 elfcpp::Elf_Xword value
;
3757 tsym
= target
->tls_get_addr_sym_
;
3759 value
= (target
->plt_section()->address() +
3760 tsym
->plt_offset());
3761 symval
.set_output_value(value
);
3762 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3769 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3770 _("unsupported reloc %u"),
3774 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3775 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3776 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3777 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3778 if (optimized_type
== tls::TLSOPT_TO_LE
)
3780 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3784 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3785 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3786 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3787 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3790 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3791 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3796 else if (optimized_type
== tls::TLSOPT_NONE
)
3798 // Relocate the field with the offset of the GOT entry for
3799 // the module index.
3800 unsigned int got_offset
;
3802 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3805 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3806 Reloc::hi22(view
, got_offset
, addend
);
3808 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3809 Reloc::lo10(view
, got_offset
, addend
);
3811 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3813 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3815 Symbol_value
<size
> symval
;
3816 elfcpp::Elf_Xword value
;
3819 tsym
= target
->tls_get_addr_sym_
;
3821 value
= (target
->plt_section()->address() +
3822 tsym
->plt_offset());
3823 symval
.set_output_value(value
);
3824 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3830 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3831 _("unsupported reloc %u"),
3835 // These relocs can appear in debugging sections, in which case
3836 // we won't see the TLS_LDM relocs. The local_dynamic_type
3837 // field tells us this.
3838 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3839 if (optimized_type
== tls::TLSOPT_TO_LE
)
3841 value
-= tls_segment
->memsz();
3842 Reloc::hix22(view
, value
, addend
);
3845 Reloc::ldo_hix22(view
, value
, addend
);
3847 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3848 if (optimized_type
== tls::TLSOPT_TO_LE
)
3850 value
-= tls_segment
->memsz();
3851 Reloc::lox10(view
, value
, addend
);
3854 Reloc::ldo_lox10(view
, value
, addend
);
3856 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3857 if (optimized_type
== tls::TLSOPT_TO_LE
)
3859 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3862 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3863 val
= elfcpp::Swap
<32, true>::readval(wv
);
3864 val
= (val
& ~0x7c000) | 0x1c000;
3865 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3869 // When optimizing IE --> LE, the only relocation that is handled
3870 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3871 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3872 // rs2 and rd are the same.
3873 case elfcpp::R_SPARC_TLS_IE_LD
:
3874 case elfcpp::R_SPARC_TLS_IE_LDX
:
3875 if (optimized_type
== tls::TLSOPT_TO_LE
)
3877 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3878 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3879 Insntype rs2
= val
& 0x1f;
3880 Insntype rd
= (val
>> 25) & 0x1f;
3885 val
= sparc_mov
| (val
& 0x3e00001f);
3887 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3891 case elfcpp::R_SPARC_TLS_IE_HI22
:
3892 case elfcpp::R_SPARC_TLS_IE_LO10
:
3893 if (optimized_type
== tls::TLSOPT_TO_LE
)
3895 value
-= tls_segment
->memsz();
3898 case elfcpp::R_SPARC_TLS_IE_HI22
:
3899 // IE_HI22 --> LE_HIX22
3900 Reloc::hix22(view
, value
, addend
);
3902 case elfcpp::R_SPARC_TLS_IE_LO10
:
3903 // IE_LO10 --> LE_LOX10
3904 Reloc::lox10(view
, value
, addend
);
3909 else if (optimized_type
== tls::TLSOPT_NONE
)
3911 // Relocate the field with the offset of the GOT entry for
3912 // the tp-relative offset of the symbol.
3915 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3916 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3920 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3921 gold_assert(object
->local_has_got_offset(r_sym
,
3922 GOT_TYPE_TLS_OFFSET
));
3923 value
= object
->local_got_offset(r_sym
,
3924 GOT_TYPE_TLS_OFFSET
);
3928 case elfcpp::R_SPARC_TLS_IE_HI22
:
3929 Reloc::hi22(view
, value
, addend
);
3931 case elfcpp::R_SPARC_TLS_IE_LO10
:
3932 Reloc::lo10(view
, value
, addend
);
3937 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3938 _("unsupported reloc %u"),
3942 case elfcpp::R_SPARC_TLS_IE_ADD
:
3943 // This seems to be mainly so that we can find the addition
3944 // instruction if there is one. There doesn't seem to be any
3945 // actual relocation to apply.
3948 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3949 // If we're creating a shared library, a dynamic relocation will
3950 // have been created for this location, so do not apply it now.
3951 if (!parameters
->options().shared())
3953 value
-= tls_segment
->memsz();
3954 Reloc::hix22(view
, value
, addend
);
3958 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3959 // If we're creating a shared library, a dynamic relocation will
3960 // have been created for this location, so do not apply it now.
3961 if (!parameters
->options().shared())
3963 value
-= tls_segment
->memsz();
3964 Reloc::lox10(view
, value
, addend
);
3970 // Relax a call instruction.
3972 template<int size
, bool big_endian
>
3974 Target_sparc
<size
, big_endian
>::Relocate::relax_call(
3975 Target_sparc
<size
, big_endian
>* target
,
3976 unsigned char* view
,
3977 const elfcpp::Rela
<size
, big_endian
>& rela
,
3978 section_size_type view_size
)
3980 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3981 Insntype
*wv
= reinterpret_cast<Insntype
*>(view
);
3982 Insntype call_insn
, delay_insn
, set_insn
;
3983 uint32_t op3
, reg
, off
;
3985 // This code tries to relax call instructions that meet
3986 // certain criteria.
3988 // The first criteria is that the call must be such that the return
3989 // address which the call writes into %o7 is unused. Two sequences
3990 // meet this criteria, and are used to implement tail calls.
3992 // Leaf function tail call:
3994 // or %o7, %g0, %ANY_REG
3996 // or %ANY_REG, %g0, %o7
3998 // Non-leaf function tail call:
4003 // The second criteria is that the call destination is close. If
4004 // the displacement can fit in a signed 22-bit immediate field of a
4005 // pre-V9 branch, we can do it. If we are generating a 64-bit
4006 // object or a 32-bit object with ELF machine type EF_SPARC32PLUS,
4007 // and the displacement fits in a signed 19-bit immediate field,
4008 // then we can use a V9 branch.
4010 // Make sure the delay instruction can be safely accessed.
4011 if (rela
.get_r_offset() + 8 > view_size
)
4014 call_insn
= elfcpp::Swap
<32, true>::readval(wv
);
4015 delay_insn
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
4017 // Make sure it is really a call instruction.
4018 if (((call_insn
>> 30) & 0x3) != 1)
4021 if (((delay_insn
>> 30) & 0x3) != 2)
4024 // Accept only a restore or an integer arithmetic operation whose
4025 // sole side effect is to write the %o7 register (and perhaps set
4026 // the condition codes, which are considered clobbered across
4029 // For example, we don't want to match a tagged addition or
4030 // subtraction. We also don't want to match something like a
4033 // Specifically we accept add{,cc}, and{,cc}, or{,cc},
4034 // xor{,cc}, sub{,cc}, andn{,cc}, orn{,cc}, and xnor{,cc}.
4036 op3
= (delay_insn
>> 19) & 0x3f;
4037 reg
= (delay_insn
>> 25) & 0x1f;
4039 && ((op3
& 0x28) != 0 || reg
!= 15))
4042 // For non-restore instructions, make sure %o7 isn't
4047 reg
= (delay_insn
>> 14) & 0x15;
4051 // And if non-immediate, check RS2
4052 if (((delay_insn
>> 13) & 1) == 0)
4054 reg
= (delay_insn
& 0x1f);
4060 // Now check the branch distance. We are called after the
4061 // call has been relocated, so we just have to peek at the
4062 // offset contained in the instruction.
4063 off
= call_insn
& 0x3fffffff;
4064 if ((off
& 0x3fe00000) != 0
4065 && (off
& 0x3fe00000) != 0x3fe00000)
4068 if ((size
== 64 || target
->elf_machine_
== elfcpp::EM_SPARC32PLUS
)
4069 && ((off
& 0x3c0000) == 0
4070 || (off
& 0x3c0000) == 0x3c0000))
4073 call_insn
= 0x10680000 | (off
& 0x07ffff);
4078 call_insn
= 0x10800000 | (off
& 0x3fffff);
4080 elfcpp::Swap
<32, true>::writeval(wv
, call_insn
);
4082 // See if we can NOP out the delay slot instruction. We peek
4083 // at the instruction before the call to make sure we're dealing
4084 // with exactly the:
4086 // or %o7, %g0, %ANY_REG
4088 // or %ANY_REG, %g0, %o7
4090 // case. Otherwise this might be a tricky piece of hand written
4091 // assembler calculating %o7 in some non-trivial way, and therefore
4092 // we can't be sure that NOP'ing out the delay slot is safe.
4094 && rela
.get_r_offset() >= 4)
4096 if ((delay_insn
& ~(0x1f << 14)) != 0x9e100000)
4099 set_insn
= elfcpp::Swap
<32, true>::readval(wv
- 1);
4100 if ((set_insn
& ~(0x1f << 25)) != 0x8013c000)
4103 reg
= (set_insn
>> 25) & 0x1f;
4104 if (reg
== 0 || reg
== 15)
4106 if (reg
!= ((delay_insn
>> 14) & 0x1f))
4109 // All tests pass, nop it out.
4110 elfcpp::Swap
<32, true>::writeval(wv
+ 1, sparc_nop
);
4114 // Relocate section data.
4116 template<int size
, bool big_endian
>
4118 Target_sparc
<size
, big_endian
>::relocate_section(
4119 const Relocate_info
<size
, big_endian
>* relinfo
,
4120 unsigned int sh_type
,
4121 const unsigned char* prelocs
,
4123 Output_section
* output_section
,
4124 bool needs_special_offset_handling
,
4125 unsigned char* view
,
4126 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4127 section_size_type view_size
,
4128 const Reloc_symbol_changes
* reloc_symbol_changes
)
4130 typedef Target_sparc
<size
, big_endian
> Sparc
;
4131 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
4133 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4135 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
4142 needs_special_offset_handling
,
4146 reloc_symbol_changes
);
4149 // Return the size of a relocation while scanning during a relocatable
4152 template<int size
, bool big_endian
>
4154 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4158 // We are always SHT_RELA, so we should never get here.
4163 // Scan the relocs during a relocatable link.
4165 template<int size
, bool big_endian
>
4167 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4168 Symbol_table
* symtab
,
4170 Sized_relobj_file
<size
, big_endian
>* object
,
4171 unsigned int data_shndx
,
4172 unsigned int sh_type
,
4173 const unsigned char* prelocs
,
4175 Output_section
* output_section
,
4176 bool needs_special_offset_handling
,
4177 size_t local_symbol_count
,
4178 const unsigned char* plocal_symbols
,
4179 Relocatable_relocs
* rr
)
4181 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4183 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4184 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4186 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4187 Scan_relocatable_relocs
>(
4195 needs_special_offset_handling
,
4201 // Emit relocations for a section.
4203 template<int size
, bool big_endian
>
4205 Target_sparc
<size
, big_endian
>::relocate_relocs(
4206 const Relocate_info
<size
, big_endian
>* relinfo
,
4207 unsigned int sh_type
,
4208 const unsigned char* prelocs
,
4210 Output_section
* output_section
,
4211 off_t offset_in_output_section
,
4212 const Relocatable_relocs
* rr
,
4213 unsigned char* view
,
4214 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4215 section_size_type view_size
,
4216 unsigned char* reloc_view
,
4217 section_size_type reloc_view_size
)
4219 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4221 gold::relocate_relocs
<size
, big_endian
, elfcpp::SHT_RELA
>(
4226 offset_in_output_section
,
4235 // Return the value to use for a dynamic which requires special
4236 // treatment. This is how we support equality comparisons of function
4237 // pointers across shared library boundaries, as described in the
4238 // processor specific ABI supplement.
4240 template<int size
, bool big_endian
>
4242 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4244 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4245 return this->plt_section()->address() + gsym
->plt_offset();
4248 // do_make_elf_object to override the same function in the base class.
4249 // We need to use a target-specific sub-class of
4250 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4251 // of the ELF headers. Hence we need to have our own ELF object creation.
4253 template<int size
, bool big_endian
>
4255 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4256 const std::string
& name
,
4257 Input_file
* input_file
,
4258 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4260 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4261 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4262 elfcpp::Elf_Word omm
, mm
;
4266 case elfcpp::EM_SPARC32PLUS
:
4267 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4270 case elfcpp::EM_SPARC
:
4271 case elfcpp::EM_SPARCV9
:
4278 if (!this->elf_flags_set_
)
4280 this->elf_flags_
= flags
;
4281 this->elf_flags_set_
= true;
4285 // Accumulate cpu feature bits.
4286 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4287 | elfcpp::EF_SPARC_SUN_US1
4288 | elfcpp::EF_SPARC_HAL_R1
4289 | elfcpp::EF_SPARC_SUN_US3
));
4291 // Bump the memory model setting to the most restrictive
4292 // one we encounter.
4293 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4294 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4297 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4299 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4300 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4302 else if (mm
== elfcpp::EF_SPARCV9_PSO
4303 && omm
== elfcpp::EF_SPARCV9_RMO
)
4305 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4306 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4311 // Validate that the little-endian flag matches how we've
4312 // been instantiated.
4313 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4316 gold_error(_("%s: little endian elf flag set on BE object"),
4319 gold_error(_("%s: little endian elf flag clear on LE object"),
4323 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4326 // Adjust ELF file header.
4328 template<int size
, bool big_endian
>
4330 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4331 unsigned char* view
,
4334 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4336 oehdr
.put_e_machine(this->elf_machine_
);
4337 oehdr
.put_e_flags(this->elf_flags_
);
4339 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4342 // The selector for sparc object files.
4344 template<int size
, bool big_endian
>
4345 class Target_selector_sparc
: public Target_selector
4348 Target_selector_sparc()
4349 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4350 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4351 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4355 do_recognize(Input_file
*, off_t
, int machine
, int, int)
4360 if (machine
!= elfcpp::EM_SPARCV9
)
4365 if (machine
!= elfcpp::EM_SPARC
4366 && machine
!= elfcpp::EM_SPARC32PLUS
)
4374 return this->instantiate_target();
4378 do_instantiate_target()
4379 { return new Target_sparc
<size
, big_endian
>(); }
4382 Target_selector_sparc
<32, true> target_selector_sparc32
;
4383 Target_selector_sparc
<64, true> target_selector_sparc64
;
4385 } // End anonymous namespace.