1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
38 #include "target-reloc.h"
39 #include "target-select.h"
48 template<int size
, bool big_endian
>
49 class Output_data_plt_sparc
;
51 template<int size
, bool big_endian
>
52 class Target_sparc
: public Sized_target
<size
, big_endian
>
55 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, big_endian
> Reloc_section
;
58 : Sized_target
<size
, big_endian
>(&sparc_info
),
59 got_(NULL
), plt_(NULL
), rela_dyn_(NULL
),
60 copy_relocs_(NULL
), dynbss_(NULL
), got_mod_index_offset_(-1U),
61 tls_get_addr_sym_(NULL
)
65 // Scan the relocations to look for symbol adjustments.
67 scan_relocs(const General_options
& options
,
70 Sized_relobj
<size
, big_endian
>* object
,
71 unsigned int data_shndx
,
73 const unsigned char* prelocs
,
75 Output_section
* output_section
,
76 bool needs_special_offset_handling
,
77 size_t local_symbol_count
,
78 const unsigned char* plocal_symbols
);
79 // Finalize the sections.
81 do_finalize_sections(Layout
*);
83 // Return the value to use for a dynamic which requires special
86 do_dynsym_value(const Symbol
*) const;
88 // Relocate a section.
90 relocate_section(const Relocate_info
<size
, big_endian
>*,
92 const unsigned char* prelocs
,
94 Output_section
* output_section
,
95 bool needs_special_offset_handling
,
97 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
98 section_size_type view_size
);
100 // Scan the relocs during a relocatable link.
102 scan_relocatable_relocs(const General_options
& options
,
103 Symbol_table
* symtab
,
105 Sized_relobj
<size
, big_endian
>* object
,
106 unsigned int data_shndx
,
107 unsigned int sh_type
,
108 const unsigned char* prelocs
,
110 Output_section
* output_section
,
111 bool needs_special_offset_handling
,
112 size_t local_symbol_count
,
113 const unsigned char* plocal_symbols
,
114 Relocatable_relocs
*);
116 // Relocate a section during a relocatable link.
118 relocate_for_relocatable(const Relocate_info
<size
, big_endian
>*,
119 unsigned int sh_type
,
120 const unsigned char* prelocs
,
122 Output_section
* output_section
,
123 off_t offset_in_output_section
,
124 const Relocatable_relocs
*,
126 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
127 section_size_type view_size
,
128 unsigned char* reloc_view
,
129 section_size_type reloc_view_size
);
130 // Return whether SYM is defined by the ABI.
132 do_is_defined_by_abi(Symbol
* sym
) const
134 // XXX Really need to support this better...
135 if (sym
->type() == elfcpp::STT_SPARC_REGISTER
)
138 return strcmp(sym
->name(), "___tls_get_addr") == 0;
141 // Return the size of the GOT section.
145 gold_assert(this->got_
!= NULL
);
146 return this->got_
->data_size();
151 // The class which scans relocations.
155 local(const General_options
& options
, Symbol_table
* symtab
,
156 Layout
* layout
, Target_sparc
* target
,
157 Sized_relobj
<size
, big_endian
>* object
,
158 unsigned int data_shndx
,
159 Output_section
* output_section
,
160 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
161 const elfcpp::Sym
<size
, big_endian
>& lsym
);
164 global(const General_options
& options
, Symbol_table
* symtab
,
165 Layout
* layout
, Target_sparc
* target
,
166 Sized_relobj
<size
, big_endian
>* object
,
167 unsigned int data_shndx
,
168 Output_section
* output_section
,
169 const elfcpp::Rela
<size
, big_endian
>& reloc
, unsigned int r_type
,
173 unsupported_reloc_local(Sized_relobj
<size
, big_endian
>*,
174 unsigned int r_type
);
177 unsupported_reloc_global(Sized_relobj
<size
, big_endian
>*,
178 unsigned int r_type
, Symbol
*);
181 generate_tls_call(Symbol_table
* symtab
, Layout
* layout
,
182 Target_sparc
* target
);
185 // The class which implements relocation.
190 : ignore_gd_add_(false)
195 if (this->ignore_gd_add_
)
197 // FIXME: This needs to specify the location somehow.
198 gold_error(_("missing expected TLS relocation"));
202 // Do a relocation. Return false if the caller should not issue
203 // any warnings about this relocation.
205 relocate(const Relocate_info
<size
, big_endian
>*, Target_sparc
*,
206 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
207 unsigned int r_type
, const Sized_symbol
<size
>*,
208 const Symbol_value
<size
>*,
210 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
214 // Do a TLS relocation.
216 relocate_tls(const Relocate_info
<size
, big_endian
>*, Target_sparc
* target
,
217 size_t relnum
, const elfcpp::Rela
<size
, big_endian
>&,
218 unsigned int r_type
, const Sized_symbol
<size
>*,
219 const Symbol_value
<size
>*,
221 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
224 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
228 // A class which returns the size required for a relocation type,
229 // used while scanning relocs during a relocatable link.
230 class Relocatable_size_for_reloc
234 get_size_for_reloc(unsigned int, Relobj
*);
237 // Get the GOT section, creating it if necessary.
238 Output_data_got
<size
, big_endian
>*
239 got_section(Symbol_table
*, Layout
*);
241 // Create a PLT entry for a global symbol.
243 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
245 // Create a GOT entry for the TLS module index.
247 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
248 Sized_relobj
<size
, big_endian
>* object
);
250 // Return the gsym for "__tls_get_addr". Cache if not already
253 tls_get_addr_sym(Symbol_table
* symtab
)
255 if (!this->tls_get_addr_sym_
)
256 this->tls_get_addr_sym_
= symtab
->lookup("__tls_get_addr", NULL
);
257 gold_assert(this->tls_get_addr_sym_
);
258 return this->tls_get_addr_sym_
;
261 // Get the PLT section.
262 const Output_data_plt_sparc
<size
, big_endian
>*
265 gold_assert(this->plt_
!= NULL
);
269 // Get the dynamic reloc section, creating it if necessary.
271 rela_dyn_section(Layout
*);
273 // Return true if the symbol may need a COPY relocation.
274 // References from an executable object to non-function symbols
275 // defined in a dynamic object may need a COPY relocation.
277 may_need_copy_reloc(Symbol
* gsym
)
279 return (!parameters
->options().shared()
280 && gsym
->is_from_dynobj()
281 && gsym
->type() != elfcpp::STT_FUNC
);
284 // Copy a relocation against a global symbol.
286 copy_reloc(const General_options
*, Symbol_table
*, Layout
*,
287 Sized_relobj
<size
, big_endian
>*, unsigned int,
288 Output_section
*, Symbol
*, const elfcpp::Rela
<size
, big_endian
>&);
290 // Information about this specific target which we pass to the
291 // general Target structure.
292 static Target::Target_info sparc_info
;
294 // The types of GOT entries needed for this platform.
297 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
298 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
299 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
303 Output_data_got
<size
, big_endian
>* got_
;
305 Output_data_plt_sparc
<size
, big_endian
>* plt_
;
306 // The dynamic reloc section.
307 Reloc_section
* rela_dyn_
;
308 // Relocs saved to avoid a COPY reloc.
309 Copy_relocs
<size
, big_endian
>* copy_relocs_
;
310 // Space for variables copied with a COPY reloc.
311 Output_data_space
* dynbss_
;
312 // Offset of the GOT entry for the TLS module index;
313 unsigned int got_mod_index_offset_
;
314 // Cached pointer to __tls_get_addr symbol
315 Symbol
* tls_get_addr_sym_
;
319 Target::Target_info Target_sparc
<32, true>::sparc_info
=
322 true, // is_big_endian
323 elfcpp::EM_SPARC
, // machine_code
324 false, // has_make_symbol
325 false, // has_resolve
326 false, // has_code_fill
327 true, // is_default_stack_executable
329 "/usr/lib/ld.so.1", // dynamic_linker
330 0x00010000, // default_text_segment_address
331 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
332 8 * 1024 // common_pagesize (overridable by -z common-page-size)
336 Target::Target_info Target_sparc
<64, true>::sparc_info
=
339 true, // is_big_endian
340 elfcpp::EM_SPARCV9
, // machine_code
341 false, // has_make_symbol
342 false, // has_resolve
343 false, // has_code_fill
344 true, // is_default_stack_executable
346 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
347 0x100000, // default_text_segment_address
348 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
349 8 * 1024 // common_pagesize (overridable by -z common-page-size)
352 // We have to take care here, even when operating in little-endian
353 // mode, sparc instructions are still big endian.
354 template<int size
, bool big_endian
>
355 class Sparc_relocate_functions
358 // Do a simple relocation with the addend in the relocation.
359 template<int valsize
>
361 rela(unsigned char* view
,
362 unsigned int right_shift
,
363 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
364 typename
elfcpp::Swap
<size
, big_endian
>::Valtype value
,
365 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
367 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
368 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
369 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
370 Valtype reloc
= ((value
+ addend
) >> right_shift
);
375 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
378 // Do a simple relocation using a symbol value with the addend in
380 template<int valsize
>
382 rela(unsigned char* view
,
383 unsigned int right_shift
,
384 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
385 const Sized_relobj
<size
, big_endian
>* object
,
386 const Symbol_value
<size
>* psymval
,
387 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype addend
)
389 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
390 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
391 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
392 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
397 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
400 // Do a simple relocation using a symbol value with the addend in
401 // the relocation, unaligned.
402 template<int valsize
>
404 rela_ua(unsigned char* view
,
405 unsigned int right_shift
, elfcpp::Elf_Xword dst_mask
,
406 const Sized_relobj
<size
, big_endian
>* object
,
407 const Symbol_value
<size
>* psymval
,
408 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
)
410 typedef typename
elfcpp::Swap_unaligned
<valsize
,
411 big_endian
>::Valtype Valtype
;
412 unsigned char* wv
= view
;
413 Valtype val
= elfcpp::Swap_unaligned
<valsize
, big_endian
>::readval(wv
);
414 Valtype reloc
= (psymval
->value(object
, addend
) >> right_shift
);
419 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
422 // Do a simple PC relative relocation with a Symbol_value with the
423 // addend in the relocation.
424 template<int valsize
>
426 pcrela(unsigned char* view
,
427 unsigned int right_shift
,
428 typename
elfcpp::Elf_types
<valsize
>::Elf_Addr dst_mask
,
429 const Sized_relobj
<size
, big_endian
>* object
,
430 const Symbol_value
<size
>* psymval
,
431 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
432 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
434 typedef typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype Valtype
;
435 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
436 Valtype val
= elfcpp::Swap
<valsize
, big_endian
>::readval(wv
);
437 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
443 elfcpp::Swap
<valsize
, big_endian
>::writeval(wv
, val
| reloc
);
446 template<int valsize
>
448 pcrela_unaligned(unsigned char* view
,
449 const Sized_relobj
<size
, big_endian
>* object
,
450 const Symbol_value
<size
>* psymval
,
451 typename
elfcpp::Swap
<size
, big_endian
>::Valtype addend
,
452 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
454 typedef typename
elfcpp::Swap_unaligned
<valsize
,
455 big_endian
>::Valtype Valtype
;
456 unsigned char* wv
= view
;
457 Valtype reloc
= (psymval
->value(object
, addend
) - address
);
459 elfcpp::Swap_unaligned
<valsize
, big_endian
>::writeval(wv
, reloc
);
462 typedef Sparc_relocate_functions
<size
, big_endian
> This
;
463 typedef Sparc_relocate_functions
<size
, true> This_insn
;
466 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
468 wdisp30(unsigned char* view
,
469 const Sized_relobj
<size
, big_endian
>* object
,
470 const Symbol_value
<size
>* psymval
,
471 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
472 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
474 This_insn::template pcrela
<32>(view
, 2, 0x3fffffff, object
,
475 psymval
, addend
, address
);
478 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
480 wdisp22(unsigned char* view
,
481 const Sized_relobj
<size
, big_endian
>* object
,
482 const Symbol_value
<size
>* psymval
,
483 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
484 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
486 This_insn::template pcrela
<32>(view
, 2, 0x003fffff, object
,
487 psymval
, addend
, address
);
490 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
492 wdisp19(unsigned char* view
,
493 const Sized_relobj
<size
, big_endian
>* object
,
494 const Symbol_value
<size
>* psymval
,
495 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
496 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
498 This_insn::template pcrela
<32>(view
, 2, 0x0007ffff, object
,
499 psymval
, addend
, address
);
502 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
504 wdisp16(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 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
511 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
512 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
513 Valtype reloc
= ((psymval
->value(object
, addend
) - address
)
516 // The relocation value is split between the low 14 bits,
518 val
&= ~((0x3 << 20) | 0x3fff);
519 reloc
= (((reloc
& 0xc000) << (20 - 14))
520 | (reloc
& 0x3ffff));
522 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
525 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
527 pc22(unsigned char* view
,
528 const Sized_relobj
<size
, big_endian
>* object
,
529 const Symbol_value
<size
>* psymval
,
530 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
531 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
533 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
534 psymval
, addend
, address
);
537 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
539 pc10(unsigned char* view
,
540 const Sized_relobj
<size
, big_endian
>* object
,
541 const Symbol_value
<size
>* psymval
,
542 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
543 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
545 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
546 psymval
, addend
, address
);
549 // R_SPARC_HI22: (Symbol + Addend) >> 10
551 hi22(unsigned char* view
,
552 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
553 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
555 This_insn::template rela
<32>(view
, 10, 0x003fffff, value
, addend
);
558 // R_SPARC_HI22: (Symbol + Addend) >> 10
560 hi22(unsigned char* view
,
561 const Sized_relobj
<size
, big_endian
>* object
,
562 const Symbol_value
<size
>* psymval
,
563 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
565 This_insn::template rela
<32>(view
, 10, 0x003fffff, object
, psymval
, addend
);
568 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
570 pcplt22(unsigned char* view
,
571 const Sized_relobj
<size
, big_endian
>* object
,
572 const Symbol_value
<size
>* psymval
,
573 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
574 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
576 This_insn::template pcrela
<32>(view
, 10, 0x003fffff, object
,
577 psymval
, addend
, address
);
580 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
582 lo10(unsigned char* view
,
583 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
584 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
586 This_insn::template rela
<32>(view
, 0, 0x000003ff, value
, addend
);
589 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
591 lo10(unsigned char* view
,
592 const Sized_relobj
<size
, big_endian
>* object
,
593 const Symbol_value
<size
>* psymval
,
594 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
596 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
599 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
601 lo10(unsigned char* view
,
602 const Sized_relobj
<size
, big_endian
>* object
,
603 const Symbol_value
<size
>* psymval
,
604 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
605 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
607 This_insn::template pcrela
<32>(view
, 0, 0x000003ff, object
,
608 psymval
, addend
, address
);
611 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
613 olo10(unsigned char* view
,
614 const Sized_relobj
<size
, big_endian
>* object
,
615 const Symbol_value
<size
>* psymval
,
616 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
617 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend2
)
619 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
620 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
621 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
622 Valtype reloc
= psymval
->value(object
, addend
);
629 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
632 // R_SPARC_22: (Symbol + Addend)
634 rela32_22(unsigned char* view
,
635 const Sized_relobj
<size
, big_endian
>* object
,
636 const Symbol_value
<size
>* psymval
,
637 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
639 This_insn::template rela
<32>(view
, 0, 0x003fffff, object
, psymval
, addend
);
642 // R_SPARC_13: (Symbol + Addend)
644 rela32_13(unsigned char* view
,
645 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
646 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
648 This_insn::template rela
<32>(view
, 0, 0x00001fff, value
, addend
);
651 // R_SPARC_13: (Symbol + Addend)
653 rela32_13(unsigned char* view
,
654 const Sized_relobj
<size
, big_endian
>* object
,
655 const Symbol_value
<size
>* psymval
,
656 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
658 This_insn::template rela
<32>(view
, 0, 0x00001fff, object
, psymval
, addend
);
661 // R_SPARC_UA16: (Symbol + Addend)
663 ua16(unsigned char* view
,
664 const Sized_relobj
<size
, big_endian
>* object
,
665 const Symbol_value
<size
>* psymval
,
666 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
668 This::template rela_ua
<16>(view
, 0, 0xffff, object
, psymval
, addend
);
671 // R_SPARC_UA32: (Symbol + Addend)
673 ua32(unsigned char* view
,
674 const Sized_relobj
<size
, big_endian
>* object
,
675 const Symbol_value
<size
>* psymval
,
676 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
678 This::template rela_ua
<32>(view
, 0, 0xffffffff, object
, psymval
, addend
);
681 // R_SPARC_UA64: (Symbol + Addend)
683 ua64(unsigned char* view
,
684 const Sized_relobj
<size
, big_endian
>* object
,
685 const Symbol_value
<size
>* psymval
,
686 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
688 This::template rela_ua
<64>(view
, 0, ~(elfcpp::Elf_Xword
) 0,
689 object
, psymval
, addend
);
692 // R_SPARC_DISP8: (Symbol + Addend - Address)
694 disp8(unsigned char* view
,
695 const Sized_relobj
<size
, big_endian
>* object
,
696 const Symbol_value
<size
>* psymval
,
697 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
698 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
700 This::template pcrela_unaligned
<8>(view
, object
, psymval
,
704 // R_SPARC_DISP16: (Symbol + Addend - Address)
706 disp16(unsigned char* view
,
707 const Sized_relobj
<size
, big_endian
>* object
,
708 const Symbol_value
<size
>* psymval
,
709 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
710 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
712 This::template pcrela_unaligned
<16>(view
, object
, psymval
,
716 // R_SPARC_DISP32: (Symbol + Addend - Address)
718 disp32(unsigned char* view
,
719 const Sized_relobj
<size
, big_endian
>* object
,
720 const Symbol_value
<size
>* psymval
,
721 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
722 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
724 This::template pcrela_unaligned
<32>(view
, object
, psymval
,
728 // R_SPARC_DISP64: (Symbol + Addend - Address)
730 disp64(unsigned char* view
,
731 const Sized_relobj
<size
, big_endian
>* object
,
732 const Symbol_value
<size
>* psymval
,
733 elfcpp::Elf_Xword addend
,
734 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
736 This::template pcrela_unaligned
<64>(view
, object
, psymval
,
740 // R_SPARC_H44: (Symbol + Addend) >> 22
742 h44(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
)
747 This_insn::template rela
<32>(view
, 22, 0x003fffff, object
, psymval
, addend
);
750 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
752 m44(unsigned char* view
,
753 const Sized_relobj
<size
, big_endian
>* object
,
754 const Symbol_value
<size
>* psymval
,
755 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
757 This_insn::template rela
<32>(view
, 12, 0x000003ff, object
, psymval
, addend
);
760 // R_SPARC_L44: (Symbol + Addend) & 0xfff
762 l44(unsigned char* view
,
763 const Sized_relobj
<size
, big_endian
>* object
,
764 const Symbol_value
<size
>* psymval
,
765 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
767 This_insn::template rela
<32>(view
, 0, 0x00000fff, object
, psymval
, addend
);
770 // R_SPARC_HH22: (Symbol + Addend) >> 42
772 hh22(unsigned char* view
,
773 const Sized_relobj
<size
, big_endian
>* object
,
774 const Symbol_value
<size
>* psymval
,
775 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
777 This_insn::template rela
<32>(view
, 42, 0x003fffff, object
, psymval
, addend
);
780 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
782 pc_hh22(unsigned char* view
,
783 const Sized_relobj
<size
, big_endian
>* object
,
784 const Symbol_value
<size
>* psymval
,
785 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
786 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
788 This_insn::template pcrela
<32>(view
, 42, 0x003fffff, object
,
789 psymval
, addend
, address
);
792 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
794 hm10(unsigned char* view
,
795 const Sized_relobj
<size
, big_endian
>* object
,
796 const Symbol_value
<size
>* psymval
,
797 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
799 This_insn::template rela
<32>(view
, 32, 0x000003ff, object
, psymval
, addend
);
802 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
804 pc_hm10(unsigned char* view
,
805 const Sized_relobj
<size
, big_endian
>* object
,
806 const Symbol_value
<size
>* psymval
,
807 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
,
808 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
810 This_insn::template pcrela
<32>(view
, 32, 0x000003ff, object
,
811 psymval
, addend
, address
);
814 // R_SPARC_11: (Symbol + Addend)
816 rela32_11(unsigned char* view
,
817 const Sized_relobj
<size
, big_endian
>* object
,
818 const Symbol_value
<size
>* psymval
,
819 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
821 This_insn::template rela
<32>(view
, 0, 0x000007ff, object
, psymval
, addend
);
824 // R_SPARC_10: (Symbol + Addend)
826 rela32_10(unsigned char* view
,
827 const Sized_relobj
<size
, big_endian
>* object
,
828 const Symbol_value
<size
>* psymval
,
829 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
831 This_insn::template rela
<32>(view
, 0, 0x000003ff, object
, psymval
, addend
);
834 // R_SPARC_7: (Symbol + Addend)
836 rela32_7(unsigned char* view
,
837 const Sized_relobj
<size
, big_endian
>* object
,
838 const Symbol_value
<size
>* psymval
,
839 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
841 This_insn::template rela
<32>(view
, 0, 0x0000007f, object
, psymval
, addend
);
844 // R_SPARC_6: (Symbol + Addend)
846 rela32_6(unsigned char* view
,
847 const Sized_relobj
<size
, big_endian
>* object
,
848 const Symbol_value
<size
>* psymval
,
849 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
851 This_insn::template rela
<32>(view
, 0, 0x0000003f, object
, psymval
, addend
);
854 // R_SPARC_5: (Symbol + Addend)
856 rela32_5(unsigned char* view
,
857 const Sized_relobj
<size
, big_endian
>* object
,
858 const Symbol_value
<size
>* psymval
,
859 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
861 This_insn::template rela
<32>(view
, 0, 0x0000001f, object
, psymval
, addend
);
864 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
866 ldo_hix22(unsigned char* view
,
867 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
868 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
870 This_insn::hi22(view
, value
, addend
);
873 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
875 ldo_lox10(unsigned char* view
,
876 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
877 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
879 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
880 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
881 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
882 Valtype reloc
= (value
+ addend
);
887 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
890 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
892 hix22(unsigned char* view
,
893 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
894 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
896 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
897 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
898 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
899 Valtype reloc
= (value
+ addend
);
903 reloc
^= ~(Valtype
)0;
908 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
911 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
913 hix22(unsigned char* view
,
914 const Sized_relobj
<size
, big_endian
>* object
,
915 const Symbol_value
<size
>* psymval
,
916 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
918 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
919 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
920 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
921 Valtype reloc
= psymval
->value(object
, addend
);
925 reloc
^= ~(Valtype
)0;
930 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
934 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
936 lox10(unsigned char* view
,
937 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
938 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
940 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
941 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
942 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
943 Valtype reloc
= (value
+ addend
);
949 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
952 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
954 lox10(unsigned char* view
,
955 const Sized_relobj
<size
, big_endian
>* object
,
956 const Symbol_value
<size
>* psymval
,
957 typename
elfcpp::Elf_types
<size
>::Elf_Addr addend
)
959 typedef typename
elfcpp::Swap
<32, true>::Valtype Valtype
;
960 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
961 Valtype val
= elfcpp::Swap
<32, true>::readval(wv
);
962 Valtype reloc
= psymval
->value(object
, addend
);
968 elfcpp::Swap
<32, true>::writeval(wv
, val
| reloc
);
972 // Get the GOT section, creating it if necessary.
974 template<int size
, bool big_endian
>
975 Output_data_got
<size
, big_endian
>*
976 Target_sparc
<size
, big_endian
>::got_section(Symbol_table
* symtab
,
979 if (this->got_
== NULL
)
981 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
983 this->got_
= new Output_data_got
<size
, big_endian
>();
985 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
986 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
989 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
990 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
992 0, 0, elfcpp::STT_OBJECT
,
994 elfcpp::STV_HIDDEN
, 0,
1001 // Get the dynamic reloc section, creating it if necessary.
1003 template<int size
, bool big_endian
>
1004 typename Target_sparc
<size
, big_endian
>::Reloc_section
*
1005 Target_sparc
<size
, big_endian
>::rela_dyn_section(Layout
* layout
)
1007 if (this->rela_dyn_
== NULL
)
1009 gold_assert(layout
!= NULL
);
1010 this->rela_dyn_
= new Reloc_section();
1011 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1012 elfcpp::SHF_ALLOC
, this->rela_dyn_
);
1014 return this->rela_dyn_
;
1017 // A class to handle the PLT data.
1019 template<int size
, bool big_endian
>
1020 class Output_data_plt_sparc
: public Output_section_data
1023 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true,
1024 size
, big_endian
> Reloc_section
;
1026 Output_data_plt_sparc(Layout
*);
1028 // Add an entry to the PLT.
1029 void add_entry(Symbol
* gsym
);
1031 // Return the .rela.plt section data.
1032 const Reloc_section
* rel_plt() const
1038 void do_adjust_output_section(Output_section
* os
);
1041 // The size of an entry in the PLT.
1042 static const int base_plt_entry_size
= (size
== 32 ? 12 : 32);
1044 static const unsigned int plt_entries_per_block
= 160;
1045 static const unsigned int plt_insn_chunk_size
= 24;
1046 static const unsigned int plt_pointer_chunk_size
= 8;
1047 static const unsigned int plt_block_size
=
1048 (plt_entries_per_block
1049 * (plt_insn_chunk_size
+ plt_pointer_chunk_size
));
1051 // Set the final size.
1053 set_final_data_size()
1055 unsigned int full_count
= this->count_
+ 4;
1056 unsigned int extra
= (size
== 32 ? 4 : 0);
1058 if (size
== 32 || full_count
< 32768)
1059 this->set_data_size((full_count
* base_plt_entry_size
) + extra
);
1062 unsigned int ext_cnt
= full_count
- 32768;
1064 this->set_data_size((32768 * base_plt_entry_size
)
1066 * (plt_insn_chunk_size
1067 + plt_pointer_chunk_size
)));
1071 // Write out the PLT data.
1073 do_write(Output_file
*);
1075 // The reloc section.
1076 Reloc_section
* rel_
;
1077 // The number of PLT entries.
1078 unsigned int count_
;
1081 // Define the constants as required by C++ standard.
1083 template<int size
, bool big_endian
>
1084 const int Output_data_plt_sparc
<size
, big_endian
>::base_plt_entry_size
;
1086 template<int size
, bool big_endian
>
1088 Output_data_plt_sparc
<size
, big_endian
>::plt_entries_per_block
;
1090 template<int size
, bool big_endian
>
1091 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_insn_chunk_size
;
1093 template<int size
, bool big_endian
>
1095 Output_data_plt_sparc
<size
, big_endian
>::plt_pointer_chunk_size
;
1097 template<int size
, bool big_endian
>
1098 const unsigned int Output_data_plt_sparc
<size
, big_endian
>::plt_block_size
;
1100 // Create the PLT section. The ordinary .got section is an argument,
1101 // since we need to refer to the start.
1103 template<int size
, bool big_endian
>
1104 Output_data_plt_sparc
<size
, big_endian
>::Output_data_plt_sparc(Layout
* layout
)
1105 : Output_section_data(size
== 32 ? 4 : 8), count_(0)
1107 this->rel_
= new Reloc_section();
1108 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1109 elfcpp::SHF_ALLOC
, this->rel_
);
1112 template<int size
, bool big_endian
>
1114 Output_data_plt_sparc
<size
, big_endian
>::do_adjust_output_section(Output_section
* os
)
1119 // Add an entry to the PLT.
1121 template<int size
, bool big_endian
>
1123 Output_data_plt_sparc
<size
, big_endian
>::add_entry(Symbol
* gsym
)
1125 gold_assert(!gsym
->has_plt_offset());
1127 unsigned int index
= this->count_
+ 4;
1128 section_offset_type plt_offset
;
1130 if (size
== 32 || index
< 32768)
1131 plt_offset
= index
* base_plt_entry_size
;
1134 unsigned int ext_index
= index
- 32768;
1136 plt_offset
= (32768 * base_plt_entry_size
)
1137 + ((ext_index
/ plt_entries_per_block
)
1139 + ((ext_index
% plt_entries_per_block
)
1140 * plt_insn_chunk_size
);
1143 gsym
->set_plt_offset(plt_offset
);
1147 // Every PLT entry needs a reloc.
1148 gsym
->set_needs_dynsym_entry();
1149 this->rel_
->add_global(gsym
, elfcpp::R_SPARC_JMP_SLOT
, this,
1152 // Note that we don't need to save the symbol. The contents of the
1153 // PLT are independent of which symbols are used. The symbols only
1154 // appear in the relocations.
1157 static const unsigned int sparc_nop
= 0x01000000;
1158 static const unsigned int sparc_sethi_g1
= 0x03000000;
1159 static const unsigned int sparc_branch_always
= 0x30800000;
1160 static const unsigned int sparc_branch_always_pt
= 0x30680000;
1161 static const unsigned int sparc_mov
= 0x80100000;
1162 static const unsigned int sparc_mov_g0_o0
= 0x90100000;
1163 static const unsigned int sparc_mov_o7_g5
= 0x8a10000f;
1164 static const unsigned int sparc_call_plus_8
= 0x40000002;
1165 static const unsigned int sparc_ldx_o7_imm_g1
= 0xc25be000;
1166 static const unsigned int sparc_jmpl_o7_g1_g1
= 0x83c3c001;
1167 static const unsigned int sparc_mov_g5_o7
= 0x9e100005;
1169 // Write out the PLT.
1171 template<int size
, bool big_endian
>
1173 Output_data_plt_sparc
<size
, big_endian
>::do_write(Output_file
* of
)
1175 const off_t offset
= this->offset();
1176 const section_size_type oview_size
=
1177 convert_to_section_size_type(this->data_size());
1178 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
1179 unsigned char* pov
= oview
;
1181 memset(pov
, 0, base_plt_entry_size
* 4);
1182 pov
+= base_plt_entry_size
* 4;
1184 unsigned int plt_offset
= base_plt_entry_size
* 4;
1185 const unsigned int count
= this->count_
;
1191 limit
= (count
> 32768 ? 32768 : count
);
1193 for (unsigned int i
= 0; i
< limit
; ++i
)
1195 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1196 sparc_sethi_g1
+ plt_offset
);
1197 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1198 sparc_branch_always_pt
+
1199 (((base_plt_entry_size
-
1200 (plt_offset
+ 4)) >> 2) &
1202 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1203 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c, sparc_nop
);
1204 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10, sparc_nop
);
1205 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14, sparc_nop
);
1206 elfcpp::Swap
<32, true>::writeval(pov
+ 0x18, sparc_nop
);
1207 elfcpp::Swap
<32, true>::writeval(pov
+ 0x1c, sparc_nop
);
1209 pov
+= base_plt_entry_size
;
1210 plt_offset
+= base_plt_entry_size
;
1215 unsigned int ext_cnt
= count
- 32768;
1216 unsigned int blks
= ext_cnt
/ plt_entries_per_block
;
1218 for (unsigned int i
= 0; i
< blks
; ++i
)
1220 unsigned int data_off
= (plt_entries_per_block
1221 * plt_insn_chunk_size
) - 4;
1223 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1225 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1227 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1229 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1231 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1232 sparc_ldx_o7_imm_g1
+
1233 (data_off
& 0x1fff));
1234 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1235 sparc_jmpl_o7_g1_g1
);
1236 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1239 elfcpp::Swap
<64, big_endian
>::writeval(
1240 pov
+ 0x4 + data_off
,
1241 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1243 pov
+= plt_insn_chunk_size
;
1248 unsigned int sub_blk_cnt
= ext_cnt
% plt_entries_per_block
;
1249 for (unsigned int i
= 0; i
< sub_blk_cnt
; ++i
)
1251 unsigned int data_off
= (sub_blk_cnt
1252 * plt_insn_chunk_size
) - 4;
1254 for (unsigned int j
= 0; j
< plt_entries_per_block
; ++j
)
1256 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1258 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1260 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08,
1262 elfcpp::Swap
<32, true>::writeval(pov
+ 0x0c,
1263 sparc_ldx_o7_imm_g1
+
1264 (data_off
& 0x1fff));
1265 elfcpp::Swap
<32, true>::writeval(pov
+ 0x10,
1266 sparc_jmpl_o7_g1_g1
);
1267 elfcpp::Swap
<32, true>::writeval(pov
+ 0x14,
1270 elfcpp::Swap
<64, big_endian
>::writeval(
1271 pov
+ 0x4 + data_off
,
1272 (elfcpp::Elf_Xword
) (oview
- (pov
+ 0x04)));
1274 pov
+= plt_insn_chunk_size
;
1282 for (unsigned int i
= 0; i
< count
; ++i
)
1284 elfcpp::Swap
<32, true>::writeval(pov
+ 0x00,
1285 sparc_sethi_g1
+ plt_offset
);
1286 elfcpp::Swap
<32, true>::writeval(pov
+ 0x04,
1287 sparc_branch_always
+
1288 (((- (plt_offset
+ 4)) >> 2) &
1290 elfcpp::Swap
<32, true>::writeval(pov
+ 0x08, sparc_nop
);
1292 pov
+= base_plt_entry_size
;
1293 plt_offset
+= base_plt_entry_size
;
1296 elfcpp::Swap
<32, true>::writeval(pov
, sparc_nop
);
1300 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
1302 of
->write_output_view(offset
, oview_size
, oview
);
1305 // Create a PLT entry for a global symbol.
1307 template<int size
, bool big_endian
>
1309 Target_sparc
<size
, big_endian
>::make_plt_entry(Symbol_table
* symtab
,
1313 if (gsym
->has_plt_offset())
1316 if (this->plt_
== NULL
)
1318 // Create the GOT sections first.
1319 this->got_section(symtab
, layout
);
1321 this->plt_
= new Output_data_plt_sparc
<size
, big_endian
>(layout
);
1322 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
1324 | elfcpp::SHF_EXECINSTR
1325 | elfcpp::SHF_WRITE
),
1328 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1329 symtab
->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL
,
1331 0, 0, elfcpp::STT_OBJECT
,
1333 elfcpp::STV_HIDDEN
, 0,
1337 this->plt_
->add_entry(gsym
);
1340 // Create a GOT entry for the TLS module index.
1342 template<int size
, bool big_endian
>
1344 Target_sparc
<size
, big_endian
>::got_mod_index_entry(Symbol_table
* symtab
,
1346 Sized_relobj
<size
, big_endian
>* object
)
1348 if (this->got_mod_index_offset_
== -1U)
1350 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
1351 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1352 Output_data_got
<size
, big_endian
>* got
;
1353 unsigned int got_offset
;
1355 got
= this->got_section(symtab
, layout
);
1356 got_offset
= got
->add_constant(0);
1357 rela_dyn
->add_local(object
, 0,
1359 elfcpp::R_SPARC_TLS_DTPMOD64
:
1360 elfcpp::R_SPARC_TLS_DTPMOD32
), got
,
1362 got
->add_constant(0);
1363 this->got_mod_index_offset_
= got_offset
;
1365 return this->got_mod_index_offset_
;
1368 // Handle a relocation against a non-function symbol defined in a
1369 // dynamic object. The traditional way to handle this is to generate
1370 // a COPY relocation to copy the variable at runtime from the shared
1371 // object into the executable's data segment. However, this is
1372 // undesirable in general, as if the size of the object changes in the
1373 // dynamic object, the executable will no longer work correctly. If
1374 // this relocation is in a writable section, then we can create a
1375 // dynamic reloc and the dynamic linker will resolve it to the correct
1376 // address at runtime. However, we do not want do that if the
1377 // relocation is in a read-only section, as it would prevent the
1378 // readonly segment from being shared. And if we have to eventually
1379 // generate a COPY reloc, then any dynamic relocations will be
1380 // useless. So this means that if this is a writable section, we need
1381 // to save the relocation until we see whether we have to create a
1382 // COPY relocation for this symbol for any other relocation.
1384 template<int size
, bool big_endian
>
1386 Target_sparc
<size
, big_endian
>::copy_reloc(const General_options
* options
,
1387 Symbol_table
* symtab
,
1389 Sized_relobj
<size
, big_endian
>* object
,
1390 unsigned int data_shndx
,
1391 Output_section
* output_section
,
1393 const elfcpp::Rela
<size
, big_endian
>& rel
)
1395 Sized_symbol
<size
>* ssym
= symtab
->get_sized_symbol
<size
>(gsym
);
1397 if (!Copy_relocs
<size
, big_endian
>::need_copy_reloc(options
, object
,
1400 // So far we do not need a COPY reloc. Save this relocation.
1401 // If it turns out that we never need a COPY reloc for this
1402 // symbol, then we will emit the relocation.
1403 if (this->copy_relocs_
== NULL
)
1404 this->copy_relocs_
= new Copy_relocs
<size
, big_endian
>();
1405 this->copy_relocs_
->save(ssym
, object
, data_shndx
, output_section
, rel
);
1409 // Allocate space for this symbol in the .bss section.
1411 typename
elfcpp::Elf_types
<size
>::Elf_WXword symsize
= ssym
->symsize();
1413 // There is no defined way to determine the required alignment
1414 // of the symbol. We pick the alignment based on the size. We
1415 // set an arbitrary maximum of 256.
1417 // XXX remove this when bss alignment issue is fixed...
1418 for (align
= (size
== 32 ? 4 : 8); align
< 512; align
<<= 1)
1419 if ((symsize
& align
) != 0)
1422 if (this->dynbss_
== NULL
)
1424 this->dynbss_
= new Output_data_space(align
);
1425 layout
->add_output_section_data(".bss",
1428 | elfcpp::SHF_WRITE
),
1432 Output_data_space
* dynbss
= this->dynbss_
;
1434 if (align
> dynbss
->addralign())
1435 dynbss
->set_space_alignment(align
);
1437 section_size_type dynbss_size
=
1438 convert_to_section_size_type(dynbss
->current_data_size());
1439 dynbss_size
= align_address(dynbss_size
, align
);
1440 section_size_type offset
= dynbss_size
;
1441 dynbss
->set_current_data_size(dynbss_size
+ symsize
);
1443 symtab
->define_with_copy_reloc(ssym
, dynbss
, offset
);
1445 // Add the COPY reloc.
1446 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
1447 rela_dyn
->add_global(ssym
, elfcpp::R_SPARC_COPY
, dynbss
, offset
, 0);
1451 // Optimize the TLS relocation type based on what we know about the
1452 // symbol. IS_FINAL is true if the final address of this symbol is
1453 // known at link time.
1455 static tls::Tls_optimization
1456 optimize_tls_reloc(bool is_final
, int r_type
)
1458 // If we are generating a shared library, then we can't do anything
1460 if (parameters
->options().shared())
1461 return tls::TLSOPT_NONE
;
1465 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1466 case elfcpp::R_SPARC_TLS_GD_LO10
:
1467 case elfcpp::R_SPARC_TLS_GD_ADD
:
1468 case elfcpp::R_SPARC_TLS_GD_CALL
:
1469 // These are General-Dynamic which permits fully general TLS
1470 // access. Since we know that we are generating an executable,
1471 // we can convert this to Initial-Exec. If we also know that
1472 // this is a local symbol, we can further switch to Local-Exec.
1474 return tls::TLSOPT_TO_LE
;
1475 return tls::TLSOPT_TO_IE
;
1477 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1478 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1479 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1480 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1481 // This is Local-Dynamic, which refers to a local symbol in the
1482 // dynamic TLS block. Since we know that we generating an
1483 // executable, we can switch to Local-Exec.
1484 return tls::TLSOPT_TO_LE
;
1486 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1487 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1488 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1489 // Another type of Local-Dynamic relocation.
1490 return tls::TLSOPT_TO_LE
;
1492 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1493 case elfcpp::R_SPARC_TLS_IE_LO10
:
1494 case elfcpp::R_SPARC_TLS_IE_LD
:
1495 case elfcpp::R_SPARC_TLS_IE_LDX
:
1496 // These are Initial-Exec relocs which get the thread offset
1497 // from the GOT. If we know that we are linking against the
1498 // local symbol, we can switch to Local-Exec, which links the
1499 // thread offset into the instruction.
1501 return tls::TLSOPT_TO_LE
;
1502 return tls::TLSOPT_NONE
;
1504 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1505 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1506 // When we already have Local-Exec, there is nothing further we
1508 return tls::TLSOPT_NONE
;
1515 // Generate a PLT entry slot for a call to __tls_get_addr
1516 template<int size
, bool big_endian
>
1518 Target_sparc
<size
, big_endian
>::Scan::generate_tls_call(Symbol_table
* symtab
,
1520 Target_sparc
<size
, big_endian
>* target
)
1522 Symbol
* gsym
= target
->tls_get_addr_sym(symtab
);
1524 target
->make_plt_entry(symtab
, layout
, gsym
);
1527 // Report an unsupported relocation against a local symbol.
1529 template<int size
, bool big_endian
>
1531 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_local(
1532 Sized_relobj
<size
, big_endian
>* object
,
1533 unsigned int r_type
)
1535 gold_error(_("%s: unsupported reloc %u against local symbol"),
1536 object
->name().c_str(), r_type
);
1539 // Scan a relocation for a local symbol.
1541 template<int size
, bool big_endian
>
1543 Target_sparc
<size
, big_endian
>::Scan::local(
1544 const General_options
&,
1545 Symbol_table
* symtab
,
1547 Target_sparc
<size
, big_endian
>* target
,
1548 Sized_relobj
<size
, big_endian
>* object
,
1549 unsigned int data_shndx
,
1550 Output_section
* output_section
,
1551 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1552 unsigned int r_type
,
1553 const elfcpp::Sym
<size
, big_endian
>& lsym
)
1555 unsigned int orig_r_type
= r_type
;
1560 case elfcpp::R_SPARC_NONE
:
1561 case elfcpp::R_SPARC_REGISTER
:
1562 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1563 case elfcpp::R_SPARC_GNU_VTENTRY
:
1566 case elfcpp::R_SPARC_64
:
1567 case elfcpp::R_SPARC_32
:
1568 // If building a shared library (or a position-independent
1569 // executable), we need to create a dynamic relocation for
1570 // this location. The relocation applied at link time will
1571 // apply the link-time value, so we flag the location with
1572 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1573 // relocate it easily.
1574 if (parameters
->options().output_is_position_independent())
1576 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1577 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1578 rela_dyn
->add_local_relative(object
, r_sym
, elfcpp::R_SPARC_RELATIVE
,
1579 output_section
, data_shndx
,
1580 reloc
.get_r_offset(),
1581 reloc
.get_r_addend());
1585 case elfcpp::R_SPARC_HIX22
:
1586 case elfcpp::R_SPARC_LOX10
:
1587 case elfcpp::R_SPARC_H44
:
1588 case elfcpp::R_SPARC_M44
:
1589 case elfcpp::R_SPARC_L44
:
1590 case elfcpp::R_SPARC_HH22
:
1591 case elfcpp::R_SPARC_HM10
:
1592 case elfcpp::R_SPARC_LM22
:
1593 case elfcpp::R_SPARC_UA64
:
1594 case elfcpp::R_SPARC_UA32
:
1595 case elfcpp::R_SPARC_UA16
:
1596 case elfcpp::R_SPARC_HI22
:
1597 case elfcpp::R_SPARC_LO10
:
1598 case elfcpp::R_SPARC_OLO10
:
1599 case elfcpp::R_SPARC_16
:
1600 case elfcpp::R_SPARC_11
:
1601 case elfcpp::R_SPARC_10
:
1602 case elfcpp::R_SPARC_8
:
1603 case elfcpp::R_SPARC_7
:
1604 case elfcpp::R_SPARC_6
:
1605 case elfcpp::R_SPARC_5
:
1606 // If building a shared library (or a position-independent
1607 // executable), we need to create a dynamic relocation for
1609 if (parameters
->options().output_is_position_independent())
1611 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1612 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
1614 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1615 rela_dyn
->add_local(object
, r_sym
, orig_r_type
, output_section
,
1616 data_shndx
, reloc
.get_r_offset(),
1617 reloc
.get_r_addend());
1621 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1622 gold_assert(lsym
.get_st_value() == 0);
1623 rela_dyn
->add_local_relative(object
, r_sym
, orig_r_type
,
1624 output_section
, data_shndx
,
1625 reloc
.get_r_offset(),
1626 reloc
.get_r_addend());
1631 case elfcpp::R_SPARC_WDISP30
:
1632 case elfcpp::R_SPARC_WDISP22
:
1633 case elfcpp::R_SPARC_WDISP19
:
1634 case elfcpp::R_SPARC_WDISP16
:
1635 case elfcpp::R_SPARC_DISP8
:
1636 case elfcpp::R_SPARC_DISP16
:
1637 case elfcpp::R_SPARC_DISP32
:
1638 case elfcpp::R_SPARC_DISP64
:
1639 case elfcpp::R_SPARC_PC10
:
1640 case elfcpp::R_SPARC_PC22
:
1643 case elfcpp::R_SPARC_GOT10
:
1644 case elfcpp::R_SPARC_GOT13
:
1645 case elfcpp::R_SPARC_GOT22
:
1647 // The symbol requires a GOT entry.
1648 Output_data_got
<size
, big_endian
>* got
;
1651 got
= target
->got_section(symtab
, layout
);
1652 r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1654 // If we are generating a shared object, we need to add a
1655 // dynamic relocation for this symbol's GOT entry.
1656 if (parameters
->options().output_is_position_independent())
1658 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
))
1660 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1663 off
= got
->add_constant(0);
1664 object
->set_local_got_offset(r_sym
, GOT_TYPE_STANDARD
, off
);
1665 rela_dyn
->add_local_relative(object
, r_sym
,
1666 elfcpp::R_SPARC_RELATIVE
,
1671 got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
1675 // These are initial TLS relocs, which are expected when
1677 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1678 case elfcpp::R_SPARC_TLS_GD_LO10
:
1679 case elfcpp::R_SPARC_TLS_GD_ADD
:
1680 case elfcpp::R_SPARC_TLS_GD_CALL
:
1681 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1682 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1683 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1684 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1685 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1686 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1687 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1688 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1689 case elfcpp::R_SPARC_TLS_IE_LO10
:
1690 case elfcpp::R_SPARC_TLS_IE_LD
:
1691 case elfcpp::R_SPARC_TLS_IE_LDX
:
1692 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1693 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1695 bool output_is_shared
= parameters
->options().shared();
1696 const tls::Tls_optimization optimized_type
1697 = optimize_tls_reloc(!output_is_shared
, r_type
);
1700 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
1701 case elfcpp::R_SPARC_TLS_GD_LO10
:
1702 case elfcpp::R_SPARC_TLS_GD_ADD
:
1703 case elfcpp::R_SPARC_TLS_GD_CALL
:
1704 if (optimized_type
== tls::TLSOPT_NONE
)
1706 // Create a pair of GOT entries for the module index and
1707 // dtv-relative offset.
1708 Output_data_got
<size
, big_endian
>* got
1709 = target
->got_section(symtab
, layout
);
1710 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1711 got
->add_local_pair_with_rela(object
, r_sym
,
1712 lsym
.get_st_shndx(),
1714 target
->rela_dyn_section(layout
),
1716 elfcpp::R_SPARC_TLS_DTPMOD64
:
1717 elfcpp::R_SPARC_TLS_DTPMOD32
), 0);
1718 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
1719 generate_tls_call(symtab
, layout
, target
);
1721 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1722 unsupported_reloc_local(object
, r_type
);
1725 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
1726 case elfcpp::R_SPARC_TLS_LDM_LO10
:
1727 case elfcpp::R_SPARC_TLS_LDM_ADD
:
1728 case elfcpp::R_SPARC_TLS_LDM_CALL
:
1729 if (optimized_type
== tls::TLSOPT_NONE
)
1731 // Create a GOT entry for the module index.
1732 target
->got_mod_index_entry(symtab
, layout
, object
);
1734 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
1735 generate_tls_call(symtab
, layout
, target
);
1737 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1738 unsupported_reloc_local(object
, r_type
);
1741 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
1742 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
1743 case elfcpp::R_SPARC_TLS_LDO_ADD
:
1746 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
1747 case elfcpp::R_SPARC_TLS_IE_LO10
:
1748 case elfcpp::R_SPARC_TLS_IE_LD
:
1749 case elfcpp::R_SPARC_TLS_IE_LDX
:
1750 layout
->set_has_static_tls();
1751 if (optimized_type
== tls::TLSOPT_NONE
)
1753 // Create a GOT entry for the tp-relative offset.
1754 Output_data_got
<size
, big_endian
>* got
1755 = target
->got_section(symtab
, layout
);
1756 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1758 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
))
1760 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1761 unsigned int off
= got
->add_constant(0);
1763 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
,
1765 rela_dyn
->add_local_relative(object
, r_sym
,
1767 elfcpp::R_SPARC_TLS_TPOFF64
:
1768 elfcpp::R_SPARC_TLS_TPOFF32
),
1772 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
1773 unsupported_reloc_local(object
, r_type
);
1776 case elfcpp::R_SPARC_TLS_LE_HIX22
: // Local-exec
1777 case elfcpp::R_SPARC_TLS_LE_LOX10
:
1778 layout
->set_has_static_tls();
1779 if (output_is_shared
)
1781 // We need to create a dynamic relocation.
1782 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
1783 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
1784 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1785 rela_dyn
->add_local_relative(object
, r_sym
, r_type
,
1786 output_section
, data_shndx
,
1787 reloc
.get_r_offset(), 0);
1794 // These are relocations which should only be seen by the
1795 // dynamic linker, and should never be seen here.
1796 case elfcpp::R_SPARC_COPY
:
1797 case elfcpp::R_SPARC_GLOB_DAT
:
1798 case elfcpp::R_SPARC_JMP_SLOT
:
1799 case elfcpp::R_SPARC_RELATIVE
:
1800 case elfcpp::R_SPARC_TLS_DTPMOD64
:
1801 case elfcpp::R_SPARC_TLS_DTPMOD32
:
1802 case elfcpp::R_SPARC_TLS_DTPOFF64
:
1803 case elfcpp::R_SPARC_TLS_DTPOFF32
:
1804 case elfcpp::R_SPARC_TLS_TPOFF64
:
1805 case elfcpp::R_SPARC_TLS_TPOFF32
:
1806 gold_error(_("%s: unexpected reloc %u in object file"),
1807 object
->name().c_str(), r_type
);
1811 unsupported_reloc_local(object
, r_type
);
1816 // Report an unsupported relocation against a global symbol.
1818 template<int size
, bool big_endian
>
1820 Target_sparc
<size
, big_endian
>::Scan::unsupported_reloc_global(
1821 Sized_relobj
<size
, big_endian
>* object
,
1822 unsigned int r_type
,
1825 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1826 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
1829 // Scan a relocation for a global symbol.
1831 template<int size
, bool big_endian
>
1833 Target_sparc
<size
, big_endian
>::Scan::global(
1834 const General_options
& options
,
1835 Symbol_table
* symtab
,
1837 Target_sparc
<size
, big_endian
>* target
,
1838 Sized_relobj
<size
, big_endian
>* object
,
1839 unsigned int data_shndx
,
1840 Output_section
* output_section
,
1841 const elfcpp::Rela
<size
, big_endian
>& reloc
,
1842 unsigned int r_type
,
1845 unsigned int orig_r_type
= r_type
;
1850 case elfcpp::R_SPARC_NONE
:
1851 case elfcpp::R_SPARC_REGISTER
:
1852 case elfcpp::R_SPARC_GNU_VTINHERIT
:
1853 case elfcpp::R_SPARC_GNU_VTENTRY
:
1856 case elfcpp::R_SPARC_PLT64
:
1857 case elfcpp::R_SPARC_PLT32
:
1858 case elfcpp::R_SPARC_HIPLT22
:
1859 case elfcpp::R_SPARC_LOPLT10
:
1860 case elfcpp::R_SPARC_PCPLT32
:
1861 case elfcpp::R_SPARC_PCPLT22
:
1862 case elfcpp::R_SPARC_PCPLT10
:
1863 case elfcpp::R_SPARC_WPLT30
:
1864 // If the symbol is fully resolved, this is just a PC32 reloc.
1865 // Otherwise we need a PLT entry.
1866 if (gsym
->final_value_is_known())
1868 // If building a shared library, we can also skip the PLT entry
1869 // if the symbol is defined in the output file and is protected
1871 if (gsym
->is_defined()
1872 && !gsym
->is_from_dynobj()
1873 && !gsym
->is_preemptible())
1875 target
->make_plt_entry(symtab
, layout
, gsym
);
1878 case elfcpp::R_SPARC_DISP8
:
1879 case elfcpp::R_SPARC_DISP16
:
1880 case elfcpp::R_SPARC_DISP32
:
1881 case elfcpp::R_SPARC_DISP64
:
1882 case elfcpp::R_SPARC_PC_HH22
:
1883 case elfcpp::R_SPARC_PC_HM10
:
1884 case elfcpp::R_SPARC_PC_LM22
:
1885 case elfcpp::R_SPARC_PC10
:
1886 case elfcpp::R_SPARC_PC22
:
1887 case elfcpp::R_SPARC_WDISP30
:
1888 case elfcpp::R_SPARC_WDISP22
:
1889 case elfcpp::R_SPARC_WDISP19
:
1890 case elfcpp::R_SPARC_WDISP16
:
1892 if (gsym
->needs_plt_entry())
1893 target
->make_plt_entry(symtab
, layout
, gsym
);
1894 // Make a dynamic relocation if necessary.
1895 int flags
= Symbol::NON_PIC_REF
;
1896 if (gsym
->type() == elfcpp::STT_FUNC
)
1897 flags
|= Symbol::FUNCTION_CALL
;
1898 if (gsym
->needs_dynamic_reloc(flags
))
1900 if (target
->may_need_copy_reloc(gsym
))
1902 target
->copy_reloc(&options
, symtab
, layout
, object
,
1903 data_shndx
, output_section
, gsym
,
1908 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1909 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
, object
,
1910 data_shndx
, reloc
.get_r_offset(),
1911 reloc
.get_r_addend());
1917 case elfcpp::R_SPARC_UA64
:
1918 case elfcpp::R_SPARC_64
:
1919 case elfcpp::R_SPARC_HIX22
:
1920 case elfcpp::R_SPARC_LOX10
:
1921 case elfcpp::R_SPARC_H44
:
1922 case elfcpp::R_SPARC_M44
:
1923 case elfcpp::R_SPARC_L44
:
1924 case elfcpp::R_SPARC_HH22
:
1925 case elfcpp::R_SPARC_HM10
:
1926 case elfcpp::R_SPARC_LM22
:
1927 case elfcpp::R_SPARC_HI22
:
1928 case elfcpp::R_SPARC_LO10
:
1929 case elfcpp::R_SPARC_OLO10
:
1930 case elfcpp::R_SPARC_UA32
:
1931 case elfcpp::R_SPARC_32
:
1932 case elfcpp::R_SPARC_UA16
:
1933 case elfcpp::R_SPARC_16
:
1934 case elfcpp::R_SPARC_11
:
1935 case elfcpp::R_SPARC_10
:
1936 case elfcpp::R_SPARC_8
:
1937 case elfcpp::R_SPARC_7
:
1938 case elfcpp::R_SPARC_6
:
1939 case elfcpp::R_SPARC_5
:
1941 // Make a PLT entry if necessary.
1942 if (gsym
->needs_plt_entry())
1944 target
->make_plt_entry(symtab
, layout
, gsym
);
1945 // Since this is not a PC-relative relocation, we may be
1946 // taking the address of a function. In that case we need to
1947 // set the entry in the dynamic symbol table to the address of
1949 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
1950 gsym
->set_needs_dynsym_value();
1952 // Make a dynamic relocation if necessary.
1953 if (gsym
->needs_dynamic_reloc(Symbol::ABSOLUTE_REF
))
1955 if (target
->may_need_copy_reloc(gsym
))
1957 target
->copy_reloc(&options
, symtab
, layout
, object
,
1958 data_shndx
, output_section
, gsym
, reloc
);
1960 else if ((r_type
== elfcpp::R_SPARC_32
1961 || r_type
== elfcpp::R_SPARC_64
)
1962 && gsym
->can_use_relative_reloc(false))
1964 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1965 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
1966 output_section
, object
,
1967 data_shndx
, reloc
.get_r_offset(),
1968 reloc
.get_r_addend());
1972 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
1974 if (gsym
->is_from_dynobj()
1975 || gsym
->is_undefined()
1976 || gsym
->is_preemptible())
1977 rela_dyn
->add_global(gsym
, orig_r_type
, output_section
,
1979 reloc
.get_r_offset(),
1980 reloc
.get_r_addend());
1982 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
1983 output_section
, object
,
1985 reloc
.get_r_offset(),
1986 reloc
.get_r_addend());
1992 case elfcpp::R_SPARC_GOT10
:
1993 case elfcpp::R_SPARC_GOT13
:
1994 case elfcpp::R_SPARC_GOT22
:
1996 // The symbol requires a GOT entry.
1997 Output_data_got
<size
, big_endian
>* got
;
1999 got
= target
->got_section(symtab
, layout
);
2000 if (gsym
->final_value_is_known())
2001 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
2004 // If this symbol is not fully resolved, we need to add a
2005 // dynamic relocation for it.
2006 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2007 if (gsym
->is_from_dynobj()
2008 || gsym
->is_undefined()
2009 || gsym
->is_preemptible())
2010 got
->add_global_with_rela(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
2011 elfcpp::R_SPARC_GLOB_DAT
);
2012 else if (!gsym
->has_got_offset(GOT_TYPE_STANDARD
))
2014 unsigned int off
= got
->add_constant(0);
2016 gsym
->set_got_offset(GOT_TYPE_STANDARD
, off
);
2017 rela_dyn
->add_global_relative(gsym
, elfcpp::R_SPARC_RELATIVE
,
2024 // These are initial tls relocs, which are expected when
2026 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2027 case elfcpp::R_SPARC_TLS_GD_LO10
:
2028 case elfcpp::R_SPARC_TLS_GD_ADD
:
2029 case elfcpp::R_SPARC_TLS_GD_CALL
:
2030 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2031 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2032 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2033 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2034 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2035 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2036 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2037 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2038 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2039 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2040 case elfcpp::R_SPARC_TLS_IE_LO10
:
2041 case elfcpp::R_SPARC_TLS_IE_LD
:
2042 case elfcpp::R_SPARC_TLS_IE_LDX
:
2044 const bool is_final
= gsym
->final_value_is_known();
2045 const tls::Tls_optimization optimized_type
2046 = optimize_tls_reloc(is_final
, r_type
);
2049 case elfcpp::R_SPARC_TLS_GD_HI22
: // Global-dynamic
2050 case elfcpp::R_SPARC_TLS_GD_LO10
:
2051 case elfcpp::R_SPARC_TLS_GD_ADD
:
2052 case elfcpp::R_SPARC_TLS_GD_CALL
:
2053 if (optimized_type
== tls::TLSOPT_NONE
)
2055 // Create a pair of GOT entries for the module index and
2056 // dtv-relative offset.
2057 Output_data_got
<size
, big_endian
>* got
2058 = target
->got_section(symtab
, layout
);
2059 got
->add_global_pair_with_rela(gsym
, GOT_TYPE_TLS_PAIR
,
2060 target
->rela_dyn_section(layout
),
2062 elfcpp::R_SPARC_TLS_DTPMOD64
:
2063 elfcpp::R_SPARC_TLS_DTPMOD32
),
2065 elfcpp::R_SPARC_TLS_DTPOFF64
:
2066 elfcpp::R_SPARC_TLS_DTPOFF32
));
2068 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2069 if (r_type
== elfcpp::R_SPARC_TLS_GD_CALL
)
2070 generate_tls_call(symtab
, layout
, target
);
2072 else if (optimized_type
== tls::TLSOPT_TO_IE
)
2074 // Create a GOT entry for the tp-relative offset.
2075 Output_data_got
<size
, big_endian
>* got
2076 = target
->got_section(symtab
, layout
);
2077 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2078 target
->rela_dyn_section(layout
),
2080 elfcpp::R_SPARC_TLS_TPOFF64
:
2081 elfcpp::R_SPARC_TLS_TPOFF32
));
2083 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2084 unsupported_reloc_global(object
, r_type
, gsym
);
2087 case elfcpp::R_SPARC_TLS_LDM_HI22
: // Local-dynamic
2088 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2089 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2090 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2091 if (optimized_type
== tls::TLSOPT_NONE
)
2093 // Create a GOT entry for the module index.
2094 target
->got_mod_index_entry(symtab
, layout
, object
);
2096 if (r_type
== elfcpp::R_SPARC_TLS_LDM_CALL
)
2097 generate_tls_call(symtab
, layout
, target
);
2099 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2100 unsupported_reloc_global(object
, r_type
, gsym
);
2103 case elfcpp::R_SPARC_TLS_LDO_HIX22
: // Alternate local-dynamic
2104 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2105 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2108 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2109 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2110 layout
->set_has_static_tls();
2111 if (parameters
->options().shared())
2113 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
2114 rela_dyn
->add_global_relative(gsym
, orig_r_type
,
2115 output_section
, object
,
2116 data_shndx
, reloc
.get_r_offset(),
2121 case elfcpp::R_SPARC_TLS_IE_HI22
: // Initial-exec
2122 case elfcpp::R_SPARC_TLS_IE_LO10
:
2123 case elfcpp::R_SPARC_TLS_IE_LD
:
2124 case elfcpp::R_SPARC_TLS_IE_LDX
:
2125 layout
->set_has_static_tls();
2126 if (optimized_type
== tls::TLSOPT_NONE
)
2128 // Create a GOT entry for the tp-relative offset.
2129 Output_data_got
<size
, big_endian
>* got
2130 = target
->got_section(symtab
, layout
);
2131 got
->add_global_with_rela(gsym
, GOT_TYPE_TLS_OFFSET
,
2132 target
->rela_dyn_section(layout
),
2134 elfcpp::R_SPARC_TLS_TPOFF64
:
2135 elfcpp::R_SPARC_TLS_TPOFF32
));
2137 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
2138 unsupported_reloc_global(object
, r_type
, gsym
);
2144 // These are relocations which should only be seen by the
2145 // dynamic linker, and should never be seen here.
2146 case elfcpp::R_SPARC_COPY
:
2147 case elfcpp::R_SPARC_GLOB_DAT
:
2148 case elfcpp::R_SPARC_JMP_SLOT
:
2149 case elfcpp::R_SPARC_RELATIVE
:
2150 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2151 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2152 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2153 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2154 case elfcpp::R_SPARC_TLS_TPOFF64
:
2155 case elfcpp::R_SPARC_TLS_TPOFF32
:
2156 gold_error(_("%s: unexpected reloc %u in object file"),
2157 object
->name().c_str(), r_type
);
2161 unsupported_reloc_global(object
, r_type
, gsym
);
2166 // Scan relocations for a section.
2168 template<int size
, bool big_endian
>
2170 Target_sparc
<size
, big_endian
>::scan_relocs(
2171 const General_options
& options
,
2172 Symbol_table
* symtab
,
2174 Sized_relobj
<size
, big_endian
>* object
,
2175 unsigned int data_shndx
,
2176 unsigned int sh_type
,
2177 const unsigned char* prelocs
,
2179 Output_section
* output_section
,
2180 bool needs_special_offset_handling
,
2181 size_t local_symbol_count
,
2182 const unsigned char* plocal_symbols
)
2184 typedef Target_sparc
<size
, big_endian
> Sparc
;
2185 typedef typename Target_sparc
<size
, big_endian
>::Scan Scan
;
2187 if (sh_type
== elfcpp::SHT_REL
)
2189 gold_error(_("%s: unsupported REL reloc section"),
2190 object
->name().c_str());
2194 gold::scan_relocs
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
, Scan
>(
2204 needs_special_offset_handling
,
2209 // Finalize the sections.
2211 template<int size
, bool big_endian
>
2213 Target_sparc
<size
, big_endian
>::do_finalize_sections(Layout
* layout
)
2215 // Fill in some more dynamic tags.
2216 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
2219 if (this->plt_
!= NULL
)
2221 const Output_data
* od
= this->plt_
->rel_plt();
2222 odyn
->add_section_size(elfcpp::DT_PLTRELSZ
, od
);
2223 odyn
->add_section_address(elfcpp::DT_JMPREL
, od
);
2224 odyn
->add_constant(elfcpp::DT_PLTREL
, elfcpp::DT_RELA
);
2226 odyn
->add_section_address(elfcpp::DT_PLTGOT
, this->plt_
);
2229 if (this->rela_dyn_
!= NULL
)
2231 const Output_data
* od
= this->rela_dyn_
;
2232 odyn
->add_section_address(elfcpp::DT_RELA
, od
);
2233 odyn
->add_section_size(elfcpp::DT_RELASZ
, od
);
2234 odyn
->add_constant(elfcpp::DT_RELAENT
,
2235 elfcpp::Elf_sizes
<size
>::rela_size
);
2238 if (!parameters
->options().shared())
2240 // The value of the DT_DEBUG tag is filled in by the dynamic
2241 // linker at run time, and used by the debugger.
2242 odyn
->add_constant(elfcpp::DT_DEBUG
, 0);
2246 // Emit any relocs we saved in an attempt to avoid generating COPY
2248 if (this->copy_relocs_
== NULL
)
2250 if (this->copy_relocs_
->any_to_emit())
2252 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2253 this->copy_relocs_
->emit(rela_dyn
);
2255 delete this->copy_relocs_
;
2256 this->copy_relocs_
= NULL
;
2259 // Perform a relocation.
2261 template<int size
, bool big_endian
>
2263 Target_sparc
<size
, big_endian
>::Relocate::relocate(
2264 const Relocate_info
<size
, big_endian
>* relinfo
,
2265 Target_sparc
* target
,
2267 const elfcpp::Rela
<size
, big_endian
>& rela
,
2268 unsigned int r_type
,
2269 const Sized_symbol
<size
>* gsym
,
2270 const Symbol_value
<size
>* psymval
,
2271 unsigned char* view
,
2272 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2273 section_size_type view_size
)
2277 if (this->ignore_gd_add_
)
2279 if (r_type
!= elfcpp::R_SPARC_TLS_GD_ADD
)
2280 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2281 _("missing expected TLS relocation"));
2284 this->ignore_gd_add_
= false;
2289 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2291 // Pick the value to use for symbols defined in shared objects.
2292 Symbol_value
<size
> symval
;
2294 && (gsym
->is_from_dynobj()
2295 || (parameters
->options().shared()
2296 && (gsym
->is_undefined() || gsym
->is_preemptible())))
2297 && gsym
->has_plt_offset())
2299 elfcpp::Elf_Xword value
;
2301 value
= target
->plt_section()->address() + gsym
->plt_offset();
2303 symval
.set_output_value(value
);
2308 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2309 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2311 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2312 // pointer points to the beginning, not the end, of the table.
2313 // So we just use the plain offset.
2314 bool have_got_offset
= false;
2315 unsigned int got_offset
= 0;
2318 case elfcpp::R_SPARC_GOT10
:
2319 case elfcpp::R_SPARC_GOT13
:
2320 case elfcpp::R_SPARC_GOT22
:
2323 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
2324 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
);
2328 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2329 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
2330 got_offset
= object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
2332 have_got_offset
= true;
2341 case elfcpp::R_SPARC_NONE
:
2342 case elfcpp::R_SPARC_REGISTER
:
2343 case elfcpp::R_SPARC_GNU_VTINHERIT
:
2344 case elfcpp::R_SPARC_GNU_VTENTRY
:
2347 case elfcpp::R_SPARC_8
:
2348 Relocate_functions
<size
, big_endian
>::rela8(view
, object
,
2352 case elfcpp::R_SPARC_16
:
2353 Relocate_functions
<size
, big_endian
>::rela16(view
, object
,
2357 case elfcpp::R_SPARC_32
:
2358 if (!parameters
->options().output_is_position_independent())
2359 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2363 case elfcpp::R_SPARC_DISP8
:
2364 Reloc::disp8(view
, object
, psymval
, addend
, address
);
2367 case elfcpp::R_SPARC_DISP16
:
2368 Reloc::disp16(view
, object
, psymval
, addend
, address
);
2371 case elfcpp::R_SPARC_DISP32
:
2372 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2375 case elfcpp::R_SPARC_DISP64
:
2376 Reloc::disp64(view
, object
, psymval
, addend
, address
);
2379 case elfcpp::R_SPARC_WDISP30
:
2380 case elfcpp::R_SPARC_WPLT30
:
2381 Reloc::wdisp30(view
, object
, psymval
, addend
, address
);
2384 case elfcpp::R_SPARC_WDISP22
:
2385 Reloc::wdisp22(view
, object
, psymval
, addend
, address
);
2388 case elfcpp::R_SPARC_WDISP19
:
2389 Reloc::wdisp19(view
, object
, psymval
, addend
, address
);
2392 case elfcpp::R_SPARC_WDISP16
:
2393 Reloc::wdisp16(view
, object
, psymval
, addend
, address
);
2396 case elfcpp::R_SPARC_HI22
:
2397 Reloc::hi22(view
, object
, psymval
, addend
);
2400 case elfcpp::R_SPARC_22
:
2401 Reloc::rela32_22(view
, object
, psymval
, addend
);
2404 case elfcpp::R_SPARC_13
:
2405 Reloc::rela32_13(view
, object
, psymval
, addend
);
2408 case elfcpp::R_SPARC_LO10
:
2409 Reloc::lo10(view
, object
, psymval
, addend
);
2412 case elfcpp::R_SPARC_GOT10
:
2413 Reloc::lo10(view
, got_offset
, addend
);
2416 case elfcpp::R_SPARC_GOT13
:
2417 Reloc::rela32_13(view
, got_offset
, addend
);
2420 case elfcpp::R_SPARC_GOT22
:
2421 Reloc::hi22(view
, got_offset
, addend
);
2424 case elfcpp::R_SPARC_PC10
:
2425 Reloc::pc10(view
, object
, psymval
, addend
, address
);
2428 case elfcpp::R_SPARC_PC22
:
2429 Reloc::pc22(view
, object
, psymval
, addend
, address
);
2432 case elfcpp::R_SPARC_TLS_DTPOFF32
:
2433 case elfcpp::R_SPARC_UA32
:
2434 Reloc::ua32(view
, object
, psymval
, addend
);
2437 case elfcpp::R_SPARC_PLT64
:
2438 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2442 case elfcpp::R_SPARC_PLT32
:
2443 Relocate_functions
<size
, big_endian
>::rela32(view
, object
,
2447 case elfcpp::R_SPARC_HIPLT22
:
2448 Reloc::hi22(view
, object
, psymval
, addend
);
2451 case elfcpp::R_SPARC_LOPLT10
:
2452 Reloc::lo10(view
, object
, psymval
, addend
);
2455 case elfcpp::R_SPARC_PCPLT32
:
2456 Reloc::disp32(view
, object
, psymval
, addend
, address
);
2459 case elfcpp::R_SPARC_PCPLT22
:
2460 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2463 case elfcpp::R_SPARC_PCPLT10
:
2464 Reloc::lo10(view
, object
, psymval
, addend
, address
);
2467 case elfcpp::R_SPARC_64
:
2468 if (!parameters
->options().output_is_position_independent())
2469 Relocate_functions
<size
, big_endian
>::rela64(view
, object
,
2473 case elfcpp::R_SPARC_OLO10
:
2475 unsigned int addend2
= rela
.get_r_info() & 0xffffffff;
2476 addend2
= ((addend2
>> 8) ^ 0x800000) - 0x800000;
2477 Reloc::olo10(view
, object
, psymval
, addend
, addend2
);
2481 case elfcpp::R_SPARC_HH22
:
2482 Reloc::hh22(view
, object
, psymval
, addend
);
2485 case elfcpp::R_SPARC_PC_HH22
:
2486 Reloc::pc_hh22(view
, object
, psymval
, addend
, address
);
2489 case elfcpp::R_SPARC_HM10
:
2490 Reloc::hm10(view
, object
, psymval
, addend
);
2493 case elfcpp::R_SPARC_PC_HM10
:
2494 Reloc::pc_hm10(view
, object
, psymval
, addend
, address
);
2497 case elfcpp::R_SPARC_LM22
:
2498 Reloc::hi22(view
, object
, psymval
, addend
);
2501 case elfcpp::R_SPARC_PC_LM22
:
2502 Reloc::pcplt22(view
, object
, psymval
, addend
, address
);
2505 case elfcpp::R_SPARC_11
:
2506 Reloc::rela32_11(view
, object
, psymval
, addend
);
2509 case elfcpp::R_SPARC_10
:
2510 Reloc::rela32_10(view
, object
, psymval
, addend
);
2513 case elfcpp::R_SPARC_7
:
2514 Reloc::rela32_7(view
, object
, psymval
, addend
);
2517 case elfcpp::R_SPARC_6
:
2518 Reloc::rela32_6(view
, object
, psymval
, addend
);
2521 case elfcpp::R_SPARC_5
:
2522 Reloc::rela32_5(view
, object
, psymval
, addend
);
2525 case elfcpp::R_SPARC_HIX22
:
2526 Reloc::hix22(view
, object
, psymval
, addend
);
2529 case elfcpp::R_SPARC_LOX10
:
2530 Reloc::lox10(view
, object
, psymval
, addend
);
2533 case elfcpp::R_SPARC_H44
:
2534 Reloc::h44(view
, object
, psymval
, addend
);
2537 case elfcpp::R_SPARC_M44
:
2538 Reloc::m44(view
, object
, psymval
, addend
);
2541 case elfcpp::R_SPARC_L44
:
2542 Reloc::l44(view
, object
, psymval
, addend
);
2545 case elfcpp::R_SPARC_TLS_DTPOFF64
:
2546 case elfcpp::R_SPARC_UA64
:
2547 Reloc::ua64(view
, object
, psymval
, addend
);
2550 case elfcpp::R_SPARC_UA16
:
2551 Reloc::ua16(view
, object
, psymval
, addend
);
2554 case elfcpp::R_SPARC_TLS_GD_HI22
:
2555 case elfcpp::R_SPARC_TLS_GD_LO10
:
2556 case elfcpp::R_SPARC_TLS_GD_ADD
:
2557 case elfcpp::R_SPARC_TLS_GD_CALL
:
2558 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2559 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2560 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2561 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2562 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2563 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2564 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2565 case elfcpp::R_SPARC_TLS_IE_HI22
:
2566 case elfcpp::R_SPARC_TLS_IE_LO10
:
2567 case elfcpp::R_SPARC_TLS_IE_LD
:
2568 case elfcpp::R_SPARC_TLS_IE_LDX
:
2569 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2570 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2571 this->relocate_tls(relinfo
, target
, relnum
, rela
,
2572 r_type
, gsym
, psymval
, view
,
2573 address
, view_size
);
2576 case elfcpp::R_SPARC_COPY
:
2577 case elfcpp::R_SPARC_GLOB_DAT
:
2578 case elfcpp::R_SPARC_JMP_SLOT
:
2579 case elfcpp::R_SPARC_RELATIVE
:
2580 // These are outstanding tls relocs, which are unexpected when
2582 case elfcpp::R_SPARC_TLS_DTPMOD64
:
2583 case elfcpp::R_SPARC_TLS_DTPMOD32
:
2584 case elfcpp::R_SPARC_TLS_TPOFF64
:
2585 case elfcpp::R_SPARC_TLS_TPOFF32
:
2586 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2587 _("unexpected reloc %u in object file"),
2592 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2593 _("unsupported reloc %u"),
2601 // Perform a TLS relocation.
2603 template<int size
, bool big_endian
>
2605 Target_sparc
<size
, big_endian
>::Relocate::relocate_tls(
2606 const Relocate_info
<size
, big_endian
>* relinfo
,
2607 Target_sparc
<size
, big_endian
>* target
,
2609 const elfcpp::Rela
<size
, big_endian
>& rela
,
2610 unsigned int r_type
,
2611 const Sized_symbol
<size
>* gsym
,
2612 const Symbol_value
<size
>* psymval
,
2613 unsigned char* view
,
2614 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2617 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
2618 typedef Sparc_relocate_functions
<size
, big_endian
> Reloc
;
2619 const Sized_relobj
<size
, big_endian
>* object
= relinfo
->object
;
2620 typedef typename
elfcpp::Swap
<32, true>::Valtype Insntype
;
2622 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
2623 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(object
, 0);
2625 const bool is_final
=
2627 ? !parameters
->options().output_is_position_independent()
2628 : gsym
->final_value_is_known());
2629 const tls::Tls_optimization optimized_type
2630 = optimize_tls_reloc(is_final
, r_type
);
2634 case elfcpp::R_SPARC_TLS_GD_HI22
:
2635 case elfcpp::R_SPARC_TLS_GD_LO10
:
2636 case elfcpp::R_SPARC_TLS_GD_ADD
:
2637 case elfcpp::R_SPARC_TLS_GD_CALL
:
2638 if (optimized_type
== tls::TLSOPT_TO_LE
)
2640 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2643 value
-= tls_segment
->memsz();
2647 case elfcpp::R_SPARC_TLS_GD_HI22
:
2648 // TLS_GD_HI22 --> TLS_LE_HIX22
2649 Reloc::hix22(view
, value
, addend
);
2652 case elfcpp::R_SPARC_TLS_GD_LO10
:
2653 // TLS_GD_LO10 --> TLS_LE_LOX10
2654 Reloc::lox10(view
, value
, addend
);
2657 case elfcpp::R_SPARC_TLS_GD_ADD
:
2658 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2659 val
= elfcpp::Swap
<32, true>::readval(wv
);
2660 val
= (val
& ~0x7c000) | 0x1c000;
2661 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2663 case elfcpp::R_SPARC_TLS_GD_CALL
:
2664 // call __tls_get_addr --> nop
2665 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2672 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
2673 ? GOT_TYPE_TLS_OFFSET
2674 : GOT_TYPE_TLS_PAIR
);
2677 gold_assert(gsym
->has_got_offset(got_type
));
2678 value
= gsym
->got_offset(got_type
);
2682 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2683 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
2684 value
= object
->local_got_offset(r_sym
, got_type
);
2686 if (optimized_type
== tls::TLSOPT_TO_IE
)
2688 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2693 case elfcpp::R_SPARC_TLS_GD_HI22
:
2694 // TLS_GD_HI22 --> TLS_IE_HI22
2695 Reloc::hi22(view
, value
, addend
);
2698 case elfcpp::R_SPARC_TLS_GD_LO10
:
2699 // TLS_GD_LO10 --> TLS_IE_LO10
2700 Reloc::lo10(view
, value
, addend
);
2703 case elfcpp::R_SPARC_TLS_GD_ADD
:
2704 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2705 val
= elfcpp::Swap
<32, true>::readval(wv
);
2712 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2715 case elfcpp::R_SPARC_TLS_GD_CALL
:
2716 // The compiler can put the TLS_GD_ADD instruction
2717 // into the delay slot of the call. If so, we need
2718 // to transpose the two instructions so that the
2719 // the new sequence works properly.
2721 // The test we use is if the instruction in the
2722 // delay slot is an add with destination register
2724 val
= elfcpp::Swap
<32, true>::readval(wv
+ 1);
2725 if ((val
& 0x81f80000) == 0x80000000
2726 && ((val
>> 25) & 0x1f) == 0x8)
2733 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2736 this->ignore_gd_add_
= true;
2739 // call __tls_get_addr --> add %g7, %o0, %o0
2740 elfcpp::Swap
<32, true>::writeval(wv
, 0x9001c008);
2745 else if (optimized_type
== tls::TLSOPT_NONE
)
2749 case elfcpp::R_SPARC_TLS_GD_HI22
:
2750 Reloc::hi22(view
, value
, addend
);
2752 case elfcpp::R_SPARC_TLS_GD_LO10
:
2753 Reloc::lo10(view
, value
, addend
);
2755 case elfcpp::R_SPARC_TLS_GD_ADD
:
2757 case elfcpp::R_SPARC_TLS_GD_CALL
:
2759 Symbol_value
<size
> symval
;
2760 elfcpp::Elf_Xword value
;
2763 tsym
= target
->tls_get_addr_sym_
;
2765 value
= (target
->plt_section()->address() +
2766 tsym
->plt_offset());
2767 symval
.set_output_value(value
);
2768 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2775 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2776 _("unsupported reloc %u"),
2780 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2781 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2782 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2783 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2784 if (optimized_type
== tls::TLSOPT_TO_LE
)
2786 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2790 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2791 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2792 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2793 elfcpp::Swap
<32, true>::writeval(wv
, sparc_nop
);
2796 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2797 elfcpp::Swap
<32, true>::writeval(wv
, sparc_mov_g0_o0
);
2802 else if (optimized_type
== tls::TLSOPT_NONE
)
2804 // Relocate the field with the offset of the GOT entry for
2805 // the module index.
2806 unsigned int got_offset
;
2808 got_offset
= target
->got_mod_index_entry(NULL
, NULL
, NULL
);
2811 case elfcpp::R_SPARC_TLS_LDM_HI22
:
2812 Reloc::hi22(view
, got_offset
, addend
);
2814 case elfcpp::R_SPARC_TLS_LDM_LO10
:
2815 Reloc::lo10(view
, got_offset
, addend
);
2817 case elfcpp::R_SPARC_TLS_LDM_ADD
:
2819 case elfcpp::R_SPARC_TLS_LDM_CALL
:
2821 Symbol_value
<size
> symval
;
2822 elfcpp::Elf_Xword value
;
2825 tsym
= target
->tls_get_addr_sym_
;
2827 value
= (target
->plt_section()->address() +
2828 tsym
->plt_offset());
2829 symval
.set_output_value(value
);
2830 Reloc::wdisp30(view
, object
, &symval
, addend
, address
);
2836 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2837 _("unsupported reloc %u"),
2841 // These relocs can appear in debugging sections, in which case
2842 // we won't see the TLS_LDM relocs. The local_dynamic_type
2843 // field tells us this.
2844 case elfcpp::R_SPARC_TLS_LDO_HIX22
:
2845 if (optimized_type
== tls::TLSOPT_TO_LE
)
2847 value
-= tls_segment
->memsz();
2848 Reloc::hix22(view
, value
, addend
);
2851 Reloc::ldo_hix22(view
, value
, addend
);
2853 case elfcpp::R_SPARC_TLS_LDO_LOX10
:
2854 if (optimized_type
== tls::TLSOPT_TO_LE
)
2856 value
-= tls_segment
->memsz();
2857 Reloc::lox10(view
, value
, addend
);
2860 Reloc::ldo_lox10(view
, value
, addend
);
2862 case elfcpp::R_SPARC_TLS_LDO_ADD
:
2863 if (optimized_type
== tls::TLSOPT_TO_LE
)
2865 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2868 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2869 val
= elfcpp::Swap
<32, true>::readval(wv
);
2870 val
= (val
& ~0x7c000) | 0x1c000;
2871 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2875 // When optimizing IE --> LE, the only relocation that is handled
2876 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2877 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2878 // rs2 and rd are the same.
2879 case elfcpp::R_SPARC_TLS_IE_LD
:
2880 case elfcpp::R_SPARC_TLS_IE_LDX
:
2881 if (optimized_type
== tls::TLSOPT_TO_LE
)
2883 Insntype
* wv
= reinterpret_cast<Insntype
*>(view
);
2884 Insntype val
= elfcpp::Swap
<32, true>::readval(wv
);
2885 Insntype rs2
= val
& 0x1f;
2886 Insntype rd
= (val
>> 25) & 0x1f;
2891 val
= sparc_mov
| (val
& 0x3e00001f);
2893 elfcpp::Swap
<32, true>::writeval(wv
, val
);
2897 case elfcpp::R_SPARC_TLS_IE_HI22
:
2898 case elfcpp::R_SPARC_TLS_IE_LO10
:
2899 if (optimized_type
== tls::TLSOPT_TO_LE
)
2901 value
-= tls_segment
->memsz();
2904 case elfcpp::R_SPARC_TLS_IE_HI22
:
2905 // IE_HI22 --> LE_HIX22
2906 Reloc::hix22(view
, value
, addend
);
2908 case elfcpp::R_SPARC_TLS_IE_LO10
:
2909 // IE_LO10 --> LE_LOX10
2910 Reloc::lox10(view
, value
, addend
);
2915 else if (optimized_type
== tls::TLSOPT_NONE
)
2917 // Relocate the field with the offset of the GOT entry for
2918 // the tp-relative offset of the symbol.
2921 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
2922 value
= gsym
->got_offset(GOT_TYPE_TLS_OFFSET
);
2926 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
2927 gold_assert(object
->local_has_got_offset(r_sym
,
2928 GOT_TYPE_TLS_OFFSET
));
2929 value
= object
->local_got_offset(r_sym
,
2930 GOT_TYPE_TLS_OFFSET
);
2934 case elfcpp::R_SPARC_TLS_IE_HI22
:
2935 Reloc::hi22(view
, value
, addend
);
2937 case elfcpp::R_SPARC_TLS_IE_LO10
:
2938 Reloc::lo10(view
, value
, addend
);
2943 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
2944 _("unsupported reloc %u"),
2948 case elfcpp::R_SPARC_TLS_LE_HIX22
:
2949 // If we're creating a shared library, a dynamic relocation will
2950 // have been created for this location, so do not apply it now.
2951 if (!parameters
->options().shared())
2953 value
-= tls_segment
->memsz();
2954 Reloc::hix22(view
, value
, addend
);
2958 case elfcpp::R_SPARC_TLS_LE_LOX10
:
2959 // If we're creating a shared library, a dynamic relocation will
2960 // have been created for this location, so do not apply it now.
2961 if (!parameters
->options().shared())
2963 value
-= tls_segment
->memsz();
2964 Reloc::lox10(view
, value
, addend
);
2970 // Relocate section data.
2972 template<int size
, bool big_endian
>
2974 Target_sparc
<size
, big_endian
>::relocate_section(
2975 const Relocate_info
<size
, big_endian
>* relinfo
,
2976 unsigned int sh_type
,
2977 const unsigned char* prelocs
,
2979 Output_section
* output_section
,
2980 bool needs_special_offset_handling
,
2981 unsigned char* view
,
2982 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
2983 section_size_type view_size
)
2985 typedef Target_sparc
<size
, big_endian
> Sparc
;
2986 typedef typename Target_sparc
<size
, big_endian
>::Relocate Sparc_relocate
;
2988 gold_assert(sh_type
== elfcpp::SHT_RELA
);
2990 gold::relocate_section
<size
, big_endian
, Sparc
, elfcpp::SHT_RELA
,
2997 needs_special_offset_handling
,
3003 // Return the size of a relocation while scanning during a relocatable
3006 template<int size
, bool big_endian
>
3008 Target_sparc
<size
, big_endian
>::Relocatable_size_for_reloc::get_size_for_reloc(
3012 // We are always SHT_RELA, so we should never get here.
3017 // Scan the relocs during a relocatable link.
3019 template<int size
, bool big_endian
>
3021 Target_sparc
<size
, big_endian
>::scan_relocatable_relocs(
3022 const General_options
& options
,
3023 Symbol_table
* symtab
,
3025 Sized_relobj
<size
, big_endian
>* object
,
3026 unsigned int data_shndx
,
3027 unsigned int sh_type
,
3028 const unsigned char* prelocs
,
3030 Output_section
* output_section
,
3031 bool needs_special_offset_handling
,
3032 size_t local_symbol_count
,
3033 const unsigned char* plocal_symbols
,
3034 Relocatable_relocs
* rr
)
3036 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3038 typedef gold::Default_scan_relocatable_relocs
<elfcpp::SHT_RELA
,
3039 Relocatable_size_for_reloc
> Scan_relocatable_relocs
;
3041 gold::scan_relocatable_relocs
<size
, big_endian
, elfcpp::SHT_RELA
,
3042 Scan_relocatable_relocs
>(
3051 needs_special_offset_handling
,
3057 // Relocate a section during a relocatable link.
3059 template<int size
, bool big_endian
>
3061 Target_sparc
<size
, big_endian
>::relocate_for_relocatable(
3062 const Relocate_info
<size
, big_endian
>* relinfo
,
3063 unsigned int sh_type
,
3064 const unsigned char* prelocs
,
3066 Output_section
* output_section
,
3067 off_t offset_in_output_section
,
3068 const Relocatable_relocs
* rr
,
3069 unsigned char* view
,
3070 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
3071 section_size_type view_size
,
3072 unsigned char* reloc_view
,
3073 section_size_type reloc_view_size
)
3075 gold_assert(sh_type
== elfcpp::SHT_RELA
);
3077 gold::relocate_for_relocatable
<size
, big_endian
, elfcpp::SHT_RELA
>(
3082 offset_in_output_section
,
3091 // Return the value to use for a dynamic which requires special
3092 // treatment. This is how we support equality comparisons of function
3093 // pointers across shared library boundaries, as described in the
3094 // processor specific ABI supplement.
3096 template<int size
, bool big_endian
>
3098 Target_sparc
<size
, big_endian
>::do_dynsym_value(const Symbol
* gsym
) const
3100 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
3101 return this->plt_section()->address() + gsym
->plt_offset();
3104 // The selector for sparc object files.
3106 template<int size
, bool big_endian
>
3107 class Target_selector_sparc
: public Target_selector
3110 Target_selector_sparc()
3111 : Target_selector(elfcpp::EM_NONE
, size
, big_endian
,
3112 (size
== 64 ? "elf64-sparc" : "elf32-sparc"))
3115 Target
* instantiated_target_
;
3117 Target
* do_recognize(int machine
, int, int)
3122 if (machine
!= elfcpp::EM_SPARCV9
)
3127 if (machine
!= elfcpp::EM_SPARC
3128 && machine
!= elfcpp::EM_SPARC32PLUS
)
3136 return do_instantiate_target();
3139 Target
* do_instantiate_target()
3141 if (this->instantiated_target_
== NULL
)
3142 this->instantiated_target_
= new Target_sparc
<size
, big_endian
>();
3143 return this->instantiated_target_
;
3147 Target_selector_sparc
<32, true> target_selector_sparc32
;
3148 Target_selector_sparc
<64, true> target_selector_sparc64
;
3150 } // End anonymous namespace.