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