PR 5755
[deliverable/binutils-gdb.git] / gold / x86_64.cc
CommitLineData
2e30d253
ILT
1// x86_64.cc -- x86_64 target support for gold.
2
3// Copyright 2006, 2007, Free Software Foundation, Inc.
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public License
10// as published by the Free Software Foundation; either version 2, or
11// (at your option) any later version.
12
13// In addition to the permissions in the GNU Library General Public
14// License, the Free Software Foundation gives you unlimited
15// permission to link the compiled version of this file into
16// combinations with other programs, and to distribute those
17// combinations without any restriction coming from the use of this
18// file. (The Library Public License restrictions do apply in other
19// respects; for example, they cover modification of the file, and
20/// distribution when not linked into a combined executable.)
21
22// This program is distributed in the hope that it will be useful, but
23// WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25// Library General Public License for more details.
26
27// You should have received a copy of the GNU Library General Public
28// License along with this program; if not, write to the Free Software
29// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
30// 02110-1301, USA.
31
32#include "gold.h"
33
34#include <cstring>
35
36#include "elfcpp.h"
37#include "parameters.h"
38#include "reloc.h"
39#include "x86_64.h"
40#include "object.h"
41#include "symtab.h"
42#include "layout.h"
43#include "output.h"
44#include "target.h"
45#include "target-reloc.h"
46#include "target-select.h"
e041f13d 47#include "tls.h"
2e30d253
ILT
48
49namespace
50{
51
52using namespace gold;
53
54class Output_data_plt_x86_64;
55
56// The x86_64 target class.
d61c17ea
ILT
57// See the ABI at
58// http://www.x86-64.org/documentation/abi.pdf
59// TLS info comes from
60// http://people.redhat.com/drepper/tls.pdf
0ffd9845 61// http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt
2e30d253
ILT
62
63class Target_x86_64 : public Sized_target<64, false>
64{
65 public:
e822f2b1
ILT
66 // In the x86_64 ABI (p 68), it says "The AMD64 ABI architectures
67 // uses only Elf64_Rela relocation entries with explicit addends."
2e30d253
ILT
68 typedef Output_data_reloc<elfcpp::SHT_RELA, true, 64, false> Reloc_section;
69
70 Target_x86_64()
71 : Sized_target<64, false>(&x86_64_info),
0ffd9845 72 got_(NULL), plt_(NULL), got_plt_(NULL), rela_dyn_(NULL),
31d60480 73 copy_relocs_(NULL), dynbss_(NULL), got_mod_index_offset_(-1U)
2e30d253
ILT
74 { }
75
76 // Scan the relocations to look for symbol adjustments.
77 void
78 scan_relocs(const General_options& options,
79 Symbol_table* symtab,
80 Layout* layout,
81 Sized_relobj<64, false>* object,
82 unsigned int data_shndx,
83 unsigned int sh_type,
84 const unsigned char* prelocs,
85 size_t reloc_count,
730cdc88
ILT
86 Output_section* output_section,
87 bool needs_special_offset_handling,
2e30d253 88 size_t local_symbol_count,
730cdc88 89 const unsigned char* plocal_symbols);
2e30d253
ILT
90
91 // Finalize the sections.
92 void
93 do_finalize_sections(Layout*);
94
4fb6c25d
ILT
95 // Return the value to use for a dynamic which requires special
96 // treatment.
97 uint64_t
98 do_dynsym_value(const Symbol*) const;
99
2e30d253
ILT
100 // Relocate a section.
101 void
102 relocate_section(const Relocate_info<64, false>*,
103 unsigned int sh_type,
104 const unsigned char* prelocs,
105 size_t reloc_count,
730cdc88
ILT
106 Output_section* output_section,
107 bool needs_special_offset_handling,
2e30d253
ILT
108 unsigned char* view,
109 elfcpp::Elf_types<64>::Elf_Addr view_address,
fe8718a4 110 section_size_type view_size);
2e30d253 111
6a74a719
ILT
112 // Scan the relocs during a relocatable link.
113 void
114 scan_relocatable_relocs(const General_options& options,
115 Symbol_table* symtab,
116 Layout* layout,
117 Sized_relobj<64, false>* object,
118 unsigned int data_shndx,
119 unsigned int sh_type,
120 const unsigned char* prelocs,
121 size_t reloc_count,
122 Output_section* output_section,
123 bool needs_special_offset_handling,
124 size_t local_symbol_count,
125 const unsigned char* plocal_symbols,
126 Relocatable_relocs*);
127
128 // Relocate a section during a relocatable link.
129 void
130 relocate_for_relocatable(const Relocate_info<64, false>*,
131 unsigned int sh_type,
132 const unsigned char* prelocs,
133 size_t reloc_count,
134 Output_section* output_section,
135 off_t offset_in_output_section,
136 const Relocatable_relocs*,
137 unsigned char* view,
138 elfcpp::Elf_types<64>::Elf_Addr view_address,
139 section_size_type view_size,
140 unsigned char* reloc_view,
141 section_size_type reloc_view_size);
142
2e30d253
ILT
143 // Return a string used to fill a code section with nops.
144 std::string
fe8718a4 145 do_code_fill(section_size_type length);
2e30d253 146
9a2d6984
ILT
147 // Return whether SYM is defined by the ABI.
148 bool
149 do_is_defined_by_abi(Symbol* sym) const
150 { return strcmp(sym->name(), "__tls_get_addr") == 0; }
151
96f2030e 152 // Return the size of the GOT section.
fe8718a4 153 section_size_type
96f2030e
ILT
154 got_size()
155 {
156 gold_assert(this->got_ != NULL);
157 return this->got_->data_size();
158 }
159
2e30d253
ILT
160 private:
161 // The class which scans relocations.
162 struct Scan
163 {
164 inline void
165 local(const General_options& options, Symbol_table* symtab,
166 Layout* layout, Target_x86_64* target,
167 Sized_relobj<64, false>* object,
168 unsigned int data_shndx,
07f397ab 169 Output_section* output_section,
2e30d253
ILT
170 const elfcpp::Rela<64, false>& reloc, unsigned int r_type,
171 const elfcpp::Sym<64, false>& lsym);
172
173 inline void
174 global(const General_options& options, Symbol_table* symtab,
175 Layout* layout, Target_x86_64* target,
176 Sized_relobj<64, false>* object,
177 unsigned int data_shndx,
07f397ab 178 Output_section* output_section,
2e30d253
ILT
179 const elfcpp::Rela<64, false>& reloc, unsigned int r_type,
180 Symbol* gsym);
e041f13d
ILT
181
182 static void
183 unsupported_reloc_local(Sized_relobj<64, false>*, unsigned int r_type);
184
185 static void
186 unsupported_reloc_global(Sized_relobj<64, false>*, unsigned int r_type,
187 Symbol*);
2e30d253
ILT
188 };
189
190 // The class which implements relocation.
191 class Relocate
192 {
193 public:
194 Relocate()
195 : skip_call_tls_get_addr_(false)
196 { }
197
198 ~Relocate()
199 {
200 if (this->skip_call_tls_get_addr_)
201 {
202 // FIXME: This needs to specify the location somehow.
a0c4fb0a 203 gold_error(_("missing expected TLS relocation"));
2e30d253
ILT
204 }
205 }
206
207 // Do a relocation. Return false if the caller should not issue
208 // any warnings about this relocation.
209 inline bool
210 relocate(const Relocate_info<64, false>*, Target_x86_64*, size_t relnum,
211 const elfcpp::Rela<64, false>&,
212 unsigned int r_type, const Sized_symbol<64>*,
213 const Symbol_value<64>*,
214 unsigned char*, elfcpp::Elf_types<64>::Elf_Addr,
fe8718a4 215 section_size_type);
2e30d253
ILT
216
217 private:
218 // Do a TLS relocation.
219 inline void
7bf1f802
ILT
220 relocate_tls(const Relocate_info<64, false>*, Target_x86_64*,
221 size_t relnum, const elfcpp::Rela<64, false>&,
2e30d253
ILT
222 unsigned int r_type, const Sized_symbol<64>*,
223 const Symbol_value<64>*,
fe8718a4
ILT
224 unsigned char*, elfcpp::Elf_types<64>::Elf_Addr,
225 section_size_type);
2e30d253 226
7bf1f802
ILT
227 // Do a TLS General-Dynamic to Local-Exec transition.
228 inline void
229 tls_gd_to_ie(const Relocate_info<64, false>*, size_t relnum,
230 Output_segment* tls_segment,
231 const elfcpp::Rela<64, false>&, unsigned int r_type,
232 elfcpp::Elf_types<64>::Elf_Addr value,
233 unsigned char* view,
fe8718a4 234 section_size_type view_size);
7bf1f802 235
56622147
ILT
236 // Do a TLS General-Dynamic to Local-Exec transition.
237 inline void
238 tls_gd_to_le(const Relocate_info<64, false>*, size_t relnum,
2e30d253
ILT
239 Output_segment* tls_segment,
240 const elfcpp::Rela<64, false>&, unsigned int r_type,
241 elfcpp::Elf_types<64>::Elf_Addr value,
242 unsigned char* view,
fe8718a4 243 section_size_type view_size);
2e30d253 244
56622147 245 // Do a TLS Local-Dynamic to Local-Exec transition.
2e30d253 246 inline void
56622147 247 tls_ld_to_le(const Relocate_info<64, false>*, size_t relnum,
2e30d253
ILT
248 Output_segment* tls_segment,
249 const elfcpp::Rela<64, false>&, unsigned int r_type,
250 elfcpp::Elf_types<64>::Elf_Addr value,
251 unsigned char* view,
fe8718a4 252 section_size_type view_size);
2e30d253 253
56622147
ILT
254 // Do a TLS Initial-Exec to Local-Exec transition.
255 static inline void
256 tls_ie_to_le(const Relocate_info<64, false>*, size_t relnum,
72ec2876
ILT
257 Output_segment* tls_segment,
258 const elfcpp::Rela<64, false>&, unsigned int r_type,
259 elfcpp::Elf_types<64>::Elf_Addr value,
260 unsigned char* view,
fe8718a4 261 section_size_type view_size);
2e30d253
ILT
262
263 // This is set if we should skip the next reloc, which should be a
264 // PLT32 reloc against ___tls_get_addr.
265 bool skip_call_tls_get_addr_;
266 };
267
6a74a719
ILT
268 // A class which returns the size required for a relocation type,
269 // used while scanning relocs during a relocatable link.
270 class Relocatable_size_for_reloc
271 {
272 public:
273 unsigned int
274 get_size_for_reloc(unsigned int, Relobj*);
275 };
276
2e30d253
ILT
277 // Adjust TLS relocation type based on the options and whether this
278 // is a local symbol.
e041f13d 279 static tls::Tls_optimization
2e30d253
ILT
280 optimize_tls_reloc(bool is_final, int r_type);
281
282 // Get the GOT section, creating it if necessary.
283 Output_data_got<64, false>*
284 got_section(Symbol_table*, Layout*);
285
96f2030e
ILT
286 // Get the GOT PLT section.
287 Output_data_space*
288 got_plt_section() const
289 {
290 gold_assert(this->got_plt_ != NULL);
291 return this->got_plt_;
292 }
293
2e30d253
ILT
294 // Create a PLT entry for a global symbol.
295 void
296 make_plt_entry(Symbol_table*, Layout*, Symbol*);
297
31d60480
ILT
298 // Create a GOT entry for the TLS module index.
299 unsigned int
300 got_mod_index_entry(Symbol_table* symtab, Layout* layout,
301 Sized_relobj<64, false>* object);
302
2e30d253
ILT
303 // Get the PLT section.
304 Output_data_plt_x86_64*
305 plt_section() const
306 {
307 gold_assert(this->plt_ != NULL);
308 return this->plt_;
309 }
310
311 // Get the dynamic reloc section, creating it if necessary.
312 Reloc_section*
0ffd9845 313 rela_dyn_section(Layout*);
2e30d253 314
d61c6bd4
ILT
315 // Return true if the symbol may need a COPY relocation.
316 // References from an executable object to non-function symbols
317 // defined in a dynamic object may need a COPY relocation.
318 bool
319 may_need_copy_reloc(Symbol* gsym)
320 {
321 return (!parameters->output_is_shared()
322 && gsym->is_from_dynobj()
323 && gsym->type() != elfcpp::STT_FUNC);
324 }
325
2e30d253
ILT
326 // Copy a relocation against a global symbol.
327 void
328 copy_reloc(const General_options*, Symbol_table*, Layout*,
329 Sized_relobj<64, false>*, unsigned int,
4f4c5f80 330 Output_section*, Symbol*, const elfcpp::Rela<64, false>&);
2e30d253
ILT
331
332 // Information about this specific target which we pass to the
333 // general Target structure.
334 static const Target::Target_info x86_64_info;
335
336 // The GOT section.
337 Output_data_got<64, false>* got_;
338 // The PLT section.
339 Output_data_plt_x86_64* plt_;
340 // The GOT PLT section.
341 Output_data_space* got_plt_;
342 // The dynamic reloc section.
0ffd9845 343 Reloc_section* rela_dyn_;
2e30d253
ILT
344 // Relocs saved to avoid a COPY reloc.
345 Copy_relocs<64, false>* copy_relocs_;
346 // Space for variables copied with a COPY reloc.
347 Output_data_space* dynbss_;
31d60480
ILT
348 // Offset of the GOT entry for the TLS module index;
349 unsigned int got_mod_index_offset_;
2e30d253
ILT
350};
351
352const Target::Target_info Target_x86_64::x86_64_info =
353{
354 64, // size
355 false, // is_big_endian
356 elfcpp::EM_X86_64, // machine_code
357 false, // has_make_symbol
358 false, // has_resolve
359 true, // has_code_fill
35cdfc9a 360 true, // is_default_stack_executable
2e30d253 361 "/lib/ld64.so.1", // program interpreter
0c5e9c22 362 0x400000, // default_text_segment_address
2e30d253
ILT
363 0x1000, // abi_pagesize
364 0x1000 // common_pagesize
365};
366
367// Get the GOT section, creating it if necessary.
368
369Output_data_got<64, false>*
370Target_x86_64::got_section(Symbol_table* symtab, Layout* layout)
371{
372 if (this->got_ == NULL)
373 {
374 gold_assert(symtab != NULL && layout != NULL);
375
376 this->got_ = new Output_data_got<64, false>();
377
378 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
379 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
380 this->got_);
381
382 // The old GNU linker creates a .got.plt section. We just
383 // create another set of data in the .got section. Note that we
384 // always create a PLT if we create a GOT, although the PLT
385 // might be empty.
2e30d253
ILT
386 this->got_plt_ = new Output_data_space(8);
387 layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
388 elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
389 this->got_plt_);
390
391 // The first three entries are reserved.
27bc2bce 392 this->got_plt_->set_current_data_size(3 * 8);
2e30d253
ILT
393
394 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
9b07f471 395 symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
2e30d253
ILT
396 this->got_plt_,
397 0, 0, elfcpp::STT_OBJECT,
398 elfcpp::STB_LOCAL,
399 elfcpp::STV_HIDDEN, 0,
400 false, false);
401 }
402
403 return this->got_;
404}
405
406// Get the dynamic reloc section, creating it if necessary.
407
408Target_x86_64::Reloc_section*
0ffd9845 409Target_x86_64::rela_dyn_section(Layout* layout)
2e30d253 410{
0ffd9845 411 if (this->rela_dyn_ == NULL)
2e30d253
ILT
412 {
413 gold_assert(layout != NULL);
0ffd9845 414 this->rela_dyn_ = new Reloc_section();
2e30d253 415 layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
0ffd9845 416 elfcpp::SHF_ALLOC, this->rela_dyn_);
2e30d253 417 }
0ffd9845 418 return this->rela_dyn_;
2e30d253
ILT
419}
420
421// A class to handle the PLT data.
422
423class Output_data_plt_x86_64 : public Output_section_data
424{
425 public:
426 typedef Output_data_reloc<elfcpp::SHT_RELA, true, 64, false> Reloc_section;
427
428 Output_data_plt_x86_64(Layout*, Output_data_space*);
429
430 // Add an entry to the PLT.
431 void
432 add_entry(Symbol* gsym);
433
434 // Return the .rel.plt section data.
435 const Reloc_section*
436 rel_plt() const
437 { return this->rel_; }
438
439 protected:
440 void
441 do_adjust_output_section(Output_section* os);
442
443 private:
444 // The size of an entry in the PLT.
445 static const int plt_entry_size = 16;
446
447 // The first entry in the PLT.
448 // From the AMD64 ABI: "Unlike Intel386 ABI, this ABI uses the same
449 // procedure linkage table for both programs and shared objects."
450 static unsigned char first_plt_entry[plt_entry_size];
451
452 // Other entries in the PLT for an executable.
453 static unsigned char plt_entry[plt_entry_size];
454
455 // Set the final size.
456 void
27bc2bce 457 set_final_data_size()
2e30d253
ILT
458 { this->set_data_size((this->count_ + 1) * plt_entry_size); }
459
460 // Write out the PLT data.
461 void
462 do_write(Output_file*);
463
464 // The reloc section.
465 Reloc_section* rel_;
466 // The .got.plt section.
467 Output_data_space* got_plt_;
468 // The number of PLT entries.
469 unsigned int count_;
470};
471
472// Create the PLT section. The ordinary .got section is an argument,
473// since we need to refer to the start. We also create our own .got
474// section just for PLT entries.
475
476Output_data_plt_x86_64::Output_data_plt_x86_64(Layout* layout,
477 Output_data_space* got_plt)
2e30d253
ILT
478 : Output_section_data(8), got_plt_(got_plt), count_(0)
479{
480 this->rel_ = new Reloc_section();
481 layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
482 elfcpp::SHF_ALLOC, this->rel_);
483}
484
485void
486Output_data_plt_x86_64::do_adjust_output_section(Output_section* os)
487{
488 // UnixWare sets the entsize of .plt to 4, and so does the old GNU
489 // linker, and so do we.
490 os->set_entsize(4);
491}
492
493// Add an entry to the PLT.
494
495void
496Output_data_plt_x86_64::add_entry(Symbol* gsym)
497{
498 gold_assert(!gsym->has_plt_offset());
499
500 // Note that when setting the PLT offset we skip the initial
501 // reserved PLT entry.
502 gsym->set_plt_offset((this->count_ + 1) * plt_entry_size);
503
504 ++this->count_;
505
fe8718a4 506 section_offset_type got_offset = this->got_plt_->current_data_size();
2e30d253
ILT
507
508 // Every PLT entry needs a GOT entry which points back to the PLT
509 // entry (this will be changed by the dynamic linker, normally
510 // lazily when the function is called).
27bc2bce 511 this->got_plt_->set_current_data_size(got_offset + 8);
2e30d253
ILT
512
513 // Every PLT entry needs a reloc.
514 gsym->set_needs_dynsym_entry();
515 this->rel_->add_global(gsym, elfcpp::R_X86_64_JUMP_SLOT, this->got_plt_,
516 got_offset, 0);
517
518 // Note that we don't need to save the symbol. The contents of the
519 // PLT are independent of which symbols are used. The symbols only
520 // appear in the relocations.
521}
522
523// The first entry in the PLT for an executable.
524
525unsigned char Output_data_plt_x86_64::first_plt_entry[plt_entry_size] =
526{
527 // From AMD64 ABI Draft 0.98, page 76
528 0xff, 0x35, // pushq contents of memory address
2e30d253 529 0, 0, 0, 0, // replaced with address of .got + 8
78d911fd
ILT
530 0xff, 0x25, // jmp indirect
531 0, 0, 0, 0, // replaced with address of .got + 16
2e30d253
ILT
532 0x90, 0x90, 0x90, 0x90 // noop (x4)
533};
534
535// Subsequent entries in the PLT for an executable.
536
537unsigned char Output_data_plt_x86_64::plt_entry[plt_entry_size] =
538{
539 // From AMD64 ABI Draft 0.98, page 76
540 0xff, 0x25, // jmpq indirect
541 0, 0, 0, 0, // replaced with address of symbol in .got
542 0x68, // pushq immediate
543 0, 0, 0, 0, // replaced with offset into relocation table
544 0xe9, // jmpq relative
545 0, 0, 0, 0 // replaced with offset to start of .plt
546};
547
548// Write out the PLT. This uses the hand-coded instructions above,
549// and adjusts them as needed. This is specified by the AMD64 ABI.
550
551void
552Output_data_plt_x86_64::do_write(Output_file* of)
553{
554 const off_t offset = this->offset();
fe8718a4
ILT
555 const section_size_type oview_size =
556 convert_to_section_size_type(this->data_size());
2e30d253
ILT
557 unsigned char* const oview = of->get_output_view(offset, oview_size);
558
559 const off_t got_file_offset = this->got_plt_->offset();
fe8718a4
ILT
560 const section_size_type got_size =
561 convert_to_section_size_type(this->got_plt_->data_size());
2e30d253
ILT
562 unsigned char* const got_view = of->get_output_view(got_file_offset,
563 got_size);
564
565 unsigned char* pov = oview;
566
567 elfcpp::Elf_types<32>::Elf_Addr plt_address = this->address();
568 elfcpp::Elf_types<32>::Elf_Addr got_address = this->got_plt_->address();
569
570 memcpy(pov, first_plt_entry, plt_entry_size);
78d911fd
ILT
571 // We do a jmp relative to the PC at the end of this instruction.
572 elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, got_address + 8
573 - (plt_address + 6));
574 elfcpp::Swap<32, false>::writeval(pov + 8, got_address + 16
575 - (plt_address + 12));
2e30d253
ILT
576 pov += plt_entry_size;
577
578 unsigned char* got_pov = got_view;
579
580 memset(got_pov, 0, 24);
581 got_pov += 24;
582
583 unsigned int plt_offset = plt_entry_size;
584 unsigned int got_offset = 24;
585 const unsigned int count = this->count_;
586 for (unsigned int plt_index = 0;
587 plt_index < count;
588 ++plt_index,
589 pov += plt_entry_size,
590 got_pov += 8,
591 plt_offset += plt_entry_size,
592 got_offset += 8)
593 {
594 // Set and adjust the PLT entry itself.
595 memcpy(pov, plt_entry, plt_entry_size);
78d911fd
ILT
596 elfcpp::Swap_unaligned<32, false>::writeval(pov + 2,
597 (got_address + got_offset
598 - (plt_address + plt_offset
599 + 6)));
2e30d253
ILT
600
601 elfcpp::Swap_unaligned<32, false>::writeval(pov + 7, plt_index);
602 elfcpp::Swap<32, false>::writeval(pov + 12,
603 - (plt_offset + plt_entry_size));
604
605 // Set the entry in the GOT.
606 elfcpp::Swap<64, false>::writeval(got_pov, plt_address + plt_offset + 6);
607 }
608
fe8718a4
ILT
609 gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
610 gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
2e30d253
ILT
611
612 of->write_output_view(offset, oview_size, oview);
613 of->write_output_view(got_file_offset, got_size, got_view);
614}
615
616// Create a PLT entry for a global symbol.
617
618void
619Target_x86_64::make_plt_entry(Symbol_table* symtab, Layout* layout,
620 Symbol* gsym)
621{
622 if (gsym->has_plt_offset())
623 return;
624
625 if (this->plt_ == NULL)
626 {
627 // Create the GOT sections first.
628 this->got_section(symtab, layout);
629
630 this->plt_ = new Output_data_plt_x86_64(layout, this->got_plt_);
631 layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
632 (elfcpp::SHF_ALLOC
633 | elfcpp::SHF_EXECINSTR),
634 this->plt_);
635 }
636
637 this->plt_->add_entry(gsym);
638}
639
31d60480
ILT
640// Create a GOT entry for the TLS module index.
641
642unsigned int
643Target_x86_64::got_mod_index_entry(Symbol_table* symtab, Layout* layout,
644 Sized_relobj<64, false>* object)
645{
646 if (this->got_mod_index_offset_ == -1U)
647 {
648 gold_assert(symtab != NULL && layout != NULL && object != NULL);
649 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
650 Output_data_got<64, false>* got = this->got_section(symtab, layout);
651 unsigned int got_offset = got->add_constant(0);
652 rela_dyn->add_local(object, 0, elfcpp::R_X86_64_DTPMOD64, got,
653 got_offset, 0);
654 got->add_constant(0);
655 this->got_mod_index_offset_ = got_offset;
656 }
657 return this->got_mod_index_offset_;
658}
659
2e30d253
ILT
660// Handle a relocation against a non-function symbol defined in a
661// dynamic object. The traditional way to handle this is to generate
662// a COPY relocation to copy the variable at runtime from the shared
663// object into the executable's data segment. However, this is
664// undesirable in general, as if the size of the object changes in the
665// dynamic object, the executable will no longer work correctly. If
666// this relocation is in a writable section, then we can create a
667// dynamic reloc and the dynamic linker will resolve it to the correct
668// address at runtime. However, we do not want do that if the
669// relocation is in a read-only section, as it would prevent the
670// readonly segment from being shared. And if we have to eventually
671// generate a COPY reloc, then any dynamic relocations will be
672// useless. So this means that if this is a writable section, we need
673// to save the relocation until we see whether we have to create a
674// COPY relocation for this symbol for any other relocation.
675
676void
677Target_x86_64::copy_reloc(const General_options* options,
d61c17ea
ILT
678 Symbol_table* symtab,
679 Layout* layout,
680 Sized_relobj<64, false>* object,
4f4c5f80
ILT
681 unsigned int data_shndx,
682 Output_section* output_section,
683 Symbol* gsym,
72ec2876 684 const elfcpp::Rela<64, false>& rela)
2e30d253
ILT
685{
686 Sized_symbol<64>* ssym;
687 ssym = symtab->get_sized_symbol SELECT_SIZE_NAME(64) (gsym
688 SELECT_SIZE(64));
689
690 if (!Copy_relocs<64, false>::need_copy_reloc(options, object,
691 data_shndx, ssym))
692 {
693 // So far we do not need a COPY reloc. Save this relocation.
694 // If it turns out that we never need a COPY reloc for this
695 // symbol, then we will emit the relocation.
696 if (this->copy_relocs_ == NULL)
697 this->copy_relocs_ = new Copy_relocs<64, false>();
4f4c5f80 698 this->copy_relocs_->save(ssym, object, data_shndx, output_section, rela);
2e30d253
ILT
699 }
700 else
701 {
702 // Allocate space for this symbol in the .bss section.
703
704 elfcpp::Elf_types<64>::Elf_WXword symsize = ssym->symsize();
705
706 // There is no defined way to determine the required alignment
707 // of the symbol. We pick the alignment based on the size. We
708 // set an arbitrary maximum of 256.
709 unsigned int align;
710 for (align = 1; align < 512; align <<= 1)
711 if ((symsize & align) != 0)
712 break;
713
714 if (this->dynbss_ == NULL)
715 {
716 this->dynbss_ = new Output_data_space(align);
717 layout->add_output_section_data(".bss",
718 elfcpp::SHT_NOBITS,
719 (elfcpp::SHF_ALLOC
720 | elfcpp::SHF_WRITE),
721 this->dynbss_);
722 }
723
724 Output_data_space* dynbss = this->dynbss_;
725
726 if (align > dynbss->addralign())
727 dynbss->set_space_alignment(align);
728
fe8718a4 729 section_size_type dynbss_size = dynbss->current_data_size();
2e30d253 730 dynbss_size = align_address(dynbss_size, align);
fe8718a4 731 section_size_type offset = dynbss_size;
27bc2bce 732 dynbss->set_current_data_size(dynbss_size + symsize);
2e30d253 733
9b07f471 734 symtab->define_with_copy_reloc(ssym, dynbss, offset);
2e30d253
ILT
735
736 // Add the COPY reloc.
0ffd9845
ILT
737 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
738 rela_dyn->add_global(ssym, elfcpp::R_X86_64_COPY, dynbss, offset, 0);
2e30d253
ILT
739 }
740}
741
742
743// Optimize the TLS relocation type based on what we know about the
744// symbol. IS_FINAL is true if the final address of this symbol is
745// known at link time.
746
e041f13d 747tls::Tls_optimization
2e30d253
ILT
748Target_x86_64::optimize_tls_reloc(bool is_final, int r_type)
749{
2e30d253
ILT
750 // If we are generating a shared library, then we can't do anything
751 // in the linker.
752 if (parameters->output_is_shared())
e041f13d 753 return tls::TLSOPT_NONE;
2e30d253
ILT
754
755 switch (r_type)
756 {
757 case elfcpp::R_X86_64_TLSGD:
e041f13d
ILT
758 case elfcpp::R_X86_64_GOTPC32_TLSDESC:
759 case elfcpp::R_X86_64_TLSDESC_CALL:
760 // These are General-Dynamic which permits fully general TLS
2e30d253
ILT
761 // access. Since we know that we are generating an executable,
762 // we can convert this to Initial-Exec. If we also know that
763 // this is a local symbol, we can further switch to Local-Exec.
764 if (is_final)
e041f13d
ILT
765 return tls::TLSOPT_TO_LE;
766 return tls::TLSOPT_TO_IE;
2e30d253 767
d61c17ea 768 case elfcpp::R_X86_64_TLSLD:
2e30d253
ILT
769 // This is Local-Dynamic, which refers to a local symbol in the
770 // dynamic TLS block. Since we know that we generating an
771 // executable, we can switch to Local-Exec.
e041f13d 772 return tls::TLSOPT_TO_LE;
2e30d253 773
0ffd9845 774 case elfcpp::R_X86_64_DTPOFF32:
0ffd9845
ILT
775 case elfcpp::R_X86_64_DTPOFF64:
776 // Another Local-Dynamic reloc.
e041f13d 777 return tls::TLSOPT_TO_LE;
0ffd9845 778
d61c17ea 779 case elfcpp::R_X86_64_GOTTPOFF:
2e30d253
ILT
780 // These are Initial-Exec relocs which get the thread offset
781 // from the GOT. If we know that we are linking against the
782 // local symbol, we can switch to Local-Exec, which links the
783 // thread offset into the instruction.
784 if (is_final)
e041f13d
ILT
785 return tls::TLSOPT_TO_LE;
786 return tls::TLSOPT_NONE;
2e30d253 787
d61c17ea 788 case elfcpp::R_X86_64_TPOFF32:
2e30d253
ILT
789 // When we already have Local-Exec, there is nothing further we
790 // can do.
e041f13d 791 return tls::TLSOPT_NONE;
2e30d253
ILT
792
793 default:
794 gold_unreachable();
795 }
2e30d253
ILT
796}
797
e041f13d
ILT
798// Report an unsupported relocation against a local symbol.
799
800void
801Target_x86_64::Scan::unsupported_reloc_local(Sized_relobj<64, false>* object,
802 unsigned int r_type)
803{
75f2446e
ILT
804 gold_error(_("%s: unsupported reloc %u against local symbol"),
805 object->name().c_str(), r_type);
e041f13d
ILT
806}
807
2e30d253
ILT
808// Scan a relocation for a local symbol.
809
810inline void
811Target_x86_64::Scan::local(const General_options&,
d61c17ea
ILT
812 Symbol_table* symtab,
813 Layout* layout,
814 Target_x86_64* target,
815 Sized_relobj<64, false>* object,
0ffd9845 816 unsigned int data_shndx,
4f4c5f80 817 Output_section* output_section,
0ffd9845 818 const elfcpp::Rela<64, false>& reloc,
d61c17ea 819 unsigned int r_type,
7bf1f802 820 const elfcpp::Sym<64, false>& lsym)
2e30d253
ILT
821{
822 switch (r_type)
823 {
824 case elfcpp::R_X86_64_NONE:
e822f2b1
ILT
825 case elfcpp::R_386_GNU_VTINHERIT:
826 case elfcpp::R_386_GNU_VTENTRY:
2e30d253
ILT
827 break;
828
829 case elfcpp::R_X86_64_64:
d61c6bd4
ILT
830 // If building a shared library (or a position-independent
831 // executable), we need to create a dynamic relocation for
832 // this location. The relocation applied at link time will
833 // apply the link-time value, so we flag the location with
834 // an R_386_RELATIVE relocation so the dynamic loader can
835 // relocate it easily.
836 if (parameters->output_is_position_independent())
837 {
e8c846c3 838 unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
d61c6bd4 839 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
e8c846c3
ILT
840 rela_dyn->add_local_relative(object, r_sym,
841 elfcpp::R_X86_64_RELATIVE,
842 output_section, data_shndx,
843 reloc.get_r_offset(),
844 reloc.get_r_addend());
d61c6bd4
ILT
845 }
846 break;
847
2e30d253
ILT
848 case elfcpp::R_X86_64_32:
849 case elfcpp::R_X86_64_32S:
850 case elfcpp::R_X86_64_16:
851 case elfcpp::R_X86_64_8:
96f2030e
ILT
852 // If building a shared library (or a position-independent
853 // executable), we need to create a dynamic relocation for
854 // this location. The relocation applied at link time will
855 // apply the link-time value, so we flag the location with
856 // an R_386_RELATIVE relocation so the dynamic loader can
857 // relocate it easily.
858 if (parameters->output_is_position_independent())
859 {
96f2030e 860 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
d61c6bd4 861 unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
4f4c5f80
ILT
862 rela_dyn->add_local(object, r_sym, r_type, output_section,
863 data_shndx, reloc.get_r_offset(),
d61c6bd4 864 reloc.get_r_addend());
96f2030e 865 }
2e30d253
ILT
866 break;
867
868 case elfcpp::R_X86_64_PC64:
869 case elfcpp::R_X86_64_PC32:
870 case elfcpp::R_X86_64_PC16:
871 case elfcpp::R_X86_64_PC8:
872 break;
873
f389a824
ILT
874 case elfcpp::R_X86_64_PLT32:
875 // Since we know this is a local symbol, we can handle this as a
876 // PC32 reloc.
877 break;
878
fdc2f80f 879 case elfcpp::R_X86_64_GOTPC32:
e822f2b1 880 case elfcpp::R_X86_64_GOTOFF64:
fdc2f80f
ILT
881 case elfcpp::R_X86_64_GOTPC64:
882 case elfcpp::R_X86_64_PLTOFF64:
2e30d253
ILT
883 // We need a GOT section.
884 target->got_section(symtab, layout);
ee9e9e86
ILT
885 // For PLTOFF64, we'd normally want a PLT section, but since we
886 // know this is a local symbol, no PLT is needed.
2e30d253
ILT
887 break;
888
0ffd9845
ILT
889 case elfcpp::R_X86_64_GOT64:
890 case elfcpp::R_X86_64_GOT32:
891 case elfcpp::R_X86_64_GOTPCREL64:
892 case elfcpp::R_X86_64_GOTPCREL:
ee9e9e86 893 case elfcpp::R_X86_64_GOTPLT64:
0ffd9845
ILT
894 {
895 // The symbol requires a GOT entry.
896 Output_data_got<64, false>* got = target->got_section(symtab, layout);
897 unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
898 if (got->add_local(object, r_sym))
899 {
900 // If we are generating a shared object, we need to add a
7bf1f802 901 // dynamic relocation for this symbol's GOT entry.
96f2030e 902 if (parameters->output_is_position_independent())
0ffd9845
ILT
903 {
904 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
7bf1f802
ILT
905 // R_X86_64_RELATIVE assumes a 64-bit relocation.
906 if (r_type != elfcpp::R_X86_64_GOT32)
e8c846c3
ILT
907 rela_dyn->add_local_relative(object, r_sym,
908 elfcpp::R_X86_64_RELATIVE, got,
909 object->local_got_offset(r_sym),
910 0);
7bf1f802
ILT
911 else
912 rela_dyn->add_local(object, r_sym, r_type,
913 got, object->local_got_offset(r_sym), 0);
0ffd9845
ILT
914 }
915 }
ee9e9e86
ILT
916 // For GOTPLT64, we'd normally want a PLT section, but since
917 // we know this is a local symbol, no PLT is needed.
0ffd9845
ILT
918 }
919 break;
920
2e30d253
ILT
921 case elfcpp::R_X86_64_COPY:
922 case elfcpp::R_X86_64_GLOB_DAT:
923 case elfcpp::R_X86_64_JUMP_SLOT:
924 case elfcpp::R_X86_64_RELATIVE:
d61c17ea 925 // These are outstanding tls relocs, which are unexpected when linking
2e30d253 926 case elfcpp::R_X86_64_TPOFF64:
2e30d253 927 case elfcpp::R_X86_64_DTPMOD64:
2e30d253 928 case elfcpp::R_X86_64_TLSDESC:
75f2446e
ILT
929 gold_error(_("%s: unexpected reloc %u in object file"),
930 object->name().c_str(), r_type);
2e30d253
ILT
931 break;
932
d61c17ea 933 // These are initial tls relocs, which are expected when linking
56622147
ILT
934 case elfcpp::R_X86_64_TLSGD: // Global-dynamic
935 case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url)
e041f13d 936 case elfcpp::R_X86_64_TLSDESC_CALL:
56622147 937 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
0ffd9845
ILT
938 case elfcpp::R_X86_64_DTPOFF32:
939 case elfcpp::R_X86_64_DTPOFF64:
56622147
ILT
940 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
941 case elfcpp::R_X86_64_TPOFF32: // Local-exec
2e30d253
ILT
942 {
943 bool output_is_shared = parameters->output_is_shared();
e041f13d
ILT
944 const tls::Tls_optimization optimized_type
945 = Target_x86_64::optimize_tls_reloc(!output_is_shared, r_type);
2e30d253
ILT
946 switch (r_type)
947 {
56622147 948 case elfcpp::R_X86_64_TLSGD: // General-dynamic
7bf1f802
ILT
949 if (optimized_type == tls::TLSOPT_NONE)
950 {
951 // Create a pair of GOT entries for the module index and
952 // dtv-relative offset.
953 Output_data_got<64, false>* got
954 = target->got_section(symtab, layout);
955 unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
956 got->add_local_tls_with_rela(object, r_sym,
957 lsym.get_st_shndx(), true,
958 target->rela_dyn_section(layout),
959 elfcpp::R_X86_64_DTPMOD64);
960 }
961 else if (optimized_type != tls::TLSOPT_TO_LE)
962 unsupported_reloc_local(object, r_type);
963 break;
964
56622147
ILT
965 case elfcpp::R_X86_64_GOTPC32_TLSDESC:
966 case elfcpp::R_X86_64_TLSDESC_CALL:
967 // FIXME: If not relaxing to LE, we need to generate
7bf1f802 968 // a GOT entry with a R_x86_64_TLSDESC reloc.
56622147
ILT
969 if (optimized_type != tls::TLSOPT_TO_LE)
970 unsupported_reloc_local(object, r_type);
2e30d253
ILT
971 break;
972
e041f13d 973 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
7bf1f802
ILT
974 if (optimized_type == tls::TLSOPT_NONE)
975 {
976 // Create a GOT entry for the module index.
31d60480 977 target->got_mod_index_entry(symtab, layout, object);
7bf1f802
ILT
978 }
979 else if (optimized_type != tls::TLSOPT_TO_LE)
980 unsupported_reloc_local(object, r_type);
981 break;
982
0ffd9845
ILT
983 case elfcpp::R_X86_64_DTPOFF32:
984 case elfcpp::R_X86_64_DTPOFF64:
e041f13d
ILT
985 break;
986
56622147 987 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
535890bb 988 layout->set_has_static_tls();
7bf1f802
ILT
989 if (optimized_type == tls::TLSOPT_NONE)
990 {
991 // Create a GOT entry for the tp-relative offset.
992 Output_data_got<64, false>* got
993 = target->got_section(symtab, layout);
994 unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
995 got->add_local_with_rela(object, r_sym,
996 target->rela_dyn_section(layout),
997 elfcpp::R_X86_64_TPOFF64);
998 }
999 else if (optimized_type != tls::TLSOPT_TO_LE)
56622147
ILT
1000 unsupported_reloc_local(object, r_type);
1001 break;
0ffd9845 1002
56622147 1003 case elfcpp::R_X86_64_TPOFF32: // Local-exec
535890bb 1004 layout->set_has_static_tls();
7bf1f802
ILT
1005 if (output_is_shared)
1006 unsupported_reloc_local(object, r_type);
2e30d253 1007 break;
e041f13d
ILT
1008
1009 default:
1010 gold_unreachable();
2e30d253
ILT
1011 }
1012 }
1013 break;
2e30d253 1014
fdc2f80f
ILT
1015 case elfcpp::R_X86_64_SIZE32:
1016 case elfcpp::R_X86_64_SIZE64:
2e30d253 1017 default:
75f2446e
ILT
1018 gold_error(_("%s: unsupported reloc %u against local symbol"),
1019 object->name().c_str(), r_type);
2e30d253
ILT
1020 break;
1021 }
1022}
1023
1024
e041f13d
ILT
1025// Report an unsupported relocation against a global symbol.
1026
1027void
1028Target_x86_64::Scan::unsupported_reloc_global(Sized_relobj<64, false>* object,
1029 unsigned int r_type,
1030 Symbol* gsym)
1031{
75f2446e 1032 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
a2b1aa12 1033 object->name().c_str(), r_type, gsym->demangled_name().c_str());
e041f13d
ILT
1034}
1035
2e30d253
ILT
1036// Scan a relocation for a global symbol.
1037
1038inline void
1039Target_x86_64::Scan::global(const General_options& options,
d61c17ea
ILT
1040 Symbol_table* symtab,
1041 Layout* layout,
1042 Target_x86_64* target,
1043 Sized_relobj<64, false>* object,
1044 unsigned int data_shndx,
4f4c5f80 1045 Output_section* output_section,
d61c17ea
ILT
1046 const elfcpp::Rela<64, false>& reloc,
1047 unsigned int r_type,
1048 Symbol* gsym)
2e30d253
ILT
1049{
1050 switch (r_type)
1051 {
1052 case elfcpp::R_X86_64_NONE:
e822f2b1
ILT
1053 case elfcpp::R_386_GNU_VTINHERIT:
1054 case elfcpp::R_386_GNU_VTENTRY:
2e30d253
ILT
1055 break;
1056
1057 case elfcpp::R_X86_64_64:
2e30d253
ILT
1058 case elfcpp::R_X86_64_32:
1059 case elfcpp::R_X86_64_32S:
2e30d253 1060 case elfcpp::R_X86_64_16:
2e30d253 1061 case elfcpp::R_X86_64_8:
96f2030e 1062 {
d61c6bd4
ILT
1063 // Make a PLT entry if necessary.
1064 if (gsym->needs_plt_entry())
1065 {
1066 target->make_plt_entry(symtab, layout, gsym);
1067 // Since this is not a PC-relative relocation, we may be
1068 // taking the address of a function. In that case we need to
1069 // set the entry in the dynamic symbol table to the address of
1070 // the PLT entry.
03e8f2b2 1071 if (gsym->is_from_dynobj() && !parameters->output_is_shared())
d61c6bd4
ILT
1072 gsym->set_needs_dynsym_value();
1073 }
1074 // Make a dynamic relocation if necessary.
0700cf32 1075 if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
d61c6bd4
ILT
1076 {
1077 if (target->may_need_copy_reloc(gsym))
1078 {
7bf1f802
ILT
1079 target->copy_reloc(&options, symtab, layout, object,
1080 data_shndx, output_section, gsym, reloc);
d61c6bd4
ILT
1081 }
1082 else if (r_type == elfcpp::R_X86_64_64
1083 && gsym->can_use_relative_reloc(false))
1084 {
1085 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
e8c846c3
ILT
1086 rela_dyn->add_global_relative(gsym, elfcpp::R_X86_64_RELATIVE,
1087 output_section, object,
1088 data_shndx, reloc.get_r_offset(),
1089 reloc.get_r_addend());
d61c6bd4
ILT
1090 }
1091 else
1092 {
96f2030e 1093 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
4f4c5f80
ILT
1094 rela_dyn->add_global(gsym, r_type, output_section, object,
1095 data_shndx, reloc.get_r_offset(),
96f2030e 1096 reloc.get_r_addend());
d61c6bd4
ILT
1097 }
1098 }
1099 }
1100 break;
1101
1102 case elfcpp::R_X86_64_PC64:
1103 case elfcpp::R_X86_64_PC32:
1104 case elfcpp::R_X86_64_PC16:
1105 case elfcpp::R_X86_64_PC8:
1106 {
1107 // Make a PLT entry if necessary.
1108 if (gsym->needs_plt_entry())
1109 target->make_plt_entry(symtab, layout, gsym);
1110 // Make a dynamic relocation if necessary.
0700cf32
ILT
1111 int flags = Symbol::NON_PIC_REF;
1112 if (gsym->type() == elfcpp::STT_FUNC)
1113 flags |= Symbol::FUNCTION_CALL;
1114 if (gsym->needs_dynamic_reloc(flags))
86849f1f 1115 {
d61c6bd4
ILT
1116 if (target->may_need_copy_reloc(gsym))
1117 {
7bf1f802
ILT
1118 target->copy_reloc(&options, symtab, layout, object,
1119 data_shndx, output_section, gsym, reloc);
d61c6bd4 1120 }
86849f1f 1121 else
d61c6bd4
ILT
1122 {
1123 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
4f4c5f80
ILT
1124 rela_dyn->add_global(gsym, r_type, output_section, object,
1125 data_shndx, reloc.get_r_offset(),
d61c6bd4
ILT
1126 reloc.get_r_addend());
1127 }
86849f1f 1128 }
d61c6bd4 1129 }
2e30d253
ILT
1130 break;
1131
ff006520 1132 case elfcpp::R_X86_64_GOT64:
2e30d253 1133 case elfcpp::R_X86_64_GOT32:
ff006520
ILT
1134 case elfcpp::R_X86_64_GOTPCREL64:
1135 case elfcpp::R_X86_64_GOTPCREL:
1136 case elfcpp::R_X86_64_GOTPLT64:
2e30d253
ILT
1137 {
1138 // The symbol requires a GOT entry.
1139 Output_data_got<64, false>* got = target->got_section(symtab, layout);
7bf1f802
ILT
1140 if (gsym->final_value_is_known())
1141 got->add_global(gsym);
1142 else
1143 {
2e30d253
ILT
1144 // If this symbol is not fully resolved, we need to add a
1145 // dynamic relocation for it.
7bf1f802 1146 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
8fc19601
ILT
1147 if (gsym->is_from_dynobj()
1148 || gsym->is_undefined()
1149 || gsym->is_preemptible())
7bf1f802
ILT
1150 got->add_global_with_rela(gsym, rela_dyn,
1151 elfcpp::R_X86_64_GLOB_DAT);
1152 else
2e30d253 1153 {
7bf1f802 1154 if (got->add_global(gsym))
e8c846c3
ILT
1155 rela_dyn->add_global_relative(gsym,
1156 elfcpp::R_X86_64_RELATIVE,
1157 got, gsym->got_offset(), 0);
2e30d253
ILT
1158 }
1159 }
ee9e9e86
ILT
1160 // For GOTPLT64, we also need a PLT entry (but only if the
1161 // symbol is not fully resolved).
1162 if (r_type == elfcpp::R_X86_64_GOTPLT64
1163 && !gsym->final_value_is_known())
1164 target->make_plt_entry(symtab, layout, gsym);
2e30d253
ILT
1165 }
1166 break;
1167
1168 case elfcpp::R_X86_64_PLT32:
1169 // If the symbol is fully resolved, this is just a PC32 reloc.
1170 // Otherwise we need a PLT entry.
1171 if (gsym->final_value_is_known())
1172 break;
96f2030e
ILT
1173 // If building a shared library, we can also skip the PLT entry
1174 // if the symbol is defined in the output file and is protected
1175 // or hidden.
1176 if (gsym->is_defined()
1177 && !gsym->is_from_dynobj()
1178 && !gsym->is_preemptible())
1179 break;
2e30d253
ILT
1180 target->make_plt_entry(symtab, layout, gsym);
1181 break;
1182
fdc2f80f 1183 case elfcpp::R_X86_64_GOTPC32:
e822f2b1 1184 case elfcpp::R_X86_64_GOTOFF64:
fdc2f80f
ILT
1185 case elfcpp::R_X86_64_GOTPC64:
1186 case elfcpp::R_X86_64_PLTOFF64:
2e30d253
ILT
1187 // We need a GOT section.
1188 target->got_section(symtab, layout);
ee9e9e86
ILT
1189 // For PLTOFF64, we also need a PLT entry (but only if the
1190 // symbol is not fully resolved).
1191 if (r_type == elfcpp::R_X86_64_PLTOFF64
1192 && !gsym->final_value_is_known())
1193 target->make_plt_entry(symtab, layout, gsym);
2e30d253
ILT
1194 break;
1195
2e30d253
ILT
1196 case elfcpp::R_X86_64_COPY:
1197 case elfcpp::R_X86_64_GLOB_DAT:
1198 case elfcpp::R_X86_64_JUMP_SLOT:
1199 case elfcpp::R_X86_64_RELATIVE:
d61c17ea 1200 // These are outstanding tls relocs, which are unexpected when linking
e822f2b1 1201 case elfcpp::R_X86_64_TPOFF64:
2e30d253 1202 case elfcpp::R_X86_64_DTPMOD64:
e822f2b1 1203 case elfcpp::R_X86_64_TLSDESC:
75f2446e
ILT
1204 gold_error(_("%s: unexpected reloc %u in object file"),
1205 object->name().c_str(), r_type);
2e30d253 1206 break;
2e30d253 1207
d61c17ea 1208 // These are initial tls relocs, which are expected for global()
56622147
ILT
1209 case elfcpp::R_X86_64_TLSGD: // Global-dynamic
1210 case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url)
e041f13d 1211 case elfcpp::R_X86_64_TLSDESC_CALL:
56622147 1212 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
0ffd9845
ILT
1213 case elfcpp::R_X86_64_DTPOFF32:
1214 case elfcpp::R_X86_64_DTPOFF64:
56622147
ILT
1215 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
1216 case elfcpp::R_X86_64_TPOFF32: // Local-exec
2e30d253
ILT
1217 {
1218 const bool is_final = gsym->final_value_is_known();
e041f13d
ILT
1219 const tls::Tls_optimization optimized_type
1220 = Target_x86_64::optimize_tls_reloc(is_final, r_type);
2e30d253
ILT
1221 switch (r_type)
1222 {
56622147 1223 case elfcpp::R_X86_64_TLSGD: // General-dynamic
7bf1f802
ILT
1224 if (optimized_type == tls::TLSOPT_NONE)
1225 {
1226 // Create a pair of GOT entries for the module index and
1227 // dtv-relative offset.
1228 Output_data_got<64, false>* got
1229 = target->got_section(symtab, layout);
1230 got->add_global_tls_with_rela(gsym,
1231 target->rela_dyn_section(layout),
1232 elfcpp::R_X86_64_DTPMOD64,
1233 elfcpp::R_X86_64_DTPOFF64);
1234 }
1235 else if (optimized_type == tls::TLSOPT_TO_IE)
1236 {
1237 // Create a GOT entry for the tp-relative offset.
1238 Output_data_got<64, false>* got
1239 = target->got_section(symtab, layout);
1240 got->add_global_with_rela(gsym,
1241 target->rela_dyn_section(layout),
1242 elfcpp::R_X86_64_TPOFF64);
1243 }
1244 else if (optimized_type != tls::TLSOPT_TO_LE)
1245 unsupported_reloc_global(object, r_type, gsym);
1246 break;
1247
56622147
ILT
1248 case elfcpp::R_X86_64_GOTPC32_TLSDESC:
1249 case elfcpp::R_X86_64_TLSDESC_CALL:
1250 // FIXME: If not relaxing to LE, we need to generate
1251 // DTPMOD64 and DTPOFF64, or TLSDESC, relocs.
1252 if (optimized_type != tls::TLSOPT_TO_LE)
1253 unsupported_reloc_global(object, r_type, gsym);
2e30d253
ILT
1254 break;
1255
e041f13d 1256 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
7bf1f802
ILT
1257 if (optimized_type == tls::TLSOPT_NONE)
1258 {
1259 // Create a GOT entry for the module index.
31d60480 1260 target->got_mod_index_entry(symtab, layout, object);
7bf1f802
ILT
1261 }
1262 else if (optimized_type != tls::TLSOPT_TO_LE)
1263 unsupported_reloc_global(object, r_type, gsym);
1264 break;
1265
0ffd9845
ILT
1266 case elfcpp::R_X86_64_DTPOFF32:
1267 case elfcpp::R_X86_64_DTPOFF64:
e041f13d
ILT
1268 break;
1269
56622147 1270 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
535890bb 1271 layout->set_has_static_tls();
7bf1f802
ILT
1272 if (optimized_type == tls::TLSOPT_NONE)
1273 {
1274 // Create a GOT entry for the tp-relative offset.
1275 Output_data_got<64, false>* got
1276 = target->got_section(symtab, layout);
1277 got->add_global_with_rela(gsym,
1278 target->rela_dyn_section(layout),
1279 elfcpp::R_X86_64_TPOFF64);
1280 }
1281 else if (optimized_type != tls::TLSOPT_TO_LE)
56622147
ILT
1282 unsupported_reloc_global(object, r_type, gsym);
1283 break;
0ffd9845 1284
56622147 1285 case elfcpp::R_X86_64_TPOFF32: // Local-exec
535890bb 1286 layout->set_has_static_tls();
7bf1f802
ILT
1287 if (parameters->output_is_shared())
1288 unsupported_reloc_local(object, r_type);
2e30d253 1289 break;
e041f13d
ILT
1290
1291 default:
1292 gold_unreachable();
2e30d253
ILT
1293 }
1294 }
1295 break;
fdc2f80f
ILT
1296
1297 case elfcpp::R_X86_64_SIZE32:
1298 case elfcpp::R_X86_64_SIZE64:
2e30d253 1299 default:
75f2446e 1300 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
a2b1aa12
ILT
1301 object->name().c_str(), r_type,
1302 gsym->demangled_name().c_str());
2e30d253
ILT
1303 break;
1304 }
1305}
1306
1307// Scan relocations for a section.
1308
1309void
1310Target_x86_64::scan_relocs(const General_options& options,
d61c17ea
ILT
1311 Symbol_table* symtab,
1312 Layout* layout,
1313 Sized_relobj<64, false>* object,
1314 unsigned int data_shndx,
1315 unsigned int sh_type,
1316 const unsigned char* prelocs,
1317 size_t reloc_count,
730cdc88
ILT
1318 Output_section* output_section,
1319 bool needs_special_offset_handling,
d61c17ea 1320 size_t local_symbol_count,
730cdc88 1321 const unsigned char* plocal_symbols)
2e30d253
ILT
1322{
1323 if (sh_type == elfcpp::SHT_REL)
1324 {
75f2446e
ILT
1325 gold_error(_("%s: unsupported REL reloc section"),
1326 object->name().c_str());
1327 return;
2e30d253
ILT
1328 }
1329
1330 gold::scan_relocs<64, false, Target_x86_64, elfcpp::SHT_RELA,
1331 Target_x86_64::Scan>(
1332 options,
1333 symtab,
1334 layout,
1335 this,
1336 object,
1337 data_shndx,
1338 prelocs,
1339 reloc_count,
730cdc88
ILT
1340 output_section,
1341 needs_special_offset_handling,
2e30d253 1342 local_symbol_count,
730cdc88 1343 plocal_symbols);
2e30d253
ILT
1344}
1345
1346// Finalize the sections.
1347
1348void
1349Target_x86_64::do_finalize_sections(Layout* layout)
1350{
1351 // Fill in some more dynamic tags.
1352 Output_data_dynamic* const odyn = layout->dynamic_data();
1353 if (odyn != NULL)
1354 {
1355 if (this->got_plt_ != NULL)
1356 odyn->add_section_address(elfcpp::DT_PLTGOT, this->got_plt_);
1357
1358 if (this->plt_ != NULL)
1359 {
1360 const Output_data* od = this->plt_->rel_plt();
1361 odyn->add_section_size(elfcpp::DT_PLTRELSZ, od);
1362 odyn->add_section_address(elfcpp::DT_JMPREL, od);
1363 odyn->add_constant(elfcpp::DT_PLTREL, elfcpp::DT_RELA);
1364 }
1365
0ffd9845 1366 if (this->rela_dyn_ != NULL)
2e30d253 1367 {
0ffd9845 1368 const Output_data* od = this->rela_dyn_;
2e30d253 1369 odyn->add_section_address(elfcpp::DT_RELA, od);
e84992bb 1370 odyn->add_section_size(elfcpp::DT_RELASZ, od);
2e30d253 1371 odyn->add_constant(elfcpp::DT_RELAENT,
e84992bb 1372 elfcpp::Elf_sizes<64>::rela_size);
2e30d253
ILT
1373 }
1374
1375 if (!parameters->output_is_shared())
1376 {
1377 // The value of the DT_DEBUG tag is filled in by the dynamic
1378 // linker at run time, and used by the debugger.
1379 odyn->add_constant(elfcpp::DT_DEBUG, 0);
1380 }
1381 }
1382
1383 // Emit any relocs we saved in an attempt to avoid generating COPY
1384 // relocs.
1385 if (this->copy_relocs_ == NULL)
1386 return;
1387 if (this->copy_relocs_->any_to_emit())
1388 {
0ffd9845
ILT
1389 Reloc_section* rela_dyn = this->rela_dyn_section(layout);
1390 this->copy_relocs_->emit(rela_dyn);
2e30d253
ILT
1391 }
1392 delete this->copy_relocs_;
1393 this->copy_relocs_ = NULL;
1394}
1395
1396// Perform a relocation.
1397
1398inline bool
1399Target_x86_64::Relocate::relocate(const Relocate_info<64, false>* relinfo,
1400 Target_x86_64* target,
1401 size_t relnum,
0ffd9845 1402 const elfcpp::Rela<64, false>& rela,
2e30d253
ILT
1403 unsigned int r_type,
1404 const Sized_symbol<64>* gsym,
1405 const Symbol_value<64>* psymval,
1406 unsigned char* view,
1407 elfcpp::Elf_types<64>::Elf_Addr address,
fe8718a4 1408 section_size_type view_size)
2e30d253
ILT
1409{
1410 if (this->skip_call_tls_get_addr_)
1411 {
1412 if (r_type != elfcpp::R_X86_64_PLT32
1413 || gsym == NULL
0ffd9845 1414 || strcmp(gsym->name(), "__tls_get_addr") != 0)
2e30d253 1415 {
75f2446e
ILT
1416 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1417 _("missing expected TLS relocation"));
1418 }
1419 else
1420 {
1421 this->skip_call_tls_get_addr_ = false;
1422 return false;
2e30d253 1423 }
2e30d253
ILT
1424 }
1425
1426 // Pick the value to use for symbols defined in shared objects.
1427 Symbol_value<64> symval;
96f2030e
ILT
1428 if (gsym != NULL
1429 && (gsym->is_from_dynobj()
1430 || (parameters->output_is_shared()
8fc19601 1431 && (gsym->is_undefined() || gsym->is_preemptible())))
96f2030e 1432 && gsym->has_plt_offset())
2e30d253
ILT
1433 {
1434 symval.set_output_value(target->plt_section()->address()
1435 + gsym->plt_offset());
1436 psymval = &symval;
1437 }
1438
1439 const Sized_relobj<64, false>* object = relinfo->object;
0ffd9845
ILT
1440 const elfcpp::Elf_Xword addend = rela.get_r_addend();
1441
1442 // Get the GOT offset if needed.
96f2030e
ILT
1443 // The GOT pointer points to the end of the GOT section.
1444 // We need to subtract the size of the GOT section to get
1445 // the actual offset to use in the relocation.
0ffd9845
ILT
1446 bool have_got_offset = false;
1447 unsigned int got_offset = 0;
1448 switch (r_type)
1449 {
1450 case elfcpp::R_X86_64_GOT32:
1451 case elfcpp::R_X86_64_GOT64:
1452 case elfcpp::R_X86_64_GOTPLT64:
1453 case elfcpp::R_X86_64_GOTPCREL:
1454 case elfcpp::R_X86_64_GOTPCREL64:
1455 if (gsym != NULL)
1456 {
1457 gold_assert(gsym->has_got_offset());
96f2030e 1458 got_offset = gsym->got_offset() - target->got_size();
0ffd9845
ILT
1459 }
1460 else
1461 {
1462 unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info());
7bf1f802 1463 gold_assert(object->local_has_got_offset(r_sym));
96f2030e 1464 got_offset = object->local_got_offset(r_sym) - target->got_size();
0ffd9845
ILT
1465 }
1466 have_got_offset = true;
1467 break;
1468
1469 default:
1470 break;
1471 }
2e30d253
ILT
1472
1473 switch (r_type)
1474 {
1475 case elfcpp::R_X86_64_NONE:
e822f2b1
ILT
1476 case elfcpp::R_386_GNU_VTINHERIT:
1477 case elfcpp::R_386_GNU_VTENTRY:
2e30d253
ILT
1478 break;
1479
1480 case elfcpp::R_X86_64_64:
1481 Relocate_functions<64, false>::rela64(view, object, psymval, addend);
1482 break;
1483
1484 case elfcpp::R_X86_64_PC64:
1485 Relocate_functions<64, false>::pcrela64(view, object, psymval, addend,
1486 address);
1487 break;
1488
1489 case elfcpp::R_X86_64_32:
7bb3655e
ILT
1490 // FIXME: we need to verify that value + addend fits into 32 bits:
1491 // uint64_t x = value + addend;
1492 // x == static_cast<uint64_t>(static_cast<uint32_t>(x))
1493 // Likewise for other <=32-bit relocations (but see R_X86_64_32S).
2e30d253
ILT
1494 Relocate_functions<64, false>::rela32(view, object, psymval, addend);
1495 break;
1496
1497 case elfcpp::R_X86_64_32S:
7bb3655e
ILT
1498 // FIXME: we need to verify that value + addend fits into 32 bits:
1499 // int64_t x = value + addend; // note this quantity is signed!
1500 // x == static_cast<int64_t>(static_cast<int32_t>(x))
2e30d253
ILT
1501 Relocate_functions<64, false>::rela32(view, object, psymval, addend);
1502 break;
1503
1504 case elfcpp::R_X86_64_PC32:
1505 Relocate_functions<64, false>::pcrela32(view, object, psymval, addend,
1506 address);
1507 break;
1508
1509 case elfcpp::R_X86_64_16:
1510 Relocate_functions<64, false>::rela16(view, object, psymval, addend);
1511 break;
1512
1513 case elfcpp::R_X86_64_PC16:
1514 Relocate_functions<64, false>::pcrela16(view, object, psymval, addend,
1515 address);
1516 break;
1517
1518 case elfcpp::R_X86_64_8:
1519 Relocate_functions<64, false>::rela8(view, object, psymval, addend);
1520 break;
1521
1522 case elfcpp::R_X86_64_PC8:
1523 Relocate_functions<64, false>::pcrela8(view, object, psymval, addend,
1524 address);
1525 break;
1526
1527 case elfcpp::R_X86_64_PLT32:
f389a824
ILT
1528 gold_assert(gsym == NULL
1529 || gsym->has_plt_offset()
99f8faca
ILT
1530 || gsym->final_value_is_known()
1531 || (gsym->is_defined()
1532 && !gsym->is_from_dynobj()
1533 && !gsym->is_preemptible()));
ee9e9e86
ILT
1534 // Note: while this code looks the same as for R_X86_64_PC32, it
1535 // behaves differently because psymval was set to point to
1536 // the PLT entry, rather than the symbol, in Scan::global().
2e30d253
ILT
1537 Relocate_functions<64, false>::pcrela32(view, object, psymval, addend,
1538 address);
1539 break;
1540
ee9e9e86
ILT
1541 case elfcpp::R_X86_64_PLTOFF64:
1542 {
1543 gold_assert(gsym);
1544 gold_assert(gsym->has_plt_offset()
1545 || gsym->final_value_is_known());
1546 elfcpp::Elf_types<64>::Elf_Addr got_address;
1547 got_address = target->got_section(NULL, NULL)->address();
c1866bd5
ILT
1548 Relocate_functions<64, false>::rela64(view, object, psymval,
1549 addend - got_address);
ee9e9e86
ILT
1550 }
1551
2e30d253 1552 case elfcpp::R_X86_64_GOT32:
0ffd9845
ILT
1553 gold_assert(have_got_offset);
1554 Relocate_functions<64, false>::rela32(view, got_offset, addend);
2e30d253
ILT
1555 break;
1556
e822f2b1
ILT
1557 case elfcpp::R_X86_64_GOTPC32:
1558 {
1559 gold_assert(gsym);
1560 elfcpp::Elf_types<64>::Elf_Addr value;
96f2030e 1561 value = target->got_plt_section()->address();
e822f2b1
ILT
1562 Relocate_functions<64, false>::pcrela32(view, value, addend, address);
1563 }
1564 break;
1565
1566 case elfcpp::R_X86_64_GOT64:
1567 // The ABI doc says "Like GOT64, but indicates a PLT entry is needed."
1568 // Since we always add a PLT entry, this is equivalent.
fdc2f80f 1569 case elfcpp::R_X86_64_GOTPLT64:
0ffd9845
ILT
1570 gold_assert(have_got_offset);
1571 Relocate_functions<64, false>::rela64(view, got_offset, addend);
e822f2b1
ILT
1572 break;
1573
1574 case elfcpp::R_X86_64_GOTPC64:
1575 {
1576 gold_assert(gsym);
1577 elfcpp::Elf_types<64>::Elf_Addr value;
96f2030e 1578 value = target->got_plt_section()->address();
e822f2b1
ILT
1579 Relocate_functions<64, false>::pcrela64(view, value, addend, address);
1580 }
1581 break;
1582
2e30d253
ILT
1583 case elfcpp::R_X86_64_GOTOFF64:
1584 {
1585 elfcpp::Elf_types<64>::Elf_Addr value;
1586 value = (psymval->value(object, 0)
96f2030e 1587 - target->got_plt_section()->address());
2e30d253
ILT
1588 Relocate_functions<64, false>::rela64(view, value, addend);
1589 }
1590 break;
1591
1592 case elfcpp::R_X86_64_GOTPCREL:
1593 {
0ffd9845
ILT
1594 gold_assert(have_got_offset);
1595 elfcpp::Elf_types<64>::Elf_Addr value;
96f2030e 1596 value = target->got_plt_section()->address() + got_offset;
0ffd9845 1597 Relocate_functions<64, false>::pcrela32(view, value, addend, address);
2e30d253
ILT
1598 }
1599 break;
1600
e822f2b1
ILT
1601 case elfcpp::R_X86_64_GOTPCREL64:
1602 {
0ffd9845
ILT
1603 gold_assert(have_got_offset);
1604 elfcpp::Elf_types<64>::Elf_Addr value;
96f2030e 1605 value = target->got_plt_section()->address() + got_offset;
0ffd9845 1606 Relocate_functions<64, false>::pcrela64(view, value, addend, address);
e822f2b1
ILT
1607 }
1608 break;
1609
2e30d253
ILT
1610 case elfcpp::R_X86_64_COPY:
1611 case elfcpp::R_X86_64_GLOB_DAT:
1612 case elfcpp::R_X86_64_JUMP_SLOT:
1613 case elfcpp::R_X86_64_RELATIVE:
d61c17ea 1614 // These are outstanding tls relocs, which are unexpected when linking
2e30d253 1615 case elfcpp::R_X86_64_TPOFF64:
2e30d253 1616 case elfcpp::R_X86_64_DTPMOD64:
2e30d253 1617 case elfcpp::R_X86_64_TLSDESC:
75f2446e
ILT
1618 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1619 _("unexpected reloc %u in object file"),
1620 r_type);
2e30d253
ILT
1621 break;
1622
d61c17ea 1623 // These are initial tls relocs, which are expected when linking
56622147
ILT
1624 case elfcpp::R_X86_64_TLSGD: // Global-dynamic
1625 case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url)
e041f13d 1626 case elfcpp::R_X86_64_TLSDESC_CALL:
56622147 1627 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
0ffd9845
ILT
1628 case elfcpp::R_X86_64_DTPOFF32:
1629 case elfcpp::R_X86_64_DTPOFF64:
56622147
ILT
1630 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
1631 case elfcpp::R_X86_64_TPOFF32: // Local-exec
7bf1f802
ILT
1632 this->relocate_tls(relinfo, target, relnum, rela, r_type, gsym, psymval,
1633 view, address, view_size);
2e30d253 1634 break;
2e30d253 1635
fdc2f80f
ILT
1636 case elfcpp::R_X86_64_SIZE32:
1637 case elfcpp::R_X86_64_SIZE64:
2e30d253 1638 default:
75f2446e
ILT
1639 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1640 _("unsupported reloc %u"),
1641 r_type);
2e30d253
ILT
1642 break;
1643 }
1644
1645 return true;
1646}
1647
1648// Perform a TLS relocation.
1649
1650inline void
d61c17ea 1651Target_x86_64::Relocate::relocate_tls(const Relocate_info<64, false>* relinfo,
7bf1f802 1652 Target_x86_64* target,
d61c17ea 1653 size_t relnum,
72ec2876 1654 const elfcpp::Rela<64, false>& rela,
d61c17ea
ILT
1655 unsigned int r_type,
1656 const Sized_symbol<64>* gsym,
1657 const Symbol_value<64>* psymval,
1658 unsigned char* view,
6a41d30b 1659 elfcpp::Elf_types<64>::Elf_Addr address,
fe8718a4 1660 section_size_type view_size)
2e30d253 1661{
2e30d253 1662 Output_segment* tls_segment = relinfo->layout->tls_segment();
7bf1f802
ILT
1663
1664 const Sized_relobj<64, false>* object = relinfo->object;
6a41d30b 1665 const elfcpp::Elf_Xword addend = rela.get_r_addend();
2e30d253
ILT
1666
1667 elfcpp::Elf_types<64>::Elf_Addr value = psymval->value(relinfo->object, 0);
1668
1669 const bool is_final = (gsym == NULL
96f2030e 1670 ? !parameters->output_is_position_independent()
2e30d253 1671 : gsym->final_value_is_known());
e041f13d
ILT
1672 const tls::Tls_optimization optimized_type
1673 = Target_x86_64::optimize_tls_reloc(is_final, r_type);
2e30d253
ILT
1674 switch (r_type)
1675 {
56622147
ILT
1676 case elfcpp::R_X86_64_TLSGD: // Global-dynamic
1677 case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url)
e041f13d
ILT
1678 case elfcpp::R_X86_64_TLSDESC_CALL:
1679 if (optimized_type == tls::TLSOPT_TO_LE)
2e30d253 1680 {
7bf1f802 1681 gold_assert(tls_segment != NULL);
2e30d253 1682 this->tls_gd_to_le(relinfo, relnum, tls_segment,
72ec2876 1683 rela, r_type, value, view,
2e30d253
ILT
1684 view_size);
1685 break;
1686 }
7bf1f802
ILT
1687 else
1688 {
1689 unsigned int got_offset;
1690 if (gsym != NULL)
1691 {
1692 gold_assert(gsym->has_tls_got_offset(true));
1693 got_offset = gsym->tls_got_offset(true) - target->got_size();
1694 }
1695 else
1696 {
1697 unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info());
1698 gold_assert(object->local_has_tls_got_offset(r_sym, true));
1699 got_offset = (object->local_tls_got_offset(r_sym, true)
1700 - target->got_size());
1701 }
1702 if (optimized_type == tls::TLSOPT_TO_IE)
1703 {
1704 gold_assert(tls_segment != NULL);
1705 this->tls_gd_to_ie(relinfo, relnum, tls_segment, rela, r_type,
1706 got_offset, view, view_size);
1707 break;
1708 }
1709 else if (optimized_type == tls::TLSOPT_NONE)
1710 {
1711 // Relocate the field with the offset of the pair of GOT
1712 // entries.
6a41d30b
ILT
1713 value = target->got_plt_section()->address() + got_offset;
1714 Relocate_functions<64, false>::pcrela32(view, value, addend,
1715 address);
7bf1f802
ILT
1716 break;
1717 }
1718 }
72ec2876 1719 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
75f2446e 1720 _("unsupported reloc %u"), r_type);
2e30d253
ILT
1721 break;
1722
56622147 1723 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
e041f13d
ILT
1724 if (optimized_type == tls::TLSOPT_TO_LE)
1725 {
7bf1f802 1726 gold_assert(tls_segment != NULL);
72ec2876
ILT
1727 this->tls_ld_to_le(relinfo, relnum, tls_segment, rela, r_type,
1728 value, view, view_size);
1729 break;
e041f13d 1730 }
7bf1f802
ILT
1731 else if (optimized_type == tls::TLSOPT_NONE)
1732 {
1733 // Relocate the field with the offset of the GOT entry for
1734 // the module index.
1735 unsigned int got_offset;
31d60480
ILT
1736 got_offset = (target->got_mod_index_entry(NULL, NULL, NULL)
1737 - target->got_size());
6a41d30b
ILT
1738 value = target->got_plt_section()->address() + got_offset;
1739 Relocate_functions<64, false>::pcrela32(view, value, addend,
1740 address);
7bf1f802
ILT
1741 break;
1742 }
72ec2876 1743 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
75f2446e 1744 _("unsupported reloc %u"), r_type);
2e30d253 1745 break;
0ffd9845
ILT
1746
1747 case elfcpp::R_X86_64_DTPOFF32:
7bf1f802 1748 gold_assert(tls_segment != NULL);
e041f13d 1749 if (optimized_type == tls::TLSOPT_TO_LE)
6a41d30b
ILT
1750 value -= tls_segment->memsz();
1751 Relocate_functions<64, false>::rela32(view, value, 0);
0ffd9845
ILT
1752 break;
1753
1754 case elfcpp::R_X86_64_DTPOFF64:
7bf1f802 1755 gold_assert(tls_segment != NULL);
e041f13d 1756 if (optimized_type == tls::TLSOPT_TO_LE)
6a41d30b
ILT
1757 value -= tls_segment->memsz();
1758 Relocate_functions<64, false>::rela64(view, value, 0);
0ffd9845 1759 break;
2e30d253 1760
56622147
ILT
1761 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
1762 if (optimized_type == tls::TLSOPT_TO_LE)
1763 {
7bf1f802 1764 gold_assert(tls_segment != NULL);
56622147
ILT
1765 Target_x86_64::Relocate::tls_ie_to_le(relinfo, relnum, tls_segment,
1766 rela, r_type, value, view,
1767 view_size);
1768 break;
1769 }
7bf1f802
ILT
1770 else if (optimized_type == tls::TLSOPT_NONE)
1771 {
1772 // Relocate the field with the offset of the GOT entry for
1773 // the tp-relative offset of the symbol.
1774 unsigned int got_offset;
1775 if (gsym != NULL)
1776 {
1777 gold_assert(gsym->has_got_offset());
1778 got_offset = gsym->got_offset() - target->got_size();
1779 }
1780 else
1781 {
1782 unsigned int r_sym = elfcpp::elf_r_sym<64>(rela.get_r_info());
1783 gold_assert(object->local_has_got_offset(r_sym));
1784 got_offset = (object->local_got_offset(r_sym)
1785 - target->got_size());
1786 }
6a41d30b
ILT
1787 value = target->got_plt_section()->address() + got_offset;
1788 Relocate_functions<64, false>::pcrela32(view, value, addend, address);
7bf1f802
ILT
1789 break;
1790 }
56622147
ILT
1791 gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
1792 _("unsupported reloc type %u"),
1793 r_type);
1794 break;
0ffd9845 1795
56622147 1796 case elfcpp::R_X86_64_TPOFF32: // Local-exec
6a41d30b
ILT
1797 value -= tls_segment->memsz();
1798 Relocate_functions<64, false>::rela32(view, value, 0);
56622147 1799 break;
2e30d253 1800 }
2e30d253
ILT
1801}
1802
7bf1f802
ILT
1803// Do a relocation in which we convert a TLS General-Dynamic to an
1804// Initial-Exec.
1805
1806inline void
1807Target_x86_64::Relocate::tls_gd_to_ie(const Relocate_info<64, false>* relinfo,
1808 size_t relnum,
1809 Output_segment* tls_segment,
1810 const elfcpp::Rela<64, false>& rela,
1811 unsigned int,
1812 elfcpp::Elf_types<64>::Elf_Addr value,
1813 unsigned char* view,
fe8718a4 1814 section_size_type view_size)
7bf1f802
ILT
1815{
1816 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
1817 // .word 0x6666; rex64; call __tls_get_addr
1818 // ==> movq %fs:0,%rax; addq x@gottpoff(%rip),%rax
1819
1820 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -4);
1821 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 12);
1822
1823 tls::check_tls(relinfo, relnum, rela.get_r_offset(),
1824 (memcmp(view - 4, "\x66\x48\x8d\x3d", 4) == 0));
1825 tls::check_tls(relinfo, relnum, rela.get_r_offset(),
1826 (memcmp(view + 4, "\x66\x66\x48\xe8", 4) == 0));
1827
1828 memcpy(view - 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0\0", 16);
1829
6a41d30b 1830 value -= tls_segment->memsz();
7bf1f802
ILT
1831 Relocate_functions<64, false>::rela32(view + 8, value, 0);
1832
1833 // The next reloc should be a PLT32 reloc against __tls_get_addr.
1834 // We can skip it.
1835 this->skip_call_tls_get_addr_ = true;
1836}
1837
e041f13d 1838// Do a relocation in which we convert a TLS General-Dynamic to a
2e30d253
ILT
1839// Local-Exec.
1840
1841inline void
d61c17ea
ILT
1842Target_x86_64::Relocate::tls_gd_to_le(const Relocate_info<64, false>* relinfo,
1843 size_t relnum,
1844 Output_segment* tls_segment,
72ec2876 1845 const elfcpp::Rela<64, false>& rela,
d61c17ea
ILT
1846 unsigned int,
1847 elfcpp::Elf_types<64>::Elf_Addr value,
1848 unsigned char* view,
fe8718a4 1849 section_size_type view_size)
2e30d253 1850{
0ffd9845
ILT
1851 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
1852 // .word 0x6666; rex64; call __tls_get_addr
1853 // ==> movq %fs:0,%rax; leaq x@tpoff(%rax),%rax
2e30d253 1854
72ec2876
ILT
1855 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -4);
1856 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 12);
2e30d253 1857
72ec2876
ILT
1858 tls::check_tls(relinfo, relnum, rela.get_r_offset(),
1859 (memcmp(view - 4, "\x66\x48\x8d\x3d", 4) == 0));
1860 tls::check_tls(relinfo, relnum, rela.get_r_offset(),
1861 (memcmp(view + 4, "\x66\x66\x48\xe8", 4) == 0));
2e30d253 1862
0ffd9845 1863 memcpy(view - 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0\0", 16);
2e30d253 1864
6a41d30b 1865 value -= tls_segment->memsz();
0ffd9845 1866 Relocate_functions<64, false>::rela32(view + 8, value, 0);
2e30d253
ILT
1867
1868 // The next reloc should be a PLT32 reloc against __tls_get_addr.
1869 // We can skip it.
1870 this->skip_call_tls_get_addr_ = true;
2e30d253
ILT
1871}
1872
2e30d253 1873inline void
72ec2876
ILT
1874Target_x86_64::Relocate::tls_ld_to_le(const Relocate_info<64, false>* relinfo,
1875 size_t relnum,
1876 Output_segment*,
1877 const elfcpp::Rela<64, false>& rela,
1878 unsigned int,
1879 elfcpp::Elf_types<64>::Elf_Addr,
1880 unsigned char* view,
fe8718a4 1881 section_size_type view_size)
2e30d253 1882{
72ec2876
ILT
1883 // leaq foo@tlsld(%rip),%rdi; call __tls_get_addr@plt;
1884 // ... leq foo@dtpoff(%rax),%reg
1885 // ==> .word 0x6666; .byte 0x66; movq %fs:0,%rax ... leaq x@tpoff(%rax),%rdx
2e30d253 1886
72ec2876
ILT
1887 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3);
1888 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 9);
2e30d253 1889
72ec2876
ILT
1890 tls::check_tls(relinfo, relnum, rela.get_r_offset(),
1891 view[-3] == 0x48 && view[-2] == 0x8d && view[-1] == 0x3d);
1892
1893 tls::check_tls(relinfo, relnum, rela.get_r_offset(), view[4] == 0xe8);
1894
1895 memcpy(view - 3, "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0\0", 12);
1896
1897 // The next reloc should be a PLT32 reloc against __tls_get_addr.
1898 // We can skip it.
1899 this->skip_call_tls_get_addr_ = true;
2e30d253
ILT
1900}
1901
56622147
ILT
1902// Do a relocation in which we convert a TLS Initial-Exec to a
1903// Local-Exec.
1904
1905inline void
1906Target_x86_64::Relocate::tls_ie_to_le(const Relocate_info<64, false>* relinfo,
1907 size_t relnum,
1908 Output_segment* tls_segment,
1909 const elfcpp::Rela<64, false>& rela,
1910 unsigned int,
1911 elfcpp::Elf_types<64>::Elf_Addr value,
1912 unsigned char* view,
fe8718a4 1913 section_size_type view_size)
56622147
ILT
1914{
1915 // We need to examine the opcodes to figure out which instruction we
1916 // are looking at.
1917
1918 // movq foo@gottpoff(%rip),%reg ==> movq $YY,%reg
1919 // addq foo@gottpoff(%rip),%reg ==> addq $YY,%reg
1920
1921 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3);
1922 tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4);
1923
1924 unsigned char op1 = view[-3];
1925 unsigned char op2 = view[-2];
1926 unsigned char op3 = view[-1];
1927 unsigned char reg = op3 >> 3;
1928
1929 if (op2 == 0x8b)
1930 {
1931 // movq
1932 if (op1 == 0x4c)
1933 view[-3] = 0x49;
1934 view[-2] = 0xc7;
1935 view[-1] = 0xc0 | reg;
1936 }
1937 else if (reg == 4)
1938 {
1939 // Special handling for %rsp.
1940 if (op1 == 0x4c)
1941 view[-3] = 0x49;
1942 view[-2] = 0x81;
1943 view[-1] = 0xc0 | reg;
1944 }
1945 else
1946 {
1947 // addq
1948 if (op1 == 0x4c)
1949 view[-3] = 0x4d;
1950 view[-2] = 0x8d;
1951 view[-1] = 0x80 | reg | (reg << 3);
1952 }
1953
6a41d30b 1954 value -= tls_segment->memsz();
56622147
ILT
1955 Relocate_functions<64, false>::rela32(view, value, 0);
1956}
1957
2e30d253
ILT
1958// Relocate section data.
1959
1960void
1961Target_x86_64::relocate_section(const Relocate_info<64, false>* relinfo,
d61c17ea
ILT
1962 unsigned int sh_type,
1963 const unsigned char* prelocs,
1964 size_t reloc_count,
730cdc88
ILT
1965 Output_section* output_section,
1966 bool needs_special_offset_handling,
d61c17ea
ILT
1967 unsigned char* view,
1968 elfcpp::Elf_types<64>::Elf_Addr address,
fe8718a4 1969 section_size_type view_size)
2e30d253
ILT
1970{
1971 gold_assert(sh_type == elfcpp::SHT_RELA);
1972
1973 gold::relocate_section<64, false, Target_x86_64, elfcpp::SHT_RELA,
1974 Target_x86_64::Relocate>(
1975 relinfo,
1976 this,
1977 prelocs,
1978 reloc_count,
730cdc88
ILT
1979 output_section,
1980 needs_special_offset_handling,
2e30d253
ILT
1981 view,
1982 address,
1983 view_size);
1984}
1985
6a74a719
ILT
1986// Return the size of a relocation while scanning during a relocatable
1987// link.
1988
1989unsigned int
1990Target_x86_64::Relocatable_size_for_reloc::get_size_for_reloc(
1991 unsigned int r_type,
1992 Relobj* object)
1993{
1994 switch (r_type)
1995 {
1996 case elfcpp::R_X86_64_NONE:
1997 case elfcpp::R_386_GNU_VTINHERIT:
1998 case elfcpp::R_386_GNU_VTENTRY:
1999 case elfcpp::R_X86_64_TLSGD: // Global-dynamic
2000 case elfcpp::R_X86_64_GOTPC32_TLSDESC: // Global-dynamic (from ~oliva url)
2001 case elfcpp::R_X86_64_TLSDESC_CALL:
2002 case elfcpp::R_X86_64_TLSLD: // Local-dynamic
2003 case elfcpp::R_X86_64_DTPOFF32:
2004 case elfcpp::R_X86_64_DTPOFF64:
2005 case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec
2006 case elfcpp::R_X86_64_TPOFF32: // Local-exec
2007 return 0;
2008
2009 case elfcpp::R_X86_64_64:
2010 case elfcpp::R_X86_64_PC64:
2011 case elfcpp::R_X86_64_GOTOFF64:
2012 case elfcpp::R_X86_64_GOTPC64:
2013 case elfcpp::R_X86_64_PLTOFF64:
2014 case elfcpp::R_X86_64_GOT64:
2015 case elfcpp::R_X86_64_GOTPCREL64:
2016 case elfcpp::R_X86_64_GOTPCREL:
2017 case elfcpp::R_X86_64_GOTPLT64:
2018 return 8;
2019
2020 case elfcpp::R_X86_64_32:
2021 case elfcpp::R_X86_64_32S:
2022 case elfcpp::R_X86_64_PC32:
2023 case elfcpp::R_X86_64_PLT32:
2024 case elfcpp::R_X86_64_GOTPC32:
2025 case elfcpp::R_X86_64_GOT32:
2026 return 4;
2027
2028 case elfcpp::R_X86_64_16:
2029 case elfcpp::R_X86_64_PC16:
2030 return 2;
2031
2032 case elfcpp::R_X86_64_8:
2033 case elfcpp::R_X86_64_PC8:
2034 return 1;
2035
2036 case elfcpp::R_X86_64_COPY:
2037 case elfcpp::R_X86_64_GLOB_DAT:
2038 case elfcpp::R_X86_64_JUMP_SLOT:
2039 case elfcpp::R_X86_64_RELATIVE:
2040 // These are outstanding tls relocs, which are unexpected when linking
2041 case elfcpp::R_X86_64_TPOFF64:
2042 case elfcpp::R_X86_64_DTPMOD64:
2043 case elfcpp::R_X86_64_TLSDESC:
2044 object->error(_("unexpected reloc %u in object file"), r_type);
2045 return 0;
2046
2047 case elfcpp::R_X86_64_SIZE32:
2048 case elfcpp::R_X86_64_SIZE64:
2049 default:
2050 object->error(_("unsupported reloc %u against local symbol"), r_type);
2051 return 0;
2052 }
2053}
2054
2055// Scan the relocs during a relocatable link.
2056
2057void
2058Target_x86_64::scan_relocatable_relocs(const General_options& options,
2059 Symbol_table* symtab,
2060 Layout* layout,
2061 Sized_relobj<64, false>* object,
2062 unsigned int data_shndx,
2063 unsigned int sh_type,
2064 const unsigned char* prelocs,
2065 size_t reloc_count,
2066 Output_section* output_section,
2067 bool needs_special_offset_handling,
2068 size_t local_symbol_count,
2069 const unsigned char* plocal_symbols,
2070 Relocatable_relocs* rr)
2071{
2072 gold_assert(sh_type == elfcpp::SHT_RELA);
2073
2074 typedef gold::Default_scan_relocatable_relocs<elfcpp::SHT_RELA,
2075 Relocatable_size_for_reloc> Scan_relocatable_relocs;
2076
2077 gold::scan_relocatable_relocs<64, false, Target_x86_64, elfcpp::SHT_RELA,
2078 Scan_relocatable_relocs>(
2079 options,
2080 symtab,
2081 layout,
2082 object,
2083 data_shndx,
2084 prelocs,
2085 reloc_count,
2086 output_section,
2087 needs_special_offset_handling,
2088 local_symbol_count,
2089 plocal_symbols,
2090 rr);
2091}
2092
2093// Relocate a section during a relocatable link.
2094
2095void
2096Target_x86_64::relocate_for_relocatable(
2097 const Relocate_info<64, false>* relinfo,
2098 unsigned int sh_type,
2099 const unsigned char* prelocs,
2100 size_t reloc_count,
2101 Output_section* output_section,
2102 off_t offset_in_output_section,
2103 const Relocatable_relocs* rr,
2104 unsigned char* view,
2105 elfcpp::Elf_types<64>::Elf_Addr view_address,
2106 section_size_type view_size,
2107 unsigned char* reloc_view,
2108 section_size_type reloc_view_size)
2109{
2110 gold_assert(sh_type == elfcpp::SHT_RELA);
2111
2112 gold::relocate_for_relocatable<64, false, Target_x86_64, elfcpp::SHT_RELA>(
2113 relinfo,
2114 prelocs,
2115 reloc_count,
2116 output_section,
2117 offset_in_output_section,
2118 rr,
2119 view,
2120 view_address,
2121 view_size,
2122 reloc_view,
2123 reloc_view_size);
2124}
2125
4fb6c25d
ILT
2126// Return the value to use for a dynamic which requires special
2127// treatment. This is how we support equality comparisons of function
2128// pointers across shared library boundaries, as described in the
2129// processor specific ABI supplement.
2130
2131uint64_t
2132Target_x86_64::do_dynsym_value(const Symbol* gsym) const
2133{
2134 gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
2135 return this->plt_section()->address() + gsym->plt_offset();
2136}
2137
2e30d253
ILT
2138// Return a string used to fill a code section with nops to take up
2139// the specified length.
2140
2141std::string
fe8718a4 2142Target_x86_64::do_code_fill(section_size_type length)
2e30d253
ILT
2143{
2144 if (length >= 16)
2145 {
2146 // Build a jmpq instruction to skip over the bytes.
2147 unsigned char jmp[5];
2148 jmp[0] = 0xe9;
2149 elfcpp::Swap_unaligned<64, false>::writeval(jmp + 1, length - 5);
2150 return (std::string(reinterpret_cast<char*>(&jmp[0]), 5)
2151 + std::string(length - 5, '\0'));
2152 }
2153
2154 // Nop sequences of various lengths.
2155 const char nop1[1] = { 0x90 }; // nop
2156 const char nop2[2] = { 0x66, 0x90 }; // xchg %ax %ax
2157 const char nop3[3] = { 0x8d, 0x76, 0x00 }; // leal 0(%esi),%esi
2158 const char nop4[4] = { 0x8d, 0x74, 0x26, 0x00}; // leal 0(%esi,1),%esi
2159 const char nop5[5] = { 0x90, 0x8d, 0x74, 0x26, // nop
2160 0x00 }; // leal 0(%esi,1),%esi
2161 const char nop6[6] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2162 0x00, 0x00 };
2163 const char nop7[7] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2164 0x00, 0x00, 0x00 };
2165 const char nop8[8] = { 0x90, 0x8d, 0xb4, 0x26, // nop
2166 0x00, 0x00, 0x00, 0x00 }; // leal 0L(%esi,1),%esi
2167 const char nop9[9] = { 0x89, 0xf6, 0x8d, 0xbc, // movl %esi,%esi
2168 0x27, 0x00, 0x00, 0x00, // leal 0L(%edi,1),%edi
2169 0x00 };
2170 const char nop10[10] = { 0x8d, 0x76, 0x00, 0x8d, // leal 0(%esi),%esi
2171 0xbc, 0x27, 0x00, 0x00, // leal 0L(%edi,1),%edi
2172 0x00, 0x00 };
2173 const char nop11[11] = { 0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi
2174 0x8d, 0xbc, 0x27, 0x00, // leal 0L(%edi,1),%edi
2175 0x00, 0x00, 0x00 };
2176 const char nop12[12] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2177 0x00, 0x00, 0x8d, 0xbf, // leal 0L(%edi),%edi
2178 0x00, 0x00, 0x00, 0x00 };
2179 const char nop13[13] = { 0x8d, 0xb6, 0x00, 0x00, // leal 0L(%esi),%esi
2180 0x00, 0x00, 0x8d, 0xbc, // leal 0L(%edi,1),%edi
2181 0x27, 0x00, 0x00, 0x00,
2182 0x00 };
2183 const char nop14[14] = { 0x8d, 0xb4, 0x26, 0x00, // leal 0L(%esi,1),%esi
2184 0x00, 0x00, 0x00, 0x8d, // leal 0L(%edi,1),%edi
2185 0xbc, 0x27, 0x00, 0x00,
2186 0x00, 0x00 };
2187 const char nop15[15] = { 0xeb, 0x0d, 0x90, 0x90, // jmp .+15
2188 0x90, 0x90, 0x90, 0x90, // nop,nop,nop,...
2189 0x90, 0x90, 0x90, 0x90,
2190 0x90, 0x90, 0x90 };
2191
2192 const char* nops[16] = {
2193 NULL,
2194 nop1, nop2, nop3, nop4, nop5, nop6, nop7,
2195 nop8, nop9, nop10, nop11, nop12, nop13, nop14, nop15
2196 };
2197
2198 return std::string(nops[length], length);
2199}
2200
2201// The selector for x86_64 object files.
2202
2203class Target_selector_x86_64 : public Target_selector
2204{
2205public:
2206 Target_selector_x86_64()
2207 : Target_selector(elfcpp::EM_X86_64, 64, false)
2208 { }
2209
2210 Target*
2211 recognize(int machine, int osabi, int abiversion);
2212
2213 private:
2214 Target_x86_64* target_;
2215};
2216
2217// Recognize an x86_64 object file when we already know that the machine
2218// number is EM_X86_64.
2219
2220Target*
2221Target_selector_x86_64::recognize(int, int, int)
2222{
2223 if (this->target_ == NULL)
2224 this->target_ = new Target_x86_64();
2225 return this->target_;
2226}
2227
2228Target_selector_x86_64 target_selector_x86_64;
2229
2230} // End anonymous namespace.
This page took 0.143654 seconds and 4 git commands to generate.