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 the size of the GOT section.
162 gold_assert(this->got_
!= NULL
);
163 return this->got_
->data_size();
168 // The class which scans relocations.
173 : issued_non_pic_error_(false)
177 local(const General_options
& options
, Symbol_table
* symtab
,
178 Layout
* layout
, Target_sparc
* target
,
179 Sized_relobj
<size
, big_endian
>* object
,
180 unsigned int data_shndx
,
181 Output_section
* output_section
,
182 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
183 const elfcpp::Sym
<size
, big_endian
>& lsym
);
186 global(const General_options
& options
, Symbol_table
* symtab
,
187 Layout
* layout
, Target_sparc
* target
,
188 Sized_relobj
<size
, big_endian
>* object
,
189 unsigned int data_shndx
,
190 Output_section
* output_section
,
191 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
196 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
197 unsigned int r_type
);
200 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
201 unsigned int r_type
, Symbol
*);
204 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
205 Target_sparc
* target
);
208 check_non_pic(Relobj
*, unsigned int r_type
);
210 // Whether we have issued an error about a non-PIC compilation.
211 bool issued_non_pic_error_
;
214 // The class which implements relocation.
219 : ignore_gd_add_(false)
224 if (this->ignore_gd_add_
)
226 // FIXME: This needs to specify the location somehow.
227 gold_error(_("missing expected TLS relocation"));
231 // Do a relocation. Return false if the caller should not issue
232 // any warnings about this relocation.
234 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
235 Output_section
*, size_t relnum
,
236 const elfcpp::Rela
<size
, big_endian
>&,
237 unsigned int r_type
, const Sized_symbol
<size
>*,
238 const Symbol_value
<size
>*,
240 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
244 // Do a TLS relocation.
246 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
247 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
248 unsigned int r_type
, const Sized_symbol
<size
>*,
249 const Symbol_value
<size
>*,
251 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
254 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
258 // A class which returns the size required for a relocation type,
259 // used while scanning relocs during a relocatable link.
260 class Relocatable_size_for_reloc
264 get_size_for_reloc(unsigned int, Relobj
*);
267 // Get the GOT section, creating it if necessary.
268 Output_data_got
<size
, big_endian
>*
269 got_section(Symbol_table
*, Layout
*);
271 // Create a PLT entry for a global symbol.
273 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
275 // Create a GOT entry for the TLS module index.
277 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
278 Sized_relobj
<size
, big_endian
>* object
);
280 // Return the gsym for "__tls_get_addr". Cache if not already
283 tls_get_addr_sym(Symbol_table
* symtab
)
285 if (!this->tls_get_addr_sym_
)
286 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
287 gold_assert(this->tls_get_addr_sym_
);
288 return this->tls_get_addr_sym_
;
291 // Get the PLT section.
292 const Output_data_plt_sparc
<size
, big_endian
>*
295 gold_assert(this->plt_
!= NULL
);
299 // Get the dynamic reloc section, creating it if necessary.
301 rela_dyn_section(Layout
*);
303 // Return true if the symbol may need a COPY relocation.
304 // References from an executable object to non-function symbols
305 // defined in a dynamic object may need a COPY relocation.
307 may_need_copy_reloc(Symbol
* gsym
)
309 return (!parameters
->options().shared()
310 && gsym
->is_from_dynobj()
311 && gsym
->type() != elfcpp::STT_FUNC
);
314 // Copy a relocation against a global symbol.
316 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
317 Sized_relobj
<size
, big_endian
>* object
,
318 unsigned int shndx
, Output_section
* output_section
,
319 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
321 this->copy_relocs_
.copy_reloc(symtab
, layout
,
322 symtab
->get_sized_symbol
<size
>(sym
),
323 object
, shndx
, output_section
,
324 reloc
, this->rela_dyn_section(layout
));
327 // Information about this specific target which we pass to the
328 // general Target structure.
329 static Target::Target_info sparc_info
;
331 // The types of GOT entries needed for this platform.
334 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
335 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
336 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
340 Output_data_got
<size
, big_endian
>* got_
;
342 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
343 // The dynamic reloc section.
344 Reloc_section
* rela_dyn_
;
345 // Relocs saved to avoid a COPY reloc.
346 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
347 // Space for variables copied with a COPY reloc.
348 Output_data_space
* dynbss_
;
349 // Offset of the GOT entry for the TLS module index;
350 unsigned int got_mod_index_offset_
;
351 // Cached pointer to __tls_get_addr symbol
352 Symbol
* tls_get_addr_sym_
;
356 Target::Target_info Target_sparc
<32, true>::sparc_info
=
359 true, // is_big_endian
360 elfcpp::EM_SPARC
, // 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/ld.so.1", // dynamic_linker
367 0x00010000, // 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)
373 Target::Target_info Target_sparc
<64, true>::sparc_info
=
376 true, // is_big_endian
377 elfcpp::EM_SPARCV9
, // machine_code
378 false, // has_make_symbol
379 false, // has_resolve
380 false, // has_code_fill
381 true, // is_default_stack_executable
383 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
384 0x100000, // default_text_segment_address
385 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
386 8 * 1024 // common_pagesize (overridable by -z common-page-size)
389 // We have to take care here, even when operating in little-endian
390 // mode, sparc instructions are still big endian.
391 template<int size
, bool big_endian
>
392 class Sparc_relocate_functions
395 // Do a simple relocation with the addend in the relocation.
396 template<int valsize
>
398 rela(unsigned char* view
,
399 unsigned int right_shift
,
400 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
401 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
402 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
404 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
405 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
406 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
407 Valtype reloc
= ((value
+ addend
) >> right_shift
);
412 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
415 // Do a simple relocation using a symbol value with the addend in
417 template<int valsize
>
419 rela(unsigned char* view
,
420 unsigned int right_shift
,
421 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
422 const Sized_relobj
<size
, big_endian
>* object
,
423 const Symbol_value
<size
>* psymval
,
424 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
426 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
427 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
428 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
429 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
434 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
437 // Do a simple relocation using a symbol value with the addend in
438 // the relocation, unaligned.
439 template<int valsize
>
441 rela_ua(unsigned char* view
,
442 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
443 const Sized_relobj
<size
, big_endian
>* object
,
444 const Symbol_value
<size
>* psymval
,
445 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
447 typedef typename
elfcpp::Swap_unaligned
<valsize
,
448 big_endian
>::Valtype Valtype
;
449 unsigned char* wv
= view
;
450 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
451 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
456 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
459 // Do a simple PC relative relocation with a Symbol_value with the
460 // addend in the relocation.
461 template<int valsize
>
463 pcrela(unsigned char* view
,
464 unsigned int right_shift
,
465 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
466 const Sized_relobj
<size
, big_endian
>* object
,
467 const Symbol_value
<size
>* psymval
,
468 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
469 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
471 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
472 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
473 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
474 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
480 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
483 template<int valsize
>
485 pcrela_unaligned(unsigned char* view
,
486 const Sized_relobj
<size
, big_endian
>* object
,
487 const Symbol_value
<size
>* psymval
,
488 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
489 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
491 typedef typename
elfcpp::Swap_unaligned
<valsize
,
492 big_endian
>::Valtype Valtype
;
493 unsigned char* wv
= view
;
494 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
496 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
499 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
500 typedef Sparc_relocate_functions
<size
, true> This_insn
;
503 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
505 wdisp30(unsigned char* view
,
506 const Sized_relobj
<size
, big_endian
>* object
,
507 const Symbol_value
<size
>* psymval
,
508 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
509 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
511 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
512 psymval
, addend
, address
);
515 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
517 wdisp22(unsigned char* view
,
518 const Sized_relobj
<size
, big_endian
>* object
,
519 const Symbol_value
<size
>* psymval
,
520 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
521 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
523 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
524 psymval
, addend
, address
);
527 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
529 wdisp19(unsigned char* view
,
530 const Sized_relobj
<size
, big_endian
>* object
,
531 const Symbol_value
<size
>* psymval
,
532 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
533 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
535 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
536 psymval
, addend
, address
);
539 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
541 wdisp16(unsigned char* view
,
542 const Sized_relobj
<size
, big_endian
>* object
,
543 const Symbol_value
<size
>* psymval
,
544 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
545 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
547 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
548 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
549 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
550 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
553 // The relocation value is split between the low 14 bits,
555 val
&= ~((0x3 << 20) | 0x3fff);
556 reloc
= (((reloc
& 0xc000) << (20 - 14))
557 | (reloc
& 0x3ffff));
559 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
562 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
564 pc22(unsigned char* view
,
565 const Sized_relobj
<size
, big_endian
>* object
,
566 const Symbol_value
<size
>* psymval
,
567 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
568 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
570 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
571 psymval
, addend
, address
);
574 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
576 pc10(unsigned char* view
,
577 const Sized_relobj
<size
, big_endian
>* object
,
578 const Symbol_value
<size
>* psymval
,
579 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
580 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
582 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
583 psymval
, addend
, address
);
586 // R_SPARC_HI22: (Symbol + Addend) >> 10
588 hi22(unsigned char* view
,
589 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
590 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
592 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
595 // R_SPARC_HI22: (Symbol + Addend) >> 10
597 hi22(unsigned char* view
,
598 const Sized_relobj
<size
, big_endian
>* object
,
599 const Symbol_value
<size
>* psymval
,
600 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
602 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
605 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
607 pcplt22(unsigned char* view
,
608 const Sized_relobj
<size
, big_endian
>* object
,
609 const Symbol_value
<size
>* psymval
,
610 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
611 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
613 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
614 psymval
, addend
, address
);
617 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
619 lo10(unsigned char* view
,
620 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
621 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
623 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
626 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
628 lo10(unsigned char* view
,
629 const Sized_relobj
<size
, big_endian
>* object
,
630 const Symbol_value
<size
>* psymval
,
631 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
633 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
636 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
638 lo10(unsigned char* view
,
639 const Sized_relobj
<size
, big_endian
>* object
,
640 const Symbol_value
<size
>* psymval
,
641 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
642 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
644 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
645 psymval
, addend
, address
);
648 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
650 olo10(unsigned char* view
,
651 const Sized_relobj
<size
, big_endian
>* object
,
652 const Symbol_value
<size
>* psymval
,
653 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
654 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
656 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
657 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
658 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
659 Valtype reloc
= psymval
->value(object
, addend
);
666 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
669 // R_SPARC_22: (Symbol + Addend)
671 rela32_22(unsigned char* view
,
672 const Sized_relobj
<size
, big_endian
>* object
,
673 const Symbol_value
<size
>* psymval
,
674 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
676 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
679 // R_SPARC_13: (Symbol + Addend)
681 rela32_13(unsigned char* view
,
682 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
683 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
685 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
688 // R_SPARC_13: (Symbol + Addend)
690 rela32_13(unsigned char* view
,
691 const Sized_relobj
<size
, big_endian
>* object
,
692 const Symbol_value
<size
>* psymval
,
693 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
695 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
698 // R_SPARC_UA16: (Symbol + Addend)
700 ua16(unsigned char* view
,
701 const Sized_relobj
<size
, big_endian
>* object
,
702 const Symbol_value
<size
>* psymval
,
703 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
705 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
708 // R_SPARC_UA32: (Symbol + Addend)
710 ua32(unsigned char* view
,
711 const Sized_relobj
<size
, big_endian
>* object
,
712 const Symbol_value
<size
>* psymval
,
713 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
715 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
718 // R_SPARC_UA64: (Symbol + Addend)
720 ua64(unsigned char* view
,
721 const Sized_relobj
<size
, big_endian
>* object
,
722 const Symbol_value
<size
>* psymval
,
723 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
725 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
726 object
, psymval
, addend
);
729 // R_SPARC_DISP8: (Symbol + Addend - Address)
731 disp8(unsigned char* view
,
732 const Sized_relobj
<size
, big_endian
>* object
,
733 const Symbol_value
<size
>* psymval
,
734 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
735 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
737 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
741 // R_SPARC_DISP16: (Symbol + Addend - Address)
743 disp16(unsigned char* view
,
744 const Sized_relobj
<size
, big_endian
>* object
,
745 const Symbol_value
<size
>* psymval
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
747 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
749 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
753 // R_SPARC_DISP32: (Symbol + Addend - Address)
755 disp32(unsigned char* view
,
756 const Sized_relobj
<size
, big_endian
>* object
,
757 const Symbol_value
<size
>* psymval
,
758 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
759 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
761 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
765 // R_SPARC_DISP64: (Symbol + Addend - Address)
767 disp64(unsigned char* view
,
768 const Sized_relobj
<size
, big_endian
>* object
,
769 const Symbol_value
<size
>* psymval
,
770 elfcpp::Elf_Xword addend
,
771 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
773 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
777 // R_SPARC_H44: (Symbol + Addend) >> 22
779 h44(unsigned char* view
,
780 const Sized_relobj
<size
, big_endian
>* object
,
781 const Symbol_value
<size
>* psymval
,
782 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
784 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
787 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
789 m44(unsigned char* view
,
790 const Sized_relobj
<size
, big_endian
>* object
,
791 const Symbol_value
<size
>* psymval
,
792 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
794 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
797 // R_SPARC_L44: (Symbol + Addend) & 0xfff
799 l44(unsigned char* view
,
800 const Sized_relobj
<size
, big_endian
>* object
,
801 const Symbol_value
<size
>* psymval
,
802 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
804 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
807 // R_SPARC_HH22: (Symbol + Addend) >> 42
809 hh22(unsigned char* view
,
810 const Sized_relobj
<size
, big_endian
>* object
,
811 const Symbol_value
<size
>* psymval
,
812 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
814 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
817 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
819 pc_hh22(unsigned char* view
,
820 const Sized_relobj
<size
, big_endian
>* object
,
821 const Symbol_value
<size
>* psymval
,
822 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
823 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
825 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
826 psymval
, addend
, address
);
829 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
831 hm10(unsigned char* view
,
832 const Sized_relobj
<size
, big_endian
>* object
,
833 const Symbol_value
<size
>* psymval
,
834 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
836 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
839 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
841 pc_hm10(unsigned char* view
,
842 const Sized_relobj
<size
, big_endian
>* object
,
843 const Symbol_value
<size
>* psymval
,
844 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
845 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
847 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
848 psymval
, addend
, address
);
851 // R_SPARC_11: (Symbol + Addend)
853 rela32_11(unsigned char* view
,
854 const Sized_relobj
<size
, big_endian
>* object
,
855 const Symbol_value
<size
>* psymval
,
856 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
858 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
861 // R_SPARC_10: (Symbol + Addend)
863 rela32_10(unsigned char* view
,
864 const Sized_relobj
<size
, big_endian
>* object
,
865 const Symbol_value
<size
>* psymval
,
866 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
868 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
871 // R_SPARC_7: (Symbol + Addend)
873 rela32_7(unsigned char* view
,
874 const Sized_relobj
<size
, big_endian
>* object
,
875 const Symbol_value
<size
>* psymval
,
876 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
878 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
881 // R_SPARC_6: (Symbol + Addend)
883 rela32_6(unsigned char* view
,
884 const Sized_relobj
<size
, big_endian
>* object
,
885 const Symbol_value
<size
>* psymval
,
886 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
888 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
891 // R_SPARC_5: (Symbol + Addend)
893 rela32_5(unsigned char* view
,
894 const Sized_relobj
<size
, big_endian
>* object
,
895 const Symbol_value
<size
>* psymval
,
896 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
898 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
901 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
903 ldo_hix22(unsigned char* view
,
904 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
905 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
907 This_insn::hi22(view
, value
, addend
);
910 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
912 ldo_lox10(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
);
924 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
927 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
929 hix22(unsigned char* view
,
930 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
931 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
933 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
934 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
935 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
936 Valtype reloc
= (value
+ addend
);
940 reloc
^= ~(Valtype
)0;
945 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
948 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
950 hix22(unsigned char* view
,
951 const Sized_relobj
<size
, big_endian
>* object
,
952 const Symbol_value
<size
>* psymval
,
953 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
955 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
956 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
957 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
958 Valtype reloc
= psymval
->value(object
, addend
);
962 reloc
^= ~(Valtype
)0;
967 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
971 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
973 lox10(unsigned char* view
,
974 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
975 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
977 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
978 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
979 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
980 Valtype reloc
= (value
+ addend
);
986 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
989 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
991 lox10(unsigned char* view
,
992 const Sized_relobj
<size
, big_endian
>* object
,
993 const Symbol_value
<size
>* psymval
,
994 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
996 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
997 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
998 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
999 Valtype reloc
= psymval
->value(object
, addend
);
1005 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1009 // Get the GOT section, creating it if necessary.
1011 template<int size
, bool big_endian
>
1012 Output_data_got
<size
, big_endian
>*
1013 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1016 if (this->got_
== NULL
)
1018 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1020 this->got_
= new Output_data_got
<size
, big_endian
>();
1023 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1025 | elfcpp::SHF_WRITE
),
1029 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1030 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1032 0, 0, elfcpp::STT_OBJECT
,
1034 elfcpp::STV_HIDDEN
, 0,
1041 // Get the dynamic reloc section, creating it if necessary.
1043 template<int size
, bool big_endian
>
1044 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1045 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1047 if (this->rela_dyn_
== NULL
)
1049 gold_assert(layout
!= NULL
);
1050 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1051 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1052 elfcpp::SHF_ALLOC
, this->rela_dyn_
);
1054 return this->rela_dyn_
;
1057 // A class to handle the PLT data.
1059 template<int size
, bool big_endian
>
1060 class Output_data_plt_sparc
: public Output_section_data
1063 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1064 size
, big_endian
> Reloc_section
;
1066 Output_data_plt_sparc(Layout
*);
1068 // Add an entry to the PLT.
1069 void add_entry(Symbol
* gsym
);
1071 // Return the .rela.plt section data.
1072 const Reloc_section
* rel_plt() const
1078 void do_adjust_output_section(Output_section
* os
);
1080 // Write to a map file.
1082 do_print_to_mapfile(Mapfile
* mapfile
) const
1083 { mapfile
->print_output_data(this, _("** PLT")); }
1086 // The size of an entry in the PLT.
1087 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1089 static const unsigned int plt_entries_per_block
= 160;
1090 static const unsigned int plt_insn_chunk_size
= 24;
1091 static const unsigned int plt_pointer_chunk_size
= 8;
1092 static const unsigned int plt_block_size
=
1093 (plt_entries_per_block
1094 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1096 // Set the final size.
1098 set_final_data_size()
1100 unsigned int full_count
= this->count_
+ 4;
1101 unsigned int extra
= (size
== 32 ? 4 : 0);
1103 if (size
== 32 || full_count
< 32768)
1104 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1107 unsigned int ext_cnt
= full_count
- 32768;
1109 this->set_data_size((32768 * base_plt_entry_size
)
1111 * (plt_insn_chunk_size
1112 + plt_pointer_chunk_size
)));
1116 // Write out the PLT data.
1118 do_write(Output_file
*);
1120 // The reloc section.
1121 Reloc_section
* rel_
;
1122 // The number of PLT entries.
1123 unsigned int count_
;
1126 // Define the constants as required by C++ standard.
1128 template<int size
, bool big_endian
>
1129 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1131 template<int size
, bool big_endian
>
1133 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1135 template<int size
, bool big_endian
>
1136 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1138 template<int size
, bool big_endian
>
1140 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1142 template<int size
, bool big_endian
>
1143 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1145 // Create the PLT section. The ordinary .got section is an argument,
1146 // since we need to refer to the start.
1148 template<int size
, bool big_endian
>
1149 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1150 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1152 this->rel_
= new Reloc_section(false);
1153 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1154 elfcpp::SHF_ALLOC
, this->rel_
);
1157 template<int size
, bool big_endian
>
1159 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1164 // Add an entry to the PLT.
1166 template<int size
, bool big_endian
>
1168 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1170 gold_assert(!gsym
->has_plt_offset());
1172 unsigned int index
= this->count_
+ 4;
1173 section_offset_type plt_offset
;
1175 if (size
== 32 || index
< 32768)
1176 plt_offset
= index
* base_plt_entry_size
;
1179 unsigned int ext_index
= index
- 32768;
1181 plt_offset
= (32768 * base_plt_entry_size
)
1182 + ((ext_index
/ plt_entries_per_block
)
1184 + ((ext_index
% plt_entries_per_block
)
1185 * plt_insn_chunk_size
);
1188 gsym
->set_plt_offset(plt_offset
);
1192 // Every PLT entry needs a reloc.
1193 gsym
->set_needs_dynsym_entry();
1194 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1197 // Note that we don't need to save the symbol. The contents of the
1198 // PLT are independent of which symbols are used. The symbols only
1199 // appear in the relocations.
1202 static const unsigned int sparc_nop
= 0x01000000;
1203 static const unsigned int sparc_sethi_g1
= 0x03000000;
1204 static const unsigned int sparc_branch_always
= 0x30800000;
1205 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1206 static const unsigned int sparc_mov
= 0x80100000;
1207 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1208 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1209 static const unsigned int sparc_call_plus_8
= 0x40000002;
1210 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1211 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1212 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1214 // Write out the PLT.
1216 template<int size
, bool big_endian
>
1218 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1220 const off_t offset
= this->offset();
1221 const section_size_type oview_size
=
1222 convert_to_section_size_type(this->data_size());
1223 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1224 unsigned char* pov
= oview
;
1226 memset(pov
, 0, base_plt_entry_size
* 4);
1227 pov
+= base_plt_entry_size
* 4;
1229 unsigned int plt_offset
= base_plt_entry_size
* 4;
1230 const unsigned int count
= this->count_
;
1236 limit
= (count
> 32768 ? 32768 : count
);
1238 for (unsigned int i
= 0; i
< limit
; ++i
)
1240 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1241 sparc_sethi_g1
+ plt_offset
);
1242 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1243 sparc_branch_always_pt
+
1244 (((base_plt_entry_size
-
1245 (plt_offset
+ 4)) >> 2) &
1247 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1248 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1249 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1250 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1251 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1252 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1254 pov
+= base_plt_entry_size
;
1255 plt_offset
+= base_plt_entry_size
;
1260 unsigned int ext_cnt
= count
- 32768;
1261 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1263 for (unsigned int i
= 0; i
< blks
; ++i
)
1265 unsigned int data_off
= (plt_entries_per_block
1266 * plt_insn_chunk_size
) - 4;
1268 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1270 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1272 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1274 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1276 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1277 sparc_ldx_o7_imm_g1
+
1278 (data_off
& 0x1fff));
1279 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1280 sparc_jmpl_o7_g1_g1
);
1281 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1284 elfcpp::Swap
<64, big_endian
>::writeval(
1285 pov
+ 0x4 + data_off
,
1286 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1288 pov
+= plt_insn_chunk_size
;
1293 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1294 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1296 unsigned int data_off
= (sub_blk_cnt
1297 * plt_insn_chunk_size
) - 4;
1299 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1301 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1303 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1305 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1307 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1308 sparc_ldx_o7_imm_g1
+
1309 (data_off
& 0x1fff));
1310 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1311 sparc_jmpl_o7_g1_g1
);
1312 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1315 elfcpp::Swap
<64, big_endian
>::writeval(
1316 pov
+ 0x4 + data_off
,
1317 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1319 pov
+= plt_insn_chunk_size
;
1327 for (unsigned int i
= 0; i
< count
; ++i
)
1329 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1330 sparc_sethi_g1
+ plt_offset
);
1331 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1332 sparc_branch_always
+
1333 (((- (plt_offset
+ 4)) >> 2) &
1335 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1337 pov
+= base_plt_entry_size
;
1338 plt_offset
+= base_plt_entry_size
;
1341 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1345 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1347 of
->write_output_view(offset
, oview_size
, oview
);
1350 // Create a PLT entry for a global symbol.
1352 template<int size
, bool big_endian
>
1354 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1358 if (gsym
->has_plt_offset())
1361 if (this->plt_
== NULL
)
1363 // Create the GOT sections first.
1364 this->got_section(symtab
, layout
);
1366 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1367 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1369 | elfcpp::SHF_EXECINSTR
1370 | elfcpp::SHF_WRITE
),
1373 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1374 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1376 0, 0, elfcpp::STT_OBJECT
,
1378 elfcpp::STV_HIDDEN
, 0,
1382 this->plt_
->add_entry(gsym
);
1385 // Create a GOT entry for the TLS module index.
1387 template<int size
, bool big_endian
>
1389 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1391 Sized_relobj
<size
, big_endian
>* object
)
1393 if (this->got_mod_index_offset_
== -1U)
1395 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1396 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1397 Output_data_got
<size
, big_endian
>* got
;
1398 unsigned int got_offset
;
1400 got
= this->got_section(symtab
, layout
);
1401 got_offset
= got
->add_constant(0);
1402 rela_dyn
->add_local(object
, 0,
1404 elfcpp::R_SPARC_TLS_DTPMOD64
:
1405 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1407 got
->add_constant(0);
1408 this->got_mod_index_offset_
= got_offset
;
1410 return this->got_mod_index_offset_
;
1413 // Optimize the TLS relocation type based on what we know about the
1414 // symbol. IS_FINAL is true if the final address of this symbol is
1415 // known at link time.
1417 static tls::Tls_optimization
1418 optimize_tls_reloc(bool is_final
, int r_type
)
1420 // If we are generating a shared library, then we can't do anything
1422 if (parameters
->options().shared())
1423 return tls::TLSOPT_NONE
;
1427 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1428 case elfcpp::R_SPARC_TLS_GD_LO10
:
1429 case elfcpp::R_SPARC_TLS_GD_ADD
:
1430 case elfcpp::R_SPARC_TLS_GD_CALL
:
1431 // These are General-Dynamic which permits fully general TLS
1432 // access. Since we know that we are generating an executable,
1433 // we can convert this to Initial-Exec. If we also know that
1434 // this is a local symbol, we can further switch to Local-Exec.
1436 return tls::TLSOPT_TO_LE
;
1437 return tls::TLSOPT_TO_IE
;
1439 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1440 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1441 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1442 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1443 // This is Local-Dynamic, which refers to a local symbol in the
1444 // dynamic TLS block. Since we know that we generating an
1445 // executable, we can switch to Local-Exec.
1446 return tls::TLSOPT_TO_LE
;
1448 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1449 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1450 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1451 // Another type of Local-Dynamic relocation.
1452 return tls::TLSOPT_TO_LE
;
1454 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1455 case elfcpp::R_SPARC_TLS_IE_LO10
:
1456 case elfcpp::R_SPARC_TLS_IE_LD
:
1457 case elfcpp::R_SPARC_TLS_IE_LDX
:
1458 // These are Initial-Exec relocs which get the thread offset
1459 // from the GOT. If we know that we are linking against the
1460 // local symbol, we can switch to Local-Exec, which links the
1461 // thread offset into the instruction.
1463 return tls::TLSOPT_TO_LE
;
1464 return tls::TLSOPT_NONE
;
1466 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1467 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1468 // When we already have Local-Exec, there is nothing further we
1470 return tls::TLSOPT_NONE
;
1477 // Generate a PLT entry slot for a call to __tls_get_addr
1478 template<int size
, bool big_endian
>
1480 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1482 Target_sparc
<size
, big_endian
>* target
)
1484 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1486 target
->make_plt_entry(symtab
, layout
, gsym
);
1489 // Report an unsupported relocation against a local symbol.
1491 template<int size
, bool big_endian
>
1493 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1494 Sized_relobj
<size
, big_endian
>* object
,
1495 unsigned int r_type
)
1497 gold_error(_("%s: unsupported reloc %u against local symbol"),
1498 object
->name().c_str(), r_type
);
1501 // We are about to emit a dynamic relocation of type R_TYPE. If the
1502 // dynamic linker does not support it, issue an error.
1504 template<int size
, bool big_endian
>
1506 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1508 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1514 // These are the relocation types supported by glibc for sparc 64-bit.
1515 case elfcpp::R_SPARC_RELATIVE
:
1516 case elfcpp::R_SPARC_COPY
:
1517 case elfcpp::R_SPARC_64
:
1518 case elfcpp::R_SPARC_GLOB_DAT
:
1519 case elfcpp::R_SPARC_JMP_SLOT
:
1520 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1521 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1522 case elfcpp::R_SPARC_TLS_TPOFF64
:
1523 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1524 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1525 case elfcpp::R_SPARC_8
:
1526 case elfcpp::R_SPARC_16
:
1527 case elfcpp::R_SPARC_DISP8
:
1528 case elfcpp::R_SPARC_DISP16
:
1529 case elfcpp::R_SPARC_DISP32
:
1530 case elfcpp::R_SPARC_WDISP30
:
1531 case elfcpp::R_SPARC_LO10
:
1532 case elfcpp::R_SPARC_HI22
:
1533 case elfcpp::R_SPARC_OLO10
:
1534 case elfcpp::R_SPARC_H44
:
1535 case elfcpp::R_SPARC_M44
:
1536 case elfcpp::R_SPARC_L44
:
1537 case elfcpp::R_SPARC_HH22
:
1538 case elfcpp::R_SPARC_HM10
:
1539 case elfcpp::R_SPARC_LM22
:
1540 case elfcpp::R_SPARC_UA16
:
1541 case elfcpp::R_SPARC_UA32
:
1542 case elfcpp::R_SPARC_UA64
:
1553 // These are the relocation types supported by glibc for sparc 32-bit.
1554 case elfcpp::R_SPARC_RELATIVE
:
1555 case elfcpp::R_SPARC_COPY
:
1556 case elfcpp::R_SPARC_GLOB_DAT
:
1557 case elfcpp::R_SPARC_32
:
1558 case elfcpp::R_SPARC_JMP_SLOT
:
1559 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1560 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1561 case elfcpp::R_SPARC_TLS_TPOFF32
:
1562 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1563 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1564 case elfcpp::R_SPARC_8
:
1565 case elfcpp::R_SPARC_16
:
1566 case elfcpp::R_SPARC_DISP8
:
1567 case elfcpp::R_SPARC_DISP16
:
1568 case elfcpp::R_SPARC_DISP32
:
1569 case elfcpp::R_SPARC_LO10
:
1570 case elfcpp::R_SPARC_WDISP30
:
1571 case elfcpp::R_SPARC_HI22
:
1572 case elfcpp::R_SPARC_UA16
:
1573 case elfcpp::R_SPARC_UA32
:
1581 // This prevents us from issuing more than one error per reloc
1582 // section. But we can still wind up issuing more than one
1583 // error per object file.
1584 if (this->issued_non_pic_error_
)
1586 object
->error(_("requires unsupported dynamic reloc; "
1587 "recompile with -fPIC"));
1588 this->issued_non_pic_error_
= true;
1592 // Scan a relocation for a local symbol.
1594 template<int size
, bool big_endian
>
1596 Target_sparc
<size
, big_endian
>::Scan::local(
1597 const General_options
&,
1598 Symbol_table
* symtab
,
1600 Target_sparc
<size
, big_endian
>* target
,
1601 Sized_relobj
<size
, big_endian
>* object
,
1602 unsigned int data_shndx
,
1603 Output_section
* output_section
,
1604 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1605 unsigned int r_type
,
1606 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1608 unsigned int orig_r_type
= r_type
;
1613 case elfcpp::R_SPARC_NONE
:
1614 case elfcpp::R_SPARC_REGISTER
:
1615 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1616 case elfcpp::R_SPARC_GNU_VTENTRY
:
1619 case elfcpp::R_SPARC_64
:
1620 case elfcpp::R_SPARC_32
:
1621 // If building a shared library (or a position-independent
1622 // executable), we need to create a dynamic relocation for
1623 // this location. The relocation applied at link time will
1624 // apply the link-time value, so we flag the location with
1625 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1626 // relocate it easily.
1627 if (parameters
->options().output_is_position_independent())
1629 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1630 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1631 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1632 output_section
, data_shndx
,
1633 reloc
.get_r_offset(),
1634 reloc
.get_r_addend());
1638 case elfcpp::R_SPARC_HIX22
:
1639 case elfcpp::R_SPARC_LOX10
:
1640 case elfcpp::R_SPARC_H44
:
1641 case elfcpp::R_SPARC_M44
:
1642 case elfcpp::R_SPARC_L44
:
1643 case elfcpp::R_SPARC_HH22
:
1644 case elfcpp::R_SPARC_HM10
:
1645 case elfcpp::R_SPARC_LM22
:
1646 case elfcpp::R_SPARC_UA64
:
1647 case elfcpp::R_SPARC_UA32
:
1648 case elfcpp::R_SPARC_UA16
:
1649 case elfcpp::R_SPARC_HI22
:
1650 case elfcpp::R_SPARC_LO10
:
1651 case elfcpp::R_SPARC_OLO10
:
1652 case elfcpp::R_SPARC_16
:
1653 case elfcpp::R_SPARC_11
:
1654 case elfcpp::R_SPARC_10
:
1655 case elfcpp::R_SPARC_8
:
1656 case elfcpp::R_SPARC_7
:
1657 case elfcpp::R_SPARC_6
:
1658 case elfcpp::R_SPARC_5
:
1659 // If building a shared library (or a position-independent
1660 // executable), we need to create a dynamic relocation for
1662 if (parameters
->options().output_is_position_independent())
1664 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1666 check_non_pic(object
, r_type
);
1667 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1669 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1670 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1671 data_shndx
, reloc
.get_r_offset(),
1672 reloc
.get_r_addend());
1676 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1677 gold_assert(lsym
.get_st_value() == 0);
1678 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1679 output_section
, data_shndx
,
1680 reloc
.get_r_offset(),
1681 reloc
.get_r_addend());
1686 case elfcpp::R_SPARC_WDISP30
:
1687 case elfcpp::R_SPARC_WDISP22
:
1688 case elfcpp::R_SPARC_WDISP19
:
1689 case elfcpp::R_SPARC_WDISP16
:
1690 case elfcpp::R_SPARC_DISP8
:
1691 case elfcpp::R_SPARC_DISP16
:
1692 case elfcpp::R_SPARC_DISP32
:
1693 case elfcpp::R_SPARC_DISP64
:
1694 case elfcpp::R_SPARC_PC10
:
1695 case elfcpp::R_SPARC_PC22
:
1698 case elfcpp::R_SPARC_GOT10
:
1699 case elfcpp::R_SPARC_GOT13
:
1700 case elfcpp::R_SPARC_GOT22
:
1702 // The symbol requires a GOT entry.
1703 Output_data_got
<size
, big_endian
>* got
;
1706 got
= target
->got_section(symtab
, layout
);
1707 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1709 // If we are generating a shared object, we need to add a
1710 // dynamic relocation for this symbol's GOT entry.
1711 if (parameters
->options().output_is_position_independent())
1713 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1715 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1718 off
= got
->add_constant(0);
1719 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1720 rela_dyn
->add_local_relative(object
, r_sym
,
1721 elfcpp::R_SPARC_RELATIVE
,
1726 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1730 // These are initial TLS relocs, which are expected when
1732 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1733 case elfcpp::R_SPARC_TLS_GD_LO10
:
1734 case elfcpp::R_SPARC_TLS_GD_ADD
:
1735 case elfcpp::R_SPARC_TLS_GD_CALL
:
1736 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1737 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1738 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1739 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1740 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1741 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1742 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1743 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1744 case elfcpp::R_SPARC_TLS_IE_LO10
:
1745 case elfcpp::R_SPARC_TLS_IE_LD
:
1746 case elfcpp::R_SPARC_TLS_IE_LDX
:
1747 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1748 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1750 bool output_is_shared
= parameters
->options().shared();
1751 const tls::Tls_optimization optimized_type
1752 = optimize_tls_reloc(!output_is_shared
, r_type
);
1755 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1756 case elfcpp::R_SPARC_TLS_GD_LO10
:
1757 case elfcpp::R_SPARC_TLS_GD_ADD
:
1758 case elfcpp::R_SPARC_TLS_GD_CALL
:
1759 if (optimized_type
== tls::TLSOPT_NONE
)
1761 // Create a pair of GOT entries for the module index and
1762 // dtv-relative offset.
1763 Output_data_got
<size
, big_endian
>* got
1764 = target
->got_section(symtab
, layout
);
1765 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1766 unsigned int shndx
= lsym
.get_st_shndx();
1768 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1770 object
->error(_("local symbol %u has bad shndx %u"),
1773 got
->add_local_pair_with_rela(object
, r_sym
,
1774 lsym
.get_st_shndx(),
1776 target
->rela_dyn_section(layout
),
1778 ? elfcpp::R_SPARC_TLS_DTPMOD64
1779 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1781 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1782 generate_tls_call(symtab
, layout
, target
);
1784 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1785 unsupported_reloc_local(object
, r_type
);
1788 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1789 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1790 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1791 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1792 if (optimized_type
== tls::TLSOPT_NONE
)
1794 // Create a GOT entry for the module index.
1795 target
->got_mod_index_entry(symtab
, layout
, object
);
1797 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1798 generate_tls_call(symtab
, layout
, target
);
1800 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1801 unsupported_reloc_local(object
, r_type
);
1804 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1805 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1806 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1809 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1810 case elfcpp::R_SPARC_TLS_IE_LO10
:
1811 case elfcpp::R_SPARC_TLS_IE_LD
:
1812 case elfcpp::R_SPARC_TLS_IE_LDX
:
1813 layout
->set_has_static_tls();
1814 if (optimized_type
== tls::TLSOPT_NONE
)
1816 // Create a GOT entry for the tp-relative offset.
1817 Output_data_got
<size
, big_endian
>* got
1818 = target
->got_section(symtab
, layout
);
1819 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1821 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1823 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1824 unsigned int off
= got
->add_constant(0);
1826 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1828 rela_dyn
->add_local_relative(object
, r_sym
,
1830 elfcpp::R_SPARC_TLS_TPOFF64
:
1831 elfcpp::R_SPARC_TLS_TPOFF32
),
1835 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1836 unsupported_reloc_local(object
, r_type
);
1839 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1840 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1841 layout
->set_has_static_tls();
1842 if (output_is_shared
)
1844 // We need to create a dynamic relocation.
1845 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1846 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1847 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1848 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1849 output_section
, data_shndx
,
1850 reloc
.get_r_offset(), 0);
1857 // These are relocations which should only be seen by the
1858 // dynamic linker, and should never be seen here.
1859 case elfcpp::R_SPARC_COPY
:
1860 case elfcpp::R_SPARC_GLOB_DAT
:
1861 case elfcpp::R_SPARC_JMP_SLOT
:
1862 case elfcpp::R_SPARC_RELATIVE
:
1863 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1864 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1865 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1866 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1867 case elfcpp::R_SPARC_TLS_TPOFF64
:
1868 case elfcpp::R_SPARC_TLS_TPOFF32
:
1869 gold_error(_("%s: unexpected reloc %u in object file"),
1870 object
->name().c_str(), r_type
);
1874 unsupported_reloc_local(object
, r_type
);
1879 // Report an unsupported relocation against a global symbol.
1881 template<int size
, bool big_endian
>
1883 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1884 Sized_relobj
<size
, big_endian
>* object
,
1885 unsigned int r_type
,
1888 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1889 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1892 // Scan a relocation for a global symbol.
1894 template<int size
, bool big_endian
>
1896 Target_sparc
<size
, big_endian
>::Scan::global(
1897 const General_options
&,
1898 Symbol_table
* symtab
,
1900 Target_sparc
<size
, big_endian
>* target
,
1901 Sized_relobj
<size
, big_endian
>* object
,
1902 unsigned int data_shndx
,
1903 Output_section
* output_section
,
1904 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1905 unsigned int r_type
,
1908 unsigned int orig_r_type
= r_type
;
1913 case elfcpp::R_SPARC_NONE
:
1914 case elfcpp::R_SPARC_REGISTER
:
1915 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1916 case elfcpp::R_SPARC_GNU_VTENTRY
:
1919 case elfcpp::R_SPARC_PLT64
:
1920 case elfcpp::R_SPARC_PLT32
:
1921 case elfcpp::R_SPARC_HIPLT22
:
1922 case elfcpp::R_SPARC_LOPLT10
:
1923 case elfcpp::R_SPARC_PCPLT32
:
1924 case elfcpp::R_SPARC_PCPLT22
:
1925 case elfcpp::R_SPARC_PCPLT10
:
1926 case elfcpp::R_SPARC_WPLT30
:
1927 // If the symbol is fully resolved, this is just a PC32 reloc.
1928 // Otherwise we need a PLT entry.
1929 if (gsym
->final_value_is_known())
1931 // If building a shared library, we can also skip the PLT entry
1932 // if the symbol is defined in the output file and is protected
1934 if (gsym
->is_defined()
1935 && !gsym
->is_from_dynobj()
1936 && !gsym
->is_preemptible())
1938 target
->make_plt_entry(symtab
, layout
, gsym
);
1941 case elfcpp::R_SPARC_DISP8
:
1942 case elfcpp::R_SPARC_DISP16
:
1943 case elfcpp::R_SPARC_DISP32
:
1944 case elfcpp::R_SPARC_DISP64
:
1945 case elfcpp::R_SPARC_PC_HH22
:
1946 case elfcpp::R_SPARC_PC_HM10
:
1947 case elfcpp::R_SPARC_PC_LM22
:
1948 case elfcpp::R_SPARC_PC10
:
1949 case elfcpp::R_SPARC_PC22
:
1950 case elfcpp::R_SPARC_WDISP30
:
1951 case elfcpp::R_SPARC_WDISP22
:
1952 case elfcpp::R_SPARC_WDISP19
:
1953 case elfcpp::R_SPARC_WDISP16
:
1955 if (gsym
->needs_plt_entry())
1956 target
->make_plt_entry(symtab
, layout
, gsym
);
1957 // Make a dynamic relocation if necessary.
1958 int flags
= Symbol::NON_PIC_REF
;
1959 if (gsym
->type() == elfcpp::STT_FUNC
)
1960 flags
|= Symbol::FUNCTION_CALL
;
1961 if (gsym
->needs_dynamic_reloc(flags
))
1963 if (target
->may_need_copy_reloc(gsym
))
1965 target
->copy_reloc(symtab
, layout
, object
,
1966 data_shndx
, output_section
, gsym
,
1971 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1972 check_non_pic(object
, r_type
);
1973 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1974 data_shndx
, reloc
.get_r_offset(),
1975 reloc
.get_r_addend());
1981 case elfcpp::R_SPARC_UA64
:
1982 case elfcpp::R_SPARC_64
:
1983 case elfcpp::R_SPARC_HIX22
:
1984 case elfcpp::R_SPARC_LOX10
:
1985 case elfcpp::R_SPARC_H44
:
1986 case elfcpp::R_SPARC_M44
:
1987 case elfcpp::R_SPARC_L44
:
1988 case elfcpp::R_SPARC_HH22
:
1989 case elfcpp::R_SPARC_HM10
:
1990 case elfcpp::R_SPARC_LM22
:
1991 case elfcpp::R_SPARC_HI22
:
1992 case elfcpp::R_SPARC_LO10
:
1993 case elfcpp::R_SPARC_OLO10
:
1994 case elfcpp::R_SPARC_UA32
:
1995 case elfcpp::R_SPARC_32
:
1996 case elfcpp::R_SPARC_UA16
:
1997 case elfcpp::R_SPARC_16
:
1998 case elfcpp::R_SPARC_11
:
1999 case elfcpp::R_SPARC_10
:
2000 case elfcpp::R_SPARC_8
:
2001 case elfcpp::R_SPARC_7
:
2002 case elfcpp::R_SPARC_6
:
2003 case elfcpp::R_SPARC_5
:
2005 // Make a PLT entry if necessary.
2006 if (gsym
->needs_plt_entry())
2008 target
->make_plt_entry(symtab
, layout
, gsym
);
2009 // Since this is not a PC-relative relocation, we may be
2010 // taking the address of a function. In that case we need to
2011 // set the entry in the dynamic symbol table to the address of
2013 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2014 gsym
->set_needs_dynsym_value();
2016 // Make a dynamic relocation if necessary.
2017 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2019 if (target
->may_need_copy_reloc(gsym
))
2021 target
->copy_reloc(symtab
, layout
, object
,
2022 data_shndx
, output_section
, gsym
, reloc
);
2024 else if ((r_type
== elfcpp::R_SPARC_32
2025 || r_type
== elfcpp::R_SPARC_64
)
2026 && gsym
->can_use_relative_reloc(false))
2028 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2029 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2030 output_section
, object
,
2031 data_shndx
, reloc
.get_r_offset(),
2032 reloc
.get_r_addend());
2036 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2038 check_non_pic(object
, r_type
);
2039 if (gsym
->is_from_dynobj()
2040 || gsym
->is_undefined()
2041 || gsym
->is_preemptible())
2042 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2044 reloc
.get_r_offset(),
2045 reloc
.get_r_addend());
2047 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2048 output_section
, object
,
2050 reloc
.get_r_offset(),
2051 reloc
.get_r_addend());
2057 case elfcpp::R_SPARC_GOT10
:
2058 case elfcpp::R_SPARC_GOT13
:
2059 case elfcpp::R_SPARC_GOT22
:
2061 // The symbol requires a GOT entry.
2062 Output_data_got
<size
, big_endian
>* got
;
2064 got
= target
->got_section(symtab
, layout
);
2065 if (gsym
->final_value_is_known())
2066 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2069 // If this symbol is not fully resolved, we need to add a
2070 // dynamic relocation for it.
2071 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2072 if (gsym
->is_from_dynobj()
2073 || gsym
->is_undefined()
2074 || gsym
->is_preemptible())
2075 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2076 elfcpp::R_SPARC_GLOB_DAT
);
2077 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2079 unsigned int off
= got
->add_constant(0);
2081 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2082 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2089 // These are initial tls relocs, which are expected when
2091 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2092 case elfcpp::R_SPARC_TLS_GD_LO10
:
2093 case elfcpp::R_SPARC_TLS_GD_ADD
:
2094 case elfcpp::R_SPARC_TLS_GD_CALL
:
2095 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2096 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2097 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2098 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2099 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2100 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2101 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2102 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2103 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2104 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2105 case elfcpp::R_SPARC_TLS_IE_LO10
:
2106 case elfcpp::R_SPARC_TLS_IE_LD
:
2107 case elfcpp::R_SPARC_TLS_IE_LDX
:
2109 const bool is_final
= gsym
->final_value_is_known();
2110 const tls::Tls_optimization optimized_type
2111 = optimize_tls_reloc(is_final
, r_type
);
2114 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2115 case elfcpp::R_SPARC_TLS_GD_LO10
:
2116 case elfcpp::R_SPARC_TLS_GD_ADD
:
2117 case elfcpp::R_SPARC_TLS_GD_CALL
:
2118 if (optimized_type
== tls::TLSOPT_NONE
)
2120 // Create a pair of GOT entries for the module index and
2121 // dtv-relative offset.
2122 Output_data_got
<size
, big_endian
>* got
2123 = target
->got_section(symtab
, layout
);
2124 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2125 target
->rela_dyn_section(layout
),
2127 elfcpp::R_SPARC_TLS_DTPMOD64
:
2128 elfcpp::R_SPARC_TLS_DTPMOD32
),
2130 elfcpp::R_SPARC_TLS_DTPOFF64
:
2131 elfcpp::R_SPARC_TLS_DTPOFF32
));
2133 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2134 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2135 generate_tls_call(symtab
, layout
, target
);
2137 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2139 // Create a GOT entry for the tp-relative offset.
2140 Output_data_got
<size
, big_endian
>* got
2141 = target
->got_section(symtab
, layout
);
2142 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2143 target
->rela_dyn_section(layout
),
2145 elfcpp::R_SPARC_TLS_TPOFF64
:
2146 elfcpp::R_SPARC_TLS_TPOFF32
));
2148 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2149 unsupported_reloc_global(object
, r_type
, gsym
);
2152 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2153 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2154 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2155 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2156 if (optimized_type
== tls::TLSOPT_NONE
)
2158 // Create a GOT entry for the module index.
2159 target
->got_mod_index_entry(symtab
, layout
, object
);
2161 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2162 generate_tls_call(symtab
, layout
, target
);
2164 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2165 unsupported_reloc_global(object
, r_type
, gsym
);
2168 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2169 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2170 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2173 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2174 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2175 layout
->set_has_static_tls();
2176 if (parameters
->options().shared())
2178 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2179 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2180 output_section
, object
,
2181 data_shndx
, reloc
.get_r_offset(),
2186 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2187 case elfcpp::R_SPARC_TLS_IE_LO10
:
2188 case elfcpp::R_SPARC_TLS_IE_LD
:
2189 case elfcpp::R_SPARC_TLS_IE_LDX
:
2190 layout
->set_has_static_tls();
2191 if (optimized_type
== tls::TLSOPT_NONE
)
2193 // Create a GOT entry for the tp-relative offset.
2194 Output_data_got
<size
, big_endian
>* got
2195 = target
->got_section(symtab
, layout
);
2196 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2197 target
->rela_dyn_section(layout
),
2199 elfcpp::R_SPARC_TLS_TPOFF64
:
2200 elfcpp::R_SPARC_TLS_TPOFF32
));
2202 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2203 unsupported_reloc_global(object
, r_type
, gsym
);
2209 // These are relocations which should only be seen by the
2210 // dynamic linker, and should never be seen here.
2211 case elfcpp::R_SPARC_COPY
:
2212 case elfcpp::R_SPARC_GLOB_DAT
:
2213 case elfcpp::R_SPARC_JMP_SLOT
:
2214 case elfcpp::R_SPARC_RELATIVE
:
2215 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2216 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2217 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2218 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2219 case elfcpp::R_SPARC_TLS_TPOFF64
:
2220 case elfcpp::R_SPARC_TLS_TPOFF32
:
2221 gold_error(_("%s: unexpected reloc %u in object file"),
2222 object
->name().c_str(), r_type
);
2226 unsupported_reloc_global(object
, r_type
, gsym
);
2231 // Process relocations for gc.
2233 template<int size
, bool big_endian
>
2235 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2236 const General_options
& options
,
2237 Symbol_table
* symtab
,
2239 Sized_relobj
<size
, big_endian
>* object
,
2240 unsigned int data_shndx
,
2242 const unsigned char* prelocs
,
2244 Output_section
* output_section
,
2245 bool needs_special_offset_handling
,
2246 size_t local_symbol_count
,
2247 const unsigned char* plocal_symbols
)
2249 typedef Target_sparc
<size
, big_endian
> Sparc
;
2250 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2252 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2262 needs_special_offset_handling
,
2267 // Scan relocations for a section.
2269 template<int size
, bool big_endian
>
2271 Target_sparc
<size
, big_endian
>::scan_relocs(
2272 const General_options
& options
,
2273 Symbol_table
* symtab
,
2275 Sized_relobj
<size
, big_endian
>* object
,
2276 unsigned int data_shndx
,
2277 unsigned int sh_type
,
2278 const unsigned char* prelocs
,
2280 Output_section
* output_section
,
2281 bool needs_special_offset_handling
,
2282 size_t local_symbol_count
,
2283 const unsigned char* plocal_symbols
)
2285 typedef Target_sparc
<size
, big_endian
> Sparc
;
2286 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2288 if (sh_type
== elfcpp::SHT_REL
)
2290 gold_error(_("%s: unsupported REL reloc section"),
2291 object
->name().c_str());
2295 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2305 needs_special_offset_handling
,
2310 // Finalize the sections.
2312 template<int size
, bool big_endian
>
2314 Target_sparc
<size
, big_endian
>::do_finalize_sections(Layout
* layout
)
2316 // Fill in some more dynamic tags.
2317 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2320 if (this->plt_
!= NULL
)
2322 const Output_data
* od
= this->plt_
->rel_plt();
2323 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2324 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2325 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2327 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2330 if (this->rela_dyn_
!= NULL
)
2332 const Output_data
* od
= this->rela_dyn_
;
2333 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2334 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2335 odyn
->add_constant(elfcpp::DT_RELAENT
,
2336 elfcpp::Elf_sizes
<size
>::rela_size
);
2339 if (!parameters
->options().shared())
2341 // The value of the DT_DEBUG tag is filled in by the dynamic
2342 // linker at run time, and used by the debugger.
2343 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2347 // Emit any relocs we saved in an attempt to avoid generating COPY
2349 if (this->copy_relocs_
.any_saved_relocs())
2350 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2353 // Perform a relocation.
2355 template<int size
, bool big_endian
>
2357 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2358 const Relocate_info
<size
, big_endian
>* relinfo
,
2359 Target_sparc
* target
,
2362 const elfcpp::Rela
<size
, big_endian
>& rela
,
2363 unsigned int r_type
,
2364 const Sized_symbol
<size
>* gsym
,
2365 const Symbol_value
<size
>* psymval
,
2366 unsigned char* view
,
2367 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2368 section_size_type view_size
)
2372 if (this->ignore_gd_add_
)
2374 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2375 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2376 _("missing expected TLS relocation"));
2379 this->ignore_gd_add_
= false;
2384 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2386 // Pick the value to use for symbols defined in shared objects.
2387 Symbol_value
<size
> symval
;
2389 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2390 || r_type
== elfcpp::R_SPARC_DISP16
2391 || r_type
== elfcpp::R_SPARC_DISP32
2392 || r_type
== elfcpp::R_SPARC_DISP64
2393 || r_type
== elfcpp::R_SPARC_PC_HH22
2394 || r_type
== elfcpp::R_SPARC_PC_HM10
2395 || r_type
== elfcpp::R_SPARC_PC_LM22
2396 || r_type
== elfcpp::R_SPARC_PC10
2397 || r_type
== elfcpp::R_SPARC_PC22
2398 || r_type
== elfcpp::R_SPARC_WDISP30
2399 || r_type
== elfcpp::R_SPARC_WDISP22
2400 || r_type
== elfcpp::R_SPARC_WDISP19
2401 || r_type
== elfcpp::R_SPARC_WDISP16
))
2403 elfcpp::Elf_Xword value
;
2405 value
= target
->plt_section()->address() + gsym
->plt_offset();
2407 symval
.set_output_value(value
);
2412 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2413 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2415 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2416 // pointer points to the beginning, not the end, of the table.
2417 // So we just use the plain offset.
2418 bool have_got_offset
= false;
2419 unsigned int got_offset
= 0;
2422 case elfcpp::R_SPARC_GOT10
:
2423 case elfcpp::R_SPARC_GOT13
:
2424 case elfcpp::R_SPARC_GOT22
:
2427 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2428 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2432 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2433 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2434 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2436 have_got_offset
= true;
2445 case elfcpp::R_SPARC_NONE
:
2446 case elfcpp::R_SPARC_REGISTER
:
2447 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2448 case elfcpp::R_SPARC_GNU_VTENTRY
:
2451 case elfcpp::R_SPARC_8
:
2452 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2456 case elfcpp::R_SPARC_16
:
2457 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2461 case elfcpp::R_SPARC_32
:
2462 if (!parameters
->options().output_is_position_independent())
2463 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2467 case elfcpp::R_SPARC_DISP8
:
2468 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2471 case elfcpp::R_SPARC_DISP16
:
2472 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2475 case elfcpp::R_SPARC_DISP32
:
2476 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2479 case elfcpp::R_SPARC_DISP64
:
2480 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2483 case elfcpp::R_SPARC_WDISP30
:
2484 case elfcpp::R_SPARC_WPLT30
:
2485 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2488 case elfcpp::R_SPARC_WDISP22
:
2489 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2492 case elfcpp::R_SPARC_WDISP19
:
2493 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2496 case elfcpp::R_SPARC_WDISP16
:
2497 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2500 case elfcpp::R_SPARC_HI22
:
2501 Reloc::hi22(view
, object
, psymval
, addend
);
2504 case elfcpp::R_SPARC_22
:
2505 Reloc::rela32_22(view
, object
, psymval
, addend
);
2508 case elfcpp::R_SPARC_13
:
2509 Reloc::rela32_13(view
, object
, psymval
, addend
);
2512 case elfcpp::R_SPARC_LO10
:
2513 Reloc::lo10(view
, object
, psymval
, addend
);
2516 case elfcpp::R_SPARC_GOT10
:
2517 Reloc::lo10(view
, got_offset
, addend
);
2520 case elfcpp::R_SPARC_GOT13
:
2521 Reloc::rela32_13(view
, got_offset
, addend
);
2524 case elfcpp::R_SPARC_GOT22
:
2525 Reloc::hi22(view
, got_offset
, addend
);
2528 case elfcpp::R_SPARC_PC10
:
2529 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2532 case elfcpp::R_SPARC_PC22
:
2533 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2536 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2537 case elfcpp::R_SPARC_UA32
:
2538 Reloc::ua32(view
, object
, psymval
, addend
);
2541 case elfcpp::R_SPARC_PLT64
:
2542 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2546 case elfcpp::R_SPARC_PLT32
:
2547 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2551 case elfcpp::R_SPARC_HIPLT22
:
2552 Reloc::hi22(view
, object
, psymval
, addend
);
2555 case elfcpp::R_SPARC_LOPLT10
:
2556 Reloc::lo10(view
, object
, psymval
, addend
);
2559 case elfcpp::R_SPARC_PCPLT32
:
2560 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2563 case elfcpp::R_SPARC_PCPLT22
:
2564 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2567 case elfcpp::R_SPARC_PCPLT10
:
2568 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2571 case elfcpp::R_SPARC_64
:
2572 if (!parameters
->options().output_is_position_independent())
2573 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2577 case elfcpp::R_SPARC_OLO10
:
2579 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2580 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2581 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2585 case elfcpp::R_SPARC_HH22
:
2586 Reloc::hh22(view
, object
, psymval
, addend
);
2589 case elfcpp::R_SPARC_PC_HH22
:
2590 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2593 case elfcpp::R_SPARC_HM10
:
2594 Reloc::hm10(view
, object
, psymval
, addend
);
2597 case elfcpp::R_SPARC_PC_HM10
:
2598 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2601 case elfcpp::R_SPARC_LM22
:
2602 Reloc::hi22(view
, object
, psymval
, addend
);
2605 case elfcpp::R_SPARC_PC_LM22
:
2606 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2609 case elfcpp::R_SPARC_11
:
2610 Reloc::rela32_11(view
, object
, psymval
, addend
);
2613 case elfcpp::R_SPARC_10
:
2614 Reloc::rela32_10(view
, object
, psymval
, addend
);
2617 case elfcpp::R_SPARC_7
:
2618 Reloc::rela32_7(view
, object
, psymval
, addend
);
2621 case elfcpp::R_SPARC_6
:
2622 Reloc::rela32_6(view
, object
, psymval
, addend
);
2625 case elfcpp::R_SPARC_5
:
2626 Reloc::rela32_5(view
, object
, psymval
, addend
);
2629 case elfcpp::R_SPARC_HIX22
:
2630 Reloc::hix22(view
, object
, psymval
, addend
);
2633 case elfcpp::R_SPARC_LOX10
:
2634 Reloc::lox10(view
, object
, psymval
, addend
);
2637 case elfcpp::R_SPARC_H44
:
2638 Reloc::h44(view
, object
, psymval
, addend
);
2641 case elfcpp::R_SPARC_M44
:
2642 Reloc::m44(view
, object
, psymval
, addend
);
2645 case elfcpp::R_SPARC_L44
:
2646 Reloc::l44(view
, object
, psymval
, addend
);
2649 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2650 case elfcpp::R_SPARC_UA64
:
2651 Reloc::ua64(view
, object
, psymval
, addend
);
2654 case elfcpp::R_SPARC_UA16
:
2655 Reloc::ua16(view
, object
, psymval
, addend
);
2658 case elfcpp::R_SPARC_TLS_GD_HI22
:
2659 case elfcpp::R_SPARC_TLS_GD_LO10
:
2660 case elfcpp::R_SPARC_TLS_GD_ADD
:
2661 case elfcpp::R_SPARC_TLS_GD_CALL
:
2662 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2663 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2664 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2665 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2666 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2667 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2668 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2669 case elfcpp::R_SPARC_TLS_IE_HI22
:
2670 case elfcpp::R_SPARC_TLS_IE_LO10
:
2671 case elfcpp::R_SPARC_TLS_IE_LD
:
2672 case elfcpp::R_SPARC_TLS_IE_LDX
:
2673 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2674 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2675 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2676 r_type
, gsym
, psymval
, view
,
2677 address
, view_size
);
2680 case elfcpp::R_SPARC_COPY
:
2681 case elfcpp::R_SPARC_GLOB_DAT
:
2682 case elfcpp::R_SPARC_JMP_SLOT
:
2683 case elfcpp::R_SPARC_RELATIVE
:
2684 // These are outstanding tls relocs, which are unexpected when
2686 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2687 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2688 case elfcpp::R_SPARC_TLS_TPOFF64
:
2689 case elfcpp::R_SPARC_TLS_TPOFF32
:
2690 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2691 _("unexpected reloc %u in object file"),
2696 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2697 _("unsupported reloc %u"),
2705 // Perform a TLS relocation.
2707 template<int size
, bool big_endian
>
2709 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2710 const Relocate_info
<size
, big_endian
>* relinfo
,
2711 Target_sparc
<size
, big_endian
>* target
,
2713 const elfcpp::Rela
<size
, big_endian
>& rela
,
2714 unsigned int r_type
,
2715 const Sized_symbol
<size
>* gsym
,
2716 const Symbol_value
<size
>* psymval
,
2717 unsigned char* view
,
2718 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2721 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2722 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2723 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2724 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2726 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2727 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2729 const bool is_final
=
2731 ? !parameters
->options().output_is_position_independent()
2732 : gsym
->final_value_is_known());
2733 const tls::Tls_optimization optimized_type
2734 = optimize_tls_reloc(is_final
, r_type
);
2738 case elfcpp::R_SPARC_TLS_GD_HI22
:
2739 case elfcpp::R_SPARC_TLS_GD_LO10
:
2740 case elfcpp::R_SPARC_TLS_GD_ADD
:
2741 case elfcpp::R_SPARC_TLS_GD_CALL
:
2742 if (optimized_type
== tls::TLSOPT_TO_LE
)
2744 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2747 value
-= tls_segment
->memsz();
2751 case elfcpp::R_SPARC_TLS_GD_HI22
:
2752 // TLS_GD_HI22 --> TLS_LE_HIX22
2753 Reloc::hix22(view
, value
, addend
);
2756 case elfcpp::R_SPARC_TLS_GD_LO10
:
2757 // TLS_GD_LO10 --> TLS_LE_LOX10
2758 Reloc::lox10(view
, value
, addend
);
2761 case elfcpp::R_SPARC_TLS_GD_ADD
:
2762 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2763 val
= elfcpp::Swap
<32, true>::readval(wv
);
2764 val
= (val
& ~0x7c000) | 0x1c000;
2765 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2767 case elfcpp::R_SPARC_TLS_GD_CALL
:
2768 // call __tls_get_addr --> nop
2769 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2776 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2777 ? GOT_TYPE_TLS_OFFSET
2778 : GOT_TYPE_TLS_PAIR
);
2781 gold_assert(gsym
->has_got_offset(got_type
));
2782 value
= gsym
->got_offset(got_type
);
2786 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2787 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2788 value
= object
->local_got_offset(r_sym
, got_type
);
2790 if (optimized_type
== tls::TLSOPT_TO_IE
)
2792 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2797 case elfcpp::R_SPARC_TLS_GD_HI22
:
2798 // TLS_GD_HI22 --> TLS_IE_HI22
2799 Reloc::hi22(view
, value
, addend
);
2802 case elfcpp::R_SPARC_TLS_GD_LO10
:
2803 // TLS_GD_LO10 --> TLS_IE_LO10
2804 Reloc::lo10(view
, value
, addend
);
2807 case elfcpp::R_SPARC_TLS_GD_ADD
:
2808 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2809 val
= elfcpp::Swap
<32, true>::readval(wv
);
2816 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2819 case elfcpp::R_SPARC_TLS_GD_CALL
:
2820 // The compiler can put the TLS_GD_ADD instruction
2821 // into the delay slot of the call. If so, we need
2822 // to transpose the two instructions so that the
2823 // the new sequence works properly.
2825 // The test we use is if the instruction in the
2826 // delay slot is an add with destination register
2828 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2829 if ((val
& 0x81f80000) == 0x80000000
2830 && ((val
>> 25) & 0x1f) == 0x8)
2837 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2840 this->ignore_gd_add_
= true;
2843 // call __tls_get_addr --> add %g7, %o0, %o0
2844 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2849 else if (optimized_type
== tls::TLSOPT_NONE
)
2853 case elfcpp::R_SPARC_TLS_GD_HI22
:
2854 Reloc::hi22(view
, value
, addend
);
2856 case elfcpp::R_SPARC_TLS_GD_LO10
:
2857 Reloc::lo10(view
, value
, addend
);
2859 case elfcpp::R_SPARC_TLS_GD_ADD
:
2861 case elfcpp::R_SPARC_TLS_GD_CALL
:
2863 Symbol_value
<size
> symval
;
2864 elfcpp::Elf_Xword value
;
2867 tsym
= target
->tls_get_addr_sym_
;
2869 value
= (target
->plt_section()->address() +
2870 tsym
->plt_offset());
2871 symval
.set_output_value(value
);
2872 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2879 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2880 _("unsupported reloc %u"),
2884 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2885 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2886 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2887 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2888 if (optimized_type
== tls::TLSOPT_TO_LE
)
2890 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2894 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2895 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2896 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2897 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2900 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2901 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2906 else if (optimized_type
== tls::TLSOPT_NONE
)
2908 // Relocate the field with the offset of the GOT entry for
2909 // the module index.
2910 unsigned int got_offset
;
2912 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2915 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2916 Reloc::hi22(view
, got_offset
, addend
);
2918 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2919 Reloc::lo10(view
, got_offset
, addend
);
2921 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2923 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2925 Symbol_value
<size
> symval
;
2926 elfcpp::Elf_Xword value
;
2929 tsym
= target
->tls_get_addr_sym_
;
2931 value
= (target
->plt_section()->address() +
2932 tsym
->plt_offset());
2933 symval
.set_output_value(value
);
2934 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2940 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2941 _("unsupported reloc %u"),
2945 // These relocs can appear in debugging sections, in which case
2946 // we won't see the TLS_LDM relocs. The local_dynamic_type
2947 // field tells us this.
2948 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2949 if (optimized_type
== tls::TLSOPT_TO_LE
)
2951 value
-= tls_segment
->memsz();
2952 Reloc::hix22(view
, value
, addend
);
2955 Reloc::ldo_hix22(view
, value
, addend
);
2957 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2958 if (optimized_type
== tls::TLSOPT_TO_LE
)
2960 value
-= tls_segment
->memsz();
2961 Reloc::lox10(view
, value
, addend
);
2964 Reloc::ldo_lox10(view
, value
, addend
);
2966 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2967 if (optimized_type
== tls::TLSOPT_TO_LE
)
2969 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2972 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2973 val
= elfcpp::Swap
<32, true>::readval(wv
);
2974 val
= (val
& ~0x7c000) | 0x1c000;
2975 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2979 // When optimizing IE --> LE, the only relocation that is handled
2980 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2981 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2982 // rs2 and rd are the same.
2983 case elfcpp::R_SPARC_TLS_IE_LD
:
2984 case elfcpp::R_SPARC_TLS_IE_LDX
:
2985 if (optimized_type
== tls::TLSOPT_TO_LE
)
2987 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2988 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
2989 Insntype rs2
= val
& 0x1f;
2990 Insntype rd
= (val
>> 25) & 0x1f;
2995 val
= sparc_mov
| (val
& 0x3e00001f);
2997 elfcpp::Swap
<32, true>::writeval(wv
, val
);
3001 case elfcpp::R_SPARC_TLS_IE_HI22
:
3002 case elfcpp::R_SPARC_TLS_IE_LO10
:
3003 if (optimized_type
== tls::TLSOPT_TO_LE
)
3005 value
-= tls_segment
->memsz();
3008 case elfcpp::R_SPARC_TLS_IE_HI22
:
3009 // IE_HI22 --> LE_HIX22
3010 Reloc::hix22(view
, value
, addend
);
3012 case elfcpp::R_SPARC_TLS_IE_LO10
:
3013 // IE_LO10 --> LE_LOX10
3014 Reloc::lox10(view
, value
, addend
);
3019 else if (optimized_type
== tls::TLSOPT_NONE
)
3021 // Relocate the field with the offset of the GOT entry for
3022 // the tp-relative offset of the symbol.
3025 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3026 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3030 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3031 gold_assert(object
->local_has_got_offset(r_sym
,
3032 GOT_TYPE_TLS_OFFSET
));
3033 value
= object
->local_got_offset(r_sym
,
3034 GOT_TYPE_TLS_OFFSET
);
3038 case elfcpp::R_SPARC_TLS_IE_HI22
:
3039 Reloc::hi22(view
, value
, addend
);
3041 case elfcpp::R_SPARC_TLS_IE_LO10
:
3042 Reloc::lo10(view
, value
, addend
);
3047 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3048 _("unsupported reloc %u"),
3052 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3053 // If we're creating a shared library, a dynamic relocation will
3054 // have been created for this location, so do not apply it now.
3055 if (!parameters
->options().shared())
3057 value
-= tls_segment
->memsz();
3058 Reloc::hix22(view
, value
, addend
);
3062 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3063 // If we're creating a shared library, a dynamic relocation will
3064 // have been created for this location, so do not apply it now.
3065 if (!parameters
->options().shared())
3067 value
-= tls_segment
->memsz();
3068 Reloc::lox10(view
, value
, addend
);
3074 // Relocate section data.
3076 template<int size
, bool big_endian
>
3078 Target_sparc
<size
, big_endian
>::relocate_section(
3079 const Relocate_info
<size
, big_endian
>* relinfo
,
3080 unsigned int sh_type
,
3081 const unsigned char* prelocs
,
3083 Output_section
* output_section
,
3084 bool needs_special_offset_handling
,
3085 unsigned char* view
,
3086 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3087 section_size_type view_size
)
3089 typedef Target_sparc
<size
, big_endian
> Sparc
;
3090 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3092 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3094 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3101 needs_special_offset_handling
,
3107 // Return the size of a relocation while scanning during a relocatable
3110 template<int size
, bool big_endian
>
3112 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3116 // We are always SHT_RELA, so we should never get here.
3121 // Scan the relocs during a relocatable link.
3123 template<int size
, bool big_endian
>
3125 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3126 const General_options
& options
,
3127 Symbol_table
* symtab
,
3129 Sized_relobj
<size
, big_endian
>* object
,
3130 unsigned int data_shndx
,
3131 unsigned int sh_type
,
3132 const unsigned char* prelocs
,
3134 Output_section
* output_section
,
3135 bool needs_special_offset_handling
,
3136 size_t local_symbol_count
,
3137 const unsigned char* plocal_symbols
,
3138 Relocatable_relocs
* rr
)
3140 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3142 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3143 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3145 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3146 Scan_relocatable_relocs
>(
3155 needs_special_offset_handling
,
3161 // Relocate a section during a relocatable link.
3163 template<int size
, bool big_endian
>
3165 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3166 const Relocate_info
<size
, big_endian
>* relinfo
,
3167 unsigned int sh_type
,
3168 const unsigned char* prelocs
,
3170 Output_section
* output_section
,
3171 off_t offset_in_output_section
,
3172 const Relocatable_relocs
* rr
,
3173 unsigned char* view
,
3174 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3175 section_size_type view_size
,
3176 unsigned char* reloc_view
,
3177 section_size_type reloc_view_size
)
3179 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3181 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3186 offset_in_output_section
,
3195 // Return the value to use for a dynamic which requires special
3196 // treatment. This is how we support equality comparisons of function
3197 // pointers across shared library boundaries, as described in the
3198 // processor specific ABI supplement.
3200 template<int size
, bool big_endian
>
3202 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3204 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3205 return this->plt_section()->address() + gsym
->plt_offset();
3208 // The selector for sparc object files.
3210 template<int size
, bool big_endian
>
3211 class Target_selector_sparc
: public Target_selector
3214 Target_selector_sparc()
3215 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3216 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3219 Target
* instantiated_target_
;
3221 Target
* do_recognize(int machine
, int, int)
3226 if (machine
!= elfcpp::EM_SPARCV9
)
3231 if (machine
!= elfcpp::EM_SPARC
3232 && machine
!= elfcpp::EM_SPARC32PLUS
)
3240 return do_instantiate_target();
3243 Target
* do_instantiate_target()
3245 if (this->instantiated_target_
== NULL
)
3246 this->instantiated_target_
= new Target_sparc
<size
, big_endian
>();
3247 return this->instantiated_target_
;
3251 Target_selector_sparc
<32, true> target_selector_sparc32
;
3252 Target_selector_sparc
<64, true> target_selector_sparc64
;
3254 } // End anonymous namespace.