daily update
[deliverable/binutils-gdb.git] / gold / tilegx.cc
CommitLineData
5c0b3823
WL
1// tilegx.cc -- tilegx target support for gold.
2
3// Copyright 2012 Free Software Foundation, Inc.
4// Written by Jiong Wang (jiwang@tilera.com)
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 <cstring>
26
27#include "elfcpp.h"
28#include "dwarf.h"
29#include "parameters.h"
30#include "reloc.h"
31#include "tilegx.h"
32#include "object.h"
33#include "symtab.h"
34#include "layout.h"
35#include "output.h"
36#include "copy-relocs.h"
37#include "target.h"
38#include "target-reloc.h"
39#include "target-select.h"
40#include "tls.h"
41#include "gc.h"
42#include "icf.h"
43
44// the first got entry reserved
45const int32_t TILEGX_GOT_RESERVE_COUNT = 1;
46
47// the first two .got.plt entry reserved
48const int32_t TILEGX_GOTPLT_RESERVE_COUNT = 2;
49
50// 1. for both 64/32 bit mode, the instruction bundle is always 64bit.
51// 2. thus .plt section should always be aligned to 64 bit.
52const int32_t TILEGX_INST_BUNDLE_SIZE = 64;
53
54namespace
55{
56
57using namespace gold;
58
59// A class to handle the PLT data.
60// This is an abstract base class that handles most of the linker details
61// but does not know the actual contents of PLT entries. The derived
62// classes below fill in those details.
63
64template<int size, bool big_endian>
65class Output_data_plt_tilegx : public Output_section_data
66{
67 public:
68 typedef Output_data_reloc<elfcpp::SHT_RELA, true,size, big_endian>
69 Reloc_section;
70
71 Output_data_plt_tilegx(Layout* layout, uint64_t addralign,
72 Output_data_got<size, big_endian>* got,
73 Output_data_space* got_plt,
74 Output_data_space* got_irelative)
75 : Output_section_data(addralign), layout_(layout),
76 irelative_rel_(NULL), got_(got), got_plt_(got_plt),
77 got_irelative_(got_irelative), count_(0),
78 irelative_count_(0), free_list_()
79 { this->init(layout); }
80
81 Output_data_plt_tilegx(Layout* layout, uint64_t plt_entry_size,
82 Output_data_got<size, big_endian>* got,
83 Output_data_space* got_plt,
84 Output_data_space* got_irelative,
85 unsigned int plt_count)
86 : Output_section_data((plt_count + 1) * plt_entry_size,
87 TILEGX_INST_BUNDLE_SIZE, false),
88 layout_(layout), irelative_rel_(NULL), got_(got),
89 got_plt_(got_plt), got_irelative_(got_irelative), count_(plt_count),
90 irelative_count_(0), free_list_()
91 {
92 this->init(layout);
93
94 // Initialize the free list and reserve the first entry.
95 this->free_list_.init((plt_count + 1) * plt_entry_size, false);
96 this->free_list_.remove(0, plt_entry_size);
97 }
98
99 // Initialize the PLT section.
100 void
101 init(Layout* layout);
102
103 // Add an entry to the PLT.
104 void
105 add_entry(Symbol_table*, Layout*, Symbol* gsym);
106
107 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
108 unsigned int
109 add_local_ifunc_entry(Symbol_table*, Layout*,
110 Sized_relobj_file<size, big_endian>*, unsigned int);
111
112 // Add the relocation for a PLT entry.
113 void
114 add_relocation(Symbol_table*, Layout*, Symbol*, unsigned int);
115
116 // Return the .rela.plt section data.
117 Reloc_section*
118 rela_plt()
119 { return this->rel_; }
120
121 // Return where the IRELATIVE relocations should go in the PLT
122 // relocations.
123 Reloc_section*
124 rela_irelative(Symbol_table*, Layout*);
125
126 // Return whether we created a section for IRELATIVE relocations.
127 bool
128 has_irelative_section() const
129 { return this->irelative_rel_ != NULL; }
130
131 // Return the number of PLT entries.
132 unsigned int
133 entry_count() const
134 { return this->count_ + this->irelative_count_; }
135
136 // Return the offset of the first non-reserved PLT entry.
137 unsigned int
138 first_plt_entry_offset()
139 { return this->get_plt_entry_size(); }
140
141 // Return the size of a PLT entry.
142 unsigned int
143 get_plt_entry_size() const
144 { return plt_entry_size; }
145
146 // Reserve a slot in the PLT for an existing symbol in an incremental update.
147 void
148 reserve_slot(unsigned int plt_index)
149 {
150 this->free_list_.remove((plt_index + 1) * this->get_plt_entry_size(),
151 (plt_index + 2) * this->get_plt_entry_size());
152 }
153
154 // Return the PLT address to use for a global symbol.
155 uint64_t
156 address_for_global(const Symbol*);
157
158 // Return the PLT address to use for a local symbol.
159 uint64_t
160 address_for_local(const Relobj*, unsigned int symndx);
161
162 protected:
163 // Fill in the first PLT entry.
164 void
165 fill_first_plt_entry(unsigned char*);
166
167 // Fill in a normal PLT entry. Returns the offset into the entry that
168 // should be the initial GOT slot value.
169 void
170 fill_plt_entry(unsigned char*,
171 typename elfcpp::Elf_types<size>::Elf_Addr,
172 unsigned int,
173 typename elfcpp::Elf_types<size>::Elf_Addr,
174 unsigned int, unsigned int);
175
176 void
177 do_adjust_output_section(Output_section* os);
178
179 // Write to a map file.
180 void
181 do_print_to_mapfile(Mapfile* mapfile) const
182 { mapfile->print_output_data(this, _("** PLT")); }
183
184 private:
185 // Set the final size.
186 void
187 set_final_data_size();
188
189 // Write out the PLT data.
190 void
191 do_write(Output_file*);
192
193 // A pointer to the Layout class, so that we can find the .dynamic
194 // section when we write out the GOT PLT section.
195 Layout* layout_;
196 // The reloc section.
197 Reloc_section* rel_;
198 // The IRELATIVE relocs, if necessary. These must follow the
199 // regular PLT relocations.
200 Reloc_section* irelative_rel_;
201 // The .got section.
202 Output_data_got<size, big_endian>* got_;
203 // The .got.plt section.
204 Output_data_space* got_plt_;
205 // The part of the .got.plt section used for IRELATIVE relocs.
206 Output_data_space* got_irelative_;
207 // The number of PLT entries.
208 unsigned int count_;
209 // Number of PLT entries with R_TILEGX_IRELATIVE relocs. These
210 // follow the regular PLT entries.
211 unsigned int irelative_count_;
212 // List of available regions within the section, for incremental
213 // update links.
214 Free_list free_list_;
215 // The size of an entry in the PLT.
216 static const int plt_entry_size = 40;
217 // The first entry in the PLT.
218 static const unsigned char first_plt_entry[plt_entry_size];
219 // Other entries in the PLT for an executable.
220 static const unsigned char plt_entry[plt_entry_size];
221};
222
223// The tilegx target class.
224// See the ABI at
225// http://www.tilera.com/scm
226// TLS info comes from
227// http://people.redhat.com/drepper/tls.pdf
228
229template<int size, bool big_endian>
230class Target_tilegx : public Sized_target<size, big_endian>
231{
232 public:
233 // TileGX use RELA
234 typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian>
235 Reloc_section;
236
237 Target_tilegx(const Target::Target_info* info = &tilegx_info)
238 : Sized_target<size, big_endian>(info),
239 got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
240 global_offset_table_(NULL), tilegx_dynamic_(NULL), rela_dyn_(NULL),
241 rela_irelative_(NULL), copy_relocs_(elfcpp::R_TILEGX_COPY),
242 dynbss_(NULL), got_mod_index_offset_(-1U),
243 tls_get_addr_sym_defined_(false)
244 { }
245
246 // Scan the relocations to look for symbol adjustments.
247 void
248 gc_process_relocs(Symbol_table* symtab,
249 Layout* layout,
250 Sized_relobj_file<size, big_endian>* object,
251 unsigned int data_shndx,
252 unsigned int sh_type,
253 const unsigned char* prelocs,
254 size_t reloc_count,
255 Output_section* output_section,
256 bool needs_special_offset_handling,
257 size_t local_symbol_count,
258 const unsigned char* plocal_symbols);
259
260 // Scan the relocations to look for symbol adjustments.
261 void
262 scan_relocs(Symbol_table* symtab,
263 Layout* layout,
264 Sized_relobj_file<size, big_endian>* object,
265 unsigned int data_shndx,
266 unsigned int sh_type,
267 const unsigned char* prelocs,
268 size_t reloc_count,
269 Output_section* output_section,
270 bool needs_special_offset_handling,
271 size_t local_symbol_count,
272 const unsigned char* plocal_symbols);
273
274 // Finalize the sections.
275 void
276 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
277
278 // Return the value to use for a dynamic which requires special
279 // treatment.
280 uint64_t
281 do_dynsym_value(const Symbol*) const;
282
283 // Relocate a section.
284 void
285 relocate_section(const Relocate_info<size, big_endian>*,
286 unsigned int sh_type,
287 const unsigned char* prelocs,
288 size_t reloc_count,
289 Output_section* output_section,
290 bool needs_special_offset_handling,
291 unsigned char* view,
292 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
293 section_size_type view_size,
294 const Reloc_symbol_changes*);
295
296 // Scan the relocs during a relocatable link.
297 void
298 scan_relocatable_relocs(Symbol_table* symtab,
299 Layout* layout,
300 Sized_relobj_file<size, big_endian>* object,
301 unsigned int data_shndx,
302 unsigned int sh_type,
303 const unsigned char* prelocs,
304 size_t reloc_count,
305 Output_section* output_section,
306 bool needs_special_offset_handling,
307 size_t local_symbol_count,
308 const unsigned char* plocal_symbols,
309 Relocatable_relocs*);
310
311 // Relocate a section during a relocatable link.
312 void
313 relocate_relocs(
314 const Relocate_info<size, big_endian>*,
315 unsigned int sh_type,
316 const unsigned char* prelocs,
317 size_t reloc_count,
318 Output_section* output_section,
319 off_t offset_in_output_section,
320 const Relocatable_relocs*,
321 unsigned char* view,
322 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
323 section_size_type view_size,
324 unsigned char* reloc_view,
325 section_size_type reloc_view_size);
326
327 // Return whether SYM is defined by the ABI.
328 bool
329 do_is_defined_by_abi(const Symbol* sym) const
330 { return strcmp(sym->name(), "__tls_get_addr") == 0; }
331
332 // define tilegx specific symbols
333 virtual void
334 do_define_standard_symbols(Symbol_table*, Layout*);
335
336 // Return the PLT section.
337 uint64_t
338 do_plt_address_for_global(const Symbol* gsym) const
339 { return this->plt_section()->address_for_global(gsym); }
340
341 uint64_t
342 do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
343 { return this->plt_section()->address_for_local(relobj, symndx); }
344
345 // This function should be defined in targets that can use relocation
346 // types to determine (implemented in local_reloc_may_be_function_pointer
347 // and global_reloc_may_be_function_pointer)
348 // if a function's pointer is taken. ICF uses this in safe mode to only
349 // fold those functions whose pointer is defintely not taken. For tilegx
350 // pie binaries, safe ICF cannot be done by looking at relocation types.
351 bool
352 do_can_check_for_function_pointers() const
353 { return true; }
354
355 // Return the base for a DW_EH_PE_datarel encoding.
356 uint64_t
357 do_ehframe_datarel_base() const;
358
359 // Return whether there is a GOT section.
360 bool
361 has_got_section() const
362 { return this->got_ != NULL; }
363
364 // Return the size of the GOT section.
365 section_size_type
366 got_size() const
367 {
368 gold_assert(this->got_ != NULL);
369 return this->got_->data_size();
370 }
371
372 // Return the number of entries in the GOT.
373 unsigned int
374 got_entry_count() const
375 {
376 if (this->got_ == NULL)
377 return 0;
378 return this->got_size() / (size / 8);
379 }
380
381 // Return the number of entries in the PLT.
382 unsigned int
383 plt_entry_count() const;
384
385 // Return the offset of the first non-reserved PLT entry.
386 unsigned int
387 first_plt_entry_offset() const;
388
389 // Return the size of each PLT entry.
390 unsigned int
391 plt_entry_size() const;
392
393 // Create the GOT section for an incremental update.
394 Output_data_got_base*
395 init_got_plt_for_update(Symbol_table* symtab,
396 Layout* layout,
397 unsigned int got_count,
398 unsigned int plt_count);
399
400 // Reserve a GOT entry for a local symbol, and regenerate any
401 // necessary dynamic relocations.
402 void
403 reserve_local_got_entry(unsigned int got_index,
404 Sized_relobj<size, big_endian>* obj,
405 unsigned int r_sym,
406 unsigned int got_type);
407
408 // Reserve a GOT entry for a global symbol, and regenerate any
409 // necessary dynamic relocations.
410 void
411 reserve_global_got_entry(unsigned int got_index, Symbol* gsym,
412 unsigned int got_type);
413
414 // Register an existing PLT entry for a global symbol.
415 void
416 register_global_plt_entry(Symbol_table*, Layout*, unsigned int plt_index,
417 Symbol* gsym);
418
419 // Force a COPY relocation for a given symbol.
420 void
421 emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t);
422
423 // Apply an incremental relocation.
424 void
425 apply_relocation(const Relocate_info<size, big_endian>* relinfo,
426 typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
427 unsigned int r_type,
428 typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
429 const Symbol* gsym,
430 unsigned char* view,
431 typename elfcpp::Elf_types<size>::Elf_Addr address,
432 section_size_type view_size);
433
434 private:
435 // The class which scans relocations.
436 class Scan
437 {
438 public:
439 Scan()
440 : issued_non_pic_error_(false)
441 { }
442
443 static inline int
444 get_reference_flags(unsigned int r_type);
445
446 inline void
447 local(Symbol_table* symtab, Layout* layout, Target_tilegx* target,
448 Sized_relobj_file<size, big_endian>* object,
449 unsigned int data_shndx,
450 Output_section* output_section,
451 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
452 const elfcpp::Sym<size, big_endian>& lsym,
453 bool is_discarded);
454
455 inline void
456 global(Symbol_table* symtab, Layout* layout, Target_tilegx* target,
457 Sized_relobj_file<size, big_endian>* object,
458 unsigned int data_shndx,
459 Output_section* output_section,
460 const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
461 Symbol* gsym);
462
463 inline bool
464 local_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
465 Target_tilegx* target,
466 Sized_relobj_file<size, big_endian>* object,
467 unsigned int data_shndx,
468 Output_section* output_section,
469 const elfcpp::Rela<size, big_endian>& reloc,
470 unsigned int r_type,
471 const elfcpp::Sym<size, big_endian>& lsym);
472
473 inline bool
474 global_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
475 Target_tilegx* target,
476 Sized_relobj_file<size, big_endian>* object,
477 unsigned int data_shndx,
478 Output_section* output_section,
479 const elfcpp::Rela<size, big_endian>& reloc,
480 unsigned int r_type,
481 Symbol* gsym);
482
483 private:
484 static void
485 unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
486 unsigned int r_type);
487
488 static void
489 unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
490 unsigned int r_type, Symbol*);
491
492 void
493 check_non_pic(Relobj*, unsigned int r_type);
494
495 inline bool
496 possible_function_pointer_reloc(unsigned int r_type);
497
498 bool
499 reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*,
500 unsigned int r_type);
501
502 // Whether we have issued an error about a non-PIC compilation.
503 bool issued_non_pic_error_;
504 };
505
506 // The class which implements relocation.
507 class Relocate
508 {
509 public:
510 Relocate()
511 { }
512
513 ~Relocate()
514 {
515 }
516
517 // Do a relocation. Return false if the caller should not issue
518 // any warnings about this relocation.
519 inline bool
520 relocate(const Relocate_info<size, big_endian>*, Target_tilegx*,
521 Output_section*,
522 size_t relnum, const elfcpp::Rela<size, big_endian>&,
523 unsigned int r_type, const Sized_symbol<size>*,
524 const Symbol_value<size>*,
525 unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
526 section_size_type);
527 };
528
529 // A class which returns the size required for a relocation type,
530 // used while scanning relocs during a relocatable link.
531 class Relocatable_size_for_reloc
532 {
533 public:
534 unsigned int
535 get_size_for_reloc(unsigned int, Relobj*);
536 };
537
538 // Adjust TLS relocation type based on the options and whether this
539 // is a local symbol.
540 static tls::Tls_optimization
541 optimize_tls_reloc(bool is_final, int r_type);
542
543 // Get the GOT section, creating it if necessary.
544 Output_data_got<size, big_endian>*
545 got_section(Symbol_table*, Layout*);
546
547 // Get the GOT PLT section.
548 Output_data_space*
549 got_plt_section() const
550 {
551 gold_assert(this->got_plt_ != NULL);
552 return this->got_plt_;
553 }
554
555 // Create the PLT section.
556 void
557 make_plt_section(Symbol_table* symtab, Layout* layout);
558
559 // Create a PLT entry for a global symbol.
560 void
561 make_plt_entry(Symbol_table*, Layout*, Symbol*);
562
563 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
564 void
565 make_local_ifunc_plt_entry(Symbol_table*, Layout*,
566 Sized_relobj_file<size, big_endian>* relobj,
567 unsigned int local_sym_index);
568
569 // Create a GOT entry for the TLS module index.
570 unsigned int
571 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
572 Sized_relobj_file<size, big_endian>* object);
573
574 // Get the PLT section.
575 Output_data_plt_tilegx<size, big_endian>*
576 plt_section() const
577 {
578 gold_assert(this->plt_ != NULL);
579 return this->plt_;
580 }
581
582 // Get the dynamic reloc section, creating it if necessary.
583 Reloc_section*
584 rela_dyn_section(Layout*);
585
586 // Get the section to use for IRELATIVE relocations.
587 Reloc_section*
588 rela_irelative_section(Layout*);
589
590 // Add a potential copy relocation.
591 void
592 copy_reloc(Symbol_table* symtab, Layout* layout,
593 Sized_relobj_file<size, big_endian>* object,
594 unsigned int shndx, Output_section* output_section,
595 Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
596 {
597 this->copy_relocs_.copy_reloc(symtab, layout,
598 symtab->get_sized_symbol<size>(sym),
599 object, shndx, output_section,
600 reloc, this->rela_dyn_section(layout));
601 }
602
603 // Information about this specific target which we pass to the
604 // general Target structure.
605 static const Target::Target_info tilegx_info;
606
607 // The types of GOT entries needed for this platform.
608 // These values are exposed to the ABI in an incremental link.
609 // Do not renumber existing values without changing the version
610 // number of the .gnu_incremental_inputs section.
611 enum Got_type
612 {
613 GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
614 GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
615 GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
616 GOT_TYPE_TLS_DESC = 3 // GOT entry for TLS_DESC pair
617 };
618
619 // This type is used as the argument to the target specific
620 // relocation routines. The only target specific reloc is
621 // R_X86_64_TLSDESC against a local symbol.
622 struct Tlsdesc_info
623 {
624 Tlsdesc_info(Sized_relobj_file<size, big_endian>* a_object,
625 unsigned int a_r_sym)
626 : object(a_object), r_sym(a_r_sym)
627 { }
628
629 // The object in which the local symbol is defined.
630 Sized_relobj_file<size, big_endian>* object;
631 // The local symbol index in the object.
632 unsigned int r_sym;
633 };
634
635 // The GOT section.
636 Output_data_got<size, big_endian>* got_;
637 // The PLT section.
638 Output_data_plt_tilegx<size, big_endian>* plt_;
639 // The GOT PLT section.
640 Output_data_space* got_plt_;
641 // The GOT section for IRELATIVE relocations.
642 Output_data_space* got_irelative_;
643 // The _GLOBAL_OFFSET_TABLE_ symbol.
644 Symbol* global_offset_table_;
645 // The _TILEGX_DYNAMIC_ symbol.
646 Symbol* tilegx_dynamic_;
647 // The dynamic reloc section.
648 Reloc_section* rela_dyn_;
649 // The section to use for IRELATIVE relocs.
650 Reloc_section* rela_irelative_;
651 // Relocs saved to avoid a COPY reloc.
652 Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
653 // Space for variables copied with a COPY reloc.
654 Output_data_space* dynbss_;
655 // Offset of the GOT entry for the TLS module index.
656 unsigned int got_mod_index_offset_;
657 // True if the _tls_get_addr symbol has been defined.
658 bool tls_get_addr_sym_defined_;
659};
660
661template<>
662const Target::Target_info Target_tilegx<64, false>::tilegx_info =
663{
664 64, // size
665 false, // is_big_endian
666 elfcpp::EM_TILEGX, // machine_code
667 false, // has_make_symbol
668 false, // has_resolve
669 false, // has_code_fill
670 true, // is_default_stack_executable
671 false, // can_icf_inline_merge_sections
672 '\0', // wrap_char
673 "/lib/ld.so.1", // program interpreter
674 0x10000, // default_text_segment_address
675 0x10000, // abi_pagesize (overridable by -z max-page-size)
676 0x10000, // common_pagesize (overridable by -z common-page-size)
677 false, // isolate_execinstr
678 0, // rosegment_gap
679 elfcpp::SHN_UNDEF, // small_common_shndx
680 elfcpp::SHN_UNDEF, // large_common_shndx
681 0, // small_common_section_flags
682 0, // large_common_section_flags
683 NULL, // attributes_section
684 NULL // attributes_vendor
685};
686
687template<>
688const Target::Target_info Target_tilegx<32, false>::tilegx_info =
689{
690 32, // size
691 false, // is_big_endian
692 elfcpp::EM_TILEGX, // machine_code
693 false, // has_make_symbol
694 false, // has_resolve
695 false, // has_code_fill
696 true, // is_default_stack_executable
697 false, // can_icf_inline_merge_sections
698 '\0', // wrap_char
699 "/lib32/ld.so.1", // program interpreter
700 0x10000, // default_text_segment_address
701 0x10000, // abi_pagesize (overridable by -z max-page-size)
702 0x10000, // common_pagesize (overridable by -z common-page-size)
703 false, // isolate_execinstr
704 0, // rosegment_gap
705 elfcpp::SHN_UNDEF, // small_common_shndx
706 elfcpp::SHN_UNDEF, // large_common_shndx
707 0, // small_common_section_flags
708 0, // large_common_section_flags
709 NULL, // attributes_section
710 NULL // attributes_vendor
711};
712
713template<>
714const Target::Target_info Target_tilegx<64, true>::tilegx_info =
715{
716 64, // size
717 true, // is_big_endian
718 elfcpp::EM_TILEGX, // machine_code
719 false, // has_make_symbol
720 false, // has_resolve
721 false, // has_code_fill
722 true, // is_default_stack_executable
723 false, // can_icf_inline_merge_sections
724 '\0', // wrap_char
725 "/lib/ld.so.1", // program interpreter
726 0x10000, // default_text_segment_address
727 0x10000, // abi_pagesize (overridable by -z max-page-size)
728 0x10000, // common_pagesize (overridable by -z common-page-size)
729 false, // isolate_execinstr
730 0, // rosegment_gap
731 elfcpp::SHN_UNDEF, // small_common_shndx
732 elfcpp::SHN_UNDEF, // large_common_shndx
733 0, // small_common_section_flags
734 0, // large_common_section_flags
735 NULL, // attributes_section
736 NULL // attributes_vendor
737};
738
739template<>
740const Target::Target_info Target_tilegx<32, true>::tilegx_info =
741{
742 32, // size
743 true, // is_big_endian
744 elfcpp::EM_TILEGX, // machine_code
745 false, // has_make_symbol
746 false, // has_resolve
747 false, // has_code_fill
748 true, // is_default_stack_executable
749 false, // can_icf_inline_merge_sections
750 '\0', // wrap_char
751 "/lib32/ld.so.1", // program interpreter
752 0x10000, // default_text_segment_address
753 0x10000, // abi_pagesize (overridable by -z max-page-size)
754 0x10000, // common_pagesize (overridable by -z common-page-size)
755 false, // isolate_execinstr
756 0, // rosegment_gap
757 elfcpp::SHN_UNDEF, // small_common_shndx
758 elfcpp::SHN_UNDEF, // large_common_shndx
759 0, // small_common_section_flags
760 0, // large_common_section_flags
761 NULL, // attributes_section
762 NULL // attributes_vendor
763};
764
765// tilegx relocation handlers
766template<int size, bool big_endian>
767class Tilegx_relocate_functions
768{
769public:
770 // overflow check will be supported later
771 typedef enum
772 {
773 STATUS_OKAY, // No error during relocation.
774 STATUS_OVERFLOW, // Relocation overflow.
775 STATUS_BAD_RELOC // Relocation cannot be applied.
776 } Status;
777
778 struct Tilegx_howto
779 {
780 // right shift operand by this number of bits.
781 unsigned char srshift;
782
783 // the offset to apply relocation.
784 unsigned char doffset;
785
786 // set to 1 for pc-relative relocation.
787 unsigned char is_pcrel;
788
789 // size in bits, or 0 if this table entry should be ignored.
790 unsigned char bsize;
791
792 // whether we need to check overflow.
793 unsigned char overflow;
794 };
795
796 static const Tilegx_howto howto[elfcpp::R_TILEGX_NUM];
797
798private:
799
800 // Do a simple rela relocation
801 template<int valsize>
802 static inline void
803 rela(unsigned char* view,
804 const Sized_relobj_file<size, big_endian>* object,
805 const Symbol_value<size>* psymval,
806 typename elfcpp::Swap<size, big_endian>::Valtype addend,
807 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
808 elfcpp::Elf_Xword bitmask)
809 {
810 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
811 Valtype* wv = reinterpret_cast<Valtype*>(view);
812 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
813 Valtype reloc = 0;
814 if (size == 32)
815 reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
816 else
817 reloc = psymval->value(object, addend) >> srshift;
818
819 elfcpp::Elf_Xword dst_mask = bitmask << doffset;
820
821 val &= ~dst_mask;
822 reloc &= bitmask;
823
824 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | (reloc<<doffset));
825 }
826
827 // Do a simple rela relocation
828 template<int valsize>
829 static inline void
830 rela_ua(unsigned char* view,
831 const Sized_relobj_file<size, big_endian>* object,
832 const Symbol_value<size>* psymval,
833 typename elfcpp::Swap<size, big_endian>::Valtype addend,
834 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
835 elfcpp::Elf_Xword bitmask)
836 {
837 typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
838 Valtype;
839 unsigned char* wv = view;
840 Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
841 Valtype reloc = 0;
842 if (size == 32)
843 reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
844 else
845 reloc = psymval->value(object, addend) >> srshift;
846
847 elfcpp::Elf_Xword dst_mask = bitmask << doffset;
848
849 val &= ~dst_mask;
850 reloc &= bitmask;
851
852 elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv,
853 val | (reloc<<doffset));
854 }
855
856 template<int valsize>
857 static inline void
858 rela(unsigned char* view,
859 const Sized_relobj_file<size, big_endian>* object,
860 const Symbol_value<size>* psymval,
861 typename elfcpp::Swap<size, big_endian>::Valtype addend,
862 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset1,
863 elfcpp::Elf_Xword bitmask1, elfcpp::Elf_Xword doffset2,
864 elfcpp::Elf_Xword bitmask2)
865 {
866 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
867 Valtype* wv = reinterpret_cast<Valtype*>(view);
868 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
869 Valtype reloc = 0;
870 if (size == 32)
871 reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
872 else
873 reloc = psymval->value(object, addend) >> srshift;
874
875 elfcpp::Elf_Xword dst_mask = (bitmask1 << doffset1)
876 | (bitmask2 << doffset2);
877 val &= ~dst_mask;
878 reloc = ((reloc & bitmask1) << doffset1)
879 | ((reloc & bitmask2) << doffset2);
880
881 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
882
883 }
884
885 // Do a simple PC relative relocation with a Symbol_value with the
886 // addend in the relocation.
887 template<int valsize>
888 static inline void
889 pcrela(unsigned char* view,
890 const Sized_relobj_file<size, big_endian>* object,
891 const Symbol_value<size>* psymval,
892 typename elfcpp::Swap<size, big_endian>::Valtype addend,
893 typename elfcpp::Elf_types<size>::Elf_Addr address,
894 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
895 elfcpp::Elf_Xword bitmask)
896
897 {
898 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
899 Valtype* wv = reinterpret_cast<Valtype*>(view);
900 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
901 Valtype reloc = 0;
902 if (size == 32)
903 reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
904 >> srshift;
905 else
906 reloc = (psymval->value(object, addend) - address) >> srshift;
907
908 elfcpp::Elf_Xword dst_mask = bitmask << doffset;
909 val &= ~dst_mask;
910 reloc &= bitmask;
911
912 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | (reloc<<doffset));
913 }
914
915 template<int valsize>
916 static inline void
917 pcrela_ua(unsigned char* view,
918 const Sized_relobj_file<size, big_endian>* object,
919 const Symbol_value<size>* psymval,
920 typename elfcpp::Swap<size, big_endian>::Valtype addend,
921 typename elfcpp::Elf_types<size>::Elf_Addr address,
922 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
923 elfcpp::Elf_Xword bitmask)
924
925 {
926 typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
927 Valtype;
928 unsigned char* wv = view;
929 Valtype reloc = 0;
930 if (size == 32)
931 reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
932 >> srshift;
933 else
934 reloc = (psymval->value(object, addend) - address) >> srshift;
935
936 reloc &= bitmask;
937
938 elfcpp::Swap<valsize, big_endian>::writeval(wv, reloc << doffset);
939 }
940
941 template<int valsize>
942 static inline void
943 pcrela(unsigned char* view,
944 const Sized_relobj_file<size, big_endian>* object,
945 const Symbol_value<size>* psymval,
946 typename elfcpp::Swap<size, big_endian>::Valtype addend,
947 typename elfcpp::Elf_types<size>::Elf_Addr address,
948 elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset1,
949 elfcpp::Elf_Xword bitmask1, elfcpp::Elf_Xword doffset2,
950 elfcpp::Elf_Xword bitmask2)
951
952 {
953 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
954 Valtype* wv = reinterpret_cast<Valtype*>(view);
955 Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
956 Valtype reloc = 0;
957 if (size == 32)
958 reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
959 >> srshift;
960 else
961 reloc = (psymval->value(object, addend) - address) >> srshift;
962
963 elfcpp::Elf_Xword dst_mask = (bitmask1 << doffset1)
964 | (bitmask2 << doffset2);
965 val &= ~dst_mask;
966 reloc = ((reloc & bitmask1) << doffset1)
967 | ((reloc & bitmask2) << doffset2);
968
969 elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
970 }
971
972 typedef Tilegx_relocate_functions<size, big_endian> This;
973 typedef Relocate_functions<size, big_endian> Base;
974
975public:
976
977 static inline void
978 abs64(unsigned char* view,
979 const Sized_relobj_file<size, big_endian>* object,
980 const Symbol_value<size>* psymval,
981 typename elfcpp::Elf_types<size>::Elf_Addr addend)
982 {
983 This::template rela_ua<64>(view, object, psymval, addend, 0, 0,
984 0xffffffffffffffffllu);
985 }
986
987 static inline void
988 abs32(unsigned char* view,
989 const Sized_relobj_file<size, big_endian>* object,
990 const Symbol_value<size>* psymval,
991 typename elfcpp::Elf_types<size>::Elf_Addr addend)
992 {
993 This::template rela_ua<32>(view, object, psymval, addend, 0, 0,
994 0xffffffff);
995 }
996
997 static inline void
998 abs16(unsigned char* view,
999 const Sized_relobj_file<size, big_endian>* object,
1000 const Symbol_value<size>* psymval,
1001 typename elfcpp::Elf_types<size>::Elf_Addr addend)
1002 {
1003 This::template rela_ua<16>(view, object, psymval, addend, 0, 0,
1004 0xffff);
1005 }
1006
1007 static inline void
1008 pc_abs64(unsigned char* view,
1009 const Sized_relobj_file<size, big_endian>* object,
1010 const Symbol_value<size>* psymval,
1011 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1012 typename elfcpp::Elf_types<size>::Elf_Addr address)
1013 {
1014 This::template pcrela_ua<64>(view, object, psymval, addend, address, 0, 0,
1015 0xffffffffffffffffllu);
1016 }
1017
1018 static inline void
1019 pc_abs32(unsigned char* view,
1020 const Sized_relobj_file<size, big_endian>* object,
1021 const Symbol_value<size>* psymval,
1022 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1023 typename elfcpp::Elf_types<size>::Elf_Addr address)
1024 {
1025 This::template pcrela_ua<32>(view, object, psymval, addend, address, 0, 0,
1026 0xffffffff);
1027 }
1028
1029 static inline void
1030 pc_abs16(unsigned char* view,
1031 const Sized_relobj_file<size, big_endian>* object,
1032 const Symbol_value<size>* psymval,
1033 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1034 typename elfcpp::Elf_types<size>::Elf_Addr address)
1035 {
1036 This::template pcrela_ua<16>(view, object, psymval, addend, address, 0, 0,
1037 0xffff);
1038 }
1039
1040 static inline void
1041 imm_x_general(unsigned char* view,
1042 const Sized_relobj_file<size, big_endian>* object,
1043 const Symbol_value<size>* psymval,
1044 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1045 Tilegx_howto &r_howto)
1046 {
1047 This::template rela<64>(view, object, psymval, addend,
1048 (elfcpp::Elf_Xword)(r_howto.srshift),
1049 (elfcpp::Elf_Xword)(r_howto.doffset),
1050 (elfcpp::Elf_Xword)((1 << r_howto.bsize) - 1));
1051 }
1052
1053 static inline void
1054 imm_x_pcrel_general(unsigned char* view,
1055 const Sized_relobj_file<size, big_endian>* object,
1056 const Symbol_value<size>* psymval,
1057 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1058 typename elfcpp::Elf_types<size>::Elf_Addr address,
1059 Tilegx_howto &r_howto)
1060 {
1061 This::template pcrela<64>(view, object, psymval, addend, address,
1062 (elfcpp::Elf_Xword)(r_howto.srshift),
1063 (elfcpp::Elf_Xword)(r_howto.doffset),
1064 (elfcpp::Elf_Xword)((1 << r_howto.bsize) - 1));
1065 }
1066
1067 static inline void
1068 imm_x_two_part_general(unsigned char* view,
1069 const Sized_relobj_file<size, big_endian>* object,
1070 const Symbol_value<size>* psymval,
1071 typename elfcpp::Elf_types<size>::Elf_Addr addend,
1072 typename elfcpp::Elf_types<size>::Elf_Addr address,
1073 unsigned int r_type)
1074 {
1075
1076 elfcpp::Elf_Xword doffset1 = 0llu;
1077 elfcpp::Elf_Xword doffset2 = 0llu;
1078 elfcpp::Elf_Xword dmask1 = 0llu;
1079 elfcpp::Elf_Xword dmask2 = 0llu;
1080 elfcpp::Elf_Xword rshift = 0llu;
1081 unsigned int pc_rel = 0;
1082
1083 switch (r_type)
1084 {
1085 case elfcpp::R_TILEGX_BROFF_X1:
1086 doffset1 = 31llu;
1087 doffset2 = 37llu;
1088 dmask1 = 0x3fllu;
1089 dmask2 = 0x1ffc0llu;
1090 rshift = 3llu;
1091 pc_rel = 1;
1092 break;
1093 case elfcpp::R_TILEGX_DEST_IMM8_X1:
1094 doffset1 = 31llu;
1095 doffset2 = 43llu;
1096 dmask1 = 0x3fllu;
1097 dmask2 = 0xc0llu;
1098 rshift = 0llu;
1099 break;
1100 }
1101
1102 if (pc_rel)
1103 This::template pcrela<64>(view, object, psymval, addend, address,
1104 rshift, doffset1, dmask1, doffset2, dmask2);
1105 else
1106 This::template rela<64>(view, object, psymval, addend, rshift,
1107 doffset1, dmask1, doffset2, dmask2);
1108
1109 }
1110
1111 static inline void
1112 tls_relax(unsigned char* view, unsigned int r_type,
1113 tls::Tls_optimization opt_t)
1114 {
1115
1116 const uint64_t TILEGX_X_MOVE_R0_R0 = 0x283bf8005107f000llu;
1117 const uint64_t TILEGX_Y_MOVE_R0_R0 = 0xae05f800540bf000llu;
1118 const uint64_t TILEGX_X_LD = 0x286ae80000000000llu;
1119 const uint64_t TILEGX_X_LD4S = 0x286a980000000000llu;
1120 const uint64_t TILEGX_X1_FULL_MASK = 0x3fffffff80000000llu;
1121 const uint64_t TILEGX_X0_RRR_MASK = 0x000000007ffc0000llu;
1122 const uint64_t TILEGX_X1_RRR_MASK = 0x3ffe000000000000llu;
1123 const uint64_t TILEGX_Y0_RRR_MASK = 0x00000000780c0000llu;
1124 const uint64_t TILEGX_Y1_RRR_MASK = 0x3c06000000000000llu;
1125 const uint64_t TILEGX_X0_RRR_SRCB_MASK = 0x000000007ffff000llu;
1126 const uint64_t TILEGX_X1_RRR_SRCB_MASK = 0x3ffff80000000000llu;
1127 const uint64_t TILEGX_Y0_RRR_SRCB_MASK = 0x00000000780ff000llu;
1128 const uint64_t TILEGX_Y1_RRR_SRCB_MASK = 0x3c07f80000000000llu;
1129 const uint64_t TILEGX_X_ADD_R0_R0_TP = 0x2807a800500f5000llu;
1130 const uint64_t TILEGX_Y_ADD_R0_R0_TP = 0x9a13a8002c275000llu;
1131 const uint64_t TILEGX_X_ADDX_R0_R0_TP = 0x2805a800500b5000llu;
1132 const uint64_t TILEGX_Y_ADDX_R0_R0_TP = 0x9a01a8002c035000llu;
1133
1134 const uint64_t R_TILEGX_IMM8_X0_TLS_ADD_MASK =
1135 (TILEGX_X0_RRR_MASK | (0x3Fllu << 12));
1136
1137 const uint64_t R_TILEGX_IMM8_X1_TLS_ADD_MASK =
1138 (TILEGX_X1_RRR_MASK | (0x3Fllu << 43));
1139
1140 const uint64_t R_TILEGX_IMM8_Y0_TLS_ADD_MASK =
1141 (TILEGX_Y0_RRR_MASK | (0x3Fllu << 12));
1142
1143 const uint64_t R_TILEGX_IMM8_Y1_TLS_ADD_MASK =
1144 (TILEGX_Y1_RRR_MASK | (0x3Fllu << 43));
1145
1146 const uint64_t R_TILEGX_IMM8_X0_TLS_ADD_LE_MASK =
1147 (TILEGX_X0_RRR_SRCB_MASK | (0x3Fllu << 6));
1148
1149 const uint64_t R_TILEGX_IMM8_X1_TLS_ADD_LE_MASK =
1150 (TILEGX_X1_RRR_SRCB_MASK | (0x3Fllu << 37));
1151
1152 const uint64_t R_TILEGX_IMM8_Y0_TLS_ADD_LE_MASK =
1153 (TILEGX_Y0_RRR_SRCB_MASK | (0x3Fllu << 6));
1154
1155 const uint64_t R_TILEGX_IMM8_Y1_TLS_ADD_LE_MASK =
1156 (TILEGX_Y1_RRR_SRCB_MASK | (0x3Fllu << 37));
1157
1158 typedef typename elfcpp::Swap<64, big_endian>::Valtype Valtype;
1159 Valtype* wv = reinterpret_cast<Valtype*>(view);
1160 Valtype val = elfcpp::Swap<64, big_endian>::readval(wv);
1161 Valtype reloc = 0;
1162
1163 switch (r_type)
1164 {
1165 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
1166 if (opt_t == tls::TLSOPT_NONE) {
1167 // GD/IE: 1. copy dest operand into the second source operand
1168 // 2. change the opcode to "add"
1169 reloc = (val & 0x3Fllu) << 12; // featch the dest reg
1170 reloc |= ((size == 32
1171 ? TILEGX_X_ADDX_R0_R0_TP
1172 : TILEGX_X_ADD_R0_R0_TP)
1173 & TILEGX_X0_RRR_MASK); // change opcode
1174 val &= ~R_TILEGX_IMM8_X0_TLS_ADD_MASK;
1175 } else if (opt_t == tls::TLSOPT_TO_LE) {
1176 // LE: 1. copy dest operand into the first source operand
1177 // 2. change the opcode to "move"
1178 reloc = (val & 0x3Fllu) << 6;
1179 reloc |= (TILEGX_X_MOVE_R0_R0 & TILEGX_X0_RRR_SRCB_MASK);
1180 val &= ~R_TILEGX_IMM8_X0_TLS_ADD_LE_MASK;
1181 } else
1182 gold_unreachable();
1183 break;
1184 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
1185 if (opt_t == tls::TLSOPT_NONE) {
1186 reloc = (val & (0x3Fllu << 31)) << 12;
1187 reloc |= ((size == 32
1188 ? TILEGX_X_ADDX_R0_R0_TP
1189 : TILEGX_X_ADD_R0_R0_TP)
1190 & TILEGX_X1_RRR_MASK);
1191 val &= ~R_TILEGX_IMM8_X1_TLS_ADD_MASK;
1192 } else if (opt_t == tls::TLSOPT_TO_LE) {
1193 reloc = (val & (0x3Fllu << 31)) << 6;
1194 reloc |= (TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK);
1195 val &= ~R_TILEGX_IMM8_X1_TLS_ADD_LE_MASK;
1196 } else
1197 gold_unreachable();
1198 break;
1199 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
1200 if (opt_t == tls::TLSOPT_NONE) {
1201 reloc = (val & 0x3Fllu) << 12;
1202 reloc |= ((size == 32
1203 ? TILEGX_Y_ADDX_R0_R0_TP
1204 : TILEGX_Y_ADD_R0_R0_TP)
1205 & TILEGX_Y0_RRR_MASK);
1206 val &= ~R_TILEGX_IMM8_Y0_TLS_ADD_MASK;
1207 } else if (opt_t == tls::TLSOPT_TO_LE) {
1208 reloc = (val & 0x3Fllu) << 6;
1209 reloc |= (TILEGX_Y_MOVE_R0_R0 & TILEGX_Y0_RRR_SRCB_MASK);
1210 val &= ~R_TILEGX_IMM8_Y0_TLS_ADD_LE_MASK;
1211 } else
1212 gold_unreachable();
1213 break;
1214 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
1215 if (opt_t == tls::TLSOPT_NONE) {
1216 reloc = (val & (0x3Fllu << 31)) << 12;
1217 reloc |= ((size == 32
1218 ? TILEGX_Y_ADDX_R0_R0_TP
1219 : TILEGX_Y_ADD_R0_R0_TP)
1220 & TILEGX_Y1_RRR_MASK);
1221 val &= ~R_TILEGX_IMM8_Y1_TLS_ADD_MASK;
1222 } else if (opt_t == tls::TLSOPT_TO_LE) {
1223 reloc = (val & (0x3Fllu << 31)) << 6;
1224 reloc |= (TILEGX_Y_MOVE_R0_R0 & TILEGX_Y1_RRR_SRCB_MASK);
1225 val &= ~R_TILEGX_IMM8_Y1_TLS_ADD_LE_MASK;
1226 } else
1227 gold_unreachable();
1228 break;
1229 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
1230 if (opt_t == tls::TLSOPT_NONE) {
1231 // GD see comments for optimize_tls_reloc
1232 reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X0_RRR_SRCB_MASK;
1233 val &= ~TILEGX_X0_RRR_SRCB_MASK;
1234 } else if (opt_t == tls::TLSOPT_TO_IE
1235 || opt_t == tls::TLSOPT_TO_LE) {
1236 // IE/LE
1237 reloc = (size == 32
1238 ? TILEGX_X_ADDX_R0_R0_TP
1239 : TILEGX_X_ADD_R0_R0_TP)
1240 & TILEGX_X0_RRR_SRCB_MASK;
1241 val &= ~TILEGX_X0_RRR_SRCB_MASK;
1242 }
1243 break;
1244 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
1245 if (opt_t == tls::TLSOPT_NONE) {
1246 reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK;
1247 val &= ~TILEGX_X1_RRR_SRCB_MASK;
1248 } else if (opt_t == tls::TLSOPT_TO_IE
1249 || opt_t == tls::TLSOPT_TO_LE) {
1250 reloc = (size == 32
1251 ? TILEGX_X_ADDX_R0_R0_TP
1252 : TILEGX_X_ADD_R0_R0_TP)
1253 & TILEGX_X1_RRR_SRCB_MASK;
1254 val &= ~TILEGX_X1_RRR_SRCB_MASK;
1255 }
1256 break;
1257 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
1258 if (opt_t == tls::TLSOPT_NONE) {
1259 reloc = TILEGX_Y_MOVE_R0_R0 & TILEGX_Y0_RRR_SRCB_MASK;
1260 val &= ~TILEGX_Y0_RRR_SRCB_MASK;
1261 } else if (opt_t == tls::TLSOPT_TO_IE
1262 || opt_t == tls::TLSOPT_TO_LE) {
1263 reloc = (size == 32
1264 ? TILEGX_Y_ADDX_R0_R0_TP
1265 : TILEGX_Y_ADD_R0_R0_TP)
1266 & TILEGX_Y0_RRR_SRCB_MASK;
1267 val &= ~TILEGX_Y0_RRR_SRCB_MASK;
1268 }
1269 break;
1270 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
1271 if (opt_t == tls::TLSOPT_NONE) {
1272 reloc = TILEGX_Y_MOVE_R0_R0 & TILEGX_Y1_RRR_SRCB_MASK;
1273 val &= ~TILEGX_Y1_RRR_SRCB_MASK;
1274 } else if (opt_t == tls::TLSOPT_TO_IE
1275 || opt_t == tls::TLSOPT_TO_LE) {
1276 reloc = (size == 32
1277 ? TILEGX_Y_ADDX_R0_R0_TP
1278 : TILEGX_Y_ADD_R0_R0_TP)
1279 & TILEGX_Y1_RRR_SRCB_MASK;
1280 val &= ~TILEGX_Y1_RRR_SRCB_MASK;
1281 }
1282 break;
1283 case elfcpp::R_TILEGX_TLS_IE_LOAD:
1284 if (opt_t == tls::TLSOPT_NONE) {
1285 // IE
1286 reloc = (size == 32
1287 ? TILEGX_X_LD4S
1288 : TILEGX_X_LD)
1289 & TILEGX_X1_RRR_SRCB_MASK;
1290 val &= ~TILEGX_X1_RRR_SRCB_MASK;
1291 } else if (opt_t == tls::TLSOPT_TO_LE) {
1292 // LE
1293 reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK;
1294 val &= ~TILEGX_X1_RRR_SRCB_MASK;
1295 } else
1296 gold_unreachable();
1297 break;
1298 case elfcpp::R_TILEGX_TLS_GD_CALL:
1299 if (opt_t == tls::TLSOPT_TO_IE) {
1300 // ld/ld4s r0, r0
1301 reloc = (size == 32
1302 ? TILEGX_X_LD4S
1303 : TILEGX_X_LD) & TILEGX_X1_FULL_MASK;
1304 val &= ~TILEGX_X1_FULL_MASK;
1305 } else if (opt_t == tls::TLSOPT_TO_LE) {
1306 // move r0, r0
1307 reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_FULL_MASK;
1308 val &= ~TILEGX_X1_FULL_MASK;
1309 } else
1310 // should be handled in ::relocate
1311 gold_unreachable();
1312 break;
1313 default:
1314 gold_unreachable();
1315 break;
1316 }
1317 elfcpp::Swap<64, big_endian>::writeval(wv, val | reloc);
1318 }
1319};
1320
1321template<>
1322const Tilegx_relocate_functions<64, false>::Tilegx_howto
1323Tilegx_relocate_functions<64, false>::howto[elfcpp::R_TILEGX_NUM] =
1324{
1325 { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
1326 { 0, 0, 0, 64, 0}, // R_TILEGX_64
1327 { 0, 0, 0, 32, 0}, // R_TILEGX_32
1328 { 0, 0, 0, 16, 0}, // R_TILEGX_16
1329 { 0, 0, 0, 8, 0}, // R_TILEGX_8
1330 { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
1331 { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
1332 { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
1333 { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
1334 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
1335 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
1336 { 32, 0, 0, 0, 0}, // R_TILEGX_HW2
1337 { 48, 0, 0, 0, 0}, // R_TILEGX_HW3
1338 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
1339 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
1340 { 32, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
1341 { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
1342 { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
1343 { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
1344 { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
1345 { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
1346 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
1347 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
1348 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
1349 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
1350 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
1351 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
1352 { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
1353 { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
1354 { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
1355 { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
1356 { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
1357 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
1358 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
1359 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
1360 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
1361 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
1362 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
1363 { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
1364 { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
1365 { 32, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
1366 { 32, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
1367 { 48, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
1368 { 48, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
1369 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
1370 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
1371 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
1372 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
1373 { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
1374 { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
1375 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
1376 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
1377 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
1378 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
1379 { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
1380 { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
1381 { 48, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
1382 { 48, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
1383 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
1384 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
1385 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
1386 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
1387 { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
1388 { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
1389 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
1390 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
1391 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
1392 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
1393 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
1394 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
1395 { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
1396 { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
1397 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
1398 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
1399 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
1400 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
1401 { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
1402 { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
1403 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
1404 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
1405 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
1406 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
1407 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
1408 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
1409 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
1410 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
1411 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
1412 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
1413 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
1414 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
1415 { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
1416 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1417 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
1418 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
1419 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
1420 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
1421 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
1422 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
1423 { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
1424 { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
1425 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
1426 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
1427 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
1428 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
1429 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1430 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1431 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
1432 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
1433 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
1434 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
1435 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
1436 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
1437 { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
1438 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
1439 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
1440 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
1441 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
1442 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
1443 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
1444 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
1445 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
1446 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
1447 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
1448 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
1449};
1450
1451template<>
1452const Tilegx_relocate_functions<32, false>::Tilegx_howto
1453Tilegx_relocate_functions<32, false>::howto[elfcpp::R_TILEGX_NUM] =
1454{
1455 { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
1456 { 0, 0, 0, 64, 0}, // R_TILEGX_64
1457 { 0, 0, 0, 32, 0}, // R_TILEGX_32
1458 { 0, 0, 0, 16, 0}, // R_TILEGX_16
1459 { 0, 0, 0, 8, 0}, // R_TILEGX_8
1460 { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
1461 { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
1462 { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
1463 { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
1464 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
1465 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
1466 { 31, 0, 0, 0, 0}, // R_TILEGX_HW2
1467 { 31, 0, 0, 0, 0}, // R_TILEGX_HW3
1468 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
1469 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
1470 { 31, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
1471 { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
1472 { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
1473 { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
1474 { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
1475 { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
1476 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
1477 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
1478 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
1479 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
1480 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
1481 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
1482 { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
1483 { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
1484 { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
1485 { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
1486 { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
1487 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
1488 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
1489 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
1490 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
1491 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
1492 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
1493 { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
1494 { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
1495 { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
1496 { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
1497 { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
1498 { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
1499 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
1500 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
1501 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
1502 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
1503 { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
1504 { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
1505 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
1506 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
1507 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
1508 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
1509 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
1510 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
1511 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
1512 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
1513 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
1514 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
1515 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
1516 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
1517 { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
1518 { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
1519 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
1520 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
1521 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
1522 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
1523 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
1524 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
1525 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
1526 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
1527 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
1528 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
1529 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
1530 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
1531 { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
1532 { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
1533 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
1534 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
1535 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
1536 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
1537 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
1538 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
1539 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
1540 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
1541 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
1542 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
1543 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
1544 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
1545 { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
1546 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1547 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
1548 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
1549 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
1550 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
1551 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
1552 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
1553 { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
1554 { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
1555 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
1556 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
1557 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
1558 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
1559 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1560 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1561 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
1562 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
1563 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
1564 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
1565 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
1566 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
1567 { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
1568 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
1569 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
1570 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
1571 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
1572 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
1573 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
1574 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
1575 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
1576 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
1577 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
1578 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
1579};
1580
1581template<>
1582const Tilegx_relocate_functions<64, true>::Tilegx_howto
1583Tilegx_relocate_functions<64, true>::howto[elfcpp::R_TILEGX_NUM] =
1584{
1585 { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
1586 { 0, 0, 0, 64, 0}, // R_TILEGX_64
1587 { 0, 0, 0, 32, 0}, // R_TILEGX_32
1588 { 0, 0, 0, 16, 0}, // R_TILEGX_16
1589 { 0, 0, 0, 8, 0}, // R_TILEGX_8
1590 { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
1591 { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
1592 { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
1593 { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
1594 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
1595 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
1596 { 32, 0, 0, 0, 0}, // R_TILEGX_HW2
1597 { 48, 0, 0, 0, 0}, // R_TILEGX_HW3
1598 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
1599 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
1600 { 32, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
1601 { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
1602 { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
1603 { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
1604 { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
1605 { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
1606 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
1607 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
1608 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
1609 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
1610 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
1611 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
1612 { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
1613 { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
1614 { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
1615 { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
1616 { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
1617 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
1618 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
1619 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
1620 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
1621 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
1622 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
1623 { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
1624 { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
1625 { 32, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
1626 { 32, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
1627 { 48, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
1628 { 48, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
1629 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
1630 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
1631 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
1632 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
1633 { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
1634 { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
1635 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
1636 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
1637 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
1638 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
1639 { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
1640 { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
1641 { 48, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
1642 { 48, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
1643 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
1644 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
1645 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
1646 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
1647 { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
1648 { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
1649 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
1650 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
1651 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
1652 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
1653 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
1654 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
1655 { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
1656 { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
1657 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
1658 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
1659 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
1660 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
1661 { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
1662 { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
1663 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
1664 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
1665 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
1666 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
1667 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
1668 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
1669 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
1670 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
1671 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
1672 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
1673 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
1674 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
1675 { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
1676 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1677 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
1678 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
1679 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
1680 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
1681 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
1682 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
1683 { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
1684 { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
1685 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
1686 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
1687 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
1688 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
1689 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1690 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1691 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
1692 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
1693 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
1694 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
1695 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
1696 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
1697 { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
1698 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
1699 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
1700 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
1701 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
1702 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
1703 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
1704 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
1705 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
1706 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
1707 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
1708 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
1709};
1710
1711template<>
1712const Tilegx_relocate_functions<32, true>::Tilegx_howto
1713Tilegx_relocate_functions<32, true>::howto[elfcpp::R_TILEGX_NUM] =
1714{
1715 { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
1716 { 0, 0, 0, 64, 0}, // R_TILEGX_64
1717 { 0, 0, 0, 32, 0}, // R_TILEGX_32
1718 { 0, 0, 0, 16, 0}, // R_TILEGX_16
1719 { 0, 0, 0, 8, 0}, // R_TILEGX_8
1720 { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
1721 { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
1722 { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
1723 { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
1724 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
1725 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
1726 { 31, 0, 0, 0, 0}, // R_TILEGX_HW2
1727 { 31, 0, 0, 0, 0}, // R_TILEGX_HW3
1728 { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
1729 { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
1730 { 31, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
1731 { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
1732 { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
1733 { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
1734 { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
1735 { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
1736 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
1737 { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
1738 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
1739 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
1740 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
1741 { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
1742 { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
1743 { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
1744 { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
1745 { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
1746 { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
1747 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
1748 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
1749 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
1750 { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
1751 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
1752 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
1753 { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
1754 { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
1755 { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
1756 { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
1757 { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
1758 { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
1759 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
1760 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
1761 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
1762 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
1763 { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
1764 { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
1765 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
1766 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
1767 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
1768 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
1769 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
1770 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
1771 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
1772 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
1773 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
1774 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
1775 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
1776 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
1777 { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
1778 { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
1779 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
1780 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
1781 { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
1782 { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
1783 { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
1784 { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
1785 { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
1786 { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
1787 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
1788 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
1789 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
1790 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
1791 { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
1792 { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
1793 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
1794 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
1795 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
1796 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
1797 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
1798 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
1799 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
1800 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
1801 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
1802 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
1803 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
1804 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
1805 { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
1806 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1807 { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
1808 { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
1809 { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
1810 { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
1811 { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
1812 { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
1813 { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
1814 { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
1815 { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
1816 { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
1817 { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
1818 { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
1819 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1820 { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
1821 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
1822 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
1823 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
1824 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
1825 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
1826 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
1827 { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
1828 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
1829 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
1830 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
1831 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
1832 { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
1833 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
1834 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
1835 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
1836 { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
1837 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
1838 { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
1839};
1840
1841// Get the GOT section, creating it if necessary.
1842
1843template<int size, bool big_endian>
1844Output_data_got<size, big_endian>*
1845Target_tilegx<size, big_endian>::got_section(Symbol_table* symtab,
1846 Layout* layout)
1847{
1848 if (this->got_ == NULL)
1849 {
1850 gold_assert(symtab != NULL && layout != NULL);
1851
1852 // When using -z now, we can treat .got.plt as a relro section.
1853 // Without -z now, it is modified after program startup by lazy
1854 // PLT relocations.
1855 bool is_got_plt_relro = parameters->options().now();
1856 Output_section_order got_order = (is_got_plt_relro
1857 ? ORDER_RELRO
1858 : ORDER_RELRO_LAST);
1859 Output_section_order got_plt_order = (is_got_plt_relro
1860 ? ORDER_RELRO
1861 : ORDER_NON_RELRO_FIRST);
1862
1863 this->got_ = new Output_data_got<size, big_endian>();
1864
1865 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
1866 (elfcpp::SHF_ALLOC
1867 | elfcpp::SHF_WRITE),
1868 this->got_, got_order, true);
1869
1870 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1871 this->global_offset_table_ =
1872 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
1873 Symbol_table::PREDEFINED,
1874 this->got_,
1875 0, 0, elfcpp::STT_OBJECT,
1876 elfcpp::STB_LOCAL,
1877 elfcpp::STV_HIDDEN, 0,
1878 false, false);
1879
1880 if (parameters->options().shared()) {
1881 // we need to keep the address of .dynamic section in the
1882 // first got entry for .so
1883 this->tilegx_dynamic_ =
1884 symtab->define_in_output_data("_TILEGX_DYNAMIC_", NULL,
1885 Symbol_table::PREDEFINED,
1886 layout->dynamic_section(),
1887 0, 0, elfcpp::STT_OBJECT,
1888 elfcpp::STB_LOCAL,
1889 elfcpp::STV_HIDDEN, 0,
1890 false, false);
1891
1892 this->got_->add_global(this->tilegx_dynamic_, GOT_TYPE_STANDARD);
1893 } else
1894 // for executable, just set the first entry to zero.
1895 this->got_->set_current_data_size(size / 8);
1896
1897 this->got_plt_ = new Output_data_space(size / 8, "** GOT PLT");
1898 layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
1899 (elfcpp::SHF_ALLOC
1900 | elfcpp::SHF_WRITE),
1901 this->got_plt_, got_plt_order,
1902 is_got_plt_relro);
1903
1904 // The first two entries are reserved.
1905 this->got_plt_->set_current_data_size
1906 (TILEGX_GOTPLT_RESERVE_COUNT * (size / 8));
1907
1908 if (!is_got_plt_relro)
1909 {
1910 // Those bytes can go into the relro segment.
1911 layout->increase_relro(size / 8);
1912 }
1913
1914
1915 // If there are any IRELATIVE relocations, they get GOT entries
1916 // in .got.plt after the jump slot entries.
1917 this->got_irelative_
1918 = new Output_data_space(size / 8, "** GOT IRELATIVE PLT");
1919 layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
1920 (elfcpp::SHF_ALLOC
1921 | elfcpp::SHF_WRITE),
1922 this->got_irelative_,
1923 got_plt_order, is_got_plt_relro);
1924 }
1925
1926 return this->got_;
1927}
1928
1929// Get the dynamic reloc section, creating it if necessary.
1930
1931template<int size, bool big_endian>
1932typename Target_tilegx<size, big_endian>::Reloc_section*
1933Target_tilegx<size, big_endian>::rela_dyn_section(Layout* layout)
1934{
1935 if (this->rela_dyn_ == NULL)
1936 {
1937 gold_assert(layout != NULL);
1938 this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
1939 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1940 elfcpp::SHF_ALLOC, this->rela_dyn_,
1941 ORDER_DYNAMIC_RELOCS, false);
1942 }
1943 return this->rela_dyn_;
1944}
1945
1946// Get the section to use for IRELATIVE relocs, creating it if
1947// necessary. These go in .rela.dyn, but only after all other dynamic
1948// relocations. They need to follow the other dynamic relocations so
1949// that they can refer to global variables initialized by those
1950// relocs.
1951
1952template<int size, bool big_endian>
1953typename Target_tilegx<size, big_endian>::Reloc_section*
1954Target_tilegx<size, big_endian>::rela_irelative_section(Layout* layout)
1955{
1956 if (this->rela_irelative_ == NULL)
1957 {
1958 // Make sure we have already created the dynamic reloc section.
1959 this->rela_dyn_section(layout);
1960 this->rela_irelative_ = new Reloc_section(false);
1961 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
1962 elfcpp::SHF_ALLOC, this->rela_irelative_,
1963 ORDER_DYNAMIC_RELOCS, false);
1964 gold_assert(this->rela_dyn_->output_section()
1965 == this->rela_irelative_->output_section());
1966 }
1967 return this->rela_irelative_;
1968}
1969
1970// Initialize the PLT section.
1971
1972template<int size, bool big_endian>
1973void
1974Output_data_plt_tilegx<size, big_endian>::init(Layout* layout)
1975{
1976 this->rel_ = new Reloc_section(false);
1977 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
1978 elfcpp::SHF_ALLOC, this->rel_,
1979 ORDER_DYNAMIC_PLT_RELOCS, false);
1980}
1981
1982template<int size, bool big_endian>
1983void
1984Output_data_plt_tilegx<size, big_endian>::do_adjust_output_section(
1985 Output_section* os)
1986{
1987 os->set_entsize(this->get_plt_entry_size());
1988}
1989
1990// Add an entry to the PLT.
1991
1992template<int size, bool big_endian>
1993void
1994Output_data_plt_tilegx<size, big_endian>::add_entry(Symbol_table* symtab,
1995 Layout* layout, Symbol* gsym)
1996{
1997 gold_assert(!gsym->has_plt_offset());
1998
1999 unsigned int plt_index;
2000 off_t plt_offset;
2001 section_offset_type got_offset;
2002
2003 unsigned int* pcount;
2004 unsigned int reserved;
2005 Output_data_space* got;
2006 if (gsym->type() == elfcpp::STT_GNU_IFUNC
2007 && gsym->can_use_relative_reloc(false))
2008 {
2009 pcount = &this->irelative_count_;
2010 reserved = 0;
2011 got = this->got_irelative_;
2012 }
2013 else
2014 {
2015 pcount = &this->count_;
2016 reserved = TILEGX_GOTPLT_RESERVE_COUNT;
2017 got = this->got_plt_;
2018 }
2019
2020 if (!this->is_data_size_valid())
2021 {
2022 plt_index = *pcount;
2023
2024 // TILEGX .plt section layout
2025 //
2026 // ----
2027 // plt_header
2028 // ----
2029 // plt stub
2030 // ----
2031 // ...
2032 // ----
2033 //
2034 // TILEGX .got.plt section layout
2035 //
2036 // ----
2037 // reserv1
2038 // ----
2039 // reserv2
2040 // ----
2041 // entries for normal function
2042 // ----
2043 // ...
2044 // ----
2045 // entries for ifunc
2046 // ----
2047 // ...
2048 // ----
2049 if (got == this->got_irelative_)
2050 plt_offset = plt_index * this->get_plt_entry_size();
2051 else
2052 plt_offset = (plt_index + 1) * this->get_plt_entry_size();
2053
2054 ++*pcount;
2055
2056 got_offset = (plt_index + reserved) * (size / 8);
2057 gold_assert(got_offset == got->current_data_size());
2058
2059 // Every PLT entry needs a GOT entry which points back to the PLT
2060 // entry (this will be changed by the dynamic linker, normally
2061 // lazily when the function is called).
2062 got->set_current_data_size(got_offset + size / 8);
2063 }
2064 else
2065 {
2066 // FIXME: This is probably not correct for IRELATIVE relocs.
2067
2068 // For incremental updates, find an available slot.
2069 plt_offset = this->free_list_.allocate(this->get_plt_entry_size(),
2070 this->get_plt_entry_size(), 0);
2071 if (plt_offset == -1)
2072 gold_fallback(_("out of patch space (PLT);"
2073 " relink with --incremental-full"));
2074
2075 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
2076 // can be calculated from the PLT index, adjusting for the three
2077 // reserved entries at the beginning of the GOT.
2078 plt_index = plt_offset / this->get_plt_entry_size() - 1;
2079 got_offset = (plt_index + reserved) * (size / 8);
2080 }
2081
2082 gsym->set_plt_offset(plt_offset);
2083
2084 // Every PLT entry needs a reloc.
2085 this->add_relocation(symtab, layout, gsym, got_offset);
2086
2087 // Note that we don't need to save the symbol. The contents of the
2088 // PLT are independent of which symbols are used. The symbols only
2089 // appear in the relocations.
2090}
2091
2092// Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
2093// the PLT offset.
2094
2095template<int size, bool big_endian>
2096unsigned int
2097Output_data_plt_tilegx<size, big_endian>::add_local_ifunc_entry(
2098 Symbol_table* symtab,
2099 Layout* layout,
2100 Sized_relobj_file<size, big_endian>* relobj,
2101 unsigned int local_sym_index)
2102{
2103 unsigned int plt_offset =
2104 this->irelative_count_ * this->get_plt_entry_size();
2105 ++this->irelative_count_;
2106
2107 section_offset_type got_offset = this->got_irelative_->current_data_size();
2108
2109 // Every PLT entry needs a GOT entry which points back to the PLT
2110 // entry.
2111 this->got_irelative_->set_current_data_size(got_offset + size / 8);
2112
2113 // Every PLT entry needs a reloc.
2114 Reloc_section* rela = this->rela_irelative(symtab, layout);
2115 rela->add_symbolless_local_addend(relobj, local_sym_index,
2116 elfcpp::R_TILEGX_IRELATIVE,
2117 this->got_irelative_, got_offset, 0);
2118
2119 return plt_offset;
2120}
2121
2122// Add the relocation for a PLT entry.
2123
2124template<int size, bool big_endian>
2125void
2126Output_data_plt_tilegx<size, big_endian>::add_relocation(Symbol_table* symtab,
2127 Layout* layout,
2128 Symbol* gsym,
2129 unsigned int got_offset)
2130{
2131 if (gsym->type() == elfcpp::STT_GNU_IFUNC
2132 && gsym->can_use_relative_reloc(false))
2133 {
2134 Reloc_section* rela = this->rela_irelative(symtab, layout);
2135 rela->add_symbolless_global_addend(gsym, elfcpp::R_TILEGX_IRELATIVE,
2136 this->got_irelative_, got_offset, 0);
2137 }
2138 else
2139 {
2140 gsym->set_needs_dynsym_entry();
2141 this->rel_->add_global(gsym, elfcpp::R_TILEGX_JMP_SLOT, this->got_plt_,
2142 got_offset, 0);
2143 }
2144}
2145
2146// Return where the IRELATIVE relocations should go in the PLT. These
2147// follow the JUMP_SLOT and the TLSDESC relocations.
2148
2149template<int size, bool big_endian>
2150typename Output_data_plt_tilegx<size, big_endian>::Reloc_section*
2151Output_data_plt_tilegx<size, big_endian>::rela_irelative(Symbol_table* symtab,
2152 Layout* layout)
2153{
2154 if (this->irelative_rel_ == NULL)
2155 {
2156 // case we see any later on.
2157 this->irelative_rel_ = new Reloc_section(false);
2158 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
2159 elfcpp::SHF_ALLOC, this->irelative_rel_,
2160 ORDER_DYNAMIC_PLT_RELOCS, false);
2161 gold_assert(this->irelative_rel_->output_section()
2162 == this->rel_->output_section());
2163
2164 if (parameters->doing_static_link())
2165 {
2166 // A statically linked executable will only have a .rela.plt
2167 // section to hold R_TILEGX_IRELATIVE relocs for
2168 // STT_GNU_IFUNC symbols. The library will use these
2169 // symbols to locate the IRELATIVE relocs at program startup
2170 // time.
2171 symtab->define_in_output_data("__rela_iplt_start", NULL,
2172 Symbol_table::PREDEFINED,
2173 this->irelative_rel_, 0, 0,
2174 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
2175 elfcpp::STV_HIDDEN, 0, false, true);
2176 symtab->define_in_output_data("__rela_iplt_end", NULL,
2177 Symbol_table::PREDEFINED,
2178 this->irelative_rel_, 0, 0,
2179 elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
2180 elfcpp::STV_HIDDEN, 0, true, true);
2181 }
2182 }
2183 return this->irelative_rel_;
2184}
2185
2186// Return the PLT address to use for a global symbol.
2187
2188template<int size, bool big_endian>
2189uint64_t
2190Output_data_plt_tilegx<size, big_endian>::address_for_global(
2191 const Symbol* gsym)
2192{
2193 uint64_t offset = 0;
2194 if (gsym->type() == elfcpp::STT_GNU_IFUNC
2195 && gsym->can_use_relative_reloc(false))
2196 offset = (this->count_ + 1) * this->get_plt_entry_size();
2197 return this->address() + offset;
2198}
2199
2200// Return the PLT address to use for a local symbol. These are always
2201// IRELATIVE relocs.
2202
2203template<int size, bool big_endian>
2204uint64_t
2205Output_data_plt_tilegx<size, big_endian>::address_for_local(const Relobj*,
2206 unsigned int)
2207{
2208 return this->address() + (this->count_ + 1) * this->get_plt_entry_size();
2209}
2210
2211// Set the final size.
2212template<int size, bool big_endian>
2213void
2214Output_data_plt_tilegx<size, big_endian>::set_final_data_size()
2215{
2216 unsigned int count = this->count_ + this->irelative_count_;
2217 this->set_data_size((count + 1) * this->get_plt_entry_size());
2218}
2219
2220// The first entry in the PLT for an executable.
2221template<>
2222const unsigned char
2223Output_data_plt_tilegx<64, false>::first_plt_entry[plt_entry_size] =
2224{
2225 0x00, 0x30, 0x48, 0x51,
2226 0x6e, 0x43, 0xa0, 0x18, // { ld_add r28, r27, 8 }
2227 0x00, 0x30, 0xbc, 0x35,
2228 0x00, 0x40, 0xde, 0x9e, // { ld r27, r27 }
2229 0xff, 0xaf, 0x30, 0x40,
2230 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
2231 // padding
2232 0x00, 0x00, 0x00, 0x00,
2233 0x00, 0x00, 0x00, 0x00,
2234 0x00, 0x00, 0x00, 0x00,
2235 0x00, 0x00, 0x00, 0x00
2236};
2237
2238template<>
2239const unsigned char
2240Output_data_plt_tilegx<32, false>::first_plt_entry[plt_entry_size] =
2241{
2242 0x00, 0x30, 0x48, 0x51,
2243 0x6e, 0x23, 0x58, 0x18, // { ld4s_add r28, r27, 4 }
2244 0x00, 0x30, 0xbc, 0x35,
2245 0x00, 0x40, 0xde, 0x9c, // { ld4s r27, r27 }
2246 0xff, 0xaf, 0x30, 0x40,
2247 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
2248 // padding
2249 0x00, 0x00, 0x00, 0x00,
2250 0x00, 0x00, 0x00, 0x00,
2251 0x00, 0x00, 0x00, 0x00,
2252 0x00, 0x00, 0x00, 0x00
2253};
2254
2255template<>
2256const unsigned char
2257Output_data_plt_tilegx<64, true>::first_plt_entry[plt_entry_size] =
2258{
2259 0x00, 0x30, 0x48, 0x51,
2260 0x6e, 0x43, 0xa0, 0x18, // { ld_add r28, r27, 8 }
2261 0x00, 0x30, 0xbc, 0x35,
2262 0x00, 0x40, 0xde, 0x9e, // { ld r27, r27 }
2263 0xff, 0xaf, 0x30, 0x40,
2264 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
2265 // padding
2266 0x00, 0x00, 0x00, 0x00,
2267 0x00, 0x00, 0x00, 0x00,
2268 0x00, 0x00, 0x00, 0x00,
2269 0x00, 0x00, 0x00, 0x00
2270};
2271
2272template<>
2273const unsigned char
2274Output_data_plt_tilegx<32, true>::first_plt_entry[plt_entry_size] =
2275{
2276 0x00, 0x30, 0x48, 0x51,
2277 0x6e, 0x23, 0x58, 0x18, // { ld4s_add r28, r27, 4 }
2278 0x00, 0x30, 0xbc, 0x35,
2279 0x00, 0x40, 0xde, 0x9c, // { ld4s r27, r27 }
2280 0xff, 0xaf, 0x30, 0x40,
2281 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
2282 // padding
2283 0x00, 0x00, 0x00, 0x00,
2284 0x00, 0x00, 0x00, 0x00,
2285 0x00, 0x00, 0x00, 0x00,
2286 0x00, 0x00, 0x00, 0x00
2287};
2288
2289template<int size, bool big_endian>
2290void
2291Output_data_plt_tilegx<size, big_endian>::fill_first_plt_entry(
2292 unsigned char* pov)
2293{
2294 memcpy(pov, first_plt_entry, plt_entry_size);
2295}
2296
2297// Subsequent entries in the PLT for an executable.
2298
2299template<>
2300const unsigned char
2301Output_data_plt_tilegx<64, false>::plt_entry[plt_entry_size] =
2302{
2303 0xdc, 0x0f, 0x00, 0x10,
2304 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
2305 0xdb, 0x0f, 0x00, 0x10,
2306 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
2307 0x9c, 0xc6, 0x0d, 0xd0,
2308 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
2309 0x9b, 0xb6, 0xc5, 0xad,
2310 0xff, 0x57, 0xe0, 0x8e, // { add r27, r26, r27 ; info 10 ; ld r28, r28 }
2311 0xdd, 0x0f, 0x00, 0x70,
2312 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
2313
2314};
2315
2316template<>
2317const unsigned char
2318Output_data_plt_tilegx<32, false>::plt_entry[plt_entry_size] =
2319{
2320 0xdc, 0x0f, 0x00, 0x10,
2321 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
2322 0xdb, 0x0f, 0x00, 0x10,
2323 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
2324 0x9c, 0xc6, 0x0d, 0xd0,
2325 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
2326 0x9b, 0xb6, 0xc5, 0xad,
2327 0xff, 0x57, 0xe0, 0x8c, // { add r27, r26, r27 ; info 10 ; ld4s r28, r28 }
2328 0xdd, 0x0f, 0x00, 0x70,
2329 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
2330};
2331
2332template<>
2333const unsigned char
2334Output_data_plt_tilegx<64, true>::plt_entry[plt_entry_size] =
2335{
2336 0xdc, 0x0f, 0x00, 0x10,
2337 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
2338 0xdb, 0x0f, 0x00, 0x10,
2339 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
2340 0x9c, 0xc6, 0x0d, 0xd0,
2341 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
2342 0x9b, 0xb6, 0xc5, 0xad,
2343 0xff, 0x57, 0xe0, 0x8e, // { add r27, r26, r27 ; info 10 ; ld r28, r28 }
2344 0xdd, 0x0f, 0x00, 0x70,
2345 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
2346
2347};
2348
2349template<>
2350const unsigned char
2351Output_data_plt_tilegx<32, true>::plt_entry[plt_entry_size] =
2352{
2353 0xdc, 0x0f, 0x00, 0x10,
2354 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
2355 0xdb, 0x0f, 0x00, 0x10,
2356 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
2357 0x9c, 0xc6, 0x0d, 0xd0,
2358 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
2359 0x9b, 0xb6, 0xc5, 0xad,
2360 0xff, 0x57, 0xe0, 0x8c, // { add r27, r26, r27 ; info 10 ; ld4s r28, r28 }
2361 0xdd, 0x0f, 0x00, 0x70,
2362 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
2363};
2364
2365template<int size, bool big_endian>
2366void
2367Output_data_plt_tilegx<size, big_endian>::fill_plt_entry(
2368 unsigned char* pov,
2369 typename elfcpp::Elf_types<size>::Elf_Addr gotplt_base,
2370 unsigned int got_offset,
2371 typename elfcpp::Elf_types<size>::Elf_Addr plt_base,
2372 unsigned int plt_offset, unsigned int plt_index)
2373{
2374
2375 const uint32_t TILEGX_IMM16_MASK = 0xFFFF;
2376 const uint32_t TILEGX_X0_IMM16_BITOFF = 12;
2377 const uint32_t TILEGX_X1_IMM16_BITOFF = 43;
2378
2379 typedef typename elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::Valtype
2380 Valtype;
2381 memcpy(pov, plt_entry, plt_entry_size);
2382
2383 // first bundle in plt stub - x0
2384 Valtype* wv = reinterpret_cast<Valtype*>(pov);
2385 Valtype val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
2386 Valtype reloc =
2387 ((gotplt_base + got_offset) - (plt_base + plt_offset + 8)) >> 16;
2388 elfcpp::Elf_Xword dst_mask =
2389 (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
2390 val &= ~dst_mask;
2391 reloc &= TILEGX_IMM16_MASK;
2392 elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
2393 val | (reloc<<TILEGX_X0_IMM16_BITOFF));
2394
2395 // second bundle in plt stub - x1
2396 wv = reinterpret_cast<Valtype*>(pov + 8);
2397 val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
2398 reloc = (gotplt_base + got_offset) - (plt_base + plt_offset + 8);
2399 dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X1_IMM16_BITOFF;
2400 val &= ~dst_mask;
2401 reloc &= TILEGX_IMM16_MASK;
2402 elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
2403 val | (reloc<<TILEGX_X1_IMM16_BITOFF));
2404
2405 // second bundle in plt stub - x0
2406 wv = reinterpret_cast<Valtype*>(pov + 8);
2407 val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
2408 reloc = (gotplt_base - (plt_base + plt_offset + 8)) >> 16;
2409 dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
2410 val &= ~dst_mask;
2411 reloc &= TILEGX_IMM16_MASK;
2412 elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
2413 val | (reloc<<TILEGX_X0_IMM16_BITOFF));
2414
2415 // third bundle in plt stub - x1
2416 wv = reinterpret_cast<Valtype*>(pov + 16);
2417 val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
2418 reloc = gotplt_base - (plt_base + plt_offset + 8);
2419 dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X1_IMM16_BITOFF;
2420 val &= ~dst_mask;
2421 reloc &= TILEGX_IMM16_MASK;
2422 elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
2423 val | (reloc<<TILEGX_X1_IMM16_BITOFF));
2424
2425 // fifth bundle in plt stub - carry plt_index x0
2426 wv = reinterpret_cast<Valtype*>(pov + 32);
2427 val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
2428 dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
2429 val &= ~dst_mask;
2430 plt_index &= TILEGX_IMM16_MASK;
2431 elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
2432 val | (plt_index<<TILEGX_X0_IMM16_BITOFF));
2433
2434}
2435
2436// Write out the PLT. This uses the hand-coded instructions above.
2437
2438template<int size, bool big_endian>
2439void
2440Output_data_plt_tilegx<size, big_endian>::do_write(Output_file* of)
2441{
2442 const off_t offset = this->offset();
2443 const section_size_type oview_size =
2444 convert_to_section_size_type(this->data_size());
2445 unsigned char* const oview = of->get_output_view(offset, oview_size);
2446
2447 const off_t got_file_offset = this->got_plt_->offset();
2448 gold_assert(parameters->incremental_update()
2449 || (got_file_offset + this->got_plt_->data_size()
2450 == this->got_irelative_->offset()));
2451 const section_size_type got_size =
2452 convert_to_section_size_type(this->got_plt_->data_size()
2453 + this->got_irelative_->data_size());
2454 unsigned char* const got_view = of->get_output_view(got_file_offset,
2455 got_size);
2456
2457 unsigned char* pov = oview;
2458
2459 // The base address of the .plt section.
2460 typename elfcpp::Elf_types<size>::Elf_Addr plt_address = this->address();
2461 typename elfcpp::Elf_types<size>::Elf_Addr got_address =
2462 this->got_plt_->address();
2463
2464 this->fill_first_plt_entry(pov);
2465 pov += this->get_plt_entry_size();
2466
2467 unsigned char* got_pov = got_view;
2468
2469 // first entry of .got.plt are set to -1
2470 // second entry of .got.plt are set to 0
2471 memset(got_pov, 0xff, size / 8);
2472 got_pov += size / 8;
2473 memset(got_pov, 0x0, size / 8);
2474 got_pov += size / 8;
2475
2476 unsigned int plt_offset = this->get_plt_entry_size();
2477 const unsigned int count = this->count_ + this->irelative_count_;
2478 unsigned int got_offset = (size / 8) * TILEGX_GOTPLT_RESERVE_COUNT;
2479 for (unsigned int plt_index = 0;
2480 plt_index < count;
2481 ++plt_index,
2482 pov += this->get_plt_entry_size(),
2483 got_pov += size / 8,
2484 plt_offset += this->get_plt_entry_size(),
2485 got_offset += size / 8)
2486 {
2487 // Set and adjust the PLT entry itself.
2488 this->fill_plt_entry(pov, got_address, got_offset,
2489 plt_address, plt_offset, plt_index);
2490
2491 // Initialize entry in .got.plt to plt start address
2492 elfcpp::Swap<size, big_endian>::writeval(got_pov, plt_address);
2493 }
2494
2495 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
2496 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
2497
2498 of->write_output_view(offset, oview_size, oview);
2499 of->write_output_view(got_file_offset, got_size, got_view);
2500}
2501
2502// Create the PLT section.
2503
2504template<int size, bool big_endian>
2505void
2506Target_tilegx<size, big_endian>::make_plt_section(Symbol_table* symtab,
2507 Layout* layout)
2508{
2509 if (this->plt_ == NULL)
2510 {
2511 // Create the GOT sections first.
2512 this->got_section(symtab, layout);
2513
2514 // Ensure that .rela.dyn always appears before .rela.plt,
2515 // becuase on TILE-Gx, .rela.dyn needs to include .rela.plt
2516 // in it's range.
2517 this->rela_dyn_section(layout);
2518
2519 this->plt_ = new Output_data_plt_tilegx<size, big_endian>(layout,
2520 TILEGX_INST_BUNDLE_SIZE, this->got_, this->got_plt_,
2521 this->got_irelative_);
2522
2523 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
2524 (elfcpp::SHF_ALLOC
2525 | elfcpp::SHF_EXECINSTR),
2526 this->plt_, ORDER_NON_RELRO_FIRST,
2527 false);
2528
2529 // Make the sh_info field of .rela.plt point to .plt.
2530 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
2531 rela_plt_os->set_info_section(this->plt_->output_section());
2532 }
2533}
2534
2535// Create a PLT entry for a global symbol.
2536
2537template<int size, bool big_endian>
2538void
2539Target_tilegx<size, big_endian>::make_plt_entry(Symbol_table* symtab,
2540 Layout* layout, Symbol* gsym)
2541{
2542 if (gsym->has_plt_offset())
2543 return;
2544
2545 if (this->plt_ == NULL)
2546 this->make_plt_section(symtab, layout);
2547
2548 this->plt_->add_entry(symtab, layout, gsym);
2549}
2550
2551// Make a PLT entry for a local STT_GNU_IFUNC symbol.
2552
2553template<int size, bool big_endian>
2554void
2555Target_tilegx<size, big_endian>::make_local_ifunc_plt_entry(
2556 Symbol_table* symtab, Layout* layout,
2557 Sized_relobj_file<size, big_endian>* relobj,
2558 unsigned int local_sym_index)
2559{
2560 if (relobj->local_has_plt_offset(local_sym_index))
2561 return;
2562 if (this->plt_ == NULL)
2563 this->make_plt_section(symtab, layout);
2564 unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
2565 relobj,
2566 local_sym_index);
2567 relobj->set_local_plt_offset(local_sym_index, plt_offset);
2568}
2569
2570// Return the number of entries in the PLT.
2571
2572template<int size, bool big_endian>
2573unsigned int
2574Target_tilegx<size, big_endian>::plt_entry_count() const
2575{
2576 if (this->plt_ == NULL)
2577 return 0;
2578 return this->plt_->entry_count();
2579}
2580
2581// Return the offset of the first non-reserved PLT entry.
2582
2583template<int size, bool big_endian>
2584unsigned int
2585Target_tilegx<size, big_endian>::first_plt_entry_offset() const
2586{
2587 return this->plt_->first_plt_entry_offset();
2588}
2589
2590// Return the size of each PLT entry.
2591
2592template<int size, bool big_endian>
2593unsigned int
2594Target_tilegx<size, big_endian>::plt_entry_size() const
2595{
2596 return this->plt_->get_plt_entry_size();
2597}
2598
2599// Create the GOT and PLT sections for an incremental update.
2600
2601template<int size, bool big_endian>
2602Output_data_got_base*
2603Target_tilegx<size, big_endian>::init_got_plt_for_update(Symbol_table* symtab,
2604 Layout* layout,
2605 unsigned int got_count,
2606 unsigned int plt_count)
2607{
2608 gold_assert(this->got_ == NULL);
2609
2610 this->got_ =
2611 new Output_data_got<size, big_endian>((got_count
2612 + TILEGX_GOT_RESERVE_COUNT)
2613 * (size / 8));
2614 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
2615 (elfcpp::SHF_ALLOC
2616 | elfcpp::SHF_WRITE),
2617 this->got_, ORDER_RELRO_LAST,
2618 true);
2619
2620 // Define _GLOBAL_OFFSET_TABLE_ at the start of the GOT.
2621 this->global_offset_table_ =
2622 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
2623 Symbol_table::PREDEFINED,
2624 this->got_,
2625 0, 0, elfcpp::STT_OBJECT,
2626 elfcpp::STB_LOCAL,
2627 elfcpp::STV_HIDDEN, 0,
2628 false, false);
2629
2630 if (parameters->options().shared()) {
2631 this->tilegx_dynamic_ =
2632 symtab->define_in_output_data("_TILEGX_DYNAMIC_", NULL,
2633 Symbol_table::PREDEFINED,
2634 layout->dynamic_section(),
2635 0, 0, elfcpp::STT_OBJECT,
2636 elfcpp::STB_LOCAL,
2637 elfcpp::STV_HIDDEN, 0,
2638 false, false);
2639
2640 this->got_->add_global(this->tilegx_dynamic_, GOT_TYPE_STANDARD);
2641 } else
2642 this->got_->set_current_data_size(size / 8);
2643
2644 // Add the two reserved entries.
2645 this->got_plt_
2646 = new Output_data_space((plt_count + TILEGX_GOTPLT_RESERVE_COUNT)
2647 * (size / 8), size / 8, "** GOT PLT");
2648 layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
2649 (elfcpp::SHF_ALLOC
2650 | elfcpp::SHF_WRITE),
2651 this->got_plt_, ORDER_NON_RELRO_FIRST,
2652 false);
2653
2654 // If there are any IRELATIVE relocations, they get GOT entries in
2655 // .got.plt after the jump slot.
2656 this->got_irelative_
2657 = new Output_data_space(0, size / 8, "** GOT IRELATIVE PLT");
2658 layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
2659 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
2660 this->got_irelative_,
2661 ORDER_NON_RELRO_FIRST, false);
2662
2663 // Create the PLT section.
2664 this->plt_ = new Output_data_plt_tilegx<size, big_endian>(layout,
2665 this->plt_entry_size(), this->got_, this->got_plt_, this->got_irelative_,
2666 plt_count);
2667
2668 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
2669 elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
2670 this->plt_, ORDER_PLT, false);
2671
2672 // Make the sh_info field of .rela.plt point to .plt.
2673 Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
2674 rela_plt_os->set_info_section(this->plt_->output_section());
2675
2676 // Create the rela_dyn section.
2677 this->rela_dyn_section(layout);
2678
2679 return this->got_;
2680}
2681
2682// Reserve a GOT entry for a local symbol, and regenerate any
2683// necessary dynamic relocations.
2684
2685template<int size, bool big_endian>
2686void
2687Target_tilegx<size, big_endian>::reserve_local_got_entry(
2688 unsigned int got_index,
2689 Sized_relobj<size, big_endian>* obj,
2690 unsigned int r_sym,
2691 unsigned int got_type)
2692{
2693 unsigned int got_offset = (got_index + TILEGX_GOT_RESERVE_COUNT)
2694 * (size / 8);
2695 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
2696
2697 this->got_->reserve_local(got_index, obj, r_sym, got_type);
2698 switch (got_type)
2699 {
2700 case GOT_TYPE_STANDARD:
2701 if (parameters->options().output_is_position_independent())
2702 rela_dyn->add_local_relative(obj, r_sym, elfcpp::R_TILEGX_RELATIVE,
2703 this->got_, got_offset, 0, false);
2704 break;
2705 case GOT_TYPE_TLS_OFFSET:
2706 rela_dyn->add_local(obj, r_sym,
2707 size == 32 ? elfcpp::R_TILEGX_TLS_DTPOFF32
2708 : elfcpp::R_TILEGX_TLS_DTPOFF64,
2709 this->got_, got_offset, 0);
2710 break;
2711 case GOT_TYPE_TLS_PAIR:
2712 this->got_->reserve_slot(got_index + 1);
2713 rela_dyn->add_local(obj, r_sym,
2714 size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
2715 : elfcpp::R_TILEGX_TLS_DTPMOD64,
2716 this->got_, got_offset, 0);
2717 break;
2718 case GOT_TYPE_TLS_DESC:
2719 gold_fatal(_("TLS_DESC not yet supported for incremental linking"));
2720 break;
2721 default:
2722 gold_unreachable();
2723 }
2724}
2725
2726// Reserve a GOT entry for a global symbol, and regenerate any
2727// necessary dynamic relocations.
2728
2729template<int size, bool big_endian>
2730void
2731Target_tilegx<size, big_endian>::reserve_global_got_entry(
2732 unsigned int got_index, Symbol* gsym, unsigned int got_type)
2733{
2734 unsigned int got_offset = (got_index + TILEGX_GOT_RESERVE_COUNT)
2735 * (size / 8);
2736 Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
2737
2738 this->got_->reserve_global(got_index, gsym, got_type);
2739 switch (got_type)
2740 {
2741 case GOT_TYPE_STANDARD:
2742 if (!gsym->final_value_is_known())
2743 {
2744 if (gsym->is_from_dynobj()
2745 || gsym->is_undefined()
2746 || gsym->is_preemptible()
2747 || gsym->type() == elfcpp::STT_GNU_IFUNC)
2748 rela_dyn->add_global(gsym, elfcpp::R_TILEGX_GLOB_DAT,
2749 this->got_, got_offset, 0);
2750 else
2751 rela_dyn->add_global_relative(gsym, elfcpp::R_TILEGX_RELATIVE,
2752 this->got_, got_offset, 0, false);
2753 }
2754 break;
2755 case GOT_TYPE_TLS_OFFSET:
2756 rela_dyn->add_global_relative(gsym,
2757 size == 32 ? elfcpp::R_TILEGX_TLS_TPOFF32
2758 : elfcpp::R_TILEGX_TLS_TPOFF64,
2759 this->got_, got_offset, 0, false);
2760 break;
2761 case GOT_TYPE_TLS_PAIR:
2762 this->got_->reserve_slot(got_index + 1);
2763 rela_dyn->add_global_relative(gsym,
2764 size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
2765 : elfcpp::R_TILEGX_TLS_DTPMOD64,
2766 this->got_, got_offset, 0, false);
2767 rela_dyn->add_global_relative(gsym,
2768 size == 32 ? elfcpp::R_TILEGX_TLS_DTPOFF32
2769 : elfcpp::R_TILEGX_TLS_DTPOFF64,
2770 this->got_, got_offset + size / 8,
2771 0, false);
2772 break;
2773 case GOT_TYPE_TLS_DESC:
2774 gold_fatal(_("TLS_DESC not yet supported for TILEGX"));
2775 break;
2776 default:
2777 gold_unreachable();
2778 }
2779}
2780
2781// Register an existing PLT entry for a global symbol.
2782
2783template<int size, bool big_endian>
2784void
2785Target_tilegx<size, big_endian>::register_global_plt_entry(
2786 Symbol_table* symtab, Layout* layout, unsigned int plt_index, Symbol* gsym)
2787{
2788 gold_assert(this->plt_ != NULL);
2789 gold_assert(!gsym->has_plt_offset());
2790
2791 this->plt_->reserve_slot(plt_index);
2792
2793 gsym->set_plt_offset((plt_index + 1) * this->plt_entry_size());
2794
2795 unsigned int got_offset = (plt_index + 2) * (size / 8);
2796 this->plt_->add_relocation(symtab, layout, gsym, got_offset);
2797}
2798
2799// Force a COPY relocation for a given symbol.
2800
2801template<int size, bool big_endian>
2802void
2803Target_tilegx<size, big_endian>::emit_copy_reloc(
2804 Symbol_table* symtab, Symbol* sym, Output_section* os, off_t offset)
2805{
2806 this->copy_relocs_.emit_copy_reloc(symtab,
2807 symtab->get_sized_symbol<size>(sym),
2808 os,
2809 offset,
2810 this->rela_dyn_section(NULL));
2811}
2812
2813// Create a GOT entry for the TLS module index.
2814
2815template<int size, bool big_endian>
2816unsigned int
2817Target_tilegx<size, big_endian>::got_mod_index_entry(Symbol_table* symtab,
2818 Layout* layout,
2819 Sized_relobj_file<size, big_endian>* object)
2820{
2821 if (this->got_mod_index_offset_ == -1U)
2822 {
2823 gold_assert(symtab != NULL && layout != NULL && object != NULL);
2824 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
2825 Output_data_got<size, big_endian>* got
2826 = this->got_section(symtab, layout);
2827 unsigned int got_offset = got->add_constant(0);
2828 rela_dyn->add_local(object, 0,
2829 size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
2830 : elfcpp::R_TILEGX_TLS_DTPMOD64, got,
2831 got_offset, 0);
2832 got->add_constant(0);
2833 this->got_mod_index_offset_ = got_offset;
2834 }
2835 return this->got_mod_index_offset_;
2836}
2837
2838// Optimize the TLS relocation type based on what we know about the
2839// symbol. IS_FINAL is true if the final address of this symbol is
2840// known at link time.
2841//
2842// the transformation rules is described below:
2843//
2844// compiler GD reference
2845// |
2846// V
2847// moveli tmp, hw1_last_tls_gd(x) X0/X1
2848// shl16insli r0, tmp, hw0_tls_gd(x) X0/X1
2849// addi r0, got, tls_add(x) Y0/Y1/X0/X1
2850// jal tls_gd_call(x) X1
2851// addi adr, r0, tls_gd_add(x) Y0/Y1/X0/X1
2852//
2853// linker tranformation of GD insn sequence
2854// |
2855// V
2856// ==> GD:
2857// moveli tmp, hw1_last_tls_gd(x) X0/X1
2858// shl16insli r0, tmp, hw0_tls_gd(x) X0/X1
2859// add r0, got, r0 Y0/Y1/X0/X1
2860// jal plt(__tls_get_addr) X1
2861// move adr, r0 Y0/Y1/X0/X1
2862// ==> IE:
2863// moveli tmp, hw1_last_tls_ie(x) X0/X1
2864// shl16insli r0, tmp, hw0_tls_ie(x) X0/X1
2865// add r0, got, r0 Y0/Y1/X0/X1
2866// ld r0, r0 X1
2867// add adr, r0, tp Y0/Y1/X0/X1
2868// ==> LE:
2869// moveli tmp, hw1_last_tls_le(x) X0/X1
2870// shl16insli r0, tmp, hw0_tls_le(x) X0/X1
2871// move r0, r0 Y0/Y1/X0/X1
2872// move r0, r0 Y0/Y1/X0/X1
2873// add adr, r0, tp Y0/Y1/X0/X1
2874//
2875//
2876// compiler IE reference
2877// |
2878// V
2879// moveli tmp, hw1_last_tls_ie(x) X0/X1
2880// shl16insli tmp, tmp, hw0_tls_ie(x) X0/X1
2881// addi tmp, got, tls_add(x) Y0/Y1/X0/X1
2882// ld_tls tmp, tmp, tls_ie_load(x) X1
2883// add adr, tmp, tp Y0/Y1/X0/X1
2884//
2885// linker transformation for IE insn sequence
2886// |
2887// V
2888// ==> IE:
2889// moveli tmp, hw1_last_tls_ie(x) X0/X1
2890// shl16insli tmp, tmp, hw0_tls_ie(x) X0/X1
2891// add tmp, got, tmp Y0/Y1/X0/X1
2892// ld tmp, tmp X1
2893// add adr, tmp, tp Y0/Y1/X0/X1
2894// ==> LE:
2895// moveli tmp, hw1_last_tls_le(x) X0/X1
2896// shl16insli tmp, tmp, hw0_tls_le(x) X0/X1
2897// move tmp, tmp Y0/Y1/X0/X1
2898// move tmp, tmp Y0/Y1/X0/X1
2899//
2900//
2901// compiler LE reference
2902// |
2903// V
2904// moveli tmp, hw1_last_tls_le(x) X0/X1
2905// shl16insli tmp, tmp, hw0_tls_le(x) X0/X1
2906// add adr, tmp, tp Y0/Y1/X0/X1
2907
2908template<int size, bool big_endian>
2909tls::Tls_optimization
2910Target_tilegx<size, big_endian>::optimize_tls_reloc(bool is_final, int r_type)
2911{
2912 // If we are generating a shared library, then we can't do anything
2913 // in the linker.
2914 if (parameters->options().shared())
2915 return tls::TLSOPT_NONE;
2916
2917 switch (r_type)
2918 {
2919 // unique GD relocations
2920 case elfcpp::R_TILEGX_TLS_GD_CALL:
2921 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
2922 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
2923 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
2924 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
2925 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
2926 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
2927 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
2928 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
2929 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
2930 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
2931 // These are General-Dynamic which permits fully general TLS
2932 // access. Since we know that we are generating an executable,
2933 // we can convert this to Initial-Exec. If we also know that
2934 // this is a local symbol, we can further switch to Local-Exec.
2935 if (is_final)
2936 return tls::TLSOPT_TO_LE;
2937 return tls::TLSOPT_TO_IE;
2938
2939 // unique IE relocations
2940 case elfcpp::R_TILEGX_TLS_IE_LOAD:
2941 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
2942 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
2943 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
2944 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
2945 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
2946 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
2947 // These are Initial-Exec relocs which get the thread offset
2948 // from the GOT. If we know that we are linking against the
2949 // local symbol, we can switch to Local-Exec, which links the
2950 // thread offset into the instruction.
2951 if (is_final)
2952 return tls::TLSOPT_TO_LE;
2953 return tls::TLSOPT_NONE;
2954
2955 // could be created for both GD and IE
2956 // but they are expanded into the same
2957 // instruction in GD and IE.
2958 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
2959 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
2960 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
2961 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
2962 if (is_final)
2963 return tls::TLSOPT_TO_LE;
2964 return tls::TLSOPT_NONE;
2965
2966 // unique LE relocations
2967 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
2968 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
2969 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
2970 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
2971 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
2972 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
2973 // When we already have Local-Exec, there is nothing further we
2974 // can do.
2975 return tls::TLSOPT_NONE;
2976
2977 default:
2978 gold_unreachable();
2979 }
2980}
2981
2982// Get the Reference_flags for a particular relocation.
2983
2984template<int size, bool big_endian>
2985int
2986Target_tilegx<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
2987{
2988 switch (r_type)
2989 {
2990 case elfcpp::R_TILEGX_NONE:
2991 case elfcpp::R_TILEGX_GNU_VTINHERIT:
2992 case elfcpp::R_TILEGX_GNU_VTENTRY:
2993 // No symbol reference.
2994 return 0;
2995
2996 case elfcpp::R_TILEGX_64:
2997 case elfcpp::R_TILEGX_32:
2998 case elfcpp::R_TILEGX_16:
2999 case elfcpp::R_TILEGX_8:
3000 return Symbol::ABSOLUTE_REF;
3001
3002 case elfcpp::R_TILEGX_BROFF_X1:
3003 case elfcpp::R_TILEGX_64_PCREL:
3004 case elfcpp::R_TILEGX_32_PCREL:
3005 case elfcpp::R_TILEGX_16_PCREL:
3006 case elfcpp::R_TILEGX_8_PCREL:
3007 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
3008 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
3009 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
3010 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
3011 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
3012 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
3013 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
3014 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
3015 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
3016 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
3017 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
3018 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
3019 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
3020 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
3021 return Symbol::RELATIVE_REF;
3022
3023 case elfcpp::R_TILEGX_JUMPOFF_X1:
3024 case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
3025 case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
3026 case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
3027 case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
3028 case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
3029 case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
3030 case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
3031 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
3032 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
3033 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
3034 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
3035 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
3036 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
3037 return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
3038
3039 case elfcpp::R_TILEGX_IMM16_X0_HW0:
3040 case elfcpp::R_TILEGX_IMM16_X1_HW0:
3041 case elfcpp::R_TILEGX_IMM16_X0_HW1:
3042 case elfcpp::R_TILEGX_IMM16_X1_HW1:
3043 case elfcpp::R_TILEGX_IMM16_X0_HW2:
3044 case elfcpp::R_TILEGX_IMM16_X1_HW2:
3045 case elfcpp::R_TILEGX_IMM16_X0_HW3:
3046 case elfcpp::R_TILEGX_IMM16_X1_HW3:
3047 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
3048 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
3049 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
3050 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
3051 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
3052 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
3053 return Symbol::ABSOLUTE_REF;
3054
3055 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
3056 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
3057 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
3058 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
3059 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
3060 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
3061 // Absolute in GOT.
3062 return Symbol::ABSOLUTE_REF;
3063
3064 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
3065 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
3066 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
3067 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
3068 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
3069 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
3070 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
3071 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
3072 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
3073 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
3074 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
3075 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
3076 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
3077 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
3078 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
3079 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
3080 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
3081 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
3082 case elfcpp::R_TILEGX_TLS_DTPOFF64:
3083 case elfcpp::R_TILEGX_TLS_DTPMOD32:
3084 case elfcpp::R_TILEGX_TLS_DTPOFF32:
3085 case elfcpp::R_TILEGX_TLS_TPOFF32:
3086 case elfcpp::R_TILEGX_TLS_GD_CALL:
3087 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
3088 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
3089 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
3090 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
3091 case elfcpp::R_TILEGX_TLS_IE_LOAD:
3092 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
3093 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
3094 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
3095 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
3096 return Symbol::TLS_REF;
3097
3098 case elfcpp::R_TILEGX_COPY:
3099 case elfcpp::R_TILEGX_GLOB_DAT:
3100 case elfcpp::R_TILEGX_JMP_SLOT:
3101 case elfcpp::R_TILEGX_RELATIVE:
3102 case elfcpp::R_TILEGX_TLS_TPOFF64:
3103 case elfcpp::R_TILEGX_TLS_DTPMOD64:
3104 default:
3105 // Not expected. We will give an error later.
3106 return 0;
3107 }
3108}
3109
3110// Report an unsupported relocation against a local symbol.
3111
3112template<int size, bool big_endian>
3113void
3114Target_tilegx<size, big_endian>::Scan::unsupported_reloc_local(
3115 Sized_relobj_file<size, big_endian>* object,
3116 unsigned int r_type)
3117{
3118 gold_error(_("%s: unsupported reloc %u against local symbol"),
3119 object->name().c_str(), r_type);
3120}
3121
3122// We are about to emit a dynamic relocation of type R_TYPE. If the
3123// dynamic linker does not support it, issue an error.
3124template<int size, bool big_endian>
3125void
3126Target_tilegx<size, big_endian>::Scan::check_non_pic(Relobj* object,
3127 unsigned int r_type)
3128{
3129 switch (r_type)
3130 {
3131 // These are the relocation types supported by glibc for tilegx
3132 // which should always work.
3133 case elfcpp::R_TILEGX_RELATIVE:
3134 case elfcpp::R_TILEGX_GLOB_DAT:
3135 case elfcpp::R_TILEGX_JMP_SLOT:
3136 case elfcpp::R_TILEGX_TLS_DTPMOD64:
3137 case elfcpp::R_TILEGX_TLS_DTPOFF64:
3138 case elfcpp::R_TILEGX_TLS_TPOFF64:
3139 case elfcpp::R_TILEGX_8:
3140 case elfcpp::R_TILEGX_16:
3141 case elfcpp::R_TILEGX_32:
3142 case elfcpp::R_TILEGX_64:
3143 case elfcpp::R_TILEGX_COPY:
3144 case elfcpp::R_TILEGX_IMM16_X0_HW0:
3145 case elfcpp::R_TILEGX_IMM16_X1_HW0:
3146 case elfcpp::R_TILEGX_IMM16_X0_HW1:
3147 case elfcpp::R_TILEGX_IMM16_X1_HW1:
3148 case elfcpp::R_TILEGX_IMM16_X0_HW2:
3149 case elfcpp::R_TILEGX_IMM16_X1_HW2:
3150 case elfcpp::R_TILEGX_IMM16_X0_HW3:
3151 case elfcpp::R_TILEGX_IMM16_X1_HW3:
3152 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
3153 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
3154 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
3155 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
3156 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
3157 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
3158 case elfcpp::R_TILEGX_BROFF_X1:
3159 case elfcpp::R_TILEGX_JUMPOFF_X1:
3160 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
3161 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
3162 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
3163 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
3164 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
3165 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
3166 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
3167 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
3168 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
3169 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
3170 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
3171 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
3172 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
3173 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
3174 return;
3175
3176 default:
3177 // This prevents us from issuing more than one error per reloc
3178 // section. But we can still wind up issuing more than one
3179 // error per object file.
3180 if (this->issued_non_pic_error_)
3181 return;
3182 gold_assert(parameters->options().output_is_position_independent());
3183 object->error(_("requires unsupported dynamic reloc %u; "
3184 "recompile with -fPIC"),
3185 r_type);
3186 this->issued_non_pic_error_ = true;
3187 return;
3188
3189 case elfcpp::R_TILEGX_NONE:
3190 gold_unreachable();
3191 }
3192}
3193
3194// Return whether we need to make a PLT entry for a relocation of the
3195// given type against a STT_GNU_IFUNC symbol.
3196
3197template<int size, bool big_endian>
3198bool
3199Target_tilegx<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
3200 Sized_relobj_file<size, big_endian>* object, unsigned int r_type)
3201{
3202 int flags = Scan::get_reference_flags(r_type);
3203 if (flags & Symbol::TLS_REF)
3204 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
3205 object->name().c_str(), r_type);
3206 return flags != 0;
3207}
3208
3209// Scan a relocation for a local symbol.
3210
3211template<int size, bool big_endian>
3212inline void
3213Target_tilegx<size, big_endian>::Scan::local(Symbol_table* symtab,
3214 Layout* layout,
3215 Target_tilegx<size, big_endian>* target,
3216 Sized_relobj_file<size, big_endian>* object,
3217 unsigned int data_shndx,
3218 Output_section* output_section,
3219 const elfcpp::Rela<size, big_endian>& reloc,
3220 unsigned int r_type,
3221 const elfcpp::Sym<size, big_endian>& lsym,
3222 bool is_discarded)
3223{
3224 if (is_discarded)
3225 return;
3226
3227 // A local STT_GNU_IFUNC symbol may require a PLT entry.
3228 bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
3229 if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type))
3230 {
3231 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3232 target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
3233 }
3234
3235 switch (r_type)
3236 {
3237 case elfcpp::R_TILEGX_NONE:
3238 case elfcpp::R_TILEGX_GNU_VTINHERIT:
3239 case elfcpp::R_TILEGX_GNU_VTENTRY:
3240 break;
3241
3242 // If building a shared library (or a position-independent
3243 // executable), because the runtime address needs plus
3244 // the module base address, so generate a R_TILEGX_RELATIVE.
3245 case elfcpp::R_TILEGX_32:
3246 case elfcpp::R_TILEGX_64:
3247 if (parameters->options().output_is_position_independent())
3248 {
3249 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3250 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3251 rela_dyn->add_local_relative(object, r_sym,
3252 elfcpp::R_TILEGX_RELATIVE,
3253 output_section, data_shndx,
3254 reloc.get_r_offset(),
3255 reloc.get_r_addend(), is_ifunc);
3256 }
3257 break;
3258
3259 // If building a shared library (or a position-independent
3260 // executable), we need to create a dynamic relocation for this
3261 // location.
3262 case elfcpp::R_TILEGX_8:
3263 case elfcpp::R_TILEGX_16:
3264 case elfcpp::R_TILEGX_IMM16_X0_HW0:
3265 case elfcpp::R_TILEGX_IMM16_X1_HW0:
3266 case elfcpp::R_TILEGX_IMM16_X0_HW1:
3267 case elfcpp::R_TILEGX_IMM16_X1_HW1:
3268 case elfcpp::R_TILEGX_IMM16_X0_HW2:
3269 case elfcpp::R_TILEGX_IMM16_X1_HW2:
3270 case elfcpp::R_TILEGX_IMM16_X0_HW3:
3271 case elfcpp::R_TILEGX_IMM16_X1_HW3:
3272 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
3273 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
3274 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
3275 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
3276 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
3277 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
3278 if (parameters->options().output_is_position_independent())
3279 {
3280 this->check_non_pic(object, r_type);
3281
3282 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3283 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3284 if (lsym.get_st_type() != elfcpp::STT_SECTION)
3285 rela_dyn->add_local(object, r_sym, r_type, output_section,
3286 data_shndx, reloc.get_r_offset(),
3287 reloc.get_r_addend());
3288 else
3289 {
3290 gold_assert(lsym.get_st_value() == 0);
3291 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
3292 output_section,
3293 data_shndx,
3294 reloc.get_r_offset(),
3295 reloc.get_r_addend());
3296
3297 }
3298 }
3299 break;
3300
3301 // R_TILEGX_JUMPOFF_X1_PLT against local symbol
3302 // may happen for ifunc case.
3303 case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
3304 case elfcpp::R_TILEGX_JUMPOFF_X1:
3305 case elfcpp::R_TILEGX_64_PCREL:
3306 case elfcpp::R_TILEGX_32_PCREL:
3307 case elfcpp::R_TILEGX_16_PCREL:
3308 case elfcpp::R_TILEGX_8_PCREL:
3309 case elfcpp::R_TILEGX_BROFF_X1:
3310 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
3311 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
3312 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
3313 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
3314 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
3315 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
3316 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
3317 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
3318 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
3319 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
3320 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
3321 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
3322 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
3323 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
3324 case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
3325 case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
3326 case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
3327 case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
3328 case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
3329 case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
3330 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
3331 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
3332 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
3333 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
3334 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
3335 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
3336 break;
3337
3338 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
3339 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
3340 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
3341 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
3342 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
3343 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
3344 {
3345 // The symbol requires a GOT entry.
3346 Output_data_got<size, big_endian>* got
3347 = target->got_section(symtab, layout);
3348 unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3349
3350 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
3351 // lets function pointers compare correctly with shared
3352 // libraries. Otherwise we would need an IRELATIVE reloc.
3353 bool is_new;
3354 if (is_ifunc)
3355 is_new = got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
3356 else
3357 is_new = got->add_local(object, r_sym, GOT_TYPE_STANDARD);
3358 if (is_new)
3359 {
3360 // tilegx dynamic linker will not update local got entry,
3361 // so, if we are generating a shared object, we need to add a
3362 // dynamic relocation for this symbol's GOT entry to inform
3363 // dynamic linker plus the load base explictly.
3364 if (parameters->options().output_is_position_independent())
3365 {
3366 unsigned int got_offset
3367 = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
3368
3369 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3370 rela_dyn->add_local_relative(object, r_sym,
3371 r_type,
3372 got, got_offset, 0, is_ifunc);
3373 }
3374 }
3375 }
3376 break;
3377
3378 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
3379 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
3380 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
3381 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
3382 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
3383 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
3384 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
3385 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
3386 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
3387 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
3388 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
3389 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
3390 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
3391 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
3392 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
3393 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
3394 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
3395 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
3396 case elfcpp::R_TILEGX_TLS_GD_CALL:
3397 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
3398 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
3399 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
3400 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
3401 case elfcpp::R_TILEGX_TLS_IE_LOAD:
3402 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
3403 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
3404 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
3405 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
3406 {
3407 bool output_is_shared = parameters->options().shared();
3408 const tls::Tls_optimization opt_t =
3409 Target_tilegx<size, big_endian>::optimize_tls_reloc(
3410 !output_is_shared, r_type);
3411
3412 switch (r_type)
3413 {
3414 case elfcpp::R_TILEGX_TLS_GD_CALL:
3415 // FIXME: predefine __tls_get_addr
3416 //
3417 // R_TILEGX_TLS_GD_CALL implicitly reference __tls_get_addr,
3418 // while all other target, x86/arm/mips/powerpc/sparc
3419 // generate tls relocation against __tls_get_addr explictly,
3420 // so for TILEGX, we need the following hack.
3421 if (opt_t == tls::TLSOPT_NONE) {
3422 if (!target->tls_get_addr_sym_defined_) {
3423 Symbol* sym = NULL;
3424 options::parse_set(NULL, "__tls_get_addr",
3425 (gold::options::String_set*)
3426 &parameters->options().undefined());
3427 symtab->add_undefined_symbols_from_command_line(layout);
3428 target->tls_get_addr_sym_defined_ = true;
3429 sym = symtab->lookup("__tls_get_addr");
3430 sym->set_in_reg();
3431 }
3432 target->make_plt_entry(symtab, layout,
3433 symtab->lookup("__tls_get_addr"));
3434 }
3435 break;
3436
3437 // only make effect when applying relocation
3438 case elfcpp::R_TILEGX_TLS_IE_LOAD:
3439 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
3440 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
3441 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
3442 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
3443 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
3444 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
3445 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
3446 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
3447 break;
3448
3449 // GD: requires two GOT entry for module index and offset
3450 // IE: requires one GOT entry for tp-relative offset
3451 // LE: shouldn't happen for global symbol
3452 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
3453 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
3454 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
3455 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
3456 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
3457 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
3458 {
3459 if (opt_t == tls::TLSOPT_NONE) {
3460 Output_data_got<size, big_endian> *got
3461 = target->got_section(symtab, layout);
3462 unsigned int r_sym
3463 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3464 unsigned int shndx = lsym.get_st_shndx();
3465 bool is_ordinary;
3466 shndx = object->adjust_sym_shndx(r_sym, shndx,
3467 &is_ordinary);
3468 if (!is_ordinary)
3469 object->error(_("local symbol %u has bad shndx %u"),
3470 r_sym, shndx);
3471 else
3472 got->add_local_pair_with_rel(object, r_sym, shndx,
3473 GOT_TYPE_TLS_PAIR,
3474 target->rela_dyn_section(layout),
3475 size == 32
3476 ? elfcpp::R_TILEGX_TLS_DTPMOD32
3477 : elfcpp::R_TILEGX_TLS_DTPMOD64);
3478 } else if (opt_t == tls::TLSOPT_TO_IE) {
3479 Output_data_got<size, big_endian>* got
3480 = target->got_section(symtab, layout);
3481 Reloc_section* rela_dyn
3482 = target->rela_dyn_section(layout);
3483 unsigned int r_sym
3484 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3485 unsigned int off = got->add_constant(0);
3486 object->set_local_got_offset(r_sym,
3487 GOT_TYPE_TLS_OFFSET,off);
3488 rela_dyn->add_symbolless_local_addend(object, r_sym,
3489 size == 32
3490 ? elfcpp::R_TILEGX_TLS_TPOFF32
3491 : elfcpp::R_TILEGX_TLS_TPOFF64,
3492 got, off, 0);
3493 } else if (opt_t != tls::TLSOPT_TO_LE)
3494 // only TO_LE is allowed for local symbol
3495 unsupported_reloc_local(object, r_type);
3496 }
3497 break;
3498
3499 // IE
3500 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
3501 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
3502 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
3503 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
3504 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
3505 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
3506 {
3507 layout->set_has_static_tls();
3508 if (opt_t == tls::TLSOPT_NONE) {
3509 Output_data_got<size, big_endian>* got
3510 = target->got_section(symtab, layout);
3511 Reloc_section* rela_dyn
3512 = target->rela_dyn_section(layout);
3513 unsigned int r_sym
3514 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3515 unsigned int off = got->add_constant(0);
3516 object->set_local_got_offset(r_sym,
3517 GOT_TYPE_TLS_OFFSET, off);
3518 rela_dyn->add_symbolless_local_addend(object, r_sym,
3519 size == 32
3520 ? elfcpp::R_TILEGX_TLS_TPOFF32
3521 : elfcpp::R_TILEGX_TLS_TPOFF64,
3522 got, off, 0);
3523 } else if (opt_t != tls::TLSOPT_TO_LE)
3524 unsupported_reloc_local(object, r_type);
3525 }
3526 break;
3527
3528 // LE
3529 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
3530 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
3531 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
3532 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
3533 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
3534 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
3535 layout->set_has_static_tls();
3536 if (parameters->options().shared()) {
3537 // defer to dynamic linker
3538 gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
3539 unsigned int r_sym
3540 = elfcpp::elf_r_sym<size>(reloc.get_r_info());
3541 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3542 rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
3543 output_section, data_shndx,
3544 reloc.get_r_offset(), 0);
3545 }
3546 break;
3547
3548 default:
3549 gold_unreachable();
3550 }
3551 }
3552 break;
3553
3554 case elfcpp::R_TILEGX_COPY:
3555 case elfcpp::R_TILEGX_GLOB_DAT:
3556 case elfcpp::R_TILEGX_JMP_SLOT:
3557 case elfcpp::R_TILEGX_RELATIVE:
3558 // These are outstanding tls relocs, which are unexpected when linking
3559 case elfcpp::R_TILEGX_TLS_TPOFF32:
3560 case elfcpp::R_TILEGX_TLS_TPOFF64:
3561 case elfcpp::R_TILEGX_TLS_DTPMOD32:
3562 case elfcpp::R_TILEGX_TLS_DTPMOD64:
3563 case elfcpp::R_TILEGX_TLS_DTPOFF32:
3564 case elfcpp::R_TILEGX_TLS_DTPOFF64:
3565 gold_error(_("%s: unexpected reloc %u in object file"),
3566 object->name().c_str(), r_type);
3567 break;
3568
3569 default:
3570 gold_error(_("%s: unsupported reloc %u against local symbol"),
3571 object->name().c_str(), r_type);
3572 break;
3573 }
3574}
3575
3576
3577// Report an unsupported relocation against a global symbol.
3578
3579template<int size, bool big_endian>
3580void
3581Target_tilegx<size, big_endian>::Scan::unsupported_reloc_global(
3582 Sized_relobj_file<size, big_endian>* object,
3583 unsigned int r_type,
3584 Symbol* gsym)
3585{
3586 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3587 object->name().c_str(), r_type, gsym->demangled_name().c_str());
3588}
3589
3590// Returns true if this relocation type could be that of a function pointer.
3591template<int size, bool big_endian>
3592inline bool
3593Target_tilegx<size, big_endian>::Scan::possible_function_pointer_reloc(
3594 unsigned int r_type)
3595{
3596 switch (r_type)
3597 {
3598 case elfcpp::R_TILEGX_IMM16_X0_HW0:
3599 case elfcpp::R_TILEGX_IMM16_X1_HW0:
3600 case elfcpp::R_TILEGX_IMM16_X0_HW1:
3601 case elfcpp::R_TILEGX_IMM16_X1_HW1:
3602 case elfcpp::R_TILEGX_IMM16_X0_HW2:
3603 case elfcpp::R_TILEGX_IMM16_X1_HW2:
3604 case elfcpp::R_TILEGX_IMM16_X0_HW3:
3605 case elfcpp::R_TILEGX_IMM16_X1_HW3:
3606 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
3607 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
3608 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
3609 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
3610 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
3611 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
3612 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
3613 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
3614 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
3615 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
3616 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
3617 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
3618 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
3619 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
3620 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
3621 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
3622 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
3623 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
3624 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
3625 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
3626 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
3627 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
3628 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
3629 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
3630 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
3631 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
3632 {
3633 return true;
3634 }
3635 }
3636 return false;
3637}
3638
3639// For safe ICF, scan a relocation for a local symbol to check if it
3640// corresponds to a function pointer being taken. In that case mark
3641// the function whose pointer was taken as not foldable.
3642
3643template<int size, bool big_endian>
3644inline bool
3645Target_tilegx<size, big_endian>::Scan::local_reloc_may_be_function_pointer(
3646 Symbol_table* ,
3647 Layout* ,
3648 Target_tilegx<size, big_endian>* ,
3649 Sized_relobj_file<size, big_endian>* ,
3650 unsigned int ,
3651 Output_section* ,
3652 const elfcpp::Rela<size, big_endian>& ,
3653 unsigned int r_type,
3654 const elfcpp::Sym<size, big_endian>&)
3655{
3656 return possible_function_pointer_reloc(r_type);
3657}
3658
3659// For safe ICF, scan a relocation for a global symbol to check if it
3660// corresponds to a function pointer being taken. In that case mark
3661// the function whose pointer was taken as not foldable.
3662
3663template<int size, bool big_endian>
3664inline bool
3665Target_tilegx<size, big_endian>::Scan::global_reloc_may_be_function_pointer(
3666 Symbol_table*,
3667 Layout* ,
3668 Target_tilegx<size, big_endian>* ,
3669 Sized_relobj_file<size, big_endian>* ,
3670 unsigned int ,
3671 Output_section* ,
3672 const elfcpp::Rela<size, big_endian>& ,
3673 unsigned int r_type,
3674 Symbol* gsym)
3675{
3676 // GOT is not a function.
3677 if (strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
3678 return false;
3679
3680 // When building a shared library, do not fold symbols whose visibility
3681 // is hidden, internal or protected.
3682 return ((parameters->options().shared()
3683 && (gsym->visibility() == elfcpp::STV_INTERNAL
3684 || gsym->visibility() == elfcpp::STV_PROTECTED
3685 || gsym->visibility() == elfcpp::STV_HIDDEN))
3686 || possible_function_pointer_reloc(r_type));
3687}
3688
3689// Scan a relocation for a global symbol.
3690
3691template<int size, bool big_endian>
3692inline void
3693Target_tilegx<size, big_endian>::Scan::global(Symbol_table* symtab,
3694 Layout* layout,
3695 Target_tilegx<size, big_endian>* target,
3696 Sized_relobj_file<size, big_endian>* object,
3697 unsigned int data_shndx,
3698 Output_section* output_section,
3699 const elfcpp::Rela<size, big_endian>& reloc,
3700 unsigned int r_type,
3701 Symbol* gsym)
3702{
3703 // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
3704 // section. We check here to avoid creating a dynamic reloc against
3705 // _GLOBAL_OFFSET_TABLE_.
3706 if (!target->has_got_section()
3707 && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
3708 target->got_section(symtab, layout);
3709
3710 // A STT_GNU_IFUNC symbol may require a PLT entry.
3711 if (gsym->type() == elfcpp::STT_GNU_IFUNC
3712 && this->reloc_needs_plt_for_ifunc(object, r_type))
3713 target->make_plt_entry(symtab, layout, gsym);
3714
3715 switch (r_type)
3716 {
3717 case elfcpp::R_TILEGX_NONE:
3718 case elfcpp::R_TILEGX_GNU_VTINHERIT:
3719 case elfcpp::R_TILEGX_GNU_VTENTRY:
3720 break;
3721
3722 case elfcpp::R_TILEGX_DEST_IMM8_X1:
3723 case elfcpp::R_TILEGX_IMM16_X0_HW0:
3724 case elfcpp::R_TILEGX_IMM16_X1_HW0:
3725 case elfcpp::R_TILEGX_IMM16_X0_HW1:
3726 case elfcpp::R_TILEGX_IMM16_X1_HW1:
3727 case elfcpp::R_TILEGX_IMM16_X0_HW2:
3728 case elfcpp::R_TILEGX_IMM16_X1_HW2:
3729 case elfcpp::R_TILEGX_IMM16_X0_HW3:
3730 case elfcpp::R_TILEGX_IMM16_X1_HW3:
3731 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
3732 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
3733 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
3734 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
3735 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
3736 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
3737 case elfcpp::R_TILEGX_64:
3738 case elfcpp::R_TILEGX_32:
3739 case elfcpp::R_TILEGX_16:
3740 case elfcpp::R_TILEGX_8:
3741 {
3742 // Make a PLT entry if necessary.
3743 if (gsym->needs_plt_entry())
3744 {
3745 target->make_plt_entry(symtab, layout, gsym);
3746 // Since this is not a PC-relative relocation, we may be
3747 // taking the address of a function. In that case we need to
3748 // set the entry in the dynamic symbol table to the address of
3749 // the PLT entry.
3750 if (gsym->is_from_dynobj() && !parameters->options().shared())
3751 gsym->set_needs_dynsym_value();
3752 }
3753 // Make a dynamic relocation if necessary.
3754 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
3755 {
3756 if (gsym->may_need_copy_reloc())
3757 {
3758 target->copy_reloc(symtab, layout, object,
3759 data_shndx, output_section, gsym, reloc);
3760 }
3761 else if (((size == 64 && r_type == elfcpp::R_TILEGX_64)
3762 || (size == 32 && r_type == elfcpp::R_TILEGX_32))
3763 && gsym->type() == elfcpp::STT_GNU_IFUNC
3764 && gsym->can_use_relative_reloc(false)
3765 && !gsym->is_from_dynobj()
3766 && !gsym->is_undefined()
3767 && !gsym->is_preemptible())
3768 {
3769 // Use an IRELATIVE reloc for a locally defined
3770 // STT_GNU_IFUNC symbol. This makes a function
3771 // address in a PIE executable match the address in a
3772 // shared library that it links against.
3773 Reloc_section* rela_dyn =
3774 target->rela_irelative_section(layout);
3775 unsigned int r_type = elfcpp::R_TILEGX_IRELATIVE;
3776 rela_dyn->add_symbolless_global_addend(gsym, r_type,
3777 output_section, object,
3778 data_shndx,
3779 reloc.get_r_offset(),
3780 reloc.get_r_addend());
3781 } else if ((r_type == elfcpp::R_TILEGX_64
3782 || r_type == elfcpp::R_TILEGX_32)
3783 && gsym->can_use_relative_reloc(false))
3784 {
3785 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3786 rela_dyn->add_global_relative(gsym, elfcpp::R_TILEGX_RELATIVE,
3787 output_section, object,
3788 data_shndx,
3789 reloc.get_r_offset(),
3790 reloc.get_r_addend(), false);
3791 }
3792 else
3793 {
3794 this->check_non_pic(object, r_type);
3795 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3796 rela_dyn->add_global(gsym, r_type, output_section, object,
3797 data_shndx, reloc.get_r_offset(),
3798 reloc.get_r_addend());
3799 }
3800 }
3801 }
3802 break;
3803
3804 case elfcpp::R_TILEGX_BROFF_X1:
3805 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
3806 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
3807 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
3808 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
3809 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
3810 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
3811 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
3812 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
3813 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
3814 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
3815 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
3816 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
3817 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
3818 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
3819 case elfcpp::R_TILEGX_64_PCREL:
3820 case elfcpp::R_TILEGX_32_PCREL:
3821 case elfcpp::R_TILEGX_16_PCREL:
3822 case elfcpp::R_TILEGX_8_PCREL:
3823 {
3824 // Make a PLT entry if necessary.
3825 if (gsym->needs_plt_entry())
3826 target->make_plt_entry(symtab, layout, gsym);
3827 // Make a dynamic relocation if necessary.
3828 if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
3829 {
3830 if (gsym->may_need_copy_reloc())
3831 {
3832 target->copy_reloc(symtab, layout, object,
3833 data_shndx, output_section, gsym, reloc);
3834 }
3835 else
3836 {
3837 this->check_non_pic(object, r_type);
3838 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3839 rela_dyn->add_global(gsym, r_type, output_section, object,
3840 data_shndx, reloc.get_r_offset(),
3841 reloc.get_r_addend());
3842 }
3843 }
3844 }
3845 break;
3846
3847 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
3848 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
3849 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
3850 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
3851 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
3852 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
3853 {
3854 // The symbol requires a GOT entry.
3855 Output_data_got<size, big_endian>* got
3856 = target->got_section(symtab, layout);
3857 if (gsym->final_value_is_known())
3858 {
3859 // For a STT_GNU_IFUNC symbol we want the PLT address.
3860 if (gsym->type() == elfcpp::STT_GNU_IFUNC)
3861 got->add_global_plt(gsym, GOT_TYPE_STANDARD);
3862 else
3863 got->add_global(gsym, GOT_TYPE_STANDARD);
3864 }
3865 else
3866 {
3867 // If this symbol is not fully resolved, we need to add a
3868 // dynamic relocation for it.
3869 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
3870
3871 // Use a GLOB_DAT rather than a RELATIVE reloc if:
3872 //
3873 // 1) The symbol may be defined in some other module.
3874 //
3875 // 2) We are building a shared library and this is a
3876 // protected symbol; using GLOB_DAT means that the dynamic
3877 // linker can use the address of the PLT in the main
3878 // executable when appropriate so that function address
3879 // comparisons work.
3880 //
3881 // 3) This is a STT_GNU_IFUNC symbol in position dependent
3882 // code, again so that function address comparisons work.
3883 if (gsym->is_from_dynobj()
3884 || gsym->is_undefined()
3885 || gsym->is_preemptible()
3886 || (gsym->visibility() == elfcpp::STV_PROTECTED
3887 && parameters->options().shared())
3888 || (gsym->type() == elfcpp::STT_GNU_IFUNC
3889 && parameters->options().output_is_position_independent()))
3890 got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
3891 elfcpp::R_TILEGX_GLOB_DAT);
3892 else
3893 {
3894 // For a STT_GNU_IFUNC symbol we want to write the PLT
3895 // offset into the GOT, so that function pointer
3896 // comparisons work correctly.
3897 bool is_new;
3898 if (gsym->type() != elfcpp::STT_GNU_IFUNC)
3899 is_new = got->add_global(gsym, GOT_TYPE_STANDARD);
3900 else
3901 {
3902 is_new = got->add_global_plt(gsym, GOT_TYPE_STANDARD);
3903 // Tell the dynamic linker to use the PLT address
3904 // when resolving relocations.
3905 if (gsym->is_from_dynobj()
3906 && !parameters->options().shared())
3907 gsym->set_needs_dynsym_value();
3908 }
3909 if (is_new)
3910 {
3911 unsigned int got_off = gsym->got_offset(GOT_TYPE_STANDARD);
3912 rela_dyn->add_global_relative(gsym,
3913 r_type,
3914 got, got_off, 0, false);
3915 }
3916 }
3917 }
3918 }
3919 break;
3920
3921 // a minor difference here for R_TILEGX_JUMPOFF_X1
3922 // between bfd linker and gold linker for gold, when
3923 // R_TILEGX_JUMPOFF_X1 against global symbol, we
3924 // turn it into JUMPOFF_X1_PLT, otherwise the distance
3925 // to the symbol function may overflow at runtime.
3926 case elfcpp::R_TILEGX_JUMPOFF_X1:
3927
3928 case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
3929 case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
3930 case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
3931 case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
3932 case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
3933 case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
3934 case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
3935 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
3936 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
3937 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
3938 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
3939 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
3940 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
3941 // If the symbol is fully resolved, this is just a PC32 reloc.
3942 // Otherwise we need a PLT entry.
3943 if (gsym->final_value_is_known())
3944 break;
3945 // If building a shared library, we can also skip the PLT entry
3946 // if the symbol is defined in the output file and is protected
3947 // or hidden.
3948 if (gsym->is_defined()
3949 && !gsym->is_from_dynobj()
3950 && !gsym->is_preemptible())
3951 break;
3952 target->make_plt_entry(symtab, layout, gsym);
3953 break;
3954
3955
3956 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
3957 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
3958 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
3959 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
3960 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
3961 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
3962 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
3963 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
3964 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
3965 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
3966 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
3967 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
3968 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
3969 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
3970 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
3971 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
3972 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
3973 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
3974 case elfcpp::R_TILEGX_TLS_GD_CALL:
3975 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
3976 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
3977 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
3978 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
3979 case elfcpp::R_TILEGX_TLS_IE_LOAD:
3980 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
3981 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
3982 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
3983 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
3984 {
3985 const bool is_final = gsym->final_value_is_known();
3986 const tls::Tls_optimization opt_t =
3987 Target_tilegx<size, big_endian>::optimize_tls_reloc(is_final,
3988 r_type);
3989
3990 switch (r_type)
3991 {
3992 // only expand to plt against __tls_get_addr in GD model
3993 case elfcpp::R_TILEGX_TLS_GD_CALL:
3994 if (opt_t == tls::TLSOPT_NONE) {
3995 // FIXME: it's better '__tls_get_addr' referenced explictly
3996 if (!target->tls_get_addr_sym_defined_) {
3997 Symbol* sym = NULL;
3998 options::parse_set(NULL, "__tls_get_addr",
3999 (gold::options::String_set*)
4000 &parameters->options().undefined());
4001 symtab->add_undefined_symbols_from_command_line(layout);
4002 target->tls_get_addr_sym_defined_ = true;
4003 sym = symtab->lookup("__tls_get_addr");
4004 sym->set_in_reg();
4005 }
4006 target->make_plt_entry(symtab, layout,
4007 symtab->lookup("__tls_get_addr"));
4008 }
4009 break;
4010
4011 // only make effect when applying relocation
4012 case elfcpp::R_TILEGX_TLS_IE_LOAD:
4013 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
4014 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
4015 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
4016 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
4017 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
4018 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
4019 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
4020 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
4021 break;
4022
4023 // GD: requires two GOT entry for module index and offset
4024 // IE: requires one GOT entry for tp-relative offset
4025 // LE: shouldn't happen for global symbol
4026 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
4027 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
4028 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
4029 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
4030 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
4031 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
4032 {
4033 if (opt_t == tls::TLSOPT_NONE) {
4034 Output_data_got<size, big_endian>* got
4035 = target->got_section(symtab, layout);
4036 got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
4037 target->rela_dyn_section(layout),
4038 size == 32
4039 ? elfcpp::R_TILEGX_TLS_DTPMOD32
4040 : elfcpp::R_TILEGX_TLS_DTPMOD64,
4041 size == 32
4042 ? elfcpp::R_TILEGX_TLS_DTPOFF32
4043 : elfcpp::R_TILEGX_TLS_DTPOFF64);
4044 } else if (opt_t == tls::TLSOPT_TO_IE) {
4045 // Create a GOT entry for the tp-relative offset.
4046 Output_data_got<size, big_endian>* got
4047 = target->got_section(symtab, layout);
4048 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
4049 target->rela_dyn_section(layout),
4050 size == 32
4051 ? elfcpp::R_TILEGX_TLS_TPOFF32
4052 : elfcpp::R_TILEGX_TLS_TPOFF64);
4053 } else if (opt_t != tls::TLSOPT_TO_LE)
4054 // exteranl symbol should not be optimized to TO_LE
4055 unsupported_reloc_global(object, r_type, gsym);
4056 }
4057 break;
4058
4059 // IE
4060 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
4061 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
4062 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
4063 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
4064 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
4065 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
4066 {
4067 layout->set_has_static_tls();
4068 if (opt_t == tls::TLSOPT_NONE) {
4069 // Create a GOT entry for the tp-relative offset.
4070 Output_data_got<size, big_endian>* got
4071 = target->got_section(symtab, layout);
4072 got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
4073 target->rela_dyn_section(layout),
4074 size == 32
4075 ? elfcpp::R_TILEGX_TLS_TPOFF32
4076 : elfcpp::R_TILEGX_TLS_TPOFF64);
4077 } else if (opt_t != tls::TLSOPT_TO_LE)
4078 unsupported_reloc_global(object, r_type, gsym);
4079 }
4080 break;
4081
4082 // LE
4083 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
4084 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
4085 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
4086 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
4087 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
4088 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
4089 layout->set_has_static_tls();
4090 if (parameters->options().shared()) {
4091 // defer to dynamic linker
4092 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
4093 rela_dyn->add_symbolless_global_addend(gsym, r_type,
4094 output_section, object,
4095 data_shndx,
4096 reloc.get_r_offset(), 0);
4097 }
4098 break;
4099
4100 default:
4101 gold_unreachable();
4102 }
4103 }
4104 break;
4105
4106 // below are outstanding relocs
4107 // should not existed in static linking stage
4108 case elfcpp::R_TILEGX_COPY:
4109 case elfcpp::R_TILEGX_GLOB_DAT:
4110 case elfcpp::R_TILEGX_JMP_SLOT:
4111 case elfcpp::R_TILEGX_RELATIVE:
4112 case elfcpp::R_TILEGX_TLS_TPOFF32:
4113 case elfcpp::R_TILEGX_TLS_TPOFF64:
4114 case elfcpp::R_TILEGX_TLS_DTPMOD32:
4115 case elfcpp::R_TILEGX_TLS_DTPMOD64:
4116 case elfcpp::R_TILEGX_TLS_DTPOFF32:
4117 case elfcpp::R_TILEGX_TLS_DTPOFF64:
4118 gold_error(_("%s: unexpected reloc %u in object file"),
4119 object->name().c_str(), r_type);
4120 break;
4121
4122 default:
4123 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
4124 object->name().c_str(), r_type,
4125 gsym->demangled_name().c_str());
4126 break;
4127 }
4128}
4129
4130template<int size, bool big_endian>
4131void
4132Target_tilegx<size, big_endian>::gc_process_relocs(Symbol_table* symtab,
4133 Layout* layout,
4134 Sized_relobj_file<size, big_endian>* object,
4135 unsigned int data_shndx,
4136 unsigned int sh_type,
4137 const unsigned char* prelocs,
4138 size_t reloc_count,
4139 Output_section* output_section,
4140 bool needs_special_offset_handling,
4141 size_t local_symbol_count,
4142 const unsigned char* plocal_symbols)
4143{
4144 typedef Target_tilegx<size, big_endian> Tilegx;
4145 typedef typename Target_tilegx<size, big_endian>::Scan Scan;
4146
4147 if (sh_type == elfcpp::SHT_REL)
4148 {
4149 return;
4150 }
4151
4152 gold::gc_process_relocs<size, big_endian,
4153 Tilegx, elfcpp::SHT_RELA, Scan,
4154 typename Target_tilegx<size, big_endian>::Relocatable_size_for_reloc>(
4155 symtab,
4156 layout,
4157 this,
4158 object,
4159 data_shndx,
4160 prelocs,
4161 reloc_count,
4162 output_section,
4163 needs_special_offset_handling,
4164 local_symbol_count,
4165 plocal_symbols);
4166}
4167// Scan relocations for a section.
4168
4169template<int size, bool big_endian>
4170void
4171Target_tilegx<size, big_endian>::scan_relocs(Symbol_table* symtab,
4172 Layout* layout,
4173 Sized_relobj_file<size, big_endian>* object,
4174 unsigned int data_shndx,
4175 unsigned int sh_type,
4176 const unsigned char* prelocs,
4177 size_t reloc_count,
4178 Output_section* output_section,
4179 bool needs_special_offset_handling,
4180 size_t local_symbol_count,
4181 const unsigned char* plocal_symbols)
4182{
4183 typedef Target_tilegx<size, big_endian> Tilegx;
4184 typedef typename Target_tilegx<size, big_endian>::Scan Scan;
4185
4186 if (sh_type == elfcpp::SHT_REL)
4187 {
4188 gold_error(_("%s: unsupported REL reloc section"),
4189 object->name().c_str());
4190 return;
4191 }
4192
4193 gold::scan_relocs<size, big_endian, Tilegx, elfcpp::SHT_RELA, Scan>(
4194 symtab,
4195 layout,
4196 this,
4197 object,
4198 data_shndx,
4199 prelocs,
4200 reloc_count,
4201 output_section,
4202 needs_special_offset_handling,
4203 local_symbol_count,
4204 plocal_symbols);
4205}
4206
4207template<int size, bool big_endian>
4208void
4209Target_tilegx<size, big_endian>::do_define_standard_symbols(
4210 Symbol_table* symtab,
4211 Layout* layout)
4212{
4213 Output_section* feedback_section = layout->find_output_section(".feedback");
4214
4215 if (feedback_section != NULL)
4216 {
4217 symtab->define_in_output_data("__feedback_section_end",
4218 NULL,
4219 Symbol_table::PREDEFINED,
4220 feedback_section,
4221 0,
4222 0,
4223 elfcpp::STT_NOTYPE,
4224 elfcpp::STB_GLOBAL,
4225 elfcpp::STV_HIDDEN,
4226 0,
4227 true, // offset_is_from_end
4228 false);
4229 }
4230}
4231
4232// Finalize the sections.
4233
4234template<int size, bool big_endian>
4235void
4236Target_tilegx<size, big_endian>::do_finalize_sections(
4237 Layout* layout,
4238 const Input_objects*,
4239 Symbol_table* symtab)
4240{
4241 const Reloc_section* rel_plt = (this->plt_ == NULL
4242 ? NULL
4243 : this->plt_->rela_plt());
4244 layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
4245 this->rela_dyn_, true, true);
4246
4247 // Emit any relocs we saved in an attempt to avoid generating COPY
4248 // relocs.
4249 if (this->copy_relocs_.any_saved_relocs())
4250 this->copy_relocs_.emit(this->rela_dyn_section(layout));
4251
4252 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
4253 // the .got section.
4254 Symbol* sym = this->global_offset_table_;
4255 if (sym != NULL)
4256 {
4257 uint64_t data_size = this->got_->current_data_size();
4258 symtab->get_sized_symbol<size>(sym)->set_symsize(data_size);
4259 }
4260
4261 if (parameters->doing_static_link()
4262 && (this->plt_ == NULL || !this->plt_->has_irelative_section()))
4263 {
4264 // If linking statically, make sure that the __rela_iplt symbols
4265 // were defined if necessary, even if we didn't create a PLT.
4266 static const Define_symbol_in_segment syms[] =
4267 {
4268 {
4269 "__rela_iplt_start", // name
4270 elfcpp::PT_LOAD, // segment_type
4271 elfcpp::PF_W, // segment_flags_set
4272 elfcpp::PF(0), // segment_flags_clear
4273 0, // value
4274 0, // size
4275 elfcpp::STT_NOTYPE, // type
4276 elfcpp::STB_GLOBAL, // binding
4277 elfcpp::STV_HIDDEN, // visibility
4278 0, // nonvis
4279 Symbol::SEGMENT_START, // offset_from_base
4280 true // only_if_ref
4281 },
4282 {
4283 "__rela_iplt_end", // name
4284 elfcpp::PT_LOAD, // segment_type
4285 elfcpp::PF_W, // segment_flags_set
4286 elfcpp::PF(0), // segment_flags_clear
4287 0, // value
4288 0, // size
4289 elfcpp::STT_NOTYPE, // type
4290 elfcpp::STB_GLOBAL, // binding
4291 elfcpp::STV_HIDDEN, // visibility
4292 0, // nonvis
4293 Symbol::SEGMENT_START, // offset_from_base
4294 true // only_if_ref
4295 }
4296 };
4297
4298 symtab->define_symbols(layout, 2, syms,
4299 layout->script_options()->saw_sections_clause());
4300 }
4301}
4302
4303// Perform a relocation.
4304
4305template<int size, bool big_endian>
4306inline bool
4307Target_tilegx<size, big_endian>::Relocate::relocate(
4308 const Relocate_info<size, big_endian>* relinfo,
4309 Target_tilegx<size, big_endian>* target,
4310 Output_section*,
4311 size_t relnum,
4312 const elfcpp::Rela<size, big_endian>& rela,
4313 unsigned int r_type,
4314 const Sized_symbol<size>* gsym,
4315 const Symbol_value<size>* psymval,
4316 unsigned char* view,
4317 typename elfcpp::Elf_types<size>::Elf_Addr address,
4318 section_size_type)
4319{
4320 typedef Tilegx_relocate_functions<size, big_endian> TilegxReloc;
4321 typename TilegxReloc::Tilegx_howto r_howto;
4322
4323 const Sized_relobj_file<size, big_endian>* object = relinfo->object;
4324
4325 // Pick the value to use for symbols defined in the PLT.
4326 Symbol_value<size> symval;
4327 if (gsym != NULL
4328 && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
4329 {
4330 symval.set_output_value(target->plt_address_for_global(gsym)
4331 + gsym->plt_offset());
4332 psymval = &symval;
4333 }
4334 else if (gsym == NULL && psymval->is_ifunc_symbol())
4335 {
4336 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
4337 if (object->local_has_plt_offset(r_sym))
4338 {
4339 symval.set_output_value(target->plt_address_for_local(object, r_sym)
4340 + object->local_plt_offset(r_sym));
4341 psymval = &symval;
4342 }
4343 }
4344
4345 elfcpp::Elf_Xword addend = rela.get_r_addend();
4346
4347 // Get the GOT offset if needed.
4348 // For tilegx, the GOT pointer points to the start of the GOT section.
4349 bool have_got_offset = false;
4350 unsigned int got_offset = 0;
4351 unsigned int got_type = GOT_TYPE_STANDARD;
4352 bool always_apply_relocation = false;
4353 switch (r_type)
4354 {
4355 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
4356 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
4357 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
4358 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
4359 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
4360 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
4361 if (gsym != NULL)
4362 {
4363 gold_assert(gsym->has_got_offset(got_type));
4364 got_offset = gsym->got_offset(got_type);
4365 }
4366 else
4367 {
4368 unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
4369 gold_assert(object->local_has_got_offset(r_sym, got_type));
4370 got_offset = object->local_got_offset(r_sym, got_type);
4371 }
4372 have_got_offset = true;
4373 break;
4374
4375 default:
4376 break;
4377 }
4378
4379 r_howto = TilegxReloc::howto[r_type];
4380 switch (r_type)
4381 {
4382 case elfcpp::R_TILEGX_NONE:
4383 case elfcpp::R_TILEGX_GNU_VTINHERIT:
4384 case elfcpp::R_TILEGX_GNU_VTENTRY:
4385 break;
4386
4387 case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
4388 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
4389 case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
4390 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
4391 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
4392 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
4393 gold_assert(have_got_offset);
4394 symval.set_output_value(got_offset);
4395 psymval = &symval;
4396 always_apply_relocation = true;
4397 addend = 0;
4398
4399 // when under PIC mode, these relocations are deferred to rtld
4400 case elfcpp::R_TILEGX_IMM16_X0_HW0:
4401 case elfcpp::R_TILEGX_IMM16_X1_HW0:
4402 case elfcpp::R_TILEGX_IMM16_X0_HW1:
4403 case elfcpp::R_TILEGX_IMM16_X1_HW1:
4404 case elfcpp::R_TILEGX_IMM16_X0_HW2:
4405 case elfcpp::R_TILEGX_IMM16_X1_HW2:
4406 case elfcpp::R_TILEGX_IMM16_X0_HW3:
4407 case elfcpp::R_TILEGX_IMM16_X1_HW3:
4408 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
4409 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
4410 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
4411 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
4412 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
4413 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
4414 if (always_apply_relocation
4415 || !parameters->options().output_is_position_independent())
4416 TilegxReloc::imm_x_general(view, object, psymval, addend, r_howto);
4417 break;
4418
4419 case elfcpp::R_TILEGX_JUMPOFF_X1:
4420 case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
4421 gold_assert(gsym == NULL
4422 || gsym->has_plt_offset()
4423 || gsym->final_value_is_known()
4424 || (gsym->is_defined()
4425 && !gsym->is_from_dynobj()
4426 && !gsym->is_preemptible()));
4427 TilegxReloc::imm_x_pcrel_general(view, object, psymval, addend,
4428 address, r_howto);
4429 break;
4430
4431
4432 case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
4433 case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
4434 case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
4435 case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
4436 case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
4437 case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
4438 case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
4439 case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
4440 case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
4441 case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
4442 case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
4443 case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
4444 case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
4445 case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
4446 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
4447 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
4448 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
4449 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
4450 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
4451 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
4452 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
4453 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
4454 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
4455 case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
4456 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
4457 case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
4458 TilegxReloc::imm_x_pcrel_general(view, object, psymval, addend,
4459 address, r_howto);
4460 break;
4461
4462 case elfcpp::R_TILEGX_BROFF_X1:
4463 case elfcpp::R_TILEGX_DEST_IMM8_X1:
4464 TilegxReloc::imm_x_two_part_general(view, object, psymval,
4465 addend, address, r_type);
4466 break;
4467
4468
4469 // below are general relocation types, which can be
4470 // handled by target-independent handlers
4471 case elfcpp::R_TILEGX_64:
4472 TilegxReloc::abs64(view, object, psymval, addend);
4473 break;
4474
4475 case elfcpp::R_TILEGX_64_PCREL:
4476 TilegxReloc::pc_abs64(view, object, psymval, addend, address);
4477 break;
4478
4479 case elfcpp::R_TILEGX_32:
4480 TilegxReloc::abs32(view, object, psymval, addend);
4481 break;
4482
4483 case elfcpp::R_TILEGX_32_PCREL:
4484 TilegxReloc::pc_abs32(view, object, psymval, addend, address);
4485 break;
4486
4487 case elfcpp::R_TILEGX_16:
4488 TilegxReloc::abs16(view, object, psymval, addend);
4489 break;
4490
4491 case elfcpp::R_TILEGX_16_PCREL:
4492 TilegxReloc::pc_abs16(view, object, psymval, addend, address);
4493 break;
4494
4495 case elfcpp::R_TILEGX_8:
4496 Relocate_functions<size, big_endian>::rela8(view, object,
4497 psymval, addend);
4498 break;
4499
4500 case elfcpp::R_TILEGX_8_PCREL:
4501 Relocate_functions<size, big_endian>::pcrela8(view, object,
4502 psymval, addend, address);
4503 break;
4504
4505 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
4506 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
4507 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
4508 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
4509 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
4510 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
4511 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
4512 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
4513 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
4514 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
4515 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
4516 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
4517 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
4518 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
4519 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
4520 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
4521 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
4522 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
4523 case elfcpp::R_TILEGX_TLS_GD_CALL:
4524 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
4525 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
4526 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
4527 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
4528 case elfcpp::R_TILEGX_TLS_IE_LOAD:
4529 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
4530 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
4531 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
4532 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
4533 {
4534 const bool is_final = (gsym == NULL
4535 ? !parameters->options().shared()
4536 : gsym->final_value_is_known());
4537 tls::Tls_optimization opt_t =
4538 Target_tilegx<size, big_endian>::optimize_tls_reloc(is_final,
4539 r_type);
4540
4541 switch (r_type)
4542 {
4543
4544 case elfcpp::R_TILEGX_TLS_GD_CALL:
4545 {
4546 if (opt_t == tls::TLSOPT_NONE) {
4547 Symbol *tls_sym = relinfo->symtab->lookup("__tls_get_addr");
4548 symval.set_output_value(
4549 target->plt_address_for_global(tls_sym)
4550 + tls_sym->plt_offset());
4551 psymval = &symval;
4552 TilegxReloc::imm_x_pcrel_general(view, object, psymval,
4553 addend, address, r_howto);
4554 }
4555 else if (opt_t == tls::TLSOPT_TO_IE
4556 || opt_t == tls::TLSOPT_TO_LE)
4557 TilegxReloc::tls_relax(view, r_type, opt_t);
4558 }
4559 break;
4560
4561 // XX_TLS_GD is the same as normal X_GOT relocation
4562 // except allocating a got entry pair,
4563 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
4564 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
4565 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
4566 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
4567 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
4568 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
4569 if (opt_t == tls::TLSOPT_NONE) {
4570 got_type = GOT_TYPE_TLS_PAIR;
4571 have_got_offset = true;
4572 } else if (opt_t == tls::TLSOPT_TO_IE) {
4573 got_type = GOT_TYPE_TLS_OFFSET;
4574 have_got_offset = true;
4575 }
4576 goto do_update_value;
4577 // XX_TLS_IE is the same as normal X_GOT relocation
4578 // except allocating one additional runtime relocation
4579 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
4580 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
4581 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
4582 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
4583 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
4584 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
4585 if (opt_t == tls::TLSOPT_NONE) {
4586 got_type = GOT_TYPE_TLS_OFFSET;
4587 have_got_offset = true;
4588 }
4589 do_update_value:
4590 if (have_got_offset) {
4591 if (gsym != NULL) {
4592 gold_assert(gsym->has_got_offset(got_type));
4593 got_offset = gsym->got_offset(got_type);
4594 } else {
4595 unsigned int r_sym
4596 = elfcpp::elf_r_sym<size>(rela.get_r_info());
4597 gold_assert(object->local_has_got_offset(r_sym, got_type));
4598 got_offset = object->local_got_offset(r_sym, got_type);
4599 }
4600 }
4601
4602 if (opt_t == tls::TLSOPT_NONE
4603 || opt_t == tls::TLSOPT_TO_IE) {
4604 // for both GD/IE, these relocations
4605 // actually calculate got offset, so
4606 // there behavior are the same
4607 gold_assert(have_got_offset);
4608 symval.set_output_value(got_offset);
4609 psymval = &symval;
4610 addend = 0;
4611 TilegxReloc::imm_x_general(view, object, psymval,
4612 addend, r_howto);
4613 break;
4614 } // else if (opt_t == tls::TLSOPT_TO_LE)
4615 // both GD/IE are turned into LE, which
4616 // is absolute relocation.
4617 //
4618 // | go through
4619 // |
4620 // V
4621 // LE
4622 //
4623 // tp
4624 // |
4625 // V
4626 // t_var1 | t_var2 | t_var3 | ...
4627 // --------------------------------------------------
4628 //
4629 // so offset to tp should be negative, we get offset
4630 // from the following formular for LE
4631 //
4632 // t_var1_off = t_var1_sym_value - tls_section_start
4633 //
4634 case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
4635 case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
4636 case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
4637 case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
4638 case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
4639 case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
4640 {
4641 Output_segment *tls_segment = relinfo->layout->tls_segment();
4642 if (tls_segment == NULL) {
4643 gold_assert(parameters->errors()->error_count() > 0
4644 || issue_undefined_symbol_error(gsym));
4645 return false;
4646 }
4647
4648 typename elfcpp::Elf_types<size>::Elf_Addr value
4649 = psymval->value(relinfo->object, 0);
4650 symval.set_output_value(value);
4651 psymval = &symval;
4652 TilegxReloc::imm_x_general(view, object, psymval,
4653 addend, r_howto);
4654 }
4655 break;
4656
4657 // tls relaxation
4658 case elfcpp::R_TILEGX_TLS_IE_LOAD:
4659 case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
4660 case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
4661 case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
4662 case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
4663 case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
4664 case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
4665 case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
4666 case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
4667 TilegxReloc::tls_relax(view, r_type, opt_t);
4668 break;
4669
4670 default:
4671 gold_unreachable();
4672 }
4673 }
4674 break;
4675
4676 // below are outstanding relocs
4677 // should not existed in static linking stage
4678 case elfcpp::R_TILEGX_COPY:
4679 case elfcpp::R_TILEGX_GLOB_DAT:
4680 case elfcpp::R_TILEGX_JMP_SLOT:
4681 case elfcpp::R_TILEGX_RELATIVE:
4682 case elfcpp::R_TILEGX_TLS_TPOFF32:
4683 case elfcpp::R_TILEGX_TLS_TPOFF64:
4684 case elfcpp::R_TILEGX_TLS_DTPMOD32:
4685 case elfcpp::R_TILEGX_TLS_DTPMOD64:
4686 case elfcpp::R_TILEGX_TLS_DTPOFF32:
4687 case elfcpp::R_TILEGX_TLS_DTPOFF64:
4688 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
4689 _("unexpected reloc %u in object file"),
4690 r_type);
4691 break;
4692
4693 default:
4694 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
4695 _("unsupported reloc %u"),
4696 r_type);
4697 break;
4698 }
4699
4700 return true;
4701}
4702
4703// Relocate section data.
4704
4705template<int size, bool big_endian>
4706void
4707Target_tilegx<size, big_endian>::relocate_section(
4708 const Relocate_info<size, big_endian>* relinfo,
4709 unsigned int sh_type,
4710 const unsigned char* prelocs,
4711 size_t reloc_count,
4712 Output_section* output_section,
4713 bool needs_special_offset_handling,
4714 unsigned char* view,
4715 typename elfcpp::Elf_types<size>::Elf_Addr address,
4716 section_size_type view_size,
4717 const Reloc_symbol_changes* reloc_symbol_changes)
4718{
4719 typedef Target_tilegx<size, big_endian> Tilegx;
4720 typedef typename Target_tilegx<size, big_endian>::Relocate Tilegx_relocate;
4721
4722 gold_assert(sh_type == elfcpp::SHT_RELA);
4723
4724 gold::relocate_section<size, big_endian, Tilegx,
4725 elfcpp::SHT_RELA, Tilegx_relocate>(
4726 relinfo,
4727 this,
4728 prelocs,
4729 reloc_count,
4730 output_section,
4731 needs_special_offset_handling,
4732 view,
4733 address,
4734 view_size,
4735 reloc_symbol_changes);
4736}
4737
4738// Apply an incremental relocation. Incremental relocations always refer
4739// to global symbols.
4740
4741template<int size, bool big_endian>
4742void
4743Target_tilegx<size, big_endian>::apply_relocation(
4744 const Relocate_info<size, big_endian>* relinfo,
4745 typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
4746 unsigned int r_type,
4747 typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
4748 const Symbol* gsym,
4749 unsigned char* view,
4750 typename elfcpp::Elf_types<size>::Elf_Addr address,
4751 section_size_type view_size)
4752{
4753 gold::apply_relocation<size, big_endian, Target_tilegx<size, big_endian>,
4754 typename Target_tilegx<size, big_endian>::Relocate>(
4755 relinfo,
4756 this,
4757 r_offset,
4758 r_type,
4759 r_addend,
4760 gsym,
4761 view,
4762 address,
4763 view_size);
4764}
4765
4766// Return the size of a relocation while scanning during a relocatable
4767// link.
4768
4769template<int size, bool big_endian>
4770unsigned int
4771Target_tilegx<size,big_endian>::Relocatable_size_for_reloc::get_size_for_reloc(
4772 unsigned int, Relobj*)
4773{
4774 // We are always SHT_RELA, so we should never get here.
4775 gold_unreachable();
4776 return 0;
4777}
4778
4779// Scan the relocs during a relocatable link.
4780
4781template<int size, bool big_endian>
4782void
4783Target_tilegx<size, big_endian>::scan_relocatable_relocs(
4784 Symbol_table* symtab,
4785 Layout* layout,
4786 Sized_relobj_file<size, big_endian>* object,
4787 unsigned int data_shndx,
4788 unsigned int sh_type,
4789 const unsigned char* prelocs,
4790 size_t reloc_count,
4791 Output_section* output_section,
4792 bool needs_special_offset_handling,
4793 size_t local_symbol_count,
4794 const unsigned char* plocal_symbols,
4795 Relocatable_relocs* rr)
4796{
4797 gold_assert(sh_type == elfcpp::SHT_RELA);
4798
4799 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
4800 Relocatable_size_for_reloc> Scan_relocatable_relocs;
4801
4802 gold::scan_relocatable_relocs<size, big_endian, elfcpp::SHT_RELA,
4803 Scan_relocatable_relocs>(
4804 symtab,
4805 layout,
4806 object,
4807 data_shndx,
4808 prelocs,
4809 reloc_count,
4810 output_section,
4811 needs_special_offset_handling,
4812 local_symbol_count,
4813 plocal_symbols,
4814 rr);
4815}
4816
4817// Relocate a section during a relocatable link.
4818
4819template<int size, bool big_endian>
4820void
4821Target_tilegx<size, big_endian>::relocate_relocs(
4822 const Relocate_info<size, big_endian>* relinfo,
4823 unsigned int sh_type,
4824 const unsigned char* prelocs,
4825 size_t reloc_count,
4826 Output_section* output_section,
4827 off_t offset_in_output_section,
4828 const Relocatable_relocs* rr,
4829 unsigned char* view,
4830 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
4831 section_size_type view_size,
4832 unsigned char* reloc_view,
4833 section_size_type reloc_view_size)
4834{
4835 gold_assert(sh_type == elfcpp::SHT_RELA);
4836
4837 gold::relocate_relocs<size, big_endian, elfcpp::SHT_RELA>(
4838 relinfo,
4839 prelocs,
4840 reloc_count,
4841 output_section,
4842 offset_in_output_section,
4843 rr,
4844 view,
4845 view_address,
4846 view_size,
4847 reloc_view,
4848 reloc_view_size);
4849}
4850
4851// Return the value to use for a dynamic which requires special
4852// treatment. This is how we support equality comparisons of function
4853// pointers across shared library boundaries, as described in the
4854// processor specific ABI supplement.
4855
4856template<int size, bool big_endian>
4857uint64_t
4858Target_tilegx<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
4859{
4860 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
4861 return this->plt_address_for_global(gsym) + gsym->plt_offset();
4862}
4863
4864// Return the value to use for the base of a DW_EH_PE_datarel offset
4865// in an FDE. Solaris and SVR4 use DW_EH_PE_datarel because their
4866// assembler can not write out the difference between two labels in
4867// different sections, so instead of using a pc-relative value they
4868// use an offset from the GOT.
4869
4870template<int size, bool big_endian>
4871uint64_t
4872Target_tilegx<size, big_endian>::do_ehframe_datarel_base() const
4873{
4874 gold_assert(this->global_offset_table_ != NULL);
4875 Symbol* sym = this->global_offset_table_;
4876 Sized_symbol<size>* ssym = static_cast<Sized_symbol<size>*>(sym);
4877 return ssym->value();
4878}
4879
4880// The selector for tilegx object files.
4881
4882template<int size, bool big_endian>
4883class Target_selector_tilegx : public Target_selector
4884{
4885public:
4886 Target_selector_tilegx()
4887 : Target_selector(elfcpp::EM_TILEGX, size, big_endian,
4888 (size == 64
4889 ? (big_endian ? "elf64-tilegx-be" : "elf64-tilegx-le")
4890 : (big_endian ? "elf32-tilegx-be"
4891 : "elf32-tilegx-le")),
4892 (size == 64
4893 ? (big_endian ? "elf64tilegx_be" : "elf64tilegx")
4894 : (big_endian ? "elf32tilegx_be" : "elf32tilegx")))
4895 { }
4896
4897 Target*
4898 do_instantiate_target()
4899 { return new Target_tilegx<size, big_endian>(); }
4900
4901};
4902
4903Target_selector_tilegx<64, false> target_selector_tilegx64_le;
4904Target_selector_tilegx<32, false> target_selector_tilegx32_le;
4905Target_selector_tilegx<64, true> target_selector_tilegx64_be;
4906Target_selector_tilegx<32, true> target_selector_tilegx32_be;
4907} // End anonymous namespace.
This page took 0.193424 seconds and 4 git commands to generate.