1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008, 2009 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();
172 // The class which scans relocations.
177 : issued_non_pic_error_(false)
181 local(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
182 Sized_relobj
<size
, big_endian
>* object
,
183 unsigned int data_shndx
,
184 Output_section
* output_section
,
185 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
186 const elfcpp::Sym
<size
, big_endian
>& lsym
);
189 global(Symbol_table
* symtab
, Layout
* layout
, Target_sparc
* target
,
190 Sized_relobj
<size
, big_endian
>* object
,
191 unsigned int data_shndx
,
192 Output_section
* output_section
,
193 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
198 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
199 unsigned int r_type
);
202 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
203 unsigned int r_type
, Symbol
*);
206 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
207 Target_sparc
* target
);
210 check_non_pic(Relobj
*, unsigned int r_type
);
212 // Whether we have issued an error about a non-PIC compilation.
213 bool issued_non_pic_error_
;
216 // The class which implements relocation.
221 : ignore_gd_add_(false)
226 if (this->ignore_gd_add_
)
228 // FIXME: This needs to specify the location somehow.
229 gold_error(_("missing expected TLS relocation"));
233 // Do a relocation. Return false if the caller should not issue
234 // any warnings about this relocation.
236 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
237 Output_section
*, size_t relnum
,
238 const elfcpp::Rela
<size
, big_endian
>&,
239 unsigned int r_type
, const Sized_symbol
<size
>*,
240 const Symbol_value
<size
>*,
242 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
246 // Do a TLS relocation.
248 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
249 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
250 unsigned int r_type
, const Sized_symbol
<size
>*,
251 const Symbol_value
<size
>*,
253 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
256 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
260 // A class which returns the size required for a relocation type,
261 // used while scanning relocs during a relocatable link.
262 class Relocatable_size_for_reloc
266 get_size_for_reloc(unsigned int, Relobj
*);
269 // Get the GOT section, creating it if necessary.
270 Output_data_got
<size
, big_endian
>*
271 got_section(Symbol_table
*, Layout
*);
273 // Create a PLT entry for a global symbol.
275 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
277 // Create a GOT entry for the TLS module index.
279 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
280 Sized_relobj
<size
, big_endian
>* object
);
282 // Return the gsym for "__tls_get_addr". Cache if not already
285 tls_get_addr_sym(Symbol_table
* symtab
)
287 if (!this->tls_get_addr_sym_
)
288 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
289 gold_assert(this->tls_get_addr_sym_
);
290 return this->tls_get_addr_sym_
;
293 // Get the PLT section.
294 const Output_data_plt_sparc
<size
, big_endian
>*
297 gold_assert(this->plt_
!= NULL
);
301 // Get the dynamic reloc section, creating it if necessary.
303 rela_dyn_section(Layout
*);
305 // Copy a relocation against a global symbol.
307 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
308 Sized_relobj
<size
, big_endian
>* object
,
309 unsigned int shndx
, Output_section
* output_section
,
310 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
312 this->copy_relocs_
.copy_reloc(symtab
, layout
,
313 symtab
->get_sized_symbol
<size
>(sym
),
314 object
, shndx
, output_section
,
315 reloc
, this->rela_dyn_section(layout
));
318 // Information about this specific target which we pass to the
319 // general Target structure.
320 static Target::Target_info sparc_info
;
322 // The types of GOT entries needed for this platform.
325 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
326 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
327 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
331 Output_data_got
<size
, big_endian
>* got_
;
333 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
334 // The dynamic reloc section.
335 Reloc_section
* rela_dyn_
;
336 // Relocs saved to avoid a COPY reloc.
337 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
338 // Space for variables copied with a COPY reloc.
339 Output_data_space
* dynbss_
;
340 // Offset of the GOT entry for the TLS module index;
341 unsigned int got_mod_index_offset_
;
342 // Cached pointer to __tls_get_addr symbol
343 Symbol
* tls_get_addr_sym_
;
347 Target::Target_info Target_sparc
<32, true>::sparc_info
=
350 true, // is_big_endian
351 elfcpp::EM_SPARC
, // machine_code
352 false, // has_make_symbol
353 false, // has_resolve
354 false, // has_code_fill
355 true, // is_default_stack_executable
357 "/usr/lib/ld.so.1", // dynamic_linker
358 0x00010000, // default_text_segment_address
359 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
360 8 * 1024, // common_pagesize (overridable by -z common-page-size)
361 elfcpp::SHN_UNDEF
, // small_common_shndx
362 elfcpp::SHN_UNDEF
, // large_common_shndx
363 0, // small_common_section_flags
364 0, // large_common_section_flags
365 NULL
, // attributes_section
366 NULL
// attributes_vendor
370 Target::Target_info Target_sparc
<64, true>::sparc_info
=
373 true, // is_big_endian
374 elfcpp::EM_SPARCV9
, // machine_code
375 false, // has_make_symbol
376 false, // has_resolve
377 false, // has_code_fill
378 true, // is_default_stack_executable
380 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
381 0x100000, // default_text_segment_address
382 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
383 8 * 1024, // common_pagesize (overridable by -z common-page-size)
384 elfcpp::SHN_UNDEF
, // small_common_shndx
385 elfcpp::SHN_UNDEF
, // large_common_shndx
386 0, // small_common_section_flags
387 0, // large_common_section_flags
388 NULL
, // attributes_section
389 NULL
// attributes_vendor
392 // We have to take care here, even when operating in little-endian
393 // mode, sparc instructions are still big endian.
394 template<int size
, bool big_endian
>
395 class Sparc_relocate_functions
398 // Do a simple relocation with the addend in the relocation.
399 template<int valsize
>
401 rela(unsigned char* view
,
402 unsigned int right_shift
,
403 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
404 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
405 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
407 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
408 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
409 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
410 Valtype reloc
= ((value
+ addend
) >> right_shift
);
415 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
418 // Do a simple relocation using a symbol value with the addend in
420 template<int valsize
>
422 rela(unsigned char* view
,
423 unsigned int right_shift
,
424 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
425 const Sized_relobj
<size
, big_endian
>* object
,
426 const Symbol_value
<size
>* psymval
,
427 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
429 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
430 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
431 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
432 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
437 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
440 // Do a simple relocation using a symbol value with the addend in
441 // the relocation, unaligned.
442 template<int valsize
>
444 rela_ua(unsigned char* view
,
445 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
446 const Sized_relobj
<size
, big_endian
>* object
,
447 const Symbol_value
<size
>* psymval
,
448 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
450 typedef typename
elfcpp::Swap_unaligned
<valsize
,
451 big_endian
>::Valtype Valtype
;
452 unsigned char* wv
= view
;
453 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
454 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
459 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
462 // Do a simple PC relative relocation with a Symbol_value with the
463 // addend in the relocation.
464 template<int valsize
>
466 pcrela(unsigned char* view
,
467 unsigned int right_shift
,
468 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
469 const Sized_relobj
<size
, big_endian
>* object
,
470 const Symbol_value
<size
>* psymval
,
471 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
472 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
474 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
475 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
476 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
477 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
483 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
486 template<int valsize
>
488 pcrela_unaligned(unsigned char* view
,
489 const Sized_relobj
<size
, big_endian
>* object
,
490 const Symbol_value
<size
>* psymval
,
491 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
492 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
494 typedef typename
elfcpp::Swap_unaligned
<valsize
,
495 big_endian
>::Valtype Valtype
;
496 unsigned char* wv
= view
;
497 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
499 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
502 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
503 typedef Sparc_relocate_functions
<size
, true> This_insn
;
506 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
508 wdisp30(unsigned char* view
,
509 const Sized_relobj
<size
, big_endian
>* object
,
510 const Symbol_value
<size
>* psymval
,
511 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
512 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
514 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
515 psymval
, addend
, address
);
518 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
520 wdisp22(unsigned char* view
,
521 const Sized_relobj
<size
, big_endian
>* object
,
522 const Symbol_value
<size
>* psymval
,
523 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
524 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
526 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
527 psymval
, addend
, address
);
530 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
532 wdisp19(unsigned char* view
,
533 const Sized_relobj
<size
, big_endian
>* object
,
534 const Symbol_value
<size
>* psymval
,
535 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
536 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
538 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
539 psymval
, addend
, address
);
542 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
544 wdisp16(unsigned char* view
,
545 const Sized_relobj
<size
, big_endian
>* object
,
546 const Symbol_value
<size
>* psymval
,
547 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
548 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
550 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
551 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
552 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
553 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
556 // The relocation value is split between the low 14 bits,
558 val
&= ~((0x3 << 20) | 0x3fff);
559 reloc
= (((reloc
& 0xc000) << (20 - 14))
560 | (reloc
& 0x3ffff));
562 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
565 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
567 pc22(unsigned char* view
,
568 const Sized_relobj
<size
, big_endian
>* object
,
569 const Symbol_value
<size
>* psymval
,
570 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
571 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
573 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
574 psymval
, addend
, address
);
577 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
579 pc10(unsigned char* view
,
580 const Sized_relobj
<size
, big_endian
>* object
,
581 const Symbol_value
<size
>* psymval
,
582 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
583 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
585 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
586 psymval
, addend
, address
);
589 // R_SPARC_HI22: (Symbol + Addend) >> 10
591 hi22(unsigned char* view
,
592 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
593 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
595 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
598 // R_SPARC_HI22: (Symbol + Addend) >> 10
600 hi22(unsigned char* view
,
601 const Sized_relobj
<size
, big_endian
>* object
,
602 const Symbol_value
<size
>* psymval
,
603 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
605 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
608 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
610 pcplt22(unsigned char* view
,
611 const Sized_relobj
<size
, big_endian
>* object
,
612 const Symbol_value
<size
>* psymval
,
613 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
614 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
616 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
617 psymval
, addend
, address
);
620 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
622 lo10(unsigned char* view
,
623 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
624 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
626 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
629 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
631 lo10(unsigned char* view
,
632 const Sized_relobj
<size
, big_endian
>* object
,
633 const Symbol_value
<size
>* psymval
,
634 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
636 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
639 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
641 lo10(unsigned char* view
,
642 const Sized_relobj
<size
, big_endian
>* object
,
643 const Symbol_value
<size
>* psymval
,
644 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
645 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
647 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
648 psymval
, addend
, address
);
651 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
653 olo10(unsigned char* view
,
654 const Sized_relobj
<size
, big_endian
>* object
,
655 const Symbol_value
<size
>* psymval
,
656 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
657 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
659 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
660 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
661 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
662 Valtype reloc
= psymval
->value(object
, addend
);
669 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
672 // R_SPARC_22: (Symbol + Addend)
674 rela32_22(unsigned char* view
,
675 const Sized_relobj
<size
, big_endian
>* object
,
676 const Symbol_value
<size
>* psymval
,
677 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
679 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
682 // R_SPARC_13: (Symbol + Addend)
684 rela32_13(unsigned char* view
,
685 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
686 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
688 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
691 // R_SPARC_13: (Symbol + Addend)
693 rela32_13(unsigned char* view
,
694 const Sized_relobj
<size
, big_endian
>* object
,
695 const Symbol_value
<size
>* psymval
,
696 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
698 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
701 // R_SPARC_UA16: (Symbol + Addend)
703 ua16(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
)
708 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
711 // R_SPARC_UA32: (Symbol + Addend)
713 ua32(unsigned char* view
,
714 const Sized_relobj
<size
, big_endian
>* object
,
715 const Symbol_value
<size
>* psymval
,
716 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
718 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
721 // R_SPARC_UA64: (Symbol + Addend)
723 ua64(unsigned char* view
,
724 const Sized_relobj
<size
, big_endian
>* object
,
725 const Symbol_value
<size
>* psymval
,
726 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
728 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
729 object
, psymval
, addend
);
732 // R_SPARC_DISP8: (Symbol + Addend - Address)
734 disp8(unsigned char* view
,
735 const Sized_relobj
<size
, big_endian
>* object
,
736 const Symbol_value
<size
>* psymval
,
737 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
738 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
740 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
744 // R_SPARC_DISP16: (Symbol + Addend - Address)
746 disp16(unsigned char* view
,
747 const Sized_relobj
<size
, big_endian
>* object
,
748 const Symbol_value
<size
>* psymval
,
749 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
750 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
752 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
756 // R_SPARC_DISP32: (Symbol + Addend - Address)
758 disp32(unsigned char* view
,
759 const Sized_relobj
<size
, big_endian
>* object
,
760 const Symbol_value
<size
>* psymval
,
761 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
762 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
764 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
768 // R_SPARC_DISP64: (Symbol + Addend - Address)
770 disp64(unsigned char* view
,
771 const Sized_relobj
<size
, big_endian
>* object
,
772 const Symbol_value
<size
>* psymval
,
773 elfcpp::Elf_Xword addend
,
774 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
776 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
780 // R_SPARC_H44: (Symbol + Addend) >> 22
782 h44(unsigned char* view
,
783 const Sized_relobj
<size
, big_endian
>* object
,
784 const Symbol_value
<size
>* psymval
,
785 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
787 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
790 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
792 m44(unsigned char* view
,
793 const Sized_relobj
<size
, big_endian
>* object
,
794 const Symbol_value
<size
>* psymval
,
795 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
797 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
800 // R_SPARC_L44: (Symbol + Addend) & 0xfff
802 l44(unsigned char* view
,
803 const Sized_relobj
<size
, big_endian
>* object
,
804 const Symbol_value
<size
>* psymval
,
805 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
807 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
810 // R_SPARC_HH22: (Symbol + Addend) >> 42
812 hh22(unsigned char* view
,
813 const Sized_relobj
<size
, big_endian
>* object
,
814 const Symbol_value
<size
>* psymval
,
815 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
817 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
820 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
822 pc_hh22(unsigned char* view
,
823 const Sized_relobj
<size
, big_endian
>* object
,
824 const Symbol_value
<size
>* psymval
,
825 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
826 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
828 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
829 psymval
, addend
, address
);
832 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
834 hm10(unsigned char* view
,
835 const Sized_relobj
<size
, big_endian
>* object
,
836 const Symbol_value
<size
>* psymval
,
837 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
839 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
842 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
844 pc_hm10(unsigned char* view
,
845 const Sized_relobj
<size
, big_endian
>* object
,
846 const Symbol_value
<size
>* psymval
,
847 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
848 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
850 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
851 psymval
, addend
, address
);
854 // R_SPARC_11: (Symbol + Addend)
856 rela32_11(unsigned char* view
,
857 const Sized_relobj
<size
, big_endian
>* object
,
858 const Symbol_value
<size
>* psymval
,
859 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
861 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
864 // R_SPARC_10: (Symbol + Addend)
866 rela32_10(unsigned char* view
,
867 const Sized_relobj
<size
, big_endian
>* object
,
868 const Symbol_value
<size
>* psymval
,
869 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
871 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
874 // R_SPARC_7: (Symbol + Addend)
876 rela32_7(unsigned char* view
,
877 const Sized_relobj
<size
, big_endian
>* object
,
878 const Symbol_value
<size
>* psymval
,
879 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
881 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
884 // R_SPARC_6: (Symbol + Addend)
886 rela32_6(unsigned char* view
,
887 const Sized_relobj
<size
, big_endian
>* object
,
888 const Symbol_value
<size
>* psymval
,
889 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
891 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
894 // R_SPARC_5: (Symbol + Addend)
896 rela32_5(unsigned char* view
,
897 const Sized_relobj
<size
, big_endian
>* object
,
898 const Symbol_value
<size
>* psymval
,
899 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
901 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
904 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
906 ldo_hix22(unsigned char* view
,
907 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
908 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
910 This_insn::hi22(view
, value
, addend
);
913 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
915 ldo_lox10(unsigned char* view
,
916 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
917 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
919 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
920 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
921 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
922 Valtype reloc
= (value
+ addend
);
927 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
930 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
932 hix22(unsigned char* view
,
933 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
934 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
936 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
937 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
938 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
939 Valtype reloc
= (value
+ addend
);
943 reloc
^= ~(Valtype
)0;
948 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
951 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
953 hix22(unsigned char* view
,
954 const Sized_relobj
<size
, big_endian
>* object
,
955 const Symbol_value
<size
>* psymval
,
956 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
958 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
959 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
960 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
961 Valtype reloc
= psymval
->value(object
, addend
);
965 reloc
^= ~(Valtype
)0;
970 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
974 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
976 lox10(unsigned char* view
,
977 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
978 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
980 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
981 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
982 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
983 Valtype reloc
= (value
+ addend
);
989 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
992 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
994 lox10(unsigned char* view
,
995 const Sized_relobj
<size
, big_endian
>* object
,
996 const Symbol_value
<size
>* psymval
,
997 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
999 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1000 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1001 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1002 Valtype reloc
= psymval
->value(object
, addend
);
1008 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1012 // Get the GOT section, creating it if necessary.
1014 template<int size
, bool big_endian
>
1015 Output_data_got
<size
, big_endian
>*
1016 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1019 if (this->got_
== NULL
)
1021 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1023 this->got_
= new Output_data_got
<size
, big_endian
>();
1026 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1028 | elfcpp::SHF_WRITE
),
1029 this->got_
, false, true, false,
1032 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1033 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1034 Symbol_table::PREDEFINED
,
1036 0, 0, elfcpp::STT_OBJECT
,
1038 elfcpp::STV_HIDDEN
, 0,
1045 // Get the dynamic reloc section, creating it if necessary.
1047 template<int size
, bool big_endian
>
1048 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1049 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1051 if (this->rela_dyn_
== NULL
)
1053 gold_assert(layout
!= NULL
);
1054 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1055 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1056 elfcpp::SHF_ALLOC
, this->rela_dyn_
, true,
1057 false, false, false);
1059 return this->rela_dyn_
;
1062 // A class to handle the PLT data.
1064 template<int size
, bool big_endian
>
1065 class Output_data_plt_sparc
: public Output_section_data
1068 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1069 size
, big_endian
> Reloc_section
;
1071 Output_data_plt_sparc(Layout
*);
1073 // Add an entry to the PLT.
1074 void add_entry(Symbol
* gsym
);
1076 // Return the .rela.plt section data.
1077 const Reloc_section
* rel_plt() const
1083 void do_adjust_output_section(Output_section
* os
);
1085 // Write to a map file.
1087 do_print_to_mapfile(Mapfile
* mapfile
) const
1088 { mapfile
->print_output_data(this, _("** PLT")); }
1091 // The size of an entry in the PLT.
1092 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1094 static const unsigned int plt_entries_per_block
= 160;
1095 static const unsigned int plt_insn_chunk_size
= 24;
1096 static const unsigned int plt_pointer_chunk_size
= 8;
1097 static const unsigned int plt_block_size
=
1098 (plt_entries_per_block
1099 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1101 // Set the final size.
1103 set_final_data_size()
1105 unsigned int full_count
= this->count_
+ 4;
1106 unsigned int extra
= (size
== 32 ? 4 : 0);
1108 if (size
== 32 || full_count
< 32768)
1109 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1112 unsigned int ext_cnt
= full_count
- 32768;
1114 this->set_data_size((32768 * base_plt_entry_size
)
1116 * (plt_insn_chunk_size
1117 + plt_pointer_chunk_size
)));
1121 // Write out the PLT data.
1123 do_write(Output_file
*);
1125 // The reloc section.
1126 Reloc_section
* rel_
;
1127 // The number of PLT entries.
1128 unsigned int count_
;
1131 // Define the constants as required by C++ standard.
1133 template<int size
, bool big_endian
>
1134 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1136 template<int size
, bool big_endian
>
1138 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1140 template<int size
, bool big_endian
>
1141 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1143 template<int size
, bool big_endian
>
1145 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1147 template<int size
, bool big_endian
>
1148 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1150 // Create the PLT section. The ordinary .got section is an argument,
1151 // since we need to refer to the start.
1153 template<int size
, bool big_endian
>
1154 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1155 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1157 this->rel_
= new Reloc_section(false);
1158 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1159 elfcpp::SHF_ALLOC
, this->rel_
, true,
1160 false, false, false);
1163 template<int size
, bool big_endian
>
1165 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1170 // Add an entry to the PLT.
1172 template<int size
, bool big_endian
>
1174 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1176 gold_assert(!gsym
->has_plt_offset());
1178 unsigned int index
= this->count_
+ 4;
1179 section_offset_type plt_offset
;
1181 if (size
== 32 || index
< 32768)
1182 plt_offset
= index
* base_plt_entry_size
;
1185 unsigned int ext_index
= index
- 32768;
1187 plt_offset
= (32768 * base_plt_entry_size
)
1188 + ((ext_index
/ plt_entries_per_block
)
1190 + ((ext_index
% plt_entries_per_block
)
1191 * plt_insn_chunk_size
);
1194 gsym
->set_plt_offset(plt_offset
);
1198 // Every PLT entry needs a reloc.
1199 gsym
->set_needs_dynsym_entry();
1200 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1203 // Note that we don't need to save the symbol. The contents of the
1204 // PLT are independent of which symbols are used. The symbols only
1205 // appear in the relocations.
1208 static const unsigned int sparc_nop
= 0x01000000;
1209 static const unsigned int sparc_sethi_g1
= 0x03000000;
1210 static const unsigned int sparc_branch_always
= 0x30800000;
1211 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1212 static const unsigned int sparc_mov
= 0x80100000;
1213 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1214 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1215 static const unsigned int sparc_call_plus_8
= 0x40000002;
1216 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1217 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1218 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1220 // Write out the PLT.
1222 template<int size
, bool big_endian
>
1224 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1226 const off_t offset
= this->offset();
1227 const section_size_type oview_size
=
1228 convert_to_section_size_type(this->data_size());
1229 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1230 unsigned char* pov
= oview
;
1232 memset(pov
, 0, base_plt_entry_size
* 4);
1233 pov
+= base_plt_entry_size
* 4;
1235 unsigned int plt_offset
= base_plt_entry_size
* 4;
1236 const unsigned int count
= this->count_
;
1242 limit
= (count
> 32768 ? 32768 : count
);
1244 for (unsigned int i
= 0; i
< limit
; ++i
)
1246 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1247 sparc_sethi_g1
+ plt_offset
);
1248 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1249 sparc_branch_always_pt
+
1250 (((base_plt_entry_size
-
1251 (plt_offset
+ 4)) >> 2) &
1253 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1254 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1255 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1256 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1257 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1258 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1260 pov
+= base_plt_entry_size
;
1261 plt_offset
+= base_plt_entry_size
;
1266 unsigned int ext_cnt
= count
- 32768;
1267 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1269 for (unsigned int i
= 0; i
< blks
; ++i
)
1271 unsigned int data_off
= (plt_entries_per_block
1272 * plt_insn_chunk_size
) - 4;
1274 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1276 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1278 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1280 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1282 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1283 sparc_ldx_o7_imm_g1
+
1284 (data_off
& 0x1fff));
1285 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1286 sparc_jmpl_o7_g1_g1
);
1287 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1290 elfcpp::Swap
<64, big_endian
>::writeval(
1291 pov
+ 0x4 + data_off
,
1292 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1294 pov
+= plt_insn_chunk_size
;
1299 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1300 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1302 unsigned int data_off
= (sub_blk_cnt
1303 * plt_insn_chunk_size
) - 4;
1305 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1307 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1309 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1311 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1313 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1314 sparc_ldx_o7_imm_g1
+
1315 (data_off
& 0x1fff));
1316 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1317 sparc_jmpl_o7_g1_g1
);
1318 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1321 elfcpp::Swap
<64, big_endian
>::writeval(
1322 pov
+ 0x4 + data_off
,
1323 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1325 pov
+= plt_insn_chunk_size
;
1333 for (unsigned int i
= 0; i
< count
; ++i
)
1335 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1336 sparc_sethi_g1
+ plt_offset
);
1337 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1338 sparc_branch_always
+
1339 (((- (plt_offset
+ 4)) >> 2) &
1341 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1343 pov
+= base_plt_entry_size
;
1344 plt_offset
+= base_plt_entry_size
;
1347 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1351 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1353 of
->write_output_view(offset
, oview_size
, oview
);
1356 // Create a PLT entry for a global symbol.
1358 template<int size
, bool big_endian
>
1360 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1364 if (gsym
->has_plt_offset())
1367 if (this->plt_
== NULL
)
1369 // Create the GOT sections first.
1370 this->got_section(symtab
, layout
);
1372 // Ensure that .rela.dyn always appears before .rela.plt This is
1373 // necessary due to how, on Sparc and some other targets, .rela.dyn
1374 // needs to include .rela.plt in it's range.
1375 this->rela_dyn_section(layout
);
1377 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1378 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1380 | elfcpp::SHF_EXECINSTR
1381 | elfcpp::SHF_WRITE
),
1382 this->plt_
, false, false, false, false);
1384 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1385 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1386 Symbol_table::PREDEFINED
,
1388 0, 0, elfcpp::STT_OBJECT
,
1390 elfcpp::STV_HIDDEN
, 0,
1394 this->plt_
->add_entry(gsym
);
1397 // Create a GOT entry for the TLS module index.
1399 template<int size
, bool big_endian
>
1401 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1403 Sized_relobj
<size
, big_endian
>* object
)
1405 if (this->got_mod_index_offset_
== -1U)
1407 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1408 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1409 Output_data_got
<size
, big_endian
>* got
;
1410 unsigned int got_offset
;
1412 got
= this->got_section(symtab
, layout
);
1413 got_offset
= got
->add_constant(0);
1414 rela_dyn
->add_local(object
, 0,
1416 elfcpp::R_SPARC_TLS_DTPMOD64
:
1417 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1419 got
->add_constant(0);
1420 this->got_mod_index_offset_
= got_offset
;
1422 return this->got_mod_index_offset_
;
1425 // Optimize the TLS relocation type based on what we know about the
1426 // symbol. IS_FINAL is true if the final address of this symbol is
1427 // known at link time.
1429 static tls::Tls_optimization
1430 optimize_tls_reloc(bool is_final
, int r_type
)
1432 // If we are generating a shared library, then we can't do anything
1434 if (parameters
->options().shared())
1435 return tls::TLSOPT_NONE
;
1439 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1440 case elfcpp::R_SPARC_TLS_GD_LO10
:
1441 case elfcpp::R_SPARC_TLS_GD_ADD
:
1442 case elfcpp::R_SPARC_TLS_GD_CALL
:
1443 // These are General-Dynamic which permits fully general TLS
1444 // access. Since we know that we are generating an executable,
1445 // we can convert this to Initial-Exec. If we also know that
1446 // this is a local symbol, we can further switch to Local-Exec.
1448 return tls::TLSOPT_TO_LE
;
1449 return tls::TLSOPT_TO_IE
;
1451 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1452 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1453 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1454 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1455 // This is Local-Dynamic, which refers to a local symbol in the
1456 // dynamic TLS block. Since we know that we generating an
1457 // executable, we can switch to Local-Exec.
1458 return tls::TLSOPT_TO_LE
;
1460 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1461 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1462 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1463 // Another type of Local-Dynamic relocation.
1464 return tls::TLSOPT_TO_LE
;
1466 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1467 case elfcpp::R_SPARC_TLS_IE_LO10
:
1468 case elfcpp::R_SPARC_TLS_IE_LD
:
1469 case elfcpp::R_SPARC_TLS_IE_LDX
:
1470 case elfcpp::R_SPARC_TLS_IE_ADD
:
1471 // These are Initial-Exec relocs which get the thread offset
1472 // from the GOT. If we know that we are linking against the
1473 // local symbol, we can switch to Local-Exec, which links the
1474 // thread offset into the instruction.
1476 return tls::TLSOPT_TO_LE
;
1477 return tls::TLSOPT_NONE
;
1479 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1480 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1481 // When we already have Local-Exec, there is nothing further we
1483 return tls::TLSOPT_NONE
;
1490 // Generate a PLT entry slot for a call to __tls_get_addr
1491 template<int size
, bool big_endian
>
1493 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1495 Target_sparc
<size
, big_endian
>* target
)
1497 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1499 target
->make_plt_entry(symtab
, layout
, gsym
);
1502 // Report an unsupported relocation against a local symbol.
1504 template<int size
, bool big_endian
>
1506 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1507 Sized_relobj
<size
, big_endian
>* object
,
1508 unsigned int r_type
)
1510 gold_error(_("%s: unsupported reloc %u against local symbol"),
1511 object
->name().c_str(), r_type
);
1514 // We are about to emit a dynamic relocation of type R_TYPE. If the
1515 // dynamic linker does not support it, issue an error.
1517 template<int size
, bool big_endian
>
1519 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1521 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1527 // These are the relocation types supported by glibc for sparc 64-bit.
1528 case elfcpp::R_SPARC_RELATIVE
:
1529 case elfcpp::R_SPARC_COPY
:
1530 case elfcpp::R_SPARC_64
:
1531 case elfcpp::R_SPARC_GLOB_DAT
:
1532 case elfcpp::R_SPARC_JMP_SLOT
:
1533 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1534 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1535 case elfcpp::R_SPARC_TLS_TPOFF64
:
1536 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1537 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1538 case elfcpp::R_SPARC_8
:
1539 case elfcpp::R_SPARC_16
:
1540 case elfcpp::R_SPARC_DISP8
:
1541 case elfcpp::R_SPARC_DISP16
:
1542 case elfcpp::R_SPARC_DISP32
:
1543 case elfcpp::R_SPARC_WDISP30
:
1544 case elfcpp::R_SPARC_LO10
:
1545 case elfcpp::R_SPARC_HI22
:
1546 case elfcpp::R_SPARC_OLO10
:
1547 case elfcpp::R_SPARC_H44
:
1548 case elfcpp::R_SPARC_M44
:
1549 case elfcpp::R_SPARC_L44
:
1550 case elfcpp::R_SPARC_HH22
:
1551 case elfcpp::R_SPARC_HM10
:
1552 case elfcpp::R_SPARC_LM22
:
1553 case elfcpp::R_SPARC_UA16
:
1554 case elfcpp::R_SPARC_UA32
:
1555 case elfcpp::R_SPARC_UA64
:
1566 // These are the relocation types supported by glibc for sparc 32-bit.
1567 case elfcpp::R_SPARC_RELATIVE
:
1568 case elfcpp::R_SPARC_COPY
:
1569 case elfcpp::R_SPARC_GLOB_DAT
:
1570 case elfcpp::R_SPARC_32
:
1571 case elfcpp::R_SPARC_JMP_SLOT
:
1572 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1573 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1574 case elfcpp::R_SPARC_TLS_TPOFF32
:
1575 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1576 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1577 case elfcpp::R_SPARC_8
:
1578 case elfcpp::R_SPARC_16
:
1579 case elfcpp::R_SPARC_DISP8
:
1580 case elfcpp::R_SPARC_DISP16
:
1581 case elfcpp::R_SPARC_DISP32
:
1582 case elfcpp::R_SPARC_LO10
:
1583 case elfcpp::R_SPARC_WDISP30
:
1584 case elfcpp::R_SPARC_HI22
:
1585 case elfcpp::R_SPARC_UA16
:
1586 case elfcpp::R_SPARC_UA32
:
1594 // This prevents us from issuing more than one error per reloc
1595 // section. But we can still wind up issuing more than one
1596 // error per object file.
1597 if (this->issued_non_pic_error_
)
1599 gold_assert(parameters
->options().output_is_position_independent());
1600 object
->error(_("requires unsupported dynamic reloc; "
1601 "recompile with -fPIC"));
1602 this->issued_non_pic_error_
= true;
1606 // Scan a relocation for a local symbol.
1608 template<int size
, bool big_endian
>
1610 Target_sparc
<size
, big_endian
>::Scan::local(
1611 Symbol_table
* symtab
,
1613 Target_sparc
<size
, big_endian
>* target
,
1614 Sized_relobj
<size
, big_endian
>* object
,
1615 unsigned int data_shndx
,
1616 Output_section
* output_section
,
1617 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1618 unsigned int r_type
,
1619 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1621 unsigned int orig_r_type
= r_type
;
1626 case elfcpp::R_SPARC_NONE
:
1627 case elfcpp::R_SPARC_REGISTER
:
1628 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1629 case elfcpp::R_SPARC_GNU_VTENTRY
:
1632 case elfcpp::R_SPARC_64
:
1633 case elfcpp::R_SPARC_32
:
1634 // If building a shared library (or a position-independent
1635 // executable), we need to create a dynamic relocation for
1636 // this location. The relocation applied at link time will
1637 // apply the link-time value, so we flag the location with
1638 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1639 // relocate it easily.
1640 if (parameters
->options().output_is_position_independent())
1642 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1643 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1644 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1645 output_section
, data_shndx
,
1646 reloc
.get_r_offset(),
1647 reloc
.get_r_addend());
1651 case elfcpp::R_SPARC_HIX22
:
1652 case elfcpp::R_SPARC_LOX10
:
1653 case elfcpp::R_SPARC_H44
:
1654 case elfcpp::R_SPARC_M44
:
1655 case elfcpp::R_SPARC_L44
:
1656 case elfcpp::R_SPARC_HH22
:
1657 case elfcpp::R_SPARC_HM10
:
1658 case elfcpp::R_SPARC_LM22
:
1659 case elfcpp::R_SPARC_UA64
:
1660 case elfcpp::R_SPARC_UA32
:
1661 case elfcpp::R_SPARC_UA16
:
1662 case elfcpp::R_SPARC_HI22
:
1663 case elfcpp::R_SPARC_LO10
:
1664 case elfcpp::R_SPARC_OLO10
:
1665 case elfcpp::R_SPARC_16
:
1666 case elfcpp::R_SPARC_11
:
1667 case elfcpp::R_SPARC_10
:
1668 case elfcpp::R_SPARC_8
:
1669 case elfcpp::R_SPARC_7
:
1670 case elfcpp::R_SPARC_6
:
1671 case elfcpp::R_SPARC_5
:
1672 // If building a shared library (or a position-independent
1673 // executable), we need to create a dynamic relocation for
1675 if (parameters
->options().output_is_position_independent())
1677 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1678 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1680 check_non_pic(object
, r_type
);
1681 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1683 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1684 data_shndx
, reloc
.get_r_offset(),
1685 reloc
.get_r_addend());
1689 gold_assert(lsym
.get_st_value() == 0);
1690 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, orig_r_type
,
1691 output_section
, data_shndx
,
1692 reloc
.get_r_offset(),
1693 reloc
.get_r_addend());
1698 case elfcpp::R_SPARC_WDISP30
:
1699 case elfcpp::R_SPARC_WDISP22
:
1700 case elfcpp::R_SPARC_WDISP19
:
1701 case elfcpp::R_SPARC_WDISP16
:
1702 case elfcpp::R_SPARC_DISP8
:
1703 case elfcpp::R_SPARC_DISP16
:
1704 case elfcpp::R_SPARC_DISP32
:
1705 case elfcpp::R_SPARC_DISP64
:
1706 case elfcpp::R_SPARC_PC10
:
1707 case elfcpp::R_SPARC_PC22
:
1710 case elfcpp::R_SPARC_GOTDATA_OP
:
1711 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
1712 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
1713 case elfcpp::R_SPARC_GOT10
:
1714 case elfcpp::R_SPARC_GOT13
:
1715 case elfcpp::R_SPARC_GOT22
:
1717 // The symbol requires a GOT entry.
1718 Output_data_got
<size
, big_endian
>* got
;
1721 got
= target
->got_section(symtab
, layout
);
1722 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1724 // If we are generating a shared object, we need to add a
1725 // dynamic relocation for this symbol's GOT entry.
1726 if (parameters
->options().output_is_position_independent())
1728 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1730 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1733 off
= got
->add_constant(0);
1734 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1735 rela_dyn
->add_local_relative(object
, r_sym
,
1736 elfcpp::R_SPARC_RELATIVE
,
1741 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1745 // These are initial TLS relocs, which are expected when
1747 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1748 case elfcpp::R_SPARC_TLS_GD_LO10
:
1749 case elfcpp::R_SPARC_TLS_GD_ADD
:
1750 case elfcpp::R_SPARC_TLS_GD_CALL
:
1751 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1752 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1753 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1754 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1755 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1756 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1757 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1758 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1759 case elfcpp::R_SPARC_TLS_IE_LO10
:
1760 case elfcpp::R_SPARC_TLS_IE_LD
:
1761 case elfcpp::R_SPARC_TLS_IE_LDX
:
1762 case elfcpp::R_SPARC_TLS_IE_ADD
:
1763 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1764 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1766 bool output_is_shared
= parameters
->options().shared();
1767 const tls::Tls_optimization optimized_type
1768 = optimize_tls_reloc(!output_is_shared
, r_type
);
1771 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1772 case elfcpp::R_SPARC_TLS_GD_LO10
:
1773 case elfcpp::R_SPARC_TLS_GD_ADD
:
1774 case elfcpp::R_SPARC_TLS_GD_CALL
:
1775 if (optimized_type
== tls::TLSOPT_NONE
)
1777 // Create a pair of GOT entries for the module index and
1778 // dtv-relative offset.
1779 Output_data_got
<size
, big_endian
>* got
1780 = target
->got_section(symtab
, layout
);
1781 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1782 unsigned int shndx
= lsym
.get_st_shndx();
1784 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1786 object
->error(_("local symbol %u has bad shndx %u"),
1789 got
->add_local_pair_with_rela(object
, r_sym
,
1790 lsym
.get_st_shndx(),
1792 target
->rela_dyn_section(layout
),
1794 ? elfcpp::R_SPARC_TLS_DTPMOD64
1795 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1797 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1798 generate_tls_call(symtab
, layout
, target
);
1800 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1801 unsupported_reloc_local(object
, r_type
);
1804 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1805 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1806 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1807 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1808 if (optimized_type
== tls::TLSOPT_NONE
)
1810 // Create a GOT entry for the module index.
1811 target
->got_mod_index_entry(symtab
, layout
, object
);
1813 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1814 generate_tls_call(symtab
, layout
, target
);
1816 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1817 unsupported_reloc_local(object
, r_type
);
1820 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1821 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1822 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1825 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1826 case elfcpp::R_SPARC_TLS_IE_LO10
:
1827 case elfcpp::R_SPARC_TLS_IE_LD
:
1828 case elfcpp::R_SPARC_TLS_IE_LDX
:
1829 case elfcpp::R_SPARC_TLS_IE_ADD
:
1830 layout
->set_has_static_tls();
1831 if (optimized_type
== tls::TLSOPT_NONE
)
1833 // Create a GOT entry for the tp-relative offset.
1834 Output_data_got
<size
, big_endian
>* got
1835 = target
->got_section(symtab
, layout
);
1836 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1838 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1840 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1841 unsigned int off
= got
->add_constant(0);
1843 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
, off
);
1845 rela_dyn
->add_symbolless_local_addend(object
, r_sym
,
1847 elfcpp::R_SPARC_TLS_TPOFF64
:
1848 elfcpp::R_SPARC_TLS_TPOFF32
),
1852 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1853 unsupported_reloc_local(object
, r_type
);
1856 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1857 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1858 layout
->set_has_static_tls();
1859 if (output_is_shared
)
1861 // We need to create a dynamic relocation.
1862 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1863 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1864 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1865 rela_dyn
->add_symbolless_local_addend(object
, r_sym
, r_type
,
1866 output_section
, data_shndx
,
1867 reloc
.get_r_offset(), 0);
1874 // These are relocations which should only be seen by the
1875 // dynamic linker, and should never be seen here.
1876 case elfcpp::R_SPARC_COPY
:
1877 case elfcpp::R_SPARC_GLOB_DAT
:
1878 case elfcpp::R_SPARC_JMP_SLOT
:
1879 case elfcpp::R_SPARC_RELATIVE
:
1880 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1881 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1882 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1883 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1884 case elfcpp::R_SPARC_TLS_TPOFF64
:
1885 case elfcpp::R_SPARC_TLS_TPOFF32
:
1886 gold_error(_("%s: unexpected reloc %u in object file"),
1887 object
->name().c_str(), r_type
);
1891 unsupported_reloc_local(object
, r_type
);
1896 // Report an unsupported relocation against a global symbol.
1898 template<int size
, bool big_endian
>
1900 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1901 Sized_relobj
<size
, big_endian
>* object
,
1902 unsigned int r_type
,
1905 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1906 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1909 // Scan a relocation for a global symbol.
1911 template<int size
, bool big_endian
>
1913 Target_sparc
<size
, big_endian
>::Scan::global(
1914 Symbol_table
* symtab
,
1916 Target_sparc
<size
, big_endian
>* target
,
1917 Sized_relobj
<size
, big_endian
>* object
,
1918 unsigned int data_shndx
,
1919 Output_section
* output_section
,
1920 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1921 unsigned int r_type
,
1924 unsigned int orig_r_type
= r_type
;
1926 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
1927 // section. We check here to avoid creating a dynamic reloc against
1928 // _GLOBAL_OFFSET_TABLE_.
1929 if (!target
->has_got_section()
1930 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
1931 target
->got_section(symtab
, layout
);
1936 case elfcpp::R_SPARC_NONE
:
1937 case elfcpp::R_SPARC_REGISTER
:
1938 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1939 case elfcpp::R_SPARC_GNU_VTENTRY
:
1942 case elfcpp::R_SPARC_PLT64
:
1943 case elfcpp::R_SPARC_PLT32
:
1944 case elfcpp::R_SPARC_HIPLT22
:
1945 case elfcpp::R_SPARC_LOPLT10
:
1946 case elfcpp::R_SPARC_PCPLT32
:
1947 case elfcpp::R_SPARC_PCPLT22
:
1948 case elfcpp::R_SPARC_PCPLT10
:
1949 case elfcpp::R_SPARC_WPLT30
:
1950 // If the symbol is fully resolved, this is just a PC32 reloc.
1951 // Otherwise we need a PLT entry.
1952 if (gsym
->final_value_is_known())
1954 // If building a shared library, we can also skip the PLT entry
1955 // if the symbol is defined in the output file and is protected
1957 if (gsym
->is_defined()
1958 && !gsym
->is_from_dynobj()
1959 && !gsym
->is_preemptible())
1961 target
->make_plt_entry(symtab
, layout
, gsym
);
1964 case elfcpp::R_SPARC_DISP8
:
1965 case elfcpp::R_SPARC_DISP16
:
1966 case elfcpp::R_SPARC_DISP32
:
1967 case elfcpp::R_SPARC_DISP64
:
1968 case elfcpp::R_SPARC_PC_HH22
:
1969 case elfcpp::R_SPARC_PC_HM10
:
1970 case elfcpp::R_SPARC_PC_LM22
:
1971 case elfcpp::R_SPARC_PC10
:
1972 case elfcpp::R_SPARC_PC22
:
1973 case elfcpp::R_SPARC_WDISP30
:
1974 case elfcpp::R_SPARC_WDISP22
:
1975 case elfcpp::R_SPARC_WDISP19
:
1976 case elfcpp::R_SPARC_WDISP16
:
1978 if (gsym
->needs_plt_entry())
1979 target
->make_plt_entry(symtab
, layout
, gsym
);
1980 // Make a dynamic relocation if necessary.
1981 int flags
= Symbol::NON_PIC_REF
;
1982 if (gsym
->type() == elfcpp::STT_FUNC
)
1983 flags
|= Symbol::FUNCTION_CALL
;
1984 if (gsym
->needs_dynamic_reloc(flags
))
1986 if (gsym
->may_need_copy_reloc())
1988 target
->copy_reloc(symtab
, layout
, object
,
1989 data_shndx
, output_section
, gsym
,
1994 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1995 check_non_pic(object
, r_type
);
1996 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1997 data_shndx
, reloc
.get_r_offset(),
1998 reloc
.get_r_addend());
2004 case elfcpp::R_SPARC_UA64
:
2005 case elfcpp::R_SPARC_64
:
2006 case elfcpp::R_SPARC_HIX22
:
2007 case elfcpp::R_SPARC_LOX10
:
2008 case elfcpp::R_SPARC_H44
:
2009 case elfcpp::R_SPARC_M44
:
2010 case elfcpp::R_SPARC_L44
:
2011 case elfcpp::R_SPARC_HH22
:
2012 case elfcpp::R_SPARC_HM10
:
2013 case elfcpp::R_SPARC_LM22
:
2014 case elfcpp::R_SPARC_HI22
:
2015 case elfcpp::R_SPARC_LO10
:
2016 case elfcpp::R_SPARC_OLO10
:
2017 case elfcpp::R_SPARC_UA32
:
2018 case elfcpp::R_SPARC_32
:
2019 case elfcpp::R_SPARC_UA16
:
2020 case elfcpp::R_SPARC_16
:
2021 case elfcpp::R_SPARC_11
:
2022 case elfcpp::R_SPARC_10
:
2023 case elfcpp::R_SPARC_8
:
2024 case elfcpp::R_SPARC_7
:
2025 case elfcpp::R_SPARC_6
:
2026 case elfcpp::R_SPARC_5
:
2028 // Make a PLT entry if necessary.
2029 if (gsym
->needs_plt_entry())
2031 target
->make_plt_entry(symtab
, layout
, gsym
);
2032 // Since this is not a PC-relative relocation, we may be
2033 // taking the address of a function. In that case we need to
2034 // set the entry in the dynamic symbol table to the address of
2036 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2037 gsym
->set_needs_dynsym_value();
2039 // Make a dynamic relocation if necessary.
2040 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2042 unsigned int r_off
= reloc
.get_r_offset();
2044 // The assembler can sometimes emit unaligned relocations
2045 // for dwarf2 cfi directives.
2048 case elfcpp::R_SPARC_16
:
2050 orig_r_type
= r_type
= elfcpp::R_SPARC_UA16
;
2052 case elfcpp::R_SPARC_32
:
2054 orig_r_type
= r_type
= elfcpp::R_SPARC_UA32
;
2056 case elfcpp::R_SPARC_64
:
2058 orig_r_type
= r_type
= elfcpp::R_SPARC_UA64
;
2060 case elfcpp::R_SPARC_UA16
:
2062 orig_r_type
= r_type
= elfcpp::R_SPARC_16
;
2064 case elfcpp::R_SPARC_UA32
:
2066 orig_r_type
= r_type
= elfcpp::R_SPARC_32
;
2068 case elfcpp::R_SPARC_UA64
:
2070 orig_r_type
= r_type
= elfcpp::R_SPARC_64
;
2074 if (gsym
->may_need_copy_reloc())
2076 target
->copy_reloc(symtab
, layout
, object
,
2077 data_shndx
, output_section
, gsym
, reloc
);
2079 else if ((r_type
== elfcpp::R_SPARC_32
2080 || r_type
== elfcpp::R_SPARC_64
)
2081 && gsym
->can_use_relative_reloc(false))
2083 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2084 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2085 output_section
, object
,
2086 data_shndx
, reloc
.get_r_offset(),
2087 reloc
.get_r_addend());
2091 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2093 check_non_pic(object
, r_type
);
2094 if (gsym
->is_from_dynobj()
2095 || gsym
->is_undefined()
2096 || gsym
->is_preemptible())
2097 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2099 reloc
.get_r_offset(),
2100 reloc
.get_r_addend());
2102 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2105 reloc
.get_r_offset(),
2106 reloc
.get_r_addend());
2112 case elfcpp::R_SPARC_GOTDATA_OP
:
2113 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2114 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2115 case elfcpp::R_SPARC_GOT10
:
2116 case elfcpp::R_SPARC_GOT13
:
2117 case elfcpp::R_SPARC_GOT22
:
2119 // The symbol requires a GOT entry.
2120 Output_data_got
<size
, big_endian
>* got
;
2122 got
= target
->got_section(symtab
, layout
);
2123 if (gsym
->final_value_is_known())
2124 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2127 // If this symbol is not fully resolved, we need to add a
2128 // dynamic relocation for it.
2129 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2130 if (gsym
->is_from_dynobj()
2131 || gsym
->is_undefined()
2132 || gsym
->is_preemptible())
2133 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2134 elfcpp::R_SPARC_GLOB_DAT
);
2135 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2137 unsigned int off
= got
->add_constant(0);
2139 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2140 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2147 // These are initial tls relocs, which are expected when
2149 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2150 case elfcpp::R_SPARC_TLS_GD_LO10
:
2151 case elfcpp::R_SPARC_TLS_GD_ADD
:
2152 case elfcpp::R_SPARC_TLS_GD_CALL
:
2153 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2154 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2155 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2156 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2157 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2158 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2159 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2160 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2161 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2162 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2163 case elfcpp::R_SPARC_TLS_IE_LO10
:
2164 case elfcpp::R_SPARC_TLS_IE_LD
:
2165 case elfcpp::R_SPARC_TLS_IE_LDX
:
2166 case elfcpp::R_SPARC_TLS_IE_ADD
:
2168 const bool is_final
= gsym
->final_value_is_known();
2169 const tls::Tls_optimization optimized_type
2170 = optimize_tls_reloc(is_final
, r_type
);
2173 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2174 case elfcpp::R_SPARC_TLS_GD_LO10
:
2175 case elfcpp::R_SPARC_TLS_GD_ADD
:
2176 case elfcpp::R_SPARC_TLS_GD_CALL
:
2177 if (optimized_type
== tls::TLSOPT_NONE
)
2179 // Create a pair of GOT entries for the module index and
2180 // dtv-relative offset.
2181 Output_data_got
<size
, big_endian
>* got
2182 = target
->got_section(symtab
, layout
);
2183 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2184 target
->rela_dyn_section(layout
),
2186 elfcpp::R_SPARC_TLS_DTPMOD64
:
2187 elfcpp::R_SPARC_TLS_DTPMOD32
),
2189 elfcpp::R_SPARC_TLS_DTPOFF64
:
2190 elfcpp::R_SPARC_TLS_DTPOFF32
));
2192 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2193 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2194 generate_tls_call(symtab
, layout
, target
);
2196 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2198 // Create a GOT entry for the tp-relative offset.
2199 Output_data_got
<size
, big_endian
>* got
2200 = target
->got_section(symtab
, layout
);
2201 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2202 target
->rela_dyn_section(layout
),
2204 elfcpp::R_SPARC_TLS_TPOFF64
:
2205 elfcpp::R_SPARC_TLS_TPOFF32
));
2207 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2208 unsupported_reloc_global(object
, r_type
, gsym
);
2211 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2212 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2213 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2214 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2215 if (optimized_type
== tls::TLSOPT_NONE
)
2217 // Create a GOT entry for the module index.
2218 target
->got_mod_index_entry(symtab
, layout
, object
);
2220 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2221 generate_tls_call(symtab
, layout
, target
);
2223 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2224 unsupported_reloc_global(object
, r_type
, gsym
);
2227 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2228 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2229 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2232 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2233 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2234 layout
->set_has_static_tls();
2235 if (parameters
->options().shared())
2237 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2238 rela_dyn
->add_symbolless_global_addend(gsym
, orig_r_type
,
2239 output_section
, object
,
2240 data_shndx
, reloc
.get_r_offset(),
2245 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2246 case elfcpp::R_SPARC_TLS_IE_LO10
:
2247 case elfcpp::R_SPARC_TLS_IE_LD
:
2248 case elfcpp::R_SPARC_TLS_IE_LDX
:
2249 case elfcpp::R_SPARC_TLS_IE_ADD
:
2250 layout
->set_has_static_tls();
2251 if (optimized_type
== tls::TLSOPT_NONE
)
2253 // Create a GOT entry for the tp-relative offset.
2254 Output_data_got
<size
, big_endian
>* got
2255 = target
->got_section(symtab
, layout
);
2256 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2257 target
->rela_dyn_section(layout
),
2259 elfcpp::R_SPARC_TLS_TPOFF64
:
2260 elfcpp::R_SPARC_TLS_TPOFF32
));
2262 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2263 unsupported_reloc_global(object
, r_type
, gsym
);
2269 // These are relocations which should only be seen by the
2270 // dynamic linker, and should never be seen here.
2271 case elfcpp::R_SPARC_COPY
:
2272 case elfcpp::R_SPARC_GLOB_DAT
:
2273 case elfcpp::R_SPARC_JMP_SLOT
:
2274 case elfcpp::R_SPARC_RELATIVE
:
2275 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2276 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2277 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2278 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2279 case elfcpp::R_SPARC_TLS_TPOFF64
:
2280 case elfcpp::R_SPARC_TLS_TPOFF32
:
2281 gold_error(_("%s: unexpected reloc %u in object file"),
2282 object
->name().c_str(), r_type
);
2286 unsupported_reloc_global(object
, r_type
, gsym
);
2291 // Process relocations for gc.
2293 template<int size
, bool big_endian
>
2295 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2296 Symbol_table
* symtab
,
2298 Sized_relobj
<size
, big_endian
>* object
,
2299 unsigned int data_shndx
,
2301 const unsigned char* prelocs
,
2303 Output_section
* output_section
,
2304 bool needs_special_offset_handling
,
2305 size_t local_symbol_count
,
2306 const unsigned char* plocal_symbols
)
2308 typedef Target_sparc
<size
, big_endian
> Sparc
;
2309 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2311 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2320 needs_special_offset_handling
,
2325 // Scan relocations for a section.
2327 template<int size
, bool big_endian
>
2329 Target_sparc
<size
, big_endian
>::scan_relocs(
2330 Symbol_table
* symtab
,
2332 Sized_relobj
<size
, big_endian
>* object
,
2333 unsigned int data_shndx
,
2334 unsigned int sh_type
,
2335 const unsigned char* prelocs
,
2337 Output_section
* output_section
,
2338 bool needs_special_offset_handling
,
2339 size_t local_symbol_count
,
2340 const unsigned char* plocal_symbols
)
2342 typedef Target_sparc
<size
, big_endian
> Sparc
;
2343 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2345 if (sh_type
== elfcpp::SHT_REL
)
2347 gold_error(_("%s: unsupported REL reloc section"),
2348 object
->name().c_str());
2352 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2361 needs_special_offset_handling
,
2366 // Finalize the sections.
2368 template<int size
, bool big_endian
>
2370 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2372 const Input_objects
*,
2375 // Fill in some more dynamic tags.
2376 const Reloc_section
* rel_plt
= (this->plt_
== NULL
2378 : this->plt_
->rel_plt());
2379 layout
->add_target_dynamic_tags(false, this->plt_
, rel_plt
,
2380 this->rela_dyn_
, true, true);
2382 // Emit any relocs we saved in an attempt to avoid generating COPY
2384 if (this->copy_relocs_
.any_saved_relocs())
2385 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2388 // Perform a relocation.
2390 template<int size
, bool big_endian
>
2392 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2393 const Relocate_info
<size
, big_endian
>* relinfo
,
2394 Target_sparc
* target
,
2397 const elfcpp::Rela
<size
, big_endian
>& rela
,
2398 unsigned int r_type
,
2399 const Sized_symbol
<size
>* gsym
,
2400 const Symbol_value
<size
>* psymval
,
2401 unsigned char* view
,
2402 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2403 section_size_type view_size
)
2407 if (this->ignore_gd_add_
)
2409 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2410 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2411 _("missing expected TLS relocation"));
2414 this->ignore_gd_add_
= false;
2419 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2421 // Pick the value to use for symbols defined in shared objects.
2422 Symbol_value
<size
> symval
;
2424 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2425 || r_type
== elfcpp::R_SPARC_DISP16
2426 || r_type
== elfcpp::R_SPARC_DISP32
2427 || r_type
== elfcpp::R_SPARC_DISP64
2428 || r_type
== elfcpp::R_SPARC_PC_HH22
2429 || r_type
== elfcpp::R_SPARC_PC_HM10
2430 || r_type
== elfcpp::R_SPARC_PC_LM22
2431 || r_type
== elfcpp::R_SPARC_PC10
2432 || r_type
== elfcpp::R_SPARC_PC22
2433 || r_type
== elfcpp::R_SPARC_WDISP30
2434 || r_type
== elfcpp::R_SPARC_WDISP22
2435 || r_type
== elfcpp::R_SPARC_WDISP19
2436 || r_type
== elfcpp::R_SPARC_WDISP16
))
2438 elfcpp::Elf_Xword value
;
2440 value
= target
->plt_section()->address() + gsym
->plt_offset();
2442 symval
.set_output_value(value
);
2447 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2448 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2450 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2451 // pointer points to the beginning, not the end, of the table.
2452 // So we just use the plain offset.
2453 bool have_got_offset
= false;
2454 unsigned int got_offset
= 0;
2457 case elfcpp::R_SPARC_GOTDATA_OP
:
2458 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2459 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2460 case elfcpp::R_SPARC_GOT10
:
2461 case elfcpp::R_SPARC_GOT13
:
2462 case elfcpp::R_SPARC_GOT22
:
2465 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2466 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2470 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2471 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2472 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2474 have_got_offset
= true;
2483 case elfcpp::R_SPARC_NONE
:
2484 case elfcpp::R_SPARC_REGISTER
:
2485 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2486 case elfcpp::R_SPARC_GNU_VTENTRY
:
2489 case elfcpp::R_SPARC_8
:
2490 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2494 case elfcpp::R_SPARC_16
:
2495 if (rela
.get_r_offset() & 0x1)
2497 // The assembler can sometimes emit unaligned relocations
2498 // for dwarf2 cfi directives.
2499 Reloc::ua16(view
, object
, psymval
, addend
);
2502 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2506 case elfcpp::R_SPARC_32
:
2507 if (!parameters
->options().output_is_position_independent())
2509 if (rela
.get_r_offset() & 0x3)
2511 // The assembler can sometimes emit unaligned relocations
2512 // for dwarf2 cfi directives.
2513 Reloc::ua32(view
, object
, psymval
, addend
);
2516 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2521 case elfcpp::R_SPARC_DISP8
:
2522 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2525 case elfcpp::R_SPARC_DISP16
:
2526 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2529 case elfcpp::R_SPARC_DISP32
:
2530 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2533 case elfcpp::R_SPARC_DISP64
:
2534 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2537 case elfcpp::R_SPARC_WDISP30
:
2538 case elfcpp::R_SPARC_WPLT30
:
2539 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2542 case elfcpp::R_SPARC_WDISP22
:
2543 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2546 case elfcpp::R_SPARC_WDISP19
:
2547 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2550 case elfcpp::R_SPARC_WDISP16
:
2551 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2554 case elfcpp::R_SPARC_HI22
:
2555 Reloc::hi22(view
, object
, psymval
, addend
);
2558 case elfcpp::R_SPARC_22
:
2559 Reloc::rela32_22(view
, object
, psymval
, addend
);
2562 case elfcpp::R_SPARC_13
:
2563 Reloc::rela32_13(view
, object
, psymval
, addend
);
2566 case elfcpp::R_SPARC_LO10
:
2567 Reloc::lo10(view
, object
, psymval
, addend
);
2570 case elfcpp::R_SPARC_GOT10
:
2571 Reloc::lo10(view
, got_offset
, addend
);
2574 case elfcpp::R_SPARC_GOTDATA_OP
:
2577 case elfcpp::R_SPARC_GOTDATA_OP_LOX10
:
2578 case elfcpp::R_SPARC_GOT13
:
2579 Reloc::rela32_13(view
, got_offset
, addend
);
2582 case elfcpp::R_SPARC_GOTDATA_OP_HIX22
:
2583 case elfcpp::R_SPARC_GOT22
:
2584 Reloc::hi22(view
, got_offset
, addend
);
2587 case elfcpp::R_SPARC_PC10
:
2588 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2591 case elfcpp::R_SPARC_PC22
:
2592 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2595 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2596 case elfcpp::R_SPARC_UA32
:
2597 Reloc::ua32(view
, object
, psymval
, addend
);
2600 case elfcpp::R_SPARC_PLT64
:
2601 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2605 case elfcpp::R_SPARC_PLT32
:
2606 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2610 case elfcpp::R_SPARC_HIPLT22
:
2611 Reloc::hi22(view
, object
, psymval
, addend
);
2614 case elfcpp::R_SPARC_LOPLT10
:
2615 Reloc::lo10(view
, object
, psymval
, addend
);
2618 case elfcpp::R_SPARC_PCPLT32
:
2619 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2622 case elfcpp::R_SPARC_PCPLT22
:
2623 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2626 case elfcpp::R_SPARC_PCPLT10
:
2627 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2630 case elfcpp::R_SPARC_64
:
2631 if (!parameters
->options().output_is_position_independent())
2633 if (rela
.get_r_offset() & 0x7)
2635 // The assembler can sometimes emit unaligned relocations
2636 // for dwarf2 cfi directives.
2637 Reloc::ua64(view
, object
, psymval
, addend
);
2640 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2645 case elfcpp::R_SPARC_OLO10
:
2647 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2648 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2649 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2653 case elfcpp::R_SPARC_HH22
:
2654 Reloc::hh22(view
, object
, psymval
, addend
);
2657 case elfcpp::R_SPARC_PC_HH22
:
2658 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2661 case elfcpp::R_SPARC_HM10
:
2662 Reloc::hm10(view
, object
, psymval
, addend
);
2665 case elfcpp::R_SPARC_PC_HM10
:
2666 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2669 case elfcpp::R_SPARC_LM22
:
2670 Reloc::hi22(view
, object
, psymval
, addend
);
2673 case elfcpp::R_SPARC_PC_LM22
:
2674 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2677 case elfcpp::R_SPARC_11
:
2678 Reloc::rela32_11(view
, object
, psymval
, addend
);
2681 case elfcpp::R_SPARC_10
:
2682 Reloc::rela32_10(view
, object
, psymval
, addend
);
2685 case elfcpp::R_SPARC_7
:
2686 Reloc::rela32_7(view
, object
, psymval
, addend
);
2689 case elfcpp::R_SPARC_6
:
2690 Reloc::rela32_6(view
, object
, psymval
, addend
);
2693 case elfcpp::R_SPARC_5
:
2694 Reloc::rela32_5(view
, object
, psymval
, addend
);
2697 case elfcpp::R_SPARC_HIX22
:
2698 Reloc::hix22(view
, object
, psymval
, addend
);
2701 case elfcpp::R_SPARC_LOX10
:
2702 Reloc::lox10(view
, object
, psymval
, addend
);
2705 case elfcpp::R_SPARC_H44
:
2706 Reloc::h44(view
, object
, psymval
, addend
);
2709 case elfcpp::R_SPARC_M44
:
2710 Reloc::m44(view
, object
, psymval
, addend
);
2713 case elfcpp::R_SPARC_L44
:
2714 Reloc::l44(view
, object
, psymval
, addend
);
2717 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2718 case elfcpp::R_SPARC_UA64
:
2719 Reloc::ua64(view
, object
, psymval
, addend
);
2722 case elfcpp::R_SPARC_UA16
:
2723 Reloc::ua16(view
, object
, psymval
, addend
);
2726 case elfcpp::R_SPARC_TLS_GD_HI22
:
2727 case elfcpp::R_SPARC_TLS_GD_LO10
:
2728 case elfcpp::R_SPARC_TLS_GD_ADD
:
2729 case elfcpp::R_SPARC_TLS_GD_CALL
:
2730 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2731 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2732 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2733 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2734 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2735 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2736 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2737 case elfcpp::R_SPARC_TLS_IE_HI22
:
2738 case elfcpp::R_SPARC_TLS_IE_LO10
:
2739 case elfcpp::R_SPARC_TLS_IE_LD
:
2740 case elfcpp::R_SPARC_TLS_IE_LDX
:
2741 case elfcpp::R_SPARC_TLS_IE_ADD
:
2742 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2743 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2744 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2745 r_type
, gsym
, psymval
, view
,
2746 address
, view_size
);
2749 case elfcpp::R_SPARC_COPY
:
2750 case elfcpp::R_SPARC_GLOB_DAT
:
2751 case elfcpp::R_SPARC_JMP_SLOT
:
2752 case elfcpp::R_SPARC_RELATIVE
:
2753 // These are outstanding tls relocs, which are unexpected when
2755 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2756 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2757 case elfcpp::R_SPARC_TLS_TPOFF64
:
2758 case elfcpp::R_SPARC_TLS_TPOFF32
:
2759 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2760 _("unexpected reloc %u in object file"),
2765 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2766 _("unsupported reloc %u"),
2774 // Perform a TLS relocation.
2776 template<int size
, bool big_endian
>
2778 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2779 const Relocate_info
<size
, big_endian
>* relinfo
,
2780 Target_sparc
<size
, big_endian
>* target
,
2782 const elfcpp::Rela
<size
, big_endian
>& rela
,
2783 unsigned int r_type
,
2784 const Sized_symbol
<size
>* gsym
,
2785 const Symbol_value
<size
>* psymval
,
2786 unsigned char* view
,
2787 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2790 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2791 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2792 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2793 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2795 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2796 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2798 const bool is_final
=
2800 ? !parameters
->options().output_is_position_independent()
2801 : gsym
->final_value_is_known());
2802 const tls::Tls_optimization optimized_type
2803 = optimize_tls_reloc(is_final
, r_type
);
2807 case elfcpp::R_SPARC_TLS_GD_HI22
:
2808 case elfcpp::R_SPARC_TLS_GD_LO10
:
2809 case elfcpp::R_SPARC_TLS_GD_ADD
:
2810 case elfcpp::R_SPARC_TLS_GD_CALL
:
2811 if (optimized_type
== tls::TLSOPT_TO_LE
)
2813 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2816 value
-= tls_segment
->memsz();
2820 case elfcpp::R_SPARC_TLS_GD_HI22
:
2821 // TLS_GD_HI22 --> TLS_LE_HIX22
2822 Reloc::hix22(view
, value
, addend
);
2825 case elfcpp::R_SPARC_TLS_GD_LO10
:
2826 // TLS_GD_LO10 --> TLS_LE_LOX10
2827 Reloc::lox10(view
, value
, addend
);
2830 case elfcpp::R_SPARC_TLS_GD_ADD
:
2831 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2832 val
= elfcpp::Swap
<32, true>::readval(wv
);
2833 val
= (val
& ~0x7c000) | 0x1c000;
2834 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2836 case elfcpp::R_SPARC_TLS_GD_CALL
:
2837 // call __tls_get_addr --> nop
2838 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2845 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2846 ? GOT_TYPE_TLS_OFFSET
2847 : GOT_TYPE_TLS_PAIR
);
2850 gold_assert(gsym
->has_got_offset(got_type
));
2851 value
= gsym
->got_offset(got_type
);
2855 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2856 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2857 value
= object
->local_got_offset(r_sym
, got_type
);
2859 if (optimized_type
== tls::TLSOPT_TO_IE
)
2861 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2866 case elfcpp::R_SPARC_TLS_GD_HI22
:
2867 // TLS_GD_HI22 --> TLS_IE_HI22
2868 Reloc::hi22(view
, value
, addend
);
2871 case elfcpp::R_SPARC_TLS_GD_LO10
:
2872 // TLS_GD_LO10 --> TLS_IE_LO10
2873 Reloc::lo10(view
, value
, addend
);
2876 case elfcpp::R_SPARC_TLS_GD_ADD
:
2877 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2878 val
= elfcpp::Swap
<32, true>::readval(wv
);
2885 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2888 case elfcpp::R_SPARC_TLS_GD_CALL
:
2889 // The compiler can put the TLS_GD_ADD instruction
2890 // into the delay slot of the call. If so, we need
2891 // to transpose the two instructions so that the
2892 // the new sequence works properly.
2894 // The test we use is if the instruction in the
2895 // delay slot is an add with destination register
2897 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2898 if ((val
& 0x81f80000) == 0x80000000
2899 && ((val
>> 25) & 0x1f) == 0x8)
2906 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2909 this->ignore_gd_add_
= true;
2912 // call __tls_get_addr --> add %g7, %o0, %o0
2913 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2918 else if (optimized_type
== tls::TLSOPT_NONE
)
2922 case elfcpp::R_SPARC_TLS_GD_HI22
:
2923 Reloc::hi22(view
, value
, addend
);
2925 case elfcpp::R_SPARC_TLS_GD_LO10
:
2926 Reloc::lo10(view
, value
, addend
);
2928 case elfcpp::R_SPARC_TLS_GD_ADD
:
2930 case elfcpp::R_SPARC_TLS_GD_CALL
:
2932 Symbol_value
<size
> symval
;
2933 elfcpp::Elf_Xword value
;
2936 tsym
= target
->tls_get_addr_sym_
;
2938 value
= (target
->plt_section()->address() +
2939 tsym
->plt_offset());
2940 symval
.set_output_value(value
);
2941 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2948 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2949 _("unsupported reloc %u"),
2953 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2954 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2955 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2956 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2957 if (optimized_type
== tls::TLSOPT_TO_LE
)
2959 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2963 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2964 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2965 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2966 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2969 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2970 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2975 else if (optimized_type
== tls::TLSOPT_NONE
)
2977 // Relocate the field with the offset of the GOT entry for
2978 // the module index.
2979 unsigned int got_offset
;
2981 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2984 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2985 Reloc::hi22(view
, got_offset
, addend
);
2987 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2988 Reloc::lo10(view
, got_offset
, addend
);
2990 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2992 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2994 Symbol_value
<size
> symval
;
2995 elfcpp::Elf_Xword value
;
2998 tsym
= target
->tls_get_addr_sym_
;
3000 value
= (target
->plt_section()->address() +
3001 tsym
->plt_offset());
3002 symval
.set_output_value(value
);
3003 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
3009 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3010 _("unsupported reloc %u"),
3014 // These relocs can appear in debugging sections, in which case
3015 // we won't see the TLS_LDM relocs. The local_dynamic_type
3016 // field tells us this.
3017 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
3018 if (optimized_type
== tls::TLSOPT_TO_LE
)
3020 value
-= tls_segment
->memsz();
3021 Reloc::hix22(view
, value
, addend
);
3024 Reloc::ldo_hix22(view
, value
, addend
);
3026 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
3027 if (optimized_type
== tls::TLSOPT_TO_LE
)
3029 value
-= tls_segment
->memsz();
3030 Reloc::lox10(view
, value
, addend
);
3033 Reloc::ldo_lox10(view
, value
, addend
);
3035 case elfcpp::R_SPARC_TLS_LDO_ADD
:
3036 if (optimized_type
== tls::TLSOPT_TO_LE
)
3038 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3041 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
3042 val
= elfcpp::Swap
<32, true>::readval(wv
);
3043 val
= (val
& ~0x7c000) | 0x1c000;
3044 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3048 // When optimizing IE --> LE, the only relocation that is handled
3049 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
3050 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3051 // rs2 and rd are the same.
3052 case elfcpp::R_SPARC_TLS_IE_LD
:
3053 case elfcpp::R_SPARC_TLS_IE_LDX
:
3054 if (optimized_type
== tls::TLSOPT_TO_LE
)
3056 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3057 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3058 Insntype rs2
= val
& 0x1f;
3059 Insntype rd
= (val
>> 25) & 0x1f;
3064 val
= sparc_mov
| (val
& 0x3e00001f);
3066 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3070 case elfcpp::R_SPARC_TLS_IE_HI22
:
3071 case elfcpp::R_SPARC_TLS_IE_LO10
:
3072 if (optimized_type
== tls::TLSOPT_TO_LE
)
3074 value
-= tls_segment
->memsz();
3077 case elfcpp::R_SPARC_TLS_IE_HI22
:
3078 // IE_HI22 --> LE_HIX22
3079 Reloc::hix22(view
, value
, addend
);
3081 case elfcpp::R_SPARC_TLS_IE_LO10
:
3082 // IE_LO10 --> LE_LOX10
3083 Reloc::lox10(view
, value
, addend
);
3088 else if (optimized_type
== tls::TLSOPT_NONE
)
3090 // Relocate the field with the offset of the GOT entry for
3091 // the tp-relative offset of the symbol.
3094 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3095 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3099 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3100 gold_assert(object
->local_has_got_offset(r_sym
,
3101 GOT_TYPE_TLS_OFFSET
));
3102 value
= object
->local_got_offset(r_sym
,
3103 GOT_TYPE_TLS_OFFSET
);
3107 case elfcpp::R_SPARC_TLS_IE_HI22
:
3108 Reloc::hi22(view
, value
, addend
);
3110 case elfcpp::R_SPARC_TLS_IE_LO10
:
3111 Reloc::lo10(view
, value
, addend
);
3116 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3117 _("unsupported reloc %u"),
3121 case elfcpp::R_SPARC_TLS_IE_ADD
:
3122 // This seems to be mainly so that we can find the addition
3123 // instruction if there is one. There doesn't seem to be any
3124 // actual relocation to apply.
3127 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3128 // If we're creating a shared library, a dynamic relocation will
3129 // have been created for this location, so do not apply it now.
3130 if (!parameters
->options().shared())
3132 value
-= tls_segment
->memsz();
3133 Reloc::hix22(view
, value
, addend
);
3137 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3138 // If we're creating a shared library, a dynamic relocation will
3139 // have been created for this location, so do not apply it now.
3140 if (!parameters
->options().shared())
3142 value
-= tls_segment
->memsz();
3143 Reloc::lox10(view
, value
, addend
);
3149 // Relocate section data.
3151 template<int size
, bool big_endian
>
3153 Target_sparc
<size
, big_endian
>::relocate_section(
3154 const Relocate_info
<size
, big_endian
>* relinfo
,
3155 unsigned int sh_type
,
3156 const unsigned char* prelocs
,
3158 Output_section
* output_section
,
3159 bool needs_special_offset_handling
,
3160 unsigned char* view
,
3161 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3162 section_size_type view_size
,
3163 const Reloc_symbol_changes
* reloc_symbol_changes
)
3165 typedef Target_sparc
<size
, big_endian
> Sparc
;
3166 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3168 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3170 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3177 needs_special_offset_handling
,
3181 reloc_symbol_changes
);
3184 // Return the size of a relocation while scanning during a relocatable
3187 template<int size
, bool big_endian
>
3189 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3193 // We are always SHT_RELA, so we should never get here.
3198 // Scan the relocs during a relocatable link.
3200 template<int size
, bool big_endian
>
3202 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3203 Symbol_table
* symtab
,
3205 Sized_relobj
<size
, big_endian
>* object
,
3206 unsigned int data_shndx
,
3207 unsigned int sh_type
,
3208 const unsigned char* prelocs
,
3210 Output_section
* output_section
,
3211 bool needs_special_offset_handling
,
3212 size_t local_symbol_count
,
3213 const unsigned char* plocal_symbols
,
3214 Relocatable_relocs
* rr
)
3216 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3218 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3219 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3221 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3222 Scan_relocatable_relocs
>(
3230 needs_special_offset_handling
,
3236 // Relocate a section during a relocatable link.
3238 template<int size
, bool big_endian
>
3240 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3241 const Relocate_info
<size
, big_endian
>* relinfo
,
3242 unsigned int sh_type
,
3243 const unsigned char* prelocs
,
3245 Output_section
* output_section
,
3246 off_t offset_in_output_section
,
3247 const Relocatable_relocs
* rr
,
3248 unsigned char* view
,
3249 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3250 section_size_type view_size
,
3251 unsigned char* reloc_view
,
3252 section_size_type reloc_view_size
)
3254 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3256 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3261 offset_in_output_section
,
3270 // Return the value to use for a dynamic which requires special
3271 // treatment. This is how we support equality comparisons of function
3272 // pointers across shared library boundaries, as described in the
3273 // processor specific ABI supplement.
3275 template<int size
, bool big_endian
>
3277 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3279 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3280 return this->plt_section()->address() + gsym
->plt_offset();
3283 // The selector for sparc object files.
3285 template<int size
, bool big_endian
>
3286 class Target_selector_sparc
: public Target_selector
3289 Target_selector_sparc()
3290 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3291 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3294 Target
* do_recognize(int machine
, int, int)
3299 if (machine
!= elfcpp::EM_SPARCV9
)
3304 if (machine
!= elfcpp::EM_SPARC
3305 && machine
!= elfcpp::EM_SPARC32PLUS
)
3313 return this->instantiate_target();
3316 Target
* do_instantiate_target()
3317 { return new Target_sparc
<size
, big_endian
>(); }
3320 Target_selector_sparc
<32, true> target_selector_sparc32
;
3321 Target_selector_sparc
<64, true> target_selector_sparc64
;
3323 } // End anonymous namespace.