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 get_reference_flags(unsigned int r_type
);
205 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
206 Sized_relobj
<size
, big_endian
>* object
,
207 unsigned int data_shndx
,
208 Output_section
* output_section
,
209 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
210 const elfcpp::Sym
<size
, big_endian
>& lsym
);
213 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
214 Sized_relobj
<size
, big_endian
>* object
,
215 unsigned int data_shndx
,
216 Output_section
* output_section
,
217 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
221 local_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
223 Sized_relobj
<size
, big_endian
>* ,
226 const elfcpp::Rela
<size
, big_endian
>& ,
228 const elfcpp::Sym
<size
, big_endian
>&)
232 global_reloc_may_be_function_pointer(Symbol_table
* , Layout
* ,
234 Sized_relobj
<size
, big_endian
>* ,
237 const elfcpp::Rela
<size
,
239 unsigned int , Symbol
*)
245 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
246 unsigned int r_type
);
249 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
250 unsigned int r_type
, Symbol
*);
253 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
254 Target_sparc
* target
);
257 check_non_pic(Relobj
*, unsigned int r_type
);
259 // Whether we have issued an error about a non-PIC compilation.
260 bool issued_non_pic_error_
;
263 // The class which implements relocation.
268 : ignore_gd_add_(false)
273 if (this->ignore_gd_add_
)
275 // FIXME: This needs to specify the location somehow.
276 gold_error(_("missing expected TLS relocation"));
280 // Do a relocation. Return false if the caller should not issue
281 // any warnings about this relocation.
283 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
284 Output_section
*, size_t relnum
,
285 const elfcpp::Rela
<size
, big_endian
>&,
286 unsigned int r_type
, const Sized_symbol
<size
>*,
287 const Symbol_value
<size
>*,
289 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
293 // Do a TLS relocation.
295 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
296 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
297 unsigned int r_type
, const Sized_symbol
<size
>*,
298 const Symbol_value
<size
>*,
300 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
303 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
307 // A class which returns the size required for a relocation type,
308 // used while scanning relocs during a relocatable link.
309 class Relocatable_size_for_reloc
313 get_size_for_reloc(unsigned int, Relobj
*);
316 // Get the GOT section, creating it if necessary.
317 Output_data_got
<size
, big_endian
>*
318 got_section(Symbol_table
*, Layout
*);
320 // Create a PLT entry for a global symbol.
322 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
324 // Create a GOT entry for the TLS module index.
326 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
327 Sized_relobj
<size
, big_endian
>* object
);
329 // Return the gsym for "__tls_get_addr". Cache if not already
332 tls_get_addr_sym(Symbol_table
* symtab
)
334 if (!this->tls_get_addr_sym_
)
335 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
336 gold_assert(this->tls_get_addr_sym_
);
337 return this->tls_get_addr_sym_
;
340 // Get the PLT section.
341 const Output_data_plt_sparc
<size
, big_endian
>*
344 gold_assert(this->plt_
!= NULL
);
348 // Get the dynamic reloc section, creating it if necessary.
350 rela_dyn_section(Layout
*);
352 // Copy a relocation against a global symbol.
354 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
355 Sized_relobj
<size
, big_endian
>* object
,
356 unsigned int shndx
, Output_section
* output_section
,
357 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
359 this->copy_relocs_
.copy_reloc(symtab
, layout
,
360 symtab
->get_sized_symbol
<size
>(sym
),
361 object
, shndx
, output_section
,
362 reloc
, this->rela_dyn_section(layout
));
365 // Information about this specific target which we pass to the
366 // general Target structure.
367 static Target::Target_info sparc_info
;
369 // The types of GOT entries needed for this platform.
370 // These values are exposed to the ABI in an incremental link.
371 // Do not renumber existing values without changing the version
372 // number of the .gnu_incremental_inputs section.
375 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
376 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
377 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
381 Output_data_got
<size
, big_endian
>* got_
;
383 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
384 // The dynamic reloc section.
385 Reloc_section
* rela_dyn_
;
386 // Relocs saved to avoid a COPY reloc.
387 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
388 // Space for variables copied with a COPY reloc.
389 Output_data_space
* dynbss_
;
390 // Offset of the GOT entry for the TLS module index;
391 unsigned int got_mod_index_offset_
;
392 // Cached pointer to __tls_get_addr symbol
393 Symbol
* tls_get_addr_sym_
;
397 Target::Target_info Target_sparc
<32, true>::sparc_info
=
400 true, // is_big_endian
401 elfcpp::EM_SPARC
, // machine_code
402 false, // has_make_symbol
403 false, // has_resolve
404 false, // has_code_fill
405 true, // is_default_stack_executable
407 "/usr/lib/ld.so.1", // dynamic_linker
408 0x00010000, // default_text_segment_address
409 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
410 8 * 1024, // common_pagesize (overridable by -z common-page-size)
411 elfcpp::SHN_UNDEF
, // small_common_shndx
412 elfcpp::SHN_UNDEF
, // large_common_shndx
413 0, // small_common_section_flags
414 0, // large_common_section_flags
415 NULL
, // attributes_section
416 NULL
// attributes_vendor
420 Target::Target_info Target_sparc
<64, true>::sparc_info
=
423 true, // is_big_endian
424 elfcpp::EM_SPARCV9
, // machine_code
425 false, // has_make_symbol
426 false, // has_resolve
427 false, // has_code_fill
428 true, // is_default_stack_executable
430 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
431 0x100000, // default_text_segment_address
432 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
433 8 * 1024, // common_pagesize (overridable by -z common-page-size)
434 elfcpp::SHN_UNDEF
, // small_common_shndx
435 elfcpp::SHN_UNDEF
, // large_common_shndx
436 0, // small_common_section_flags
437 0, // large_common_section_flags
438 NULL
, // attributes_section
439 NULL
// attributes_vendor
442 // We have to take care here, even when operating in little-endian
443 // mode, sparc instructions are still big endian.
444 template<int size
, bool big_endian
>
445 class Sparc_relocate_functions
448 // Do a simple relocation with the addend in the relocation.
449 template<int valsize
>
451 rela(unsigned char* view
,
452 unsigned int right_shift
,
453 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
454 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
455 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
457 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
458 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
459 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
460 Valtype reloc
= ((value
+ addend
) >> right_shift
);
465 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
468 // Do a simple relocation using a symbol value with the addend in
470 template<int valsize
>
472 rela(unsigned char* view
,
473 unsigned int right_shift
,
474 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
475 const Sized_relobj
<size
, big_endian
>* object
,
476 const Symbol_value
<size
>* psymval
,
477 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
479 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
480 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
481 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
482 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
487 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
490 // Do a simple relocation using a symbol value with the addend in
491 // the relocation, unaligned.
492 template<int valsize
>
494 rela_ua(unsigned char* view
,
495 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
496 const Sized_relobj
<size
, big_endian
>* object
,
497 const Symbol_value
<size
>* psymval
,
498 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
500 typedef typename
elfcpp::Swap_unaligned
<valsize
,
501 big_endian
>::Valtype Valtype
;
502 unsigned char* wv
= view
;
503 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
504 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
509 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
512 // Do a simple PC relative relocation with a Symbol_value with the
513 // addend in the relocation.
514 template<int valsize
>
516 pcrela(unsigned char* view
,
517 unsigned int right_shift
,
518 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
519 const Sized_relobj
<size
, big_endian
>* object
,
520 const Symbol_value
<size
>* psymval
,
521 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
522 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
524 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
525 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
526 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
527 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
533 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
536 template<int valsize
>
538 pcrela_unaligned(unsigned char* view
,
539 const Sized_relobj
<size
, big_endian
>* object
,
540 const Symbol_value
<size
>* psymval
,
541 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
542 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
544 typedef typename
elfcpp::Swap_unaligned
<valsize
,
545 big_endian
>::Valtype Valtype
;
546 unsigned char* wv
= view
;
547 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
549 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
552 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
553 typedef Sparc_relocate_functions
<size
, true> This_insn
;
556 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
558 wdisp30(unsigned char* view
,
559 const Sized_relobj
<size
, big_endian
>* object
,
560 const Symbol_value
<size
>* psymval
,
561 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
562 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
564 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
565 psymval
, addend
, address
);
568 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
570 wdisp22(unsigned char* view
,
571 const Sized_relobj
<size
, big_endian
>* object
,
572 const Symbol_value
<size
>* psymval
,
573 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
574 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
576 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
577 psymval
, addend
, address
);
580 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
582 wdisp19(unsigned char* view
,
583 const Sized_relobj
<size
, big_endian
>* object
,
584 const Symbol_value
<size
>* psymval
,
585 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
586 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
588 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
589 psymval
, addend
, address
);
592 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
594 wdisp16(unsigned char* view
,
595 const Sized_relobj
<size
, big_endian
>* object
,
596 const Symbol_value
<size
>* psymval
,
597 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
598 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
600 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
601 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
602 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
603 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
606 // The relocation value is split between the low 14 bits,
608 val
&= ~((0x3 << 20) | 0x3fff);
609 reloc
= (((reloc
& 0xc000) << (20 - 14))
610 | (reloc
& 0x3ffff));
612 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
615 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
617 pc22(unsigned char* view
,
618 const Sized_relobj
<size
, big_endian
>* object
,
619 const Symbol_value
<size
>* psymval
,
620 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
621 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
623 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
624 psymval
, addend
, address
);
627 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
629 pc10(unsigned char* view
,
630 const Sized_relobj
<size
, big_endian
>* object
,
631 const Symbol_value
<size
>* psymval
,
632 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
633 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
635 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
636 psymval
, addend
, address
);
639 // R_SPARC_HI22: (Symbol + Addend) >> 10
641 hi22(unsigned char* view
,
642 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
643 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
645 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
648 // R_SPARC_HI22: (Symbol + Addend) >> 10
650 hi22(unsigned char* view
,
651 const Sized_relobj
<size
, big_endian
>* object
,
652 const Symbol_value
<size
>* psymval
,
653 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
655 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
658 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
660 pcplt22(unsigned char* view
,
661 const Sized_relobj
<size
, big_endian
>* object
,
662 const Symbol_value
<size
>* psymval
,
663 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
664 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
666 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
667 psymval
, addend
, address
);
670 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
672 lo10(unsigned char* view
,
673 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
674 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
676 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
679 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
681 lo10(unsigned char* view
,
682 const Sized_relobj
<size
, big_endian
>* object
,
683 const Symbol_value
<size
>* psymval
,
684 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
686 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
689 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
691 lo10(unsigned char* view
,
692 const Sized_relobj
<size
, big_endian
>* object
,
693 const Symbol_value
<size
>* psymval
,
694 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
695 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
697 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
698 psymval
, addend
, address
);
701 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
703 olo10(unsigned char* view
,
704 const Sized_relobj
<size
, big_endian
>* object
,
705 const Symbol_value
<size
>* psymval
,
706 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
707 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
709 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
710 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
711 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
712 Valtype reloc
= psymval
->value(object
, addend
);
719 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
722 // R_SPARC_22: (Symbol + Addend)
724 rela32_22(unsigned char* view
,
725 const Sized_relobj
<size
, big_endian
>* object
,
726 const Symbol_value
<size
>* psymval
,
727 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
729 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
732 // R_SPARC_13: (Symbol + Addend)
734 rela32_13(unsigned char* view
,
735 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
736 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
738 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
741 // R_SPARC_13: (Symbol + Addend)
743 rela32_13(unsigned char* view
,
744 const Sized_relobj
<size
, big_endian
>* object
,
745 const Symbol_value
<size
>* psymval
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
748 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
751 // R_SPARC_UA16: (Symbol + Addend)
753 ua16(unsigned char* view
,
754 const Sized_relobj
<size
, big_endian
>* object
,
755 const Symbol_value
<size
>* psymval
,
756 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
758 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
761 // R_SPARC_UA32: (Symbol + Addend)
763 ua32(unsigned char* view
,
764 const Sized_relobj
<size
, big_endian
>* object
,
765 const Symbol_value
<size
>* psymval
,
766 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
768 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
771 // R_SPARC_UA64: (Symbol + Addend)
773 ua64(unsigned char* view
,
774 const Sized_relobj
<size
, big_endian
>* object
,
775 const Symbol_value
<size
>* psymval
,
776 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
778 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
779 object
, psymval
, addend
);
782 // R_SPARC_DISP8: (Symbol + Addend - Address)
784 disp8(unsigned char* view
,
785 const Sized_relobj
<size
, big_endian
>* object
,
786 const Symbol_value
<size
>* psymval
,
787 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
788 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
790 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
794 // R_SPARC_DISP16: (Symbol + Addend - Address)
796 disp16(unsigned char* view
,
797 const Sized_relobj
<size
, big_endian
>* object
,
798 const Symbol_value
<size
>* psymval
,
799 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
800 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
802 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
806 // R_SPARC_DISP32: (Symbol + Addend - Address)
808 disp32(unsigned char* view
,
809 const Sized_relobj
<size
, big_endian
>* object
,
810 const Symbol_value
<size
>* psymval
,
811 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
812 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
814 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
818 // R_SPARC_DISP64: (Symbol + Addend - Address)
820 disp64(unsigned char* view
,
821 const Sized_relobj
<size
, big_endian
>* object
,
822 const Symbol_value
<size
>* psymval
,
823 elfcpp::Elf_Xword addend
,
824 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
826 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
830 // R_SPARC_H44: (Symbol + Addend) >> 22
832 h44(unsigned char* view
,
833 const Sized_relobj
<size
, big_endian
>* object
,
834 const Symbol_value
<size
>* psymval
,
835 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
837 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
840 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
842 m44(unsigned char* view
,
843 const Sized_relobj
<size
, big_endian
>* object
,
844 const Symbol_value
<size
>* psymval
,
845 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
847 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
850 // R_SPARC_L44: (Symbol + Addend) & 0xfff
852 l44(unsigned char* view
,
853 const Sized_relobj
<size
, big_endian
>* object
,
854 const Symbol_value
<size
>* psymval
,
855 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
857 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
860 // R_SPARC_HH22: (Symbol + Addend) >> 42
862 hh22(unsigned char* view
,
863 const Sized_relobj
<size
, big_endian
>* object
,
864 const Symbol_value
<size
>* psymval
,
865 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
867 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
870 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
872 pc_hh22(unsigned char* view
,
873 const Sized_relobj
<size
, big_endian
>* object
,
874 const Symbol_value
<size
>* psymval
,
875 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
876 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
878 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
879 psymval
, addend
, address
);
882 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
884 hm10(unsigned char* view
,
885 const Sized_relobj
<size
, big_endian
>* object
,
886 const Symbol_value
<size
>* psymval
,
887 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
889 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
892 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
894 pc_hm10(unsigned char* view
,
895 const Sized_relobj
<size
, big_endian
>* object
,
896 const Symbol_value
<size
>* psymval
,
897 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
898 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
900 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
901 psymval
, addend
, address
);
904 // R_SPARC_11: (Symbol + Addend)
906 rela32_11(unsigned char* view
,
907 const Sized_relobj
<size
, big_endian
>* object
,
908 const Symbol_value
<size
>* psymval
,
909 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
911 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
914 // R_SPARC_10: (Symbol + Addend)
916 rela32_10(unsigned char* view
,
917 const Sized_relobj
<size
, big_endian
>* object
,
918 const Symbol_value
<size
>* psymval
,
919 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
921 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
924 // R_SPARC_7: (Symbol + Addend)
926 rela32_7(unsigned char* view
,
927 const Sized_relobj
<size
, big_endian
>* object
,
928 const Symbol_value
<size
>* psymval
,
929 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
931 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
934 // R_SPARC_6: (Symbol + Addend)
936 rela32_6(unsigned char* view
,
937 const Sized_relobj
<size
, big_endian
>* object
,
938 const Symbol_value
<size
>* psymval
,
939 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
941 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
944 // R_SPARC_5: (Symbol + Addend)
946 rela32_5(unsigned char* view
,
947 const Sized_relobj
<size
, big_endian
>* object
,
948 const Symbol_value
<size
>* psymval
,
949 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
951 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
954 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
956 ldo_hix22(unsigned char* view
,
957 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
958 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
960 This_insn::hi22(view
, value
, addend
);
963 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
965 ldo_lox10(unsigned char* view
,
966 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
967 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
969 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
970 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
971 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
972 Valtype reloc
= (value
+ addend
);
977 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
980 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
982 hix22(unsigned char* view
,
983 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
984 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
986 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
987 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
988 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
989 Valtype reloc
= (value
+ addend
);
993 reloc
^= ~(Valtype
)0;
998 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1001 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
1003 hix22(unsigned char* view
,
1004 const Sized_relobj
<size
, big_endian
>* object
,
1005 const Symbol_value
<size
>* psymval
,
1006 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1008 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1009 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1010 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1011 Valtype reloc
= psymval
->value(object
, addend
);
1015 reloc
^= ~(Valtype
)0;
1020 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1024 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
1026 lox10(unsigned char* view
,
1027 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1028 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1030 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1031 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1032 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1033 Valtype reloc
= (value
+ addend
);
1039 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1042 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
1044 lox10(unsigned char* view
,
1045 const Sized_relobj
<size
, big_endian
>* object
,
1046 const Symbol_value
<size
>* psymval
,
1047 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1049 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1050 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1051 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1052 Valtype reloc
= psymval
->value(object
, addend
);
1058 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1062 // Get the GOT section, creating it if necessary.
1064 template<int size
, bool big_endian
>
1065 Output_data_got
<size
, big_endian
>*
1066 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1069 if (this->got_
== NULL
)
1071 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1073 this->got_
= new Output_data_got
<size
, big_endian
>();
1075 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1077 | elfcpp::SHF_WRITE
),
1078 this->got_
, ORDER_RELRO
, true);
1080 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1081 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1082 Symbol_table::PREDEFINED
,
1084 0, 0, elfcpp::STT_OBJECT
,
1086 elfcpp::STV_HIDDEN
, 0,
1093 // Get the dynamic reloc section, creating it if necessary.
1095 template<int size
, bool big_endian
>
1096 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1097 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1099 if (this->rela_dyn_
== NULL
)
1101 gold_assert(layout
!= NULL
);
1102 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1103 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1104 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1105 ORDER_DYNAMIC_RELOCS
, false);
1107 return this->rela_dyn_
;
1110 // A class to handle the PLT data.
1112 template<int size
, bool big_endian
>
1113 class Output_data_plt_sparc
: public Output_section_data
1116 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1117 size
, big_endian
> Reloc_section
;
1119 Output_data_plt_sparc(Layout
*);
1121 // Add an entry to the PLT.
1122 void add_entry(Symbol
* gsym
);
1124 // Return the .rela.plt section data.
1125 const Reloc_section
* rel_plt() const
1130 // Return the number of PLT entries.
1133 { return this->count_
; }
1135 // Return the offset of the first non-reserved PLT entry.
1137 first_plt_entry_offset()
1138 { return 4 * base_plt_entry_size
; }
1140 // Return the size of a PLT entry.
1142 get_plt_entry_size()
1143 { return base_plt_entry_size
; }
1146 void do_adjust_output_section(Output_section
* os
);
1148 // Write to a map file.
1150 do_print_to_mapfile(Mapfile
* mapfile
) const
1151 { mapfile
->print_output_data(this, _("** PLT")); }
1154 // The size of an entry in the PLT.
1155 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1157 static const unsigned int plt_entries_per_block
= 160;
1158 static const unsigned int plt_insn_chunk_size
= 24;
1159 static const unsigned int plt_pointer_chunk_size
= 8;
1160 static const unsigned int plt_block_size
=
1161 (plt_entries_per_block
1162 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1164 // Set the final size.
1166 set_final_data_size()
1168 unsigned int full_count
= this->count_
+ 4;
1169 unsigned int extra
= (size
== 32 ? 4 : 0);
1171 if (size
== 32 || full_count
< 32768)
1172 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1175 unsigned int ext_cnt
= full_count
- 32768;
1177 this->set_data_size((32768 * base_plt_entry_size
)
1179 * (plt_insn_chunk_size
1180 + plt_pointer_chunk_size
)));
1184 // Write out the PLT data.
1186 do_write(Output_file
*);
1188 // The reloc section.
1189 Reloc_section
* rel_
;
1190 // The number of PLT entries.
1191 unsigned int count_
;
1194 // Define the constants as required by C++ standard.
1196 template<int size
, bool big_endian
>
1197 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1199 template<int size
, bool big_endian
>
1201 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1203 template<int size
, bool big_endian
>
1204 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1206 template<int size
, bool big_endian
>
1208 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1210 template<int size
, bool big_endian
>
1211 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1213 // Create the PLT section. The ordinary .got section is an argument,
1214 // since we need to refer to the start.
1216 template<int size
, bool big_endian
>
1217 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1218 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1220 this->rel_
= new Reloc_section(false);
1221 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1222 elfcpp::SHF_ALLOC
, this->rel_
,
1223 ORDER_DYNAMIC_PLT_RELOCS
, false);
1226 template<int size
, bool big_endian
>
1228 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1233 // Add an entry to the PLT.
1235 template<int size
, bool big_endian
>
1237 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1239 gold_assert(!gsym
->has_plt_offset());
1241 unsigned int index
= this->count_
+ 4;
1242 section_offset_type plt_offset
;
1244 if (size
== 32 || index
< 32768)
1245 plt_offset
= index
* base_plt_entry_size
;
1248 unsigned int ext_index
= index
- 32768;
1250 plt_offset
= (32768 * base_plt_entry_size
)
1251 + ((ext_index
/ plt_entries_per_block
)
1253 + ((ext_index
% plt_entries_per_block
)
1254 * plt_insn_chunk_size
);
1257 gsym
->set_plt_offset(plt_offset
);
1261 // Every PLT entry needs a reloc.
1262 gsym
->set_needs_dynsym_entry();
1263 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1266 // Note that we don't need to save the symbol. The contents of the
1267 // PLT are independent of which symbols are used. The symbols only
1268 // appear in the relocations.
1271 static const unsigned int sparc_nop
= 0x01000000;
1272 static const unsigned int sparc_sethi_g1
= 0x03000000;
1273 static const unsigned int sparc_branch_always
= 0x30800000;
1274 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1275 static const unsigned int sparc_mov
= 0x80100000;
1276 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1277 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1278 static const unsigned int sparc_call_plus_8
= 0x40000002;
1279 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1280 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1281 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1283 // Write out the PLT.
1285 template<int size
, bool big_endian
>
1287 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1289 const off_t offset
= this->offset();
1290 const section_size_type oview_size
=
1291 convert_to_section_size_type(this->data_size());
1292 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1293 unsigned char* pov
= oview
;
1295 memset(pov
, 0, base_plt_entry_size
* 4);
1296 pov
+= base_plt_entry_size
* 4;
1298 unsigned int plt_offset
= base_plt_entry_size
* 4;
1299 const unsigned int count
= this->count_
;
1305 limit
= (count
> 32768 ? 32768 : count
);
1307 for (unsigned int i
= 0; i
< limit
; ++i
)
1309 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1310 sparc_sethi_g1
+ plt_offset
);
1311 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1312 sparc_branch_always_pt
+
1313 (((base_plt_entry_size
-
1314 (plt_offset
+ 4)) >> 2) &
1316 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1317 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1318 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1319 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1320 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1321 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1323 pov
+= base_plt_entry_size
;
1324 plt_offset
+= base_plt_entry_size
;
1329 unsigned int ext_cnt
= count
- 32768;
1330 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1332 for (unsigned int i
= 0; i
< blks
; ++i
)
1334 unsigned int data_off
= (plt_entries_per_block
1335 * plt_insn_chunk_size
) - 4;
1337 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1339 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1341 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1343 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1345 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1346 sparc_ldx_o7_imm_g1
+
1347 (data_off
& 0x1fff));
1348 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1349 sparc_jmpl_o7_g1_g1
);
1350 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1353 elfcpp::Swap
<64, big_endian
>::writeval(
1354 pov
+ 0x4 + data_off
,
1355 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1357 pov
+= plt_insn_chunk_size
;
1362 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1363 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1365 unsigned int data_off
= (sub_blk_cnt
1366 * plt_insn_chunk_size
) - 4;
1368 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1370 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1372 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1374 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1376 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1377 sparc_ldx_o7_imm_g1
+
1378 (data_off
& 0x1fff));
1379 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1380 sparc_jmpl_o7_g1_g1
);
1381 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1384 elfcpp::Swap
<64, big_endian
>::writeval(
1385 pov
+ 0x4 + data_off
,
1386 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1388 pov
+= plt_insn_chunk_size
;
1396 for (unsigned int i
= 0; i
< count
; ++i
)
1398 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1399 sparc_sethi_g1
+ plt_offset
);
1400 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1401 sparc_branch_always
+
1402 (((- (plt_offset
+ 4)) >> 2) &
1404 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1406 pov
+= base_plt_entry_size
;
1407 plt_offset
+= base_plt_entry_size
;
1410 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1414 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1416 of
->write_output_view(offset
, oview_size
, oview
);
1419 // Create a PLT entry for a global symbol.
1421 template<int size
, bool big_endian
>
1423 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1427 if (gsym
->has_plt_offset())
1430 if (this->plt_
== NULL
)
1432 // Create the GOT sections first.
1433 this->got_section(symtab
, layout
);
1435 // Ensure that .rela.dyn always appears before .rela.plt This is
1436 // necessary due to how, on Sparc and some other targets, .rela.dyn
1437 // needs to include .rela.plt in it's range.
1438 this->rela_dyn_section(layout
);
1440 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1441 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1443 | elfcpp::SHF_EXECINSTR
1444 | elfcpp::SHF_WRITE
),
1445 this->plt_
, ORDER_PLT
, false);
1447 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1448 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1449 Symbol_table::PREDEFINED
,
1451 0, 0, elfcpp::STT_OBJECT
,
1453 elfcpp::STV_HIDDEN
, 0,
1457 this->plt_
->add_entry(gsym
);
1460 // Return the number of entries in the PLT.
1462 template<int size
, bool big_endian
>
1464 Target_sparc
<size
, big_endian
>::plt_entry_count() const
1466 if (this->plt_
== NULL
)
1468 return this->plt_
->entry_count();
1471 // Return the offset of the first non-reserved PLT entry.
1473 template<int size
, bool big_endian
>
1475 Target_sparc
<size
, big_endian
>::first_plt_entry_offset() const
1477 return Output_data_plt_sparc
<size
, big_endian
>::first_plt_entry_offset();
1480 // Return the size of each PLT entry.
1482 template<int size
, bool big_endian
>
1484 Target_sparc
<size
, big_endian
>::plt_entry_size() const
1486 return Output_data_plt_sparc
<size
, big_endian
>::get_plt_entry_size();
1489 // Create a GOT entry for the TLS module index.
1491 template<int size
, bool big_endian
>
1493 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1495 Sized_relobj
<size
, big_endian
>* object
)
1497 if (this->got_mod_index_offset_
== -1U)
1499 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1500 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1501 Output_data_got
<size
, big_endian
>* got
;
1502 unsigned int got_offset
;
1504 got
= this->got_section(symtab
, layout
);
1505 got_offset
= got
->add_constant(0);
1506 rela_dyn
->add_local(object
, 0,
1508 elfcpp::R_SPARC_TLS_DTPMOD64
:
1509 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1511 got
->add_constant(0);
1512 this->got_mod_index_offset_
= got_offset
;
1514 return this->got_mod_index_offset_
;
1517 // Optimize the TLS relocation type based on what we know about the
1518 // symbol. IS_FINAL is true if the final address of this symbol is
1519 // known at link time.
1521 static tls::Tls_optimization
1522 optimize_tls_reloc(bool is_final
, int r_type
)
1524 // If we are generating a shared library, then we can't do anything
1526 if (parameters
->options().shared())
1527 return tls::TLSOPT_NONE
;
1531 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1532 case elfcpp::R_SPARC_TLS_GD_LO10
:
1533 case elfcpp::R_SPARC_TLS_GD_ADD
:
1534 case elfcpp::R_SPARC_TLS_GD_CALL
:
1535 // These are General-Dynamic which permits fully general TLS
1536 // access. Since we know that we are generating an executable,
1537 // we can convert this to Initial-Exec. If we also know that
1538 // this is a local symbol, we can further switch to Local-Exec.
1540 return tls::TLSOPT_TO_LE
;
1541 return tls::TLSOPT_TO_IE
;
1543 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1544 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1545 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1546 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1547 // This is Local-Dynamic, which refers to a local symbol in the
1548 // dynamic TLS block. Since we know that we generating an
1549 // executable, we can switch to Local-Exec.
1550 return tls::TLSOPT_TO_LE
;
1552 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1553 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1554 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1555 // Another type of Local-Dynamic relocation.
1556 return tls::TLSOPT_TO_LE
;
1558 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1559 case elfcpp::R_SPARC_TLS_IE_LO10
:
1560 case elfcpp::R_SPARC_TLS_IE_LD
:
1561 case elfcpp::R_SPARC_TLS_IE_LDX
:
1562 case elfcpp::R_SPARC_TLS_IE_ADD
:
1563 // These are Initial-Exec relocs which get the thread offset
1564 // from the GOT. If we know that we are linking against the
1565 // local symbol, we can switch to Local-Exec, which links the
1566 // thread offset into the instruction.
1568 return tls::TLSOPT_TO_LE
;
1569 return tls::TLSOPT_NONE
;
1571 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1572 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1573 // When we already have Local-Exec, there is nothing further we
1575 return tls::TLSOPT_NONE
;
1582 // Get the Reference_flags for a particular relocation.
1584 template<int size
, bool big_endian
>
1586 Target_sparc
<size
, big_endian
>::Scan::get_reference_flags(unsigned int r_type
)
1591 case elfcpp::R_SPARC_NONE
:
1592 case elfcpp::R_SPARC_REGISTER
:
1593 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1594 case elfcpp::R_SPARC_GNU_VTENTRY
:
1595 // No symbol reference.
1598 case elfcpp::R_SPARC_UA64
:
1599 case elfcpp::R_SPARC_64
:
1600 case elfcpp::R_SPARC_HIX22
:
1601 case elfcpp::R_SPARC_LOX10
:
1602 case elfcpp::R_SPARC_H44
:
1603 case elfcpp::R_SPARC_M44
:
1604 case elfcpp::R_SPARC_L44
:
1605 case elfcpp::R_SPARC_HH22
:
1606 case elfcpp::R_SPARC_HM10
:
1607 case elfcpp::R_SPARC_LM22
:
1608 case elfcpp::R_SPARC_HI22
:
1609 case elfcpp::R_SPARC_LO10
:
1610 case elfcpp::R_SPARC_OLO10
:
1611 case elfcpp::R_SPARC_UA32
:
1612 case elfcpp::R_SPARC_32
:
1613 case elfcpp::R_SPARC_UA16
:
1614 case elfcpp::R_SPARC_16
:
1615 case elfcpp::R_SPARC_11
:
1616 case elfcpp::R_SPARC_10
:
1617 case elfcpp::R_SPARC_8
:
1618 case elfcpp::R_SPARC_7
:
1619 case elfcpp::R_SPARC_6
:
1620 case elfcpp::R_SPARC_5
:
1621 return Symbol::ABSOLUTE_REF
;
1623 case elfcpp::R_SPARC_DISP8
:
1624 case elfcpp::R_SPARC_DISP16
:
1625 case elfcpp::R_SPARC_DISP32
:
1626 case elfcpp::R_SPARC_DISP64
:
1627 case elfcpp::R_SPARC_PC_HH22
:
1628 case elfcpp::R_SPARC_PC_HM10
:
1629 case elfcpp::R_SPARC_PC_LM22
:
1630 case elfcpp::R_SPARC_PC10
:
1631 case elfcpp::R_SPARC_PC22
:
1632 case elfcpp::R_SPARC_WDISP30
:
1633 case elfcpp::R_SPARC_WDISP22
:
1634 case elfcpp::R_SPARC_WDISP19
:
1635 case elfcpp::R_SPARC_WDISP16
:
1636 return Symbol::RELATIVE_REF
;
1638 case elfcpp::R_SPARC_PLT64
:
1639 case elfcpp::R_SPARC_PLT32
:
1640 case elfcpp::R_SPARC_HIPLT22
:
1641 case elfcpp::R_SPARC_LOPLT10
:
1642 case elfcpp::R_SPARC_PCPLT10
:
1643 return Symbol::FUNCTION_CALL
| Symbol::ABSOLUTE_REF
;
1645 case elfcpp::R_SPARC_PCPLT32
:
1646 case elfcpp::R_SPARC_PCPLT22
:
1647 case elfcpp::R_SPARC_WPLT30
:
1648 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
1650 case elfcpp::R_SPARC_GOTDATA_OP
:
1651 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1652 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1653 case elfcpp::R_SPARC_GOT10
:
1654 case elfcpp::R_SPARC_GOT13
:
1655 case elfcpp::R_SPARC_GOT22
:
1657 return Symbol::ABSOLUTE_REF
;
1659 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1660 case elfcpp::R_SPARC_TLS_GD_LO10
:
1661 case elfcpp::R_SPARC_TLS_GD_ADD
:
1662 case elfcpp::R_SPARC_TLS_GD_CALL
:
1663 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1664 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1665 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1666 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1667 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1668 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1669 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1670 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1671 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1672 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1673 case elfcpp::R_SPARC_TLS_IE_LO10
:
1674 case elfcpp::R_SPARC_TLS_IE_LD
:
1675 case elfcpp::R_SPARC_TLS_IE_LDX
:
1676 case elfcpp::R_SPARC_TLS_IE_ADD
:
1677 return Symbol::TLS_REF
;
1679 case elfcpp::R_SPARC_COPY
:
1680 case elfcpp::R_SPARC_GLOB_DAT
:
1681 case elfcpp::R_SPARC_JMP_SLOT
:
1682 case elfcpp::R_SPARC_RELATIVE
:
1683 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1684 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1685 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1686 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1687 case elfcpp::R_SPARC_TLS_TPOFF64
:
1688 case elfcpp::R_SPARC_TLS_TPOFF32
:
1690 // Not expected. We will give an error later.
1695 // Generate a PLT entry slot for a call to __tls_get_addr
1696 template<int size
, bool big_endian
>
1698 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1700 Target_sparc
<size
, big_endian
>* target
)
1702 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1704 target
->make_plt_entry(symtab
, layout
, gsym
);
1707 // Report an unsupported relocation against a local symbol.
1709 template<int size
, bool big_endian
>
1711 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1712 Sized_relobj
<size
, big_endian
>* object
,
1713 unsigned int r_type
)
1715 gold_error(_("%s: unsupported reloc %u against local symbol"),
1716 object
->name().c_str(), r_type
);
1719 // We are about to emit a dynamic relocation of type R_TYPE. If the
1720 // dynamic linker does not support it, issue an error.
1722 template<int size
, bool big_endian
>
1724 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1726 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1732 // These are the relocation types supported by glibc for sparc 64-bit.
1733 case elfcpp::R_SPARC_RELATIVE
:
1734 case elfcpp::R_SPARC_COPY
:
1735 case elfcpp::R_SPARC_64
:
1736 case elfcpp::R_SPARC_GLOB_DAT
:
1737 case elfcpp::R_SPARC_JMP_SLOT
:
1738 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1739 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1740 case elfcpp::R_SPARC_TLS_TPOFF64
:
1741 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1742 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1743 case elfcpp::R_SPARC_8
:
1744 case elfcpp::R_SPARC_16
:
1745 case elfcpp::R_SPARC_DISP8
:
1746 case elfcpp::R_SPARC_DISP16
:
1747 case elfcpp::R_SPARC_DISP32
:
1748 case elfcpp::R_SPARC_WDISP30
:
1749 case elfcpp::R_SPARC_LO10
:
1750 case elfcpp::R_SPARC_HI22
:
1751 case elfcpp::R_SPARC_OLO10
:
1752 case elfcpp::R_SPARC_H44
:
1753 case elfcpp::R_SPARC_M44
:
1754 case elfcpp::R_SPARC_L44
:
1755 case elfcpp::R_SPARC_HH22
:
1756 case elfcpp::R_SPARC_HM10
:
1757 case elfcpp::R_SPARC_LM22
:
1758 case elfcpp::R_SPARC_UA16
:
1759 case elfcpp::R_SPARC_UA32
:
1760 case elfcpp::R_SPARC_UA64
:
1771 // These are the relocation types supported by glibc for sparc 32-bit.
1772 case elfcpp::R_SPARC_RELATIVE
:
1773 case elfcpp::R_SPARC_COPY
:
1774 case elfcpp::R_SPARC_GLOB_DAT
:
1775 case elfcpp::R_SPARC_32
:
1776 case elfcpp::R_SPARC_JMP_SLOT
:
1777 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1778 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1779 case elfcpp::R_SPARC_TLS_TPOFF32
:
1780 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1781 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1782 case elfcpp::R_SPARC_8
:
1783 case elfcpp::R_SPARC_16
:
1784 case elfcpp::R_SPARC_DISP8
:
1785 case elfcpp::R_SPARC_DISP16
:
1786 case elfcpp::R_SPARC_DISP32
:
1787 case elfcpp::R_SPARC_LO10
:
1788 case elfcpp::R_SPARC_WDISP30
:
1789 case elfcpp::R_SPARC_HI22
:
1790 case elfcpp::R_SPARC_UA16
:
1791 case elfcpp::R_SPARC_UA32
:
1799 // This prevents us from issuing more than one error per reloc
1800 // section. But we can still wind up issuing more than one
1801 // error per object file.
1802 if (this->issued_non_pic_error_
)
1804 gold_assert(parameters
->options().output_is_position_independent());
1805 object
->error(_("requires unsupported dynamic reloc; "
1806 "recompile with -fPIC"));
1807 this->issued_non_pic_error_
= true;
1811 // Scan a relocation for a local symbol.
1813 template<int size
, bool big_endian
>
1815 Target_sparc
<size
, big_endian
>::Scan::local(
1816 Symbol_table
* symtab
,
1818 Target_sparc
<size
, big_endian
>* target
,
1819 Sized_relobj
<size
, big_endian
>* object
,
1820 unsigned int data_shndx
,
1821 Output_section
* output_section
,
1822 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1823 unsigned int r_type
,
1824 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1826 unsigned int orig_r_type
= r_type
;
1831 case elfcpp::R_SPARC_NONE
:
1832 case elfcpp::R_SPARC_REGISTER
:
1833 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1834 case elfcpp::R_SPARC_GNU_VTENTRY
:
1837 case elfcpp::R_SPARC_64
:
1838 case elfcpp::R_SPARC_32
:
1839 // If building a shared library (or a position-independent
1840 // executable), we need to create a dynamic relocation for
1841 // this location. The relocation applied at link time will
1842 // apply the link-time value, so we flag the location with
1843 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1844 // relocate it easily.
1845 if (parameters
->options().output_is_position_independent())
1847 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1848 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1849 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1850 output_section
, data_shndx
,
1851 reloc
.get_r_offset(),
1852 reloc
.get_r_addend());
1856 case elfcpp::R_SPARC_HIX22
:
1857 case elfcpp::R_SPARC_LOX10
:
1858 case elfcpp::R_SPARC_H44
:
1859 case elfcpp::R_SPARC_M44
:
1860 case elfcpp::R_SPARC_L44
:
1861 case elfcpp::R_SPARC_HH22
:
1862 case elfcpp::R_SPARC_HM10
:
1863 case elfcpp::R_SPARC_LM22
:
1864 case elfcpp::R_SPARC_UA64
:
1865 case elfcpp::R_SPARC_UA32
:
1866 case elfcpp::R_SPARC_UA16
:
1867 case elfcpp::R_SPARC_HI22
:
1868 case elfcpp::R_SPARC_LO10
:
1869 case elfcpp::R_SPARC_OLO10
:
1870 case elfcpp::R_SPARC_16
:
1871 case elfcpp::R_SPARC_11
:
1872 case elfcpp::R_SPARC_10
:
1873 case elfcpp::R_SPARC_8
:
1874 case elfcpp::R_SPARC_7
:
1875 case elfcpp::R_SPARC_6
:
1876 case elfcpp::R_SPARC_5
:
1877 // If building a shared library (or a position-independent
1878 // executable), we need to create a dynamic relocation for
1880 if (parameters
->options().output_is_position_independent())
1882 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1883 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1885 check_non_pic(object
, r_type
);
1886 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1888 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1889 data_shndx
, reloc
.get_r_offset(),
1890 reloc
.get_r_addend());
1894 gold_assert(lsym
.get_st_value() == 0);
1895 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
1896 output_section
, data_shndx
,
1897 reloc
.get_r_offset(),
1898 reloc
.get_r_addend());
1903 case elfcpp::R_SPARC_WDISP30
:
1904 case elfcpp::R_SPARC_WPLT30
:
1905 case elfcpp::R_SPARC_WDISP22
:
1906 case elfcpp::R_SPARC_WDISP19
:
1907 case elfcpp::R_SPARC_WDISP16
:
1908 case elfcpp::R_SPARC_DISP8
:
1909 case elfcpp::R_SPARC_DISP16
:
1910 case elfcpp::R_SPARC_DISP32
:
1911 case elfcpp::R_SPARC_DISP64
:
1912 case elfcpp::R_SPARC_PC10
:
1913 case elfcpp::R_SPARC_PC22
:
1916 case elfcpp::R_SPARC_GOTDATA_OP
:
1917 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1918 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1919 case elfcpp::R_SPARC_GOT10
:
1920 case elfcpp::R_SPARC_GOT13
:
1921 case elfcpp::R_SPARC_GOT22
:
1923 // The symbol requires a GOT entry.
1924 Output_data_got
<size
, big_endian
>* got
;
1927 got
= target
->got_section(symtab
, layout
);
1928 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1930 // If we are generating a shared object, we need to add a
1931 // dynamic relocation for this symbol's GOT entry.
1932 if (parameters
->options().output_is_position_independent())
1934 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1936 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1939 off
= got
->add_constant(0);
1940 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1941 rela_dyn
->add_local_relative(object
, r_sym
,
1942 elfcpp::R_SPARC_RELATIVE
,
1947 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1951 // These are initial TLS relocs, which are expected when
1953 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1954 case elfcpp::R_SPARC_TLS_GD_LO10
:
1955 case elfcpp::R_SPARC_TLS_GD_ADD
:
1956 case elfcpp::R_SPARC_TLS_GD_CALL
:
1957 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1958 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1959 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1960 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1961 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1962 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1963 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1964 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1965 case elfcpp::R_SPARC_TLS_IE_LO10
:
1966 case elfcpp::R_SPARC_TLS_IE_LD
:
1967 case elfcpp::R_SPARC_TLS_IE_LDX
:
1968 case elfcpp::R_SPARC_TLS_IE_ADD
:
1969 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1970 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1972 bool output_is_shared
= parameters
->options().shared();
1973 const tls::Tls_optimization optimized_type
1974 = optimize_tls_reloc(!output_is_shared
, r_type
);
1977 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1978 case elfcpp::R_SPARC_TLS_GD_LO10
:
1979 case elfcpp::R_SPARC_TLS_GD_ADD
:
1980 case elfcpp::R_SPARC_TLS_GD_CALL
:
1981 if (optimized_type
== tls::TLSOPT_NONE
)
1983 // Create a pair of GOT entries for the module index and
1984 // dtv-relative offset.
1985 Output_data_got
<size
, big_endian
>* got
1986 = target
->got_section(symtab
, layout
);
1987 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1988 unsigned int shndx
= lsym
.get_st_shndx();
1990 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1992 object
->error(_("local symbol %u has bad shndx %u"),
1995 got
->add_local_pair_with_rela(object
, r_sym
,
1996 lsym
.get_st_shndx(),
1998 target
->rela_dyn_section(layout
),
2000 ? elfcpp::R_SPARC_TLS_DTPMOD64
2001 : elfcpp::R_SPARC_TLS_DTPMOD32
),
2003 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2004 generate_tls_call(symtab
, layout
, target
);
2006 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2007 unsupported_reloc_local(object
, r_type
);
2010 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2011 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2012 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2013 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2014 if (optimized_type
== tls::TLSOPT_NONE
)
2016 // Create a GOT entry for the module index.
2017 target
->got_mod_index_entry(symtab
, layout
, object
);
2019 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2020 generate_tls_call(symtab
, layout
, target
);
2022 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2023 unsupported_reloc_local(object
, r_type
);
2026 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2027 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2028 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2031 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2032 case elfcpp::R_SPARC_TLS_IE_LO10
:
2033 case elfcpp::R_SPARC_TLS_IE_LD
:
2034 case elfcpp::R_SPARC_TLS_IE_LDX
:
2035 case elfcpp::R_SPARC_TLS_IE_ADD
:
2036 layout
->set_has_static_tls();
2037 if (optimized_type
== tls::TLSOPT_NONE
)
2039 // Create a GOT entry for the tp-relative offset.
2040 Output_data_got
<size
, big_endian
>* got
2041 = target
->got_section(symtab
, layout
);
2042 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2044 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
2046 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2047 unsigned int off
= got
->add_constant(0);
2049 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
2051 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
2053 elfcpp::R_SPARC_TLS_TPOFF64
:
2054 elfcpp::R_SPARC_TLS_TPOFF32
),
2058 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2059 unsupported_reloc_local(object
, r_type
);
2062 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
2063 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2064 layout
->set_has_static_tls();
2065 if (output_is_shared
)
2067 // We need to create a dynamic relocation.
2068 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
2069 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
2070 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2071 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
2072 output_section
, data_shndx
,
2073 reloc
.get_r_offset(), 0);
2080 // These are relocations which should only be seen by the
2081 // dynamic linker, and should never be seen here.
2082 case elfcpp::R_SPARC_COPY
:
2083 case elfcpp::R_SPARC_GLOB_DAT
:
2084 case elfcpp::R_SPARC_JMP_SLOT
:
2085 case elfcpp::R_SPARC_RELATIVE
:
2086 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2087 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2088 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2089 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2090 case elfcpp::R_SPARC_TLS_TPOFF64
:
2091 case elfcpp::R_SPARC_TLS_TPOFF32
:
2092 gold_error(_("%s: unexpected reloc %u in object file"),
2093 object
->name().c_str(), r_type
);
2097 unsupported_reloc_local(object
, r_type
);
2102 // Report an unsupported relocation against a global symbol.
2104 template<int size
, bool big_endian
>
2106 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
2107 Sized_relobj
<size
, big_endian
>* object
,
2108 unsigned int r_type
,
2111 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
2112 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
2115 // Scan a relocation for a global symbol.
2117 template<int size
, bool big_endian
>
2119 Target_sparc
<size
, big_endian
>::Scan::global(
2120 Symbol_table
* symtab
,
2122 Target_sparc
<size
, big_endian
>* target
,
2123 Sized_relobj
<size
, big_endian
>* object
,
2124 unsigned int data_shndx
,
2125 Output_section
* output_section
,
2126 const elfcpp::Rela
<size
, big_endian
>& reloc
,
2127 unsigned int r_type
,
2130 unsigned int orig_r_type
= r_type
;
2132 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
2133 // section. We check here to avoid creating a dynamic reloc against
2134 // _GLOBAL_OFFSET_TABLE_.
2135 if (!target
->has_got_section()
2136 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
2137 target
->got_section(symtab
, layout
);
2142 case elfcpp::R_SPARC_NONE
:
2143 case elfcpp::R_SPARC_REGISTER
:
2144 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2145 case elfcpp::R_SPARC_GNU_VTENTRY
:
2148 case elfcpp::R_SPARC_PLT64
:
2149 case elfcpp::R_SPARC_PLT32
:
2150 case elfcpp::R_SPARC_HIPLT22
:
2151 case elfcpp::R_SPARC_LOPLT10
:
2152 case elfcpp::R_SPARC_PCPLT32
:
2153 case elfcpp::R_SPARC_PCPLT22
:
2154 case elfcpp::R_SPARC_PCPLT10
:
2155 case elfcpp::R_SPARC_WPLT30
:
2156 // If the symbol is fully resolved, this is just a PC32 reloc.
2157 // Otherwise we need a PLT entry.
2158 if (gsym
->final_value_is_known())
2160 // If building a shared library, we can also skip the PLT entry
2161 // if the symbol is defined in the output file and is protected
2163 if (gsym
->is_defined()
2164 && !gsym
->is_from_dynobj()
2165 && !gsym
->is_preemptible())
2167 target
->make_plt_entry(symtab
, layout
, gsym
);
2170 case elfcpp::R_SPARC_DISP8
:
2171 case elfcpp::R_SPARC_DISP16
:
2172 case elfcpp::R_SPARC_DISP32
:
2173 case elfcpp::R_SPARC_DISP64
:
2174 case elfcpp::R_SPARC_PC_HH22
:
2175 case elfcpp::R_SPARC_PC_HM10
:
2176 case elfcpp::R_SPARC_PC_LM22
:
2177 case elfcpp::R_SPARC_PC10
:
2178 case elfcpp::R_SPARC_PC22
:
2179 case elfcpp::R_SPARC_WDISP30
:
2180 case elfcpp::R_SPARC_WDISP22
:
2181 case elfcpp::R_SPARC_WDISP19
:
2182 case elfcpp::R_SPARC_WDISP16
:
2184 if (gsym
->needs_plt_entry())
2185 target
->make_plt_entry(symtab
, layout
, gsym
);
2186 // Make a dynamic relocation if necessary.
2187 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2189 if (gsym
->may_need_copy_reloc())
2191 target
->copy_reloc(symtab
, layout
, object
,
2192 data_shndx
, output_section
, gsym
,
2197 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2198 check_non_pic(object
, r_type
);
2199 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
2200 data_shndx
, reloc
.get_r_offset(),
2201 reloc
.get_r_addend());
2207 case elfcpp::R_SPARC_UA64
:
2208 case elfcpp::R_SPARC_64
:
2209 case elfcpp::R_SPARC_HIX22
:
2210 case elfcpp::R_SPARC_LOX10
:
2211 case elfcpp::R_SPARC_H44
:
2212 case elfcpp::R_SPARC_M44
:
2213 case elfcpp::R_SPARC_L44
:
2214 case elfcpp::R_SPARC_HH22
:
2215 case elfcpp::R_SPARC_HM10
:
2216 case elfcpp::R_SPARC_LM22
:
2217 case elfcpp::R_SPARC_HI22
:
2218 case elfcpp::R_SPARC_LO10
:
2219 case elfcpp::R_SPARC_OLO10
:
2220 case elfcpp::R_SPARC_UA32
:
2221 case elfcpp::R_SPARC_32
:
2222 case elfcpp::R_SPARC_UA16
:
2223 case elfcpp::R_SPARC_16
:
2224 case elfcpp::R_SPARC_11
:
2225 case elfcpp::R_SPARC_10
:
2226 case elfcpp::R_SPARC_8
:
2227 case elfcpp::R_SPARC_7
:
2228 case elfcpp::R_SPARC_6
:
2229 case elfcpp::R_SPARC_5
:
2231 // Make a PLT entry if necessary.
2232 if (gsym
->needs_plt_entry())
2234 target
->make_plt_entry(symtab
, layout
, gsym
);
2235 // Since this is not a PC-relative relocation, we may be
2236 // taking the address of a function. In that case we need to
2237 // set the entry in the dynamic symbol table to the address of
2239 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2240 gsym
->set_needs_dynsym_value();
2242 // Make a dynamic relocation if necessary.
2243 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
2245 unsigned int r_off
= reloc
.get_r_offset();
2247 // The assembler can sometimes emit unaligned relocations
2248 // for dwarf2 cfi directives.
2251 case elfcpp::R_SPARC_16
:
2253 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2255 case elfcpp::R_SPARC_32
:
2257 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2259 case elfcpp::R_SPARC_64
:
2261 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2263 case elfcpp::R_SPARC_UA16
:
2265 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2267 case elfcpp::R_SPARC_UA32
:
2269 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2271 case elfcpp::R_SPARC_UA64
:
2273 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2277 if (gsym
->may_need_copy_reloc())
2279 target
->copy_reloc(symtab
, layout
, object
,
2280 data_shndx
, output_section
, gsym
, reloc
);
2282 else if ((r_type
== elfcpp::R_SPARC_32
2283 || r_type
== elfcpp::R_SPARC_64
)
2284 && gsym
->can_use_relative_reloc(false))
2286 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2287 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2288 output_section
, object
,
2289 data_shndx
, reloc
.get_r_offset(),
2290 reloc
.get_r_addend());
2294 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2296 check_non_pic(object
, r_type
);
2297 if (gsym
->is_from_dynobj()
2298 || gsym
->is_undefined()
2299 || gsym
->is_preemptible())
2300 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2302 reloc
.get_r_offset(),
2303 reloc
.get_r_addend());
2305 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2308 reloc
.get_r_offset(),
2309 reloc
.get_r_addend());
2315 case elfcpp::R_SPARC_GOTDATA_OP
:
2316 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2317 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2318 case elfcpp::R_SPARC_GOT10
:
2319 case elfcpp::R_SPARC_GOT13
:
2320 case elfcpp::R_SPARC_GOT22
:
2322 // The symbol requires a GOT entry.
2323 Output_data_got
<size
, big_endian
>* got
;
2325 got
= target
->got_section(symtab
, layout
);
2326 if (gsym
->final_value_is_known())
2327 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2330 // If this symbol is not fully resolved, we need to add a
2331 // dynamic relocation for it.
2332 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2333 if (gsym
->is_from_dynobj()
2334 || gsym
->is_undefined()
2335 || gsym
->is_preemptible())
2336 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2337 elfcpp::R_SPARC_GLOB_DAT
);
2338 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2340 unsigned int off
= got
->add_constant(0);
2342 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2343 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2350 // These are initial tls relocs, which are expected when
2352 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2353 case elfcpp::R_SPARC_TLS_GD_LO10
:
2354 case elfcpp::R_SPARC_TLS_GD_ADD
:
2355 case elfcpp::R_SPARC_TLS_GD_CALL
:
2356 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2357 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2358 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2359 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2360 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2361 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2362 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2363 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2364 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2365 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2366 case elfcpp::R_SPARC_TLS_IE_LO10
:
2367 case elfcpp::R_SPARC_TLS_IE_LD
:
2368 case elfcpp::R_SPARC_TLS_IE_LDX
:
2369 case elfcpp::R_SPARC_TLS_IE_ADD
:
2371 const bool is_final
= gsym
->final_value_is_known();
2372 const tls::Tls_optimization optimized_type
2373 = optimize_tls_reloc(is_final
, r_type
);
2376 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2377 case elfcpp::R_SPARC_TLS_GD_LO10
:
2378 case elfcpp::R_SPARC_TLS_GD_ADD
:
2379 case elfcpp::R_SPARC_TLS_GD_CALL
:
2380 if (optimized_type
== tls::TLSOPT_NONE
)
2382 // Create a pair of GOT entries for the module index and
2383 // dtv-relative offset.
2384 Output_data_got
<size
, big_endian
>* got
2385 = target
->got_section(symtab
, layout
);
2386 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2387 target
->rela_dyn_section(layout
),
2389 elfcpp::R_SPARC_TLS_DTPMOD64
:
2390 elfcpp::R_SPARC_TLS_DTPMOD32
),
2392 elfcpp::R_SPARC_TLS_DTPOFF64
:
2393 elfcpp::R_SPARC_TLS_DTPOFF32
));
2395 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2396 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2397 generate_tls_call(symtab
, layout
, target
);
2399 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2401 // Create a GOT entry for the tp-relative offset.
2402 Output_data_got
<size
, big_endian
>* got
2403 = target
->got_section(symtab
, layout
);
2404 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2405 target
->rela_dyn_section(layout
),
2407 elfcpp::R_SPARC_TLS_TPOFF64
:
2408 elfcpp::R_SPARC_TLS_TPOFF32
));
2410 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2411 unsupported_reloc_global(object
, r_type
, gsym
);
2414 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2415 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2416 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2417 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2418 if (optimized_type
== tls::TLSOPT_NONE
)
2420 // Create a GOT entry for the module index.
2421 target
->got_mod_index_entry(symtab
, layout
, object
);
2423 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2424 generate_tls_call(symtab
, layout
, target
);
2426 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2427 unsupported_reloc_global(object
, r_type
, gsym
);
2430 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2431 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2432 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2435 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2436 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2437 layout
->set_has_static_tls();
2438 if (parameters
->options().shared())
2440 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2441 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2442 output_section
, object
,
2443 data_shndx
, reloc
.get_r_offset(),
2448 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2449 case elfcpp::R_SPARC_TLS_IE_LO10
:
2450 case elfcpp::R_SPARC_TLS_IE_LD
:
2451 case elfcpp::R_SPARC_TLS_IE_LDX
:
2452 case elfcpp::R_SPARC_TLS_IE_ADD
:
2453 layout
->set_has_static_tls();
2454 if (optimized_type
== tls::TLSOPT_NONE
)
2456 // Create a GOT entry for the tp-relative offset.
2457 Output_data_got
<size
, big_endian
>* got
2458 = target
->got_section(symtab
, layout
);
2459 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2460 target
->rela_dyn_section(layout
),
2462 elfcpp::R_SPARC_TLS_TPOFF64
:
2463 elfcpp::R_SPARC_TLS_TPOFF32
));
2465 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2466 unsupported_reloc_global(object
, r_type
, gsym
);
2472 // These are relocations which should only be seen by the
2473 // dynamic linker, and should never be seen here.
2474 case elfcpp::R_SPARC_COPY
:
2475 case elfcpp::R_SPARC_GLOB_DAT
:
2476 case elfcpp::R_SPARC_JMP_SLOT
:
2477 case elfcpp::R_SPARC_RELATIVE
:
2478 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2479 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2480 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2481 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2482 case elfcpp::R_SPARC_TLS_TPOFF64
:
2483 case elfcpp::R_SPARC_TLS_TPOFF32
:
2484 gold_error(_("%s: unexpected reloc %u in object file"),
2485 object
->name().c_str(), r_type
);
2489 unsupported_reloc_global(object
, r_type
, gsym
);
2494 // Process relocations for gc.
2496 template<int size
, bool big_endian
>
2498 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2499 Symbol_table
* symtab
,
2501 Sized_relobj
<size
, big_endian
>* object
,
2502 unsigned int data_shndx
,
2504 const unsigned char* prelocs
,
2506 Output_section
* output_section
,
2507 bool needs_special_offset_handling
,
2508 size_t local_symbol_count
,
2509 const unsigned char* plocal_symbols
)
2511 typedef Target_sparc
<size
, big_endian
> Sparc
;
2512 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2514 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
,
2515 typename
Target_sparc::Relocatable_size_for_reloc
>(
2524 needs_special_offset_handling
,
2529 // Scan relocations for a section.
2531 template<int size
, bool big_endian
>
2533 Target_sparc
<size
, big_endian
>::scan_relocs(
2534 Symbol_table
* symtab
,
2536 Sized_relobj
<size
, big_endian
>* object
,
2537 unsigned int data_shndx
,
2538 unsigned int sh_type
,
2539 const unsigned char* prelocs
,
2541 Output_section
* output_section
,
2542 bool needs_special_offset_handling
,
2543 size_t local_symbol_count
,
2544 const unsigned char* plocal_symbols
)
2546 typedef Target_sparc
<size
, big_endian
> Sparc
;
2547 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2549 if (sh_type
== elfcpp::SHT_REL
)
2551 gold_error(_("%s: unsupported REL reloc section"),
2552 object
->name().c_str());
2556 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2565 needs_special_offset_handling
,
2570 // Finalize the sections.
2572 template<int size
, bool big_endian
>
2574 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2576 const Input_objects
*,
2579 // Fill in some more dynamic tags.
2580 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2582 : this->plt_
->rel_plt());
2583 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2584 this->rela_dyn_
, true, true);
2586 // Emit any relocs we saved in an attempt to avoid generating COPY
2588 if (this->copy_relocs_
.any_saved_relocs())
2589 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2592 // Perform a relocation.
2594 template<int size
, bool big_endian
>
2596 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2597 const Relocate_info
<size
, big_endian
>* relinfo
,
2598 Target_sparc
* target
,
2601 const elfcpp::Rela
<size
, big_endian
>& rela
,
2602 unsigned int r_type
,
2603 const Sized_symbol
<size
>* gsym
,
2604 const Symbol_value
<size
>* psymval
,
2605 unsigned char* view
,
2606 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2607 section_size_type view_size
)
2611 if (this->ignore_gd_add_
)
2613 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2614 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2615 _("missing expected TLS relocation"));
2618 this->ignore_gd_add_
= false;
2623 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2625 // Pick the value to use for symbols defined in shared objects.
2626 Symbol_value
<size
> symval
;
2628 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
2630 elfcpp::Elf_Xword value
;
2632 value
= target
->plt_section()->address() + gsym
->plt_offset();
2634 symval
.set_output_value(value
);
2639 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2640 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2642 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2643 // pointer points to the beginning, not the end, of the table.
2644 // So we just use the plain offset.
2645 unsigned int got_offset
= 0;
2648 case elfcpp::R_SPARC_GOTDATA_OP
:
2649 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2650 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2651 case elfcpp::R_SPARC_GOT10
:
2652 case elfcpp::R_SPARC_GOT13
:
2653 case elfcpp::R_SPARC_GOT22
:
2656 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2657 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2661 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2662 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2663 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2673 case elfcpp::R_SPARC_NONE
:
2674 case elfcpp::R_SPARC_REGISTER
:
2675 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2676 case elfcpp::R_SPARC_GNU_VTENTRY
:
2679 case elfcpp::R_SPARC_8
:
2680 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2684 case elfcpp::R_SPARC_16
:
2685 if (rela
.get_r_offset() & 0x1)
2687 // The assembler can sometimes emit unaligned relocations
2688 // for dwarf2 cfi directives.
2689 Reloc::ua16(view
, object
, psymval
, addend
);
2692 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2696 case elfcpp::R_SPARC_32
:
2697 if (!parameters
->options().output_is_position_independent())
2699 if (rela
.get_r_offset() & 0x3)
2701 // The assembler can sometimes emit unaligned relocations
2702 // for dwarf2 cfi directives.
2703 Reloc::ua32(view
, object
, psymval
, addend
);
2706 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2711 case elfcpp::R_SPARC_DISP8
:
2712 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2715 case elfcpp::R_SPARC_DISP16
:
2716 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2719 case elfcpp::R_SPARC_DISP32
:
2720 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2723 case elfcpp::R_SPARC_DISP64
:
2724 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2727 case elfcpp::R_SPARC_WDISP30
:
2728 case elfcpp::R_SPARC_WPLT30
:
2729 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2732 case elfcpp::R_SPARC_WDISP22
:
2733 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2736 case elfcpp::R_SPARC_WDISP19
:
2737 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2740 case elfcpp::R_SPARC_WDISP16
:
2741 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2744 case elfcpp::R_SPARC_HI22
:
2745 Reloc::hi22(view
, object
, psymval
, addend
);
2748 case elfcpp::R_SPARC_22
:
2749 Reloc::rela32_22(view
, object
, psymval
, addend
);
2752 case elfcpp::R_SPARC_13
:
2753 Reloc::rela32_13(view
, object
, psymval
, addend
);
2756 case elfcpp::R_SPARC_LO10
:
2757 Reloc::lo10(view
, object
, psymval
, addend
);
2760 case elfcpp::R_SPARC_GOT10
:
2761 Reloc::lo10(view
, got_offset
, addend
);
2764 case elfcpp::R_SPARC_GOTDATA_OP
:
2767 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2768 case elfcpp::R_SPARC_GOT13
:
2769 Reloc::rela32_13(view
, got_offset
, addend
);
2772 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2773 case elfcpp::R_SPARC_GOT22
:
2774 Reloc::hi22(view
, got_offset
, addend
);
2777 case elfcpp::R_SPARC_PC10
:
2778 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2781 case elfcpp::R_SPARC_PC22
:
2782 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2785 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2786 case elfcpp::R_SPARC_UA32
:
2787 Reloc::ua32(view
, object
, psymval
, addend
);
2790 case elfcpp::R_SPARC_PLT64
:
2791 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2795 case elfcpp::R_SPARC_PLT32
:
2796 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2800 case elfcpp::R_SPARC_HIPLT22
:
2801 Reloc::hi22(view
, object
, psymval
, addend
);
2804 case elfcpp::R_SPARC_LOPLT10
:
2805 Reloc::lo10(view
, object
, psymval
, addend
);
2808 case elfcpp::R_SPARC_PCPLT32
:
2809 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2812 case elfcpp::R_SPARC_PCPLT22
:
2813 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2816 case elfcpp::R_SPARC_PCPLT10
:
2817 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2820 case elfcpp::R_SPARC_64
:
2821 if (!parameters
->options().output_is_position_independent())
2823 if (rela
.get_r_offset() & 0x7)
2825 // The assembler can sometimes emit unaligned relocations
2826 // for dwarf2 cfi directives.
2827 Reloc::ua64(view
, object
, psymval
, addend
);
2830 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2835 case elfcpp::R_SPARC_OLO10
:
2837 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2838 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2839 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2843 case elfcpp::R_SPARC_HH22
:
2844 Reloc::hh22(view
, object
, psymval
, addend
);
2847 case elfcpp::R_SPARC_PC_HH22
:
2848 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2851 case elfcpp::R_SPARC_HM10
:
2852 Reloc::hm10(view
, object
, psymval
, addend
);
2855 case elfcpp::R_SPARC_PC_HM10
:
2856 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2859 case elfcpp::R_SPARC_LM22
:
2860 Reloc::hi22(view
, object
, psymval
, addend
);
2863 case elfcpp::R_SPARC_PC_LM22
:
2864 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2867 case elfcpp::R_SPARC_11
:
2868 Reloc::rela32_11(view
, object
, psymval
, addend
);
2871 case elfcpp::R_SPARC_10
:
2872 Reloc::rela32_10(view
, object
, psymval
, addend
);
2875 case elfcpp::R_SPARC_7
:
2876 Reloc::rela32_7(view
, object
, psymval
, addend
);
2879 case elfcpp::R_SPARC_6
:
2880 Reloc::rela32_6(view
, object
, psymval
, addend
);
2883 case elfcpp::R_SPARC_5
:
2884 Reloc::rela32_5(view
, object
, psymval
, addend
);
2887 case elfcpp::R_SPARC_HIX22
:
2888 Reloc::hix22(view
, object
, psymval
, addend
);
2891 case elfcpp::R_SPARC_LOX10
:
2892 Reloc::lox10(view
, object
, psymval
, addend
);
2895 case elfcpp::R_SPARC_H44
:
2896 Reloc::h44(view
, object
, psymval
, addend
);
2899 case elfcpp::R_SPARC_M44
:
2900 Reloc::m44(view
, object
, psymval
, addend
);
2903 case elfcpp::R_SPARC_L44
:
2904 Reloc::l44(view
, object
, psymval
, addend
);
2907 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2908 case elfcpp::R_SPARC_UA64
:
2909 Reloc::ua64(view
, object
, psymval
, addend
);
2912 case elfcpp::R_SPARC_UA16
:
2913 Reloc::ua16(view
, object
, psymval
, addend
);
2916 case elfcpp::R_SPARC_TLS_GD_HI22
:
2917 case elfcpp::R_SPARC_TLS_GD_LO10
:
2918 case elfcpp::R_SPARC_TLS_GD_ADD
:
2919 case elfcpp::R_SPARC_TLS_GD_CALL
:
2920 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2921 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2922 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2923 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2924 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2925 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2926 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2927 case elfcpp::R_SPARC_TLS_IE_HI22
:
2928 case elfcpp::R_SPARC_TLS_IE_LO10
:
2929 case elfcpp::R_SPARC_TLS_IE_LD
:
2930 case elfcpp::R_SPARC_TLS_IE_LDX
:
2931 case elfcpp::R_SPARC_TLS_IE_ADD
:
2932 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2933 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2934 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2935 r_type
, gsym
, psymval
, view
,
2936 address
, view_size
);
2939 case elfcpp::R_SPARC_COPY
:
2940 case elfcpp::R_SPARC_GLOB_DAT
:
2941 case elfcpp::R_SPARC_JMP_SLOT
:
2942 case elfcpp::R_SPARC_RELATIVE
:
2943 // These are outstanding tls relocs, which are unexpected when
2945 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2946 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2947 case elfcpp::R_SPARC_TLS_TPOFF64
:
2948 case elfcpp::R_SPARC_TLS_TPOFF32
:
2949 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2950 _("unexpected reloc %u in object file"),
2955 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2956 _("unsupported reloc %u"),
2964 // Perform a TLS relocation.
2966 template<int size
, bool big_endian
>
2968 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2969 const Relocate_info
<size
, big_endian
>* relinfo
,
2970 Target_sparc
<size
, big_endian
>* target
,
2972 const elfcpp::Rela
<size
, big_endian
>& rela
,
2973 unsigned int r_type
,
2974 const Sized_symbol
<size
>* gsym
,
2975 const Symbol_value
<size
>* psymval
,
2976 unsigned char* view
,
2977 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2980 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2981 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2982 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2983 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2985 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2986 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2988 const bool is_final
=
2990 ? !parameters
->options().output_is_position_independent()
2991 : gsym
->final_value_is_known());
2992 const tls::Tls_optimization optimized_type
2993 = optimize_tls_reloc(is_final
, r_type
);
2997 case elfcpp::R_SPARC_TLS_GD_HI22
:
2998 case elfcpp::R_SPARC_TLS_GD_LO10
:
2999 case elfcpp::R_SPARC_TLS_GD_ADD
:
3000 case elfcpp::R_SPARC_TLS_GD_CALL
:
3001 if (optimized_type
== tls::TLSOPT_TO_LE
)
3003 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3006 value
-= tls_segment
->memsz();
3010 case elfcpp::R_SPARC_TLS_GD_HI22
:
3011 // TLS_GD_HI22 --> TLS_LE_HIX22
3012 Reloc::hix22(view
, value
, addend
);
3015 case elfcpp::R_SPARC_TLS_GD_LO10
:
3016 // TLS_GD_LO10 --> TLS_LE_LOX10
3017 Reloc::lox10(view
, value
, addend
);
3020 case elfcpp::R_SPARC_TLS_GD_ADD
:
3021 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
3022 val
= elfcpp::Swap
<32, true>::readval(wv
);
3023 val
= (val
& ~0x7c000) | 0x1c000;
3024 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3026 case elfcpp::R_SPARC_TLS_GD_CALL
:
3027 // call __tls_get_addr --> nop
3028 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3035 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
3036 ? GOT_TYPE_TLS_OFFSET
3037 : GOT_TYPE_TLS_PAIR
);
3040 gold_assert(gsym
->has_got_offset(got_type
));
3041 value
= gsym
->got_offset(got_type
);
3045 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3046 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
3047 value
= object
->local_got_offset(r_sym
, got_type
);
3049 if (optimized_type
== tls::TLSOPT_TO_IE
)
3051 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3056 case elfcpp::R_SPARC_TLS_GD_HI22
:
3057 // TLS_GD_HI22 --> TLS_IE_HI22
3058 Reloc::hi22(view
, value
, addend
);
3061 case elfcpp::R_SPARC_TLS_GD_LO10
:
3062 // TLS_GD_LO10 --> TLS_IE_LO10
3063 Reloc::lo10(view
, value
, addend
);
3066 case elfcpp::R_SPARC_TLS_GD_ADD
:
3067 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
3068 val
= elfcpp::Swap
<32, true>::readval(wv
);
3075 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3078 case elfcpp::R_SPARC_TLS_GD_CALL
:
3079 // The compiler can put the TLS_GD_ADD instruction
3080 // into the delay slot of the call. If so, we need
3081 // to transpose the two instructions so that the
3082 // new sequence works properly.
3084 // The test we use is if the instruction in the
3085 // delay slot is an add with destination register
3087 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
3088 if ((val
& 0x81f80000) == 0x80000000
3089 && ((val
>> 25) & 0x1f) == 0x8)
3096 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3099 this->ignore_gd_add_
= true;
3102 // call __tls_get_addr --> add %g7, %o0, %o0
3103 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
3108 else if (optimized_type
== tls::TLSOPT_NONE
)
3112 case elfcpp::R_SPARC_TLS_GD_HI22
:
3113 Reloc::hi22(view
, value
, addend
);
3115 case elfcpp::R_SPARC_TLS_GD_LO10
:
3116 Reloc::lo10(view
, value
, addend
);
3118 case elfcpp::R_SPARC_TLS_GD_ADD
:
3120 case elfcpp::R_SPARC_TLS_GD_CALL
:
3122 Symbol_value
<size
> symval
;
3123 elfcpp::Elf_Xword value
;
3126 tsym
= target
->tls_get_addr_sym_
;
3128 value
= (target
->plt_section()->address() +
3129 tsym
->plt_offset());
3130 symval
.set_output_value(value
);
3131 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3138 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3139 _("unsupported reloc %u"),
3143 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3144 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3145 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3146 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3147 if (optimized_type
== tls::TLSOPT_TO_LE
)
3149 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3153 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3154 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3155 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3156 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
3159 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3160 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
3165 else if (optimized_type
== tls::TLSOPT_NONE
)
3167 // Relocate the field with the offset of the GOT entry for
3168 // the module index.
3169 unsigned int got_offset
;
3171 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
3174 case elfcpp::R_SPARC_TLS_LDM_HI22
:
3175 Reloc::hi22(view
, got_offset
, addend
);
3177 case elfcpp::R_SPARC_TLS_LDM_LO10
:
3178 Reloc::lo10(view
, got_offset
, addend
);
3180 case elfcpp::R_SPARC_TLS_LDM_ADD
:
3182 case elfcpp::R_SPARC_TLS_LDM_CALL
:
3184 Symbol_value
<size
> symval
;
3185 elfcpp::Elf_Xword value
;
3188 tsym
= target
->tls_get_addr_sym_
;
3190 value
= (target
->plt_section()->address() +
3191 tsym
->plt_offset());
3192 symval
.set_output_value(value
);
3193 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3199 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3200 _("unsupported reloc %u"),
3204 // These relocs can appear in debugging sections, in which case
3205 // we won't see the TLS_LDM relocs. The local_dynamic_type
3206 // field tells us this.
3207 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3208 if (optimized_type
== tls::TLSOPT_TO_LE
)
3210 value
-= tls_segment
->memsz();
3211 Reloc::hix22(view
, value
, addend
);
3214 Reloc::ldo_hix22(view
, value
, addend
);
3216 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3217 if (optimized_type
== tls::TLSOPT_TO_LE
)
3219 value
-= tls_segment
->memsz();
3220 Reloc::lox10(view
, value
, addend
);
3223 Reloc::ldo_lox10(view
, value
, addend
);
3225 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3226 if (optimized_type
== tls::TLSOPT_TO_LE
)
3228 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3231 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3232 val
= elfcpp::Swap
<32, true>::readval(wv
);
3233 val
= (val
& ~0x7c000) | 0x1c000;
3234 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3238 // When optimizing IE --> LE, the only relocation that is handled
3239 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3240 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3241 // rs2 and rd are the same.
3242 case elfcpp::R_SPARC_TLS_IE_LD
:
3243 case elfcpp::R_SPARC_TLS_IE_LDX
:
3244 if (optimized_type
== tls::TLSOPT_TO_LE
)
3246 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3247 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3248 Insntype rs2
= val
& 0x1f;
3249 Insntype rd
= (val
>> 25) & 0x1f;
3254 val
= sparc_mov
| (val
& 0x3e00001f);
3256 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3260 case elfcpp::R_SPARC_TLS_IE_HI22
:
3261 case elfcpp::R_SPARC_TLS_IE_LO10
:
3262 if (optimized_type
== tls::TLSOPT_TO_LE
)
3264 value
-= tls_segment
->memsz();
3267 case elfcpp::R_SPARC_TLS_IE_HI22
:
3268 // IE_HI22 --> LE_HIX22
3269 Reloc::hix22(view
, value
, addend
);
3271 case elfcpp::R_SPARC_TLS_IE_LO10
:
3272 // IE_LO10 --> LE_LOX10
3273 Reloc::lox10(view
, value
, addend
);
3278 else if (optimized_type
== tls::TLSOPT_NONE
)
3280 // Relocate the field with the offset of the GOT entry for
3281 // the tp-relative offset of the symbol.
3284 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3285 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3289 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3290 gold_assert(object
->local_has_got_offset(r_sym
,
3291 GOT_TYPE_TLS_OFFSET
));
3292 value
= object
->local_got_offset(r_sym
,
3293 GOT_TYPE_TLS_OFFSET
);
3297 case elfcpp::R_SPARC_TLS_IE_HI22
:
3298 Reloc::hi22(view
, value
, addend
);
3300 case elfcpp::R_SPARC_TLS_IE_LO10
:
3301 Reloc::lo10(view
, value
, addend
);
3306 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3307 _("unsupported reloc %u"),
3311 case elfcpp::R_SPARC_TLS_IE_ADD
:
3312 // This seems to be mainly so that we can find the addition
3313 // instruction if there is one. There doesn't seem to be any
3314 // actual relocation to apply.
3317 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3318 // If we're creating a shared library, a dynamic relocation will
3319 // have been created for this location, so do not apply it now.
3320 if (!parameters
->options().shared())
3322 value
-= tls_segment
->memsz();
3323 Reloc::hix22(view
, value
, addend
);
3327 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3328 // If we're creating a shared library, a dynamic relocation will
3329 // have been created for this location, so do not apply it now.
3330 if (!parameters
->options().shared())
3332 value
-= tls_segment
->memsz();
3333 Reloc::lox10(view
, value
, addend
);
3339 // Relocate section data.
3341 template<int size
, bool big_endian
>
3343 Target_sparc
<size
, big_endian
>::relocate_section(
3344 const Relocate_info
<size
, big_endian
>* relinfo
,
3345 unsigned int sh_type
,
3346 const unsigned char* prelocs
,
3348 Output_section
* output_section
,
3349 bool needs_special_offset_handling
,
3350 unsigned char* view
,
3351 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3352 section_size_type view_size
,
3353 const Reloc_symbol_changes
* reloc_symbol_changes
)
3355 typedef Target_sparc
<size
, big_endian
> Sparc
;
3356 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3358 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3360 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3367 needs_special_offset_handling
,
3371 reloc_symbol_changes
);
3374 // Return the size of a relocation while scanning during a relocatable
3377 template<int size
, bool big_endian
>
3379 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3383 // We are always SHT_RELA, so we should never get here.
3388 // Scan the relocs during a relocatable link.
3390 template<int size
, bool big_endian
>
3392 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3393 Symbol_table
* symtab
,
3395 Sized_relobj
<size
, big_endian
>* object
,
3396 unsigned int data_shndx
,
3397 unsigned int sh_type
,
3398 const unsigned char* prelocs
,
3400 Output_section
* output_section
,
3401 bool needs_special_offset_handling
,
3402 size_t local_symbol_count
,
3403 const unsigned char* plocal_symbols
,
3404 Relocatable_relocs
* rr
)
3406 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3408 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3409 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3411 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3412 Scan_relocatable_relocs
>(
3420 needs_special_offset_handling
,
3426 // Relocate a section during a relocatable link.
3428 template<int size
, bool big_endian
>
3430 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3431 const Relocate_info
<size
, big_endian
>* relinfo
,
3432 unsigned int sh_type
,
3433 const unsigned char* prelocs
,
3435 Output_section
* output_section
,
3436 off_t offset_in_output_section
,
3437 const Relocatable_relocs
* rr
,
3438 unsigned char* view
,
3439 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3440 section_size_type view_size
,
3441 unsigned char* reloc_view
,
3442 section_size_type reloc_view_size
)
3444 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3446 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3451 offset_in_output_section
,
3460 // Return the value to use for a dynamic which requires special
3461 // treatment. This is how we support equality comparisons of function
3462 // pointers across shared library boundaries, as described in the
3463 // processor specific ABI supplement.
3465 template<int size
, bool big_endian
>
3467 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3469 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3470 return this->plt_section()->address() + gsym
->plt_offset();
3473 // The selector for sparc object files.
3475 template<int size
, bool big_endian
>
3476 class Target_selector_sparc
: public Target_selector
3479 Target_selector_sparc()
3480 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3481 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3484 Target
* do_recognize(int machine
, int, int)
3489 if (machine
!= elfcpp::EM_SPARCV9
)
3494 if (machine
!= elfcpp::EM_SPARC
3495 && machine
!= elfcpp::EM_SPARC32PLUS
)
3503 return this->instantiate_target();
3506 Target
* do_instantiate_target()
3507 { return new Target_sparc
<size
, big_endian
>(); }
3510 Target_selector_sparc
<32, true> target_selector_sparc32
;
3511 Target_selector_sparc
<64, true> target_selector_sparc64
;
3513 } // End anonymous namespace.