1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
),
64 elf_machine_(sparc_info
.machine_code
), elf_flags_(0),
69 // Process the relocations to determine unreferenced sections for
70 // garbage collection.
72 gc_process_relocs(Symbol_table
* symtab
,
74 Sized_relobj_file
<size
, big_endian
>* object
,
75 unsigned int data_shndx
,
77 const unsigned char* prelocs
,
79 Output_section
* output_section
,
80 bool needs_special_offset_handling
,
81 size_t local_symbol_count
,
82 const unsigned char* plocal_symbols
);
84 // Scan the relocations to look for symbol adjustments.
86 scan_relocs(Symbol_table
* symtab
,
88 Sized_relobj_file
<size
, big_endian
>* object
,
89 unsigned int data_shndx
,
91 const unsigned char* prelocs
,
93 Output_section
* output_section
,
94 bool needs_special_offset_handling
,
95 size_t local_symbol_count
,
96 const unsigned char* plocal_symbols
);
97 // Finalize the sections.
99 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
101 // Return the value to use for a dynamic which requires special
104 do_dynsym_value(const Symbol
*) const;
106 // Relocate a section.
108 relocate_section(const Relocate_info
<size
, big_endian
>*,
109 unsigned int sh_type
,
110 const unsigned char* prelocs
,
112 Output_section
* output_section
,
113 bool needs_special_offset_handling
,
115 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
116 section_size_type view_size
,
117 const Reloc_symbol_changes
*);
119 // Scan the relocs during a relocatable link.
121 scan_relocatable_relocs(Symbol_table
* symtab
,
123 Sized_relobj_file
<size
, big_endian
>* object
,
124 unsigned int data_shndx
,
125 unsigned int sh_type
,
126 const unsigned char* prelocs
,
128 Output_section
* output_section
,
129 bool needs_special_offset_handling
,
130 size_t local_symbol_count
,
131 const unsigned char* plocal_symbols
,
132 Relocatable_relocs
*);
134 // Relocate a section during a relocatable link.
136 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
137 unsigned int sh_type
,
138 const unsigned char* prelocs
,
140 Output_section
* output_section
,
141 off_t offset_in_output_section
,
142 const Relocatable_relocs
*,
144 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
145 section_size_type view_size
,
146 unsigned char* reloc_view
,
147 section_size_type reloc_view_size
);
148 // Return whether SYM is defined by the ABI.
150 do_is_defined_by_abi(const Symbol
* sym
) const
152 // XXX Really need to support this better...
153 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
156 return strcmp(sym
->name(), "___tls_get_addr") == 0;
159 // Return the PLT address to use for a global symbol.
161 do_plt_address_for_global(const Symbol
* gsym
) const
162 { return this->plt_section()->address_for_global(gsym
); }
165 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
166 { return this->plt_section()->address_for_local(relobj
, symndx
); }
168 // Return whether there is a GOT section.
170 has_got_section() const
171 { return this->got_
!= NULL
; }
173 // Return the size of the GOT section.
177 gold_assert(this->got_
!= NULL
);
178 return this->got_
->data_size();
181 // Return the number of entries in the GOT.
183 got_entry_count() const
185 if (this->got_
== NULL
)
187 return this->got_size() / (size
/ 8);
190 // Return the address of the GOT.
194 if (this->got_
== NULL
)
196 return this->got_
->address();
199 // Return the number of entries in the PLT.
201 plt_entry_count() const;
203 // Return the offset of the first non-reserved PLT entry.
205 first_plt_entry_offset() const;
207 // Return the size of each PLT entry.
209 plt_entry_size() const;
212 // Make an ELF object.
214 do_make_elf_object(const std::string
&, Input_file
*, off_t
,
215 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
);
218 do_adjust_elf_header(unsigned char* view
, int len
) const;
222 // The class which scans relocations.
227 : issued_non_pic_error_(false)
231 get_reference_flags(unsigned int r_type
);
234 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
235 Sized_relobj_file
<size
, big_endian
>* object
,
236 unsigned int data_shndx
,
237 Output_section
* output_section
,
238 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
239 const elfcpp::Sym
<size
, big_endian
>& lsym
);
242 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
243 Sized_relobj_file
<size
, big_endian
>* object
,
244 unsigned int data_shndx
,
245 Output_section
* output_section
,
246 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
250 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
252 Sized_relobj_file
<size
, big_endian
>* ,
255 const elfcpp::Rela
<size
, big_endian
>& ,
257 const elfcpp::Sym
<size
, big_endian
>&)
261 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
263 Sized_relobj_file
<size
, big_endian
>* ,
266 const elfcpp::Rela
<size
,
268 unsigned int , Symbol
*)
274 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
275 unsigned int r_type
);
278 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
279 unsigned int r_type
, Symbol
*);
282 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
283 Target_sparc
* target
);
286 check_non_pic(Relobj
*, unsigned int r_type
);
289 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
290 unsigned int r_type
);
292 // Whether we have issued an error about a non-PIC compilation.
293 bool issued_non_pic_error_
;
296 // The class which implements relocation.
301 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
306 if (this->ignore_gd_add_
)
308 // FIXME: This needs to specify the location somehow.
309 gold_error(_("missing expected TLS relocation"));
313 // Do a relocation. Return false if the caller should not issue
314 // any warnings about this relocation.
316 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
317 Output_section
*, size_t relnum
,
318 const elfcpp::Rela
<size
, big_endian
>&,
319 unsigned int r_type
, const Sized_symbol
<size
>*,
320 const Symbol_value
<size
>*,
322 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
326 // Do a TLS relocation.
328 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
329 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
330 unsigned int r_type
, const Sized_symbol
<size
>*,
331 const Symbol_value
<size
>*,
333 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
336 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
339 // If we hit a reloc at this view address, adjust it back by 4 bytes.
340 unsigned char *reloc_adjust_addr_
;
343 // A class which returns the size required for a relocation type,
344 // used while scanning relocs during a relocatable link.
345 class Relocatable_size_for_reloc
349 get_size_for_reloc(unsigned int, Relobj
*);
352 // Get the GOT section, creating it if necessary.
353 Output_data_got
<size
, big_endian
>*
354 got_section(Symbol_table
*, Layout
*);
356 // Create the PLT section.
358 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
360 // Create a PLT entry for a global symbol.
362 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
364 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
366 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
367 Sized_relobj_file
<size
, big_endian
>* relobj
,
368 unsigned int local_sym_index
);
370 // Create a GOT entry for the TLS module index.
372 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
373 Sized_relobj_file
<size
, big_endian
>* object
);
375 // Return the gsym for "__tls_get_addr". Cache if not already
378 tls_get_addr_sym(Symbol_table
* symtab
)
380 if (!this->tls_get_addr_sym_
)
381 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
382 gold_assert(this->tls_get_addr_sym_
);
383 return this->tls_get_addr_sym_
;
386 // Get the PLT section.
387 Output_data_plt_sparc
<size
, big_endian
>*
390 gold_assert(this->plt_
!= NULL
);
394 // Get the dynamic reloc section, creating it if necessary.
396 rela_dyn_section(Layout
*);
398 // Get the section to use for IFUNC relocations.
400 rela_ifunc_section(Layout
*);
402 // Copy a relocation against a global symbol.
404 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
405 Sized_relobj_file
<size
, big_endian
>* object
,
406 unsigned int shndx
, Output_section
* output_section
,
407 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
409 this->copy_relocs_
.copy_reloc(symtab
, layout
,
410 symtab
->get_sized_symbol
<size
>(sym
),
411 object
, shndx
, output_section
,
412 reloc
, this->rela_dyn_section(layout
));
415 // Information about this specific target which we pass to the
416 // general Target structure.
417 static Target::Target_info sparc_info
;
419 // The types of GOT entries needed for this platform.
420 // These values are exposed to the ABI in an incremental link.
421 // Do not renumber existing values without changing the version
422 // number of the .gnu_incremental_inputs section.
425 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
426 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
427 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
431 Output_data_got
<size
, big_endian
>* got_
;
433 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
434 // The dynamic reloc section.
435 Reloc_section
* rela_dyn_
;
436 // The section to use for IFUNC relocs.
437 Reloc_section
* rela_ifunc_
;
438 // Relocs saved to avoid a COPY reloc.
439 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
440 // Space for variables copied with a COPY reloc.
441 Output_data_space
* dynbss_
;
442 // Offset of the GOT entry for the TLS module index;
443 unsigned int got_mod_index_offset_
;
444 // Cached pointer to __tls_get_addr symbol
445 Symbol
* tls_get_addr_sym_
;
446 // Accumulated elf machine type
447 elfcpp::Elf_Half elf_machine_
;
448 // Accumulated elf header flags
449 elfcpp::Elf_Word elf_flags_
;
450 // Whether elf_flags_ has been set for the first time yet
455 Target::Target_info Target_sparc
<32, true>::sparc_info
=
458 true, // is_big_endian
459 elfcpp::EM_SPARC
, // machine_code
460 false, // has_make_symbol
461 false, // has_resolve
462 false, // has_code_fill
463 true, // is_default_stack_executable
464 false, // can_icf_inline_merge_sections
466 "/usr/lib/ld.so.1", // dynamic_linker
467 0x00010000, // default_text_segment_address
468 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
469 8 * 1024, // common_pagesize (overridable by -z common-page-size)
470 elfcpp::SHN_UNDEF
, // small_common_shndx
471 elfcpp::SHN_UNDEF
, // large_common_shndx
472 0, // small_common_section_flags
473 0, // large_common_section_flags
474 NULL
, // attributes_section
475 NULL
// attributes_vendor
479 Target::Target_info Target_sparc
<64, true>::sparc_info
=
482 true, // is_big_endian
483 elfcpp::EM_SPARCV9
, // machine_code
484 false, // has_make_symbol
485 false, // has_resolve
486 false, // has_code_fill
487 true, // is_default_stack_executable
488 false, // can_icf_inline_merge_sections
490 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
491 0x100000, // default_text_segment_address
492 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
493 8 * 1024, // common_pagesize (overridable by -z common-page-size)
494 elfcpp::SHN_UNDEF
, // small_common_shndx
495 elfcpp::SHN_UNDEF
, // large_common_shndx
496 0, // small_common_section_flags
497 0, // large_common_section_flags
498 NULL
, // attributes_section
499 NULL
// attributes_vendor
502 // We have to take care here, even when operating in little-endian
503 // mode, sparc instructions are still big endian.
504 template<int size
, bool big_endian
>
505 class Sparc_relocate_functions
508 // Do a simple relocation with the addend in the relocation.
509 template<int valsize
>
511 rela(unsigned char* view
,
512 unsigned int right_shift
,
513 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
514 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
515 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
517 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
518 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
519 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
520 Valtype reloc
= ((value
+ addend
) >> right_shift
);
525 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
528 // Do a simple relocation using a symbol value with the addend in
530 template<int valsize
>
532 rela(unsigned char* view
,
533 unsigned int right_shift
,
534 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
535 const Sized_relobj_file
<size
, big_endian
>* object
,
536 const Symbol_value
<size
>* psymval
,
537 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
539 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
540 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
541 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
542 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
547 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
550 // Do a simple relocation using a symbol value with the addend in
551 // the relocation, unaligned.
552 template<int valsize
>
554 rela_ua(unsigned char* view
,
555 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
556 const Sized_relobj_file
<size
, big_endian
>* object
,
557 const Symbol_value
<size
>* psymval
,
558 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
560 typedef typename
elfcpp::Swap_unaligned
<valsize
,
561 big_endian
>::Valtype Valtype
;
562 unsigned char* wv
= view
;
563 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
564 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
569 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
572 // Do a simple PC relative relocation with a Symbol_value with the
573 // addend in the relocation.
574 template<int valsize
>
576 pcrela(unsigned char* view
,
577 unsigned int right_shift
,
578 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
579 const Sized_relobj_file
<size
, big_endian
>* object
,
580 const Symbol_value
<size
>* psymval
,
581 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
582 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
584 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
585 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
586 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
587 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
593 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
596 template<int valsize
>
598 pcrela_unaligned(unsigned char* view
,
599 const Sized_relobj_file
<size
, big_endian
>* object
,
600 const Symbol_value
<size
>* psymval
,
601 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
602 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
604 typedef typename
elfcpp::Swap_unaligned
<valsize
,
605 big_endian
>::Valtype Valtype
;
606 unsigned char* wv
= view
;
607 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
609 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
612 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
613 typedef Sparc_relocate_functions
<size
, true> This_insn
;
616 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
618 wdisp30(unsigned char* view
,
619 const Sized_relobj_file
<size
, big_endian
>* object
,
620 const Symbol_value
<size
>* psymval
,
621 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
622 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
624 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
625 psymval
, addend
, address
);
628 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
630 wdisp22(unsigned char* view
,
631 const Sized_relobj_file
<size
, big_endian
>* object
,
632 const Symbol_value
<size
>* psymval
,
633 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
634 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
636 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
637 psymval
, addend
, address
);
640 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
642 wdisp19(unsigned char* view
,
643 const Sized_relobj_file
<size
, big_endian
>* object
,
644 const Symbol_value
<size
>* psymval
,
645 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
646 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
648 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
649 psymval
, addend
, address
);
652 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
654 wdisp16(unsigned char* view
,
655 const Sized_relobj_file
<size
, big_endian
>* object
,
656 const Symbol_value
<size
>* psymval
,
657 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
658 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
660 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
661 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
662 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
663 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
666 // The relocation value is split between the low 14 bits,
668 val
&= ~((0x3 << 20) | 0x3fff);
669 reloc
= (((reloc
& 0xc000) << (20 - 14))
670 | (reloc
& 0x3ffff));
672 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
675 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
677 wdisp10(unsigned char* view
,
678 const Sized_relobj_file
<size
, big_endian
>* object
,
679 const Symbol_value
<size
>* psymval
,
680 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
681 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
683 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
684 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
685 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
686 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
689 // The relocation value is split between the low bits 5-12,
690 // and high bits 19-20.
691 val
&= ~((0x3 << 19) | (0xff << 5));
692 reloc
= (((reloc
& 0x300) << (19 - 8))
693 | ((reloc
& 0xff) << (5 - 0)));
695 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
698 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
700 pc22(unsigned char* view
,
701 const Sized_relobj_file
<size
, big_endian
>* object
,
702 const Symbol_value
<size
>* psymval
,
703 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
704 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
706 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
707 psymval
, addend
, address
);
710 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
712 pc10(unsigned char* view
,
713 const Sized_relobj_file
<size
, big_endian
>* object
,
714 const Symbol_value
<size
>* psymval
,
715 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
716 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
718 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
719 psymval
, addend
, address
);
722 // R_SPARC_HI22: (Symbol + Addend) >> 10
724 hi22(unsigned char* view
,
725 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
726 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
728 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
731 // R_SPARC_HI22: (Symbol + Addend) >> 10
733 hi22(unsigned char* view
,
734 const Sized_relobj_file
<size
, big_endian
>* object
,
735 const Symbol_value
<size
>* psymval
,
736 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
738 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
741 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
743 pcplt22(unsigned char* view
,
744 const Sized_relobj_file
<size
, big_endian
>* object
,
745 const Symbol_value
<size
>* psymval
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
747 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
749 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
750 psymval
, addend
, address
);
753 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
755 lo10(unsigned char* view
,
756 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
757 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
759 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
762 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
764 lo10(unsigned char* view
,
765 const Sized_relobj_file
<size
, big_endian
>* object
,
766 const Symbol_value
<size
>* psymval
,
767 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
769 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
772 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
774 lo10(unsigned char* view
,
775 const Sized_relobj_file
<size
, big_endian
>* object
,
776 const Symbol_value
<size
>* psymval
,
777 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
778 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
780 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
781 psymval
, addend
, address
);
784 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
786 olo10(unsigned char* view
,
787 const Sized_relobj_file
<size
, big_endian
>* object
,
788 const Symbol_value
<size
>* psymval
,
789 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
790 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
792 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
793 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
794 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
795 Valtype reloc
= psymval
->value(object
, addend
);
802 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
805 // R_SPARC_22: (Symbol + Addend)
807 rela32_22(unsigned char* view
,
808 const Sized_relobj_file
<size
, big_endian
>* object
,
809 const Symbol_value
<size
>* psymval
,
810 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
812 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
815 // R_SPARC_13: (Symbol + Addend)
817 rela32_13(unsigned char* view
,
818 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
819 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
821 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
824 // R_SPARC_13: (Symbol + Addend)
826 rela32_13(unsigned char* view
,
827 const Sized_relobj_file
<size
, big_endian
>* object
,
828 const Symbol_value
<size
>* psymval
,
829 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
831 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
834 // R_SPARC_UA16: (Symbol + Addend)
836 ua16(unsigned char* view
,
837 const Sized_relobj_file
<size
, big_endian
>* object
,
838 const Symbol_value
<size
>* psymval
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
841 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
844 // R_SPARC_UA32: (Symbol + Addend)
846 ua32(unsigned char* view
,
847 const Sized_relobj_file
<size
, big_endian
>* object
,
848 const Symbol_value
<size
>* psymval
,
849 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
851 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
854 // R_SPARC_UA64: (Symbol + Addend)
856 ua64(unsigned char* view
,
857 const Sized_relobj_file
<size
, big_endian
>* object
,
858 const Symbol_value
<size
>* psymval
,
859 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
861 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
862 object
, psymval
, addend
);
865 // R_SPARC_DISP8: (Symbol + Addend - Address)
867 disp8(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
,
871 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
873 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
877 // R_SPARC_DISP16: (Symbol + Addend - Address)
879 disp16(unsigned char* view
,
880 const Sized_relobj_file
<size
, big_endian
>* object
,
881 const Symbol_value
<size
>* psymval
,
882 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
883 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
885 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
889 // R_SPARC_DISP32: (Symbol + Addend - Address)
891 disp32(unsigned char* view
,
892 const Sized_relobj_file
<size
, big_endian
>* object
,
893 const Symbol_value
<size
>* psymval
,
894 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
895 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
897 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
901 // R_SPARC_DISP64: (Symbol + Addend - Address)
903 disp64(unsigned char* view
,
904 const Sized_relobj_file
<size
, big_endian
>* object
,
905 const Symbol_value
<size
>* psymval
,
906 elfcpp::Elf_Xword addend
,
907 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
909 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
913 // R_SPARC_H34: (Symbol + Addend) >> 12
915 h34(unsigned char* view
,
916 const Sized_relobj_file
<size
, big_endian
>* object
,
917 const Symbol_value
<size
>* psymval
,
918 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
920 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
923 // R_SPARC_H44: (Symbol + Addend) >> 22
925 h44(unsigned char* view
,
926 const Sized_relobj_file
<size
, big_endian
>* object
,
927 const Symbol_value
<size
>* psymval
,
928 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
930 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
933 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
935 m44(unsigned char* view
,
936 const Sized_relobj_file
<size
, big_endian
>* object
,
937 const Symbol_value
<size
>* psymval
,
938 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
940 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
943 // R_SPARC_L44: (Symbol + Addend) & 0xfff
945 l44(unsigned char* view
,
946 const Sized_relobj_file
<size
, big_endian
>* object
,
947 const Symbol_value
<size
>* psymval
,
948 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
950 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
953 // R_SPARC_HH22: (Symbol + Addend) >> 42
955 hh22(unsigned char* view
,
956 const Sized_relobj_file
<size
, big_endian
>* object
,
957 const Symbol_value
<size
>* psymval
,
958 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
960 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
963 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
965 pc_hh22(unsigned char* view
,
966 const Sized_relobj_file
<size
, big_endian
>* object
,
967 const Symbol_value
<size
>* psymval
,
968 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
969 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
971 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
972 psymval
, addend
, address
);
975 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
977 hm10(unsigned char* view
,
978 const Sized_relobj_file
<size
, big_endian
>* object
,
979 const Symbol_value
<size
>* psymval
,
980 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
982 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
985 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
987 pc_hm10(unsigned char* view
,
988 const Sized_relobj_file
<size
, big_endian
>* object
,
989 const Symbol_value
<size
>* psymval
,
990 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
991 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
993 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
994 psymval
, addend
, address
);
997 // R_SPARC_11: (Symbol + Addend)
999 rela32_11(unsigned char* view
,
1000 const Sized_relobj_file
<size
, big_endian
>* object
,
1001 const Symbol_value
<size
>* psymval
,
1002 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1004 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
1007 // R_SPARC_10: (Symbol + Addend)
1009 rela32_10(unsigned char* view
,
1010 const Sized_relobj_file
<size
, big_endian
>* object
,
1011 const Symbol_value
<size
>* psymval
,
1012 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1014 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
1017 // R_SPARC_7: (Symbol + Addend)
1019 rela32_7(unsigned char* view
,
1020 const Sized_relobj_file
<size
, big_endian
>* object
,
1021 const Symbol_value
<size
>* psymval
,
1022 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1024 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1027 // R_SPARC_6: (Symbol + Addend)
1029 rela32_6(unsigned char* view
,
1030 const Sized_relobj_file
<size
, big_endian
>* object
,
1031 const Symbol_value
<size
>* psymval
,
1032 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1034 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1037 // R_SPARC_5: (Symbol + Addend)
1039 rela32_5(unsigned char* view
,
1040 const Sized_relobj_file
<size
, big_endian
>* object
,
1041 const Symbol_value
<size
>* psymval
,
1042 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1044 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1047 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1049 ldo_hix22(unsigned char* view
,
1050 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1051 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1053 This_insn::hi22(view
, value
, addend
);
1056 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1058 ldo_lox10(unsigned char* view
,
1059 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1060 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1062 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1063 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1064 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1065 Valtype reloc
= (value
+ addend
);
1070 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1073 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1075 hix22(unsigned char* view
,
1076 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1077 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1079 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1080 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1081 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1082 Valtype reloc
= (value
+ addend
);
1086 reloc
^= ~(Valtype
)0;
1091 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1094 // R_SPARC_GOTDATA_OP_HIX22: @gdopoff(Symbol + Addend) >> 10
1096 gdop_hix22(unsigned char* view
,
1097 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1098 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1100 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1101 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1102 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1103 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1108 reloc
^= ~static_cast<int32_t>(0);
1113 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1116 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1118 hix22(unsigned char* view
,
1119 const Sized_relobj_file
<size
, big_endian
>* object
,
1120 const Symbol_value
<size
>* psymval
,
1121 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1123 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1124 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1125 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1126 Valtype reloc
= psymval
->value(object
, addend
);
1130 reloc
^= ~(Valtype
)0;
1135 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1139 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1141 lox10(unsigned char* view
,
1142 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1143 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1145 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1146 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1147 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1148 Valtype reloc
= (value
+ addend
);
1154 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1157 // R_SPARC_GOTDATA_OP_LOX10: (@gdopoff(Symbol + Addend) & 0x3ff) | 0x1c00
1159 gdop_lox10(unsigned char* view
,
1160 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1161 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1163 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1164 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1165 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1166 int32_t reloc
= static_cast<int32_t>(value
+ addend
);
1169 reloc
= (reloc
& 0x3ff) | 0x1c00;
1171 reloc
= (reloc
& 0x3ff);
1174 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1177 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1179 lox10(unsigned char* view
,
1180 const Sized_relobj_file
<size
, big_endian
>* object
,
1181 const Symbol_value
<size
>* psymval
,
1182 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1184 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1185 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1186 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1187 Valtype reloc
= psymval
->value(object
, addend
);
1193 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1197 // Get the GOT section, creating it if necessary.
1199 template<int size
, bool big_endian
>
1200 Output_data_got
<size
, big_endian
>*
1201 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1204 if (this->got_
== NULL
)
1206 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1208 this->got_
= new Output_data_got
<size
, big_endian
>();
1210 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1212 | elfcpp::SHF_WRITE
),
1213 this->got_
, ORDER_RELRO
, true);
1215 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1216 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1217 Symbol_table::PREDEFINED
,
1219 0, 0, elfcpp::STT_OBJECT
,
1221 elfcpp::STV_HIDDEN
, 0,
1228 // Get the dynamic reloc section, creating it if necessary.
1230 template<int size
, bool big_endian
>
1231 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1232 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1234 if (this->rela_dyn_
== NULL
)
1236 gold_assert(layout
!= NULL
);
1237 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1238 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1239 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1240 ORDER_DYNAMIC_RELOCS
, false);
1242 return this->rela_dyn_
;
1245 // Get the section to use for IFUNC relocs, creating it if
1246 // necessary. These go in .rela.dyn, but only after all other dynamic
1247 // relocations. They need to follow the other dynamic relocations so
1248 // that they can refer to global variables initialized by those
1251 template<int size
, bool big_endian
>
1252 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1253 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1255 if (this->rela_ifunc_
== NULL
)
1257 // Make sure we have already created the dynamic reloc section.
1258 this->rela_dyn_section(layout
);
1259 this->rela_ifunc_
= new Reloc_section(false);
1260 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1261 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1262 ORDER_DYNAMIC_RELOCS
, false);
1263 gold_assert(this->rela_dyn_
->output_section()
1264 == this->rela_ifunc_
->output_section());
1266 return this->rela_ifunc_
;
1269 // A class to handle the PLT data.
1271 template<int size
, bool big_endian
>
1272 class Output_data_plt_sparc
: public Output_section_data
1275 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1276 size
, big_endian
> Reloc_section
;
1278 Output_data_plt_sparc(Layout
*);
1280 // Add an entry to the PLT.
1281 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1283 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1285 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1286 Sized_relobj_file
<size
, big_endian
>* relobj
,
1287 unsigned int local_sym_index
);
1289 // Return the .rela.plt section data.
1290 const Reloc_section
* rel_plt() const
1295 // Return where the IFUNC relocations should go.
1297 rela_ifunc(Symbol_table
*, Layout
*);
1300 emit_pending_ifunc_relocs();
1302 // Return whether we created a section for IFUNC relocations.
1304 has_ifunc_section() const
1305 { return this->ifunc_rel_
!= NULL
; }
1307 // Return the number of PLT entries.
1310 { return this->count_
+ this->ifunc_count_
; }
1312 // Return the offset of the first non-reserved PLT entry.
1314 first_plt_entry_offset()
1315 { return 4 * base_plt_entry_size
; }
1317 // Return the size of a PLT entry.
1319 get_plt_entry_size()
1320 { return base_plt_entry_size
; }
1322 // Return the PLT address to use for a global symbol.
1324 address_for_global(const Symbol
*);
1326 // Return the PLT address to use for a local symbol.
1328 address_for_local(const Relobj
*, unsigned int symndx
);
1331 void do_adjust_output_section(Output_section
* os
);
1333 // Write to a map file.
1335 do_print_to_mapfile(Mapfile
* mapfile
) const
1336 { mapfile
->print_output_data(this, _("** PLT")); }
1339 // The size of an entry in the PLT.
1340 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1342 static const unsigned int plt_entries_per_block
= 160;
1343 static const unsigned int plt_insn_chunk_size
= 24;
1344 static const unsigned int plt_pointer_chunk_size
= 8;
1345 static const unsigned int plt_block_size
=
1346 (plt_entries_per_block
1347 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1350 plt_index_to_offset(unsigned int index
)
1352 section_offset_type offset
;
1354 if (size
== 32 || index
< 32768)
1355 offset
= index
* base_plt_entry_size
;
1358 unsigned int ext_index
= index
- 32768;
1360 offset
= (32768 * base_plt_entry_size
)
1361 + ((ext_index
/ plt_entries_per_block
)
1363 + ((ext_index
% plt_entries_per_block
)
1364 * plt_insn_chunk_size
);
1369 // Set the final size.
1371 set_final_data_size()
1373 unsigned int full_count
= this->entry_count() + 4;
1374 unsigned int extra
= (size
== 32 ? 4 : 0);
1375 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1377 return this->set_data_size(sz
);
1380 // Write out the PLT data.
1382 do_write(Output_file
*);
1388 unsigned int plt_index
;
1394 Sized_relobj_file
<size
, big_endian
>* object
;
1395 unsigned int local_sym_index
;
1396 unsigned int plt_index
;
1399 // The reloc section.
1400 Reloc_section
* rel_
;
1401 // The IFUNC relocations, if necessary. These must follow the
1402 // regular relocations.
1403 Reloc_section
* ifunc_rel_
;
1404 // The number of PLT entries.
1405 unsigned int count_
;
1406 // The number of PLT entries for IFUNC symbols.
1407 unsigned int ifunc_count_
;
1408 // Global STT_GNU_IFUNC symbols.
1409 std::vector
<Global_ifunc
> global_ifuncs_
;
1410 // Local STT_GNU_IFUNC symbols.
1411 std::vector
<Local_ifunc
> local_ifuncs_
;
1414 // Define the constants as required by C++ standard.
1416 template<int size
, bool big_endian
>
1417 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1419 template<int size
, bool big_endian
>
1421 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1423 template<int size
, bool big_endian
>
1424 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1426 template<int size
, bool big_endian
>
1428 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1430 template<int size
, bool big_endian
>
1431 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1433 // Create the PLT section. The ordinary .got section is an argument,
1434 // since we need to refer to the start.
1436 template<int size
, bool big_endian
>
1437 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1438 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1439 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1441 this->rel_
= new Reloc_section(false);
1442 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1443 elfcpp::SHF_ALLOC
, this->rel_
,
1444 ORDER_DYNAMIC_PLT_RELOCS
, false);
1447 template<int size
, bool big_endian
>
1449 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1454 // Add an entry to the PLT.
1456 template<int size
, bool big_endian
>
1458 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1462 gold_assert(!gsym
->has_plt_offset());
1464 section_offset_type plt_offset
;
1467 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1468 && gsym
->can_use_relative_reloc(false))
1470 index
= this->ifunc_count_
;
1471 plt_offset
= plt_index_to_offset(index
);
1472 gsym
->set_plt_offset(plt_offset
);
1473 ++this->ifunc_count_
;
1474 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1476 struct Global_ifunc gi
;
1479 gi
.plt_index
= index
;
1480 this->global_ifuncs_
.push_back(gi
);
1484 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1485 gsym
->set_plt_offset(plt_offset
);
1487 gsym
->set_needs_dynsym_entry();
1488 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1492 // Note that we don't need to save the symbol. The contents of the
1493 // PLT are independent of which symbols are used. The symbols only
1494 // appear in the relocations.
1497 template<int size
, bool big_endian
>
1499 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1500 Symbol_table
* symtab
,
1502 Sized_relobj_file
<size
, big_endian
>* relobj
,
1503 unsigned int local_sym_index
)
1505 unsigned int index
= this->ifunc_count_
;
1506 section_offset_type plt_offset
;
1508 plt_offset
= plt_index_to_offset(index
);
1509 ++this->ifunc_count_
;
1511 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1513 struct Local_ifunc li
;
1516 li
.local_sym_index
= local_sym_index
;
1517 li
.plt_index
= index
;
1518 this->local_ifuncs_
.push_back(li
);
1523 // Emit any pending IFUNC plt relocations.
1525 template<int size
, bool big_endian
>
1527 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1529 // Emit any pending IFUNC relocs.
1530 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1531 this->global_ifuncs_
.begin();
1532 p
!= this->global_ifuncs_
.end();
1535 section_offset_type plt_offset
;
1538 index
= this->count_
+ p
->plt_index
+ 4;
1539 plt_offset
= this->plt_index_to_offset(index
);
1540 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1541 this, plt_offset
, 0);
1544 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1545 this->local_ifuncs_
.begin();
1546 p
!= this->local_ifuncs_
.end();
1549 section_offset_type plt_offset
;
1552 index
= this->count_
+ p
->plt_index
+ 4;
1553 plt_offset
= this->plt_index_to_offset(index
);
1554 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1555 elfcpp::R_SPARC_JMP_IREL
,
1556 this, plt_offset
, 0);
1560 // Return where the IFUNC relocations should go in the PLT. These
1561 // follow the non-IFUNC relocations.
1563 template<int size
, bool big_endian
>
1564 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1565 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1566 Symbol_table
* symtab
,
1569 if (this->ifunc_rel_
== NULL
)
1571 this->ifunc_rel_
= new Reloc_section(false);
1572 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1573 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1574 ORDER_DYNAMIC_PLT_RELOCS
, false);
1575 gold_assert(this->ifunc_rel_
->output_section()
1576 == this->rel_
->output_section());
1578 if (parameters
->doing_static_link())
1580 // A statically linked executable will only have a .rel.plt
1581 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1582 // relocs for STT_GNU_IFUNC symbols. The library will use
1583 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1584 // at program startup time.
1585 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1586 Symbol_table::PREDEFINED
,
1587 this->ifunc_rel_
, 0, 0,
1588 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1589 elfcpp::STV_HIDDEN
, 0, false, true);
1590 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1591 Symbol_table::PREDEFINED
,
1592 this->ifunc_rel_
, 0, 0,
1593 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1594 elfcpp::STV_HIDDEN
, 0, true, true);
1597 return this->ifunc_rel_
;
1600 // Return the PLT address to use for a global symbol.
1602 template<int size
, bool big_endian
>
1604 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1606 uint64_t offset
= 0;
1607 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1608 && gsym
->can_use_relative_reloc(false))
1609 offset
= plt_index_to_offset(this->count_
+ 4);
1610 return this->address() + offset
;
1613 // Return the PLT address to use for a local symbol. These are always
1614 // IRELATIVE relocs.
1616 template<int size
, bool big_endian
>
1618 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1622 return this->address() + plt_index_to_offset(this->count_
+ 4);
1625 static const unsigned int sparc_nop
= 0x01000000;
1626 static const unsigned int sparc_sethi_g1
= 0x03000000;
1627 static const unsigned int sparc_branch_always
= 0x30800000;
1628 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1629 static const unsigned int sparc_mov
= 0x80100000;
1630 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1631 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1632 static const unsigned int sparc_call_plus_8
= 0x40000002;
1633 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1634 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1635 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1637 // Write out the PLT.
1639 template<int size
, bool big_endian
>
1641 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1643 const off_t offset
= this->offset();
1644 const section_size_type oview_size
=
1645 convert_to_section_size_type(this->data_size());
1646 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1647 unsigned char* pov
= oview
;
1649 memset(pov
, 0, base_plt_entry_size
* 4);
1650 pov
+= this->first_plt_entry_offset();
1652 unsigned int plt_offset
= base_plt_entry_size
* 4;
1653 const unsigned int count
= this->entry_count();
1659 limit
= (count
> 32768 ? 32768 : count
);
1661 for (unsigned int i
= 0; i
< limit
; ++i
)
1663 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1664 sparc_sethi_g1
+ plt_offset
);
1665 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1666 sparc_branch_always_pt
+
1667 (((base_plt_entry_size
-
1668 (plt_offset
+ 4)) >> 2) &
1670 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1671 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1672 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1673 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1674 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1675 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1677 pov
+= base_plt_entry_size
;
1678 plt_offset
+= base_plt_entry_size
;
1683 unsigned int ext_cnt
= count
- 32768;
1684 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1686 for (unsigned int i
= 0; i
< blks
; ++i
)
1688 unsigned int data_off
= (plt_entries_per_block
1689 * plt_insn_chunk_size
) - 4;
1691 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1693 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1695 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1697 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1699 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1700 sparc_ldx_o7_imm_g1
+
1701 (data_off
& 0x1fff));
1702 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1703 sparc_jmpl_o7_g1_g1
);
1704 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1707 elfcpp::Swap
<64, big_endian
>::writeval(
1708 pov
+ 0x4 + data_off
,
1709 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1711 pov
+= plt_insn_chunk_size
;
1716 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1717 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1719 unsigned int data_off
= (sub_blk_cnt
1720 * plt_insn_chunk_size
) - 4;
1722 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1724 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1726 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1728 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1730 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1731 sparc_ldx_o7_imm_g1
+
1732 (data_off
& 0x1fff));
1733 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1734 sparc_jmpl_o7_g1_g1
);
1735 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1738 elfcpp::Swap
<64, big_endian
>::writeval(
1739 pov
+ 0x4 + data_off
,
1740 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1742 pov
+= plt_insn_chunk_size
;
1750 for (unsigned int i
= 0; i
< count
; ++i
)
1752 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1753 sparc_sethi_g1
+ plt_offset
);
1754 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1755 sparc_branch_always
+
1756 (((- (plt_offset
+ 4)) >> 2) &
1758 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1760 pov
+= base_plt_entry_size
;
1761 plt_offset
+= base_plt_entry_size
;
1764 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1768 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1770 of
->write_output_view(offset
, oview_size
, oview
);
1773 // Create the PLT section.
1775 template<int size
, bool big_endian
>
1777 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1780 // Create the GOT sections first.
1781 this->got_section(symtab
, layout
);
1783 // Ensure that .rela.dyn always appears before .rela.plt This is
1784 // necessary due to how, on Sparc and some other targets, .rela.dyn
1785 // needs to include .rela.plt in it's range.
1786 this->rela_dyn_section(layout
);
1788 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1789 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1791 | elfcpp::SHF_EXECINSTR
1792 | elfcpp::SHF_WRITE
),
1793 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1795 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1796 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1797 Symbol_table::PREDEFINED
,
1799 0, 0, elfcpp::STT_OBJECT
,
1801 elfcpp::STV_HIDDEN
, 0,
1805 // Create a PLT entry for a global symbol.
1807 template<int size
, bool big_endian
>
1809 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1813 if (gsym
->has_plt_offset())
1816 if (this->plt_
== NULL
)
1817 this->make_plt_section(symtab
, layout
);
1819 this->plt_
->add_entry(symtab
, layout
, gsym
);
1822 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1824 template<int size
, bool big_endian
>
1826 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1827 Symbol_table
* symtab
,
1829 Sized_relobj_file
<size
, big_endian
>* relobj
,
1830 unsigned int local_sym_index
)
1832 if (relobj
->local_has_plt_offset(local_sym_index
))
1834 if (this->plt_
== NULL
)
1835 this->make_plt_section(symtab
, layout
);
1836 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1839 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1842 // Return the number of entries in the PLT.
1844 template<int size
, bool big_endian
>
1846 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1848 if (this->plt_
== NULL
)
1850 return this->plt_
->entry_count();
1853 // Return the offset of the first non-reserved PLT entry.
1855 template<int size
, bool big_endian
>
1857 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1859 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1862 // Return the size of each PLT entry.
1864 template<int size
, bool big_endian
>
1866 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1868 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1871 // Create a GOT entry for the TLS module index.
1873 template<int size
, bool big_endian
>
1875 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1876 Symbol_table
* symtab
,
1878 Sized_relobj_file
<size
, big_endian
>* object
)
1880 if (this->got_mod_index_offset_
== -1U)
1882 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1883 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1884 Output_data_got
<size
, big_endian
>* got
;
1885 unsigned int got_offset
;
1887 got
= this->got_section(symtab
, layout
);
1888 got_offset
= got
->add_constant(0);
1889 rela_dyn
->add_local(object
, 0,
1891 elfcpp::R_SPARC_TLS_DTPMOD64
:
1892 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1894 got
->add_constant(0);
1895 this->got_mod_index_offset_
= got_offset
;
1897 return this->got_mod_index_offset_
;
1900 // Optimize the TLS relocation type based on what we know about the
1901 // symbol. IS_FINAL is true if the final address of this symbol is
1902 // known at link time.
1904 static tls::Tls_optimization
1905 optimize_tls_reloc(bool is_final
, int r_type
)
1907 // If we are generating a shared library, then we can't do anything
1909 if (parameters
->options().shared())
1910 return tls::TLSOPT_NONE
;
1914 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1915 case elfcpp::R_SPARC_TLS_GD_LO10
:
1916 case elfcpp::R_SPARC_TLS_GD_ADD
:
1917 case elfcpp::R_SPARC_TLS_GD_CALL
:
1918 // These are General-Dynamic which permits fully general TLS
1919 // access. Since we know that we are generating an executable,
1920 // we can convert this to Initial-Exec. If we also know that
1921 // this is a local symbol, we can further switch to Local-Exec.
1923 return tls::TLSOPT_TO_LE
;
1924 return tls::TLSOPT_TO_IE
;
1926 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1927 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1928 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1929 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1930 // This is Local-Dynamic, which refers to a local symbol in the
1931 // dynamic TLS block. Since we know that we generating an
1932 // executable, we can switch to Local-Exec.
1933 return tls::TLSOPT_TO_LE
;
1935 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1936 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1937 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1938 // Another type of Local-Dynamic relocation.
1939 return tls::TLSOPT_TO_LE
;
1941 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1942 case elfcpp::R_SPARC_TLS_IE_LO10
:
1943 case elfcpp::R_SPARC_TLS_IE_LD
:
1944 case elfcpp::R_SPARC_TLS_IE_LDX
:
1945 case elfcpp::R_SPARC_TLS_IE_ADD
:
1946 // These are Initial-Exec relocs which get the thread offset
1947 // from the GOT. If we know that we are linking against the
1948 // local symbol, we can switch to Local-Exec, which links the
1949 // thread offset into the instruction.
1951 return tls::TLSOPT_TO_LE
;
1952 return tls::TLSOPT_NONE
;
1954 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1955 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1956 // When we already have Local-Exec, there is nothing further we
1958 return tls::TLSOPT_NONE
;
1965 // Get the Reference_flags for a particular relocation.
1967 template<int size
, bool big_endian
>
1969 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1974 case elfcpp::R_SPARC_NONE
:
1975 case elfcpp::R_SPARC_REGISTER
:
1976 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1977 case elfcpp::R_SPARC_GNU_VTENTRY
:
1978 // No symbol reference.
1981 case elfcpp::R_SPARC_UA64
:
1982 case elfcpp::R_SPARC_64
:
1983 case elfcpp::R_SPARC_HIX22
:
1984 case elfcpp::R_SPARC_LOX10
:
1985 case elfcpp::R_SPARC_H34
:
1986 case elfcpp::R_SPARC_H44
:
1987 case elfcpp::R_SPARC_M44
:
1988 case elfcpp::R_SPARC_L44
:
1989 case elfcpp::R_SPARC_HH22
:
1990 case elfcpp::R_SPARC_HM10
:
1991 case elfcpp::R_SPARC_LM22
:
1992 case elfcpp::R_SPARC_HI22
:
1993 case elfcpp::R_SPARC_LO10
:
1994 case elfcpp::R_SPARC_OLO10
:
1995 case elfcpp::R_SPARC_UA32
:
1996 case elfcpp::R_SPARC_32
:
1997 case elfcpp::R_SPARC_UA16
:
1998 case elfcpp::R_SPARC_16
:
1999 case elfcpp::R_SPARC_11
:
2000 case elfcpp::R_SPARC_10
:
2001 case elfcpp::R_SPARC_8
:
2002 case elfcpp::R_SPARC_7
:
2003 case elfcpp::R_SPARC_6
:
2004 case elfcpp::R_SPARC_5
:
2005 return Symbol::ABSOLUTE_REF
;
2007 case elfcpp::R_SPARC_DISP8
:
2008 case elfcpp::R_SPARC_DISP16
:
2009 case elfcpp::R_SPARC_DISP32
:
2010 case elfcpp::R_SPARC_DISP64
:
2011 case elfcpp::R_SPARC_PC_HH22
:
2012 case elfcpp::R_SPARC_PC_HM10
:
2013 case elfcpp::R_SPARC_PC_LM22
:
2014 case elfcpp::R_SPARC_PC10
:
2015 case elfcpp::R_SPARC_PC22
:
2016 case elfcpp::R_SPARC_WDISP30
:
2017 case elfcpp::R_SPARC_WDISP22
:
2018 case elfcpp::R_SPARC_WDISP19
:
2019 case elfcpp::R_SPARC_WDISP16
:
2020 case elfcpp::R_SPARC_WDISP10
:
2021 return Symbol::RELATIVE_REF
;
2023 case elfcpp::R_SPARC_PLT64
:
2024 case elfcpp::R_SPARC_PLT32
:
2025 case elfcpp::R_SPARC_HIPLT22
:
2026 case elfcpp::R_SPARC_LOPLT10
:
2027 case elfcpp::R_SPARC_PCPLT10
:
2028 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
2030 case elfcpp::R_SPARC_PCPLT32
:
2031 case elfcpp::R_SPARC_PCPLT22
:
2032 case elfcpp::R_SPARC_WPLT30
:
2033 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2035 case elfcpp::R_SPARC_GOTDATA_OP
:
2036 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2037 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2038 case elfcpp::R_SPARC_GOT10
:
2039 case elfcpp::R_SPARC_GOT13
:
2040 case elfcpp::R_SPARC_GOT22
:
2042 return Symbol::ABSOLUTE_REF
;
2044 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2045 case elfcpp::R_SPARC_TLS_GD_LO10
:
2046 case elfcpp::R_SPARC_TLS_GD_ADD
:
2047 case elfcpp::R_SPARC_TLS_GD_CALL
:
2048 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2049 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2050 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2051 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2052 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2053 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2054 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2055 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2056 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2057 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2058 case elfcpp::R_SPARC_TLS_IE_LO10
:
2059 case elfcpp::R_SPARC_TLS_IE_LD
:
2060 case elfcpp::R_SPARC_TLS_IE_LDX
:
2061 case elfcpp::R_SPARC_TLS_IE_ADD
:
2062 return Symbol::TLS_REF
;
2064 case elfcpp::R_SPARC_COPY
:
2065 case elfcpp::R_SPARC_GLOB_DAT
:
2066 case elfcpp::R_SPARC_JMP_SLOT
:
2067 case elfcpp::R_SPARC_JMP_IREL
:
2068 case elfcpp::R_SPARC_RELATIVE
:
2069 case elfcpp::R_SPARC_IRELATIVE
:
2070 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2071 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2072 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2073 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2074 case elfcpp::R_SPARC_TLS_TPOFF64
:
2075 case elfcpp::R_SPARC_TLS_TPOFF32
:
2077 // Not expected. We will give an error later.
2082 // Generate a PLT entry slot for a call to __tls_get_addr
2083 template<int size
, bool big_endian
>
2085 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2087 Target_sparc
<size
, big_endian
>* target
)
2089 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2091 target
->make_plt_entry(symtab
, layout
, gsym
);
2094 // Report an unsupported relocation against a local symbol.
2096 template<int size
, bool big_endian
>
2098 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2099 Sized_relobj_file
<size
, big_endian
>* object
,
2100 unsigned int r_type
)
2102 gold_error(_("%s: unsupported reloc %u against local symbol"),
2103 object
->name().c_str(), r_type
);
2106 // We are about to emit a dynamic relocation of type R_TYPE. If the
2107 // dynamic linker does not support it, issue an error.
2109 template<int size
, bool big_endian
>
2111 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2113 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2119 // These are the relocation types supported by glibc for sparc 64-bit.
2120 case elfcpp::R_SPARC_RELATIVE
:
2121 case elfcpp::R_SPARC_IRELATIVE
:
2122 case elfcpp::R_SPARC_COPY
:
2123 case elfcpp::R_SPARC_64
:
2124 case elfcpp::R_SPARC_GLOB_DAT
:
2125 case elfcpp::R_SPARC_JMP_SLOT
:
2126 case elfcpp::R_SPARC_JMP_IREL
:
2127 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2128 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2129 case elfcpp::R_SPARC_TLS_TPOFF64
:
2130 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2131 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2132 case elfcpp::R_SPARC_8
:
2133 case elfcpp::R_SPARC_16
:
2134 case elfcpp::R_SPARC_DISP8
:
2135 case elfcpp::R_SPARC_DISP16
:
2136 case elfcpp::R_SPARC_DISP32
:
2137 case elfcpp::R_SPARC_WDISP30
:
2138 case elfcpp::R_SPARC_LO10
:
2139 case elfcpp::R_SPARC_HI22
:
2140 case elfcpp::R_SPARC_OLO10
:
2141 case elfcpp::R_SPARC_H34
:
2142 case elfcpp::R_SPARC_H44
:
2143 case elfcpp::R_SPARC_M44
:
2144 case elfcpp::R_SPARC_L44
:
2145 case elfcpp::R_SPARC_HH22
:
2146 case elfcpp::R_SPARC_HM10
:
2147 case elfcpp::R_SPARC_LM22
:
2148 case elfcpp::R_SPARC_UA16
:
2149 case elfcpp::R_SPARC_UA32
:
2150 case elfcpp::R_SPARC_UA64
:
2161 // These are the relocation types supported by glibc for sparc 32-bit.
2162 case elfcpp::R_SPARC_RELATIVE
:
2163 case elfcpp::R_SPARC_IRELATIVE
:
2164 case elfcpp::R_SPARC_COPY
:
2165 case elfcpp::R_SPARC_GLOB_DAT
:
2166 case elfcpp::R_SPARC_32
:
2167 case elfcpp::R_SPARC_JMP_SLOT
:
2168 case elfcpp::R_SPARC_JMP_IREL
:
2169 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2170 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2171 case elfcpp::R_SPARC_TLS_TPOFF32
:
2172 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2173 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2174 case elfcpp::R_SPARC_8
:
2175 case elfcpp::R_SPARC_16
:
2176 case elfcpp::R_SPARC_DISP8
:
2177 case elfcpp::R_SPARC_DISP16
:
2178 case elfcpp::R_SPARC_DISP32
:
2179 case elfcpp::R_SPARC_LO10
:
2180 case elfcpp::R_SPARC_WDISP30
:
2181 case elfcpp::R_SPARC_HI22
:
2182 case elfcpp::R_SPARC_UA16
:
2183 case elfcpp::R_SPARC_UA32
:
2191 // This prevents us from issuing more than one error per reloc
2192 // section. But we can still wind up issuing more than one
2193 // error per object file.
2194 if (this->issued_non_pic_error_
)
2196 gold_assert(parameters
->options().output_is_position_independent());
2197 object
->error(_("requires unsupported dynamic reloc; "
2198 "recompile with -fPIC"));
2199 this->issued_non_pic_error_
= true;
2203 // Return whether we need to make a PLT entry for a relocation of the
2204 // given type against a STT_GNU_IFUNC symbol.
2206 template<int size
, bool big_endian
>
2208 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2209 Sized_relobj_file
<size
, big_endian
>* object
,
2210 unsigned int r_type
)
2212 int flags
= Scan::get_reference_flags(r_type
);
2213 if (flags
& Symbol::TLS_REF
)
2214 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2215 object
->name().c_str(), r_type
);
2219 // Scan a relocation for a local symbol.
2221 template<int size
, bool big_endian
>
2223 Target_sparc
<size
, big_endian
>::Scan::local(
2224 Symbol_table
* symtab
,
2226 Target_sparc
<size
, big_endian
>* target
,
2227 Sized_relobj_file
<size
, big_endian
>* object
,
2228 unsigned int data_shndx
,
2229 Output_section
* output_section
,
2230 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2231 unsigned int r_type
,
2232 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2234 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2235 unsigned int orig_r_type
= r_type
;
2239 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2241 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2242 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2247 case elfcpp::R_SPARC_NONE
:
2248 case elfcpp::R_SPARC_REGISTER
:
2249 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2250 case elfcpp::R_SPARC_GNU_VTENTRY
:
2253 case elfcpp::R_SPARC_64
:
2254 case elfcpp::R_SPARC_32
:
2255 // If building a shared library (or a position-independent
2256 // executable), we need to create a dynamic relocation for
2257 // this location. The relocation applied at link time will
2258 // apply the link-time value, so we flag the location with
2259 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2260 // relocate it easily.
2261 if (parameters
->options().output_is_position_independent())
2263 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2264 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2265 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2266 output_section
, data_shndx
,
2267 reloc
.get_r_offset(),
2268 reloc
.get_r_addend(), is_ifunc
);
2272 case elfcpp::R_SPARC_HIX22
:
2273 case elfcpp::R_SPARC_LOX10
:
2274 case elfcpp::R_SPARC_H34
:
2275 case elfcpp::R_SPARC_H44
:
2276 case elfcpp::R_SPARC_M44
:
2277 case elfcpp::R_SPARC_L44
:
2278 case elfcpp::R_SPARC_HH22
:
2279 case elfcpp::R_SPARC_HM10
:
2280 case elfcpp::R_SPARC_LM22
:
2281 case elfcpp::R_SPARC_UA64
:
2282 case elfcpp::R_SPARC_UA32
:
2283 case elfcpp::R_SPARC_UA16
:
2284 case elfcpp::R_SPARC_HI22
:
2285 case elfcpp::R_SPARC_LO10
:
2286 case elfcpp::R_SPARC_OLO10
:
2287 case elfcpp::R_SPARC_16
:
2288 case elfcpp::R_SPARC_11
:
2289 case elfcpp::R_SPARC_10
:
2290 case elfcpp::R_SPARC_8
:
2291 case elfcpp::R_SPARC_7
:
2292 case elfcpp::R_SPARC_6
:
2293 case elfcpp::R_SPARC_5
:
2294 // If building a shared library (or a position-independent
2295 // executable), we need to create a dynamic relocation for
2297 if (parameters
->options().output_is_position_independent())
2299 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2300 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2302 check_non_pic(object
, r_type
);
2303 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2305 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2306 data_shndx
, reloc
.get_r_offset(),
2307 reloc
.get_r_addend());
2311 gold_assert(lsym
.get_st_value() == 0);
2312 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2313 output_section
, data_shndx
,
2314 reloc
.get_r_offset(),
2315 reloc
.get_r_addend());
2320 case elfcpp::R_SPARC_WDISP30
:
2321 case elfcpp::R_SPARC_WPLT30
:
2322 case elfcpp::R_SPARC_WDISP22
:
2323 case elfcpp::R_SPARC_WDISP19
:
2324 case elfcpp::R_SPARC_WDISP16
:
2325 case elfcpp::R_SPARC_WDISP10
:
2326 case elfcpp::R_SPARC_DISP8
:
2327 case elfcpp::R_SPARC_DISP16
:
2328 case elfcpp::R_SPARC_DISP32
:
2329 case elfcpp::R_SPARC_DISP64
:
2330 case elfcpp::R_SPARC_PC10
:
2331 case elfcpp::R_SPARC_PC22
:
2334 case elfcpp::R_SPARC_GOTDATA_OP
:
2335 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2336 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2337 // We will optimize this into a GOT relative relocation
2338 // and code transform the GOT load into an addition.
2341 case elfcpp::R_SPARC_GOT10
:
2342 case elfcpp::R_SPARC_GOT13
:
2343 case elfcpp::R_SPARC_GOT22
:
2345 // The symbol requires a GOT entry.
2346 Output_data_got
<size
, big_endian
>* got
;
2349 got
= target
->got_section(symtab
, layout
);
2350 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2352 // If we are generating a shared object, we need to add a
2353 // dynamic relocation for this symbol's GOT entry.
2354 if (parameters
->options().output_is_position_independent())
2356 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2358 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2359 unsigned int off
= got
->add_constant(0);
2360 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2361 rela_dyn
->add_local_relative(object
, r_sym
,
2362 elfcpp::R_SPARC_RELATIVE
,
2363 got
, off
, 0, is_ifunc
);
2367 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2371 // These are initial TLS relocs, which are expected when
2373 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2374 case elfcpp::R_SPARC_TLS_GD_LO10
:
2375 case elfcpp::R_SPARC_TLS_GD_ADD
:
2376 case elfcpp::R_SPARC_TLS_GD_CALL
:
2377 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2378 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2379 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2380 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2381 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2382 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2383 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2384 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2385 case elfcpp::R_SPARC_TLS_IE_LO10
:
2386 case elfcpp::R_SPARC_TLS_IE_LD
:
2387 case elfcpp::R_SPARC_TLS_IE_LDX
:
2388 case elfcpp::R_SPARC_TLS_IE_ADD
:
2389 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2390 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2392 bool output_is_shared
= parameters
->options().shared();
2393 const tls::Tls_optimization optimized_type
2394 = optimize_tls_reloc(!output_is_shared
, r_type
);
2397 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2398 case elfcpp::R_SPARC_TLS_GD_LO10
:
2399 case elfcpp::R_SPARC_TLS_GD_ADD
:
2400 case elfcpp::R_SPARC_TLS_GD_CALL
:
2401 if (optimized_type
== tls::TLSOPT_NONE
)
2403 // Create a pair of GOT entries for the module index and
2404 // dtv-relative offset.
2405 Output_data_got
<size
, big_endian
>* got
2406 = target
->got_section(symtab
, layout
);
2407 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2408 unsigned int shndx
= lsym
.get_st_shndx();
2410 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2412 object
->error(_("local symbol %u has bad shndx %u"),
2415 got
->add_local_pair_with_rel(object
, r_sym
,
2416 lsym
.get_st_shndx(),
2418 target
->rela_dyn_section(layout
),
2420 ? elfcpp::R_SPARC_TLS_DTPMOD64
2421 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2423 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2424 generate_tls_call(symtab
, layout
, target
);
2426 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2427 unsupported_reloc_local(object
, r_type
);
2430 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2431 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2432 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2433 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2434 if (optimized_type
== tls::TLSOPT_NONE
)
2436 // Create a GOT entry for the module index.
2437 target
->got_mod_index_entry(symtab
, layout
, object
);
2439 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2440 generate_tls_call(symtab
, layout
, target
);
2442 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2443 unsupported_reloc_local(object
, r_type
);
2446 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2447 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2448 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2451 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2452 case elfcpp::R_SPARC_TLS_IE_LO10
:
2453 case elfcpp::R_SPARC_TLS_IE_LD
:
2454 case elfcpp::R_SPARC_TLS_IE_LDX
:
2455 case elfcpp::R_SPARC_TLS_IE_ADD
:
2456 layout
->set_has_static_tls();
2457 if (optimized_type
== tls::TLSOPT_NONE
)
2459 // Create a GOT entry for the tp-relative offset.
2460 Output_data_got
<size
, big_endian
>* got
2461 = target
->got_section(symtab
, layout
);
2462 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2464 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2466 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2467 unsigned int off
= got
->add_constant(0);
2469 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2471 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2473 elfcpp::R_SPARC_TLS_TPOFF64
:
2474 elfcpp::R_SPARC_TLS_TPOFF32
),
2478 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2479 unsupported_reloc_local(object
, r_type
);
2482 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2483 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2484 layout
->set_has_static_tls();
2485 if (output_is_shared
)
2487 // We need to create a dynamic relocation.
2488 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2489 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2490 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2491 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2492 output_section
, data_shndx
,
2493 reloc
.get_r_offset(), 0);
2500 // These are relocations which should only be seen by the
2501 // dynamic linker, and should never be seen here.
2502 case elfcpp::R_SPARC_COPY
:
2503 case elfcpp::R_SPARC_GLOB_DAT
:
2504 case elfcpp::R_SPARC_JMP_SLOT
:
2505 case elfcpp::R_SPARC_JMP_IREL
:
2506 case elfcpp::R_SPARC_RELATIVE
:
2507 case elfcpp::R_SPARC_IRELATIVE
:
2508 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2509 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2510 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2511 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2512 case elfcpp::R_SPARC_TLS_TPOFF64
:
2513 case elfcpp::R_SPARC_TLS_TPOFF32
:
2514 gold_error(_("%s: unexpected reloc %u in object file"),
2515 object
->name().c_str(), r_type
);
2519 unsupported_reloc_local(object
, r_type
);
2524 // Report an unsupported relocation against a global symbol.
2526 template<int size
, bool big_endian
>
2528 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2529 Sized_relobj_file
<size
, big_endian
>* object
,
2530 unsigned int r_type
,
2533 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2534 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2537 // Scan a relocation for a global symbol.
2539 template<int size
, bool big_endian
>
2541 Target_sparc
<size
, big_endian
>::Scan::global(
2542 Symbol_table
* symtab
,
2544 Target_sparc
<size
, big_endian
>* target
,
2545 Sized_relobj_file
<size
, big_endian
>* object
,
2546 unsigned int data_shndx
,
2547 Output_section
* output_section
,
2548 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2549 unsigned int r_type
,
2552 unsigned int orig_r_type
= r_type
;
2553 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2555 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2556 // section. We check here to avoid creating a dynamic reloc against
2557 // _GLOBAL_OFFSET_TABLE_.
2558 if (!target
->has_got_section()
2559 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2560 target
->got_section(symtab
, layout
);
2564 // A STT_GNU_IFUNC symbol may require a PLT entry.
2566 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2567 target
->make_plt_entry(symtab
, layout
, gsym
);
2571 case elfcpp::R_SPARC_NONE
:
2572 case elfcpp::R_SPARC_REGISTER
:
2573 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2574 case elfcpp::R_SPARC_GNU_VTENTRY
:
2577 case elfcpp::R_SPARC_PLT64
:
2578 case elfcpp::R_SPARC_PLT32
:
2579 case elfcpp::R_SPARC_HIPLT22
:
2580 case elfcpp::R_SPARC_LOPLT10
:
2581 case elfcpp::R_SPARC_PCPLT32
:
2582 case elfcpp::R_SPARC_PCPLT22
:
2583 case elfcpp::R_SPARC_PCPLT10
:
2584 case elfcpp::R_SPARC_WPLT30
:
2585 // If the symbol is fully resolved, this is just a PC32 reloc.
2586 // Otherwise we need a PLT entry.
2587 if (gsym
->final_value_is_known())
2589 // If building a shared library, we can also skip the PLT entry
2590 // if the symbol is defined in the output file and is protected
2592 if (gsym
->is_defined()
2593 && !gsym
->is_from_dynobj()
2594 && !gsym
->is_preemptible())
2596 target
->make_plt_entry(symtab
, layout
, gsym
);
2599 case elfcpp::R_SPARC_DISP8
:
2600 case elfcpp::R_SPARC_DISP16
:
2601 case elfcpp::R_SPARC_DISP32
:
2602 case elfcpp::R_SPARC_DISP64
:
2603 case elfcpp::R_SPARC_PC_HH22
:
2604 case elfcpp::R_SPARC_PC_HM10
:
2605 case elfcpp::R_SPARC_PC_LM22
:
2606 case elfcpp::R_SPARC_PC10
:
2607 case elfcpp::R_SPARC_PC22
:
2608 case elfcpp::R_SPARC_WDISP30
:
2609 case elfcpp::R_SPARC_WDISP22
:
2610 case elfcpp::R_SPARC_WDISP19
:
2611 case elfcpp::R_SPARC_WDISP16
:
2612 case elfcpp::R_SPARC_WDISP10
:
2614 if (gsym
->needs_plt_entry())
2615 target
->make_plt_entry(symtab
, layout
, gsym
);
2616 // Make a dynamic relocation if necessary.
2617 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2619 if (gsym
->may_need_copy_reloc())
2621 target
->copy_reloc(symtab
, layout
, object
,
2622 data_shndx
, output_section
, gsym
,
2627 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2628 check_non_pic(object
, r_type
);
2629 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2630 data_shndx
, reloc
.get_r_offset(),
2631 reloc
.get_r_addend());
2637 case elfcpp::R_SPARC_UA64
:
2638 case elfcpp::R_SPARC_64
:
2639 case elfcpp::R_SPARC_HIX22
:
2640 case elfcpp::R_SPARC_LOX10
:
2641 case elfcpp::R_SPARC_H34
:
2642 case elfcpp::R_SPARC_H44
:
2643 case elfcpp::R_SPARC_M44
:
2644 case elfcpp::R_SPARC_L44
:
2645 case elfcpp::R_SPARC_HH22
:
2646 case elfcpp::R_SPARC_HM10
:
2647 case elfcpp::R_SPARC_LM22
:
2648 case elfcpp::R_SPARC_HI22
:
2649 case elfcpp::R_SPARC_LO10
:
2650 case elfcpp::R_SPARC_OLO10
:
2651 case elfcpp::R_SPARC_UA32
:
2652 case elfcpp::R_SPARC_32
:
2653 case elfcpp::R_SPARC_UA16
:
2654 case elfcpp::R_SPARC_16
:
2655 case elfcpp::R_SPARC_11
:
2656 case elfcpp::R_SPARC_10
:
2657 case elfcpp::R_SPARC_8
:
2658 case elfcpp::R_SPARC_7
:
2659 case elfcpp::R_SPARC_6
:
2660 case elfcpp::R_SPARC_5
:
2662 // Make a PLT entry if necessary.
2663 if (gsym
->needs_plt_entry())
2665 target
->make_plt_entry(symtab
, layout
, gsym
);
2666 // Since this is not a PC-relative relocation, we may be
2667 // taking the address of a function. In that case we need to
2668 // set the entry in the dynamic symbol table to the address of
2670 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2671 gsym
->set_needs_dynsym_value();
2673 // Make a dynamic relocation if necessary.
2674 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2676 unsigned int r_off
= reloc
.get_r_offset();
2678 // The assembler can sometimes emit unaligned relocations
2679 // for dwarf2 cfi directives.
2682 case elfcpp::R_SPARC_16
:
2684 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2686 case elfcpp::R_SPARC_32
:
2688 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2690 case elfcpp::R_SPARC_64
:
2692 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2694 case elfcpp::R_SPARC_UA16
:
2696 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2698 case elfcpp::R_SPARC_UA32
:
2700 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2702 case elfcpp::R_SPARC_UA64
:
2704 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2708 if (gsym
->may_need_copy_reloc())
2710 target
->copy_reloc(symtab
, layout
, object
,
2711 data_shndx
, output_section
, gsym
, reloc
);
2713 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2714 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2715 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2716 && gsym
->can_use_relative_reloc(false)
2717 && !gsym
->is_from_dynobj()
2718 && !gsym
->is_undefined()
2719 && !gsym
->is_preemptible())
2721 // Use an IRELATIVE reloc for a locally defined
2722 // STT_GNU_IFUNC symbol. This makes a function
2723 // address in a PIE executable match the address in a
2724 // shared library that it links against.
2725 Reloc_section
* rela_dyn
=
2726 target
->rela_ifunc_section(layout
);
2727 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2728 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2729 output_section
, object
,
2731 reloc
.get_r_offset(),
2732 reloc
.get_r_addend());
2734 else if ((r_type
== elfcpp::R_SPARC_32
2735 || r_type
== elfcpp::R_SPARC_64
)
2736 && gsym
->can_use_relative_reloc(false))
2738 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2739 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2740 output_section
, object
,
2741 data_shndx
, reloc
.get_r_offset(),
2742 reloc
.get_r_addend(), is_ifunc
);
2746 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2748 check_non_pic(object
, r_type
);
2749 if (gsym
->is_from_dynobj()
2750 || gsym
->is_undefined()
2751 || gsym
->is_preemptible())
2752 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2754 reloc
.get_r_offset(),
2755 reloc
.get_r_addend());
2757 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2760 reloc
.get_r_offset(),
2761 reloc
.get_r_addend());
2767 case elfcpp::R_SPARC_GOTDATA_OP
:
2768 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2769 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2770 if (gsym
->is_defined()
2771 && !gsym
->is_from_dynobj()
2772 && !gsym
->is_preemptible()
2775 // We will optimize this into a GOT relative relocation
2776 // and code transform the GOT load into an addition.
2779 case elfcpp::R_SPARC_GOT10
:
2780 case elfcpp::R_SPARC_GOT13
:
2781 case elfcpp::R_SPARC_GOT22
:
2783 // The symbol requires a GOT entry.
2784 Output_data_got
<size
, big_endian
>* got
;
2786 got
= target
->got_section(symtab
, layout
);
2787 if (gsym
->final_value_is_known())
2789 // For a STT_GNU_IFUNC symbol we want the PLT address.
2790 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2791 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2793 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2797 // If this symbol is not fully resolved, we need to add a
2798 // GOT entry with a dynamic relocation.
2799 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2801 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2803 // 1) The symbol may be defined in some other module.
2805 // 2) We are building a shared library and this is a
2806 // protected symbol; using GLOB_DAT means that the dynamic
2807 // linker can use the address of the PLT in the main
2808 // executable when appropriate so that function address
2809 // comparisons work.
2811 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2812 // code, again so that function address comparisons work.
2813 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2814 if (gsym
->is_from_dynobj()
2815 || gsym
->is_undefined()
2816 || gsym
->is_preemptible()
2817 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2818 && parameters
->options().shared())
2819 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2820 && parameters
->options().output_is_position_independent()
2821 && !gsym
->is_forced_local()))
2823 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2825 // If this symbol is forced local, this relocation will
2826 // not work properly. That's because ld.so on sparc
2827 // (and 32-bit powerpc) expects st_value in the r_addend
2828 // of relocations for STB_LOCAL symbols. Curiously the
2829 // BFD linker does not promote global hidden symbols to be
2830 // STB_LOCAL in the dynamic symbol table like Gold does.
2831 gold_assert(!gsym
->is_forced_local());
2832 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2835 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2837 unsigned int off
= got
->add_constant(0);
2839 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2842 // Tell the dynamic linker to use the PLT address
2843 // when resolving relocations.
2844 if (gsym
->is_from_dynobj()
2845 && !parameters
->options().shared())
2846 gsym
->set_needs_dynsym_value();
2848 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2849 got
, off
, 0, is_ifunc
);
2855 // These are initial tls relocs, which are expected when
2857 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2858 case elfcpp::R_SPARC_TLS_GD_LO10
:
2859 case elfcpp::R_SPARC_TLS_GD_ADD
:
2860 case elfcpp::R_SPARC_TLS_GD_CALL
:
2861 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2862 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2863 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2864 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2865 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2866 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2867 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2868 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2869 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2870 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2871 case elfcpp::R_SPARC_TLS_IE_LO10
:
2872 case elfcpp::R_SPARC_TLS_IE_LD
:
2873 case elfcpp::R_SPARC_TLS_IE_LDX
:
2874 case elfcpp::R_SPARC_TLS_IE_ADD
:
2876 const bool is_final
= gsym
->final_value_is_known();
2877 const tls::Tls_optimization optimized_type
2878 = optimize_tls_reloc(is_final
, r_type
);
2881 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2882 case elfcpp::R_SPARC_TLS_GD_LO10
:
2883 case elfcpp::R_SPARC_TLS_GD_ADD
:
2884 case elfcpp::R_SPARC_TLS_GD_CALL
:
2885 if (optimized_type
== tls::TLSOPT_NONE
)
2887 // Create a pair of GOT entries for the module index and
2888 // dtv-relative offset.
2889 Output_data_got
<size
, big_endian
>* got
2890 = target
->got_section(symtab
, layout
);
2891 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2892 target
->rela_dyn_section(layout
),
2894 ? elfcpp::R_SPARC_TLS_DTPMOD64
2895 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2897 ? elfcpp::R_SPARC_TLS_DTPOFF64
2898 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2900 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2901 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2902 generate_tls_call(symtab
, layout
, target
);
2904 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2906 // Create a GOT entry for the tp-relative offset.
2907 Output_data_got
<size
, big_endian
>* got
2908 = target
->got_section(symtab
, layout
);
2909 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2910 target
->rela_dyn_section(layout
),
2912 elfcpp::R_SPARC_TLS_TPOFF64
:
2913 elfcpp::R_SPARC_TLS_TPOFF32
));
2915 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2916 unsupported_reloc_global(object
, r_type
, gsym
);
2919 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2920 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2921 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2922 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2923 if (optimized_type
== tls::TLSOPT_NONE
)
2925 // Create a GOT entry for the module index.
2926 target
->got_mod_index_entry(symtab
, layout
, object
);
2928 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2929 generate_tls_call(symtab
, layout
, target
);
2931 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2932 unsupported_reloc_global(object
, r_type
, gsym
);
2935 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2936 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2937 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2940 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2941 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2942 layout
->set_has_static_tls();
2943 if (parameters
->options().shared())
2945 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2946 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2947 output_section
, object
,
2948 data_shndx
, reloc
.get_r_offset(),
2953 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2954 case elfcpp::R_SPARC_TLS_IE_LO10
:
2955 case elfcpp::R_SPARC_TLS_IE_LD
:
2956 case elfcpp::R_SPARC_TLS_IE_LDX
:
2957 case elfcpp::R_SPARC_TLS_IE_ADD
:
2958 layout
->set_has_static_tls();
2959 if (optimized_type
== tls::TLSOPT_NONE
)
2961 // Create a GOT entry for the tp-relative offset.
2962 Output_data_got
<size
, big_endian
>* got
2963 = target
->got_section(symtab
, layout
);
2964 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2965 target
->rela_dyn_section(layout
),
2967 ? elfcpp::R_SPARC_TLS_TPOFF64
2968 : elfcpp::R_SPARC_TLS_TPOFF32
));
2970 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2971 unsupported_reloc_global(object
, r_type
, gsym
);
2977 // These are relocations which should only be seen by the
2978 // dynamic linker, and should never be seen here.
2979 case elfcpp::R_SPARC_COPY
:
2980 case elfcpp::R_SPARC_GLOB_DAT
:
2981 case elfcpp::R_SPARC_JMP_SLOT
:
2982 case elfcpp::R_SPARC_JMP_IREL
:
2983 case elfcpp::R_SPARC_RELATIVE
:
2984 case elfcpp::R_SPARC_IRELATIVE
:
2985 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2986 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2987 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2988 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2989 case elfcpp::R_SPARC_TLS_TPOFF64
:
2990 case elfcpp::R_SPARC_TLS_TPOFF32
:
2991 gold_error(_("%s: unexpected reloc %u in object file"),
2992 object
->name().c_str(), r_type
);
2996 unsupported_reloc_global(object
, r_type
, gsym
);
3001 // Process relocations for gc.
3003 template<int size
, bool big_endian
>
3005 Target_sparc
<size
, big_endian
>::gc_process_relocs(
3006 Symbol_table
* symtab
,
3008 Sized_relobj_file
<size
, big_endian
>* object
,
3009 unsigned int data_shndx
,
3011 const unsigned char* prelocs
,
3013 Output_section
* output_section
,
3014 bool needs_special_offset_handling
,
3015 size_t local_symbol_count
,
3016 const unsigned char* plocal_symbols
)
3018 typedef Target_sparc
<size
, big_endian
> Sparc
;
3019 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3021 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
3022 typename
Target_sparc::Relocatable_size_for_reloc
>(
3031 needs_special_offset_handling
,
3036 // Scan relocations for a section.
3038 template<int size
, bool big_endian
>
3040 Target_sparc
<size
, big_endian
>::scan_relocs(
3041 Symbol_table
* symtab
,
3043 Sized_relobj_file
<size
, big_endian
>* object
,
3044 unsigned int data_shndx
,
3045 unsigned int sh_type
,
3046 const unsigned char* prelocs
,
3048 Output_section
* output_section
,
3049 bool needs_special_offset_handling
,
3050 size_t local_symbol_count
,
3051 const unsigned char* plocal_symbols
)
3053 typedef Target_sparc
<size
, big_endian
> Sparc
;
3054 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
3056 if (sh_type
== elfcpp::SHT_REL
)
3058 gold_error(_("%s: unsupported REL reloc section"),
3059 object
->name().c_str());
3063 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
3072 needs_special_offset_handling
,
3077 // Finalize the sections.
3079 template<int size
, bool big_endian
>
3081 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3083 const Input_objects
*,
3084 Symbol_table
* symtab
)
3087 this->plt_
->emit_pending_ifunc_relocs();
3089 // Fill in some more dynamic tags.
3090 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3092 : this->plt_
->rel_plt());
3093 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3094 this->rela_dyn_
, true, true);
3096 // Emit any relocs we saved in an attempt to avoid generating COPY
3098 if (this->copy_relocs_
.any_saved_relocs())
3099 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3101 if (parameters
->doing_static_link()
3102 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3104 // If linking statically, make sure that the __rela_iplt symbols
3105 // were defined if necessary, even if we didn't create a PLT.
3106 static const Define_symbol_in_segment syms
[] =
3109 "__rela_iplt_start", // name
3110 elfcpp::PT_LOAD
, // segment_type
3111 elfcpp::PF_W
, // segment_flags_set
3112 elfcpp::PF(0), // segment_flags_clear
3115 elfcpp::STT_NOTYPE
, // type
3116 elfcpp::STB_GLOBAL
, // binding
3117 elfcpp::STV_HIDDEN
, // visibility
3119 Symbol::SEGMENT_START
, // offset_from_base
3123 "__rela_iplt_end", // name
3124 elfcpp::PT_LOAD
, // segment_type
3125 elfcpp::PF_W
, // segment_flags_set
3126 elfcpp::PF(0), // segment_flags_clear
3129 elfcpp::STT_NOTYPE
, // type
3130 elfcpp::STB_GLOBAL
, // binding
3131 elfcpp::STV_HIDDEN
, // visibility
3133 Symbol::SEGMENT_START
, // offset_from_base
3138 symtab
->define_symbols(layout
, 2, syms
,
3139 layout
->script_options()->saw_sections_clause());
3143 // Perform a relocation.
3145 template<int size
, bool big_endian
>
3147 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3148 const Relocate_info
<size
, big_endian
>* relinfo
,
3149 Target_sparc
* target
,
3152 const elfcpp::Rela
<size
, big_endian
>& rela
,
3153 unsigned int r_type
,
3154 const Sized_symbol
<size
>* gsym
,
3155 const Symbol_value
<size
>* psymval
,
3156 unsigned char* view
,
3157 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3158 section_size_type view_size
)
3160 bool orig_is_ifunc
= psymval
->is_ifunc_symbol();
3163 if (this->ignore_gd_add_
)
3165 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3166 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3167 _("missing expected TLS relocation"));
3170 this->ignore_gd_add_
= false;
3174 if (this->reloc_adjust_addr_
== view
)
3177 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3178 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3180 // Pick the value to use for symbols defined in shared objects.
3181 Symbol_value
<size
> symval
;
3183 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3185 elfcpp::Elf_Xword value
;
3187 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3189 symval
.set_output_value(value
);
3193 else if (gsym
== NULL
&& orig_is_ifunc
)
3195 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3196 if (object
->local_has_plt_offset(r_sym
))
3198 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3199 + object
->local_plt_offset(r_sym
));
3204 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3206 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3207 // pointer points to the beginning, not the end, of the table.
3208 // So we just use the plain offset.
3209 unsigned int got_offset
= 0;
3210 bool gdop_valid
= false;
3213 case elfcpp::R_SPARC_GOTDATA_OP
:
3214 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3215 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3216 // If this is local, we did not create a GOT entry because we
3217 // intend to transform this into a GOT relative relocation.
3219 || (gsym
->is_defined()
3220 && !gsym
->is_from_dynobj()
3221 && !gsym
->is_preemptible()
3224 got_offset
= psymval
->value(object
, 0) - target
->got_address();
3228 case elfcpp::R_SPARC_GOT10
:
3229 case elfcpp::R_SPARC_GOT13
:
3230 case elfcpp::R_SPARC_GOT22
:
3233 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3234 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3238 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3239 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3240 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3250 case elfcpp::R_SPARC_NONE
:
3251 case elfcpp::R_SPARC_REGISTER
:
3252 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3253 case elfcpp::R_SPARC_GNU_VTENTRY
:
3256 case elfcpp::R_SPARC_8
:
3257 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3261 case elfcpp::R_SPARC_16
:
3262 if (rela
.get_r_offset() & 0x1)
3264 // The assembler can sometimes emit unaligned relocations
3265 // for dwarf2 cfi directives.
3266 Reloc::ua16(view
, object
, psymval
, addend
);
3269 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3273 case elfcpp::R_SPARC_32
:
3274 if (!parameters
->options().output_is_position_independent())
3276 if (rela
.get_r_offset() & 0x3)
3278 // The assembler can sometimes emit unaligned relocations
3279 // for dwarf2 cfi directives.
3280 Reloc::ua32(view
, object
, psymval
, addend
);
3283 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3288 case elfcpp::R_SPARC_DISP8
:
3289 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3292 case elfcpp::R_SPARC_DISP16
:
3293 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3296 case elfcpp::R_SPARC_DISP32
:
3297 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3300 case elfcpp::R_SPARC_DISP64
:
3301 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3304 case elfcpp::R_SPARC_WDISP30
:
3305 case elfcpp::R_SPARC_WPLT30
:
3306 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3309 case elfcpp::R_SPARC_WDISP22
:
3310 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3313 case elfcpp::R_SPARC_WDISP19
:
3314 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3317 case elfcpp::R_SPARC_WDISP16
:
3318 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3321 case elfcpp::R_SPARC_WDISP10
:
3322 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3325 case elfcpp::R_SPARC_HI22
:
3326 Reloc::hi22(view
, object
, psymval
, addend
);
3329 case elfcpp::R_SPARC_22
:
3330 Reloc::rela32_22(view
, object
, psymval
, addend
);
3333 case elfcpp::R_SPARC_13
:
3334 Reloc::rela32_13(view
, object
, psymval
, addend
);
3337 case elfcpp::R_SPARC_LO10
:
3338 Reloc::lo10(view
, object
, psymval
, addend
);
3341 case elfcpp::R_SPARC_GOT10
:
3342 Reloc::lo10(view
, got_offset
, addend
);
3345 case elfcpp::R_SPARC_GOTDATA_OP
:
3348 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3349 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3352 // {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd
3353 val
= elfcpp::Swap
<32, true>::readval(wv
);
3354 val
= 0x80000000 | (val
& 0x3e07c01f);
3355 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3359 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3362 Reloc::gdop_lox10(view
, got_offset
, addend
);
3366 case elfcpp::R_SPARC_GOT13
:
3367 Reloc::rela32_13(view
, got_offset
, addend
);
3370 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3373 Reloc::gdop_hix22(view
, got_offset
, addend
);
3377 case elfcpp::R_SPARC_GOT22
:
3378 Reloc::hi22(view
, got_offset
, addend
);
3381 case elfcpp::R_SPARC_PC10
:
3382 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3385 case elfcpp::R_SPARC_PC22
:
3386 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3389 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3390 case elfcpp::R_SPARC_UA32
:
3391 Reloc::ua32(view
, object
, psymval
, addend
);
3394 case elfcpp::R_SPARC_PLT64
:
3395 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3399 case elfcpp::R_SPARC_PLT32
:
3400 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3404 case elfcpp::R_SPARC_HIPLT22
:
3405 Reloc::hi22(view
, object
, psymval
, addend
);
3408 case elfcpp::R_SPARC_LOPLT10
:
3409 Reloc::lo10(view
, object
, psymval
, addend
);
3412 case elfcpp::R_SPARC_PCPLT32
:
3413 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3416 case elfcpp::R_SPARC_PCPLT22
:
3417 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3420 case elfcpp::R_SPARC_PCPLT10
:
3421 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3424 case elfcpp::R_SPARC_64
:
3425 if (!parameters
->options().output_is_position_independent())
3427 if (rela
.get_r_offset() & 0x7)
3429 // The assembler can sometimes emit unaligned relocations
3430 // for dwarf2 cfi directives.
3431 Reloc::ua64(view
, object
, psymval
, addend
);
3434 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3439 case elfcpp::R_SPARC_OLO10
:
3441 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3442 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3443 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3447 case elfcpp::R_SPARC_HH22
:
3448 Reloc::hh22(view
, object
, psymval
, addend
);
3451 case elfcpp::R_SPARC_PC_HH22
:
3452 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3455 case elfcpp::R_SPARC_HM10
:
3456 Reloc::hm10(view
, object
, psymval
, addend
);
3459 case elfcpp::R_SPARC_PC_HM10
:
3460 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3463 case elfcpp::R_SPARC_LM22
:
3464 Reloc::hi22(view
, object
, psymval
, addend
);
3467 case elfcpp::R_SPARC_PC_LM22
:
3468 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3471 case elfcpp::R_SPARC_11
:
3472 Reloc::rela32_11(view
, object
, psymval
, addend
);
3475 case elfcpp::R_SPARC_10
:
3476 Reloc::rela32_10(view
, object
, psymval
, addend
);
3479 case elfcpp::R_SPARC_7
:
3480 Reloc::rela32_7(view
, object
, psymval
, addend
);
3483 case elfcpp::R_SPARC_6
:
3484 Reloc::rela32_6(view
, object
, psymval
, addend
);
3487 case elfcpp::R_SPARC_5
:
3488 Reloc::rela32_5(view
, object
, psymval
, addend
);
3491 case elfcpp::R_SPARC_HIX22
:
3492 Reloc::hix22(view
, object
, psymval
, addend
);
3495 case elfcpp::R_SPARC_LOX10
:
3496 Reloc::lox10(view
, object
, psymval
, addend
);
3499 case elfcpp::R_SPARC_H34
:
3500 Reloc::h34(view
, object
, psymval
, addend
);
3503 case elfcpp::R_SPARC_H44
:
3504 Reloc::h44(view
, object
, psymval
, addend
);
3507 case elfcpp::R_SPARC_M44
:
3508 Reloc::m44(view
, object
, psymval
, addend
);
3511 case elfcpp::R_SPARC_L44
:
3512 Reloc::l44(view
, object
, psymval
, addend
);
3515 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3516 case elfcpp::R_SPARC_UA64
:
3517 Reloc::ua64(view
, object
, psymval
, addend
);
3520 case elfcpp::R_SPARC_UA16
:
3521 Reloc::ua16(view
, object
, psymval
, addend
);
3524 case elfcpp::R_SPARC_TLS_GD_HI22
:
3525 case elfcpp::R_SPARC_TLS_GD_LO10
:
3526 case elfcpp::R_SPARC_TLS_GD_ADD
:
3527 case elfcpp::R_SPARC_TLS_GD_CALL
:
3528 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3529 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3530 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3531 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3532 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3533 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3534 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3535 case elfcpp::R_SPARC_TLS_IE_HI22
:
3536 case elfcpp::R_SPARC_TLS_IE_LO10
:
3537 case elfcpp::R_SPARC_TLS_IE_LD
:
3538 case elfcpp::R_SPARC_TLS_IE_LDX
:
3539 case elfcpp::R_SPARC_TLS_IE_ADD
:
3540 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3541 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3542 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3543 r_type
, gsym
, psymval
, view
,
3544 address
, view_size
);
3547 case elfcpp::R_SPARC_COPY
:
3548 case elfcpp::R_SPARC_GLOB_DAT
:
3549 case elfcpp::R_SPARC_JMP_SLOT
:
3550 case elfcpp::R_SPARC_JMP_IREL
:
3551 case elfcpp::R_SPARC_RELATIVE
:
3552 case elfcpp::R_SPARC_IRELATIVE
:
3553 // These are outstanding tls relocs, which are unexpected when
3555 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3556 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3557 case elfcpp::R_SPARC_TLS_TPOFF64
:
3558 case elfcpp::R_SPARC_TLS_TPOFF32
:
3559 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3560 _("unexpected reloc %u in object file"),
3565 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3566 _("unsupported reloc %u"),
3574 // Perform a TLS relocation.
3576 template<int size
, bool big_endian
>
3578 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3579 const Relocate_info
<size
, big_endian
>* relinfo
,
3580 Target_sparc
<size
, big_endian
>* target
,
3582 const elfcpp::Rela
<size
, big_endian
>& rela
,
3583 unsigned int r_type
,
3584 const Sized_symbol
<size
>* gsym
,
3585 const Symbol_value
<size
>* psymval
,
3586 unsigned char* view
,
3587 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3590 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3591 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3592 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3593 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3595 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3596 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3598 const bool is_final
=
3600 ? !parameters
->options().output_is_position_independent()
3601 : gsym
->final_value_is_known());
3602 const tls::Tls_optimization optimized_type
3603 = optimize_tls_reloc(is_final
, r_type
);
3607 case elfcpp::R_SPARC_TLS_GD_HI22
:
3608 case elfcpp::R_SPARC_TLS_GD_LO10
:
3609 case elfcpp::R_SPARC_TLS_GD_ADD
:
3610 case elfcpp::R_SPARC_TLS_GD_CALL
:
3611 if (optimized_type
== tls::TLSOPT_TO_LE
)
3613 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3616 value
-= tls_segment
->memsz();
3620 case elfcpp::R_SPARC_TLS_GD_HI22
:
3621 // TLS_GD_HI22 --> TLS_LE_HIX22
3622 Reloc::hix22(view
, value
, addend
);
3625 case elfcpp::R_SPARC_TLS_GD_LO10
:
3626 // TLS_GD_LO10 --> TLS_LE_LOX10
3627 Reloc::lox10(view
, value
, addend
);
3630 case elfcpp::R_SPARC_TLS_GD_ADD
:
3631 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3632 val
= elfcpp::Swap
<32, true>::readval(wv
);
3633 val
= (val
& ~0x7c000) | 0x1c000;
3634 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3636 case elfcpp::R_SPARC_TLS_GD_CALL
:
3637 // call __tls_get_addr --> nop
3638 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3645 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3646 ? GOT_TYPE_TLS_OFFSET
3647 : GOT_TYPE_TLS_PAIR
);
3650 gold_assert(gsym
->has_got_offset(got_type
));
3651 value
= gsym
->got_offset(got_type
);
3655 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3656 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3657 value
= object
->local_got_offset(r_sym
, got_type
);
3659 if (optimized_type
== tls::TLSOPT_TO_IE
)
3661 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3666 case elfcpp::R_SPARC_TLS_GD_HI22
:
3667 // TLS_GD_HI22 --> TLS_IE_HI22
3668 Reloc::hi22(view
, value
, addend
);
3671 case elfcpp::R_SPARC_TLS_GD_LO10
:
3672 // TLS_GD_LO10 --> TLS_IE_LO10
3673 Reloc::lo10(view
, value
, addend
);
3676 case elfcpp::R_SPARC_TLS_GD_ADD
:
3677 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3678 val
= elfcpp::Swap
<32, true>::readval(wv
);
3685 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3688 case elfcpp::R_SPARC_TLS_GD_CALL
:
3689 // The compiler can put the TLS_GD_ADD instruction
3690 // into the delay slot of the call. If so, we need
3691 // to transpose the two instructions so that the
3692 // new sequence works properly.
3694 // The test we use is if the instruction in the
3695 // delay slot is an add with destination register
3697 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3698 if ((val
& 0x81f80000) == 0x80000000
3699 && ((val
>> 25) & 0x1f) == 0x8)
3706 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3709 this->ignore_gd_add_
= true;
3713 // Even if the delay slot isn't the TLS_GD_ADD
3714 // instruction, we still have to handle the case
3715 // where it sets up %o0 in some other way.
3716 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3718 this->reloc_adjust_addr_
= view
+ 4;
3720 // call __tls_get_addr --> add %g7, %o0, %o0
3721 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3726 else if (optimized_type
== tls::TLSOPT_NONE
)
3730 case elfcpp::R_SPARC_TLS_GD_HI22
:
3731 Reloc::hi22(view
, value
, addend
);
3733 case elfcpp::R_SPARC_TLS_GD_LO10
:
3734 Reloc::lo10(view
, value
, addend
);
3736 case elfcpp::R_SPARC_TLS_GD_ADD
:
3738 case elfcpp::R_SPARC_TLS_GD_CALL
:
3740 Symbol_value
<size
> symval
;
3741 elfcpp::Elf_Xword value
;
3744 tsym
= target
->tls_get_addr_sym_
;
3746 value
= (target
->plt_section()->address() +
3747 tsym
->plt_offset());
3748 symval
.set_output_value(value
);
3749 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3756 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3757 _("unsupported reloc %u"),
3761 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3762 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3763 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3764 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3765 if (optimized_type
== tls::TLSOPT_TO_LE
)
3767 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3771 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3772 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3773 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3774 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3777 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3778 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3783 else if (optimized_type
== tls::TLSOPT_NONE
)
3785 // Relocate the field with the offset of the GOT entry for
3786 // the module index.
3787 unsigned int got_offset
;
3789 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3792 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3793 Reloc::hi22(view
, got_offset
, addend
);
3795 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3796 Reloc::lo10(view
, got_offset
, addend
);
3798 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3800 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3802 Symbol_value
<size
> symval
;
3803 elfcpp::Elf_Xword value
;
3806 tsym
= target
->tls_get_addr_sym_
;
3808 value
= (target
->plt_section()->address() +
3809 tsym
->plt_offset());
3810 symval
.set_output_value(value
);
3811 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3817 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3818 _("unsupported reloc %u"),
3822 // These relocs can appear in debugging sections, in which case
3823 // we won't see the TLS_LDM relocs. The local_dynamic_type
3824 // field tells us this.
3825 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3826 if (optimized_type
== tls::TLSOPT_TO_LE
)
3828 value
-= tls_segment
->memsz();
3829 Reloc::hix22(view
, value
, addend
);
3832 Reloc::ldo_hix22(view
, value
, addend
);
3834 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3835 if (optimized_type
== tls::TLSOPT_TO_LE
)
3837 value
-= tls_segment
->memsz();
3838 Reloc::lox10(view
, value
, addend
);
3841 Reloc::ldo_lox10(view
, value
, addend
);
3843 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3844 if (optimized_type
== tls::TLSOPT_TO_LE
)
3846 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3849 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3850 val
= elfcpp::Swap
<32, true>::readval(wv
);
3851 val
= (val
& ~0x7c000) | 0x1c000;
3852 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3856 // When optimizing IE --> LE, the only relocation that is handled
3857 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3858 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3859 // rs2 and rd are the same.
3860 case elfcpp::R_SPARC_TLS_IE_LD
:
3861 case elfcpp::R_SPARC_TLS_IE_LDX
:
3862 if (optimized_type
== tls::TLSOPT_TO_LE
)
3864 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3865 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3866 Insntype rs2
= val
& 0x1f;
3867 Insntype rd
= (val
>> 25) & 0x1f;
3872 val
= sparc_mov
| (val
& 0x3e00001f);
3874 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3878 case elfcpp::R_SPARC_TLS_IE_HI22
:
3879 case elfcpp::R_SPARC_TLS_IE_LO10
:
3880 if (optimized_type
== tls::TLSOPT_TO_LE
)
3882 value
-= tls_segment
->memsz();
3885 case elfcpp::R_SPARC_TLS_IE_HI22
:
3886 // IE_HI22 --> LE_HIX22
3887 Reloc::hix22(view
, value
, addend
);
3889 case elfcpp::R_SPARC_TLS_IE_LO10
:
3890 // IE_LO10 --> LE_LOX10
3891 Reloc::lox10(view
, value
, addend
);
3896 else if (optimized_type
== tls::TLSOPT_NONE
)
3898 // Relocate the field with the offset of the GOT entry for
3899 // the tp-relative offset of the symbol.
3902 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3903 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3907 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3908 gold_assert(object
->local_has_got_offset(r_sym
,
3909 GOT_TYPE_TLS_OFFSET
));
3910 value
= object
->local_got_offset(r_sym
,
3911 GOT_TYPE_TLS_OFFSET
);
3915 case elfcpp::R_SPARC_TLS_IE_HI22
:
3916 Reloc::hi22(view
, value
, addend
);
3918 case elfcpp::R_SPARC_TLS_IE_LO10
:
3919 Reloc::lo10(view
, value
, addend
);
3924 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3925 _("unsupported reloc %u"),
3929 case elfcpp::R_SPARC_TLS_IE_ADD
:
3930 // This seems to be mainly so that we can find the addition
3931 // instruction if there is one. There doesn't seem to be any
3932 // actual relocation to apply.
3935 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3936 // If we're creating a shared library, a dynamic relocation will
3937 // have been created for this location, so do not apply it now.
3938 if (!parameters
->options().shared())
3940 value
-= tls_segment
->memsz();
3941 Reloc::hix22(view
, value
, addend
);
3945 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3946 // If we're creating a shared library, a dynamic relocation will
3947 // have been created for this location, so do not apply it now.
3948 if (!parameters
->options().shared())
3950 value
-= tls_segment
->memsz();
3951 Reloc::lox10(view
, value
, addend
);
3957 // Relocate section data.
3959 template<int size
, bool big_endian
>
3961 Target_sparc
<size
, big_endian
>::relocate_section(
3962 const Relocate_info
<size
, big_endian
>* relinfo
,
3963 unsigned int sh_type
,
3964 const unsigned char* prelocs
,
3966 Output_section
* output_section
,
3967 bool needs_special_offset_handling
,
3968 unsigned char* view
,
3969 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3970 section_size_type view_size
,
3971 const Reloc_symbol_changes
* reloc_symbol_changes
)
3973 typedef Target_sparc
<size
, big_endian
> Sparc
;
3974 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3976 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3978 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3985 needs_special_offset_handling
,
3989 reloc_symbol_changes
);
3992 // Return the size of a relocation while scanning during a relocatable
3995 template<int size
, bool big_endian
>
3997 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
4001 // We are always SHT_RELA, so we should never get here.
4006 // Scan the relocs during a relocatable link.
4008 template<int size
, bool big_endian
>
4010 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
4011 Symbol_table
* symtab
,
4013 Sized_relobj_file
<size
, big_endian
>* object
,
4014 unsigned int data_shndx
,
4015 unsigned int sh_type
,
4016 const unsigned char* prelocs
,
4018 Output_section
* output_section
,
4019 bool needs_special_offset_handling
,
4020 size_t local_symbol_count
,
4021 const unsigned char* plocal_symbols
,
4022 Relocatable_relocs
* rr
)
4024 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4026 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
4027 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
4029 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
4030 Scan_relocatable_relocs
>(
4038 needs_special_offset_handling
,
4044 // Relocate a section during a relocatable link.
4046 template<int size
, bool big_endian
>
4048 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
4049 const Relocate_info
<size
, big_endian
>* relinfo
,
4050 unsigned int sh_type
,
4051 const unsigned char* prelocs
,
4053 Output_section
* output_section
,
4054 off_t offset_in_output_section
,
4055 const Relocatable_relocs
* rr
,
4056 unsigned char* view
,
4057 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
4058 section_size_type view_size
,
4059 unsigned char* reloc_view
,
4060 section_size_type reloc_view_size
)
4062 gold_assert(sh_type
== elfcpp::SHT_RELA
);
4064 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
4069 offset_in_output_section
,
4078 // Return the value to use for a dynamic which requires special
4079 // treatment. This is how we support equality comparisons of function
4080 // pointers across shared library boundaries, as described in the
4081 // processor specific ABI supplement.
4083 template<int size
, bool big_endian
>
4085 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
4087 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
4088 return this->plt_section()->address() + gsym
->plt_offset();
4091 // do_make_elf_object to override the same function in the base class.
4092 // We need to use a target-specific sub-class of
4093 // Sized_relobj_file<size, big_endian> to process SPARC specific bits
4094 // of the ELF headers. Hence we need to have our own ELF object creation.
4096 template<int size
, bool big_endian
>
4098 Target_sparc
<size
, big_endian
>::do_make_elf_object(
4099 const std::string
& name
,
4100 Input_file
* input_file
,
4101 off_t offset
, const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
4103 elfcpp::Elf_Half machine
= ehdr
.get_e_machine();
4104 elfcpp::Elf_Word flags
= ehdr
.get_e_flags();
4105 elfcpp::Elf_Word omm
, mm
;
4109 case elfcpp::EM_SPARC32PLUS
:
4110 this->elf_machine_
= elfcpp::EM_SPARC32PLUS
;
4113 case elfcpp::EM_SPARC
:
4114 case elfcpp::EM_SPARCV9
:
4121 if (!this->elf_flags_set_
)
4123 this->elf_flags_
= flags
;
4124 this->elf_flags_set_
= true;
4128 // Accumulate cpu feature bits.
4129 this->elf_flags_
|= (flags
& (elfcpp::EF_SPARC_32PLUS
4130 | elfcpp::EF_SPARC_SUN_US1
4131 | elfcpp::EF_SPARC_HAL_R1
4132 | elfcpp::EF_SPARC_SUN_US3
));
4134 // Bump the memory model setting to the most restrictive
4135 // one we encounter.
4136 omm
= (this->elf_flags_
& elfcpp::EF_SPARCV9_MM
);
4137 mm
= (flags
& elfcpp::EF_SPARCV9_MM
);
4140 if (mm
== elfcpp::EF_SPARCV9_TSO
)
4142 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4143 this->elf_flags_
|= elfcpp::EF_SPARCV9_TSO
;
4145 else if (mm
== elfcpp::EF_SPARCV9_PSO
4146 && omm
== elfcpp::EF_SPARCV9_RMO
)
4148 this->elf_flags_
&= ~elfcpp::EF_SPARCV9_MM
;
4149 this->elf_flags_
|= elfcpp::EF_SPARCV9_PSO
;
4154 // Validate that the little-endian flag matches how we've
4155 // been instantiated.
4156 if (!(flags
& elfcpp::EF_SPARC_LEDATA
) != big_endian
)
4159 gold_error(_("%s: little endian elf flag set on BE object"),
4162 gold_error(_("%s: little endian elf flag clear on LE object"),
4166 return Target::do_make_elf_object(name
, input_file
, offset
, ehdr
);
4169 // Adjust ELF file header.
4171 template<int size
, bool big_endian
>
4173 Target_sparc
<size
, big_endian
>::do_adjust_elf_header(
4174 unsigned char* view
,
4177 elfcpp::Ehdr_write
<size
, big_endian
> oehdr(view
);
4179 oehdr
.put_e_machine(this->elf_machine_
);
4180 oehdr
.put_e_flags(this->elf_flags_
);
4182 Sized_target
<size
, big_endian
>::do_adjust_elf_header(view
, len
);
4185 // The selector for sparc object files.
4187 template<int size
, bool big_endian
>
4188 class Target_selector_sparc
: public Target_selector
4191 Target_selector_sparc()
4192 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
4193 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
4194 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
4197 Target
* do_recognize(int machine
, int, int)
4202 if (machine
!= elfcpp::EM_SPARCV9
)
4207 if (machine
!= elfcpp::EM_SPARC
4208 && machine
!= elfcpp::EM_SPARC32PLUS
)
4216 return this->instantiate_target();
4219 Target
* do_instantiate_target()
4220 { return new Target_sparc
<size
, big_endian
>(); }
4223 Target_selector_sparc
<32, true> target_selector_sparc32
;
4224 Target_selector_sparc
<64, true> target_selector_sparc64
;
4226 } // End anonymous namespace.