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