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
*);
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
368 Target::Target_info Target_sparc
<64, true>::sparc_info
=
371 true, // is_big_endian
372 elfcpp::EM_SPARCV9
, // machine_code
373 false, // has_make_symbol
374 false, // has_resolve
375 false, // has_code_fill
376 true, // is_default_stack_executable
378 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
379 0x100000, // default_text_segment_address
380 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
381 8 * 1024, // common_pagesize (overridable by -z common-page-size)
382 elfcpp::SHN_UNDEF
, // small_common_shndx
383 elfcpp::SHN_UNDEF
, // large_common_shndx
384 0, // small_common_section_flags
385 0 // large_common_section_flags
388 // We have to take care here, even when operating in little-endian
389 // mode, sparc instructions are still big endian.
390 template<int size
, bool big_endian
>
391 class Sparc_relocate_functions
394 // Do a simple relocation with the addend in the relocation.
395 template<int valsize
>
397 rela(unsigned char* view
,
398 unsigned int right_shift
,
399 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
400 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
401 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
403 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
404 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
405 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
406 Valtype reloc
= ((value
+ addend
) >> right_shift
);
411 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
414 // Do a simple relocation using a symbol value with the addend in
416 template<int valsize
>
418 rela(unsigned char* view
,
419 unsigned int right_shift
,
420 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
421 const Sized_relobj
<size
, big_endian
>* object
,
422 const Symbol_value
<size
>* psymval
,
423 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
425 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
426 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
427 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
428 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
433 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
436 // Do a simple relocation using a symbol value with the addend in
437 // the relocation, unaligned.
438 template<int valsize
>
440 rela_ua(unsigned char* view
,
441 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
442 const Sized_relobj
<size
, big_endian
>* object
,
443 const Symbol_value
<size
>* psymval
,
444 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
446 typedef typename
elfcpp::Swap_unaligned
<valsize
,
447 big_endian
>::Valtype Valtype
;
448 unsigned char* wv
= view
;
449 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
450 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
455 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
458 // Do a simple PC relative relocation with a Symbol_value with the
459 // addend in the relocation.
460 template<int valsize
>
462 pcrela(unsigned char* view
,
463 unsigned int right_shift
,
464 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
465 const Sized_relobj
<size
, big_endian
>* object
,
466 const Symbol_value
<size
>* psymval
,
467 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
468 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
470 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
471 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
472 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
473 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
479 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
482 template<int valsize
>
484 pcrela_unaligned(unsigned char* view
,
485 const Sized_relobj
<size
, big_endian
>* object
,
486 const Symbol_value
<size
>* psymval
,
487 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
488 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
490 typedef typename
elfcpp::Swap_unaligned
<valsize
,
491 big_endian
>::Valtype Valtype
;
492 unsigned char* wv
= view
;
493 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
495 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
498 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
499 typedef Sparc_relocate_functions
<size
, true> This_insn
;
502 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
504 wdisp30(unsigned char* view
,
505 const Sized_relobj
<size
, big_endian
>* object
,
506 const Symbol_value
<size
>* psymval
,
507 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
508 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
510 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
511 psymval
, addend
, address
);
514 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
516 wdisp22(unsigned char* view
,
517 const Sized_relobj
<size
, big_endian
>* object
,
518 const Symbol_value
<size
>* psymval
,
519 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
520 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
522 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
523 psymval
, addend
, address
);
526 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
528 wdisp19(unsigned char* view
,
529 const Sized_relobj
<size
, big_endian
>* object
,
530 const Symbol_value
<size
>* psymval
,
531 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
532 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
534 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
535 psymval
, addend
, address
);
538 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
540 wdisp16(unsigned char* view
,
541 const Sized_relobj
<size
, big_endian
>* object
,
542 const Symbol_value
<size
>* psymval
,
543 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
544 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
546 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
547 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
548 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
549 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
552 // The relocation value is split between the low 14 bits,
554 val
&= ~((0x3 << 20) | 0x3fff);
555 reloc
= (((reloc
& 0xc000) << (20 - 14))
556 | (reloc
& 0x3ffff));
558 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
561 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
563 pc22(unsigned char* view
,
564 const Sized_relobj
<size
, big_endian
>* object
,
565 const Symbol_value
<size
>* psymval
,
566 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
567 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
569 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
570 psymval
, addend
, address
);
573 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
575 pc10(unsigned char* view
,
576 const Sized_relobj
<size
, big_endian
>* object
,
577 const Symbol_value
<size
>* psymval
,
578 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
579 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
581 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
582 psymval
, addend
, address
);
585 // R_SPARC_HI22: (Symbol + Addend) >> 10
587 hi22(unsigned char* view
,
588 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
589 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
591 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
594 // R_SPARC_HI22: (Symbol + Addend) >> 10
596 hi22(unsigned char* view
,
597 const Sized_relobj
<size
, big_endian
>* object
,
598 const Symbol_value
<size
>* psymval
,
599 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
601 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
604 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
606 pcplt22(unsigned char* view
,
607 const Sized_relobj
<size
, big_endian
>* object
,
608 const Symbol_value
<size
>* psymval
,
609 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
610 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
612 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
613 psymval
, addend
, address
);
616 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
618 lo10(unsigned char* view
,
619 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
620 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
622 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
625 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
627 lo10(unsigned char* view
,
628 const Sized_relobj
<size
, big_endian
>* object
,
629 const Symbol_value
<size
>* psymval
,
630 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
632 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
635 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
637 lo10(unsigned char* view
,
638 const Sized_relobj
<size
, big_endian
>* object
,
639 const Symbol_value
<size
>* psymval
,
640 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
641 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
643 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
644 psymval
, addend
, address
);
647 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
649 olo10(unsigned char* view
,
650 const Sized_relobj
<size
, big_endian
>* object
,
651 const Symbol_value
<size
>* psymval
,
652 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
653 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
655 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
656 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
657 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
658 Valtype reloc
= psymval
->value(object
, addend
);
665 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
668 // R_SPARC_22: (Symbol + Addend)
670 rela32_22(unsigned char* view
,
671 const Sized_relobj
<size
, big_endian
>* object
,
672 const Symbol_value
<size
>* psymval
,
673 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
675 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
678 // R_SPARC_13: (Symbol + Addend)
680 rela32_13(unsigned char* view
,
681 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
682 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
684 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
687 // R_SPARC_13: (Symbol + Addend)
689 rela32_13(unsigned char* view
,
690 const Sized_relobj
<size
, big_endian
>* object
,
691 const Symbol_value
<size
>* psymval
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
694 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
697 // R_SPARC_UA16: (Symbol + Addend)
699 ua16(unsigned char* view
,
700 const Sized_relobj
<size
, big_endian
>* object
,
701 const Symbol_value
<size
>* psymval
,
702 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
704 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
707 // R_SPARC_UA32: (Symbol + Addend)
709 ua32(unsigned char* view
,
710 const Sized_relobj
<size
, big_endian
>* object
,
711 const Symbol_value
<size
>* psymval
,
712 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
714 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
717 // R_SPARC_UA64: (Symbol + Addend)
719 ua64(unsigned char* view
,
720 const Sized_relobj
<size
, big_endian
>* object
,
721 const Symbol_value
<size
>* psymval
,
722 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
724 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
725 object
, psymval
, addend
);
728 // R_SPARC_DISP8: (Symbol + Addend - Address)
730 disp8(unsigned char* view
,
731 const Sized_relobj
<size
, big_endian
>* object
,
732 const Symbol_value
<size
>* psymval
,
733 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
734 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
736 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
740 // R_SPARC_DISP16: (Symbol + Addend - Address)
742 disp16(unsigned char* view
,
743 const Sized_relobj
<size
, big_endian
>* object
,
744 const Symbol_value
<size
>* psymval
,
745 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
748 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
752 // R_SPARC_DISP32: (Symbol + Addend - Address)
754 disp32(unsigned char* view
,
755 const Sized_relobj
<size
, big_endian
>* object
,
756 const Symbol_value
<size
>* psymval
,
757 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
758 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
760 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
764 // R_SPARC_DISP64: (Symbol + Addend - Address)
766 disp64(unsigned char* view
,
767 const Sized_relobj
<size
, big_endian
>* object
,
768 const Symbol_value
<size
>* psymval
,
769 elfcpp::Elf_Xword addend
,
770 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
772 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
776 // R_SPARC_H44: (Symbol + Addend) >> 22
778 h44(unsigned char* view
,
779 const Sized_relobj
<size
, big_endian
>* object
,
780 const Symbol_value
<size
>* psymval
,
781 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
783 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
786 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
788 m44(unsigned char* view
,
789 const Sized_relobj
<size
, big_endian
>* object
,
790 const Symbol_value
<size
>* psymval
,
791 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
793 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
796 // R_SPARC_L44: (Symbol + Addend) & 0xfff
798 l44(unsigned char* view
,
799 const Sized_relobj
<size
, big_endian
>* object
,
800 const Symbol_value
<size
>* psymval
,
801 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
803 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
806 // R_SPARC_HH22: (Symbol + Addend) >> 42
808 hh22(unsigned char* view
,
809 const Sized_relobj
<size
, big_endian
>* object
,
810 const Symbol_value
<size
>* psymval
,
811 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
813 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
816 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
818 pc_hh22(unsigned char* view
,
819 const Sized_relobj
<size
, big_endian
>* object
,
820 const Symbol_value
<size
>* psymval
,
821 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
822 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
824 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
825 psymval
, addend
, address
);
828 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
830 hm10(unsigned char* view
,
831 const Sized_relobj
<size
, big_endian
>* object
,
832 const Symbol_value
<size
>* psymval
,
833 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
835 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
838 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
840 pc_hm10(unsigned char* view
,
841 const Sized_relobj
<size
, big_endian
>* object
,
842 const Symbol_value
<size
>* psymval
,
843 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
844 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
846 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
847 psymval
, addend
, address
);
850 // R_SPARC_11: (Symbol + Addend)
852 rela32_11(unsigned char* view
,
853 const Sized_relobj
<size
, big_endian
>* object
,
854 const Symbol_value
<size
>* psymval
,
855 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
857 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
860 // R_SPARC_10: (Symbol + Addend)
862 rela32_10(unsigned char* view
,
863 const Sized_relobj
<size
, big_endian
>* object
,
864 const Symbol_value
<size
>* psymval
,
865 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
867 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
870 // R_SPARC_7: (Symbol + Addend)
872 rela32_7(unsigned char* view
,
873 const Sized_relobj
<size
, big_endian
>* object
,
874 const Symbol_value
<size
>* psymval
,
875 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
877 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
880 // R_SPARC_6: (Symbol + Addend)
882 rela32_6(unsigned char* view
,
883 const Sized_relobj
<size
, big_endian
>* object
,
884 const Symbol_value
<size
>* psymval
,
885 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
887 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
890 // R_SPARC_5: (Symbol + Addend)
892 rela32_5(unsigned char* view
,
893 const Sized_relobj
<size
, big_endian
>* object
,
894 const Symbol_value
<size
>* psymval
,
895 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
897 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
900 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
902 ldo_hix22(unsigned char* view
,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
904 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
906 This_insn::hi22(view
, value
, addend
);
909 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
911 ldo_lox10(unsigned char* view
,
912 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
913 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
915 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
916 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
917 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
918 Valtype reloc
= (value
+ addend
);
923 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
926 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
928 hix22(unsigned char* view
,
929 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
930 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
932 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
933 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
934 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
935 Valtype reloc
= (value
+ addend
);
939 reloc
^= ~(Valtype
)0;
944 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
947 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
949 hix22(unsigned char* view
,
950 const Sized_relobj
<size
, big_endian
>* object
,
951 const Symbol_value
<size
>* psymval
,
952 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
954 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
955 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
956 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
957 Valtype reloc
= psymval
->value(object
, addend
);
961 reloc
^= ~(Valtype
)0;
966 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
970 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
972 lox10(unsigned char* view
,
973 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
974 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
976 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
977 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
978 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
979 Valtype reloc
= (value
+ addend
);
985 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
988 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
990 lox10(unsigned char* view
,
991 const Sized_relobj
<size
, big_endian
>* object
,
992 const Symbol_value
<size
>* psymval
,
993 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
995 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
996 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
997 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
998 Valtype reloc
= psymval
->value(object
, addend
);
1004 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1008 // Get the GOT section, creating it if necessary.
1010 template<int size
, bool big_endian
>
1011 Output_data_got
<size
, big_endian
>*
1012 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1015 if (this->got_
== NULL
)
1017 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1019 this->got_
= new Output_data_got
<size
, big_endian
>();
1022 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1024 | elfcpp::SHF_WRITE
),
1028 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1029 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1031 0, 0, elfcpp::STT_OBJECT
,
1033 elfcpp::STV_HIDDEN
, 0,
1040 // Get the dynamic reloc section, creating it if necessary.
1042 template<int size
, bool big_endian
>
1043 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1044 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1046 if (this->rela_dyn_
== NULL
)
1048 gold_assert(layout
!= NULL
);
1049 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1050 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1051 elfcpp::SHF_ALLOC
, this->rela_dyn_
, true);
1053 return this->rela_dyn_
;
1056 // A class to handle the PLT data.
1058 template<int size
, bool big_endian
>
1059 class Output_data_plt_sparc
: public Output_section_data
1062 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1063 size
, big_endian
> Reloc_section
;
1065 Output_data_plt_sparc(Layout
*);
1067 // Add an entry to the PLT.
1068 void add_entry(Symbol
* gsym
);
1070 // Return the .rela.plt section data.
1071 const Reloc_section
* rel_plt() const
1077 void do_adjust_output_section(Output_section
* os
);
1079 // Write to a map file.
1081 do_print_to_mapfile(Mapfile
* mapfile
) const
1082 { mapfile
->print_output_data(this, _("** PLT")); }
1085 // The size of an entry in the PLT.
1086 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1088 static const unsigned int plt_entries_per_block
= 160;
1089 static const unsigned int plt_insn_chunk_size
= 24;
1090 static const unsigned int plt_pointer_chunk_size
= 8;
1091 static const unsigned int plt_block_size
=
1092 (plt_entries_per_block
1093 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1095 // Set the final size.
1097 set_final_data_size()
1099 unsigned int full_count
= this->count_
+ 4;
1100 unsigned int extra
= (size
== 32 ? 4 : 0);
1102 if (size
== 32 || full_count
< 32768)
1103 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1106 unsigned int ext_cnt
= full_count
- 32768;
1108 this->set_data_size((32768 * base_plt_entry_size
)
1110 * (plt_insn_chunk_size
1111 + plt_pointer_chunk_size
)));
1115 // Write out the PLT data.
1117 do_write(Output_file
*);
1119 // The reloc section.
1120 Reloc_section
* rel_
;
1121 // The number of PLT entries.
1122 unsigned int count_
;
1125 // Define the constants as required by C++ standard.
1127 template<int size
, bool big_endian
>
1128 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1130 template<int size
, bool big_endian
>
1132 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1134 template<int size
, bool big_endian
>
1135 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1137 template<int size
, bool big_endian
>
1139 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1141 template<int size
, bool big_endian
>
1142 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1144 // Create the PLT section. The ordinary .got section is an argument,
1145 // since we need to refer to the start.
1147 template<int size
, bool big_endian
>
1148 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1149 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1151 this->rel_
= new Reloc_section(false);
1152 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1153 elfcpp::SHF_ALLOC
, this->rel_
, true);
1156 template<int size
, bool big_endian
>
1158 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1163 // Add an entry to the PLT.
1165 template<int size
, bool big_endian
>
1167 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1169 gold_assert(!gsym
->has_plt_offset());
1171 unsigned int index
= this->count_
+ 4;
1172 section_offset_type plt_offset
;
1174 if (size
== 32 || index
< 32768)
1175 plt_offset
= index
* base_plt_entry_size
;
1178 unsigned int ext_index
= index
- 32768;
1180 plt_offset
= (32768 * base_plt_entry_size
)
1181 + ((ext_index
/ plt_entries_per_block
)
1183 + ((ext_index
% plt_entries_per_block
)
1184 * plt_insn_chunk_size
);
1187 gsym
->set_plt_offset(plt_offset
);
1191 // Every PLT entry needs a reloc.
1192 gsym
->set_needs_dynsym_entry();
1193 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1196 // Note that we don't need to save the symbol. The contents of the
1197 // PLT are independent of which symbols are used. The symbols only
1198 // appear in the relocations.
1201 static const unsigned int sparc_nop
= 0x01000000;
1202 static const unsigned int sparc_sethi_g1
= 0x03000000;
1203 static const unsigned int sparc_branch_always
= 0x30800000;
1204 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1205 static const unsigned int sparc_mov
= 0x80100000;
1206 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1207 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1208 static const unsigned int sparc_call_plus_8
= 0x40000002;
1209 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1210 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1211 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1213 // Write out the PLT.
1215 template<int size
, bool big_endian
>
1217 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1219 const off_t offset
= this->offset();
1220 const section_size_type oview_size
=
1221 convert_to_section_size_type(this->data_size());
1222 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1223 unsigned char* pov
= oview
;
1225 memset(pov
, 0, base_plt_entry_size
* 4);
1226 pov
+= base_plt_entry_size
* 4;
1228 unsigned int plt_offset
= base_plt_entry_size
* 4;
1229 const unsigned int count
= this->count_
;
1235 limit
= (count
> 32768 ? 32768 : count
);
1237 for (unsigned int i
= 0; i
< limit
; ++i
)
1239 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1240 sparc_sethi_g1
+ plt_offset
);
1241 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1242 sparc_branch_always_pt
+
1243 (((base_plt_entry_size
-
1244 (plt_offset
+ 4)) >> 2) &
1246 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1247 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1248 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1249 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1250 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1251 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1253 pov
+= base_plt_entry_size
;
1254 plt_offset
+= base_plt_entry_size
;
1259 unsigned int ext_cnt
= count
- 32768;
1260 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1262 for (unsigned int i
= 0; i
< blks
; ++i
)
1264 unsigned int data_off
= (plt_entries_per_block
1265 * plt_insn_chunk_size
) - 4;
1267 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1269 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1271 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1273 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1275 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1276 sparc_ldx_o7_imm_g1
+
1277 (data_off
& 0x1fff));
1278 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1279 sparc_jmpl_o7_g1_g1
);
1280 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1283 elfcpp::Swap
<64, big_endian
>::writeval(
1284 pov
+ 0x4 + data_off
,
1285 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1287 pov
+= plt_insn_chunk_size
;
1292 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1293 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1295 unsigned int data_off
= (sub_blk_cnt
1296 * plt_insn_chunk_size
) - 4;
1298 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1300 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1302 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1304 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1306 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1307 sparc_ldx_o7_imm_g1
+
1308 (data_off
& 0x1fff));
1309 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1310 sparc_jmpl_o7_g1_g1
);
1311 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1314 elfcpp::Swap
<64, big_endian
>::writeval(
1315 pov
+ 0x4 + data_off
,
1316 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1318 pov
+= plt_insn_chunk_size
;
1326 for (unsigned int i
= 0; i
< count
; ++i
)
1328 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1329 sparc_sethi_g1
+ plt_offset
);
1330 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1331 sparc_branch_always
+
1332 (((- (plt_offset
+ 4)) >> 2) &
1334 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1336 pov
+= base_plt_entry_size
;
1337 plt_offset
+= base_plt_entry_size
;
1340 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1344 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1346 of
->write_output_view(offset
, oview_size
, oview
);
1349 // Create a PLT entry for a global symbol.
1351 template<int size
, bool big_endian
>
1353 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1357 if (gsym
->has_plt_offset())
1360 if (this->plt_
== NULL
)
1362 // Create the GOT sections first.
1363 this->got_section(symtab
, layout
);
1365 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1366 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1368 | elfcpp::SHF_EXECINSTR
1369 | elfcpp::SHF_WRITE
),
1372 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1373 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1375 0, 0, elfcpp::STT_OBJECT
,
1377 elfcpp::STV_HIDDEN
, 0,
1381 this->plt_
->add_entry(gsym
);
1384 // Create a GOT entry for the TLS module index.
1386 template<int size
, bool big_endian
>
1388 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1390 Sized_relobj
<size
, big_endian
>* object
)
1392 if (this->got_mod_index_offset_
== -1U)
1394 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1395 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1396 Output_data_got
<size
, big_endian
>* got
;
1397 unsigned int got_offset
;
1399 got
= this->got_section(symtab
, layout
);
1400 got_offset
= got
->add_constant(0);
1401 rela_dyn
->add_local(object
, 0,
1403 elfcpp::R_SPARC_TLS_DTPMOD64
:
1404 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1406 got
->add_constant(0);
1407 this->got_mod_index_offset_
= got_offset
;
1409 return this->got_mod_index_offset_
;
1412 // Optimize the TLS relocation type based on what we know about the
1413 // symbol. IS_FINAL is true if the final address of this symbol is
1414 // known at link time.
1416 static tls::Tls_optimization
1417 optimize_tls_reloc(bool is_final
, int r_type
)
1419 // If we are generating a shared library, then we can't do anything
1421 if (parameters
->options().shared())
1422 return tls::TLSOPT_NONE
;
1426 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1427 case elfcpp::R_SPARC_TLS_GD_LO10
:
1428 case elfcpp::R_SPARC_TLS_GD_ADD
:
1429 case elfcpp::R_SPARC_TLS_GD_CALL
:
1430 // These are General-Dynamic which permits fully general TLS
1431 // access. Since we know that we are generating an executable,
1432 // we can convert this to Initial-Exec. If we also know that
1433 // this is a local symbol, we can further switch to Local-Exec.
1435 return tls::TLSOPT_TO_LE
;
1436 return tls::TLSOPT_TO_IE
;
1438 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1439 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1440 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1441 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1442 // This is Local-Dynamic, which refers to a local symbol in the
1443 // dynamic TLS block. Since we know that we generating an
1444 // executable, we can switch to Local-Exec.
1445 return tls::TLSOPT_TO_LE
;
1447 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1448 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1449 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1450 // Another type of Local-Dynamic relocation.
1451 return tls::TLSOPT_TO_LE
;
1453 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1454 case elfcpp::R_SPARC_TLS_IE_LO10
:
1455 case elfcpp::R_SPARC_TLS_IE_LD
:
1456 case elfcpp::R_SPARC_TLS_IE_LDX
:
1457 case elfcpp::R_SPARC_TLS_IE_ADD
:
1458 // These are Initial-Exec relocs which get the thread offset
1459 // from the GOT. If we know that we are linking against the
1460 // local symbol, we can switch to Local-Exec, which links the
1461 // thread offset into the instruction.
1463 return tls::TLSOPT_TO_LE
;
1464 return tls::TLSOPT_NONE
;
1466 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1467 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1468 // When we already have Local-Exec, there is nothing further we
1470 return tls::TLSOPT_NONE
;
1477 // Generate a PLT entry slot for a call to __tls_get_addr
1478 template<int size
, bool big_endian
>
1480 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1482 Target_sparc
<size
, big_endian
>* target
)
1484 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1486 target
->make_plt_entry(symtab
, layout
, gsym
);
1489 // Report an unsupported relocation against a local symbol.
1491 template<int size
, bool big_endian
>
1493 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1494 Sized_relobj
<size
, big_endian
>* object
,
1495 unsigned int r_type
)
1497 gold_error(_("%s: unsupported reloc %u against local symbol"),
1498 object
->name().c_str(), r_type
);
1501 // We are about to emit a dynamic relocation of type R_TYPE. If the
1502 // dynamic linker does not support it, issue an error.
1504 template<int size
, bool big_endian
>
1506 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1508 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1514 // These are the relocation types supported by glibc for sparc 64-bit.
1515 case elfcpp::R_SPARC_RELATIVE
:
1516 case elfcpp::R_SPARC_COPY
:
1517 case elfcpp::R_SPARC_64
:
1518 case elfcpp::R_SPARC_GLOB_DAT
:
1519 case elfcpp::R_SPARC_JMP_SLOT
:
1520 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1521 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1522 case elfcpp::R_SPARC_TLS_TPOFF64
:
1523 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1524 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1525 case elfcpp::R_SPARC_8
:
1526 case elfcpp::R_SPARC_16
:
1527 case elfcpp::R_SPARC_DISP8
:
1528 case elfcpp::R_SPARC_DISP16
:
1529 case elfcpp::R_SPARC_DISP32
:
1530 case elfcpp::R_SPARC_WDISP30
:
1531 case elfcpp::R_SPARC_LO10
:
1532 case elfcpp::R_SPARC_HI22
:
1533 case elfcpp::R_SPARC_OLO10
:
1534 case elfcpp::R_SPARC_H44
:
1535 case elfcpp::R_SPARC_M44
:
1536 case elfcpp::R_SPARC_L44
:
1537 case elfcpp::R_SPARC_HH22
:
1538 case elfcpp::R_SPARC_HM10
:
1539 case elfcpp::R_SPARC_LM22
:
1540 case elfcpp::R_SPARC_UA16
:
1541 case elfcpp::R_SPARC_UA32
:
1542 case elfcpp::R_SPARC_UA64
:
1553 // These are the relocation types supported by glibc for sparc 32-bit.
1554 case elfcpp::R_SPARC_RELATIVE
:
1555 case elfcpp::R_SPARC_COPY
:
1556 case elfcpp::R_SPARC_GLOB_DAT
:
1557 case elfcpp::R_SPARC_32
:
1558 case elfcpp::R_SPARC_JMP_SLOT
:
1559 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1560 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1561 case elfcpp::R_SPARC_TLS_TPOFF32
:
1562 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1563 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1564 case elfcpp::R_SPARC_8
:
1565 case elfcpp::R_SPARC_16
:
1566 case elfcpp::R_SPARC_DISP8
:
1567 case elfcpp::R_SPARC_DISP16
:
1568 case elfcpp::R_SPARC_DISP32
:
1569 case elfcpp::R_SPARC_LO10
:
1570 case elfcpp::R_SPARC_WDISP30
:
1571 case elfcpp::R_SPARC_HI22
:
1572 case elfcpp::R_SPARC_UA16
:
1573 case elfcpp::R_SPARC_UA32
:
1581 // This prevents us from issuing more than one error per reloc
1582 // section. But we can still wind up issuing more than one
1583 // error per object file.
1584 if (this->issued_non_pic_error_
)
1586 gold_assert(parameters
->options().output_is_position_independent());
1587 object
->error(_("requires unsupported dynamic reloc; "
1588 "recompile with -fPIC"));
1589 this->issued_non_pic_error_
= true;
1593 // Scan a relocation for a local symbol.
1595 template<int size
, bool big_endian
>
1597 Target_sparc
<size
, big_endian
>::Scan::local(
1598 Symbol_table
* symtab
,
1600 Target_sparc
<size
, big_endian
>* target
,
1601 Sized_relobj
<size
, big_endian
>* object
,
1602 unsigned int data_shndx
,
1603 Output_section
* output_section
,
1604 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1605 unsigned int r_type
,
1606 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1608 unsigned int orig_r_type
= r_type
;
1613 case elfcpp::R_SPARC_NONE
:
1614 case elfcpp::R_SPARC_REGISTER
:
1615 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1616 case elfcpp::R_SPARC_GNU_VTENTRY
:
1619 case elfcpp::R_SPARC_64
:
1620 case elfcpp::R_SPARC_32
:
1621 // If building a shared library (or a position-independent
1622 // executable), we need to create a dynamic relocation for
1623 // this location. The relocation applied at link time will
1624 // apply the link-time value, so we flag the location with
1625 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1626 // relocate it easily.
1627 if (parameters
->options().output_is_position_independent())
1629 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1630 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1631 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1632 output_section
, data_shndx
,
1633 reloc
.get_r_offset(),
1634 reloc
.get_r_addend());
1638 case elfcpp::R_SPARC_HIX22
:
1639 case elfcpp::R_SPARC_LOX10
:
1640 case elfcpp::R_SPARC_H44
:
1641 case elfcpp::R_SPARC_M44
:
1642 case elfcpp::R_SPARC_L44
:
1643 case elfcpp::R_SPARC_HH22
:
1644 case elfcpp::R_SPARC_HM10
:
1645 case elfcpp::R_SPARC_LM22
:
1646 case elfcpp::R_SPARC_UA64
:
1647 case elfcpp::R_SPARC_UA32
:
1648 case elfcpp::R_SPARC_UA16
:
1649 case elfcpp::R_SPARC_HI22
:
1650 case elfcpp::R_SPARC_LO10
:
1651 case elfcpp::R_SPARC_OLO10
:
1652 case elfcpp::R_SPARC_16
:
1653 case elfcpp::R_SPARC_11
:
1654 case elfcpp::R_SPARC_10
:
1655 case elfcpp::R_SPARC_8
:
1656 case elfcpp::R_SPARC_7
:
1657 case elfcpp::R_SPARC_6
:
1658 case elfcpp::R_SPARC_5
:
1659 // If building a shared library (or a position-independent
1660 // executable), we need to create a dynamic relocation for
1662 if (parameters
->options().output_is_position_independent())
1664 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1666 check_non_pic(object
, r_type
);
1667 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1669 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1670 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1671 data_shndx
, reloc
.get_r_offset(),
1672 reloc
.get_r_addend());
1676 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1677 gold_assert(lsym
.get_st_value() == 0);
1678 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1679 output_section
, data_shndx
,
1680 reloc
.get_r_offset(),
1681 reloc
.get_r_addend());
1686 case elfcpp::R_SPARC_WDISP30
:
1687 case elfcpp::R_SPARC_WDISP22
:
1688 case elfcpp::R_SPARC_WDISP19
:
1689 case elfcpp::R_SPARC_WDISP16
:
1690 case elfcpp::R_SPARC_DISP8
:
1691 case elfcpp::R_SPARC_DISP16
:
1692 case elfcpp::R_SPARC_DISP32
:
1693 case elfcpp::R_SPARC_DISP64
:
1694 case elfcpp::R_SPARC_PC10
:
1695 case elfcpp::R_SPARC_PC22
:
1698 case elfcpp::R_SPARC_GOT10
:
1699 case elfcpp::R_SPARC_GOT13
:
1700 case elfcpp::R_SPARC_GOT22
:
1702 // The symbol requires a GOT entry.
1703 Output_data_got
<size
, big_endian
>* got
;
1706 got
= target
->got_section(symtab
, layout
);
1707 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1709 // If we are generating a shared object, we need to add a
1710 // dynamic relocation for this symbol's GOT entry.
1711 if (parameters
->options().output_is_position_independent())
1713 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1715 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1718 off
= got
->add_constant(0);
1719 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1720 rela_dyn
->add_local_relative(object
, r_sym
,
1721 elfcpp::R_SPARC_RELATIVE
,
1726 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1730 // These are initial TLS relocs, which are expected when
1732 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1733 case elfcpp::R_SPARC_TLS_GD_LO10
:
1734 case elfcpp::R_SPARC_TLS_GD_ADD
:
1735 case elfcpp::R_SPARC_TLS_GD_CALL
:
1736 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1737 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1738 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1739 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1740 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1741 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1742 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1743 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1744 case elfcpp::R_SPARC_TLS_IE_LO10
:
1745 case elfcpp::R_SPARC_TLS_IE_LD
:
1746 case elfcpp::R_SPARC_TLS_IE_LDX
:
1747 case elfcpp::R_SPARC_TLS_IE_ADD
:
1748 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1749 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1751 bool output_is_shared
= parameters
->options().shared();
1752 const tls::Tls_optimization optimized_type
1753 = optimize_tls_reloc(!output_is_shared
, r_type
);
1756 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1757 case elfcpp::R_SPARC_TLS_GD_LO10
:
1758 case elfcpp::R_SPARC_TLS_GD_ADD
:
1759 case elfcpp::R_SPARC_TLS_GD_CALL
:
1760 if (optimized_type
== tls::TLSOPT_NONE
)
1762 // Create a pair of GOT entries for the module index and
1763 // dtv-relative offset.
1764 Output_data_got
<size
, big_endian
>* got
1765 = target
->got_section(symtab
, layout
);
1766 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1767 unsigned int shndx
= lsym
.get_st_shndx();
1769 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1771 object
->error(_("local symbol %u has bad shndx %u"),
1774 got
->add_local_pair_with_rela(object
, r_sym
,
1775 lsym
.get_st_shndx(),
1777 target
->rela_dyn_section(layout
),
1779 ? elfcpp::R_SPARC_TLS_DTPMOD64
1780 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1782 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1783 generate_tls_call(symtab
, layout
, target
);
1785 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1786 unsupported_reloc_local(object
, r_type
);
1789 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1790 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1791 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1792 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1793 if (optimized_type
== tls::TLSOPT_NONE
)
1795 // Create a GOT entry for the module index.
1796 target
->got_mod_index_entry(symtab
, layout
, object
);
1798 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1799 generate_tls_call(symtab
, layout
, target
);
1801 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1802 unsupported_reloc_local(object
, r_type
);
1805 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1806 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1807 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1810 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1811 case elfcpp::R_SPARC_TLS_IE_LO10
:
1812 case elfcpp::R_SPARC_TLS_IE_LD
:
1813 case elfcpp::R_SPARC_TLS_IE_LDX
:
1814 case elfcpp::R_SPARC_TLS_IE_ADD
:
1815 layout
->set_has_static_tls();
1816 if (optimized_type
== tls::TLSOPT_NONE
)
1818 // Create a GOT entry for the tp-relative offset.
1819 Output_data_got
<size
, big_endian
>* got
1820 = target
->got_section(symtab
, layout
);
1821 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1823 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1825 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1826 unsigned int off
= got
->add_constant(0);
1828 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1830 rela_dyn
->add_local_relative(object
, r_sym
,
1832 elfcpp::R_SPARC_TLS_TPOFF64
:
1833 elfcpp::R_SPARC_TLS_TPOFF32
),
1837 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1838 unsupported_reloc_local(object
, r_type
);
1841 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1842 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1843 layout
->set_has_static_tls();
1844 if (output_is_shared
)
1846 // We need to create a dynamic relocation.
1847 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1848 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1849 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1850 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1851 output_section
, data_shndx
,
1852 reloc
.get_r_offset(), 0);
1859 // These are relocations which should only be seen by the
1860 // dynamic linker, and should never be seen here.
1861 case elfcpp::R_SPARC_COPY
:
1862 case elfcpp::R_SPARC_GLOB_DAT
:
1863 case elfcpp::R_SPARC_JMP_SLOT
:
1864 case elfcpp::R_SPARC_RELATIVE
:
1865 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1866 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1867 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1868 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1869 case elfcpp::R_SPARC_TLS_TPOFF64
:
1870 case elfcpp::R_SPARC_TLS_TPOFF32
:
1871 gold_error(_("%s: unexpected reloc %u in object file"),
1872 object
->name().c_str(), r_type
);
1876 unsupported_reloc_local(object
, r_type
);
1881 // Report an unsupported relocation against a global symbol.
1883 template<int size
, bool big_endian
>
1885 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1886 Sized_relobj
<size
, big_endian
>* object
,
1887 unsigned int r_type
,
1890 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1891 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1894 // Scan a relocation for a global symbol.
1896 template<int size
, bool big_endian
>
1898 Target_sparc
<size
, big_endian
>::Scan::global(
1899 Symbol_table
* symtab
,
1901 Target_sparc
<size
, big_endian
>* target
,
1902 Sized_relobj
<size
, big_endian
>* object
,
1903 unsigned int data_shndx
,
1904 Output_section
* output_section
,
1905 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1906 unsigned int r_type
,
1909 unsigned int orig_r_type
= r_type
;
1911 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
1912 // section. We check here to avoid creating a dynamic reloc against
1913 // _GLOBAL_OFFSET_TABLE_.
1914 if (!target
->has_got_section()
1915 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
1916 target
->got_section(symtab
, layout
);
1921 case elfcpp::R_SPARC_NONE
:
1922 case elfcpp::R_SPARC_REGISTER
:
1923 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1924 case elfcpp::R_SPARC_GNU_VTENTRY
:
1927 case elfcpp::R_SPARC_PLT64
:
1928 case elfcpp::R_SPARC_PLT32
:
1929 case elfcpp::R_SPARC_HIPLT22
:
1930 case elfcpp::R_SPARC_LOPLT10
:
1931 case elfcpp::R_SPARC_PCPLT32
:
1932 case elfcpp::R_SPARC_PCPLT22
:
1933 case elfcpp::R_SPARC_PCPLT10
:
1934 case elfcpp::R_SPARC_WPLT30
:
1935 // If the symbol is fully resolved, this is just a PC32 reloc.
1936 // Otherwise we need a PLT entry.
1937 if (gsym
->final_value_is_known())
1939 // If building a shared library, we can also skip the PLT entry
1940 // if the symbol is defined in the output file and is protected
1942 if (gsym
->is_defined()
1943 && !gsym
->is_from_dynobj()
1944 && !gsym
->is_preemptible())
1946 target
->make_plt_entry(symtab
, layout
, gsym
);
1949 case elfcpp::R_SPARC_DISP8
:
1950 case elfcpp::R_SPARC_DISP16
:
1951 case elfcpp::R_SPARC_DISP32
:
1952 case elfcpp::R_SPARC_DISP64
:
1953 case elfcpp::R_SPARC_PC_HH22
:
1954 case elfcpp::R_SPARC_PC_HM10
:
1955 case elfcpp::R_SPARC_PC_LM22
:
1956 case elfcpp::R_SPARC_PC10
:
1957 case elfcpp::R_SPARC_PC22
:
1958 case elfcpp::R_SPARC_WDISP30
:
1959 case elfcpp::R_SPARC_WDISP22
:
1960 case elfcpp::R_SPARC_WDISP19
:
1961 case elfcpp::R_SPARC_WDISP16
:
1963 if (gsym
->needs_plt_entry())
1964 target
->make_plt_entry(symtab
, layout
, gsym
);
1965 // Make a dynamic relocation if necessary.
1966 int flags
= Symbol::NON_PIC_REF
;
1967 if (gsym
->type() == elfcpp::STT_FUNC
)
1968 flags
|= Symbol::FUNCTION_CALL
;
1969 if (gsym
->needs_dynamic_reloc(flags
))
1971 if (gsym
->may_need_copy_reloc())
1973 target
->copy_reloc(symtab
, layout
, object
,
1974 data_shndx
, output_section
, gsym
,
1979 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1980 check_non_pic(object
, r_type
);
1981 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1982 data_shndx
, reloc
.get_r_offset(),
1983 reloc
.get_r_addend());
1989 case elfcpp::R_SPARC_UA64
:
1990 case elfcpp::R_SPARC_64
:
1991 case elfcpp::R_SPARC_HIX22
:
1992 case elfcpp::R_SPARC_LOX10
:
1993 case elfcpp::R_SPARC_H44
:
1994 case elfcpp::R_SPARC_M44
:
1995 case elfcpp::R_SPARC_L44
:
1996 case elfcpp::R_SPARC_HH22
:
1997 case elfcpp::R_SPARC_HM10
:
1998 case elfcpp::R_SPARC_LM22
:
1999 case elfcpp::R_SPARC_HI22
:
2000 case elfcpp::R_SPARC_LO10
:
2001 case elfcpp::R_SPARC_OLO10
:
2002 case elfcpp::R_SPARC_UA32
:
2003 case elfcpp::R_SPARC_32
:
2004 case elfcpp::R_SPARC_UA16
:
2005 case elfcpp::R_SPARC_16
:
2006 case elfcpp::R_SPARC_11
:
2007 case elfcpp::R_SPARC_10
:
2008 case elfcpp::R_SPARC_8
:
2009 case elfcpp::R_SPARC_7
:
2010 case elfcpp::R_SPARC_6
:
2011 case elfcpp::R_SPARC_5
:
2013 // Make a PLT entry if necessary.
2014 if (gsym
->needs_plt_entry())
2016 target
->make_plt_entry(symtab
, layout
, gsym
);
2017 // Since this is not a PC-relative relocation, we may be
2018 // taking the address of a function. In that case we need to
2019 // set the entry in the dynamic symbol table to the address of
2021 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2022 gsym
->set_needs_dynsym_value();
2024 // Make a dynamic relocation if necessary.
2025 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2027 if (gsym
->may_need_copy_reloc())
2029 target
->copy_reloc(symtab
, layout
, object
,
2030 data_shndx
, output_section
, gsym
, reloc
);
2032 else if ((r_type
== elfcpp::R_SPARC_32
2033 || r_type
== elfcpp::R_SPARC_64
)
2034 && gsym
->can_use_relative_reloc(false))
2036 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2037 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2038 output_section
, object
,
2039 data_shndx
, reloc
.get_r_offset(),
2040 reloc
.get_r_addend());
2044 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2046 check_non_pic(object
, r_type
);
2047 if (gsym
->is_from_dynobj()
2048 || gsym
->is_undefined()
2049 || gsym
->is_preemptible())
2050 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2052 reloc
.get_r_offset(),
2053 reloc
.get_r_addend());
2055 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2056 output_section
, object
,
2058 reloc
.get_r_offset(),
2059 reloc
.get_r_addend());
2065 case elfcpp::R_SPARC_GOT10
:
2066 case elfcpp::R_SPARC_GOT13
:
2067 case elfcpp::R_SPARC_GOT22
:
2069 // The symbol requires a GOT entry.
2070 Output_data_got
<size
, big_endian
>* got
;
2072 got
= target
->got_section(symtab
, layout
);
2073 if (gsym
->final_value_is_known())
2074 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2077 // If this symbol is not fully resolved, we need to add a
2078 // dynamic relocation for it.
2079 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2080 if (gsym
->is_from_dynobj()
2081 || gsym
->is_undefined()
2082 || gsym
->is_preemptible())
2083 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2084 elfcpp::R_SPARC_GLOB_DAT
);
2085 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2087 unsigned int off
= got
->add_constant(0);
2089 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2090 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2097 // These are initial tls relocs, which are expected when
2099 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2100 case elfcpp::R_SPARC_TLS_GD_LO10
:
2101 case elfcpp::R_SPARC_TLS_GD_ADD
:
2102 case elfcpp::R_SPARC_TLS_GD_CALL
:
2103 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2104 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2105 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2106 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2107 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2108 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2109 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2110 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2111 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2112 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2113 case elfcpp::R_SPARC_TLS_IE_LO10
:
2114 case elfcpp::R_SPARC_TLS_IE_LD
:
2115 case elfcpp::R_SPARC_TLS_IE_LDX
:
2116 case elfcpp::R_SPARC_TLS_IE_ADD
:
2118 const bool is_final
= gsym
->final_value_is_known();
2119 const tls::Tls_optimization optimized_type
2120 = optimize_tls_reloc(is_final
, r_type
);
2123 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2124 case elfcpp::R_SPARC_TLS_GD_LO10
:
2125 case elfcpp::R_SPARC_TLS_GD_ADD
:
2126 case elfcpp::R_SPARC_TLS_GD_CALL
:
2127 if (optimized_type
== tls::TLSOPT_NONE
)
2129 // Create a pair of GOT entries for the module index and
2130 // dtv-relative offset.
2131 Output_data_got
<size
, big_endian
>* got
2132 = target
->got_section(symtab
, layout
);
2133 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2134 target
->rela_dyn_section(layout
),
2136 elfcpp::R_SPARC_TLS_DTPMOD64
:
2137 elfcpp::R_SPARC_TLS_DTPMOD32
),
2139 elfcpp::R_SPARC_TLS_DTPOFF64
:
2140 elfcpp::R_SPARC_TLS_DTPOFF32
));
2142 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2143 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2144 generate_tls_call(symtab
, layout
, target
);
2146 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2148 // Create a GOT entry for the tp-relative offset.
2149 Output_data_got
<size
, big_endian
>* got
2150 = target
->got_section(symtab
, layout
);
2151 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2152 target
->rela_dyn_section(layout
),
2154 elfcpp::R_SPARC_TLS_TPOFF64
:
2155 elfcpp::R_SPARC_TLS_TPOFF32
));
2157 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2158 unsupported_reloc_global(object
, r_type
, gsym
);
2161 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2162 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2163 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2164 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2165 if (optimized_type
== tls::TLSOPT_NONE
)
2167 // Create a GOT entry for the module index.
2168 target
->got_mod_index_entry(symtab
, layout
, object
);
2170 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2171 generate_tls_call(symtab
, layout
, target
);
2173 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2174 unsupported_reloc_global(object
, r_type
, gsym
);
2177 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2178 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2179 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2182 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2183 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2184 layout
->set_has_static_tls();
2185 if (parameters
->options().shared())
2187 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2188 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2189 output_section
, object
,
2190 data_shndx
, reloc
.get_r_offset(),
2195 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2196 case elfcpp::R_SPARC_TLS_IE_LO10
:
2197 case elfcpp::R_SPARC_TLS_IE_LD
:
2198 case elfcpp::R_SPARC_TLS_IE_LDX
:
2199 case elfcpp::R_SPARC_TLS_IE_ADD
:
2200 layout
->set_has_static_tls();
2201 if (optimized_type
== tls::TLSOPT_NONE
)
2203 // Create a GOT entry for the tp-relative offset.
2204 Output_data_got
<size
, big_endian
>* got
2205 = target
->got_section(symtab
, layout
);
2206 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2207 target
->rela_dyn_section(layout
),
2209 elfcpp::R_SPARC_TLS_TPOFF64
:
2210 elfcpp::R_SPARC_TLS_TPOFF32
));
2212 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2213 unsupported_reloc_global(object
, r_type
, gsym
);
2219 // These are relocations which should only be seen by the
2220 // dynamic linker, and should never be seen here.
2221 case elfcpp::R_SPARC_COPY
:
2222 case elfcpp::R_SPARC_GLOB_DAT
:
2223 case elfcpp::R_SPARC_JMP_SLOT
:
2224 case elfcpp::R_SPARC_RELATIVE
:
2225 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2226 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2227 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2228 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2229 case elfcpp::R_SPARC_TLS_TPOFF64
:
2230 case elfcpp::R_SPARC_TLS_TPOFF32
:
2231 gold_error(_("%s: unexpected reloc %u in object file"),
2232 object
->name().c_str(), r_type
);
2236 unsupported_reloc_global(object
, r_type
, gsym
);
2241 // Process relocations for gc.
2243 template<int size
, bool big_endian
>
2245 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2246 Symbol_table
* symtab
,
2248 Sized_relobj
<size
, big_endian
>* object
,
2249 unsigned int data_shndx
,
2251 const unsigned char* prelocs
,
2253 Output_section
* output_section
,
2254 bool needs_special_offset_handling
,
2255 size_t local_symbol_count
,
2256 const unsigned char* plocal_symbols
)
2258 typedef Target_sparc
<size
, big_endian
> Sparc
;
2259 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2261 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2270 needs_special_offset_handling
,
2275 // Scan relocations for a section.
2277 template<int size
, bool big_endian
>
2279 Target_sparc
<size
, big_endian
>::scan_relocs(
2280 Symbol_table
* symtab
,
2282 Sized_relobj
<size
, big_endian
>* object
,
2283 unsigned int data_shndx
,
2284 unsigned int sh_type
,
2285 const unsigned char* prelocs
,
2287 Output_section
* output_section
,
2288 bool needs_special_offset_handling
,
2289 size_t local_symbol_count
,
2290 const unsigned char* plocal_symbols
)
2292 typedef Target_sparc
<size
, big_endian
> Sparc
;
2293 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2295 if (sh_type
== elfcpp::SHT_REL
)
2297 gold_error(_("%s: unsupported REL reloc section"),
2298 object
->name().c_str());
2302 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2311 needs_special_offset_handling
,
2316 // Finalize the sections.
2318 template<int size
, bool big_endian
>
2320 Target_sparc
<size
, big_endian
>::do_finalize_sections(
2322 const Input_objects
*)
2324 // Fill in some more dynamic tags.
2325 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2328 if (this->plt_
!= NULL
2329 && this->plt_
->output_section() != NULL
)
2331 const Output_data
* od
= this->plt_
->rel_plt();
2332 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2333 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2334 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2336 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2339 if (this->rela_dyn_
!= NULL
2340 && this->rela_dyn_
->output_section() != NULL
)
2342 const Output_data
* od
= this->rela_dyn_
;
2343 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2344 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2345 odyn
->add_constant(elfcpp::DT_RELAENT
,
2346 elfcpp::Elf_sizes
<size
>::rela_size
);
2349 if (!parameters
->options().shared())
2351 // The value of the DT_DEBUG tag is filled in by the dynamic
2352 // linker at run time, and used by the debugger.
2353 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2357 // Emit any relocs we saved in an attempt to avoid generating COPY
2359 if (this->copy_relocs_
.any_saved_relocs())
2360 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2363 // Perform a relocation.
2365 template<int size
, bool big_endian
>
2367 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2368 const Relocate_info
<size
, big_endian
>* relinfo
,
2369 Target_sparc
* target
,
2372 const elfcpp::Rela
<size
, big_endian
>& rela
,
2373 unsigned int r_type
,
2374 const Sized_symbol
<size
>* gsym
,
2375 const Symbol_value
<size
>* psymval
,
2376 unsigned char* view
,
2377 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2378 section_size_type view_size
)
2382 if (this->ignore_gd_add_
)
2384 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2385 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2386 _("missing expected TLS relocation"));
2389 this->ignore_gd_add_
= false;
2394 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2396 // Pick the value to use for symbols defined in shared objects.
2397 Symbol_value
<size
> symval
;
2399 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2400 || r_type
== elfcpp::R_SPARC_DISP16
2401 || r_type
== elfcpp::R_SPARC_DISP32
2402 || r_type
== elfcpp::R_SPARC_DISP64
2403 || r_type
== elfcpp::R_SPARC_PC_HH22
2404 || r_type
== elfcpp::R_SPARC_PC_HM10
2405 || r_type
== elfcpp::R_SPARC_PC_LM22
2406 || r_type
== elfcpp::R_SPARC_PC10
2407 || r_type
== elfcpp::R_SPARC_PC22
2408 || r_type
== elfcpp::R_SPARC_WDISP30
2409 || r_type
== elfcpp::R_SPARC_WDISP22
2410 || r_type
== elfcpp::R_SPARC_WDISP19
2411 || r_type
== elfcpp::R_SPARC_WDISP16
))
2413 elfcpp::Elf_Xword value
;
2415 value
= target
->plt_section()->address() + gsym
->plt_offset();
2417 symval
.set_output_value(value
);
2422 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2423 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2425 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2426 // pointer points to the beginning, not the end, of the table.
2427 // So we just use the plain offset.
2428 bool have_got_offset
= false;
2429 unsigned int got_offset
= 0;
2432 case elfcpp::R_SPARC_GOT10
:
2433 case elfcpp::R_SPARC_GOT13
:
2434 case elfcpp::R_SPARC_GOT22
:
2437 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2438 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2442 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2443 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2444 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2446 have_got_offset
= true;
2455 case elfcpp::R_SPARC_NONE
:
2456 case elfcpp::R_SPARC_REGISTER
:
2457 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2458 case elfcpp::R_SPARC_GNU_VTENTRY
:
2461 case elfcpp::R_SPARC_8
:
2462 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2466 case elfcpp::R_SPARC_16
:
2467 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2471 case elfcpp::R_SPARC_32
:
2472 if (!parameters
->options().output_is_position_independent())
2473 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2477 case elfcpp::R_SPARC_DISP8
:
2478 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2481 case elfcpp::R_SPARC_DISP16
:
2482 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2485 case elfcpp::R_SPARC_DISP32
:
2486 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2489 case elfcpp::R_SPARC_DISP64
:
2490 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2493 case elfcpp::R_SPARC_WDISP30
:
2494 case elfcpp::R_SPARC_WPLT30
:
2495 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2498 case elfcpp::R_SPARC_WDISP22
:
2499 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2502 case elfcpp::R_SPARC_WDISP19
:
2503 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2506 case elfcpp::R_SPARC_WDISP16
:
2507 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2510 case elfcpp::R_SPARC_HI22
:
2511 Reloc::hi22(view
, object
, psymval
, addend
);
2514 case elfcpp::R_SPARC_22
:
2515 Reloc::rela32_22(view
, object
, psymval
, addend
);
2518 case elfcpp::R_SPARC_13
:
2519 Reloc::rela32_13(view
, object
, psymval
, addend
);
2522 case elfcpp::R_SPARC_LO10
:
2523 Reloc::lo10(view
, object
, psymval
, addend
);
2526 case elfcpp::R_SPARC_GOT10
:
2527 Reloc::lo10(view
, got_offset
, addend
);
2530 case elfcpp::R_SPARC_GOT13
:
2531 Reloc::rela32_13(view
, got_offset
, addend
);
2534 case elfcpp::R_SPARC_GOT22
:
2535 Reloc::hi22(view
, got_offset
, addend
);
2538 case elfcpp::R_SPARC_PC10
:
2539 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2542 case elfcpp::R_SPARC_PC22
:
2543 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2546 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2547 case elfcpp::R_SPARC_UA32
:
2548 Reloc::ua32(view
, object
, psymval
, addend
);
2551 case elfcpp::R_SPARC_PLT64
:
2552 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2556 case elfcpp::R_SPARC_PLT32
:
2557 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2561 case elfcpp::R_SPARC_HIPLT22
:
2562 Reloc::hi22(view
, object
, psymval
, addend
);
2565 case elfcpp::R_SPARC_LOPLT10
:
2566 Reloc::lo10(view
, object
, psymval
, addend
);
2569 case elfcpp::R_SPARC_PCPLT32
:
2570 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2573 case elfcpp::R_SPARC_PCPLT22
:
2574 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2577 case elfcpp::R_SPARC_PCPLT10
:
2578 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2581 case elfcpp::R_SPARC_64
:
2582 if (!parameters
->options().output_is_position_independent())
2583 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2587 case elfcpp::R_SPARC_OLO10
:
2589 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2590 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2591 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2595 case elfcpp::R_SPARC_HH22
:
2596 Reloc::hh22(view
, object
, psymval
, addend
);
2599 case elfcpp::R_SPARC_PC_HH22
:
2600 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2603 case elfcpp::R_SPARC_HM10
:
2604 Reloc::hm10(view
, object
, psymval
, addend
);
2607 case elfcpp::R_SPARC_PC_HM10
:
2608 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2611 case elfcpp::R_SPARC_LM22
:
2612 Reloc::hi22(view
, object
, psymval
, addend
);
2615 case elfcpp::R_SPARC_PC_LM22
:
2616 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2619 case elfcpp::R_SPARC_11
:
2620 Reloc::rela32_11(view
, object
, psymval
, addend
);
2623 case elfcpp::R_SPARC_10
:
2624 Reloc::rela32_10(view
, object
, psymval
, addend
);
2627 case elfcpp::R_SPARC_7
:
2628 Reloc::rela32_7(view
, object
, psymval
, addend
);
2631 case elfcpp::R_SPARC_6
:
2632 Reloc::rela32_6(view
, object
, psymval
, addend
);
2635 case elfcpp::R_SPARC_5
:
2636 Reloc::rela32_5(view
, object
, psymval
, addend
);
2639 case elfcpp::R_SPARC_HIX22
:
2640 Reloc::hix22(view
, object
, psymval
, addend
);
2643 case elfcpp::R_SPARC_LOX10
:
2644 Reloc::lox10(view
, object
, psymval
, addend
);
2647 case elfcpp::R_SPARC_H44
:
2648 Reloc::h44(view
, object
, psymval
, addend
);
2651 case elfcpp::R_SPARC_M44
:
2652 Reloc::m44(view
, object
, psymval
, addend
);
2655 case elfcpp::R_SPARC_L44
:
2656 Reloc::l44(view
, object
, psymval
, addend
);
2659 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2660 case elfcpp::R_SPARC_UA64
:
2661 Reloc::ua64(view
, object
, psymval
, addend
);
2664 case elfcpp::R_SPARC_UA16
:
2665 Reloc::ua16(view
, object
, psymval
, addend
);
2668 case elfcpp::R_SPARC_TLS_GD_HI22
:
2669 case elfcpp::R_SPARC_TLS_GD_LO10
:
2670 case elfcpp::R_SPARC_TLS_GD_ADD
:
2671 case elfcpp::R_SPARC_TLS_GD_CALL
:
2672 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2673 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2674 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2675 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2676 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2677 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2678 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2679 case elfcpp::R_SPARC_TLS_IE_HI22
:
2680 case elfcpp::R_SPARC_TLS_IE_LO10
:
2681 case elfcpp::R_SPARC_TLS_IE_LD
:
2682 case elfcpp::R_SPARC_TLS_IE_LDX
:
2683 case elfcpp::R_SPARC_TLS_IE_ADD
:
2684 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2685 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2686 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2687 r_type
, gsym
, psymval
, view
,
2688 address
, view_size
);
2691 case elfcpp::R_SPARC_COPY
:
2692 case elfcpp::R_SPARC_GLOB_DAT
:
2693 case elfcpp::R_SPARC_JMP_SLOT
:
2694 case elfcpp::R_SPARC_RELATIVE
:
2695 // These are outstanding tls relocs, which are unexpected when
2697 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2698 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2699 case elfcpp::R_SPARC_TLS_TPOFF64
:
2700 case elfcpp::R_SPARC_TLS_TPOFF32
:
2701 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2702 _("unexpected reloc %u in object file"),
2707 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2708 _("unsupported reloc %u"),
2716 // Perform a TLS relocation.
2718 template<int size
, bool big_endian
>
2720 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2721 const Relocate_info
<size
, big_endian
>* relinfo
,
2722 Target_sparc
<size
, big_endian
>* target
,
2724 const elfcpp::Rela
<size
, big_endian
>& rela
,
2725 unsigned int r_type
,
2726 const Sized_symbol
<size
>* gsym
,
2727 const Symbol_value
<size
>* psymval
,
2728 unsigned char* view
,
2729 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2732 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2733 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2734 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2735 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2737 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2738 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2740 const bool is_final
=
2742 ? !parameters
->options().output_is_position_independent()
2743 : gsym
->final_value_is_known());
2744 const tls::Tls_optimization optimized_type
2745 = optimize_tls_reloc(is_final
, r_type
);
2749 case elfcpp::R_SPARC_TLS_GD_HI22
:
2750 case elfcpp::R_SPARC_TLS_GD_LO10
:
2751 case elfcpp::R_SPARC_TLS_GD_ADD
:
2752 case elfcpp::R_SPARC_TLS_GD_CALL
:
2753 if (optimized_type
== tls::TLSOPT_TO_LE
)
2755 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2758 value
-= tls_segment
->memsz();
2762 case elfcpp::R_SPARC_TLS_GD_HI22
:
2763 // TLS_GD_HI22 --> TLS_LE_HIX22
2764 Reloc::hix22(view
, value
, addend
);
2767 case elfcpp::R_SPARC_TLS_GD_LO10
:
2768 // TLS_GD_LO10 --> TLS_LE_LOX10
2769 Reloc::lox10(view
, value
, addend
);
2772 case elfcpp::R_SPARC_TLS_GD_ADD
:
2773 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2774 val
= elfcpp::Swap
<32, true>::readval(wv
);
2775 val
= (val
& ~0x7c000) | 0x1c000;
2776 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2778 case elfcpp::R_SPARC_TLS_GD_CALL
:
2779 // call __tls_get_addr --> nop
2780 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2787 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2788 ? GOT_TYPE_TLS_OFFSET
2789 : GOT_TYPE_TLS_PAIR
);
2792 gold_assert(gsym
->has_got_offset(got_type
));
2793 value
= gsym
->got_offset(got_type
);
2797 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2798 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2799 value
= object
->local_got_offset(r_sym
, got_type
);
2801 if (optimized_type
== tls::TLSOPT_TO_IE
)
2803 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2808 case elfcpp::R_SPARC_TLS_GD_HI22
:
2809 // TLS_GD_HI22 --> TLS_IE_HI22
2810 Reloc::hi22(view
, value
, addend
);
2813 case elfcpp::R_SPARC_TLS_GD_LO10
:
2814 // TLS_GD_LO10 --> TLS_IE_LO10
2815 Reloc::lo10(view
, value
, addend
);
2818 case elfcpp::R_SPARC_TLS_GD_ADD
:
2819 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2820 val
= elfcpp::Swap
<32, true>::readval(wv
);
2827 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2830 case elfcpp::R_SPARC_TLS_GD_CALL
:
2831 // The compiler can put the TLS_GD_ADD instruction
2832 // into the delay slot of the call. If so, we need
2833 // to transpose the two instructions so that the
2834 // the new sequence works properly.
2836 // The test we use is if the instruction in the
2837 // delay slot is an add with destination register
2839 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2840 if ((val
& 0x81f80000) == 0x80000000
2841 && ((val
>> 25) & 0x1f) == 0x8)
2848 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2851 this->ignore_gd_add_
= true;
2854 // call __tls_get_addr --> add %g7, %o0, %o0
2855 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2860 else if (optimized_type
== tls::TLSOPT_NONE
)
2864 case elfcpp::R_SPARC_TLS_GD_HI22
:
2865 Reloc::hi22(view
, value
, addend
);
2867 case elfcpp::R_SPARC_TLS_GD_LO10
:
2868 Reloc::lo10(view
, value
, addend
);
2870 case elfcpp::R_SPARC_TLS_GD_ADD
:
2872 case elfcpp::R_SPARC_TLS_GD_CALL
:
2874 Symbol_value
<size
> symval
;
2875 elfcpp::Elf_Xword value
;
2878 tsym
= target
->tls_get_addr_sym_
;
2880 value
= (target
->plt_section()->address() +
2881 tsym
->plt_offset());
2882 symval
.set_output_value(value
);
2883 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2890 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2891 _("unsupported reloc %u"),
2895 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2896 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2897 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2898 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2899 if (optimized_type
== tls::TLSOPT_TO_LE
)
2901 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2905 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2906 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2907 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2908 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2911 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2912 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2917 else if (optimized_type
== tls::TLSOPT_NONE
)
2919 // Relocate the field with the offset of the GOT entry for
2920 // the module index.
2921 unsigned int got_offset
;
2923 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2926 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2927 Reloc::hi22(view
, got_offset
, addend
);
2929 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2930 Reloc::lo10(view
, got_offset
, addend
);
2932 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2934 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2936 Symbol_value
<size
> symval
;
2937 elfcpp::Elf_Xword value
;
2940 tsym
= target
->tls_get_addr_sym_
;
2942 value
= (target
->plt_section()->address() +
2943 tsym
->plt_offset());
2944 symval
.set_output_value(value
);
2945 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2951 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2952 _("unsupported reloc %u"),
2956 // These relocs can appear in debugging sections, in which case
2957 // we won't see the TLS_LDM relocs. The local_dynamic_type
2958 // field tells us this.
2959 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2960 if (optimized_type
== tls::TLSOPT_TO_LE
)
2962 value
-= tls_segment
->memsz();
2963 Reloc::hix22(view
, value
, addend
);
2966 Reloc::ldo_hix22(view
, value
, addend
);
2968 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2969 if (optimized_type
== tls::TLSOPT_TO_LE
)
2971 value
-= tls_segment
->memsz();
2972 Reloc::lox10(view
, value
, addend
);
2975 Reloc::ldo_lox10(view
, value
, addend
);
2977 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2978 if (optimized_type
== tls::TLSOPT_TO_LE
)
2980 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2983 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2984 val
= elfcpp::Swap
<32, true>::readval(wv
);
2985 val
= (val
& ~0x7c000) | 0x1c000;
2986 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2990 // When optimizing IE --> LE, the only relocation that is handled
2991 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2992 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2993 // rs2 and rd are the same.
2994 case elfcpp::R_SPARC_TLS_IE_LD
:
2995 case elfcpp::R_SPARC_TLS_IE_LDX
:
2996 if (optimized_type
== tls::TLSOPT_TO_LE
)
2998 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2999 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3000 Insntype rs2
= val
& 0x1f;
3001 Insntype rd
= (val
>> 25) & 0x1f;
3006 val
= sparc_mov
| (val
& 0x3e00001f);
3008 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3012 case elfcpp::R_SPARC_TLS_IE_HI22
:
3013 case elfcpp::R_SPARC_TLS_IE_LO10
:
3014 if (optimized_type
== tls::TLSOPT_TO_LE
)
3016 value
-= tls_segment
->memsz();
3019 case elfcpp::R_SPARC_TLS_IE_HI22
:
3020 // IE_HI22 --> LE_HIX22
3021 Reloc::hix22(view
, value
, addend
);
3023 case elfcpp::R_SPARC_TLS_IE_LO10
:
3024 // IE_LO10 --> LE_LOX10
3025 Reloc::lox10(view
, value
, addend
);
3030 else if (optimized_type
== tls::TLSOPT_NONE
)
3032 // Relocate the field with the offset of the GOT entry for
3033 // the tp-relative offset of the symbol.
3036 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3037 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3041 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3042 gold_assert(object
->local_has_got_offset(r_sym
,
3043 GOT_TYPE_TLS_OFFSET
));
3044 value
= object
->local_got_offset(r_sym
,
3045 GOT_TYPE_TLS_OFFSET
);
3049 case elfcpp::R_SPARC_TLS_IE_HI22
:
3050 Reloc::hi22(view
, value
, addend
);
3052 case elfcpp::R_SPARC_TLS_IE_LO10
:
3053 Reloc::lo10(view
, value
, addend
);
3058 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3059 _("unsupported reloc %u"),
3063 case elfcpp::R_SPARC_TLS_IE_ADD
:
3064 // This seems to be mainly so that we can find the addition
3065 // instruction if there is one. There doesn't seem to be any
3066 // actual relocation to apply.
3069 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3070 // If we're creating a shared library, a dynamic relocation will
3071 // have been created for this location, so do not apply it now.
3072 if (!parameters
->options().shared())
3074 value
-= tls_segment
->memsz();
3075 Reloc::hix22(view
, value
, addend
);
3079 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3080 // If we're creating a shared library, a dynamic relocation will
3081 // have been created for this location, so do not apply it now.
3082 if (!parameters
->options().shared())
3084 value
-= tls_segment
->memsz();
3085 Reloc::lox10(view
, value
, addend
);
3091 // Relocate section data.
3093 template<int size
, bool big_endian
>
3095 Target_sparc
<size
, big_endian
>::relocate_section(
3096 const Relocate_info
<size
, big_endian
>* relinfo
,
3097 unsigned int sh_type
,
3098 const unsigned char* prelocs
,
3100 Output_section
* output_section
,
3101 bool needs_special_offset_handling
,
3102 unsigned char* view
,
3103 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3104 section_size_type view_size
,
3105 const Reloc_symbol_changes
* reloc_symbol_changes
)
3107 typedef Target_sparc
<size
, big_endian
> Sparc
;
3108 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3110 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3112 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3119 needs_special_offset_handling
,
3123 reloc_symbol_changes
);
3126 // Return the size of a relocation while scanning during a relocatable
3129 template<int size
, bool big_endian
>
3131 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3135 // We are always SHT_RELA, so we should never get here.
3140 // Scan the relocs during a relocatable link.
3142 template<int size
, bool big_endian
>
3144 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3145 Symbol_table
* symtab
,
3147 Sized_relobj
<size
, big_endian
>* object
,
3148 unsigned int data_shndx
,
3149 unsigned int sh_type
,
3150 const unsigned char* prelocs
,
3152 Output_section
* output_section
,
3153 bool needs_special_offset_handling
,
3154 size_t local_symbol_count
,
3155 const unsigned char* plocal_symbols
,
3156 Relocatable_relocs
* rr
)
3158 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3160 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3161 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3163 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3164 Scan_relocatable_relocs
>(
3172 needs_special_offset_handling
,
3178 // Relocate a section during a relocatable link.
3180 template<int size
, bool big_endian
>
3182 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3183 const Relocate_info
<size
, big_endian
>* relinfo
,
3184 unsigned int sh_type
,
3185 const unsigned char* prelocs
,
3187 Output_section
* output_section
,
3188 off_t offset_in_output_section
,
3189 const Relocatable_relocs
* rr
,
3190 unsigned char* view
,
3191 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3192 section_size_type view_size
,
3193 unsigned char* reloc_view
,
3194 section_size_type reloc_view_size
)
3196 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3198 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3203 offset_in_output_section
,
3212 // Return the value to use for a dynamic which requires special
3213 // treatment. This is how we support equality comparisons of function
3214 // pointers across shared library boundaries, as described in the
3215 // processor specific ABI supplement.
3217 template<int size
, bool big_endian
>
3219 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3221 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3222 return this->plt_section()->address() + gsym
->plt_offset();
3225 // The selector for sparc object files.
3227 template<int size
, bool big_endian
>
3228 class Target_selector_sparc
: public Target_selector
3231 Target_selector_sparc()
3232 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3233 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3236 Target
* do_recognize(int machine
, int, int)
3241 if (machine
!= elfcpp::EM_SPARCV9
)
3246 if (machine
!= elfcpp::EM_SPARC
3247 && machine
!= elfcpp::EM_SPARC32PLUS
)
3255 return this->instantiate_target();
3258 Target
* do_instantiate_target()
3259 { return new Target_sparc
<size
, big_endian
>(); }
3262 Target_selector_sparc
<32, true> target_selector_sparc32
;
3263 Target_selector_sparc
<64, true> target_selector_sparc64
;
3265 } // End anonymous namespace.