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 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
236 unsigned int r_type
, const Sized_symbol
<size
>*,
237 const Symbol_value
<size
>*,
239 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
243 // Do a TLS relocation.
245 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
246 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
247 unsigned int r_type
, const Sized_symbol
<size
>*,
248 const Symbol_value
<size
>*,
250 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
253 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
257 // A class which returns the size required for a relocation type,
258 // used while scanning relocs during a relocatable link.
259 class Relocatable_size_for_reloc
263 get_size_for_reloc(unsigned int, Relobj
*);
266 // Get the GOT section, creating it if necessary.
267 Output_data_got
<size
, big_endian
>*
268 got_section(Symbol_table
*, Layout
*);
270 // Create a PLT entry for a global symbol.
272 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
274 // Create a GOT entry for the TLS module index.
276 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
277 Sized_relobj
<size
, big_endian
>* object
);
279 // Return the gsym for "__tls_get_addr". Cache if not already
282 tls_get_addr_sym(Symbol_table
* symtab
)
284 if (!this->tls_get_addr_sym_
)
285 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
286 gold_assert(this->tls_get_addr_sym_
);
287 return this->tls_get_addr_sym_
;
290 // Get the PLT section.
291 const Output_data_plt_sparc
<size
, big_endian
>*
294 gold_assert(this->plt_
!= NULL
);
298 // Get the dynamic reloc section, creating it if necessary.
300 rela_dyn_section(Layout
*);
302 // Return true if the symbol may need a COPY relocation.
303 // References from an executable object to non-function symbols
304 // defined in a dynamic object may need a COPY relocation.
306 may_need_copy_reloc(Symbol
* gsym
)
308 return (!parameters
->options().shared()
309 && gsym
->is_from_dynobj()
310 && gsym
->type() != elfcpp::STT_FUNC
);
313 // Copy a relocation against a global symbol.
315 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
316 Sized_relobj
<size
, big_endian
>* object
,
317 unsigned int shndx
, Output_section
* output_section
,
318 Symbol
* sym
, const elfcpp::Rela
<size
, big_endian
>& reloc
)
320 this->copy_relocs_
.copy_reloc(symtab
, layout
,
321 symtab
->get_sized_symbol
<size
>(sym
),
322 object
, shndx
, output_section
,
323 reloc
, this->rela_dyn_section(layout
));
326 // Information about this specific target which we pass to the
327 // general Target structure.
328 static Target::Target_info sparc_info
;
330 // The types of GOT entries needed for this platform.
333 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
334 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
335 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
339 Output_data_got
<size
, big_endian
>* got_
;
341 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
342 // The dynamic reloc section.
343 Reloc_section
* rela_dyn_
;
344 // Relocs saved to avoid a COPY reloc.
345 Copy_relocs
<elfcpp::SHT_RELA
, size
, big_endian
> copy_relocs_
;
346 // Space for variables copied with a COPY reloc.
347 Output_data_space
* dynbss_
;
348 // Offset of the GOT entry for the TLS module index;
349 unsigned int got_mod_index_offset_
;
350 // Cached pointer to __tls_get_addr symbol
351 Symbol
* tls_get_addr_sym_
;
355 Target::Target_info Target_sparc
<32, true>::sparc_info
=
358 true, // is_big_endian
359 elfcpp::EM_SPARC
, // machine_code
360 false, // has_make_symbol
361 false, // has_resolve
362 false, // has_code_fill
363 true, // is_default_stack_executable
365 "/usr/lib/ld.so.1", // dynamic_linker
366 0x00010000, // default_text_segment_address
367 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
368 8 * 1024 // common_pagesize (overridable by -z common-page-size)
372 Target::Target_info Target_sparc
<64, true>::sparc_info
=
375 true, // is_big_endian
376 elfcpp::EM_SPARCV9
, // machine_code
377 false, // has_make_symbol
378 false, // has_resolve
379 false, // has_code_fill
380 true, // is_default_stack_executable
382 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
383 0x100000, // default_text_segment_address
384 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
385 8 * 1024 // common_pagesize (overridable by -z common-page-size)
388 // We have to take care here, even when operating in little-endian
389 // mode, sparc instructions are still big endian.
390 template<int size
, bool big_endian
>
391 class Sparc_relocate_functions
394 // Do a simple relocation with the addend in the relocation.
395 template<int valsize
>
397 rela(unsigned char* view
,
398 unsigned int right_shift
,
399 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
400 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
401 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
403 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
404 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
405 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
406 Valtype reloc
= ((value
+ addend
) >> right_shift
);
411 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
414 // Do a simple relocation using a symbol value with the addend in
416 template<int valsize
>
418 rela(unsigned char* view
,
419 unsigned int right_shift
,
420 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
421 const Sized_relobj
<size
, big_endian
>* object
,
422 const Symbol_value
<size
>* psymval
,
423 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
425 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
426 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
427 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
428 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
433 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
436 // Do a simple relocation using a symbol value with the addend in
437 // the relocation, unaligned.
438 template<int valsize
>
440 rela_ua(unsigned char* view
,
441 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
442 const Sized_relobj
<size
, big_endian
>* object
,
443 const Symbol_value
<size
>* psymval
,
444 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
446 typedef typename
elfcpp::Swap_unaligned
<valsize
,
447 big_endian
>::Valtype Valtype
;
448 unsigned char* wv
= view
;
449 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
450 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
455 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
458 // Do a simple PC relative relocation with a Symbol_value with the
459 // addend in the relocation.
460 template<int valsize
>
462 pcrela(unsigned char* view
,
463 unsigned int right_shift
,
464 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
465 const Sized_relobj
<size
, big_endian
>* object
,
466 const Symbol_value
<size
>* psymval
,
467 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
468 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
470 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
471 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
472 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
473 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
479 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
482 template<int valsize
>
484 pcrela_unaligned(unsigned char* view
,
485 const Sized_relobj
<size
, big_endian
>* object
,
486 const Symbol_value
<size
>* psymval
,
487 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
488 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
490 typedef typename
elfcpp::Swap_unaligned
<valsize
,
491 big_endian
>::Valtype Valtype
;
492 unsigned char* wv
= view
;
493 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
495 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
498 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
499 typedef Sparc_relocate_functions
<size
, true> This_insn
;
502 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
504 wdisp30(unsigned char* view
,
505 const Sized_relobj
<size
, big_endian
>* object
,
506 const Symbol_value
<size
>* psymval
,
507 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
508 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
510 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
511 psymval
, addend
, address
);
514 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
516 wdisp22(unsigned char* view
,
517 const Sized_relobj
<size
, big_endian
>* object
,
518 const Symbol_value
<size
>* psymval
,
519 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
520 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
522 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
523 psymval
, addend
, address
);
526 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
528 wdisp19(unsigned char* view
,
529 const Sized_relobj
<size
, big_endian
>* object
,
530 const Symbol_value
<size
>* psymval
,
531 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
532 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
534 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
535 psymval
, addend
, address
);
538 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
540 wdisp16(unsigned char* view
,
541 const Sized_relobj
<size
, big_endian
>* object
,
542 const Symbol_value
<size
>* psymval
,
543 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
544 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
546 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
547 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
548 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
549 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
552 // The relocation value is split between the low 14 bits,
554 val
&= ~((0x3 << 20) | 0x3fff);
555 reloc
= (((reloc
& 0xc000) << (20 - 14))
556 | (reloc
& 0x3ffff));
558 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
561 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
563 pc22(unsigned char* view
,
564 const Sized_relobj
<size
, big_endian
>* object
,
565 const Symbol_value
<size
>* psymval
,
566 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
567 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
569 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
570 psymval
, addend
, address
);
573 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
575 pc10(unsigned char* view
,
576 const Sized_relobj
<size
, big_endian
>* object
,
577 const Symbol_value
<size
>* psymval
,
578 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
579 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
581 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
582 psymval
, addend
, address
);
585 // R_SPARC_HI22: (Symbol + Addend) >> 10
587 hi22(unsigned char* view
,
588 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
589 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
591 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
594 // R_SPARC_HI22: (Symbol + Addend) >> 10
596 hi22(unsigned char* view
,
597 const Sized_relobj
<size
, big_endian
>* object
,
598 const Symbol_value
<size
>* psymval
,
599 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
601 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
604 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
606 pcplt22(unsigned char* view
,
607 const Sized_relobj
<size
, big_endian
>* object
,
608 const Symbol_value
<size
>* psymval
,
609 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
610 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
612 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
613 psymval
, addend
, address
);
616 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
618 lo10(unsigned char* view
,
619 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
620 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
622 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
625 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
627 lo10(unsigned char* view
,
628 const Sized_relobj
<size
, big_endian
>* object
,
629 const Symbol_value
<size
>* psymval
,
630 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
632 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
635 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
637 lo10(unsigned char* view
,
638 const Sized_relobj
<size
, big_endian
>* object
,
639 const Symbol_value
<size
>* psymval
,
640 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
641 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
643 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
644 psymval
, addend
, address
);
647 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
649 olo10(unsigned char* view
,
650 const Sized_relobj
<size
, big_endian
>* object
,
651 const Symbol_value
<size
>* psymval
,
652 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
653 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
655 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
656 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
657 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
658 Valtype reloc
= psymval
->value(object
, addend
);
665 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
668 // R_SPARC_22: (Symbol + Addend)
670 rela32_22(unsigned char* view
,
671 const Sized_relobj
<size
, big_endian
>* object
,
672 const Symbol_value
<size
>* psymval
,
673 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
675 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
678 // R_SPARC_13: (Symbol + Addend)
680 rela32_13(unsigned char* view
,
681 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
682 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
684 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
687 // R_SPARC_13: (Symbol + Addend)
689 rela32_13(unsigned char* view
,
690 const Sized_relobj
<size
, big_endian
>* object
,
691 const Symbol_value
<size
>* psymval
,
692 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
694 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
697 // R_SPARC_UA16: (Symbol + Addend)
699 ua16(unsigned char* view
,
700 const Sized_relobj
<size
, big_endian
>* object
,
701 const Symbol_value
<size
>* psymval
,
702 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
704 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
707 // R_SPARC_UA32: (Symbol + Addend)
709 ua32(unsigned char* view
,
710 const Sized_relobj
<size
, big_endian
>* object
,
711 const Symbol_value
<size
>* psymval
,
712 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
714 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
717 // R_SPARC_UA64: (Symbol + Addend)
719 ua64(unsigned char* view
,
720 const Sized_relobj
<size
, big_endian
>* object
,
721 const Symbol_value
<size
>* psymval
,
722 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
724 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
725 object
, psymval
, addend
);
728 // R_SPARC_DISP8: (Symbol + Addend - Address)
730 disp8(unsigned char* view
,
731 const Sized_relobj
<size
, big_endian
>* object
,
732 const Symbol_value
<size
>* psymval
,
733 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
734 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
736 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
740 // R_SPARC_DISP16: (Symbol + Addend - Address)
742 disp16(unsigned char* view
,
743 const Sized_relobj
<size
, big_endian
>* object
,
744 const Symbol_value
<size
>* psymval
,
745 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
746 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
748 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
752 // R_SPARC_DISP32: (Symbol + Addend - Address)
754 disp32(unsigned char* view
,
755 const Sized_relobj
<size
, big_endian
>* object
,
756 const Symbol_value
<size
>* psymval
,
757 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
758 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
760 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
764 // R_SPARC_DISP64: (Symbol + Addend - Address)
766 disp64(unsigned char* view
,
767 const Sized_relobj
<size
, big_endian
>* object
,
768 const Symbol_value
<size
>* psymval
,
769 elfcpp::Elf_Xword addend
,
770 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
772 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
776 // R_SPARC_H44: (Symbol + Addend) >> 22
778 h44(unsigned char* view
,
779 const Sized_relobj
<size
, big_endian
>* object
,
780 const Symbol_value
<size
>* psymval
,
781 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
783 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
786 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
788 m44(unsigned char* view
,
789 const Sized_relobj
<size
, big_endian
>* object
,
790 const Symbol_value
<size
>* psymval
,
791 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
793 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
796 // R_SPARC_L44: (Symbol + Addend) & 0xfff
798 l44(unsigned char* view
,
799 const Sized_relobj
<size
, big_endian
>* object
,
800 const Symbol_value
<size
>* psymval
,
801 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
803 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
806 // R_SPARC_HH22: (Symbol + Addend) >> 42
808 hh22(unsigned char* view
,
809 const Sized_relobj
<size
, big_endian
>* object
,
810 const Symbol_value
<size
>* psymval
,
811 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
813 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
816 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
818 pc_hh22(unsigned char* view
,
819 const Sized_relobj
<size
, big_endian
>* object
,
820 const Symbol_value
<size
>* psymval
,
821 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
822 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
824 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
825 psymval
, addend
, address
);
828 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
830 hm10(unsigned char* view
,
831 const Sized_relobj
<size
, big_endian
>* object
,
832 const Symbol_value
<size
>* psymval
,
833 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
835 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
838 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
840 pc_hm10(unsigned char* view
,
841 const Sized_relobj
<size
, big_endian
>* object
,
842 const Symbol_value
<size
>* psymval
,
843 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
844 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
846 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
847 psymval
, addend
, address
);
850 // R_SPARC_11: (Symbol + Addend)
852 rela32_11(unsigned char* view
,
853 const Sized_relobj
<size
, big_endian
>* object
,
854 const Symbol_value
<size
>* psymval
,
855 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
857 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
860 // R_SPARC_10: (Symbol + Addend)
862 rela32_10(unsigned char* view
,
863 const Sized_relobj
<size
, big_endian
>* object
,
864 const Symbol_value
<size
>* psymval
,
865 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
867 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
870 // R_SPARC_7: (Symbol + Addend)
872 rela32_7(unsigned char* view
,
873 const Sized_relobj
<size
, big_endian
>* object
,
874 const Symbol_value
<size
>* psymval
,
875 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
877 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
880 // R_SPARC_6: (Symbol + Addend)
882 rela32_6(unsigned char* view
,
883 const Sized_relobj
<size
, big_endian
>* object
,
884 const Symbol_value
<size
>* psymval
,
885 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
887 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
890 // R_SPARC_5: (Symbol + Addend)
892 rela32_5(unsigned char* view
,
893 const Sized_relobj
<size
, big_endian
>* object
,
894 const Symbol_value
<size
>* psymval
,
895 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
897 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
900 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
902 ldo_hix22(unsigned char* view
,
903 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
904 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
906 This_insn::hi22(view
, value
, addend
);
909 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
911 ldo_lox10(unsigned char* view
,
912 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
913 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
915 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
916 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
917 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
918 Valtype reloc
= (value
+ addend
);
923 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
926 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
928 hix22(unsigned char* view
,
929 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
930 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
932 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
933 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
934 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
935 Valtype reloc
= (value
+ addend
);
939 reloc
^= ~(Valtype
)0;
944 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
947 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
949 hix22(unsigned char* view
,
950 const Sized_relobj
<size
, big_endian
>* object
,
951 const Symbol_value
<size
>* psymval
,
952 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
954 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
955 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
956 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
957 Valtype reloc
= psymval
->value(object
, addend
);
961 reloc
^= ~(Valtype
)0;
966 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
970 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
972 lox10(unsigned char* view
,
973 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
974 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
976 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
977 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
978 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
979 Valtype reloc
= (value
+ addend
);
985 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
988 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
990 lox10(unsigned char* view
,
991 const Sized_relobj
<size
, big_endian
>* object
,
992 const Symbol_value
<size
>* psymval
,
993 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
995 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
996 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
997 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
998 Valtype reloc
= psymval
->value(object
, addend
);
1004 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
1008 // Get the GOT section, creating it if necessary.
1010 template<int size
, bool big_endian
>
1011 Output_data_got
<size
, big_endian
>*
1012 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
1015 if (this->got_
== NULL
)
1017 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1019 this->got_
= new Output_data_got
<size
, big_endian
>();
1022 os
= layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1024 | elfcpp::SHF_WRITE
),
1028 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1029 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1031 0, 0, elfcpp::STT_OBJECT
,
1033 elfcpp::STV_HIDDEN
, 0,
1040 // Get the dynamic reloc section, creating it if necessary.
1042 template<int size
, bool big_endian
>
1043 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1044 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1046 if (this->rela_dyn_
== NULL
)
1048 gold_assert(layout
!= NULL
);
1049 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1050 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1051 elfcpp::SHF_ALLOC
, this->rela_dyn_
);
1053 return this->rela_dyn_
;
1056 // A class to handle the PLT data.
1058 template<int size
, bool big_endian
>
1059 class Output_data_plt_sparc
: public Output_section_data
1062 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1063 size
, big_endian
> Reloc_section
;
1065 Output_data_plt_sparc(Layout
*);
1067 // Add an entry to the PLT.
1068 void add_entry(Symbol
* gsym
);
1070 // Return the .rela.plt section data.
1071 const Reloc_section
* rel_plt() const
1077 void do_adjust_output_section(Output_section
* os
);
1079 // Write to a map file.
1081 do_print_to_mapfile(Mapfile
* mapfile
) const
1082 { mapfile
->print_output_data(this, _("** PLT")); }
1085 // The size of an entry in the PLT.
1086 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1088 static const unsigned int plt_entries_per_block
= 160;
1089 static const unsigned int plt_insn_chunk_size
= 24;
1090 static const unsigned int plt_pointer_chunk_size
= 8;
1091 static const unsigned int plt_block_size
=
1092 (plt_entries_per_block
1093 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1095 // Set the final size.
1097 set_final_data_size()
1099 unsigned int full_count
= this->count_
+ 4;
1100 unsigned int extra
= (size
== 32 ? 4 : 0);
1102 if (size
== 32 || full_count
< 32768)
1103 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1106 unsigned int ext_cnt
= full_count
- 32768;
1108 this->set_data_size((32768 * base_plt_entry_size
)
1110 * (plt_insn_chunk_size
1111 + plt_pointer_chunk_size
)));
1115 // Write out the PLT data.
1117 do_write(Output_file
*);
1119 // The reloc section.
1120 Reloc_section
* rel_
;
1121 // The number of PLT entries.
1122 unsigned int count_
;
1125 // Define the constants as required by C++ standard.
1127 template<int size
, bool big_endian
>
1128 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1130 template<int size
, bool big_endian
>
1132 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1134 template<int size
, bool big_endian
>
1135 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1137 template<int size
, bool big_endian
>
1139 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1141 template<int size
, bool big_endian
>
1142 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1144 // Create the PLT section. The ordinary .got section is an argument,
1145 // since we need to refer to the start.
1147 template<int size
, bool big_endian
>
1148 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1149 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1151 this->rel_
= new Reloc_section(false);
1152 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1153 elfcpp::SHF_ALLOC
, this->rel_
);
1156 template<int size
, bool big_endian
>
1158 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1163 // Add an entry to the PLT.
1165 template<int size
, bool big_endian
>
1167 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1169 gold_assert(!gsym
->has_plt_offset());
1171 unsigned int index
= this->count_
+ 4;
1172 section_offset_type plt_offset
;
1174 if (size
== 32 || index
< 32768)
1175 plt_offset
= index
* base_plt_entry_size
;
1178 unsigned int ext_index
= index
- 32768;
1180 plt_offset
= (32768 * base_plt_entry_size
)
1181 + ((ext_index
/ plt_entries_per_block
)
1183 + ((ext_index
% plt_entries_per_block
)
1184 * plt_insn_chunk_size
);
1187 gsym
->set_plt_offset(plt_offset
);
1191 // Every PLT entry needs a reloc.
1192 gsym
->set_needs_dynsym_entry();
1193 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1196 // Note that we don't need to save the symbol. The contents of the
1197 // PLT are independent of which symbols are used. The symbols only
1198 // appear in the relocations.
1201 static const unsigned int sparc_nop
= 0x01000000;
1202 static const unsigned int sparc_sethi_g1
= 0x03000000;
1203 static const unsigned int sparc_branch_always
= 0x30800000;
1204 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1205 static const unsigned int sparc_mov
= 0x80100000;
1206 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1207 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1208 static const unsigned int sparc_call_plus_8
= 0x40000002;
1209 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1210 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1211 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1213 // Write out the PLT.
1215 template<int size
, bool big_endian
>
1217 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1219 const off_t offset
= this->offset();
1220 const section_size_type oview_size
=
1221 convert_to_section_size_type(this->data_size());
1222 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1223 unsigned char* pov
= oview
;
1225 memset(pov
, 0, base_plt_entry_size
* 4);
1226 pov
+= base_plt_entry_size
* 4;
1228 unsigned int plt_offset
= base_plt_entry_size
* 4;
1229 const unsigned int count
= this->count_
;
1235 limit
= (count
> 32768 ? 32768 : count
);
1237 for (unsigned int i
= 0; i
< limit
; ++i
)
1239 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1240 sparc_sethi_g1
+ plt_offset
);
1241 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1242 sparc_branch_always_pt
+
1243 (((base_plt_entry_size
-
1244 (plt_offset
+ 4)) >> 2) &
1246 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1247 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1248 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1249 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1250 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1251 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1253 pov
+= base_plt_entry_size
;
1254 plt_offset
+= base_plt_entry_size
;
1259 unsigned int ext_cnt
= count
- 32768;
1260 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1262 for (unsigned int i
= 0; i
< blks
; ++i
)
1264 unsigned int data_off
= (plt_entries_per_block
1265 * plt_insn_chunk_size
) - 4;
1267 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1269 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1271 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1273 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1275 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1276 sparc_ldx_o7_imm_g1
+
1277 (data_off
& 0x1fff));
1278 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1279 sparc_jmpl_o7_g1_g1
);
1280 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1283 elfcpp::Swap
<64, big_endian
>::writeval(
1284 pov
+ 0x4 + data_off
,
1285 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1287 pov
+= plt_insn_chunk_size
;
1292 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1293 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1295 unsigned int data_off
= (sub_blk_cnt
1296 * plt_insn_chunk_size
) - 4;
1298 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1300 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1302 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1304 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1306 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1307 sparc_ldx_o7_imm_g1
+
1308 (data_off
& 0x1fff));
1309 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1310 sparc_jmpl_o7_g1_g1
);
1311 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1314 elfcpp::Swap
<64, big_endian
>::writeval(
1315 pov
+ 0x4 + data_off
,
1316 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1318 pov
+= plt_insn_chunk_size
;
1326 for (unsigned int i
= 0; i
< count
; ++i
)
1328 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1329 sparc_sethi_g1
+ plt_offset
);
1330 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1331 sparc_branch_always
+
1332 (((- (plt_offset
+ 4)) >> 2) &
1334 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1336 pov
+= base_plt_entry_size
;
1337 plt_offset
+= base_plt_entry_size
;
1340 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1344 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1346 of
->write_output_view(offset
, oview_size
, oview
);
1349 // Create a PLT entry for a global symbol.
1351 template<int size
, bool big_endian
>
1353 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1357 if (gsym
->has_plt_offset())
1360 if (this->plt_
== NULL
)
1362 // Create the GOT sections first.
1363 this->got_section(symtab
, layout
);
1365 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1366 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1368 | elfcpp::SHF_EXECINSTR
1369 | elfcpp::SHF_WRITE
),
1372 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1373 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1375 0, 0, elfcpp::STT_OBJECT
,
1377 elfcpp::STV_HIDDEN
, 0,
1381 this->plt_
->add_entry(gsym
);
1384 // Create a GOT entry for the TLS module index.
1386 template<int size
, bool big_endian
>
1388 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1390 Sized_relobj
<size
, big_endian
>* object
)
1392 if (this->got_mod_index_offset_
== -1U)
1394 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1395 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1396 Output_data_got
<size
, big_endian
>* got
;
1397 unsigned int got_offset
;
1399 got
= this->got_section(symtab
, layout
);
1400 got_offset
= got
->add_constant(0);
1401 rela_dyn
->add_local(object
, 0,
1403 elfcpp::R_SPARC_TLS_DTPMOD64
:
1404 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1406 got
->add_constant(0);
1407 this->got_mod_index_offset_
= got_offset
;
1409 return this->got_mod_index_offset_
;
1412 // Optimize the TLS relocation type based on what we know about the
1413 // symbol. IS_FINAL is true if the final address of this symbol is
1414 // known at link time.
1416 static tls::Tls_optimization
1417 optimize_tls_reloc(bool is_final
, int r_type
)
1419 // If we are generating a shared library, then we can't do anything
1421 if (parameters
->options().shared())
1422 return tls::TLSOPT_NONE
;
1426 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1427 case elfcpp::R_SPARC_TLS_GD_LO10
:
1428 case elfcpp::R_SPARC_TLS_GD_ADD
:
1429 case elfcpp::R_SPARC_TLS_GD_CALL
:
1430 // These are General-Dynamic which permits fully general TLS
1431 // access. Since we know that we are generating an executable,
1432 // we can convert this to Initial-Exec. If we also know that
1433 // this is a local symbol, we can further switch to Local-Exec.
1435 return tls::TLSOPT_TO_LE
;
1436 return tls::TLSOPT_TO_IE
;
1438 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1439 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1440 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1441 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1442 // This is Local-Dynamic, which refers to a local symbol in the
1443 // dynamic TLS block. Since we know that we generating an
1444 // executable, we can switch to Local-Exec.
1445 return tls::TLSOPT_TO_LE
;
1447 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1448 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1449 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1450 // Another type of Local-Dynamic relocation.
1451 return tls::TLSOPT_TO_LE
;
1453 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1454 case elfcpp::R_SPARC_TLS_IE_LO10
:
1455 case elfcpp::R_SPARC_TLS_IE_LD
:
1456 case elfcpp::R_SPARC_TLS_IE_LDX
:
1457 // These are Initial-Exec relocs which get the thread offset
1458 // from the GOT. If we know that we are linking against the
1459 // local symbol, we can switch to Local-Exec, which links the
1460 // thread offset into the instruction.
1462 return tls::TLSOPT_TO_LE
;
1463 return tls::TLSOPT_NONE
;
1465 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1466 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1467 // When we already have Local-Exec, there is nothing further we
1469 return tls::TLSOPT_NONE
;
1476 // Generate a PLT entry slot for a call to __tls_get_addr
1477 template<int size
, bool big_endian
>
1479 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1481 Target_sparc
<size
, big_endian
>* target
)
1483 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1485 target
->make_plt_entry(symtab
, layout
, gsym
);
1488 // Report an unsupported relocation against a local symbol.
1490 template<int size
, bool big_endian
>
1492 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1493 Sized_relobj
<size
, big_endian
>* object
,
1494 unsigned int r_type
)
1496 gold_error(_("%s: unsupported reloc %u against local symbol"),
1497 object
->name().c_str(), r_type
);
1500 // We are about to emit a dynamic relocation of type R_TYPE. If the
1501 // dynamic linker does not support it, issue an error.
1503 template<int size
, bool big_endian
>
1505 Target_sparc
<size
, big_endian
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
)
1507 gold_assert(r_type
!= elfcpp::R_SPARC_NONE
);
1513 // These are the relocation types supported by glibc for sparc 64-bit.
1514 case elfcpp::R_SPARC_RELATIVE
:
1515 case elfcpp::R_SPARC_COPY
:
1516 case elfcpp::R_SPARC_64
:
1517 case elfcpp::R_SPARC_GLOB_DAT
:
1518 case elfcpp::R_SPARC_JMP_SLOT
:
1519 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1520 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1521 case elfcpp::R_SPARC_TLS_TPOFF64
:
1522 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1523 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1524 case elfcpp::R_SPARC_8
:
1525 case elfcpp::R_SPARC_16
:
1526 case elfcpp::R_SPARC_DISP8
:
1527 case elfcpp::R_SPARC_DISP16
:
1528 case elfcpp::R_SPARC_DISP32
:
1529 case elfcpp::R_SPARC_WDISP30
:
1530 case elfcpp::R_SPARC_LO10
:
1531 case elfcpp::R_SPARC_HI22
:
1532 case elfcpp::R_SPARC_OLO10
:
1533 case elfcpp::R_SPARC_H44
:
1534 case elfcpp::R_SPARC_M44
:
1535 case elfcpp::R_SPARC_L44
:
1536 case elfcpp::R_SPARC_HH22
:
1537 case elfcpp::R_SPARC_HM10
:
1538 case elfcpp::R_SPARC_LM22
:
1539 case elfcpp::R_SPARC_UA16
:
1540 case elfcpp::R_SPARC_UA32
:
1541 case elfcpp::R_SPARC_UA64
:
1552 // These are the relocation types supported by glibc for sparc 32-bit.
1553 case elfcpp::R_SPARC_RELATIVE
:
1554 case elfcpp::R_SPARC_COPY
:
1555 case elfcpp::R_SPARC_GLOB_DAT
:
1556 case elfcpp::R_SPARC_32
:
1557 case elfcpp::R_SPARC_JMP_SLOT
:
1558 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1559 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1560 case elfcpp::R_SPARC_TLS_TPOFF32
:
1561 case elfcpp::R_SPARC_TLS_LE_HIX22
:
1562 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1563 case elfcpp::R_SPARC_8
:
1564 case elfcpp::R_SPARC_16
:
1565 case elfcpp::R_SPARC_DISP8
:
1566 case elfcpp::R_SPARC_DISP16
:
1567 case elfcpp::R_SPARC_DISP32
:
1568 case elfcpp::R_SPARC_LO10
:
1569 case elfcpp::R_SPARC_WDISP30
:
1570 case elfcpp::R_SPARC_HI22
:
1571 case elfcpp::R_SPARC_UA16
:
1572 case elfcpp::R_SPARC_UA32
:
1580 // This prevents us from issuing more than one error per reloc
1581 // section. But we can still wind up issuing more than one
1582 // error per object file.
1583 if (this->issued_non_pic_error_
)
1585 object
->error(_("requires unsupported dynamic reloc; "
1586 "recompile with -fPIC"));
1587 this->issued_non_pic_error_
= true;
1591 // Scan a relocation for a local symbol.
1593 template<int size
, bool big_endian
>
1595 Target_sparc
<size
, big_endian
>::Scan::local(
1596 const General_options
&,
1597 Symbol_table
* symtab
,
1599 Target_sparc
<size
, big_endian
>* target
,
1600 Sized_relobj
<size
, big_endian
>* object
,
1601 unsigned int data_shndx
,
1602 Output_section
* output_section
,
1603 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1604 unsigned int r_type
,
1605 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1607 unsigned int orig_r_type
= r_type
;
1612 case elfcpp::R_SPARC_NONE
:
1613 case elfcpp::R_SPARC_REGISTER
:
1614 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1615 case elfcpp::R_SPARC_GNU_VTENTRY
:
1618 case elfcpp::R_SPARC_64
:
1619 case elfcpp::R_SPARC_32
:
1620 // If building a shared library (or a position-independent
1621 // executable), we need to create a dynamic relocation for
1622 // this location. The relocation applied at link time will
1623 // apply the link-time value, so we flag the location with
1624 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1625 // relocate it easily.
1626 if (parameters
->options().output_is_position_independent())
1628 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1629 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1630 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1631 output_section
, data_shndx
,
1632 reloc
.get_r_offset(),
1633 reloc
.get_r_addend());
1637 case elfcpp::R_SPARC_HIX22
:
1638 case elfcpp::R_SPARC_LOX10
:
1639 case elfcpp::R_SPARC_H44
:
1640 case elfcpp::R_SPARC_M44
:
1641 case elfcpp::R_SPARC_L44
:
1642 case elfcpp::R_SPARC_HH22
:
1643 case elfcpp::R_SPARC_HM10
:
1644 case elfcpp::R_SPARC_LM22
:
1645 case elfcpp::R_SPARC_UA64
:
1646 case elfcpp::R_SPARC_UA32
:
1647 case elfcpp::R_SPARC_UA16
:
1648 case elfcpp::R_SPARC_HI22
:
1649 case elfcpp::R_SPARC_LO10
:
1650 case elfcpp::R_SPARC_OLO10
:
1651 case elfcpp::R_SPARC_16
:
1652 case elfcpp::R_SPARC_11
:
1653 case elfcpp::R_SPARC_10
:
1654 case elfcpp::R_SPARC_8
:
1655 case elfcpp::R_SPARC_7
:
1656 case elfcpp::R_SPARC_6
:
1657 case elfcpp::R_SPARC_5
:
1658 // If building a shared library (or a position-independent
1659 // executable), we need to create a dynamic relocation for
1661 if (parameters
->options().output_is_position_independent())
1663 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1665 check_non_pic(object
, r_type
);
1666 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1668 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1669 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1670 data_shndx
, reloc
.get_r_offset(),
1671 reloc
.get_r_addend());
1675 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1676 gold_assert(lsym
.get_st_value() == 0);
1677 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1678 output_section
, data_shndx
,
1679 reloc
.get_r_offset(),
1680 reloc
.get_r_addend());
1685 case elfcpp::R_SPARC_WDISP30
:
1686 case elfcpp::R_SPARC_WDISP22
:
1687 case elfcpp::R_SPARC_WDISP19
:
1688 case elfcpp::R_SPARC_WDISP16
:
1689 case elfcpp::R_SPARC_DISP8
:
1690 case elfcpp::R_SPARC_DISP16
:
1691 case elfcpp::R_SPARC_DISP32
:
1692 case elfcpp::R_SPARC_DISP64
:
1693 case elfcpp::R_SPARC_PC10
:
1694 case elfcpp::R_SPARC_PC22
:
1697 case elfcpp::R_SPARC_GOT10
:
1698 case elfcpp::R_SPARC_GOT13
:
1699 case elfcpp::R_SPARC_GOT22
:
1701 // The symbol requires a GOT entry.
1702 Output_data_got
<size
, big_endian
>* got
;
1705 got
= target
->got_section(symtab
, layout
);
1706 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1708 // If we are generating a shared object, we need to add a
1709 // dynamic relocation for this symbol's GOT entry.
1710 if (parameters
->options().output_is_position_independent())
1712 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1714 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1717 off
= got
->add_constant(0);
1718 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1719 rela_dyn
->add_local_relative(object
, r_sym
,
1720 elfcpp::R_SPARC_RELATIVE
,
1725 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1729 // These are initial TLS relocs, which are expected when
1731 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1732 case elfcpp::R_SPARC_TLS_GD_LO10
:
1733 case elfcpp::R_SPARC_TLS_GD_ADD
:
1734 case elfcpp::R_SPARC_TLS_GD_CALL
:
1735 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1736 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1737 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1738 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1739 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1740 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1741 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1742 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1743 case elfcpp::R_SPARC_TLS_IE_LO10
:
1744 case elfcpp::R_SPARC_TLS_IE_LD
:
1745 case elfcpp::R_SPARC_TLS_IE_LDX
:
1746 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1747 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1749 bool output_is_shared
= parameters
->options().shared();
1750 const tls::Tls_optimization optimized_type
1751 = optimize_tls_reloc(!output_is_shared
, r_type
);
1754 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1755 case elfcpp::R_SPARC_TLS_GD_LO10
:
1756 case elfcpp::R_SPARC_TLS_GD_ADD
:
1757 case elfcpp::R_SPARC_TLS_GD_CALL
:
1758 if (optimized_type
== tls::TLSOPT_NONE
)
1760 // Create a pair of GOT entries for the module index and
1761 // dtv-relative offset.
1762 Output_data_got
<size
, big_endian
>* got
1763 = target
->got_section(symtab
, layout
);
1764 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1765 unsigned int shndx
= lsym
.get_st_shndx();
1767 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
1769 object
->error(_("local symbol %u has bad shndx %u"),
1772 got
->add_local_pair_with_rela(object
, r_sym
,
1773 lsym
.get_st_shndx(),
1775 target
->rela_dyn_section(layout
),
1777 ? elfcpp::R_SPARC_TLS_DTPMOD64
1778 : elfcpp::R_SPARC_TLS_DTPMOD32
),
1780 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1781 generate_tls_call(symtab
, layout
, target
);
1783 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1784 unsupported_reloc_local(object
, r_type
);
1787 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1788 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1789 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1790 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1791 if (optimized_type
== tls::TLSOPT_NONE
)
1793 // Create a GOT entry for the module index.
1794 target
->got_mod_index_entry(symtab
, layout
, object
);
1796 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1797 generate_tls_call(symtab
, layout
, target
);
1799 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1800 unsupported_reloc_local(object
, r_type
);
1803 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1804 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1805 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1808 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1809 case elfcpp::R_SPARC_TLS_IE_LO10
:
1810 case elfcpp::R_SPARC_TLS_IE_LD
:
1811 case elfcpp::R_SPARC_TLS_IE_LDX
:
1812 layout
->set_has_static_tls();
1813 if (optimized_type
== tls::TLSOPT_NONE
)
1815 // Create a GOT entry for the tp-relative offset.
1816 Output_data_got
<size
, big_endian
>* got
1817 = target
->got_section(symtab
, layout
);
1818 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1820 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1822 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1823 unsigned int off
= got
->add_constant(0);
1825 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1827 rela_dyn
->add_local_relative(object
, r_sym
,
1829 elfcpp::R_SPARC_TLS_TPOFF64
:
1830 elfcpp::R_SPARC_TLS_TPOFF32
),
1834 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1835 unsupported_reloc_local(object
, r_type
);
1838 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1839 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1840 layout
->set_has_static_tls();
1841 if (output_is_shared
)
1843 // We need to create a dynamic relocation.
1844 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1845 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1846 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1847 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1848 output_section
, data_shndx
,
1849 reloc
.get_r_offset(), 0);
1856 // These are relocations which should only be seen by the
1857 // dynamic linker, and should never be seen here.
1858 case elfcpp::R_SPARC_COPY
:
1859 case elfcpp::R_SPARC_GLOB_DAT
:
1860 case elfcpp::R_SPARC_JMP_SLOT
:
1861 case elfcpp::R_SPARC_RELATIVE
:
1862 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1863 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1864 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1865 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1866 case elfcpp::R_SPARC_TLS_TPOFF64
:
1867 case elfcpp::R_SPARC_TLS_TPOFF32
:
1868 gold_error(_("%s: unexpected reloc %u in object file"),
1869 object
->name().c_str(), r_type
);
1873 unsupported_reloc_local(object
, r_type
);
1878 // Report an unsupported relocation against a global symbol.
1880 template<int size
, bool big_endian
>
1882 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1883 Sized_relobj
<size
, big_endian
>* object
,
1884 unsigned int r_type
,
1887 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1888 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1891 // Scan a relocation for a global symbol.
1893 template<int size
, bool big_endian
>
1895 Target_sparc
<size
, big_endian
>::Scan::global(
1896 const General_options
&,
1897 Symbol_table
* symtab
,
1899 Target_sparc
<size
, big_endian
>* target
,
1900 Sized_relobj
<size
, big_endian
>* object
,
1901 unsigned int data_shndx
,
1902 Output_section
* output_section
,
1903 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1904 unsigned int r_type
,
1907 unsigned int orig_r_type
= r_type
;
1912 case elfcpp::R_SPARC_NONE
:
1913 case elfcpp::R_SPARC_REGISTER
:
1914 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1915 case elfcpp::R_SPARC_GNU_VTENTRY
:
1918 case elfcpp::R_SPARC_PLT64
:
1919 case elfcpp::R_SPARC_PLT32
:
1920 case elfcpp::R_SPARC_HIPLT22
:
1921 case elfcpp::R_SPARC_LOPLT10
:
1922 case elfcpp::R_SPARC_PCPLT32
:
1923 case elfcpp::R_SPARC_PCPLT22
:
1924 case elfcpp::R_SPARC_PCPLT10
:
1925 case elfcpp::R_SPARC_WPLT30
:
1926 // If the symbol is fully resolved, this is just a PC32 reloc.
1927 // Otherwise we need a PLT entry.
1928 if (gsym
->final_value_is_known())
1930 // If building a shared library, we can also skip the PLT entry
1931 // if the symbol is defined in the output file and is protected
1933 if (gsym
->is_defined()
1934 && !gsym
->is_from_dynobj()
1935 && !gsym
->is_preemptible())
1937 target
->make_plt_entry(symtab
, layout
, gsym
);
1940 case elfcpp::R_SPARC_DISP8
:
1941 case elfcpp::R_SPARC_DISP16
:
1942 case elfcpp::R_SPARC_DISP32
:
1943 case elfcpp::R_SPARC_DISP64
:
1944 case elfcpp::R_SPARC_PC_HH22
:
1945 case elfcpp::R_SPARC_PC_HM10
:
1946 case elfcpp::R_SPARC_PC_LM22
:
1947 case elfcpp::R_SPARC_PC10
:
1948 case elfcpp::R_SPARC_PC22
:
1949 case elfcpp::R_SPARC_WDISP30
:
1950 case elfcpp::R_SPARC_WDISP22
:
1951 case elfcpp::R_SPARC_WDISP19
:
1952 case elfcpp::R_SPARC_WDISP16
:
1954 if (gsym
->needs_plt_entry())
1955 target
->make_plt_entry(symtab
, layout
, gsym
);
1956 // Make a dynamic relocation if necessary.
1957 int flags
= Symbol::NON_PIC_REF
;
1958 if (gsym
->type() == elfcpp::STT_FUNC
)
1959 flags
|= Symbol::FUNCTION_CALL
;
1960 if (gsym
->needs_dynamic_reloc(flags
))
1962 if (target
->may_need_copy_reloc(gsym
))
1964 target
->copy_reloc(symtab
, layout
, object
,
1965 data_shndx
, output_section
, gsym
,
1970 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1971 check_non_pic(object
, r_type
);
1972 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1973 data_shndx
, reloc
.get_r_offset(),
1974 reloc
.get_r_addend());
1980 case elfcpp::R_SPARC_UA64
:
1981 case elfcpp::R_SPARC_64
:
1982 case elfcpp::R_SPARC_HIX22
:
1983 case elfcpp::R_SPARC_LOX10
:
1984 case elfcpp::R_SPARC_H44
:
1985 case elfcpp::R_SPARC_M44
:
1986 case elfcpp::R_SPARC_L44
:
1987 case elfcpp::R_SPARC_HH22
:
1988 case elfcpp::R_SPARC_HM10
:
1989 case elfcpp::R_SPARC_LM22
:
1990 case elfcpp::R_SPARC_HI22
:
1991 case elfcpp::R_SPARC_LO10
:
1992 case elfcpp::R_SPARC_OLO10
:
1993 case elfcpp::R_SPARC_UA32
:
1994 case elfcpp::R_SPARC_32
:
1995 case elfcpp::R_SPARC_UA16
:
1996 case elfcpp::R_SPARC_16
:
1997 case elfcpp::R_SPARC_11
:
1998 case elfcpp::R_SPARC_10
:
1999 case elfcpp::R_SPARC_8
:
2000 case elfcpp::R_SPARC_7
:
2001 case elfcpp::R_SPARC_6
:
2002 case elfcpp::R_SPARC_5
:
2004 // Make a PLT entry if necessary.
2005 if (gsym
->needs_plt_entry())
2007 target
->make_plt_entry(symtab
, layout
, gsym
);
2008 // Since this is not a PC-relative relocation, we may be
2009 // taking the address of a function. In that case we need to
2010 // set the entry in the dynamic symbol table to the address of
2012 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
2013 gsym
->set_needs_dynsym_value();
2015 // Make a dynamic relocation if necessary.
2016 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
2018 if (target
->may_need_copy_reloc(gsym
))
2020 target
->copy_reloc(symtab
, layout
, object
,
2021 data_shndx
, output_section
, gsym
, reloc
);
2023 else if ((r_type
== elfcpp::R_SPARC_32
2024 || r_type
== elfcpp::R_SPARC_64
)
2025 && gsym
->can_use_relative_reloc(false))
2027 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2028 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2029 output_section
, object
,
2030 data_shndx
, reloc
.get_r_offset(),
2031 reloc
.get_r_addend());
2035 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2037 check_non_pic(object
, r_type
);
2038 if (gsym
->is_from_dynobj()
2039 || gsym
->is_undefined()
2040 || gsym
->is_preemptible())
2041 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
2043 reloc
.get_r_offset(),
2044 reloc
.get_r_addend());
2046 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2047 output_section
, object
,
2049 reloc
.get_r_offset(),
2050 reloc
.get_r_addend());
2056 case elfcpp::R_SPARC_GOT10
:
2057 case elfcpp::R_SPARC_GOT13
:
2058 case elfcpp::R_SPARC_GOT22
:
2060 // The symbol requires a GOT entry.
2061 Output_data_got
<size
, big_endian
>* got
;
2063 got
= target
->got_section(symtab
, layout
);
2064 if (gsym
->final_value_is_known())
2065 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2068 // If this symbol is not fully resolved, we need to add a
2069 // dynamic relocation for it.
2070 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2071 if (gsym
->is_from_dynobj()
2072 || gsym
->is_undefined()
2073 || gsym
->is_preemptible())
2074 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2075 elfcpp::R_SPARC_GLOB_DAT
);
2076 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2078 unsigned int off
= got
->add_constant(0);
2080 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2081 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2088 // These are initial tls relocs, which are expected when
2090 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2091 case elfcpp::R_SPARC_TLS_GD_LO10
:
2092 case elfcpp::R_SPARC_TLS_GD_ADD
:
2093 case elfcpp::R_SPARC_TLS_GD_CALL
:
2094 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2095 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2096 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2097 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2098 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2099 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2100 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2101 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2102 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2103 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2104 case elfcpp::R_SPARC_TLS_IE_LO10
:
2105 case elfcpp::R_SPARC_TLS_IE_LD
:
2106 case elfcpp::R_SPARC_TLS_IE_LDX
:
2108 const bool is_final
= gsym
->final_value_is_known();
2109 const tls::Tls_optimization optimized_type
2110 = optimize_tls_reloc(is_final
, r_type
);
2113 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2114 case elfcpp::R_SPARC_TLS_GD_LO10
:
2115 case elfcpp::R_SPARC_TLS_GD_ADD
:
2116 case elfcpp::R_SPARC_TLS_GD_CALL
:
2117 if (optimized_type
== tls::TLSOPT_NONE
)
2119 // Create a pair of GOT entries for the module index and
2120 // dtv-relative offset.
2121 Output_data_got
<size
, big_endian
>* got
2122 = target
->got_section(symtab
, layout
);
2123 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2124 target
->rela_dyn_section(layout
),
2126 elfcpp::R_SPARC_TLS_DTPMOD64
:
2127 elfcpp::R_SPARC_TLS_DTPMOD32
),
2129 elfcpp::R_SPARC_TLS_DTPOFF64
:
2130 elfcpp::R_SPARC_TLS_DTPOFF32
));
2132 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2133 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2134 generate_tls_call(symtab
, layout
, target
);
2136 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2138 // Create a GOT entry for the tp-relative offset.
2139 Output_data_got
<size
, big_endian
>* got
2140 = target
->got_section(symtab
, layout
);
2141 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2142 target
->rela_dyn_section(layout
),
2144 elfcpp::R_SPARC_TLS_TPOFF64
:
2145 elfcpp::R_SPARC_TLS_TPOFF32
));
2147 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2148 unsupported_reloc_global(object
, r_type
, gsym
);
2151 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2152 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2153 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2154 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2155 if (optimized_type
== tls::TLSOPT_NONE
)
2157 // Create a GOT entry for the module index.
2158 target
->got_mod_index_entry(symtab
, layout
, object
);
2160 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2161 generate_tls_call(symtab
, layout
, target
);
2163 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2164 unsupported_reloc_global(object
, r_type
, gsym
);
2167 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2168 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2169 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2172 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2173 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2174 layout
->set_has_static_tls();
2175 if (parameters
->options().shared())
2177 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2178 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2179 output_section
, object
,
2180 data_shndx
, reloc
.get_r_offset(),
2185 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2186 case elfcpp::R_SPARC_TLS_IE_LO10
:
2187 case elfcpp::R_SPARC_TLS_IE_LD
:
2188 case elfcpp::R_SPARC_TLS_IE_LDX
:
2189 layout
->set_has_static_tls();
2190 if (optimized_type
== tls::TLSOPT_NONE
)
2192 // Create a GOT entry for the tp-relative offset.
2193 Output_data_got
<size
, big_endian
>* got
2194 = target
->got_section(symtab
, layout
);
2195 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2196 target
->rela_dyn_section(layout
),
2198 elfcpp::R_SPARC_TLS_TPOFF64
:
2199 elfcpp::R_SPARC_TLS_TPOFF32
));
2201 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2202 unsupported_reloc_global(object
, r_type
, gsym
);
2208 // These are relocations which should only be seen by the
2209 // dynamic linker, and should never be seen here.
2210 case elfcpp::R_SPARC_COPY
:
2211 case elfcpp::R_SPARC_GLOB_DAT
:
2212 case elfcpp::R_SPARC_JMP_SLOT
:
2213 case elfcpp::R_SPARC_RELATIVE
:
2214 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2215 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2216 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2217 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2218 case elfcpp::R_SPARC_TLS_TPOFF64
:
2219 case elfcpp::R_SPARC_TLS_TPOFF32
:
2220 gold_error(_("%s: unexpected reloc %u in object file"),
2221 object
->name().c_str(), r_type
);
2225 unsupported_reloc_global(object
, r_type
, gsym
);
2230 // Process relocations for gc.
2232 template<int size
, bool big_endian
>
2234 Target_sparc
<size
, big_endian
>::gc_process_relocs(
2235 const General_options
& options
,
2236 Symbol_table
* symtab
,
2238 Sized_relobj
<size
, big_endian
>* object
,
2239 unsigned int data_shndx
,
2241 const unsigned char* prelocs
,
2243 Output_section
* output_section
,
2244 bool needs_special_offset_handling
,
2245 size_t local_symbol_count
,
2246 const unsigned char* plocal_symbols
)
2248 typedef Target_sparc
<size
, big_endian
> Sparc
;
2249 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2251 gold::gc_process_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2261 needs_special_offset_handling
,
2266 // Scan relocations for a section.
2268 template<int size
, bool big_endian
>
2270 Target_sparc
<size
, big_endian
>::scan_relocs(
2271 const General_options
& options
,
2272 Symbol_table
* symtab
,
2274 Sized_relobj
<size
, big_endian
>* object
,
2275 unsigned int data_shndx
,
2276 unsigned int sh_type
,
2277 const unsigned char* prelocs
,
2279 Output_section
* output_section
,
2280 bool needs_special_offset_handling
,
2281 size_t local_symbol_count
,
2282 const unsigned char* plocal_symbols
)
2284 typedef Target_sparc
<size
, big_endian
> Sparc
;
2285 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2287 if (sh_type
== elfcpp::SHT_REL
)
2289 gold_error(_("%s: unsupported REL reloc section"),
2290 object
->name().c_str());
2294 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2304 needs_special_offset_handling
,
2309 // Finalize the sections.
2311 template<int size
, bool big_endian
>
2313 Target_sparc
<size
, big_endian
>::do_finalize_sections(Layout
* layout
)
2315 // Fill in some more dynamic tags.
2316 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2319 if (this->plt_
!= NULL
)
2321 const Output_data
* od
= this->plt_
->rel_plt();
2322 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2323 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2324 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2326 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2329 if (this->rela_dyn_
!= NULL
)
2331 const Output_data
* od
= this->rela_dyn_
;
2332 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2333 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2334 odyn
->add_constant(elfcpp::DT_RELAENT
,
2335 elfcpp::Elf_sizes
<size
>::rela_size
);
2338 if (!parameters
->options().shared())
2340 // The value of the DT_DEBUG tag is filled in by the dynamic
2341 // linker at run time, and used by the debugger.
2342 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2346 // Emit any relocs we saved in an attempt to avoid generating COPY
2348 if (this->copy_relocs_
.any_saved_relocs())
2349 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
2352 // Perform a relocation.
2354 template<int size
, bool big_endian
>
2356 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2357 const Relocate_info
<size
, big_endian
>* relinfo
,
2358 Target_sparc
* target
,
2360 const elfcpp::Rela
<size
, big_endian
>& rela
,
2361 unsigned int r_type
,
2362 const Sized_symbol
<size
>* gsym
,
2363 const Symbol_value
<size
>* psymval
,
2364 unsigned char* view
,
2365 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2366 section_size_type view_size
)
2370 if (this->ignore_gd_add_
)
2372 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2373 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2374 _("missing expected TLS relocation"));
2377 this->ignore_gd_add_
= false;
2382 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2384 // Pick the value to use for symbols defined in shared objects.
2385 Symbol_value
<size
> symval
;
2387 && gsym
->use_plt_offset(r_type
== elfcpp::R_SPARC_DISP8
2388 || r_type
== elfcpp::R_SPARC_DISP16
2389 || r_type
== elfcpp::R_SPARC_DISP32
2390 || r_type
== elfcpp::R_SPARC_DISP64
2391 || r_type
== elfcpp::R_SPARC_PC_HH22
2392 || r_type
== elfcpp::R_SPARC_PC_HM10
2393 || r_type
== elfcpp::R_SPARC_PC_LM22
2394 || r_type
== elfcpp::R_SPARC_PC10
2395 || r_type
== elfcpp::R_SPARC_PC22
2396 || r_type
== elfcpp::R_SPARC_WDISP30
2397 || r_type
== elfcpp::R_SPARC_WDISP22
2398 || r_type
== elfcpp::R_SPARC_WDISP19
2399 || r_type
== elfcpp::R_SPARC_WDISP16
))
2401 elfcpp::Elf_Xword value
;
2403 value
= target
->plt_section()->address() + gsym
->plt_offset();
2405 symval
.set_output_value(value
);
2410 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2411 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2413 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2414 // pointer points to the beginning, not the end, of the table.
2415 // So we just use the plain offset.
2416 bool have_got_offset
= false;
2417 unsigned int got_offset
= 0;
2420 case elfcpp::R_SPARC_GOT10
:
2421 case elfcpp::R_SPARC_GOT13
:
2422 case elfcpp::R_SPARC_GOT22
:
2425 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2426 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2430 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2431 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2432 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2434 have_got_offset
= true;
2443 case elfcpp::R_SPARC_NONE
:
2444 case elfcpp::R_SPARC_REGISTER
:
2445 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2446 case elfcpp::R_SPARC_GNU_VTENTRY
:
2449 case elfcpp::R_SPARC_8
:
2450 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2454 case elfcpp::R_SPARC_16
:
2455 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2459 case elfcpp::R_SPARC_32
:
2460 if (!parameters
->options().output_is_position_independent())
2461 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2465 case elfcpp::R_SPARC_DISP8
:
2466 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2469 case elfcpp::R_SPARC_DISP16
:
2470 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2473 case elfcpp::R_SPARC_DISP32
:
2474 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2477 case elfcpp::R_SPARC_DISP64
:
2478 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2481 case elfcpp::R_SPARC_WDISP30
:
2482 case elfcpp::R_SPARC_WPLT30
:
2483 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2486 case elfcpp::R_SPARC_WDISP22
:
2487 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2490 case elfcpp::R_SPARC_WDISP19
:
2491 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2494 case elfcpp::R_SPARC_WDISP16
:
2495 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2498 case elfcpp::R_SPARC_HI22
:
2499 Reloc::hi22(view
, object
, psymval
, addend
);
2502 case elfcpp::R_SPARC_22
:
2503 Reloc::rela32_22(view
, object
, psymval
, addend
);
2506 case elfcpp::R_SPARC_13
:
2507 Reloc::rela32_13(view
, object
, psymval
, addend
);
2510 case elfcpp::R_SPARC_LO10
:
2511 Reloc::lo10(view
, object
, psymval
, addend
);
2514 case elfcpp::R_SPARC_GOT10
:
2515 Reloc::lo10(view
, got_offset
, addend
);
2518 case elfcpp::R_SPARC_GOT13
:
2519 Reloc::rela32_13(view
, got_offset
, addend
);
2522 case elfcpp::R_SPARC_GOT22
:
2523 Reloc::hi22(view
, got_offset
, addend
);
2526 case elfcpp::R_SPARC_PC10
:
2527 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2530 case elfcpp::R_SPARC_PC22
:
2531 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2534 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2535 case elfcpp::R_SPARC_UA32
:
2536 Reloc::ua32(view
, object
, psymval
, addend
);
2539 case elfcpp::R_SPARC_PLT64
:
2540 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2544 case elfcpp::R_SPARC_PLT32
:
2545 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2549 case elfcpp::R_SPARC_HIPLT22
:
2550 Reloc::hi22(view
, object
, psymval
, addend
);
2553 case elfcpp::R_SPARC_LOPLT10
:
2554 Reloc::lo10(view
, object
, psymval
, addend
);
2557 case elfcpp::R_SPARC_PCPLT32
:
2558 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2561 case elfcpp::R_SPARC_PCPLT22
:
2562 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2565 case elfcpp::R_SPARC_PCPLT10
:
2566 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2569 case elfcpp::R_SPARC_64
:
2570 if (!parameters
->options().output_is_position_independent())
2571 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2575 case elfcpp::R_SPARC_OLO10
:
2577 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2578 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2579 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2583 case elfcpp::R_SPARC_HH22
:
2584 Reloc::hh22(view
, object
, psymval
, addend
);
2587 case elfcpp::R_SPARC_PC_HH22
:
2588 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2591 case elfcpp::R_SPARC_HM10
:
2592 Reloc::hm10(view
, object
, psymval
, addend
);
2595 case elfcpp::R_SPARC_PC_HM10
:
2596 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2599 case elfcpp::R_SPARC_LM22
:
2600 Reloc::hi22(view
, object
, psymval
, addend
);
2603 case elfcpp::R_SPARC_PC_LM22
:
2604 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2607 case elfcpp::R_SPARC_11
:
2608 Reloc::rela32_11(view
, object
, psymval
, addend
);
2611 case elfcpp::R_SPARC_10
:
2612 Reloc::rela32_10(view
, object
, psymval
, addend
);
2615 case elfcpp::R_SPARC_7
:
2616 Reloc::rela32_7(view
, object
, psymval
, addend
);
2619 case elfcpp::R_SPARC_6
:
2620 Reloc::rela32_6(view
, object
, psymval
, addend
);
2623 case elfcpp::R_SPARC_5
:
2624 Reloc::rela32_5(view
, object
, psymval
, addend
);
2627 case elfcpp::R_SPARC_HIX22
:
2628 Reloc::hix22(view
, object
, psymval
, addend
);
2631 case elfcpp::R_SPARC_LOX10
:
2632 Reloc::lox10(view
, object
, psymval
, addend
);
2635 case elfcpp::R_SPARC_H44
:
2636 Reloc::h44(view
, object
, psymval
, addend
);
2639 case elfcpp::R_SPARC_M44
:
2640 Reloc::m44(view
, object
, psymval
, addend
);
2643 case elfcpp::R_SPARC_L44
:
2644 Reloc::l44(view
, object
, psymval
, addend
);
2647 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2648 case elfcpp::R_SPARC_UA64
:
2649 Reloc::ua64(view
, object
, psymval
, addend
);
2652 case elfcpp::R_SPARC_UA16
:
2653 Reloc::ua16(view
, object
, psymval
, addend
);
2656 case elfcpp::R_SPARC_TLS_GD_HI22
:
2657 case elfcpp::R_SPARC_TLS_GD_LO10
:
2658 case elfcpp::R_SPARC_TLS_GD_ADD
:
2659 case elfcpp::R_SPARC_TLS_GD_CALL
:
2660 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2661 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2662 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2663 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2664 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2665 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2666 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2667 case elfcpp::R_SPARC_TLS_IE_HI22
:
2668 case elfcpp::R_SPARC_TLS_IE_LO10
:
2669 case elfcpp::R_SPARC_TLS_IE_LD
:
2670 case elfcpp::R_SPARC_TLS_IE_LDX
:
2671 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2672 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2673 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2674 r_type
, gsym
, psymval
, view
,
2675 address
, view_size
);
2678 case elfcpp::R_SPARC_COPY
:
2679 case elfcpp::R_SPARC_GLOB_DAT
:
2680 case elfcpp::R_SPARC_JMP_SLOT
:
2681 case elfcpp::R_SPARC_RELATIVE
:
2682 // These are outstanding tls relocs, which are unexpected when
2684 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2685 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2686 case elfcpp::R_SPARC_TLS_TPOFF64
:
2687 case elfcpp::R_SPARC_TLS_TPOFF32
:
2688 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2689 _("unexpected reloc %u in object file"),
2694 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2695 _("unsupported reloc %u"),
2703 // Perform a TLS relocation.
2705 template<int size
, bool big_endian
>
2707 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2708 const Relocate_info
<size
, big_endian
>* relinfo
,
2709 Target_sparc
<size
, big_endian
>* target
,
2711 const elfcpp::Rela
<size
, big_endian
>& rela
,
2712 unsigned int r_type
,
2713 const Sized_symbol
<size
>* gsym
,
2714 const Symbol_value
<size
>* psymval
,
2715 unsigned char* view
,
2716 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2719 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2720 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2721 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2722 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2724 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2725 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2727 const bool is_final
=
2729 ? !parameters
->options().output_is_position_independent()
2730 : gsym
->final_value_is_known());
2731 const tls::Tls_optimization optimized_type
2732 = optimize_tls_reloc(is_final
, r_type
);
2736 case elfcpp::R_SPARC_TLS_GD_HI22
:
2737 case elfcpp::R_SPARC_TLS_GD_LO10
:
2738 case elfcpp::R_SPARC_TLS_GD_ADD
:
2739 case elfcpp::R_SPARC_TLS_GD_CALL
:
2740 if (optimized_type
== tls::TLSOPT_TO_LE
)
2742 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2745 value
-= tls_segment
->memsz();
2749 case elfcpp::R_SPARC_TLS_GD_HI22
:
2750 // TLS_GD_HI22 --> TLS_LE_HIX22
2751 Reloc::hix22(view
, value
, addend
);
2754 case elfcpp::R_SPARC_TLS_GD_LO10
:
2755 // TLS_GD_LO10 --> TLS_LE_LOX10
2756 Reloc::lox10(view
, value
, addend
);
2759 case elfcpp::R_SPARC_TLS_GD_ADD
:
2760 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2761 val
= elfcpp::Swap
<32, true>::readval(wv
);
2762 val
= (val
& ~0x7c000) | 0x1c000;
2763 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2765 case elfcpp::R_SPARC_TLS_GD_CALL
:
2766 // call __tls_get_addr --> nop
2767 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2774 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2775 ? GOT_TYPE_TLS_OFFSET
2776 : GOT_TYPE_TLS_PAIR
);
2779 gold_assert(gsym
->has_got_offset(got_type
));
2780 value
= gsym
->got_offset(got_type
);
2784 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2785 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2786 value
= object
->local_got_offset(r_sym
, got_type
);
2788 if (optimized_type
== tls::TLSOPT_TO_IE
)
2790 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2795 case elfcpp::R_SPARC_TLS_GD_HI22
:
2796 // TLS_GD_HI22 --> TLS_IE_HI22
2797 Reloc::hi22(view
, value
, addend
);
2800 case elfcpp::R_SPARC_TLS_GD_LO10
:
2801 // TLS_GD_LO10 --> TLS_IE_LO10
2802 Reloc::lo10(view
, value
, addend
);
2805 case elfcpp::R_SPARC_TLS_GD_ADD
:
2806 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2807 val
= elfcpp::Swap
<32, true>::readval(wv
);
2814 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2817 case elfcpp::R_SPARC_TLS_GD_CALL
:
2818 // The compiler can put the TLS_GD_ADD instruction
2819 // into the delay slot of the call. If so, we need
2820 // to transpose the two instructions so that the
2821 // the new sequence works properly.
2823 // The test we use is if the instruction in the
2824 // delay slot is an add with destination register
2826 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2827 if ((val
& 0x81f80000) == 0x80000000
2828 && ((val
>> 25) & 0x1f) == 0x8)
2835 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2838 this->ignore_gd_add_
= true;
2841 // call __tls_get_addr --> add %g7, %o0, %o0
2842 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2847 else if (optimized_type
== tls::TLSOPT_NONE
)
2851 case elfcpp::R_SPARC_TLS_GD_HI22
:
2852 Reloc::hi22(view
, value
, addend
);
2854 case elfcpp::R_SPARC_TLS_GD_LO10
:
2855 Reloc::lo10(view
, value
, addend
);
2857 case elfcpp::R_SPARC_TLS_GD_ADD
:
2859 case elfcpp::R_SPARC_TLS_GD_CALL
:
2861 Symbol_value
<size
> symval
;
2862 elfcpp::Elf_Xword value
;
2865 tsym
= target
->tls_get_addr_sym_
;
2867 value
= (target
->plt_section()->address() +
2868 tsym
->plt_offset());
2869 symval
.set_output_value(value
);
2870 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2877 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2878 _("unsupported reloc %u"),
2882 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2883 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2884 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2885 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2886 if (optimized_type
== tls::TLSOPT_TO_LE
)
2888 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2892 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2893 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2894 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2895 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2898 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2899 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2904 else if (optimized_type
== tls::TLSOPT_NONE
)
2906 // Relocate the field with the offset of the GOT entry for
2907 // the module index.
2908 unsigned int got_offset
;
2910 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2913 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2914 Reloc::hi22(view
, got_offset
, addend
);
2916 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2917 Reloc::lo10(view
, got_offset
, addend
);
2919 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2921 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2923 Symbol_value
<size
> symval
;
2924 elfcpp::Elf_Xword value
;
2927 tsym
= target
->tls_get_addr_sym_
;
2929 value
= (target
->plt_section()->address() +
2930 tsym
->plt_offset());
2931 symval
.set_output_value(value
);
2932 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2938 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2939 _("unsupported reloc %u"),
2943 // These relocs can appear in debugging sections, in which case
2944 // we won't see the TLS_LDM relocs. The local_dynamic_type
2945 // field tells us this.
2946 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2947 if (optimized_type
== tls::TLSOPT_TO_LE
)
2949 value
-= tls_segment
->memsz();
2950 Reloc::hix22(view
, value
, addend
);
2953 Reloc::ldo_hix22(view
, value
, addend
);
2955 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2956 if (optimized_type
== tls::TLSOPT_TO_LE
)
2958 value
-= tls_segment
->memsz();
2959 Reloc::lox10(view
, value
, addend
);
2962 Reloc::ldo_lox10(view
, value
, addend
);
2964 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2965 if (optimized_type
== tls::TLSOPT_TO_LE
)
2967 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2970 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2971 val
= elfcpp::Swap
<32, true>::readval(wv
);
2972 val
= (val
& ~0x7c000) | 0x1c000;
2973 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2977 // When optimizing IE --> LE, the only relocation that is handled
2978 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2979 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2980 // rs2 and rd are the same.
2981 case elfcpp::R_SPARC_TLS_IE_LD
:
2982 case elfcpp::R_SPARC_TLS_IE_LDX
:
2983 if (optimized_type
== tls::TLSOPT_TO_LE
)
2985 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2986 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
2987 Insntype rs2
= val
& 0x1f;
2988 Insntype rd
= (val
>> 25) & 0x1f;
2993 val
= sparc_mov
| (val
& 0x3e00001f);
2995 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2999 case elfcpp::R_SPARC_TLS_IE_HI22
:
3000 case elfcpp::R_SPARC_TLS_IE_LO10
:
3001 if (optimized_type
== tls::TLSOPT_TO_LE
)
3003 value
-= tls_segment
->memsz();
3006 case elfcpp::R_SPARC_TLS_IE_HI22
:
3007 // IE_HI22 --> LE_HIX22
3008 Reloc::hix22(view
, value
, addend
);
3010 case elfcpp::R_SPARC_TLS_IE_LO10
:
3011 // IE_LO10 --> LE_LOX10
3012 Reloc::lox10(view
, value
, addend
);
3017 else if (optimized_type
== tls::TLSOPT_NONE
)
3019 // Relocate the field with the offset of the GOT entry for
3020 // the tp-relative offset of the symbol.
3023 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
3024 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
3028 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
3029 gold_assert(object
->local_has_got_offset(r_sym
,
3030 GOT_TYPE_TLS_OFFSET
));
3031 value
= object
->local_got_offset(r_sym
,
3032 GOT_TYPE_TLS_OFFSET
);
3036 case elfcpp::R_SPARC_TLS_IE_HI22
:
3037 Reloc::hi22(view
, value
, addend
);
3039 case elfcpp::R_SPARC_TLS_IE_LO10
:
3040 Reloc::lo10(view
, value
, addend
);
3045 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
3046 _("unsupported reloc %u"),
3050 case elfcpp::R_SPARC_TLS_LE_HIX22
:
3051 // If we're creating a shared library, a dynamic relocation will
3052 // have been created for this location, so do not apply it now.
3053 if (!parameters
->options().shared())
3055 value
-= tls_segment
->memsz();
3056 Reloc::hix22(view
, value
, addend
);
3060 case elfcpp::R_SPARC_TLS_LE_LOX10
:
3061 // If we're creating a shared library, a dynamic relocation will
3062 // have been created for this location, so do not apply it now.
3063 if (!parameters
->options().shared())
3065 value
-= tls_segment
->memsz();
3066 Reloc::lox10(view
, value
, addend
);
3072 // Relocate section data.
3074 template<int size
, bool big_endian
>
3076 Target_sparc
<size
, big_endian
>::relocate_section(
3077 const Relocate_info
<size
, big_endian
>* relinfo
,
3078 unsigned int sh_type
,
3079 const unsigned char* prelocs
,
3081 Output_section
* output_section
,
3082 bool needs_special_offset_handling
,
3083 unsigned char* view
,
3084 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
3085 section_size_type view_size
)
3087 typedef Target_sparc
<size
, big_endian
> Sparc
;
3088 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
3090 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3092 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
3099 needs_special_offset_handling
,
3105 // Return the size of a relocation while scanning during a relocatable
3108 template<int size
, bool big_endian
>
3110 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3114 // We are always SHT_RELA, so we should never get here.
3119 // Scan the relocs during a relocatable link.
3121 template<int size
, bool big_endian
>
3123 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3124 const General_options
& options
,
3125 Symbol_table
* symtab
,
3127 Sized_relobj
<size
, big_endian
>* object
,
3128 unsigned int data_shndx
,
3129 unsigned int sh_type
,
3130 const unsigned char* prelocs
,
3132 Output_section
* output_section
,
3133 bool needs_special_offset_handling
,
3134 size_t local_symbol_count
,
3135 const unsigned char* plocal_symbols
,
3136 Relocatable_relocs
* rr
)
3138 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3140 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3141 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3143 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3144 Scan_relocatable_relocs
>(
3153 needs_special_offset_handling
,
3159 // Relocate a section during a relocatable link.
3161 template<int size
, bool big_endian
>
3163 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3164 const Relocate_info
<size
, big_endian
>* relinfo
,
3165 unsigned int sh_type
,
3166 const unsigned char* prelocs
,
3168 Output_section
* output_section
,
3169 off_t offset_in_output_section
,
3170 const Relocatable_relocs
* rr
,
3171 unsigned char* view
,
3172 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3173 section_size_type view_size
,
3174 unsigned char* reloc_view
,
3175 section_size_type reloc_view_size
)
3177 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3179 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3184 offset_in_output_section
,
3193 // Return the value to use for a dynamic which requires special
3194 // treatment. This is how we support equality comparisons of function
3195 // pointers across shared library boundaries, as described in the
3196 // processor specific ABI supplement.
3198 template<int size
, bool big_endian
>
3200 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3202 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3203 return this->plt_section()->address() + gsym
->plt_offset();
3206 // The selector for sparc object files.
3208 template<int size
, bool big_endian
>
3209 class Target_selector_sparc
: public Target_selector
3212 Target_selector_sparc()
3213 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3214 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3217 Target
* instantiated_target_
;
3219 Target
* do_recognize(int machine
, int, int)
3224 if (machine
!= elfcpp::EM_SPARCV9
)
3229 if (machine
!= elfcpp::EM_SPARC
3230 && machine
!= elfcpp::EM_SPARC32PLUS
)
3238 return do_instantiate_target();
3241 Target
* do_instantiate_target()
3243 if (this->instantiated_target_
== NULL
)
3244 this->instantiated_target_
= new Target_sparc
<size
, big_endian
>();
3245 return this->instantiated_target_
;
3249 Target_selector_sparc
<32, true> target_selector_sparc32
;
3250 Target_selector_sparc
<64, true> target_selector_sparc64
;
3252 } // End anonymous namespace.