1 // sparc.cc -- sparc target support for gold.
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
30 #include "parameters.h"
37 #include "copy-relocs.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
49 template<int size, bool big_endian>
50 class Output_data_plt_sparc;
52 template<int size, bool big_endian>
53 class Target_sparc : public Sized_target<size, big_endian>
56 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
59 : Sized_target<size, big_endian>(&sparc_info),
60 got_(NULL), plt_(NULL), rela_dyn_(NULL),
61 copy_relocs_(elfcpp::R_SPARC_COPY), dynbss_(NULL),
62 got_mod_index_offset_(-1U), tls_get_addr_sym_(NULL)
66 // Scan the relocations to look for symbol adjustments.
68 scan_relocs(const General_options& options,
71 Sized_relobj<size, big_endian>* object,
72 unsigned int data_shndx,
74 const unsigned char* prelocs,
76 Output_section* output_section,
77 bool needs_special_offset_handling,
78 size_t local_symbol_count,
79 const unsigned char* plocal_symbols);
80 // Finalize the sections.
82 do_finalize_sections(Layout*);
84 // Return the value to use for a dynamic which requires special
87 do_dynsym_value(const Symbol*) const;
89 // Relocate a section.
91 relocate_section(const Relocate_info<size, big_endian>*,
93 const unsigned char* prelocs,
95 Output_section* output_section,
96 bool needs_special_offset_handling,
98 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
99 section_size_type view_size);
101 // Scan the relocs during a relocatable link.
103 scan_relocatable_relocs(const General_options& options,
104 Symbol_table* symtab,
106 Sized_relobj<size, big_endian>* object,
107 unsigned int data_shndx,
108 unsigned int sh_type,
109 const unsigned char* prelocs,
111 Output_section* output_section,
112 bool needs_special_offset_handling,
113 size_t local_symbol_count,
114 const unsigned char* plocal_symbols,
115 Relocatable_relocs*);
117 // Relocate a section during a relocatable link.
119 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
120 unsigned int sh_type,
121 const unsigned char* prelocs,
123 Output_section* output_section,
124 off_t offset_in_output_section,
125 const Relocatable_relocs*,
127 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
128 section_size_type view_size,
129 unsigned char* reloc_view,
130 section_size_type reloc_view_size);
131 // Return whether SYM is defined by the ABI.
133 do_is_defined_by_abi(Symbol* sym) const
135 // XXX Really need to support this better...
136 if (sym->type() == elfcpp::STT_SPARC_REGISTER)
139 return strcmp(sym->name(), "___tls_get_addr") == 0;
142 // Return the size of the GOT section.
146 gold_assert(this->got_ != NULL);
147 return this->got_->data_size();
152 // The class which scans relocations.
156 local(const General_options& options, Symbol_table* symtab,
157 Layout* layout, Target_sparc* target,
158 Sized_relobj<size, big_endian>* object,
159 unsigned int data_shndx,
160 Output_section* output_section,
161 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
162 const elfcpp::Sym<size, big_endian>& lsym);
165 global(const General_options& options, Symbol_table* symtab,
166 Layout* layout, Target_sparc* target,
167 Sized_relobj<size, big_endian>* object,
168 unsigned int data_shndx,
169 Output_section* output_section,
170 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
174 unsupported_reloc_local(Sized_relobj<size, big_endian>*,
175 unsigned int r_type);
178 unsupported_reloc_global(Sized_relobj<size, big_endian>*,
179 unsigned int r_type, Symbol*);
182 generate_tls_call(Symbol_table* symtab, Layout* layout,
183 Target_sparc* target);
186 // The class which implements relocation.
191 : ignore_gd_add_(false)
196 if (this->ignore_gd_add_)
198 // FIXME: This needs to specify the location somehow.
199 gold_error(_("missing expected TLS relocation"));
203 // Do a relocation. Return false if the caller should not issue
204 // any warnings about this relocation.
206 relocate(const Relocate_info<size, big_endian>*, Target_sparc*,
207 size_t relnum, const elfcpp::Rela<size, big_endian>&,
208 unsigned int r_type, const Sized_symbol<size>*,
209 const Symbol_value<size>*,
211 typename elfcpp::Elf_types<size>::Elf_Addr,
215 // Do a TLS relocation.
217 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
218 size_t relnum, const elfcpp::Rela<size, big_endian>&,
219 unsigned int r_type, const Sized_symbol<size>*,
220 const Symbol_value<size>*,
222 typename elfcpp::Elf_types<size>::Elf_Addr,
225 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
229 // A class which returns the size required for a relocation type,
230 // used while scanning relocs during a relocatable link.
231 class Relocatable_size_for_reloc
235 get_size_for_reloc(unsigned int, Relobj*);
238 // Get the GOT section, creating it if necessary.
239 Output_data_got<size, big_endian>*
240 got_section(Symbol_table*, Layout*);
242 // Create a PLT entry for a global symbol.
244 make_plt_entry(Symbol_table*, Layout*, Symbol*);
246 // Create a GOT entry for the TLS module index.
248 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
249 Sized_relobj<size, big_endian>* object);
251 // Return the gsym for "__tls_get_addr". Cache if not already
254 tls_get_addr_sym(Symbol_table* symtab)
256 if (!this->tls_get_addr_sym_)
257 this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL);
258 gold_assert(this->tls_get_addr_sym_);
259 return this->tls_get_addr_sym_;
262 // Get the PLT section.
263 const Output_data_plt_sparc<size, big_endian>*
266 gold_assert(this->plt_ != NULL);
270 // Get the dynamic reloc section, creating it if necessary.
272 rela_dyn_section(Layout*);
274 // Return true if the symbol may need a COPY relocation.
275 // References from an executable object to non-function symbols
276 // defined in a dynamic object may need a COPY relocation.
278 may_need_copy_reloc(Symbol* gsym)
280 return (!parameters->options().shared()
281 && gsym->is_from_dynobj()
282 && gsym->type() != elfcpp::STT_FUNC);
285 // Copy a relocation against a global symbol.
287 copy_reloc(Symbol_table* symtab, Layout* layout, Relobj* object,
288 unsigned int shndx, Output_section* output_section,
289 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
291 this->copy_relocs_.copy_reloc(symtab, layout,
292 symtab->get_sized_symbol<size>(sym),
293 object, shndx, output_section,
294 reloc, this->rela_dyn_section(layout));
297 // Information about this specific target which we pass to the
298 // general Target structure.
299 static Target::Target_info sparc_info;
301 // The types of GOT entries needed for this platform.
304 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
305 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
306 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
310 Output_data_got<size, big_endian>* got_;
312 Output_data_plt_sparc<size, big_endian>* plt_;
313 // The dynamic reloc section.
314 Reloc_section* rela_dyn_;
315 // Relocs saved to avoid a COPY reloc.
316 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
317 // Space for variables copied with a COPY reloc.
318 Output_data_space* dynbss_;
319 // Offset of the GOT entry for the TLS module index;
320 unsigned int got_mod_index_offset_;
321 // Cached pointer to __tls_get_addr symbol
322 Symbol* tls_get_addr_sym_;
326 Target::Target_info Target_sparc<32, true>::sparc_info =
329 true, // is_big_endian
330 elfcpp::EM_SPARC, // machine_code
331 false, // has_make_symbol
332 false, // has_resolve
333 false, // has_code_fill
334 true, // is_default_stack_executable
336 "/usr/lib/ld.so.1", // dynamic_linker
337 0x00010000, // default_text_segment_address
338 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
339 8 * 1024 // common_pagesize (overridable by -z common-page-size)
343 Target::Target_info Target_sparc<64, true>::sparc_info =
346 true, // is_big_endian
347 elfcpp::EM_SPARCV9, // machine_code
348 false, // has_make_symbol
349 false, // has_resolve
350 false, // has_code_fill
351 true, // is_default_stack_executable
353 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
354 0x100000, // default_text_segment_address
355 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
356 8 * 1024 // common_pagesize (overridable by -z common-page-size)
359 // We have to take care here, even when operating in little-endian
360 // mode, sparc instructions are still big endian.
361 template<int size, bool big_endian>
362 class Sparc_relocate_functions
365 // Do a simple relocation with the addend in the relocation.
366 template<int valsize>
368 rela(unsigned char* view,
369 unsigned int right_shift,
370 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
371 typename elfcpp::Swap<size, big_endian>::Valtype value,
372 typename elfcpp::Swap<size, big_endian>::Valtype addend)
374 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
375 Valtype* wv = reinterpret_cast<Valtype*>(view);
376 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
377 Valtype reloc = ((value + addend) >> right_shift);
382 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
385 // Do a simple relocation using a symbol value with the addend in
387 template<int valsize>
389 rela(unsigned char* view,
390 unsigned int right_shift,
391 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
392 const Sized_relobj<size, big_endian>* object,
393 const Symbol_value<size>* psymval,
394 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
396 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
397 Valtype* wv = reinterpret_cast<Valtype*>(view);
398 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
399 Valtype reloc = (psymval->value(object, addend) >> right_shift);
404 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
407 // Do a simple relocation using a symbol value with the addend in
408 // the relocation, unaligned.
409 template<int valsize>
411 rela_ua(unsigned char* view,
412 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
413 const Sized_relobj<size, big_endian>* object,
414 const Symbol_value<size>* psymval,
415 typename elfcpp::Swap<size, big_endian>::Valtype addend)
417 typedef typename elfcpp::Swap_unaligned<valsize,
418 big_endian>::Valtype Valtype;
419 unsigned char* wv = view;
420 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
421 Valtype reloc = (psymval->value(object, addend) >> right_shift);
426 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
429 // Do a simple PC relative relocation with a Symbol_value with the
430 // addend in the relocation.
431 template<int valsize>
433 pcrela(unsigned char* view,
434 unsigned int right_shift,
435 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
436 const Sized_relobj<size, big_endian>* object,
437 const Symbol_value<size>* psymval,
438 typename elfcpp::Swap<size, big_endian>::Valtype addend,
439 typename elfcpp::Elf_types<size>::Elf_Addr address)
441 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
442 Valtype* wv = reinterpret_cast<Valtype*>(view);
443 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
444 Valtype reloc = ((psymval->value(object, addend) - address)
450 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
453 template<int valsize>
455 pcrela_unaligned(unsigned char* view,
456 const Sized_relobj<size, big_endian>* object,
457 const Symbol_value<size>* psymval,
458 typename elfcpp::Swap<size, big_endian>::Valtype addend,
459 typename elfcpp::Elf_types<size>::Elf_Addr address)
461 typedef typename elfcpp::Swap_unaligned<valsize,
462 big_endian>::Valtype Valtype;
463 unsigned char* wv = view;
464 Valtype reloc = (psymval->value(object, addend) - address);
466 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
469 typedef Sparc_relocate_functions<size, big_endian> This;
470 typedef Sparc_relocate_functions<size, true> This_insn;
473 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
475 wdisp30(unsigned char* view,
476 const Sized_relobj<size, big_endian>* object,
477 const Symbol_value<size>* psymval,
478 typename elfcpp::Elf_types<size>::Elf_Addr addend,
479 typename elfcpp::Elf_types<size>::Elf_Addr address)
481 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
482 psymval, addend, address);
485 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
487 wdisp22(unsigned char* view,
488 const Sized_relobj<size, big_endian>* object,
489 const Symbol_value<size>* psymval,
490 typename elfcpp::Elf_types<size>::Elf_Addr addend,
491 typename elfcpp::Elf_types<size>::Elf_Addr address)
493 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
494 psymval, addend, address);
497 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
499 wdisp19(unsigned char* view,
500 const Sized_relobj<size, big_endian>* object,
501 const Symbol_value<size>* psymval,
502 typename elfcpp::Elf_types<size>::Elf_Addr addend,
503 typename elfcpp::Elf_types<size>::Elf_Addr address)
505 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
506 psymval, addend, address);
509 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
511 wdisp16(unsigned char* view,
512 const Sized_relobj<size, big_endian>* object,
513 const Symbol_value<size>* psymval,
514 typename elfcpp::Elf_types<size>::Elf_Addr addend,
515 typename elfcpp::Elf_types<size>::Elf_Addr address)
517 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
518 Valtype* wv = reinterpret_cast<Valtype*>(view);
519 Valtype val = elfcpp::Swap<32, true>::readval(wv);
520 Valtype reloc = ((psymval->value(object, addend) - address)
523 // The relocation value is split between the low 14 bits,
525 val &= ~((0x3 << 20) | 0x3fff);
526 reloc = (((reloc & 0xc000) << (20 - 14))
527 | (reloc & 0x3ffff));
529 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
532 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
534 pc22(unsigned char* view,
535 const Sized_relobj<size, big_endian>* object,
536 const Symbol_value<size>* psymval,
537 typename elfcpp::Elf_types<size>::Elf_Addr addend,
538 typename elfcpp::Elf_types<size>::Elf_Addr address)
540 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
541 psymval, addend, address);
544 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
546 pc10(unsigned char* view,
547 const Sized_relobj<size, big_endian>* object,
548 const Symbol_value<size>* psymval,
549 typename elfcpp::Elf_types<size>::Elf_Addr addend,
550 typename elfcpp::Elf_types<size>::Elf_Addr address)
552 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
553 psymval, addend, address);
556 // R_SPARC_HI22: (Symbol + Addend) >> 10
558 hi22(unsigned char* view,
559 typename elfcpp::Elf_types<size>::Elf_Addr value,
560 typename elfcpp::Elf_types<size>::Elf_Addr addend)
562 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
565 // R_SPARC_HI22: (Symbol + Addend) >> 10
567 hi22(unsigned char* view,
568 const Sized_relobj<size, big_endian>* object,
569 const Symbol_value<size>* psymval,
570 typename elfcpp::Elf_types<size>::Elf_Addr addend)
572 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
575 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
577 pcplt22(unsigned char* view,
578 const Sized_relobj<size, big_endian>* object,
579 const Symbol_value<size>* psymval,
580 typename elfcpp::Elf_types<size>::Elf_Addr addend,
581 typename elfcpp::Elf_types<size>::Elf_Addr address)
583 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
584 psymval, addend, address);
587 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
589 lo10(unsigned char* view,
590 typename elfcpp::Elf_types<size>::Elf_Addr value,
591 typename elfcpp::Elf_types<size>::Elf_Addr addend)
593 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
596 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
598 lo10(unsigned char* view,
599 const Sized_relobj<size, big_endian>* object,
600 const Symbol_value<size>* psymval,
601 typename elfcpp::Elf_types<size>::Elf_Addr addend)
603 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
606 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
608 lo10(unsigned char* view,
609 const Sized_relobj<size, big_endian>* object,
610 const Symbol_value<size>* psymval,
611 typename elfcpp::Elf_types<size>::Elf_Addr addend,
612 typename elfcpp::Elf_types<size>::Elf_Addr address)
614 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
615 psymval, addend, address);
618 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
620 olo10(unsigned char* view,
621 const Sized_relobj<size, big_endian>* object,
622 const Symbol_value<size>* psymval,
623 typename elfcpp::Elf_types<size>::Elf_Addr addend,
624 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
626 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
627 Valtype* wv = reinterpret_cast<Valtype*>(view);
628 Valtype val = elfcpp::Swap<32, true>::readval(wv);
629 Valtype reloc = psymval->value(object, addend);
636 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
639 // R_SPARC_22: (Symbol + Addend)
641 rela32_22(unsigned char* view,
642 const Sized_relobj<size, big_endian>* object,
643 const Symbol_value<size>* psymval,
644 typename elfcpp::Elf_types<size>::Elf_Addr addend)
646 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
649 // R_SPARC_13: (Symbol + Addend)
651 rela32_13(unsigned char* view,
652 typename elfcpp::Elf_types<size>::Elf_Addr value,
653 typename elfcpp::Elf_types<size>::Elf_Addr addend)
655 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
658 // R_SPARC_13: (Symbol + Addend)
660 rela32_13(unsigned char* view,
661 const Sized_relobj<size, big_endian>* object,
662 const Symbol_value<size>* psymval,
663 typename elfcpp::Elf_types<size>::Elf_Addr addend)
665 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
668 // R_SPARC_UA16: (Symbol + Addend)
670 ua16(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::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
678 // R_SPARC_UA32: (Symbol + Addend)
680 ua32(unsigned char* view,
681 const Sized_relobj<size, big_endian>* object,
682 const Symbol_value<size>* psymval,
683 typename elfcpp::Elf_types<size>::Elf_Addr addend)
685 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
688 // R_SPARC_UA64: (Symbol + Addend)
690 ua64(unsigned char* view,
691 const Sized_relobj<size, big_endian>* object,
692 const Symbol_value<size>* psymval,
693 typename elfcpp::Elf_types<size>::Elf_Addr addend)
695 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
696 object, psymval, addend);
699 // R_SPARC_DISP8: (Symbol + Addend - Address)
701 disp8(unsigned char* view,
702 const Sized_relobj<size, big_endian>* object,
703 const Symbol_value<size>* psymval,
704 typename elfcpp::Elf_types<size>::Elf_Addr addend,
705 typename elfcpp::Elf_types<size>::Elf_Addr address)
707 This::template pcrela_unaligned<8>(view, object, psymval,
711 // R_SPARC_DISP16: (Symbol + Addend - Address)
713 disp16(unsigned char* view,
714 const Sized_relobj<size, big_endian>* object,
715 const Symbol_value<size>* psymval,
716 typename elfcpp::Elf_types<size>::Elf_Addr addend,
717 typename elfcpp::Elf_types<size>::Elf_Addr address)
719 This::template pcrela_unaligned<16>(view, object, psymval,
723 // R_SPARC_DISP32: (Symbol + Addend - Address)
725 disp32(unsigned char* view,
726 const Sized_relobj<size, big_endian>* object,
727 const Symbol_value<size>* psymval,
728 typename elfcpp::Elf_types<size>::Elf_Addr addend,
729 typename elfcpp::Elf_types<size>::Elf_Addr address)
731 This::template pcrela_unaligned<32>(view, object, psymval,
735 // R_SPARC_DISP64: (Symbol + Addend - Address)
737 disp64(unsigned char* view,
738 const Sized_relobj<size, big_endian>* object,
739 const Symbol_value<size>* psymval,
740 elfcpp::Elf_Xword addend,
741 typename elfcpp::Elf_types<size>::Elf_Addr address)
743 This::template pcrela_unaligned<64>(view, object, psymval,
747 // R_SPARC_H44: (Symbol + Addend) >> 22
749 h44(unsigned char* view,
750 const Sized_relobj<size, big_endian>* object,
751 const Symbol_value<size>* psymval,
752 typename elfcpp::Elf_types<size>::Elf_Addr addend)
754 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
757 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
759 m44(unsigned char* view,
760 const Sized_relobj<size, big_endian>* object,
761 const Symbol_value<size>* psymval,
762 typename elfcpp::Elf_types<size>::Elf_Addr addend)
764 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
767 // R_SPARC_L44: (Symbol + Addend) & 0xfff
769 l44(unsigned char* view,
770 const Sized_relobj<size, big_endian>* object,
771 const Symbol_value<size>* psymval,
772 typename elfcpp::Elf_types<size>::Elf_Addr addend)
774 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
777 // R_SPARC_HH22: (Symbol + Addend) >> 42
779 hh22(unsigned char* view,
780 const Sized_relobj<size, big_endian>* object,
781 const Symbol_value<size>* psymval,
782 typename elfcpp::Elf_types<size>::Elf_Addr addend)
784 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
787 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
789 pc_hh22(unsigned char* view,
790 const Sized_relobj<size, big_endian>* object,
791 const Symbol_value<size>* psymval,
792 typename elfcpp::Elf_types<size>::Elf_Addr addend,
793 typename elfcpp::Elf_types<size>::Elf_Addr address)
795 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
796 psymval, addend, address);
799 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
801 hm10(unsigned char* view,
802 const Sized_relobj<size, big_endian>* object,
803 const Symbol_value<size>* psymval,
804 typename elfcpp::Elf_types<size>::Elf_Addr addend)
806 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
809 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
811 pc_hm10(unsigned char* view,
812 const Sized_relobj<size, big_endian>* object,
813 const Symbol_value<size>* psymval,
814 typename elfcpp::Elf_types<size>::Elf_Addr addend,
815 typename elfcpp::Elf_types<size>::Elf_Addr address)
817 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
818 psymval, addend, address);
821 // R_SPARC_11: (Symbol + Addend)
823 rela32_11(unsigned char* view,
824 const Sized_relobj<size, big_endian>* object,
825 const Symbol_value<size>* psymval,
826 typename elfcpp::Elf_types<size>::Elf_Addr addend)
828 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
831 // R_SPARC_10: (Symbol + Addend)
833 rela32_10(unsigned char* view,
834 const Sized_relobj<size, big_endian>* object,
835 const Symbol_value<size>* psymval,
836 typename elfcpp::Elf_types<size>::Elf_Addr addend)
838 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
841 // R_SPARC_7: (Symbol + Addend)
843 rela32_7(unsigned char* view,
844 const Sized_relobj<size, big_endian>* object,
845 const Symbol_value<size>* psymval,
846 typename elfcpp::Elf_types<size>::Elf_Addr addend)
848 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
851 // R_SPARC_6: (Symbol + Addend)
853 rela32_6(unsigned char* view,
854 const Sized_relobj<size, big_endian>* object,
855 const Symbol_value<size>* psymval,
856 typename elfcpp::Elf_types<size>::Elf_Addr addend)
858 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
861 // R_SPARC_5: (Symbol + Addend)
863 rela32_5(unsigned char* view,
864 const Sized_relobj<size, big_endian>* object,
865 const Symbol_value<size>* psymval,
866 typename elfcpp::Elf_types<size>::Elf_Addr addend)
868 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
871 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
873 ldo_hix22(unsigned char* view,
874 typename elfcpp::Elf_types<size>::Elf_Addr value,
875 typename elfcpp::Elf_types<size>::Elf_Addr addend)
877 This_insn::hi22(view, value, addend);
880 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
882 ldo_lox10(unsigned char* view,
883 typename elfcpp::Elf_types<size>::Elf_Addr value,
884 typename elfcpp::Elf_types<size>::Elf_Addr addend)
886 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
887 Valtype* wv = reinterpret_cast<Valtype*>(view);
888 Valtype val = elfcpp::Swap<32, true>::readval(wv);
889 Valtype reloc = (value + addend);
894 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
897 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
899 hix22(unsigned char* view,
900 typename elfcpp::Elf_types<size>::Elf_Addr value,
901 typename elfcpp::Elf_types<size>::Elf_Addr addend)
903 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
904 Valtype* wv = reinterpret_cast<Valtype*>(view);
905 Valtype val = elfcpp::Swap<32, true>::readval(wv);
906 Valtype reloc = (value + addend);
910 reloc ^= ~(Valtype)0;
915 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
918 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
920 hix22(unsigned char* view,
921 const Sized_relobj<size, big_endian>* object,
922 const Symbol_value<size>* psymval,
923 typename elfcpp::Elf_types<size>::Elf_Addr addend)
925 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
926 Valtype* wv = reinterpret_cast<Valtype*>(view);
927 Valtype val = elfcpp::Swap<32, true>::readval(wv);
928 Valtype reloc = psymval->value(object, addend);
932 reloc ^= ~(Valtype)0;
937 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
941 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
943 lox10(unsigned char* view,
944 typename elfcpp::Elf_types<size>::Elf_Addr value,
945 typename elfcpp::Elf_types<size>::Elf_Addr addend)
947 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
948 Valtype* wv = reinterpret_cast<Valtype*>(view);
949 Valtype val = elfcpp::Swap<32, true>::readval(wv);
950 Valtype reloc = (value + addend);
956 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
959 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
961 lox10(unsigned char* view,
962 const Sized_relobj<size, big_endian>* object,
963 const Symbol_value<size>* psymval,
964 typename elfcpp::Elf_types<size>::Elf_Addr addend)
966 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
967 Valtype* wv = reinterpret_cast<Valtype*>(view);
968 Valtype val = elfcpp::Swap<32, true>::readval(wv);
969 Valtype reloc = psymval->value(object, addend);
975 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
979 // Get the GOT section, creating it if necessary.
981 template<int size, bool big_endian>
982 Output_data_got<size, big_endian>*
983 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
986 if (this->got_ == NULL)
988 gold_assert(symtab != NULL && layout != NULL);
990 this->got_ = new Output_data_got<size, big_endian>();
992 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
993 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
996 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
997 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
999 0, 0, elfcpp::STT_OBJECT,
1001 elfcpp::STV_HIDDEN, 0,
1008 // Get the dynamic reloc section, creating it if necessary.
1010 template<int size, bool big_endian>
1011 typename Target_sparc<size, big_endian>::Reloc_section*
1012 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1014 if (this->rela_dyn_ == NULL)
1016 gold_assert(layout != NULL);
1017 this->rela_dyn_ = new Reloc_section();
1018 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1019 elfcpp::SHF_ALLOC, this->rela_dyn_);
1021 return this->rela_dyn_;
1024 // A class to handle the PLT data.
1026 template<int size, bool big_endian>
1027 class Output_data_plt_sparc : public Output_section_data
1030 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1031 size, big_endian> Reloc_section;
1033 Output_data_plt_sparc(Layout*);
1035 // Add an entry to the PLT.
1036 void add_entry(Symbol* gsym);
1038 // Return the .rela.plt section data.
1039 const Reloc_section* rel_plt() const
1045 void do_adjust_output_section(Output_section* os);
1048 // The size of an entry in the PLT.
1049 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1051 static const unsigned int plt_entries_per_block = 160;
1052 static const unsigned int plt_insn_chunk_size = 24;
1053 static const unsigned int plt_pointer_chunk_size = 8;
1054 static const unsigned int plt_block_size =
1055 (plt_entries_per_block
1056 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1058 // Set the final size.
1060 set_final_data_size()
1062 unsigned int full_count = this->count_ + 4;
1063 unsigned int extra = (size == 32 ? 4 : 0);
1065 if (size == 32 || full_count < 32768)
1066 this->set_data_size((full_count * base_plt_entry_size) + extra);
1069 unsigned int ext_cnt = full_count - 32768;
1071 this->set_data_size((32768 * base_plt_entry_size)
1073 * (plt_insn_chunk_size
1074 + plt_pointer_chunk_size)));
1078 // Write out the PLT data.
1080 do_write(Output_file*);
1082 // The reloc section.
1083 Reloc_section* rel_;
1084 // The number of PLT entries.
1085 unsigned int count_;
1088 // Define the constants as required by C++ standard.
1090 template<int size, bool big_endian>
1091 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1093 template<int size, bool big_endian>
1095 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1097 template<int size, bool big_endian>
1098 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1100 template<int size, bool big_endian>
1102 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1104 template<int size, bool big_endian>
1105 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1107 // Create the PLT section. The ordinary .got section is an argument,
1108 // since we need to refer to the start.
1110 template<int size, bool big_endian>
1111 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1112 : Output_section_data(size == 32 ? 4 : 8), count_(0)
1114 this->rel_ = new Reloc_section();
1115 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1116 elfcpp::SHF_ALLOC, this->rel_);
1119 template<int size, bool big_endian>
1121 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1126 // Add an entry to the PLT.
1128 template<int size, bool big_endian>
1130 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol* gsym)
1132 gold_assert(!gsym->has_plt_offset());
1134 unsigned int index = this->count_ + 4;
1135 section_offset_type plt_offset;
1137 if (size == 32 || index < 32768)
1138 plt_offset = index * base_plt_entry_size;
1141 unsigned int ext_index = index - 32768;
1143 plt_offset = (32768 * base_plt_entry_size)
1144 + ((ext_index / plt_entries_per_block)
1146 + ((ext_index % plt_entries_per_block)
1147 * plt_insn_chunk_size);
1150 gsym->set_plt_offset(plt_offset);
1154 // Every PLT entry needs a reloc.
1155 gsym->set_needs_dynsym_entry();
1156 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1159 // Note that we don't need to save the symbol. The contents of the
1160 // PLT are independent of which symbols are used. The symbols only
1161 // appear in the relocations.
1164 static const unsigned int sparc_nop = 0x01000000;
1165 static const unsigned int sparc_sethi_g1 = 0x03000000;
1166 static const unsigned int sparc_branch_always = 0x30800000;
1167 static const unsigned int sparc_branch_always_pt = 0x30680000;
1168 static const unsigned int sparc_mov = 0x80100000;
1169 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1170 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1171 static const unsigned int sparc_call_plus_8 = 0x40000002;
1172 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1173 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1174 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1176 // Write out the PLT.
1178 template<int size, bool big_endian>
1180 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1182 const off_t offset = this->offset();
1183 const section_size_type oview_size =
1184 convert_to_section_size_type(this->data_size());
1185 unsigned char* const oview = of->get_output_view(offset, oview_size);
1186 unsigned char* pov = oview;
1188 memset(pov, 0, base_plt_entry_size * 4);
1189 pov += base_plt_entry_size * 4;
1191 unsigned int plt_offset = base_plt_entry_size * 4;
1192 const unsigned int count = this->count_;
1198 limit = (count > 32768 ? 32768 : count);
1200 for (unsigned int i = 0; i < limit; ++i)
1202 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1203 sparc_sethi_g1 + plt_offset);
1204 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1205 sparc_branch_always_pt +
1206 (((base_plt_entry_size -
1207 (plt_offset + 4)) >> 2) &
1209 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1210 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1211 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1212 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1213 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1214 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1216 pov += base_plt_entry_size;
1217 plt_offset += base_plt_entry_size;
1222 unsigned int ext_cnt = count - 32768;
1223 unsigned int blks = ext_cnt / plt_entries_per_block;
1225 for (unsigned int i = 0; i < blks; ++i)
1227 unsigned int data_off = (plt_entries_per_block
1228 * plt_insn_chunk_size) - 4;
1230 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1232 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1234 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1236 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1238 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1239 sparc_ldx_o7_imm_g1 +
1240 (data_off & 0x1fff));
1241 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1242 sparc_jmpl_o7_g1_g1);
1243 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1246 elfcpp::Swap<64, big_endian>::writeval(
1247 pov + 0x4 + data_off,
1248 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1250 pov += plt_insn_chunk_size;
1255 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1256 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1258 unsigned int data_off = (sub_blk_cnt
1259 * plt_insn_chunk_size) - 4;
1261 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1263 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1265 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1267 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1269 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1270 sparc_ldx_o7_imm_g1 +
1271 (data_off & 0x1fff));
1272 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1273 sparc_jmpl_o7_g1_g1);
1274 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1277 elfcpp::Swap<64, big_endian>::writeval(
1278 pov + 0x4 + data_off,
1279 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1281 pov += plt_insn_chunk_size;
1289 for (unsigned int i = 0; i < count; ++i)
1291 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1292 sparc_sethi_g1 + plt_offset);
1293 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1294 sparc_branch_always +
1295 (((- (plt_offset + 4)) >> 2) &
1297 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1299 pov += base_plt_entry_size;
1300 plt_offset += base_plt_entry_size;
1303 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1307 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1309 of->write_output_view(offset, oview_size, oview);
1312 // Create a PLT entry for a global symbol.
1314 template<int size, bool big_endian>
1316 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1320 if (gsym->has_plt_offset())
1323 if (this->plt_ == NULL)
1325 // Create the GOT sections first.
1326 this->got_section(symtab, layout);
1328 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1329 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1331 | elfcpp::SHF_EXECINSTR
1332 | elfcpp::SHF_WRITE),
1335 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1336 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1338 0, 0, elfcpp::STT_OBJECT,
1340 elfcpp::STV_HIDDEN, 0,
1344 this->plt_->add_entry(gsym);
1347 // Create a GOT entry for the TLS module index.
1349 template<int size, bool big_endian>
1351 Target_sparc<size, big_endian>::got_mod_index_entry(Symbol_table* symtab,
1353 Sized_relobj<size, big_endian>* object)
1355 if (this->got_mod_index_offset_ == -1U)
1357 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1358 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1359 Output_data_got<size, big_endian>* got;
1360 unsigned int got_offset;
1362 got = this->got_section(symtab, layout);
1363 got_offset = got->add_constant(0);
1364 rela_dyn->add_local(object, 0,
1366 elfcpp::R_SPARC_TLS_DTPMOD64 :
1367 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1369 got->add_constant(0);
1370 this->got_mod_index_offset_ = got_offset;
1372 return this->got_mod_index_offset_;
1375 // Optimize the TLS relocation type based on what we know about the
1376 // symbol. IS_FINAL is true if the final address of this symbol is
1377 // known at link time.
1379 static tls::Tls_optimization
1380 optimize_tls_reloc(bool is_final, int r_type)
1382 // If we are generating a shared library, then we can't do anything
1384 if (parameters->options().shared())
1385 return tls::TLSOPT_NONE;
1389 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1390 case elfcpp::R_SPARC_TLS_GD_LO10:
1391 case elfcpp::R_SPARC_TLS_GD_ADD:
1392 case elfcpp::R_SPARC_TLS_GD_CALL:
1393 // These are General-Dynamic which permits fully general TLS
1394 // access. Since we know that we are generating an executable,
1395 // we can convert this to Initial-Exec. If we also know that
1396 // this is a local symbol, we can further switch to Local-Exec.
1398 return tls::TLSOPT_TO_LE;
1399 return tls::TLSOPT_TO_IE;
1401 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1402 case elfcpp::R_SPARC_TLS_LDM_LO10:
1403 case elfcpp::R_SPARC_TLS_LDM_ADD:
1404 case elfcpp::R_SPARC_TLS_LDM_CALL:
1405 // This is Local-Dynamic, which refers to a local symbol in the
1406 // dynamic TLS block. Since we know that we generating an
1407 // executable, we can switch to Local-Exec.
1408 return tls::TLSOPT_TO_LE;
1410 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1411 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1412 case elfcpp::R_SPARC_TLS_LDO_ADD:
1413 // Another type of Local-Dynamic relocation.
1414 return tls::TLSOPT_TO_LE;
1416 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1417 case elfcpp::R_SPARC_TLS_IE_LO10:
1418 case elfcpp::R_SPARC_TLS_IE_LD:
1419 case elfcpp::R_SPARC_TLS_IE_LDX:
1420 // These are Initial-Exec relocs which get the thread offset
1421 // from the GOT. If we know that we are linking against the
1422 // local symbol, we can switch to Local-Exec, which links the
1423 // thread offset into the instruction.
1425 return tls::TLSOPT_TO_LE;
1426 return tls::TLSOPT_NONE;
1428 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1429 case elfcpp::R_SPARC_TLS_LE_LOX10:
1430 // When we already have Local-Exec, there is nothing further we
1432 return tls::TLSOPT_NONE;
1439 // Generate a PLT entry slot for a call to __tls_get_addr
1440 template<int size, bool big_endian>
1442 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
1444 Target_sparc<size, big_endian>* target)
1446 Symbol* gsym = target->tls_get_addr_sym(symtab);
1448 target->make_plt_entry(symtab, layout, gsym);
1451 // Report an unsupported relocation against a local symbol.
1453 template<int size, bool big_endian>
1455 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
1456 Sized_relobj<size, big_endian>* object,
1457 unsigned int r_type)
1459 gold_error(_("%s: unsupported reloc %u against local symbol"),
1460 object->name().c_str(), r_type);
1463 // Scan a relocation for a local symbol.
1465 template<int size, bool big_endian>
1467 Target_sparc<size, big_endian>::Scan::local(
1468 const General_options&,
1469 Symbol_table* symtab,
1471 Target_sparc<size, big_endian>* target,
1472 Sized_relobj<size, big_endian>* object,
1473 unsigned int data_shndx,
1474 Output_section* output_section,
1475 const elfcpp::Rela<size, big_endian>& reloc,
1476 unsigned int r_type,
1477 const elfcpp::Sym<size, big_endian>& lsym)
1479 unsigned int orig_r_type = r_type;
1484 case elfcpp::R_SPARC_NONE:
1485 case elfcpp::R_SPARC_REGISTER:
1486 case elfcpp::R_SPARC_GNU_VTINHERIT:
1487 case elfcpp::R_SPARC_GNU_VTENTRY:
1490 case elfcpp::R_SPARC_64:
1491 case elfcpp::R_SPARC_32:
1492 // If building a shared library (or a position-independent
1493 // executable), we need to create a dynamic relocation for
1494 // this location. The relocation applied at link time will
1495 // apply the link-time value, so we flag the location with
1496 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1497 // relocate it easily.
1498 if (parameters->options().output_is_position_independent())
1500 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1501 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1502 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
1503 output_section, data_shndx,
1504 reloc.get_r_offset(),
1505 reloc.get_r_addend());
1509 case elfcpp::R_SPARC_HIX22:
1510 case elfcpp::R_SPARC_LOX10:
1511 case elfcpp::R_SPARC_H44:
1512 case elfcpp::R_SPARC_M44:
1513 case elfcpp::R_SPARC_L44:
1514 case elfcpp::R_SPARC_HH22:
1515 case elfcpp::R_SPARC_HM10:
1516 case elfcpp::R_SPARC_LM22:
1517 case elfcpp::R_SPARC_UA64:
1518 case elfcpp::R_SPARC_UA32:
1519 case elfcpp::R_SPARC_UA16:
1520 case elfcpp::R_SPARC_HI22:
1521 case elfcpp::R_SPARC_LO10:
1522 case elfcpp::R_SPARC_OLO10:
1523 case elfcpp::R_SPARC_16:
1524 case elfcpp::R_SPARC_11:
1525 case elfcpp::R_SPARC_10:
1526 case elfcpp::R_SPARC_8:
1527 case elfcpp::R_SPARC_7:
1528 case elfcpp::R_SPARC_6:
1529 case elfcpp::R_SPARC_5:
1530 // If building a shared library (or a position-independent
1531 // executable), we need to create a dynamic relocation for
1533 if (parameters->options().output_is_position_independent())
1535 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1536 if (lsym.get_st_type() != elfcpp::STT_SECTION)
1538 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1539 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
1540 data_shndx, reloc.get_r_offset(),
1541 reloc.get_r_addend());
1545 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1546 gold_assert(lsym.get_st_value() == 0);
1547 rela_dyn->add_local_relative(object, r_sym, orig_r_type,
1548 output_section, data_shndx,
1549 reloc.get_r_offset(),
1550 reloc.get_r_addend());
1555 case elfcpp::R_SPARC_WDISP30:
1556 case elfcpp::R_SPARC_WDISP22:
1557 case elfcpp::R_SPARC_WDISP19:
1558 case elfcpp::R_SPARC_WDISP16:
1559 case elfcpp::R_SPARC_DISP8:
1560 case elfcpp::R_SPARC_DISP16:
1561 case elfcpp::R_SPARC_DISP32:
1562 case elfcpp::R_SPARC_DISP64:
1563 case elfcpp::R_SPARC_PC10:
1564 case elfcpp::R_SPARC_PC22:
1567 case elfcpp::R_SPARC_GOT10:
1568 case elfcpp::R_SPARC_GOT13:
1569 case elfcpp::R_SPARC_GOT22:
1571 // The symbol requires a GOT entry.
1572 Output_data_got<size, big_endian>* got;
1575 got = target->got_section(symtab, layout);
1576 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1578 // If we are generating a shared object, we need to add a
1579 // dynamic relocation for this symbol's GOT entry.
1580 if (parameters->options().output_is_position_independent())
1582 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
1584 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1587 off = got->add_constant(0);
1588 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
1589 rela_dyn->add_local_relative(object, r_sym,
1590 elfcpp::R_SPARC_RELATIVE,
1595 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
1599 // These are initial TLS relocs, which are expected when
1601 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1602 case elfcpp::R_SPARC_TLS_GD_LO10:
1603 case elfcpp::R_SPARC_TLS_GD_ADD:
1604 case elfcpp::R_SPARC_TLS_GD_CALL:
1605 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
1606 case elfcpp::R_SPARC_TLS_LDM_LO10:
1607 case elfcpp::R_SPARC_TLS_LDM_ADD:
1608 case elfcpp::R_SPARC_TLS_LDM_CALL:
1609 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1610 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1611 case elfcpp::R_SPARC_TLS_LDO_ADD:
1612 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1613 case elfcpp::R_SPARC_TLS_IE_LO10:
1614 case elfcpp::R_SPARC_TLS_IE_LD:
1615 case elfcpp::R_SPARC_TLS_IE_LDX:
1616 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1617 case elfcpp::R_SPARC_TLS_LE_LOX10:
1619 bool output_is_shared = parameters->options().shared();
1620 const tls::Tls_optimization optimized_type
1621 = optimize_tls_reloc(!output_is_shared, r_type);
1624 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1625 case elfcpp::R_SPARC_TLS_GD_LO10:
1626 case elfcpp::R_SPARC_TLS_GD_ADD:
1627 case elfcpp::R_SPARC_TLS_GD_CALL:
1628 if (optimized_type == tls::TLSOPT_NONE)
1630 // Create a pair of GOT entries for the module index and
1631 // dtv-relative offset.
1632 Output_data_got<size, big_endian>* got
1633 = target->got_section(symtab, layout);
1634 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1635 got->add_local_pair_with_rela(object, r_sym,
1636 lsym.get_st_shndx(),
1638 target->rela_dyn_section(layout),
1640 elfcpp::R_SPARC_TLS_DTPMOD64 :
1641 elfcpp::R_SPARC_TLS_DTPMOD32), 0);
1642 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
1643 generate_tls_call(symtab, layout, target);
1645 else if (optimized_type != tls::TLSOPT_TO_LE)
1646 unsupported_reloc_local(object, r_type);
1649 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
1650 case elfcpp::R_SPARC_TLS_LDM_LO10:
1651 case elfcpp::R_SPARC_TLS_LDM_ADD:
1652 case elfcpp::R_SPARC_TLS_LDM_CALL:
1653 if (optimized_type == tls::TLSOPT_NONE)
1655 // Create a GOT entry for the module index.
1656 target->got_mod_index_entry(symtab, layout, object);
1658 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
1659 generate_tls_call(symtab, layout, target);
1661 else if (optimized_type != tls::TLSOPT_TO_LE)
1662 unsupported_reloc_local(object, r_type);
1665 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1666 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1667 case elfcpp::R_SPARC_TLS_LDO_ADD:
1670 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1671 case elfcpp::R_SPARC_TLS_IE_LO10:
1672 case elfcpp::R_SPARC_TLS_IE_LD:
1673 case elfcpp::R_SPARC_TLS_IE_LDX:
1674 layout->set_has_static_tls();
1675 if (optimized_type == tls::TLSOPT_NONE)
1677 // Create a GOT entry for the tp-relative offset.
1678 Output_data_got<size, big_endian>* got
1679 = target->got_section(symtab, layout);
1680 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1682 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
1684 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1685 unsigned int off = got->add_constant(0);
1687 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET,
1689 rela_dyn->add_local_relative(object, r_sym,
1691 elfcpp::R_SPARC_TLS_TPOFF64 :
1692 elfcpp::R_SPARC_TLS_TPOFF32),
1696 else if (optimized_type != tls::TLSOPT_TO_LE)
1697 unsupported_reloc_local(object, r_type);
1700 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1701 case elfcpp::R_SPARC_TLS_LE_LOX10:
1702 layout->set_has_static_tls();
1703 if (output_is_shared)
1705 // We need to create a dynamic relocation.
1706 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
1707 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1708 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1709 rela_dyn->add_local_relative(object, r_sym, r_type,
1710 output_section, data_shndx,
1711 reloc.get_r_offset(), 0);
1718 // These are relocations which should only be seen by the
1719 // dynamic linker, and should never be seen here.
1720 case elfcpp::R_SPARC_COPY:
1721 case elfcpp::R_SPARC_GLOB_DAT:
1722 case elfcpp::R_SPARC_JMP_SLOT:
1723 case elfcpp::R_SPARC_RELATIVE:
1724 case elfcpp::R_SPARC_TLS_DTPMOD64:
1725 case elfcpp::R_SPARC_TLS_DTPMOD32:
1726 case elfcpp::R_SPARC_TLS_DTPOFF64:
1727 case elfcpp::R_SPARC_TLS_DTPOFF32:
1728 case elfcpp::R_SPARC_TLS_TPOFF64:
1729 case elfcpp::R_SPARC_TLS_TPOFF32:
1730 gold_error(_("%s: unexpected reloc %u in object file"),
1731 object->name().c_str(), r_type);
1735 unsupported_reloc_local(object, r_type);
1740 // Report an unsupported relocation against a global symbol.
1742 template<int size, bool big_endian>
1744 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
1745 Sized_relobj<size, big_endian>* object,
1746 unsigned int r_type,
1749 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1750 object->name().c_str(), r_type, gsym->demangled_name().c_str());
1753 // Scan a relocation for a global symbol.
1755 template<int size, bool big_endian>
1757 Target_sparc<size, big_endian>::Scan::global(
1758 const General_options&,
1759 Symbol_table* symtab,
1761 Target_sparc<size, big_endian>* target,
1762 Sized_relobj<size, big_endian>* object,
1763 unsigned int data_shndx,
1764 Output_section* output_section,
1765 const elfcpp::Rela<size, big_endian>& reloc,
1766 unsigned int r_type,
1769 unsigned int orig_r_type = r_type;
1774 case elfcpp::R_SPARC_NONE:
1775 case elfcpp::R_SPARC_REGISTER:
1776 case elfcpp::R_SPARC_GNU_VTINHERIT:
1777 case elfcpp::R_SPARC_GNU_VTENTRY:
1780 case elfcpp::R_SPARC_PLT64:
1781 case elfcpp::R_SPARC_PLT32:
1782 case elfcpp::R_SPARC_HIPLT22:
1783 case elfcpp::R_SPARC_LOPLT10:
1784 case elfcpp::R_SPARC_PCPLT32:
1785 case elfcpp::R_SPARC_PCPLT22:
1786 case elfcpp::R_SPARC_PCPLT10:
1787 case elfcpp::R_SPARC_WPLT30:
1788 // If the symbol is fully resolved, this is just a PC32 reloc.
1789 // Otherwise we need a PLT entry.
1790 if (gsym->final_value_is_known())
1792 // If building a shared library, we can also skip the PLT entry
1793 // if the symbol is defined in the output file and is protected
1795 if (gsym->is_defined()
1796 && !gsym->is_from_dynobj()
1797 && !gsym->is_preemptible())
1799 target->make_plt_entry(symtab, layout, gsym);
1802 case elfcpp::R_SPARC_DISP8:
1803 case elfcpp::R_SPARC_DISP16:
1804 case elfcpp::R_SPARC_DISP32:
1805 case elfcpp::R_SPARC_DISP64:
1806 case elfcpp::R_SPARC_PC_HH22:
1807 case elfcpp::R_SPARC_PC_HM10:
1808 case elfcpp::R_SPARC_PC_LM22:
1809 case elfcpp::R_SPARC_PC10:
1810 case elfcpp::R_SPARC_PC22:
1811 case elfcpp::R_SPARC_WDISP30:
1812 case elfcpp::R_SPARC_WDISP22:
1813 case elfcpp::R_SPARC_WDISP19:
1814 case elfcpp::R_SPARC_WDISP16:
1816 if (gsym->needs_plt_entry())
1817 target->make_plt_entry(symtab, layout, gsym);
1818 // Make a dynamic relocation if necessary.
1819 int flags = Symbol::NON_PIC_REF;
1820 if (gsym->type() == elfcpp::STT_FUNC)
1821 flags |= Symbol::FUNCTION_CALL;
1822 if (gsym->needs_dynamic_reloc(flags))
1824 if (target->may_need_copy_reloc(gsym))
1826 target->copy_reloc(symtab, layout, object,
1827 data_shndx, output_section, gsym,
1832 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1833 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
1834 data_shndx, reloc.get_r_offset(),
1835 reloc.get_r_addend());
1841 case elfcpp::R_SPARC_UA64:
1842 case elfcpp::R_SPARC_64:
1843 case elfcpp::R_SPARC_HIX22:
1844 case elfcpp::R_SPARC_LOX10:
1845 case elfcpp::R_SPARC_H44:
1846 case elfcpp::R_SPARC_M44:
1847 case elfcpp::R_SPARC_L44:
1848 case elfcpp::R_SPARC_HH22:
1849 case elfcpp::R_SPARC_HM10:
1850 case elfcpp::R_SPARC_LM22:
1851 case elfcpp::R_SPARC_HI22:
1852 case elfcpp::R_SPARC_LO10:
1853 case elfcpp::R_SPARC_OLO10:
1854 case elfcpp::R_SPARC_UA32:
1855 case elfcpp::R_SPARC_32:
1856 case elfcpp::R_SPARC_UA16:
1857 case elfcpp::R_SPARC_16:
1858 case elfcpp::R_SPARC_11:
1859 case elfcpp::R_SPARC_10:
1860 case elfcpp::R_SPARC_8:
1861 case elfcpp::R_SPARC_7:
1862 case elfcpp::R_SPARC_6:
1863 case elfcpp::R_SPARC_5:
1865 // Make a PLT entry if necessary.
1866 if (gsym->needs_plt_entry())
1868 target->make_plt_entry(symtab, layout, gsym);
1869 // Since this is not a PC-relative relocation, we may be
1870 // taking the address of a function. In that case we need to
1871 // set the entry in the dynamic symbol table to the address of
1873 if (gsym->is_from_dynobj() && !parameters->options().shared())
1874 gsym->set_needs_dynsym_value();
1876 // Make a dynamic relocation if necessary.
1877 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
1879 if (target->may_need_copy_reloc(gsym))
1881 target->copy_reloc(symtab, layout, object,
1882 data_shndx, output_section, gsym, reloc);
1884 else if ((r_type == elfcpp::R_SPARC_32
1885 || r_type == elfcpp::R_SPARC_64)
1886 && gsym->can_use_relative_reloc(false))
1888 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1889 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
1890 output_section, object,
1891 data_shndx, reloc.get_r_offset(),
1892 reloc.get_r_addend());
1896 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1898 if (gsym->is_from_dynobj()
1899 || gsym->is_undefined()
1900 || gsym->is_preemptible())
1901 rela_dyn->add_global(gsym, orig_r_type, output_section,
1903 reloc.get_r_offset(),
1904 reloc.get_r_addend());
1906 rela_dyn->add_global_relative(gsym, orig_r_type,
1907 output_section, object,
1909 reloc.get_r_offset(),
1910 reloc.get_r_addend());
1916 case elfcpp::R_SPARC_GOT10:
1917 case elfcpp::R_SPARC_GOT13:
1918 case elfcpp::R_SPARC_GOT22:
1920 // The symbol requires a GOT entry.
1921 Output_data_got<size, big_endian>* got;
1923 got = target->got_section(symtab, layout);
1924 if (gsym->final_value_is_known())
1925 got->add_global(gsym, GOT_TYPE_STANDARD);
1928 // If this symbol is not fully resolved, we need to add a
1929 // dynamic relocation for it.
1930 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1931 if (gsym->is_from_dynobj()
1932 || gsym->is_undefined()
1933 || gsym->is_preemptible())
1934 got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn,
1935 elfcpp::R_SPARC_GLOB_DAT);
1936 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
1938 unsigned int off = got->add_constant(0);
1940 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
1941 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
1948 // These are initial tls relocs, which are expected when
1950 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1951 case elfcpp::R_SPARC_TLS_GD_LO10:
1952 case elfcpp::R_SPARC_TLS_GD_ADD:
1953 case elfcpp::R_SPARC_TLS_GD_CALL:
1954 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1955 case elfcpp::R_SPARC_TLS_LDM_LO10:
1956 case elfcpp::R_SPARC_TLS_LDM_ADD:
1957 case elfcpp::R_SPARC_TLS_LDM_CALL:
1958 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1959 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1960 case elfcpp::R_SPARC_TLS_LDO_ADD:
1961 case elfcpp::R_SPARC_TLS_LE_HIX22:
1962 case elfcpp::R_SPARC_TLS_LE_LOX10:
1963 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1964 case elfcpp::R_SPARC_TLS_IE_LO10:
1965 case elfcpp::R_SPARC_TLS_IE_LD:
1966 case elfcpp::R_SPARC_TLS_IE_LDX:
1968 const bool is_final = gsym->final_value_is_known();
1969 const tls::Tls_optimization optimized_type
1970 = optimize_tls_reloc(is_final, r_type);
1973 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1974 case elfcpp::R_SPARC_TLS_GD_LO10:
1975 case elfcpp::R_SPARC_TLS_GD_ADD:
1976 case elfcpp::R_SPARC_TLS_GD_CALL:
1977 if (optimized_type == tls::TLSOPT_NONE)
1979 // Create a pair of GOT entries for the module index and
1980 // dtv-relative offset.
1981 Output_data_got<size, big_endian>* got
1982 = target->got_section(symtab, layout);
1983 got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR,
1984 target->rela_dyn_section(layout),
1986 elfcpp::R_SPARC_TLS_DTPMOD64 :
1987 elfcpp::R_SPARC_TLS_DTPMOD32),
1989 elfcpp::R_SPARC_TLS_DTPOFF64 :
1990 elfcpp::R_SPARC_TLS_DTPOFF32));
1992 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
1993 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
1994 generate_tls_call(symtab, layout, target);
1996 else if (optimized_type == tls::TLSOPT_TO_IE)
1998 // Create a GOT entry for the tp-relative offset.
1999 Output_data_got<size, big_endian>* got
2000 = target->got_section(symtab, layout);
2001 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2002 target->rela_dyn_section(layout),
2004 elfcpp::R_SPARC_TLS_TPOFF64 :
2005 elfcpp::R_SPARC_TLS_TPOFF32));
2007 else if (optimized_type != tls::TLSOPT_TO_LE)
2008 unsupported_reloc_global(object, r_type, gsym);
2011 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2012 case elfcpp::R_SPARC_TLS_LDM_LO10:
2013 case elfcpp::R_SPARC_TLS_LDM_ADD:
2014 case elfcpp::R_SPARC_TLS_LDM_CALL:
2015 if (optimized_type == tls::TLSOPT_NONE)
2017 // Create a GOT entry for the module index.
2018 target->got_mod_index_entry(symtab, layout, object);
2020 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2021 generate_tls_call(symtab, layout, target);
2023 else if (optimized_type != tls::TLSOPT_TO_LE)
2024 unsupported_reloc_global(object, r_type, gsym);
2027 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2028 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2029 case elfcpp::R_SPARC_TLS_LDO_ADD:
2032 case elfcpp::R_SPARC_TLS_LE_HIX22:
2033 case elfcpp::R_SPARC_TLS_LE_LOX10:
2034 layout->set_has_static_tls();
2035 if (parameters->options().shared())
2037 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2038 rela_dyn->add_global_relative(gsym, orig_r_type,
2039 output_section, object,
2040 data_shndx, reloc.get_r_offset(),
2045 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2046 case elfcpp::R_SPARC_TLS_IE_LO10:
2047 case elfcpp::R_SPARC_TLS_IE_LD:
2048 case elfcpp::R_SPARC_TLS_IE_LDX:
2049 layout->set_has_static_tls();
2050 if (optimized_type == tls::TLSOPT_NONE)
2052 // Create a GOT entry for the tp-relative offset.
2053 Output_data_got<size, big_endian>* got
2054 = target->got_section(symtab, layout);
2055 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2056 target->rela_dyn_section(layout),
2058 elfcpp::R_SPARC_TLS_TPOFF64 :
2059 elfcpp::R_SPARC_TLS_TPOFF32));
2061 else if (optimized_type != tls::TLSOPT_TO_LE)
2062 unsupported_reloc_global(object, r_type, gsym);
2068 // These are relocations which should only be seen by the
2069 // dynamic linker, and should never be seen here.
2070 case elfcpp::R_SPARC_COPY:
2071 case elfcpp::R_SPARC_GLOB_DAT:
2072 case elfcpp::R_SPARC_JMP_SLOT:
2073 case elfcpp::R_SPARC_RELATIVE:
2074 case elfcpp::R_SPARC_TLS_DTPMOD64:
2075 case elfcpp::R_SPARC_TLS_DTPMOD32:
2076 case elfcpp::R_SPARC_TLS_DTPOFF64:
2077 case elfcpp::R_SPARC_TLS_DTPOFF32:
2078 case elfcpp::R_SPARC_TLS_TPOFF64:
2079 case elfcpp::R_SPARC_TLS_TPOFF32:
2080 gold_error(_("%s: unexpected reloc %u in object file"),
2081 object->name().c_str(), r_type);
2085 unsupported_reloc_global(object, r_type, gsym);
2090 // Scan relocations for a section.
2092 template<int size, bool big_endian>
2094 Target_sparc<size, big_endian>::scan_relocs(
2095 const General_options& options,
2096 Symbol_table* symtab,
2098 Sized_relobj<size, big_endian>* object,
2099 unsigned int data_shndx,
2100 unsigned int sh_type,
2101 const unsigned char* prelocs,
2103 Output_section* output_section,
2104 bool needs_special_offset_handling,
2105 size_t local_symbol_count,
2106 const unsigned char* plocal_symbols)
2108 typedef Target_sparc<size, big_endian> Sparc;
2109 typedef typename Target_sparc<size, big_endian>::Scan Scan;
2111 if (sh_type == elfcpp::SHT_REL)
2113 gold_error(_("%s: unsupported REL reloc section"),
2114 object->name().c_str());
2118 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
2128 needs_special_offset_handling,
2133 // Finalize the sections.
2135 template<int size, bool big_endian>
2137 Target_sparc<size, big_endian>::do_finalize_sections(Layout* layout)
2139 // Fill in some more dynamic tags.
2140 Output_data_dynamic* const odyn = layout->dynamic_data();
2143 if (this->plt_ != NULL)
2145 const Output_data* od = this->plt_->rel_plt();
2146 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
2147 odyn->add_section_address(elfcpp::DT_JMPREL, od);
2148 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
2150 odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_);
2153 if (this->rela_dyn_ != NULL)
2155 const Output_data* od = this->rela_dyn_;
2156 odyn->add_section_address(elfcpp::DT_RELA, od);
2157 odyn->add_section_size(elfcpp::DT_RELASZ, od);
2158 odyn->add_constant(elfcpp::DT_RELAENT,
2159 elfcpp::Elf_sizes<size>::rela_size);
2162 if (!parameters->options().shared())
2164 // The value of the DT_DEBUG tag is filled in by the dynamic
2165 // linker at run time, and used by the debugger.
2166 odyn->add_constant(elfcpp::DT_DEBUG, 0);
2170 // Emit any relocs we saved in an attempt to avoid generating COPY
2172 if (this->copy_relocs_.any_saved_relocs())
2173 this->copy_relocs_.emit(this->rela_dyn_section(layout));
2176 // Perform a relocation.
2178 template<int size, bool big_endian>
2180 Target_sparc<size, big_endian>::Relocate::relocate(
2181 const Relocate_info<size, big_endian>* relinfo,
2182 Target_sparc* target,
2184 const elfcpp::Rela<size, big_endian>& rela,
2185 unsigned int r_type,
2186 const Sized_symbol<size>* gsym,
2187 const Symbol_value<size>* psymval,
2188 unsigned char* view,
2189 typename elfcpp::Elf_types<size>::Elf_Addr address,
2190 section_size_type view_size)
2194 if (this->ignore_gd_add_)
2196 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
2197 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2198 _("missing expected TLS relocation"));
2201 this->ignore_gd_add_ = false;
2206 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2208 // Pick the value to use for symbols defined in shared objects.
2209 Symbol_value<size> symval;
2211 && (gsym->is_from_dynobj()
2212 || (parameters->options().shared()
2213 && (gsym->is_undefined() || gsym->is_preemptible())))
2214 && gsym->has_plt_offset())
2216 elfcpp::Elf_Xword value;
2218 value = target->plt_section()->address() + gsym->plt_offset();
2220 symval.set_output_value(value);
2225 const Sized_relobj<size, big_endian>* object = relinfo->object;
2226 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2228 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2229 // pointer points to the beginning, not the end, of the table.
2230 // So we just use the plain offset.
2231 bool have_got_offset = false;
2232 unsigned int got_offset = 0;
2235 case elfcpp::R_SPARC_GOT10:
2236 case elfcpp::R_SPARC_GOT13:
2237 case elfcpp::R_SPARC_GOT22:
2240 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
2241 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
2245 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2246 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
2247 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
2249 have_got_offset = true;
2258 case elfcpp::R_SPARC_NONE:
2259 case elfcpp::R_SPARC_REGISTER:
2260 case elfcpp::R_SPARC_GNU_VTINHERIT:
2261 case elfcpp::R_SPARC_GNU_VTENTRY:
2264 case elfcpp::R_SPARC_8:
2265 Relocate_functions<size, big_endian>::rela8(view, object,
2269 case elfcpp::R_SPARC_16:
2270 Relocate_functions<size, big_endian>::rela16(view, object,
2274 case elfcpp::R_SPARC_32:
2275 if (!parameters->options().output_is_position_independent())
2276 Relocate_functions<size, big_endian>::rela32(view, object,
2280 case elfcpp::R_SPARC_DISP8:
2281 Reloc::disp8(view, object, psymval, addend, address);
2284 case elfcpp::R_SPARC_DISP16:
2285 Reloc::disp16(view, object, psymval, addend, address);
2288 case elfcpp::R_SPARC_DISP32:
2289 Reloc::disp32(view, object, psymval, addend, address);
2292 case elfcpp::R_SPARC_DISP64:
2293 Reloc::disp64(view, object, psymval, addend, address);
2296 case elfcpp::R_SPARC_WDISP30:
2297 case elfcpp::R_SPARC_WPLT30:
2298 Reloc::wdisp30(view, object, psymval, addend, address);
2301 case elfcpp::R_SPARC_WDISP22:
2302 Reloc::wdisp22(view, object, psymval, addend, address);
2305 case elfcpp::R_SPARC_WDISP19:
2306 Reloc::wdisp19(view, object, psymval, addend, address);
2309 case elfcpp::R_SPARC_WDISP16:
2310 Reloc::wdisp16(view, object, psymval, addend, address);
2313 case elfcpp::R_SPARC_HI22:
2314 Reloc::hi22(view, object, psymval, addend);
2317 case elfcpp::R_SPARC_22:
2318 Reloc::rela32_22(view, object, psymval, addend);
2321 case elfcpp::R_SPARC_13:
2322 Reloc::rela32_13(view, object, psymval, addend);
2325 case elfcpp::R_SPARC_LO10:
2326 Reloc::lo10(view, object, psymval, addend);
2329 case elfcpp::R_SPARC_GOT10:
2330 Reloc::lo10(view, got_offset, addend);
2333 case elfcpp::R_SPARC_GOT13:
2334 Reloc::rela32_13(view, got_offset, addend);
2337 case elfcpp::R_SPARC_GOT22:
2338 Reloc::hi22(view, got_offset, addend);
2341 case elfcpp::R_SPARC_PC10:
2342 Reloc::pc10(view, object, psymval, addend, address);
2345 case elfcpp::R_SPARC_PC22:
2346 Reloc::pc22(view, object, psymval, addend, address);
2349 case elfcpp::R_SPARC_TLS_DTPOFF32:
2350 case elfcpp::R_SPARC_UA32:
2351 Reloc::ua32(view, object, psymval, addend);
2354 case elfcpp::R_SPARC_PLT64:
2355 Relocate_functions<size, big_endian>::rela64(view, object,
2359 case elfcpp::R_SPARC_PLT32:
2360 Relocate_functions<size, big_endian>::rela32(view, object,
2364 case elfcpp::R_SPARC_HIPLT22:
2365 Reloc::hi22(view, object, psymval, addend);
2368 case elfcpp::R_SPARC_LOPLT10:
2369 Reloc::lo10(view, object, psymval, addend);
2372 case elfcpp::R_SPARC_PCPLT32:
2373 Reloc::disp32(view, object, psymval, addend, address);
2376 case elfcpp::R_SPARC_PCPLT22:
2377 Reloc::pcplt22(view, object, psymval, addend, address);
2380 case elfcpp::R_SPARC_PCPLT10:
2381 Reloc::lo10(view, object, psymval, addend, address);
2384 case elfcpp::R_SPARC_64:
2385 if (!parameters->options().output_is_position_independent())
2386 Relocate_functions<size, big_endian>::rela64(view, object,
2390 case elfcpp::R_SPARC_OLO10:
2392 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
2393 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
2394 Reloc::olo10(view, object, psymval, addend, addend2);
2398 case elfcpp::R_SPARC_HH22:
2399 Reloc::hh22(view, object, psymval, addend);
2402 case elfcpp::R_SPARC_PC_HH22:
2403 Reloc::pc_hh22(view, object, psymval, addend, address);
2406 case elfcpp::R_SPARC_HM10:
2407 Reloc::hm10(view, object, psymval, addend);
2410 case elfcpp::R_SPARC_PC_HM10:
2411 Reloc::pc_hm10(view, object, psymval, addend, address);
2414 case elfcpp::R_SPARC_LM22:
2415 Reloc::hi22(view, object, psymval, addend);
2418 case elfcpp::R_SPARC_PC_LM22:
2419 Reloc::pcplt22(view, object, psymval, addend, address);
2422 case elfcpp::R_SPARC_11:
2423 Reloc::rela32_11(view, object, psymval, addend);
2426 case elfcpp::R_SPARC_10:
2427 Reloc::rela32_10(view, object, psymval, addend);
2430 case elfcpp::R_SPARC_7:
2431 Reloc::rela32_7(view, object, psymval, addend);
2434 case elfcpp::R_SPARC_6:
2435 Reloc::rela32_6(view, object, psymval, addend);
2438 case elfcpp::R_SPARC_5:
2439 Reloc::rela32_5(view, object, psymval, addend);
2442 case elfcpp::R_SPARC_HIX22:
2443 Reloc::hix22(view, object, psymval, addend);
2446 case elfcpp::R_SPARC_LOX10:
2447 Reloc::lox10(view, object, psymval, addend);
2450 case elfcpp::R_SPARC_H44:
2451 Reloc::h44(view, object, psymval, addend);
2454 case elfcpp::R_SPARC_M44:
2455 Reloc::m44(view, object, psymval, addend);
2458 case elfcpp::R_SPARC_L44:
2459 Reloc::l44(view, object, psymval, addend);
2462 case elfcpp::R_SPARC_TLS_DTPOFF64:
2463 case elfcpp::R_SPARC_UA64:
2464 Reloc::ua64(view, object, psymval, addend);
2467 case elfcpp::R_SPARC_UA16:
2468 Reloc::ua16(view, object, psymval, addend);
2471 case elfcpp::R_SPARC_TLS_GD_HI22:
2472 case elfcpp::R_SPARC_TLS_GD_LO10:
2473 case elfcpp::R_SPARC_TLS_GD_ADD:
2474 case elfcpp::R_SPARC_TLS_GD_CALL:
2475 case elfcpp::R_SPARC_TLS_LDM_HI22:
2476 case elfcpp::R_SPARC_TLS_LDM_LO10:
2477 case elfcpp::R_SPARC_TLS_LDM_ADD:
2478 case elfcpp::R_SPARC_TLS_LDM_CALL:
2479 case elfcpp::R_SPARC_TLS_LDO_HIX22:
2480 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2481 case elfcpp::R_SPARC_TLS_LDO_ADD:
2482 case elfcpp::R_SPARC_TLS_IE_HI22:
2483 case elfcpp::R_SPARC_TLS_IE_LO10:
2484 case elfcpp::R_SPARC_TLS_IE_LD:
2485 case elfcpp::R_SPARC_TLS_IE_LDX:
2486 case elfcpp::R_SPARC_TLS_LE_HIX22:
2487 case elfcpp::R_SPARC_TLS_LE_LOX10:
2488 this->relocate_tls(relinfo, target, relnum, rela,
2489 r_type, gsym, psymval, view,
2490 address, view_size);
2493 case elfcpp::R_SPARC_COPY:
2494 case elfcpp::R_SPARC_GLOB_DAT:
2495 case elfcpp::R_SPARC_JMP_SLOT:
2496 case elfcpp::R_SPARC_RELATIVE:
2497 // These are outstanding tls relocs, which are unexpected when
2499 case elfcpp::R_SPARC_TLS_DTPMOD64:
2500 case elfcpp::R_SPARC_TLS_DTPMOD32:
2501 case elfcpp::R_SPARC_TLS_TPOFF64:
2502 case elfcpp::R_SPARC_TLS_TPOFF32:
2503 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2504 _("unexpected reloc %u in object file"),
2509 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2510 _("unsupported reloc %u"),
2518 // Perform a TLS relocation.
2520 template<int size, bool big_endian>
2522 Target_sparc<size, big_endian>::Relocate::relocate_tls(
2523 const Relocate_info<size, big_endian>* relinfo,
2524 Target_sparc<size, big_endian>* target,
2526 const elfcpp::Rela<size, big_endian>& rela,
2527 unsigned int r_type,
2528 const Sized_symbol<size>* gsym,
2529 const Symbol_value<size>* psymval,
2530 unsigned char* view,
2531 typename elfcpp::Elf_types<size>::Elf_Addr address,
2534 Output_segment* tls_segment = relinfo->layout->tls_segment();
2535 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2536 const Sized_relobj<size, big_endian>* object = relinfo->object;
2537 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
2539 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2540 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
2542 const bool is_final =
2544 ? !parameters->options().output_is_position_independent()
2545 : gsym->final_value_is_known());
2546 const tls::Tls_optimization optimized_type
2547 = optimize_tls_reloc(is_final, r_type);
2551 case elfcpp::R_SPARC_TLS_GD_HI22:
2552 case elfcpp::R_SPARC_TLS_GD_LO10:
2553 case elfcpp::R_SPARC_TLS_GD_ADD:
2554 case elfcpp::R_SPARC_TLS_GD_CALL:
2555 if (optimized_type == tls::TLSOPT_TO_LE)
2557 Insntype* wv = reinterpret_cast<Insntype*>(view);
2560 value -= tls_segment->memsz();
2564 case elfcpp::R_SPARC_TLS_GD_HI22:
2565 // TLS_GD_HI22 --> TLS_LE_HIX22
2566 Reloc::hix22(view, value, addend);
2569 case elfcpp::R_SPARC_TLS_GD_LO10:
2570 // TLS_GD_LO10 --> TLS_LE_LOX10
2571 Reloc::lox10(view, value, addend);
2574 case elfcpp::R_SPARC_TLS_GD_ADD:
2575 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2576 val = elfcpp::Swap<32, true>::readval(wv);
2577 val = (val & ~0x7c000) | 0x1c000;
2578 elfcpp::Swap<32, true>::writeval(wv, val);
2580 case elfcpp::R_SPARC_TLS_GD_CALL:
2581 // call __tls_get_addr --> nop
2582 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
2589 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
2590 ? GOT_TYPE_TLS_OFFSET
2591 : GOT_TYPE_TLS_PAIR);
2594 gold_assert(gsym->has_got_offset(got_type));
2595 value = gsym->got_offset(got_type);
2599 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2600 gold_assert(object->local_has_got_offset(r_sym, got_type));
2601 value = object->local_got_offset(r_sym, got_type);
2603 if (optimized_type == tls::TLSOPT_TO_IE)
2605 Insntype* wv = reinterpret_cast<Insntype*>(view);
2610 case elfcpp::R_SPARC_TLS_GD_HI22:
2611 // TLS_GD_HI22 --> TLS_IE_HI22
2612 Reloc::hi22(view, value, addend);
2615 case elfcpp::R_SPARC_TLS_GD_LO10:
2616 // TLS_GD_LO10 --> TLS_IE_LO10
2617 Reloc::lo10(view, value, addend);
2620 case elfcpp::R_SPARC_TLS_GD_ADD:
2621 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2622 val = elfcpp::Swap<32, true>::readval(wv);
2629 elfcpp::Swap<32, true>::writeval(wv, val);
2632 case elfcpp::R_SPARC_TLS_GD_CALL:
2633 // The compiler can put the TLS_GD_ADD instruction
2634 // into the delay slot of the call. If so, we need
2635 // to transpose the two instructions so that the
2636 // the new sequence works properly.
2638 // The test we use is if the instruction in the
2639 // delay slot is an add with destination register
2641 val = elfcpp::Swap<32, true>::readval(wv + 1);
2642 if ((val & 0x81f80000) == 0x80000000
2643 && ((val >> 25) & 0x1f) == 0x8)
2650 elfcpp::Swap<32, true>::writeval(wv, val);
2653 this->ignore_gd_add_ = true;
2656 // call __tls_get_addr --> add %g7, %o0, %o0
2657 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
2662 else if (optimized_type == tls::TLSOPT_NONE)
2666 case elfcpp::R_SPARC_TLS_GD_HI22:
2667 Reloc::hi22(view, value, addend);
2669 case elfcpp::R_SPARC_TLS_GD_LO10:
2670 Reloc::lo10(view, value, addend);
2672 case elfcpp::R_SPARC_TLS_GD_ADD:
2674 case elfcpp::R_SPARC_TLS_GD_CALL:
2676 Symbol_value<size> symval;
2677 elfcpp::Elf_Xword value;
2680 tsym = target->tls_get_addr_sym_;
2682 value = (target->plt_section()->address() +
2683 tsym->plt_offset());
2684 symval.set_output_value(value);
2685 Reloc::wdisp30(view, object, &symval, addend, address);
2692 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2693 _("unsupported reloc %u"),
2697 case elfcpp::R_SPARC_TLS_LDM_HI22:
2698 case elfcpp::R_SPARC_TLS_LDM_LO10:
2699 case elfcpp::R_SPARC_TLS_LDM_ADD:
2700 case elfcpp::R_SPARC_TLS_LDM_CALL:
2701 if (optimized_type == tls::TLSOPT_TO_LE)
2703 Insntype* wv = reinterpret_cast<Insntype*>(view);
2707 case elfcpp::R_SPARC_TLS_LDM_HI22:
2708 case elfcpp::R_SPARC_TLS_LDM_LO10:
2709 case elfcpp::R_SPARC_TLS_LDM_ADD:
2710 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
2713 case elfcpp::R_SPARC_TLS_LDM_CALL:
2714 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
2719 else if (optimized_type == tls::TLSOPT_NONE)
2721 // Relocate the field with the offset of the GOT entry for
2722 // the module index.
2723 unsigned int got_offset;
2725 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
2728 case elfcpp::R_SPARC_TLS_LDM_HI22:
2729 Reloc::hi22(view, got_offset, addend);
2731 case elfcpp::R_SPARC_TLS_LDM_LO10:
2732 Reloc::lo10(view, got_offset, addend);
2734 case elfcpp::R_SPARC_TLS_LDM_ADD:
2736 case elfcpp::R_SPARC_TLS_LDM_CALL:
2738 Symbol_value<size> symval;
2739 elfcpp::Elf_Xword value;
2742 tsym = target->tls_get_addr_sym_;
2744 value = (target->plt_section()->address() +
2745 tsym->plt_offset());
2746 symval.set_output_value(value);
2747 Reloc::wdisp30(view, object, &symval, addend, address);
2753 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2754 _("unsupported reloc %u"),
2758 // These relocs can appear in debugging sections, in which case
2759 // we won't see the TLS_LDM relocs. The local_dynamic_type
2760 // field tells us this.
2761 case elfcpp::R_SPARC_TLS_LDO_HIX22:
2762 if (optimized_type == tls::TLSOPT_TO_LE)
2764 value -= tls_segment->memsz();
2765 Reloc::hix22(view, value, addend);
2768 Reloc::ldo_hix22(view, value, addend);
2770 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2771 if (optimized_type == tls::TLSOPT_TO_LE)
2773 value -= tls_segment->memsz();
2774 Reloc::lox10(view, value, addend);
2777 Reloc::ldo_lox10(view, value, addend);
2779 case elfcpp::R_SPARC_TLS_LDO_ADD:
2780 if (optimized_type == tls::TLSOPT_TO_LE)
2782 Insntype* wv = reinterpret_cast<Insntype*>(view);
2785 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2786 val = elfcpp::Swap<32, true>::readval(wv);
2787 val = (val & ~0x7c000) | 0x1c000;
2788 elfcpp::Swap<32, true>::writeval(wv, val);
2792 // When optimizing IE --> LE, the only relocation that is handled
2793 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2794 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2795 // rs2 and rd are the same.
2796 case elfcpp::R_SPARC_TLS_IE_LD:
2797 case elfcpp::R_SPARC_TLS_IE_LDX:
2798 if (optimized_type == tls::TLSOPT_TO_LE)
2800 Insntype* wv = reinterpret_cast<Insntype*>(view);
2801 Insntype val = elfcpp::Swap<32, true>::readval(wv);
2802 Insntype rs2 = val & 0x1f;
2803 Insntype rd = (val >> 25) & 0x1f;
2808 val = sparc_mov | (val & 0x3e00001f);
2810 elfcpp::Swap<32, true>::writeval(wv, val);
2814 case elfcpp::R_SPARC_TLS_IE_HI22:
2815 case elfcpp::R_SPARC_TLS_IE_LO10:
2816 if (optimized_type == tls::TLSOPT_TO_LE)
2818 value -= tls_segment->memsz();
2821 case elfcpp::R_SPARC_TLS_IE_HI22:
2822 // IE_HI22 --> LE_HIX22
2823 Reloc::hix22(view, value, addend);
2825 case elfcpp::R_SPARC_TLS_IE_LO10:
2826 // IE_LO10 --> LE_LOX10
2827 Reloc::lox10(view, value, addend);
2832 else if (optimized_type == tls::TLSOPT_NONE)
2834 // Relocate the field with the offset of the GOT entry for
2835 // the tp-relative offset of the symbol.
2838 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
2839 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
2843 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2844 gold_assert(object->local_has_got_offset(r_sym,
2845 GOT_TYPE_TLS_OFFSET));
2846 value = object->local_got_offset(r_sym,
2847 GOT_TYPE_TLS_OFFSET);
2851 case elfcpp::R_SPARC_TLS_IE_HI22:
2852 Reloc::hi22(view, value, addend);
2854 case elfcpp::R_SPARC_TLS_IE_LO10:
2855 Reloc::lo10(view, value, addend);
2860 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2861 _("unsupported reloc %u"),
2865 case elfcpp::R_SPARC_TLS_LE_HIX22:
2866 // If we're creating a shared library, a dynamic relocation will
2867 // have been created for this location, so do not apply it now.
2868 if (!parameters->options().shared())
2870 value -= tls_segment->memsz();
2871 Reloc::hix22(view, value, addend);
2875 case elfcpp::R_SPARC_TLS_LE_LOX10:
2876 // If we're creating a shared library, a dynamic relocation will
2877 // have been created for this location, so do not apply it now.
2878 if (!parameters->options().shared())
2880 value -= tls_segment->memsz();
2881 Reloc::lox10(view, value, addend);
2887 // Relocate section data.
2889 template<int size, bool big_endian>
2891 Target_sparc<size, big_endian>::relocate_section(
2892 const Relocate_info<size, big_endian>* relinfo,
2893 unsigned int sh_type,
2894 const unsigned char* prelocs,
2896 Output_section* output_section,
2897 bool needs_special_offset_handling,
2898 unsigned char* view,
2899 typename elfcpp::Elf_types<size>::Elf_Addr address,
2900 section_size_type view_size)
2902 typedef Target_sparc<size, big_endian> Sparc;
2903 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
2905 gold_assert(sh_type == elfcpp::SHT_RELA);
2907 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
2914 needs_special_offset_handling,
2920 // Return the size of a relocation while scanning during a relocatable
2923 template<int size, bool big_endian>
2925 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
2929 // We are always SHT_RELA, so we should never get here.
2934 // Scan the relocs during a relocatable link.
2936 template<int size, bool big_endian>
2938 Target_sparc<size, big_endian>::scan_relocatable_relocs(
2939 const General_options& options,
2940 Symbol_table* symtab,
2942 Sized_relobj<size, big_endian>* object,
2943 unsigned int data_shndx,
2944 unsigned int sh_type,
2945 const unsigned char* prelocs,
2947 Output_section* output_section,
2948 bool needs_special_offset_handling,
2949 size_t local_symbol_count,
2950 const unsigned char* plocal_symbols,
2951 Relocatable_relocs* rr)
2953 gold_assert(sh_type == elfcpp::SHT_RELA);
2955 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
2956 Relocatable_size_for_reloc> Scan_relocatable_relocs;
2958 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
2959 Scan_relocatable_relocs>(
2968 needs_special_offset_handling,
2974 // Relocate a section during a relocatable link.
2976 template<int size, bool big_endian>
2978 Target_sparc<size, big_endian>::relocate_for_relocatable(
2979 const Relocate_info<size, big_endian>* relinfo,
2980 unsigned int sh_type,
2981 const unsigned char* prelocs,
2983 Output_section* output_section,
2984 off_t offset_in_output_section,
2985 const Relocatable_relocs* rr,
2986 unsigned char* view,
2987 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
2988 section_size_type view_size,
2989 unsigned char* reloc_view,
2990 section_size_type reloc_view_size)
2992 gold_assert(sh_type == elfcpp::SHT_RELA);
2994 gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>(
2999 offset_in_output_section,
3008 // Return the value to use for a dynamic which requires special
3009 // treatment. This is how we support equality comparisons of function
3010 // pointers across shared library boundaries, as described in the
3011 // processor specific ABI supplement.
3013 template<int size, bool big_endian>
3015 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
3017 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
3018 return this->plt_section()->address() + gsym->plt_offset();
3021 // The selector for sparc object files.
3023 template<int size, bool big_endian>
3024 class Target_selector_sparc : public Target_selector
3027 Target_selector_sparc()
3028 : Target_selector(elfcpp::EM_NONE, size, big_endian,
3029 (size == 64 ? "elf64-sparc" : "elf32-sparc"))
3032 Target* instantiated_target_;
3034 Target* do_recognize(int machine, int, int)
3039 if (machine != elfcpp::EM_SPARCV9)
3044 if (machine != elfcpp::EM_SPARC
3045 && machine != elfcpp::EM_SPARC32PLUS)
3053 return do_instantiate_target();
3056 Target* do_instantiate_target()
3058 if (this->instantiated_target_ == NULL)
3059 this->instantiated_target_ = new Target_sparc<size, big_endian>();
3060 return this->instantiated_target_;
3064 Target_selector_sparc<32, true> target_selector_sparc32;
3065 Target_selector_sparc<64, true> target_selector_sparc64;
3067 } // End anonymous namespace.