1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
), rela_ifunc_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
)
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 the PLT address to use for a global symbol.
159 do_plt_address_for_global(const Symbol
* gsym
) const
160 { return this->plt_section()->address_for_global(gsym
); }
163 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
164 { return this->plt_section()->address_for_local(relobj
, symndx
); }
166 // Return whether there is a GOT section.
168 has_got_section() const
169 { return this->got_
!= NULL
; }
171 // Return the size of the GOT section.
175 gold_assert(this->got_
!= NULL
);
176 return this->got_
->data_size();
179 // Return the number of entries in the GOT.
181 got_entry_count() const
183 if (this->got_
== NULL
)
185 return this->got_size() / (size
/ 8);
188 // Return the number of entries in the PLT.
190 plt_entry_count() const;
192 // Return the offset of the first non-reserved PLT entry.
194 first_plt_entry_offset() const;
196 // Return the size of each PLT entry.
198 plt_entry_size() const;
202 // The class which scans relocations.
207 : issued_non_pic_error_(false)
211 get_reference_flags(unsigned int r_type
);
214 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
215 Sized_relobj_file
<size
, big_endian
>* object
,
216 unsigned int data_shndx
,
217 Output_section
* output_section
,
218 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
219 const elfcpp::Sym
<size
, big_endian
>& lsym
);
222 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
223 Sized_relobj_file
<size
, big_endian
>* object
,
224 unsigned int data_shndx
,
225 Output_section
* output_section
,
226 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
230 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
232 Sized_relobj_file
<size
, big_endian
>* ,
235 const elfcpp::Rela
<size
, big_endian
>& ,
237 const elfcpp::Sym
<size
, big_endian
>&)
241 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
243 Sized_relobj_file
<size
, big_endian
>* ,
246 const elfcpp::Rela
<size
,
248 unsigned int , Symbol
*)
254 unsupported_reloc_local(Sized_relobj_file
<size
, big_endian
>*,
255 unsigned int r_type
);
258 unsupported_reloc_global(Sized_relobj_file
<size
, big_endian
>*,
259 unsigned int r_type
, Symbol
*);
262 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
263 Target_sparc
* target
);
266 check_non_pic(Relobj
*, unsigned int r_type
);
269 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, big_endian
>*,
270 unsigned int r_type
);
272 // Whether we have issued an error about a non-PIC compilation.
273 bool issued_non_pic_error_
;
276 // The class which implements relocation.
281 : ignore_gd_add_(false), reloc_adjust_addr_(NULL
)
286 if (this->ignore_gd_add_
)
288 // FIXME: This needs to specify the location somehow.
289 gold_error(_("missing expected TLS relocation"));
293 // Do a relocation. Return false if the caller should not issue
294 // any warnings about this relocation.
296 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
297 Output_section
*, size_t relnum
,
298 const elfcpp::Rela
<size
, big_endian
>&,
299 unsigned int r_type
, const Sized_symbol
<size
>*,
300 const Symbol_value
<size
>*,
302 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
306 // Do a TLS relocation.
308 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
309 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
310 unsigned int r_type
, const Sized_symbol
<size
>*,
311 const Symbol_value
<size
>*,
313 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
316 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
319 // If we hit a reloc at this view address, adjust it back by 4 bytes.
320 unsigned char *reloc_adjust_addr_
;
323 // A class which returns the size required for a relocation type,
324 // used while scanning relocs during a relocatable link.
325 class Relocatable_size_for_reloc
329 get_size_for_reloc(unsigned int, Relobj
*);
332 // Get the GOT section, creating it if necessary.
333 Output_data_got
<size
, big_endian
>*
334 got_section(Symbol_table
*, Layout
*);
336 // Create the PLT section.
338 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
340 // Create a PLT entry for a global symbol.
342 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
344 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
346 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
347 Sized_relobj_file
<size
, big_endian
>* relobj
,
348 unsigned int local_sym_index
);
350 // Create a GOT entry for the TLS module index.
352 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
353 Sized_relobj_file
<size
, big_endian
>* object
);
355 // Return the gsym for "__tls_get_addr". Cache if not already
358 tls_get_addr_sym(Symbol_table
* symtab
)
360 if (!this->tls_get_addr_sym_
)
361 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
362 gold_assert(this->tls_get_addr_sym_
);
363 return this->tls_get_addr_sym_
;
366 // Get the PLT section.
367 Output_data_plt_sparc
<size
, big_endian
>*
370 gold_assert(this->plt_
!= NULL
);
374 // Get the dynamic reloc section, creating it if necessary.
376 rela_dyn_section(Layout
*);
378 // Get the section to use for IFUNC relocations.
380 rela_ifunc_section(Layout
*);
382 // Copy a relocation against a global symbol.
384 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
385 Sized_relobj_file
<size
, big_endian
>* object
,
386 unsigned int shndx
, Output_section
* output_section
,
387 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
389 this->copy_relocs_
.copy_reloc(symtab
, layout
,
390 symtab
->get_sized_symbol
<size
>(sym
),
391 object
, shndx
, output_section
,
392 reloc
, this->rela_dyn_section(layout
));
395 // Information about this specific target which we pass to the
396 // general Target structure.
397 static Target::Target_info sparc_info
;
399 // The types of GOT entries needed for this platform.
400 // These values are exposed to the ABI in an incremental link.
401 // Do not renumber existing values without changing the version
402 // number of the .gnu_incremental_inputs section.
405 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
406 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
407 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
411 Output_data_got
<size
, big_endian
>* got_
;
413 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
414 // The dynamic reloc section.
415 Reloc_section
* rela_dyn_
;
416 // The section to use for IFUNC relocs.
417 Reloc_section
* rela_ifunc_
;
418 // Relocs saved to avoid a COPY reloc.
419 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
420 // Space for variables copied with a COPY reloc.
421 Output_data_space
* dynbss_
;
422 // Offset of the GOT entry for the TLS module index;
423 unsigned int got_mod_index_offset_
;
424 // Cached pointer to __tls_get_addr symbol
425 Symbol
* tls_get_addr_sym_
;
429 Target::Target_info Target_sparc
<32, true>::sparc_info
=
432 true, // is_big_endian
433 elfcpp::EM_SPARC
, // machine_code
434 false, // has_make_symbol
435 false, // has_resolve
436 false, // has_code_fill
437 true, // is_default_stack_executable
438 false, // can_icf_inline_merge_sections
440 "/usr/lib/ld.so.1", // dynamic_linker
441 0x00010000, // default_text_segment_address
442 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
443 8 * 1024, // common_pagesize (overridable by -z common-page-size)
444 elfcpp::SHN_UNDEF
, // small_common_shndx
445 elfcpp::SHN_UNDEF
, // large_common_shndx
446 0, // small_common_section_flags
447 0, // large_common_section_flags
448 NULL
, // attributes_section
449 NULL
// attributes_vendor
453 Target::Target_info Target_sparc
<64, true>::sparc_info
=
456 true, // is_big_endian
457 elfcpp::EM_SPARCV9
, // machine_code
458 false, // has_make_symbol
459 false, // has_resolve
460 false, // has_code_fill
461 true, // is_default_stack_executable
462 false, // can_icf_inline_merge_sections
464 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
465 0x100000, // default_text_segment_address
466 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
467 8 * 1024, // common_pagesize (overridable by -z common-page-size)
468 elfcpp::SHN_UNDEF
, // small_common_shndx
469 elfcpp::SHN_UNDEF
, // large_common_shndx
470 0, // small_common_section_flags
471 0, // large_common_section_flags
472 NULL
, // attributes_section
473 NULL
// attributes_vendor
476 // We have to take care here, even when operating in little-endian
477 // mode, sparc instructions are still big endian.
478 template<int size
, bool big_endian
>
479 class Sparc_relocate_functions
482 // Do a simple relocation with the addend in the relocation.
483 template<int valsize
>
485 rela(unsigned char* view
,
486 unsigned int right_shift
,
487 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
488 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
489 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
491 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
492 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
493 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
494 Valtype reloc
= ((value
+ addend
) >> right_shift
);
499 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
502 // Do a simple relocation using a symbol value with the addend in
504 template<int valsize
>
506 rela(unsigned char* view
,
507 unsigned int right_shift
,
508 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
509 const Sized_relobj_file
<size
, big_endian
>* object
,
510 const Symbol_value
<size
>* psymval
,
511 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
513 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
514 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
515 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
516 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
521 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
524 // Do a simple relocation using a symbol value with the addend in
525 // the relocation, unaligned.
526 template<int valsize
>
528 rela_ua(unsigned char* view
,
529 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
530 const Sized_relobj_file
<size
, big_endian
>* object
,
531 const Symbol_value
<size
>* psymval
,
532 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
534 typedef typename
elfcpp::Swap_unaligned
<valsize
,
535 big_endian
>::Valtype Valtype
;
536 unsigned char* wv
= view
;
537 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
538 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
543 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
546 // Do a simple PC relative relocation with a Symbol_value with the
547 // addend in the relocation.
548 template<int valsize
>
550 pcrela(unsigned char* view
,
551 unsigned int right_shift
,
552 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
553 const Sized_relobj_file
<size
, big_endian
>* object
,
554 const Symbol_value
<size
>* psymval
,
555 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
556 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
558 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
559 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
560 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
561 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
567 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
570 template<int valsize
>
572 pcrela_unaligned(unsigned char* view
,
573 const Sized_relobj_file
<size
, big_endian
>* object
,
574 const Symbol_value
<size
>* psymval
,
575 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
576 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
578 typedef typename
elfcpp::Swap_unaligned
<valsize
,
579 big_endian
>::Valtype Valtype
;
580 unsigned char* wv
= view
;
581 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
583 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
586 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
587 typedef Sparc_relocate_functions
<size
, true> This_insn
;
590 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
592 wdisp30(unsigned char* view
,
593 const Sized_relobj_file
<size
, big_endian
>* object
,
594 const Symbol_value
<size
>* psymval
,
595 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
596 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
598 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
599 psymval
, addend
, address
);
602 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
604 wdisp22(unsigned char* view
,
605 const Sized_relobj_file
<size
, big_endian
>* object
,
606 const Symbol_value
<size
>* psymval
,
607 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
608 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
610 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
611 psymval
, addend
, address
);
614 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
616 wdisp19(unsigned char* view
,
617 const Sized_relobj_file
<size
, big_endian
>* object
,
618 const Symbol_value
<size
>* psymval
,
619 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
620 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
622 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
623 psymval
, addend
, address
);
626 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
628 wdisp16(unsigned char* view
,
629 const Sized_relobj_file
<size
, big_endian
>* object
,
630 const Symbol_value
<size
>* psymval
,
631 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
632 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
634 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
635 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
636 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
637 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
640 // The relocation value is split between the low 14 bits,
642 val
&= ~((0x3 << 20) | 0x3fff);
643 reloc
= (((reloc
& 0xc000) << (20 - 14))
644 | (reloc
& 0x3ffff));
646 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
649 // R_SPARC_WDISP10: (Symbol + Addend - Address) >> 2
651 wdisp10(unsigned char* view
,
652 const Sized_relobj_file
<size
, big_endian
>* object
,
653 const Symbol_value
<size
>* psymval
,
654 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
655 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
657 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
658 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
659 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
660 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
663 // The relocation value is split between the low bits 5-12,
664 // and high bits 19-20.
665 val
&= ~((0x3 << 19) | (0xff << 5));
666 reloc
= (((reloc
& 0x300) << (19 - 8))
667 | ((reloc
& 0xff) << (5 - 0)));
669 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
672 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
674 pc22(unsigned char* view
,
675 const Sized_relobj_file
<size
, big_endian
>* object
,
676 const Symbol_value
<size
>* psymval
,
677 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
678 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
680 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
681 psymval
, addend
, address
);
684 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
686 pc10(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
,
690 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
692 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
693 psymval
, addend
, address
);
696 // R_SPARC_HI22: (Symbol + Addend) >> 10
698 hi22(unsigned char* view
,
699 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
700 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
702 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
705 // R_SPARC_HI22: (Symbol + Addend) >> 10
707 hi22(unsigned char* view
,
708 const Sized_relobj_file
<size
, big_endian
>* object
,
709 const Symbol_value
<size
>* psymval
,
710 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
712 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
715 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
717 pcplt22(unsigned char* view
,
718 const Sized_relobj_file
<size
, big_endian
>* object
,
719 const Symbol_value
<size
>* psymval
,
720 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
721 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
723 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
724 psymval
, addend
, address
);
727 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
729 lo10(unsigned char* view
,
730 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
731 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
733 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
736 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
738 lo10(unsigned char* view
,
739 const Sized_relobj_file
<size
, big_endian
>* object
,
740 const Symbol_value
<size
>* psymval
,
741 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
743 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
746 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
748 lo10(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
,
752 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
754 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
755 psymval
, addend
, address
);
758 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
760 olo10(unsigned char* view
,
761 const Sized_relobj_file
<size
, big_endian
>* object
,
762 const Symbol_value
<size
>* psymval
,
763 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
764 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
766 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
767 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
768 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
769 Valtype reloc
= psymval
->value(object
, addend
);
776 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
779 // R_SPARC_22: (Symbol + Addend)
781 rela32_22(unsigned char* view
,
782 const Sized_relobj_file
<size
, big_endian
>* object
,
783 const Symbol_value
<size
>* psymval
,
784 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
786 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
789 // R_SPARC_13: (Symbol + Addend)
791 rela32_13(unsigned char* view
,
792 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
793 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
795 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
798 // R_SPARC_13: (Symbol + Addend)
800 rela32_13(unsigned char* view
,
801 const Sized_relobj_file
<size
, big_endian
>* object
,
802 const Symbol_value
<size
>* psymval
,
803 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
805 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
808 // R_SPARC_UA16: (Symbol + Addend)
810 ua16(unsigned char* view
,
811 const Sized_relobj_file
<size
, big_endian
>* object
,
812 const Symbol_value
<size
>* psymval
,
813 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
815 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
818 // R_SPARC_UA32: (Symbol + Addend)
820 ua32(unsigned char* view
,
821 const Sized_relobj_file
<size
, big_endian
>* object
,
822 const Symbol_value
<size
>* psymval
,
823 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
825 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
828 // R_SPARC_UA64: (Symbol + Addend)
830 ua64(unsigned char* view
,
831 const Sized_relobj_file
<size
, big_endian
>* object
,
832 const Symbol_value
<size
>* psymval
,
833 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
835 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
836 object
, psymval
, addend
);
839 // R_SPARC_DISP8: (Symbol + Addend - Address)
841 disp8(unsigned char* view
,
842 const Sized_relobj_file
<size
, big_endian
>* object
,
843 const Symbol_value
<size
>* psymval
,
844 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
845 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
847 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
851 // R_SPARC_DISP16: (Symbol + Addend - Address)
853 disp16(unsigned char* view
,
854 const Sized_relobj_file
<size
, big_endian
>* object
,
855 const Symbol_value
<size
>* psymval
,
856 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
857 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
859 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
863 // R_SPARC_DISP32: (Symbol + Addend - Address)
865 disp32(unsigned char* view
,
866 const Sized_relobj_file
<size
, big_endian
>* object
,
867 const Symbol_value
<size
>* psymval
,
868 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
869 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
871 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
875 // R_SPARC_DISP64: (Symbol + Addend - Address)
877 disp64(unsigned char* view
,
878 const Sized_relobj_file
<size
, big_endian
>* object
,
879 const Symbol_value
<size
>* psymval
,
880 elfcpp::Elf_Xword addend
,
881 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
883 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
887 // R_SPARC_H34: (Symbol + Addend) >> 12
889 h34(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
, 12, 0x003fffff, object
, psymval
, addend
);
897 // R_SPARC_H44: (Symbol + Addend) >> 22
899 h44(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
)
904 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
907 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
909 m44(unsigned char* view
,
910 const Sized_relobj_file
<size
, big_endian
>* object
,
911 const Symbol_value
<size
>* psymval
,
912 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
914 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
917 // R_SPARC_L44: (Symbol + Addend) & 0xfff
919 l44(unsigned char* view
,
920 const Sized_relobj_file
<size
, big_endian
>* object
,
921 const Symbol_value
<size
>* psymval
,
922 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
924 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
927 // R_SPARC_HH22: (Symbol + Addend) >> 42
929 hh22(unsigned char* view
,
930 const Sized_relobj_file
<size
, big_endian
>* object
,
931 const Symbol_value
<size
>* psymval
,
932 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
934 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
937 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
939 pc_hh22(unsigned char* view
,
940 const Sized_relobj_file
<size
, big_endian
>* object
,
941 const Symbol_value
<size
>* psymval
,
942 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
943 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
945 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
946 psymval
, addend
, address
);
949 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
951 hm10(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
, 32, 0x000003ff, object
, psymval
, addend
);
959 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
961 pc_hm10(unsigned char* view
,
962 const Sized_relobj_file
<size
, big_endian
>* object
,
963 const Symbol_value
<size
>* psymval
,
964 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
965 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
967 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
968 psymval
, addend
, address
);
971 // R_SPARC_11: (Symbol + Addend)
973 rela32_11(unsigned char* view
,
974 const Sized_relobj_file
<size
, big_endian
>* object
,
975 const Symbol_value
<size
>* psymval
,
976 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
978 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
981 // R_SPARC_10: (Symbol + Addend)
983 rela32_10(unsigned char* view
,
984 const Sized_relobj_file
<size
, big_endian
>* object
,
985 const Symbol_value
<size
>* psymval
,
986 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
988 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
991 // R_SPARC_7: (Symbol + Addend)
993 rela32_7(unsigned char* view
,
994 const Sized_relobj_file
<size
, big_endian
>* object
,
995 const Symbol_value
<size
>* psymval
,
996 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
998 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
1001 // R_SPARC_6: (Symbol + Addend)
1003 rela32_6(unsigned char* view
,
1004 const Sized_relobj_file
<size
, big_endian
>* object
,
1005 const Symbol_value
<size
>* psymval
,
1006 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1008 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
1011 // R_SPARC_5: (Symbol + Addend)
1013 rela32_5(unsigned char* view
,
1014 const Sized_relobj_file
<size
, big_endian
>* object
,
1015 const Symbol_value
<size
>* psymval
,
1016 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1018 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
1021 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
1023 ldo_hix22(unsigned char* view
,
1024 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1025 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1027 This_insn::hi22(view
, value
, addend
);
1030 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
1032 ldo_lox10(unsigned char* view
,
1033 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1034 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1036 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1037 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1038 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1039 Valtype reloc
= (value
+ addend
);
1044 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1047 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1049 hix22(unsigned char* view
,
1050 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1051 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1053 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1054 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1055 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1056 Valtype reloc
= (value
+ addend
);
1060 reloc
^= ~(Valtype
)0;
1065 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1068 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1070 hix22(unsigned char* view
,
1071 const Sized_relobj_file
<size
, big_endian
>* object
,
1072 const Symbol_value
<size
>* psymval
,
1073 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1075 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1076 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1077 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1078 Valtype reloc
= psymval
->value(object
, addend
);
1082 reloc
^= ~(Valtype
)0;
1087 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1091 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1093 lox10(unsigned char* view
,
1094 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1095 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1097 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1098 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1099 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1100 Valtype reloc
= (value
+ addend
);
1106 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1109 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1111 lox10(unsigned char* view
,
1112 const Sized_relobj_file
<size
, big_endian
>* object
,
1113 const Symbol_value
<size
>* psymval
,
1114 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1116 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1117 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1118 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1119 Valtype reloc
= psymval
->value(object
, addend
);
1125 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1129 // Get the GOT section, creating it if necessary.
1131 template<int size
, bool big_endian
>
1132 Output_data_got
<size
, big_endian
>*
1133 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1136 if (this->got_
== NULL
)
1138 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1140 this->got_
= new Output_data_got
<size
, big_endian
>();
1142 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1144 | elfcpp::SHF_WRITE
),
1145 this->got_
, ORDER_RELRO
, true);
1147 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1148 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1149 Symbol_table::PREDEFINED
,
1151 0, 0, elfcpp::STT_OBJECT
,
1153 elfcpp::STV_HIDDEN
, 0,
1160 // Get the dynamic reloc section, creating it if necessary.
1162 template<int size
, bool big_endian
>
1163 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1164 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1166 if (this->rela_dyn_
== NULL
)
1168 gold_assert(layout
!= NULL
);
1169 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1170 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1171 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1172 ORDER_DYNAMIC_RELOCS
, false);
1174 return this->rela_dyn_
;
1177 // Get the section to use for IFUNC relocs, creating it if
1178 // necessary. These go in .rela.dyn, but only after all other dynamic
1179 // relocations. They need to follow the other dynamic relocations so
1180 // that they can refer to global variables initialized by those
1183 template<int size
, bool big_endian
>
1184 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1185 Target_sparc
<size
, big_endian
>::rela_ifunc_section(Layout
* layout
)
1187 if (this->rela_ifunc_
== NULL
)
1189 // Make sure we have already created the dynamic reloc section.
1190 this->rela_dyn_section(layout
);
1191 this->rela_ifunc_
= new Reloc_section(false);
1192 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1193 elfcpp::SHF_ALLOC
, this->rela_ifunc_
,
1194 ORDER_DYNAMIC_RELOCS
, false);
1195 gold_assert(this->rela_dyn_
->output_section()
1196 == this->rela_ifunc_
->output_section());
1198 return this->rela_ifunc_
;
1201 // A class to handle the PLT data.
1203 template<int size
, bool big_endian
>
1204 class Output_data_plt_sparc
: public Output_section_data
1207 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1208 size
, big_endian
> Reloc_section
;
1210 Output_data_plt_sparc(Layout
*);
1212 // Add an entry to the PLT.
1213 void add_entry(Symbol_table
* symtab
, Layout
* layout
, Symbol
* gsym
);
1215 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
1217 add_local_ifunc_entry(Symbol_table
*, Layout
*,
1218 Sized_relobj_file
<size
, big_endian
>* relobj
,
1219 unsigned int local_sym_index
);
1221 // Return the .rela.plt section data.
1222 const Reloc_section
* rel_plt() const
1227 // Return where the IFUNC relocations should go.
1229 rela_ifunc(Symbol_table
*, Layout
*);
1232 emit_pending_ifunc_relocs();
1234 // Return whether we created a section for IFUNC relocations.
1236 has_ifunc_section() const
1237 { return this->ifunc_rel_
!= NULL
; }
1239 // Return the number of PLT entries.
1242 { return this->count_
+ this->ifunc_count_
; }
1244 // Return the offset of the first non-reserved PLT entry.
1246 first_plt_entry_offset()
1247 { return 4 * base_plt_entry_size
; }
1249 // Return the size of a PLT entry.
1251 get_plt_entry_size()
1252 { return base_plt_entry_size
; }
1254 // Return the PLT address to use for a global symbol.
1256 address_for_global(const Symbol
*);
1258 // Return the PLT address to use for a local symbol.
1260 address_for_local(const Relobj
*, unsigned int symndx
);
1263 void do_adjust_output_section(Output_section
* os
);
1265 // Write to a map file.
1267 do_print_to_mapfile(Mapfile
* mapfile
) const
1268 { mapfile
->print_output_data(this, _("** PLT")); }
1271 // The size of an entry in the PLT.
1272 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1274 static const unsigned int plt_entries_per_block
= 160;
1275 static const unsigned int plt_insn_chunk_size
= 24;
1276 static const unsigned int plt_pointer_chunk_size
= 8;
1277 static const unsigned int plt_block_size
=
1278 (plt_entries_per_block
1279 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1282 plt_index_to_offset(unsigned int index
)
1284 section_offset_type offset
;
1286 if (size
== 32 || index
< 32768)
1287 offset
= index
* base_plt_entry_size
;
1290 unsigned int ext_index
= index
- 32768;
1292 offset
= (32768 * base_plt_entry_size
)
1293 + ((ext_index
/ plt_entries_per_block
)
1295 + ((ext_index
% plt_entries_per_block
)
1296 * plt_insn_chunk_size
);
1301 // Set the final size.
1303 set_final_data_size()
1305 unsigned int full_count
= this->entry_count() + 4;
1306 unsigned int extra
= (size
== 32 ? 4 : 0);
1307 section_offset_type sz
= plt_index_to_offset(full_count
) + extra
;
1309 return this->set_data_size(sz
);
1312 // Write out the PLT data.
1314 do_write(Output_file
*);
1320 unsigned int plt_index
;
1326 Sized_relobj_file
<size
, big_endian
>* object
;
1327 unsigned int local_sym_index
;
1328 unsigned int plt_index
;
1331 // The reloc section.
1332 Reloc_section
* rel_
;
1333 // The IFUNC relocations, if necessary. These must follow the
1334 // regular relocations.
1335 Reloc_section
* ifunc_rel_
;
1336 // The number of PLT entries.
1337 unsigned int count_
;
1338 // The number of PLT entries for IFUNC symbols.
1339 unsigned int ifunc_count_
;
1340 // Global STT_GNU_IFUNC symbols.
1341 std::vector
<Global_ifunc
> global_ifuncs_
;
1342 // Local STT_GNU_IFUNC symbols.
1343 std::vector
<Local_ifunc
> local_ifuncs_
;
1346 // Define the constants as required by C++ standard.
1348 template<int size
, bool big_endian
>
1349 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1351 template<int size
, bool big_endian
>
1353 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1355 template<int size
, bool big_endian
>
1356 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1358 template<int size
, bool big_endian
>
1360 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1362 template<int size
, bool big_endian
>
1363 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1365 // Create the PLT section. The ordinary .got section is an argument,
1366 // since we need to refer to the start.
1368 template<int size
, bool big_endian
>
1369 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1370 : Output_section_data(size
== 32 ? 4 : 8), ifunc_rel_(NULL
),
1371 count_(0), ifunc_count_(0), global_ifuncs_(), local_ifuncs_()
1373 this->rel_
= new Reloc_section(false);
1374 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1375 elfcpp::SHF_ALLOC
, this->rel_
,
1376 ORDER_DYNAMIC_PLT_RELOCS
, false);
1379 template<int size
, bool big_endian
>
1381 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1386 // Add an entry to the PLT.
1388 template<int size
, bool big_endian
>
1390 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol_table
* symtab
,
1394 gold_assert(!gsym
->has_plt_offset());
1396 section_offset_type plt_offset
;
1399 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1400 && gsym
->can_use_relative_reloc(false))
1402 index
= this->ifunc_count_
;
1403 plt_offset
= plt_index_to_offset(index
);
1404 gsym
->set_plt_offset(plt_offset
);
1405 ++this->ifunc_count_
;
1406 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1408 struct Global_ifunc gi
;
1411 gi
.plt_index
= index
;
1412 this->global_ifuncs_
.push_back(gi
);
1416 plt_offset
= plt_index_to_offset(this->count_
+ 4);
1417 gsym
->set_plt_offset(plt_offset
);
1419 gsym
->set_needs_dynsym_entry();
1420 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1424 // Note that we don't need to save the symbol. The contents of the
1425 // PLT are independent of which symbols are used. The symbols only
1426 // appear in the relocations.
1429 template<int size
, bool big_endian
>
1431 Output_data_plt_sparc
<size
, big_endian
>::add_local_ifunc_entry(
1432 Symbol_table
* symtab
,
1434 Sized_relobj_file
<size
, big_endian
>* relobj
,
1435 unsigned int local_sym_index
)
1437 unsigned int index
= this->ifunc_count_
;
1438 section_offset_type plt_offset
;
1440 plt_offset
= plt_index_to_offset(index
);
1441 ++this->ifunc_count_
;
1443 Reloc_section
* rel
= this->rela_ifunc(symtab
, layout
);
1445 struct Local_ifunc li
;
1448 li
.local_sym_index
= local_sym_index
;
1449 li
.plt_index
= index
;
1450 this->local_ifuncs_
.push_back(li
);
1455 // Emit any pending IFUNC plt relocations.
1457 template<int size
, bool big_endian
>
1459 Output_data_plt_sparc
<size
, big_endian
>::emit_pending_ifunc_relocs()
1461 // Emit any pending IFUNC relocs.
1462 for (typename
std::vector
<Global_ifunc
>::const_iterator p
=
1463 this->global_ifuncs_
.begin();
1464 p
!= this->global_ifuncs_
.end();
1467 section_offset_type plt_offset
;
1470 index
= this->count_
+ p
->plt_index
+ 4;
1471 plt_offset
= this->plt_index_to_offset(index
);
1472 p
->rel
->add_symbolless_global_addend(p
->gsym
, elfcpp::R_SPARC_JMP_IREL
,
1473 this, plt_offset
, 0);
1476 for (typename
std::vector
<Local_ifunc
>::const_iterator p
=
1477 this->local_ifuncs_
.begin();
1478 p
!= this->local_ifuncs_
.end();
1481 section_offset_type plt_offset
;
1484 index
= this->count_
+ p
->plt_index
+ 4;
1485 plt_offset
= this->plt_index_to_offset(index
);
1486 p
->rel
->add_symbolless_local_addend(p
->object
, p
->local_sym_index
,
1487 elfcpp::R_SPARC_JMP_IREL
,
1488 this, plt_offset
, 0);
1492 // Return where the IFUNC relocations should go in the PLT. These
1493 // follow the non-IFUNC relocations.
1495 template<int size
, bool big_endian
>
1496 typename Output_data_plt_sparc
<size
, big_endian
>::Reloc_section
*
1497 Output_data_plt_sparc
<size
, big_endian
>::rela_ifunc(
1498 Symbol_table
* symtab
,
1501 if (this->ifunc_rel_
== NULL
)
1503 this->ifunc_rel_
= new Reloc_section(false);
1504 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1505 elfcpp::SHF_ALLOC
, this->ifunc_rel_
,
1506 ORDER_DYNAMIC_PLT_RELOCS
, false);
1507 gold_assert(this->ifunc_rel_
->output_section()
1508 == this->rel_
->output_section());
1510 if (parameters
->doing_static_link())
1512 // A statically linked executable will only have a .rel.plt
1513 // section to hold R_SPARC_IRELATIVE and R_SPARC_JMP_IREL
1514 // relocs for STT_GNU_IFUNC symbols. The library will use
1515 // these symbols to locate the IRELATIVE and JMP_IREL relocs
1516 // at program startup time.
1517 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1518 Symbol_table::PREDEFINED
,
1519 this->ifunc_rel_
, 0, 0,
1520 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1521 elfcpp::STV_HIDDEN
, 0, false, true);
1522 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1523 Symbol_table::PREDEFINED
,
1524 this->ifunc_rel_
, 0, 0,
1525 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1526 elfcpp::STV_HIDDEN
, 0, true, true);
1529 return this->ifunc_rel_
;
1532 // Return the PLT address to use for a global symbol.
1534 template<int size
, bool big_endian
>
1536 Output_data_plt_sparc
<size
, big_endian
>::address_for_global(const Symbol
* gsym
)
1538 uint64_t offset
= 0;
1539 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1540 && gsym
->can_use_relative_reloc(false))
1541 offset
= plt_index_to_offset(this->count_
+ 4);
1542 return this->address() + offset
;
1545 // Return the PLT address to use for a local symbol. These are always
1546 // IRELATIVE relocs.
1548 template<int size
, bool big_endian
>
1550 Output_data_plt_sparc
<size
, big_endian
>::address_for_local(
1554 return this->address() + plt_index_to_offset(this->count_
+ 4);
1557 static const unsigned int sparc_nop
= 0x01000000;
1558 static const unsigned int sparc_sethi_g1
= 0x03000000;
1559 static const unsigned int sparc_branch_always
= 0x30800000;
1560 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1561 static const unsigned int sparc_mov
= 0x80100000;
1562 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1563 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1564 static const unsigned int sparc_call_plus_8
= 0x40000002;
1565 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1566 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1567 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1569 // Write out the PLT.
1571 template<int size
, bool big_endian
>
1573 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1575 const off_t offset
= this->offset();
1576 const section_size_type oview_size
=
1577 convert_to_section_size_type(this->data_size());
1578 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1579 unsigned char* pov
= oview
;
1581 memset(pov
, 0, base_plt_entry_size
* 4);
1582 pov
+= this->first_plt_entry_offset();
1584 unsigned int plt_offset
= base_plt_entry_size
* 4;
1585 const unsigned int count
= this->entry_count();
1591 limit
= (count
> 32768 ? 32768 : count
);
1593 for (unsigned int i
= 0; i
< limit
; ++i
)
1595 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1596 sparc_sethi_g1
+ plt_offset
);
1597 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1598 sparc_branch_always_pt
+
1599 (((base_plt_entry_size
-
1600 (plt_offset
+ 4)) >> 2) &
1602 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1603 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1604 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1605 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1606 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1607 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1609 pov
+= base_plt_entry_size
;
1610 plt_offset
+= base_plt_entry_size
;
1615 unsigned int ext_cnt
= count
- 32768;
1616 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1618 for (unsigned int i
= 0; i
< blks
; ++i
)
1620 unsigned int data_off
= (plt_entries_per_block
1621 * plt_insn_chunk_size
) - 4;
1623 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1625 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1627 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1629 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1631 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1632 sparc_ldx_o7_imm_g1
+
1633 (data_off
& 0x1fff));
1634 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1635 sparc_jmpl_o7_g1_g1
);
1636 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1639 elfcpp::Swap
<64, big_endian
>::writeval(
1640 pov
+ 0x4 + data_off
,
1641 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1643 pov
+= plt_insn_chunk_size
;
1648 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1649 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1651 unsigned int data_off
= (sub_blk_cnt
1652 * plt_insn_chunk_size
) - 4;
1654 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1656 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1658 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1660 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1662 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1663 sparc_ldx_o7_imm_g1
+
1664 (data_off
& 0x1fff));
1665 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1666 sparc_jmpl_o7_g1_g1
);
1667 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1670 elfcpp::Swap
<64, big_endian
>::writeval(
1671 pov
+ 0x4 + data_off
,
1672 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1674 pov
+= plt_insn_chunk_size
;
1682 for (unsigned int i
= 0; i
< count
; ++i
)
1684 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1685 sparc_sethi_g1
+ plt_offset
);
1686 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1687 sparc_branch_always
+
1688 (((- (plt_offset
+ 4)) >> 2) &
1690 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1692 pov
+= base_plt_entry_size
;
1693 plt_offset
+= base_plt_entry_size
;
1696 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1700 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1702 of
->write_output_view(offset
, oview_size
, oview
);
1705 // Create the PLT section.
1707 template<int size
, bool big_endian
>
1709 Target_sparc
<size
, big_endian
>::make_plt_section(Symbol_table
* symtab
,
1712 // Create the GOT sections first.
1713 this->got_section(symtab
, layout
);
1715 // Ensure that .rela.dyn always appears before .rela.plt This is
1716 // necessary due to how, on Sparc and some other targets, .rela.dyn
1717 // needs to include .rela.plt in it's range.
1718 this->rela_dyn_section(layout
);
1720 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1721 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1723 | elfcpp::SHF_EXECINSTR
1724 | elfcpp::SHF_WRITE
),
1725 this->plt_
, ORDER_NON_RELRO_FIRST
, false);
1727 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1728 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1729 Symbol_table::PREDEFINED
,
1731 0, 0, elfcpp::STT_OBJECT
,
1733 elfcpp::STV_HIDDEN
, 0,
1737 // Create a PLT entry for a global symbol.
1739 template<int size
, bool big_endian
>
1741 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1745 if (gsym
->has_plt_offset())
1748 if (this->plt_
== NULL
)
1749 this->make_plt_section(symtab
, layout
);
1751 this->plt_
->add_entry(symtab
, layout
, gsym
);
1754 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
1756 template<int size
, bool big_endian
>
1758 Target_sparc
<size
, big_endian
>::make_local_ifunc_plt_entry(
1759 Symbol_table
* symtab
,
1761 Sized_relobj_file
<size
, big_endian
>* relobj
,
1762 unsigned int local_sym_index
)
1764 if (relobj
->local_has_plt_offset(local_sym_index
))
1766 if (this->plt_
== NULL
)
1767 this->make_plt_section(symtab
, layout
);
1768 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
1771 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
1774 // Return the number of entries in the PLT.
1776 template<int size
, bool big_endian
>
1778 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1780 if (this->plt_
== NULL
)
1782 return this->plt_
->entry_count();
1785 // Return the offset of the first non-reserved PLT entry.
1787 template<int size
, bool big_endian
>
1789 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1791 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1794 // Return the size of each PLT entry.
1796 template<int size
, bool big_endian
>
1798 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1800 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1803 // Create a GOT entry for the TLS module index.
1805 template<int size
, bool big_endian
>
1807 Target_sparc
<size
, big_endian
>::got_mod_index_entry(
1808 Symbol_table
* symtab
,
1810 Sized_relobj_file
<size
, big_endian
>* object
)
1812 if (this->got_mod_index_offset_
== -1U)
1814 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1815 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1816 Output_data_got
<size
, big_endian
>* got
;
1817 unsigned int got_offset
;
1819 got
= this->got_section(symtab
, layout
);
1820 got_offset
= got
->add_constant(0);
1821 rela_dyn
->add_local(object
, 0,
1823 elfcpp::R_SPARC_TLS_DTPMOD64
:
1824 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1826 got
->add_constant(0);
1827 this->got_mod_index_offset_
= got_offset
;
1829 return this->got_mod_index_offset_
;
1832 // Optimize the TLS relocation type based on what we know about the
1833 // symbol. IS_FINAL is true if the final address of this symbol is
1834 // known at link time.
1836 static tls::Tls_optimization
1837 optimize_tls_reloc(bool is_final
, int r_type
)
1839 // If we are generating a shared library, then we can't do anything
1841 if (parameters
->options().shared())
1842 return tls::TLSOPT_NONE
;
1846 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1847 case elfcpp::R_SPARC_TLS_GD_LO10
:
1848 case elfcpp::R_SPARC_TLS_GD_ADD
:
1849 case elfcpp::R_SPARC_TLS_GD_CALL
:
1850 // These are General-Dynamic which permits fully general TLS
1851 // access. Since we know that we are generating an executable,
1852 // we can convert this to Initial-Exec. If we also know that
1853 // this is a local symbol, we can further switch to Local-Exec.
1855 return tls::TLSOPT_TO_LE
;
1856 return tls::TLSOPT_TO_IE
;
1858 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1859 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1860 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1861 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1862 // This is Local-Dynamic, which refers to a local symbol in the
1863 // dynamic TLS block. Since we know that we generating an
1864 // executable, we can switch to Local-Exec.
1865 return tls::TLSOPT_TO_LE
;
1867 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1868 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1869 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1870 // Another type of Local-Dynamic relocation.
1871 return tls::TLSOPT_TO_LE
;
1873 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1874 case elfcpp::R_SPARC_TLS_IE_LO10
:
1875 case elfcpp::R_SPARC_TLS_IE_LD
:
1876 case elfcpp::R_SPARC_TLS_IE_LDX
:
1877 case elfcpp::R_SPARC_TLS_IE_ADD
:
1878 // These are Initial-Exec relocs which get the thread offset
1879 // from the GOT. If we know that we are linking against the
1880 // local symbol, we can switch to Local-Exec, which links the
1881 // thread offset into the instruction.
1883 return tls::TLSOPT_TO_LE
;
1884 return tls::TLSOPT_NONE
;
1886 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1887 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1888 // When we already have Local-Exec, there is nothing further we
1890 return tls::TLSOPT_NONE
;
1897 // Get the Reference_flags for a particular relocation.
1899 template<int size
, bool big_endian
>
1901 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1906 case elfcpp::R_SPARC_NONE
:
1907 case elfcpp::R_SPARC_REGISTER
:
1908 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1909 case elfcpp::R_SPARC_GNU_VTENTRY
:
1910 // No symbol reference.
1913 case elfcpp::R_SPARC_UA64
:
1914 case elfcpp::R_SPARC_64
:
1915 case elfcpp::R_SPARC_HIX22
:
1916 case elfcpp::R_SPARC_LOX10
:
1917 case elfcpp::R_SPARC_H34
:
1918 case elfcpp::R_SPARC_H44
:
1919 case elfcpp::R_SPARC_M44
:
1920 case elfcpp::R_SPARC_L44
:
1921 case elfcpp::R_SPARC_HH22
:
1922 case elfcpp::R_SPARC_HM10
:
1923 case elfcpp::R_SPARC_LM22
:
1924 case elfcpp::R_SPARC_HI22
:
1925 case elfcpp::R_SPARC_LO10
:
1926 case elfcpp::R_SPARC_OLO10
:
1927 case elfcpp::R_SPARC_UA32
:
1928 case elfcpp::R_SPARC_32
:
1929 case elfcpp::R_SPARC_UA16
:
1930 case elfcpp::R_SPARC_16
:
1931 case elfcpp::R_SPARC_11
:
1932 case elfcpp::R_SPARC_10
:
1933 case elfcpp::R_SPARC_8
:
1934 case elfcpp::R_SPARC_7
:
1935 case elfcpp::R_SPARC_6
:
1936 case elfcpp::R_SPARC_5
:
1937 return Symbol::ABSOLUTE_REF
;
1939 case elfcpp::R_SPARC_DISP8
:
1940 case elfcpp::R_SPARC_DISP16
:
1941 case elfcpp::R_SPARC_DISP32
:
1942 case elfcpp::R_SPARC_DISP64
:
1943 case elfcpp::R_SPARC_PC_HH22
:
1944 case elfcpp::R_SPARC_PC_HM10
:
1945 case elfcpp::R_SPARC_PC_LM22
:
1946 case elfcpp::R_SPARC_PC10
:
1947 case elfcpp::R_SPARC_PC22
:
1948 case elfcpp::R_SPARC_WDISP30
:
1949 case elfcpp::R_SPARC_WDISP22
:
1950 case elfcpp::R_SPARC_WDISP19
:
1951 case elfcpp::R_SPARC_WDISP16
:
1952 case elfcpp::R_SPARC_WDISP10
:
1953 return Symbol::RELATIVE_REF
;
1955 case elfcpp::R_SPARC_PLT64
:
1956 case elfcpp::R_SPARC_PLT32
:
1957 case elfcpp::R_SPARC_HIPLT22
:
1958 case elfcpp::R_SPARC_LOPLT10
:
1959 case elfcpp::R_SPARC_PCPLT10
:
1960 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
1962 case elfcpp::R_SPARC_PCPLT32
:
1963 case elfcpp::R_SPARC_PCPLT22
:
1964 case elfcpp::R_SPARC_WPLT30
:
1965 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1967 case elfcpp::R_SPARC_GOTDATA_OP
:
1968 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1969 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1970 case elfcpp::R_SPARC_GOT10
:
1971 case elfcpp::R_SPARC_GOT13
:
1972 case elfcpp::R_SPARC_GOT22
:
1974 return Symbol::ABSOLUTE_REF
;
1976 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1977 case elfcpp::R_SPARC_TLS_GD_LO10
:
1978 case elfcpp::R_SPARC_TLS_GD_ADD
:
1979 case elfcpp::R_SPARC_TLS_GD_CALL
:
1980 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1981 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1982 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1983 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1984 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1985 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1986 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1987 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1988 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1989 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1990 case elfcpp::R_SPARC_TLS_IE_LO10
:
1991 case elfcpp::R_SPARC_TLS_IE_LD
:
1992 case elfcpp::R_SPARC_TLS_IE_LDX
:
1993 case elfcpp::R_SPARC_TLS_IE_ADD
:
1994 return Symbol::TLS_REF
;
1996 case elfcpp::R_SPARC_COPY
:
1997 case elfcpp::R_SPARC_GLOB_DAT
:
1998 case elfcpp::R_SPARC_JMP_SLOT
:
1999 case elfcpp::R_SPARC_JMP_IREL
:
2000 case elfcpp::R_SPARC_RELATIVE
:
2001 case elfcpp::R_SPARC_IRELATIVE
:
2002 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2003 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2004 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2005 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2006 case elfcpp::R_SPARC_TLS_TPOFF64
:
2007 case elfcpp::R_SPARC_TLS_TPOFF32
:
2009 // Not expected. We will give an error later.
2014 // Generate a PLT entry slot for a call to __tls_get_addr
2015 template<int size
, bool big_endian
>
2017 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
2019 Target_sparc
<size
, big_endian
>* target
)
2021 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
2023 target
->make_plt_entry(symtab
, layout
, gsym
);
2026 // Report an unsupported relocation against a local symbol.
2028 template<int size
, bool big_endian
>
2030 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
2031 Sized_relobj_file
<size
, big_endian
>* object
,
2032 unsigned int r_type
)
2034 gold_error(_("%s: unsupported reloc %u against local symbol"),
2035 object
->name().c_str(), r_type
);
2038 // We are about to emit a dynamic relocation of type R_TYPE. If the
2039 // dynamic linker does not support it, issue an error.
2041 template<int size
, bool big_endian
>
2043 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
2045 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
2051 // These are the relocation types supported by glibc for sparc 64-bit.
2052 case elfcpp::R_SPARC_RELATIVE
:
2053 case elfcpp::R_SPARC_IRELATIVE
:
2054 case elfcpp::R_SPARC_COPY
:
2055 case elfcpp::R_SPARC_64
:
2056 case elfcpp::R_SPARC_GLOB_DAT
:
2057 case elfcpp::R_SPARC_JMP_SLOT
:
2058 case elfcpp::R_SPARC_JMP_IREL
:
2059 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2060 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2061 case elfcpp::R_SPARC_TLS_TPOFF64
:
2062 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2063 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2064 case elfcpp::R_SPARC_8
:
2065 case elfcpp::R_SPARC_16
:
2066 case elfcpp::R_SPARC_DISP8
:
2067 case elfcpp::R_SPARC_DISP16
:
2068 case elfcpp::R_SPARC_DISP32
:
2069 case elfcpp::R_SPARC_WDISP30
:
2070 case elfcpp::R_SPARC_LO10
:
2071 case elfcpp::R_SPARC_HI22
:
2072 case elfcpp::R_SPARC_OLO10
:
2073 case elfcpp::R_SPARC_H34
:
2074 case elfcpp::R_SPARC_H44
:
2075 case elfcpp::R_SPARC_M44
:
2076 case elfcpp::R_SPARC_L44
:
2077 case elfcpp::R_SPARC_HH22
:
2078 case elfcpp::R_SPARC_HM10
:
2079 case elfcpp::R_SPARC_LM22
:
2080 case elfcpp::R_SPARC_UA16
:
2081 case elfcpp::R_SPARC_UA32
:
2082 case elfcpp::R_SPARC_UA64
:
2093 // These are the relocation types supported by glibc for sparc 32-bit.
2094 case elfcpp::R_SPARC_RELATIVE
:
2095 case elfcpp::R_SPARC_IRELATIVE
:
2096 case elfcpp::R_SPARC_COPY
:
2097 case elfcpp::R_SPARC_GLOB_DAT
:
2098 case elfcpp::R_SPARC_32
:
2099 case elfcpp::R_SPARC_JMP_SLOT
:
2100 case elfcpp::R_SPARC_JMP_IREL
:
2101 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2102 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2103 case elfcpp::R_SPARC_TLS_TPOFF32
:
2104 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2105 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2106 case elfcpp::R_SPARC_8
:
2107 case elfcpp::R_SPARC_16
:
2108 case elfcpp::R_SPARC_DISP8
:
2109 case elfcpp::R_SPARC_DISP16
:
2110 case elfcpp::R_SPARC_DISP32
:
2111 case elfcpp::R_SPARC_LO10
:
2112 case elfcpp::R_SPARC_WDISP30
:
2113 case elfcpp::R_SPARC_HI22
:
2114 case elfcpp::R_SPARC_UA16
:
2115 case elfcpp::R_SPARC_UA32
:
2123 // This prevents us from issuing more than one error per reloc
2124 // section. But we can still wind up issuing more than one
2125 // error per object file.
2126 if (this->issued_non_pic_error_
)
2128 gold_assert(parameters
->options().output_is_position_independent());
2129 object
->error(_("requires unsupported dynamic reloc; "
2130 "recompile with -fPIC"));
2131 this->issued_non_pic_error_
= true;
2135 // Return whether we need to make a PLT entry for a relocation of the
2136 // given type against a STT_GNU_IFUNC symbol.
2138 template<int size
, bool big_endian
>
2140 Target_sparc
<size
, big_endian
>::Scan::reloc_needs_plt_for_ifunc(
2141 Sized_relobj_file
<size
, big_endian
>* object
,
2142 unsigned int r_type
)
2144 int flags
= Scan::get_reference_flags(r_type
);
2145 if (flags
& Symbol::TLS_REF
)
2146 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
2147 object
->name().c_str(), r_type
);
2151 // Scan a relocation for a local symbol.
2153 template<int size
, bool big_endian
>
2155 Target_sparc
<size
, big_endian
>::Scan::local(
2156 Symbol_table
* symtab
,
2158 Target_sparc
<size
, big_endian
>* target
,
2159 Sized_relobj_file
<size
, big_endian
>* object
,
2160 unsigned int data_shndx
,
2161 Output_section
* output_section
,
2162 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2163 unsigned int r_type
,
2164 const elfcpp::Sym
<size
, big_endian
>& lsym
)
2166 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
2167 unsigned int orig_r_type
= r_type
;
2171 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2173 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2174 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
2179 case elfcpp::R_SPARC_NONE
:
2180 case elfcpp::R_SPARC_REGISTER
:
2181 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2182 case elfcpp::R_SPARC_GNU_VTENTRY
:
2185 case elfcpp::R_SPARC_64
:
2186 case elfcpp::R_SPARC_32
:
2187 // If building a shared library (or a position-independent
2188 // executable), we need to create a dynamic relocation for
2189 // this location. The relocation applied at link time will
2190 // apply the link-time value, so we flag the location with
2191 // an R_SPARC_RELATIVE relocation so the dynamic loader can
2192 // relocate it easily.
2193 if (parameters
->options().output_is_position_independent())
2195 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2196 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2197 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
2198 output_section
, data_shndx
,
2199 reloc
.get_r_offset(),
2200 reloc
.get_r_addend(), is_ifunc
);
2204 case elfcpp::R_SPARC_HIX22
:
2205 case elfcpp::R_SPARC_LOX10
:
2206 case elfcpp::R_SPARC_H34
:
2207 case elfcpp::R_SPARC_H44
:
2208 case elfcpp::R_SPARC_M44
:
2209 case elfcpp::R_SPARC_L44
:
2210 case elfcpp::R_SPARC_HH22
:
2211 case elfcpp::R_SPARC_HM10
:
2212 case elfcpp::R_SPARC_LM22
:
2213 case elfcpp::R_SPARC_UA64
:
2214 case elfcpp::R_SPARC_UA32
:
2215 case elfcpp::R_SPARC_UA16
:
2216 case elfcpp::R_SPARC_HI22
:
2217 case elfcpp::R_SPARC_LO10
:
2218 case elfcpp::R_SPARC_OLO10
:
2219 case elfcpp::R_SPARC_16
:
2220 case elfcpp::R_SPARC_11
:
2221 case elfcpp::R_SPARC_10
:
2222 case elfcpp::R_SPARC_8
:
2223 case elfcpp::R_SPARC_7
:
2224 case elfcpp::R_SPARC_6
:
2225 case elfcpp::R_SPARC_5
:
2226 // If building a shared library (or a position-independent
2227 // executable), we need to create a dynamic relocation for
2229 if (parameters
->options().output_is_position_independent())
2231 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2232 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2234 check_non_pic(object
, r_type
);
2235 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
2237 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
2238 data_shndx
, reloc
.get_r_offset(),
2239 reloc
.get_r_addend());
2243 gold_assert(lsym
.get_st_value() == 0);
2244 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
2245 output_section
, data_shndx
,
2246 reloc
.get_r_offset(),
2247 reloc
.get_r_addend());
2252 case elfcpp::R_SPARC_WDISP30
:
2253 case elfcpp::R_SPARC_WPLT30
:
2254 case elfcpp::R_SPARC_WDISP22
:
2255 case elfcpp::R_SPARC_WDISP19
:
2256 case elfcpp::R_SPARC_WDISP16
:
2257 case elfcpp::R_SPARC_WDISP10
:
2258 case elfcpp::R_SPARC_DISP8
:
2259 case elfcpp::R_SPARC_DISP16
:
2260 case elfcpp::R_SPARC_DISP32
:
2261 case elfcpp::R_SPARC_DISP64
:
2262 case elfcpp::R_SPARC_PC10
:
2263 case elfcpp::R_SPARC_PC22
:
2266 case elfcpp::R_SPARC_GOTDATA_OP
:
2267 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2268 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2269 case elfcpp::R_SPARC_GOT10
:
2270 case elfcpp::R_SPARC_GOT13
:
2271 case elfcpp::R_SPARC_GOT22
:
2273 // The symbol requires a GOT entry.
2274 Output_data_got
<size
, big_endian
>* got
;
2277 got
= target
->got_section(symtab
, layout
);
2278 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2280 // If we are generating a shared object, we need to add a
2281 // dynamic relocation for this symbol's GOT entry.
2282 if (parameters
->options().output_is_position_independent())
2284 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
2286 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2287 unsigned int off
= got
->add_constant(0);
2288 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
2289 rela_dyn
->add_local_relative(object
, r_sym
,
2290 elfcpp::R_SPARC_RELATIVE
,
2291 got
, off
, 0, is_ifunc
);
2295 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
2299 // These are initial TLS relocs, which are expected when
2301 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2302 case elfcpp::R_SPARC_TLS_GD_LO10
:
2303 case elfcpp::R_SPARC_TLS_GD_ADD
:
2304 case elfcpp::R_SPARC_TLS_GD_CALL
:
2305 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2306 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2307 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2308 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2309 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2310 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2311 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2312 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2313 case elfcpp::R_SPARC_TLS_IE_LO10
:
2314 case elfcpp::R_SPARC_TLS_IE_LD
:
2315 case elfcpp::R_SPARC_TLS_IE_LDX
:
2316 case elfcpp::R_SPARC_TLS_IE_ADD
:
2317 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2318 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2320 bool output_is_shared
= parameters
->options().shared();
2321 const tls::Tls_optimization optimized_type
2322 = optimize_tls_reloc(!output_is_shared
, r_type
);
2325 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2326 case elfcpp::R_SPARC_TLS_GD_LO10
:
2327 case elfcpp::R_SPARC_TLS_GD_ADD
:
2328 case elfcpp::R_SPARC_TLS_GD_CALL
:
2329 if (optimized_type
== tls::TLSOPT_NONE
)
2331 // Create a pair of GOT entries for the module index and
2332 // dtv-relative offset.
2333 Output_data_got
<size
, big_endian
>* got
2334 = target
->got_section(symtab
, layout
);
2335 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2336 unsigned int shndx
= lsym
.get_st_shndx();
2338 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
2340 object
->error(_("local symbol %u has bad shndx %u"),
2343 got
->add_local_pair_with_rel(object
, r_sym
,
2344 lsym
.get_st_shndx(),
2346 target
->rela_dyn_section(layout
),
2348 ? elfcpp::R_SPARC_TLS_DTPMOD64
2349 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2351 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2352 generate_tls_call(symtab
, layout
, target
);
2354 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2355 unsupported_reloc_local(object
, r_type
);
2358 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2359 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2360 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2361 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2362 if (optimized_type
== tls::TLSOPT_NONE
)
2364 // Create a GOT entry for the module index.
2365 target
->got_mod_index_entry(symtab
, layout
, object
);
2367 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2368 generate_tls_call(symtab
, layout
, target
);
2370 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2371 unsupported_reloc_local(object
, r_type
);
2374 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2375 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2376 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2379 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2380 case elfcpp::R_SPARC_TLS_IE_LO10
:
2381 case elfcpp::R_SPARC_TLS_IE_LD
:
2382 case elfcpp::R_SPARC_TLS_IE_LDX
:
2383 case elfcpp::R_SPARC_TLS_IE_ADD
:
2384 layout
->set_has_static_tls();
2385 if (optimized_type
== tls::TLSOPT_NONE
)
2387 // Create a GOT entry for the tp-relative offset.
2388 Output_data_got
<size
, big_endian
>* got
2389 = target
->got_section(symtab
, layout
);
2390 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2392 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2394 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2395 unsigned int off
= got
->add_constant(0);
2397 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2399 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2401 elfcpp::R_SPARC_TLS_TPOFF64
:
2402 elfcpp::R_SPARC_TLS_TPOFF32
),
2406 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2407 unsupported_reloc_local(object
, r_type
);
2410 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2411 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2412 layout
->set_has_static_tls();
2413 if (output_is_shared
)
2415 // We need to create a dynamic relocation.
2416 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2417 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2418 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2419 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2420 output_section
, data_shndx
,
2421 reloc
.get_r_offset(), 0);
2428 // These are relocations which should only be seen by the
2429 // dynamic linker, and should never be seen here.
2430 case elfcpp::R_SPARC_COPY
:
2431 case elfcpp::R_SPARC_GLOB_DAT
:
2432 case elfcpp::R_SPARC_JMP_SLOT
:
2433 case elfcpp::R_SPARC_JMP_IREL
:
2434 case elfcpp::R_SPARC_RELATIVE
:
2435 case elfcpp::R_SPARC_IRELATIVE
:
2436 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2437 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2438 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2439 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2440 case elfcpp::R_SPARC_TLS_TPOFF64
:
2441 case elfcpp::R_SPARC_TLS_TPOFF32
:
2442 gold_error(_("%s: unexpected reloc %u in object file"),
2443 object
->name().c_str(), r_type
);
2447 unsupported_reloc_local(object
, r_type
);
2452 // Report an unsupported relocation against a global symbol.
2454 template<int size
, bool big_endian
>
2456 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2457 Sized_relobj_file
<size
, big_endian
>* object
,
2458 unsigned int r_type
,
2461 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2462 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2465 // Scan a relocation for a global symbol.
2467 template<int size
, bool big_endian
>
2469 Target_sparc
<size
, big_endian
>::Scan::global(
2470 Symbol_table
* symtab
,
2472 Target_sparc
<size
, big_endian
>* target
,
2473 Sized_relobj_file
<size
, big_endian
>* object
,
2474 unsigned int data_shndx
,
2475 Output_section
* output_section
,
2476 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2477 unsigned int r_type
,
2480 unsigned int orig_r_type
= r_type
;
2481 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2483 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2484 // section. We check here to avoid creating a dynamic reloc against
2485 // _GLOBAL_OFFSET_TABLE_.
2486 if (!target
->has_got_section()
2487 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2488 target
->got_section(symtab
, layout
);
2492 // A STT_GNU_IFUNC symbol may require a PLT entry.
2494 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
2495 target
->make_plt_entry(symtab
, layout
, gsym
);
2499 case elfcpp::R_SPARC_NONE
:
2500 case elfcpp::R_SPARC_REGISTER
:
2501 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2502 case elfcpp::R_SPARC_GNU_VTENTRY
:
2505 case elfcpp::R_SPARC_PLT64
:
2506 case elfcpp::R_SPARC_PLT32
:
2507 case elfcpp::R_SPARC_HIPLT22
:
2508 case elfcpp::R_SPARC_LOPLT10
:
2509 case elfcpp::R_SPARC_PCPLT32
:
2510 case elfcpp::R_SPARC_PCPLT22
:
2511 case elfcpp::R_SPARC_PCPLT10
:
2512 case elfcpp::R_SPARC_WPLT30
:
2513 // If the symbol is fully resolved, this is just a PC32 reloc.
2514 // Otherwise we need a PLT entry.
2515 if (gsym
->final_value_is_known())
2517 // If building a shared library, we can also skip the PLT entry
2518 // if the symbol is defined in the output file and is protected
2520 if (gsym
->is_defined()
2521 && !gsym
->is_from_dynobj()
2522 && !gsym
->is_preemptible())
2524 target
->make_plt_entry(symtab
, layout
, gsym
);
2527 case elfcpp::R_SPARC_DISP8
:
2528 case elfcpp::R_SPARC_DISP16
:
2529 case elfcpp::R_SPARC_DISP32
:
2530 case elfcpp::R_SPARC_DISP64
:
2531 case elfcpp::R_SPARC_PC_HH22
:
2532 case elfcpp::R_SPARC_PC_HM10
:
2533 case elfcpp::R_SPARC_PC_LM22
:
2534 case elfcpp::R_SPARC_PC10
:
2535 case elfcpp::R_SPARC_PC22
:
2536 case elfcpp::R_SPARC_WDISP30
:
2537 case elfcpp::R_SPARC_WDISP22
:
2538 case elfcpp::R_SPARC_WDISP19
:
2539 case elfcpp::R_SPARC_WDISP16
:
2540 case elfcpp::R_SPARC_WDISP10
:
2542 if (gsym
->needs_plt_entry())
2543 target
->make_plt_entry(symtab
, layout
, gsym
);
2544 // Make a dynamic relocation if necessary.
2545 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2547 if (gsym
->may_need_copy_reloc())
2549 target
->copy_reloc(symtab
, layout
, object
,
2550 data_shndx
, output_section
, gsym
,
2555 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2556 check_non_pic(object
, r_type
);
2557 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2558 data_shndx
, reloc
.get_r_offset(),
2559 reloc
.get_r_addend());
2565 case elfcpp::R_SPARC_UA64
:
2566 case elfcpp::R_SPARC_64
:
2567 case elfcpp::R_SPARC_HIX22
:
2568 case elfcpp::R_SPARC_LOX10
:
2569 case elfcpp::R_SPARC_H34
:
2570 case elfcpp::R_SPARC_H44
:
2571 case elfcpp::R_SPARC_M44
:
2572 case elfcpp::R_SPARC_L44
:
2573 case elfcpp::R_SPARC_HH22
:
2574 case elfcpp::R_SPARC_HM10
:
2575 case elfcpp::R_SPARC_LM22
:
2576 case elfcpp::R_SPARC_HI22
:
2577 case elfcpp::R_SPARC_LO10
:
2578 case elfcpp::R_SPARC_OLO10
:
2579 case elfcpp::R_SPARC_UA32
:
2580 case elfcpp::R_SPARC_32
:
2581 case elfcpp::R_SPARC_UA16
:
2582 case elfcpp::R_SPARC_16
:
2583 case elfcpp::R_SPARC_11
:
2584 case elfcpp::R_SPARC_10
:
2585 case elfcpp::R_SPARC_8
:
2586 case elfcpp::R_SPARC_7
:
2587 case elfcpp::R_SPARC_6
:
2588 case elfcpp::R_SPARC_5
:
2590 // Make a PLT entry if necessary.
2591 if (gsym
->needs_plt_entry())
2593 target
->make_plt_entry(symtab
, layout
, gsym
);
2594 // Since this is not a PC-relative relocation, we may be
2595 // taking the address of a function. In that case we need to
2596 // set the entry in the dynamic symbol table to the address of
2598 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2599 gsym
->set_needs_dynsym_value();
2601 // Make a dynamic relocation if necessary.
2602 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2604 unsigned int r_off
= reloc
.get_r_offset();
2606 // The assembler can sometimes emit unaligned relocations
2607 // for dwarf2 cfi directives.
2610 case elfcpp::R_SPARC_16
:
2612 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2614 case elfcpp::R_SPARC_32
:
2616 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2618 case elfcpp::R_SPARC_64
:
2620 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2622 case elfcpp::R_SPARC_UA16
:
2624 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2626 case elfcpp::R_SPARC_UA32
:
2628 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2630 case elfcpp::R_SPARC_UA64
:
2632 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2636 if (gsym
->may_need_copy_reloc())
2638 target
->copy_reloc(symtab
, layout
, object
,
2639 data_shndx
, output_section
, gsym
, reloc
);
2641 else if (((size
== 64 && r_type
== elfcpp::R_SPARC_64
)
2642 || (size
== 32 && r_type
== elfcpp::R_SPARC_32
))
2643 && gsym
->type() == elfcpp::STT_GNU_IFUNC
2644 && gsym
->can_use_relative_reloc(false)
2645 && !gsym
->is_from_dynobj()
2646 && !gsym
->is_undefined()
2647 && !gsym
->is_preemptible())
2649 // Use an IRELATIVE reloc for a locally defined
2650 // STT_GNU_IFUNC symbol. This makes a function
2651 // address in a PIE executable match the address in a
2652 // shared library that it links against.
2653 Reloc_section
* rela_dyn
=
2654 target
->rela_ifunc_section(layout
);
2655 unsigned int r_type
= elfcpp::R_SPARC_IRELATIVE
;
2656 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
2657 output_section
, object
,
2659 reloc
.get_r_offset(),
2660 reloc
.get_r_addend());
2662 else if ((r_type
== elfcpp::R_SPARC_32
2663 || r_type
== elfcpp::R_SPARC_64
)
2664 && gsym
->can_use_relative_reloc(false))
2666 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2667 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2668 output_section
, object
,
2669 data_shndx
, reloc
.get_r_offset(),
2670 reloc
.get_r_addend(), is_ifunc
);
2674 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2676 check_non_pic(object
, r_type
);
2677 if (gsym
->is_from_dynobj()
2678 || gsym
->is_undefined()
2679 || gsym
->is_preemptible())
2680 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2682 reloc
.get_r_offset(),
2683 reloc
.get_r_addend());
2685 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2688 reloc
.get_r_offset(),
2689 reloc
.get_r_addend());
2695 case elfcpp::R_SPARC_GOTDATA_OP
:
2696 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2697 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2698 case elfcpp::R_SPARC_GOT10
:
2699 case elfcpp::R_SPARC_GOT13
:
2700 case elfcpp::R_SPARC_GOT22
:
2702 // The symbol requires a GOT entry.
2703 Output_data_got
<size
, big_endian
>* got
;
2705 got
= target
->got_section(symtab
, layout
);
2706 if (gsym
->final_value_is_known())
2708 // For a STT_GNU_IFUNC symbol we want the PLT address.
2709 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2710 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
2712 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2716 // If this symbol is not fully resolved, we need to add a
2717 // GOT entry with a dynamic relocation.
2718 bool is_ifunc
= gsym
->type() == elfcpp::STT_GNU_IFUNC
;
2720 // Use a GLOB_DAT rather than a RELATIVE reloc if:
2722 // 1) The symbol may be defined in some other module.
2724 // 2) We are building a shared library and this is a
2725 // protected symbol; using GLOB_DAT means that the dynamic
2726 // linker can use the address of the PLT in the main
2727 // executable when appropriate so that function address
2728 // comparisons work.
2730 // 3) This is a STT_GNU_IFUNC symbol in position dependent
2731 // code, again so that function address comparisons work.
2732 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2733 if (gsym
->is_from_dynobj()
2734 || gsym
->is_undefined()
2735 || gsym
->is_preemptible()
2736 || (gsym
->visibility() == elfcpp::STV_PROTECTED
2737 && parameters
->options().shared())
2738 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
2739 && parameters
->options().output_is_position_independent()
2740 && !gsym
->is_forced_local()))
2742 unsigned int r_type
= elfcpp::R_SPARC_GLOB_DAT
;
2744 // If this symbol is forced local, this relocation will
2745 // not work properly. That's because ld.so on sparc
2746 // (and 32-bit powerpc) expects st_value in the r_addend
2747 // of relocations for STB_LOCAL symbols. Curiously the
2748 // BFD linker does not promote global hidden symbols to be
2749 // STB_LOCAL in the dynamic symbol table like Gold does.
2750 gold_assert(!gsym
->is_forced_local());
2751 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2754 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2756 unsigned int off
= got
->add_constant(0);
2758 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2761 // Tell the dynamic linker to use the PLT address
2762 // when resolving relocations.
2763 if (gsym
->is_from_dynobj()
2764 && !parameters
->options().shared())
2765 gsym
->set_needs_dynsym_value();
2767 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2768 got
, off
, 0, is_ifunc
);
2774 // These are initial tls relocs, which are expected when
2776 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2777 case elfcpp::R_SPARC_TLS_GD_LO10
:
2778 case elfcpp::R_SPARC_TLS_GD_ADD
:
2779 case elfcpp::R_SPARC_TLS_GD_CALL
:
2780 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2781 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2782 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2783 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2784 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2785 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2786 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2787 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2788 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2789 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2790 case elfcpp::R_SPARC_TLS_IE_LO10
:
2791 case elfcpp::R_SPARC_TLS_IE_LD
:
2792 case elfcpp::R_SPARC_TLS_IE_LDX
:
2793 case elfcpp::R_SPARC_TLS_IE_ADD
:
2795 const bool is_final
= gsym
->final_value_is_known();
2796 const tls::Tls_optimization optimized_type
2797 = optimize_tls_reloc(is_final
, r_type
);
2800 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2801 case elfcpp::R_SPARC_TLS_GD_LO10
:
2802 case elfcpp::R_SPARC_TLS_GD_ADD
:
2803 case elfcpp::R_SPARC_TLS_GD_CALL
:
2804 if (optimized_type
== tls::TLSOPT_NONE
)
2806 // Create a pair of GOT entries for the module index and
2807 // dtv-relative offset.
2808 Output_data_got
<size
, big_endian
>* got
2809 = target
->got_section(symtab
, layout
);
2810 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
2811 target
->rela_dyn_section(layout
),
2813 ? elfcpp::R_SPARC_TLS_DTPMOD64
2814 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2816 ? elfcpp::R_SPARC_TLS_DTPOFF64
2817 : elfcpp::R_SPARC_TLS_DTPOFF32
));
2819 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2820 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2821 generate_tls_call(symtab
, layout
, target
);
2823 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2825 // Create a GOT entry for the tp-relative offset.
2826 Output_data_got
<size
, big_endian
>* got
2827 = target
->got_section(symtab
, layout
);
2828 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2829 target
->rela_dyn_section(layout
),
2831 elfcpp::R_SPARC_TLS_TPOFF64
:
2832 elfcpp::R_SPARC_TLS_TPOFF32
));
2834 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2835 unsupported_reloc_global(object
, r_type
, gsym
);
2838 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2839 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2840 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2841 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2842 if (optimized_type
== tls::TLSOPT_NONE
)
2844 // Create a GOT entry for the module index.
2845 target
->got_mod_index_entry(symtab
, layout
, object
);
2847 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2848 generate_tls_call(symtab
, layout
, target
);
2850 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2851 unsupported_reloc_global(object
, r_type
, gsym
);
2854 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2855 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2856 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2859 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2860 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2861 layout
->set_has_static_tls();
2862 if (parameters
->options().shared())
2864 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2865 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2866 output_section
, object
,
2867 data_shndx
, reloc
.get_r_offset(),
2872 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2873 case elfcpp::R_SPARC_TLS_IE_LO10
:
2874 case elfcpp::R_SPARC_TLS_IE_LD
:
2875 case elfcpp::R_SPARC_TLS_IE_LDX
:
2876 case elfcpp::R_SPARC_TLS_IE_ADD
:
2877 layout
->set_has_static_tls();
2878 if (optimized_type
== tls::TLSOPT_NONE
)
2880 // Create a GOT entry for the tp-relative offset.
2881 Output_data_got
<size
, big_endian
>* got
2882 = target
->got_section(symtab
, layout
);
2883 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
2884 target
->rela_dyn_section(layout
),
2886 ? elfcpp::R_SPARC_TLS_TPOFF64
2887 : elfcpp::R_SPARC_TLS_TPOFF32
));
2889 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2890 unsupported_reloc_global(object
, r_type
, gsym
);
2896 // These are relocations which should only be seen by the
2897 // dynamic linker, and should never be seen here.
2898 case elfcpp::R_SPARC_COPY
:
2899 case elfcpp::R_SPARC_GLOB_DAT
:
2900 case elfcpp::R_SPARC_JMP_SLOT
:
2901 case elfcpp::R_SPARC_JMP_IREL
:
2902 case elfcpp::R_SPARC_RELATIVE
:
2903 case elfcpp::R_SPARC_IRELATIVE
:
2904 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2905 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2906 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2907 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2908 case elfcpp::R_SPARC_TLS_TPOFF64
:
2909 case elfcpp::R_SPARC_TLS_TPOFF32
:
2910 gold_error(_("%s: unexpected reloc %u in object file"),
2911 object
->name().c_str(), r_type
);
2915 unsupported_reloc_global(object
, r_type
, gsym
);
2920 // Process relocations for gc.
2922 template<int size
, bool big_endian
>
2924 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2925 Symbol_table
* symtab
,
2927 Sized_relobj_file
<size
, big_endian
>* object
,
2928 unsigned int data_shndx
,
2930 const unsigned char* prelocs
,
2932 Output_section
* output_section
,
2933 bool needs_special_offset_handling
,
2934 size_t local_symbol_count
,
2935 const unsigned char* plocal_symbols
)
2937 typedef Target_sparc
<size
, big_endian
> Sparc
;
2938 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2940 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
2941 typename
Target_sparc::Relocatable_size_for_reloc
>(
2950 needs_special_offset_handling
,
2955 // Scan relocations for a section.
2957 template<int size
, bool big_endian
>
2959 Target_sparc
<size
, big_endian
>::scan_relocs(
2960 Symbol_table
* symtab
,
2962 Sized_relobj_file
<size
, big_endian
>* object
,
2963 unsigned int data_shndx
,
2964 unsigned int sh_type
,
2965 const unsigned char* prelocs
,
2967 Output_section
* output_section
,
2968 bool needs_special_offset_handling
,
2969 size_t local_symbol_count
,
2970 const unsigned char* plocal_symbols
)
2972 typedef Target_sparc
<size
, big_endian
> Sparc
;
2973 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2975 if (sh_type
== elfcpp::SHT_REL
)
2977 gold_error(_("%s: unsupported REL reloc section"),
2978 object
->name().c_str());
2982 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2991 needs_special_offset_handling
,
2996 // Finalize the sections.
2998 template<int size
, bool big_endian
>
3000 Target_sparc
<size
, big_endian
>::do_finalize_sections(
3002 const Input_objects
*,
3003 Symbol_table
* symtab
)
3006 this->plt_
->emit_pending_ifunc_relocs();
3008 // Fill in some more dynamic tags.
3009 const Reloc_section
* rel_plt
= (this->plt_
== NULL
3011 : this->plt_
->rel_plt());
3012 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
3013 this->rela_dyn_
, true, true);
3015 // Emit any relocs we saved in an attempt to avoid generating COPY
3017 if (this->copy_relocs_
.any_saved_relocs())
3018 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
3020 if (parameters
->doing_static_link()
3021 && (this->plt_
== NULL
|| !this->plt_
->has_ifunc_section()))
3023 // If linking statically, make sure that the __rela_iplt symbols
3024 // were defined if necessary, even if we didn't create a PLT.
3025 static const Define_symbol_in_segment syms
[] =
3028 "__rela_iplt_start", // name
3029 elfcpp::PT_LOAD
, // segment_type
3030 elfcpp::PF_W
, // segment_flags_set
3031 elfcpp::PF(0), // segment_flags_clear
3034 elfcpp::STT_NOTYPE
, // type
3035 elfcpp::STB_GLOBAL
, // binding
3036 elfcpp::STV_HIDDEN
, // visibility
3038 Symbol::SEGMENT_START
, // offset_from_base
3042 "__rela_iplt_end", // name
3043 elfcpp::PT_LOAD
, // segment_type
3044 elfcpp::PF_W
, // segment_flags_set
3045 elfcpp::PF(0), // segment_flags_clear
3048 elfcpp::STT_NOTYPE
, // type
3049 elfcpp::STB_GLOBAL
, // binding
3050 elfcpp::STV_HIDDEN
, // visibility
3052 Symbol::SEGMENT_START
, // offset_from_base
3057 symtab
->define_symbols(layout
, 2, syms
,
3058 layout
->script_options()->saw_sections_clause());
3062 // Perform a relocation.
3064 template<int size
, bool big_endian
>
3066 Target_sparc
<size
, big_endian
>::Relocate::relocate(
3067 const Relocate_info
<size
, big_endian
>* relinfo
,
3068 Target_sparc
* target
,
3071 const elfcpp::Rela
<size
, big_endian
>& rela
,
3072 unsigned int r_type
,
3073 const Sized_symbol
<size
>* gsym
,
3074 const Symbol_value
<size
>* psymval
,
3075 unsigned char* view
,
3076 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3077 section_size_type view_size
)
3081 if (this->ignore_gd_add_
)
3083 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
3084 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3085 _("missing expected TLS relocation"));
3088 this->ignore_gd_add_
= false;
3092 if (this->reloc_adjust_addr_
== view
)
3095 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3096 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3098 // Pick the value to use for symbols defined in shared objects.
3099 Symbol_value
<size
> symval
;
3101 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
3103 elfcpp::Elf_Xword value
;
3105 value
= target
->plt_address_for_global(gsym
) + gsym
->plt_offset();
3107 symval
.set_output_value(value
);
3111 else if (gsym
== NULL
&& psymval
->is_ifunc_symbol())
3113 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3114 if (object
->local_has_plt_offset(r_sym
))
3116 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
)
3117 + object
->local_plt_offset(r_sym
));
3122 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3124 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
3125 // pointer points to the beginning, not the end, of the table.
3126 // So we just use the plain offset.
3127 unsigned int got_offset
= 0;
3130 case elfcpp::R_SPARC_GOTDATA_OP
:
3131 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3132 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3133 case elfcpp::R_SPARC_GOT10
:
3134 case elfcpp::R_SPARC_GOT13
:
3135 case elfcpp::R_SPARC_GOT22
:
3138 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
3139 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3143 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3144 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
3145 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3155 case elfcpp::R_SPARC_NONE
:
3156 case elfcpp::R_SPARC_REGISTER
:
3157 case elfcpp::R_SPARC_GNU_VTINHERIT
:
3158 case elfcpp::R_SPARC_GNU_VTENTRY
:
3161 case elfcpp::R_SPARC_8
:
3162 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
3166 case elfcpp::R_SPARC_16
:
3167 if (rela
.get_r_offset() & 0x1)
3169 // The assembler can sometimes emit unaligned relocations
3170 // for dwarf2 cfi directives.
3171 Reloc::ua16(view
, object
, psymval
, addend
);
3174 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
3178 case elfcpp::R_SPARC_32
:
3179 if (!parameters
->options().output_is_position_independent())
3181 if (rela
.get_r_offset() & 0x3)
3183 // The assembler can sometimes emit unaligned relocations
3184 // for dwarf2 cfi directives.
3185 Reloc::ua32(view
, object
, psymval
, addend
);
3188 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3193 case elfcpp::R_SPARC_DISP8
:
3194 Reloc::disp8(view
, object
, psymval
, addend
, address
);
3197 case elfcpp::R_SPARC_DISP16
:
3198 Reloc::disp16(view
, object
, psymval
, addend
, address
);
3201 case elfcpp::R_SPARC_DISP32
:
3202 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3205 case elfcpp::R_SPARC_DISP64
:
3206 Reloc::disp64(view
, object
, psymval
, addend
, address
);
3209 case elfcpp::R_SPARC_WDISP30
:
3210 case elfcpp::R_SPARC_WPLT30
:
3211 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
3214 case elfcpp::R_SPARC_WDISP22
:
3215 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
3218 case elfcpp::R_SPARC_WDISP19
:
3219 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
3222 case elfcpp::R_SPARC_WDISP16
:
3223 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
3226 case elfcpp::R_SPARC_WDISP10
:
3227 Reloc::wdisp10(view
, object
, psymval
, addend
, address
);
3230 case elfcpp::R_SPARC_HI22
:
3231 Reloc::hi22(view
, object
, psymval
, addend
);
3234 case elfcpp::R_SPARC_22
:
3235 Reloc::rela32_22(view
, object
, psymval
, addend
);
3238 case elfcpp::R_SPARC_13
:
3239 Reloc::rela32_13(view
, object
, psymval
, addend
);
3242 case elfcpp::R_SPARC_LO10
:
3243 Reloc::lo10(view
, object
, psymval
, addend
);
3246 case elfcpp::R_SPARC_GOT10
:
3247 Reloc::lo10(view
, got_offset
, addend
);
3250 case elfcpp::R_SPARC_GOTDATA_OP
:
3253 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
3254 case elfcpp::R_SPARC_GOT13
:
3255 Reloc::rela32_13(view
, got_offset
, addend
);
3258 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
3259 case elfcpp::R_SPARC_GOT22
:
3260 Reloc::hi22(view
, got_offset
, addend
);
3263 case elfcpp::R_SPARC_PC10
:
3264 Reloc::pc10(view
, object
, psymval
, addend
, address
);
3267 case elfcpp::R_SPARC_PC22
:
3268 Reloc::pc22(view
, object
, psymval
, addend
, address
);
3271 case elfcpp::R_SPARC_TLS_DTPOFF32
:
3272 case elfcpp::R_SPARC_UA32
:
3273 Reloc::ua32(view
, object
, psymval
, addend
);
3276 case elfcpp::R_SPARC_PLT64
:
3277 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3281 case elfcpp::R_SPARC_PLT32
:
3282 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
3286 case elfcpp::R_SPARC_HIPLT22
:
3287 Reloc::hi22(view
, object
, psymval
, addend
);
3290 case elfcpp::R_SPARC_LOPLT10
:
3291 Reloc::lo10(view
, object
, psymval
, addend
);
3294 case elfcpp::R_SPARC_PCPLT32
:
3295 Reloc::disp32(view
, object
, psymval
, addend
, address
);
3298 case elfcpp::R_SPARC_PCPLT22
:
3299 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3302 case elfcpp::R_SPARC_PCPLT10
:
3303 Reloc::lo10(view
, object
, psymval
, addend
, address
);
3306 case elfcpp::R_SPARC_64
:
3307 if (!parameters
->options().output_is_position_independent())
3309 if (rela
.get_r_offset() & 0x7)
3311 // The assembler can sometimes emit unaligned relocations
3312 // for dwarf2 cfi directives.
3313 Reloc::ua64(view
, object
, psymval
, addend
);
3316 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
3321 case elfcpp::R_SPARC_OLO10
:
3323 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
3324 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
3325 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
3329 case elfcpp::R_SPARC_HH22
:
3330 Reloc::hh22(view
, object
, psymval
, addend
);
3333 case elfcpp::R_SPARC_PC_HH22
:
3334 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
3337 case elfcpp::R_SPARC_HM10
:
3338 Reloc::hm10(view
, object
, psymval
, addend
);
3341 case elfcpp::R_SPARC_PC_HM10
:
3342 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
3345 case elfcpp::R_SPARC_LM22
:
3346 Reloc::hi22(view
, object
, psymval
, addend
);
3349 case elfcpp::R_SPARC_PC_LM22
:
3350 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
3353 case elfcpp::R_SPARC_11
:
3354 Reloc::rela32_11(view
, object
, psymval
, addend
);
3357 case elfcpp::R_SPARC_10
:
3358 Reloc::rela32_10(view
, object
, psymval
, addend
);
3361 case elfcpp::R_SPARC_7
:
3362 Reloc::rela32_7(view
, object
, psymval
, addend
);
3365 case elfcpp::R_SPARC_6
:
3366 Reloc::rela32_6(view
, object
, psymval
, addend
);
3369 case elfcpp::R_SPARC_5
:
3370 Reloc::rela32_5(view
, object
, psymval
, addend
);
3373 case elfcpp::R_SPARC_HIX22
:
3374 Reloc::hix22(view
, object
, psymval
, addend
);
3377 case elfcpp::R_SPARC_LOX10
:
3378 Reloc::lox10(view
, object
, psymval
, addend
);
3381 case elfcpp::R_SPARC_H34
:
3382 Reloc::h34(view
, object
, psymval
, addend
);
3385 case elfcpp::R_SPARC_H44
:
3386 Reloc::h44(view
, object
, psymval
, addend
);
3389 case elfcpp::R_SPARC_M44
:
3390 Reloc::m44(view
, object
, psymval
, addend
);
3393 case elfcpp::R_SPARC_L44
:
3394 Reloc::l44(view
, object
, psymval
, addend
);
3397 case elfcpp::R_SPARC_TLS_DTPOFF64
:
3398 case elfcpp::R_SPARC_UA64
:
3399 Reloc::ua64(view
, object
, psymval
, addend
);
3402 case elfcpp::R_SPARC_UA16
:
3403 Reloc::ua16(view
, object
, psymval
, addend
);
3406 case elfcpp::R_SPARC_TLS_GD_HI22
:
3407 case elfcpp::R_SPARC_TLS_GD_LO10
:
3408 case elfcpp::R_SPARC_TLS_GD_ADD
:
3409 case elfcpp::R_SPARC_TLS_GD_CALL
:
3410 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3411 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3412 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3413 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3414 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3415 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3416 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3417 case elfcpp::R_SPARC_TLS_IE_HI22
:
3418 case elfcpp::R_SPARC_TLS_IE_LO10
:
3419 case elfcpp::R_SPARC_TLS_IE_LD
:
3420 case elfcpp::R_SPARC_TLS_IE_LDX
:
3421 case elfcpp::R_SPARC_TLS_IE_ADD
:
3422 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3423 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3424 this->relocate_tls(relinfo
, target
, relnum
, rela
,
3425 r_type
, gsym
, psymval
, view
,
3426 address
, view_size
);
3429 case elfcpp::R_SPARC_COPY
:
3430 case elfcpp::R_SPARC_GLOB_DAT
:
3431 case elfcpp::R_SPARC_JMP_SLOT
:
3432 case elfcpp::R_SPARC_JMP_IREL
:
3433 case elfcpp::R_SPARC_RELATIVE
:
3434 case elfcpp::R_SPARC_IRELATIVE
:
3435 // These are outstanding tls relocs, which are unexpected when
3437 case elfcpp::R_SPARC_TLS_DTPMOD64
:
3438 case elfcpp::R_SPARC_TLS_DTPMOD32
:
3439 case elfcpp::R_SPARC_TLS_TPOFF64
:
3440 case elfcpp::R_SPARC_TLS_TPOFF32
:
3441 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3442 _("unexpected reloc %u in object file"),
3447 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3448 _("unsupported reloc %u"),
3456 // Perform a TLS relocation.
3458 template<int size
, bool big_endian
>
3460 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
3461 const Relocate_info
<size
, big_endian
>* relinfo
,
3462 Target_sparc
<size
, big_endian
>* target
,
3464 const elfcpp::Rela
<size
, big_endian
>& rela
,
3465 unsigned int r_type
,
3466 const Sized_symbol
<size
>* gsym
,
3467 const Symbol_value
<size
>* psymval
,
3468 unsigned char* view
,
3469 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3472 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
3473 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
3474 const Sized_relobj_file
<size
, big_endian
>* object
= relinfo
->object
;
3475 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
3477 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
3478 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
3480 const bool is_final
=
3482 ? !parameters
->options().output_is_position_independent()
3483 : gsym
->final_value_is_known());
3484 const tls::Tls_optimization optimized_type
3485 = optimize_tls_reloc(is_final
, r_type
);
3489 case elfcpp::R_SPARC_TLS_GD_HI22
:
3490 case elfcpp::R_SPARC_TLS_GD_LO10
:
3491 case elfcpp::R_SPARC_TLS_GD_ADD
:
3492 case elfcpp::R_SPARC_TLS_GD_CALL
:
3493 if (optimized_type
== tls::TLSOPT_TO_LE
)
3495 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3498 value
-= tls_segment
->memsz();
3502 case elfcpp::R_SPARC_TLS_GD_HI22
:
3503 // TLS_GD_HI22 --> TLS_LE_HIX22
3504 Reloc::hix22(view
, value
, addend
);
3507 case elfcpp::R_SPARC_TLS_GD_LO10
:
3508 // TLS_GD_LO10 --> TLS_LE_LOX10
3509 Reloc::lox10(view
, value
, addend
);
3512 case elfcpp::R_SPARC_TLS_GD_ADD
:
3513 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3514 val
= elfcpp::Swap
<32, true>::readval(wv
);
3515 val
= (val
& ~0x7c000) | 0x1c000;
3516 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3518 case elfcpp::R_SPARC_TLS_GD_CALL
:
3519 // call __tls_get_addr --> nop
3520 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3527 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3528 ? GOT_TYPE_TLS_OFFSET
3529 : GOT_TYPE_TLS_PAIR
);
3532 gold_assert(gsym
->has_got_offset(got_type
));
3533 value
= gsym
->got_offset(got_type
);
3537 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3538 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3539 value
= object
->local_got_offset(r_sym
, got_type
);
3541 if (optimized_type
== tls::TLSOPT_TO_IE
)
3543 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3548 case elfcpp::R_SPARC_TLS_GD_HI22
:
3549 // TLS_GD_HI22 --> TLS_IE_HI22
3550 Reloc::hi22(view
, value
, addend
);
3553 case elfcpp::R_SPARC_TLS_GD_LO10
:
3554 // TLS_GD_LO10 --> TLS_IE_LO10
3555 Reloc::lo10(view
, value
, addend
);
3558 case elfcpp::R_SPARC_TLS_GD_ADD
:
3559 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3560 val
= elfcpp::Swap
<32, true>::readval(wv
);
3567 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3570 case elfcpp::R_SPARC_TLS_GD_CALL
:
3571 // The compiler can put the TLS_GD_ADD instruction
3572 // into the delay slot of the call. If so, we need
3573 // to transpose the two instructions so that the
3574 // new sequence works properly.
3576 // The test we use is if the instruction in the
3577 // delay slot is an add with destination register
3579 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3580 if ((val
& 0x81f80000) == 0x80000000
3581 && ((val
>> 25) & 0x1f) == 0x8)
3588 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3591 this->ignore_gd_add_
= true;
3595 // Even if the delay slot isn't the TLS_GD_ADD
3596 // instruction, we still have to handle the case
3597 // where it sets up %o0 in some other way.
3598 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3600 this->reloc_adjust_addr_
= view
+ 4;
3602 // call __tls_get_addr --> add %g7, %o0, %o0
3603 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3608 else if (optimized_type
== tls::TLSOPT_NONE
)
3612 case elfcpp::R_SPARC_TLS_GD_HI22
:
3613 Reloc::hi22(view
, value
, addend
);
3615 case elfcpp::R_SPARC_TLS_GD_LO10
:
3616 Reloc::lo10(view
, value
, addend
);
3618 case elfcpp::R_SPARC_TLS_GD_ADD
:
3620 case elfcpp::R_SPARC_TLS_GD_CALL
:
3622 Symbol_value
<size
> symval
;
3623 elfcpp::Elf_Xword value
;
3626 tsym
= target
->tls_get_addr_sym_
;
3628 value
= (target
->plt_section()->address() +
3629 tsym
->plt_offset());
3630 symval
.set_output_value(value
);
3631 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3638 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3639 _("unsupported reloc %u"),
3643 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3644 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3645 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3646 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3647 if (optimized_type
== tls::TLSOPT_TO_LE
)
3649 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3653 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3654 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3655 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3656 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3659 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3660 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3665 else if (optimized_type
== tls::TLSOPT_NONE
)
3667 // Relocate the field with the offset of the GOT entry for
3668 // the module index.
3669 unsigned int got_offset
;
3671 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3674 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3675 Reloc::hi22(view
, got_offset
, addend
);
3677 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3678 Reloc::lo10(view
, got_offset
, addend
);
3680 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3682 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3684 Symbol_value
<size
> symval
;
3685 elfcpp::Elf_Xword value
;
3688 tsym
= target
->tls_get_addr_sym_
;
3690 value
= (target
->plt_section()->address() +
3691 tsym
->plt_offset());
3692 symval
.set_output_value(value
);
3693 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3699 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3700 _("unsupported reloc %u"),
3704 // These relocs can appear in debugging sections, in which case
3705 // we won't see the TLS_LDM relocs. The local_dynamic_type
3706 // field tells us this.
3707 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3708 if (optimized_type
== tls::TLSOPT_TO_LE
)
3710 value
-= tls_segment
->memsz();
3711 Reloc::hix22(view
, value
, addend
);
3714 Reloc::ldo_hix22(view
, value
, addend
);
3716 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3717 if (optimized_type
== tls::TLSOPT_TO_LE
)
3719 value
-= tls_segment
->memsz();
3720 Reloc::lox10(view
, value
, addend
);
3723 Reloc::ldo_lox10(view
, value
, addend
);
3725 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3726 if (optimized_type
== tls::TLSOPT_TO_LE
)
3728 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3731 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3732 val
= elfcpp::Swap
<32, true>::readval(wv
);
3733 val
= (val
& ~0x7c000) | 0x1c000;
3734 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3738 // When optimizing IE --> LE, the only relocation that is handled
3739 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3740 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3741 // rs2 and rd are the same.
3742 case elfcpp::R_SPARC_TLS_IE_LD
:
3743 case elfcpp::R_SPARC_TLS_IE_LDX
:
3744 if (optimized_type
== tls::TLSOPT_TO_LE
)
3746 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3747 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3748 Insntype rs2
= val
& 0x1f;
3749 Insntype rd
= (val
>> 25) & 0x1f;
3754 val
= sparc_mov
| (val
& 0x3e00001f);
3756 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3760 case elfcpp::R_SPARC_TLS_IE_HI22
:
3761 case elfcpp::R_SPARC_TLS_IE_LO10
:
3762 if (optimized_type
== tls::TLSOPT_TO_LE
)
3764 value
-= tls_segment
->memsz();
3767 case elfcpp::R_SPARC_TLS_IE_HI22
:
3768 // IE_HI22 --> LE_HIX22
3769 Reloc::hix22(view
, value
, addend
);
3771 case elfcpp::R_SPARC_TLS_IE_LO10
:
3772 // IE_LO10 --> LE_LOX10
3773 Reloc::lox10(view
, value
, addend
);
3778 else if (optimized_type
== tls::TLSOPT_NONE
)
3780 // Relocate the field with the offset of the GOT entry for
3781 // the tp-relative offset of the symbol.
3784 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3785 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3789 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3790 gold_assert(object
->local_has_got_offset(r_sym
,
3791 GOT_TYPE_TLS_OFFSET
));
3792 value
= object
->local_got_offset(r_sym
,
3793 GOT_TYPE_TLS_OFFSET
);
3797 case elfcpp::R_SPARC_TLS_IE_HI22
:
3798 Reloc::hi22(view
, value
, addend
);
3800 case elfcpp::R_SPARC_TLS_IE_LO10
:
3801 Reloc::lo10(view
, value
, addend
);
3806 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3807 _("unsupported reloc %u"),
3811 case elfcpp::R_SPARC_TLS_IE_ADD
:
3812 // This seems to be mainly so that we can find the addition
3813 // instruction if there is one. There doesn't seem to be any
3814 // actual relocation to apply.
3817 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3818 // If we're creating a shared library, a dynamic relocation will
3819 // have been created for this location, so do not apply it now.
3820 if (!parameters
->options().shared())
3822 value
-= tls_segment
->memsz();
3823 Reloc::hix22(view
, value
, addend
);
3827 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3828 // If we're creating a shared library, a dynamic relocation will
3829 // have been created for this location, so do not apply it now.
3830 if (!parameters
->options().shared())
3832 value
-= tls_segment
->memsz();
3833 Reloc::lox10(view
, value
, addend
);
3839 // Relocate section data.
3841 template<int size
, bool big_endian
>
3843 Target_sparc
<size
, big_endian
>::relocate_section(
3844 const Relocate_info
<size
, big_endian
>* relinfo
,
3845 unsigned int sh_type
,
3846 const unsigned char* prelocs
,
3848 Output_section
* output_section
,
3849 bool needs_special_offset_handling
,
3850 unsigned char* view
,
3851 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3852 section_size_type view_size
,
3853 const Reloc_symbol_changes
* reloc_symbol_changes
)
3855 typedef Target_sparc
<size
, big_endian
> Sparc
;
3856 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3858 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3860 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3867 needs_special_offset_handling
,
3871 reloc_symbol_changes
);
3874 // Return the size of a relocation while scanning during a relocatable
3877 template<int size
, bool big_endian
>
3879 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3883 // We are always SHT_RELA, so we should never get here.
3888 // Scan the relocs during a relocatable link.
3890 template<int size
, bool big_endian
>
3892 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3893 Symbol_table
* symtab
,
3895 Sized_relobj_file
<size
, big_endian
>* object
,
3896 unsigned int data_shndx
,
3897 unsigned int sh_type
,
3898 const unsigned char* prelocs
,
3900 Output_section
* output_section
,
3901 bool needs_special_offset_handling
,
3902 size_t local_symbol_count
,
3903 const unsigned char* plocal_symbols
,
3904 Relocatable_relocs
* rr
)
3906 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3908 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3909 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3911 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3912 Scan_relocatable_relocs
>(
3920 needs_special_offset_handling
,
3926 // Relocate a section during a relocatable link.
3928 template<int size
, bool big_endian
>
3930 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3931 const Relocate_info
<size
, big_endian
>* relinfo
,
3932 unsigned int sh_type
,
3933 const unsigned char* prelocs
,
3935 Output_section
* output_section
,
3936 off_t offset_in_output_section
,
3937 const Relocatable_relocs
* rr
,
3938 unsigned char* view
,
3939 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3940 section_size_type view_size
,
3941 unsigned char* reloc_view
,
3942 section_size_type reloc_view_size
)
3944 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3946 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3951 offset_in_output_section
,
3960 // Return the value to use for a dynamic which requires special
3961 // treatment. This is how we support equality comparisons of function
3962 // pointers across shared library boundaries, as described in the
3963 // processor specific ABI supplement.
3965 template<int size
, bool big_endian
>
3967 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3969 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3970 return this->plt_section()->address() + gsym
->plt_offset();
3973 // The selector for sparc object files.
3975 template<int size
, bool big_endian
>
3976 class Target_selector_sparc
: public Target_selector
3979 Target_selector_sparc()
3980 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3981 (size
== 64 ? "elf64-sparc" : "elf32-sparc"),
3982 (size
== 64 ? "elf64_sparc" : "elf32_sparc"))
3985 Target
* do_recognize(int machine
, int, int)
3990 if (machine
!= elfcpp::EM_SPARCV9
)
3995 if (machine
!= elfcpp::EM_SPARC
3996 && machine
!= elfcpp::EM_SPARC32PLUS
)
4004 return this->instantiate_target();
4007 Target
* do_instantiate_target()
4008 { return new Target_sparc
<size
, big_endian
>(); }
4011 Target_selector_sparc
<32, true> target_selector_sparc32
;
4012 Target_selector_sparc
<64, true> target_selector_sparc64
;
4014 } // End anonymous namespace.