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_PC22: (Symbol + Addend - Address) >> 10
622 pc22(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 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
629 psymval
, addend
, address
);
632 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
634 pc10(unsigned char* view
,
635 const Sized_relobj_file
<size
, big_endian
>* object
,
636 const Symbol_value
<size
>* psymval
,
637 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
638 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
640 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
641 psymval
, addend
, address
);
644 // R_SPARC_HI22: (Symbol + Addend) >> 10
646 hi22(unsigned char* view
,
647 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
648 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
650 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
653 // R_SPARC_HI22: (Symbol + Addend) >> 10
655 hi22(unsigned char* view
,
656 const Sized_relobj_file
<size
, big_endian
>* object
,
657 const Symbol_value
<size
>* psymval
,
658 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
660 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
663 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
665 pcplt22(unsigned char* view
,
666 const Sized_relobj_file
<size
, big_endian
>* object
,
667 const Symbol_value
<size
>* psymval
,
668 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
669 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
671 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
672 psymval
, addend
, address
);
675 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
677 lo10(unsigned char* view
,
678 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
679 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
681 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
684 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
686 lo10(unsigned char* view
,
687 const Sized_relobj_file
<size
, big_endian
>* object
,
688 const Symbol_value
<size
>* psymval
,
689 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
691 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
694 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
696 lo10(unsigned char* view
,
697 const Sized_relobj_file
<size
, big_endian
>* object
,
698 const Symbol_value
<size
>* psymval
,
699 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
700 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
702 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
703 psymval
, addend
, address
);
706 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
708 olo10(unsigned char* view
,
709 const Sized_relobj_file
<size
, big_endian
>* object
,
710 const Symbol_value
<size
>* psymval
,
711 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
712 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
714 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
715 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
716 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
717 Valtype reloc
= psymval
->value(object
, addend
);
724 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
727 // R_SPARC_22: (Symbol + Addend)
729 rela32_22(unsigned char* view
,
730 const Sized_relobj_file
<size
, big_endian
>* object
,
731 const Symbol_value
<size
>* psymval
,
732 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
734 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
737 // R_SPARC_13: (Symbol + Addend)
739 rela32_13(unsigned char* view
,
740 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
741 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
743 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
746 // R_SPARC_13: (Symbol + Addend)
748 rela32_13(unsigned char* view
,
749 const Sized_relobj_file
<size
, big_endian
>* object
,
750 const Symbol_value
<size
>* psymval
,
751 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
753 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
756 // R_SPARC_UA16: (Symbol + Addend)
758 ua16(unsigned char* view
,
759 const Sized_relobj_file
<size
, big_endian
>* object
,
760 const Symbol_value
<size
>* psymval
,
761 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
763 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
766 // R_SPARC_UA32: (Symbol + Addend)
768 ua32(unsigned char* view
,
769 const Sized_relobj_file
<size
, big_endian
>* object
,
770 const Symbol_value
<size
>* psymval
,
771 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
773 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
776 // R_SPARC_UA64: (Symbol + Addend)
778 ua64(unsigned char* view
,
779 const Sized_relobj_file
<size
, big_endian
>* object
,
780 const Symbol_value
<size
>* psymval
,
781 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
783 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
784 object
, psymval
, addend
);
787 // R_SPARC_DISP8: (Symbol + Addend - Address)
789 disp8(unsigned char* view
,
790 const Sized_relobj_file
<size
, big_endian
>* object
,
791 const Symbol_value
<size
>* psymval
,
792 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
793 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
795 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
799 // R_SPARC_DISP16: (Symbol + Addend - Address)
801 disp16(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
,
805 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
807 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
811 // R_SPARC_DISP32: (Symbol + Addend - Address)
813 disp32(unsigned char* view
,
814 const Sized_relobj_file
<size
, big_endian
>* object
,
815 const Symbol_value
<size
>* psymval
,
816 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
817 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
819 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
823 // R_SPARC_DISP64: (Symbol + Addend - Address)
825 disp64(unsigned char* view
,
826 const Sized_relobj_file
<size
, big_endian
>* object
,
827 const Symbol_value
<size
>* psymval
,
828 elfcpp::Elf_Xword addend
,
829 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
831 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
835 // R_SPARC_H44: (Symbol + Addend) >> 22
837 h44(unsigned char* view
,
838 const Sized_relobj_file
<size
, big_endian
>* object
,
839 const Symbol_value
<size
>* psymval
,
840 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
842 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
845 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
847 m44(unsigned char* view
,
848 const Sized_relobj_file
<size
, big_endian
>* object
,
849 const Symbol_value
<size
>* psymval
,
850 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
852 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
855 // R_SPARC_L44: (Symbol + Addend) & 0xfff
857 l44(unsigned char* view
,
858 const Sized_relobj_file
<size
, big_endian
>* object
,
859 const Symbol_value
<size
>* psymval
,
860 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
862 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
865 // R_SPARC_HH22: (Symbol + Addend) >> 42
867 hh22(unsigned char* view
,
868 const Sized_relobj_file
<size
, big_endian
>* object
,
869 const Symbol_value
<size
>* psymval
,
870 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
872 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
875 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
877 pc_hh22(unsigned char* view
,
878 const Sized_relobj_file
<size
, big_endian
>* object
,
879 const Symbol_value
<size
>* psymval
,
880 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
881 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
883 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
884 psymval
, addend
, address
);
887 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
889 hm10(unsigned char* view
,
890 const Sized_relobj_file
<size
, big_endian
>* object
,
891 const Symbol_value
<size
>* psymval
,
892 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
894 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
897 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
899 pc_hm10(unsigned char* view
,
900 const Sized_relobj_file
<size
, big_endian
>* object
,
901 const Symbol_value
<size
>* psymval
,
902 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
905 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
906 psymval
, addend
, address
);
909 // R_SPARC_11: (Symbol + Addend)
911 rela32_11(unsigned char* view
,
912 const Sized_relobj_file
<size
, big_endian
>* object
,
913 const Symbol_value
<size
>* psymval
,
914 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
916 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
919 // R_SPARC_10: (Symbol + Addend)
921 rela32_10(unsigned char* view
,
922 const Sized_relobj_file
<size
, big_endian
>* object
,
923 const Symbol_value
<size
>* psymval
,
924 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
926 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
929 // R_SPARC_7: (Symbol + Addend)
931 rela32_7(unsigned char* view
,
932 const Sized_relobj_file
<size
, big_endian
>* object
,
933 const Symbol_value
<size
>* psymval
,
934 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
936 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
939 // R_SPARC_6: (Symbol + Addend)
941 rela32_6(unsigned char* view
,
942 const Sized_relobj_file
<size
, big_endian
>* object
,
943 const Symbol_value
<size
>* psymval
,
944 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
946 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
949 // R_SPARC_5: (Symbol + Addend)
951 rela32_5(unsigned char* view
,
952 const Sized_relobj_file
<size
, big_endian
>* object
,
953 const Symbol_value
<size
>* psymval
,
954 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
956 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
959 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
961 ldo_hix22(unsigned char* view
,
962 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
963 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
965 This_insn::hi22(view
, value
, addend
);
968 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
970 ldo_lox10(unsigned char* view
,
971 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
972 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
974 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
975 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
976 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
977 Valtype reloc
= (value
+ addend
);
982 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
985 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
987 hix22(unsigned char* view
,
988 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
989 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
991 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
992 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
993 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
994 Valtype reloc
= (value
+ addend
);
998 reloc
^= ~(Valtype
)0;
1003 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1006 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1008 hix22(unsigned char* view
,
1009 const Sized_relobj_file
<size
, big_endian
>* object
,
1010 const Symbol_value
<size
>* psymval
,
1011 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1013 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1014 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1015 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1016 Valtype reloc
= psymval
->value(object
, addend
);
1020 reloc
^= ~(Valtype
)0;
1025 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1029 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1031 lox10(unsigned char* view
,
1032 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1033 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1035 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1036 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1037 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1038 Valtype reloc
= (value
+ addend
);
1044 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1047 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1049 lox10(unsigned char* view
,
1050 const Sized_relobj_file
<size
, big_endian
>* object
,
1051 const Symbol_value
<size
>* psymval
,
1052 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1054 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1055 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1056 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1057 Valtype reloc
= psymval
->value(object
, addend
);
1063 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1067 // Get the GOT section, creating it if necessary.
1069 template<int size
, bool big_endian
>
1070 Output_data_got
<size
, big_endian
>*
1071 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1074 if (this->got_
== NULL
)
1076 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1078 this->got_
= new Output_data_got
<size
, big_endian
>();
1080 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1082 | elfcpp::SHF_WRITE
),
1083 this->got_
, ORDER_RELRO
, true);
1085 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1086 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1087 Symbol_table::PREDEFINED
,
1089 0, 0, elfcpp::STT_OBJECT
,
1091 elfcpp::STV_HIDDEN
, 0,
1098 // Get the dynamic reloc section, creating it if necessary.
1100 template<int size
, bool big_endian
>
1101 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1102 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1104 if (this->rela_dyn_
== NULL
)
1106 gold_assert(layout
!= NULL
);
1107 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1108 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1109 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1110 ORDER_DYNAMIC_RELOCS
, false);
1112 return this->rela_dyn_
;
1115 // A class to handle the PLT data.
1117 template<int size
, bool big_endian
>
1118 class Output_data_plt_sparc
: public Output_section_data
1121 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1122 size
, big_endian
> Reloc_section
;
1124 Output_data_plt_sparc(Layout
*);
1126 // Add an entry to the PLT.
1127 void add_entry(Symbol
* gsym
);
1129 // Return the .rela.plt section data.
1130 const Reloc_section
* rel_plt() const
1135 // Return the number of PLT entries.
1138 { return this->count_
; }
1140 // Return the offset of the first non-reserved PLT entry.
1142 first_plt_entry_offset()
1143 { return 4 * base_plt_entry_size
; }
1145 // Return the size of a PLT entry.
1147 get_plt_entry_size()
1148 { return base_plt_entry_size
; }
1151 void do_adjust_output_section(Output_section
* os
);
1153 // Write to a map file.
1155 do_print_to_mapfile(Mapfile
* mapfile
) const
1156 { mapfile
->print_output_data(this, _("** PLT")); }
1159 // The size of an entry in the PLT.
1160 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1162 static const unsigned int plt_entries_per_block
= 160;
1163 static const unsigned int plt_insn_chunk_size
= 24;
1164 static const unsigned int plt_pointer_chunk_size
= 8;
1165 static const unsigned int plt_block_size
=
1166 (plt_entries_per_block
1167 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1169 // Set the final size.
1171 set_final_data_size()
1173 unsigned int full_count
= this->count_
+ 4;
1174 unsigned int extra
= (size
== 32 ? 4 : 0);
1176 if (size
== 32 || full_count
< 32768)
1177 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1180 unsigned int ext_cnt
= full_count
- 32768;
1182 this->set_data_size((32768 * base_plt_entry_size
)
1184 * (plt_insn_chunk_size
1185 + plt_pointer_chunk_size
)));
1189 // Write out the PLT data.
1191 do_write(Output_file
*);
1193 // The reloc section.
1194 Reloc_section
* rel_
;
1195 // The number of PLT entries.
1196 unsigned int count_
;
1199 // Define the constants as required by C++ standard.
1201 template<int size
, bool big_endian
>
1202 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1204 template<int size
, bool big_endian
>
1206 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1208 template<int size
, bool big_endian
>
1209 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1211 template<int size
, bool big_endian
>
1213 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1215 template<int size
, bool big_endian
>
1216 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1218 // Create the PLT section. The ordinary .got section is an argument,
1219 // since we need to refer to the start.
1221 template<int size
, bool big_endian
>
1222 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1223 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1225 this->rel_
= new Reloc_section(false);
1226 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1227 elfcpp::SHF_ALLOC
, this->rel_
,
1228 ORDER_DYNAMIC_PLT_RELOCS
, false);
1231 template<int size
, bool big_endian
>
1233 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1238 // Add an entry to the PLT.
1240 template<int size
, bool big_endian
>
1242 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1244 gold_assert(!gsym
->has_plt_offset());
1246 unsigned int index
= this->count_
+ 4;
1247 section_offset_type plt_offset
;
1249 if (size
== 32 || index
< 32768)
1250 plt_offset
= index
* base_plt_entry_size
;
1253 unsigned int ext_index
= index
- 32768;
1255 plt_offset
= (32768 * base_plt_entry_size
)
1256 + ((ext_index
/ plt_entries_per_block
)
1258 + ((ext_index
% plt_entries_per_block
)
1259 * plt_insn_chunk_size
);
1262 gsym
->set_plt_offset(plt_offset
);
1266 // Every PLT entry needs a reloc.
1267 gsym
->set_needs_dynsym_entry();
1268 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1271 // Note that we don't need to save the symbol. The contents of the
1272 // PLT are independent of which symbols are used. The symbols only
1273 // appear in the relocations.
1276 static const unsigned int sparc_nop
= 0x01000000;
1277 static const unsigned int sparc_sethi_g1
= 0x03000000;
1278 static const unsigned int sparc_branch_always
= 0x30800000;
1279 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1280 static const unsigned int sparc_mov
= 0x80100000;
1281 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1282 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1283 static const unsigned int sparc_call_plus_8
= 0x40000002;
1284 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1285 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1286 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1288 // Write out the PLT.
1290 template<int size
, bool big_endian
>
1292 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1294 const off_t offset
= this->offset();
1295 const section_size_type oview_size
=
1296 convert_to_section_size_type(this->data_size());
1297 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1298 unsigned char* pov
= oview
;
1300 memset(pov
, 0, base_plt_entry_size
* 4);
1301 pov
+= base_plt_entry_size
* 4;
1303 unsigned int plt_offset
= base_plt_entry_size
* 4;
1304 const unsigned int count
= this->count_
;
1310 limit
= (count
> 32768 ? 32768 : count
);
1312 for (unsigned int i
= 0; i
< limit
; ++i
)
1314 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1315 sparc_sethi_g1
+ plt_offset
);
1316 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1317 sparc_branch_always_pt
+
1318 (((base_plt_entry_size
-
1319 (plt_offset
+ 4)) >> 2) &
1321 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1322 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1323 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1324 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1325 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1326 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1328 pov
+= base_plt_entry_size
;
1329 plt_offset
+= base_plt_entry_size
;
1334 unsigned int ext_cnt
= count
- 32768;
1335 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1337 for (unsigned int i
= 0; i
< blks
; ++i
)
1339 unsigned int data_off
= (plt_entries_per_block
1340 * plt_insn_chunk_size
) - 4;
1342 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1344 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1346 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1348 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1350 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1351 sparc_ldx_o7_imm_g1
+
1352 (data_off
& 0x1fff));
1353 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1354 sparc_jmpl_o7_g1_g1
);
1355 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1358 elfcpp::Swap
<64, big_endian
>::writeval(
1359 pov
+ 0x4 + data_off
,
1360 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1362 pov
+= plt_insn_chunk_size
;
1367 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1368 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1370 unsigned int data_off
= (sub_blk_cnt
1371 * plt_insn_chunk_size
) - 4;
1373 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1375 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1377 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1379 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1381 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1382 sparc_ldx_o7_imm_g1
+
1383 (data_off
& 0x1fff));
1384 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1385 sparc_jmpl_o7_g1_g1
);
1386 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1389 elfcpp::Swap
<64, big_endian
>::writeval(
1390 pov
+ 0x4 + data_off
,
1391 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1393 pov
+= plt_insn_chunk_size
;
1401 for (unsigned int i
= 0; i
< count
; ++i
)
1403 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1404 sparc_sethi_g1
+ plt_offset
);
1405 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1406 sparc_branch_always
+
1407 (((- (plt_offset
+ 4)) >> 2) &
1409 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1411 pov
+= base_plt_entry_size
;
1412 plt_offset
+= base_plt_entry_size
;
1415 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1419 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1421 of
->write_output_view(offset
, oview_size
, oview
);
1424 // Create a PLT entry for a global symbol.
1426 template<int size
, bool big_endian
>
1428 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1432 if (gsym
->has_plt_offset())
1435 if (this->plt_
== NULL
)
1437 // Create the GOT sections first.
1438 this->got_section(symtab
, layout
);
1440 // Ensure that .rela.dyn always appears before .rela.plt This is
1441 // necessary due to how, on Sparc and some other targets, .rela.dyn
1442 // needs to include .rela.plt in it's range.
1443 this->rela_dyn_section(layout
);
1445 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1446 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1448 | elfcpp::SHF_EXECINSTR
1449 | elfcpp::SHF_WRITE
),
1450 this->plt_
, ORDER_PLT
, false);
1452 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1453 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1454 Symbol_table::PREDEFINED
,
1456 0, 0, elfcpp::STT_OBJECT
,
1458 elfcpp::STV_HIDDEN
, 0,
1462 this->plt_
->add_entry(gsym
);
1465 // Return the number of entries in the PLT.
1467 template<int size
, bool big_endian
>
1469 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1471 if (this->plt_
== NULL
)
1473 return this->plt_
->entry_count();
1476 // Return the offset of the first non-reserved PLT entry.
1478 template<int size
, bool big_endian
>
1480 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1482 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1485 // Return the size of each PLT entry.
1487 template<int size
, bool big_endian
>
1489 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1491 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1494 // Create a GOT entry for the TLS module index.
1496 template<int size
, bool big_endian
>
1498 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1499 Symbol_table
* symtab
,
1501 Sized_relobj_file
<size
, big_endian
>* object
)
1503 if (this->got_mod_index_offset_
== -1U)
1505 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1506 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1507 Output_data_got
<size
, big_endian
>* got
;
1508 unsigned int got_offset
;
1510 got
= this->got_section(symtab
, layout
);
1511 got_offset
= got
->add_constant(0);
1512 rela_dyn
->add_local(object
, 0,
1514 elfcpp::R_SPARC_TLS_DTPMOD64
:
1515 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1517 got
->add_constant(0);
1518 this->got_mod_index_offset_
= got_offset
;
1520 return this->got_mod_index_offset_
;
1523 // Optimize the TLS relocation type based on what we know about the
1524 // symbol. IS_FINAL is true if the final address of this symbol is
1525 // known at link time.
1527 static tls::Tls_optimization
1528 optimize_tls_reloc(bool is_final
, int r_type
)
1530 // If we are generating a shared library, then we can't do anything
1532 if (parameters
->options().shared())
1533 return tls::TLSOPT_NONE
;
1537 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1538 case elfcpp::R_SPARC_TLS_GD_LO10
:
1539 case elfcpp::R_SPARC_TLS_GD_ADD
:
1540 case elfcpp::R_SPARC_TLS_GD_CALL
:
1541 // These are General-Dynamic which permits fully general TLS
1542 // access. Since we know that we are generating an executable,
1543 // we can convert this to Initial-Exec. If we also know that
1544 // this is a local symbol, we can further switch to Local-Exec.
1546 return tls::TLSOPT_TO_LE
;
1547 return tls::TLSOPT_TO_IE
;
1549 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1550 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1551 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1552 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1553 // This is Local-Dynamic, which refers to a local symbol in the
1554 // dynamic TLS block. Since we know that we generating an
1555 // executable, we can switch to Local-Exec.
1556 return tls::TLSOPT_TO_LE
;
1558 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1559 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1560 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1561 // Another type of Local-Dynamic relocation.
1562 return tls::TLSOPT_TO_LE
;
1564 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1565 case elfcpp::R_SPARC_TLS_IE_LO10
:
1566 case elfcpp::R_SPARC_TLS_IE_LD
:
1567 case elfcpp::R_SPARC_TLS_IE_LDX
:
1568 case elfcpp::R_SPARC_TLS_IE_ADD
:
1569 // These are Initial-Exec relocs which get the thread offset
1570 // from the GOT. If we know that we are linking against the
1571 // local symbol, we can switch to Local-Exec, which links the
1572 // thread offset into the instruction.
1574 return tls::TLSOPT_TO_LE
;
1575 return tls::TLSOPT_NONE
;
1577 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1578 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1579 // When we already have Local-Exec, there is nothing further we
1581 return tls::TLSOPT_NONE
;
1588 // Get the Reference_flags for a particular relocation.
1590 template<int size
, bool big_endian
>
1592 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1597 case elfcpp::R_SPARC_NONE
:
1598 case elfcpp::R_SPARC_REGISTER
:
1599 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1600 case elfcpp::R_SPARC_GNU_VTENTRY
:
1601 // No symbol reference.
1604 case elfcpp::R_SPARC_UA64
:
1605 case elfcpp::R_SPARC_64
:
1606 case elfcpp::R_SPARC_HIX22
:
1607 case elfcpp::R_SPARC_LOX10
:
1608 case elfcpp::R_SPARC_H44
:
1609 case elfcpp::R_SPARC_M44
:
1610 case elfcpp::R_SPARC_L44
:
1611 case elfcpp::R_SPARC_HH22
:
1612 case elfcpp::R_SPARC_HM10
:
1613 case elfcpp::R_SPARC_LM22
:
1614 case elfcpp::R_SPARC_HI22
:
1615 case elfcpp::R_SPARC_LO10
:
1616 case elfcpp::R_SPARC_OLO10
:
1617 case elfcpp::R_SPARC_UA32
:
1618 case elfcpp::R_SPARC_32
:
1619 case elfcpp::R_SPARC_UA16
:
1620 case elfcpp::R_SPARC_16
:
1621 case elfcpp::R_SPARC_11
:
1622 case elfcpp::R_SPARC_10
:
1623 case elfcpp::R_SPARC_8
:
1624 case elfcpp::R_SPARC_7
:
1625 case elfcpp::R_SPARC_6
:
1626 case elfcpp::R_SPARC_5
:
1627 return Symbol::ABSOLUTE_REF
;
1629 case elfcpp::R_SPARC_DISP8
:
1630 case elfcpp::R_SPARC_DISP16
:
1631 case elfcpp::R_SPARC_DISP32
:
1632 case elfcpp::R_SPARC_DISP64
:
1633 case elfcpp::R_SPARC_PC_HH22
:
1634 case elfcpp::R_SPARC_PC_HM10
:
1635 case elfcpp::R_SPARC_PC_LM22
:
1636 case elfcpp::R_SPARC_PC10
:
1637 case elfcpp::R_SPARC_PC22
:
1638 case elfcpp::R_SPARC_WDISP30
:
1639 case elfcpp::R_SPARC_WDISP22
:
1640 case elfcpp::R_SPARC_WDISP19
:
1641 case elfcpp::R_SPARC_WDISP16
:
1642 return Symbol::RELATIVE_REF
;
1644 case elfcpp::R_SPARC_PLT64
:
1645 case elfcpp::R_SPARC_PLT32
:
1646 case elfcpp::R_SPARC_HIPLT22
:
1647 case elfcpp::R_SPARC_LOPLT10
:
1648 case elfcpp::R_SPARC_PCPLT10
:
1649 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
1651 case elfcpp::R_SPARC_PCPLT32
:
1652 case elfcpp::R_SPARC_PCPLT22
:
1653 case elfcpp::R_SPARC_WPLT30
:
1654 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1656 case elfcpp::R_SPARC_GOTDATA_OP
:
1657 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1658 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1659 case elfcpp::R_SPARC_GOT10
:
1660 case elfcpp::R_SPARC_GOT13
:
1661 case elfcpp::R_SPARC_GOT22
:
1663 return Symbol::ABSOLUTE_REF
;
1665 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1666 case elfcpp::R_SPARC_TLS_GD_LO10
:
1667 case elfcpp::R_SPARC_TLS_GD_ADD
:
1668 case elfcpp::R_SPARC_TLS_GD_CALL
:
1669 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1670 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1671 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1672 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1673 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1674 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1675 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1676 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1677 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1678 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1679 case elfcpp::R_SPARC_TLS_IE_LO10
:
1680 case elfcpp::R_SPARC_TLS_IE_LD
:
1681 case elfcpp::R_SPARC_TLS_IE_LDX
:
1682 case elfcpp::R_SPARC_TLS_IE_ADD
:
1683 return Symbol::TLS_REF
;
1685 case elfcpp::R_SPARC_COPY
:
1686 case elfcpp::R_SPARC_GLOB_DAT
:
1687 case elfcpp::R_SPARC_JMP_SLOT
:
1688 case elfcpp::R_SPARC_RELATIVE
:
1689 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1690 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1691 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1692 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1693 case elfcpp::R_SPARC_TLS_TPOFF64
:
1694 case elfcpp::R_SPARC_TLS_TPOFF32
:
1696 // Not expected. We will give an error later.
1701 // Generate a PLT entry slot for a call to __tls_get_addr
1702 template<int size
, bool big_endian
>
1704 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1706 Target_sparc
<size
, big_endian
>* target
)
1708 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1710 target
->make_plt_entry(symtab
, layout
, gsym
);
1713 // Report an unsupported relocation against a local symbol.
1715 template<int size
, bool big_endian
>
1717 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1718 Sized_relobj_file
<size
, big_endian
>* object
,
1719 unsigned int r_type
)
1721 gold_error(_("%s: unsupported reloc %u against local symbol"),
1722 object
->name().c_str(), r_type
);
1725 // We are about to emit a dynamic relocation of type R_TYPE. If the
1726 // dynamic linker does not support it, issue an error.
1728 template<int size
, bool big_endian
>
1730 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1732 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1738 // These are the relocation types supported by glibc for sparc 64-bit.
1739 case elfcpp::R_SPARC_RELATIVE
:
1740 case elfcpp::R_SPARC_COPY
:
1741 case elfcpp::R_SPARC_64
:
1742 case elfcpp::R_SPARC_GLOB_DAT
:
1743 case elfcpp::R_SPARC_JMP_SLOT
:
1744 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1745 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1746 case elfcpp::R_SPARC_TLS_TPOFF64
:
1747 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1748 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1749 case elfcpp::R_SPARC_8
:
1750 case elfcpp::R_SPARC_16
:
1751 case elfcpp::R_SPARC_DISP8
:
1752 case elfcpp::R_SPARC_DISP16
:
1753 case elfcpp::R_SPARC_DISP32
:
1754 case elfcpp::R_SPARC_WDISP30
:
1755 case elfcpp::R_SPARC_LO10
:
1756 case elfcpp::R_SPARC_HI22
:
1757 case elfcpp::R_SPARC_OLO10
:
1758 case elfcpp::R_SPARC_H44
:
1759 case elfcpp::R_SPARC_M44
:
1760 case elfcpp::R_SPARC_L44
:
1761 case elfcpp::R_SPARC_HH22
:
1762 case elfcpp::R_SPARC_HM10
:
1763 case elfcpp::R_SPARC_LM22
:
1764 case elfcpp::R_SPARC_UA16
:
1765 case elfcpp::R_SPARC_UA32
:
1766 case elfcpp::R_SPARC_UA64
:
1777 // These are the relocation types supported by glibc for sparc 32-bit.
1778 case elfcpp::R_SPARC_RELATIVE
:
1779 case elfcpp::R_SPARC_COPY
:
1780 case elfcpp::R_SPARC_GLOB_DAT
:
1781 case elfcpp::R_SPARC_32
:
1782 case elfcpp::R_SPARC_JMP_SLOT
:
1783 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1784 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1785 case elfcpp::R_SPARC_TLS_TPOFF32
:
1786 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1787 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1788 case elfcpp::R_SPARC_8
:
1789 case elfcpp::R_SPARC_16
:
1790 case elfcpp::R_SPARC_DISP8
:
1791 case elfcpp::R_SPARC_DISP16
:
1792 case elfcpp::R_SPARC_DISP32
:
1793 case elfcpp::R_SPARC_LO10
:
1794 case elfcpp::R_SPARC_WDISP30
:
1795 case elfcpp::R_SPARC_HI22
:
1796 case elfcpp::R_SPARC_UA16
:
1797 case elfcpp::R_SPARC_UA32
:
1805 // This prevents us from issuing more than one error per reloc
1806 // section. But we can still wind up issuing more than one
1807 // error per object file.
1808 if (this->issued_non_pic_error_
)
1810 gold_assert(parameters
->options().output_is_position_independent());
1811 object
->error(_("requires unsupported dynamic reloc; "
1812 "recompile with -fPIC"));
1813 this->issued_non_pic_error_
= true;
1817 // Scan a relocation for a local symbol.
1819 template<int size
, bool big_endian
>
1821 Target_sparc
<size
, big_endian
>::Scan::local(
1822 Symbol_table
* symtab
,
1824 Target_sparc
<size
, big_endian
>* target
,
1825 Sized_relobj_file
<size
, big_endian
>* object
,
1826 unsigned int data_shndx
,
1827 Output_section
* output_section
,
1828 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1829 unsigned int r_type
,
1830 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1832 unsigned int orig_r_type
= r_type
;
1837 case elfcpp::R_SPARC_NONE
:
1838 case elfcpp::R_SPARC_REGISTER
:
1839 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1840 case elfcpp::R_SPARC_GNU_VTENTRY
:
1843 case elfcpp::R_SPARC_64
:
1844 case elfcpp::R_SPARC_32
:
1845 // If building a shared library (or a position-independent
1846 // executable), we need to create a dynamic relocation for
1847 // this location. The relocation applied at link time will
1848 // apply the link-time value, so we flag the location with
1849 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1850 // relocate it easily.
1851 if (parameters
->options().output_is_position_independent())
1853 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1854 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1855 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1856 output_section
, data_shndx
,
1857 reloc
.get_r_offset(),
1858 reloc
.get_r_addend(), false);
1862 case elfcpp::R_SPARC_HIX22
:
1863 case elfcpp::R_SPARC_LOX10
:
1864 case elfcpp::R_SPARC_H44
:
1865 case elfcpp::R_SPARC_M44
:
1866 case elfcpp::R_SPARC_L44
:
1867 case elfcpp::R_SPARC_HH22
:
1868 case elfcpp::R_SPARC_HM10
:
1869 case elfcpp::R_SPARC_LM22
:
1870 case elfcpp::R_SPARC_UA64
:
1871 case elfcpp::R_SPARC_UA32
:
1872 case elfcpp::R_SPARC_UA16
:
1873 case elfcpp::R_SPARC_HI22
:
1874 case elfcpp::R_SPARC_LO10
:
1875 case elfcpp::R_SPARC_OLO10
:
1876 case elfcpp::R_SPARC_16
:
1877 case elfcpp::R_SPARC_11
:
1878 case elfcpp::R_SPARC_10
:
1879 case elfcpp::R_SPARC_8
:
1880 case elfcpp::R_SPARC_7
:
1881 case elfcpp::R_SPARC_6
:
1882 case elfcpp::R_SPARC_5
:
1883 // If building a shared library (or a position-independent
1884 // executable), we need to create a dynamic relocation for
1886 if (parameters
->options().output_is_position_independent())
1888 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1889 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1891 check_non_pic(object
, r_type
);
1892 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1894 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1895 data_shndx
, reloc
.get_r_offset(),
1896 reloc
.get_r_addend());
1900 gold_assert(lsym
.get_st_value() == 0);
1901 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
1902 output_section
, data_shndx
,
1903 reloc
.get_r_offset(),
1904 reloc
.get_r_addend());
1909 case elfcpp::R_SPARC_WDISP30
:
1910 case elfcpp::R_SPARC_WPLT30
:
1911 case elfcpp::R_SPARC_WDISP22
:
1912 case elfcpp::R_SPARC_WDISP19
:
1913 case elfcpp::R_SPARC_WDISP16
:
1914 case elfcpp::R_SPARC_DISP8
:
1915 case elfcpp::R_SPARC_DISP16
:
1916 case elfcpp::R_SPARC_DISP32
:
1917 case elfcpp::R_SPARC_DISP64
:
1918 case elfcpp::R_SPARC_PC10
:
1919 case elfcpp::R_SPARC_PC22
:
1922 case elfcpp::R_SPARC_GOTDATA_OP
:
1923 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1924 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1925 case elfcpp::R_SPARC_GOT10
:
1926 case elfcpp::R_SPARC_GOT13
:
1927 case elfcpp::R_SPARC_GOT22
:
1929 // The symbol requires a GOT entry.
1930 Output_data_got
<size
, big_endian
>* got
;
1933 got
= target
->got_section(symtab
, layout
);
1934 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1936 // If we are generating a shared object, we need to add a
1937 // dynamic relocation for this symbol's GOT entry.
1938 if (parameters
->options().output_is_position_independent())
1940 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1942 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1945 off
= got
->add_constant(0);
1946 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1947 rela_dyn
->add_local_relative(object
, r_sym
,
1948 elfcpp::R_SPARC_RELATIVE
,
1949 got
, off
, 0, false);
1953 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1957 // These are initial TLS relocs, which are expected when
1959 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1960 case elfcpp::R_SPARC_TLS_GD_LO10
:
1961 case elfcpp::R_SPARC_TLS_GD_ADD
:
1962 case elfcpp::R_SPARC_TLS_GD_CALL
:
1963 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1964 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1965 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1966 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1967 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1968 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1969 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1970 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1971 case elfcpp::R_SPARC_TLS_IE_LO10
:
1972 case elfcpp::R_SPARC_TLS_IE_LD
:
1973 case elfcpp::R_SPARC_TLS_IE_LDX
:
1974 case elfcpp::R_SPARC_TLS_IE_ADD
:
1975 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1976 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1978 bool output_is_shared
= parameters
->options().shared();
1979 const tls::Tls_optimization optimized_type
1980 = optimize_tls_reloc(!output_is_shared
, r_type
);
1983 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1984 case elfcpp::R_SPARC_TLS_GD_LO10
:
1985 case elfcpp::R_SPARC_TLS_GD_ADD
:
1986 case elfcpp::R_SPARC_TLS_GD_CALL
:
1987 if (optimized_type
== tls::TLSOPT_NONE
)
1989 // Create a pair of GOT entries for the module index and
1990 // dtv-relative offset.
1991 Output_data_got
<size
, big_endian
>* got
1992 = target
->got_section(symtab
, layout
);
1993 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1994 unsigned int shndx
= lsym
.get_st_shndx();
1996 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1998 object
->error(_("local symbol %u has bad shndx %u"),
2001 got
->add_local_pair_with_rel(object
, r_sym
,
2002 lsym
.get_st_shndx(),
2004 target
->rela_dyn_section(layout
),
2006 ? elfcpp::R_SPARC_TLS_DTPMOD64
2007 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2009 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2010 generate_tls_call(symtab
, layout
, target
);
2012 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2013 unsupported_reloc_local(object
, r_type
);
2016 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2017 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2018 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2019 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2020 if (optimized_type
== tls::TLSOPT_NONE
)
2022 // Create a GOT entry for the module index.
2023 target
->got_mod_index_entry(symtab
, layout
, object
);
2025 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2026 generate_tls_call(symtab
, layout
, target
);
2028 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2029 unsupported_reloc_local(object
, r_type
);
2032 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2033 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2034 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2037 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2038 case elfcpp::R_SPARC_TLS_IE_LO10
:
2039 case elfcpp::R_SPARC_TLS_IE_LD
:
2040 case elfcpp::R_SPARC_TLS_IE_LDX
:
2041 case elfcpp::R_SPARC_TLS_IE_ADD
:
2042 layout
->set_has_static_tls();
2043 if (optimized_type
== tls::TLSOPT_NONE
)
2045 // Create a GOT entry for the tp-relative offset.
2046 Output_data_got
<size
, big_endian
>* got
2047 = target
->got_section(symtab
, layout
);
2048 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2050 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2052 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2053 unsigned int off
= got
->add_constant(0);
2055 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2057 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2059 elfcpp::R_SPARC_TLS_TPOFF64
:
2060 elfcpp::R_SPARC_TLS_TPOFF32
),
2064 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2065 unsupported_reloc_local(object
, r_type
);
2068 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2069 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2070 layout
->set_has_static_tls();
2071 if (output_is_shared
)
2073 // We need to create a dynamic relocation.
2074 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2075 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2076 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2077 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2078 output_section
, data_shndx
,
2079 reloc
.get_r_offset(), 0);
2086 // These are relocations which should only be seen by the
2087 // dynamic linker, and should never be seen here.
2088 case elfcpp::R_SPARC_COPY
:
2089 case elfcpp::R_SPARC_GLOB_DAT
:
2090 case elfcpp::R_SPARC_JMP_SLOT
:
2091 case elfcpp::R_SPARC_RELATIVE
:
2092 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2093 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2094 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2095 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2096 case elfcpp::R_SPARC_TLS_TPOFF64
:
2097 case elfcpp::R_SPARC_TLS_TPOFF32
:
2098 gold_error(_("%s: unexpected reloc %u in object file"),
2099 object
->name().c_str(), r_type
);
2103 unsupported_reloc_local(object
, r_type
);
2108 // Report an unsupported relocation against a global symbol.
2110 template<int size
, bool big_endian
>
2112 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2113 Sized_relobj_file
<size
, big_endian
>* object
,
2114 unsigned int r_type
,
2117 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2118 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2121 // Scan a relocation for a global symbol.
2123 template<int size
, bool big_endian
>
2125 Target_sparc
<size
, big_endian
>::Scan::global(
2126 Symbol_table
* symtab
,
2128 Target_sparc
<size
, big_endian
>* target
,
2129 Sized_relobj_file
<size
, big_endian
>* object
,
2130 unsigned int data_shndx
,
2131 Output_section
* output_section
,
2132 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2133 unsigned int r_type
,
2136 unsigned int orig_r_type
= r_type
;
2138 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2139 // section. We check here to avoid creating a dynamic reloc against
2140 // _GLOBAL_OFFSET_TABLE_.
2141 if (!target
->has_got_section()
2142 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2143 target
->got_section(symtab
, layout
);
2148 case elfcpp::R_SPARC_NONE
:
2149 case elfcpp::R_SPARC_REGISTER
:
2150 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2151 case elfcpp::R_SPARC_GNU_VTENTRY
:
2154 case elfcpp::R_SPARC_PLT64
:
2155 case elfcpp::R_SPARC_PLT32
:
2156 case elfcpp::R_SPARC_HIPLT22
:
2157 case elfcpp::R_SPARC_LOPLT10
:
2158 case elfcpp::R_SPARC_PCPLT32
:
2159 case elfcpp::R_SPARC_PCPLT22
:
2160 case elfcpp::R_SPARC_PCPLT10
:
2161 case elfcpp::R_SPARC_WPLT30
:
2162 // If the symbol is fully resolved, this is just a PC32 reloc.
2163 // Otherwise we need a PLT entry.
2164 if (gsym
->final_value_is_known())
2166 // If building a shared library, we can also skip the PLT entry
2167 // if the symbol is defined in the output file and is protected
2169 if (gsym
->is_defined()
2170 && !gsym
->is_from_dynobj()
2171 && !gsym
->is_preemptible())
2173 target
->make_plt_entry(symtab
, layout
, gsym
);
2176 case elfcpp::R_SPARC_DISP8
:
2177 case elfcpp::R_SPARC_DISP16
:
2178 case elfcpp::R_SPARC_DISP32
:
2179 case elfcpp::R_SPARC_DISP64
:
2180 case elfcpp::R_SPARC_PC_HH22
:
2181 case elfcpp::R_SPARC_PC_HM10
:
2182 case elfcpp::R_SPARC_PC_LM22
:
2183 case elfcpp::R_SPARC_PC10
:
2184 case elfcpp::R_SPARC_PC22
:
2185 case elfcpp::R_SPARC_WDISP30
:
2186 case elfcpp::R_SPARC_WDISP22
:
2187 case elfcpp::R_SPARC_WDISP19
:
2188 case elfcpp::R_SPARC_WDISP16
:
2190 if (gsym
->needs_plt_entry())
2191 target
->make_plt_entry(symtab
, layout
, gsym
);
2192 // Make a dynamic relocation if necessary.
2193 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2195 if (gsym
->may_need_copy_reloc())
2197 target
->copy_reloc(symtab
, layout
, object
,
2198 data_shndx
, output_section
, gsym
,
2203 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2204 check_non_pic(object
, r_type
);
2205 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2206 data_shndx
, reloc
.get_r_offset(),
2207 reloc
.get_r_addend());
2213 case elfcpp::R_SPARC_UA64
:
2214 case elfcpp::R_SPARC_64
:
2215 case elfcpp::R_SPARC_HIX22
:
2216 case elfcpp::R_SPARC_LOX10
:
2217 case elfcpp::R_SPARC_H44
:
2218 case elfcpp::R_SPARC_M44
:
2219 case elfcpp::R_SPARC_L44
:
2220 case elfcpp::R_SPARC_HH22
:
2221 case elfcpp::R_SPARC_HM10
:
2222 case elfcpp::R_SPARC_LM22
:
2223 case elfcpp::R_SPARC_HI22
:
2224 case elfcpp::R_SPARC_LO10
:
2225 case elfcpp::R_SPARC_OLO10
:
2226 case elfcpp::R_SPARC_UA32
:
2227 case elfcpp::R_SPARC_32
:
2228 case elfcpp::R_SPARC_UA16
:
2229 case elfcpp::R_SPARC_16
:
2230 case elfcpp::R_SPARC_11
:
2231 case elfcpp::R_SPARC_10
:
2232 case elfcpp::R_SPARC_8
:
2233 case elfcpp::R_SPARC_7
:
2234 case elfcpp::R_SPARC_6
:
2235 case elfcpp::R_SPARC_5
:
2237 // Make a PLT entry if necessary.
2238 if (gsym
->needs_plt_entry())
2240 target
->make_plt_entry(symtab
, layout
, gsym
);
2241 // Since this is not a PC-relative relocation, we may be
2242 // taking the address of a function. In that case we need to
2243 // set the entry in the dynamic symbol table to the address of
2245 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2246 gsym
->set_needs_dynsym_value();
2248 // Make a dynamic relocation if necessary.
2249 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2251 unsigned int r_off
= reloc
.get_r_offset();
2253 // The assembler can sometimes emit unaligned relocations
2254 // for dwarf2 cfi directives.
2257 case elfcpp::R_SPARC_16
:
2259 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2261 case elfcpp::R_SPARC_32
:
2263 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2265 case elfcpp::R_SPARC_64
:
2267 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2269 case elfcpp::R_SPARC_UA16
:
2271 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2273 case elfcpp::R_SPARC_UA32
:
2275 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2277 case elfcpp::R_SPARC_UA64
:
2279 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2283 if (gsym
->may_need_copy_reloc())
2285 target
->copy_reloc(symtab
, layout
, object
,
2286 data_shndx
, output_section
, gsym
, reloc
);
2288 else if ((r_type
== elfcpp::R_SPARC_32
2289 || r_type
== elfcpp::R_SPARC_64
)
2290 && gsym
->can_use_relative_reloc(false))
2292 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2293 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2294 output_section
, object
,
2295 data_shndx
, reloc
.get_r_offset(),
2296 reloc
.get_r_addend());
2300 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2302 check_non_pic(object
, r_type
);
2303 if (gsym
->is_from_dynobj()
2304 || gsym
->is_undefined()
2305 || gsym
->is_preemptible())
2306 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2308 reloc
.get_r_offset(),
2309 reloc
.get_r_addend());
2311 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2314 reloc
.get_r_offset(),
2315 reloc
.get_r_addend());
2321 case elfcpp::R_SPARC_GOTDATA_OP
:
2322 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2323 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2324 case elfcpp::R_SPARC_GOT10
:
2325 case elfcpp::R_SPARC_GOT13
:
2326 case elfcpp::R_SPARC_GOT22
:
2328 // The symbol requires a GOT entry.
2329 Output_data_got
<size
, big_endian
>* got
;
2331 got
= target
->got_section(symtab
, layout
);
2332 if (gsym
->final_value_is_known())
2333 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2336 // If this symbol is not fully resolved, we need to add a
2337 // dynamic relocation for it.
2338 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2339 if (gsym
->is_from_dynobj()
2340 || gsym
->is_undefined()
2341 || gsym
->is_preemptible())
2342 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2343 elfcpp::R_SPARC_GLOB_DAT
);
2344 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2346 unsigned int off
= got
->add_constant(0);
2348 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2349 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2356 // These are initial tls relocs, which are expected when
2358 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2359 case elfcpp::R_SPARC_TLS_GD_LO10
:
2360 case elfcpp::R_SPARC_TLS_GD_ADD
:
2361 case elfcpp::R_SPARC_TLS_GD_CALL
:
2362 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2363 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2364 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2365 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2366 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2367 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2368 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2369 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2370 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2371 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2372 case elfcpp::R_SPARC_TLS_IE_LO10
:
2373 case elfcpp::R_SPARC_TLS_IE_LD
:
2374 case elfcpp::R_SPARC_TLS_IE_LDX
:
2375 case elfcpp::R_SPARC_TLS_IE_ADD
:
2377 const bool is_final
= gsym
->final_value_is_known();
2378 const tls::Tls_optimization optimized_type
2379 = optimize_tls_reloc(is_final
, r_type
);
2382 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2383 case elfcpp::R_SPARC_TLS_GD_LO10
:
2384 case elfcpp::R_SPARC_TLS_GD_ADD
:
2385 case elfcpp::R_SPARC_TLS_GD_CALL
:
2386 if (optimized_type
== tls::TLSOPT_NONE
)
2388 // Create a pair of GOT entries for the module index and
2389 // dtv-relative offset.
2390 Output_data_got
<size
, big_endian
>* got
2391 = target
->got_section(symtab
, layout
);
2392 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2393 target
->rela_dyn_section(layout
),
2395 ? elfcpp::R_SPARC_TLS_DTPMOD64
2396 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2398 ? elfcpp::R_SPARC_TLS_DTPOFF64
2399 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2401 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2402 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2403 generate_tls_call(symtab
, layout
, target
);
2405 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2407 // Create a GOT entry for the tp-relative offset.
2408 Output_data_got
<size
, big_endian
>* got
2409 = target
->got_section(symtab
, layout
);
2410 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2411 target
->rela_dyn_section(layout
),
2413 elfcpp::R_SPARC_TLS_TPOFF64
:
2414 elfcpp::R_SPARC_TLS_TPOFF32
));
2416 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2417 unsupported_reloc_global(object
, r_type
, gsym
);
2420 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2421 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2422 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2423 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2424 if (optimized_type
== tls::TLSOPT_NONE
)
2426 // Create a GOT entry for the module index.
2427 target
->got_mod_index_entry(symtab
, layout
, object
);
2429 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2430 generate_tls_call(symtab
, layout
, target
);
2432 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2433 unsupported_reloc_global(object
, r_type
, gsym
);
2436 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2437 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2438 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2441 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2442 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2443 layout
->set_has_static_tls();
2444 if (parameters
->options().shared())
2446 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2447 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2448 output_section
, object
,
2449 data_shndx
, reloc
.get_r_offset(),
2454 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2455 case elfcpp::R_SPARC_TLS_IE_LO10
:
2456 case elfcpp::R_SPARC_TLS_IE_LD
:
2457 case elfcpp::R_SPARC_TLS_IE_LDX
:
2458 case elfcpp::R_SPARC_TLS_IE_ADD
:
2459 layout
->set_has_static_tls();
2460 if (optimized_type
== tls::TLSOPT_NONE
)
2462 // Create a GOT entry for the tp-relative offset.
2463 Output_data_got
<size
, big_endian
>* got
2464 = target
->got_section(symtab
, layout
);
2465 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2466 target
->rela_dyn_section(layout
),
2468 ? elfcpp::R_SPARC_TLS_TPOFF64
2469 : elfcpp::R_SPARC_TLS_TPOFF32
));
2471 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2472 unsupported_reloc_global(object
, r_type
, gsym
);
2478 // These are relocations which should only be seen by the
2479 // dynamic linker, and should never be seen here.
2480 case elfcpp::R_SPARC_COPY
:
2481 case elfcpp::R_SPARC_GLOB_DAT
:
2482 case elfcpp::R_SPARC_JMP_SLOT
:
2483 case elfcpp::R_SPARC_RELATIVE
:
2484 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2485 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2486 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2487 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2488 case elfcpp::R_SPARC_TLS_TPOFF64
:
2489 case elfcpp::R_SPARC_TLS_TPOFF32
:
2490 gold_error(_("%s: unexpected reloc %u in object file"),
2491 object
->name().c_str(), r_type
);
2495 unsupported_reloc_global(object
, r_type
, gsym
);
2500 // Process relocations for gc.
2502 template<int size
, bool big_endian
>
2504 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2505 Symbol_table
* symtab
,
2507 Sized_relobj_file
<size
, big_endian
>* object
,
2508 unsigned int data_shndx
,
2510 const unsigned char* prelocs
,
2512 Output_section
* output_section
,
2513 bool needs_special_offset_handling
,
2514 size_t local_symbol_count
,
2515 const unsigned char* plocal_symbols
)
2517 typedef Target_sparc
<size
, big_endian
> Sparc
;
2518 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2520 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
2521 typename
Target_sparc::Relocatable_size_for_reloc
>(
2530 needs_special_offset_handling
,
2535 // Scan relocations for a section.
2537 template<int size
, bool big_endian
>
2539 Target_sparc
<size
, big_endian
>::scan_relocs(
2540 Symbol_table
* symtab
,
2542 Sized_relobj_file
<size
, big_endian
>* object
,
2543 unsigned int data_shndx
,
2544 unsigned int sh_type
,
2545 const unsigned char* prelocs
,
2547 Output_section
* output_section
,
2548 bool needs_special_offset_handling
,
2549 size_t local_symbol_count
,
2550 const unsigned char* plocal_symbols
)
2552 typedef Target_sparc
<size
, big_endian
> Sparc
;
2553 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2555 if (sh_type
== elfcpp::SHT_REL
)
2557 gold_error(_("%s: unsupported REL reloc section"),
2558 object
->name().c_str());
2562 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2571 needs_special_offset_handling
,
2576 // Finalize the sections.
2578 template<int size
, bool big_endian
>
2580 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2582 const Input_objects
*,
2585 // Fill in some more dynamic tags.
2586 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2588 : this->plt_
->rel_plt());
2589 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2590 this->rela_dyn_
, true, true);
2592 // Emit any relocs we saved in an attempt to avoid generating COPY
2594 if (this->copy_relocs_
.any_saved_relocs())
2595 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2598 // Perform a relocation.
2600 template<int size
, bool big_endian
>
2602 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2603 const Relocate_info
<size
, big_endian
>* relinfo
,
2604 Target_sparc
* target
,
2607 const elfcpp::Rela
<size
, big_endian
>& rela
,
2608 unsigned int r_type
,
2609 const Sized_symbol
<size
>* gsym
,
2610 const Symbol_value
<size
>* psymval
,
2611 unsigned char* view
,
2612 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2613 section_size_type view_size
)
2617 if (this->ignore_gd_add_
)
2619 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2620 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2621 _("missing expected TLS relocation"));
2624 this->ignore_gd_add_
= false;
2628 if (this->reloc_adjust_addr_
== view
)
2631 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2633 // Pick the value to use for symbols defined in shared objects.
2634 Symbol_value
<size
> symval
;
2636 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
2638 elfcpp::Elf_Xword value
;
2640 value
= target
->plt_section()->address() + gsym
->plt_offset();
2642 symval
.set_output_value(value
);
2647 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
2648 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2650 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2651 // pointer points to the beginning, not the end, of the table.
2652 // So we just use the plain offset.
2653 unsigned int got_offset
= 0;
2656 case elfcpp::R_SPARC_GOTDATA_OP
:
2657 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2658 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2659 case elfcpp::R_SPARC_GOT10
:
2660 case elfcpp::R_SPARC_GOT13
:
2661 case elfcpp::R_SPARC_GOT22
:
2664 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2665 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2669 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2670 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2671 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2681 case elfcpp::R_SPARC_NONE
:
2682 case elfcpp::R_SPARC_REGISTER
:
2683 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2684 case elfcpp::R_SPARC_GNU_VTENTRY
:
2687 case elfcpp::R_SPARC_8
:
2688 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2692 case elfcpp::R_SPARC_16
:
2693 if (rela
.get_r_offset() & 0x1)
2695 // The assembler can sometimes emit unaligned relocations
2696 // for dwarf2 cfi directives.
2697 Reloc::ua16(view
, object
, psymval
, addend
);
2700 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2704 case elfcpp::R_SPARC_32
:
2705 if (!parameters
->options().output_is_position_independent())
2707 if (rela
.get_r_offset() & 0x3)
2709 // The assembler can sometimes emit unaligned relocations
2710 // for dwarf2 cfi directives.
2711 Reloc::ua32(view
, object
, psymval
, addend
);
2714 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2719 case elfcpp::R_SPARC_DISP8
:
2720 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2723 case elfcpp::R_SPARC_DISP16
:
2724 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2727 case elfcpp::R_SPARC_DISP32
:
2728 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2731 case elfcpp::R_SPARC_DISP64
:
2732 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2735 case elfcpp::R_SPARC_WDISP30
:
2736 case elfcpp::R_SPARC_WPLT30
:
2737 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2740 case elfcpp::R_SPARC_WDISP22
:
2741 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2744 case elfcpp::R_SPARC_WDISP19
:
2745 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2748 case elfcpp::R_SPARC_WDISP16
:
2749 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2752 case elfcpp::R_SPARC_HI22
:
2753 Reloc::hi22(view
, object
, psymval
, addend
);
2756 case elfcpp::R_SPARC_22
:
2757 Reloc::rela32_22(view
, object
, psymval
, addend
);
2760 case elfcpp::R_SPARC_13
:
2761 Reloc::rela32_13(view
, object
, psymval
, addend
);
2764 case elfcpp::R_SPARC_LO10
:
2765 Reloc::lo10(view
, object
, psymval
, addend
);
2768 case elfcpp::R_SPARC_GOT10
:
2769 Reloc::lo10(view
, got_offset
, addend
);
2772 case elfcpp::R_SPARC_GOTDATA_OP
:
2775 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2776 case elfcpp::R_SPARC_GOT13
:
2777 Reloc::rela32_13(view
, got_offset
, addend
);
2780 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2781 case elfcpp::R_SPARC_GOT22
:
2782 Reloc::hi22(view
, got_offset
, addend
);
2785 case elfcpp::R_SPARC_PC10
:
2786 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2789 case elfcpp::R_SPARC_PC22
:
2790 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2793 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2794 case elfcpp::R_SPARC_UA32
:
2795 Reloc::ua32(view
, object
, psymval
, addend
);
2798 case elfcpp::R_SPARC_PLT64
:
2799 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2803 case elfcpp::R_SPARC_PLT32
:
2804 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2808 case elfcpp::R_SPARC_HIPLT22
:
2809 Reloc::hi22(view
, object
, psymval
, addend
);
2812 case elfcpp::R_SPARC_LOPLT10
:
2813 Reloc::lo10(view
, object
, psymval
, addend
);
2816 case elfcpp::R_SPARC_PCPLT32
:
2817 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2820 case elfcpp::R_SPARC_PCPLT22
:
2821 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2824 case elfcpp::R_SPARC_PCPLT10
:
2825 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2828 case elfcpp::R_SPARC_64
:
2829 if (!parameters
->options().output_is_position_independent())
2831 if (rela
.get_r_offset() & 0x7)
2833 // The assembler can sometimes emit unaligned relocations
2834 // for dwarf2 cfi directives.
2835 Reloc::ua64(view
, object
, psymval
, addend
);
2838 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2843 case elfcpp::R_SPARC_OLO10
:
2845 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2846 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2847 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2851 case elfcpp::R_SPARC_HH22
:
2852 Reloc::hh22(view
, object
, psymval
, addend
);
2855 case elfcpp::R_SPARC_PC_HH22
:
2856 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2859 case elfcpp::R_SPARC_HM10
:
2860 Reloc::hm10(view
, object
, psymval
, addend
);
2863 case elfcpp::R_SPARC_PC_HM10
:
2864 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2867 case elfcpp::R_SPARC_LM22
:
2868 Reloc::hi22(view
, object
, psymval
, addend
);
2871 case elfcpp::R_SPARC_PC_LM22
:
2872 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2875 case elfcpp::R_SPARC_11
:
2876 Reloc::rela32_11(view
, object
, psymval
, addend
);
2879 case elfcpp::R_SPARC_10
:
2880 Reloc::rela32_10(view
, object
, psymval
, addend
);
2883 case elfcpp::R_SPARC_7
:
2884 Reloc::rela32_7(view
, object
, psymval
, addend
);
2887 case elfcpp::R_SPARC_6
:
2888 Reloc::rela32_6(view
, object
, psymval
, addend
);
2891 case elfcpp::R_SPARC_5
:
2892 Reloc::rela32_5(view
, object
, psymval
, addend
);
2895 case elfcpp::R_SPARC_HIX22
:
2896 Reloc::hix22(view
, object
, psymval
, addend
);
2899 case elfcpp::R_SPARC_LOX10
:
2900 Reloc::lox10(view
, object
, psymval
, addend
);
2903 case elfcpp::R_SPARC_H44
:
2904 Reloc::h44(view
, object
, psymval
, addend
);
2907 case elfcpp::R_SPARC_M44
:
2908 Reloc::m44(view
, object
, psymval
, addend
);
2911 case elfcpp::R_SPARC_L44
:
2912 Reloc::l44(view
, object
, psymval
, addend
);
2915 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2916 case elfcpp::R_SPARC_UA64
:
2917 Reloc::ua64(view
, object
, psymval
, addend
);
2920 case elfcpp::R_SPARC_UA16
:
2921 Reloc::ua16(view
, object
, psymval
, addend
);
2924 case elfcpp::R_SPARC_TLS_GD_HI22
:
2925 case elfcpp::R_SPARC_TLS_GD_LO10
:
2926 case elfcpp::R_SPARC_TLS_GD_ADD
:
2927 case elfcpp::R_SPARC_TLS_GD_CALL
:
2928 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2929 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2930 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2931 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2932 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2933 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2934 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2935 case elfcpp::R_SPARC_TLS_IE_HI22
:
2936 case elfcpp::R_SPARC_TLS_IE_LO10
:
2937 case elfcpp::R_SPARC_TLS_IE_LD
:
2938 case elfcpp::R_SPARC_TLS_IE_LDX
:
2939 case elfcpp::R_SPARC_TLS_IE_ADD
:
2940 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2941 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2942 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2943 r_type
, gsym
, psymval
, view
,
2944 address
, view_size
);
2947 case elfcpp::R_SPARC_COPY
:
2948 case elfcpp::R_SPARC_GLOB_DAT
:
2949 case elfcpp::R_SPARC_JMP_SLOT
:
2950 case elfcpp::R_SPARC_RELATIVE
:
2951 // These are outstanding tls relocs, which are unexpected when
2953 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2954 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2955 case elfcpp::R_SPARC_TLS_TPOFF64
:
2956 case elfcpp::R_SPARC_TLS_TPOFF32
:
2957 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2958 _("unexpected reloc %u in object file"),
2963 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2964 _("unsupported reloc %u"),
2972 // Perform a TLS relocation.
2974 template<int size
, bool big_endian
>
2976 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2977 const Relocate_info
<size
, big_endian
>* relinfo
,
2978 Target_sparc
<size
, big_endian
>* target
,
2980 const elfcpp::Rela
<size
, big_endian
>& rela
,
2981 unsigned int r_type
,
2982 const Sized_symbol
<size
>* gsym
,
2983 const Symbol_value
<size
>* psymval
,
2984 unsigned char* view
,
2985 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2988 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2989 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2990 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
2991 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2993 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2994 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2996 const bool is_final
=
2998 ? !parameters
->options().output_is_position_independent()
2999 : gsym
->final_value_is_known());
3000 const tls::Tls_optimization optimized_type
3001 = optimize_tls_reloc(is_final
, r_type
);
3005 case elfcpp::R_SPARC_TLS_GD_HI22
:
3006 case elfcpp::R_SPARC_TLS_GD_LO10
:
3007 case elfcpp::R_SPARC_TLS_GD_ADD
:
3008 case elfcpp::R_SPARC_TLS_GD_CALL
:
3009 if (optimized_type
== tls::TLSOPT_TO_LE
)
3011 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3014 value
-= tls_segment
->memsz();
3018 case elfcpp::R_SPARC_TLS_GD_HI22
:
3019 // TLS_GD_HI22 --> TLS_LE_HIX22
3020 Reloc::hix22(view
, value
, addend
);
3023 case elfcpp::R_SPARC_TLS_GD_LO10
:
3024 // TLS_GD_LO10 --> TLS_LE_LOX10
3025 Reloc::lox10(view
, value
, addend
);
3028 case elfcpp::R_SPARC_TLS_GD_ADD
:
3029 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3030 val
= elfcpp::Swap
<32, true>::readval(wv
);
3031 val
= (val
& ~0x7c000) | 0x1c000;
3032 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3034 case elfcpp::R_SPARC_TLS_GD_CALL
:
3035 // call __tls_get_addr --> nop
3036 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3043 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3044 ? GOT_TYPE_TLS_OFFSET
3045 : GOT_TYPE_TLS_PAIR
);
3048 gold_assert(gsym
->has_got_offset(got_type
));
3049 value
= gsym
->got_offset(got_type
);
3053 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3054 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3055 value
= object
->local_got_offset(r_sym
, got_type
);
3057 if (optimized_type
== tls::TLSOPT_TO_IE
)
3059 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3064 case elfcpp::R_SPARC_TLS_GD_HI22
:
3065 // TLS_GD_HI22 --> TLS_IE_HI22
3066 Reloc::hi22(view
, value
, addend
);
3069 case elfcpp::R_SPARC_TLS_GD_LO10
:
3070 // TLS_GD_LO10 --> TLS_IE_LO10
3071 Reloc::lo10(view
, value
, addend
);
3074 case elfcpp::R_SPARC_TLS_GD_ADD
:
3075 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3076 val
= elfcpp::Swap
<32, true>::readval(wv
);
3083 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3086 case elfcpp::R_SPARC_TLS_GD_CALL
:
3087 // The compiler can put the TLS_GD_ADD instruction
3088 // into the delay slot of the call. If so, we need
3089 // to transpose the two instructions so that the
3090 // new sequence works properly.
3092 // The test we use is if the instruction in the
3093 // delay slot is an add with destination register
3095 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3096 if ((val
& 0x81f80000) == 0x80000000
3097 && ((val
>> 25) & 0x1f) == 0x8)
3104 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3107 this->ignore_gd_add_
= true;
3111 // Even if the delay slot isn't the TLS_GD_ADD
3112 // instruction, we still have to handle the case
3113 // where it sets up %o0 in some other way.
3114 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3116 this->reloc_adjust_addr_
= view
+ 4;
3118 // call __tls_get_addr --> add %g7, %o0, %o0
3119 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3124 else if (optimized_type
== tls::TLSOPT_NONE
)
3128 case elfcpp::R_SPARC_TLS_GD_HI22
:
3129 Reloc::hi22(view
, value
, addend
);
3131 case elfcpp::R_SPARC_TLS_GD_LO10
:
3132 Reloc::lo10(view
, value
, addend
);
3134 case elfcpp::R_SPARC_TLS_GD_ADD
:
3136 case elfcpp::R_SPARC_TLS_GD_CALL
:
3138 Symbol_value
<size
> symval
;
3139 elfcpp::Elf_Xword value
;
3142 tsym
= target
->tls_get_addr_sym_
;
3144 value
= (target
->plt_section()->address() +
3145 tsym
->plt_offset());
3146 symval
.set_output_value(value
);
3147 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3154 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3155 _("unsupported reloc %u"),
3159 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3160 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3161 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3162 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3163 if (optimized_type
== tls::TLSOPT_TO_LE
)
3165 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3169 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3170 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3171 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3172 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3175 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3176 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3181 else if (optimized_type
== tls::TLSOPT_NONE
)
3183 // Relocate the field with the offset of the GOT entry for
3184 // the module index.
3185 unsigned int got_offset
;
3187 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3190 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3191 Reloc::hi22(view
, got_offset
, addend
);
3193 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3194 Reloc::lo10(view
, got_offset
, addend
);
3196 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3198 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3200 Symbol_value
<size
> symval
;
3201 elfcpp::Elf_Xword value
;
3204 tsym
= target
->tls_get_addr_sym_
;
3206 value
= (target
->plt_section()->address() +
3207 tsym
->plt_offset());
3208 symval
.set_output_value(value
);
3209 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3215 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3216 _("unsupported reloc %u"),
3220 // These relocs can appear in debugging sections, in which case
3221 // we won't see the TLS_LDM relocs. The local_dynamic_type
3222 // field tells us this.
3223 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3224 if (optimized_type
== tls::TLSOPT_TO_LE
)
3226 value
-= tls_segment
->memsz();
3227 Reloc::hix22(view
, value
, addend
);
3230 Reloc::ldo_hix22(view
, value
, addend
);
3232 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3233 if (optimized_type
== tls::TLSOPT_TO_LE
)
3235 value
-= tls_segment
->memsz();
3236 Reloc::lox10(view
, value
, addend
);
3239 Reloc::ldo_lox10(view
, value
, addend
);
3241 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3242 if (optimized_type
== tls::TLSOPT_TO_LE
)
3244 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3247 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3248 val
= elfcpp::Swap
<32, true>::readval(wv
);
3249 val
= (val
& ~0x7c000) | 0x1c000;
3250 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3254 // When optimizing IE --> LE, the only relocation that is handled
3255 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3256 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3257 // rs2 and rd are the same.
3258 case elfcpp::R_SPARC_TLS_IE_LD
:
3259 case elfcpp::R_SPARC_TLS_IE_LDX
:
3260 if (optimized_type
== tls::TLSOPT_TO_LE
)
3262 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3263 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3264 Insntype rs2
= val
& 0x1f;
3265 Insntype rd
= (val
>> 25) & 0x1f;
3270 val
= sparc_mov
| (val
& 0x3e00001f);
3272 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3276 case elfcpp::R_SPARC_TLS_IE_HI22
:
3277 case elfcpp::R_SPARC_TLS_IE_LO10
:
3278 if (optimized_type
== tls::TLSOPT_TO_LE
)
3280 value
-= tls_segment
->memsz();
3283 case elfcpp::R_SPARC_TLS_IE_HI22
:
3284 // IE_HI22 --> LE_HIX22
3285 Reloc::hix22(view
, value
, addend
);
3287 case elfcpp::R_SPARC_TLS_IE_LO10
:
3288 // IE_LO10 --> LE_LOX10
3289 Reloc::lox10(view
, value
, addend
);
3294 else if (optimized_type
== tls::TLSOPT_NONE
)
3296 // Relocate the field with the offset of the GOT entry for
3297 // the tp-relative offset of the symbol.
3300 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3301 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3305 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3306 gold_assert(object
->local_has_got_offset(r_sym
,
3307 GOT_TYPE_TLS_OFFSET
));
3308 value
= object
->local_got_offset(r_sym
,
3309 GOT_TYPE_TLS_OFFSET
);
3313 case elfcpp::R_SPARC_TLS_IE_HI22
:
3314 Reloc::hi22(view
, value
, addend
);
3316 case elfcpp::R_SPARC_TLS_IE_LO10
:
3317 Reloc::lo10(view
, value
, addend
);
3322 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3323 _("unsupported reloc %u"),
3327 case elfcpp::R_SPARC_TLS_IE_ADD
:
3328 // This seems to be mainly so that we can find the addition
3329 // instruction if there is one. There doesn't seem to be any
3330 // actual relocation to apply.
3333 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3334 // If we're creating a shared library, a dynamic relocation will
3335 // have been created for this location, so do not apply it now.
3336 if (!parameters
->options().shared())
3338 value
-= tls_segment
->memsz();
3339 Reloc::hix22(view
, value
, addend
);
3343 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3344 // If we're creating a shared library, a dynamic relocation will
3345 // have been created for this location, so do not apply it now.
3346 if (!parameters
->options().shared())
3348 value
-= tls_segment
->memsz();
3349 Reloc::lox10(view
, value
, addend
);
3355 // Relocate section data.
3357 template<int size
, bool big_endian
>
3359 Target_sparc
<size
, big_endian
>::relocate_section(
3360 const Relocate_info
<size
, big_endian
>* relinfo
,
3361 unsigned int sh_type
,
3362 const unsigned char* prelocs
,
3364 Output_section
* output_section
,
3365 bool needs_special_offset_handling
,
3366 unsigned char* view
,
3367 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3368 section_size_type view_size
,
3369 const Reloc_symbol_changes
* reloc_symbol_changes
)
3371 typedef Target_sparc
<size
, big_endian
> Sparc
;
3372 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3374 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3376 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3383 needs_special_offset_handling
,
3387 reloc_symbol_changes
);
3390 // Return the size of a relocation while scanning during a relocatable
3393 template<int size
, bool big_endian
>
3395 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3399 // We are always SHT_RELA, so we should never get here.
3404 // Scan the relocs during a relocatable link.
3406 template<int size
, bool big_endian
>
3408 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3409 Symbol_table
* symtab
,
3411 Sized_relobj_file
<size
, big_endian
>* object
,
3412 unsigned int data_shndx
,
3413 unsigned int sh_type
,
3414 const unsigned char* prelocs
,
3416 Output_section
* output_section
,
3417 bool needs_special_offset_handling
,
3418 size_t local_symbol_count
,
3419 const unsigned char* plocal_symbols
,
3420 Relocatable_relocs
* rr
)
3422 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3424 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3425 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3427 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3428 Scan_relocatable_relocs
>(
3436 needs_special_offset_handling
,
3442 // Relocate a section during a relocatable link.
3444 template<int size
, bool big_endian
>
3446 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3447 const Relocate_info
<size
, big_endian
>* relinfo
,
3448 unsigned int sh_type
,
3449 const unsigned char* prelocs
,
3451 Output_section
* output_section
,
3452 off_t offset_in_output_section
,
3453 const Relocatable_relocs
* rr
,
3454 unsigned char* view
,
3455 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3456 section_size_type view_size
,
3457 unsigned char* reloc_view
,
3458 section_size_type reloc_view_size
)
3460 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3462 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3467 offset_in_output_section
,
3476 // Return the value to use for a dynamic which requires special
3477 // treatment. This is how we support equality comparisons of function
3478 // pointers across shared library boundaries, as described in the
3479 // processor specific ABI supplement.
3481 template<int size
, bool big_endian
>
3483 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3485 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3486 return this->plt_section()->address() + gsym
->plt_offset();
3489 // The selector for sparc object files.
3491 template<int size
, bool big_endian
>
3492 class Target_selector_sparc
: public Target_selector
3495 Target_selector_sparc()
3496 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3497 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
3498 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
3501 Target
* do_recognize(int machine
, int, int)
3506 if (machine
!= elfcpp::EM_SPARCV9
)
3511 if (machine
!= elfcpp::EM_SPARC
3512 && machine
!= elfcpp::EM_SPARC32PLUS
)
3520 return this->instantiate_target();
3523 Target
* do_instantiate_target()
3524 { return new Target_sparc
<size
, big_endian
>(); }
3527 Target_selector_sparc
<32, true> target_selector_sparc32
;
3528 Target_selector_sparc
<64, true> target_selector_sparc64
;
3530 } // End anonymous namespace.