1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008 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"
49 template<int size
, bool big_endian
>
50 class Output_data_plt_sparc
;
52 template<int size
, bool big_endian
>
53 class Target_sparc
: public Sized_target
<size
, big_endian
>
56 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
59 : Sized_target
<size
, big_endian
>(&sparc_info
),
60 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
),
61 copy_relocs_(elfcpp::R_SPARC_COPY
), dynbss_(NULL
),
62 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL
)
66 // Scan the relocations to look for symbol adjustments.
68 scan_relocs(const General_options
& options
,
71 Sized_relobj
<size
, big_endian
>* object
,
72 unsigned int data_shndx
,
74 const unsigned char* prelocs
,
76 Output_section
* output_section
,
77 bool needs_special_offset_handling
,
78 size_t local_symbol_count
,
79 const unsigned char* plocal_symbols
);
80 // Finalize the sections.
82 do_finalize_sections(Layout
*);
84 // Return the value to use for a dynamic which requires special
87 do_dynsym_value(const Symbol
*) const;
89 // Relocate a section.
91 relocate_section(const Relocate_info
<size
, big_endian
>*,
93 const unsigned char* prelocs
,
95 Output_section
* output_section
,
96 bool needs_special_offset_handling
,
98 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
99 section_size_type view_size
);
101 // Scan the relocs during a relocatable link.
103 scan_relocatable_relocs(const General_options
& options
,
104 Symbol_table
* symtab
,
106 Sized_relobj
<size
, big_endian
>* object
,
107 unsigned int data_shndx
,
108 unsigned int sh_type
,
109 const unsigned char* prelocs
,
111 Output_section
* output_section
,
112 bool needs_special_offset_handling
,
113 size_t local_symbol_count
,
114 const unsigned char* plocal_symbols
,
115 Relocatable_relocs
*);
117 // Relocate a section during a relocatable link.
119 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
120 unsigned int sh_type
,
121 const unsigned char* prelocs
,
123 Output_section
* output_section
,
124 off_t offset_in_output_section
,
125 const Relocatable_relocs
*,
127 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
128 section_size_type view_size
,
129 unsigned char* reloc_view
,
130 section_size_type reloc_view_size
);
131 // Return whether SYM is defined by the ABI.
133 do_is_defined_by_abi(Symbol
* sym
) const
135 // XXX Really need to support this better...
136 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
139 return strcmp(sym
->name(), "___tls_get_addr") == 0;
142 // Return the size of the GOT section.
146 gold_assert(this->got_
!= NULL
);
147 return this->got_
->data_size();
152 // The class which scans relocations.
157 : issued_non_pic_error_(false)
161 local(const General_options
& options
, Symbol_table
* symtab
,
162 Layout
* layout
, Target_sparc
* target
,
163 Sized_relobj
<size
, big_endian
>* object
,
164 unsigned int data_shndx
,
165 Output_section
* output_section
,
166 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
167 const elfcpp::Sym
<size
, big_endian
>& lsym
);
170 global(const General_options
& options
, Symbol_table
* symtab
,
171 Layout
* layout
, Target_sparc
* target
,
172 Sized_relobj
<size
, big_endian
>* object
,
173 unsigned int data_shndx
,
174 Output_section
* output_section
,
175 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
180 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
181 unsigned int r_type
);
184 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
185 unsigned int r_type
, Symbol
*);
188 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
189 Target_sparc
* target
);
192 check_non_pic(Relobj
*, unsigned int r_type
);
194 // Whether we have issued an error about a non-PIC compilation.
195 bool issued_non_pic_error_
;
198 // The class which implements relocation.
203 : ignore_gd_add_(false)
208 if (this->ignore_gd_add_
)
210 // FIXME: This needs to specify the location somehow.
211 gold_error(_("missing expected TLS relocation"));
215 // Do a relocation. Return false if the caller should not issue
216 // any warnings about this relocation.
218 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
219 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
220 unsigned int r_type
, const Sized_symbol
<size
>*,
221 const Symbol_value
<size
>*,
223 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
227 // Do a TLS relocation.
229 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
230 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
231 unsigned int r_type
, const Sized_symbol
<size
>*,
232 const Symbol_value
<size
>*,
234 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
237 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
241 // A class which returns the size required for a relocation type,
242 // used while scanning relocs during a relocatable link.
243 class Relocatable_size_for_reloc
247 get_size_for_reloc(unsigned int, Relobj
*);
250 // Get the GOT section, creating it if necessary.
251 Output_data_got
<size
, big_endian
>*
252 got_section(Symbol_table
*, Layout
*);
254 // Create a PLT entry for a global symbol.
256 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
258 // Create a GOT entry for the TLS module index.
260 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
261 Sized_relobj
<size
, big_endian
>* object
);
263 // Return the gsym for "__tls_get_addr". Cache if not already
266 tls_get_addr_sym(Symbol_table
* symtab
)
268 if (!this->tls_get_addr_sym_
)
269 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
270 gold_assert(this->tls_get_addr_sym_
);
271 return this->tls_get_addr_sym_
;
274 // Get the PLT section.
275 const Output_data_plt_sparc
<size
, big_endian
>*
278 gold_assert(this->plt_
!= NULL
);
282 // Get the dynamic reloc section, creating it if necessary.
284 rela_dyn_section(Layout
*);
286 // Return true if the symbol may need a COPY relocation.
287 // References from an executable object to non-function symbols
288 // defined in a dynamic object may need a COPY relocation.
290 may_need_copy_reloc(Symbol
* gsym
)
292 return (!parameters
->options().shared()
293 && gsym
->is_from_dynobj()
294 && gsym
->type() != elfcpp::STT_FUNC
);
297 // Copy a relocation against a global symbol.
299 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
300 Sized_relobj
<size
, big_endian
>* object
,
301 unsigned int shndx
, Output_section
* output_section
,
302 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
304 this->copy_relocs_
.copy_reloc(symtab
, layout
,
305 symtab
->get_sized_symbol
<size
>(sym
),
306 object
, shndx
, output_section
,
307 reloc
, this->rela_dyn_section(layout
));
310 // Information about this specific target which we pass to the
311 // general Target structure.
312 static Target::Target_info sparc_info
;
314 // The types of GOT entries needed for this platform.
317 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
318 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
319 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
323 Output_data_got
<size
, big_endian
>* got_
;
325 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
326 // The dynamic reloc section.
327 Reloc_section
* rela_dyn_
;
328 // Relocs saved to avoid a COPY reloc.
329 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
330 // Space for variables copied with a COPY reloc.
331 Output_data_space
* dynbss_
;
332 // Offset of the GOT entry for the TLS module index;
333 unsigned int got_mod_index_offset_
;
334 // Cached pointer to __tls_get_addr symbol
335 Symbol
* tls_get_addr_sym_
;
339 Target::Target_info Target_sparc
<32, true>::sparc_info
=
342 true, // is_big_endian
343 elfcpp::EM_SPARC
, // machine_code
344 false, // has_make_symbol
345 false, // has_resolve
346 false, // has_code_fill
347 true, // is_default_stack_executable
349 "/usr/lib/ld.so.1", // dynamic_linker
350 0x00010000, // default_text_segment_address
351 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
352 8 * 1024 // common_pagesize (overridable by -z common-page-size)
356 Target::Target_info Target_sparc
<64, true>::sparc_info
=
359 true, // is_big_endian
360 elfcpp::EM_SPARCV9
, // machine_code
361 false, // has_make_symbol
362 false, // has_resolve
363 false, // has_code_fill
364 true, // is_default_stack_executable
366 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
367 0x100000, // default_text_segment_address
368 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
369 8 * 1024 // common_pagesize (overridable by -z common-page-size)
372 // We have to take care here, even when operating in little-endian
373 // mode, sparc instructions are still big endian.
374 template<int size
, bool big_endian
>
375 class Sparc_relocate_functions
378 // Do a simple relocation with the addend in the relocation.
379 template<int valsize
>
381 rela(unsigned char* view
,
382 unsigned int right_shift
,
383 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
384 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
385 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
387 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
388 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
389 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
390 Valtype reloc
= ((value
+ addend
) >> right_shift
);
395 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
398 // Do a simple relocation using a symbol value with the addend in
400 template<int valsize
>
402 rela(unsigned char* view
,
403 unsigned int right_shift
,
404 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
405 const Sized_relobj
<size
, big_endian
>* object
,
406 const Symbol_value
<size
>* psymval
,
407 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
409 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
410 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
411 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
412 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
417 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
420 // Do a simple relocation using a symbol value with the addend in
421 // the relocation, unaligned.
422 template<int valsize
>
424 rela_ua(unsigned char* view
,
425 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
426 const Sized_relobj
<size
, big_endian
>* object
,
427 const Symbol_value
<size
>* psymval
,
428 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
430 typedef typename
elfcpp::Swap_unaligned
<valsize
,
431 big_endian
>::Valtype Valtype
;
432 unsigned char* wv
= view
;
433 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
434 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
439 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
442 // Do a simple PC relative relocation with a Symbol_value with the
443 // addend in the relocation.
444 template<int valsize
>
446 pcrela(unsigned char* view
,
447 unsigned int right_shift
,
448 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
449 const Sized_relobj
<size
, big_endian
>* object
,
450 const Symbol_value
<size
>* psymval
,
451 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
452 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
454 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
455 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
456 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
457 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
463 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
466 template<int valsize
>
468 pcrela_unaligned(unsigned char* view
,
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_unaligned
<valsize
,
475 big_endian
>::Valtype Valtype
;
476 unsigned char* wv
= view
;
477 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
479 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
482 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
483 typedef Sparc_relocate_functions
<size
, true> This_insn
;
486 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
488 wdisp30(unsigned char* view
,
489 const Sized_relobj
<size
, big_endian
>* object
,
490 const Symbol_value
<size
>* psymval
,
491 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
492 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
494 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
495 psymval
, addend
, address
);
498 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
500 wdisp22(unsigned char* view
,
501 const Sized_relobj
<size
, big_endian
>* object
,
502 const Symbol_value
<size
>* psymval
,
503 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
504 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
506 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
507 psymval
, addend
, address
);
510 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
512 wdisp19(unsigned char* view
,
513 const Sized_relobj
<size
, big_endian
>* object
,
514 const Symbol_value
<size
>* psymval
,
515 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
516 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
518 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
519 psymval
, addend
, address
);
522 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
524 wdisp16(unsigned char* view
,
525 const Sized_relobj
<size
, big_endian
>* object
,
526 const Symbol_value
<size
>* psymval
,
527 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
528 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
530 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
531 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
532 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
533 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
536 // The relocation value is split between the low 14 bits,
538 val
&= ~((0x3 << 20) | 0x3fff);
539 reloc
= (((reloc
& 0xc000) << (20 - 14))
540 | (reloc
& 0x3ffff));
542 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
545 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
547 pc22(unsigned char* view
,
548 const Sized_relobj
<size
, big_endian
>* object
,
549 const Symbol_value
<size
>* psymval
,
550 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
551 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
553 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
554 psymval
, addend
, address
);
557 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
559 pc10(unsigned char* view
,
560 const Sized_relobj
<size
, big_endian
>* object
,
561 const Symbol_value
<size
>* psymval
,
562 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
563 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
565 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
566 psymval
, addend
, address
);
569 // R_SPARC_HI22: (Symbol + Addend) >> 10
571 hi22(unsigned char* view
,
572 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
573 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
575 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
578 // R_SPARC_HI22: (Symbol + Addend) >> 10
580 hi22(unsigned char* view
,
581 const Sized_relobj
<size
, big_endian
>* object
,
582 const Symbol_value
<size
>* psymval
,
583 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
585 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
588 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
590 pcplt22(unsigned char* view
,
591 const Sized_relobj
<size
, big_endian
>* object
,
592 const Symbol_value
<size
>* psymval
,
593 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
594 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
596 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
597 psymval
, addend
, address
);
600 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
602 lo10(unsigned char* view
,
603 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
604 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
606 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
609 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
611 lo10(unsigned char* view
,
612 const Sized_relobj
<size
, big_endian
>* object
,
613 const Symbol_value
<size
>* psymval
,
614 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
616 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
619 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
621 lo10(unsigned char* view
,
622 const Sized_relobj
<size
, big_endian
>* object
,
623 const Symbol_value
<size
>* psymval
,
624 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
625 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
627 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
628 psymval
, addend
, address
);
631 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
633 olo10(unsigned char* view
,
634 const Sized_relobj
<size
, big_endian
>* object
,
635 const Symbol_value
<size
>* psymval
,
636 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
637 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
639 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
640 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
641 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
642 Valtype reloc
= psymval
->value(object
, addend
);
649 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
652 // R_SPARC_22: (Symbol + Addend)
654 rela32_22(unsigned char* view
,
655 const Sized_relobj
<size
, big_endian
>* object
,
656 const Symbol_value
<size
>* psymval
,
657 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
659 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
662 // R_SPARC_13: (Symbol + Addend)
664 rela32_13(unsigned char* view
,
665 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
666 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
668 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
671 // R_SPARC_13: (Symbol + Addend)
673 rela32_13(unsigned char* view
,
674 const Sized_relobj
<size
, big_endian
>* object
,
675 const Symbol_value
<size
>* psymval
,
676 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
678 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
681 // R_SPARC_UA16: (Symbol + Addend)
683 ua16(unsigned char* view
,
684 const Sized_relobj
<size
, big_endian
>* object
,
685 const Symbol_value
<size
>* psymval
,
686 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
688 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
691 // R_SPARC_UA32: (Symbol + Addend)
693 ua32(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::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
701 // R_SPARC_UA64: (Symbol + Addend)
703 ua64(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
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
709 object
, psymval
, addend
);
712 // R_SPARC_DISP8: (Symbol + Addend - Address)
714 disp8(unsigned char* view
,
715 const Sized_relobj
<size
, big_endian
>* object
,
716 const Symbol_value
<size
>* psymval
,
717 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
718 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
720 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
724 // R_SPARC_DISP16: (Symbol + Addend - Address)
726 disp16(unsigned char* view
,
727 const Sized_relobj
<size
, big_endian
>* object
,
728 const Symbol_value
<size
>* psymval
,
729 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
730 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
732 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
736 // R_SPARC_DISP32: (Symbol + Addend - Address)
738 disp32(unsigned char* view
,
739 const Sized_relobj
<size
, big_endian
>* object
,
740 const Symbol_value
<size
>* psymval
,
741 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
742 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
744 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
748 // R_SPARC_DISP64: (Symbol + Addend - Address)
750 disp64(unsigned char* view
,
751 const Sized_relobj
<size
, big_endian
>* object
,
752 const Symbol_value
<size
>* psymval
,
753 elfcpp::Elf_Xword addend
,
754 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
756 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
760 // R_SPARC_H44: (Symbol + Addend) >> 22
762 h44(unsigned char* view
,
763 const Sized_relobj
<size
, big_endian
>* object
,
764 const Symbol_value
<size
>* psymval
,
765 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
767 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
770 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
772 m44(unsigned char* view
,
773 const Sized_relobj
<size
, big_endian
>* object
,
774 const Symbol_value
<size
>* psymval
,
775 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
777 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
780 // R_SPARC_L44: (Symbol + Addend) & 0xfff
782 l44(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
, 0, 0x00000fff, object
, psymval
, addend
);
790 // R_SPARC_HH22: (Symbol + Addend) >> 42
792 hh22(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
, 42, 0x003fffff, object
, psymval
, addend
);
800 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
802 pc_hh22(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
,
806 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
808 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
809 psymval
, addend
, address
);
812 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
814 hm10(unsigned char* view
,
815 const Sized_relobj
<size
, big_endian
>* object
,
816 const Symbol_value
<size
>* psymval
,
817 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
819 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
822 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
824 pc_hm10(unsigned char* view
,
825 const Sized_relobj
<size
, big_endian
>* object
,
826 const Symbol_value
<size
>* psymval
,
827 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
828 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
830 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
831 psymval
, addend
, address
);
834 // R_SPARC_11: (Symbol + Addend)
836 rela32_11(unsigned char* view
,
837 const Sized_relobj
<size
, big_endian
>* object
,
838 const Symbol_value
<size
>* psymval
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
841 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
844 // R_SPARC_10: (Symbol + Addend)
846 rela32_10(unsigned char* view
,
847 const Sized_relobj
<size
, big_endian
>* object
,
848 const Symbol_value
<size
>* psymval
,
849 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
851 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
854 // R_SPARC_7: (Symbol + Addend)
856 rela32_7(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, 0x0000007f, object
, psymval
, addend
);
864 // R_SPARC_6: (Symbol + Addend)
866 rela32_6(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, 0x0000003f, object
, psymval
, addend
);
874 // R_SPARC_5: (Symbol + Addend)
876 rela32_5(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, 0x0000001f, object
, psymval
, addend
);
884 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
886 ldo_hix22(unsigned char* view
,
887 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
888 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
890 This_insn::hi22(view
, value
, addend
);
893 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
895 ldo_lox10(unsigned char* view
,
896 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
897 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
899 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
900 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
901 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
902 Valtype reloc
= (value
+ addend
);
907 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
910 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
912 hix22(unsigned char* view
,
913 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
914 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
916 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
917 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
918 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
919 Valtype reloc
= (value
+ addend
);
923 reloc
^= ~(Valtype
)0;
928 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
931 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
933 hix22(unsigned char* view
,
934 const Sized_relobj
<size
, big_endian
>* object
,
935 const Symbol_value
<size
>* psymval
,
936 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
938 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
939 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
940 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
941 Valtype reloc
= psymval
->value(object
, addend
);
945 reloc
^= ~(Valtype
)0;
950 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
954 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
956 lox10(unsigned char* view
,
957 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
958 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
960 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
961 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
962 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
963 Valtype reloc
= (value
+ addend
);
969 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
972 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
974 lox10(unsigned char* view
,
975 const Sized_relobj
<size
, big_endian
>* object
,
976 const Symbol_value
<size
>* psymval
,
977 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
979 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
980 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
981 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
982 Valtype reloc
= psymval
->value(object
, addend
);
988 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
992 // Get the GOT section, creating it if necessary.
994 template<int size
, bool big_endian
>
995 Output_data_got
<size
, big_endian
>*
996 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
999 if (this->got_
== NULL
)
1001 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1003 this->got_
= new Output_data_got
<size
, big_endian
>();
1006 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1008 | elfcpp::SHF_WRITE
),
1012 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1013 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1015 0, 0, elfcpp::STT_OBJECT
,
1017 elfcpp::STV_HIDDEN
, 0,
1024 // Get the dynamic reloc section, creating it if necessary.
1026 template<int size
, bool big_endian
>
1027 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1028 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1030 if (this->rela_dyn_
== NULL
)
1032 gold_assert(layout
!= NULL
);
1033 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1034 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1035 elfcpp::SHF_ALLOC
, this->rela_dyn_
);
1037 return this->rela_dyn_
;
1040 // A class to handle the PLT data.
1042 template<int size
, bool big_endian
>
1043 class Output_data_plt_sparc
: public Output_section_data
1046 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1047 size
, big_endian
> Reloc_section
;
1049 Output_data_plt_sparc(Layout
*);
1051 // Add an entry to the PLT.
1052 void add_entry(Symbol
* gsym
);
1054 // Return the .rela.plt section data.
1055 const Reloc_section
* rel_plt() const
1061 void do_adjust_output_section(Output_section
* os
);
1063 // Write to a map file.
1065 do_print_to_mapfile(Mapfile
* mapfile
) const
1066 { mapfile
->print_output_data(this, _("** PLT")); }
1069 // The size of an entry in the PLT.
1070 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1072 static const unsigned int plt_entries_per_block
= 160;
1073 static const unsigned int plt_insn_chunk_size
= 24;
1074 static const unsigned int plt_pointer_chunk_size
= 8;
1075 static const unsigned int plt_block_size
=
1076 (plt_entries_per_block
1077 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1079 // Set the final size.
1081 set_final_data_size()
1083 unsigned int full_count
= this->count_
+ 4;
1084 unsigned int extra
= (size
== 32 ? 4 : 0);
1086 if (size
== 32 || full_count
< 32768)
1087 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1090 unsigned int ext_cnt
= full_count
- 32768;
1092 this->set_data_size((32768 * base_plt_entry_size
)
1094 * (plt_insn_chunk_size
1095 + plt_pointer_chunk_size
)));
1099 // Write out the PLT data.
1101 do_write(Output_file
*);
1103 // The reloc section.
1104 Reloc_section
* rel_
;
1105 // The number of PLT entries.
1106 unsigned int count_
;
1109 // Define the constants as required by C++ standard.
1111 template<int size
, bool big_endian
>
1112 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1114 template<int size
, bool big_endian
>
1116 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1118 template<int size
, bool big_endian
>
1119 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1121 template<int size
, bool big_endian
>
1123 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1125 template<int size
, bool big_endian
>
1126 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1128 // Create the PLT section. The ordinary .got section is an argument,
1129 // since we need to refer to the start.
1131 template<int size
, bool big_endian
>
1132 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1133 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1135 this->rel_
= new Reloc_section(false);
1136 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1137 elfcpp::SHF_ALLOC
, this->rel_
);
1140 template<int size
, bool big_endian
>
1142 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1147 // Add an entry to the PLT.
1149 template<int size
, bool big_endian
>
1151 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1153 gold_assert(!gsym
->has_plt_offset());
1155 unsigned int index
= this->count_
+ 4;
1156 section_offset_type plt_offset
;
1158 if (size
== 32 || index
< 32768)
1159 plt_offset
= index
* base_plt_entry_size
;
1162 unsigned int ext_index
= index
- 32768;
1164 plt_offset
= (32768 * base_plt_entry_size
)
1165 + ((ext_index
/ plt_entries_per_block
)
1167 + ((ext_index
% plt_entries_per_block
)
1168 * plt_insn_chunk_size
);
1171 gsym
->set_plt_offset(plt_offset
);
1175 // Every PLT entry needs a reloc.
1176 gsym
->set_needs_dynsym_entry();
1177 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1180 // Note that we don't need to save the symbol. The contents of the
1181 // PLT are independent of which symbols are used. The symbols only
1182 // appear in the relocations.
1185 static const unsigned int sparc_nop
= 0x01000000;
1186 static const unsigned int sparc_sethi_g1
= 0x03000000;
1187 static const unsigned int sparc_branch_always
= 0x30800000;
1188 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1189 static const unsigned int sparc_mov
= 0x80100000;
1190 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1191 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1192 static const unsigned int sparc_call_plus_8
= 0x40000002;
1193 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1194 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1195 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1197 // Write out the PLT.
1199 template<int size
, bool big_endian
>
1201 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1203 const off_t offset
= this->offset();
1204 const section_size_type oview_size
=
1205 convert_to_section_size_type(this->data_size());
1206 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1207 unsigned char* pov
= oview
;
1209 memset(pov
, 0, base_plt_entry_size
* 4);
1210 pov
+= base_plt_entry_size
* 4;
1212 unsigned int plt_offset
= base_plt_entry_size
* 4;
1213 const unsigned int count
= this->count_
;
1219 limit
= (count
> 32768 ? 32768 : count
);
1221 for (unsigned int i
= 0; i
< limit
; ++i
)
1223 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1224 sparc_sethi_g1
+ plt_offset
);
1225 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1226 sparc_branch_always_pt
+
1227 (((base_plt_entry_size
-
1228 (plt_offset
+ 4)) >> 2) &
1230 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1231 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1232 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1233 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1234 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1235 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1237 pov
+= base_plt_entry_size
;
1238 plt_offset
+= base_plt_entry_size
;
1243 unsigned int ext_cnt
= count
- 32768;
1244 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1246 for (unsigned int i
= 0; i
< blks
; ++i
)
1248 unsigned int data_off
= (plt_entries_per_block
1249 * plt_insn_chunk_size
) - 4;
1251 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1253 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1255 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1257 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1259 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1260 sparc_ldx_o7_imm_g1
+
1261 (data_off
& 0x1fff));
1262 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1263 sparc_jmpl_o7_g1_g1
);
1264 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1267 elfcpp::Swap
<64, big_endian
>::writeval(
1268 pov
+ 0x4 + data_off
,
1269 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1271 pov
+= plt_insn_chunk_size
;
1276 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1277 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1279 unsigned int data_off
= (sub_blk_cnt
1280 * plt_insn_chunk_size
) - 4;
1282 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1284 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1286 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1288 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1290 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1291 sparc_ldx_o7_imm_g1
+
1292 (data_off
& 0x1fff));
1293 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1294 sparc_jmpl_o7_g1_g1
);
1295 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1298 elfcpp::Swap
<64, big_endian
>::writeval(
1299 pov
+ 0x4 + data_off
,
1300 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1302 pov
+= plt_insn_chunk_size
;
1310 for (unsigned int i
= 0; i
< count
; ++i
)
1312 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1313 sparc_sethi_g1
+ plt_offset
);
1314 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1315 sparc_branch_always
+
1316 (((- (plt_offset
+ 4)) >> 2) &
1318 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1320 pov
+= base_plt_entry_size
;
1321 plt_offset
+= base_plt_entry_size
;
1324 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1328 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1330 of
->write_output_view(offset
, oview_size
, oview
);
1333 // Create a PLT entry for a global symbol.
1335 template<int size
, bool big_endian
>
1337 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1341 if (gsym
->has_plt_offset())
1344 if (this->plt_
== NULL
)
1346 // Create the GOT sections first.
1347 this->got_section(symtab
, layout
);
1349 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1350 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1352 | elfcpp::SHF_EXECINSTR
1353 | elfcpp::SHF_WRITE
),
1356 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1357 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1359 0, 0, elfcpp::STT_OBJECT
,
1361 elfcpp::STV_HIDDEN
, 0,
1365 this->plt_
->add_entry(gsym
);
1368 // Create a GOT entry for the TLS module index.
1370 template<int size
, bool big_endian
>
1372 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1374 Sized_relobj
<size
, big_endian
>* object
)
1376 if (this->got_mod_index_offset_
== -1U)
1378 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1379 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1380 Output_data_got
<size
, big_endian
>* got
;
1381 unsigned int got_offset
;
1383 got
= this->got_section(symtab
, layout
);
1384 got_offset
= got
->add_constant(0);
1385 rela_dyn
->add_local(object
, 0,
1387 elfcpp::R_SPARC_TLS_DTPMOD64
:
1388 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1390 got
->add_constant(0);
1391 this->got_mod_index_offset_
= got_offset
;
1393 return this->got_mod_index_offset_
;
1396 // Optimize the TLS relocation type based on what we know about the
1397 // symbol. IS_FINAL is true if the final address of this symbol is
1398 // known at link time.
1400 static tls::Tls_optimization
1401 optimize_tls_reloc(bool is_final
, int r_type
)
1403 // If we are generating a shared library, then we can't do anything
1405 if (parameters
->options().shared())
1406 return tls::TLSOPT_NONE
;
1410 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1411 case elfcpp::R_SPARC_TLS_GD_LO10
:
1412 case elfcpp::R_SPARC_TLS_GD_ADD
:
1413 case elfcpp::R_SPARC_TLS_GD_CALL
:
1414 // These are General-Dynamic which permits fully general TLS
1415 // access. Since we know that we are generating an executable,
1416 // we can convert this to Initial-Exec. If we also know that
1417 // this is a local symbol, we can further switch to Local-Exec.
1419 return tls::TLSOPT_TO_LE
;
1420 return tls::TLSOPT_TO_IE
;
1422 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1423 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1424 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1425 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1426 // This is Local-Dynamic, which refers to a local symbol in the
1427 // dynamic TLS block. Since we know that we generating an
1428 // executable, we can switch to Local-Exec.
1429 return tls::TLSOPT_TO_LE
;
1431 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1432 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1433 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1434 // Another type of Local-Dynamic relocation.
1435 return tls::TLSOPT_TO_LE
;
1437 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1438 case elfcpp::R_SPARC_TLS_IE_LO10
:
1439 case elfcpp::R_SPARC_TLS_IE_LD
:
1440 case elfcpp::R_SPARC_TLS_IE_LDX
:
1441 // These are Initial-Exec relocs which get the thread offset
1442 // from the GOT. If we know that we are linking against the
1443 // local symbol, we can switch to Local-Exec, which links the
1444 // thread offset into the instruction.
1446 return tls::TLSOPT_TO_LE
;
1447 return tls::TLSOPT_NONE
;
1449 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1450 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1451 // When we already have Local-Exec, there is nothing further we
1453 return tls::TLSOPT_NONE
;
1460 // Generate a PLT entry slot for a call to __tls_get_addr
1461 template<int size
, bool big_endian
>
1463 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1465 Target_sparc
<size
, big_endian
>* target
)
1467 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1469 target
->make_plt_entry(symtab
, layout
, gsym
);
1472 // Report an unsupported relocation against a local symbol.
1474 template<int size
, bool big_endian
>
1476 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1477 Sized_relobj
<size
, big_endian
>* object
,
1478 unsigned int r_type
)
1480 gold_error(_("%s: unsupported reloc %u against local symbol"),
1481 object
->name().c_str(), r_type
);
1484 // We are about to emit a dynamic relocation of type R_TYPE. If the
1485 // dynamic linker does not support it, issue an error.
1487 template<int size
, bool big_endian
>
1489 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1491 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1497 // These are the relocation types supported by glibc for sparc 64-bit.
1498 case elfcpp::R_SPARC_RELATIVE
:
1499 case elfcpp::R_SPARC_COPY
:
1500 case elfcpp::R_SPARC_64
:
1501 case elfcpp::R_SPARC_GLOB_DAT
:
1502 case elfcpp::R_SPARC_JMP_SLOT
:
1503 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1504 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1505 case elfcpp::R_SPARC_TLS_TPOFF64
:
1506 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1507 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1508 case elfcpp::R_SPARC_8
:
1509 case elfcpp::R_SPARC_16
:
1510 case elfcpp::R_SPARC_DISP8
:
1511 case elfcpp::R_SPARC_DISP16
:
1512 case elfcpp::R_SPARC_DISP32
:
1513 case elfcpp::R_SPARC_WDISP30
:
1514 case elfcpp::R_SPARC_LO10
:
1515 case elfcpp::R_SPARC_HI22
:
1516 case elfcpp::R_SPARC_OLO10
:
1517 case elfcpp::R_SPARC_H44
:
1518 case elfcpp::R_SPARC_M44
:
1519 case elfcpp::R_SPARC_L44
:
1520 case elfcpp::R_SPARC_HH22
:
1521 case elfcpp::R_SPARC_HM10
:
1522 case elfcpp::R_SPARC_LM22
:
1523 case elfcpp::R_SPARC_UA16
:
1524 case elfcpp::R_SPARC_UA32
:
1525 case elfcpp::R_SPARC_UA64
:
1536 // These are the relocation types supported by glibc for sparc 32-bit.
1537 case elfcpp::R_SPARC_RELATIVE
:
1538 case elfcpp::R_SPARC_COPY
:
1539 case elfcpp::R_SPARC_GLOB_DAT
:
1540 case elfcpp::R_SPARC_32
:
1541 case elfcpp::R_SPARC_JMP_SLOT
:
1542 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1543 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1544 case elfcpp::R_SPARC_TLS_TPOFF32
:
1545 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1546 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1547 case elfcpp::R_SPARC_8
:
1548 case elfcpp::R_SPARC_16
:
1549 case elfcpp::R_SPARC_DISP8
:
1550 case elfcpp::R_SPARC_DISP16
:
1551 case elfcpp::R_SPARC_DISP32
:
1552 case elfcpp::R_SPARC_LO10
:
1553 case elfcpp::R_SPARC_WDISP30
:
1554 case elfcpp::R_SPARC_HI22
:
1555 case elfcpp::R_SPARC_UA16
:
1556 case elfcpp::R_SPARC_UA32
:
1564 // This prevents us from issuing more than one error per reloc
1565 // section. But we can still wind up issuing more than one
1566 // error per object file.
1567 if (this->issued_non_pic_error_
)
1569 object
->error(_("requires unsupported dynamic reloc; "
1570 "recompile with -fPIC"));
1571 this->issued_non_pic_error_
= true;
1575 // Scan a relocation for a local symbol.
1577 template<int size
, bool big_endian
>
1579 Target_sparc
<size
, big_endian
>::Scan::local(
1580 const General_options
&,
1581 Symbol_table
* symtab
,
1583 Target_sparc
<size
, big_endian
>* target
,
1584 Sized_relobj
<size
, big_endian
>* object
,
1585 unsigned int data_shndx
,
1586 Output_section
* output_section
,
1587 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1588 unsigned int r_type
,
1589 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1591 unsigned int orig_r_type
= r_type
;
1596 case elfcpp::R_SPARC_NONE
:
1597 case elfcpp::R_SPARC_REGISTER
:
1598 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1599 case elfcpp::R_SPARC_GNU_VTENTRY
:
1602 case elfcpp::R_SPARC_64
:
1603 case elfcpp::R_SPARC_32
:
1604 // If building a shared library (or a position-independent
1605 // executable), we need to create a dynamic relocation for
1606 // this location. The relocation applied at link time will
1607 // apply the link-time value, so we flag the location with
1608 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1609 // relocate it easily.
1610 if (parameters
->options().output_is_position_independent())
1612 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1613 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1614 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1615 output_section
, data_shndx
,
1616 reloc
.get_r_offset(),
1617 reloc
.get_r_addend());
1621 case elfcpp::R_SPARC_HIX22
:
1622 case elfcpp::R_SPARC_LOX10
:
1623 case elfcpp::R_SPARC_H44
:
1624 case elfcpp::R_SPARC_M44
:
1625 case elfcpp::R_SPARC_L44
:
1626 case elfcpp::R_SPARC_HH22
:
1627 case elfcpp::R_SPARC_HM10
:
1628 case elfcpp::R_SPARC_LM22
:
1629 case elfcpp::R_SPARC_UA64
:
1630 case elfcpp::R_SPARC_UA32
:
1631 case elfcpp::R_SPARC_UA16
:
1632 case elfcpp::R_SPARC_HI22
:
1633 case elfcpp::R_SPARC_LO10
:
1634 case elfcpp::R_SPARC_OLO10
:
1635 case elfcpp::R_SPARC_16
:
1636 case elfcpp::R_SPARC_11
:
1637 case elfcpp::R_SPARC_10
:
1638 case elfcpp::R_SPARC_8
:
1639 case elfcpp::R_SPARC_7
:
1640 case elfcpp::R_SPARC_6
:
1641 case elfcpp::R_SPARC_5
:
1642 // If building a shared library (or a position-independent
1643 // executable), we need to create a dynamic relocation for
1645 if (parameters
->options().output_is_position_independent())
1647 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1649 check_non_pic(object
, r_type
);
1650 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1652 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1653 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1654 data_shndx
, reloc
.get_r_offset(),
1655 reloc
.get_r_addend());
1659 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1660 gold_assert(lsym
.get_st_value() == 0);
1661 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1662 output_section
, data_shndx
,
1663 reloc
.get_r_offset(),
1664 reloc
.get_r_addend());
1669 case elfcpp::R_SPARC_WDISP30
:
1670 case elfcpp::R_SPARC_WDISP22
:
1671 case elfcpp::R_SPARC_WDISP19
:
1672 case elfcpp::R_SPARC_WDISP16
:
1673 case elfcpp::R_SPARC_DISP8
:
1674 case elfcpp::R_SPARC_DISP16
:
1675 case elfcpp::R_SPARC_DISP32
:
1676 case elfcpp::R_SPARC_DISP64
:
1677 case elfcpp::R_SPARC_PC10
:
1678 case elfcpp::R_SPARC_PC22
:
1681 case elfcpp::R_SPARC_GOT10
:
1682 case elfcpp::R_SPARC_GOT13
:
1683 case elfcpp::R_SPARC_GOT22
:
1685 // The symbol requires a GOT entry.
1686 Output_data_got
<size
, big_endian
>* got
;
1689 got
= target
->got_section(symtab
, layout
);
1690 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1692 // If we are generating a shared object, we need to add a
1693 // dynamic relocation for this symbol's GOT entry.
1694 if (parameters
->options().output_is_position_independent())
1696 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1698 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1701 off
= got
->add_constant(0);
1702 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1703 rela_dyn
->add_local_relative(object
, r_sym
,
1704 elfcpp::R_SPARC_RELATIVE
,
1709 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1713 // These are initial TLS relocs, which are expected when
1715 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1716 case elfcpp::R_SPARC_TLS_GD_LO10
:
1717 case elfcpp::R_SPARC_TLS_GD_ADD
:
1718 case elfcpp::R_SPARC_TLS_GD_CALL
:
1719 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1720 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1721 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1722 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1723 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1724 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1725 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1726 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1727 case elfcpp::R_SPARC_TLS_IE_LO10
:
1728 case elfcpp::R_SPARC_TLS_IE_LD
:
1729 case elfcpp::R_SPARC_TLS_IE_LDX
:
1730 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1731 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1733 bool output_is_shared
= parameters
->options().shared();
1734 const tls::Tls_optimization optimized_type
1735 = optimize_tls_reloc(!output_is_shared
, r_type
);
1738 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1739 case elfcpp::R_SPARC_TLS_GD_LO10
:
1740 case elfcpp::R_SPARC_TLS_GD_ADD
:
1741 case elfcpp::R_SPARC_TLS_GD_CALL
:
1742 if (optimized_type
== tls::TLSOPT_NONE
)
1744 // Create a pair of GOT entries for the module index and
1745 // dtv-relative offset.
1746 Output_data_got
<size
, big_endian
>* got
1747 = target
->got_section(symtab
, layout
);
1748 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1749 unsigned int shndx
= lsym
.get_st_shndx();
1751 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1753 object
->error(_("local symbol %u has bad shndx %u"),
1756 got
->add_local_pair_with_rela(object
, r_sym
,
1757 lsym
.get_st_shndx(),
1759 target
->rela_dyn_section(layout
),
1761 ? elfcpp::R_SPARC_TLS_DTPMOD64
1762 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1764 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1765 generate_tls_call(symtab
, layout
, target
);
1767 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1768 unsupported_reloc_local(object
, r_type
);
1771 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1772 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1773 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1774 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1775 if (optimized_type
== tls::TLSOPT_NONE
)
1777 // Create a GOT entry for the module index.
1778 target
->got_mod_index_entry(symtab
, layout
, object
);
1780 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1781 generate_tls_call(symtab
, layout
, target
);
1783 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1784 unsupported_reloc_local(object
, r_type
);
1787 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1788 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1789 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1792 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1793 case elfcpp::R_SPARC_TLS_IE_LO10
:
1794 case elfcpp::R_SPARC_TLS_IE_LD
:
1795 case elfcpp::R_SPARC_TLS_IE_LDX
:
1796 layout
->set_has_static_tls();
1797 if (optimized_type
== tls::TLSOPT_NONE
)
1799 // Create a GOT entry for the tp-relative offset.
1800 Output_data_got
<size
, big_endian
>* got
1801 = target
->got_section(symtab
, layout
);
1802 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1804 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1806 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1807 unsigned int off
= got
->add_constant(0);
1809 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1811 rela_dyn
->add_local_relative(object
, r_sym
,
1813 elfcpp::R_SPARC_TLS_TPOFF64
:
1814 elfcpp::R_SPARC_TLS_TPOFF32
),
1818 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1819 unsupported_reloc_local(object
, r_type
);
1822 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1823 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1824 layout
->set_has_static_tls();
1825 if (output_is_shared
)
1827 // We need to create a dynamic relocation.
1828 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1829 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1830 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1831 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1832 output_section
, data_shndx
,
1833 reloc
.get_r_offset(), 0);
1840 // These are relocations which should only be seen by the
1841 // dynamic linker, and should never be seen here.
1842 case elfcpp::R_SPARC_COPY
:
1843 case elfcpp::R_SPARC_GLOB_DAT
:
1844 case elfcpp::R_SPARC_JMP_SLOT
:
1845 case elfcpp::R_SPARC_RELATIVE
:
1846 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1847 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1848 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1849 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1850 case elfcpp::R_SPARC_TLS_TPOFF64
:
1851 case elfcpp::R_SPARC_TLS_TPOFF32
:
1852 gold_error(_("%s: unexpected reloc %u in object file"),
1853 object
->name().c_str(), r_type
);
1857 unsupported_reloc_local(object
, r_type
);
1862 // Report an unsupported relocation against a global symbol.
1864 template<int size
, bool big_endian
>
1866 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1867 Sized_relobj
<size
, big_endian
>* object
,
1868 unsigned int r_type
,
1871 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1872 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1875 // Scan a relocation for a global symbol.
1877 template<int size
, bool big_endian
>
1879 Target_sparc
<size
, big_endian
>::Scan::global(
1880 const General_options
&,
1881 Symbol_table
* symtab
,
1883 Target_sparc
<size
, big_endian
>* target
,
1884 Sized_relobj
<size
, big_endian
>* object
,
1885 unsigned int data_shndx
,
1886 Output_section
* output_section
,
1887 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1888 unsigned int r_type
,
1891 unsigned int orig_r_type
= r_type
;
1896 case elfcpp::R_SPARC_NONE
:
1897 case elfcpp::R_SPARC_REGISTER
:
1898 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1899 case elfcpp::R_SPARC_GNU_VTENTRY
:
1902 case elfcpp::R_SPARC_PLT64
:
1903 case elfcpp::R_SPARC_PLT32
:
1904 case elfcpp::R_SPARC_HIPLT22
:
1905 case elfcpp::R_SPARC_LOPLT10
:
1906 case elfcpp::R_SPARC_PCPLT32
:
1907 case elfcpp::R_SPARC_PCPLT22
:
1908 case elfcpp::R_SPARC_PCPLT10
:
1909 case elfcpp::R_SPARC_WPLT30
:
1910 // If the symbol is fully resolved, this is just a PC32 reloc.
1911 // Otherwise we need a PLT entry.
1912 if (gsym
->final_value_is_known())
1914 // If building a shared library, we can also skip the PLT entry
1915 // if the symbol is defined in the output file and is protected
1917 if (gsym
->is_defined()
1918 && !gsym
->is_from_dynobj()
1919 && !gsym
->is_preemptible())
1921 target
->make_plt_entry(symtab
, layout
, gsym
);
1924 case elfcpp::R_SPARC_DISP8
:
1925 case elfcpp::R_SPARC_DISP16
:
1926 case elfcpp::R_SPARC_DISP32
:
1927 case elfcpp::R_SPARC_DISP64
:
1928 case elfcpp::R_SPARC_PC_HH22
:
1929 case elfcpp::R_SPARC_PC_HM10
:
1930 case elfcpp::R_SPARC_PC_LM22
:
1931 case elfcpp::R_SPARC_PC10
:
1932 case elfcpp::R_SPARC_PC22
:
1933 case elfcpp::R_SPARC_WDISP30
:
1934 case elfcpp::R_SPARC_WDISP22
:
1935 case elfcpp::R_SPARC_WDISP19
:
1936 case elfcpp::R_SPARC_WDISP16
:
1938 if (gsym
->needs_plt_entry())
1939 target
->make_plt_entry(symtab
, layout
, gsym
);
1940 // Make a dynamic relocation if necessary.
1941 int flags
= Symbol::NON_PIC_REF
;
1942 if (gsym
->type() == elfcpp::STT_FUNC
)
1943 flags
|= Symbol::FUNCTION_CALL
;
1944 if (gsym
->needs_dynamic_reloc(flags
))
1946 if (target
->may_need_copy_reloc(gsym
))
1948 target
->copy_reloc(symtab
, layout
, object
,
1949 data_shndx
, output_section
, gsym
,
1954 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1955 check_non_pic(object
, r_type
);
1956 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1957 data_shndx
, reloc
.get_r_offset(),
1958 reloc
.get_r_addend());
1964 case elfcpp::R_SPARC_UA64
:
1965 case elfcpp::R_SPARC_64
:
1966 case elfcpp::R_SPARC_HIX22
:
1967 case elfcpp::R_SPARC_LOX10
:
1968 case elfcpp::R_SPARC_H44
:
1969 case elfcpp::R_SPARC_M44
:
1970 case elfcpp::R_SPARC_L44
:
1971 case elfcpp::R_SPARC_HH22
:
1972 case elfcpp::R_SPARC_HM10
:
1973 case elfcpp::R_SPARC_LM22
:
1974 case elfcpp::R_SPARC_HI22
:
1975 case elfcpp::R_SPARC_LO10
:
1976 case elfcpp::R_SPARC_OLO10
:
1977 case elfcpp::R_SPARC_UA32
:
1978 case elfcpp::R_SPARC_32
:
1979 case elfcpp::R_SPARC_UA16
:
1980 case elfcpp::R_SPARC_16
:
1981 case elfcpp::R_SPARC_11
:
1982 case elfcpp::R_SPARC_10
:
1983 case elfcpp::R_SPARC_8
:
1984 case elfcpp::R_SPARC_7
:
1985 case elfcpp::R_SPARC_6
:
1986 case elfcpp::R_SPARC_5
:
1988 // Make a PLT entry if necessary.
1989 if (gsym
->needs_plt_entry())
1991 target
->make_plt_entry(symtab
, layout
, gsym
);
1992 // Since this is not a PC-relative relocation, we may be
1993 // taking the address of a function. In that case we need to
1994 // set the entry in the dynamic symbol table to the address of
1996 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
1997 gsym
->set_needs_dynsym_value();
1999 // Make a dynamic relocation if necessary.
2000 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2002 if (target
->may_need_copy_reloc(gsym
))
2004 target
->copy_reloc(symtab
, layout
, object
,
2005 data_shndx
, output_section
, gsym
, reloc
);
2007 else if ((r_type
== elfcpp::R_SPARC_32
2008 || r_type
== elfcpp::R_SPARC_64
)
2009 && gsym
->can_use_relative_reloc(false))
2011 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2012 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2013 output_section
, object
,
2014 data_shndx
, reloc
.get_r_offset(),
2015 reloc
.get_r_addend());
2019 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2021 check_non_pic(object
, r_type
);
2022 if (gsym
->is_from_dynobj()
2023 || gsym
->is_undefined()
2024 || gsym
->is_preemptible())
2025 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2027 reloc
.get_r_offset(),
2028 reloc
.get_r_addend());
2030 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2031 output_section
, object
,
2033 reloc
.get_r_offset(),
2034 reloc
.get_r_addend());
2040 case elfcpp::R_SPARC_GOT10
:
2041 case elfcpp::R_SPARC_GOT13
:
2042 case elfcpp::R_SPARC_GOT22
:
2044 // The symbol requires a GOT entry.
2045 Output_data_got
<size
, big_endian
>* got
;
2047 got
= target
->got_section(symtab
, layout
);
2048 if (gsym
->final_value_is_known())
2049 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2052 // If this symbol is not fully resolved, we need to add a
2053 // dynamic relocation for it.
2054 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2055 if (gsym
->is_from_dynobj()
2056 || gsym
->is_undefined()
2057 || gsym
->is_preemptible())
2058 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2059 elfcpp::R_SPARC_GLOB_DAT
);
2060 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2062 unsigned int off
= got
->add_constant(0);
2064 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2065 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2072 // These are initial tls relocs, which are expected when
2074 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2075 case elfcpp::R_SPARC_TLS_GD_LO10
:
2076 case elfcpp::R_SPARC_TLS_GD_ADD
:
2077 case elfcpp::R_SPARC_TLS_GD_CALL
:
2078 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2079 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2080 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2081 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2082 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2083 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2084 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2085 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2086 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2087 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2088 case elfcpp::R_SPARC_TLS_IE_LO10
:
2089 case elfcpp::R_SPARC_TLS_IE_LD
:
2090 case elfcpp::R_SPARC_TLS_IE_LDX
:
2092 const bool is_final
= gsym
->final_value_is_known();
2093 const tls::Tls_optimization optimized_type
2094 = optimize_tls_reloc(is_final
, r_type
);
2097 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2098 case elfcpp::R_SPARC_TLS_GD_LO10
:
2099 case elfcpp::R_SPARC_TLS_GD_ADD
:
2100 case elfcpp::R_SPARC_TLS_GD_CALL
:
2101 if (optimized_type
== tls::TLSOPT_NONE
)
2103 // Create a pair of GOT entries for the module index and
2104 // dtv-relative offset.
2105 Output_data_got
<size
, big_endian
>* got
2106 = target
->got_section(symtab
, layout
);
2107 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2108 target
->rela_dyn_section(layout
),
2110 elfcpp::R_SPARC_TLS_DTPMOD64
:
2111 elfcpp::R_SPARC_TLS_DTPMOD32
),
2113 elfcpp::R_SPARC_TLS_DTPOFF64
:
2114 elfcpp::R_SPARC_TLS_DTPOFF32
));
2116 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2117 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2118 generate_tls_call(symtab
, layout
, target
);
2120 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2122 // Create a GOT entry for the tp-relative offset.
2123 Output_data_got
<size
, big_endian
>* got
2124 = target
->got_section(symtab
, layout
);
2125 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2126 target
->rela_dyn_section(layout
),
2128 elfcpp::R_SPARC_TLS_TPOFF64
:
2129 elfcpp::R_SPARC_TLS_TPOFF32
));
2131 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2132 unsupported_reloc_global(object
, r_type
, gsym
);
2135 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2136 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2137 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2138 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2139 if (optimized_type
== tls::TLSOPT_NONE
)
2141 // Create a GOT entry for the module index.
2142 target
->got_mod_index_entry(symtab
, layout
, object
);
2144 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2145 generate_tls_call(symtab
, layout
, target
);
2147 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2148 unsupported_reloc_global(object
, r_type
, gsym
);
2151 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2152 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2153 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2156 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2157 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2158 layout
->set_has_static_tls();
2159 if (parameters
->options().shared())
2161 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2162 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2163 output_section
, object
,
2164 data_shndx
, reloc
.get_r_offset(),
2169 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2170 case elfcpp::R_SPARC_TLS_IE_LO10
:
2171 case elfcpp::R_SPARC_TLS_IE_LD
:
2172 case elfcpp::R_SPARC_TLS_IE_LDX
:
2173 layout
->set_has_static_tls();
2174 if (optimized_type
== tls::TLSOPT_NONE
)
2176 // Create a GOT entry for the tp-relative offset.
2177 Output_data_got
<size
, big_endian
>* got
2178 = target
->got_section(symtab
, layout
);
2179 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2180 target
->rela_dyn_section(layout
),
2182 elfcpp::R_SPARC_TLS_TPOFF64
:
2183 elfcpp::R_SPARC_TLS_TPOFF32
));
2185 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2186 unsupported_reloc_global(object
, r_type
, gsym
);
2192 // These are relocations which should only be seen by the
2193 // dynamic linker, and should never be seen here.
2194 case elfcpp::R_SPARC_COPY
:
2195 case elfcpp::R_SPARC_GLOB_DAT
:
2196 case elfcpp::R_SPARC_JMP_SLOT
:
2197 case elfcpp::R_SPARC_RELATIVE
:
2198 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2199 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2200 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2201 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2202 case elfcpp::R_SPARC_TLS_TPOFF64
:
2203 case elfcpp::R_SPARC_TLS_TPOFF32
:
2204 gold_error(_("%s: unexpected reloc %u in object file"),
2205 object
->name().c_str(), r_type
);
2209 unsupported_reloc_global(object
, r_type
, gsym
);
2214 // Scan relocations for a section.
2216 template<int size
, bool big_endian
>
2218 Target_sparc
<size
, big_endian
>::scan_relocs(
2219 const General_options
& options
,
2220 Symbol_table
* symtab
,
2222 Sized_relobj
<size
, big_endian
>* object
,
2223 unsigned int data_shndx
,
2224 unsigned int sh_type
,
2225 const unsigned char* prelocs
,
2227 Output_section
* output_section
,
2228 bool needs_special_offset_handling
,
2229 size_t local_symbol_count
,
2230 const unsigned char* plocal_symbols
)
2232 typedef Target_sparc
<size
, big_endian
> Sparc
;
2233 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2235 if (sh_type
== elfcpp::SHT_REL
)
2237 gold_error(_("%s: unsupported REL reloc section"),
2238 object
->name().c_str());
2242 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2252 needs_special_offset_handling
,
2257 // Finalize the sections.
2259 template<int size
, bool big_endian
>
2261 Target_sparc
<size
, big_endian
>::do_finalize_sections(Layout
* layout
)
2263 // Fill in some more dynamic tags.
2264 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2267 if (this->plt_
!= NULL
)
2269 const Output_data
* od
= this->plt_
->rel_plt();
2270 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2271 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2272 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2274 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2277 if (this->rela_dyn_
!= NULL
)
2279 const Output_data
* od
= this->rela_dyn_
;
2280 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2281 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2282 odyn
->add_constant(elfcpp::DT_RELAENT
,
2283 elfcpp::Elf_sizes
<size
>::rela_size
);
2286 if (!parameters
->options().shared())
2288 // The value of the DT_DEBUG tag is filled in by the dynamic
2289 // linker at run time, and used by the debugger.
2290 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2294 // Emit any relocs we saved in an attempt to avoid generating COPY
2296 if (this->copy_relocs_
.any_saved_relocs())
2297 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2300 // Perform a relocation.
2302 template<int size
, bool big_endian
>
2304 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2305 const Relocate_info
<size
, big_endian
>* relinfo
,
2306 Target_sparc
* target
,
2308 const elfcpp::Rela
<size
, big_endian
>& rela
,
2309 unsigned int r_type
,
2310 const Sized_symbol
<size
>* gsym
,
2311 const Symbol_value
<size
>* psymval
,
2312 unsigned char* view
,
2313 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2314 section_size_type view_size
)
2318 if (this->ignore_gd_add_
)
2320 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2321 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2322 _("missing expected TLS relocation"));
2325 this->ignore_gd_add_
= false;
2330 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2332 // Pick the value to use for symbols defined in shared objects.
2333 Symbol_value
<size
> symval
;
2335 && (gsym
->is_from_dynobj()
2336 || (parameters
->options().shared()
2337 && (gsym
->is_undefined() || gsym
->is_preemptible())))
2338 && gsym
->has_plt_offset())
2340 elfcpp::Elf_Xword value
;
2342 value
= target
->plt_section()->address() + gsym
->plt_offset();
2344 symval
.set_output_value(value
);
2349 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2350 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2352 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2353 // pointer points to the beginning, not the end, of the table.
2354 // So we just use the plain offset.
2355 bool have_got_offset
= false;
2356 unsigned int got_offset
= 0;
2359 case elfcpp::R_SPARC_GOT10
:
2360 case elfcpp::R_SPARC_GOT13
:
2361 case elfcpp::R_SPARC_GOT22
:
2364 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2365 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2369 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2370 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2371 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2373 have_got_offset
= true;
2382 case elfcpp::R_SPARC_NONE
:
2383 case elfcpp::R_SPARC_REGISTER
:
2384 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2385 case elfcpp::R_SPARC_GNU_VTENTRY
:
2388 case elfcpp::R_SPARC_8
:
2389 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2393 case elfcpp::R_SPARC_16
:
2394 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2398 case elfcpp::R_SPARC_32
:
2399 if (!parameters
->options().output_is_position_independent())
2400 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2404 case elfcpp::R_SPARC_DISP8
:
2405 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2408 case elfcpp::R_SPARC_DISP16
:
2409 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2412 case elfcpp::R_SPARC_DISP32
:
2413 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2416 case elfcpp::R_SPARC_DISP64
:
2417 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2420 case elfcpp::R_SPARC_WDISP30
:
2421 case elfcpp::R_SPARC_WPLT30
:
2422 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2425 case elfcpp::R_SPARC_WDISP22
:
2426 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2429 case elfcpp::R_SPARC_WDISP19
:
2430 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2433 case elfcpp::R_SPARC_WDISP16
:
2434 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2437 case elfcpp::R_SPARC_HI22
:
2438 Reloc::hi22(view
, object
, psymval
, addend
);
2441 case elfcpp::R_SPARC_22
:
2442 Reloc::rela32_22(view
, object
, psymval
, addend
);
2445 case elfcpp::R_SPARC_13
:
2446 Reloc::rela32_13(view
, object
, psymval
, addend
);
2449 case elfcpp::R_SPARC_LO10
:
2450 Reloc::lo10(view
, object
, psymval
, addend
);
2453 case elfcpp::R_SPARC_GOT10
:
2454 Reloc::lo10(view
, got_offset
, addend
);
2457 case elfcpp::R_SPARC_GOT13
:
2458 Reloc::rela32_13(view
, got_offset
, addend
);
2461 case elfcpp::R_SPARC_GOT22
:
2462 Reloc::hi22(view
, got_offset
, addend
);
2465 case elfcpp::R_SPARC_PC10
:
2466 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2469 case elfcpp::R_SPARC_PC22
:
2470 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2473 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2474 case elfcpp::R_SPARC_UA32
:
2475 Reloc::ua32(view
, object
, psymval
, addend
);
2478 case elfcpp::R_SPARC_PLT64
:
2479 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2483 case elfcpp::R_SPARC_PLT32
:
2484 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2488 case elfcpp::R_SPARC_HIPLT22
:
2489 Reloc::hi22(view
, object
, psymval
, addend
);
2492 case elfcpp::R_SPARC_LOPLT10
:
2493 Reloc::lo10(view
, object
, psymval
, addend
);
2496 case elfcpp::R_SPARC_PCPLT32
:
2497 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2500 case elfcpp::R_SPARC_PCPLT22
:
2501 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2504 case elfcpp::R_SPARC_PCPLT10
:
2505 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2508 case elfcpp::R_SPARC_64
:
2509 if (!parameters
->options().output_is_position_independent())
2510 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2514 case elfcpp::R_SPARC_OLO10
:
2516 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2517 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2518 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2522 case elfcpp::R_SPARC_HH22
:
2523 Reloc::hh22(view
, object
, psymval
, addend
);
2526 case elfcpp::R_SPARC_PC_HH22
:
2527 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2530 case elfcpp::R_SPARC_HM10
:
2531 Reloc::hm10(view
, object
, psymval
, addend
);
2534 case elfcpp::R_SPARC_PC_HM10
:
2535 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2538 case elfcpp::R_SPARC_LM22
:
2539 Reloc::hi22(view
, object
, psymval
, addend
);
2542 case elfcpp::R_SPARC_PC_LM22
:
2543 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2546 case elfcpp::R_SPARC_11
:
2547 Reloc::rela32_11(view
, object
, psymval
, addend
);
2550 case elfcpp::R_SPARC_10
:
2551 Reloc::rela32_10(view
, object
, psymval
, addend
);
2554 case elfcpp::R_SPARC_7
:
2555 Reloc::rela32_7(view
, object
, psymval
, addend
);
2558 case elfcpp::R_SPARC_6
:
2559 Reloc::rela32_6(view
, object
, psymval
, addend
);
2562 case elfcpp::R_SPARC_5
:
2563 Reloc::rela32_5(view
, object
, psymval
, addend
);
2566 case elfcpp::R_SPARC_HIX22
:
2567 Reloc::hix22(view
, object
, psymval
, addend
);
2570 case elfcpp::R_SPARC_LOX10
:
2571 Reloc::lox10(view
, object
, psymval
, addend
);
2574 case elfcpp::R_SPARC_H44
:
2575 Reloc::h44(view
, object
, psymval
, addend
);
2578 case elfcpp::R_SPARC_M44
:
2579 Reloc::m44(view
, object
, psymval
, addend
);
2582 case elfcpp::R_SPARC_L44
:
2583 Reloc::l44(view
, object
, psymval
, addend
);
2586 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2587 case elfcpp::R_SPARC_UA64
:
2588 Reloc::ua64(view
, object
, psymval
, addend
);
2591 case elfcpp::R_SPARC_UA16
:
2592 Reloc::ua16(view
, object
, psymval
, addend
);
2595 case elfcpp::R_SPARC_TLS_GD_HI22
:
2596 case elfcpp::R_SPARC_TLS_GD_LO10
:
2597 case elfcpp::R_SPARC_TLS_GD_ADD
:
2598 case elfcpp::R_SPARC_TLS_GD_CALL
:
2599 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2600 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2601 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2602 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2603 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2604 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2605 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2606 case elfcpp::R_SPARC_TLS_IE_HI22
:
2607 case elfcpp::R_SPARC_TLS_IE_LO10
:
2608 case elfcpp::R_SPARC_TLS_IE_LD
:
2609 case elfcpp::R_SPARC_TLS_IE_LDX
:
2610 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2611 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2612 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2613 r_type
, gsym
, psymval
, view
,
2614 address
, view_size
);
2617 case elfcpp::R_SPARC_COPY
:
2618 case elfcpp::R_SPARC_GLOB_DAT
:
2619 case elfcpp::R_SPARC_JMP_SLOT
:
2620 case elfcpp::R_SPARC_RELATIVE
:
2621 // These are outstanding tls relocs, which are unexpected when
2623 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2624 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2625 case elfcpp::R_SPARC_TLS_TPOFF64
:
2626 case elfcpp::R_SPARC_TLS_TPOFF32
:
2627 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2628 _("unexpected reloc %u in object file"),
2633 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2634 _("unsupported reloc %u"),
2642 // Perform a TLS relocation.
2644 template<int size
, bool big_endian
>
2646 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2647 const Relocate_info
<size
, big_endian
>* relinfo
,
2648 Target_sparc
<size
, big_endian
>* target
,
2650 const elfcpp::Rela
<size
, big_endian
>& rela
,
2651 unsigned int r_type
,
2652 const Sized_symbol
<size
>* gsym
,
2653 const Symbol_value
<size
>* psymval
,
2654 unsigned char* view
,
2655 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2658 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2659 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2660 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2661 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2663 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2664 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2666 const bool is_final
=
2668 ? !parameters
->options().output_is_position_independent()
2669 : gsym
->final_value_is_known());
2670 const tls::Tls_optimization optimized_type
2671 = optimize_tls_reloc(is_final
, r_type
);
2675 case elfcpp::R_SPARC_TLS_GD_HI22
:
2676 case elfcpp::R_SPARC_TLS_GD_LO10
:
2677 case elfcpp::R_SPARC_TLS_GD_ADD
:
2678 case elfcpp::R_SPARC_TLS_GD_CALL
:
2679 if (optimized_type
== tls::TLSOPT_TO_LE
)
2681 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2684 value
-= tls_segment
->memsz();
2688 case elfcpp::R_SPARC_TLS_GD_HI22
:
2689 // TLS_GD_HI22 --> TLS_LE_HIX22
2690 Reloc::hix22(view
, value
, addend
);
2693 case elfcpp::R_SPARC_TLS_GD_LO10
:
2694 // TLS_GD_LO10 --> TLS_LE_LOX10
2695 Reloc::lox10(view
, value
, addend
);
2698 case elfcpp::R_SPARC_TLS_GD_ADD
:
2699 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2700 val
= elfcpp::Swap
<32, true>::readval(wv
);
2701 val
= (val
& ~0x7c000) | 0x1c000;
2702 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2704 case elfcpp::R_SPARC_TLS_GD_CALL
:
2705 // call __tls_get_addr --> nop
2706 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2713 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2714 ? GOT_TYPE_TLS_OFFSET
2715 : GOT_TYPE_TLS_PAIR
);
2718 gold_assert(gsym
->has_got_offset(got_type
));
2719 value
= gsym
->got_offset(got_type
);
2723 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2724 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2725 value
= object
->local_got_offset(r_sym
, got_type
);
2727 if (optimized_type
== tls::TLSOPT_TO_IE
)
2729 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2734 case elfcpp::R_SPARC_TLS_GD_HI22
:
2735 // TLS_GD_HI22 --> TLS_IE_HI22
2736 Reloc::hi22(view
, value
, addend
);
2739 case elfcpp::R_SPARC_TLS_GD_LO10
:
2740 // TLS_GD_LO10 --> TLS_IE_LO10
2741 Reloc::lo10(view
, value
, addend
);
2744 case elfcpp::R_SPARC_TLS_GD_ADD
:
2745 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2746 val
= elfcpp::Swap
<32, true>::readval(wv
);
2753 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2756 case elfcpp::R_SPARC_TLS_GD_CALL
:
2757 // The compiler can put the TLS_GD_ADD instruction
2758 // into the delay slot of the call. If so, we need
2759 // to transpose the two instructions so that the
2760 // the new sequence works properly.
2762 // The test we use is if the instruction in the
2763 // delay slot is an add with destination register
2765 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2766 if ((val
& 0x81f80000) == 0x80000000
2767 && ((val
>> 25) & 0x1f) == 0x8)
2774 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2777 this->ignore_gd_add_
= true;
2780 // call __tls_get_addr --> add %g7, %o0, %o0
2781 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2786 else if (optimized_type
== tls::TLSOPT_NONE
)
2790 case elfcpp::R_SPARC_TLS_GD_HI22
:
2791 Reloc::hi22(view
, value
, addend
);
2793 case elfcpp::R_SPARC_TLS_GD_LO10
:
2794 Reloc::lo10(view
, value
, addend
);
2796 case elfcpp::R_SPARC_TLS_GD_ADD
:
2798 case elfcpp::R_SPARC_TLS_GD_CALL
:
2800 Symbol_value
<size
> symval
;
2801 elfcpp::Elf_Xword value
;
2804 tsym
= target
->tls_get_addr_sym_
;
2806 value
= (target
->plt_section()->address() +
2807 tsym
->plt_offset());
2808 symval
.set_output_value(value
);
2809 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2816 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2817 _("unsupported reloc %u"),
2821 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2822 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2823 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2824 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2825 if (optimized_type
== tls::TLSOPT_TO_LE
)
2827 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2831 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2832 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2833 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2834 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2837 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2838 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2843 else if (optimized_type
== tls::TLSOPT_NONE
)
2845 // Relocate the field with the offset of the GOT entry for
2846 // the module index.
2847 unsigned int got_offset
;
2849 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2852 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2853 Reloc::hi22(view
, got_offset
, addend
);
2855 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2856 Reloc::lo10(view
, got_offset
, addend
);
2858 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2860 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2862 Symbol_value
<size
> symval
;
2863 elfcpp::Elf_Xword value
;
2866 tsym
= target
->tls_get_addr_sym_
;
2868 value
= (target
->plt_section()->address() +
2869 tsym
->plt_offset());
2870 symval
.set_output_value(value
);
2871 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2877 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2878 _("unsupported reloc %u"),
2882 // These relocs can appear in debugging sections, in which case
2883 // we won't see the TLS_LDM relocs. The local_dynamic_type
2884 // field tells us this.
2885 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2886 if (optimized_type
== tls::TLSOPT_TO_LE
)
2888 value
-= tls_segment
->memsz();
2889 Reloc::hix22(view
, value
, addend
);
2892 Reloc::ldo_hix22(view
, value
, addend
);
2894 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2895 if (optimized_type
== tls::TLSOPT_TO_LE
)
2897 value
-= tls_segment
->memsz();
2898 Reloc::lox10(view
, value
, addend
);
2901 Reloc::ldo_lox10(view
, value
, addend
);
2903 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2904 if (optimized_type
== tls::TLSOPT_TO_LE
)
2906 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2909 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2910 val
= elfcpp::Swap
<32, true>::readval(wv
);
2911 val
= (val
& ~0x7c000) | 0x1c000;
2912 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2916 // When optimizing IE --> LE, the only relocation that is handled
2917 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2918 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2919 // rs2 and rd are the same.
2920 case elfcpp::R_SPARC_TLS_IE_LD
:
2921 case elfcpp::R_SPARC_TLS_IE_LDX
:
2922 if (optimized_type
== tls::TLSOPT_TO_LE
)
2924 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2925 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
2926 Insntype rs2
= val
& 0x1f;
2927 Insntype rd
= (val
>> 25) & 0x1f;
2932 val
= sparc_mov
| (val
& 0x3e00001f);
2934 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2938 case elfcpp::R_SPARC_TLS_IE_HI22
:
2939 case elfcpp::R_SPARC_TLS_IE_LO10
:
2940 if (optimized_type
== tls::TLSOPT_TO_LE
)
2942 value
-= tls_segment
->memsz();
2945 case elfcpp::R_SPARC_TLS_IE_HI22
:
2946 // IE_HI22 --> LE_HIX22
2947 Reloc::hix22(view
, value
, addend
);
2949 case elfcpp::R_SPARC_TLS_IE_LO10
:
2950 // IE_LO10 --> LE_LOX10
2951 Reloc::lox10(view
, value
, addend
);
2956 else if (optimized_type
== tls::TLSOPT_NONE
)
2958 // Relocate the field with the offset of the GOT entry for
2959 // the tp-relative offset of the symbol.
2962 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
2963 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
2967 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2968 gold_assert(object
->local_has_got_offset(r_sym
,
2969 GOT_TYPE_TLS_OFFSET
));
2970 value
= object
->local_got_offset(r_sym
,
2971 GOT_TYPE_TLS_OFFSET
);
2975 case elfcpp::R_SPARC_TLS_IE_HI22
:
2976 Reloc::hi22(view
, value
, addend
);
2978 case elfcpp::R_SPARC_TLS_IE_LO10
:
2979 Reloc::lo10(view
, value
, addend
);
2984 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2985 _("unsupported reloc %u"),
2989 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2990 // If we're creating a shared library, a dynamic relocation will
2991 // have been created for this location, so do not apply it now.
2992 if (!parameters
->options().shared())
2994 value
-= tls_segment
->memsz();
2995 Reloc::hix22(view
, value
, addend
);
2999 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3000 // If we're creating a shared library, a dynamic relocation will
3001 // have been created for this location, so do not apply it now.
3002 if (!parameters
->options().shared())
3004 value
-= tls_segment
->memsz();
3005 Reloc::lox10(view
, value
, addend
);
3011 // Relocate section data.
3013 template<int size
, bool big_endian
>
3015 Target_sparc
<size
, big_endian
>::relocate_section(
3016 const Relocate_info
<size
, big_endian
>* relinfo
,
3017 unsigned int sh_type
,
3018 const unsigned char* prelocs
,
3020 Output_section
* output_section
,
3021 bool needs_special_offset_handling
,
3022 unsigned char* view
,
3023 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3024 section_size_type view_size
)
3026 typedef Target_sparc
<size
, big_endian
> Sparc
;
3027 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3029 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3031 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3038 needs_special_offset_handling
,
3044 // Return the size of a relocation while scanning during a relocatable
3047 template<int size
, bool big_endian
>
3049 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3053 // We are always SHT_RELA, so we should never get here.
3058 // Scan the relocs during a relocatable link.
3060 template<int size
, bool big_endian
>
3062 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3063 const General_options
& options
,
3064 Symbol_table
* symtab
,
3066 Sized_relobj
<size
, big_endian
>* object
,
3067 unsigned int data_shndx
,
3068 unsigned int sh_type
,
3069 const unsigned char* prelocs
,
3071 Output_section
* output_section
,
3072 bool needs_special_offset_handling
,
3073 size_t local_symbol_count
,
3074 const unsigned char* plocal_symbols
,
3075 Relocatable_relocs
* rr
)
3077 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3079 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3080 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3082 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3083 Scan_relocatable_relocs
>(
3092 needs_special_offset_handling
,
3098 // Relocate a section during a relocatable link.
3100 template<int size
, bool big_endian
>
3102 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3103 const Relocate_info
<size
, big_endian
>* relinfo
,
3104 unsigned int sh_type
,
3105 const unsigned char* prelocs
,
3107 Output_section
* output_section
,
3108 off_t offset_in_output_section
,
3109 const Relocatable_relocs
* rr
,
3110 unsigned char* view
,
3111 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3112 section_size_type view_size
,
3113 unsigned char* reloc_view
,
3114 section_size_type reloc_view_size
)
3116 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3118 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3123 offset_in_output_section
,
3132 // Return the value to use for a dynamic which requires special
3133 // treatment. This is how we support equality comparisons of function
3134 // pointers across shared library boundaries, as described in the
3135 // processor specific ABI supplement.
3137 template<int size
, bool big_endian
>
3139 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3141 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3142 return this->plt_section()->address() + gsym
->plt_offset();
3145 // The selector for sparc object files.
3147 template<int size
, bool big_endian
>
3148 class Target_selector_sparc
: public Target_selector
3151 Target_selector_sparc()
3152 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3153 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3156 Target
* instantiated_target_
;
3158 Target
* do_recognize(int machine
, int, int)
3163 if (machine
!= elfcpp::EM_SPARCV9
)
3168 if (machine
!= elfcpp::EM_SPARC
3169 && machine
!= elfcpp::EM_SPARC32PLUS
)
3177 return do_instantiate_target();
3180 Target
* do_instantiate_target()
3182 if (this->instantiated_target_
== NULL
)
3183 this->instantiated_target_
= new Target_sparc
<size
, big_endian
>();
3184 return this->instantiated_target_
;
3188 Target_selector_sparc
<32, true> target_selector_sparc32
;
3189 Target_selector_sparc
<64, true> target_selector_sparc64
;
3191 } // End anonymous namespace.