1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011 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
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
)
67 // Process the relocations to determine unreferenced sections for
68 // garbage collection.
70 gc_process_relocs(Symbol_table
* symtab
,
72 Sized_relobj_file
<size
, big_endian
>* object
,
73 unsigned int data_shndx
,
75 const unsigned char* prelocs
,
77 Output_section
* output_section
,
78 bool needs_special_offset_handling
,
79 size_t local_symbol_count
,
80 const unsigned char* plocal_symbols
);
82 // Scan the relocations to look for symbol adjustments.
84 scan_relocs(Symbol_table
* symtab
,
86 Sized_relobj_file
<size
, big_endian
>* object
,
87 unsigned int data_shndx
,
89 const unsigned char* prelocs
,
91 Output_section
* output_section
,
92 bool needs_special_offset_handling
,
93 size_t local_symbol_count
,
94 const unsigned char* plocal_symbols
);
95 // Finalize the sections.
97 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
99 // Return the value to use for a dynamic which requires special
102 do_dynsym_value(const Symbol
*) const;
104 // Relocate a section.
106 relocate_section(const Relocate_info
<size
, big_endian
>*,
107 unsigned int sh_type
,
108 const unsigned char* prelocs
,
110 Output_section
* output_section
,
111 bool needs_special_offset_handling
,
113 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
114 section_size_type view_size
,
115 const Reloc_symbol_changes
*);
117 // Scan the relocs during a relocatable link.
119 scan_relocatable_relocs(Symbol_table
* symtab
,
121 Sized_relobj_file
<size
, big_endian
>* object
,
122 unsigned int data_shndx
,
123 unsigned int sh_type
,
124 const unsigned char* prelocs
,
126 Output_section
* output_section
,
127 bool needs_special_offset_handling
,
128 size_t local_symbol_count
,
129 const unsigned char* plocal_symbols
,
130 Relocatable_relocs
*);
132 // Relocate a section during a relocatable link.
134 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
135 unsigned int sh_type
,
136 const unsigned char* prelocs
,
138 Output_section
* output_section
,
139 off_t offset_in_output_section
,
140 const Relocatable_relocs
*,
142 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
143 section_size_type view_size
,
144 unsigned char* reloc_view
,
145 section_size_type reloc_view_size
);
146 // Return whether SYM is defined by the ABI.
148 do_is_defined_by_abi(const Symbol
* sym
) const
150 // XXX Really need to support this better...
151 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
154 return strcmp(sym
->name(), "___tls_get_addr") == 0;
157 // Return whether there is a GOT section.
159 has_got_section() const
160 { return this->got_
!= NULL
; }
162 // Return the size of the GOT section.
166 gold_assert(this->got_
!= NULL
);
167 return this->got_
->data_size();
170 // Return the number of entries in the GOT.
172 got_entry_count() const
174 if (this->got_
== NULL
)
176 return this->got_size() / (size
/ 8);
179 // Return the number of entries in the PLT.
181 plt_entry_count() const;
183 // Return the offset of the first non-reserved PLT entry.
185 first_plt_entry_offset() const;
187 // Return the size of each PLT entry.
189 plt_entry_size() const;
193 // The class which scans relocations.
198 : issued_non_pic_error_(false)
202 get_reference_flags(unsigned int r_type
);
205 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
206 Sized_relobj_file
<size
, big_endian
>* object
,
207 unsigned int data_shndx
,
208 Output_section
* output_section
,
209 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
210 const elfcpp::Sym
<size
, big_endian
>& lsym
);
213 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
214 Sized_relobj_file
<size
, big_endian
>* object
,
215 unsigned int data_shndx
,
216 Output_section
* output_section
,
217 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
221 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
223 Sized_relobj_file
<size
, big_endian
>* ,
226 const elfcpp::Rela
<size
, big_endian
>& ,
228 const elfcpp::Sym
<size
, big_endian
>&)
232 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
234 Sized_relobj_file
<size
, big_endian
>* ,
237 const elfcpp::Rela
<size
,
239 unsigned int , Symbol
*)
245 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
246 unsigned int r_type
);
249 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
250 unsigned int r_type
, Symbol
*);
253 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
254 Target_sparc
* target
);
257 check_non_pic(Relobj
*, unsigned int r_type
);
259 // Whether we have issued an error about a non-PIC compilation.
260 bool issued_non_pic_error_
;
263 // The class which implements relocation.
268 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
273 if (this->ignore_gd_add_
)
275 // FIXME: This needs to specify the location somehow.
276 gold_error(_("missing expected TLS relocation"));
280 // Do a relocation. Return false if the caller should not issue
281 // any warnings about this relocation.
283 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
284 Output_section
*, size_t relnum
,
285 const elfcpp::Rela
<size
, big_endian
>&,
286 unsigned int r_type
, const Sized_symbol
<size
>*,
287 const Symbol_value
<size
>*,
289 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
293 // Do a TLS relocation.
295 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
296 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
297 unsigned int r_type
, const Sized_symbol
<size
>*,
298 const Symbol_value
<size
>*,
300 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
303 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
306 // If we hit a reloc at this view address, adjust it back by 4 bytes.
307 unsigned char *reloc_adjust_addr_
;
310 // A class which returns the size required for a relocation type,
311 // used while scanning relocs during a relocatable link.
312 class Relocatable_size_for_reloc
316 get_size_for_reloc(unsigned int, Relobj
*);
319 // Get the GOT section, creating it if necessary.
320 Output_data_got
<size
, big_endian
>*
321 got_section(Symbol_table
*, Layout
*);
323 // Create a PLT entry for a global symbol.
325 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
327 // Create a GOT entry for the TLS module index.
329 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
330 Sized_relobj_file
<size
, big_endian
>* object
);
332 // Return the gsym for "__tls_get_addr". Cache if not already
335 tls_get_addr_sym(Symbol_table
* symtab
)
337 if (!this->tls_get_addr_sym_
)
338 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
339 gold_assert(this->tls_get_addr_sym_
);
340 return this->tls_get_addr_sym_
;
343 // Get the PLT section.
344 const Output_data_plt_sparc
<size
, big_endian
>*
347 gold_assert(this->plt_
!= NULL
);
351 // Get the dynamic reloc section, creating it if necessary.
353 rela_dyn_section(Layout
*);
355 // Copy a relocation against a global symbol.
357 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
358 Sized_relobj_file
<size
, big_endian
>* object
,
359 unsigned int shndx
, Output_section
* output_section
,
360 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
362 this->copy_relocs_
.copy_reloc(symtab
, layout
,
363 symtab
->get_sized_symbol
<size
>(sym
),
364 object
, shndx
, output_section
,
365 reloc
, this->rela_dyn_section(layout
));
368 // Information about this specific target which we pass to the
369 // general Target structure.
370 static Target::Target_info sparc_info
;
372 // The types of GOT entries needed for this platform.
373 // These values are exposed to the ABI in an incremental link.
374 // Do not renumber existing values without changing the version
375 // number of the .gnu_incremental_inputs section.
378 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
379 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
380 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
384 Output_data_got
<size
, big_endian
>* got_
;
386 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
387 // The dynamic reloc section.
388 Reloc_section
* rela_dyn_
;
389 // Relocs saved to avoid a COPY reloc.
390 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
391 // Space for variables copied with a COPY reloc.
392 Output_data_space
* dynbss_
;
393 // Offset of the GOT entry for the TLS module index;
394 unsigned int got_mod_index_offset_
;
395 // Cached pointer to __tls_get_addr symbol
396 Symbol
* tls_get_addr_sym_
;
400 Target::Target_info Target_sparc
<32, true>::sparc_info
=
403 true, // is_big_endian
404 elfcpp::EM_SPARC
, // machine_code
405 false, // has_make_symbol
406 false, // has_resolve
407 false, // has_code_fill
408 true, // is_default_stack_executable
409 false, // can_icf_inline_merge_sections
411 "/usr/lib/ld.so.1", // dynamic_linker
412 0x00010000, // default_text_segment_address
413 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
414 8 * 1024, // common_pagesize (overridable by -z common-page-size)
415 elfcpp::SHN_UNDEF
, // small_common_shndx
416 elfcpp::SHN_UNDEF
, // large_common_shndx
417 0, // small_common_section_flags
418 0, // large_common_section_flags
419 NULL
, // attributes_section
420 NULL
// attributes_vendor
424 Target::Target_info Target_sparc
<64, true>::sparc_info
=
427 true, // is_big_endian
428 elfcpp::EM_SPARCV9
, // machine_code
429 false, // has_make_symbol
430 false, // has_resolve
431 false, // has_code_fill
432 true, // is_default_stack_executable
433 false, // can_icf_inline_merge_sections
435 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
436 0x100000, // default_text_segment_address
437 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
438 8 * 1024, // common_pagesize (overridable by -z common-page-size)
439 elfcpp::SHN_UNDEF
, // small_common_shndx
440 elfcpp::SHN_UNDEF
, // large_common_shndx
441 0, // small_common_section_flags
442 0, // large_common_section_flags
443 NULL
, // attributes_section
444 NULL
// attributes_vendor
447 // We have to take care here, even when operating in little-endian
448 // mode, sparc instructions are still big endian.
449 template<int size
, bool big_endian
>
450 class Sparc_relocate_functions
453 // Do a simple relocation with the addend in the relocation.
454 template<int valsize
>
456 rela(unsigned char* view
,
457 unsigned int right_shift
,
458 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
459 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
460 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
462 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
463 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
464 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
465 Valtype reloc
= ((value
+ addend
) >> right_shift
);
470 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
473 // Do a simple relocation using a symbol value with the addend in
475 template<int valsize
>
477 rela(unsigned char* view
,
478 unsigned int right_shift
,
479 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
480 const Sized_relobj_file
<size
, big_endian
>* object
,
481 const Symbol_value
<size
>* psymval
,
482 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
484 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
485 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
486 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
487 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
492 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
495 // Do a simple relocation using a symbol value with the addend in
496 // the relocation, unaligned.
497 template<int valsize
>
499 rela_ua(unsigned char* view
,
500 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
501 const Sized_relobj_file
<size
, big_endian
>* object
,
502 const Symbol_value
<size
>* psymval
,
503 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
505 typedef typename
elfcpp::Swap_unaligned
<valsize
,
506 big_endian
>::Valtype Valtype
;
507 unsigned char* wv
= view
;
508 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
509 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
514 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
517 // Do a simple PC relative relocation with a Symbol_value with the
518 // addend in the relocation.
519 template<int valsize
>
521 pcrela(unsigned char* view
,
522 unsigned int right_shift
,
523 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
524 const Sized_relobj_file
<size
, big_endian
>* object
,
525 const Symbol_value
<size
>* psymval
,
526 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
527 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
529 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
530 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
531 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
532 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
538 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
541 template<int valsize
>
543 pcrela_unaligned(unsigned char* view
,
544 const Sized_relobj_file
<size
, big_endian
>* object
,
545 const Symbol_value
<size
>* psymval
,
546 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
547 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
549 typedef typename
elfcpp::Swap_unaligned
<valsize
,
550 big_endian
>::Valtype Valtype
;
551 unsigned char* wv
= view
;
552 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
554 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
557 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
558 typedef Sparc_relocate_functions
<size
, true> This_insn
;
561 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
563 wdisp30(unsigned char* view
,
564 const Sized_relobj_file
<size
, big_endian
>* object
,
565 const Symbol_value
<size
>* psymval
,
566 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
567 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
569 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
570 psymval
, addend
, address
);
573 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
575 wdisp22(unsigned char* view
,
576 const Sized_relobj_file
<size
, big_endian
>* object
,
577 const Symbol_value
<size
>* psymval
,
578 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
579 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
581 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
582 psymval
, addend
, address
);
585 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
587 wdisp19(unsigned char* view
,
588 const Sized_relobj_file
<size
, big_endian
>* object
,
589 const Symbol_value
<size
>* psymval
,
590 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
591 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
593 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
594 psymval
, addend
, address
);
597 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
599 wdisp16(unsigned char* view
,
600 const Sized_relobj_file
<size
, big_endian
>* object
,
601 const Symbol_value
<size
>* psymval
,
602 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
603 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
605 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
606 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
607 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
608 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
611 // The relocation value is split between the low 14 bits,
613 val
&= ~((0x3 << 20) | 0x3fff);
614 reloc
= (((reloc
& 0xc000) << (20 - 14))
615 | (reloc
& 0x3ffff));
617 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
620 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
622 wdisp10(unsigned char* view
,
623 const Sized_relobj_file
<size
, big_endian
>* object
,
624 const Symbol_value
<size
>* psymval
,
625 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
626 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
628 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
629 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
630 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
631 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
634 // The relocation value is split between the low bits 5-12,
635 // and high bits 19-20.
636 val
&= ~((0x3 << 19) | (0xff << 5));
637 reloc
= (((reloc
& 0x300) << (19 - 8))
638 | ((reloc
& 0xff) << (5 - 0)));
640 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
643 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
645 pc22(unsigned char* view
,
646 const Sized_relobj_file
<size
, big_endian
>* object
,
647 const Symbol_value
<size
>* psymval
,
648 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
649 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
651 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
652 psymval
, addend
, address
);
655 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
657 pc10(unsigned char* view
,
658 const Sized_relobj_file
<size
, big_endian
>* object
,
659 const Symbol_value
<size
>* psymval
,
660 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
661 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
663 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
664 psymval
, addend
, address
);
667 // R_SPARC_HI22: (Symbol + Addend) >> 10
669 hi22(unsigned char* view
,
670 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
671 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
673 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
676 // R_SPARC_HI22: (Symbol + Addend) >> 10
678 hi22(unsigned char* view
,
679 const Sized_relobj_file
<size
, big_endian
>* object
,
680 const Symbol_value
<size
>* psymval
,
681 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
683 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
686 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
688 pcplt22(unsigned char* view
,
689 const Sized_relobj_file
<size
, big_endian
>* object
,
690 const Symbol_value
<size
>* psymval
,
691 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
694 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
695 psymval
, addend
, address
);
698 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
700 lo10(unsigned char* view
,
701 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
702 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
704 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
707 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
709 lo10(unsigned char* view
,
710 const Sized_relobj_file
<size
, big_endian
>* object
,
711 const Symbol_value
<size
>* psymval
,
712 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
714 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
717 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
719 lo10(unsigned char* view
,
720 const Sized_relobj_file
<size
, big_endian
>* object
,
721 const Symbol_value
<size
>* psymval
,
722 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
723 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
725 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
726 psymval
, addend
, address
);
729 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
731 olo10(unsigned char* view
,
732 const Sized_relobj_file
<size
, big_endian
>* object
,
733 const Symbol_value
<size
>* psymval
,
734 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
735 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
737 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
738 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
739 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
740 Valtype reloc
= psymval
->value(object
, addend
);
747 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
750 // R_SPARC_22: (Symbol + Addend)
752 rela32_22(unsigned char* view
,
753 const Sized_relobj_file
<size
, big_endian
>* object
,
754 const Symbol_value
<size
>* psymval
,
755 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
757 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
760 // R_SPARC_13: (Symbol + Addend)
762 rela32_13(unsigned char* view
,
763 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
764 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
766 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
769 // R_SPARC_13: (Symbol + Addend)
771 rela32_13(unsigned char* view
,
772 const Sized_relobj_file
<size
, big_endian
>* object
,
773 const Symbol_value
<size
>* psymval
,
774 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
776 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
779 // R_SPARC_UA16: (Symbol + Addend)
781 ua16(unsigned char* view
,
782 const Sized_relobj_file
<size
, big_endian
>* object
,
783 const Symbol_value
<size
>* psymval
,
784 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
786 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
789 // R_SPARC_UA32: (Symbol + Addend)
791 ua32(unsigned char* view
,
792 const Sized_relobj_file
<size
, big_endian
>* object
,
793 const Symbol_value
<size
>* psymval
,
794 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
796 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
799 // R_SPARC_UA64: (Symbol + Addend)
801 ua64(unsigned char* view
,
802 const Sized_relobj_file
<size
, big_endian
>* object
,
803 const Symbol_value
<size
>* psymval
,
804 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
806 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
807 object
, psymval
, addend
);
810 // R_SPARC_DISP8: (Symbol + Addend - Address)
812 disp8(unsigned char* view
,
813 const Sized_relobj_file
<size
, big_endian
>* object
,
814 const Symbol_value
<size
>* psymval
,
815 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
816 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
818 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
822 // R_SPARC_DISP16: (Symbol + Addend - Address)
824 disp16(unsigned char* view
,
825 const Sized_relobj_file
<size
, big_endian
>* object
,
826 const Symbol_value
<size
>* psymval
,
827 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
828 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
830 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
834 // R_SPARC_DISP32: (Symbol + Addend - Address)
836 disp32(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
,
840 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
842 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
846 // R_SPARC_DISP64: (Symbol + Addend - Address)
848 disp64(unsigned char* view
,
849 const Sized_relobj_file
<size
, big_endian
>* object
,
850 const Symbol_value
<size
>* psymval
,
851 elfcpp::Elf_Xword addend
,
852 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
854 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
858 // R_SPARC_H34: (Symbol + Addend) >> 12
860 h34(unsigned char* view
,
861 const Sized_relobj_file
<size
, big_endian
>* object
,
862 const Symbol_value
<size
>* psymval
,
863 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
865 This_insn::template rela
<32>(view
, 12, 0x003fffff, object
, psymval
, addend
);
868 // R_SPARC_H44: (Symbol + Addend) >> 22
870 h44(unsigned char* view
,
871 const Sized_relobj_file
<size
, big_endian
>* object
,
872 const Symbol_value
<size
>* psymval
,
873 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
875 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
878 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
880 m44(unsigned char* view
,
881 const Sized_relobj_file
<size
, big_endian
>* object
,
882 const Symbol_value
<size
>* psymval
,
883 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
885 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
888 // R_SPARC_L44: (Symbol + Addend) & 0xfff
890 l44(unsigned char* view
,
891 const Sized_relobj_file
<size
, big_endian
>* object
,
892 const Symbol_value
<size
>* psymval
,
893 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
895 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
898 // R_SPARC_HH22: (Symbol + Addend) >> 42
900 hh22(unsigned char* view
,
901 const Sized_relobj_file
<size
, big_endian
>* object
,
902 const Symbol_value
<size
>* psymval
,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
905 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
908 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
910 pc_hh22(unsigned char* view
,
911 const Sized_relobj_file
<size
, big_endian
>* object
,
912 const Symbol_value
<size
>* psymval
,
913 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
914 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
916 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
917 psymval
, addend
, address
);
920 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
922 hm10(unsigned char* view
,
923 const Sized_relobj_file
<size
, big_endian
>* object
,
924 const Symbol_value
<size
>* psymval
,
925 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
927 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
930 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
932 pc_hm10(unsigned char* view
,
933 const Sized_relobj_file
<size
, big_endian
>* object
,
934 const Symbol_value
<size
>* psymval
,
935 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
936 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
938 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
939 psymval
, addend
, address
);
942 // R_SPARC_11: (Symbol + Addend)
944 rela32_11(unsigned char* view
,
945 const Sized_relobj_file
<size
, big_endian
>* object
,
946 const Symbol_value
<size
>* psymval
,
947 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
949 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
952 // R_SPARC_10: (Symbol + Addend)
954 rela32_10(unsigned char* view
,
955 const Sized_relobj_file
<size
, big_endian
>* object
,
956 const Symbol_value
<size
>* psymval
,
957 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
959 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
962 // R_SPARC_7: (Symbol + Addend)
964 rela32_7(unsigned char* view
,
965 const Sized_relobj_file
<size
, big_endian
>* object
,
966 const Symbol_value
<size
>* psymval
,
967 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
969 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
972 // R_SPARC_6: (Symbol + Addend)
974 rela32_6(unsigned char* view
,
975 const Sized_relobj_file
<size
, big_endian
>* object
,
976 const Symbol_value
<size
>* psymval
,
977 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
979 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
982 // R_SPARC_5: (Symbol + Addend)
984 rela32_5(unsigned char* view
,
985 const Sized_relobj_file
<size
, big_endian
>* object
,
986 const Symbol_value
<size
>* psymval
,
987 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
989 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
992 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
994 ldo_hix22(unsigned char* view
,
995 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
996 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
998 This_insn::hi22(view
, value
, addend
);
1001 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1003 ldo_lox10(unsigned char* view
,
1004 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1005 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1007 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1008 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1009 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1010 Valtype reloc
= (value
+ addend
);
1015 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1018 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1020 hix22(unsigned char* view
,
1021 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1022 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1024 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1025 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1026 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1027 Valtype reloc
= (value
+ addend
);
1031 reloc
^= ~(Valtype
)0;
1036 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1039 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1041 hix22(unsigned char* view
,
1042 const Sized_relobj_file
<size
, big_endian
>* object
,
1043 const Symbol_value
<size
>* psymval
,
1044 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1046 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1047 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1048 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1049 Valtype reloc
= psymval
->value(object
, addend
);
1053 reloc
^= ~(Valtype
)0;
1058 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1062 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1064 lox10(unsigned char* view
,
1065 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1066 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1068 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1069 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1070 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1071 Valtype reloc
= (value
+ addend
);
1077 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1080 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1082 lox10(unsigned char* view
,
1083 const Sized_relobj_file
<size
, big_endian
>* object
,
1084 const Symbol_value
<size
>* psymval
,
1085 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1087 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1088 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1089 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1090 Valtype reloc
= psymval
->value(object
, addend
);
1096 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1100 // Get the GOT section, creating it if necessary.
1102 template<int size
, bool big_endian
>
1103 Output_data_got
<size
, big_endian
>*
1104 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1107 if (this->got_
== NULL
)
1109 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1111 this->got_
= new Output_data_got
<size
, big_endian
>();
1113 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1115 | elfcpp::SHF_WRITE
),
1116 this->got_
, ORDER_RELRO
, true);
1118 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1119 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1120 Symbol_table::PREDEFINED
,
1122 0, 0, elfcpp::STT_OBJECT
,
1124 elfcpp::STV_HIDDEN
, 0,
1131 // Get the dynamic reloc section, creating it if necessary.
1133 template<int size
, bool big_endian
>
1134 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1135 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1137 if (this->rela_dyn_
== NULL
)
1139 gold_assert(layout
!= NULL
);
1140 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1141 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1142 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1143 ORDER_DYNAMIC_RELOCS
, false);
1145 return this->rela_dyn_
;
1148 // A class to handle the PLT data.
1150 template<int size
, bool big_endian
>
1151 class Output_data_plt_sparc
: public Output_section_data
1154 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1155 size
, big_endian
> Reloc_section
;
1157 Output_data_plt_sparc(Layout
*);
1159 // Add an entry to the PLT.
1160 void add_entry(Symbol
* gsym
);
1162 // Return the .rela.plt section data.
1163 const Reloc_section
* rel_plt() const
1168 // Return the number of PLT entries.
1171 { return this->count_
; }
1173 // Return the offset of the first non-reserved PLT entry.
1175 first_plt_entry_offset()
1176 { return 4 * base_plt_entry_size
; }
1178 // Return the size of a PLT entry.
1180 get_plt_entry_size()
1181 { return base_plt_entry_size
; }
1184 void do_adjust_output_section(Output_section
* os
);
1186 // Write to a map file.
1188 do_print_to_mapfile(Mapfile
* mapfile
) const
1189 { mapfile
->print_output_data(this, _("** PLT")); }
1192 // The size of an entry in the PLT.
1193 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1195 static const unsigned int plt_entries_per_block
= 160;
1196 static const unsigned int plt_insn_chunk_size
= 24;
1197 static const unsigned int plt_pointer_chunk_size
= 8;
1198 static const unsigned int plt_block_size
=
1199 (plt_entries_per_block
1200 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1202 // Set the final size.
1204 set_final_data_size()
1206 unsigned int full_count
= this->count_
+ 4;
1207 unsigned int extra
= (size
== 32 ? 4 : 0);
1209 if (size
== 32 || full_count
< 32768)
1210 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1213 unsigned int ext_cnt
= full_count
- 32768;
1215 this->set_data_size((32768 * base_plt_entry_size
)
1217 * (plt_insn_chunk_size
1218 + plt_pointer_chunk_size
)));
1222 // Write out the PLT data.
1224 do_write(Output_file
*);
1226 // The reloc section.
1227 Reloc_section
* rel_
;
1228 // The number of PLT entries.
1229 unsigned int count_
;
1232 // Define the constants as required by C++ standard.
1234 template<int size
, bool big_endian
>
1235 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1237 template<int size
, bool big_endian
>
1239 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1241 template<int size
, bool big_endian
>
1242 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1244 template<int size
, bool big_endian
>
1246 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1248 template<int size
, bool big_endian
>
1249 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1251 // Create the PLT section. The ordinary .got section is an argument,
1252 // since we need to refer to the start.
1254 template<int size
, bool big_endian
>
1255 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1256 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1258 this->rel_
= new Reloc_section(false);
1259 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1260 elfcpp::SHF_ALLOC
, this->rel_
,
1261 ORDER_DYNAMIC_PLT_RELOCS
, false);
1264 template<int size
, bool big_endian
>
1266 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1271 // Add an entry to the PLT.
1273 template<int size
, bool big_endian
>
1275 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1277 gold_assert(!gsym
->has_plt_offset());
1279 unsigned int index
= this->count_
+ 4;
1280 section_offset_type plt_offset
;
1282 if (size
== 32 || index
< 32768)
1283 plt_offset
= index
* base_plt_entry_size
;
1286 unsigned int ext_index
= index
- 32768;
1288 plt_offset
= (32768 * base_plt_entry_size
)
1289 + ((ext_index
/ plt_entries_per_block
)
1291 + ((ext_index
% plt_entries_per_block
)
1292 * plt_insn_chunk_size
);
1295 gsym
->set_plt_offset(plt_offset
);
1299 // Every PLT entry needs a reloc.
1300 gsym
->set_needs_dynsym_entry();
1301 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1304 // Note that we don't need to save the symbol. The contents of the
1305 // PLT are independent of which symbols are used. The symbols only
1306 // appear in the relocations.
1309 static const unsigned int sparc_nop
= 0x01000000;
1310 static const unsigned int sparc_sethi_g1
= 0x03000000;
1311 static const unsigned int sparc_branch_always
= 0x30800000;
1312 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1313 static const unsigned int sparc_mov
= 0x80100000;
1314 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1315 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1316 static const unsigned int sparc_call_plus_8
= 0x40000002;
1317 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1318 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1319 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1321 // Write out the PLT.
1323 template<int size
, bool big_endian
>
1325 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1327 const off_t offset
= this->offset();
1328 const section_size_type oview_size
=
1329 convert_to_section_size_type(this->data_size());
1330 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1331 unsigned char* pov
= oview
;
1333 memset(pov
, 0, base_plt_entry_size
* 4);
1334 pov
+= base_plt_entry_size
* 4;
1336 unsigned int plt_offset
= base_plt_entry_size
* 4;
1337 const unsigned int count
= this->count_
;
1343 limit
= (count
> 32768 ? 32768 : count
);
1345 for (unsigned int i
= 0; i
< limit
; ++i
)
1347 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1348 sparc_sethi_g1
+ plt_offset
);
1349 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1350 sparc_branch_always_pt
+
1351 (((base_plt_entry_size
-
1352 (plt_offset
+ 4)) >> 2) &
1354 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1355 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1356 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1357 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1358 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1359 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1361 pov
+= base_plt_entry_size
;
1362 plt_offset
+= base_plt_entry_size
;
1367 unsigned int ext_cnt
= count
- 32768;
1368 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1370 for (unsigned int i
= 0; i
< blks
; ++i
)
1372 unsigned int data_off
= (plt_entries_per_block
1373 * plt_insn_chunk_size
) - 4;
1375 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1377 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1379 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1381 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1383 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1384 sparc_ldx_o7_imm_g1
+
1385 (data_off
& 0x1fff));
1386 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1387 sparc_jmpl_o7_g1_g1
);
1388 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1391 elfcpp::Swap
<64, big_endian
>::writeval(
1392 pov
+ 0x4 + data_off
,
1393 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1395 pov
+= plt_insn_chunk_size
;
1400 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1401 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1403 unsigned int data_off
= (sub_blk_cnt
1404 * plt_insn_chunk_size
) - 4;
1406 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1408 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1410 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1412 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1414 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1415 sparc_ldx_o7_imm_g1
+
1416 (data_off
& 0x1fff));
1417 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1418 sparc_jmpl_o7_g1_g1
);
1419 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1422 elfcpp::Swap
<64, big_endian
>::writeval(
1423 pov
+ 0x4 + data_off
,
1424 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1426 pov
+= plt_insn_chunk_size
;
1434 for (unsigned int i
= 0; i
< count
; ++i
)
1436 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1437 sparc_sethi_g1
+ plt_offset
);
1438 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1439 sparc_branch_always
+
1440 (((- (plt_offset
+ 4)) >> 2) &
1442 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1444 pov
+= base_plt_entry_size
;
1445 plt_offset
+= base_plt_entry_size
;
1448 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1452 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1454 of
->write_output_view(offset
, oview_size
, oview
);
1457 // Create a PLT entry for a global symbol.
1459 template<int size
, bool big_endian
>
1461 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1465 if (gsym
->has_plt_offset())
1468 if (this->plt_
== NULL
)
1470 // Create the GOT sections first.
1471 this->got_section(symtab
, layout
);
1473 // Ensure that .rela.dyn always appears before .rela.plt This is
1474 // necessary due to how, on Sparc and some other targets, .rela.dyn
1475 // needs to include .rela.plt in it's range.
1476 this->rela_dyn_section(layout
);
1478 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1479 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1481 | elfcpp::SHF_EXECINSTR
1482 | elfcpp::SHF_WRITE
),
1483 this->plt_
, ORDER_PLT
, false);
1485 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1486 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1487 Symbol_table::PREDEFINED
,
1489 0, 0, elfcpp::STT_OBJECT
,
1491 elfcpp::STV_HIDDEN
, 0,
1495 this->plt_
->add_entry(gsym
);
1498 // Return the number of entries in the PLT.
1500 template<int size
, bool big_endian
>
1502 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1504 if (this->plt_
== NULL
)
1506 return this->plt_
->entry_count();
1509 // Return the offset of the first non-reserved PLT entry.
1511 template<int size
, bool big_endian
>
1513 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1515 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1518 // Return the size of each PLT entry.
1520 template<int size
, bool big_endian
>
1522 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1524 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1527 // Create a GOT entry for the TLS module index.
1529 template<int size
, bool big_endian
>
1531 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1532 Symbol_table
* symtab
,
1534 Sized_relobj_file
<size
, big_endian
>* object
)
1536 if (this->got_mod_index_offset_
== -1U)
1538 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1539 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1540 Output_data_got
<size
, big_endian
>* got
;
1541 unsigned int got_offset
;
1543 got
= this->got_section(symtab
, layout
);
1544 got_offset
= got
->add_constant(0);
1545 rela_dyn
->add_local(object
, 0,
1547 elfcpp::R_SPARC_TLS_DTPMOD64
:
1548 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1550 got
->add_constant(0);
1551 this->got_mod_index_offset_
= got_offset
;
1553 return this->got_mod_index_offset_
;
1556 // Optimize the TLS relocation type based on what we know about the
1557 // symbol. IS_FINAL is true if the final address of this symbol is
1558 // known at link time.
1560 static tls::Tls_optimization
1561 optimize_tls_reloc(bool is_final
, int r_type
)
1563 // If we are generating a shared library, then we can't do anything
1565 if (parameters
->options().shared())
1566 return tls::TLSOPT_NONE
;
1570 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1571 case elfcpp::R_SPARC_TLS_GD_LO10
:
1572 case elfcpp::R_SPARC_TLS_GD_ADD
:
1573 case elfcpp::R_SPARC_TLS_GD_CALL
:
1574 // These are General-Dynamic which permits fully general TLS
1575 // access. Since we know that we are generating an executable,
1576 // we can convert this to Initial-Exec. If we also know that
1577 // this is a local symbol, we can further switch to Local-Exec.
1579 return tls::TLSOPT_TO_LE
;
1580 return tls::TLSOPT_TO_IE
;
1582 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1583 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1584 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1585 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1586 // This is Local-Dynamic, which refers to a local symbol in the
1587 // dynamic TLS block. Since we know that we generating an
1588 // executable, we can switch to Local-Exec.
1589 return tls::TLSOPT_TO_LE
;
1591 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1592 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1593 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1594 // Another type of Local-Dynamic relocation.
1595 return tls::TLSOPT_TO_LE
;
1597 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1598 case elfcpp::R_SPARC_TLS_IE_LO10
:
1599 case elfcpp::R_SPARC_TLS_IE_LD
:
1600 case elfcpp::R_SPARC_TLS_IE_LDX
:
1601 case elfcpp::R_SPARC_TLS_IE_ADD
:
1602 // These are Initial-Exec relocs which get the thread offset
1603 // from the GOT. If we know that we are linking against the
1604 // local symbol, we can switch to Local-Exec, which links the
1605 // thread offset into the instruction.
1607 return tls::TLSOPT_TO_LE
;
1608 return tls::TLSOPT_NONE
;
1610 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1611 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1612 // When we already have Local-Exec, there is nothing further we
1614 return tls::TLSOPT_NONE
;
1621 // Get the Reference_flags for a particular relocation.
1623 template<int size
, bool big_endian
>
1625 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1630 case elfcpp::R_SPARC_NONE
:
1631 case elfcpp::R_SPARC_REGISTER
:
1632 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1633 case elfcpp::R_SPARC_GNU_VTENTRY
:
1634 // No symbol reference.
1637 case elfcpp::R_SPARC_UA64
:
1638 case elfcpp::R_SPARC_64
:
1639 case elfcpp::R_SPARC_HIX22
:
1640 case elfcpp::R_SPARC_LOX10
:
1641 case elfcpp::R_SPARC_H34
:
1642 case elfcpp::R_SPARC_H44
:
1643 case elfcpp::R_SPARC_M44
:
1644 case elfcpp::R_SPARC_L44
:
1645 case elfcpp::R_SPARC_HH22
:
1646 case elfcpp::R_SPARC_HM10
:
1647 case elfcpp::R_SPARC_LM22
:
1648 case elfcpp::R_SPARC_HI22
:
1649 case elfcpp::R_SPARC_LO10
:
1650 case elfcpp::R_SPARC_OLO10
:
1651 case elfcpp::R_SPARC_UA32
:
1652 case elfcpp::R_SPARC_32
:
1653 case elfcpp::R_SPARC_UA16
:
1654 case elfcpp::R_SPARC_16
:
1655 case elfcpp::R_SPARC_11
:
1656 case elfcpp::R_SPARC_10
:
1657 case elfcpp::R_SPARC_8
:
1658 case elfcpp::R_SPARC_7
:
1659 case elfcpp::R_SPARC_6
:
1660 case elfcpp::R_SPARC_5
:
1661 return Symbol::ABSOLUTE_REF
;
1663 case elfcpp::R_SPARC_DISP8
:
1664 case elfcpp::R_SPARC_DISP16
:
1665 case elfcpp::R_SPARC_DISP32
:
1666 case elfcpp::R_SPARC_DISP64
:
1667 case elfcpp::R_SPARC_PC_HH22
:
1668 case elfcpp::R_SPARC_PC_HM10
:
1669 case elfcpp::R_SPARC_PC_LM22
:
1670 case elfcpp::R_SPARC_PC10
:
1671 case elfcpp::R_SPARC_PC22
:
1672 case elfcpp::R_SPARC_WDISP30
:
1673 case elfcpp::R_SPARC_WDISP22
:
1674 case elfcpp::R_SPARC_WDISP19
:
1675 case elfcpp::R_SPARC_WDISP16
:
1676 case elfcpp::R_SPARC_WDISP10
:
1677 return Symbol::RELATIVE_REF
;
1679 case elfcpp::R_SPARC_PLT64
:
1680 case elfcpp::R_SPARC_PLT32
:
1681 case elfcpp::R_SPARC_HIPLT22
:
1682 case elfcpp::R_SPARC_LOPLT10
:
1683 case elfcpp::R_SPARC_PCPLT10
:
1684 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
1686 case elfcpp::R_SPARC_PCPLT32
:
1687 case elfcpp::R_SPARC_PCPLT22
:
1688 case elfcpp::R_SPARC_WPLT30
:
1689 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1691 case elfcpp::R_SPARC_GOTDATA_OP
:
1692 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1693 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1694 case elfcpp::R_SPARC_GOT10
:
1695 case elfcpp::R_SPARC_GOT13
:
1696 case elfcpp::R_SPARC_GOT22
:
1698 return Symbol::ABSOLUTE_REF
;
1700 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1701 case elfcpp::R_SPARC_TLS_GD_LO10
:
1702 case elfcpp::R_SPARC_TLS_GD_ADD
:
1703 case elfcpp::R_SPARC_TLS_GD_CALL
:
1704 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1705 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1706 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1707 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1708 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1709 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1710 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1711 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1712 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1713 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1714 case elfcpp::R_SPARC_TLS_IE_LO10
:
1715 case elfcpp::R_SPARC_TLS_IE_LD
:
1716 case elfcpp::R_SPARC_TLS_IE_LDX
:
1717 case elfcpp::R_SPARC_TLS_IE_ADD
:
1718 return Symbol::TLS_REF
;
1720 case elfcpp::R_SPARC_COPY
:
1721 case elfcpp::R_SPARC_GLOB_DAT
:
1722 case elfcpp::R_SPARC_JMP_SLOT
:
1723 case elfcpp::R_SPARC_RELATIVE
:
1724 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1725 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1726 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1727 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1728 case elfcpp::R_SPARC_TLS_TPOFF64
:
1729 case elfcpp::R_SPARC_TLS_TPOFF32
:
1731 // Not expected. We will give an error later.
1736 // Generate a PLT entry slot for a call to __tls_get_addr
1737 template<int size
, bool big_endian
>
1739 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1741 Target_sparc
<size
, big_endian
>* target
)
1743 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1745 target
->make_plt_entry(symtab
, layout
, gsym
);
1748 // Report an unsupported relocation against a local symbol.
1750 template<int size
, bool big_endian
>
1752 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1753 Sized_relobj_file
<size
, big_endian
>* object
,
1754 unsigned int r_type
)
1756 gold_error(_("%s: unsupported reloc %u against local symbol"),
1757 object
->name().c_str(), r_type
);
1760 // We are about to emit a dynamic relocation of type R_TYPE. If the
1761 // dynamic linker does not support it, issue an error.
1763 template<int size
, bool big_endian
>
1765 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1767 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1773 // These are the relocation types supported by glibc for sparc 64-bit.
1774 case elfcpp::R_SPARC_RELATIVE
:
1775 case elfcpp::R_SPARC_COPY
:
1776 case elfcpp::R_SPARC_64
:
1777 case elfcpp::R_SPARC_GLOB_DAT
:
1778 case elfcpp::R_SPARC_JMP_SLOT
:
1779 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1780 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1781 case elfcpp::R_SPARC_TLS_TPOFF64
:
1782 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1783 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1784 case elfcpp::R_SPARC_8
:
1785 case elfcpp::R_SPARC_16
:
1786 case elfcpp::R_SPARC_DISP8
:
1787 case elfcpp::R_SPARC_DISP16
:
1788 case elfcpp::R_SPARC_DISP32
:
1789 case elfcpp::R_SPARC_WDISP30
:
1790 case elfcpp::R_SPARC_LO10
:
1791 case elfcpp::R_SPARC_HI22
:
1792 case elfcpp::R_SPARC_OLO10
:
1793 case elfcpp::R_SPARC_H34
:
1794 case elfcpp::R_SPARC_H44
:
1795 case elfcpp::R_SPARC_M44
:
1796 case elfcpp::R_SPARC_L44
:
1797 case elfcpp::R_SPARC_HH22
:
1798 case elfcpp::R_SPARC_HM10
:
1799 case elfcpp::R_SPARC_LM22
:
1800 case elfcpp::R_SPARC_UA16
:
1801 case elfcpp::R_SPARC_UA32
:
1802 case elfcpp::R_SPARC_UA64
:
1813 // These are the relocation types supported by glibc for sparc 32-bit.
1814 case elfcpp::R_SPARC_RELATIVE
:
1815 case elfcpp::R_SPARC_COPY
:
1816 case elfcpp::R_SPARC_GLOB_DAT
:
1817 case elfcpp::R_SPARC_32
:
1818 case elfcpp::R_SPARC_JMP_SLOT
:
1819 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1820 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1821 case elfcpp::R_SPARC_TLS_TPOFF32
:
1822 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1823 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1824 case elfcpp::R_SPARC_8
:
1825 case elfcpp::R_SPARC_16
:
1826 case elfcpp::R_SPARC_DISP8
:
1827 case elfcpp::R_SPARC_DISP16
:
1828 case elfcpp::R_SPARC_DISP32
:
1829 case elfcpp::R_SPARC_LO10
:
1830 case elfcpp::R_SPARC_WDISP30
:
1831 case elfcpp::R_SPARC_HI22
:
1832 case elfcpp::R_SPARC_UA16
:
1833 case elfcpp::R_SPARC_UA32
:
1841 // This prevents us from issuing more than one error per reloc
1842 // section. But we can still wind up issuing more than one
1843 // error per object file.
1844 if (this->issued_non_pic_error_
)
1846 gold_assert(parameters
->options().output_is_position_independent());
1847 object
->error(_("requires unsupported dynamic reloc; "
1848 "recompile with -fPIC"));
1849 this->issued_non_pic_error_
= true;
1853 // Scan a relocation for a local symbol.
1855 template<int size
, bool big_endian
>
1857 Target_sparc
<size
, big_endian
>::Scan::local(
1858 Symbol_table
* symtab
,
1860 Target_sparc
<size
, big_endian
>* target
,
1861 Sized_relobj_file
<size
, big_endian
>* object
,
1862 unsigned int data_shndx
,
1863 Output_section
* output_section
,
1864 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1865 unsigned int r_type
,
1866 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1868 unsigned int orig_r_type
= r_type
;
1873 case elfcpp::R_SPARC_NONE
:
1874 case elfcpp::R_SPARC_REGISTER
:
1875 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1876 case elfcpp::R_SPARC_GNU_VTENTRY
:
1879 case elfcpp::R_SPARC_64
:
1880 case elfcpp::R_SPARC_32
:
1881 // If building a shared library (or a position-independent
1882 // executable), we need to create a dynamic relocation for
1883 // this location. The relocation applied at link time will
1884 // apply the link-time value, so we flag the location with
1885 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1886 // relocate it easily.
1887 if (parameters
->options().output_is_position_independent())
1889 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1890 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1891 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1892 output_section
, data_shndx
,
1893 reloc
.get_r_offset(),
1894 reloc
.get_r_addend(), false);
1898 case elfcpp::R_SPARC_HIX22
:
1899 case elfcpp::R_SPARC_LOX10
:
1900 case elfcpp::R_SPARC_H34
:
1901 case elfcpp::R_SPARC_H44
:
1902 case elfcpp::R_SPARC_M44
:
1903 case elfcpp::R_SPARC_L44
:
1904 case elfcpp::R_SPARC_HH22
:
1905 case elfcpp::R_SPARC_HM10
:
1906 case elfcpp::R_SPARC_LM22
:
1907 case elfcpp::R_SPARC_UA64
:
1908 case elfcpp::R_SPARC_UA32
:
1909 case elfcpp::R_SPARC_UA16
:
1910 case elfcpp::R_SPARC_HI22
:
1911 case elfcpp::R_SPARC_LO10
:
1912 case elfcpp::R_SPARC_OLO10
:
1913 case elfcpp::R_SPARC_16
:
1914 case elfcpp::R_SPARC_11
:
1915 case elfcpp::R_SPARC_10
:
1916 case elfcpp::R_SPARC_8
:
1917 case elfcpp::R_SPARC_7
:
1918 case elfcpp::R_SPARC_6
:
1919 case elfcpp::R_SPARC_5
:
1920 // If building a shared library (or a position-independent
1921 // executable), we need to create a dynamic relocation for
1923 if (parameters
->options().output_is_position_independent())
1925 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1926 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1928 check_non_pic(object
, r_type
);
1929 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1931 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1932 data_shndx
, reloc
.get_r_offset(),
1933 reloc
.get_r_addend());
1937 gold_assert(lsym
.get_st_value() == 0);
1938 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
1939 output_section
, data_shndx
,
1940 reloc
.get_r_offset(),
1941 reloc
.get_r_addend());
1946 case elfcpp::R_SPARC_WDISP30
:
1947 case elfcpp::R_SPARC_WPLT30
:
1948 case elfcpp::R_SPARC_WDISP22
:
1949 case elfcpp::R_SPARC_WDISP19
:
1950 case elfcpp::R_SPARC_WDISP16
:
1951 case elfcpp::R_SPARC_WDISP10
:
1952 case elfcpp::R_SPARC_DISP8
:
1953 case elfcpp::R_SPARC_DISP16
:
1954 case elfcpp::R_SPARC_DISP32
:
1955 case elfcpp::R_SPARC_DISP64
:
1956 case elfcpp::R_SPARC_PC10
:
1957 case elfcpp::R_SPARC_PC22
:
1960 case elfcpp::R_SPARC_GOTDATA_OP
:
1961 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1962 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1963 case elfcpp::R_SPARC_GOT10
:
1964 case elfcpp::R_SPARC_GOT13
:
1965 case elfcpp::R_SPARC_GOT22
:
1967 // The symbol requires a GOT entry.
1968 Output_data_got
<size
, big_endian
>* got
;
1971 got
= target
->got_section(symtab
, layout
);
1972 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1974 // If we are generating a shared object, we need to add a
1975 // dynamic relocation for this symbol's GOT entry.
1976 if (parameters
->options().output_is_position_independent())
1978 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1980 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1983 off
= got
->add_constant(0);
1984 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1985 rela_dyn
->add_local_relative(object
, r_sym
,
1986 elfcpp::R_SPARC_RELATIVE
,
1987 got
, off
, 0, false);
1991 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1995 // These are initial TLS relocs, which are expected when
1997 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1998 case elfcpp::R_SPARC_TLS_GD_LO10
:
1999 case elfcpp::R_SPARC_TLS_GD_ADD
:
2000 case elfcpp::R_SPARC_TLS_GD_CALL
:
2001 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2002 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2003 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2004 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2005 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2006 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2007 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2008 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2009 case elfcpp::R_SPARC_TLS_IE_LO10
:
2010 case elfcpp::R_SPARC_TLS_IE_LD
:
2011 case elfcpp::R_SPARC_TLS_IE_LDX
:
2012 case elfcpp::R_SPARC_TLS_IE_ADD
:
2013 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2014 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2016 bool output_is_shared
= parameters
->options().shared();
2017 const tls::Tls_optimization optimized_type
2018 = optimize_tls_reloc(!output_is_shared
, r_type
);
2021 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2022 case elfcpp::R_SPARC_TLS_GD_LO10
:
2023 case elfcpp::R_SPARC_TLS_GD_ADD
:
2024 case elfcpp::R_SPARC_TLS_GD_CALL
:
2025 if (optimized_type
== tls::TLSOPT_NONE
)
2027 // Create a pair of GOT entries for the module index and
2028 // dtv-relative offset.
2029 Output_data_got
<size
, big_endian
>* got
2030 = target
->got_section(symtab
, layout
);
2031 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2032 unsigned int shndx
= lsym
.get_st_shndx();
2034 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2036 object
->error(_("local symbol %u has bad shndx %u"),
2039 got
->add_local_pair_with_rel(object
, r_sym
,
2040 lsym
.get_st_shndx(),
2042 target
->rela_dyn_section(layout
),
2044 ? elfcpp::R_SPARC_TLS_DTPMOD64
2045 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2047 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2048 generate_tls_call(symtab
, layout
, target
);
2050 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2051 unsupported_reloc_local(object
, r_type
);
2054 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2055 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2056 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2057 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2058 if (optimized_type
== tls::TLSOPT_NONE
)
2060 // Create a GOT entry for the module index.
2061 target
->got_mod_index_entry(symtab
, layout
, object
);
2063 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2064 generate_tls_call(symtab
, layout
, target
);
2066 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2067 unsupported_reloc_local(object
, r_type
);
2070 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2071 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2072 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2075 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2076 case elfcpp::R_SPARC_TLS_IE_LO10
:
2077 case elfcpp::R_SPARC_TLS_IE_LD
:
2078 case elfcpp::R_SPARC_TLS_IE_LDX
:
2079 case elfcpp::R_SPARC_TLS_IE_ADD
:
2080 layout
->set_has_static_tls();
2081 if (optimized_type
== tls::TLSOPT_NONE
)
2083 // Create a GOT entry for the tp-relative offset.
2084 Output_data_got
<size
, big_endian
>* got
2085 = target
->got_section(symtab
, layout
);
2086 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2088 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2090 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2091 unsigned int off
= got
->add_constant(0);
2093 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2095 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2097 elfcpp::R_SPARC_TLS_TPOFF64
:
2098 elfcpp::R_SPARC_TLS_TPOFF32
),
2102 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2103 unsupported_reloc_local(object
, r_type
);
2106 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2107 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2108 layout
->set_has_static_tls();
2109 if (output_is_shared
)
2111 // We need to create a dynamic relocation.
2112 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2113 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2114 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2115 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2116 output_section
, data_shndx
,
2117 reloc
.get_r_offset(), 0);
2124 // These are relocations which should only be seen by the
2125 // dynamic linker, and should never be seen here.
2126 case elfcpp::R_SPARC_COPY
:
2127 case elfcpp::R_SPARC_GLOB_DAT
:
2128 case elfcpp::R_SPARC_JMP_SLOT
:
2129 case elfcpp::R_SPARC_RELATIVE
:
2130 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2131 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2132 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2133 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2134 case elfcpp::R_SPARC_TLS_TPOFF64
:
2135 case elfcpp::R_SPARC_TLS_TPOFF32
:
2136 gold_error(_("%s: unexpected reloc %u in object file"),
2137 object
->name().c_str(), r_type
);
2141 unsupported_reloc_local(object
, r_type
);
2146 // Report an unsupported relocation against a global symbol.
2148 template<int size
, bool big_endian
>
2150 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2151 Sized_relobj_file
<size
, big_endian
>* object
,
2152 unsigned int r_type
,
2155 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2156 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2159 // Scan a relocation for a global symbol.
2161 template<int size
, bool big_endian
>
2163 Target_sparc
<size
, big_endian
>::Scan::global(
2164 Symbol_table
* symtab
,
2166 Target_sparc
<size
, big_endian
>* target
,
2167 Sized_relobj_file
<size
, big_endian
>* object
,
2168 unsigned int data_shndx
,
2169 Output_section
* output_section
,
2170 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2171 unsigned int r_type
,
2174 unsigned int orig_r_type
= r_type
;
2176 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2177 // section. We check here to avoid creating a dynamic reloc against
2178 // _GLOBAL_OFFSET_TABLE_.
2179 if (!target
->has_got_section()
2180 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2181 target
->got_section(symtab
, layout
);
2186 case elfcpp::R_SPARC_NONE
:
2187 case elfcpp::R_SPARC_REGISTER
:
2188 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2189 case elfcpp::R_SPARC_GNU_VTENTRY
:
2192 case elfcpp::R_SPARC_PLT64
:
2193 case elfcpp::R_SPARC_PLT32
:
2194 case elfcpp::R_SPARC_HIPLT22
:
2195 case elfcpp::R_SPARC_LOPLT10
:
2196 case elfcpp::R_SPARC_PCPLT32
:
2197 case elfcpp::R_SPARC_PCPLT22
:
2198 case elfcpp::R_SPARC_PCPLT10
:
2199 case elfcpp::R_SPARC_WPLT30
:
2200 // If the symbol is fully resolved, this is just a PC32 reloc.
2201 // Otherwise we need a PLT entry.
2202 if (gsym
->final_value_is_known())
2204 // If building a shared library, we can also skip the PLT entry
2205 // if the symbol is defined in the output file and is protected
2207 if (gsym
->is_defined()
2208 && !gsym
->is_from_dynobj()
2209 && !gsym
->is_preemptible())
2211 target
->make_plt_entry(symtab
, layout
, gsym
);
2214 case elfcpp::R_SPARC_DISP8
:
2215 case elfcpp::R_SPARC_DISP16
:
2216 case elfcpp::R_SPARC_DISP32
:
2217 case elfcpp::R_SPARC_DISP64
:
2218 case elfcpp::R_SPARC_PC_HH22
:
2219 case elfcpp::R_SPARC_PC_HM10
:
2220 case elfcpp::R_SPARC_PC_LM22
:
2221 case elfcpp::R_SPARC_PC10
:
2222 case elfcpp::R_SPARC_PC22
:
2223 case elfcpp::R_SPARC_WDISP30
:
2224 case elfcpp::R_SPARC_WDISP22
:
2225 case elfcpp::R_SPARC_WDISP19
:
2226 case elfcpp::R_SPARC_WDISP16
:
2227 case elfcpp::R_SPARC_WDISP10
:
2229 if (gsym
->needs_plt_entry())
2230 target
->make_plt_entry(symtab
, layout
, gsym
);
2231 // Make a dynamic relocation if necessary.
2232 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2234 if (gsym
->may_need_copy_reloc())
2236 target
->copy_reloc(symtab
, layout
, object
,
2237 data_shndx
, output_section
, gsym
,
2242 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2243 check_non_pic(object
, r_type
);
2244 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2245 data_shndx
, reloc
.get_r_offset(),
2246 reloc
.get_r_addend());
2252 case elfcpp::R_SPARC_UA64
:
2253 case elfcpp::R_SPARC_64
:
2254 case elfcpp::R_SPARC_HIX22
:
2255 case elfcpp::R_SPARC_LOX10
:
2256 case elfcpp::R_SPARC_H34
:
2257 case elfcpp::R_SPARC_H44
:
2258 case elfcpp::R_SPARC_M44
:
2259 case elfcpp::R_SPARC_L44
:
2260 case elfcpp::R_SPARC_HH22
:
2261 case elfcpp::R_SPARC_HM10
:
2262 case elfcpp::R_SPARC_LM22
:
2263 case elfcpp::R_SPARC_HI22
:
2264 case elfcpp::R_SPARC_LO10
:
2265 case elfcpp::R_SPARC_OLO10
:
2266 case elfcpp::R_SPARC_UA32
:
2267 case elfcpp::R_SPARC_32
:
2268 case elfcpp::R_SPARC_UA16
:
2269 case elfcpp::R_SPARC_16
:
2270 case elfcpp::R_SPARC_11
:
2271 case elfcpp::R_SPARC_10
:
2272 case elfcpp::R_SPARC_8
:
2273 case elfcpp::R_SPARC_7
:
2274 case elfcpp::R_SPARC_6
:
2275 case elfcpp::R_SPARC_5
:
2277 // Make a PLT entry if necessary.
2278 if (gsym
->needs_plt_entry())
2280 target
->make_plt_entry(symtab
, layout
, gsym
);
2281 // Since this is not a PC-relative relocation, we may be
2282 // taking the address of a function. In that case we need to
2283 // set the entry in the dynamic symbol table to the address of
2285 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2286 gsym
->set_needs_dynsym_value();
2288 // Make a dynamic relocation if necessary.
2289 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2291 unsigned int r_off
= reloc
.get_r_offset();
2293 // The assembler can sometimes emit unaligned relocations
2294 // for dwarf2 cfi directives.
2297 case elfcpp::R_SPARC_16
:
2299 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2301 case elfcpp::R_SPARC_32
:
2303 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2305 case elfcpp::R_SPARC_64
:
2307 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2309 case elfcpp::R_SPARC_UA16
:
2311 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2313 case elfcpp::R_SPARC_UA32
:
2315 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2317 case elfcpp::R_SPARC_UA64
:
2319 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2323 if (gsym
->may_need_copy_reloc())
2325 target
->copy_reloc(symtab
, layout
, object
,
2326 data_shndx
, output_section
, gsym
, reloc
);
2328 else if ((r_type
== elfcpp::R_SPARC_32
2329 || r_type
== elfcpp::R_SPARC_64
)
2330 && gsym
->can_use_relative_reloc(false))
2332 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2333 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2334 output_section
, object
,
2335 data_shndx
, reloc
.get_r_offset(),
2336 reloc
.get_r_addend());
2340 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2342 check_non_pic(object
, r_type
);
2343 if (gsym
->is_from_dynobj()
2344 || gsym
->is_undefined()
2345 || gsym
->is_preemptible())
2346 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2348 reloc
.get_r_offset(),
2349 reloc
.get_r_addend());
2351 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2354 reloc
.get_r_offset(),
2355 reloc
.get_r_addend());
2361 case elfcpp::R_SPARC_GOTDATA_OP
:
2362 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2363 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2364 case elfcpp::R_SPARC_GOT10
:
2365 case elfcpp::R_SPARC_GOT13
:
2366 case elfcpp::R_SPARC_GOT22
:
2368 // The symbol requires a GOT entry.
2369 Output_data_got
<size
, big_endian
>* got
;
2371 got
= target
->got_section(symtab
, layout
);
2372 if (gsym
->final_value_is_known())
2373 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2376 // If this symbol is not fully resolved, we need to add a
2377 // dynamic relocation for it.
2378 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2379 if (gsym
->is_from_dynobj()
2380 || gsym
->is_undefined()
2381 || gsym
->is_preemptible())
2382 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2383 elfcpp::R_SPARC_GLOB_DAT
);
2384 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2386 unsigned int off
= got
->add_constant(0);
2388 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2389 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2396 // These are initial tls relocs, which are expected when
2398 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2399 case elfcpp::R_SPARC_TLS_GD_LO10
:
2400 case elfcpp::R_SPARC_TLS_GD_ADD
:
2401 case elfcpp::R_SPARC_TLS_GD_CALL
:
2402 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2403 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2404 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2405 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2406 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2407 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2408 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2409 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2410 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2411 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2412 case elfcpp::R_SPARC_TLS_IE_LO10
:
2413 case elfcpp::R_SPARC_TLS_IE_LD
:
2414 case elfcpp::R_SPARC_TLS_IE_LDX
:
2415 case elfcpp::R_SPARC_TLS_IE_ADD
:
2417 const bool is_final
= gsym
->final_value_is_known();
2418 const tls::Tls_optimization optimized_type
2419 = optimize_tls_reloc(is_final
, r_type
);
2422 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2423 case elfcpp::R_SPARC_TLS_GD_LO10
:
2424 case elfcpp::R_SPARC_TLS_GD_ADD
:
2425 case elfcpp::R_SPARC_TLS_GD_CALL
:
2426 if (optimized_type
== tls::TLSOPT_NONE
)
2428 // Create a pair of GOT entries for the module index and
2429 // dtv-relative offset.
2430 Output_data_got
<size
, big_endian
>* got
2431 = target
->got_section(symtab
, layout
);
2432 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2433 target
->rela_dyn_section(layout
),
2435 ? elfcpp::R_SPARC_TLS_DTPMOD64
2436 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2438 ? elfcpp::R_SPARC_TLS_DTPOFF64
2439 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2441 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2442 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2443 generate_tls_call(symtab
, layout
, target
);
2445 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2447 // Create a GOT entry for the tp-relative offset.
2448 Output_data_got
<size
, big_endian
>* got
2449 = target
->got_section(symtab
, layout
);
2450 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2451 target
->rela_dyn_section(layout
),
2453 elfcpp::R_SPARC_TLS_TPOFF64
:
2454 elfcpp::R_SPARC_TLS_TPOFF32
));
2456 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2457 unsupported_reloc_global(object
, r_type
, gsym
);
2460 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2461 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2462 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2463 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2464 if (optimized_type
== tls::TLSOPT_NONE
)
2466 // Create a GOT entry for the module index.
2467 target
->got_mod_index_entry(symtab
, layout
, object
);
2469 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2470 generate_tls_call(symtab
, layout
, target
);
2472 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2473 unsupported_reloc_global(object
, r_type
, gsym
);
2476 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2477 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2478 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2481 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2482 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2483 layout
->set_has_static_tls();
2484 if (parameters
->options().shared())
2486 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2487 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2488 output_section
, object
,
2489 data_shndx
, reloc
.get_r_offset(),
2494 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2495 case elfcpp::R_SPARC_TLS_IE_LO10
:
2496 case elfcpp::R_SPARC_TLS_IE_LD
:
2497 case elfcpp::R_SPARC_TLS_IE_LDX
:
2498 case elfcpp::R_SPARC_TLS_IE_ADD
:
2499 layout
->set_has_static_tls();
2500 if (optimized_type
== tls::TLSOPT_NONE
)
2502 // Create a GOT entry for the tp-relative offset.
2503 Output_data_got
<size
, big_endian
>* got
2504 = target
->got_section(symtab
, layout
);
2505 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2506 target
->rela_dyn_section(layout
),
2508 ? elfcpp::R_SPARC_TLS_TPOFF64
2509 : elfcpp::R_SPARC_TLS_TPOFF32
));
2511 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2512 unsupported_reloc_global(object
, r_type
, gsym
);
2518 // These are relocations which should only be seen by the
2519 // dynamic linker, and should never be seen here.
2520 case elfcpp::R_SPARC_COPY
:
2521 case elfcpp::R_SPARC_GLOB_DAT
:
2522 case elfcpp::R_SPARC_JMP_SLOT
:
2523 case elfcpp::R_SPARC_RELATIVE
:
2524 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2525 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2526 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2527 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2528 case elfcpp::R_SPARC_TLS_TPOFF64
:
2529 case elfcpp::R_SPARC_TLS_TPOFF32
:
2530 gold_error(_("%s: unexpected reloc %u in object file"),
2531 object
->name().c_str(), r_type
);
2535 unsupported_reloc_global(object
, r_type
, gsym
);
2540 // Process relocations for gc.
2542 template<int size
, bool big_endian
>
2544 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2545 Symbol_table
* symtab
,
2547 Sized_relobj_file
<size
, big_endian
>* object
,
2548 unsigned int data_shndx
,
2550 const unsigned char* prelocs
,
2552 Output_section
* output_section
,
2553 bool needs_special_offset_handling
,
2554 size_t local_symbol_count
,
2555 const unsigned char* plocal_symbols
)
2557 typedef Target_sparc
<size
, big_endian
> Sparc
;
2558 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2560 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
2561 typename
Target_sparc::Relocatable_size_for_reloc
>(
2570 needs_special_offset_handling
,
2575 // Scan relocations for a section.
2577 template<int size
, bool big_endian
>
2579 Target_sparc
<size
, big_endian
>::scan_relocs(
2580 Symbol_table
* symtab
,
2582 Sized_relobj_file
<size
, big_endian
>* object
,
2583 unsigned int data_shndx
,
2584 unsigned int sh_type
,
2585 const unsigned char* prelocs
,
2587 Output_section
* output_section
,
2588 bool needs_special_offset_handling
,
2589 size_t local_symbol_count
,
2590 const unsigned char* plocal_symbols
)
2592 typedef Target_sparc
<size
, big_endian
> Sparc
;
2593 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2595 if (sh_type
== elfcpp::SHT_REL
)
2597 gold_error(_("%s: unsupported REL reloc section"),
2598 object
->name().c_str());
2602 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2611 needs_special_offset_handling
,
2616 // Finalize the sections.
2618 template<int size
, bool big_endian
>
2620 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2622 const Input_objects
*,
2625 // Fill in some more dynamic tags.
2626 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2628 : this->plt_
->rel_plt());
2629 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2630 this->rela_dyn_
, true, true);
2632 // Emit any relocs we saved in an attempt to avoid generating COPY
2634 if (this->copy_relocs_
.any_saved_relocs())
2635 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2638 // Perform a relocation.
2640 template<int size
, bool big_endian
>
2642 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2643 const Relocate_info
<size
, big_endian
>* relinfo
,
2644 Target_sparc
* target
,
2647 const elfcpp::Rela
<size
, big_endian
>& rela
,
2648 unsigned int r_type
,
2649 const Sized_symbol
<size
>* gsym
,
2650 const Symbol_value
<size
>* psymval
,
2651 unsigned char* view
,
2652 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2653 section_size_type view_size
)
2657 if (this->ignore_gd_add_
)
2659 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2660 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2661 _("missing expected TLS relocation"));
2664 this->ignore_gd_add_
= false;
2668 if (this->reloc_adjust_addr_
== view
)
2671 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2673 // Pick the value to use for symbols defined in shared objects.
2674 Symbol_value
<size
> symval
;
2676 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
2678 elfcpp::Elf_Xword value
;
2680 value
= target
->plt_section()->address() + gsym
->plt_offset();
2682 symval
.set_output_value(value
);
2687 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
2688 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2690 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2691 // pointer points to the beginning, not the end, of the table.
2692 // So we just use the plain offset.
2693 unsigned int got_offset
= 0;
2696 case elfcpp::R_SPARC_GOTDATA_OP
:
2697 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2698 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2699 case elfcpp::R_SPARC_GOT10
:
2700 case elfcpp::R_SPARC_GOT13
:
2701 case elfcpp::R_SPARC_GOT22
:
2704 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2705 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2709 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2710 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2711 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2721 case elfcpp::R_SPARC_NONE
:
2722 case elfcpp::R_SPARC_REGISTER
:
2723 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2724 case elfcpp::R_SPARC_GNU_VTENTRY
:
2727 case elfcpp::R_SPARC_8
:
2728 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2732 case elfcpp::R_SPARC_16
:
2733 if (rela
.get_r_offset() & 0x1)
2735 // The assembler can sometimes emit unaligned relocations
2736 // for dwarf2 cfi directives.
2737 Reloc::ua16(view
, object
, psymval
, addend
);
2740 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2744 case elfcpp::R_SPARC_32
:
2745 if (!parameters
->options().output_is_position_independent())
2747 if (rela
.get_r_offset() & 0x3)
2749 // The assembler can sometimes emit unaligned relocations
2750 // for dwarf2 cfi directives.
2751 Reloc::ua32(view
, object
, psymval
, addend
);
2754 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2759 case elfcpp::R_SPARC_DISP8
:
2760 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2763 case elfcpp::R_SPARC_DISP16
:
2764 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2767 case elfcpp::R_SPARC_DISP32
:
2768 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2771 case elfcpp::R_SPARC_DISP64
:
2772 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2775 case elfcpp::R_SPARC_WDISP30
:
2776 case elfcpp::R_SPARC_WPLT30
:
2777 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2780 case elfcpp::R_SPARC_WDISP22
:
2781 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2784 case elfcpp::R_SPARC_WDISP19
:
2785 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2788 case elfcpp::R_SPARC_WDISP16
:
2789 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2792 case elfcpp::R_SPARC_WDISP10
:
2793 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
2796 case elfcpp::R_SPARC_HI22
:
2797 Reloc::hi22(view
, object
, psymval
, addend
);
2800 case elfcpp::R_SPARC_22
:
2801 Reloc::rela32_22(view
, object
, psymval
, addend
);
2804 case elfcpp::R_SPARC_13
:
2805 Reloc::rela32_13(view
, object
, psymval
, addend
);
2808 case elfcpp::R_SPARC_LO10
:
2809 Reloc::lo10(view
, object
, psymval
, addend
);
2812 case elfcpp::R_SPARC_GOT10
:
2813 Reloc::lo10(view
, got_offset
, addend
);
2816 case elfcpp::R_SPARC_GOTDATA_OP
:
2819 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2820 case elfcpp::R_SPARC_GOT13
:
2821 Reloc::rela32_13(view
, got_offset
, addend
);
2824 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2825 case elfcpp::R_SPARC_GOT22
:
2826 Reloc::hi22(view
, got_offset
, addend
);
2829 case elfcpp::R_SPARC_PC10
:
2830 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2833 case elfcpp::R_SPARC_PC22
:
2834 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2837 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2838 case elfcpp::R_SPARC_UA32
:
2839 Reloc::ua32(view
, object
, psymval
, addend
);
2842 case elfcpp::R_SPARC_PLT64
:
2843 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2847 case elfcpp::R_SPARC_PLT32
:
2848 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2852 case elfcpp::R_SPARC_HIPLT22
:
2853 Reloc::hi22(view
, object
, psymval
, addend
);
2856 case elfcpp::R_SPARC_LOPLT10
:
2857 Reloc::lo10(view
, object
, psymval
, addend
);
2860 case elfcpp::R_SPARC_PCPLT32
:
2861 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2864 case elfcpp::R_SPARC_PCPLT22
:
2865 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2868 case elfcpp::R_SPARC_PCPLT10
:
2869 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2872 case elfcpp::R_SPARC_64
:
2873 if (!parameters
->options().output_is_position_independent())
2875 if (rela
.get_r_offset() & 0x7)
2877 // The assembler can sometimes emit unaligned relocations
2878 // for dwarf2 cfi directives.
2879 Reloc::ua64(view
, object
, psymval
, addend
);
2882 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2887 case elfcpp::R_SPARC_OLO10
:
2889 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2890 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2891 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2895 case elfcpp::R_SPARC_HH22
:
2896 Reloc::hh22(view
, object
, psymval
, addend
);
2899 case elfcpp::R_SPARC_PC_HH22
:
2900 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2903 case elfcpp::R_SPARC_HM10
:
2904 Reloc::hm10(view
, object
, psymval
, addend
);
2907 case elfcpp::R_SPARC_PC_HM10
:
2908 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2911 case elfcpp::R_SPARC_LM22
:
2912 Reloc::hi22(view
, object
, psymval
, addend
);
2915 case elfcpp::R_SPARC_PC_LM22
:
2916 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2919 case elfcpp::R_SPARC_11
:
2920 Reloc::rela32_11(view
, object
, psymval
, addend
);
2923 case elfcpp::R_SPARC_10
:
2924 Reloc::rela32_10(view
, object
, psymval
, addend
);
2927 case elfcpp::R_SPARC_7
:
2928 Reloc::rela32_7(view
, object
, psymval
, addend
);
2931 case elfcpp::R_SPARC_6
:
2932 Reloc::rela32_6(view
, object
, psymval
, addend
);
2935 case elfcpp::R_SPARC_5
:
2936 Reloc::rela32_5(view
, object
, psymval
, addend
);
2939 case elfcpp::R_SPARC_HIX22
:
2940 Reloc::hix22(view
, object
, psymval
, addend
);
2943 case elfcpp::R_SPARC_LOX10
:
2944 Reloc::lox10(view
, object
, psymval
, addend
);
2947 case elfcpp::R_SPARC_H34
:
2948 Reloc::h34(view
, object
, psymval
, addend
);
2951 case elfcpp::R_SPARC_H44
:
2952 Reloc::h44(view
, object
, psymval
, addend
);
2955 case elfcpp::R_SPARC_M44
:
2956 Reloc::m44(view
, object
, psymval
, addend
);
2959 case elfcpp::R_SPARC_L44
:
2960 Reloc::l44(view
, object
, psymval
, addend
);
2963 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2964 case elfcpp::R_SPARC_UA64
:
2965 Reloc::ua64(view
, object
, psymval
, addend
);
2968 case elfcpp::R_SPARC_UA16
:
2969 Reloc::ua16(view
, object
, psymval
, addend
);
2972 case elfcpp::R_SPARC_TLS_GD_HI22
:
2973 case elfcpp::R_SPARC_TLS_GD_LO10
:
2974 case elfcpp::R_SPARC_TLS_GD_ADD
:
2975 case elfcpp::R_SPARC_TLS_GD_CALL
:
2976 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2977 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2978 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2979 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2980 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2981 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2982 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2983 case elfcpp::R_SPARC_TLS_IE_HI22
:
2984 case elfcpp::R_SPARC_TLS_IE_LO10
:
2985 case elfcpp::R_SPARC_TLS_IE_LD
:
2986 case elfcpp::R_SPARC_TLS_IE_LDX
:
2987 case elfcpp::R_SPARC_TLS_IE_ADD
:
2988 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2989 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2990 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2991 r_type
, gsym
, psymval
, view
,
2992 address
, view_size
);
2995 case elfcpp::R_SPARC_COPY
:
2996 case elfcpp::R_SPARC_GLOB_DAT
:
2997 case elfcpp::R_SPARC_JMP_SLOT
:
2998 case elfcpp::R_SPARC_RELATIVE
:
2999 // These are outstanding tls relocs, which are unexpected when
3001 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3002 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3003 case elfcpp::R_SPARC_TLS_TPOFF64
:
3004 case elfcpp::R_SPARC_TLS_TPOFF32
:
3005 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3006 _("unexpected reloc %u in object file"),
3011 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3012 _("unsupported reloc %u"),
3020 // Perform a TLS relocation.
3022 template<int size
, bool big_endian
>
3024 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3025 const Relocate_info
<size
, big_endian
>* relinfo
,
3026 Target_sparc
<size
, big_endian
>* target
,
3028 const elfcpp::Rela
<size
, big_endian
>& rela
,
3029 unsigned int r_type
,
3030 const Sized_symbol
<size
>* gsym
,
3031 const Symbol_value
<size
>* psymval
,
3032 unsigned char* view
,
3033 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3036 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3037 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3038 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3039 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3041 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3042 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3044 const bool is_final
=
3046 ? !parameters
->options().output_is_position_independent()
3047 : gsym
->final_value_is_known());
3048 const tls::Tls_optimization optimized_type
3049 = optimize_tls_reloc(is_final
, r_type
);
3053 case elfcpp::R_SPARC_TLS_GD_HI22
:
3054 case elfcpp::R_SPARC_TLS_GD_LO10
:
3055 case elfcpp::R_SPARC_TLS_GD_ADD
:
3056 case elfcpp::R_SPARC_TLS_GD_CALL
:
3057 if (optimized_type
== tls::TLSOPT_TO_LE
)
3059 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3062 value
-= tls_segment
->memsz();
3066 case elfcpp::R_SPARC_TLS_GD_HI22
:
3067 // TLS_GD_HI22 --> TLS_LE_HIX22
3068 Reloc::hix22(view
, value
, addend
);
3071 case elfcpp::R_SPARC_TLS_GD_LO10
:
3072 // TLS_GD_LO10 --> TLS_LE_LOX10
3073 Reloc::lox10(view
, value
, addend
);
3076 case elfcpp::R_SPARC_TLS_GD_ADD
:
3077 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3078 val
= elfcpp::Swap
<32, true>::readval(wv
);
3079 val
= (val
& ~0x7c000) | 0x1c000;
3080 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3082 case elfcpp::R_SPARC_TLS_GD_CALL
:
3083 // call __tls_get_addr --> nop
3084 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3091 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3092 ? GOT_TYPE_TLS_OFFSET
3093 : GOT_TYPE_TLS_PAIR
);
3096 gold_assert(gsym
->has_got_offset(got_type
));
3097 value
= gsym
->got_offset(got_type
);
3101 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3102 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3103 value
= object
->local_got_offset(r_sym
, got_type
);
3105 if (optimized_type
== tls::TLSOPT_TO_IE
)
3107 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3112 case elfcpp::R_SPARC_TLS_GD_HI22
:
3113 // TLS_GD_HI22 --> TLS_IE_HI22
3114 Reloc::hi22(view
, value
, addend
);
3117 case elfcpp::R_SPARC_TLS_GD_LO10
:
3118 // TLS_GD_LO10 --> TLS_IE_LO10
3119 Reloc::lo10(view
, value
, addend
);
3122 case elfcpp::R_SPARC_TLS_GD_ADD
:
3123 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3124 val
= elfcpp::Swap
<32, true>::readval(wv
);
3131 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3134 case elfcpp::R_SPARC_TLS_GD_CALL
:
3135 // The compiler can put the TLS_GD_ADD instruction
3136 // into the delay slot of the call. If so, we need
3137 // to transpose the two instructions so that the
3138 // new sequence works properly.
3140 // The test we use is if the instruction in the
3141 // delay slot is an add with destination register
3143 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3144 if ((val
& 0x81f80000) == 0x80000000
3145 && ((val
>> 25) & 0x1f) == 0x8)
3152 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3155 this->ignore_gd_add_
= true;
3159 // Even if the delay slot isn't the TLS_GD_ADD
3160 // instruction, we still have to handle the case
3161 // where it sets up %o0 in some other way.
3162 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3164 this->reloc_adjust_addr_
= view
+ 4;
3166 // call __tls_get_addr --> add %g7, %o0, %o0
3167 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3172 else if (optimized_type
== tls::TLSOPT_NONE
)
3176 case elfcpp::R_SPARC_TLS_GD_HI22
:
3177 Reloc::hi22(view
, value
, addend
);
3179 case elfcpp::R_SPARC_TLS_GD_LO10
:
3180 Reloc::lo10(view
, value
, addend
);
3182 case elfcpp::R_SPARC_TLS_GD_ADD
:
3184 case elfcpp::R_SPARC_TLS_GD_CALL
:
3186 Symbol_value
<size
> symval
;
3187 elfcpp::Elf_Xword value
;
3190 tsym
= target
->tls_get_addr_sym_
;
3192 value
= (target
->plt_section()->address() +
3193 tsym
->plt_offset());
3194 symval
.set_output_value(value
);
3195 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3202 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3203 _("unsupported reloc %u"),
3207 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3208 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3209 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3210 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3211 if (optimized_type
== tls::TLSOPT_TO_LE
)
3213 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3217 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3218 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3219 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3220 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3223 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3224 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3229 else if (optimized_type
== tls::TLSOPT_NONE
)
3231 // Relocate the field with the offset of the GOT entry for
3232 // the module index.
3233 unsigned int got_offset
;
3235 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3238 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3239 Reloc::hi22(view
, got_offset
, addend
);
3241 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3242 Reloc::lo10(view
, got_offset
, addend
);
3244 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3246 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3248 Symbol_value
<size
> symval
;
3249 elfcpp::Elf_Xword value
;
3252 tsym
= target
->tls_get_addr_sym_
;
3254 value
= (target
->plt_section()->address() +
3255 tsym
->plt_offset());
3256 symval
.set_output_value(value
);
3257 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3263 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3264 _("unsupported reloc %u"),
3268 // These relocs can appear in debugging sections, in which case
3269 // we won't see the TLS_LDM relocs. The local_dynamic_type
3270 // field tells us this.
3271 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3272 if (optimized_type
== tls::TLSOPT_TO_LE
)
3274 value
-= tls_segment
->memsz();
3275 Reloc::hix22(view
, value
, addend
);
3278 Reloc::ldo_hix22(view
, value
, addend
);
3280 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3281 if (optimized_type
== tls::TLSOPT_TO_LE
)
3283 value
-= tls_segment
->memsz();
3284 Reloc::lox10(view
, value
, addend
);
3287 Reloc::ldo_lox10(view
, value
, addend
);
3289 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3290 if (optimized_type
== tls::TLSOPT_TO_LE
)
3292 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3295 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3296 val
= elfcpp::Swap
<32, true>::readval(wv
);
3297 val
= (val
& ~0x7c000) | 0x1c000;
3298 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3302 // When optimizing IE --> LE, the only relocation that is handled
3303 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3304 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3305 // rs2 and rd are the same.
3306 case elfcpp::R_SPARC_TLS_IE_LD
:
3307 case elfcpp::R_SPARC_TLS_IE_LDX
:
3308 if (optimized_type
== tls::TLSOPT_TO_LE
)
3310 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3311 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3312 Insntype rs2
= val
& 0x1f;
3313 Insntype rd
= (val
>> 25) & 0x1f;
3318 val
= sparc_mov
| (val
& 0x3e00001f);
3320 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3324 case elfcpp::R_SPARC_TLS_IE_HI22
:
3325 case elfcpp::R_SPARC_TLS_IE_LO10
:
3326 if (optimized_type
== tls::TLSOPT_TO_LE
)
3328 value
-= tls_segment
->memsz();
3331 case elfcpp::R_SPARC_TLS_IE_HI22
:
3332 // IE_HI22 --> LE_HIX22
3333 Reloc::hix22(view
, value
, addend
);
3335 case elfcpp::R_SPARC_TLS_IE_LO10
:
3336 // IE_LO10 --> LE_LOX10
3337 Reloc::lox10(view
, value
, addend
);
3342 else if (optimized_type
== tls::TLSOPT_NONE
)
3344 // Relocate the field with the offset of the GOT entry for
3345 // the tp-relative offset of the symbol.
3348 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3349 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3353 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3354 gold_assert(object
->local_has_got_offset(r_sym
,
3355 GOT_TYPE_TLS_OFFSET
));
3356 value
= object
->local_got_offset(r_sym
,
3357 GOT_TYPE_TLS_OFFSET
);
3361 case elfcpp::R_SPARC_TLS_IE_HI22
:
3362 Reloc::hi22(view
, value
, addend
);
3364 case elfcpp::R_SPARC_TLS_IE_LO10
:
3365 Reloc::lo10(view
, value
, addend
);
3370 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3371 _("unsupported reloc %u"),
3375 case elfcpp::R_SPARC_TLS_IE_ADD
:
3376 // This seems to be mainly so that we can find the addition
3377 // instruction if there is one. There doesn't seem to be any
3378 // actual relocation to apply.
3381 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3382 // If we're creating a shared library, a dynamic relocation will
3383 // have been created for this location, so do not apply it now.
3384 if (!parameters
->options().shared())
3386 value
-= tls_segment
->memsz();
3387 Reloc::hix22(view
, value
, addend
);
3391 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3392 // If we're creating a shared library, a dynamic relocation will
3393 // have been created for this location, so do not apply it now.
3394 if (!parameters
->options().shared())
3396 value
-= tls_segment
->memsz();
3397 Reloc::lox10(view
, value
, addend
);
3403 // Relocate section data.
3405 template<int size
, bool big_endian
>
3407 Target_sparc
<size
, big_endian
>::relocate_section(
3408 const Relocate_info
<size
, big_endian
>* relinfo
,
3409 unsigned int sh_type
,
3410 const unsigned char* prelocs
,
3412 Output_section
* output_section
,
3413 bool needs_special_offset_handling
,
3414 unsigned char* view
,
3415 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3416 section_size_type view_size
,
3417 const Reloc_symbol_changes
* reloc_symbol_changes
)
3419 typedef Target_sparc
<size
, big_endian
> Sparc
;
3420 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3422 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3424 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3431 needs_special_offset_handling
,
3435 reloc_symbol_changes
);
3438 // Return the size of a relocation while scanning during a relocatable
3441 template<int size
, bool big_endian
>
3443 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3447 // We are always SHT_RELA, so we should never get here.
3452 // Scan the relocs during a relocatable link.
3454 template<int size
, bool big_endian
>
3456 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3457 Symbol_table
* symtab
,
3459 Sized_relobj_file
<size
, big_endian
>* object
,
3460 unsigned int data_shndx
,
3461 unsigned int sh_type
,
3462 const unsigned char* prelocs
,
3464 Output_section
* output_section
,
3465 bool needs_special_offset_handling
,
3466 size_t local_symbol_count
,
3467 const unsigned char* plocal_symbols
,
3468 Relocatable_relocs
* rr
)
3470 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3472 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3473 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3475 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3476 Scan_relocatable_relocs
>(
3484 needs_special_offset_handling
,
3490 // Relocate a section during a relocatable link.
3492 template<int size
, bool big_endian
>
3494 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3495 const Relocate_info
<size
, big_endian
>* relinfo
,
3496 unsigned int sh_type
,
3497 const unsigned char* prelocs
,
3499 Output_section
* output_section
,
3500 off_t offset_in_output_section
,
3501 const Relocatable_relocs
* rr
,
3502 unsigned char* view
,
3503 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3504 section_size_type view_size
,
3505 unsigned char* reloc_view
,
3506 section_size_type reloc_view_size
)
3508 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3510 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3515 offset_in_output_section
,
3524 // Return the value to use for a dynamic which requires special
3525 // treatment. This is how we support equality comparisons of function
3526 // pointers across shared library boundaries, as described in the
3527 // processor specific ABI supplement.
3529 template<int size
, bool big_endian
>
3531 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3533 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3534 return this->plt_section()->address() + gsym
->plt_offset();
3537 // The selector for sparc object files.
3539 template<int size
, bool big_endian
>
3540 class Target_selector_sparc
: public Target_selector
3543 Target_selector_sparc()
3544 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3545 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
3546 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
3549 Target
* do_recognize(int machine
, int, int)
3554 if (machine
!= elfcpp::EM_SPARCV9
)
3559 if (machine
!= elfcpp::EM_SPARC
3560 && machine
!= elfcpp::EM_SPARC32PLUS
)
3568 return this->instantiate_target();
3571 Target
* do_instantiate_target()
3572 { return new Target_sparc
<size
, big_endian
>(); }
3575 Target_selector_sparc
<32, true> target_selector_sparc32
;
3576 Target_selector_sparc
<64, true> target_selector_sparc64
;
3578 } // End anonymous namespace.