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"
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 // Process the relocations to determine unreferenced sections for
67 // garbage collection.
69 gc_process_relocs(const General_options
& options
,
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(const General_options
& options
,
87 Sized_relobj
<size
, big_endian
>* object
,
88 unsigned int data_shndx
,
90 const unsigned char* prelocs
,
92 Output_section
* output_section
,
93 bool needs_special_offset_handling
,
94 size_t local_symbol_count
,
95 const unsigned char* plocal_symbols
);
96 // Finalize the sections.
98 do_finalize_sections(Layout
*);
100 // Return the value to use for a dynamic which requires special
103 do_dynsym_value(const Symbol
*) const;
105 // Relocate a section.
107 relocate_section(const Relocate_info
<size
, big_endian
>*,
108 unsigned int sh_type
,
109 const unsigned char* prelocs
,
111 Output_section
* output_section
,
112 bool needs_special_offset_handling
,
114 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
115 section_size_type view_size
);
117 // Scan the relocs during a relocatable link.
119 scan_relocatable_relocs(const General_options
& options
,
120 Symbol_table
* symtab
,
122 Sized_relobj
<size
, big_endian
>* object
,
123 unsigned int data_shndx
,
124 unsigned int sh_type
,
125 const unsigned char* prelocs
,
127 Output_section
* output_section
,
128 bool needs_special_offset_handling
,
129 size_t local_symbol_count
,
130 const unsigned char* plocal_symbols
,
131 Relocatable_relocs
*);
133 // Relocate a section during a relocatable link.
135 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
136 unsigned int sh_type
,
137 const unsigned char* prelocs
,
139 Output_section
* output_section
,
140 off_t offset_in_output_section
,
141 const Relocatable_relocs
*,
143 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
144 section_size_type view_size
,
145 unsigned char* reloc_view
,
146 section_size_type reloc_view_size
);
147 // Return whether SYM is defined by the ABI.
149 do_is_defined_by_abi(const Symbol
* sym
) const
151 // XXX Really need to support this better...
152 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
155 return strcmp(sym
->name(), "___tls_get_addr") == 0;
158 // Return whether there is a GOT section.
160 has_got_section() const
161 { return this->got_
!= NULL
; }
163 // Return the size of the GOT section.
167 gold_assert(this->got_
!= NULL
);
168 return this->got_
->data_size();
173 // The class which scans relocations.
178 : issued_non_pic_error_(false)
182 local(const General_options
& options
, Symbol_table
* symtab
,
183 Layout
* layout
, Target_sparc
* target
,
184 Sized_relobj
<size
, big_endian
>* object
,
185 unsigned int data_shndx
,
186 Output_section
* output_section
,
187 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
188 const elfcpp::Sym
<size
, big_endian
>& lsym
);
191 global(const General_options
& options
, Symbol_table
* symtab
,
192 Layout
* layout
, Target_sparc
* target
,
193 Sized_relobj
<size
, big_endian
>* object
,
194 unsigned int data_shndx
,
195 Output_section
* output_section
,
196 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
201 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
202 unsigned int r_type
);
205 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
206 unsigned int r_type
, Symbol
*);
209 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
210 Target_sparc
* target
);
213 check_non_pic(Relobj
*, unsigned int r_type
);
215 // Whether we have issued an error about a non-PIC compilation.
216 bool issued_non_pic_error_
;
219 // The class which implements relocation.
224 : ignore_gd_add_(false)
229 if (this->ignore_gd_add_
)
231 // FIXME: This needs to specify the location somehow.
232 gold_error(_("missing expected TLS relocation"));
236 // Do a relocation. Return false if the caller should not issue
237 // any warnings about this relocation.
239 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
240 Output_section
*, size_t relnum
,
241 const elfcpp::Rela
<size
, big_endian
>&,
242 unsigned int r_type
, const Sized_symbol
<size
>*,
243 const Symbol_value
<size
>*,
245 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
249 // Do a TLS relocation.
251 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
252 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
253 unsigned int r_type
, const Sized_symbol
<size
>*,
254 const Symbol_value
<size
>*,
256 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
259 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
263 // A class which returns the size required for a relocation type,
264 // used while scanning relocs during a relocatable link.
265 class Relocatable_size_for_reloc
269 get_size_for_reloc(unsigned int, Relobj
*);
272 // Get the GOT section, creating it if necessary.
273 Output_data_got
<size
, big_endian
>*
274 got_section(Symbol_table
*, Layout
*);
276 // Create a PLT entry for a global symbol.
278 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
280 // Create a GOT entry for the TLS module index.
282 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
283 Sized_relobj
<size
, big_endian
>* object
);
285 // Return the gsym for "__tls_get_addr". Cache if not already
288 tls_get_addr_sym(Symbol_table
* symtab
)
290 if (!this->tls_get_addr_sym_
)
291 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
292 gold_assert(this->tls_get_addr_sym_
);
293 return this->tls_get_addr_sym_
;
296 // Get the PLT section.
297 const Output_data_plt_sparc
<size
, big_endian
>*
300 gold_assert(this->plt_
!= NULL
);
304 // Get the dynamic reloc section, creating it if necessary.
306 rela_dyn_section(Layout
*);
308 // Return true if the symbol may need a COPY relocation.
309 // References from an executable object to non-function symbols
310 // defined in a dynamic object may need a COPY relocation.
312 may_need_copy_reloc(Symbol
* gsym
)
314 return (!parameters
->options().shared()
315 && gsym
->is_from_dynobj()
316 && gsym
->type() != elfcpp::STT_FUNC
);
319 // Copy a relocation against a global symbol.
321 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
322 Sized_relobj
<size
, big_endian
>* object
,
323 unsigned int shndx
, Output_section
* output_section
,
324 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
326 this->copy_relocs_
.copy_reloc(symtab
, layout
,
327 symtab
->get_sized_symbol
<size
>(sym
),
328 object
, shndx
, output_section
,
329 reloc
, this->rela_dyn_section(layout
));
332 // Information about this specific target which we pass to the
333 // general Target structure.
334 static Target::Target_info sparc_info
;
336 // The types of GOT entries needed for this platform.
339 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
340 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
341 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
345 Output_data_got
<size
, big_endian
>* got_
;
347 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
348 // The dynamic reloc section.
349 Reloc_section
* rela_dyn_
;
350 // Relocs saved to avoid a COPY reloc.
351 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
352 // Space for variables copied with a COPY reloc.
353 Output_data_space
* dynbss_
;
354 // Offset of the GOT entry for the TLS module index;
355 unsigned int got_mod_index_offset_
;
356 // Cached pointer to __tls_get_addr symbol
357 Symbol
* tls_get_addr_sym_
;
361 Target::Target_info Target_sparc
<32, true>::sparc_info
=
364 true, // is_big_endian
365 elfcpp::EM_SPARC
, // machine_code
366 false, // has_make_symbol
367 false, // has_resolve
368 false, // has_code_fill
369 true, // is_default_stack_executable
371 "/usr/lib/ld.so.1", // dynamic_linker
372 0x00010000, // default_text_segment_address
373 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
374 8 * 1024 // common_pagesize (overridable by -z common-page-size)
378 Target::Target_info Target_sparc
<64, true>::sparc_info
=
381 true, // is_big_endian
382 elfcpp::EM_SPARCV9
, // machine_code
383 false, // has_make_symbol
384 false, // has_resolve
385 false, // has_code_fill
386 true, // is_default_stack_executable
388 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
389 0x100000, // default_text_segment_address
390 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
391 8 * 1024 // common_pagesize (overridable by -z common-page-size)
394 // We have to take care here, even when operating in little-endian
395 // mode, sparc instructions are still big endian.
396 template<int size
, bool big_endian
>
397 class Sparc_relocate_functions
400 // Do a simple relocation with the addend in the relocation.
401 template<int valsize
>
403 rela(unsigned char* view
,
404 unsigned int right_shift
,
405 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
406 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
407 typename
elfcpp::Swap
<size
, 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
= ((value
+ 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
422 template<int valsize
>
424 rela(unsigned char* view
,
425 unsigned int right_shift
,
426 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
427 const Sized_relobj
<size
, big_endian
>* object
,
428 const Symbol_value
<size
>* psymval
,
429 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
431 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
432 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
433 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
434 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
439 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
442 // Do a simple relocation using a symbol value with the addend in
443 // the relocation, unaligned.
444 template<int valsize
>
446 rela_ua(unsigned char* view
,
447 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
448 const Sized_relobj
<size
, big_endian
>* object
,
449 const Symbol_value
<size
>* psymval
,
450 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
452 typedef typename
elfcpp::Swap_unaligned
<valsize
,
453 big_endian
>::Valtype Valtype
;
454 unsigned char* wv
= view
;
455 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
456 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
461 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
464 // Do a simple PC relative relocation with a Symbol_value with the
465 // addend in the relocation.
466 template<int valsize
>
468 pcrela(unsigned char* view
,
469 unsigned int right_shift
,
470 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
471 const Sized_relobj
<size
, big_endian
>* object
,
472 const Symbol_value
<size
>* psymval
,
473 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
474 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
476 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
477 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
478 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
479 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
485 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
488 template<int valsize
>
490 pcrela_unaligned(unsigned char* view
,
491 const Sized_relobj
<size
, big_endian
>* object
,
492 const Symbol_value
<size
>* psymval
,
493 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
494 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
496 typedef typename
elfcpp::Swap_unaligned
<valsize
,
497 big_endian
>::Valtype Valtype
;
498 unsigned char* wv
= view
;
499 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
501 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
504 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
505 typedef Sparc_relocate_functions
<size
, true> This_insn
;
508 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
510 wdisp30(unsigned char* view
,
511 const Sized_relobj
<size
, big_endian
>* object
,
512 const Symbol_value
<size
>* psymval
,
513 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
514 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
516 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
517 psymval
, addend
, address
);
520 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
522 wdisp22(unsigned char* view
,
523 const Sized_relobj
<size
, big_endian
>* object
,
524 const Symbol_value
<size
>* psymval
,
525 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
526 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
528 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
529 psymval
, addend
, address
);
532 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
534 wdisp19(unsigned char* view
,
535 const Sized_relobj
<size
, big_endian
>* object
,
536 const Symbol_value
<size
>* psymval
,
537 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
538 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
540 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
541 psymval
, addend
, address
);
544 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
546 wdisp16(unsigned char* view
,
547 const Sized_relobj
<size
, big_endian
>* object
,
548 const Symbol_value
<size
>* psymval
,
549 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
550 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
552 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
553 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
554 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
555 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
558 // The relocation value is split between the low 14 bits,
560 val
&= ~((0x3 << 20) | 0x3fff);
561 reloc
= (((reloc
& 0xc000) << (20 - 14))
562 | (reloc
& 0x3ffff));
564 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
567 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
569 pc22(unsigned char* view
,
570 const Sized_relobj
<size
, big_endian
>* object
,
571 const Symbol_value
<size
>* psymval
,
572 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
573 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
575 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
576 psymval
, addend
, address
);
579 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
581 pc10(unsigned char* view
,
582 const Sized_relobj
<size
, big_endian
>* object
,
583 const Symbol_value
<size
>* psymval
,
584 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
585 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
587 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
588 psymval
, addend
, address
);
591 // R_SPARC_HI22: (Symbol + Addend) >> 10
593 hi22(unsigned char* view
,
594 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
595 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
597 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
600 // R_SPARC_HI22: (Symbol + Addend) >> 10
602 hi22(unsigned char* view
,
603 const Sized_relobj
<size
, big_endian
>* object
,
604 const Symbol_value
<size
>* psymval
,
605 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
607 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
610 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
612 pcplt22(unsigned char* view
,
613 const Sized_relobj
<size
, big_endian
>* object
,
614 const Symbol_value
<size
>* psymval
,
615 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
616 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
618 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
619 psymval
, addend
, address
);
622 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
624 lo10(unsigned char* view
,
625 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
626 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
628 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
631 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
633 lo10(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
)
638 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
641 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
643 lo10(unsigned char* view
,
644 const Sized_relobj
<size
, big_endian
>* object
,
645 const Symbol_value
<size
>* psymval
,
646 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
647 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
649 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
650 psymval
, addend
, address
);
653 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
655 olo10(unsigned char* view
,
656 const Sized_relobj
<size
, big_endian
>* object
,
657 const Symbol_value
<size
>* psymval
,
658 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
659 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
661 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
662 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
663 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
664 Valtype reloc
= psymval
->value(object
, addend
);
671 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
674 // R_SPARC_22: (Symbol + Addend)
676 rela32_22(unsigned char* view
,
677 const Sized_relobj
<size
, big_endian
>* object
,
678 const Symbol_value
<size
>* psymval
,
679 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
681 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
684 // R_SPARC_13: (Symbol + Addend)
686 rela32_13(unsigned char* view
,
687 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
688 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
690 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
693 // R_SPARC_13: (Symbol + Addend)
695 rela32_13(unsigned char* view
,
696 const Sized_relobj
<size
, big_endian
>* object
,
697 const Symbol_value
<size
>* psymval
,
698 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
700 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
703 // R_SPARC_UA16: (Symbol + Addend)
705 ua16(unsigned char* view
,
706 const Sized_relobj
<size
, big_endian
>* object
,
707 const Symbol_value
<size
>* psymval
,
708 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
710 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
713 // R_SPARC_UA32: (Symbol + Addend)
715 ua32(unsigned char* view
,
716 const Sized_relobj
<size
, big_endian
>* object
,
717 const Symbol_value
<size
>* psymval
,
718 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
720 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
723 // R_SPARC_UA64: (Symbol + Addend)
725 ua64(unsigned char* view
,
726 const Sized_relobj
<size
, big_endian
>* object
,
727 const Symbol_value
<size
>* psymval
,
728 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
730 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
731 object
, psymval
, addend
);
734 // R_SPARC_DISP8: (Symbol + Addend - Address)
736 disp8(unsigned char* view
,
737 const Sized_relobj
<size
, big_endian
>* object
,
738 const Symbol_value
<size
>* psymval
,
739 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
740 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
742 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
746 // R_SPARC_DISP16: (Symbol + Addend - Address)
748 disp16(unsigned char* view
,
749 const Sized_relobj
<size
, big_endian
>* object
,
750 const Symbol_value
<size
>* psymval
,
751 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
752 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
754 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
758 // R_SPARC_DISP32: (Symbol + Addend - Address)
760 disp32(unsigned char* view
,
761 const Sized_relobj
<size
, big_endian
>* object
,
762 const Symbol_value
<size
>* psymval
,
763 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
764 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
766 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
770 // R_SPARC_DISP64: (Symbol + Addend - Address)
772 disp64(unsigned char* view
,
773 const Sized_relobj
<size
, big_endian
>* object
,
774 const Symbol_value
<size
>* psymval
,
775 elfcpp::Elf_Xword addend
,
776 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
778 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
782 // R_SPARC_H44: (Symbol + Addend) >> 22
784 h44(unsigned char* view
,
785 const Sized_relobj
<size
, big_endian
>* object
,
786 const Symbol_value
<size
>* psymval
,
787 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
789 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
792 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
794 m44(unsigned char* view
,
795 const Sized_relobj
<size
, big_endian
>* object
,
796 const Symbol_value
<size
>* psymval
,
797 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
799 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
802 // R_SPARC_L44: (Symbol + Addend) & 0xfff
804 l44(unsigned char* view
,
805 const Sized_relobj
<size
, big_endian
>* object
,
806 const Symbol_value
<size
>* psymval
,
807 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
809 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
812 // R_SPARC_HH22: (Symbol + Addend) >> 42
814 hh22(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
, 42, 0x003fffff, object
, psymval
, addend
);
822 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
824 pc_hh22(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
, 42, 0x003fffff, object
,
831 psymval
, addend
, address
);
834 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
836 hm10(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
, 32, 0x000003ff, object
, psymval
, addend
);
844 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
846 pc_hm10(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
,
850 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
852 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
853 psymval
, addend
, address
);
856 // R_SPARC_11: (Symbol + Addend)
858 rela32_11(unsigned char* view
,
859 const Sized_relobj
<size
, big_endian
>* object
,
860 const Symbol_value
<size
>* psymval
,
861 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
863 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
866 // R_SPARC_10: (Symbol + Addend)
868 rela32_10(unsigned char* view
,
869 const Sized_relobj
<size
, big_endian
>* object
,
870 const Symbol_value
<size
>* psymval
,
871 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
873 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
876 // R_SPARC_7: (Symbol + Addend)
878 rela32_7(unsigned char* view
,
879 const Sized_relobj
<size
, big_endian
>* object
,
880 const Symbol_value
<size
>* psymval
,
881 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
883 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
886 // R_SPARC_6: (Symbol + Addend)
888 rela32_6(unsigned char* view
,
889 const Sized_relobj
<size
, big_endian
>* object
,
890 const Symbol_value
<size
>* psymval
,
891 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
893 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
896 // R_SPARC_5: (Symbol + Addend)
898 rela32_5(unsigned char* view
,
899 const Sized_relobj
<size
, big_endian
>* object
,
900 const Symbol_value
<size
>* psymval
,
901 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
903 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
906 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
908 ldo_hix22(unsigned char* view
,
909 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
910 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
912 This_insn::hi22(view
, value
, addend
);
915 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
917 ldo_lox10(unsigned char* view
,
918 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
919 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
921 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
922 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
923 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
924 Valtype reloc
= (value
+ addend
);
929 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
932 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
934 hix22(unsigned char* view
,
935 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
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
= (value
+ addend
);
945 reloc
^= ~(Valtype
)0;
950 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
953 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
955 hix22(unsigned char* view
,
956 const Sized_relobj
<size
, big_endian
>* object
,
957 const Symbol_value
<size
>* psymval
,
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
= psymval
->value(object
, addend
);
967 reloc
^= ~(Valtype
)0;
972 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
976 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
978 lox10(unsigned char* view
,
979 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
980 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
982 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
983 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
984 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
985 Valtype reloc
= (value
+ addend
);
991 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
994 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
996 lox10(unsigned char* view
,
997 const Sized_relobj
<size
, big_endian
>* object
,
998 const Symbol_value
<size
>* psymval
,
999 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
1001 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
1002 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
1003 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
1004 Valtype reloc
= psymval
->value(object
, addend
);
1010 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1014 // Get the GOT section, creating it if necessary.
1016 template<int size
, bool big_endian
>
1017 Output_data_got
<size
, big_endian
>*
1018 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1021 if (this->got_
== NULL
)
1023 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1025 this->got_
= new Output_data_got
<size
, big_endian
>();
1028 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1030 | elfcpp::SHF_WRITE
),
1034 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1035 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1037 0, 0, elfcpp::STT_OBJECT
,
1039 elfcpp::STV_HIDDEN
, 0,
1046 // Get the dynamic reloc section, creating it if necessary.
1048 template<int size
, bool big_endian
>
1049 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1050 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1052 if (this->rela_dyn_
== NULL
)
1054 gold_assert(layout
!= NULL
);
1055 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1056 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1057 elfcpp::SHF_ALLOC
, this->rela_dyn_
);
1059 return this->rela_dyn_
;
1062 // A class to handle the PLT data.
1064 template<int size
, bool big_endian
>
1065 class Output_data_plt_sparc
: public Output_section_data
1068 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1069 size
, big_endian
> Reloc_section
;
1071 Output_data_plt_sparc(Layout
*);
1073 // Add an entry to the PLT.
1074 void add_entry(Symbol
* gsym
);
1076 // Return the .rela.plt section data.
1077 const Reloc_section
* rel_plt() const
1083 void do_adjust_output_section(Output_section
* os
);
1085 // Write to a map file.
1087 do_print_to_mapfile(Mapfile
* mapfile
) const
1088 { mapfile
->print_output_data(this, _("** PLT")); }
1091 // The size of an entry in the PLT.
1092 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1094 static const unsigned int plt_entries_per_block
= 160;
1095 static const unsigned int plt_insn_chunk_size
= 24;
1096 static const unsigned int plt_pointer_chunk_size
= 8;
1097 static const unsigned int plt_block_size
=
1098 (plt_entries_per_block
1099 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1101 // Set the final size.
1103 set_final_data_size()
1105 unsigned int full_count
= this->count_
+ 4;
1106 unsigned int extra
= (size
== 32 ? 4 : 0);
1108 if (size
== 32 || full_count
< 32768)
1109 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1112 unsigned int ext_cnt
= full_count
- 32768;
1114 this->set_data_size((32768 * base_plt_entry_size
)
1116 * (plt_insn_chunk_size
1117 + plt_pointer_chunk_size
)));
1121 // Write out the PLT data.
1123 do_write(Output_file
*);
1125 // The reloc section.
1126 Reloc_section
* rel_
;
1127 // The number of PLT entries.
1128 unsigned int count_
;
1131 // Define the constants as required by C++ standard.
1133 template<int size
, bool big_endian
>
1134 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1136 template<int size
, bool big_endian
>
1138 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1140 template<int size
, bool big_endian
>
1141 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1143 template<int size
, bool big_endian
>
1145 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1147 template<int size
, bool big_endian
>
1148 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1150 // Create the PLT section. The ordinary .got section is an argument,
1151 // since we need to refer to the start.
1153 template<int size
, bool big_endian
>
1154 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1155 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1157 this->rel_
= new Reloc_section(false);
1158 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1159 elfcpp::SHF_ALLOC
, this->rel_
);
1162 template<int size
, bool big_endian
>
1164 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1169 // Add an entry to the PLT.
1171 template<int size
, bool big_endian
>
1173 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1175 gold_assert(!gsym
->has_plt_offset());
1177 unsigned int index
= this->count_
+ 4;
1178 section_offset_type plt_offset
;
1180 if (size
== 32 || index
< 32768)
1181 plt_offset
= index
* base_plt_entry_size
;
1184 unsigned int ext_index
= index
- 32768;
1186 plt_offset
= (32768 * base_plt_entry_size
)
1187 + ((ext_index
/ plt_entries_per_block
)
1189 + ((ext_index
% plt_entries_per_block
)
1190 * plt_insn_chunk_size
);
1193 gsym
->set_plt_offset(plt_offset
);
1197 // Every PLT entry needs a reloc.
1198 gsym
->set_needs_dynsym_entry();
1199 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1202 // Note that we don't need to save the symbol. The contents of the
1203 // PLT are independent of which symbols are used. The symbols only
1204 // appear in the relocations.
1207 static const unsigned int sparc_nop
= 0x01000000;
1208 static const unsigned int sparc_sethi_g1
= 0x03000000;
1209 static const unsigned int sparc_branch_always
= 0x30800000;
1210 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1211 static const unsigned int sparc_mov
= 0x80100000;
1212 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1213 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1214 static const unsigned int sparc_call_plus_8
= 0x40000002;
1215 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1216 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1217 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1219 // Write out the PLT.
1221 template<int size
, bool big_endian
>
1223 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1225 const off_t offset
= this->offset();
1226 const section_size_type oview_size
=
1227 convert_to_section_size_type(this->data_size());
1228 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1229 unsigned char* pov
= oview
;
1231 memset(pov
, 0, base_plt_entry_size
* 4);
1232 pov
+= base_plt_entry_size
* 4;
1234 unsigned int plt_offset
= base_plt_entry_size
* 4;
1235 const unsigned int count
= this->count_
;
1241 limit
= (count
> 32768 ? 32768 : count
);
1243 for (unsigned int i
= 0; i
< limit
; ++i
)
1245 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1246 sparc_sethi_g1
+ plt_offset
);
1247 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1248 sparc_branch_always_pt
+
1249 (((base_plt_entry_size
-
1250 (plt_offset
+ 4)) >> 2) &
1252 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1253 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1254 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1255 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1256 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1257 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1259 pov
+= base_plt_entry_size
;
1260 plt_offset
+= base_plt_entry_size
;
1265 unsigned int ext_cnt
= count
- 32768;
1266 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1268 for (unsigned int i
= 0; i
< blks
; ++i
)
1270 unsigned int data_off
= (plt_entries_per_block
1271 * plt_insn_chunk_size
) - 4;
1273 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1275 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1277 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1279 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1281 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1282 sparc_ldx_o7_imm_g1
+
1283 (data_off
& 0x1fff));
1284 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1285 sparc_jmpl_o7_g1_g1
);
1286 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1289 elfcpp::Swap
<64, big_endian
>::writeval(
1290 pov
+ 0x4 + data_off
,
1291 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1293 pov
+= plt_insn_chunk_size
;
1298 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1299 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1301 unsigned int data_off
= (sub_blk_cnt
1302 * plt_insn_chunk_size
) - 4;
1304 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1306 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1308 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1310 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1312 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1313 sparc_ldx_o7_imm_g1
+
1314 (data_off
& 0x1fff));
1315 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1316 sparc_jmpl_o7_g1_g1
);
1317 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1320 elfcpp::Swap
<64, big_endian
>::writeval(
1321 pov
+ 0x4 + data_off
,
1322 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1324 pov
+= plt_insn_chunk_size
;
1332 for (unsigned int i
= 0; i
< count
; ++i
)
1334 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1335 sparc_sethi_g1
+ plt_offset
);
1336 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1337 sparc_branch_always
+
1338 (((- (plt_offset
+ 4)) >> 2) &
1340 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1342 pov
+= base_plt_entry_size
;
1343 plt_offset
+= base_plt_entry_size
;
1346 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1350 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1352 of
->write_output_view(offset
, oview_size
, oview
);
1355 // Create a PLT entry for a global symbol.
1357 template<int size
, bool big_endian
>
1359 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1363 if (gsym
->has_plt_offset())
1366 if (this->plt_
== NULL
)
1368 // Create the GOT sections first.
1369 this->got_section(symtab
, layout
);
1371 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1372 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1374 | elfcpp::SHF_EXECINSTR
1375 | elfcpp::SHF_WRITE
),
1378 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1379 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1381 0, 0, elfcpp::STT_OBJECT
,
1383 elfcpp::STV_HIDDEN
, 0,
1387 this->plt_
->add_entry(gsym
);
1390 // Create a GOT entry for the TLS module index.
1392 template<int size
, bool big_endian
>
1394 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1396 Sized_relobj
<size
, big_endian
>* object
)
1398 if (this->got_mod_index_offset_
== -1U)
1400 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1401 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1402 Output_data_got
<size
, big_endian
>* got
;
1403 unsigned int got_offset
;
1405 got
= this->got_section(symtab
, layout
);
1406 got_offset
= got
->add_constant(0);
1407 rela_dyn
->add_local(object
, 0,
1409 elfcpp::R_SPARC_TLS_DTPMOD64
:
1410 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1412 got
->add_constant(0);
1413 this->got_mod_index_offset_
= got_offset
;
1415 return this->got_mod_index_offset_
;
1418 // Optimize the TLS relocation type based on what we know about the
1419 // symbol. IS_FINAL is true if the final address of this symbol is
1420 // known at link time.
1422 static tls::Tls_optimization
1423 optimize_tls_reloc(bool is_final
, int r_type
)
1425 // If we are generating a shared library, then we can't do anything
1427 if (parameters
->options().shared())
1428 return tls::TLSOPT_NONE
;
1432 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1433 case elfcpp::R_SPARC_TLS_GD_LO10
:
1434 case elfcpp::R_SPARC_TLS_GD_ADD
:
1435 case elfcpp::R_SPARC_TLS_GD_CALL
:
1436 // These are General-Dynamic which permits fully general TLS
1437 // access. Since we know that we are generating an executable,
1438 // we can convert this to Initial-Exec. If we also know that
1439 // this is a local symbol, we can further switch to Local-Exec.
1441 return tls::TLSOPT_TO_LE
;
1442 return tls::TLSOPT_TO_IE
;
1444 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1445 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1446 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1447 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1448 // This is Local-Dynamic, which refers to a local symbol in the
1449 // dynamic TLS block. Since we know that we generating an
1450 // executable, we can switch to Local-Exec.
1451 return tls::TLSOPT_TO_LE
;
1453 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1454 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1455 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1456 // Another type of Local-Dynamic relocation.
1457 return tls::TLSOPT_TO_LE
;
1459 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1460 case elfcpp::R_SPARC_TLS_IE_LO10
:
1461 case elfcpp::R_SPARC_TLS_IE_LD
:
1462 case elfcpp::R_SPARC_TLS_IE_LDX
:
1463 case elfcpp::R_SPARC_TLS_IE_ADD
:
1464 // These are Initial-Exec relocs which get the thread offset
1465 // from the GOT. If we know that we are linking against the
1466 // local symbol, we can switch to Local-Exec, which links the
1467 // thread offset into the instruction.
1469 return tls::TLSOPT_TO_LE
;
1470 return tls::TLSOPT_NONE
;
1472 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1473 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1474 // When we already have Local-Exec, there is nothing further we
1476 return tls::TLSOPT_NONE
;
1483 // Generate a PLT entry slot for a call to __tls_get_addr
1484 template<int size
, bool big_endian
>
1486 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1488 Target_sparc
<size
, big_endian
>* target
)
1490 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1492 target
->make_plt_entry(symtab
, layout
, gsym
);
1495 // Report an unsupported relocation against a local symbol.
1497 template<int size
, bool big_endian
>
1499 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1500 Sized_relobj
<size
, big_endian
>* object
,
1501 unsigned int r_type
)
1503 gold_error(_("%s: unsupported reloc %u against local symbol"),
1504 object
->name().c_str(), r_type
);
1507 // We are about to emit a dynamic relocation of type R_TYPE. If the
1508 // dynamic linker does not support it, issue an error.
1510 template<int size
, bool big_endian
>
1512 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1514 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1520 // These are the relocation types supported by glibc for sparc 64-bit.
1521 case elfcpp::R_SPARC_RELATIVE
:
1522 case elfcpp::R_SPARC_COPY
:
1523 case elfcpp::R_SPARC_64
:
1524 case elfcpp::R_SPARC_GLOB_DAT
:
1525 case elfcpp::R_SPARC_JMP_SLOT
:
1526 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1527 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1528 case elfcpp::R_SPARC_TLS_TPOFF64
:
1529 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1530 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1531 case elfcpp::R_SPARC_8
:
1532 case elfcpp::R_SPARC_16
:
1533 case elfcpp::R_SPARC_DISP8
:
1534 case elfcpp::R_SPARC_DISP16
:
1535 case elfcpp::R_SPARC_DISP32
:
1536 case elfcpp::R_SPARC_WDISP30
:
1537 case elfcpp::R_SPARC_LO10
:
1538 case elfcpp::R_SPARC_HI22
:
1539 case elfcpp::R_SPARC_OLO10
:
1540 case elfcpp::R_SPARC_H44
:
1541 case elfcpp::R_SPARC_M44
:
1542 case elfcpp::R_SPARC_L44
:
1543 case elfcpp::R_SPARC_HH22
:
1544 case elfcpp::R_SPARC_HM10
:
1545 case elfcpp::R_SPARC_LM22
:
1546 case elfcpp::R_SPARC_UA16
:
1547 case elfcpp::R_SPARC_UA32
:
1548 case elfcpp::R_SPARC_UA64
:
1559 // These are the relocation types supported by glibc for sparc 32-bit.
1560 case elfcpp::R_SPARC_RELATIVE
:
1561 case elfcpp::R_SPARC_COPY
:
1562 case elfcpp::R_SPARC_GLOB_DAT
:
1563 case elfcpp::R_SPARC_32
:
1564 case elfcpp::R_SPARC_JMP_SLOT
:
1565 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1566 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1567 case elfcpp::R_SPARC_TLS_TPOFF32
:
1568 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1569 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1570 case elfcpp::R_SPARC_8
:
1571 case elfcpp::R_SPARC_16
:
1572 case elfcpp::R_SPARC_DISP8
:
1573 case elfcpp::R_SPARC_DISP16
:
1574 case elfcpp::R_SPARC_DISP32
:
1575 case elfcpp::R_SPARC_LO10
:
1576 case elfcpp::R_SPARC_WDISP30
:
1577 case elfcpp::R_SPARC_HI22
:
1578 case elfcpp::R_SPARC_UA16
:
1579 case elfcpp::R_SPARC_UA32
:
1587 // This prevents us from issuing more than one error per reloc
1588 // section. But we can still wind up issuing more than one
1589 // error per object file.
1590 if (this->issued_non_pic_error_
)
1592 object
->error(_("requires unsupported dynamic reloc; "
1593 "recompile with -fPIC"));
1594 this->issued_non_pic_error_
= true;
1598 // Scan a relocation for a local symbol.
1600 template<int size
, bool big_endian
>
1602 Target_sparc
<size
, big_endian
>::Scan::local(
1603 const General_options
&,
1604 Symbol_table
* symtab
,
1606 Target_sparc
<size
, big_endian
>* target
,
1607 Sized_relobj
<size
, big_endian
>* object
,
1608 unsigned int data_shndx
,
1609 Output_section
* output_section
,
1610 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1611 unsigned int r_type
,
1612 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1614 unsigned int orig_r_type
= r_type
;
1619 case elfcpp::R_SPARC_NONE
:
1620 case elfcpp::R_SPARC_REGISTER
:
1621 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1622 case elfcpp::R_SPARC_GNU_VTENTRY
:
1625 case elfcpp::R_SPARC_64
:
1626 case elfcpp::R_SPARC_32
:
1627 // If building a shared library (or a position-independent
1628 // executable), we need to create a dynamic relocation for
1629 // this location. The relocation applied at link time will
1630 // apply the link-time value, so we flag the location with
1631 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1632 // relocate it easily.
1633 if (parameters
->options().output_is_position_independent())
1635 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1636 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1637 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1638 output_section
, data_shndx
,
1639 reloc
.get_r_offset(),
1640 reloc
.get_r_addend());
1644 case elfcpp::R_SPARC_HIX22
:
1645 case elfcpp::R_SPARC_LOX10
:
1646 case elfcpp::R_SPARC_H44
:
1647 case elfcpp::R_SPARC_M44
:
1648 case elfcpp::R_SPARC_L44
:
1649 case elfcpp::R_SPARC_HH22
:
1650 case elfcpp::R_SPARC_HM10
:
1651 case elfcpp::R_SPARC_LM22
:
1652 case elfcpp::R_SPARC_UA64
:
1653 case elfcpp::R_SPARC_UA32
:
1654 case elfcpp::R_SPARC_UA16
:
1655 case elfcpp::R_SPARC_HI22
:
1656 case elfcpp::R_SPARC_LO10
:
1657 case elfcpp::R_SPARC_OLO10
:
1658 case elfcpp::R_SPARC_16
:
1659 case elfcpp::R_SPARC_11
:
1660 case elfcpp::R_SPARC_10
:
1661 case elfcpp::R_SPARC_8
:
1662 case elfcpp::R_SPARC_7
:
1663 case elfcpp::R_SPARC_6
:
1664 case elfcpp::R_SPARC_5
:
1665 // If building a shared library (or a position-independent
1666 // executable), we need to create a dynamic relocation for
1668 if (parameters
->options().output_is_position_independent())
1670 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1672 check_non_pic(object
, r_type
);
1673 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1675 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1676 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1677 data_shndx
, reloc
.get_r_offset(),
1678 reloc
.get_r_addend());
1682 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1683 gold_assert(lsym
.get_st_value() == 0);
1684 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1685 output_section
, data_shndx
,
1686 reloc
.get_r_offset(),
1687 reloc
.get_r_addend());
1692 case elfcpp::R_SPARC_WDISP30
:
1693 case elfcpp::R_SPARC_WDISP22
:
1694 case elfcpp::R_SPARC_WDISP19
:
1695 case elfcpp::R_SPARC_WDISP16
:
1696 case elfcpp::R_SPARC_DISP8
:
1697 case elfcpp::R_SPARC_DISP16
:
1698 case elfcpp::R_SPARC_DISP32
:
1699 case elfcpp::R_SPARC_DISP64
:
1700 case elfcpp::R_SPARC_PC10
:
1701 case elfcpp::R_SPARC_PC22
:
1704 case elfcpp::R_SPARC_GOT10
:
1705 case elfcpp::R_SPARC_GOT13
:
1706 case elfcpp::R_SPARC_GOT22
:
1708 // The symbol requires a GOT entry.
1709 Output_data_got
<size
, big_endian
>* got
;
1712 got
= target
->got_section(symtab
, layout
);
1713 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1715 // If we are generating a shared object, we need to add a
1716 // dynamic relocation for this symbol's GOT entry.
1717 if (parameters
->options().output_is_position_independent())
1719 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1721 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1724 off
= got
->add_constant(0);
1725 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1726 rela_dyn
->add_local_relative(object
, r_sym
,
1727 elfcpp::R_SPARC_RELATIVE
,
1732 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1736 // These are initial TLS relocs, which are expected when
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 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1743 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1744 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1745 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1746 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1747 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1748 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1749 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1750 case elfcpp::R_SPARC_TLS_IE_LO10
:
1751 case elfcpp::R_SPARC_TLS_IE_LD
:
1752 case elfcpp::R_SPARC_TLS_IE_LDX
:
1753 case elfcpp::R_SPARC_TLS_IE_ADD
:
1754 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1755 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1757 bool output_is_shared
= parameters
->options().shared();
1758 const tls::Tls_optimization optimized_type
1759 = optimize_tls_reloc(!output_is_shared
, r_type
);
1762 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1763 case elfcpp::R_SPARC_TLS_GD_LO10
:
1764 case elfcpp::R_SPARC_TLS_GD_ADD
:
1765 case elfcpp::R_SPARC_TLS_GD_CALL
:
1766 if (optimized_type
== tls::TLSOPT_NONE
)
1768 // Create a pair of GOT entries for the module index and
1769 // dtv-relative offset.
1770 Output_data_got
<size
, big_endian
>* got
1771 = target
->got_section(symtab
, layout
);
1772 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1773 unsigned int shndx
= lsym
.get_st_shndx();
1775 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1777 object
->error(_("local symbol %u has bad shndx %u"),
1780 got
->add_local_pair_with_rela(object
, r_sym
,
1781 lsym
.get_st_shndx(),
1783 target
->rela_dyn_section(layout
),
1785 ? elfcpp::R_SPARC_TLS_DTPMOD64
1786 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1788 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1789 generate_tls_call(symtab
, layout
, target
);
1791 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1792 unsupported_reloc_local(object
, r_type
);
1795 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1796 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1797 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1798 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1799 if (optimized_type
== tls::TLSOPT_NONE
)
1801 // Create a GOT entry for the module index.
1802 target
->got_mod_index_entry(symtab
, layout
, object
);
1804 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1805 generate_tls_call(symtab
, layout
, target
);
1807 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1808 unsupported_reloc_local(object
, r_type
);
1811 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1812 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1813 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1816 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1817 case elfcpp::R_SPARC_TLS_IE_LO10
:
1818 case elfcpp::R_SPARC_TLS_IE_LD
:
1819 case elfcpp::R_SPARC_TLS_IE_LDX
:
1820 case elfcpp::R_SPARC_TLS_IE_ADD
:
1821 layout
->set_has_static_tls();
1822 if (optimized_type
== tls::TLSOPT_NONE
)
1824 // Create a GOT entry for the tp-relative offset.
1825 Output_data_got
<size
, big_endian
>* got
1826 = target
->got_section(symtab
, layout
);
1827 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1829 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1831 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1832 unsigned int off
= got
->add_constant(0);
1834 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1836 rela_dyn
->add_local_relative(object
, r_sym
,
1838 elfcpp::R_SPARC_TLS_TPOFF64
:
1839 elfcpp::R_SPARC_TLS_TPOFF32
),
1843 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1844 unsupported_reloc_local(object
, r_type
);
1847 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1848 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1849 layout
->set_has_static_tls();
1850 if (output_is_shared
)
1852 // We need to create a dynamic relocation.
1853 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1854 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1855 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1856 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1857 output_section
, data_shndx
,
1858 reloc
.get_r_offset(), 0);
1865 // These are relocations which should only be seen by the
1866 // dynamic linker, and should never be seen here.
1867 case elfcpp::R_SPARC_COPY
:
1868 case elfcpp::R_SPARC_GLOB_DAT
:
1869 case elfcpp::R_SPARC_JMP_SLOT
:
1870 case elfcpp::R_SPARC_RELATIVE
:
1871 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1872 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1873 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1874 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1875 case elfcpp::R_SPARC_TLS_TPOFF64
:
1876 case elfcpp::R_SPARC_TLS_TPOFF32
:
1877 gold_error(_("%s: unexpected reloc %u in object file"),
1878 object
->name().c_str(), r_type
);
1882 unsupported_reloc_local(object
, r_type
);
1887 // Report an unsupported relocation against a global symbol.
1889 template<int size
, bool big_endian
>
1891 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1892 Sized_relobj
<size
, big_endian
>* object
,
1893 unsigned int r_type
,
1896 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1897 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1900 // Scan a relocation for a global symbol.
1902 template<int size
, bool big_endian
>
1904 Target_sparc
<size
, big_endian
>::Scan::global(
1905 const General_options
&,
1906 Symbol_table
* symtab
,
1908 Target_sparc
<size
, big_endian
>* target
,
1909 Sized_relobj
<size
, big_endian
>* object
,
1910 unsigned int data_shndx
,
1911 Output_section
* output_section
,
1912 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1913 unsigned int r_type
,
1916 unsigned int orig_r_type
= r_type
;
1918 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
1919 // section. We check here to avoid creating a dynamic reloc against
1920 // _GLOBAL_OFFSET_TABLE_.
1921 if (!target
->has_got_section()
1922 && strcmp(gsym
->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
1923 target
->got_section(symtab
, layout
);
1928 case elfcpp::R_SPARC_NONE
:
1929 case elfcpp::R_SPARC_REGISTER
:
1930 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1931 case elfcpp::R_SPARC_GNU_VTENTRY
:
1934 case elfcpp::R_SPARC_PLT64
:
1935 case elfcpp::R_SPARC_PLT32
:
1936 case elfcpp::R_SPARC_HIPLT22
:
1937 case elfcpp::R_SPARC_LOPLT10
:
1938 case elfcpp::R_SPARC_PCPLT32
:
1939 case elfcpp::R_SPARC_PCPLT22
:
1940 case elfcpp::R_SPARC_PCPLT10
:
1941 case elfcpp::R_SPARC_WPLT30
:
1942 // If the symbol is fully resolved, this is just a PC32 reloc.
1943 // Otherwise we need a PLT entry.
1944 if (gsym
->final_value_is_known())
1946 // If building a shared library, we can also skip the PLT entry
1947 // if the symbol is defined in the output file and is protected
1949 if (gsym
->is_defined()
1950 && !gsym
->is_from_dynobj()
1951 && !gsym
->is_preemptible())
1953 target
->make_plt_entry(symtab
, layout
, gsym
);
1956 case elfcpp::R_SPARC_DISP8
:
1957 case elfcpp::R_SPARC_DISP16
:
1958 case elfcpp::R_SPARC_DISP32
:
1959 case elfcpp::R_SPARC_DISP64
:
1960 case elfcpp::R_SPARC_PC_HH22
:
1961 case elfcpp::R_SPARC_PC_HM10
:
1962 case elfcpp::R_SPARC_PC_LM22
:
1963 case elfcpp::R_SPARC_PC10
:
1964 case elfcpp::R_SPARC_PC22
:
1965 case elfcpp::R_SPARC_WDISP30
:
1966 case elfcpp::R_SPARC_WDISP22
:
1967 case elfcpp::R_SPARC_WDISP19
:
1968 case elfcpp::R_SPARC_WDISP16
:
1970 if (gsym
->needs_plt_entry())
1971 target
->make_plt_entry(symtab
, layout
, gsym
);
1972 // Make a dynamic relocation if necessary.
1973 int flags
= Symbol::NON_PIC_REF
;
1974 if (gsym
->type() == elfcpp::STT_FUNC
)
1975 flags
|= Symbol::FUNCTION_CALL
;
1976 if (gsym
->needs_dynamic_reloc(flags
))
1978 if (target
->may_need_copy_reloc(gsym
))
1980 target
->copy_reloc(symtab
, layout
, object
,
1981 data_shndx
, output_section
, gsym
,
1986 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1987 check_non_pic(object
, r_type
);
1988 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1989 data_shndx
, reloc
.get_r_offset(),
1990 reloc
.get_r_addend());
1996 case elfcpp::R_SPARC_UA64
:
1997 case elfcpp::R_SPARC_64
:
1998 case elfcpp::R_SPARC_HIX22
:
1999 case elfcpp::R_SPARC_LOX10
:
2000 case elfcpp::R_SPARC_H44
:
2001 case elfcpp::R_SPARC_M44
:
2002 case elfcpp::R_SPARC_L44
:
2003 case elfcpp::R_SPARC_HH22
:
2004 case elfcpp::R_SPARC_HM10
:
2005 case elfcpp::R_SPARC_LM22
:
2006 case elfcpp::R_SPARC_HI22
:
2007 case elfcpp::R_SPARC_LO10
:
2008 case elfcpp::R_SPARC_OLO10
:
2009 case elfcpp::R_SPARC_UA32
:
2010 case elfcpp::R_SPARC_32
:
2011 case elfcpp::R_SPARC_UA16
:
2012 case elfcpp::R_SPARC_16
:
2013 case elfcpp::R_SPARC_11
:
2014 case elfcpp::R_SPARC_10
:
2015 case elfcpp::R_SPARC_8
:
2016 case elfcpp::R_SPARC_7
:
2017 case elfcpp::R_SPARC_6
:
2018 case elfcpp::R_SPARC_5
:
2020 // Make a PLT entry if necessary.
2021 if (gsym
->needs_plt_entry())
2023 target
->make_plt_entry(symtab
, layout
, gsym
);
2024 // Since this is not a PC-relative relocation, we may be
2025 // taking the address of a function. In that case we need to
2026 // set the entry in the dynamic symbol table to the address of
2028 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2029 gsym
->set_needs_dynsym_value();
2031 // Make a dynamic relocation if necessary.
2032 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2034 if (target
->may_need_copy_reloc(gsym
))
2036 target
->copy_reloc(symtab
, layout
, object
,
2037 data_shndx
, output_section
, gsym
, reloc
);
2039 else if ((r_type
== elfcpp::R_SPARC_32
2040 || r_type
== elfcpp::R_SPARC_64
)
2041 && gsym
->can_use_relative_reloc(false))
2043 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2044 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2045 output_section
, object
,
2046 data_shndx
, reloc
.get_r_offset(),
2047 reloc
.get_r_addend());
2051 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2053 check_non_pic(object
, r_type
);
2054 if (gsym
->is_from_dynobj()
2055 || gsym
->is_undefined()
2056 || gsym
->is_preemptible())
2057 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2059 reloc
.get_r_offset(),
2060 reloc
.get_r_addend());
2062 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2063 output_section
, object
,
2065 reloc
.get_r_offset(),
2066 reloc
.get_r_addend());
2072 case elfcpp::R_SPARC_GOT10
:
2073 case elfcpp::R_SPARC_GOT13
:
2074 case elfcpp::R_SPARC_GOT22
:
2076 // The symbol requires a GOT entry.
2077 Output_data_got
<size
, big_endian
>* got
;
2079 got
= target
->got_section(symtab
, layout
);
2080 if (gsym
->final_value_is_known())
2081 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2084 // If this symbol is not fully resolved, we need to add a
2085 // dynamic relocation for it.
2086 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2087 if (gsym
->is_from_dynobj()
2088 || gsym
->is_undefined()
2089 || gsym
->is_preemptible())
2090 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2091 elfcpp::R_SPARC_GLOB_DAT
);
2092 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2094 unsigned int off
= got
->add_constant(0);
2096 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2097 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2104 // These are initial tls relocs, which are expected when
2106 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2107 case elfcpp::R_SPARC_TLS_GD_LO10
:
2108 case elfcpp::R_SPARC_TLS_GD_ADD
:
2109 case elfcpp::R_SPARC_TLS_GD_CALL
:
2110 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2111 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2112 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2113 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2114 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2115 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2116 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2117 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2118 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2119 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2120 case elfcpp::R_SPARC_TLS_IE_LO10
:
2121 case elfcpp::R_SPARC_TLS_IE_LD
:
2122 case elfcpp::R_SPARC_TLS_IE_LDX
:
2123 case elfcpp::R_SPARC_TLS_IE_ADD
:
2125 const bool is_final
= gsym
->final_value_is_known();
2126 const tls::Tls_optimization optimized_type
2127 = optimize_tls_reloc(is_final
, r_type
);
2130 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2131 case elfcpp::R_SPARC_TLS_GD_LO10
:
2132 case elfcpp::R_SPARC_TLS_GD_ADD
:
2133 case elfcpp::R_SPARC_TLS_GD_CALL
:
2134 if (optimized_type
== tls::TLSOPT_NONE
)
2136 // Create a pair of GOT entries for the module index and
2137 // dtv-relative offset.
2138 Output_data_got
<size
, big_endian
>* got
2139 = target
->got_section(symtab
, layout
);
2140 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2141 target
->rela_dyn_section(layout
),
2143 elfcpp::R_SPARC_TLS_DTPMOD64
:
2144 elfcpp::R_SPARC_TLS_DTPMOD32
),
2146 elfcpp::R_SPARC_TLS_DTPOFF64
:
2147 elfcpp::R_SPARC_TLS_DTPOFF32
));
2149 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2150 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2151 generate_tls_call(symtab
, layout
, target
);
2153 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2155 // Create a GOT entry for the tp-relative offset.
2156 Output_data_got
<size
, big_endian
>* got
2157 = target
->got_section(symtab
, layout
);
2158 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2159 target
->rela_dyn_section(layout
),
2161 elfcpp::R_SPARC_TLS_TPOFF64
:
2162 elfcpp::R_SPARC_TLS_TPOFF32
));
2164 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2165 unsupported_reloc_global(object
, r_type
, gsym
);
2168 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2169 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2170 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2171 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2172 if (optimized_type
== tls::TLSOPT_NONE
)
2174 // Create a GOT entry for the module index.
2175 target
->got_mod_index_entry(symtab
, layout
, object
);
2177 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2178 generate_tls_call(symtab
, layout
, target
);
2180 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2181 unsupported_reloc_global(object
, r_type
, gsym
);
2184 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2185 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2186 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2189 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2190 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2191 layout
->set_has_static_tls();
2192 if (parameters
->options().shared())
2194 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2195 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2196 output_section
, object
,
2197 data_shndx
, reloc
.get_r_offset(),
2202 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2203 case elfcpp::R_SPARC_TLS_IE_LO10
:
2204 case elfcpp::R_SPARC_TLS_IE_LD
:
2205 case elfcpp::R_SPARC_TLS_IE_LDX
:
2206 case elfcpp::R_SPARC_TLS_IE_ADD
:
2207 layout
->set_has_static_tls();
2208 if (optimized_type
== tls::TLSOPT_NONE
)
2210 // Create a GOT entry for the tp-relative offset.
2211 Output_data_got
<size
, big_endian
>* got
2212 = target
->got_section(symtab
, layout
);
2213 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2214 target
->rela_dyn_section(layout
),
2216 elfcpp::R_SPARC_TLS_TPOFF64
:
2217 elfcpp::R_SPARC_TLS_TPOFF32
));
2219 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2220 unsupported_reloc_global(object
, r_type
, gsym
);
2226 // These are relocations which should only be seen by the
2227 // dynamic linker, and should never be seen here.
2228 case elfcpp::R_SPARC_COPY
:
2229 case elfcpp::R_SPARC_GLOB_DAT
:
2230 case elfcpp::R_SPARC_JMP_SLOT
:
2231 case elfcpp::R_SPARC_RELATIVE
:
2232 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2233 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2234 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2235 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2236 case elfcpp::R_SPARC_TLS_TPOFF64
:
2237 case elfcpp::R_SPARC_TLS_TPOFF32
:
2238 gold_error(_("%s: unexpected reloc %u in object file"),
2239 object
->name().c_str(), r_type
);
2243 unsupported_reloc_global(object
, r_type
, gsym
);
2248 // Process relocations for gc.
2250 template<int size
, bool big_endian
>
2252 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2253 const General_options
& options
,
2254 Symbol_table
* symtab
,
2256 Sized_relobj
<size
, big_endian
>* object
,
2257 unsigned int data_shndx
,
2259 const unsigned char* prelocs
,
2261 Output_section
* output_section
,
2262 bool needs_special_offset_handling
,
2263 size_t local_symbol_count
,
2264 const unsigned char* plocal_symbols
)
2266 typedef Target_sparc
<size
, big_endian
> Sparc
;
2267 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2269 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2279 needs_special_offset_handling
,
2284 // Scan relocations for a section.
2286 template<int size
, bool big_endian
>
2288 Target_sparc
<size
, big_endian
>::scan_relocs(
2289 const General_options
& options
,
2290 Symbol_table
* symtab
,
2292 Sized_relobj
<size
, big_endian
>* object
,
2293 unsigned int data_shndx
,
2294 unsigned int sh_type
,
2295 const unsigned char* prelocs
,
2297 Output_section
* output_section
,
2298 bool needs_special_offset_handling
,
2299 size_t local_symbol_count
,
2300 const unsigned char* plocal_symbols
)
2302 typedef Target_sparc
<size
, big_endian
> Sparc
;
2303 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2305 if (sh_type
== elfcpp::SHT_REL
)
2307 gold_error(_("%s: unsupported REL reloc section"),
2308 object
->name().c_str());
2312 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2322 needs_special_offset_handling
,
2327 // Finalize the sections.
2329 template<int size
, bool big_endian
>
2331 Target_sparc
<size
, big_endian
>::do_finalize_sections(Layout
* layout
)
2333 // Fill in some more dynamic tags.
2334 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2337 if (this->plt_
!= NULL
)
2339 const Output_data
* od
= this->plt_
->rel_plt();
2340 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2341 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2342 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2344 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2347 if (this->rela_dyn_
!= NULL
)
2349 const Output_data
* od
= this->rela_dyn_
;
2350 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2351 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2352 odyn
->add_constant(elfcpp::DT_RELAENT
,
2353 elfcpp::Elf_sizes
<size
>::rela_size
);
2356 if (!parameters
->options().shared())
2358 // The value of the DT_DEBUG tag is filled in by the dynamic
2359 // linker at run time, and used by the debugger.
2360 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2364 // Emit any relocs we saved in an attempt to avoid generating COPY
2366 if (this->copy_relocs_
.any_saved_relocs())
2367 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2370 // Perform a relocation.
2372 template<int size
, bool big_endian
>
2374 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2375 const Relocate_info
<size
, big_endian
>* relinfo
,
2376 Target_sparc
* target
,
2379 const elfcpp::Rela
<size
, big_endian
>& rela
,
2380 unsigned int r_type
,
2381 const Sized_symbol
<size
>* gsym
,
2382 const Symbol_value
<size
>* psymval
,
2383 unsigned char* view
,
2384 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2385 section_size_type view_size
)
2389 if (this->ignore_gd_add_
)
2391 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2392 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2393 _("missing expected TLS relocation"));
2396 this->ignore_gd_add_
= false;
2401 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2403 // Pick the value to use for symbols defined in shared objects.
2404 Symbol_value
<size
> symval
;
2406 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2407 || r_type
== elfcpp::R_SPARC_DISP16
2408 || r_type
== elfcpp::R_SPARC_DISP32
2409 || r_type
== elfcpp::R_SPARC_DISP64
2410 || r_type
== elfcpp::R_SPARC_PC_HH22
2411 || r_type
== elfcpp::R_SPARC_PC_HM10
2412 || r_type
== elfcpp::R_SPARC_PC_LM22
2413 || r_type
== elfcpp::R_SPARC_PC10
2414 || r_type
== elfcpp::R_SPARC_PC22
2415 || r_type
== elfcpp::R_SPARC_WDISP30
2416 || r_type
== elfcpp::R_SPARC_WDISP22
2417 || r_type
== elfcpp::R_SPARC_WDISP19
2418 || r_type
== elfcpp::R_SPARC_WDISP16
))
2420 elfcpp::Elf_Xword value
;
2422 value
= target
->plt_section()->address() + gsym
->plt_offset();
2424 symval
.set_output_value(value
);
2429 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2430 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2432 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2433 // pointer points to the beginning, not the end, of the table.
2434 // So we just use the plain offset.
2435 bool have_got_offset
= false;
2436 unsigned int got_offset
= 0;
2439 case elfcpp::R_SPARC_GOT10
:
2440 case elfcpp::R_SPARC_GOT13
:
2441 case elfcpp::R_SPARC_GOT22
:
2444 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2445 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2449 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2450 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2451 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2453 have_got_offset
= true;
2462 case elfcpp::R_SPARC_NONE
:
2463 case elfcpp::R_SPARC_REGISTER
:
2464 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2465 case elfcpp::R_SPARC_GNU_VTENTRY
:
2468 case elfcpp::R_SPARC_8
:
2469 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2473 case elfcpp::R_SPARC_16
:
2474 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2478 case elfcpp::R_SPARC_32
:
2479 if (!parameters
->options().output_is_position_independent())
2480 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2484 case elfcpp::R_SPARC_DISP8
:
2485 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2488 case elfcpp::R_SPARC_DISP16
:
2489 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2492 case elfcpp::R_SPARC_DISP32
:
2493 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2496 case elfcpp::R_SPARC_DISP64
:
2497 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2500 case elfcpp::R_SPARC_WDISP30
:
2501 case elfcpp::R_SPARC_WPLT30
:
2502 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2505 case elfcpp::R_SPARC_WDISP22
:
2506 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2509 case elfcpp::R_SPARC_WDISP19
:
2510 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2513 case elfcpp::R_SPARC_WDISP16
:
2514 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2517 case elfcpp::R_SPARC_HI22
:
2518 Reloc::hi22(view
, object
, psymval
, addend
);
2521 case elfcpp::R_SPARC_22
:
2522 Reloc::rela32_22(view
, object
, psymval
, addend
);
2525 case elfcpp::R_SPARC_13
:
2526 Reloc::rela32_13(view
, object
, psymval
, addend
);
2529 case elfcpp::R_SPARC_LO10
:
2530 Reloc::lo10(view
, object
, psymval
, addend
);
2533 case elfcpp::R_SPARC_GOT10
:
2534 Reloc::lo10(view
, got_offset
, addend
);
2537 case elfcpp::R_SPARC_GOT13
:
2538 Reloc::rela32_13(view
, got_offset
, addend
);
2541 case elfcpp::R_SPARC_GOT22
:
2542 Reloc::hi22(view
, got_offset
, addend
);
2545 case elfcpp::R_SPARC_PC10
:
2546 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2549 case elfcpp::R_SPARC_PC22
:
2550 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2553 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2554 case elfcpp::R_SPARC_UA32
:
2555 Reloc::ua32(view
, object
, psymval
, addend
);
2558 case elfcpp::R_SPARC_PLT64
:
2559 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2563 case elfcpp::R_SPARC_PLT32
:
2564 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2568 case elfcpp::R_SPARC_HIPLT22
:
2569 Reloc::hi22(view
, object
, psymval
, addend
);
2572 case elfcpp::R_SPARC_LOPLT10
:
2573 Reloc::lo10(view
, object
, psymval
, addend
);
2576 case elfcpp::R_SPARC_PCPLT32
:
2577 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2580 case elfcpp::R_SPARC_PCPLT22
:
2581 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2584 case elfcpp::R_SPARC_PCPLT10
:
2585 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2588 case elfcpp::R_SPARC_64
:
2589 if (!parameters
->options().output_is_position_independent())
2590 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2594 case elfcpp::R_SPARC_OLO10
:
2596 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2597 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2598 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2602 case elfcpp::R_SPARC_HH22
:
2603 Reloc::hh22(view
, object
, psymval
, addend
);
2606 case elfcpp::R_SPARC_PC_HH22
:
2607 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2610 case elfcpp::R_SPARC_HM10
:
2611 Reloc::hm10(view
, object
, psymval
, addend
);
2614 case elfcpp::R_SPARC_PC_HM10
:
2615 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2618 case elfcpp::R_SPARC_LM22
:
2619 Reloc::hi22(view
, object
, psymval
, addend
);
2622 case elfcpp::R_SPARC_PC_LM22
:
2623 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2626 case elfcpp::R_SPARC_11
:
2627 Reloc::rela32_11(view
, object
, psymval
, addend
);
2630 case elfcpp::R_SPARC_10
:
2631 Reloc::rela32_10(view
, object
, psymval
, addend
);
2634 case elfcpp::R_SPARC_7
:
2635 Reloc::rela32_7(view
, object
, psymval
, addend
);
2638 case elfcpp::R_SPARC_6
:
2639 Reloc::rela32_6(view
, object
, psymval
, addend
);
2642 case elfcpp::R_SPARC_5
:
2643 Reloc::rela32_5(view
, object
, psymval
, addend
);
2646 case elfcpp::R_SPARC_HIX22
:
2647 Reloc::hix22(view
, object
, psymval
, addend
);
2650 case elfcpp::R_SPARC_LOX10
:
2651 Reloc::lox10(view
, object
, psymval
, addend
);
2654 case elfcpp::R_SPARC_H44
:
2655 Reloc::h44(view
, object
, psymval
, addend
);
2658 case elfcpp::R_SPARC_M44
:
2659 Reloc::m44(view
, object
, psymval
, addend
);
2662 case elfcpp::R_SPARC_L44
:
2663 Reloc::l44(view
, object
, psymval
, addend
);
2666 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2667 case elfcpp::R_SPARC_UA64
:
2668 Reloc::ua64(view
, object
, psymval
, addend
);
2671 case elfcpp::R_SPARC_UA16
:
2672 Reloc::ua16(view
, object
, psymval
, addend
);
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 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2680 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2681 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2682 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2683 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2684 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2685 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2686 case elfcpp::R_SPARC_TLS_IE_HI22
:
2687 case elfcpp::R_SPARC_TLS_IE_LO10
:
2688 case elfcpp::R_SPARC_TLS_IE_LD
:
2689 case elfcpp::R_SPARC_TLS_IE_LDX
:
2690 case elfcpp::R_SPARC_TLS_IE_ADD
:
2691 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2692 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2693 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2694 r_type
, gsym
, psymval
, view
,
2695 address
, view_size
);
2698 case elfcpp::R_SPARC_COPY
:
2699 case elfcpp::R_SPARC_GLOB_DAT
:
2700 case elfcpp::R_SPARC_JMP_SLOT
:
2701 case elfcpp::R_SPARC_RELATIVE
:
2702 // These are outstanding tls relocs, which are unexpected when
2704 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2705 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2706 case elfcpp::R_SPARC_TLS_TPOFF64
:
2707 case elfcpp::R_SPARC_TLS_TPOFF32
:
2708 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2709 _("unexpected reloc %u in object file"),
2714 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2715 _("unsupported reloc %u"),
2723 // Perform a TLS relocation.
2725 template<int size
, bool big_endian
>
2727 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2728 const Relocate_info
<size
, big_endian
>* relinfo
,
2729 Target_sparc
<size
, big_endian
>* target
,
2731 const elfcpp::Rela
<size
, big_endian
>& rela
,
2732 unsigned int r_type
,
2733 const Sized_symbol
<size
>* gsym
,
2734 const Symbol_value
<size
>* psymval
,
2735 unsigned char* view
,
2736 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2739 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2740 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2741 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2742 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2744 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2745 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2747 const bool is_final
=
2749 ? !parameters
->options().output_is_position_independent()
2750 : gsym
->final_value_is_known());
2751 const tls::Tls_optimization optimized_type
2752 = optimize_tls_reloc(is_final
, r_type
);
2756 case elfcpp::R_SPARC_TLS_GD_HI22
:
2757 case elfcpp::R_SPARC_TLS_GD_LO10
:
2758 case elfcpp::R_SPARC_TLS_GD_ADD
:
2759 case elfcpp::R_SPARC_TLS_GD_CALL
:
2760 if (optimized_type
== tls::TLSOPT_TO_LE
)
2762 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2765 value
-= tls_segment
->memsz();
2769 case elfcpp::R_SPARC_TLS_GD_HI22
:
2770 // TLS_GD_HI22 --> TLS_LE_HIX22
2771 Reloc::hix22(view
, value
, addend
);
2774 case elfcpp::R_SPARC_TLS_GD_LO10
:
2775 // TLS_GD_LO10 --> TLS_LE_LOX10
2776 Reloc::lox10(view
, value
, addend
);
2779 case elfcpp::R_SPARC_TLS_GD_ADD
:
2780 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2781 val
= elfcpp::Swap
<32, true>::readval(wv
);
2782 val
= (val
& ~0x7c000) | 0x1c000;
2783 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2785 case elfcpp::R_SPARC_TLS_GD_CALL
:
2786 // call __tls_get_addr --> nop
2787 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2794 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2795 ? GOT_TYPE_TLS_OFFSET
2796 : GOT_TYPE_TLS_PAIR
);
2799 gold_assert(gsym
->has_got_offset(got_type
));
2800 value
= gsym
->got_offset(got_type
);
2804 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2805 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2806 value
= object
->local_got_offset(r_sym
, got_type
);
2808 if (optimized_type
== tls::TLSOPT_TO_IE
)
2810 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2815 case elfcpp::R_SPARC_TLS_GD_HI22
:
2816 // TLS_GD_HI22 --> TLS_IE_HI22
2817 Reloc::hi22(view
, value
, addend
);
2820 case elfcpp::R_SPARC_TLS_GD_LO10
:
2821 // TLS_GD_LO10 --> TLS_IE_LO10
2822 Reloc::lo10(view
, value
, addend
);
2825 case elfcpp::R_SPARC_TLS_GD_ADD
:
2826 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2827 val
= elfcpp::Swap
<32, true>::readval(wv
);
2834 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2837 case elfcpp::R_SPARC_TLS_GD_CALL
:
2838 // The compiler can put the TLS_GD_ADD instruction
2839 // into the delay slot of the call. If so, we need
2840 // to transpose the two instructions so that the
2841 // the new sequence works properly.
2843 // The test we use is if the instruction in the
2844 // delay slot is an add with destination register
2846 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2847 if ((val
& 0x81f80000) == 0x80000000
2848 && ((val
>> 25) & 0x1f) == 0x8)
2855 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2858 this->ignore_gd_add_
= true;
2861 // call __tls_get_addr --> add %g7, %o0, %o0
2862 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2867 else if (optimized_type
== tls::TLSOPT_NONE
)
2871 case elfcpp::R_SPARC_TLS_GD_HI22
:
2872 Reloc::hi22(view
, value
, addend
);
2874 case elfcpp::R_SPARC_TLS_GD_LO10
:
2875 Reloc::lo10(view
, value
, addend
);
2877 case elfcpp::R_SPARC_TLS_GD_ADD
:
2879 case elfcpp::R_SPARC_TLS_GD_CALL
:
2881 Symbol_value
<size
> symval
;
2882 elfcpp::Elf_Xword value
;
2885 tsym
= target
->tls_get_addr_sym_
;
2887 value
= (target
->plt_section()->address() +
2888 tsym
->plt_offset());
2889 symval
.set_output_value(value
);
2890 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2897 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2898 _("unsupported reloc %u"),
2902 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2903 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2904 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2905 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2906 if (optimized_type
== tls::TLSOPT_TO_LE
)
2908 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2912 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2913 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2914 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2915 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2918 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2919 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2924 else if (optimized_type
== tls::TLSOPT_NONE
)
2926 // Relocate the field with the offset of the GOT entry for
2927 // the module index.
2928 unsigned int got_offset
;
2930 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2933 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2934 Reloc::hi22(view
, got_offset
, addend
);
2936 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2937 Reloc::lo10(view
, got_offset
, addend
);
2939 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2941 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2943 Symbol_value
<size
> symval
;
2944 elfcpp::Elf_Xword value
;
2947 tsym
= target
->tls_get_addr_sym_
;
2949 value
= (target
->plt_section()->address() +
2950 tsym
->plt_offset());
2951 symval
.set_output_value(value
);
2952 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2958 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2959 _("unsupported reloc %u"),
2963 // These relocs can appear in debugging sections, in which case
2964 // we won't see the TLS_LDM relocs. The local_dynamic_type
2965 // field tells us this.
2966 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2967 if (optimized_type
== tls::TLSOPT_TO_LE
)
2969 value
-= tls_segment
->memsz();
2970 Reloc::hix22(view
, value
, addend
);
2973 Reloc::ldo_hix22(view
, value
, addend
);
2975 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2976 if (optimized_type
== tls::TLSOPT_TO_LE
)
2978 value
-= tls_segment
->memsz();
2979 Reloc::lox10(view
, value
, addend
);
2982 Reloc::ldo_lox10(view
, value
, addend
);
2984 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2985 if (optimized_type
== tls::TLSOPT_TO_LE
)
2987 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2990 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2991 val
= elfcpp::Swap
<32, true>::readval(wv
);
2992 val
= (val
& ~0x7c000) | 0x1c000;
2993 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2997 // When optimizing IE --> LE, the only relocation that is handled
2998 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2999 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
3000 // rs2 and rd are the same.
3001 case elfcpp::R_SPARC_TLS_IE_LD
:
3002 case elfcpp::R_SPARC_TLS_IE_LDX
:
3003 if (optimized_type
== tls::TLSOPT_TO_LE
)
3005 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
3006 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
3007 Insntype rs2
= val
& 0x1f;
3008 Insntype rd
= (val
>> 25) & 0x1f;
3013 val
= sparc_mov
| (val
& 0x3e00001f);
3015 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3019 case elfcpp::R_SPARC_TLS_IE_HI22
:
3020 case elfcpp::R_SPARC_TLS_IE_LO10
:
3021 if (optimized_type
== tls::TLSOPT_TO_LE
)
3023 value
-= tls_segment
->memsz();
3026 case elfcpp::R_SPARC_TLS_IE_HI22
:
3027 // IE_HI22 --> LE_HIX22
3028 Reloc::hix22(view
, value
, addend
);
3030 case elfcpp::R_SPARC_TLS_IE_LO10
:
3031 // IE_LO10 --> LE_LOX10
3032 Reloc::lox10(view
, value
, addend
);
3037 else if (optimized_type
== tls::TLSOPT_NONE
)
3039 // Relocate the field with the offset of the GOT entry for
3040 // the tp-relative offset of the symbol.
3043 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3044 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3048 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3049 gold_assert(object
->local_has_got_offset(r_sym
,
3050 GOT_TYPE_TLS_OFFSET
));
3051 value
= object
->local_got_offset(r_sym
,
3052 GOT_TYPE_TLS_OFFSET
);
3056 case elfcpp::R_SPARC_TLS_IE_HI22
:
3057 Reloc::hi22(view
, value
, addend
);
3059 case elfcpp::R_SPARC_TLS_IE_LO10
:
3060 Reloc::lo10(view
, value
, addend
);
3065 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3066 _("unsupported reloc %u"),
3070 case elfcpp::R_SPARC_TLS_IE_ADD
:
3071 // This seems to be mainly so that we can find the addition
3072 // instruction if there is one. There doesn't seem to be any
3073 // actual relocation to apply.
3076 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3077 // If we're creating a shared library, a dynamic relocation will
3078 // have been created for this location, so do not apply it now.
3079 if (!parameters
->options().shared())
3081 value
-= tls_segment
->memsz();
3082 Reloc::hix22(view
, value
, addend
);
3086 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3087 // If we're creating a shared library, a dynamic relocation will
3088 // have been created for this location, so do not apply it now.
3089 if (!parameters
->options().shared())
3091 value
-= tls_segment
->memsz();
3092 Reloc::lox10(view
, value
, addend
);
3098 // Relocate section data.
3100 template<int size
, bool big_endian
>
3102 Target_sparc
<size
, big_endian
>::relocate_section(
3103 const Relocate_info
<size
, big_endian
>* relinfo
,
3104 unsigned int sh_type
,
3105 const unsigned char* prelocs
,
3107 Output_section
* output_section
,
3108 bool needs_special_offset_handling
,
3109 unsigned char* view
,
3110 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3111 section_size_type view_size
)
3113 typedef Target_sparc
<size
, big_endian
> Sparc
;
3114 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3116 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3118 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3125 needs_special_offset_handling
,
3131 // Return the size of a relocation while scanning during a relocatable
3134 template<int size
, bool big_endian
>
3136 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3140 // We are always SHT_RELA, so we should never get here.
3145 // Scan the relocs during a relocatable link.
3147 template<int size
, bool big_endian
>
3149 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3150 const General_options
& options
,
3151 Symbol_table
* symtab
,
3153 Sized_relobj
<size
, big_endian
>* object
,
3154 unsigned int data_shndx
,
3155 unsigned int sh_type
,
3156 const unsigned char* prelocs
,
3158 Output_section
* output_section
,
3159 bool needs_special_offset_handling
,
3160 size_t local_symbol_count
,
3161 const unsigned char* plocal_symbols
,
3162 Relocatable_relocs
* rr
)
3164 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3166 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3167 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3169 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3170 Scan_relocatable_relocs
>(
3179 needs_special_offset_handling
,
3185 // Relocate a section during a relocatable link.
3187 template<int size
, bool big_endian
>
3189 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3190 const Relocate_info
<size
, big_endian
>* relinfo
,
3191 unsigned int sh_type
,
3192 const unsigned char* prelocs
,
3194 Output_section
* output_section
,
3195 off_t offset_in_output_section
,
3196 const Relocatable_relocs
* rr
,
3197 unsigned char* view
,
3198 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3199 section_size_type view_size
,
3200 unsigned char* reloc_view
,
3201 section_size_type reloc_view_size
)
3203 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3205 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3210 offset_in_output_section
,
3219 // Return the value to use for a dynamic which requires special
3220 // treatment. This is how we support equality comparisons of function
3221 // pointers across shared library boundaries, as described in the
3222 // processor specific ABI supplement.
3224 template<int size
, bool big_endian
>
3226 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3228 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3229 return this->plt_section()->address() + gsym
->plt_offset();
3232 // The selector for sparc object files.
3234 template<int size
, bool big_endian
>
3235 class Target_selector_sparc
: public Target_selector
3238 Target_selector_sparc()
3239 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3240 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3243 Target
* do_recognize(int machine
, int, int)
3248 if (machine
!= elfcpp::EM_SPARCV9
)
3253 if (machine
!= elfcpp::EM_SPARC
3254 && machine
!= elfcpp::EM_SPARC32PLUS
)
3262 return this->instantiate_target();
3265 Target
* do_instantiate_target()
3266 { return new Target_sparc
<size
, big_endian
>(); }
3269 Target_selector_sparc
<32, true> target_selector_sparc32
;
3270 Target_selector_sparc
<64, true> target_selector_sparc64
;
3272 } // End anonymous namespace.