Handle output sections with more than 0x7fffffff bytes.
[deliverable/binutils-gdb.git] / gold / sparc.cc
1 // sparc.cc -- sparc target support for gold.
2
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by David S. Miller <davem@davemloft.net>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 #include "gold.h"
24
25 #include <cstdlib>
26 #include <cstdio>
27 #include <cstring>
28
29 #include "elfcpp.h"
30 #include "parameters.h"
31 #include "reloc.h"
32 #include "sparc.h"
33 #include "object.h"
34 #include "symtab.h"
35 #include "layout.h"
36 #include "output.h"
37 #include "copy-relocs.h"
38 #include "target.h"
39 #include "target-reloc.h"
40 #include "target-select.h"
41 #include "tls.h"
42 #include "errors.h"
43
44 namespace
45 {
46
47 using namespace gold;
48
49 template<int size, bool big_endian>
50 class Output_data_plt_sparc;
51
52 template<int size, bool big_endian>
53 class Target_sparc : public Sized_target<size, big_endian>
54 {
55 public:
56 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Reloc_section;
57
58 Target_sparc()
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)
63 {
64 }
65
66 // Scan the relocations to look for symbol adjustments.
67 void
68 scan_relocs(const General_options& options,
69 Symbol_table* symtab,
70 Layout* layout,
71 Sized_relobj<size, big_endian>* object,
72 unsigned int data_shndx,
73 unsigned int sh_type,
74 const unsigned char* prelocs,
75 size_t reloc_count,
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.
81 void
82 do_finalize_sections(Layout*);
83
84 // Return the value to use for a dynamic which requires special
85 // treatment.
86 uint64_t
87 do_dynsym_value(const Symbol*) const;
88
89 // Relocate a section.
90 void
91 relocate_section(const Relocate_info<size, big_endian>*,
92 unsigned int sh_type,
93 const unsigned char* prelocs,
94 size_t reloc_count,
95 Output_section* output_section,
96 bool needs_special_offset_handling,
97 unsigned char* view,
98 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
99 section_size_type view_size);
100
101 // Scan the relocs during a relocatable link.
102 void
103 scan_relocatable_relocs(const General_options& options,
104 Symbol_table* symtab,
105 Layout* layout,
106 Sized_relobj<size, big_endian>* object,
107 unsigned int data_shndx,
108 unsigned int sh_type,
109 const unsigned char* prelocs,
110 size_t reloc_count,
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*);
116
117 // Relocate a section during a relocatable link.
118 void
119 relocate_for_relocatable(const Relocate_info<size, big_endian>*,
120 unsigned int sh_type,
121 const unsigned char* prelocs,
122 size_t reloc_count,
123 Output_section* output_section,
124 off_t offset_in_output_section,
125 const Relocatable_relocs*,
126 unsigned char* view,
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.
132 bool
133 do_is_defined_by_abi(Symbol* sym) const
134 {
135 // XXX Really need to support this better...
136 if (sym->type() == elfcpp::STT_SPARC_REGISTER)
137 return 1;
138
139 return strcmp(sym->name(), "___tls_get_addr") == 0;
140 }
141
142 // Return the size of the GOT section.
143 section_size_type
144 got_size()
145 {
146 gold_assert(this->got_ != NULL);
147 return this->got_->data_size();
148 }
149
150 private:
151
152 // The class which scans relocations.
153 class Scan
154 {
155 public:
156 Scan()
157 : issued_non_pic_error_(false)
158 { }
159
160 inline void
161 local(const General_options& options, Symbol_table* symtab,
162 Layout* layout, Target_sparc* target,
163 Sized_relobj<size, big_endian>* object,
164 unsigned int data_shndx,
165 Output_section* output_section,
166 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
167 const elfcpp::Sym<size, big_endian>& lsym);
168
169 inline void
170 global(const General_options& options, Symbol_table* symtab,
171 Layout* layout, Target_sparc* target,
172 Sized_relobj<size, big_endian>* object,
173 unsigned int data_shndx,
174 Output_section* output_section,
175 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
176 Symbol* gsym);
177
178 private:
179 static void
180 unsupported_reloc_local(Sized_relobj<size, big_endian>*,
181 unsigned int r_type);
182
183 static void
184 unsupported_reloc_global(Sized_relobj<size, big_endian>*,
185 unsigned int r_type, Symbol*);
186
187 static void
188 generate_tls_call(Symbol_table* symtab, Layout* layout,
189 Target_sparc* target);
190
191 void
192 check_non_pic(Relobj*, unsigned int r_type);
193
194 // Whether we have issued an error about a non-PIC compilation.
195 bool issued_non_pic_error_;
196 };
197
198 // The class which implements relocation.
199 class Relocate
200 {
201 public:
202 Relocate()
203 : ignore_gd_add_(false)
204 { }
205
206 ~Relocate()
207 {
208 if (this->ignore_gd_add_)
209 {
210 // FIXME: This needs to specify the location somehow.
211 gold_error(_("missing expected TLS relocation"));
212 }
213 }
214
215 // Do a relocation. Return false if the caller should not issue
216 // any warnings about this relocation.
217 inline bool
218 relocate(const Relocate_info<size, big_endian>*, Target_sparc*,
219 size_t relnum, const elfcpp::Rela<size, big_endian>&,
220 unsigned int r_type, const Sized_symbol<size>*,
221 const Symbol_value<size>*,
222 unsigned char*,
223 typename elfcpp::Elf_types<size>::Elf_Addr,
224 section_size_type);
225
226 private:
227 // Do a TLS relocation.
228 inline void
229 relocate_tls(const Relocate_info<size, big_endian>*, Target_sparc* target,
230 size_t relnum, const elfcpp::Rela<size, big_endian>&,
231 unsigned int r_type, const Sized_symbol<size>*,
232 const Symbol_value<size>*,
233 unsigned char*,
234 typename elfcpp::Elf_types<size>::Elf_Addr,
235 section_size_type);
236
237 // Ignore the next relocation which should be R_SPARC_TLS_GD_ADD
238 bool ignore_gd_add_;
239 };
240
241 // A class which returns the size required for a relocation type,
242 // used while scanning relocs during a relocatable link.
243 class Relocatable_size_for_reloc
244 {
245 public:
246 unsigned int
247 get_size_for_reloc(unsigned int, Relobj*);
248 };
249
250 // Get the GOT section, creating it if necessary.
251 Output_data_got<size, big_endian>*
252 got_section(Symbol_table*, Layout*);
253
254 // Create a PLT entry for a global symbol.
255 void
256 make_plt_entry(Symbol_table*, Layout*, Symbol*);
257
258 // Create a GOT entry for the TLS module index.
259 unsigned int
260 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
261 Sized_relobj<size, big_endian>* object);
262
263 // Return the gsym for "__tls_get_addr". Cache if not already
264 // cached.
265 Symbol*
266 tls_get_addr_sym(Symbol_table* symtab)
267 {
268 if (!this->tls_get_addr_sym_)
269 this->tls_get_addr_sym_ = symtab->lookup("__tls_get_addr", NULL);
270 gold_assert(this->tls_get_addr_sym_);
271 return this->tls_get_addr_sym_;
272 }
273
274 // Get the PLT section.
275 const Output_data_plt_sparc<size, big_endian>*
276 plt_section() const
277 {
278 gold_assert(this->plt_ != NULL);
279 return this->plt_;
280 }
281
282 // Get the dynamic reloc section, creating it if necessary.
283 Reloc_section*
284 rela_dyn_section(Layout*);
285
286 // Return true if the symbol may need a COPY relocation.
287 // References from an executable object to non-function symbols
288 // defined in a dynamic object may need a COPY relocation.
289 bool
290 may_need_copy_reloc(Symbol* gsym)
291 {
292 return (!parameters->options().shared()
293 && gsym->is_from_dynobj()
294 && gsym->type() != elfcpp::STT_FUNC);
295 }
296
297 // Copy a relocation against a global symbol.
298 void
299 copy_reloc(Symbol_table* symtab, Layout* layout,
300 Sized_relobj<size, big_endian>* object,
301 unsigned int shndx, Output_section* output_section,
302 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
303 {
304 this->copy_relocs_.copy_reloc(symtab, layout,
305 symtab->get_sized_symbol<size>(sym),
306 object, shndx, output_section,
307 reloc, this->rela_dyn_section(layout));
308 }
309
310 // Information about this specific target which we pass to the
311 // general Target structure.
312 static Target::Target_info sparc_info;
313
314 // The types of GOT entries needed for this platform.
315 enum Got_type
316 {
317 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
318 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
319 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
320 };
321
322 // The GOT section.
323 Output_data_got<size, big_endian>* got_;
324 // The PLT section.
325 Output_data_plt_sparc<size, big_endian>* plt_;
326 // The dynamic reloc section.
327 Reloc_section* rela_dyn_;
328 // Relocs saved to avoid a COPY reloc.
329 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
330 // Space for variables copied with a COPY reloc.
331 Output_data_space* dynbss_;
332 // Offset of the GOT entry for the TLS module index;
333 unsigned int got_mod_index_offset_;
334 // Cached pointer to __tls_get_addr symbol
335 Symbol* tls_get_addr_sym_;
336 };
337
338 template<>
339 Target::Target_info Target_sparc<32, true>::sparc_info =
340 {
341 32, // size
342 true, // is_big_endian
343 elfcpp::EM_SPARC, // machine_code
344 false, // has_make_symbol
345 false, // has_resolve
346 false, // has_code_fill
347 true, // is_default_stack_executable
348 '\0', // wrap_char
349 "/usr/lib/ld.so.1", // dynamic_linker
350 0x00010000, // default_text_segment_address
351 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
352 8 * 1024 // common_pagesize (overridable by -z common-page-size)
353 };
354
355 template<>
356 Target::Target_info Target_sparc<64, true>::sparc_info =
357 {
358 64, // size
359 true, // is_big_endian
360 elfcpp::EM_SPARCV9, // machine_code
361 false, // has_make_symbol
362 false, // has_resolve
363 false, // has_code_fill
364 true, // is_default_stack_executable
365 '\0', // wrap_char
366 "/usr/lib/sparcv9/ld.so.1", // dynamic_linker
367 0x100000, // default_text_segment_address
368 64 * 1024, // abi_pagesize (overridable by -z max-page-size)
369 8 * 1024 // common_pagesize (overridable by -z common-page-size)
370 };
371
372 // We have to take care here, even when operating in little-endian
373 // mode, sparc instructions are still big endian.
374 template<int size, bool big_endian>
375 class Sparc_relocate_functions
376 {
377 private:
378 // Do a simple relocation with the addend in the relocation.
379 template<int valsize>
380 static inline void
381 rela(unsigned char* view,
382 unsigned int right_shift,
383 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
384 typename elfcpp::Swap<size, big_endian>::Valtype value,
385 typename elfcpp::Swap<size, big_endian>::Valtype addend)
386 {
387 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
388 Valtype* wv = reinterpret_cast<Valtype*>(view);
389 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
390 Valtype reloc = ((value + addend) >> right_shift);
391
392 val &= ~dst_mask;
393 reloc &= dst_mask;
394
395 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
396 }
397
398 // Do a simple relocation using a symbol value with the addend in
399 // the relocation.
400 template<int valsize>
401 static inline void
402 rela(unsigned char* view,
403 unsigned int right_shift,
404 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
405 const Sized_relobj<size, big_endian>* object,
406 const Symbol_value<size>* psymval,
407 typename elfcpp::Swap<valsize, big_endian>::Valtype addend)
408 {
409 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
410 Valtype* wv = reinterpret_cast<Valtype*>(view);
411 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
412 Valtype reloc = (psymval->value(object, addend) >> right_shift);
413
414 val &= ~dst_mask;
415 reloc &= dst_mask;
416
417 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
418 }
419
420 // Do a simple relocation using a symbol value with the addend in
421 // the relocation, unaligned.
422 template<int valsize>
423 static inline void
424 rela_ua(unsigned char* view,
425 unsigned int right_shift, elfcpp::Elf_Xword dst_mask,
426 const Sized_relobj<size, big_endian>* object,
427 const Symbol_value<size>* psymval,
428 typename elfcpp::Swap<size, big_endian>::Valtype addend)
429 {
430 typedef typename elfcpp::Swap_unaligned<valsize,
431 big_endian>::Valtype Valtype;
432 unsigned char* wv = view;
433 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
434 Valtype reloc = (psymval->value(object, addend) >> right_shift);
435
436 val &= ~dst_mask;
437 reloc &= dst_mask;
438
439 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, val | reloc);
440 }
441
442 // Do a simple PC relative relocation with a Symbol_value with the
443 // addend in the relocation.
444 template<int valsize>
445 static inline void
446 pcrela(unsigned char* view,
447 unsigned int right_shift,
448 typename elfcpp::Elf_types<valsize>::Elf_Addr dst_mask,
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)
453 {
454 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
455 Valtype* wv = reinterpret_cast<Valtype*>(view);
456 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
457 Valtype reloc = ((psymval->value(object, addend) - address)
458 >> right_shift);
459
460 val &= ~dst_mask;
461 reloc &= dst_mask;
462
463 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
464 }
465
466 template<int valsize>
467 static inline void
468 pcrela_unaligned(unsigned char* view,
469 const Sized_relobj<size, big_endian>* object,
470 const Symbol_value<size>* psymval,
471 typename elfcpp::Swap<size, big_endian>::Valtype addend,
472 typename elfcpp::Elf_types<size>::Elf_Addr address)
473 {
474 typedef typename elfcpp::Swap_unaligned<valsize,
475 big_endian>::Valtype Valtype;
476 unsigned char* wv = view;
477 Valtype reloc = (psymval->value(object, addend) - address);
478
479 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv, reloc);
480 }
481
482 typedef Sparc_relocate_functions<size, big_endian> This;
483 typedef Sparc_relocate_functions<size, true> This_insn;
484
485 public:
486 // R_SPARC_WDISP30: (Symbol + Addend - Address) >> 2
487 static inline void
488 wdisp30(unsigned char* view,
489 const Sized_relobj<size, big_endian>* object,
490 const Symbol_value<size>* psymval,
491 typename elfcpp::Elf_types<size>::Elf_Addr addend,
492 typename elfcpp::Elf_types<size>::Elf_Addr address)
493 {
494 This_insn::template pcrela<32>(view, 2, 0x3fffffff, object,
495 psymval, addend, address);
496 }
497
498 // R_SPARC_WDISP22: (Symbol + Addend - Address) >> 2
499 static inline void
500 wdisp22(unsigned char* view,
501 const Sized_relobj<size, big_endian>* object,
502 const Symbol_value<size>* psymval,
503 typename elfcpp::Elf_types<size>::Elf_Addr addend,
504 typename elfcpp::Elf_types<size>::Elf_Addr address)
505 {
506 This_insn::template pcrela<32>(view, 2, 0x003fffff, object,
507 psymval, addend, address);
508 }
509
510 // R_SPARC_WDISP19: (Symbol + Addend - Address) >> 2
511 static inline void
512 wdisp19(unsigned char* view,
513 const Sized_relobj<size, big_endian>* object,
514 const Symbol_value<size>* psymval,
515 typename elfcpp::Elf_types<size>::Elf_Addr addend,
516 typename elfcpp::Elf_types<size>::Elf_Addr address)
517 {
518 This_insn::template pcrela<32>(view, 2, 0x0007ffff, object,
519 psymval, addend, address);
520 }
521
522 // R_SPARC_WDISP16: (Symbol + Addend - Address) >> 2
523 static inline void
524 wdisp16(unsigned char* view,
525 const Sized_relobj<size, big_endian>* object,
526 const Symbol_value<size>* psymval,
527 typename elfcpp::Elf_types<size>::Elf_Addr addend,
528 typename elfcpp::Elf_types<size>::Elf_Addr address)
529 {
530 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
531 Valtype* wv = reinterpret_cast<Valtype*>(view);
532 Valtype val = elfcpp::Swap<32, true>::readval(wv);
533 Valtype reloc = ((psymval->value(object, addend) - address)
534 >> 2);
535
536 // The relocation value is split between the low 14 bits,
537 // and bits 20-21.
538 val &= ~((0x3 << 20) | 0x3fff);
539 reloc = (((reloc & 0xc000) << (20 - 14))
540 | (reloc & 0x3ffff));
541
542 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
543 }
544
545 // R_SPARC_PC22: (Symbol + Addend - Address) >> 10
546 static inline void
547 pc22(unsigned char* view,
548 const Sized_relobj<size, big_endian>* object,
549 const Symbol_value<size>* psymval,
550 typename elfcpp::Elf_types<size>::Elf_Addr addend,
551 typename elfcpp::Elf_types<size>::Elf_Addr address)
552 {
553 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
554 psymval, addend, address);
555 }
556
557 // R_SPARC_PC10: (Symbol + Addend - Address) & 0x3ff
558 static inline void
559 pc10(unsigned char* view,
560 const Sized_relobj<size, big_endian>* object,
561 const Symbol_value<size>* psymval,
562 typename elfcpp::Elf_types<size>::Elf_Addr addend,
563 typename elfcpp::Elf_types<size>::Elf_Addr address)
564 {
565 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
566 psymval, addend, address);
567 }
568
569 // R_SPARC_HI22: (Symbol + Addend) >> 10
570 static inline void
571 hi22(unsigned char* view,
572 typename elfcpp::Elf_types<size>::Elf_Addr value,
573 typename elfcpp::Elf_types<size>::Elf_Addr addend)
574 {
575 This_insn::template rela<32>(view, 10, 0x003fffff, value, addend);
576 }
577
578 // R_SPARC_HI22: (Symbol + Addend) >> 10
579 static inline void
580 hi22(unsigned char* view,
581 const Sized_relobj<size, big_endian>* object,
582 const Symbol_value<size>* psymval,
583 typename elfcpp::Elf_types<size>::Elf_Addr addend)
584 {
585 This_insn::template rela<32>(view, 10, 0x003fffff, object, psymval, addend);
586 }
587
588 // R_SPARC_PCPLT22: (Symbol + Addend - Address) >> 10
589 static inline void
590 pcplt22(unsigned char* view,
591 const Sized_relobj<size, big_endian>* object,
592 const Symbol_value<size>* psymval,
593 typename elfcpp::Elf_types<size>::Elf_Addr addend,
594 typename elfcpp::Elf_types<size>::Elf_Addr address)
595 {
596 This_insn::template pcrela<32>(view, 10, 0x003fffff, object,
597 psymval, addend, address);
598 }
599
600 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
601 static inline void
602 lo10(unsigned char* view,
603 typename elfcpp::Elf_types<size>::Elf_Addr value,
604 typename elfcpp::Elf_types<size>::Elf_Addr addend)
605 {
606 This_insn::template rela<32>(view, 0, 0x000003ff, value, addend);
607 }
608
609 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
610 static inline void
611 lo10(unsigned char* view,
612 const Sized_relobj<size, big_endian>* object,
613 const Symbol_value<size>* psymval,
614 typename elfcpp::Elf_types<size>::Elf_Addr addend)
615 {
616 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
617 }
618
619 // R_SPARC_LO10: (Symbol + Addend) & 0x3ff
620 static inline void
621 lo10(unsigned char* view,
622 const Sized_relobj<size, big_endian>* object,
623 const Symbol_value<size>* psymval,
624 typename elfcpp::Elf_types<size>::Elf_Addr addend,
625 typename elfcpp::Elf_types<size>::Elf_Addr address)
626 {
627 This_insn::template pcrela<32>(view, 0, 0x000003ff, object,
628 psymval, addend, address);
629 }
630
631 // R_SPARC_OLO10: ((Symbol + Addend) & 0x3ff) + Addend2
632 static inline void
633 olo10(unsigned char* view,
634 const Sized_relobj<size, big_endian>* object,
635 const Symbol_value<size>* psymval,
636 typename elfcpp::Elf_types<size>::Elf_Addr addend,
637 typename elfcpp::Elf_types<size>::Elf_Addr addend2)
638 {
639 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
640 Valtype* wv = reinterpret_cast<Valtype*>(view);
641 Valtype val = elfcpp::Swap<32, true>::readval(wv);
642 Valtype reloc = psymval->value(object, addend);
643
644 val &= ~0x1fff;
645 reloc &= 0x3ff;
646 reloc += addend2;
647 reloc &= 0x1fff;
648
649 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
650 }
651
652 // R_SPARC_22: (Symbol + Addend)
653 static inline void
654 rela32_22(unsigned char* view,
655 const Sized_relobj<size, big_endian>* object,
656 const Symbol_value<size>* psymval,
657 typename elfcpp::Elf_types<size>::Elf_Addr addend)
658 {
659 This_insn::template rela<32>(view, 0, 0x003fffff, object, psymval, addend);
660 }
661
662 // R_SPARC_13: (Symbol + Addend)
663 static inline void
664 rela32_13(unsigned char* view,
665 typename elfcpp::Elf_types<size>::Elf_Addr value,
666 typename elfcpp::Elf_types<size>::Elf_Addr addend)
667 {
668 This_insn::template rela<32>(view, 0, 0x00001fff, value, addend);
669 }
670
671 // R_SPARC_13: (Symbol + Addend)
672 static inline void
673 rela32_13(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)
677 {
678 This_insn::template rela<32>(view, 0, 0x00001fff, object, psymval, addend);
679 }
680
681 // R_SPARC_UA16: (Symbol + Addend)
682 static inline void
683 ua16(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)
687 {
688 This::template rela_ua<16>(view, 0, 0xffff, object, psymval, addend);
689 }
690
691 // R_SPARC_UA32: (Symbol + Addend)
692 static inline void
693 ua32(unsigned char* view,
694 const Sized_relobj<size, big_endian>* object,
695 const Symbol_value<size>* psymval,
696 typename elfcpp::Elf_types<size>::Elf_Addr addend)
697 {
698 This::template rela_ua<32>(view, 0, 0xffffffff, object, psymval, addend);
699 }
700
701 // R_SPARC_UA64: (Symbol + Addend)
702 static inline void
703 ua64(unsigned char* view,
704 const Sized_relobj<size, big_endian>* object,
705 const Symbol_value<size>* psymval,
706 typename elfcpp::Elf_types<size>::Elf_Addr addend)
707 {
708 This::template rela_ua<64>(view, 0, ~(elfcpp::Elf_Xword) 0,
709 object, psymval, addend);
710 }
711
712 // R_SPARC_DISP8: (Symbol + Addend - Address)
713 static inline void
714 disp8(unsigned char* view,
715 const Sized_relobj<size, big_endian>* object,
716 const Symbol_value<size>* psymval,
717 typename elfcpp::Elf_types<size>::Elf_Addr addend,
718 typename elfcpp::Elf_types<size>::Elf_Addr address)
719 {
720 This::template pcrela_unaligned<8>(view, object, psymval,
721 addend, address);
722 }
723
724 // R_SPARC_DISP16: (Symbol + Addend - Address)
725 static inline void
726 disp16(unsigned char* view,
727 const Sized_relobj<size, big_endian>* object,
728 const Symbol_value<size>* psymval,
729 typename elfcpp::Elf_types<size>::Elf_Addr addend,
730 typename elfcpp::Elf_types<size>::Elf_Addr address)
731 {
732 This::template pcrela_unaligned<16>(view, object, psymval,
733 addend, address);
734 }
735
736 // R_SPARC_DISP32: (Symbol + Addend - Address)
737 static inline void
738 disp32(unsigned char* view,
739 const Sized_relobj<size, big_endian>* object,
740 const Symbol_value<size>* psymval,
741 typename elfcpp::Elf_types<size>::Elf_Addr addend,
742 typename elfcpp::Elf_types<size>::Elf_Addr address)
743 {
744 This::template pcrela_unaligned<32>(view, object, psymval,
745 addend, address);
746 }
747
748 // R_SPARC_DISP64: (Symbol + Addend - Address)
749 static inline void
750 disp64(unsigned char* view,
751 const Sized_relobj<size, big_endian>* object,
752 const Symbol_value<size>* psymval,
753 elfcpp::Elf_Xword addend,
754 typename elfcpp::Elf_types<size>::Elf_Addr address)
755 {
756 This::template pcrela_unaligned<64>(view, object, psymval,
757 addend, address);
758 }
759
760 // R_SPARC_H44: (Symbol + Addend) >> 22
761 static inline void
762 h44(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)
766 {
767 This_insn::template rela<32>(view, 22, 0x003fffff, object, psymval, addend);
768 }
769
770 // R_SPARC_M44: ((Symbol + Addend) >> 12) & 0x3ff
771 static inline void
772 m44(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)
776 {
777 This_insn::template rela<32>(view, 12, 0x000003ff, object, psymval, addend);
778 }
779
780 // R_SPARC_L44: (Symbol + Addend) & 0xfff
781 static inline void
782 l44(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 {
787 This_insn::template rela<32>(view, 0, 0x00000fff, object, psymval, addend);
788 }
789
790 // R_SPARC_HH22: (Symbol + Addend) >> 42
791 static inline void
792 hh22(unsigned char* view,
793 const Sized_relobj<size, big_endian>* object,
794 const Symbol_value<size>* psymval,
795 typename elfcpp::Elf_types<size>::Elf_Addr addend)
796 {
797 This_insn::template rela<32>(view, 42, 0x003fffff, object, psymval, addend);
798 }
799
800 // R_SPARC_PC_HH22: (Symbol + Addend - Address) >> 42
801 static inline void
802 pc_hh22(unsigned char* view,
803 const Sized_relobj<size, big_endian>* object,
804 const Symbol_value<size>* psymval,
805 typename elfcpp::Elf_types<size>::Elf_Addr addend,
806 typename elfcpp::Elf_types<size>::Elf_Addr address)
807 {
808 This_insn::template pcrela<32>(view, 42, 0x003fffff, object,
809 psymval, addend, address);
810 }
811
812 // R_SPARC_HM10: ((Symbol + Addend) >> 32) & 0x3ff
813 static inline void
814 hm10(unsigned char* view,
815 const Sized_relobj<size, big_endian>* object,
816 const Symbol_value<size>* psymval,
817 typename elfcpp::Elf_types<size>::Elf_Addr addend)
818 {
819 This_insn::template rela<32>(view, 32, 0x000003ff, object, psymval, addend);
820 }
821
822 // R_SPARC_PC_HM10: ((Symbol + Addend - Address) >> 32) & 0x3ff
823 static inline void
824 pc_hm10(unsigned char* view,
825 const Sized_relobj<size, big_endian>* object,
826 const Symbol_value<size>* psymval,
827 typename elfcpp::Elf_types<size>::Elf_Addr addend,
828 typename elfcpp::Elf_types<size>::Elf_Addr address)
829 {
830 This_insn::template pcrela<32>(view, 32, 0x000003ff, object,
831 psymval, addend, address);
832 }
833
834 // R_SPARC_11: (Symbol + Addend)
835 static inline void
836 rela32_11(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)
840 {
841 This_insn::template rela<32>(view, 0, 0x000007ff, object, psymval, addend);
842 }
843
844 // R_SPARC_10: (Symbol + Addend)
845 static inline void
846 rela32_10(unsigned char* view,
847 const Sized_relobj<size, big_endian>* object,
848 const Symbol_value<size>* psymval,
849 typename elfcpp::Elf_types<size>::Elf_Addr addend)
850 {
851 This_insn::template rela<32>(view, 0, 0x000003ff, object, psymval, addend);
852 }
853
854 // R_SPARC_7: (Symbol + Addend)
855 static inline void
856 rela32_7(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)
860 {
861 This_insn::template rela<32>(view, 0, 0x0000007f, object, psymval, addend);
862 }
863
864 // R_SPARC_6: (Symbol + Addend)
865 static inline void
866 rela32_6(unsigned char* view,
867 const Sized_relobj<size, big_endian>* object,
868 const Symbol_value<size>* psymval,
869 typename elfcpp::Elf_types<size>::Elf_Addr addend)
870 {
871 This_insn::template rela<32>(view, 0, 0x0000003f, object, psymval, addend);
872 }
873
874 // R_SPARC_5: (Symbol + Addend)
875 static inline void
876 rela32_5(unsigned char* view,
877 const Sized_relobj<size, big_endian>* object,
878 const Symbol_value<size>* psymval,
879 typename elfcpp::Elf_types<size>::Elf_Addr addend)
880 {
881 This_insn::template rela<32>(view, 0, 0x0000001f, object, psymval, addend);
882 }
883
884 // R_SPARC_TLS_LDO_HIX22: @dtpoff(Symbol + Addend) >> 10
885 static inline void
886 ldo_hix22(unsigned char* view,
887 typename elfcpp::Elf_types<size>::Elf_Addr value,
888 typename elfcpp::Elf_types<size>::Elf_Addr addend)
889 {
890 This_insn::hi22(view, value, addend);
891 }
892
893 // R_SPARC_TLS_LDO_LOX10: @dtpoff(Symbol + Addend) & 0x3ff
894 static inline void
895 ldo_lox10(unsigned char* view,
896 typename elfcpp::Elf_types<size>::Elf_Addr value,
897 typename elfcpp::Elf_types<size>::Elf_Addr addend)
898 {
899 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
900 Valtype* wv = reinterpret_cast<Valtype*>(view);
901 Valtype val = elfcpp::Swap<32, true>::readval(wv);
902 Valtype reloc = (value + addend);
903
904 val &= ~0x1fff;
905 reloc &= 0x3ff;
906
907 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
908 }
909
910 // R_SPARC_TLS_LE_HIX22: (@tpoff(Symbol + Addend) ^ 0xffffffffffffffff) >> 10
911 static inline void
912 hix22(unsigned char* view,
913 typename elfcpp::Elf_types<size>::Elf_Addr value,
914 typename elfcpp::Elf_types<size>::Elf_Addr addend)
915 {
916 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
917 Valtype* wv = reinterpret_cast<Valtype*>(view);
918 Valtype val = elfcpp::Swap<32, true>::readval(wv);
919 Valtype reloc = (value + addend);
920
921 val &= ~0x3fffff;
922
923 reloc ^= ~(Valtype)0;
924 reloc >>= 10;
925
926 reloc &= 0x3fffff;
927
928 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
929 }
930
931 // R_SPARC_HIX22: ((Symbol + Addend) ^ 0xffffffffffffffff) >> 10
932 static inline void
933 hix22(unsigned char* view,
934 const Sized_relobj<size, big_endian>* object,
935 const Symbol_value<size>* psymval,
936 typename elfcpp::Elf_types<size>::Elf_Addr addend)
937 {
938 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
939 Valtype* wv = reinterpret_cast<Valtype*>(view);
940 Valtype val = elfcpp::Swap<32, true>::readval(wv);
941 Valtype reloc = psymval->value(object, addend);
942
943 val &= ~0x3fffff;
944
945 reloc ^= ~(Valtype)0;
946 reloc >>= 10;
947
948 reloc &= 0x3fffff;
949
950 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
951 }
952
953
954 // R_SPARC_TLS_LE_LOX10: (@tpoff(Symbol + Addend) & 0x3ff) | 0x1c00
955 static inline void
956 lox10(unsigned char* view,
957 typename elfcpp::Elf_types<size>::Elf_Addr value,
958 typename elfcpp::Elf_types<size>::Elf_Addr addend)
959 {
960 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
961 Valtype* wv = reinterpret_cast<Valtype*>(view);
962 Valtype val = elfcpp::Swap<32, true>::readval(wv);
963 Valtype reloc = (value + addend);
964
965 val &= ~0x1fff;
966 reloc &= 0x3ff;
967 reloc |= 0x1c00;
968
969 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
970 }
971
972 // R_SPARC_LOX10: ((Symbol + Addend) & 0x3ff) | 0x1c00
973 static inline void
974 lox10(unsigned char* view,
975 const Sized_relobj<size, big_endian>* object,
976 const Symbol_value<size>* psymval,
977 typename elfcpp::Elf_types<size>::Elf_Addr addend)
978 {
979 typedef typename elfcpp::Swap<32, true>::Valtype Valtype;
980 Valtype* wv = reinterpret_cast<Valtype*>(view);
981 Valtype val = elfcpp::Swap<32, true>::readval(wv);
982 Valtype reloc = psymval->value(object, addend);
983
984 val &= ~0x1fff;
985 reloc &= 0x3ff;
986 reloc |= 0x1c00;
987
988 elfcpp::Swap<32, true>::writeval(wv, val | reloc);
989 }
990 };
991
992 // Get the GOT section, creating it if necessary.
993
994 template<int size, bool big_endian>
995 Output_data_got<size, big_endian>*
996 Target_sparc<size, big_endian>::got_section(Symbol_table* symtab,
997 Layout* layout)
998 {
999 if (this->got_ == NULL)
1000 {
1001 gold_assert(symtab != NULL && layout != NULL);
1002
1003 this->got_ = new Output_data_got<size, big_endian>();
1004
1005 Output_section* os;
1006 os = layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1007 (elfcpp::SHF_ALLOC
1008 | elfcpp::SHF_WRITE),
1009 this->got_);
1010 os->set_is_relro();
1011
1012 // Define _GLOBAL_OFFSET_TABLE_ at the start of the .got section.
1013 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1014 this->got_,
1015 0, 0, elfcpp::STT_OBJECT,
1016 elfcpp::STB_LOCAL,
1017 elfcpp::STV_HIDDEN, 0,
1018 false, false);
1019 }
1020
1021 return this->got_;
1022 }
1023
1024 // Get the dynamic reloc section, creating it if necessary.
1025
1026 template<int size, bool big_endian>
1027 typename Target_sparc<size, big_endian>::Reloc_section*
1028 Target_sparc<size, big_endian>::rela_dyn_section(Layout* layout)
1029 {
1030 if (this->rela_dyn_ == NULL)
1031 {
1032 gold_assert(layout != NULL);
1033 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1034 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1035 elfcpp::SHF_ALLOC, this->rela_dyn_);
1036 }
1037 return this->rela_dyn_;
1038 }
1039
1040 // A class to handle the PLT data.
1041
1042 template<int size, bool big_endian>
1043 class Output_data_plt_sparc : public Output_section_data
1044 {
1045 public:
1046 typedef Output_data_reloc<elfcpp::SHT_RELA, true,
1047 size, big_endian> Reloc_section;
1048
1049 Output_data_plt_sparc(Layout*);
1050
1051 // Add an entry to the PLT.
1052 void add_entry(Symbol* gsym);
1053
1054 // Return the .rela.plt section data.
1055 const Reloc_section* rel_plt() const
1056 {
1057 return this->rel_;
1058 }
1059
1060 protected:
1061 void do_adjust_output_section(Output_section* os);
1062
1063 // Write to a map file.
1064 void
1065 do_print_to_mapfile(Mapfile* mapfile) const
1066 { mapfile->print_output_data(this, _("** PLT")); }
1067
1068 private:
1069 // The size of an entry in the PLT.
1070 static const int base_plt_entry_size = (size == 32 ? 12 : 32);
1071
1072 static const unsigned int plt_entries_per_block = 160;
1073 static const unsigned int plt_insn_chunk_size = 24;
1074 static const unsigned int plt_pointer_chunk_size = 8;
1075 static const unsigned int plt_block_size =
1076 (plt_entries_per_block
1077 * (plt_insn_chunk_size + plt_pointer_chunk_size));
1078
1079 // Set the final size.
1080 void
1081 set_final_data_size()
1082 {
1083 unsigned int full_count = this->count_ + 4;
1084 unsigned int extra = (size == 32 ? 4 : 0);
1085
1086 if (size == 32 || full_count < 32768)
1087 this->set_data_size((full_count * base_plt_entry_size) + extra);
1088 else
1089 {
1090 unsigned int ext_cnt = full_count - 32768;
1091
1092 this->set_data_size((32768 * base_plt_entry_size)
1093 + (ext_cnt
1094 * (plt_insn_chunk_size
1095 + plt_pointer_chunk_size)));
1096 }
1097 }
1098
1099 // Write out the PLT data.
1100 void
1101 do_write(Output_file*);
1102
1103 // The reloc section.
1104 Reloc_section* rel_;
1105 // The number of PLT entries.
1106 unsigned int count_;
1107 };
1108
1109 // Define the constants as required by C++ standard.
1110
1111 template<int size, bool big_endian>
1112 const int Output_data_plt_sparc<size, big_endian>::base_plt_entry_size;
1113
1114 template<int size, bool big_endian>
1115 const unsigned int
1116 Output_data_plt_sparc<size, big_endian>::plt_entries_per_block;
1117
1118 template<int size, bool big_endian>
1119 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_insn_chunk_size;
1120
1121 template<int size, bool big_endian>
1122 const unsigned int
1123 Output_data_plt_sparc<size, big_endian>::plt_pointer_chunk_size;
1124
1125 template<int size, bool big_endian>
1126 const unsigned int Output_data_plt_sparc<size, big_endian>::plt_block_size;
1127
1128 // Create the PLT section. The ordinary .got section is an argument,
1129 // since we need to refer to the start.
1130
1131 template<int size, bool big_endian>
1132 Output_data_plt_sparc<size, big_endian>::Output_data_plt_sparc(Layout* layout)
1133 : Output_section_data(size == 32 ? 4 : 8), count_(0)
1134 {
1135 this->rel_ = new Reloc_section(false);
1136 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1137 elfcpp::SHF_ALLOC, this->rel_);
1138 }
1139
1140 template<int size, bool big_endian>
1141 void
1142 Output_data_plt_sparc<size, big_endian>::do_adjust_output_section(Output_section* os)
1143 {
1144 os->set_entsize(0);
1145 }
1146
1147 // Add an entry to the PLT.
1148
1149 template<int size, bool big_endian>
1150 void
1151 Output_data_plt_sparc<size, big_endian>::add_entry(Symbol* gsym)
1152 {
1153 gold_assert(!gsym->has_plt_offset());
1154
1155 unsigned int index = this->count_ + 4;
1156 section_offset_type plt_offset;
1157
1158 if (size == 32 || index < 32768)
1159 plt_offset = index * base_plt_entry_size;
1160 else
1161 {
1162 unsigned int ext_index = index - 32768;
1163
1164 plt_offset = (32768 * base_plt_entry_size)
1165 + ((ext_index / plt_entries_per_block)
1166 * plt_block_size)
1167 + ((ext_index % plt_entries_per_block)
1168 * plt_insn_chunk_size);
1169 }
1170
1171 gsym->set_plt_offset(plt_offset);
1172
1173 ++this->count_;
1174
1175 // Every PLT entry needs a reloc.
1176 gsym->set_needs_dynsym_entry();
1177 this->rel_->add_global(gsym, elfcpp::R_SPARC_JMP_SLOT, this,
1178 plt_offset, 0);
1179
1180 // Note that we don't need to save the symbol. The contents of the
1181 // PLT are independent of which symbols are used. The symbols only
1182 // appear in the relocations.
1183 }
1184
1185 static const unsigned int sparc_nop = 0x01000000;
1186 static const unsigned int sparc_sethi_g1 = 0x03000000;
1187 static const unsigned int sparc_branch_always = 0x30800000;
1188 static const unsigned int sparc_branch_always_pt = 0x30680000;
1189 static const unsigned int sparc_mov = 0x80100000;
1190 static const unsigned int sparc_mov_g0_o0 = 0x90100000;
1191 static const unsigned int sparc_mov_o7_g5 = 0x8a10000f;
1192 static const unsigned int sparc_call_plus_8 = 0x40000002;
1193 static const unsigned int sparc_ldx_o7_imm_g1 = 0xc25be000;
1194 static const unsigned int sparc_jmpl_o7_g1_g1 = 0x83c3c001;
1195 static const unsigned int sparc_mov_g5_o7 = 0x9e100005;
1196
1197 // Write out the PLT.
1198
1199 template<int size, bool big_endian>
1200 void
1201 Output_data_plt_sparc<size, big_endian>::do_write(Output_file* of)
1202 {
1203 const off_t offset = this->offset();
1204 const section_size_type oview_size =
1205 convert_to_section_size_type(this->data_size());
1206 unsigned char* const oview = of->get_output_view(offset, oview_size);
1207 unsigned char* pov = oview;
1208
1209 memset(pov, 0, base_plt_entry_size * 4);
1210 pov += base_plt_entry_size * 4;
1211
1212 unsigned int plt_offset = base_plt_entry_size * 4;
1213 const unsigned int count = this->count_;
1214
1215 if (size == 64)
1216 {
1217 unsigned int limit;
1218
1219 limit = (count > 32768 ? 32768 : count);
1220
1221 for (unsigned int i = 0; i < limit; ++i)
1222 {
1223 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1224 sparc_sethi_g1 + plt_offset);
1225 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1226 sparc_branch_always_pt +
1227 (((base_plt_entry_size -
1228 (plt_offset + 4)) >> 2) &
1229 0x7ffff));
1230 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1231 elfcpp::Swap<32, true>::writeval(pov + 0x0c, sparc_nop);
1232 elfcpp::Swap<32, true>::writeval(pov + 0x10, sparc_nop);
1233 elfcpp::Swap<32, true>::writeval(pov + 0x14, sparc_nop);
1234 elfcpp::Swap<32, true>::writeval(pov + 0x18, sparc_nop);
1235 elfcpp::Swap<32, true>::writeval(pov + 0x1c, sparc_nop);
1236
1237 pov += base_plt_entry_size;
1238 plt_offset += base_plt_entry_size;
1239 }
1240
1241 if (count > 32768)
1242 {
1243 unsigned int ext_cnt = count - 32768;
1244 unsigned int blks = ext_cnt / plt_entries_per_block;
1245
1246 for (unsigned int i = 0; i < blks; ++i)
1247 {
1248 unsigned int data_off = (plt_entries_per_block
1249 * plt_insn_chunk_size) - 4;
1250
1251 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1252 {
1253 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1254 sparc_mov_o7_g5);
1255 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1256 sparc_call_plus_8);
1257 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1258 sparc_nop);
1259 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1260 sparc_ldx_o7_imm_g1 +
1261 (data_off & 0x1fff));
1262 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1263 sparc_jmpl_o7_g1_g1);
1264 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1265 sparc_mov_g5_o7);
1266
1267 elfcpp::Swap<64, big_endian>::writeval(
1268 pov + 0x4 + data_off,
1269 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1270
1271 pov += plt_insn_chunk_size;
1272 data_off -= 16;
1273 }
1274 }
1275
1276 unsigned int sub_blk_cnt = ext_cnt % plt_entries_per_block;
1277 for (unsigned int i = 0; i < sub_blk_cnt; ++i)
1278 {
1279 unsigned int data_off = (sub_blk_cnt
1280 * plt_insn_chunk_size) - 4;
1281
1282 for (unsigned int j = 0; j < plt_entries_per_block; ++j)
1283 {
1284 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1285 sparc_mov_o7_g5);
1286 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1287 sparc_call_plus_8);
1288 elfcpp::Swap<32, true>::writeval(pov + 0x08,
1289 sparc_nop);
1290 elfcpp::Swap<32, true>::writeval(pov + 0x0c,
1291 sparc_ldx_o7_imm_g1 +
1292 (data_off & 0x1fff));
1293 elfcpp::Swap<32, true>::writeval(pov + 0x10,
1294 sparc_jmpl_o7_g1_g1);
1295 elfcpp::Swap<32, true>::writeval(pov + 0x14,
1296 sparc_mov_g5_o7);
1297
1298 elfcpp::Swap<64, big_endian>::writeval(
1299 pov + 0x4 + data_off,
1300 (elfcpp::Elf_Xword) (oview - (pov + 0x04)));
1301
1302 pov += plt_insn_chunk_size;
1303 data_off -= 16;
1304 }
1305 }
1306 }
1307 }
1308 else
1309 {
1310 for (unsigned int i = 0; i < count; ++i)
1311 {
1312 elfcpp::Swap<32, true>::writeval(pov + 0x00,
1313 sparc_sethi_g1 + plt_offset);
1314 elfcpp::Swap<32, true>::writeval(pov + 0x04,
1315 sparc_branch_always +
1316 (((- (plt_offset + 4)) >> 2) &
1317 0x003fffff));
1318 elfcpp::Swap<32, true>::writeval(pov + 0x08, sparc_nop);
1319
1320 pov += base_plt_entry_size;
1321 plt_offset += base_plt_entry_size;
1322 }
1323
1324 elfcpp::Swap<32, true>::writeval(pov, sparc_nop);
1325 pov += 4;
1326 }
1327
1328 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
1329
1330 of->write_output_view(offset, oview_size, oview);
1331 }
1332
1333 // Create a PLT entry for a global symbol.
1334
1335 template<int size, bool big_endian>
1336 void
1337 Target_sparc<size, big_endian>::make_plt_entry(Symbol_table* symtab,
1338 Layout* layout,
1339 Symbol* gsym)
1340 {
1341 if (gsym->has_plt_offset())
1342 return;
1343
1344 if (this->plt_ == NULL)
1345 {
1346 // Create the GOT sections first.
1347 this->got_section(symtab, layout);
1348
1349 this->plt_ = new Output_data_plt_sparc<size, big_endian>(layout);
1350 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
1351 (elfcpp::SHF_ALLOC
1352 | elfcpp::SHF_EXECINSTR
1353 | elfcpp::SHF_WRITE),
1354 this->plt_);
1355
1356 // Define _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section.
1357 symtab->define_in_output_data("_PROCEDURE_LINKAGE_TABLE_", NULL,
1358 this->plt_,
1359 0, 0, elfcpp::STT_OBJECT,
1360 elfcpp::STB_LOCAL,
1361 elfcpp::STV_HIDDEN, 0,
1362 false, false);
1363 }
1364
1365 this->plt_->add_entry(gsym);
1366 }
1367
1368 // Create a GOT entry for the TLS module index.
1369
1370 template<int size, bool big_endian>
1371 unsigned int
1372 Target_sparc<size, big_endian>::got_mod_index_entry(Symbol_table* symtab,
1373 Layout* layout,
1374 Sized_relobj<size, big_endian>* object)
1375 {
1376 if (this->got_mod_index_offset_ == -1U)
1377 {
1378 gold_assert(symtab != NULL && layout != NULL && object != NULL);
1379 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1380 Output_data_got<size, big_endian>* got;
1381 unsigned int got_offset;
1382
1383 got = this->got_section(symtab, layout);
1384 got_offset = got->add_constant(0);
1385 rela_dyn->add_local(object, 0,
1386 (size == 64 ?
1387 elfcpp::R_SPARC_TLS_DTPMOD64 :
1388 elfcpp::R_SPARC_TLS_DTPMOD32), got,
1389 got_offset, 0);
1390 got->add_constant(0);
1391 this->got_mod_index_offset_ = got_offset;
1392 }
1393 return this->got_mod_index_offset_;
1394 }
1395
1396 // Optimize the TLS relocation type based on what we know about the
1397 // symbol. IS_FINAL is true if the final address of this symbol is
1398 // known at link time.
1399
1400 static tls::Tls_optimization
1401 optimize_tls_reloc(bool is_final, int r_type)
1402 {
1403 // If we are generating a shared library, then we can't do anything
1404 // in the linker.
1405 if (parameters->options().shared())
1406 return tls::TLSOPT_NONE;
1407
1408 switch (r_type)
1409 {
1410 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1411 case elfcpp::R_SPARC_TLS_GD_LO10:
1412 case elfcpp::R_SPARC_TLS_GD_ADD:
1413 case elfcpp::R_SPARC_TLS_GD_CALL:
1414 // These are General-Dynamic which permits fully general TLS
1415 // access. Since we know that we are generating an executable,
1416 // we can convert this to Initial-Exec. If we also know that
1417 // this is a local symbol, we can further switch to Local-Exec.
1418 if (is_final)
1419 return tls::TLSOPT_TO_LE;
1420 return tls::TLSOPT_TO_IE;
1421
1422 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
1423 case elfcpp::R_SPARC_TLS_LDM_LO10:
1424 case elfcpp::R_SPARC_TLS_LDM_ADD:
1425 case elfcpp::R_SPARC_TLS_LDM_CALL:
1426 // This is Local-Dynamic, which refers to a local symbol in the
1427 // dynamic TLS block. Since we know that we generating an
1428 // executable, we can switch to Local-Exec.
1429 return tls::TLSOPT_TO_LE;
1430
1431 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1432 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1433 case elfcpp::R_SPARC_TLS_LDO_ADD:
1434 // Another type of Local-Dynamic relocation.
1435 return tls::TLSOPT_TO_LE;
1436
1437 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1438 case elfcpp::R_SPARC_TLS_IE_LO10:
1439 case elfcpp::R_SPARC_TLS_IE_LD:
1440 case elfcpp::R_SPARC_TLS_IE_LDX:
1441 // These are Initial-Exec relocs which get the thread offset
1442 // from the GOT. If we know that we are linking against the
1443 // local symbol, we can switch to Local-Exec, which links the
1444 // thread offset into the instruction.
1445 if (is_final)
1446 return tls::TLSOPT_TO_LE;
1447 return tls::TLSOPT_NONE;
1448
1449 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1450 case elfcpp::R_SPARC_TLS_LE_LOX10:
1451 // When we already have Local-Exec, there is nothing further we
1452 // can do.
1453 return tls::TLSOPT_NONE;
1454
1455 default:
1456 gold_unreachable();
1457 }
1458 }
1459
1460 // Generate a PLT entry slot for a call to __tls_get_addr
1461 template<int size, bool big_endian>
1462 void
1463 Target_sparc<size, big_endian>::Scan::generate_tls_call(Symbol_table* symtab,
1464 Layout* layout,
1465 Target_sparc<size, big_endian>* target)
1466 {
1467 Symbol* gsym = target->tls_get_addr_sym(symtab);
1468
1469 target->make_plt_entry(symtab, layout, gsym);
1470 }
1471
1472 // Report an unsupported relocation against a local symbol.
1473
1474 template<int size, bool big_endian>
1475 void
1476 Target_sparc<size, big_endian>::Scan::unsupported_reloc_local(
1477 Sized_relobj<size, big_endian>* object,
1478 unsigned int r_type)
1479 {
1480 gold_error(_("%s: unsupported reloc %u against local symbol"),
1481 object->name().c_str(), r_type);
1482 }
1483
1484 // We are about to emit a dynamic relocation of type R_TYPE. If the
1485 // dynamic linker does not support it, issue an error.
1486
1487 template<int size, bool big_endian>
1488 void
1489 Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object, unsigned int r_type)
1490 {
1491 gold_assert(r_type != elfcpp::R_SPARC_NONE);
1492
1493 if (size == 64)
1494 {
1495 switch (r_type)
1496 {
1497 // These are the relocation types supported by glibc for sparc 64-bit.
1498 case elfcpp::R_SPARC_RELATIVE:
1499 case elfcpp::R_SPARC_COPY:
1500 case elfcpp::R_SPARC_64:
1501 case elfcpp::R_SPARC_GLOB_DAT:
1502 case elfcpp::R_SPARC_JMP_SLOT:
1503 case elfcpp::R_SPARC_TLS_DTPMOD64:
1504 case elfcpp::R_SPARC_TLS_DTPOFF64:
1505 case elfcpp::R_SPARC_TLS_TPOFF64:
1506 case elfcpp::R_SPARC_TLS_LE_HIX22:
1507 case elfcpp::R_SPARC_TLS_LE_LOX10:
1508 case elfcpp::R_SPARC_8:
1509 case elfcpp::R_SPARC_16:
1510 case elfcpp::R_SPARC_DISP8:
1511 case elfcpp::R_SPARC_DISP16:
1512 case elfcpp::R_SPARC_DISP32:
1513 case elfcpp::R_SPARC_WDISP30:
1514 case elfcpp::R_SPARC_LO10:
1515 case elfcpp::R_SPARC_HI22:
1516 case elfcpp::R_SPARC_OLO10:
1517 case elfcpp::R_SPARC_H44:
1518 case elfcpp::R_SPARC_M44:
1519 case elfcpp::R_SPARC_L44:
1520 case elfcpp::R_SPARC_HH22:
1521 case elfcpp::R_SPARC_HM10:
1522 case elfcpp::R_SPARC_LM22:
1523 case elfcpp::R_SPARC_UA16:
1524 case elfcpp::R_SPARC_UA32:
1525 case elfcpp::R_SPARC_UA64:
1526 return;
1527
1528 default:
1529 break;
1530 }
1531 }
1532 else
1533 {
1534 switch (r_type)
1535 {
1536 // These are the relocation types supported by glibc for sparc 32-bit.
1537 case elfcpp::R_SPARC_RELATIVE:
1538 case elfcpp::R_SPARC_COPY:
1539 case elfcpp::R_SPARC_GLOB_DAT:
1540 case elfcpp::R_SPARC_32:
1541 case elfcpp::R_SPARC_JMP_SLOT:
1542 case elfcpp::R_SPARC_TLS_DTPMOD32:
1543 case elfcpp::R_SPARC_TLS_DTPOFF32:
1544 case elfcpp::R_SPARC_TLS_TPOFF32:
1545 case elfcpp::R_SPARC_TLS_LE_HIX22:
1546 case elfcpp::R_SPARC_TLS_LE_LOX10:
1547 case elfcpp::R_SPARC_8:
1548 case elfcpp::R_SPARC_16:
1549 case elfcpp::R_SPARC_DISP8:
1550 case elfcpp::R_SPARC_DISP16:
1551 case elfcpp::R_SPARC_DISP32:
1552 case elfcpp::R_SPARC_LO10:
1553 case elfcpp::R_SPARC_WDISP30:
1554 case elfcpp::R_SPARC_HI22:
1555 case elfcpp::R_SPARC_UA16:
1556 case elfcpp::R_SPARC_UA32:
1557 return;
1558
1559 default:
1560 break;
1561 }
1562 }
1563
1564 // This prevents us from issuing more than one error per reloc
1565 // section. But we can still wind up issuing more than one
1566 // error per object file.
1567 if (this->issued_non_pic_error_)
1568 return;
1569 object->error(_("requires unsupported dynamic reloc; "
1570 "recompile with -fPIC"));
1571 this->issued_non_pic_error_ = true;
1572 return;
1573 }
1574
1575 // Scan a relocation for a local symbol.
1576
1577 template<int size, bool big_endian>
1578 inline void
1579 Target_sparc<size, big_endian>::Scan::local(
1580 const General_options&,
1581 Symbol_table* symtab,
1582 Layout* layout,
1583 Target_sparc<size, big_endian>* target,
1584 Sized_relobj<size, big_endian>* object,
1585 unsigned int data_shndx,
1586 Output_section* output_section,
1587 const elfcpp::Rela<size, big_endian>& reloc,
1588 unsigned int r_type,
1589 const elfcpp::Sym<size, big_endian>& lsym)
1590 {
1591 unsigned int orig_r_type = r_type;
1592
1593 r_type &= 0xff;
1594 switch (r_type)
1595 {
1596 case elfcpp::R_SPARC_NONE:
1597 case elfcpp::R_SPARC_REGISTER:
1598 case elfcpp::R_SPARC_GNU_VTINHERIT:
1599 case elfcpp::R_SPARC_GNU_VTENTRY:
1600 break;
1601
1602 case elfcpp::R_SPARC_64:
1603 case elfcpp::R_SPARC_32:
1604 // If building a shared library (or a position-independent
1605 // executable), we need to create a dynamic relocation for
1606 // this location. The relocation applied at link time will
1607 // apply the link-time value, so we flag the location with
1608 // an R_SPARC_RELATIVE relocation so the dynamic loader can
1609 // relocate it easily.
1610 if (parameters->options().output_is_position_independent())
1611 {
1612 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1613 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1614 rela_dyn->add_local_relative(object, r_sym, elfcpp::R_SPARC_RELATIVE,
1615 output_section, data_shndx,
1616 reloc.get_r_offset(),
1617 reloc.get_r_addend());
1618 }
1619 break;
1620
1621 case elfcpp::R_SPARC_HIX22:
1622 case elfcpp::R_SPARC_LOX10:
1623 case elfcpp::R_SPARC_H44:
1624 case elfcpp::R_SPARC_M44:
1625 case elfcpp::R_SPARC_L44:
1626 case elfcpp::R_SPARC_HH22:
1627 case elfcpp::R_SPARC_HM10:
1628 case elfcpp::R_SPARC_LM22:
1629 case elfcpp::R_SPARC_UA64:
1630 case elfcpp::R_SPARC_UA32:
1631 case elfcpp::R_SPARC_UA16:
1632 case elfcpp::R_SPARC_HI22:
1633 case elfcpp::R_SPARC_LO10:
1634 case elfcpp::R_SPARC_OLO10:
1635 case elfcpp::R_SPARC_16:
1636 case elfcpp::R_SPARC_11:
1637 case elfcpp::R_SPARC_10:
1638 case elfcpp::R_SPARC_8:
1639 case elfcpp::R_SPARC_7:
1640 case elfcpp::R_SPARC_6:
1641 case elfcpp::R_SPARC_5:
1642 // If building a shared library (or a position-independent
1643 // executable), we need to create a dynamic relocation for
1644 // this location.
1645 if (parameters->options().output_is_position_independent())
1646 {
1647 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1648
1649 check_non_pic(object, r_type);
1650 if (lsym.get_st_type() != elfcpp::STT_SECTION)
1651 {
1652 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1653 rela_dyn->add_local(object, r_sym, orig_r_type, output_section,
1654 data_shndx, reloc.get_r_offset(),
1655 reloc.get_r_addend());
1656 }
1657 else
1658 {
1659 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1660 gold_assert(lsym.get_st_value() == 0);
1661 rela_dyn->add_local_relative(object, r_sym, orig_r_type,
1662 output_section, data_shndx,
1663 reloc.get_r_offset(),
1664 reloc.get_r_addend());
1665 }
1666 }
1667 break;
1668
1669 case elfcpp::R_SPARC_WDISP30:
1670 case elfcpp::R_SPARC_WDISP22:
1671 case elfcpp::R_SPARC_WDISP19:
1672 case elfcpp::R_SPARC_WDISP16:
1673 case elfcpp::R_SPARC_DISP8:
1674 case elfcpp::R_SPARC_DISP16:
1675 case elfcpp::R_SPARC_DISP32:
1676 case elfcpp::R_SPARC_DISP64:
1677 case elfcpp::R_SPARC_PC10:
1678 case elfcpp::R_SPARC_PC22:
1679 break;
1680
1681 case elfcpp::R_SPARC_GOT10:
1682 case elfcpp::R_SPARC_GOT13:
1683 case elfcpp::R_SPARC_GOT22:
1684 {
1685 // The symbol requires a GOT entry.
1686 Output_data_got<size, big_endian>* got;
1687 unsigned int r_sym;
1688
1689 got = target->got_section(symtab, layout);
1690 r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1691
1692 // If we are generating a shared object, we need to add a
1693 // dynamic relocation for this symbol's GOT entry.
1694 if (parameters->options().output_is_position_independent())
1695 {
1696 if (!object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD))
1697 {
1698 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1699 unsigned int off;
1700
1701 off = got->add_constant(0);
1702 object->set_local_got_offset(r_sym, GOT_TYPE_STANDARD, off);
1703 rela_dyn->add_local_relative(object, r_sym,
1704 elfcpp::R_SPARC_RELATIVE,
1705 got, off, 0);
1706 }
1707 }
1708 else
1709 got->add_local(object, r_sym, GOT_TYPE_STANDARD);
1710 }
1711 break;
1712
1713 // These are initial TLS relocs, which are expected when
1714 // linking.
1715 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1716 case elfcpp::R_SPARC_TLS_GD_LO10:
1717 case elfcpp::R_SPARC_TLS_GD_ADD:
1718 case elfcpp::R_SPARC_TLS_GD_CALL:
1719 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
1720 case elfcpp::R_SPARC_TLS_LDM_LO10:
1721 case elfcpp::R_SPARC_TLS_LDM_ADD:
1722 case elfcpp::R_SPARC_TLS_LDM_CALL:
1723 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1724 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1725 case elfcpp::R_SPARC_TLS_LDO_ADD:
1726 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1727 case elfcpp::R_SPARC_TLS_IE_LO10:
1728 case elfcpp::R_SPARC_TLS_IE_LD:
1729 case elfcpp::R_SPARC_TLS_IE_LDX:
1730 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1731 case elfcpp::R_SPARC_TLS_LE_LOX10:
1732 {
1733 bool output_is_shared = parameters->options().shared();
1734 const tls::Tls_optimization optimized_type
1735 = optimize_tls_reloc(!output_is_shared, r_type);
1736 switch (r_type)
1737 {
1738 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
1739 case elfcpp::R_SPARC_TLS_GD_LO10:
1740 case elfcpp::R_SPARC_TLS_GD_ADD:
1741 case elfcpp::R_SPARC_TLS_GD_CALL:
1742 if (optimized_type == tls::TLSOPT_NONE)
1743 {
1744 // Create a pair of GOT entries for the module index and
1745 // dtv-relative offset.
1746 Output_data_got<size, big_endian>* got
1747 = target->got_section(symtab, layout);
1748 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1749 unsigned int shndx = lsym.get_st_shndx();
1750 bool is_ordinary;
1751 shndx = object->adjust_sym_shndx(r_sym, shndx, &is_ordinary);
1752 if (!is_ordinary)
1753 object->error(_("local symbol %u has bad shndx %u"),
1754 r_sym, shndx);
1755 else
1756 got->add_local_pair_with_rela(object, r_sym,
1757 lsym.get_st_shndx(),
1758 GOT_TYPE_TLS_PAIR,
1759 target->rela_dyn_section(layout),
1760 (size == 64
1761 ? elfcpp::R_SPARC_TLS_DTPMOD64
1762 : elfcpp::R_SPARC_TLS_DTPMOD32),
1763 0);
1764 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
1765 generate_tls_call(symtab, layout, target);
1766 }
1767 else if (optimized_type != tls::TLSOPT_TO_LE)
1768 unsupported_reloc_local(object, r_type);
1769 break;
1770
1771 case elfcpp::R_SPARC_TLS_LDM_HI22 : // Local-dynamic
1772 case elfcpp::R_SPARC_TLS_LDM_LO10:
1773 case elfcpp::R_SPARC_TLS_LDM_ADD:
1774 case elfcpp::R_SPARC_TLS_LDM_CALL:
1775 if (optimized_type == tls::TLSOPT_NONE)
1776 {
1777 // Create a GOT entry for the module index.
1778 target->got_mod_index_entry(symtab, layout, object);
1779
1780 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
1781 generate_tls_call(symtab, layout, target);
1782 }
1783 else if (optimized_type != tls::TLSOPT_TO_LE)
1784 unsupported_reloc_local(object, r_type);
1785 break;
1786
1787 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
1788 case elfcpp::R_SPARC_TLS_LDO_LOX10:
1789 case elfcpp::R_SPARC_TLS_LDO_ADD:
1790 break;
1791
1792 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
1793 case elfcpp::R_SPARC_TLS_IE_LO10:
1794 case elfcpp::R_SPARC_TLS_IE_LD:
1795 case elfcpp::R_SPARC_TLS_IE_LDX:
1796 layout->set_has_static_tls();
1797 if (optimized_type == tls::TLSOPT_NONE)
1798 {
1799 // Create a GOT entry for the tp-relative offset.
1800 Output_data_got<size, big_endian>* got
1801 = target->got_section(symtab, layout);
1802 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1803
1804 if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
1805 {
1806 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1807 unsigned int off = got->add_constant(0);
1808
1809 object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET,
1810 off);
1811 rela_dyn->add_local_relative(object, r_sym,
1812 (size == 64 ?
1813 elfcpp::R_SPARC_TLS_TPOFF64 :
1814 elfcpp::R_SPARC_TLS_TPOFF32),
1815 got, off, 0);
1816 }
1817 }
1818 else if (optimized_type != tls::TLSOPT_TO_LE)
1819 unsupported_reloc_local(object, r_type);
1820 break;
1821
1822 case elfcpp::R_SPARC_TLS_LE_HIX22: // Local-exec
1823 case elfcpp::R_SPARC_TLS_LE_LOX10:
1824 layout->set_has_static_tls();
1825 if (output_is_shared)
1826 {
1827 // We need to create a dynamic relocation.
1828 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
1829 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
1830 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1831 rela_dyn->add_local_relative(object, r_sym, r_type,
1832 output_section, data_shndx,
1833 reloc.get_r_offset(), 0);
1834 }
1835 break;
1836 }
1837 }
1838 break;
1839
1840 // These are relocations which should only be seen by the
1841 // dynamic linker, and should never be seen here.
1842 case elfcpp::R_SPARC_COPY:
1843 case elfcpp::R_SPARC_GLOB_DAT:
1844 case elfcpp::R_SPARC_JMP_SLOT:
1845 case elfcpp::R_SPARC_RELATIVE:
1846 case elfcpp::R_SPARC_TLS_DTPMOD64:
1847 case elfcpp::R_SPARC_TLS_DTPMOD32:
1848 case elfcpp::R_SPARC_TLS_DTPOFF64:
1849 case elfcpp::R_SPARC_TLS_DTPOFF32:
1850 case elfcpp::R_SPARC_TLS_TPOFF64:
1851 case elfcpp::R_SPARC_TLS_TPOFF32:
1852 gold_error(_("%s: unexpected reloc %u in object file"),
1853 object->name().c_str(), r_type);
1854 break;
1855
1856 default:
1857 unsupported_reloc_local(object, r_type);
1858 break;
1859 }
1860 }
1861
1862 // Report an unsupported relocation against a global symbol.
1863
1864 template<int size, bool big_endian>
1865 void
1866 Target_sparc<size, big_endian>::Scan::unsupported_reloc_global(
1867 Sized_relobj<size, big_endian>* object,
1868 unsigned int r_type,
1869 Symbol* gsym)
1870 {
1871 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
1872 object->name().c_str(), r_type, gsym->demangled_name().c_str());
1873 }
1874
1875 // Scan a relocation for a global symbol.
1876
1877 template<int size, bool big_endian>
1878 inline void
1879 Target_sparc<size, big_endian>::Scan::global(
1880 const General_options&,
1881 Symbol_table* symtab,
1882 Layout* layout,
1883 Target_sparc<size, big_endian>* target,
1884 Sized_relobj<size, big_endian>* object,
1885 unsigned int data_shndx,
1886 Output_section* output_section,
1887 const elfcpp::Rela<size, big_endian>& reloc,
1888 unsigned int r_type,
1889 Symbol* gsym)
1890 {
1891 unsigned int orig_r_type = r_type;
1892
1893 r_type &= 0xff;
1894 switch (r_type)
1895 {
1896 case elfcpp::R_SPARC_NONE:
1897 case elfcpp::R_SPARC_REGISTER:
1898 case elfcpp::R_SPARC_GNU_VTINHERIT:
1899 case elfcpp::R_SPARC_GNU_VTENTRY:
1900 break;
1901
1902 case elfcpp::R_SPARC_PLT64:
1903 case elfcpp::R_SPARC_PLT32:
1904 case elfcpp::R_SPARC_HIPLT22:
1905 case elfcpp::R_SPARC_LOPLT10:
1906 case elfcpp::R_SPARC_PCPLT32:
1907 case elfcpp::R_SPARC_PCPLT22:
1908 case elfcpp::R_SPARC_PCPLT10:
1909 case elfcpp::R_SPARC_WPLT30:
1910 // If the symbol is fully resolved, this is just a PC32 reloc.
1911 // Otherwise we need a PLT entry.
1912 if (gsym->final_value_is_known())
1913 break;
1914 // If building a shared library, we can also skip the PLT entry
1915 // if the symbol is defined in the output file and is protected
1916 // or hidden.
1917 if (gsym->is_defined()
1918 && !gsym->is_from_dynobj()
1919 && !gsym->is_preemptible())
1920 break;
1921 target->make_plt_entry(symtab, layout, gsym);
1922 break;
1923
1924 case elfcpp::R_SPARC_DISP8:
1925 case elfcpp::R_SPARC_DISP16:
1926 case elfcpp::R_SPARC_DISP32:
1927 case elfcpp::R_SPARC_DISP64:
1928 case elfcpp::R_SPARC_PC_HH22:
1929 case elfcpp::R_SPARC_PC_HM10:
1930 case elfcpp::R_SPARC_PC_LM22:
1931 case elfcpp::R_SPARC_PC10:
1932 case elfcpp::R_SPARC_PC22:
1933 case elfcpp::R_SPARC_WDISP30:
1934 case elfcpp::R_SPARC_WDISP22:
1935 case elfcpp::R_SPARC_WDISP19:
1936 case elfcpp::R_SPARC_WDISP16:
1937 {
1938 if (gsym->needs_plt_entry())
1939 target->make_plt_entry(symtab, layout, gsym);
1940 // Make a dynamic relocation if necessary.
1941 int flags = Symbol::NON_PIC_REF;
1942 if (gsym->type() == elfcpp::STT_FUNC)
1943 flags |= Symbol::FUNCTION_CALL;
1944 if (gsym->needs_dynamic_reloc(flags))
1945 {
1946 if (target->may_need_copy_reloc(gsym))
1947 {
1948 target->copy_reloc(symtab, layout, object,
1949 data_shndx, output_section, gsym,
1950 reloc);
1951 }
1952 else
1953 {
1954 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
1955 check_non_pic(object, r_type);
1956 rela_dyn->add_global(gsym, orig_r_type, output_section, object,
1957 data_shndx, reloc.get_r_offset(),
1958 reloc.get_r_addend());
1959 }
1960 }
1961 }
1962 break;
1963
1964 case elfcpp::R_SPARC_UA64:
1965 case elfcpp::R_SPARC_64:
1966 case elfcpp::R_SPARC_HIX22:
1967 case elfcpp::R_SPARC_LOX10:
1968 case elfcpp::R_SPARC_H44:
1969 case elfcpp::R_SPARC_M44:
1970 case elfcpp::R_SPARC_L44:
1971 case elfcpp::R_SPARC_HH22:
1972 case elfcpp::R_SPARC_HM10:
1973 case elfcpp::R_SPARC_LM22:
1974 case elfcpp::R_SPARC_HI22:
1975 case elfcpp::R_SPARC_LO10:
1976 case elfcpp::R_SPARC_OLO10:
1977 case elfcpp::R_SPARC_UA32:
1978 case elfcpp::R_SPARC_32:
1979 case elfcpp::R_SPARC_UA16:
1980 case elfcpp::R_SPARC_16:
1981 case elfcpp::R_SPARC_11:
1982 case elfcpp::R_SPARC_10:
1983 case elfcpp::R_SPARC_8:
1984 case elfcpp::R_SPARC_7:
1985 case elfcpp::R_SPARC_6:
1986 case elfcpp::R_SPARC_5:
1987 {
1988 // Make a PLT entry if necessary.
1989 if (gsym->needs_plt_entry())
1990 {
1991 target->make_plt_entry(symtab, layout, gsym);
1992 // Since this is not a PC-relative relocation, we may be
1993 // taking the address of a function. In that case we need to
1994 // set the entry in the dynamic symbol table to the address of
1995 // the PLT entry.
1996 if (gsym->is_from_dynobj() && !parameters->options().shared())
1997 gsym->set_needs_dynsym_value();
1998 }
1999 // Make a dynamic relocation if necessary.
2000 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
2001 {
2002 if (target->may_need_copy_reloc(gsym))
2003 {
2004 target->copy_reloc(symtab, layout, object,
2005 data_shndx, output_section, gsym, reloc);
2006 }
2007 else if ((r_type == elfcpp::R_SPARC_32
2008 || r_type == elfcpp::R_SPARC_64)
2009 && gsym->can_use_relative_reloc(false))
2010 {
2011 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2012 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2013 output_section, object,
2014 data_shndx, reloc.get_r_offset(),
2015 reloc.get_r_addend());
2016 }
2017 else
2018 {
2019 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2020
2021 check_non_pic(object, r_type);
2022 if (gsym->is_from_dynobj()
2023 || gsym->is_undefined()
2024 || gsym->is_preemptible())
2025 rela_dyn->add_global(gsym, orig_r_type, output_section,
2026 object, data_shndx,
2027 reloc.get_r_offset(),
2028 reloc.get_r_addend());
2029 else
2030 rela_dyn->add_global_relative(gsym, orig_r_type,
2031 output_section, object,
2032 data_shndx,
2033 reloc.get_r_offset(),
2034 reloc.get_r_addend());
2035 }
2036 }
2037 }
2038 break;
2039
2040 case elfcpp::R_SPARC_GOT10:
2041 case elfcpp::R_SPARC_GOT13:
2042 case elfcpp::R_SPARC_GOT22:
2043 {
2044 // The symbol requires a GOT entry.
2045 Output_data_got<size, big_endian>* got;
2046
2047 got = target->got_section(symtab, layout);
2048 if (gsym->final_value_is_known())
2049 got->add_global(gsym, GOT_TYPE_STANDARD);
2050 else
2051 {
2052 // If this symbol is not fully resolved, we need to add a
2053 // dynamic relocation for it.
2054 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2055 if (gsym->is_from_dynobj()
2056 || gsym->is_undefined()
2057 || gsym->is_preemptible())
2058 got->add_global_with_rela(gsym, GOT_TYPE_STANDARD, rela_dyn,
2059 elfcpp::R_SPARC_GLOB_DAT);
2060 else if (!gsym->has_got_offset(GOT_TYPE_STANDARD))
2061 {
2062 unsigned int off = got->add_constant(0);
2063
2064 gsym->set_got_offset(GOT_TYPE_STANDARD, off);
2065 rela_dyn->add_global_relative(gsym, elfcpp::R_SPARC_RELATIVE,
2066 got, off, 0);
2067 }
2068 }
2069 }
2070 break;
2071
2072 // These are initial tls relocs, which are expected when
2073 // linking.
2074 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2075 case elfcpp::R_SPARC_TLS_GD_LO10:
2076 case elfcpp::R_SPARC_TLS_GD_ADD:
2077 case elfcpp::R_SPARC_TLS_GD_CALL:
2078 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2079 case elfcpp::R_SPARC_TLS_LDM_LO10:
2080 case elfcpp::R_SPARC_TLS_LDM_ADD:
2081 case elfcpp::R_SPARC_TLS_LDM_CALL:
2082 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2083 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2084 case elfcpp::R_SPARC_TLS_LDO_ADD:
2085 case elfcpp::R_SPARC_TLS_LE_HIX22:
2086 case elfcpp::R_SPARC_TLS_LE_LOX10:
2087 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2088 case elfcpp::R_SPARC_TLS_IE_LO10:
2089 case elfcpp::R_SPARC_TLS_IE_LD:
2090 case elfcpp::R_SPARC_TLS_IE_LDX:
2091 {
2092 const bool is_final = gsym->final_value_is_known();
2093 const tls::Tls_optimization optimized_type
2094 = optimize_tls_reloc(is_final, r_type);
2095 switch (r_type)
2096 {
2097 case elfcpp::R_SPARC_TLS_GD_HI22: // Global-dynamic
2098 case elfcpp::R_SPARC_TLS_GD_LO10:
2099 case elfcpp::R_SPARC_TLS_GD_ADD:
2100 case elfcpp::R_SPARC_TLS_GD_CALL:
2101 if (optimized_type == tls::TLSOPT_NONE)
2102 {
2103 // Create a pair of GOT entries for the module index and
2104 // dtv-relative offset.
2105 Output_data_got<size, big_endian>* got
2106 = target->got_section(symtab, layout);
2107 got->add_global_pair_with_rela(gsym, GOT_TYPE_TLS_PAIR,
2108 target->rela_dyn_section(layout),
2109 (size == 64 ?
2110 elfcpp::R_SPARC_TLS_DTPMOD64 :
2111 elfcpp::R_SPARC_TLS_DTPMOD32),
2112 (size == 64 ?
2113 elfcpp::R_SPARC_TLS_DTPOFF64 :
2114 elfcpp::R_SPARC_TLS_DTPOFF32));
2115
2116 // Emit R_SPARC_WPLT30 against "__tls_get_addr"
2117 if (r_type == elfcpp::R_SPARC_TLS_GD_CALL)
2118 generate_tls_call(symtab, layout, target);
2119 }
2120 else if (optimized_type == tls::TLSOPT_TO_IE)
2121 {
2122 // Create a GOT entry for the tp-relative offset.
2123 Output_data_got<size, big_endian>* got
2124 = target->got_section(symtab, layout);
2125 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2126 target->rela_dyn_section(layout),
2127 (size == 64 ?
2128 elfcpp::R_SPARC_TLS_TPOFF64 :
2129 elfcpp::R_SPARC_TLS_TPOFF32));
2130 }
2131 else if (optimized_type != tls::TLSOPT_TO_LE)
2132 unsupported_reloc_global(object, r_type, gsym);
2133 break;
2134
2135 case elfcpp::R_SPARC_TLS_LDM_HI22: // Local-dynamic
2136 case elfcpp::R_SPARC_TLS_LDM_LO10:
2137 case elfcpp::R_SPARC_TLS_LDM_ADD:
2138 case elfcpp::R_SPARC_TLS_LDM_CALL:
2139 if (optimized_type == tls::TLSOPT_NONE)
2140 {
2141 // Create a GOT entry for the module index.
2142 target->got_mod_index_entry(symtab, layout, object);
2143
2144 if (r_type == elfcpp::R_SPARC_TLS_LDM_CALL)
2145 generate_tls_call(symtab, layout, target);
2146 }
2147 else if (optimized_type != tls::TLSOPT_TO_LE)
2148 unsupported_reloc_global(object, r_type, gsym);
2149 break;
2150
2151 case elfcpp::R_SPARC_TLS_LDO_HIX22: // Alternate local-dynamic
2152 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2153 case elfcpp::R_SPARC_TLS_LDO_ADD:
2154 break;
2155
2156 case elfcpp::R_SPARC_TLS_LE_HIX22:
2157 case elfcpp::R_SPARC_TLS_LE_LOX10:
2158 layout->set_has_static_tls();
2159 if (parameters->options().shared())
2160 {
2161 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
2162 rela_dyn->add_global_relative(gsym, orig_r_type,
2163 output_section, object,
2164 data_shndx, reloc.get_r_offset(),
2165 0);
2166 }
2167 break;
2168
2169 case elfcpp::R_SPARC_TLS_IE_HI22: // Initial-exec
2170 case elfcpp::R_SPARC_TLS_IE_LO10:
2171 case elfcpp::R_SPARC_TLS_IE_LD:
2172 case elfcpp::R_SPARC_TLS_IE_LDX:
2173 layout->set_has_static_tls();
2174 if (optimized_type == tls::TLSOPT_NONE)
2175 {
2176 // Create a GOT entry for the tp-relative offset.
2177 Output_data_got<size, big_endian>* got
2178 = target->got_section(symtab, layout);
2179 got->add_global_with_rela(gsym, GOT_TYPE_TLS_OFFSET,
2180 target->rela_dyn_section(layout),
2181 (size == 64 ?
2182 elfcpp::R_SPARC_TLS_TPOFF64 :
2183 elfcpp::R_SPARC_TLS_TPOFF32));
2184 }
2185 else if (optimized_type != tls::TLSOPT_TO_LE)
2186 unsupported_reloc_global(object, r_type, gsym);
2187 break;
2188 }
2189 }
2190 break;
2191
2192 // These are relocations which should only be seen by the
2193 // dynamic linker, and should never be seen here.
2194 case elfcpp::R_SPARC_COPY:
2195 case elfcpp::R_SPARC_GLOB_DAT:
2196 case elfcpp::R_SPARC_JMP_SLOT:
2197 case elfcpp::R_SPARC_RELATIVE:
2198 case elfcpp::R_SPARC_TLS_DTPMOD64:
2199 case elfcpp::R_SPARC_TLS_DTPMOD32:
2200 case elfcpp::R_SPARC_TLS_DTPOFF64:
2201 case elfcpp::R_SPARC_TLS_DTPOFF32:
2202 case elfcpp::R_SPARC_TLS_TPOFF64:
2203 case elfcpp::R_SPARC_TLS_TPOFF32:
2204 gold_error(_("%s: unexpected reloc %u in object file"),
2205 object->name().c_str(), r_type);
2206 break;
2207
2208 default:
2209 unsupported_reloc_global(object, r_type, gsym);
2210 break;
2211 }
2212 }
2213
2214 // Scan relocations for a section.
2215
2216 template<int size, bool big_endian>
2217 void
2218 Target_sparc<size, big_endian>::scan_relocs(
2219 const General_options& options,
2220 Symbol_table* symtab,
2221 Layout* layout,
2222 Sized_relobj<size, big_endian>* object,
2223 unsigned int data_shndx,
2224 unsigned int sh_type,
2225 const unsigned char* prelocs,
2226 size_t reloc_count,
2227 Output_section* output_section,
2228 bool needs_special_offset_handling,
2229 size_t local_symbol_count,
2230 const unsigned char* plocal_symbols)
2231 {
2232 typedef Target_sparc<size, big_endian> Sparc;
2233 typedef typename Target_sparc<size, big_endian>::Scan Scan;
2234
2235 if (sh_type == elfcpp::SHT_REL)
2236 {
2237 gold_error(_("%s: unsupported REL reloc section"),
2238 object->name().c_str());
2239 return;
2240 }
2241
2242 gold::scan_relocs<size, big_endian, Sparc, elfcpp::SHT_RELA, Scan>(
2243 options,
2244 symtab,
2245 layout,
2246 this,
2247 object,
2248 data_shndx,
2249 prelocs,
2250 reloc_count,
2251 output_section,
2252 needs_special_offset_handling,
2253 local_symbol_count,
2254 plocal_symbols);
2255 }
2256
2257 // Finalize the sections.
2258
2259 template<int size, bool big_endian>
2260 void
2261 Target_sparc<size, big_endian>::do_finalize_sections(Layout* layout)
2262 {
2263 // Fill in some more dynamic tags.
2264 Output_data_dynamic* const odyn = layout->dynamic_data();
2265 if (odyn != NULL)
2266 {
2267 if (this->plt_ != NULL)
2268 {
2269 const Output_data* od = this->plt_->rel_plt();
2270 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
2271 odyn->add_section_address(elfcpp::DT_JMPREL, od);
2272 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
2273
2274 odyn->add_section_address(elfcpp::DT_PLTGOT, this->plt_);
2275 }
2276
2277 if (this->rela_dyn_ != NULL)
2278 {
2279 const Output_data* od = this->rela_dyn_;
2280 odyn->add_section_address(elfcpp::DT_RELA, od);
2281 odyn->add_section_size(elfcpp::DT_RELASZ, od);
2282 odyn->add_constant(elfcpp::DT_RELAENT,
2283 elfcpp::Elf_sizes<size>::rela_size);
2284 }
2285
2286 if (!parameters->options().shared())
2287 {
2288 // The value of the DT_DEBUG tag is filled in by the dynamic
2289 // linker at run time, and used by the debugger.
2290 odyn->add_constant(elfcpp::DT_DEBUG, 0);
2291 }
2292 }
2293
2294 // Emit any relocs we saved in an attempt to avoid generating COPY
2295 // relocs.
2296 if (this->copy_relocs_.any_saved_relocs())
2297 this->copy_relocs_.emit(this->rela_dyn_section(layout));
2298 }
2299
2300 // Perform a relocation.
2301
2302 template<int size, bool big_endian>
2303 inline bool
2304 Target_sparc<size, big_endian>::Relocate::relocate(
2305 const Relocate_info<size, big_endian>* relinfo,
2306 Target_sparc* target,
2307 size_t relnum,
2308 const elfcpp::Rela<size, big_endian>& rela,
2309 unsigned int r_type,
2310 const Sized_symbol<size>* gsym,
2311 const Symbol_value<size>* psymval,
2312 unsigned char* view,
2313 typename elfcpp::Elf_types<size>::Elf_Addr address,
2314 section_size_type view_size)
2315 {
2316 r_type &= 0xff;
2317
2318 if (this->ignore_gd_add_)
2319 {
2320 if (r_type != elfcpp::R_SPARC_TLS_GD_ADD)
2321 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2322 _("missing expected TLS relocation"));
2323 else
2324 {
2325 this->ignore_gd_add_ = false;
2326 return false;
2327 }
2328 }
2329
2330 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2331
2332 // Pick the value to use for symbols defined in shared objects.
2333 Symbol_value<size> symval;
2334 if (gsym != NULL
2335 && (gsym->is_from_dynobj()
2336 || (parameters->options().shared()
2337 && (gsym->is_undefined() || gsym->is_preemptible())))
2338 && gsym->has_plt_offset())
2339 {
2340 elfcpp::Elf_Xword value;
2341
2342 value = target->plt_section()->address() + gsym->plt_offset();
2343
2344 symval.set_output_value(value);
2345
2346 psymval = &symval;
2347 }
2348
2349 const Sized_relobj<size, big_endian>* object = relinfo->object;
2350 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2351
2352 // Get the GOT offset if needed. Unlike i386 and x86_64, our GOT
2353 // pointer points to the beginning, not the end, of the table.
2354 // So we just use the plain offset.
2355 bool have_got_offset = false;
2356 unsigned int got_offset = 0;
2357 switch (r_type)
2358 {
2359 case elfcpp::R_SPARC_GOT10:
2360 case elfcpp::R_SPARC_GOT13:
2361 case elfcpp::R_SPARC_GOT22:
2362 if (gsym != NULL)
2363 {
2364 gold_assert(gsym->has_got_offset(GOT_TYPE_STANDARD));
2365 got_offset = gsym->got_offset(GOT_TYPE_STANDARD);
2366 }
2367 else
2368 {
2369 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2370 gold_assert(object->local_has_got_offset(r_sym, GOT_TYPE_STANDARD));
2371 got_offset = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
2372 }
2373 have_got_offset = true;
2374 break;
2375
2376 default:
2377 break;
2378 }
2379
2380 switch (r_type)
2381 {
2382 case elfcpp::R_SPARC_NONE:
2383 case elfcpp::R_SPARC_REGISTER:
2384 case elfcpp::R_SPARC_GNU_VTINHERIT:
2385 case elfcpp::R_SPARC_GNU_VTENTRY:
2386 break;
2387
2388 case elfcpp::R_SPARC_8:
2389 Relocate_functions<size, big_endian>::rela8(view, object,
2390 psymval, addend);
2391 break;
2392
2393 case elfcpp::R_SPARC_16:
2394 Relocate_functions<size, big_endian>::rela16(view, object,
2395 psymval, addend);
2396 break;
2397
2398 case elfcpp::R_SPARC_32:
2399 if (!parameters->options().output_is_position_independent())
2400 Relocate_functions<size, big_endian>::rela32(view, object,
2401 psymval, addend);
2402 break;
2403
2404 case elfcpp::R_SPARC_DISP8:
2405 Reloc::disp8(view, object, psymval, addend, address);
2406 break;
2407
2408 case elfcpp::R_SPARC_DISP16:
2409 Reloc::disp16(view, object, psymval, addend, address);
2410 break;
2411
2412 case elfcpp::R_SPARC_DISP32:
2413 Reloc::disp32(view, object, psymval, addend, address);
2414 break;
2415
2416 case elfcpp::R_SPARC_DISP64:
2417 Reloc::disp64(view, object, psymval, addend, address);
2418 break;
2419
2420 case elfcpp::R_SPARC_WDISP30:
2421 case elfcpp::R_SPARC_WPLT30:
2422 Reloc::wdisp30(view, object, psymval, addend, address);
2423 break;
2424
2425 case elfcpp::R_SPARC_WDISP22:
2426 Reloc::wdisp22(view, object, psymval, addend, address);
2427 break;
2428
2429 case elfcpp::R_SPARC_WDISP19:
2430 Reloc::wdisp19(view, object, psymval, addend, address);
2431 break;
2432
2433 case elfcpp::R_SPARC_WDISP16:
2434 Reloc::wdisp16(view, object, psymval, addend, address);
2435 break;
2436
2437 case elfcpp::R_SPARC_HI22:
2438 Reloc::hi22(view, object, psymval, addend);
2439 break;
2440
2441 case elfcpp::R_SPARC_22:
2442 Reloc::rela32_22(view, object, psymval, addend);
2443 break;
2444
2445 case elfcpp::R_SPARC_13:
2446 Reloc::rela32_13(view, object, psymval, addend);
2447 break;
2448
2449 case elfcpp::R_SPARC_LO10:
2450 Reloc::lo10(view, object, psymval, addend);
2451 break;
2452
2453 case elfcpp::R_SPARC_GOT10:
2454 Reloc::lo10(view, got_offset, addend);
2455 break;
2456
2457 case elfcpp::R_SPARC_GOT13:
2458 Reloc::rela32_13(view, got_offset, addend);
2459 break;
2460
2461 case elfcpp::R_SPARC_GOT22:
2462 Reloc::hi22(view, got_offset, addend);
2463 break;
2464
2465 case elfcpp::R_SPARC_PC10:
2466 Reloc::pc10(view, object, psymval, addend, address);
2467 break;
2468
2469 case elfcpp::R_SPARC_PC22:
2470 Reloc::pc22(view, object, psymval, addend, address);
2471 break;
2472
2473 case elfcpp::R_SPARC_TLS_DTPOFF32:
2474 case elfcpp::R_SPARC_UA32:
2475 Reloc::ua32(view, object, psymval, addend);
2476 break;
2477
2478 case elfcpp::R_SPARC_PLT64:
2479 Relocate_functions<size, big_endian>::rela64(view, object,
2480 psymval, addend);
2481 break;
2482
2483 case elfcpp::R_SPARC_PLT32:
2484 Relocate_functions<size, big_endian>::rela32(view, object,
2485 psymval, addend);
2486 break;
2487
2488 case elfcpp::R_SPARC_HIPLT22:
2489 Reloc::hi22(view, object, psymval, addend);
2490 break;
2491
2492 case elfcpp::R_SPARC_LOPLT10:
2493 Reloc::lo10(view, object, psymval, addend);
2494 break;
2495
2496 case elfcpp::R_SPARC_PCPLT32:
2497 Reloc::disp32(view, object, psymval, addend, address);
2498 break;
2499
2500 case elfcpp::R_SPARC_PCPLT22:
2501 Reloc::pcplt22(view, object, psymval, addend, address);
2502 break;
2503
2504 case elfcpp::R_SPARC_PCPLT10:
2505 Reloc::lo10(view, object, psymval, addend, address);
2506 break;
2507
2508 case elfcpp::R_SPARC_64:
2509 if (!parameters->options().output_is_position_independent())
2510 Relocate_functions<size, big_endian>::rela64(view, object,
2511 psymval, addend);
2512 break;
2513
2514 case elfcpp::R_SPARC_OLO10:
2515 {
2516 unsigned int addend2 = rela.get_r_info() & 0xffffffff;
2517 addend2 = ((addend2 >> 8) ^ 0x800000) - 0x800000;
2518 Reloc::olo10(view, object, psymval, addend, addend2);
2519 }
2520 break;
2521
2522 case elfcpp::R_SPARC_HH22:
2523 Reloc::hh22(view, object, psymval, addend);
2524 break;
2525
2526 case elfcpp::R_SPARC_PC_HH22:
2527 Reloc::pc_hh22(view, object, psymval, addend, address);
2528 break;
2529
2530 case elfcpp::R_SPARC_HM10:
2531 Reloc::hm10(view, object, psymval, addend);
2532 break;
2533
2534 case elfcpp::R_SPARC_PC_HM10:
2535 Reloc::pc_hm10(view, object, psymval, addend, address);
2536 break;
2537
2538 case elfcpp::R_SPARC_LM22:
2539 Reloc::hi22(view, object, psymval, addend);
2540 break;
2541
2542 case elfcpp::R_SPARC_PC_LM22:
2543 Reloc::pcplt22(view, object, psymval, addend, address);
2544 break;
2545
2546 case elfcpp::R_SPARC_11:
2547 Reloc::rela32_11(view, object, psymval, addend);
2548 break;
2549
2550 case elfcpp::R_SPARC_10:
2551 Reloc::rela32_10(view, object, psymval, addend);
2552 break;
2553
2554 case elfcpp::R_SPARC_7:
2555 Reloc::rela32_7(view, object, psymval, addend);
2556 break;
2557
2558 case elfcpp::R_SPARC_6:
2559 Reloc::rela32_6(view, object, psymval, addend);
2560 break;
2561
2562 case elfcpp::R_SPARC_5:
2563 Reloc::rela32_5(view, object, psymval, addend);
2564 break;
2565
2566 case elfcpp::R_SPARC_HIX22:
2567 Reloc::hix22(view, object, psymval, addend);
2568 break;
2569
2570 case elfcpp::R_SPARC_LOX10:
2571 Reloc::lox10(view, object, psymval, addend);
2572 break;
2573
2574 case elfcpp::R_SPARC_H44:
2575 Reloc::h44(view, object, psymval, addend);
2576 break;
2577
2578 case elfcpp::R_SPARC_M44:
2579 Reloc::m44(view, object, psymval, addend);
2580 break;
2581
2582 case elfcpp::R_SPARC_L44:
2583 Reloc::l44(view, object, psymval, addend);
2584 break;
2585
2586 case elfcpp::R_SPARC_TLS_DTPOFF64:
2587 case elfcpp::R_SPARC_UA64:
2588 Reloc::ua64(view, object, psymval, addend);
2589 break;
2590
2591 case elfcpp::R_SPARC_UA16:
2592 Reloc::ua16(view, object, psymval, addend);
2593 break;
2594
2595 case elfcpp::R_SPARC_TLS_GD_HI22:
2596 case elfcpp::R_SPARC_TLS_GD_LO10:
2597 case elfcpp::R_SPARC_TLS_GD_ADD:
2598 case elfcpp::R_SPARC_TLS_GD_CALL:
2599 case elfcpp::R_SPARC_TLS_LDM_HI22:
2600 case elfcpp::R_SPARC_TLS_LDM_LO10:
2601 case elfcpp::R_SPARC_TLS_LDM_ADD:
2602 case elfcpp::R_SPARC_TLS_LDM_CALL:
2603 case elfcpp::R_SPARC_TLS_LDO_HIX22:
2604 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2605 case elfcpp::R_SPARC_TLS_LDO_ADD:
2606 case elfcpp::R_SPARC_TLS_IE_HI22:
2607 case elfcpp::R_SPARC_TLS_IE_LO10:
2608 case elfcpp::R_SPARC_TLS_IE_LD:
2609 case elfcpp::R_SPARC_TLS_IE_LDX:
2610 case elfcpp::R_SPARC_TLS_LE_HIX22:
2611 case elfcpp::R_SPARC_TLS_LE_LOX10:
2612 this->relocate_tls(relinfo, target, relnum, rela,
2613 r_type, gsym, psymval, view,
2614 address, view_size);
2615 break;
2616
2617 case elfcpp::R_SPARC_COPY:
2618 case elfcpp::R_SPARC_GLOB_DAT:
2619 case elfcpp::R_SPARC_JMP_SLOT:
2620 case elfcpp::R_SPARC_RELATIVE:
2621 // These are outstanding tls relocs, which are unexpected when
2622 // linking.
2623 case elfcpp::R_SPARC_TLS_DTPMOD64:
2624 case elfcpp::R_SPARC_TLS_DTPMOD32:
2625 case elfcpp::R_SPARC_TLS_TPOFF64:
2626 case elfcpp::R_SPARC_TLS_TPOFF32:
2627 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2628 _("unexpected reloc %u in object file"),
2629 r_type);
2630 break;
2631
2632 default:
2633 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2634 _("unsupported reloc %u"),
2635 r_type);
2636 break;
2637 }
2638
2639 return true;
2640 }
2641
2642 // Perform a TLS relocation.
2643
2644 template<int size, bool big_endian>
2645 inline void
2646 Target_sparc<size, big_endian>::Relocate::relocate_tls(
2647 const Relocate_info<size, big_endian>* relinfo,
2648 Target_sparc<size, big_endian>* target,
2649 size_t relnum,
2650 const elfcpp::Rela<size, big_endian>& rela,
2651 unsigned int r_type,
2652 const Sized_symbol<size>* gsym,
2653 const Symbol_value<size>* psymval,
2654 unsigned char* view,
2655 typename elfcpp::Elf_types<size>::Elf_Addr address,
2656 section_size_type)
2657 {
2658 Output_segment* tls_segment = relinfo->layout->tls_segment();
2659 typedef Sparc_relocate_functions<size, big_endian> Reloc;
2660 const Sized_relobj<size, big_endian>* object = relinfo->object;
2661 typedef typename elfcpp::Swap<32, true>::Valtype Insntype;
2662
2663 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2664 typename elfcpp::Elf_types<size>::Elf_Addr value = psymval->value(object, 0);
2665
2666 const bool is_final =
2667 (gsym == NULL
2668 ? !parameters->options().output_is_position_independent()
2669 : gsym->final_value_is_known());
2670 const tls::Tls_optimization optimized_type
2671 = optimize_tls_reloc(is_final, r_type);
2672
2673 switch (r_type)
2674 {
2675 case elfcpp::R_SPARC_TLS_GD_HI22:
2676 case elfcpp::R_SPARC_TLS_GD_LO10:
2677 case elfcpp::R_SPARC_TLS_GD_ADD:
2678 case elfcpp::R_SPARC_TLS_GD_CALL:
2679 if (optimized_type == tls::TLSOPT_TO_LE)
2680 {
2681 Insntype* wv = reinterpret_cast<Insntype*>(view);
2682 Insntype val;
2683
2684 value -= tls_segment->memsz();
2685
2686 switch (r_type)
2687 {
2688 case elfcpp::R_SPARC_TLS_GD_HI22:
2689 // TLS_GD_HI22 --> TLS_LE_HIX22
2690 Reloc::hix22(view, value, addend);
2691 break;
2692
2693 case elfcpp::R_SPARC_TLS_GD_LO10:
2694 // TLS_GD_LO10 --> TLS_LE_LOX10
2695 Reloc::lox10(view, value, addend);
2696 break;
2697
2698 case elfcpp::R_SPARC_TLS_GD_ADD:
2699 // add %reg1, %reg2, %reg3 --> mov %g7, %reg2, %reg3
2700 val = elfcpp::Swap<32, true>::readval(wv);
2701 val = (val & ~0x7c000) | 0x1c000;
2702 elfcpp::Swap<32, true>::writeval(wv, val);
2703 break;
2704 case elfcpp::R_SPARC_TLS_GD_CALL:
2705 // call __tls_get_addr --> nop
2706 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
2707 break;
2708 }
2709 break;
2710 }
2711 else
2712 {
2713 unsigned int got_type = (optimized_type == tls::TLSOPT_TO_IE
2714 ? GOT_TYPE_TLS_OFFSET
2715 : GOT_TYPE_TLS_PAIR);
2716 if (gsym != NULL)
2717 {
2718 gold_assert(gsym->has_got_offset(got_type));
2719 value = gsym->got_offset(got_type);
2720 }
2721 else
2722 {
2723 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2724 gold_assert(object->local_has_got_offset(r_sym, got_type));
2725 value = object->local_got_offset(r_sym, got_type);
2726 }
2727 if (optimized_type == tls::TLSOPT_TO_IE)
2728 {
2729 Insntype* wv = reinterpret_cast<Insntype*>(view);
2730 Insntype val;
2731
2732 switch (r_type)
2733 {
2734 case elfcpp::R_SPARC_TLS_GD_HI22:
2735 // TLS_GD_HI22 --> TLS_IE_HI22
2736 Reloc::hi22(view, value, addend);
2737 break;
2738
2739 case elfcpp::R_SPARC_TLS_GD_LO10:
2740 // TLS_GD_LO10 --> TLS_IE_LO10
2741 Reloc::lo10(view, value, addend);
2742 break;
2743
2744 case elfcpp::R_SPARC_TLS_GD_ADD:
2745 // add %reg1, %reg2, %reg3 --> ld [%reg1 + %reg2], %reg3
2746 val = elfcpp::Swap<32, true>::readval(wv);
2747
2748 if (size == 64)
2749 val |= 0xc0580000;
2750 else
2751 val |= 0xc0000000;
2752
2753 elfcpp::Swap<32, true>::writeval(wv, val);
2754 break;
2755
2756 case elfcpp::R_SPARC_TLS_GD_CALL:
2757 // The compiler can put the TLS_GD_ADD instruction
2758 // into the delay slot of the call. If so, we need
2759 // to transpose the two instructions so that the
2760 // the new sequence works properly.
2761 //
2762 // The test we use is if the instruction in the
2763 // delay slot is an add with destination register
2764 // equal to %o0
2765 val = elfcpp::Swap<32, true>::readval(wv + 1);
2766 if ((val & 0x81f80000) == 0x80000000
2767 && ((val >> 25) & 0x1f) == 0x8)
2768 {
2769 if (size == 64)
2770 val |= 0xc0580000;
2771 else
2772 val |= 0xc0000000;
2773
2774 elfcpp::Swap<32, true>::writeval(wv, val);
2775
2776 wv += 1;
2777 this->ignore_gd_add_ = true;
2778 }
2779
2780 // call __tls_get_addr --> add %g7, %o0, %o0
2781 elfcpp::Swap<32, true>::writeval(wv, 0x9001c008);
2782 break;
2783 }
2784 break;
2785 }
2786 else if (optimized_type == tls::TLSOPT_NONE)
2787 {
2788 switch (r_type)
2789 {
2790 case elfcpp::R_SPARC_TLS_GD_HI22:
2791 Reloc::hi22(view, value, addend);
2792 break;
2793 case elfcpp::R_SPARC_TLS_GD_LO10:
2794 Reloc::lo10(view, value, addend);
2795 break;
2796 case elfcpp::R_SPARC_TLS_GD_ADD:
2797 break;
2798 case elfcpp::R_SPARC_TLS_GD_CALL:
2799 {
2800 Symbol_value<size> symval;
2801 elfcpp::Elf_Xword value;
2802 Symbol* tsym;
2803
2804 tsym = target->tls_get_addr_sym_;
2805 gold_assert(tsym);
2806 value = (target->plt_section()->address() +
2807 tsym->plt_offset());
2808 symval.set_output_value(value);
2809 Reloc::wdisp30(view, object, &symval, addend, address);
2810 }
2811 break;
2812 }
2813 break;
2814 }
2815 }
2816 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2817 _("unsupported reloc %u"),
2818 r_type);
2819 break;
2820
2821 case elfcpp::R_SPARC_TLS_LDM_HI22:
2822 case elfcpp::R_SPARC_TLS_LDM_LO10:
2823 case elfcpp::R_SPARC_TLS_LDM_ADD:
2824 case elfcpp::R_SPARC_TLS_LDM_CALL:
2825 if (optimized_type == tls::TLSOPT_TO_LE)
2826 {
2827 Insntype* wv = reinterpret_cast<Insntype*>(view);
2828
2829 switch (r_type)
2830 {
2831 case elfcpp::R_SPARC_TLS_LDM_HI22:
2832 case elfcpp::R_SPARC_TLS_LDM_LO10:
2833 case elfcpp::R_SPARC_TLS_LDM_ADD:
2834 elfcpp::Swap<32, true>::writeval(wv, sparc_nop);
2835 break;
2836
2837 case elfcpp::R_SPARC_TLS_LDM_CALL:
2838 elfcpp::Swap<32, true>::writeval(wv, sparc_mov_g0_o0);
2839 break;
2840 }
2841 break;
2842 }
2843 else if (optimized_type == tls::TLSOPT_NONE)
2844 {
2845 // Relocate the field with the offset of the GOT entry for
2846 // the module index.
2847 unsigned int got_offset;
2848
2849 got_offset = target->got_mod_index_entry(NULL, NULL, NULL);
2850 switch (r_type)
2851 {
2852 case elfcpp::R_SPARC_TLS_LDM_HI22:
2853 Reloc::hi22(view, got_offset, addend);
2854 break;
2855 case elfcpp::R_SPARC_TLS_LDM_LO10:
2856 Reloc::lo10(view, got_offset, addend);
2857 break;
2858 case elfcpp::R_SPARC_TLS_LDM_ADD:
2859 break;
2860 case elfcpp::R_SPARC_TLS_LDM_CALL:
2861 {
2862 Symbol_value<size> symval;
2863 elfcpp::Elf_Xword value;
2864 Symbol* tsym;
2865
2866 tsym = target->tls_get_addr_sym_;
2867 gold_assert(tsym);
2868 value = (target->plt_section()->address() +
2869 tsym->plt_offset());
2870 symval.set_output_value(value);
2871 Reloc::wdisp30(view, object, &symval, addend, address);
2872 }
2873 break;
2874 }
2875 break;
2876 }
2877 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2878 _("unsupported reloc %u"),
2879 r_type);
2880 break;
2881
2882 // These relocs can appear in debugging sections, in which case
2883 // we won't see the TLS_LDM relocs. The local_dynamic_type
2884 // field tells us this.
2885 case elfcpp::R_SPARC_TLS_LDO_HIX22:
2886 if (optimized_type == tls::TLSOPT_TO_LE)
2887 {
2888 value -= tls_segment->memsz();
2889 Reloc::hix22(view, value, addend);
2890 }
2891 else
2892 Reloc::ldo_hix22(view, value, addend);
2893 break;
2894 case elfcpp::R_SPARC_TLS_LDO_LOX10:
2895 if (optimized_type == tls::TLSOPT_TO_LE)
2896 {
2897 value -= tls_segment->memsz();
2898 Reloc::lox10(view, value, addend);
2899 }
2900 else
2901 Reloc::ldo_lox10(view, value, addend);
2902 break;
2903 case elfcpp::R_SPARC_TLS_LDO_ADD:
2904 if (optimized_type == tls::TLSOPT_TO_LE)
2905 {
2906 Insntype* wv = reinterpret_cast<Insntype*>(view);
2907 Insntype val;
2908
2909 // add %reg1, %reg2, %reg3 --> add %g7, %reg2, %reg3
2910 val = elfcpp::Swap<32, true>::readval(wv);
2911 val = (val & ~0x7c000) | 0x1c000;
2912 elfcpp::Swap<32, true>::writeval(wv, val);
2913 }
2914 break;
2915
2916 // When optimizing IE --> LE, the only relocation that is handled
2917 // differently is R_SPARC_TLS_IE_LD, it is rewritten from
2918 // 'ld{,x} [rs1 + rs2], rd' into 'mov rs2, rd' or simply a NOP is
2919 // rs2 and rd are the same.
2920 case elfcpp::R_SPARC_TLS_IE_LD:
2921 case elfcpp::R_SPARC_TLS_IE_LDX:
2922 if (optimized_type == tls::TLSOPT_TO_LE)
2923 {
2924 Insntype* wv = reinterpret_cast<Insntype*>(view);
2925 Insntype val = elfcpp::Swap<32, true>::readval(wv);
2926 Insntype rs2 = val & 0x1f;
2927 Insntype rd = (val >> 25) & 0x1f;
2928
2929 if (rs2 == rd)
2930 val = sparc_nop;
2931 else
2932 val = sparc_mov | (val & 0x3e00001f);
2933
2934 elfcpp::Swap<32, true>::writeval(wv, val);
2935 }
2936 break;
2937
2938 case elfcpp::R_SPARC_TLS_IE_HI22:
2939 case elfcpp::R_SPARC_TLS_IE_LO10:
2940 if (optimized_type == tls::TLSOPT_TO_LE)
2941 {
2942 value -= tls_segment->memsz();
2943 switch (r_type)
2944 {
2945 case elfcpp::R_SPARC_TLS_IE_HI22:
2946 // IE_HI22 --> LE_HIX22
2947 Reloc::hix22(view, value, addend);
2948 break;
2949 case elfcpp::R_SPARC_TLS_IE_LO10:
2950 // IE_LO10 --> LE_LOX10
2951 Reloc::lox10(view, value, addend);
2952 break;
2953 }
2954 break;
2955 }
2956 else if (optimized_type == tls::TLSOPT_NONE)
2957 {
2958 // Relocate the field with the offset of the GOT entry for
2959 // the tp-relative offset of the symbol.
2960 if (gsym != NULL)
2961 {
2962 gold_assert(gsym->has_got_offset(GOT_TYPE_TLS_OFFSET));
2963 value = gsym->got_offset(GOT_TYPE_TLS_OFFSET);
2964 }
2965 else
2966 {
2967 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
2968 gold_assert(object->local_has_got_offset(r_sym,
2969 GOT_TYPE_TLS_OFFSET));
2970 value = object->local_got_offset(r_sym,
2971 GOT_TYPE_TLS_OFFSET);
2972 }
2973 switch (r_type)
2974 {
2975 case elfcpp::R_SPARC_TLS_IE_HI22:
2976 Reloc::hi22(view, value, addend);
2977 break;
2978 case elfcpp::R_SPARC_TLS_IE_LO10:
2979 Reloc::lo10(view, value, addend);
2980 break;
2981 }
2982 break;
2983 }
2984 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
2985 _("unsupported reloc %u"),
2986 r_type);
2987 break;
2988
2989 case elfcpp::R_SPARC_TLS_LE_HIX22:
2990 // If we're creating a shared library, a dynamic relocation will
2991 // have been created for this location, so do not apply it now.
2992 if (!parameters->options().shared())
2993 {
2994 value -= tls_segment->memsz();
2995 Reloc::hix22(view, value, addend);
2996 }
2997 break;
2998
2999 case elfcpp::R_SPARC_TLS_LE_LOX10:
3000 // If we're creating a shared library, a dynamic relocation will
3001 // have been created for this location, so do not apply it now.
3002 if (!parameters->options().shared())
3003 {
3004 value -= tls_segment->memsz();
3005 Reloc::lox10(view, value, addend);
3006 }
3007 break;
3008 }
3009 }
3010
3011 // Relocate section data.
3012
3013 template<int size, bool big_endian>
3014 void
3015 Target_sparc<size, big_endian>::relocate_section(
3016 const Relocate_info<size, big_endian>* relinfo,
3017 unsigned int sh_type,
3018 const unsigned char* prelocs,
3019 size_t reloc_count,
3020 Output_section* output_section,
3021 bool needs_special_offset_handling,
3022 unsigned char* view,
3023 typename elfcpp::Elf_types<size>::Elf_Addr address,
3024 section_size_type view_size)
3025 {
3026 typedef Target_sparc<size, big_endian> Sparc;
3027 typedef typename Target_sparc<size, big_endian>::Relocate Sparc_relocate;
3028
3029 gold_assert(sh_type == elfcpp::SHT_RELA);
3030
3031 gold::relocate_section<size, big_endian, Sparc, elfcpp::SHT_RELA,
3032 Sparc_relocate>(
3033 relinfo,
3034 this,
3035 prelocs,
3036 reloc_count,
3037 output_section,
3038 needs_special_offset_handling,
3039 view,
3040 address,
3041 view_size);
3042 }
3043
3044 // Return the size of a relocation while scanning during a relocatable
3045 // link.
3046
3047 template<int size, bool big_endian>
3048 unsigned int
3049 Target_sparc<size, big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
3050 unsigned int,
3051 Relobj*)
3052 {
3053 // We are always SHT_RELA, so we should never get here.
3054 gold_unreachable();
3055 return 0;
3056 }
3057
3058 // Scan the relocs during a relocatable link.
3059
3060 template<int size, bool big_endian>
3061 void
3062 Target_sparc<size, big_endian>::scan_relocatable_relocs(
3063 const General_options& options,
3064 Symbol_table* symtab,
3065 Layout* layout,
3066 Sized_relobj<size, big_endian>* object,
3067 unsigned int data_shndx,
3068 unsigned int sh_type,
3069 const unsigned char* prelocs,
3070 size_t reloc_count,
3071 Output_section* output_section,
3072 bool needs_special_offset_handling,
3073 size_t local_symbol_count,
3074 const unsigned char* plocal_symbols,
3075 Relocatable_relocs* rr)
3076 {
3077 gold_assert(sh_type == elfcpp::SHT_RELA);
3078
3079 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
3080 Relocatable_size_for_reloc> Scan_relocatable_relocs;
3081
3082 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
3083 Scan_relocatable_relocs>(
3084 options,
3085 symtab,
3086 layout,
3087 object,
3088 data_shndx,
3089 prelocs,
3090 reloc_count,
3091 output_section,
3092 needs_special_offset_handling,
3093 local_symbol_count,
3094 plocal_symbols,
3095 rr);
3096 }
3097
3098 // Relocate a section during a relocatable link.
3099
3100 template<int size, bool big_endian>
3101 void
3102 Target_sparc<size, big_endian>::relocate_for_relocatable(
3103 const Relocate_info<size, big_endian>* relinfo,
3104 unsigned int sh_type,
3105 const unsigned char* prelocs,
3106 size_t reloc_count,
3107 Output_section* output_section,
3108 off_t offset_in_output_section,
3109 const Relocatable_relocs* rr,
3110 unsigned char* view,
3111 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
3112 section_size_type view_size,
3113 unsigned char* reloc_view,
3114 section_size_type reloc_view_size)
3115 {
3116 gold_assert(sh_type == elfcpp::SHT_RELA);
3117
3118 gold::relocate_for_relocatable<size, big_endian, elfcpp::SHT_RELA>(
3119 relinfo,
3120 prelocs,
3121 reloc_count,
3122 output_section,
3123 offset_in_output_section,
3124 rr,
3125 view,
3126 view_address,
3127 view_size,
3128 reloc_view,
3129 reloc_view_size);
3130 }
3131
3132 // Return the value to use for a dynamic which requires special
3133 // treatment. This is how we support equality comparisons of function
3134 // pointers across shared library boundaries, as described in the
3135 // processor specific ABI supplement.
3136
3137 template<int size, bool big_endian>
3138 uint64_t
3139 Target_sparc<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
3140 {
3141 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
3142 return this->plt_section()->address() + gsym->plt_offset();
3143 }
3144
3145 // The selector for sparc object files.
3146
3147 template<int size, bool big_endian>
3148 class Target_selector_sparc : public Target_selector
3149 {
3150 public:
3151 Target_selector_sparc()
3152 : Target_selector(elfcpp::EM_NONE, size, big_endian,
3153 (size == 64 ? "elf64-sparc" : "elf32-sparc"))
3154 { }
3155
3156 Target* instantiated_target_;
3157
3158 Target* do_recognize(int machine, int, int)
3159 {
3160 switch (size)
3161 {
3162 case 64:
3163 if (machine != elfcpp::EM_SPARCV9)
3164 return NULL;
3165 break;
3166
3167 case 32:
3168 if (machine != elfcpp::EM_SPARC
3169 && machine != elfcpp::EM_SPARC32PLUS)
3170 return NULL;
3171 break;
3172
3173 default:
3174 return NULL;
3175 }
3176
3177 return do_instantiate_target();
3178 }
3179
3180 Target* do_instantiate_target()
3181 {
3182 if (this->instantiated_target_ == NULL)
3183 this->instantiated_target_ = new Target_sparc<size, big_endian>();
3184 return this->instantiated_target_;
3185 }
3186 };
3187
3188 Target_selector_sparc<32, true> target_selector_sparc32;
3189 Target_selector_sparc<64, true> target_selector_sparc64;
3190
3191 } // End anonymous namespace.
This page took 0.091073 seconds and 5 git commands to generate.