1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
50 template<int size
, bool big_endian
>
51 class Output_data_plt_sparc
;
53 template<int size
, bool big_endian
>
54 class Target_sparc
: public Sized_target
<size
, big_endian
>
57 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
60 : Sized_target
<size
, big_endian
>(&sparc_info
),
61 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
),
62 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
63 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
)
67 // Process the relocations to determine unreferenced sections for
68 // garbage collection.
70 gc_process_relocs(Symbol_table
* symtab
,
72 Sized_relobj
<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
<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
<size
, big_endian
>* object
,
122 unsigned int data_shndx
,
123 unsigned int sh_type
,
124 const unsigned char* prelocs
,
126 Output_section
* output_section
,
127 bool needs_special_offset_handling
,
128 size_t local_symbol_count
,
129 const unsigned char* plocal_symbols
,
130 Relocatable_relocs
*);
132 // Relocate a section during a relocatable link.
134 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
135 unsigned int sh_type
,
136 const unsigned char* prelocs
,
138 Output_section
* output_section
,
139 off_t offset_in_output_section
,
140 const Relocatable_relocs
*,
142 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
143 section_size_type view_size
,
144 unsigned char* reloc_view
,
145 section_size_type reloc_view_size
);
146 // Return whether SYM is defined by the ABI.
148 do_is_defined_by_abi(const Symbol
* sym
) const
150 // XXX Really need to support this better...
151 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
154 return strcmp(sym
->name(), "___tls_get_addr") == 0;
157 // Return whether there is a GOT section.
159 has_got_section() const
160 { return this->got_
!= NULL
; }
162 // Return the size of the GOT section.
166 gold_assert(this->got_
!= NULL
);
167 return this->got_
->data_size();
170 // Return the number of entries in the GOT.
172 got_entry_count() const
174 if (this->got_
== NULL
)
176 return this->got_size() / (size
/ 8);
179 // Return the number of entries in the PLT.
181 plt_entry_count() const;
183 // Return the offset of the first non-reserved PLT entry.
185 first_plt_entry_offset() const;
187 // Return the size of each PLT entry.
189 plt_entry_size() const;
193 // The class which scans relocations.
198 : issued_non_pic_error_(false)
202 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
203 Sized_relobj
<size
, big_endian
>* object
,
204 unsigned int data_shndx
,
205 Output_section
* output_section
,
206 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
207 const elfcpp::Sym
<size
, big_endian
>& lsym
);
210 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
211 Sized_relobj
<size
, big_endian
>* object
,
212 unsigned int data_shndx
,
213 Output_section
* output_section
,
214 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
218 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
220 Sized_relobj
<size
, big_endian
>* ,
223 const elfcpp::Rela
<size
, big_endian
>& ,
225 const elfcpp::Sym
<size
, big_endian
>&)
229 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
231 Sized_relobj
<size
, big_endian
>* ,
234 const elfcpp::Rela
<size
,
236 unsigned int , Symbol
*)
242 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
243 unsigned int r_type
);
246 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
247 unsigned int r_type
, Symbol
*);
250 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
251 Target_sparc
* target
);
254 check_non_pic(Relobj
*, unsigned int r_type
);
256 // Whether we have issued an error about a non-PIC compilation.
257 bool issued_non_pic_error_
;
260 // The class which implements relocation.
265 : ignore_gd_add_(false)
270 if (this->ignore_gd_add_
)
272 // FIXME: This needs to specify the location somehow.
273 gold_error(_("missing expected TLS relocation"));
277 // Do a relocation. Return false if the caller should not issue
278 // any warnings about this relocation.
280 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
281 Output_section
*, size_t relnum
,
282 const elfcpp::Rela
<size
, big_endian
>&,
283 unsigned int r_type
, const Sized_symbol
<size
>*,
284 const Symbol_value
<size
>*,
286 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
290 // Do a TLS relocation.
292 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
293 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
294 unsigned int r_type
, const Sized_symbol
<size
>*,
295 const Symbol_value
<size
>*,
297 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
300 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
304 // A class which returns the size required for a relocation type,
305 // used while scanning relocs during a relocatable link.
306 class Relocatable_size_for_reloc
310 get_size_for_reloc(unsigned int, Relobj
*);
313 // Get the GOT section, creating it if necessary.
314 Output_data_got
<size
, big_endian
>*
315 got_section(Symbol_table
*, Layout
*);
317 // Create a PLT entry for a global symbol.
319 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
321 // Create a GOT entry for the TLS module index.
323 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
324 Sized_relobj
<size
, big_endian
>* object
);
326 // Return the gsym for "__tls_get_addr". Cache if not already
329 tls_get_addr_sym(Symbol_table
* symtab
)
331 if (!this->tls_get_addr_sym_
)
332 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
333 gold_assert(this->tls_get_addr_sym_
);
334 return this->tls_get_addr_sym_
;
337 // Get the PLT section.
338 const Output_data_plt_sparc
<size
, big_endian
>*
341 gold_assert(this->plt_
!= NULL
);
345 // Get the dynamic reloc section, creating it if necessary.
347 rela_dyn_section(Layout
*);
349 // Copy a relocation against a global symbol.
351 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
352 Sized_relobj
<size
, big_endian
>* object
,
353 unsigned int shndx
, Output_section
* output_section
,
354 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
356 this->copy_relocs_
.copy_reloc(symtab
, layout
,
357 symtab
->get_sized_symbol
<size
>(sym
),
358 object
, shndx
, output_section
,
359 reloc
, this->rela_dyn_section(layout
));
362 // Information about this specific target which we pass to the
363 // general Target structure.
364 static Target::Target_info sparc_info
;
366 // The types of GOT entries needed for this platform.
367 // These values are exposed to the ABI in an incremental link.
368 // Do not renumber existing values without changing the version
369 // number of the .gnu_incremental_inputs section.
372 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
373 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
374 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
378 Output_data_got
<size
, big_endian
>* got_
;
380 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
381 // The dynamic reloc section.
382 Reloc_section
* rela_dyn_
;
383 // Relocs saved to avoid a COPY reloc.
384 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
385 // Space for variables copied with a COPY reloc.
386 Output_data_space
* dynbss_
;
387 // Offset of the GOT entry for the TLS module index;
388 unsigned int got_mod_index_offset_
;
389 // Cached pointer to __tls_get_addr symbol
390 Symbol
* tls_get_addr_sym_
;
394 Target::Target_info Target_sparc
<32, true>::sparc_info
=
397 true, // is_big_endian
398 elfcpp::EM_SPARC
, // machine_code
399 false, // has_make_symbol
400 false, // has_resolve
401 false, // has_code_fill
402 true, // is_default_stack_executable
404 "/usr/lib/ld.so.1", // dynamic_linker
405 0x00010000, // default_text_segment_address
406 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
407 8 * 1024, // common_pagesize (overridable by -z common-page-size)
408 elfcpp::SHN_UNDEF
, // small_common_shndx
409 elfcpp::SHN_UNDEF
, // large_common_shndx
410 0, // small_common_section_flags
411 0, // large_common_section_flags
412 NULL
, // attributes_section
413 NULL
// attributes_vendor
417 Target::Target_info Target_sparc
<64, true>::sparc_info
=
420 true, // is_big_endian
421 elfcpp::EM_SPARCV9
, // machine_code
422 false, // has_make_symbol
423 false, // has_resolve
424 false, // has_code_fill
425 true, // is_default_stack_executable
427 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
428 0x100000, // default_text_segment_address
429 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
430 8 * 1024, // common_pagesize (overridable by -z common-page-size)
431 elfcpp::SHN_UNDEF
, // small_common_shndx
432 elfcpp::SHN_UNDEF
, // large_common_shndx
433 0, // small_common_section_flags
434 0, // large_common_section_flags
435 NULL
, // attributes_section
436 NULL
// attributes_vendor
439 // We have to take care here, even when operating in little-endian
440 // mode, sparc instructions are still big endian.
441 template<int size
, bool big_endian
>
442 class Sparc_relocate_functions
445 // Do a simple relocation with the addend in the relocation.
446 template<int valsize
>
448 rela(unsigned char* view
,
449 unsigned int right_shift
,
450 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
451 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
452 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
454 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
455 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
456 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
457 Valtype reloc
= ((value
+ addend
) >> right_shift
);
462 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
465 // Do a simple relocation using a symbol value with the addend in
467 template<int valsize
>
469 rela(unsigned char* view
,
470 unsigned int right_shift
,
471 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
472 const Sized_relobj
<size
, big_endian
>* object
,
473 const Symbol_value
<size
>* psymval
,
474 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
476 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
477 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
478 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
479 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
484 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
487 // Do a simple relocation using a symbol value with the addend in
488 // the relocation, unaligned.
489 template<int valsize
>
491 rela_ua(unsigned char* view
,
492 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
493 const Sized_relobj
<size
, big_endian
>* object
,
494 const Symbol_value
<size
>* psymval
,
495 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
497 typedef typename
elfcpp::Swap_unaligned
<valsize
,
498 big_endian
>::Valtype Valtype
;
499 unsigned char* wv
= view
;
500 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
501 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
506 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
509 // Do a simple PC relative relocation with a Symbol_value with the
510 // addend in the relocation.
511 template<int valsize
>
513 pcrela(unsigned char* view
,
514 unsigned int right_shift
,
515 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
516 const Sized_relobj
<size
, big_endian
>* object
,
517 const Symbol_value
<size
>* psymval
,
518 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
519 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
521 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
522 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
523 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
524 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
530 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
533 template<int valsize
>
535 pcrela_unaligned(unsigned char* view
,
536 const Sized_relobj
<size
, big_endian
>* object
,
537 const Symbol_value
<size
>* psymval
,
538 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
539 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
541 typedef typename
elfcpp::Swap_unaligned
<valsize
,
542 big_endian
>::Valtype Valtype
;
543 unsigned char* wv
= view
;
544 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
546 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
549 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
550 typedef Sparc_relocate_functions
<size
, true> This_insn
;
553 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
555 wdisp30(unsigned char* view
,
556 const Sized_relobj
<size
, big_endian
>* object
,
557 const Symbol_value
<size
>* psymval
,
558 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
559 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
561 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
562 psymval
, addend
, address
);
565 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
567 wdisp22(unsigned char* view
,
568 const Sized_relobj
<size
, big_endian
>* object
,
569 const Symbol_value
<size
>* psymval
,
570 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
571 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
573 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
574 psymval
, addend
, address
);
577 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
579 wdisp19(unsigned char* view
,
580 const Sized_relobj
<size
, big_endian
>* object
,
581 const Symbol_value
<size
>* psymval
,
582 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
583 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
585 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
586 psymval
, addend
, address
);
589 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
591 wdisp16(unsigned char* view
,
592 const Sized_relobj
<size
, big_endian
>* object
,
593 const Symbol_value
<size
>* psymval
,
594 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
595 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
597 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
598 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
599 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
600 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
603 // The relocation value is split between the low 14 bits,
605 val
&= ~((0x3 << 20) | 0x3fff);
606 reloc
= (((reloc
& 0xc000) << (20 - 14))
607 | (reloc
& 0x3ffff));
609 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
612 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
614 pc22(unsigned char* view
,
615 const Sized_relobj
<size
, big_endian
>* object
,
616 const Symbol_value
<size
>* psymval
,
617 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
618 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
620 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
621 psymval
, addend
, address
);
624 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
626 pc10(unsigned char* view
,
627 const Sized_relobj
<size
, big_endian
>* object
,
628 const Symbol_value
<size
>* psymval
,
629 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
630 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
632 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
633 psymval
, addend
, address
);
636 // R_SPARC_HI22: (Symbol + Addend) >> 10
638 hi22(unsigned char* view
,
639 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
640 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
642 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
645 // R_SPARC_HI22: (Symbol + Addend) >> 10
647 hi22(unsigned char* view
,
648 const Sized_relobj
<size
, big_endian
>* object
,
649 const Symbol_value
<size
>* psymval
,
650 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
652 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
655 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
657 pcplt22(unsigned char* view
,
658 const Sized_relobj
<size
, big_endian
>* object
,
659 const Symbol_value
<size
>* psymval
,
660 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
661 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
663 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
664 psymval
, addend
, address
);
667 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
669 lo10(unsigned char* view
,
670 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
671 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
673 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
676 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
678 lo10(unsigned char* view
,
679 const Sized_relobj
<size
, big_endian
>* object
,
680 const Symbol_value
<size
>* psymval
,
681 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
683 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
686 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
688 lo10(unsigned char* view
,
689 const Sized_relobj
<size
, big_endian
>* object
,
690 const Symbol_value
<size
>* psymval
,
691 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
694 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
695 psymval
, addend
, address
);
698 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
700 olo10(unsigned char* view
,
701 const Sized_relobj
<size
, big_endian
>* object
,
702 const Symbol_value
<size
>* psymval
,
703 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
704 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
706 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
707 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
708 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
709 Valtype reloc
= psymval
->value(object
, addend
);
716 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
719 // R_SPARC_22: (Symbol + Addend)
721 rela32_22(unsigned char* view
,
722 const Sized_relobj
<size
, big_endian
>* object
,
723 const Symbol_value
<size
>* psymval
,
724 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
726 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
729 // R_SPARC_13: (Symbol + Addend)
731 rela32_13(unsigned char* view
,
732 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
733 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
735 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
738 // R_SPARC_13: (Symbol + Addend)
740 rela32_13(unsigned char* view
,
741 const Sized_relobj
<size
, big_endian
>* object
,
742 const Symbol_value
<size
>* psymval
,
743 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
745 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
748 // R_SPARC_UA16: (Symbol + Addend)
750 ua16(unsigned char* view
,
751 const Sized_relobj
<size
, big_endian
>* object
,
752 const Symbol_value
<size
>* psymval
,
753 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
755 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
758 // R_SPARC_UA32: (Symbol + Addend)
760 ua32(unsigned char* view
,
761 const Sized_relobj
<size
, big_endian
>* object
,
762 const Symbol_value
<size
>* psymval
,
763 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
765 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
768 // R_SPARC_UA64: (Symbol + Addend)
770 ua64(unsigned char* view
,
771 const Sized_relobj
<size
, big_endian
>* object
,
772 const Symbol_value
<size
>* psymval
,
773 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
775 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
776 object
, psymval
, addend
);
779 // R_SPARC_DISP8: (Symbol + Addend - Address)
781 disp8(unsigned char* view
,
782 const Sized_relobj
<size
, big_endian
>* object
,
783 const Symbol_value
<size
>* psymval
,
784 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
785 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
787 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
791 // R_SPARC_DISP16: (Symbol + Addend - Address)
793 disp16(unsigned char* view
,
794 const Sized_relobj
<size
, big_endian
>* object
,
795 const Symbol_value
<size
>* psymval
,
796 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
797 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
799 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
803 // R_SPARC_DISP32: (Symbol + Addend - Address)
805 disp32(unsigned char* view
,
806 const Sized_relobj
<size
, big_endian
>* object
,
807 const Symbol_value
<size
>* psymval
,
808 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
809 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
811 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
815 // R_SPARC_DISP64: (Symbol + Addend - Address)
817 disp64(unsigned char* view
,
818 const Sized_relobj
<size
, big_endian
>* object
,
819 const Symbol_value
<size
>* psymval
,
820 elfcpp::Elf_Xword addend
,
821 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
823 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
827 // R_SPARC_H44: (Symbol + Addend) >> 22
829 h44(unsigned char* view
,
830 const Sized_relobj
<size
, big_endian
>* object
,
831 const Symbol_value
<size
>* psymval
,
832 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
834 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
837 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
839 m44(unsigned char* view
,
840 const Sized_relobj
<size
, big_endian
>* object
,
841 const Symbol_value
<size
>* psymval
,
842 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
844 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
847 // R_SPARC_L44: (Symbol + Addend) & 0xfff
849 l44(unsigned char* view
,
850 const Sized_relobj
<size
, big_endian
>* object
,
851 const Symbol_value
<size
>* psymval
,
852 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
854 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
857 // R_SPARC_HH22: (Symbol + Addend) >> 42
859 hh22(unsigned char* view
,
860 const Sized_relobj
<size
, big_endian
>* object
,
861 const Symbol_value
<size
>* psymval
,
862 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
864 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
867 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
869 pc_hh22(unsigned char* view
,
870 const Sized_relobj
<size
, big_endian
>* object
,
871 const Symbol_value
<size
>* psymval
,
872 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
873 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
875 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
876 psymval
, addend
, address
);
879 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
881 hm10(unsigned char* view
,
882 const Sized_relobj
<size
, big_endian
>* object
,
883 const Symbol_value
<size
>* psymval
,
884 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
886 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
889 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
891 pc_hm10(unsigned char* view
,
892 const Sized_relobj
<size
, big_endian
>* object
,
893 const Symbol_value
<size
>* psymval
,
894 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
895 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
897 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
898 psymval
, addend
, address
);
901 // R_SPARC_11: (Symbol + Addend)
903 rela32_11(unsigned char* view
,
904 const Sized_relobj
<size
, big_endian
>* object
,
905 const Symbol_value
<size
>* psymval
,
906 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
908 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
911 // R_SPARC_10: (Symbol + Addend)
913 rela32_10(unsigned char* view
,
914 const Sized_relobj
<size
, big_endian
>* object
,
915 const Symbol_value
<size
>* psymval
,
916 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
918 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
921 // R_SPARC_7: (Symbol + Addend)
923 rela32_7(unsigned char* view
,
924 const Sized_relobj
<size
, big_endian
>* object
,
925 const Symbol_value
<size
>* psymval
,
926 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
928 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
931 // R_SPARC_6: (Symbol + Addend)
933 rela32_6(unsigned char* view
,
934 const Sized_relobj
<size
, big_endian
>* object
,
935 const Symbol_value
<size
>* psymval
,
936 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
938 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
941 // R_SPARC_5: (Symbol + Addend)
943 rela32_5(unsigned char* view
,
944 const Sized_relobj
<size
, big_endian
>* object
,
945 const Symbol_value
<size
>* psymval
,
946 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
948 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
951 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
953 ldo_hix22(unsigned char* view
,
954 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
955 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
957 This_insn::hi22(view
, value
, addend
);
960 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
962 ldo_lox10(unsigned char* view
,
963 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
964 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
966 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
967 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
968 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
969 Valtype reloc
= (value
+ addend
);
974 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
977 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
979 hix22(unsigned char* view
,
980 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
981 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
983 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
984 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
985 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
986 Valtype reloc
= (value
+ addend
);
990 reloc
^= ~(Valtype
)0;
995 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
998 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1000 hix22(unsigned char* view
,
1001 const Sized_relobj
<size
, big_endian
>* object
,
1002 const Symbol_value
<size
>* psymval
,
1003 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1005 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1006 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1007 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1008 Valtype reloc
= psymval
->value(object
, addend
);
1012 reloc
^= ~(Valtype
)0;
1017 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1021 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1023 lox10(unsigned char* view
,
1024 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1025 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1027 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1028 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1029 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1030 Valtype reloc
= (value
+ addend
);
1036 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1039 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1041 lox10(unsigned char* view
,
1042 const Sized_relobj
<size
, big_endian
>* object
,
1043 const Symbol_value
<size
>* psymval
,
1044 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1046 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1047 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1048 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1049 Valtype reloc
= psymval
->value(object
, addend
);
1055 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1059 // Get the GOT section, creating it if necessary.
1061 template<int size
, bool big_endian
>
1062 Output_data_got
<size
, big_endian
>*
1063 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1066 if (this->got_
== NULL
)
1068 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1070 this->got_
= new Output_data_got
<size
, big_endian
>();
1072 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1074 | elfcpp::SHF_WRITE
),
1075 this->got_
, ORDER_RELRO
, true);
1077 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1078 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1079 Symbol_table::PREDEFINED
,
1081 0, 0, elfcpp::STT_OBJECT
,
1083 elfcpp::STV_HIDDEN
, 0,
1090 // Get the dynamic reloc section, creating it if necessary.
1092 template<int size
, bool big_endian
>
1093 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1094 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1096 if (this->rela_dyn_
== NULL
)
1098 gold_assert(layout
!= NULL
);
1099 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1100 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1101 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1102 ORDER_DYNAMIC_RELOCS
, false);
1104 return this->rela_dyn_
;
1107 // A class to handle the PLT data.
1109 template<int size
, bool big_endian
>
1110 class Output_data_plt_sparc
: public Output_section_data
1113 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1114 size
, big_endian
> Reloc_section
;
1116 Output_data_plt_sparc(Layout
*);
1118 // Add an entry to the PLT.
1119 void add_entry(Symbol
* gsym
);
1121 // Return the .rela.plt section data.
1122 const Reloc_section
* rel_plt() const
1127 // Return the number of PLT entries.
1130 { return this->count_
; }
1132 // Return the offset of the first non-reserved PLT entry.
1134 first_plt_entry_offset()
1135 { return 4 * base_plt_entry_size
; }
1137 // Return the size of a PLT entry.
1139 get_plt_entry_size()
1140 { return base_plt_entry_size
; }
1143 void do_adjust_output_section(Output_section
* os
);
1145 // Write to a map file.
1147 do_print_to_mapfile(Mapfile
* mapfile
) const
1148 { mapfile
->print_output_data(this, _("** PLT")); }
1151 // The size of an entry in the PLT.
1152 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1154 static const unsigned int plt_entries_per_block
= 160;
1155 static const unsigned int plt_insn_chunk_size
= 24;
1156 static const unsigned int plt_pointer_chunk_size
= 8;
1157 static const unsigned int plt_block_size
=
1158 (plt_entries_per_block
1159 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1161 // Set the final size.
1163 set_final_data_size()
1165 unsigned int full_count
= this->count_
+ 4;
1166 unsigned int extra
= (size
== 32 ? 4 : 0);
1168 if (size
== 32 || full_count
< 32768)
1169 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1172 unsigned int ext_cnt
= full_count
- 32768;
1174 this->set_data_size((32768 * base_plt_entry_size
)
1176 * (plt_insn_chunk_size
1177 + plt_pointer_chunk_size
)));
1181 // Write out the PLT data.
1183 do_write(Output_file
*);
1185 // The reloc section.
1186 Reloc_section
* rel_
;
1187 // The number of PLT entries.
1188 unsigned int count_
;
1191 // Define the constants as required by C++ standard.
1193 template<int size
, bool big_endian
>
1194 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1196 template<int size
, bool big_endian
>
1198 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1200 template<int size
, bool big_endian
>
1201 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1203 template<int size
, bool big_endian
>
1205 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1207 template<int size
, bool big_endian
>
1208 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1210 // Create the PLT section. The ordinary .got section is an argument,
1211 // since we need to refer to the start.
1213 template<int size
, bool big_endian
>
1214 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1215 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1217 this->rel_
= new Reloc_section(false);
1218 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1219 elfcpp::SHF_ALLOC
, this->rel_
,
1220 ORDER_DYNAMIC_PLT_RELOCS
, false);
1223 template<int size
, bool big_endian
>
1225 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1230 // Add an entry to the PLT.
1232 template<int size
, bool big_endian
>
1234 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1236 gold_assert(!gsym
->has_plt_offset());
1238 unsigned int index
= this->count_
+ 4;
1239 section_offset_type plt_offset
;
1241 if (size
== 32 || index
< 32768)
1242 plt_offset
= index
* base_plt_entry_size
;
1245 unsigned int ext_index
= index
- 32768;
1247 plt_offset
= (32768 * base_plt_entry_size
)
1248 + ((ext_index
/ plt_entries_per_block
)
1250 + ((ext_index
% plt_entries_per_block
)
1251 * plt_insn_chunk_size
);
1254 gsym
->set_plt_offset(plt_offset
);
1258 // Every PLT entry needs a reloc.
1259 gsym
->set_needs_dynsym_entry();
1260 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1263 // Note that we don't need to save the symbol. The contents of the
1264 // PLT are independent of which symbols are used. The symbols only
1265 // appear in the relocations.
1268 static const unsigned int sparc_nop
= 0x01000000;
1269 static const unsigned int sparc_sethi_g1
= 0x03000000;
1270 static const unsigned int sparc_branch_always
= 0x30800000;
1271 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1272 static const unsigned int sparc_mov
= 0x80100000;
1273 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1274 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1275 static const unsigned int sparc_call_plus_8
= 0x40000002;
1276 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1277 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1278 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1280 // Write out the PLT.
1282 template<int size
, bool big_endian
>
1284 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1286 const off_t offset
= this->offset();
1287 const section_size_type oview_size
=
1288 convert_to_section_size_type(this->data_size());
1289 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1290 unsigned char* pov
= oview
;
1292 memset(pov
, 0, base_plt_entry_size
* 4);
1293 pov
+= base_plt_entry_size
* 4;
1295 unsigned int plt_offset
= base_plt_entry_size
* 4;
1296 const unsigned int count
= this->count_
;
1302 limit
= (count
> 32768 ? 32768 : count
);
1304 for (unsigned int i
= 0; i
< limit
; ++i
)
1306 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1307 sparc_sethi_g1
+ plt_offset
);
1308 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1309 sparc_branch_always_pt
+
1310 (((base_plt_entry_size
-
1311 (plt_offset
+ 4)) >> 2) &
1313 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1314 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1315 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1316 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1317 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1318 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1320 pov
+= base_plt_entry_size
;
1321 plt_offset
+= base_plt_entry_size
;
1326 unsigned int ext_cnt
= count
- 32768;
1327 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1329 for (unsigned int i
= 0; i
< blks
; ++i
)
1331 unsigned int data_off
= (plt_entries_per_block
1332 * plt_insn_chunk_size
) - 4;
1334 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1336 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1338 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1340 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1342 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1343 sparc_ldx_o7_imm_g1
+
1344 (data_off
& 0x1fff));
1345 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1346 sparc_jmpl_o7_g1_g1
);
1347 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1350 elfcpp::Swap
<64, big_endian
>::writeval(
1351 pov
+ 0x4 + data_off
,
1352 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1354 pov
+= plt_insn_chunk_size
;
1359 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1360 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1362 unsigned int data_off
= (sub_blk_cnt
1363 * plt_insn_chunk_size
) - 4;
1365 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1367 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1369 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1371 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1373 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1374 sparc_ldx_o7_imm_g1
+
1375 (data_off
& 0x1fff));
1376 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1377 sparc_jmpl_o7_g1_g1
);
1378 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1381 elfcpp::Swap
<64, big_endian
>::writeval(
1382 pov
+ 0x4 + data_off
,
1383 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1385 pov
+= plt_insn_chunk_size
;
1393 for (unsigned int i
= 0; i
< count
; ++i
)
1395 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1396 sparc_sethi_g1
+ plt_offset
);
1397 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1398 sparc_branch_always
+
1399 (((- (plt_offset
+ 4)) >> 2) &
1401 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1403 pov
+= base_plt_entry_size
;
1404 plt_offset
+= base_plt_entry_size
;
1407 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1411 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1413 of
->write_output_view(offset
, oview_size
, oview
);
1416 // Create a PLT entry for a global symbol.
1418 template<int size
, bool big_endian
>
1420 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1424 if (gsym
->has_plt_offset())
1427 if (this->plt_
== NULL
)
1429 // Create the GOT sections first.
1430 this->got_section(symtab
, layout
);
1432 // Ensure that .rela.dyn always appears before .rela.plt This is
1433 // necessary due to how, on Sparc and some other targets, .rela.dyn
1434 // needs to include .rela.plt in it's range.
1435 this->rela_dyn_section(layout
);
1437 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1438 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1440 | elfcpp::SHF_EXECINSTR
1441 | elfcpp::SHF_WRITE
),
1442 this->plt_
, ORDER_PLT
, false);
1444 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1445 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1446 Symbol_table::PREDEFINED
,
1448 0, 0, elfcpp::STT_OBJECT
,
1450 elfcpp::STV_HIDDEN
, 0,
1454 this->plt_
->add_entry(gsym
);
1457 // Return the number of entries in the PLT.
1459 template<int size
, bool big_endian
>
1461 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1463 if (this->plt_
== NULL
)
1465 return this->plt_
->entry_count();
1468 // Return the offset of the first non-reserved PLT entry.
1470 template<int size
, bool big_endian
>
1472 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1474 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1477 // Return the size of each PLT entry.
1479 template<int size
, bool big_endian
>
1481 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1483 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1486 // Create a GOT entry for the TLS module index.
1488 template<int size
, bool big_endian
>
1490 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1492 Sized_relobj
<size
, big_endian
>* object
)
1494 if (this->got_mod_index_offset_
== -1U)
1496 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1497 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1498 Output_data_got
<size
, big_endian
>* got
;
1499 unsigned int got_offset
;
1501 got
= this->got_section(symtab
, layout
);
1502 got_offset
= got
->add_constant(0);
1503 rela_dyn
->add_local(object
, 0,
1505 elfcpp::R_SPARC_TLS_DTPMOD64
:
1506 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1508 got
->add_constant(0);
1509 this->got_mod_index_offset_
= got_offset
;
1511 return this->got_mod_index_offset_
;
1514 // Optimize the TLS relocation type based on what we know about the
1515 // symbol. IS_FINAL is true if the final address of this symbol is
1516 // known at link time.
1518 static tls::Tls_optimization
1519 optimize_tls_reloc(bool is_final
, int r_type
)
1521 // If we are generating a shared library, then we can't do anything
1523 if (parameters
->options().shared())
1524 return tls::TLSOPT_NONE
;
1528 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1529 case elfcpp::R_SPARC_TLS_GD_LO10
:
1530 case elfcpp::R_SPARC_TLS_GD_ADD
:
1531 case elfcpp::R_SPARC_TLS_GD_CALL
:
1532 // These are General-Dynamic which permits fully general TLS
1533 // access. Since we know that we are generating an executable,
1534 // we can convert this to Initial-Exec. If we also know that
1535 // this is a local symbol, we can further switch to Local-Exec.
1537 return tls::TLSOPT_TO_LE
;
1538 return tls::TLSOPT_TO_IE
;
1540 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1541 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1542 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1543 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1544 // This is Local-Dynamic, which refers to a local symbol in the
1545 // dynamic TLS block. Since we know that we generating an
1546 // executable, we can switch to Local-Exec.
1547 return tls::TLSOPT_TO_LE
;
1549 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1550 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1551 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1552 // Another type of Local-Dynamic relocation.
1553 return tls::TLSOPT_TO_LE
;
1555 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1556 case elfcpp::R_SPARC_TLS_IE_LO10
:
1557 case elfcpp::R_SPARC_TLS_IE_LD
:
1558 case elfcpp::R_SPARC_TLS_IE_LDX
:
1559 case elfcpp::R_SPARC_TLS_IE_ADD
:
1560 // These are Initial-Exec relocs which get the thread offset
1561 // from the GOT. If we know that we are linking against the
1562 // local symbol, we can switch to Local-Exec, which links the
1563 // thread offset into the instruction.
1565 return tls::TLSOPT_TO_LE
;
1566 return tls::TLSOPT_NONE
;
1568 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1569 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1570 // When we already have Local-Exec, there is nothing further we
1572 return tls::TLSOPT_NONE
;
1579 // Generate a PLT entry slot for a call to __tls_get_addr
1580 template<int size
, bool big_endian
>
1582 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1584 Target_sparc
<size
, big_endian
>* target
)
1586 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1588 target
->make_plt_entry(symtab
, layout
, gsym
);
1591 // Report an unsupported relocation against a local symbol.
1593 template<int size
, bool big_endian
>
1595 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1596 Sized_relobj
<size
, big_endian
>* object
,
1597 unsigned int r_type
)
1599 gold_error(_("%s: unsupported reloc %u against local symbol"),
1600 object
->name().c_str(), r_type
);
1603 // We are about to emit a dynamic relocation of type R_TYPE. If the
1604 // dynamic linker does not support it, issue an error.
1606 template<int size
, bool big_endian
>
1608 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1610 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1616 // These are the relocation types supported by glibc for sparc 64-bit.
1617 case elfcpp::R_SPARC_RELATIVE
:
1618 case elfcpp::R_SPARC_COPY
:
1619 case elfcpp::R_SPARC_64
:
1620 case elfcpp::R_SPARC_GLOB_DAT
:
1621 case elfcpp::R_SPARC_JMP_SLOT
:
1622 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1623 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1624 case elfcpp::R_SPARC_TLS_TPOFF64
:
1625 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1626 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1627 case elfcpp::R_SPARC_8
:
1628 case elfcpp::R_SPARC_16
:
1629 case elfcpp::R_SPARC_DISP8
:
1630 case elfcpp::R_SPARC_DISP16
:
1631 case elfcpp::R_SPARC_DISP32
:
1632 case elfcpp::R_SPARC_WDISP30
:
1633 case elfcpp::R_SPARC_LO10
:
1634 case elfcpp::R_SPARC_HI22
:
1635 case elfcpp::R_SPARC_OLO10
:
1636 case elfcpp::R_SPARC_H44
:
1637 case elfcpp::R_SPARC_M44
:
1638 case elfcpp::R_SPARC_L44
:
1639 case elfcpp::R_SPARC_HH22
:
1640 case elfcpp::R_SPARC_HM10
:
1641 case elfcpp::R_SPARC_LM22
:
1642 case elfcpp::R_SPARC_UA16
:
1643 case elfcpp::R_SPARC_UA32
:
1644 case elfcpp::R_SPARC_UA64
:
1655 // These are the relocation types supported by glibc for sparc 32-bit.
1656 case elfcpp::R_SPARC_RELATIVE
:
1657 case elfcpp::R_SPARC_COPY
:
1658 case elfcpp::R_SPARC_GLOB_DAT
:
1659 case elfcpp::R_SPARC_32
:
1660 case elfcpp::R_SPARC_JMP_SLOT
:
1661 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1662 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1663 case elfcpp::R_SPARC_TLS_TPOFF32
:
1664 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1665 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1666 case elfcpp::R_SPARC_8
:
1667 case elfcpp::R_SPARC_16
:
1668 case elfcpp::R_SPARC_DISP8
:
1669 case elfcpp::R_SPARC_DISP16
:
1670 case elfcpp::R_SPARC_DISP32
:
1671 case elfcpp::R_SPARC_LO10
:
1672 case elfcpp::R_SPARC_WDISP30
:
1673 case elfcpp::R_SPARC_HI22
:
1674 case elfcpp::R_SPARC_UA16
:
1675 case elfcpp::R_SPARC_UA32
:
1683 // This prevents us from issuing more than one error per reloc
1684 // section. But we can still wind up issuing more than one
1685 // error per object file.
1686 if (this->issued_non_pic_error_
)
1688 gold_assert(parameters
->options().output_is_position_independent());
1689 object
->error(_("requires unsupported dynamic reloc; "
1690 "recompile with -fPIC"));
1691 this->issued_non_pic_error_
= true;
1695 // Scan a relocation for a local symbol.
1697 template<int size
, bool big_endian
>
1699 Target_sparc
<size
, big_endian
>::Scan::local(
1700 Symbol_table
* symtab
,
1702 Target_sparc
<size
, big_endian
>* target
,
1703 Sized_relobj
<size
, big_endian
>* object
,
1704 unsigned int data_shndx
,
1705 Output_section
* output_section
,
1706 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1707 unsigned int r_type
,
1708 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1710 unsigned int orig_r_type
= r_type
;
1715 case elfcpp::R_SPARC_NONE
:
1716 case elfcpp::R_SPARC_REGISTER
:
1717 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1718 case elfcpp::R_SPARC_GNU_VTENTRY
:
1721 case elfcpp::R_SPARC_64
:
1722 case elfcpp::R_SPARC_32
:
1723 // If building a shared library (or a position-independent
1724 // executable), we need to create a dynamic relocation for
1725 // this location. The relocation applied at link time will
1726 // apply the link-time value, so we flag the location with
1727 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1728 // relocate it easily.
1729 if (parameters
->options().output_is_position_independent())
1731 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1732 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1733 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1734 output_section
, data_shndx
,
1735 reloc
.get_r_offset(),
1736 reloc
.get_r_addend());
1740 case elfcpp::R_SPARC_HIX22
:
1741 case elfcpp::R_SPARC_LOX10
:
1742 case elfcpp::R_SPARC_H44
:
1743 case elfcpp::R_SPARC_M44
:
1744 case elfcpp::R_SPARC_L44
:
1745 case elfcpp::R_SPARC_HH22
:
1746 case elfcpp::R_SPARC_HM10
:
1747 case elfcpp::R_SPARC_LM22
:
1748 case elfcpp::R_SPARC_UA64
:
1749 case elfcpp::R_SPARC_UA32
:
1750 case elfcpp::R_SPARC_UA16
:
1751 case elfcpp::R_SPARC_HI22
:
1752 case elfcpp::R_SPARC_LO10
:
1753 case elfcpp::R_SPARC_OLO10
:
1754 case elfcpp::R_SPARC_16
:
1755 case elfcpp::R_SPARC_11
:
1756 case elfcpp::R_SPARC_10
:
1757 case elfcpp::R_SPARC_8
:
1758 case elfcpp::R_SPARC_7
:
1759 case elfcpp::R_SPARC_6
:
1760 case elfcpp::R_SPARC_5
:
1761 // If building a shared library (or a position-independent
1762 // executable), we need to create a dynamic relocation for
1764 if (parameters
->options().output_is_position_independent())
1766 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1767 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1769 check_non_pic(object
, r_type
);
1770 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1772 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1773 data_shndx
, reloc
.get_r_offset(),
1774 reloc
.get_r_addend());
1778 gold_assert(lsym
.get_st_value() == 0);
1779 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
1780 output_section
, data_shndx
,
1781 reloc
.get_r_offset(),
1782 reloc
.get_r_addend());
1787 case elfcpp::R_SPARC_WDISP30
:
1788 case elfcpp::R_SPARC_WPLT30
:
1789 case elfcpp::R_SPARC_WDISP22
:
1790 case elfcpp::R_SPARC_WDISP19
:
1791 case elfcpp::R_SPARC_WDISP16
:
1792 case elfcpp::R_SPARC_DISP8
:
1793 case elfcpp::R_SPARC_DISP16
:
1794 case elfcpp::R_SPARC_DISP32
:
1795 case elfcpp::R_SPARC_DISP64
:
1796 case elfcpp::R_SPARC_PC10
:
1797 case elfcpp::R_SPARC_PC22
:
1800 case elfcpp::R_SPARC_GOTDATA_OP
:
1801 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1802 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1803 case elfcpp::R_SPARC_GOT10
:
1804 case elfcpp::R_SPARC_GOT13
:
1805 case elfcpp::R_SPARC_GOT22
:
1807 // The symbol requires a GOT entry.
1808 Output_data_got
<size
, big_endian
>* got
;
1811 got
= target
->got_section(symtab
, layout
);
1812 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1814 // If we are generating a shared object, we need to add a
1815 // dynamic relocation for this symbol's GOT entry.
1816 if (parameters
->options().output_is_position_independent())
1818 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1820 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1823 off
= got
->add_constant(0);
1824 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1825 rela_dyn
->add_local_relative(object
, r_sym
,
1826 elfcpp::R_SPARC_RELATIVE
,
1831 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1835 // These are initial TLS relocs, which are expected when
1837 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1838 case elfcpp::R_SPARC_TLS_GD_LO10
:
1839 case elfcpp::R_SPARC_TLS_GD_ADD
:
1840 case elfcpp::R_SPARC_TLS_GD_CALL
:
1841 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1842 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1843 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1844 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1845 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1846 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1847 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1848 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1849 case elfcpp::R_SPARC_TLS_IE_LO10
:
1850 case elfcpp::R_SPARC_TLS_IE_LD
:
1851 case elfcpp::R_SPARC_TLS_IE_LDX
:
1852 case elfcpp::R_SPARC_TLS_IE_ADD
:
1853 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1854 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1856 bool output_is_shared
= parameters
->options().shared();
1857 const tls::Tls_optimization optimized_type
1858 = optimize_tls_reloc(!output_is_shared
, r_type
);
1861 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1862 case elfcpp::R_SPARC_TLS_GD_LO10
:
1863 case elfcpp::R_SPARC_TLS_GD_ADD
:
1864 case elfcpp::R_SPARC_TLS_GD_CALL
:
1865 if (optimized_type
== tls::TLSOPT_NONE
)
1867 // Create a pair of GOT entries for the module index and
1868 // dtv-relative offset.
1869 Output_data_got
<size
, big_endian
>* got
1870 = target
->got_section(symtab
, layout
);
1871 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1872 unsigned int shndx
= lsym
.get_st_shndx();
1874 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1876 object
->error(_("local symbol %u has bad shndx %u"),
1879 got
->add_local_pair_with_rela(object
, r_sym
,
1880 lsym
.get_st_shndx(),
1882 target
->rela_dyn_section(layout
),
1884 ? elfcpp::R_SPARC_TLS_DTPMOD64
1885 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1887 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1888 generate_tls_call(symtab
, layout
, target
);
1890 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1891 unsupported_reloc_local(object
, r_type
);
1894 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1895 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1896 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1897 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1898 if (optimized_type
== tls::TLSOPT_NONE
)
1900 // Create a GOT entry for the module index.
1901 target
->got_mod_index_entry(symtab
, layout
, object
);
1903 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1904 generate_tls_call(symtab
, layout
, target
);
1906 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1907 unsupported_reloc_local(object
, r_type
);
1910 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1911 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1912 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1915 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1916 case elfcpp::R_SPARC_TLS_IE_LO10
:
1917 case elfcpp::R_SPARC_TLS_IE_LD
:
1918 case elfcpp::R_SPARC_TLS_IE_LDX
:
1919 case elfcpp::R_SPARC_TLS_IE_ADD
:
1920 layout
->set_has_static_tls();
1921 if (optimized_type
== tls::TLSOPT_NONE
)
1923 // Create a GOT entry for the tp-relative offset.
1924 Output_data_got
<size
, big_endian
>* got
1925 = target
->got_section(symtab
, layout
);
1926 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1928 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1930 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1931 unsigned int off
= got
->add_constant(0);
1933 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
1935 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
1937 elfcpp::R_SPARC_TLS_TPOFF64
:
1938 elfcpp::R_SPARC_TLS_TPOFF32
),
1942 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1943 unsupported_reloc_local(object
, r_type
);
1946 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1947 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1948 layout
->set_has_static_tls();
1949 if (output_is_shared
)
1951 // We need to create a dynamic relocation.
1952 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1953 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1954 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1955 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
1956 output_section
, data_shndx
,
1957 reloc
.get_r_offset(), 0);
1964 // These are relocations which should only be seen by the
1965 // dynamic linker, and should never be seen here.
1966 case elfcpp::R_SPARC_COPY
:
1967 case elfcpp::R_SPARC_GLOB_DAT
:
1968 case elfcpp::R_SPARC_JMP_SLOT
:
1969 case elfcpp::R_SPARC_RELATIVE
:
1970 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1971 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1972 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1973 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1974 case elfcpp::R_SPARC_TLS_TPOFF64
:
1975 case elfcpp::R_SPARC_TLS_TPOFF32
:
1976 gold_error(_("%s: unexpected reloc %u in object file"),
1977 object
->name().c_str(), r_type
);
1981 unsupported_reloc_local(object
, r_type
);
1986 // Report an unsupported relocation against a global symbol.
1988 template<int size
, bool big_endian
>
1990 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1991 Sized_relobj
<size
, big_endian
>* object
,
1992 unsigned int r_type
,
1995 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1996 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1999 // Scan a relocation for a global symbol.
2001 template<int size
, bool big_endian
>
2003 Target_sparc
<size
, big_endian
>::Scan::global(
2004 Symbol_table
* symtab
,
2006 Target_sparc
<size
, big_endian
>* target
,
2007 Sized_relobj
<size
, big_endian
>* object
,
2008 unsigned int data_shndx
,
2009 Output_section
* output_section
,
2010 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2011 unsigned int r_type
,
2014 unsigned int orig_r_type
= r_type
;
2016 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2017 // section. We check here to avoid creating a dynamic reloc against
2018 // _GLOBAL_OFFSET_TABLE_.
2019 if (!target
->has_got_section()
2020 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2021 target
->got_section(symtab
, layout
);
2026 case elfcpp::R_SPARC_NONE
:
2027 case elfcpp::R_SPARC_REGISTER
:
2028 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2029 case elfcpp::R_SPARC_GNU_VTENTRY
:
2032 case elfcpp::R_SPARC_PLT64
:
2033 case elfcpp::R_SPARC_PLT32
:
2034 case elfcpp::R_SPARC_HIPLT22
:
2035 case elfcpp::R_SPARC_LOPLT10
:
2036 case elfcpp::R_SPARC_PCPLT32
:
2037 case elfcpp::R_SPARC_PCPLT22
:
2038 case elfcpp::R_SPARC_PCPLT10
:
2039 case elfcpp::R_SPARC_WPLT30
:
2040 // If the symbol is fully resolved, this is just a PC32 reloc.
2041 // Otherwise we need a PLT entry.
2042 if (gsym
->final_value_is_known())
2044 // If building a shared library, we can also skip the PLT entry
2045 // if the symbol is defined in the output file and is protected
2047 if (gsym
->is_defined()
2048 && !gsym
->is_from_dynobj()
2049 && !gsym
->is_preemptible())
2051 target
->make_plt_entry(symtab
, layout
, gsym
);
2054 case elfcpp::R_SPARC_DISP8
:
2055 case elfcpp::R_SPARC_DISP16
:
2056 case elfcpp::R_SPARC_DISP32
:
2057 case elfcpp::R_SPARC_DISP64
:
2058 case elfcpp::R_SPARC_PC_HH22
:
2059 case elfcpp::R_SPARC_PC_HM10
:
2060 case elfcpp::R_SPARC_PC_LM22
:
2061 case elfcpp::R_SPARC_PC10
:
2062 case elfcpp::R_SPARC_PC22
:
2063 case elfcpp::R_SPARC_WDISP30
:
2064 case elfcpp::R_SPARC_WDISP22
:
2065 case elfcpp::R_SPARC_WDISP19
:
2066 case elfcpp::R_SPARC_WDISP16
:
2068 if (gsym
->needs_plt_entry())
2069 target
->make_plt_entry(symtab
, layout
, gsym
);
2070 // Make a dynamic relocation if necessary.
2071 int flags
= Symbol::NON_PIC_REF
;
2072 if (gsym
->type() == elfcpp::STT_FUNC
)
2073 flags
|= Symbol::FUNCTION_CALL
;
2074 if (gsym
->needs_dynamic_reloc(flags
))
2076 if (gsym
->may_need_copy_reloc())
2078 target
->copy_reloc(symtab
, layout
, object
,
2079 data_shndx
, output_section
, gsym
,
2084 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2085 check_non_pic(object
, r_type
);
2086 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2087 data_shndx
, reloc
.get_r_offset(),
2088 reloc
.get_r_addend());
2094 case elfcpp::R_SPARC_UA64
:
2095 case elfcpp::R_SPARC_64
:
2096 case elfcpp::R_SPARC_HIX22
:
2097 case elfcpp::R_SPARC_LOX10
:
2098 case elfcpp::R_SPARC_H44
:
2099 case elfcpp::R_SPARC_M44
:
2100 case elfcpp::R_SPARC_L44
:
2101 case elfcpp::R_SPARC_HH22
:
2102 case elfcpp::R_SPARC_HM10
:
2103 case elfcpp::R_SPARC_LM22
:
2104 case elfcpp::R_SPARC_HI22
:
2105 case elfcpp::R_SPARC_LO10
:
2106 case elfcpp::R_SPARC_OLO10
:
2107 case elfcpp::R_SPARC_UA32
:
2108 case elfcpp::R_SPARC_32
:
2109 case elfcpp::R_SPARC_UA16
:
2110 case elfcpp::R_SPARC_16
:
2111 case elfcpp::R_SPARC_11
:
2112 case elfcpp::R_SPARC_10
:
2113 case elfcpp::R_SPARC_8
:
2114 case elfcpp::R_SPARC_7
:
2115 case elfcpp::R_SPARC_6
:
2116 case elfcpp::R_SPARC_5
:
2118 // Make a PLT entry if necessary.
2119 if (gsym
->needs_plt_entry())
2121 target
->make_plt_entry(symtab
, layout
, gsym
);
2122 // Since this is not a PC-relative relocation, we may be
2123 // taking the address of a function. In that case we need to
2124 // set the entry in the dynamic symbol table to the address of
2126 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2127 gsym
->set_needs_dynsym_value();
2129 // Make a dynamic relocation if necessary.
2130 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2132 unsigned int r_off
= reloc
.get_r_offset();
2134 // The assembler can sometimes emit unaligned relocations
2135 // for dwarf2 cfi directives.
2138 case elfcpp::R_SPARC_16
:
2140 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2142 case elfcpp::R_SPARC_32
:
2144 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2146 case elfcpp::R_SPARC_64
:
2148 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2150 case elfcpp::R_SPARC_UA16
:
2152 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2154 case elfcpp::R_SPARC_UA32
:
2156 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2158 case elfcpp::R_SPARC_UA64
:
2160 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2164 if (gsym
->may_need_copy_reloc())
2166 target
->copy_reloc(symtab
, layout
, object
,
2167 data_shndx
, output_section
, gsym
, reloc
);
2169 else if ((r_type
== elfcpp::R_SPARC_32
2170 || r_type
== elfcpp::R_SPARC_64
)
2171 && gsym
->can_use_relative_reloc(false))
2173 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2174 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2175 output_section
, object
,
2176 data_shndx
, reloc
.get_r_offset(),
2177 reloc
.get_r_addend());
2181 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2183 check_non_pic(object
, r_type
);
2184 if (gsym
->is_from_dynobj()
2185 || gsym
->is_undefined()
2186 || gsym
->is_preemptible())
2187 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2189 reloc
.get_r_offset(),
2190 reloc
.get_r_addend());
2192 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2195 reloc
.get_r_offset(),
2196 reloc
.get_r_addend());
2202 case elfcpp::R_SPARC_GOTDATA_OP
:
2203 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2204 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2205 case elfcpp::R_SPARC_GOT10
:
2206 case elfcpp::R_SPARC_GOT13
:
2207 case elfcpp::R_SPARC_GOT22
:
2209 // The symbol requires a GOT entry.
2210 Output_data_got
<size
, big_endian
>* got
;
2212 got
= target
->got_section(symtab
, layout
);
2213 if (gsym
->final_value_is_known())
2214 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2217 // If this symbol is not fully resolved, we need to add a
2218 // dynamic relocation for it.
2219 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2220 if (gsym
->is_from_dynobj()
2221 || gsym
->is_undefined()
2222 || gsym
->is_preemptible())
2223 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2224 elfcpp::R_SPARC_GLOB_DAT
);
2225 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2227 unsigned int off
= got
->add_constant(0);
2229 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2230 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2237 // These are initial tls relocs, which are expected when
2239 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2240 case elfcpp::R_SPARC_TLS_GD_LO10
:
2241 case elfcpp::R_SPARC_TLS_GD_ADD
:
2242 case elfcpp::R_SPARC_TLS_GD_CALL
:
2243 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2244 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2245 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2246 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2247 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2248 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2249 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2250 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2251 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2252 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2253 case elfcpp::R_SPARC_TLS_IE_LO10
:
2254 case elfcpp::R_SPARC_TLS_IE_LD
:
2255 case elfcpp::R_SPARC_TLS_IE_LDX
:
2256 case elfcpp::R_SPARC_TLS_IE_ADD
:
2258 const bool is_final
= gsym
->final_value_is_known();
2259 const tls::Tls_optimization optimized_type
2260 = optimize_tls_reloc(is_final
, r_type
);
2263 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2264 case elfcpp::R_SPARC_TLS_GD_LO10
:
2265 case elfcpp::R_SPARC_TLS_GD_ADD
:
2266 case elfcpp::R_SPARC_TLS_GD_CALL
:
2267 if (optimized_type
== tls::TLSOPT_NONE
)
2269 // Create a pair of GOT entries for the module index and
2270 // dtv-relative offset.
2271 Output_data_got
<size
, big_endian
>* got
2272 = target
->got_section(symtab
, layout
);
2273 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2274 target
->rela_dyn_section(layout
),
2276 elfcpp::R_SPARC_TLS_DTPMOD64
:
2277 elfcpp::R_SPARC_TLS_DTPMOD32
),
2279 elfcpp::R_SPARC_TLS_DTPOFF64
:
2280 elfcpp::R_SPARC_TLS_DTPOFF32
));
2282 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2283 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2284 generate_tls_call(symtab
, layout
, target
);
2286 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2288 // Create a GOT entry for the tp-relative offset.
2289 Output_data_got
<size
, big_endian
>* got
2290 = target
->got_section(symtab
, layout
);
2291 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2292 target
->rela_dyn_section(layout
),
2294 elfcpp::R_SPARC_TLS_TPOFF64
:
2295 elfcpp::R_SPARC_TLS_TPOFF32
));
2297 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2298 unsupported_reloc_global(object
, r_type
, gsym
);
2301 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2302 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2303 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2304 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2305 if (optimized_type
== tls::TLSOPT_NONE
)
2307 // Create a GOT entry for the module index.
2308 target
->got_mod_index_entry(symtab
, layout
, object
);
2310 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2311 generate_tls_call(symtab
, layout
, target
);
2313 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2314 unsupported_reloc_global(object
, r_type
, gsym
);
2317 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2318 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2319 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2322 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2323 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2324 layout
->set_has_static_tls();
2325 if (parameters
->options().shared())
2327 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2328 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2329 output_section
, object
,
2330 data_shndx
, reloc
.get_r_offset(),
2335 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2336 case elfcpp::R_SPARC_TLS_IE_LO10
:
2337 case elfcpp::R_SPARC_TLS_IE_LD
:
2338 case elfcpp::R_SPARC_TLS_IE_LDX
:
2339 case elfcpp::R_SPARC_TLS_IE_ADD
:
2340 layout
->set_has_static_tls();
2341 if (optimized_type
== tls::TLSOPT_NONE
)
2343 // Create a GOT entry for the tp-relative offset.
2344 Output_data_got
<size
, big_endian
>* got
2345 = target
->got_section(symtab
, layout
);
2346 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2347 target
->rela_dyn_section(layout
),
2349 elfcpp::R_SPARC_TLS_TPOFF64
:
2350 elfcpp::R_SPARC_TLS_TPOFF32
));
2352 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2353 unsupported_reloc_global(object
, r_type
, gsym
);
2359 // These are relocations which should only be seen by the
2360 // dynamic linker, and should never be seen here.
2361 case elfcpp::R_SPARC_COPY
:
2362 case elfcpp::R_SPARC_GLOB_DAT
:
2363 case elfcpp::R_SPARC_JMP_SLOT
:
2364 case elfcpp::R_SPARC_RELATIVE
:
2365 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2366 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2367 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2368 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2369 case elfcpp::R_SPARC_TLS_TPOFF64
:
2370 case elfcpp::R_SPARC_TLS_TPOFF32
:
2371 gold_error(_("%s: unexpected reloc %u in object file"),
2372 object
->name().c_str(), r_type
);
2376 unsupported_reloc_global(object
, r_type
, gsym
);
2381 // Process relocations for gc.
2383 template<int size
, bool big_endian
>
2385 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2386 Symbol_table
* symtab
,
2388 Sized_relobj
<size
, big_endian
>* object
,
2389 unsigned int data_shndx
,
2391 const unsigned char* prelocs
,
2393 Output_section
* output_section
,
2394 bool needs_special_offset_handling
,
2395 size_t local_symbol_count
,
2396 const unsigned char* plocal_symbols
)
2398 typedef Target_sparc
<size
, big_endian
> Sparc
;
2399 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2401 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
2402 typename
Target_sparc::Relocatable_size_for_reloc
>(
2411 needs_special_offset_handling
,
2416 // Scan relocations for a section.
2418 template<int size
, bool big_endian
>
2420 Target_sparc
<size
, big_endian
>::scan_relocs(
2421 Symbol_table
* symtab
,
2423 Sized_relobj
<size
, big_endian
>* object
,
2424 unsigned int data_shndx
,
2425 unsigned int sh_type
,
2426 const unsigned char* prelocs
,
2428 Output_section
* output_section
,
2429 bool needs_special_offset_handling
,
2430 size_t local_symbol_count
,
2431 const unsigned char* plocal_symbols
)
2433 typedef Target_sparc
<size
, big_endian
> Sparc
;
2434 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2436 if (sh_type
== elfcpp::SHT_REL
)
2438 gold_error(_("%s: unsupported REL reloc section"),
2439 object
->name().c_str());
2443 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2452 needs_special_offset_handling
,
2457 // Finalize the sections.
2459 template<int size
, bool big_endian
>
2461 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2463 const Input_objects
*,
2466 // Fill in some more dynamic tags.
2467 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2469 : this->plt_
->rel_plt());
2470 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2471 this->rela_dyn_
, true, true);
2473 // Emit any relocs we saved in an attempt to avoid generating COPY
2475 if (this->copy_relocs_
.any_saved_relocs())
2476 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2479 // Perform a relocation.
2481 template<int size
, bool big_endian
>
2483 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2484 const Relocate_info
<size
, big_endian
>* relinfo
,
2485 Target_sparc
* target
,
2488 const elfcpp::Rela
<size
, big_endian
>& rela
,
2489 unsigned int r_type
,
2490 const Sized_symbol
<size
>* gsym
,
2491 const Symbol_value
<size
>* psymval
,
2492 unsigned char* view
,
2493 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2494 section_size_type view_size
)
2498 if (this->ignore_gd_add_
)
2500 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2501 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2502 _("missing expected TLS relocation"));
2505 this->ignore_gd_add_
= false;
2510 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2512 // Pick the value to use for symbols defined in shared objects.
2513 Symbol_value
<size
> symval
;
2515 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2516 || r_type
== elfcpp::R_SPARC_DISP16
2517 || r_type
== elfcpp::R_SPARC_DISP32
2518 || r_type
== elfcpp::R_SPARC_DISP64
2519 || r_type
== elfcpp::R_SPARC_PC_HH22
2520 || r_type
== elfcpp::R_SPARC_PC_HM10
2521 || r_type
== elfcpp::R_SPARC_PC_LM22
2522 || r_type
== elfcpp::R_SPARC_PC10
2523 || r_type
== elfcpp::R_SPARC_PC22
2524 || r_type
== elfcpp::R_SPARC_WDISP30
2525 || r_type
== elfcpp::R_SPARC_WDISP22
2526 || r_type
== elfcpp::R_SPARC_WDISP19
2527 || r_type
== elfcpp::R_SPARC_WDISP16
))
2529 elfcpp::Elf_Xword value
;
2531 value
= target
->plt_section()->address() + gsym
->plt_offset();
2533 symval
.set_output_value(value
);
2538 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2539 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2541 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2542 // pointer points to the beginning, not the end, of the table.
2543 // So we just use the plain offset.
2544 unsigned int got_offset
= 0;
2547 case elfcpp::R_SPARC_GOTDATA_OP
:
2548 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2549 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2550 case elfcpp::R_SPARC_GOT10
:
2551 case elfcpp::R_SPARC_GOT13
:
2552 case elfcpp::R_SPARC_GOT22
:
2555 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2556 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2560 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2561 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2562 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2572 case elfcpp::R_SPARC_NONE
:
2573 case elfcpp::R_SPARC_REGISTER
:
2574 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2575 case elfcpp::R_SPARC_GNU_VTENTRY
:
2578 case elfcpp::R_SPARC_8
:
2579 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2583 case elfcpp::R_SPARC_16
:
2584 if (rela
.get_r_offset() & 0x1)
2586 // The assembler can sometimes emit unaligned relocations
2587 // for dwarf2 cfi directives.
2588 Reloc::ua16(view
, object
, psymval
, addend
);
2591 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2595 case elfcpp::R_SPARC_32
:
2596 if (!parameters
->options().output_is_position_independent())
2598 if (rela
.get_r_offset() & 0x3)
2600 // The assembler can sometimes emit unaligned relocations
2601 // for dwarf2 cfi directives.
2602 Reloc::ua32(view
, object
, psymval
, addend
);
2605 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2610 case elfcpp::R_SPARC_DISP8
:
2611 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2614 case elfcpp::R_SPARC_DISP16
:
2615 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2618 case elfcpp::R_SPARC_DISP32
:
2619 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2622 case elfcpp::R_SPARC_DISP64
:
2623 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2626 case elfcpp::R_SPARC_WDISP30
:
2627 case elfcpp::R_SPARC_WPLT30
:
2628 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2631 case elfcpp::R_SPARC_WDISP22
:
2632 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2635 case elfcpp::R_SPARC_WDISP19
:
2636 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2639 case elfcpp::R_SPARC_WDISP16
:
2640 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2643 case elfcpp::R_SPARC_HI22
:
2644 Reloc::hi22(view
, object
, psymval
, addend
);
2647 case elfcpp::R_SPARC_22
:
2648 Reloc::rela32_22(view
, object
, psymval
, addend
);
2651 case elfcpp::R_SPARC_13
:
2652 Reloc::rela32_13(view
, object
, psymval
, addend
);
2655 case elfcpp::R_SPARC_LO10
:
2656 Reloc::lo10(view
, object
, psymval
, addend
);
2659 case elfcpp::R_SPARC_GOT10
:
2660 Reloc::lo10(view
, got_offset
, addend
);
2663 case elfcpp::R_SPARC_GOTDATA_OP
:
2666 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2667 case elfcpp::R_SPARC_GOT13
:
2668 Reloc::rela32_13(view
, got_offset
, addend
);
2671 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2672 case elfcpp::R_SPARC_GOT22
:
2673 Reloc::hi22(view
, got_offset
, addend
);
2676 case elfcpp::R_SPARC_PC10
:
2677 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2680 case elfcpp::R_SPARC_PC22
:
2681 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2684 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2685 case elfcpp::R_SPARC_UA32
:
2686 Reloc::ua32(view
, object
, psymval
, addend
);
2689 case elfcpp::R_SPARC_PLT64
:
2690 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2694 case elfcpp::R_SPARC_PLT32
:
2695 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2699 case elfcpp::R_SPARC_HIPLT22
:
2700 Reloc::hi22(view
, object
, psymval
, addend
);
2703 case elfcpp::R_SPARC_LOPLT10
:
2704 Reloc::lo10(view
, object
, psymval
, addend
);
2707 case elfcpp::R_SPARC_PCPLT32
:
2708 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2711 case elfcpp::R_SPARC_PCPLT22
:
2712 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2715 case elfcpp::R_SPARC_PCPLT10
:
2716 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2719 case elfcpp::R_SPARC_64
:
2720 if (!parameters
->options().output_is_position_independent())
2722 if (rela
.get_r_offset() & 0x7)
2724 // The assembler can sometimes emit unaligned relocations
2725 // for dwarf2 cfi directives.
2726 Reloc::ua64(view
, object
, psymval
, addend
);
2729 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2734 case elfcpp::R_SPARC_OLO10
:
2736 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2737 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2738 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2742 case elfcpp::R_SPARC_HH22
:
2743 Reloc::hh22(view
, object
, psymval
, addend
);
2746 case elfcpp::R_SPARC_PC_HH22
:
2747 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2750 case elfcpp::R_SPARC_HM10
:
2751 Reloc::hm10(view
, object
, psymval
, addend
);
2754 case elfcpp::R_SPARC_PC_HM10
:
2755 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2758 case elfcpp::R_SPARC_LM22
:
2759 Reloc::hi22(view
, object
, psymval
, addend
);
2762 case elfcpp::R_SPARC_PC_LM22
:
2763 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2766 case elfcpp::R_SPARC_11
:
2767 Reloc::rela32_11(view
, object
, psymval
, addend
);
2770 case elfcpp::R_SPARC_10
:
2771 Reloc::rela32_10(view
, object
, psymval
, addend
);
2774 case elfcpp::R_SPARC_7
:
2775 Reloc::rela32_7(view
, object
, psymval
, addend
);
2778 case elfcpp::R_SPARC_6
:
2779 Reloc::rela32_6(view
, object
, psymval
, addend
);
2782 case elfcpp::R_SPARC_5
:
2783 Reloc::rela32_5(view
, object
, psymval
, addend
);
2786 case elfcpp::R_SPARC_HIX22
:
2787 Reloc::hix22(view
, object
, psymval
, addend
);
2790 case elfcpp::R_SPARC_LOX10
:
2791 Reloc::lox10(view
, object
, psymval
, addend
);
2794 case elfcpp::R_SPARC_H44
:
2795 Reloc::h44(view
, object
, psymval
, addend
);
2798 case elfcpp::R_SPARC_M44
:
2799 Reloc::m44(view
, object
, psymval
, addend
);
2802 case elfcpp::R_SPARC_L44
:
2803 Reloc::l44(view
, object
, psymval
, addend
);
2806 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2807 case elfcpp::R_SPARC_UA64
:
2808 Reloc::ua64(view
, object
, psymval
, addend
);
2811 case elfcpp::R_SPARC_UA16
:
2812 Reloc::ua16(view
, object
, psymval
, addend
);
2815 case elfcpp::R_SPARC_TLS_GD_HI22
:
2816 case elfcpp::R_SPARC_TLS_GD_LO10
:
2817 case elfcpp::R_SPARC_TLS_GD_ADD
:
2818 case elfcpp::R_SPARC_TLS_GD_CALL
:
2819 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2820 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2821 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2822 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2823 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2824 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2825 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2826 case elfcpp::R_SPARC_TLS_IE_HI22
:
2827 case elfcpp::R_SPARC_TLS_IE_LO10
:
2828 case elfcpp::R_SPARC_TLS_IE_LD
:
2829 case elfcpp::R_SPARC_TLS_IE_LDX
:
2830 case elfcpp::R_SPARC_TLS_IE_ADD
:
2831 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2832 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2833 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2834 r_type
, gsym
, psymval
, view
,
2835 address
, view_size
);
2838 case elfcpp::R_SPARC_COPY
:
2839 case elfcpp::R_SPARC_GLOB_DAT
:
2840 case elfcpp::R_SPARC_JMP_SLOT
:
2841 case elfcpp::R_SPARC_RELATIVE
:
2842 // These are outstanding tls relocs, which are unexpected when
2844 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2845 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2846 case elfcpp::R_SPARC_TLS_TPOFF64
:
2847 case elfcpp::R_SPARC_TLS_TPOFF32
:
2848 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2849 _("unexpected reloc %u in object file"),
2854 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2855 _("unsupported reloc %u"),
2863 // Perform a TLS relocation.
2865 template<int size
, bool big_endian
>
2867 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2868 const Relocate_info
<size
, big_endian
>* relinfo
,
2869 Target_sparc
<size
, big_endian
>* target
,
2871 const elfcpp::Rela
<size
, big_endian
>& rela
,
2872 unsigned int r_type
,
2873 const Sized_symbol
<size
>* gsym
,
2874 const Symbol_value
<size
>* psymval
,
2875 unsigned char* view
,
2876 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2879 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2880 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2881 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2882 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2884 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2885 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2887 const bool is_final
=
2889 ? !parameters
->options().output_is_position_independent()
2890 : gsym
->final_value_is_known());
2891 const tls::Tls_optimization optimized_type
2892 = optimize_tls_reloc(is_final
, r_type
);
2896 case elfcpp::R_SPARC_TLS_GD_HI22
:
2897 case elfcpp::R_SPARC_TLS_GD_LO10
:
2898 case elfcpp::R_SPARC_TLS_GD_ADD
:
2899 case elfcpp::R_SPARC_TLS_GD_CALL
:
2900 if (optimized_type
== tls::TLSOPT_TO_LE
)
2902 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2905 value
-= tls_segment
->memsz();
2909 case elfcpp::R_SPARC_TLS_GD_HI22
:
2910 // TLS_GD_HI22 --> TLS_LE_HIX22
2911 Reloc::hix22(view
, value
, addend
);
2914 case elfcpp::R_SPARC_TLS_GD_LO10
:
2915 // TLS_GD_LO10 --> TLS_LE_LOX10
2916 Reloc::lox10(view
, value
, addend
);
2919 case elfcpp::R_SPARC_TLS_GD_ADD
:
2920 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2921 val
= elfcpp::Swap
<32, true>::readval(wv
);
2922 val
= (val
& ~0x7c000) | 0x1c000;
2923 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2925 case elfcpp::R_SPARC_TLS_GD_CALL
:
2926 // call __tls_get_addr --> nop
2927 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2934 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2935 ? GOT_TYPE_TLS_OFFSET
2936 : GOT_TYPE_TLS_PAIR
);
2939 gold_assert(gsym
->has_got_offset(got_type
));
2940 value
= gsym
->got_offset(got_type
);
2944 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2945 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2946 value
= object
->local_got_offset(r_sym
, got_type
);
2948 if (optimized_type
== tls::TLSOPT_TO_IE
)
2950 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2955 case elfcpp::R_SPARC_TLS_GD_HI22
:
2956 // TLS_GD_HI22 --> TLS_IE_HI22
2957 Reloc::hi22(view
, value
, addend
);
2960 case elfcpp::R_SPARC_TLS_GD_LO10
:
2961 // TLS_GD_LO10 --> TLS_IE_LO10
2962 Reloc::lo10(view
, value
, addend
);
2965 case elfcpp::R_SPARC_TLS_GD_ADD
:
2966 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2967 val
= elfcpp::Swap
<32, true>::readval(wv
);
2974 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2977 case elfcpp::R_SPARC_TLS_GD_CALL
:
2978 // The compiler can put the TLS_GD_ADD instruction
2979 // into the delay slot of the call. If so, we need
2980 // to transpose the two instructions so that the
2981 // the new sequence works properly.
2983 // The test we use is if the instruction in the
2984 // delay slot is an add with destination register
2986 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2987 if ((val
& 0x81f80000) == 0x80000000
2988 && ((val
>> 25) & 0x1f) == 0x8)
2995 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2998 this->ignore_gd_add_
= true;
3001 // call __tls_get_addr --> add %g7, %o0, %o0
3002 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3007 else if (optimized_type
== tls::TLSOPT_NONE
)
3011 case elfcpp::R_SPARC_TLS_GD_HI22
:
3012 Reloc::hi22(view
, value
, addend
);
3014 case elfcpp::R_SPARC_TLS_GD_LO10
:
3015 Reloc::lo10(view
, value
, addend
);
3017 case elfcpp::R_SPARC_TLS_GD_ADD
:
3019 case elfcpp::R_SPARC_TLS_GD_CALL
:
3021 Symbol_value
<size
> symval
;
3022 elfcpp::Elf_Xword value
;
3025 tsym
= target
->tls_get_addr_sym_
;
3027 value
= (target
->plt_section()->address() +
3028 tsym
->plt_offset());
3029 symval
.set_output_value(value
);
3030 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3037 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3038 _("unsupported reloc %u"),
3042 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3043 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3044 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3045 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3046 if (optimized_type
== tls::TLSOPT_TO_LE
)
3048 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3052 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3053 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3054 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3055 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3058 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3059 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3064 else if (optimized_type
== tls::TLSOPT_NONE
)
3066 // Relocate the field with the offset of the GOT entry for
3067 // the module index.
3068 unsigned int got_offset
;
3070 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3073 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3074 Reloc::hi22(view
, got_offset
, addend
);
3076 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3077 Reloc::lo10(view
, got_offset
, addend
);
3079 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3081 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3083 Symbol_value
<size
> symval
;
3084 elfcpp::Elf_Xword value
;
3087 tsym
= target
->tls_get_addr_sym_
;
3089 value
= (target
->plt_section()->address() +
3090 tsym
->plt_offset());
3091 symval
.set_output_value(value
);
3092 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3098 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3099 _("unsupported reloc %u"),
3103 // These relocs can appear in debugging sections, in which case
3104 // we won't see the TLS_LDM relocs. The local_dynamic_type
3105 // field tells us this.
3106 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3107 if (optimized_type
== tls::TLSOPT_TO_LE
)
3109 value
-= tls_segment
->memsz();
3110 Reloc::hix22(view
, value
, addend
);
3113 Reloc::ldo_hix22(view
, value
, addend
);
3115 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3116 if (optimized_type
== tls::TLSOPT_TO_LE
)
3118 value
-= tls_segment
->memsz();
3119 Reloc::lox10(view
, value
, addend
);
3122 Reloc::ldo_lox10(view
, value
, addend
);
3124 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3125 if (optimized_type
== tls::TLSOPT_TO_LE
)
3127 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3130 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3131 val
= elfcpp::Swap
<32, true>::readval(wv
);
3132 val
= (val
& ~0x7c000) | 0x1c000;
3133 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3137 // When optimizing IE --> LE, the only relocation that is handled
3138 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3139 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3140 // rs2 and rd are the same.
3141 case elfcpp::R_SPARC_TLS_IE_LD
:
3142 case elfcpp::R_SPARC_TLS_IE_LDX
:
3143 if (optimized_type
== tls::TLSOPT_TO_LE
)
3145 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3146 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3147 Insntype rs2
= val
& 0x1f;
3148 Insntype rd
= (val
>> 25) & 0x1f;
3153 val
= sparc_mov
| (val
& 0x3e00001f);
3155 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3159 case elfcpp::R_SPARC_TLS_IE_HI22
:
3160 case elfcpp::R_SPARC_TLS_IE_LO10
:
3161 if (optimized_type
== tls::TLSOPT_TO_LE
)
3163 value
-= tls_segment
->memsz();
3166 case elfcpp::R_SPARC_TLS_IE_HI22
:
3167 // IE_HI22 --> LE_HIX22
3168 Reloc::hix22(view
, value
, addend
);
3170 case elfcpp::R_SPARC_TLS_IE_LO10
:
3171 // IE_LO10 --> LE_LOX10
3172 Reloc::lox10(view
, value
, addend
);
3177 else if (optimized_type
== tls::TLSOPT_NONE
)
3179 // Relocate the field with the offset of the GOT entry for
3180 // the tp-relative offset of the symbol.
3183 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3184 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3188 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3189 gold_assert(object
->local_has_got_offset(r_sym
,
3190 GOT_TYPE_TLS_OFFSET
));
3191 value
= object
->local_got_offset(r_sym
,
3192 GOT_TYPE_TLS_OFFSET
);
3196 case elfcpp::R_SPARC_TLS_IE_HI22
:
3197 Reloc::hi22(view
, value
, addend
);
3199 case elfcpp::R_SPARC_TLS_IE_LO10
:
3200 Reloc::lo10(view
, value
, addend
);
3205 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3206 _("unsupported reloc %u"),
3210 case elfcpp::R_SPARC_TLS_IE_ADD
:
3211 // This seems to be mainly so that we can find the addition
3212 // instruction if there is one. There doesn't seem to be any
3213 // actual relocation to apply.
3216 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3217 // If we're creating a shared library, a dynamic relocation will
3218 // have been created for this location, so do not apply it now.
3219 if (!parameters
->options().shared())
3221 value
-= tls_segment
->memsz();
3222 Reloc::hix22(view
, value
, addend
);
3226 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3227 // If we're creating a shared library, a dynamic relocation will
3228 // have been created for this location, so do not apply it now.
3229 if (!parameters
->options().shared())
3231 value
-= tls_segment
->memsz();
3232 Reloc::lox10(view
, value
, addend
);
3238 // Relocate section data.
3240 template<int size
, bool big_endian
>
3242 Target_sparc
<size
, big_endian
>::relocate_section(
3243 const Relocate_info
<size
, big_endian
>* relinfo
,
3244 unsigned int sh_type
,
3245 const unsigned char* prelocs
,
3247 Output_section
* output_section
,
3248 bool needs_special_offset_handling
,
3249 unsigned char* view
,
3250 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3251 section_size_type view_size
,
3252 const Reloc_symbol_changes
* reloc_symbol_changes
)
3254 typedef Target_sparc
<size
, big_endian
> Sparc
;
3255 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3257 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3259 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3266 needs_special_offset_handling
,
3270 reloc_symbol_changes
);
3273 // Return the size of a relocation while scanning during a relocatable
3276 template<int size
, bool big_endian
>
3278 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3282 // We are always SHT_RELA, so we should never get here.
3287 // Scan the relocs during a relocatable link.
3289 template<int size
, bool big_endian
>
3291 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3292 Symbol_table
* symtab
,
3294 Sized_relobj
<size
, big_endian
>* object
,
3295 unsigned int data_shndx
,
3296 unsigned int sh_type
,
3297 const unsigned char* prelocs
,
3299 Output_section
* output_section
,
3300 bool needs_special_offset_handling
,
3301 size_t local_symbol_count
,
3302 const unsigned char* plocal_symbols
,
3303 Relocatable_relocs
* rr
)
3305 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3307 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3308 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3310 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3311 Scan_relocatable_relocs
>(
3319 needs_special_offset_handling
,
3325 // Relocate a section during a relocatable link.
3327 template<int size
, bool big_endian
>
3329 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3330 const Relocate_info
<size
, big_endian
>* relinfo
,
3331 unsigned int sh_type
,
3332 const unsigned char* prelocs
,
3334 Output_section
* output_section
,
3335 off_t offset_in_output_section
,
3336 const Relocatable_relocs
* rr
,
3337 unsigned char* view
,
3338 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3339 section_size_type view_size
,
3340 unsigned char* reloc_view
,
3341 section_size_type reloc_view_size
)
3343 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3345 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3350 offset_in_output_section
,
3359 // Return the value to use for a dynamic which requires special
3360 // treatment. This is how we support equality comparisons of function
3361 // pointers across shared library boundaries, as described in the
3362 // processor specific ABI supplement.
3364 template<int size
, bool big_endian
>
3366 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3368 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3369 return this->plt_section()->address() + gsym
->plt_offset();
3372 // The selector for sparc object files.
3374 template<int size
, bool big_endian
>
3375 class Target_selector_sparc
: public Target_selector
3378 Target_selector_sparc()
3379 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3380 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3383 Target
* do_recognize(int machine
, int, int)
3388 if (machine
!= elfcpp::EM_SPARCV9
)
3393 if (machine
!= elfcpp::EM_SPARC
3394 && machine
!= elfcpp::EM_SPARC32PLUS
)
3402 return this->instantiate_target();
3405 Target
* do_instantiate_target()
3406 { return new Target_sparc
<size
, big_endian
>(); }
3409 Target_selector_sparc
<32, true> target_selector_sparc32
;
3410 Target_selector_sparc
<64, true> target_selector_sparc64
;
3412 } // End anonymous namespace.