1 // x86_64.cc -- x86_64 target support for gold.
3 // Copyright (C) 2006-2023 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
29 #include "parameters.h"
36 #include "copy-relocs.h"
38 #include "target-reloc.h"
39 #include "target-select.h"
51 // A class to handle the .got.plt section.
53 class Output_data_got_plt_x86_64
: public Output_section_data_build
56 Output_data_got_plt_x86_64(Layout
* layout
)
57 : Output_section_data_build(8),
61 Output_data_got_plt_x86_64(Layout
* layout
, off_t data_size
)
62 : Output_section_data_build(data_size
, 8),
67 // Write out the PLT data.
69 do_write(Output_file
*);
71 // Write to a map file.
73 do_print_to_mapfile(Mapfile
* mapfile
) const
74 { mapfile
->print_output_data(this, "** GOT PLT"); }
77 // A pointer to the Layout class, so that we can find the .dynamic
78 // section when we write out the GOT PLT section.
82 // A class to handle the PLT data.
83 // This is an abstract base class that handles most of the linker details
84 // but does not know the actual contents of PLT entries. The derived
85 // classes below fill in those details.
88 class Output_data_plt_x86_64
: public Output_section_data
91 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, false> Reloc_section
;
93 Output_data_plt_x86_64(Layout
* layout
, uint64_t addralign
,
94 Output_data_got
<64, false>* got
,
95 Output_data_got_plt_x86_64
* got_plt
,
96 Output_data_space
* got_irelative
)
97 : Output_section_data(addralign
), tlsdesc_rel_(NULL
),
98 irelative_rel_(NULL
), got_(got
), got_plt_(got_plt
),
99 got_irelative_(got_irelative
), count_(0), irelative_count_(0),
100 tlsdesc_got_offset_(-1U), free_list_()
101 { this->init(layout
); }
103 Output_data_plt_x86_64(Layout
* layout
, uint64_t plt_entry_size
,
104 Output_data_got
<64, false>* got
,
105 Output_data_got_plt_x86_64
* got_plt
,
106 Output_data_space
* got_irelative
,
107 unsigned int plt_count
)
108 : Output_section_data((plt_count
+ 1) * plt_entry_size
,
109 plt_entry_size
, false),
110 tlsdesc_rel_(NULL
), irelative_rel_(NULL
), got_(got
),
111 got_plt_(got_plt
), got_irelative_(got_irelative
), count_(plt_count
),
112 irelative_count_(0), tlsdesc_got_offset_(-1U), free_list_()
116 // Initialize the free list and reserve the first entry.
117 this->free_list_
.init((plt_count
+ 1) * plt_entry_size
, false);
118 this->free_list_
.remove(0, plt_entry_size
);
121 // Initialize the PLT section.
123 init(Layout
* layout
);
125 // Add an entry to the PLT.
127 add_entry(Symbol_table
*, Layout
*, Symbol
* gsym
);
129 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
131 add_local_ifunc_entry(Symbol_table
* symtab
, Layout
*,
132 Sized_relobj_file
<size
, false>* relobj
,
133 unsigned int local_sym_index
);
135 // Add the relocation for a PLT entry.
137 add_relocation(Symbol_table
*, Layout
*, Symbol
* gsym
,
138 unsigned int got_offset
);
140 // Add the reserved TLSDESC_PLT entry to the PLT.
142 reserve_tlsdesc_entry(unsigned int got_offset
)
143 { this->tlsdesc_got_offset_
= got_offset
; }
145 // Return true if a TLSDESC_PLT entry has been reserved.
147 has_tlsdesc_entry() const
148 { return this->tlsdesc_got_offset_
!= -1U; }
150 // Return the GOT offset for the reserved TLSDESC_PLT entry.
152 get_tlsdesc_got_offset() const
153 { return this->tlsdesc_got_offset_
; }
155 // Return the offset of the reserved TLSDESC_PLT entry.
157 get_tlsdesc_plt_offset() const
159 return ((this->count_
+ this->irelative_count_
+ 1)
160 * this->get_plt_entry_size());
163 // Return the .rela.plt section data.
166 { return this->rel_
; }
168 // Return where the TLSDESC relocations should go.
170 rela_tlsdesc(Layout
*);
172 // Return where the IRELATIVE relocations should go in the PLT
175 rela_irelative(Symbol_table
*, Layout
*);
177 // Return whether we created a section for IRELATIVE relocations.
179 has_irelative_section() const
180 { return this->irelative_rel_
!= NULL
; }
182 // Get count of regular PLT entries.
184 regular_count() const
185 { return this->count_
; }
187 // Return the total number of PLT entries.
190 { return this->count_
+ this->irelative_count_
; }
192 // Return the offset of the first non-reserved PLT entry.
194 first_plt_entry_offset()
195 { return this->get_plt_entry_size(); }
197 // Return the size of a PLT entry.
199 get_plt_entry_size() const
200 { return this->do_get_plt_entry_size(); }
202 // Reserve a slot in the PLT for an existing symbol in an incremental update.
204 reserve_slot(unsigned int plt_index
)
206 this->free_list_
.remove((plt_index
+ 1) * this->get_plt_entry_size(),
207 (plt_index
+ 2) * this->get_plt_entry_size());
210 // Return the PLT address to use for a global symbol.
212 address_for_global(const Symbol
* sym
)
213 { return do_address_for_global(sym
); }
215 // Return the PLT address to use for a local symbol.
217 address_for_local(const Relobj
* obj
, unsigned int symndx
)
218 { return do_address_for_local(obj
, symndx
); }
220 // Add .eh_frame information for the PLT.
222 add_eh_frame(Layout
* layout
)
223 { this->do_add_eh_frame(layout
); }
226 Output_data_got
<64, false>*
228 { return this->got_
; }
230 Output_data_got_plt_x86_64
*
232 { return this->got_plt_
; }
235 got_irelative() const
236 { return this->got_irelative_
; }
238 // Fill in the first PLT entry.
240 fill_first_plt_entry(unsigned char* pov
,
241 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
242 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
)
243 { this->do_fill_first_plt_entry(pov
, got_address
, plt_address
); }
245 // Fill in a normal PLT entry. Returns the offset into the entry that
246 // should be the initial GOT slot value.
248 fill_plt_entry(unsigned char* pov
,
249 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
250 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
251 unsigned int got_offset
,
252 unsigned int plt_offset
,
253 unsigned int plt_index
)
255 return this->do_fill_plt_entry(pov
, got_address
, plt_address
,
256 got_offset
, plt_offset
, plt_index
);
259 // Fill in the reserved TLSDESC PLT entry.
261 fill_tlsdesc_entry(unsigned char* pov
,
262 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
263 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
264 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
265 unsigned int tlsdesc_got_offset
,
266 unsigned int plt_offset
)
268 this->do_fill_tlsdesc_entry(pov
, got_address
, plt_address
, got_base
,
269 tlsdesc_got_offset
, plt_offset
);
273 do_get_plt_entry_size() const = 0;
276 do_fill_first_plt_entry(unsigned char* pov
,
277 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_addr
,
278 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_addr
)
282 do_fill_plt_entry(unsigned char* pov
,
283 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
284 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
285 unsigned int got_offset
,
286 unsigned int plt_offset
,
287 unsigned int plt_index
) = 0;
290 do_fill_tlsdesc_entry(unsigned char* pov
,
291 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
292 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
293 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
294 unsigned int tlsdesc_got_offset
,
295 unsigned int plt_offset
) = 0;
297 // Return the PLT address to use for a global symbol.
299 do_address_for_global(const Symbol
* sym
);
301 // Return the PLT address to use for a local symbol.
303 do_address_for_local(const Relobj
* obj
, unsigned int symndx
);
306 do_add_eh_frame(Layout
* layout
) = 0;
309 do_adjust_output_section(Output_section
* os
);
311 // Write to a map file.
313 do_print_to_mapfile(Mapfile
* mapfile
) const
314 { mapfile
->print_output_data(this, _("** PLT")); }
316 // The CIE of the .eh_frame unwind information for the PLT.
317 static const int plt_eh_frame_cie_size
= 16;
318 static const unsigned char plt_eh_frame_cie
[plt_eh_frame_cie_size
];
321 // Set the final size.
323 set_final_data_size();
325 // Write out the PLT data.
327 do_write(Output_file
*);
329 // The reloc section.
331 // The TLSDESC relocs, if necessary. These must follow the regular
333 Reloc_section
* tlsdesc_rel_
;
334 // The IRELATIVE relocs, if necessary. These must follow the
335 // regular PLT relocations and the TLSDESC relocations.
336 Reloc_section
* irelative_rel_
;
338 Output_data_got
<64, false>* got_
;
339 // The .got.plt section.
340 Output_data_got_plt_x86_64
* got_plt_
;
341 // The part of the .got.plt section used for IRELATIVE relocs.
342 Output_data_space
* got_irelative_
;
343 // The number of PLT entries.
345 // Number of PLT entries with R_X86_64_IRELATIVE relocs. These
346 // follow the regular PLT entries.
347 unsigned int irelative_count_
;
348 // Offset of the reserved TLSDESC_GOT entry when needed.
349 unsigned int tlsdesc_got_offset_
;
350 // List of available regions within the section, for incremental
352 Free_list free_list_
;
356 class Output_data_plt_x86_64_standard
: public Output_data_plt_x86_64
<size
>
359 Output_data_plt_x86_64_standard(Layout
* layout
,
360 Output_data_got
<64, false>* got
,
361 Output_data_got_plt_x86_64
* got_plt
,
362 Output_data_space
* got_irelative
)
363 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
364 got
, got_plt
, got_irelative
)
367 Output_data_plt_x86_64_standard(Layout
* layout
,
368 Output_data_got
<64, false>* got
,
369 Output_data_got_plt_x86_64
* got_plt
,
370 Output_data_space
* got_irelative
,
371 unsigned int plt_count
)
372 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
373 got
, got_plt
, got_irelative
,
379 do_get_plt_entry_size() const
380 { return plt_entry_size
; }
383 do_add_eh_frame(Layout
* layout
)
385 layout
->add_eh_frame_for_plt(this,
386 this->plt_eh_frame_cie
,
387 this->plt_eh_frame_cie_size
,
389 plt_eh_frame_fde_size
);
393 do_fill_first_plt_entry(unsigned char* pov
,
394 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_addr
,
395 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_addr
);
398 do_fill_plt_entry(unsigned char* pov
,
399 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
400 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
401 unsigned int got_offset
,
402 unsigned int plt_offset
,
403 unsigned int plt_index
);
406 do_fill_tlsdesc_entry(unsigned char* pov
,
407 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
408 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
409 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
410 unsigned int tlsdesc_got_offset
,
411 unsigned int plt_offset
);
414 // The size of an entry in the PLT.
415 static const int plt_entry_size
= 16;
417 // The first entry in the PLT.
418 // From the AMD64 ABI: "Unlike Intel386 ABI, this ABI uses the same
419 // procedure linkage table for both programs and shared objects."
420 static const unsigned char first_plt_entry
[plt_entry_size
];
422 // Other entries in the PLT for an executable.
423 static const unsigned char plt_entry
[plt_entry_size
];
425 // The reserved TLSDESC entry in the PLT for an executable.
426 static const unsigned char tlsdesc_plt_entry
[plt_entry_size
];
428 // The .eh_frame unwind information for the PLT.
429 static const int plt_eh_frame_fde_size
= 32;
430 static const unsigned char plt_eh_frame_fde
[plt_eh_frame_fde_size
];
433 // We use this PLT when Indirect Branch Tracking (IBT) is enabled.
436 class Output_data_plt_x86_64_ibt
: public Output_data_plt_x86_64
<size
>
439 Output_data_plt_x86_64_ibt(Layout
* layout
,
440 Output_data_got
<64, false>* got
,
441 Output_data_got_plt_x86_64
* got_plt
,
442 Output_data_space
* got_irelative
)
443 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
444 got
, got_plt
, got_irelative
),
448 Output_data_plt_x86_64_ibt(Layout
* layout
,
449 Output_data_got
<64, false>* got
,
450 Output_data_got_plt_x86_64
* got_plt
,
451 Output_data_space
* got_irelative
,
452 unsigned int plt_count
)
453 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
454 got
, got_plt
, got_irelative
,
461 do_get_plt_entry_size() const
462 { return plt_entry_size
; }
464 // Return the PLT address to use for a global symbol.
466 do_address_for_global(const Symbol
*);
468 // Return the PLT address to use for a local symbol.
470 do_address_for_local(const Relobj
*, unsigned int symndx
);
473 do_add_eh_frame(Layout
* layout
)
475 layout
->add_eh_frame_for_plt(this,
476 this->plt_eh_frame_cie
,
477 this->plt_eh_frame_cie_size
,
479 plt_eh_frame_fde_size
);
483 do_fill_first_plt_entry(unsigned char* pov
,
484 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_addr
,
485 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_addr
);
488 do_fill_plt_entry(unsigned char* pov
,
489 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
490 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
491 unsigned int got_offset
,
492 unsigned int plt_offset
,
493 unsigned int plt_index
);
496 do_fill_tlsdesc_entry(unsigned char* pov
,
497 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
498 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
499 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
500 unsigned int tlsdesc_got_offset
,
501 unsigned int plt_offset
);
504 fill_aplt_entry(unsigned char* pov
,
505 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
506 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
507 unsigned int got_offset
,
508 unsigned int plt_offset
,
509 unsigned int plt_index
);
512 // Set the final size.
514 set_final_data_size();
516 // Write out the PLT data.
518 do_write(Output_file
*);
520 // Offset of the Additional PLT (if using -z bndplt).
521 unsigned int aplt_offset_
;
523 // The size of an entry in the PLT.
524 static const int plt_entry_size
= 16;
526 // The size of an entry in the additional PLT.
527 static const int aplt_entry_size
= 16;
529 // The first entry in the PLT.
530 // From the AMD64 ABI: "Unlike Intel386 ABI, this ABI uses the same
531 // procedure linkage table for both programs and shared objects."
532 static const unsigned char first_plt_entry
[plt_entry_size
];
534 // Other entries in the PLT for an executable.
535 static const unsigned char plt_entry
[plt_entry_size
];
537 // Entries in the additional PLT.
538 static const unsigned char aplt_entry
[aplt_entry_size
];
540 // The reserved TLSDESC entry in the PLT for an executable.
541 static const unsigned char tlsdesc_plt_entry
[plt_entry_size
];
543 // The .eh_frame unwind information for the PLT.
544 static const int plt_eh_frame_fde_size
= 32;
545 static const unsigned char plt_eh_frame_fde
[plt_eh_frame_fde_size
];
552 Lazy_view(Sized_relobj_file
<size
, false>* object
, unsigned int data_shndx
)
553 : object_(object
), data_shndx_(data_shndx
), view_(NULL
), view_size_(0)
557 operator[](size_t offset
)
559 if (this->view_
== NULL
)
560 this->view_
= this->object_
->section_contents(this->data_shndx_
,
563 if (offset
>= this->view_size_
)
565 return this->view_
[offset
];
569 Sized_relobj_file
<size
, false>* object_
;
570 unsigned int data_shndx_
;
571 const unsigned char* view_
;
572 section_size_type view_size_
;
575 // The x86_64 target class.
577 // http://www.x86-64.org/documentation/abi.pdf
578 // TLS info comes from
579 // http://people.redhat.com/drepper/tls.pdf
580 // http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt
583 class Target_x86_64
: public Sized_target
<size
, false>
586 // In the x86_64 ABI (p 68), it says "The AMD64 ABI architectures
587 // uses only Elf64_Rela relocation entries with explicit addends."
588 typedef Output_data_reloc
<elfcpp::SHT_RELA
, true, size
, false> Reloc_section
;
590 Target_x86_64(const Target::Target_info
* info
= &x86_64_info
)
591 : Sized_target
<size
, false>(info
),
592 got_(NULL
), plt_(NULL
), got_plt_(NULL
), got_irelative_(NULL
),
593 got_tlsdesc_(NULL
), global_offset_table_(NULL
), rela_dyn_(NULL
),
594 rela_irelative_(NULL
), copy_relocs_(elfcpp::R_X86_64_COPY
),
595 got_mod_index_offset_(-1U), tlsdesc_reloc_info_(),
596 tls_base_symbol_defined_(false), isa_1_used_(0), isa_1_needed_(0),
597 feature_1_(0), feature_2_used_(0), feature_2_needed_(0),
598 object_isa_1_used_(0), object_feature_1_(0),
599 object_feature_2_used_(0), seen_first_object_(false)
602 // Hook for a new output section.
604 do_new_output_section(Output_section
*) const;
606 // Scan the relocations to look for symbol adjustments.
608 gc_process_relocs(Symbol_table
* symtab
,
610 Sized_relobj_file
<size
, false>* object
,
611 unsigned int data_shndx
,
612 unsigned int sh_type
,
613 const unsigned char* prelocs
,
615 Output_section
* output_section
,
616 bool needs_special_offset_handling
,
617 size_t local_symbol_count
,
618 const unsigned char* plocal_symbols
);
620 // Scan the relocations to look for symbol adjustments.
622 scan_relocs(Symbol_table
* symtab
,
624 Sized_relobj_file
<size
, false>* object
,
625 unsigned int data_shndx
,
626 unsigned int sh_type
,
627 const unsigned char* prelocs
,
629 Output_section
* output_section
,
630 bool needs_special_offset_handling
,
631 size_t local_symbol_count
,
632 const unsigned char* plocal_symbols
);
634 // Finalize the sections.
636 do_finalize_sections(Layout
*, const Input_objects
*, Symbol_table
*);
638 // Return the value to use for a dynamic which requires special
641 do_dynsym_value(const Symbol
*) const;
643 // Relocate a section.
645 relocate_section(const Relocate_info
<size
, false>*,
646 unsigned int sh_type
,
647 const unsigned char* prelocs
,
649 Output_section
* output_section
,
650 bool needs_special_offset_handling
,
652 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
653 section_size_type view_size
,
654 const Reloc_symbol_changes
*);
656 // Scan the relocs during a relocatable link.
658 scan_relocatable_relocs(Symbol_table
* symtab
,
660 Sized_relobj_file
<size
, false>* object
,
661 unsigned int data_shndx
,
662 unsigned int sh_type
,
663 const unsigned char* prelocs
,
665 Output_section
* output_section
,
666 bool needs_special_offset_handling
,
667 size_t local_symbol_count
,
668 const unsigned char* plocal_symbols
,
669 Relocatable_relocs
*);
671 // Scan the relocs for --emit-relocs.
673 emit_relocs_scan(Symbol_table
* symtab
,
675 Sized_relobj_file
<size
, false>* object
,
676 unsigned int data_shndx
,
677 unsigned int sh_type
,
678 const unsigned char* prelocs
,
680 Output_section
* output_section
,
681 bool needs_special_offset_handling
,
682 size_t local_symbol_count
,
683 const unsigned char* plocal_syms
,
684 Relocatable_relocs
* rr
);
686 // Emit relocations for a section.
689 const Relocate_info
<size
, false>*,
690 unsigned int sh_type
,
691 const unsigned char* prelocs
,
693 Output_section
* output_section
,
694 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
696 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
697 section_size_type view_size
,
698 unsigned char* reloc_view
,
699 section_size_type reloc_view_size
);
701 // Return a string used to fill a code section with nops.
703 do_code_fill(section_size_type length
) const;
705 // Return whether SYM is defined by the ABI.
707 do_is_defined_by_abi(const Symbol
* sym
) const
708 { return strcmp(sym
->name(), "__tls_get_addr") == 0; }
710 // Return the symbol index to use for a target specific relocation.
711 // The only target specific relocation is R_X86_64_TLSDESC for a
712 // local symbol, which is an absolute reloc.
714 do_reloc_symbol_index(void*, unsigned int r_type
) const
716 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC
);
720 // Return the addend to use for a target specific relocation.
722 do_reloc_addend(void* arg
, unsigned int r_type
, uint64_t addend
) const;
724 // Return the PLT section.
726 do_plt_address_for_global(const Symbol
* gsym
) const
727 { return this->plt_section()->address_for_global(gsym
); }
730 do_plt_address_for_local(const Relobj
* relobj
, unsigned int symndx
) const
731 { return this->plt_section()->address_for_local(relobj
, symndx
); }
733 // This function should be defined in targets that can use relocation
734 // types to determine (implemented in local_reloc_may_be_function_pointer
735 // and global_reloc_may_be_function_pointer)
736 // if a function's pointer is taken. ICF uses this in safe mode to only
737 // fold those functions whose pointer is defintely not taken. For x86_64
738 // pie binaries, safe ICF cannot be done by looking at only relocation
739 // types, and for certain cases (e.g. R_X86_64_PC32), the instruction
740 // opcode is checked as well to distinguish a function call from taking
741 // a function's pointer.
743 do_can_check_for_function_pointers() const
746 // Return the base for a DW_EH_PE_datarel encoding.
748 do_ehframe_datarel_base() const;
750 // Adjust -fsplit-stack code which calls non-split-stack code.
752 do_calls_non_split(Relobj
* object
, unsigned int shndx
,
753 section_offset_type fnoffset
, section_size_type fnsize
,
754 const unsigned char* prelocs
, size_t reloc_count
,
755 unsigned char* view
, section_size_type view_size
,
756 std::string
* from
, std::string
* to
) const;
758 // Return the size of the GOT section.
762 gold_assert(this->got_
!= NULL
);
763 return this->got_
->data_size();
766 // Return the number of entries in the GOT.
768 got_entry_count() const
770 if (this->got_
== NULL
)
772 return this->got_size() / 8;
775 // Return the number of entries in the PLT.
777 plt_entry_count() const;
779 // Return the offset of the first non-reserved PLT entry.
781 first_plt_entry_offset() const;
783 // Return the size of each PLT entry.
785 plt_entry_size() const;
787 // Return the size of each GOT entry.
789 got_entry_size() const
792 // Create the GOT section for an incremental update.
793 Output_data_got_base
*
794 init_got_plt_for_update(Symbol_table
* symtab
,
796 unsigned int got_count
,
797 unsigned int plt_count
);
799 // Reserve a GOT entry for a local symbol, and regenerate any
800 // necessary dynamic relocations.
802 reserve_local_got_entry(unsigned int got_index
,
803 Sized_relobj
<size
, false>* obj
,
805 unsigned int got_type
);
807 // Reserve a GOT entry for a global symbol, and regenerate any
808 // necessary dynamic relocations.
810 reserve_global_got_entry(unsigned int got_index
, Symbol
* gsym
,
811 unsigned int got_type
);
813 // Register an existing PLT entry for a global symbol.
815 register_global_plt_entry(Symbol_table
*, Layout
*, unsigned int plt_index
,
818 // Force a COPY relocation for a given symbol.
820 emit_copy_reloc(Symbol_table
*, Symbol
*, Output_section
*, off_t
);
822 // Apply an incremental relocation.
824 apply_relocation(const Relocate_info
<size
, false>* relinfo
,
825 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
827 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
830 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
831 section_size_type view_size
);
833 // Add a new reloc argument, returning the index in the vector.
835 add_tlsdesc_info(Sized_relobj_file
<size
, false>* object
, unsigned int r_sym
)
837 this->tlsdesc_reloc_info_
.push_back(Tlsdesc_info(object
, r_sym
));
838 return this->tlsdesc_reloc_info_
.size() - 1;
841 Output_data_plt_x86_64
<size
>*
842 make_data_plt(Layout
* layout
,
843 Output_data_got
<64, false>* got
,
844 Output_data_got_plt_x86_64
* got_plt
,
845 Output_data_space
* got_irelative
)
847 return this->do_make_data_plt(layout
, got
, got_plt
, got_irelative
);
850 Output_data_plt_x86_64
<size
>*
851 make_data_plt(Layout
* layout
,
852 Output_data_got
<64, false>* got
,
853 Output_data_got_plt_x86_64
* got_plt
,
854 Output_data_space
* got_irelative
,
855 unsigned int plt_count
)
857 return this->do_make_data_plt(layout
, got
, got_plt
, got_irelative
,
861 virtual Output_data_plt_x86_64
<size
>*
862 do_make_data_plt(Layout
* layout
,
863 Output_data_got
<64, false>* got
,
864 Output_data_got_plt_x86_64
* got_plt
,
865 Output_data_space
* got_irelative
);
867 virtual Output_data_plt_x86_64
<size
>*
868 do_make_data_plt(Layout
* layout
,
869 Output_data_got
<64, false>* got
,
870 Output_data_got_plt_x86_64
* got_plt
,
871 Output_data_space
* got_irelative
,
872 unsigned int plt_count
);
875 // The class which scans relocations.
880 : issued_non_pic_error_(false)
884 get_reference_flags(unsigned int r_type
);
887 local(Symbol_table
* symtab
, Layout
* layout
, Target_x86_64
* target
,
888 Sized_relobj_file
<size
, false>* object
,
889 unsigned int data_shndx
,
890 Output_section
* output_section
,
891 const elfcpp::Rela
<size
, false>& reloc
, unsigned int r_type
,
892 const elfcpp::Sym
<size
, false>& lsym
,
896 global(Symbol_table
* symtab
, Layout
* layout
, Target_x86_64
* target
,
897 Sized_relobj_file
<size
, false>* object
,
898 unsigned int data_shndx
,
899 Output_section
* output_section
,
900 const elfcpp::Rela
<size
, false>& reloc
, unsigned int r_type
,
904 local_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
905 Target_x86_64
* target
,
906 Sized_relobj_file
<size
, false>* object
,
907 unsigned int data_shndx
,
908 Output_section
* output_section
,
909 const elfcpp::Rela
<size
, false>& reloc
,
911 const elfcpp::Sym
<size
, false>& lsym
);
914 global_reloc_may_be_function_pointer(Symbol_table
* symtab
, Layout
* layout
,
915 Target_x86_64
* target
,
916 Sized_relobj_file
<size
, false>* object
,
917 unsigned int data_shndx
,
918 Output_section
* output_section
,
919 const elfcpp::Rela
<size
, false>& reloc
,
925 unsupported_reloc_local(Sized_relobj_file
<size
, false>*,
926 unsigned int r_type
);
929 unsupported_reloc_global(Sized_relobj_file
<size
, false>*,
930 unsigned int r_type
, Symbol
*);
933 check_non_pic(Relobj
*, unsigned int r_type
, Symbol
*);
936 possible_function_pointer_reloc(Sized_relobj_file
<size
, false>* src_obj
,
937 unsigned int src_indx
,
938 unsigned int r_offset
,
939 unsigned int r_type
);
942 reloc_needs_plt_for_ifunc(Sized_relobj_file
<size
, false>*,
943 unsigned int r_type
);
945 // Whether we have issued an error about a non-PIC compilation.
946 bool issued_non_pic_error_
;
949 // The class which implements relocation.
954 : skip_call_tls_get_addr_(false)
959 if (this->skip_call_tls_get_addr_
)
961 // FIXME: This needs to specify the location somehow.
962 gold_error(_("missing expected TLS relocation"));
966 // Do a relocation. Return false if the caller should not issue
967 // any warnings about this relocation.
969 relocate(const Relocate_info
<size
, false>*, unsigned int,
970 Target_x86_64
*, Output_section
*, size_t, const unsigned char*,
971 const Sized_symbol
<size
>*, const Symbol_value
<size
>*,
972 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
976 // Do a TLS relocation.
978 relocate_tls(const Relocate_info
<size
, false>*, Target_x86_64
*,
979 size_t relnum
, const elfcpp::Rela
<size
, false>&,
980 unsigned int r_type
, const Sized_symbol
<size
>*,
981 const Symbol_value
<size
>*,
982 unsigned char*, typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
985 // Do a TLS General-Dynamic to Initial-Exec transition.
987 tls_gd_to_ie(const Relocate_info
<size
, false>*, size_t relnum
,
988 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
989 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
991 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
992 section_size_type view_size
);
994 // Do a TLS General-Dynamic to Local-Exec transition.
996 tls_gd_to_le(const Relocate_info
<size
, false>*, size_t relnum
,
997 Output_segment
* tls_segment
,
998 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
999 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1000 unsigned char* view
,
1001 section_size_type view_size
);
1003 // Do a TLSDESC-style General-Dynamic to Initial-Exec transition.
1005 tls_desc_gd_to_ie(const Relocate_info
<size
, false>*, size_t relnum
,
1006 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
1007 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1008 unsigned char* view
,
1009 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
1010 section_size_type view_size
);
1012 // Do a TLSDESC-style General-Dynamic to Local-Exec transition.
1014 tls_desc_gd_to_le(const Relocate_info
<size
, false>*, size_t relnum
,
1015 Output_segment
* tls_segment
,
1016 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
1017 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1018 unsigned char* view
,
1019 section_size_type view_size
);
1021 // Do a TLS Local-Dynamic to Local-Exec transition.
1023 tls_ld_to_le(const Relocate_info
<size
, false>*, size_t relnum
,
1024 Output_segment
* tls_segment
,
1025 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
1026 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1027 unsigned char* view
,
1028 section_size_type view_size
);
1030 // Do a TLS Initial-Exec to Local-Exec transition.
1032 tls_ie_to_le(const Relocate_info
<size
, false>*, size_t relnum
,
1033 Output_segment
* tls_segment
,
1034 const elfcpp::Rela
<size
, false>&, unsigned int r_type
,
1035 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
1036 unsigned char* view
,
1037 section_size_type view_size
);
1039 // This is set if we should skip the next reloc, which should be a
1040 // PLT32 reloc against ___tls_get_addr.
1041 bool skip_call_tls_get_addr_
;
1044 // Check if relocation against this symbol is a candidate for
1046 // mov foo@GOTPCREL(%rip), %reg
1047 // to lea foo(%rip), %reg.
1048 template<class View_type
>
1050 can_convert_mov_to_lea(const Symbol
* gsym
, unsigned int r_type
,
1051 size_t r_offset
, View_type
* view
)
1053 gold_assert(gsym
!= NULL
);
1054 // We cannot do the conversion unless it's one of these relocations.
1055 if (r_type
!= elfcpp::R_X86_64_GOTPCREL
1056 && r_type
!= elfcpp::R_X86_64_GOTPCRELX
1057 && r_type
!= elfcpp::R_X86_64_REX_GOTPCRELX
)
1059 // We cannot convert references to IFUNC symbols, or to symbols that
1060 // are not local to the current module.
1061 // We can't do predefined symbols because they may become undefined
1062 // (e.g., __ehdr_start when the headers aren't mapped to a segment).
1063 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1064 || gsym
->is_undefined()
1065 || gsym
->is_predefined()
1066 || gsym
->is_from_dynobj()
1067 || gsym
->is_preemptible())
1069 // If we are building a shared object and the symbol is protected, we may
1070 // need to go through the GOT.
1071 if (parameters
->options().shared()
1072 && gsym
->visibility() == elfcpp::STV_PROTECTED
)
1074 // We cannot convert references to the _DYNAMIC symbol.
1075 if (strcmp(gsym
->name(), "_DYNAMIC") == 0)
1077 // Check for a MOV opcode.
1078 return (*view
)[r_offset
- 2] == 0x8b;
1082 // callq *foo@GOTPCRELX(%rip) to
1084 // and jmpq *foo@GOTPCRELX(%rip) to
1087 template<class View_type
>
1089 can_convert_callq_to_direct(const Symbol
* gsym
, unsigned int r_type
,
1090 size_t r_offset
, View_type
* view
)
1092 gold_assert(gsym
!= NULL
);
1093 // We cannot do the conversion unless it's a GOTPCRELX relocation.
1094 if (r_type
!= elfcpp::R_X86_64_GOTPCRELX
)
1096 // We cannot convert references to IFUNC symbols, or to symbols that
1097 // are not local to the current module.
1098 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1099 || gsym
->is_undefined ()
1100 || gsym
->is_from_dynobj()
1101 || gsym
->is_preemptible())
1103 // Check for a CALLQ or JMPQ opcode.
1104 return ((*view
)[r_offset
- 2] == 0xff
1105 && ((*view
)[r_offset
- 1] == 0x15
1106 || (*view
)[r_offset
- 1] == 0x25));
1109 // Adjust TLS relocation type based on the options and whether this
1110 // is a local symbol.
1111 static tls::Tls_optimization
1112 optimize_tls_reloc(bool is_final
, int r_type
);
1114 // Get the GOT section, creating it if necessary.
1115 Output_data_got
<64, false>*
1116 got_section(Symbol_table
*, Layout
*);
1118 // Get the GOT PLT section.
1119 Output_data_got_plt_x86_64
*
1120 got_plt_section() const
1122 gold_assert(this->got_plt_
!= NULL
);
1123 return this->got_plt_
;
1126 // Get the GOT section for TLSDESC entries.
1127 Output_data_got
<64, false>*
1128 got_tlsdesc_section() const
1130 gold_assert(this->got_tlsdesc_
!= NULL
);
1131 return this->got_tlsdesc_
;
1134 // Create the PLT section.
1136 make_plt_section(Symbol_table
* symtab
, Layout
* layout
);
1138 // Create a PLT entry for a global symbol.
1140 make_plt_entry(Symbol_table
*, Layout
*, Symbol
*);
1142 // Create a PLT entry for a local STT_GNU_IFUNC symbol.
1144 make_local_ifunc_plt_entry(Symbol_table
*, Layout
*,
1145 Sized_relobj_file
<size
, false>* relobj
,
1146 unsigned int local_sym_index
);
1148 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
1150 define_tls_base_symbol(Symbol_table
*, Layout
*);
1152 // Create the reserved PLT and GOT entries for the TLS descriptor resolver.
1154 reserve_tlsdesc_entries(Symbol_table
* symtab
, Layout
* layout
);
1156 // Create a GOT entry for the TLS module index.
1158 got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
1159 Sized_relobj_file
<size
, false>* object
);
1161 // Get the PLT section.
1162 Output_data_plt_x86_64
<size
>*
1165 gold_assert(this->plt_
!= NULL
);
1169 // Get the dynamic reloc section, creating it if necessary.
1171 rela_dyn_section(Layout
*);
1173 // Get the section to use for TLSDESC relocations.
1175 rela_tlsdesc_section(Layout
*) const;
1177 // Get the section to use for IRELATIVE relocations.
1179 rela_irelative_section(Layout
*);
1181 // Add a potential copy relocation.
1183 copy_reloc(Symbol_table
* symtab
, Layout
* layout
,
1184 Sized_relobj_file
<size
, false>* object
,
1185 unsigned int shndx
, Output_section
* output_section
,
1186 Symbol
* sym
, const elfcpp::Rela
<size
, false>& reloc
)
1188 unsigned int r_type
= elfcpp::elf_r_type
<size
>(reloc
.get_r_info());
1189 this->copy_relocs_
.copy_reloc(symtab
, layout
,
1190 symtab
->get_sized_symbol
<size
>(sym
),
1191 object
, shndx
, output_section
,
1192 r_type
, reloc
.get_r_offset(),
1193 reloc
.get_r_addend(),
1194 this->rela_dyn_section(layout
));
1197 // Record a target-specific program property in the .note.gnu.property
1200 record_gnu_property(unsigned int, unsigned int, size_t,
1201 const unsigned char*, const Object
*);
1203 // Merge the target-specific program properties from the current object.
1205 merge_gnu_properties(const Object
*);
1207 // Finalize the target-specific program properties and add them back to
1210 do_finalize_gnu_properties(Layout
*) const;
1212 // Information about this specific target which we pass to the
1213 // general Target structure.
1214 static const Target::Target_info x86_64_info
;
1216 // The types of GOT entries needed for this platform.
1217 // These values are exposed to the ABI in an incremental link.
1218 // Do not renumber existing values without changing the version
1219 // number of the .gnu_incremental_inputs section.
1222 GOT_TYPE_STANDARD
= 0, // GOT entry for a regular symbol
1223 GOT_TYPE_TLS_OFFSET
= 1, // GOT entry for TLS offset
1224 GOT_TYPE_TLS_PAIR
= 2, // GOT entry for TLS module/offset pair
1225 GOT_TYPE_TLS_DESC
= 3 // GOT entry for TLS_DESC pair
1228 // This type is used as the argument to the target specific
1229 // relocation routines. The only target specific reloc is
1230 // R_X86_64_TLSDESC against a local symbol.
1233 Tlsdesc_info(Sized_relobj_file
<size
, false>* a_object
, unsigned int a_r_sym
)
1234 : object(a_object
), r_sym(a_r_sym
)
1237 // The object in which the local symbol is defined.
1238 Sized_relobj_file
<size
, false>* object
;
1239 // The local symbol index in the object.
1244 Output_data_got
<64, false>* got_
;
1246 Output_data_plt_x86_64
<size
>* plt_
;
1247 // The GOT PLT section.
1248 Output_data_got_plt_x86_64
* got_plt_
;
1249 // The GOT section for IRELATIVE relocations.
1250 Output_data_space
* got_irelative_
;
1251 // The GOT section for TLSDESC relocations.
1252 Output_data_got
<64, false>* got_tlsdesc_
;
1253 // The _GLOBAL_OFFSET_TABLE_ symbol.
1254 Symbol
* global_offset_table_
;
1255 // The dynamic reloc section.
1256 Reloc_section
* rela_dyn_
;
1257 // The section to use for IRELATIVE relocs.
1258 Reloc_section
* rela_irelative_
;
1259 // Relocs saved to avoid a COPY reloc.
1260 Copy_relocs
<elfcpp::SHT_RELA
, size
, false> copy_relocs_
;
1261 // Offset of the GOT entry for the TLS module index.
1262 unsigned int got_mod_index_offset_
;
1263 // We handle R_X86_64_TLSDESC against a local symbol as a target
1264 // specific relocation. Here we store the object and local symbol
1265 // index for the relocation.
1266 std::vector
<Tlsdesc_info
> tlsdesc_reloc_info_
;
1267 // True if the _TLS_MODULE_BASE_ symbol has been defined.
1268 bool tls_base_symbol_defined_
;
1269 // Target-specific program properties, from .note.gnu.property section.
1270 // Each bit represents a specific feature.
1271 uint32_t isa_1_used_
;
1272 uint32_t isa_1_needed_
;
1273 uint32_t feature_1_
;
1274 uint32_t feature_2_used_
;
1275 uint32_t feature_2_needed_
;
1276 // Target-specific properties from the current object.
1277 // These bits get ORed into ISA_1_USED_ after all properties for the object
1278 // have been processed. But if either is all zeroes (as when the property
1279 // is absent from an object), the result should be all zeroes.
1280 // (See PR ld/23486.)
1281 uint32_t object_isa_1_used_
;
1282 // These bits get ANDed into FEATURE_1_ after all properties for the object
1283 // have been processed.
1284 uint32_t object_feature_1_
;
1285 uint32_t object_feature_2_used_
;
1286 // Whether we have seen our first object, for use in initializing FEATURE_1_.
1287 bool seen_first_object_
;
1291 const Target::Target_info Target_x86_64
<64>::x86_64_info
=
1294 false, // is_big_endian
1295 elfcpp::EM_X86_64
, // machine_code
1296 false, // has_make_symbol
1297 false, // has_resolve
1298 true, // has_code_fill
1299 true, // is_default_stack_executable
1300 true, // can_icf_inline_merge_sections
1302 "/lib/ld64.so.1", // program interpreter
1303 0x400000, // default_text_segment_address
1304 0x1000, // abi_pagesize (overridable by -z max-page-size)
1305 0x1000, // common_pagesize (overridable by -z common-page-size)
1306 false, // isolate_execinstr
1308 elfcpp::SHN_UNDEF
, // small_common_shndx
1309 elfcpp::SHN_X86_64_LCOMMON
, // large_common_shndx
1310 0, // small_common_section_flags
1311 elfcpp::SHF_X86_64_LARGE
, // large_common_section_flags
1312 NULL
, // attributes_section
1313 NULL
, // attributes_vendor
1314 "_start", // entry_symbol_name
1315 32, // hash_entry_size
1316 elfcpp::SHT_X86_64_UNWIND
, // unwind_section_type
1320 const Target::Target_info Target_x86_64
<32>::x86_64_info
=
1323 false, // is_big_endian
1324 elfcpp::EM_X86_64
, // machine_code
1325 false, // has_make_symbol
1326 false, // has_resolve
1327 true, // has_code_fill
1328 true, // is_default_stack_executable
1329 true, // can_icf_inline_merge_sections
1331 "/libx32/ldx32.so.1", // program interpreter
1332 0x400000, // default_text_segment_address
1333 0x1000, // abi_pagesize (overridable by -z max-page-size)
1334 0x1000, // common_pagesize (overridable by -z common-page-size)
1335 false, // isolate_execinstr
1337 elfcpp::SHN_UNDEF
, // small_common_shndx
1338 elfcpp::SHN_X86_64_LCOMMON
, // large_common_shndx
1339 0, // small_common_section_flags
1340 elfcpp::SHF_X86_64_LARGE
, // large_common_section_flags
1341 NULL
, // attributes_section
1342 NULL
, // attributes_vendor
1343 "_start", // entry_symbol_name
1344 32, // hash_entry_size
1345 elfcpp::SHT_X86_64_UNWIND
, // unwind_section_type
1348 // This is called when a new output section is created. This is where
1349 // we handle the SHF_X86_64_LARGE.
1353 Target_x86_64
<size
>::do_new_output_section(Output_section
* os
) const
1355 if ((os
->flags() & elfcpp::SHF_X86_64_LARGE
) != 0)
1356 os
->set_is_large_section();
1359 // Get the GOT section, creating it if necessary.
1362 Output_data_got
<64, false>*
1363 Target_x86_64
<size
>::got_section(Symbol_table
* symtab
, Layout
* layout
)
1365 if (this->got_
== NULL
)
1367 gold_assert(symtab
!= NULL
&& layout
!= NULL
);
1369 // When using -z now, we can treat .got.plt as a relro section.
1370 // Without -z now, it is modified after program startup by lazy
1372 bool is_got_plt_relro
= parameters
->options().now();
1373 Output_section_order got_order
= (is_got_plt_relro
1375 : ORDER_RELRO_LAST
);
1376 Output_section_order got_plt_order
= (is_got_plt_relro
1378 : ORDER_NON_RELRO_FIRST
);
1380 this->got_
= new Output_data_got
<64, false>();
1382 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
1384 | elfcpp::SHF_WRITE
),
1385 this->got_
, got_order
, true);
1387 this->got_plt_
= new Output_data_got_plt_x86_64(layout
);
1388 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1390 | elfcpp::SHF_WRITE
),
1391 this->got_plt_
, got_plt_order
,
1394 // The first three entries are reserved.
1395 this->got_plt_
->set_current_data_size(3 * 8);
1397 if (!is_got_plt_relro
)
1399 // Those bytes can go into the relro segment.
1400 layout
->increase_relro(3 * 8);
1403 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
1404 this->global_offset_table_
=
1405 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
1406 Symbol_table::PREDEFINED
,
1408 0, 0, elfcpp::STT_OBJECT
,
1410 elfcpp::STV_HIDDEN
, 0,
1413 // If there are any IRELATIVE relocations, they get GOT entries
1414 // in .got.plt after the jump slot entries.
1415 this->got_irelative_
= new Output_data_space(8, "** GOT IRELATIVE PLT");
1416 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1418 | elfcpp::SHF_WRITE
),
1419 this->got_irelative_
,
1420 got_plt_order
, is_got_plt_relro
);
1422 // If there are any TLSDESC relocations, they get GOT entries in
1423 // .got.plt after the jump slot and IRELATIVE entries.
1424 this->got_tlsdesc_
= new Output_data_got
<64, false>();
1425 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
1427 | elfcpp::SHF_WRITE
),
1429 got_plt_order
, is_got_plt_relro
);
1435 // Get the dynamic reloc section, creating it if necessary.
1438 typename Target_x86_64
<size
>::Reloc_section
*
1439 Target_x86_64
<size
>::rela_dyn_section(Layout
* layout
)
1441 if (this->rela_dyn_
== NULL
)
1443 gold_assert(layout
!= NULL
);
1444 this->rela_dyn_
= new Reloc_section(parameters
->options().combreloc());
1445 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1446 elfcpp::SHF_ALLOC
, this->rela_dyn_
,
1447 ORDER_DYNAMIC_RELOCS
, false);
1449 return this->rela_dyn_
;
1452 // Get the section to use for IRELATIVE relocs, creating it if
1453 // necessary. These go in .rela.dyn, but only after all other dynamic
1454 // relocations. They need to follow the other dynamic relocations so
1455 // that they can refer to global variables initialized by those
1459 typename Target_x86_64
<size
>::Reloc_section
*
1460 Target_x86_64
<size
>::rela_irelative_section(Layout
* layout
)
1462 if (this->rela_irelative_
== NULL
)
1464 // Make sure we have already created the dynamic reloc section.
1465 this->rela_dyn_section(layout
);
1466 this->rela_irelative_
= new Reloc_section(false);
1467 layout
->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA
,
1468 elfcpp::SHF_ALLOC
, this->rela_irelative_
,
1469 ORDER_DYNAMIC_RELOCS
, false);
1470 gold_assert(this->rela_dyn_
->output_section()
1471 == this->rela_irelative_
->output_section());
1473 return this->rela_irelative_
;
1476 // Record a target-specific program property from the .note.gnu.property
1480 Target_x86_64
<size
>::record_gnu_property(
1481 unsigned int, unsigned int pr_type
,
1482 size_t pr_datasz
, const unsigned char* pr_data
,
1483 const Object
* object
)
1489 case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_USED
:
1490 case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
:
1491 case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED
:
1492 case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED
:
1493 case elfcpp::GNU_PROPERTY_X86_ISA_1_USED
:
1494 case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED
:
1495 case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND
:
1496 case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED
:
1497 case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
1500 gold_warning(_("%s: corrupt .note.gnu.property section "
1501 "(pr_datasz for property %d is not 4)"),
1502 object
->name().c_str(), pr_type
);
1505 val
= elfcpp::Swap
<32, false>::readval(pr_data
);
1508 gold_warning(_("%s: unknown program property type 0x%x "
1509 "in .note.gnu.property section"),
1510 object
->name().c_str(), pr_type
);
1516 case elfcpp::GNU_PROPERTY_X86_ISA_1_USED
:
1517 this->object_isa_1_used_
|= val
;
1519 case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED
:
1520 this->isa_1_needed_
|= val
;
1522 case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND
:
1523 // If we see multiple feature props in one object, OR them together.
1524 this->object_feature_1_
|= val
;
1526 case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED
:
1527 this->object_feature_2_used_
|= val
;
1529 case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED
:
1530 this->feature_2_needed_
|= val
;
1535 // Merge the target-specific program properties from the current object.
1538 Target_x86_64
<size
>::merge_gnu_properties(const Object
*)
1540 if (this->seen_first_object_
)
1542 // If any object is missing the ISA_1_USED property, we must omit
1543 // it from the output file.
1544 if (this->object_isa_1_used_
== 0)
1545 this->isa_1_used_
= 0;
1546 else if (this->isa_1_used_
!= 0)
1547 this->isa_1_used_
|= this->object_isa_1_used_
;
1548 this->feature_1_
&= this->object_feature_1_
;
1549 // If any object is missing the FEATURE_2_USED property, we must
1550 // omit it from the output file.
1551 if (this->object_feature_2_used_
== 0)
1552 this->feature_2_used_
= 0;
1553 else if (this->feature_2_used_
!= 0)
1554 this->feature_2_used_
|= this->object_feature_2_used_
;
1558 this->isa_1_used_
= this->object_isa_1_used_
;
1559 this->feature_1_
= this->object_feature_1_
;
1560 this->feature_2_used_
= this->object_feature_2_used_
;
1561 this->seen_first_object_
= true;
1563 this->object_isa_1_used_
= 0;
1564 this->object_feature_1_
= 0;
1565 this->object_feature_2_used_
= 0;
1569 add_property(Layout
* layout
, unsigned int pr_type
, uint32_t val
)
1571 unsigned char buf
[4];
1572 elfcpp::Swap
<32, false>::writeval(buf
, val
);
1573 layout
->add_gnu_property(elfcpp::NT_GNU_PROPERTY_TYPE_0
, pr_type
, 4, buf
);
1576 // Finalize the target-specific program properties and add them back to
1580 Target_x86_64
<size
>::do_finalize_gnu_properties(Layout
* layout
) const
1582 if (this->isa_1_used_
!= 0)
1583 add_property(layout
, elfcpp::GNU_PROPERTY_X86_ISA_1_USED
,
1585 if (this->isa_1_needed_
!= 0)
1586 add_property(layout
, elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED
,
1587 this->isa_1_needed_
);
1588 if (this->feature_1_
!= 0)
1589 add_property(layout
, elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND
,
1591 if (this->feature_2_used_
!= 0)
1592 add_property(layout
, elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED
,
1593 this->feature_2_used_
);
1594 if (this->feature_2_needed_
!= 0)
1595 add_property(layout
, elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED
,
1596 this->feature_2_needed_
);
1599 // Write the first three reserved words of the .got.plt section.
1600 // The remainder of the section is written while writing the PLT
1601 // in Output_data_plt_i386::do_write.
1604 Output_data_got_plt_x86_64::do_write(Output_file
* of
)
1606 // The first entry in the GOT is the address of the .dynamic section
1607 // aka the PT_DYNAMIC segment. The next two entries are reserved.
1608 // We saved space for them when we created the section in
1609 // Target_x86_64::got_section.
1610 const off_t got_file_offset
= this->offset();
1611 gold_assert(this->data_size() >= 24);
1612 unsigned char* const got_view
= of
->get_output_view(got_file_offset
, 24);
1613 Output_section
* dynamic
= this->layout_
->dynamic_section();
1614 uint64_t dynamic_addr
= dynamic
== NULL
? 0 : dynamic
->address();
1615 elfcpp::Swap
<64, false>::writeval(got_view
, dynamic_addr
);
1616 memset(got_view
+ 8, 0, 16);
1617 of
->write_output_view(got_file_offset
, 24, got_view
);
1620 // Initialize the PLT section.
1624 Output_data_plt_x86_64
<size
>::init(Layout
* layout
)
1626 this->rel_
= new Reloc_section(false);
1627 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1628 elfcpp::SHF_ALLOC
, this->rel_
,
1629 ORDER_DYNAMIC_PLT_RELOCS
, false);
1634 Output_data_plt_x86_64
<size
>::do_adjust_output_section(Output_section
* os
)
1636 os
->set_entsize(this->get_plt_entry_size());
1639 // Add an entry to the PLT.
1643 Output_data_plt_x86_64
<size
>::add_entry(Symbol_table
* symtab
, Layout
* layout
,
1646 gold_assert(!gsym
->has_plt_offset());
1648 unsigned int plt_index
;
1650 section_offset_type got_offset
;
1652 unsigned int* pcount
;
1653 unsigned int offset
;
1654 unsigned int reserved
;
1655 Output_section_data_build
* got
;
1656 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1657 && gsym
->can_use_relative_reloc(false))
1659 pcount
= &this->irelative_count_
;
1662 got
= this->got_irelative_
;
1666 pcount
= &this->count_
;
1669 got
= this->got_plt_
;
1672 if (!this->is_data_size_valid())
1674 // Note that when setting the PLT offset for a non-IRELATIVE
1675 // entry we skip the initial reserved PLT entry.
1676 plt_index
= *pcount
+ offset
;
1677 plt_offset
= plt_index
* this->get_plt_entry_size();
1681 got_offset
= (plt_index
- offset
+ reserved
) * 8;
1682 gold_assert(got_offset
== got
->current_data_size());
1684 // Every PLT entry needs a GOT entry which points back to the PLT
1685 // entry (this will be changed by the dynamic linker, normally
1686 // lazily when the function is called).
1687 got
->set_current_data_size(got_offset
+ 8);
1691 // FIXME: This is probably not correct for IRELATIVE relocs.
1693 // For incremental updates, find an available slot.
1694 plt_offset
= this->free_list_
.allocate(this->get_plt_entry_size(),
1695 this->get_plt_entry_size(), 0);
1696 if (plt_offset
== -1)
1697 gold_fallback(_("out of patch space (PLT);"
1698 " relink with --incremental-full"));
1700 // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
1701 // can be calculated from the PLT index, adjusting for the three
1702 // reserved entries at the beginning of the GOT.
1703 plt_index
= plt_offset
/ this->get_plt_entry_size() - 1;
1704 got_offset
= (plt_index
- offset
+ reserved
) * 8;
1707 gsym
->set_plt_offset(plt_offset
);
1709 // Every PLT entry needs a reloc.
1710 this->add_relocation(symtab
, layout
, gsym
, got_offset
);
1712 // Note that we don't need to save the symbol. The contents of the
1713 // PLT are independent of which symbols are used. The symbols only
1714 // appear in the relocations.
1717 // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
1722 Output_data_plt_x86_64
<size
>::add_local_ifunc_entry(
1723 Symbol_table
* symtab
,
1725 Sized_relobj_file
<size
, false>* relobj
,
1726 unsigned int local_sym_index
)
1728 unsigned int plt_offset
= this->irelative_count_
* this->get_plt_entry_size();
1729 ++this->irelative_count_
;
1731 section_offset_type got_offset
= this->got_irelative_
->current_data_size();
1733 // Every PLT entry needs a GOT entry which points back to the PLT
1735 this->got_irelative_
->set_current_data_size(got_offset
+ 8);
1737 // Every PLT entry needs a reloc.
1738 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1739 rela
->add_symbolless_local_addend(relobj
, local_sym_index
,
1740 elfcpp::R_X86_64_IRELATIVE
,
1741 this->got_irelative_
, got_offset
, 0);
1746 // Add the relocation for a PLT entry.
1750 Output_data_plt_x86_64
<size
>::add_relocation(Symbol_table
* symtab
,
1753 unsigned int got_offset
)
1755 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1756 && gsym
->can_use_relative_reloc(false))
1758 Reloc_section
* rela
= this->rela_irelative(symtab
, layout
);
1759 rela
->add_symbolless_global_addend(gsym
, elfcpp::R_X86_64_IRELATIVE
,
1760 this->got_irelative_
, got_offset
, 0);
1764 gsym
->set_needs_dynsym_entry();
1765 this->rel_
->add_global(gsym
, elfcpp::R_X86_64_JUMP_SLOT
, this->got_plt_
,
1770 // Return where the TLSDESC relocations should go, creating it if
1771 // necessary. These follow the JUMP_SLOT relocations.
1774 typename Output_data_plt_x86_64
<size
>::Reloc_section
*
1775 Output_data_plt_x86_64
<size
>::rela_tlsdesc(Layout
* layout
)
1777 if (this->tlsdesc_rel_
== NULL
)
1779 this->tlsdesc_rel_
= new Reloc_section(false);
1780 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1781 elfcpp::SHF_ALLOC
, this->tlsdesc_rel_
,
1782 ORDER_DYNAMIC_PLT_RELOCS
, false);
1783 gold_assert(this->tlsdesc_rel_
->output_section()
1784 == this->rel_
->output_section());
1786 return this->tlsdesc_rel_
;
1789 // Return where the IRELATIVE relocations should go in the PLT. These
1790 // follow the JUMP_SLOT and the TLSDESC relocations.
1793 typename Output_data_plt_x86_64
<size
>::Reloc_section
*
1794 Output_data_plt_x86_64
<size
>::rela_irelative(Symbol_table
* symtab
,
1797 if (this->irelative_rel_
== NULL
)
1799 // Make sure we have a place for the TLSDESC relocations, in
1800 // case we see any later on.
1801 this->rela_tlsdesc(layout
);
1802 this->irelative_rel_
= new Reloc_section(false);
1803 layout
->add_output_section_data(".rela.plt", elfcpp::SHT_RELA
,
1804 elfcpp::SHF_ALLOC
, this->irelative_rel_
,
1805 ORDER_DYNAMIC_PLT_RELOCS
, false);
1806 gold_assert(this->irelative_rel_
->output_section()
1807 == this->rel_
->output_section());
1809 if (parameters
->doing_static_link())
1811 // A statically linked executable will only have a .rela.plt
1812 // section to hold R_X86_64_IRELATIVE relocs for
1813 // STT_GNU_IFUNC symbols. The library will use these
1814 // symbols to locate the IRELATIVE relocs at program startup
1816 symtab
->define_in_output_data("__rela_iplt_start", NULL
,
1817 Symbol_table::PREDEFINED
,
1818 this->irelative_rel_
, 0, 0,
1819 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1820 elfcpp::STV_HIDDEN
, 0, false, true);
1821 symtab
->define_in_output_data("__rela_iplt_end", NULL
,
1822 Symbol_table::PREDEFINED
,
1823 this->irelative_rel_
, 0, 0,
1824 elfcpp::STT_NOTYPE
, elfcpp::STB_GLOBAL
,
1825 elfcpp::STV_HIDDEN
, 0, true, true);
1828 return this->irelative_rel_
;
1831 // Return the PLT address to use for a global symbol.
1835 Output_data_plt_x86_64
<size
>::do_address_for_global(const Symbol
* gsym
)
1837 uint64_t offset
= 0;
1838 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1839 && gsym
->can_use_relative_reloc(false))
1840 offset
= (this->count_
+ 1) * this->get_plt_entry_size();
1841 return this->address() + offset
+ gsym
->plt_offset();
1844 // Return the PLT address to use for a local symbol. These are always
1845 // IRELATIVE relocs.
1849 Output_data_plt_x86_64
<size
>::do_address_for_local(const Relobj
* object
,
1852 return (this->address()
1853 + (this->count_
+ 1) * this->get_plt_entry_size()
1854 + object
->local_plt_offset(r_sym
));
1857 // Set the final size.
1860 Output_data_plt_x86_64
<size
>::set_final_data_size()
1862 // Number of regular and IFUNC PLT entries, plus the first entry.
1863 unsigned int count
= this->count_
+ this->irelative_count_
+ 1;
1864 // Count the TLSDESC entry, if present.
1865 if (this->has_tlsdesc_entry())
1867 this->set_data_size(count
* this->get_plt_entry_size());
1870 // The first entry in the PLT for an executable.
1874 Output_data_plt_x86_64_standard
<size
>::first_plt_entry
[plt_entry_size
] =
1876 // From AMD64 ABI Draft 0.98, page 76
1877 0xff, 0x35, // pushq contents of memory address
1878 0, 0, 0, 0, // replaced with address of .got + 8
1879 0xff, 0x25, // jmp indirect
1880 0, 0, 0, 0, // replaced with address of .got + 16
1881 0x90, 0x90, 0x90, 0x90 // noop (x4)
1886 Output_data_plt_x86_64_standard
<size
>::do_fill_first_plt_entry(
1888 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
1889 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
)
1891 memcpy(pov
, first_plt_entry
, plt_entry_size
);
1892 // We do a jmp relative to the PC at the end of this instruction.
1893 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1895 - (plt_address
+ 6)));
1896 elfcpp::Swap
<32, false>::writeval(pov
+ 8,
1898 - (plt_address
+ 12)));
1901 // Subsequent entries in the PLT for an executable.
1905 Output_data_plt_x86_64_standard
<size
>::plt_entry
[plt_entry_size
] =
1907 // From AMD64 ABI Draft 0.98, page 76
1908 0xff, 0x25, // jmpq indirect
1909 0, 0, 0, 0, // replaced with address of symbol in .got
1910 0x68, // pushq immediate
1911 0, 0, 0, 0, // replaced with offset into relocation table
1912 0xe9, // jmpq relative
1913 0, 0, 0, 0 // replaced with offset to start of .plt
1918 Output_data_plt_x86_64_standard
<size
>::do_fill_plt_entry(
1920 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
1921 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
1922 unsigned int got_offset
,
1923 unsigned int plt_offset
,
1924 unsigned int plt_index
)
1926 // Check PC-relative offset overflow in PLT entry.
1927 uint64_t plt_got_pcrel_offset
= (got_address
+ got_offset
1928 - (plt_address
+ plt_offset
+ 6));
1929 if (Bits
<32>::has_overflow(plt_got_pcrel_offset
))
1930 gold_error(_("PC-relative offset overflow in PLT entry %d"),
1933 memcpy(pov
, plt_entry
, plt_entry_size
);
1934 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1935 plt_got_pcrel_offset
);
1937 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 7, plt_index
);
1938 elfcpp::Swap
<32, false>::writeval(pov
+ 12,
1939 - (plt_offset
+ plt_entry_size
));
1944 // The reserved TLSDESC entry in the PLT for an executable.
1948 Output_data_plt_x86_64_standard
<size
>::tlsdesc_plt_entry
[plt_entry_size
] =
1950 // From Alexandre Oliva, "Thread-Local Storage Descriptors for IA32
1951 // and AMD64/EM64T", Version 0.9.4 (2005-10-10).
1952 0xff, 0x35, // pushq x(%rip)
1953 0, 0, 0, 0, // replaced with address of linkmap GOT entry (at PLTGOT + 8)
1954 0xff, 0x25, // jmpq *y(%rip)
1955 0, 0, 0, 0, // replaced with offset of reserved TLSDESC_GOT entry
1962 Output_data_plt_x86_64_standard
<size
>::do_fill_tlsdesc_entry(
1964 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
1965 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
1966 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
1967 unsigned int tlsdesc_got_offset
,
1968 unsigned int plt_offset
)
1970 memcpy(pov
, tlsdesc_plt_entry
, plt_entry_size
);
1971 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
1973 - (plt_address
+ plt_offset
1975 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 8,
1977 + tlsdesc_got_offset
1978 - (plt_address
+ plt_offset
1982 // Return the APLT address to use for a global symbol (for IBT).
1986 Output_data_plt_x86_64_ibt
<size
>::do_address_for_global(const Symbol
* gsym
)
1988 uint64_t offset
= this->aplt_offset_
;
1989 // Convert the PLT offset into an APLT offset.
1990 unsigned int plt_offset
= gsym
->plt_offset();
1991 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
1992 && gsym
->can_use_relative_reloc(false))
1993 offset
+= this->regular_count() * aplt_entry_size
;
1995 plt_offset
-= plt_entry_size
;
1996 plt_offset
= plt_offset
/ (plt_entry_size
/ aplt_entry_size
);
1997 return this->address() + offset
+ plt_offset
;
2000 // Return the PLT address to use for a local symbol. These are always
2001 // IRELATIVE relocs.
2005 Output_data_plt_x86_64_ibt
<size
>::do_address_for_local(const Relobj
* object
,
2008 // Convert the PLT offset into an APLT offset.
2009 const Sized_relobj_file
<size
, false>* sized_relobj
=
2010 static_cast<const Sized_relobj_file
<size
, false>*>(object
);
2011 const Symbol_value
<size
>* psymval
= sized_relobj
->local_symbol(r_sym
);
2012 unsigned int plt_offset
= ((object
->local_plt_offset(r_sym
)
2013 - (psymval
->is_ifunc_symbol()
2014 ? 0 : plt_entry_size
))
2015 / (plt_entry_size
/ aplt_entry_size
));
2016 return (this->address()
2017 + this->aplt_offset_
2018 + this->regular_count() * aplt_entry_size
2022 // Set the final size.
2026 Output_data_plt_x86_64_ibt
<size
>::set_final_data_size()
2028 // Number of regular and IFUNC PLT entries.
2029 unsigned int count
= this->entry_count();
2030 // Count the first entry and the TLSDESC entry, if present.
2031 unsigned int extra
= this->has_tlsdesc_entry() ? 2 : 1;
2032 unsigned int plt_size
= (count
+ extra
) * plt_entry_size
;
2033 // Offset of the APLT.
2034 this->aplt_offset_
= plt_size
;
2035 // Size of the APLT.
2036 plt_size
+= count
* aplt_entry_size
;
2037 this->set_data_size(plt_size
);
2040 // The first entry in the IBT PLT.
2044 Output_data_plt_x86_64_ibt
<size
>::first_plt_entry
[plt_entry_size
] =
2046 0xff, 0x35, // pushq contents of memory address
2047 0, 0, 0, 0, // replaced with address of .got + 8
2048 0xff, 0x25, // jmp indirect
2049 0, 0, 0, 0, // replaced with address of .got + 16
2050 0x90, 0x90, 0x90, 0x90 // noop (x4)
2055 Output_data_plt_x86_64_ibt
<size
>::do_fill_first_plt_entry(
2057 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
2058 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
)
2060 // Offsets to the addresses needing relocation.
2061 const unsigned int roff1
= 2;
2062 const unsigned int roff2
= 8;
2064 memcpy(pov
, first_plt_entry
, plt_entry_size
);
2065 // We do a jmp relative to the PC at the end of this instruction.
2066 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ roff1
,
2068 - (plt_address
+ roff1
+ 4)));
2069 elfcpp::Swap
<32, false>::writeval(pov
+ roff2
,
2071 - (plt_address
+ roff2
+ 4)));
2074 // Subsequent entries in the IBT PLT.
2078 Output_data_plt_x86_64_ibt
<size
>::plt_entry
[plt_entry_size
] =
2080 // From AMD64 ABI Draft 1.0-rc1, Chapter 13.
2081 0xf3, 0x0f, 0x1e, 0xfa, // endbr64
2082 0x68, // pushq immediate
2083 0, 0, 0, 0, // replaced with offset into relocation table
2084 0xe9, // jmpq relative
2085 0, 0, 0, 0, // replaced with offset to start of .plt
2089 // Entries in the IBT Additional PLT.
2093 Output_data_plt_x86_64_ibt
<size
>::aplt_entry
[aplt_entry_size
] =
2095 // From AMD64 ABI Draft 1.0-rc1, Chapter 13.
2096 0xf3, 0x0f, 0x1e, 0xfa, // endbr64
2097 0xff, 0x25, // jmpq indirect
2098 0, 0, 0, 0, // replaced with address of symbol in .got
2099 0x0f, 0x1f, 0x04, 0x00, // nop
2105 Output_data_plt_x86_64_ibt
<size
>::do_fill_plt_entry(
2107 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
2108 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
2110 unsigned int plt_offset
,
2111 unsigned int plt_index
)
2113 // Offsets to the addresses needing relocation.
2114 const unsigned int roff1
= 5;
2115 const unsigned int roff2
= 10;
2117 memcpy(pov
, plt_entry
, plt_entry_size
);
2118 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ roff1
, plt_index
);
2119 elfcpp::Swap
<32, false>::writeval(pov
+ roff2
, -(plt_offset
+ roff2
+ 4));
2125 Output_data_plt_x86_64_ibt
<size
>::fill_aplt_entry(
2127 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
2128 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
2129 unsigned int got_offset
,
2130 unsigned int plt_offset
,
2131 unsigned int plt_index
)
2133 // Offset to the address needing relocation.
2134 const unsigned int roff
= 6;
2136 // Check PC-relative offset overflow in PLT entry.
2137 uint64_t plt_got_pcrel_offset
= (got_address
+ got_offset
2138 - (plt_address
+ plt_offset
+ roff
+ 4));
2139 if (Bits
<32>::has_overflow(plt_got_pcrel_offset
))
2140 gold_error(_("PC-relative offset overflow in APLT entry %d"),
2143 memcpy(pov
, aplt_entry
, aplt_entry_size
);
2144 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ roff
, plt_got_pcrel_offset
);
2147 // The reserved TLSDESC entry in the IBT PLT for an executable.
2151 Output_data_plt_x86_64_ibt
<size
>::tlsdesc_plt_entry
[plt_entry_size
] =
2153 // From Alexandre Oliva, "Thread-Local Storage Descriptors for IA32
2154 // and AMD64/EM64T", Version 0.9.4 (2005-10-10).
2155 0xf3, 0x0f, 0x1e, 0xfa, // endbr64
2156 0xff, 0x35, // pushq x(%rip)
2157 0, 0, 0, 0, // replaced with address of linkmap GOT entry (at PLTGOT + 8)
2158 0xff, 0x25, // jmpq *y(%rip)
2159 0, 0, 0, 0, // replaced with offset of reserved TLSDESC_GOT entry
2164 Output_data_plt_x86_64_ibt
<size
>::do_fill_tlsdesc_entry(
2166 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
2167 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
2168 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
2169 unsigned int tlsdesc_got_offset
,
2170 unsigned int plt_offset
)
2172 memcpy(pov
, tlsdesc_plt_entry
, plt_entry_size
);
2173 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 6,
2175 - (plt_address
+ plt_offset
2177 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 12,
2179 + tlsdesc_got_offset
2180 - (plt_address
+ plt_offset
2184 // The .eh_frame unwind information for the PLT.
2188 Output_data_plt_x86_64
<size
>::plt_eh_frame_cie
[plt_eh_frame_cie_size
] =
2191 'z', // Augmentation: augmentation size included.
2192 'R', // Augmentation: FDE encoding included.
2193 '\0', // End of augmentation string.
2194 1, // Code alignment factor.
2195 0x78, // Data alignment factor.
2196 16, // Return address column.
2197 1, // Augmentation size.
2198 (elfcpp::DW_EH_PE_pcrel
// FDE encoding.
2199 | elfcpp::DW_EH_PE_sdata4
),
2200 elfcpp::DW_CFA_def_cfa
, 7, 8, // DW_CFA_def_cfa: r7 (rsp) ofs 8.
2201 elfcpp::DW_CFA_offset
+ 16, 1,// DW_CFA_offset: r16 (rip) at cfa-8.
2202 elfcpp::DW_CFA_nop
, // Align to 16 bytes.
2208 Output_data_plt_x86_64_standard
<size
>::plt_eh_frame_fde
[plt_eh_frame_fde_size
] =
2210 0, 0, 0, 0, // Replaced with offset to .plt.
2211 0, 0, 0, 0, // Replaced with size of .plt.
2212 0, // Augmentation size.
2213 elfcpp::DW_CFA_def_cfa_offset
, 16, // DW_CFA_def_cfa_offset: 16.
2214 elfcpp::DW_CFA_advance_loc
+ 6, // Advance 6 to __PLT__ + 6.
2215 elfcpp::DW_CFA_def_cfa_offset
, 24, // DW_CFA_def_cfa_offset: 24.
2216 elfcpp::DW_CFA_advance_loc
+ 10, // Advance 10 to __PLT__ + 16.
2217 elfcpp::DW_CFA_def_cfa_expression
, // DW_CFA_def_cfa_expression.
2218 11, // Block length.
2219 elfcpp::DW_OP_breg7
, 8, // Push %rsp + 8.
2220 elfcpp::DW_OP_breg16
, 0, // Push %rip.
2221 elfcpp::DW_OP_lit15
, // Push 0xf.
2222 elfcpp::DW_OP_and
, // & (%rip & 0xf).
2223 elfcpp::DW_OP_lit11
, // Push 0xb.
2224 elfcpp::DW_OP_ge
, // >= ((%rip & 0xf) >= 0xb)
2225 elfcpp::DW_OP_lit3
, // Push 3.
2226 elfcpp::DW_OP_shl
, // << (((%rip & 0xf) >= 0xb) << 3)
2227 elfcpp::DW_OP_plus
, // + ((((%rip&0xf)>=0xb)<<3)+%rsp+8
2228 elfcpp::DW_CFA_nop
, // Align to 32 bytes.
2234 // The .eh_frame unwind information for the PLT.
2237 Output_data_plt_x86_64_ibt
<size
>::plt_eh_frame_fde
[plt_eh_frame_fde_size
] =
2239 0, 0, 0, 0, // Replaced with offset to .plt.
2240 0, 0, 0, 0, // Replaced with size of .plt.
2241 0, // Augmentation size.
2242 elfcpp::DW_CFA_def_cfa_offset
, 16, // DW_CFA_def_cfa_offset: 16.
2243 elfcpp::DW_CFA_advance_loc
+ 6, // Advance 6 to __PLT__ + 6.
2244 elfcpp::DW_CFA_def_cfa_offset
, 24, // DW_CFA_def_cfa_offset: 24.
2245 elfcpp::DW_CFA_advance_loc
+ 10, // Advance 10 to __PLT__ + 16.
2246 elfcpp::DW_CFA_def_cfa_expression
, // DW_CFA_def_cfa_expression.
2247 11, // Block length.
2248 elfcpp::DW_OP_breg7
, 8, // Push %rsp + 8.
2249 elfcpp::DW_OP_breg16
, 0, // Push %rip.
2250 elfcpp::DW_OP_lit15
, // Push 0xf.
2251 elfcpp::DW_OP_and
, // & (%rip & 0xf).
2252 elfcpp::DW_OP_lit9
, // Push 9.
2253 elfcpp::DW_OP_ge
, // >= ((%rip & 0xf) >= 9)
2254 elfcpp::DW_OP_lit3
, // Push 3.
2255 elfcpp::DW_OP_shl
, // << (((%rip & 0xf) >= 9) << 3)
2256 elfcpp::DW_OP_plus
, // + ((((%rip&0xf)>=9)<<3)+%rsp+8
2257 elfcpp::DW_CFA_nop
, // Align to 32 bytes.
2263 // Write out the PLT. This uses the hand-coded instructions above,
2264 // and adjusts them as needed. This is specified by the AMD64 ABI.
2268 Output_data_plt_x86_64
<size
>::do_write(Output_file
* of
)
2270 const off_t offset
= this->offset();
2271 const section_size_type oview_size
=
2272 convert_to_section_size_type(this->data_size());
2273 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2275 const off_t got_file_offset
= this->got_plt_
->offset();
2276 gold_assert(parameters
->incremental_update()
2277 || (got_file_offset
+ this->got_plt_
->data_size()
2278 == this->got_irelative_
->offset()));
2279 const section_size_type got_size
=
2280 convert_to_section_size_type(this->got_plt_
->data_size()
2281 + this->got_irelative_
->data_size());
2282 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
2285 unsigned char* pov
= oview
;
2287 // The base address of the .plt section.
2288 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
= this->address();
2289 // The base address of the .got section.
2290 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
= this->got_
->address();
2291 // The base address of the PLT portion of the .got section,
2292 // which is where the GOT pointer will point, and where the
2293 // three reserved GOT entries are located.
2294 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
2295 = this->got_plt_
->address();
2297 this->fill_first_plt_entry(pov
, got_address
, plt_address
);
2298 pov
+= this->get_plt_entry_size();
2300 // The first three entries in the GOT are reserved, and are written
2301 // by Output_data_got_plt_x86_64::do_write.
2302 unsigned char* got_pov
= got_view
+ 24;
2304 unsigned int plt_offset
= this->get_plt_entry_size();
2305 unsigned int got_offset
= 24;
2306 const unsigned int count
= this->count_
+ this->irelative_count_
;
2307 for (unsigned int plt_index
= 0;
2310 pov
+= this->get_plt_entry_size(),
2312 plt_offset
+= this->get_plt_entry_size(),
2315 // Set and adjust the PLT entry itself.
2316 unsigned int lazy_offset
= this->fill_plt_entry(pov
,
2317 got_address
, plt_address
,
2318 got_offset
, plt_offset
,
2321 // Set the entry in the GOT.
2322 elfcpp::Swap
<64, false>::writeval(got_pov
,
2323 plt_address
+ plt_offset
+ lazy_offset
);
2326 if (this->has_tlsdesc_entry())
2328 // Set and adjust the reserved TLSDESC PLT entry.
2329 unsigned int tlsdesc_got_offset
= this->get_tlsdesc_got_offset();
2330 this->fill_tlsdesc_entry(pov
, got_address
, plt_address
, got_base
,
2331 tlsdesc_got_offset
, plt_offset
);
2332 pov
+= this->get_plt_entry_size();
2335 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
2336 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
2338 of
->write_output_view(offset
, oview_size
, oview
);
2339 of
->write_output_view(got_file_offset
, got_size
, got_view
);
2342 // Write out the IBT PLT.
2346 Output_data_plt_x86_64_ibt
<size
>::do_write(Output_file
* of
)
2348 const off_t offset
= this->offset();
2349 const section_size_type oview_size
=
2350 convert_to_section_size_type(this->data_size());
2351 unsigned char* const oview
= of
->get_output_view(offset
, oview_size
);
2353 Output_data_got
<64, false>* got
= this->got();
2354 Output_data_got_plt_x86_64
* got_plt
= this->got_plt();
2355 Output_data_space
* got_irelative
= this->got_irelative();
2357 const off_t got_file_offset
= got_plt
->offset();
2358 gold_assert(parameters
->incremental_update()
2359 || (got_file_offset
+ got_plt
->data_size()
2360 == got_irelative
->offset()));
2361 const section_size_type got_size
=
2362 convert_to_section_size_type(got_plt
->data_size()
2363 + got_irelative
->data_size());
2364 unsigned char* const got_view
= of
->get_output_view(got_file_offset
,
2367 unsigned char* pov
= oview
;
2369 // The base address of the .plt section.
2370 elfcpp::Elf_types
<64>::Elf_Addr plt_address
= this->address();
2371 // The base address of the .got section.
2372 elfcpp::Elf_types
<64>::Elf_Addr got_base
= got
->address();
2373 // The base address of the PLT portion of the .got section,
2374 // which is where the GOT pointer will point, and where the
2375 // three reserved GOT entries are located.
2376 elfcpp::Elf_types
<64>::Elf_Addr got_address
= got_plt
->address();
2378 this->fill_first_plt_entry(pov
, got_address
, plt_address
);
2379 pov
+= plt_entry_size
;
2381 // The first three entries in the GOT are reserved, and are written
2382 // by Output_data_got_plt_x86_64::do_write.
2383 unsigned char* got_pov
= got_view
+ 24;
2385 unsigned int plt_offset
= plt_entry_size
;
2386 unsigned int got_offset
= 24;
2387 const unsigned int count
= this->entry_count();
2388 for (unsigned int plt_index
= 0;
2391 pov
+= plt_entry_size
,
2393 plt_offset
+= plt_entry_size
,
2396 // Set and adjust the PLT entry itself.
2397 unsigned int lazy_offset
= this->fill_plt_entry(pov
,
2398 got_address
, plt_address
,
2399 got_offset
, plt_offset
,
2402 // Set the entry in the GOT.
2403 elfcpp::Swap
<64, false>::writeval(got_pov
,
2404 plt_address
+ plt_offset
+ lazy_offset
);
2407 if (this->has_tlsdesc_entry())
2409 // Set and adjust the reserved TLSDESC PLT entry.
2410 unsigned int tlsdesc_got_offset
= this->get_tlsdesc_got_offset();
2411 this->fill_tlsdesc_entry(pov
, got_address
, plt_address
, got_base
,
2412 tlsdesc_got_offset
, plt_offset
);
2413 pov
+= this->get_plt_entry_size();
2414 plt_offset
+= plt_entry_size
;
2417 // Write the additional PLT.
2419 for (unsigned int plt_index
= 0;
2422 pov
+= aplt_entry_size
,
2423 plt_offset
+= aplt_entry_size
,
2426 // Set and adjust the APLT entry.
2427 this->fill_aplt_entry(pov
, got_address
, plt_address
, got_offset
,
2428 plt_offset
, plt_index
);
2431 gold_assert(static_cast<section_size_type
>(pov
- oview
) == oview_size
);
2432 gold_assert(static_cast<section_size_type
>(got_pov
- got_view
) == got_size
);
2434 of
->write_output_view(offset
, oview_size
, oview
);
2435 of
->write_output_view(got_file_offset
, got_size
, got_view
);
2438 // Create the PLT section.
2442 Target_x86_64
<size
>::make_plt_section(Symbol_table
* symtab
, Layout
* layout
)
2444 if (this->plt_
== NULL
)
2446 // Create the GOT sections first.
2447 this->got_section(symtab
, layout
);
2449 this->plt_
= this->make_data_plt(layout
, this->got_
, this->got_plt_
,
2450 this->got_irelative_
);
2452 // Add unwind information if requested.
2453 if (parameters
->options().ld_generated_unwind_info())
2454 this->plt_
->add_eh_frame(layout
);
2456 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
2458 | elfcpp::SHF_EXECINSTR
),
2459 this->plt_
, ORDER_PLT
, false);
2461 // Make the sh_info field of .rela.plt point to .plt.
2462 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
2463 rela_plt_os
->set_info_section(this->plt_
->output_section());
2468 Output_data_plt_x86_64
<32>*
2469 Target_x86_64
<32>::do_make_data_plt(Layout
* layout
,
2470 Output_data_got
<64, false>* got
,
2471 Output_data_got_plt_x86_64
* got_plt
,
2472 Output_data_space
* got_irelative
)
2474 if (this->feature_1_
& elfcpp::GNU_PROPERTY_X86_FEATURE_1_IBT
)
2475 return new Output_data_plt_x86_64_ibt
<32>(layout
, got
, got_plt
,
2477 return new Output_data_plt_x86_64_standard
<32>(layout
, got
, got_plt
,
2482 Output_data_plt_x86_64
<64>*
2483 Target_x86_64
<64>::do_make_data_plt(Layout
* layout
,
2484 Output_data_got
<64, false>* got
,
2485 Output_data_got_plt_x86_64
* got_plt
,
2486 Output_data_space
* got_irelative
)
2488 if (this->feature_1_
& elfcpp::GNU_PROPERTY_X86_FEATURE_1_IBT
)
2489 return new Output_data_plt_x86_64_ibt
<64>(layout
, got
, got_plt
,
2492 return new Output_data_plt_x86_64_standard
<64>(layout
, got
, got_plt
,
2497 Output_data_plt_x86_64
<32>*
2498 Target_x86_64
<32>::do_make_data_plt(Layout
* layout
,
2499 Output_data_got
<64, false>* got
,
2500 Output_data_got_plt_x86_64
* got_plt
,
2501 Output_data_space
* got_irelative
,
2502 unsigned int plt_count
)
2504 if (this->feature_1_
& elfcpp::GNU_PROPERTY_X86_FEATURE_1_IBT
)
2505 return new Output_data_plt_x86_64_ibt
<32>(layout
, got
, got_plt
,
2506 got_irelative
, plt_count
);
2507 return new Output_data_plt_x86_64_standard
<32>(layout
, got
, got_plt
,
2508 got_irelative
, plt_count
);
2512 Output_data_plt_x86_64
<64>*
2513 Target_x86_64
<64>::do_make_data_plt(Layout
* layout
,
2514 Output_data_got
<64, false>* got
,
2515 Output_data_got_plt_x86_64
* got_plt
,
2516 Output_data_space
* got_irelative
,
2517 unsigned int plt_count
)
2519 if (this->feature_1_
& elfcpp::GNU_PROPERTY_X86_FEATURE_1_IBT
)
2520 return new Output_data_plt_x86_64_ibt
<64>(layout
, got
, got_plt
,
2521 got_irelative
, plt_count
);
2523 return new Output_data_plt_x86_64_standard
<64>(layout
, got
, got_plt
,
2528 // Return the section for TLSDESC relocations.
2531 typename Target_x86_64
<size
>::Reloc_section
*
2532 Target_x86_64
<size
>::rela_tlsdesc_section(Layout
* layout
) const
2534 return this->plt_section()->rela_tlsdesc(layout
);
2537 // Create a PLT entry for a global symbol.
2541 Target_x86_64
<size
>::make_plt_entry(Symbol_table
* symtab
, Layout
* layout
,
2544 if (gsym
->has_plt_offset())
2547 if (this->plt_
== NULL
)
2548 this->make_plt_section(symtab
, layout
);
2550 this->plt_
->add_entry(symtab
, layout
, gsym
);
2553 // Make a PLT entry for a local STT_GNU_IFUNC symbol.
2557 Target_x86_64
<size
>::make_local_ifunc_plt_entry(
2558 Symbol_table
* symtab
, Layout
* layout
,
2559 Sized_relobj_file
<size
, false>* relobj
,
2560 unsigned int local_sym_index
)
2562 if (relobj
->local_has_plt_offset(local_sym_index
))
2564 if (this->plt_
== NULL
)
2565 this->make_plt_section(symtab
, layout
);
2566 unsigned int plt_offset
= this->plt_
->add_local_ifunc_entry(symtab
, layout
,
2569 relobj
->set_local_plt_offset(local_sym_index
, plt_offset
);
2572 // Return the number of entries in the PLT.
2576 Target_x86_64
<size
>::plt_entry_count() const
2578 if (this->plt_
== NULL
)
2580 return this->plt_
->entry_count();
2583 // Return the offset of the first non-reserved PLT entry.
2587 Target_x86_64
<size
>::first_plt_entry_offset() const
2589 if (this->plt_
== NULL
)
2591 return this->plt_
->first_plt_entry_offset();
2594 // Return the size of each PLT entry.
2598 Target_x86_64
<size
>::plt_entry_size() const
2600 if (this->plt_
== NULL
)
2602 return this->plt_
->get_plt_entry_size();
2605 // Create the GOT and PLT sections for an incremental update.
2608 Output_data_got_base
*
2609 Target_x86_64
<size
>::init_got_plt_for_update(Symbol_table
* symtab
,
2611 unsigned int got_count
,
2612 unsigned int plt_count
)
2614 gold_assert(this->got_
== NULL
);
2616 this->got_
= new Output_data_got
<64, false>(got_count
* 8);
2617 layout
->add_output_section_data(".got", elfcpp::SHT_PROGBITS
,
2619 | elfcpp::SHF_WRITE
),
2620 this->got_
, ORDER_RELRO_LAST
,
2623 // Add the three reserved entries.
2624 this->got_plt_
= new Output_data_got_plt_x86_64(layout
, (plt_count
+ 3) * 8);
2625 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
2627 | elfcpp::SHF_WRITE
),
2628 this->got_plt_
, ORDER_NON_RELRO_FIRST
,
2631 // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
2632 this->global_offset_table_
=
2633 symtab
->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL
,
2634 Symbol_table::PREDEFINED
,
2636 0, 0, elfcpp::STT_OBJECT
,
2638 elfcpp::STV_HIDDEN
, 0,
2641 // If there are any TLSDESC relocations, they get GOT entries in
2642 // .got.plt after the jump slot entries.
2643 // FIXME: Get the count for TLSDESC entries.
2644 this->got_tlsdesc_
= new Output_data_got
<64, false>(0);
2645 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
2646 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2648 ORDER_NON_RELRO_FIRST
, false);
2650 // If there are any IRELATIVE relocations, they get GOT entries in
2651 // .got.plt after the jump slot and TLSDESC entries.
2652 this->got_irelative_
= new Output_data_space(0, 8, "** GOT IRELATIVE PLT");
2653 layout
->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS
,
2654 elfcpp::SHF_ALLOC
| elfcpp::SHF_WRITE
,
2655 this->got_irelative_
,
2656 ORDER_NON_RELRO_FIRST
, false);
2658 // Create the PLT section.
2659 this->plt_
= this->make_data_plt(layout
, this->got_
,
2661 this->got_irelative_
,
2664 // Add unwind information if requested.
2665 if (parameters
->options().ld_generated_unwind_info())
2666 this->plt_
->add_eh_frame(layout
);
2668 layout
->add_output_section_data(".plt", elfcpp::SHT_PROGBITS
,
2669 elfcpp::SHF_ALLOC
| elfcpp::SHF_EXECINSTR
,
2670 this->plt_
, ORDER_PLT
, false);
2672 // Make the sh_info field of .rela.plt point to .plt.
2673 Output_section
* rela_plt_os
= this->plt_
->rela_plt()->output_section();
2674 rela_plt_os
->set_info_section(this->plt_
->output_section());
2676 // Create the rela_dyn section.
2677 this->rela_dyn_section(layout
);
2682 // Reserve a GOT entry for a local symbol, and regenerate any
2683 // necessary dynamic relocations.
2687 Target_x86_64
<size
>::reserve_local_got_entry(
2688 unsigned int got_index
,
2689 Sized_relobj
<size
, false>* obj
,
2691 unsigned int got_type
)
2693 unsigned int got_offset
= got_index
* 8;
2694 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
2696 this->got_
->reserve_local(got_index
, obj
, r_sym
, got_type
);
2699 case GOT_TYPE_STANDARD
:
2700 if (parameters
->options().output_is_position_independent())
2701 rela_dyn
->add_local_relative(obj
, r_sym
, elfcpp::R_X86_64_RELATIVE
,
2702 this->got_
, got_offset
, 0, false);
2704 case GOT_TYPE_TLS_OFFSET
:
2705 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_X86_64_TPOFF64
,
2706 this->got_
, got_offset
, 0);
2708 case GOT_TYPE_TLS_PAIR
:
2709 this->got_
->reserve_slot(got_index
+ 1);
2710 rela_dyn
->add_local(obj
, r_sym
, elfcpp::R_X86_64_DTPMOD64
,
2711 this->got_
, got_offset
, 0);
2713 case GOT_TYPE_TLS_DESC
:
2714 gold_fatal(_("TLS_DESC not yet supported for incremental linking"));
2715 // this->got_->reserve_slot(got_index + 1);
2716 // rela_dyn->add_target_specific(elfcpp::R_X86_64_TLSDESC, arg,
2717 // this->got_, got_offset, 0);
2724 // Reserve a GOT entry for a global symbol, and regenerate any
2725 // necessary dynamic relocations.
2729 Target_x86_64
<size
>::reserve_global_got_entry(unsigned int got_index
,
2731 unsigned int got_type
)
2733 unsigned int got_offset
= got_index
* 8;
2734 Reloc_section
* rela_dyn
= this->rela_dyn_section(NULL
);
2736 this->got_
->reserve_global(got_index
, gsym
, got_type
);
2739 case GOT_TYPE_STANDARD
:
2740 if (!gsym
->final_value_is_known())
2742 if (gsym
->is_from_dynobj()
2743 || gsym
->is_undefined()
2744 || gsym
->is_preemptible()
2745 || gsym
->type() == elfcpp::STT_GNU_IFUNC
)
2746 rela_dyn
->add_global(gsym
, elfcpp::R_X86_64_GLOB_DAT
,
2747 this->got_
, got_offset
, 0);
2749 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_RELATIVE
,
2750 this->got_
, got_offset
, 0, false);
2753 case GOT_TYPE_TLS_OFFSET
:
2754 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_TPOFF64
,
2755 this->got_
, got_offset
, 0, false);
2757 case GOT_TYPE_TLS_PAIR
:
2758 this->got_
->reserve_slot(got_index
+ 1);
2759 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_DTPMOD64
,
2760 this->got_
, got_offset
, 0, false);
2761 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_DTPOFF64
,
2762 this->got_
, got_offset
+ 8, 0, false);
2764 case GOT_TYPE_TLS_DESC
:
2765 this->got_
->reserve_slot(got_index
+ 1);
2766 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_TLSDESC
,
2767 this->got_
, got_offset
, 0, false);
2774 // Register an existing PLT entry for a global symbol.
2778 Target_x86_64
<size
>::register_global_plt_entry(Symbol_table
* symtab
,
2780 unsigned int plt_index
,
2783 gold_assert(this->plt_
!= NULL
);
2784 gold_assert(!gsym
->has_plt_offset());
2786 this->plt_
->reserve_slot(plt_index
);
2788 gsym
->set_plt_offset((plt_index
+ 1) * this->plt_entry_size());
2790 unsigned int got_offset
= (plt_index
+ 3) * 8;
2791 this->plt_
->add_relocation(symtab
, layout
, gsym
, got_offset
);
2794 // Force a COPY relocation for a given symbol.
2798 Target_x86_64
<size
>::emit_copy_reloc(
2799 Symbol_table
* symtab
, Symbol
* sym
, Output_section
* os
, off_t offset
)
2801 this->copy_relocs_
.emit_copy_reloc(symtab
,
2802 symtab
->get_sized_symbol
<size
>(sym
),
2805 this->rela_dyn_section(NULL
));
2808 // Define the _TLS_MODULE_BASE_ symbol in the TLS segment.
2812 Target_x86_64
<size
>::define_tls_base_symbol(Symbol_table
* symtab
,
2815 if (this->tls_base_symbol_defined_
)
2818 Output_segment
* tls_segment
= layout
->tls_segment();
2819 if (tls_segment
!= NULL
)
2821 bool is_exec
= parameters
->options().output_is_executable();
2822 symtab
->define_in_output_segment("_TLS_MODULE_BASE_", NULL
,
2823 Symbol_table::PREDEFINED
,
2827 elfcpp::STV_HIDDEN
, 0,
2829 ? Symbol::SEGMENT_END
2830 : Symbol::SEGMENT_START
),
2833 this->tls_base_symbol_defined_
= true;
2836 // Create the reserved PLT and GOT entries for the TLS descriptor resolver.
2840 Target_x86_64
<size
>::reserve_tlsdesc_entries(Symbol_table
* symtab
,
2843 if (this->plt_
== NULL
)
2844 this->make_plt_section(symtab
, layout
);
2846 if (!this->plt_
->has_tlsdesc_entry())
2848 // Allocate the TLSDESC_GOT entry.
2849 Output_data_got
<64, false>* got
= this->got_section(symtab
, layout
);
2850 unsigned int got_offset
= got
->add_constant(0);
2852 // Allocate the TLSDESC_PLT entry.
2853 this->plt_
->reserve_tlsdesc_entry(got_offset
);
2857 // Create a GOT entry for the TLS module index.
2861 Target_x86_64
<size
>::got_mod_index_entry(Symbol_table
* symtab
, Layout
* layout
,
2862 Sized_relobj_file
<size
, false>* object
)
2864 if (this->got_mod_index_offset_
== -1U)
2866 gold_assert(symtab
!= NULL
&& layout
!= NULL
&& object
!= NULL
);
2867 Reloc_section
* rela_dyn
= this->rela_dyn_section(layout
);
2868 Output_data_got
<64, false>* got
= this->got_section(symtab
, layout
);
2869 unsigned int got_offset
= got
->add_constant(0);
2870 rela_dyn
->add_local(object
, 0, elfcpp::R_X86_64_DTPMOD64
, got
,
2872 got
->add_constant(0);
2873 this->got_mod_index_offset_
= got_offset
;
2875 return this->got_mod_index_offset_
;
2878 // Optimize the TLS relocation type based on what we know about the
2879 // symbol. IS_FINAL is true if the final address of this symbol is
2880 // known at link time.
2883 tls::Tls_optimization
2884 Target_x86_64
<size
>::optimize_tls_reloc(bool is_final
, int r_type
)
2886 // If we are generating a shared library, then we can't do anything
2888 if (parameters
->options().shared())
2889 return tls::TLSOPT_NONE
;
2893 case elfcpp::R_X86_64_TLSGD
:
2894 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
2895 case elfcpp::R_X86_64_TLSDESC_CALL
:
2896 // These are General-Dynamic which permits fully general TLS
2897 // access. Since we know that we are generating an executable,
2898 // we can convert this to Initial-Exec. If we also know that
2899 // this is a local symbol, we can further switch to Local-Exec.
2901 return tls::TLSOPT_TO_LE
;
2902 return tls::TLSOPT_TO_IE
;
2904 case elfcpp::R_X86_64_TLSLD
:
2905 // This is Local-Dynamic, which refers to a local symbol in the
2906 // dynamic TLS block. Since we know that we generating an
2907 // executable, we can switch to Local-Exec.
2908 return tls::TLSOPT_TO_LE
;
2910 case elfcpp::R_X86_64_DTPOFF32
:
2911 case elfcpp::R_X86_64_DTPOFF64
:
2912 // Another Local-Dynamic reloc.
2913 return tls::TLSOPT_TO_LE
;
2915 case elfcpp::R_X86_64_GOTTPOFF
:
2916 // These are Initial-Exec relocs which get the thread offset
2917 // from the GOT. If we know that we are linking against the
2918 // local symbol, we can switch to Local-Exec, which links the
2919 // thread offset into the instruction.
2921 return tls::TLSOPT_TO_LE
;
2922 return tls::TLSOPT_NONE
;
2924 case elfcpp::R_X86_64_TPOFF32
:
2925 // When we already have Local-Exec, there is nothing further we
2927 return tls::TLSOPT_NONE
;
2934 // Get the Reference_flags for a particular relocation.
2938 Target_x86_64
<size
>::Scan::get_reference_flags(unsigned int r_type
)
2942 case elfcpp::R_X86_64_NONE
:
2943 case elfcpp::R_X86_64_GNU_VTINHERIT
:
2944 case elfcpp::R_X86_64_GNU_VTENTRY
:
2945 case elfcpp::R_X86_64_GOTPC32
:
2946 case elfcpp::R_X86_64_GOTPC64
:
2947 // No symbol reference.
2950 case elfcpp::R_X86_64_64
:
2951 case elfcpp::R_X86_64_32
:
2952 case elfcpp::R_X86_64_32S
:
2953 case elfcpp::R_X86_64_16
:
2954 case elfcpp::R_X86_64_8
:
2955 return Symbol::ABSOLUTE_REF
;
2957 case elfcpp::R_X86_64_PC64
:
2958 case elfcpp::R_X86_64_PC32
:
2959 case elfcpp::R_X86_64_PC16
:
2960 case elfcpp::R_X86_64_PC8
:
2961 case elfcpp::R_X86_64_GOTOFF64
:
2962 return Symbol::RELATIVE_REF
;
2964 case elfcpp::R_X86_64_PLT32
:
2965 case elfcpp::R_X86_64_PLTOFF64
:
2966 return Symbol::FUNCTION_CALL
| Symbol::RELATIVE_REF
;
2968 case elfcpp::R_X86_64_GOT64
:
2969 case elfcpp::R_X86_64_GOT32
:
2970 case elfcpp::R_X86_64_GOTPCREL64
:
2971 case elfcpp::R_X86_64_GOTPCREL
:
2972 case elfcpp::R_X86_64_GOTPCRELX
:
2973 case elfcpp::R_X86_64_REX_GOTPCRELX
:
2974 case elfcpp::R_X86_64_GOTPLT64
:
2976 return Symbol::ABSOLUTE_REF
;
2978 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
2979 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
2980 case elfcpp::R_X86_64_TLSDESC_CALL
:
2981 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
2982 case elfcpp::R_X86_64_DTPOFF32
:
2983 case elfcpp::R_X86_64_DTPOFF64
:
2984 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
2985 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
2986 return Symbol::TLS_REF
;
2988 case elfcpp::R_X86_64_COPY
:
2989 case elfcpp::R_X86_64_GLOB_DAT
:
2990 case elfcpp::R_X86_64_JUMP_SLOT
:
2991 case elfcpp::R_X86_64_RELATIVE
:
2992 case elfcpp::R_X86_64_IRELATIVE
:
2993 case elfcpp::R_X86_64_TPOFF64
:
2994 case elfcpp::R_X86_64_DTPMOD64
:
2995 case elfcpp::R_X86_64_TLSDESC
:
2996 case elfcpp::R_X86_64_SIZE32
:
2997 case elfcpp::R_X86_64_SIZE64
:
2999 // Not expected. We will give an error later.
3004 // Report an unsupported relocation against a local symbol.
3008 Target_x86_64
<size
>::Scan::unsupported_reloc_local(
3009 Sized_relobj_file
<size
, false>* object
,
3010 unsigned int r_type
)
3012 gold_error(_("%s: unsupported reloc %u against local symbol"),
3013 object
->name().c_str(), r_type
);
3016 // We are about to emit a dynamic relocation of type R_TYPE. If the
3017 // dynamic linker does not support it, issue an error. The GNU linker
3018 // only issues a non-PIC error for an allocated read-only section.
3019 // Here we know the section is allocated, but we don't know that it is
3020 // read-only. But we check for all the relocation types which the
3021 // glibc dynamic linker supports, so it seems appropriate to issue an
3022 // error even if the section is not read-only. If GSYM is not NULL,
3023 // it is the symbol the relocation is against; if it is NULL, the
3024 // relocation is against a local symbol.
3028 Target_x86_64
<size
>::Scan::check_non_pic(Relobj
* object
, unsigned int r_type
,
3033 // These are the relocation types supported by glibc for x86_64
3034 // which should always work.
3035 case elfcpp::R_X86_64_RELATIVE
:
3036 case elfcpp::R_X86_64_IRELATIVE
:
3037 case elfcpp::R_X86_64_GLOB_DAT
:
3038 case elfcpp::R_X86_64_JUMP_SLOT
:
3039 case elfcpp::R_X86_64_DTPMOD64
:
3040 case elfcpp::R_X86_64_DTPOFF64
:
3041 case elfcpp::R_X86_64_TPOFF64
:
3042 case elfcpp::R_X86_64_64
:
3043 case elfcpp::R_X86_64_COPY
:
3046 // glibc supports these reloc types, but they can overflow.
3047 case elfcpp::R_X86_64_PC32
:
3048 // A PC relative reference is OK against a local symbol or if
3049 // the symbol is defined locally.
3051 || (!gsym
->is_from_dynobj()
3052 && !gsym
->is_undefined()
3053 && !gsym
->is_preemptible()))
3056 case elfcpp::R_X86_64_32
:
3057 // R_X86_64_32 is OK for x32.
3058 if (size
== 32 && r_type
== elfcpp::R_X86_64_32
)
3060 if (this->issued_non_pic_error_
)
3062 gold_assert(parameters
->options().output_is_position_independent());
3064 object
->error(_("requires dynamic R_X86_64_32 reloc which may "
3065 "overflow at runtime; recompile with -fPIC"));
3071 case elfcpp::R_X86_64_32
:
3072 r_name
= "R_X86_64_32";
3074 case elfcpp::R_X86_64_PC32
:
3075 r_name
= "R_X86_64_PC32";
3081 object
->error(_("requires dynamic %s reloc against '%s' "
3082 "which may overflow at runtime; recompile "
3084 r_name
, gsym
->name());
3086 this->issued_non_pic_error_
= true;
3090 // This prevents us from issuing more than one error per reloc
3091 // section. But we can still wind up issuing more than one
3092 // error per object file.
3093 if (this->issued_non_pic_error_
)
3095 gold_assert(parameters
->options().output_is_position_independent());
3096 object
->error(_("requires unsupported dynamic reloc %u; "
3097 "recompile with -fPIC"),
3099 this->issued_non_pic_error_
= true;
3102 case elfcpp::R_X86_64_NONE
:
3107 // Return whether we need to make a PLT entry for a relocation of the
3108 // given type against a STT_GNU_IFUNC symbol.
3112 Target_x86_64
<size
>::Scan::reloc_needs_plt_for_ifunc(
3113 Sized_relobj_file
<size
, false>* object
,
3114 unsigned int r_type
)
3116 int flags
= Scan::get_reference_flags(r_type
);
3117 if (flags
& Symbol::TLS_REF
)
3118 gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
3119 object
->name().c_str(), r_type
);
3123 // Scan a relocation for a local symbol.
3127 Target_x86_64
<size
>::Scan::local(Symbol_table
* symtab
,
3129 Target_x86_64
<size
>* target
,
3130 Sized_relobj_file
<size
, false>* object
,
3131 unsigned int data_shndx
,
3132 Output_section
* output_section
,
3133 const elfcpp::Rela
<size
, false>& reloc
,
3134 unsigned int r_type
,
3135 const elfcpp::Sym
<size
, false>& lsym
,
3141 // A local STT_GNU_IFUNC symbol may require a PLT entry.
3142 bool is_ifunc
= lsym
.get_st_type() == elfcpp::STT_GNU_IFUNC
;
3143 if (is_ifunc
&& this->reloc_needs_plt_for_ifunc(object
, r_type
))
3145 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3146 target
->make_local_ifunc_plt_entry(symtab
, layout
, object
, r_sym
);
3151 case elfcpp::R_X86_64_NONE
:
3152 case elfcpp::R_X86_64_GNU_VTINHERIT
:
3153 case elfcpp::R_X86_64_GNU_VTENTRY
:
3156 case elfcpp::R_X86_64_64
:
3157 // If building a shared library (or a position-independent
3158 // executable), we need to create a dynamic relocation for this
3159 // location. The relocation applied at link time will apply the
3160 // link-time value, so we flag the location with an
3161 // R_X86_64_RELATIVE relocation so the dynamic loader can
3162 // relocate it easily.
3163 if (parameters
->options().output_is_position_independent())
3165 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3166 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3167 rela_dyn
->add_local_relative(object
, r_sym
,
3169 ? elfcpp::R_X86_64_RELATIVE64
3170 : elfcpp::R_X86_64_RELATIVE
),
3171 output_section
, data_shndx
,
3172 reloc
.get_r_offset(),
3173 reloc
.get_r_addend(), is_ifunc
);
3177 case elfcpp::R_X86_64_32
:
3178 case elfcpp::R_X86_64_32S
:
3179 case elfcpp::R_X86_64_16
:
3180 case elfcpp::R_X86_64_8
:
3181 // If building a shared library (or a position-independent
3182 // executable), we need to create a dynamic relocation for this
3183 // location. We can't use an R_X86_64_RELATIVE relocation
3184 // because that is always a 64-bit relocation.
3185 if (parameters
->options().output_is_position_independent())
3187 // Use R_X86_64_RELATIVE relocation for R_X86_64_32 under x32.
3188 if (size
== 32 && r_type
== elfcpp::R_X86_64_32
)
3190 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3191 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3192 rela_dyn
->add_local_relative(object
, r_sym
,
3193 elfcpp::R_X86_64_RELATIVE
,
3194 output_section
, data_shndx
,
3195 reloc
.get_r_offset(),
3196 reloc
.get_r_addend(), is_ifunc
);
3200 this->check_non_pic(object
, r_type
, NULL
);
3202 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3203 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3204 if (lsym
.get_st_type() != elfcpp::STT_SECTION
)
3205 rela_dyn
->add_local(object
, r_sym
, r_type
, output_section
,
3206 data_shndx
, reloc
.get_r_offset(),
3207 reloc
.get_r_addend());
3210 gold_assert(lsym
.get_st_value() == 0);
3211 unsigned int shndx
= lsym
.get_st_shndx();
3213 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
,
3216 object
->error(_("section symbol %u has bad shndx %u"),
3219 rela_dyn
->add_local_section(object
, shndx
,
3220 r_type
, output_section
,
3221 data_shndx
, reloc
.get_r_offset(),
3222 reloc
.get_r_addend());
3227 case elfcpp::R_X86_64_PC64
:
3228 case elfcpp::R_X86_64_PC32
:
3229 case elfcpp::R_X86_64_PC16
:
3230 case elfcpp::R_X86_64_PC8
:
3233 case elfcpp::R_X86_64_PLT32
:
3234 // Since we know this is a local symbol, we can handle this as a
3238 case elfcpp::R_X86_64_GOTPC32
:
3239 case elfcpp::R_X86_64_GOTOFF64
:
3240 case elfcpp::R_X86_64_GOTPC64
:
3241 case elfcpp::R_X86_64_PLTOFF64
:
3242 // We need a GOT section.
3243 target
->got_section(symtab
, layout
);
3244 // For PLTOFF64, we'd normally want a PLT section, but since we
3245 // know this is a local symbol, no PLT is needed.
3248 case elfcpp::R_X86_64_GOT64
:
3249 case elfcpp::R_X86_64_GOT32
:
3250 case elfcpp::R_X86_64_GOTPCREL64
:
3251 case elfcpp::R_X86_64_GOTPCREL
:
3252 case elfcpp::R_X86_64_GOTPCRELX
:
3253 case elfcpp::R_X86_64_REX_GOTPCRELX
:
3254 case elfcpp::R_X86_64_GOTPLT64
:
3256 // The symbol requires a GOT section.
3257 Output_data_got
<64, false>* got
= target
->got_section(symtab
, layout
);
3259 // If the relocation symbol isn't IFUNC,
3260 // and is local, then we will convert
3261 // mov foo@GOTPCREL(%rip), %reg
3262 // to lea foo(%rip), %reg.
3263 // in Relocate::relocate.
3264 if (!parameters
->incremental()
3265 && (r_type
== elfcpp::R_X86_64_GOTPCREL
3266 || r_type
== elfcpp::R_X86_64_GOTPCRELX
3267 || r_type
== elfcpp::R_X86_64_REX_GOTPCRELX
)
3268 && reloc
.get_r_addend() == -4
3269 && reloc
.get_r_offset() >= 2
3272 section_size_type stype
;
3273 const unsigned char* view
= object
->section_contents(data_shndx
,
3275 if (view
[reloc
.get_r_offset() - 2] == 0x8b)
3279 // The symbol requires a GOT entry.
3280 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3282 // For a STT_GNU_IFUNC symbol we want the PLT offset. That
3283 // lets function pointers compare correctly with shared
3284 // libraries. Otherwise we would need an IRELATIVE reloc.
3287 is_new
= got
->add_local_plt(object
, r_sym
, GOT_TYPE_STANDARD
);
3289 is_new
= got
->add_local(object
, r_sym
, GOT_TYPE_STANDARD
);
3292 // If we are generating a shared object, we need to add a
3293 // dynamic relocation for this symbol's GOT entry.
3294 if (parameters
->options().output_is_position_independent())
3296 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3297 // R_X86_64_RELATIVE assumes a 64-bit relocation.
3298 if (r_type
!= elfcpp::R_X86_64_GOT32
)
3300 unsigned int got_offset
=
3301 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
);
3302 rela_dyn
->add_local_relative(object
, r_sym
,
3303 elfcpp::R_X86_64_RELATIVE
,
3304 got
, got_offset
, 0, is_ifunc
);
3308 this->check_non_pic(object
, r_type
, NULL
);
3310 gold_assert(lsym
.get_st_type() != elfcpp::STT_SECTION
);
3311 rela_dyn
->add_local(
3312 object
, r_sym
, r_type
, got
,
3313 object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
), 0);
3317 // For GOTPLT64, we'd normally want a PLT section, but since
3318 // we know this is a local symbol, no PLT is needed.
3322 case elfcpp::R_X86_64_COPY
:
3323 case elfcpp::R_X86_64_GLOB_DAT
:
3324 case elfcpp::R_X86_64_JUMP_SLOT
:
3325 case elfcpp::R_X86_64_RELATIVE
:
3326 case elfcpp::R_X86_64_IRELATIVE
:
3327 // These are outstanding tls relocs, which are unexpected when linking
3328 case elfcpp::R_X86_64_TPOFF64
:
3329 case elfcpp::R_X86_64_DTPMOD64
:
3330 case elfcpp::R_X86_64_TLSDESC
:
3331 gold_error(_("%s: unexpected reloc %u in object file"),
3332 object
->name().c_str(), r_type
);
3335 // These are initial tls relocs, which are expected when linking
3336 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
3337 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
3338 case elfcpp::R_X86_64_TLSDESC_CALL
:
3339 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3340 case elfcpp::R_X86_64_DTPOFF32
:
3341 case elfcpp::R_X86_64_DTPOFF64
:
3342 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3343 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3345 bool output_is_shared
= parameters
->options().shared();
3346 const tls::Tls_optimization optimized_type
3347 = Target_x86_64
<size
>::optimize_tls_reloc(!output_is_shared
,
3351 case elfcpp::R_X86_64_TLSGD
: // General-dynamic
3352 if (optimized_type
== tls::TLSOPT_NONE
)
3354 // Create a pair of GOT entries for the module index and
3355 // dtv-relative offset.
3356 Output_data_got
<64, false>* got
3357 = target
->got_section(symtab
, layout
);
3358 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3359 unsigned int shndx
= lsym
.get_st_shndx();
3361 shndx
= object
->adjust_sym_shndx(r_sym
, shndx
, &is_ordinary
);
3363 object
->error(_("local symbol %u has bad shndx %u"),
3366 got
->add_local_pair_with_rel(object
, r_sym
,
3369 target
->rela_dyn_section(layout
),
3370 elfcpp::R_X86_64_DTPMOD64
);
3372 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3373 unsupported_reloc_local(object
, r_type
);
3376 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
3377 target
->define_tls_base_symbol(symtab
, layout
);
3378 if (optimized_type
== tls::TLSOPT_NONE
)
3380 // Create reserved PLT and GOT entries for the resolver.
3381 target
->reserve_tlsdesc_entries(symtab
, layout
);
3383 // Generate a double GOT entry with an
3384 // R_X86_64_TLSDESC reloc. The R_X86_64_TLSDESC reloc
3385 // is resolved lazily, so the GOT entry needs to be in
3386 // an area in .got.plt, not .got. Call got_section to
3387 // make sure the section has been created.
3388 target
->got_section(symtab
, layout
);
3389 Output_data_got
<64, false>* got
= target
->got_tlsdesc_section();
3390 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3391 if (!object
->local_has_got_offset(r_sym
, GOT_TYPE_TLS_DESC
))
3393 unsigned int got_offset
= got
->add_constant(0);
3394 got
->add_constant(0);
3395 object
->set_local_got_offset(r_sym
, GOT_TYPE_TLS_DESC
,
3397 Reloc_section
* rt
= target
->rela_tlsdesc_section(layout
);
3398 // We store the arguments we need in a vector, and
3399 // use the index into the vector as the parameter
3400 // to pass to the target specific routines.
3401 uintptr_t intarg
= target
->add_tlsdesc_info(object
, r_sym
);
3402 void* arg
= reinterpret_cast<void*>(intarg
);
3403 rt
->add_target_specific(elfcpp::R_X86_64_TLSDESC
, arg
,
3404 got
, got_offset
, 0);
3407 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3408 unsupported_reloc_local(object
, r_type
);
3411 case elfcpp::R_X86_64_TLSDESC_CALL
:
3414 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3415 if (optimized_type
== tls::TLSOPT_NONE
)
3417 // Create a GOT entry for the module index.
3418 target
->got_mod_index_entry(symtab
, layout
, object
);
3420 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3421 unsupported_reloc_local(object
, r_type
);
3424 case elfcpp::R_X86_64_DTPOFF32
:
3425 case elfcpp::R_X86_64_DTPOFF64
:
3428 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3429 layout
->set_has_static_tls();
3430 if (optimized_type
== tls::TLSOPT_NONE
)
3432 // Create a GOT entry for the tp-relative offset.
3433 Output_data_got
<64, false>* got
3434 = target
->got_section(symtab
, layout
);
3435 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(reloc
.get_r_info());
3436 got
->add_local_with_rel(object
, r_sym
, GOT_TYPE_TLS_OFFSET
,
3437 target
->rela_dyn_section(layout
),
3438 elfcpp::R_X86_64_TPOFF64
);
3440 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3441 unsupported_reloc_local(object
, r_type
);
3444 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3445 layout
->set_has_static_tls();
3446 if (output_is_shared
)
3447 unsupported_reloc_local(object
, r_type
);
3456 case elfcpp::R_X86_64_SIZE32
:
3457 case elfcpp::R_X86_64_SIZE64
:
3459 gold_error(_("%s: unsupported reloc %u against local symbol"),
3460 object
->name().c_str(), r_type
);
3466 // Report an unsupported relocation against a global symbol.
3470 Target_x86_64
<size
>::Scan::unsupported_reloc_global(
3471 Sized_relobj_file
<size
, false>* object
,
3472 unsigned int r_type
,
3475 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3476 object
->name().c_str(), r_type
, gsym
->demangled_name().c_str());
3479 // Returns true if this relocation type could be that of a function pointer.
3482 Target_x86_64
<size
>::Scan::possible_function_pointer_reloc(
3483 Sized_relobj_file
<size
, false>* src_obj
,
3484 unsigned int src_indx
,
3485 unsigned int r_offset
,
3486 unsigned int r_type
)
3490 case elfcpp::R_X86_64_64
:
3491 case elfcpp::R_X86_64_32
:
3492 case elfcpp::R_X86_64_32S
:
3493 case elfcpp::R_X86_64_16
:
3494 case elfcpp::R_X86_64_8
:
3495 case elfcpp::R_X86_64_GOT64
:
3496 case elfcpp::R_X86_64_GOT32
:
3497 case elfcpp::R_X86_64_GOTPCREL64
:
3498 case elfcpp::R_X86_64_GOTPCREL
:
3499 case elfcpp::R_X86_64_GOTPCRELX
:
3500 case elfcpp::R_X86_64_REX_GOTPCRELX
:
3501 case elfcpp::R_X86_64_GOTPLT64
:
3505 case elfcpp::R_X86_64_PC32
:
3507 // This relocation may be used both for function calls and
3508 // for taking address of a function. We distinguish between
3509 // them by checking the opcodes.
3510 uint64_t sh_flags
= src_obj
->section_flags(src_indx
);
3511 bool is_executable
= (sh_flags
& elfcpp::SHF_EXECINSTR
) != 0;
3514 section_size_type stype
;
3515 const unsigned char* view
= src_obj
->section_contents(src_indx
,
3521 && view
[r_offset
- 1] == 0xe8)
3526 && view
[r_offset
- 1] == 0xe9)
3529 // jo/jno/jb/jnb/je/jne/jna/ja/js/jns/jp/jnp/jl/jge/jle/jg
3531 && view
[r_offset
- 2] == 0x0f
3532 && view
[r_offset
- 1] >= 0x80
3533 && view
[r_offset
- 1] <= 0x8f)
3537 // Be conservative and treat all others as function pointers.
3544 // For safe ICF, scan a relocation for a local symbol to check if it
3545 // corresponds to a function pointer being taken. In that case mark
3546 // the function whose pointer was taken as not foldable.
3550 Target_x86_64
<size
>::Scan::local_reloc_may_be_function_pointer(
3553 Target_x86_64
<size
>* ,
3554 Sized_relobj_file
<size
, false>* src_obj
,
3555 unsigned int src_indx
,
3557 const elfcpp::Rela
<size
, false>& reloc
,
3558 unsigned int r_type
,
3559 const elfcpp::Sym
<size
, false>&)
3561 return possible_function_pointer_reloc(src_obj
, src_indx
,
3562 reloc
.get_r_offset(), r_type
);
3565 // For safe ICF, scan a relocation for a global symbol to check if it
3566 // corresponds to a function pointer being taken. In that case mark
3567 // the function whose pointer was taken as not foldable.
3571 Target_x86_64
<size
>::Scan::global_reloc_may_be_function_pointer(
3574 Target_x86_64
<size
>* ,
3575 Sized_relobj_file
<size
, false>* src_obj
,
3576 unsigned int src_indx
,
3578 const elfcpp::Rela
<size
, false>& reloc
,
3579 unsigned int r_type
,
3582 return possible_function_pointer_reloc(src_obj
, src_indx
,
3583 reloc
.get_r_offset(), r_type
);
3586 // Scan a relocation for a global symbol.
3590 Target_x86_64
<size
>::Scan::global(Symbol_table
* symtab
,
3592 Target_x86_64
<size
>* target
,
3593 Sized_relobj_file
<size
, false>* object
,
3594 unsigned int data_shndx
,
3595 Output_section
* output_section
,
3596 const elfcpp::Rela
<size
, false>& reloc
,
3597 unsigned int r_type
,
3600 // A STT_GNU_IFUNC symbol may require a PLT entry.
3601 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
3602 && this->reloc_needs_plt_for_ifunc(object
, r_type
))
3603 target
->make_plt_entry(symtab
, layout
, gsym
);
3607 case elfcpp::R_X86_64_NONE
:
3608 case elfcpp::R_X86_64_GNU_VTINHERIT
:
3609 case elfcpp::R_X86_64_GNU_VTENTRY
:
3612 case elfcpp::R_X86_64_64
:
3613 case elfcpp::R_X86_64_32
:
3614 case elfcpp::R_X86_64_32S
:
3615 case elfcpp::R_X86_64_16
:
3616 case elfcpp::R_X86_64_8
:
3618 // Make a PLT entry if necessary.
3619 if (gsym
->needs_plt_entry())
3621 target
->make_plt_entry(symtab
, layout
, gsym
);
3622 // Since this is not a PC-relative relocation, we may be
3623 // taking the address of a function. In that case we need to
3624 // set the entry in the dynamic symbol table to the address of
3626 if (gsym
->is_from_dynobj() && !parameters
->options().shared())
3627 gsym
->set_needs_dynsym_value();
3629 // Make a dynamic relocation if necessary.
3630 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
3632 if (!parameters
->options().output_is_position_independent()
3633 && gsym
->may_need_copy_reloc())
3635 target
->copy_reloc(symtab
, layout
, object
,
3636 data_shndx
, output_section
, gsym
, reloc
);
3638 else if (((size
== 64 && r_type
== elfcpp::R_X86_64_64
)
3639 || (size
== 32 && r_type
== elfcpp::R_X86_64_32
))
3640 && gsym
->type() == elfcpp::STT_GNU_IFUNC
3641 && gsym
->can_use_relative_reloc(false)
3642 && !gsym
->is_from_dynobj()
3643 && !gsym
->is_undefined()
3644 && !gsym
->is_preemptible())
3646 // Use an IRELATIVE reloc for a locally defined
3647 // STT_GNU_IFUNC symbol. This makes a function
3648 // address in a PIE executable match the address in a
3649 // shared library that it links against.
3650 Reloc_section
* rela_dyn
=
3651 target
->rela_irelative_section(layout
);
3652 unsigned int r_type
= elfcpp::R_X86_64_IRELATIVE
;
3653 rela_dyn
->add_symbolless_global_addend(gsym
, r_type
,
3654 output_section
, object
,
3656 reloc
.get_r_offset(),
3657 reloc
.get_r_addend());
3659 else if (((size
== 64 && r_type
== elfcpp::R_X86_64_64
)
3660 || (size
== 32 && r_type
== elfcpp::R_X86_64_32
))
3661 && gsym
->can_use_relative_reloc(false))
3663 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3664 rela_dyn
->add_global_relative(gsym
, elfcpp::R_X86_64_RELATIVE
,
3665 output_section
, object
,
3667 reloc
.get_r_offset(),
3668 reloc
.get_r_addend(), false);
3672 this->check_non_pic(object
, r_type
, gsym
);
3673 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3674 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
3675 data_shndx
, reloc
.get_r_offset(),
3676 reloc
.get_r_addend());
3682 case elfcpp::R_X86_64_PC64
:
3683 case elfcpp::R_X86_64_PC32
:
3684 case elfcpp::R_X86_64_PC16
:
3685 case elfcpp::R_X86_64_PC8
:
3687 // Make a PLT entry if necessary.
3688 if (gsym
->needs_plt_entry())
3689 target
->make_plt_entry(symtab
, layout
, gsym
);
3690 // Make a dynamic relocation if necessary.
3691 if (gsym
->needs_dynamic_reloc(Scan::get_reference_flags(r_type
)))
3693 if (parameters
->options().output_is_executable()
3694 && gsym
->may_need_copy_reloc())
3696 target
->copy_reloc(symtab
, layout
, object
,
3697 data_shndx
, output_section
, gsym
, reloc
);
3701 this->check_non_pic(object
, r_type
, gsym
);
3702 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3703 rela_dyn
->add_global(gsym
, r_type
, output_section
, object
,
3704 data_shndx
, reloc
.get_r_offset(),
3705 reloc
.get_r_addend());
3711 case elfcpp::R_X86_64_GOT64
:
3712 case elfcpp::R_X86_64_GOT32
:
3713 case elfcpp::R_X86_64_GOTPCREL64
:
3714 case elfcpp::R_X86_64_GOTPCREL
:
3715 case elfcpp::R_X86_64_GOTPCRELX
:
3716 case elfcpp::R_X86_64_REX_GOTPCRELX
:
3717 case elfcpp::R_X86_64_GOTPLT64
:
3719 // The symbol requires a GOT entry.
3720 Output_data_got
<64, false>* got
= target
->got_section(symtab
, layout
);
3722 // If we convert this from
3723 // mov foo@GOTPCREL(%rip), %reg
3724 // to lea foo(%rip), %reg.
3727 // (callq|jmpq) *foo@GOTPCRELX(%rip) to
3729 // in Relocate::relocate, then there is nothing to do here.
3730 // We cannot make these optimizations in incremental linking mode,
3731 // because we look at the opcode to decide whether or not to make
3732 // change, and during an incremental update, the change may have
3733 // already been applied.
3735 Lazy_view
<size
> view(object
, data_shndx
);
3736 size_t r_offset
= reloc
.get_r_offset();
3737 if (!parameters
->incremental()
3738 && reloc
.get_r_addend() == -4
3740 && Target_x86_64
<size
>::can_convert_mov_to_lea(gsym
, r_type
,
3744 if (!parameters
->incremental()
3746 && Target_x86_64
<size
>::can_convert_callq_to_direct(gsym
, r_type
,
3751 if (gsym
->final_value_is_known())
3753 // For a STT_GNU_IFUNC symbol we want the PLT address.
3754 if (gsym
->type() == elfcpp::STT_GNU_IFUNC
)
3755 got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
3757 got
->add_global(gsym
, GOT_TYPE_STANDARD
);
3761 // If this symbol is not fully resolved, we need to add a
3762 // dynamic relocation for it.
3763 Reloc_section
* rela_dyn
= target
->rela_dyn_section(layout
);
3765 // Use a GLOB_DAT rather than a RELATIVE reloc if:
3767 // 1) The symbol may be defined in some other module.
3769 // 2) We are building a shared library and this is a
3770 // protected symbol; using GLOB_DAT means that the dynamic
3771 // linker can use the address of the PLT in the main
3772 // executable when appropriate so that function address
3773 // comparisons work.
3775 // 3) This is a STT_GNU_IFUNC symbol in position dependent
3776 // code, again so that function address comparisons work.
3777 if (gsym
->is_from_dynobj()
3778 || gsym
->is_undefined()
3779 || gsym
->is_preemptible()
3780 || (gsym
->visibility() == elfcpp::STV_PROTECTED
3781 && parameters
->options().shared())
3782 || (gsym
->type() == elfcpp::STT_GNU_IFUNC
3783 && parameters
->options().output_is_position_independent()))
3784 got
->add_global_with_rel(gsym
, GOT_TYPE_STANDARD
, rela_dyn
,
3785 elfcpp::R_X86_64_GLOB_DAT
);
3788 // For a STT_GNU_IFUNC symbol we want to write the PLT
3789 // offset into the GOT, so that function pointer
3790 // comparisons work correctly.
3792 if (gsym
->type() != elfcpp::STT_GNU_IFUNC
)
3793 is_new
= got
->add_global(gsym
, GOT_TYPE_STANDARD
);
3796 is_new
= got
->add_global_plt(gsym
, GOT_TYPE_STANDARD
);
3797 // Tell the dynamic linker to use the PLT address
3798 // when resolving relocations.
3799 if (gsym
->is_from_dynobj()
3800 && !parameters
->options().shared())
3801 gsym
->set_needs_dynsym_value();
3805 unsigned int got_off
= gsym
->got_offset(GOT_TYPE_STANDARD
);
3806 rela_dyn
->add_global_relative(gsym
,
3807 elfcpp::R_X86_64_RELATIVE
,
3808 got
, got_off
, 0, false);
3815 case elfcpp::R_X86_64_PLT32
:
3816 // If the symbol is fully resolved, this is just a PC32 reloc.
3817 // Otherwise we need a PLT entry.
3818 if (gsym
->final_value_is_known())
3820 // If building a shared library, we can also skip the PLT entry
3821 // if the symbol is defined in the output file and is protected
3823 if (gsym
->is_defined()
3824 && !gsym
->is_from_dynobj()
3825 && !gsym
->is_preemptible())
3827 target
->make_plt_entry(symtab
, layout
, gsym
);
3830 case elfcpp::R_X86_64_GOTPC32
:
3831 case elfcpp::R_X86_64_GOTOFF64
:
3832 case elfcpp::R_X86_64_GOTPC64
:
3833 case elfcpp::R_X86_64_PLTOFF64
:
3834 // We need a GOT section.
3835 target
->got_section(symtab
, layout
);
3836 // For PLTOFF64, we also need a PLT entry (but only if the
3837 // symbol is not fully resolved).
3838 if (r_type
== elfcpp::R_X86_64_PLTOFF64
3839 && !gsym
->final_value_is_known())
3840 target
->make_plt_entry(symtab
, layout
, gsym
);
3843 case elfcpp::R_X86_64_COPY
:
3844 case elfcpp::R_X86_64_GLOB_DAT
:
3845 case elfcpp::R_X86_64_JUMP_SLOT
:
3846 case elfcpp::R_X86_64_RELATIVE
:
3847 case elfcpp::R_X86_64_IRELATIVE
:
3848 // These are outstanding tls relocs, which are unexpected when linking
3849 case elfcpp::R_X86_64_TPOFF64
:
3850 case elfcpp::R_X86_64_DTPMOD64
:
3851 case elfcpp::R_X86_64_TLSDESC
:
3852 gold_error(_("%s: unexpected reloc %u in object file"),
3853 object
->name().c_str(), r_type
);
3856 // These are initial tls relocs, which are expected for global()
3857 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
3858 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
3859 case elfcpp::R_X86_64_TLSDESC_CALL
:
3860 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3861 case elfcpp::R_X86_64_DTPOFF32
:
3862 case elfcpp::R_X86_64_DTPOFF64
:
3863 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3864 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3866 // For the Initial-Exec model, we can treat undef symbols as final
3867 // when building an executable.
3868 const bool is_final
= (gsym
->final_value_is_known() ||
3869 (r_type
== elfcpp::R_X86_64_GOTTPOFF
&&
3870 gsym
->is_undefined() &&
3871 parameters
->options().output_is_executable()));
3872 const tls::Tls_optimization optimized_type
3873 = Target_x86_64
<size
>::optimize_tls_reloc(is_final
, r_type
);
3876 case elfcpp::R_X86_64_TLSGD
: // General-dynamic
3877 if (optimized_type
== tls::TLSOPT_NONE
)
3879 // Create a pair of GOT entries for the module index and
3880 // dtv-relative offset.
3881 Output_data_got
<64, false>* got
3882 = target
->got_section(symtab
, layout
);
3883 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_PAIR
,
3884 target
->rela_dyn_section(layout
),
3885 elfcpp::R_X86_64_DTPMOD64
,
3886 elfcpp::R_X86_64_DTPOFF64
);
3888 else if (optimized_type
== tls::TLSOPT_TO_IE
)
3890 // Create a GOT entry for the tp-relative offset.
3891 Output_data_got
<64, false>* got
3892 = target
->got_section(symtab
, layout
);
3893 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
3894 target
->rela_dyn_section(layout
),
3895 elfcpp::R_X86_64_TPOFF64
);
3897 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3898 unsupported_reloc_global(object
, r_type
, gsym
);
3901 case elfcpp::R_X86_64_GOTPC32_TLSDESC
:
3902 target
->define_tls_base_symbol(symtab
, layout
);
3903 if (optimized_type
== tls::TLSOPT_NONE
)
3905 // Create reserved PLT and GOT entries for the resolver.
3906 target
->reserve_tlsdesc_entries(symtab
, layout
);
3908 // Create a double GOT entry with an R_X86_64_TLSDESC
3909 // reloc. The R_X86_64_TLSDESC reloc is resolved
3910 // lazily, so the GOT entry needs to be in an area in
3911 // .got.plt, not .got. Call got_section to make sure
3912 // the section has been created.
3913 target
->got_section(symtab
, layout
);
3914 Output_data_got
<64, false>* got
= target
->got_tlsdesc_section();
3915 Reloc_section
* rt
= target
->rela_tlsdesc_section(layout
);
3916 got
->add_global_pair_with_rel(gsym
, GOT_TYPE_TLS_DESC
, rt
,
3917 elfcpp::R_X86_64_TLSDESC
, 0);
3919 else if (optimized_type
== tls::TLSOPT_TO_IE
)
3921 // Create a GOT entry for the tp-relative offset.
3922 Output_data_got
<64, false>* got
3923 = target
->got_section(symtab
, layout
);
3924 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
3925 target
->rela_dyn_section(layout
),
3926 elfcpp::R_X86_64_TPOFF64
);
3928 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3929 unsupported_reloc_global(object
, r_type
, gsym
);
3932 case elfcpp::R_X86_64_TLSDESC_CALL
:
3935 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
3936 if (optimized_type
== tls::TLSOPT_NONE
)
3938 // Create a GOT entry for the module index.
3939 target
->got_mod_index_entry(symtab
, layout
, object
);
3941 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3942 unsupported_reloc_global(object
, r_type
, gsym
);
3945 case elfcpp::R_X86_64_DTPOFF32
:
3946 case elfcpp::R_X86_64_DTPOFF64
:
3949 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
3950 layout
->set_has_static_tls();
3951 if (optimized_type
== tls::TLSOPT_NONE
)
3953 // Create a GOT entry for the tp-relative offset.
3954 Output_data_got
<64, false>* got
3955 = target
->got_section(symtab
, layout
);
3956 got
->add_global_with_rel(gsym
, GOT_TYPE_TLS_OFFSET
,
3957 target
->rela_dyn_section(layout
),
3958 elfcpp::R_X86_64_TPOFF64
);
3960 else if (optimized_type
!= tls::TLSOPT_TO_LE
)
3961 unsupported_reloc_global(object
, r_type
, gsym
);
3964 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
3965 layout
->set_has_static_tls();
3966 if (parameters
->options().shared())
3967 unsupported_reloc_global(object
, r_type
, gsym
);
3976 case elfcpp::R_X86_64_SIZE32
:
3977 case elfcpp::R_X86_64_SIZE64
:
3979 gold_error(_("%s: unsupported reloc %u against global symbol %s"),
3980 object
->name().c_str(), r_type
,
3981 gsym
->demangled_name().c_str());
3988 Target_x86_64
<size
>::gc_process_relocs(Symbol_table
* symtab
,
3990 Sized_relobj_file
<size
, false>* object
,
3991 unsigned int data_shndx
,
3992 unsigned int sh_type
,
3993 const unsigned char* prelocs
,
3995 Output_section
* output_section
,
3996 bool needs_special_offset_handling
,
3997 size_t local_symbol_count
,
3998 const unsigned char* plocal_symbols
)
4000 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
4003 if (sh_type
== elfcpp::SHT_REL
)
4008 gold::gc_process_relocs
<size
, false, Target_x86_64
<size
>, Scan
,
4018 needs_special_offset_handling
,
4023 // Scan relocations for a section.
4027 Target_x86_64
<size
>::scan_relocs(Symbol_table
* symtab
,
4029 Sized_relobj_file
<size
, false>* object
,
4030 unsigned int data_shndx
,
4031 unsigned int sh_type
,
4032 const unsigned char* prelocs
,
4034 Output_section
* output_section
,
4035 bool needs_special_offset_handling
,
4036 size_t local_symbol_count
,
4037 const unsigned char* plocal_symbols
)
4039 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
4042 if (sh_type
== elfcpp::SHT_REL
)
4044 gold_error(_("%s: unsupported REL reloc section"),
4045 object
->name().c_str());
4049 gold::scan_relocs
<size
, false, Target_x86_64
<size
>, Scan
, Classify_reloc
>(
4058 needs_special_offset_handling
,
4063 // Finalize the sections.
4067 Target_x86_64
<size
>::do_finalize_sections(
4069 const Input_objects
*,
4070 Symbol_table
* symtab
)
4072 const Reloc_section
* rel_plt
= (this->plt_
== NULL
4074 : this->plt_
->rela_plt());
4075 layout
->add_target_dynamic_tags(false, this->got_plt_
, rel_plt
,
4076 this->rela_dyn_
, true, false, false);
4078 // Fill in some more dynamic tags.
4079 Output_data_dynamic
* const odyn
= layout
->dynamic_data();
4082 if (this->plt_
!= NULL
4083 && this->plt_
->output_section() != NULL
4084 && this->plt_
->has_tlsdesc_entry())
4086 unsigned int plt_offset
= this->plt_
->get_tlsdesc_plt_offset();
4087 unsigned int got_offset
= this->plt_
->get_tlsdesc_got_offset();
4088 this->got_
->finalize_data_size();
4089 odyn
->add_section_plus_offset(elfcpp::DT_TLSDESC_PLT
,
4090 this->plt_
, plt_offset
);
4091 odyn
->add_section_plus_offset(elfcpp::DT_TLSDESC_GOT
,
4092 this->got_
, got_offset
);
4096 // Emit any relocs we saved in an attempt to avoid generating COPY
4098 if (this->copy_relocs_
.any_saved_relocs())
4099 this->copy_relocs_
.emit(this->rela_dyn_section(layout
));
4101 // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
4102 // the .got.plt section.
4103 Symbol
* sym
= this->global_offset_table_
;
4106 uint64_t data_size
= this->got_plt_
->current_data_size();
4107 symtab
->get_sized_symbol
<size
>(sym
)->set_symsize(data_size
);
4110 if (parameters
->doing_static_link()
4111 && (this->plt_
== NULL
|| !this->plt_
->has_irelative_section()))
4113 // If linking statically, make sure that the __rela_iplt symbols
4114 // were defined if necessary, even if we didn't create a PLT.
4115 static const Define_symbol_in_segment syms
[] =
4118 "__rela_iplt_start", // name
4119 elfcpp::PT_LOAD
, // segment_type
4120 elfcpp::PF_W
, // segment_flags_set
4121 elfcpp::PF(0), // segment_flags_clear
4124 elfcpp::STT_NOTYPE
, // type
4125 elfcpp::STB_GLOBAL
, // binding
4126 elfcpp::STV_HIDDEN
, // visibility
4128 Symbol::SEGMENT_START
, // offset_from_base
4132 "__rela_iplt_end", // name
4133 elfcpp::PT_LOAD
, // segment_type
4134 elfcpp::PF_W
, // segment_flags_set
4135 elfcpp::PF(0), // segment_flags_clear
4138 elfcpp::STT_NOTYPE
, // type
4139 elfcpp::STB_GLOBAL
, // binding
4140 elfcpp::STV_HIDDEN
, // visibility
4142 Symbol::SEGMENT_START
, // offset_from_base
4147 symtab
->define_symbols(layout
, 2, syms
,
4148 layout
->script_options()->saw_sections_clause());
4152 // For x32, we need to handle PC-relative relocations using full 64-bit
4153 // arithmetic, so that we can detect relocation overflows properly.
4154 // This class overrides the pcrela32_check methods from the defaults in
4155 // Relocate_functions in reloc.h.
4158 class X86_64_relocate_functions
: public Relocate_functions
<size
, false>
4161 typedef Relocate_functions
<size
, false> Base
;
4163 // Do a simple PC relative relocation with the addend in the
4165 static inline typename
Base::Reloc_status
4166 pcrela32_check(unsigned char* view
,
4167 typename
elfcpp::Elf_types
<64>::Elf_Addr value
,
4168 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
,
4169 typename
elfcpp::Elf_types
<64>::Elf_Addr address
)
4171 typedef typename
elfcpp::Swap
<32, false>::Valtype Valtype
;
4172 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
4173 value
= value
+ addend
- address
;
4174 elfcpp::Swap
<32, false>::writeval(wv
, value
);
4175 return (Bits
<32>::has_overflow(value
)
4176 ? Base::RELOC_OVERFLOW
: Base::RELOC_OK
);
4179 // Do a simple PC relative relocation with a Symbol_value with the
4180 // addend in the relocation.
4181 static inline typename
Base::Reloc_status
4182 pcrela32_check(unsigned char* view
,
4183 const Sized_relobj_file
<size
, false>* object
,
4184 const Symbol_value
<size
>* psymval
,
4185 typename
elfcpp::Elf_types
<64>::Elf_Swxword addend
,
4186 typename
elfcpp::Elf_types
<64>::Elf_Addr address
)
4188 typedef typename
elfcpp::Swap
<32, false>::Valtype Valtype
;
4189 Valtype
* wv
= reinterpret_cast<Valtype
*>(view
);
4190 typename
elfcpp::Elf_types
<64>::Elf_Addr value
;
4192 value
= psymval
->value(object
, addend
);
4195 // For negative addends, get the symbol value without
4196 // the addend, then add the addend using 64-bit arithmetic.
4197 value
= psymval
->value(object
, 0);
4201 elfcpp::Swap
<32, false>::writeval(wv
, value
);
4202 return (Bits
<32>::has_overflow(value
)
4203 ? Base::RELOC_OVERFLOW
: Base::RELOC_OK
);
4207 // Perform a relocation.
4211 Target_x86_64
<size
>::Relocate::relocate(
4212 const Relocate_info
<size
, false>* relinfo
,
4214 Target_x86_64
<size
>* target
,
4217 const unsigned char* preloc
,
4218 const Sized_symbol
<size
>* gsym
,
4219 const Symbol_value
<size
>* psymval
,
4220 unsigned char* view
,
4221 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4222 section_size_type view_size
)
4224 typedef X86_64_relocate_functions
<size
> Reloc_funcs
;
4225 const elfcpp::Rela
<size
, false> rela(preloc
);
4226 unsigned int r_type
= elfcpp::elf_r_type
<size
>(rela
.get_r_info());
4228 if (this->skip_call_tls_get_addr_
)
4230 if ((r_type
!= elfcpp::R_X86_64_PLT32
4231 && r_type
!= elfcpp::R_X86_64_GOTPCREL
4232 && r_type
!= elfcpp::R_X86_64_GOTPCRELX
4233 && r_type
!= elfcpp::R_X86_64_PC32
)
4235 || strcmp(gsym
->name(), "__tls_get_addr") != 0)
4237 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4238 _("missing expected TLS relocation"));
4239 this->skip_call_tls_get_addr_
= false;
4243 this->skip_call_tls_get_addr_
= false;
4251 const Sized_relobj_file
<size
, false>* object
= relinfo
->object
;
4253 // Pick the value to use for symbols defined in the PLT.
4254 Symbol_value
<size
> symval
;
4256 && gsym
->use_plt_offset(Scan::get_reference_flags(r_type
)))
4258 symval
.set_output_value(target
->plt_address_for_global(gsym
));
4261 else if (gsym
== NULL
&& psymval
->is_ifunc_symbol())
4263 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4264 if (object
->local_has_plt_offset(r_sym
))
4266 symval
.set_output_value(target
->plt_address_for_local(object
, r_sym
));
4271 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
4273 // Get the GOT offset if needed.
4274 // The GOT pointer points to the end of the GOT section.
4275 // We need to subtract the size of the GOT section to get
4276 // the actual offset to use in the relocation.
4277 bool have_got_offset
= false;
4278 // Since the actual offset is always negative, we use signed int to
4279 // support 64-bit GOT relocations.
4283 case elfcpp::R_X86_64_GOT32
:
4284 case elfcpp::R_X86_64_GOT64
:
4285 case elfcpp::R_X86_64_GOTPLT64
:
4286 case elfcpp::R_X86_64_GOTPCREL64
:
4289 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
4290 got_offset
= gsym
->got_offset(GOT_TYPE_STANDARD
) - target
->got_size();
4294 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4295 gold_assert(object
->local_has_got_offset(r_sym
, GOT_TYPE_STANDARD
));
4296 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
4297 - target
->got_size());
4299 have_got_offset
= true;
4306 typename
Reloc_funcs::Reloc_status rstatus
= Reloc_funcs::RELOC_OK
;
4310 case elfcpp::R_X86_64_NONE
:
4311 case elfcpp::R_X86_64_GNU_VTINHERIT
:
4312 case elfcpp::R_X86_64_GNU_VTENTRY
:
4315 case elfcpp::R_X86_64_64
:
4316 Reloc_funcs::rela64(view
, object
, psymval
, addend
);
4319 case elfcpp::R_X86_64_PC64
:
4320 Reloc_funcs::pcrela64(view
, object
, psymval
, addend
,
4324 case elfcpp::R_X86_64_32
:
4325 rstatus
= Reloc_funcs::rela32_check(view
, object
, psymval
, addend
,
4326 Reloc_funcs::CHECK_UNSIGNED
);
4329 case elfcpp::R_X86_64_32S
:
4330 rstatus
= Reloc_funcs::rela32_check(view
, object
, psymval
, addend
,
4331 Reloc_funcs::CHECK_SIGNED
);
4334 case elfcpp::R_X86_64_PC32
:
4335 rstatus
= Reloc_funcs::pcrela32_check(view
, object
, psymval
, addend
,
4339 case elfcpp::R_X86_64_16
:
4340 Reloc_funcs::rela16(view
, object
, psymval
, addend
);
4343 case elfcpp::R_X86_64_PC16
:
4344 Reloc_funcs::pcrela16(view
, object
, psymval
, addend
, address
);
4347 case elfcpp::R_X86_64_8
:
4348 Reloc_funcs::rela8(view
, object
, psymval
, addend
);
4351 case elfcpp::R_X86_64_PC8
:
4352 Reloc_funcs::pcrela8(view
, object
, psymval
, addend
, address
);
4355 case elfcpp::R_X86_64_PLT32
:
4356 gold_assert(gsym
== NULL
4357 || gsym
->has_plt_offset()
4358 || gsym
->final_value_is_known()
4359 || (gsym
->is_defined()
4360 && !gsym
->is_from_dynobj()
4361 && !gsym
->is_preemptible()));
4362 // Note: while this code looks the same as for R_X86_64_PC32, it
4363 // behaves differently because psymval was set to point to
4364 // the PLT entry, rather than the symbol, in Scan::global().
4365 rstatus
= Reloc_funcs::pcrela32_check(view
, object
, psymval
, addend
,
4369 case elfcpp::R_X86_64_PLTOFF64
:
4372 gold_assert(gsym
->has_plt_offset()
4373 || gsym
->final_value_is_known());
4374 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
;
4375 // This is the address of GLOBAL_OFFSET_TABLE.
4376 got_address
= target
->got_plt_section()->address();
4377 Reloc_funcs::rela64(view
, object
, psymval
, addend
- got_address
);
4381 case elfcpp::R_X86_64_GOT32
:
4382 gold_assert(have_got_offset
);
4383 Reloc_funcs::rela32(view
, got_offset
, addend
);
4386 case elfcpp::R_X86_64_GOTPC32
:
4389 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
4390 value
= target
->got_plt_section()->address();
4391 Reloc_funcs::pcrela32_check(view
, value
, addend
, address
);
4395 case elfcpp::R_X86_64_GOT64
:
4396 case elfcpp::R_X86_64_GOTPLT64
:
4397 // R_X86_64_GOTPLT64 is obsolete and treated the same as
4399 gold_assert(have_got_offset
);
4400 Reloc_funcs::rela64(view
, got_offset
, addend
);
4403 case elfcpp::R_X86_64_GOTPC64
:
4406 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
4407 value
= target
->got_plt_section()->address();
4408 Reloc_funcs::pcrela64(view
, value
, addend
, address
);
4412 case elfcpp::R_X86_64_GOTOFF64
:
4414 typename
elfcpp::Elf_types
<size
>::Elf_Addr reladdr
;
4415 reladdr
= target
->got_plt_section()->address();
4416 Reloc_funcs::pcrela64(view
, object
, psymval
, addend
, reladdr
);
4420 case elfcpp::R_X86_64_GOTPCREL
:
4421 case elfcpp::R_X86_64_GOTPCRELX
:
4422 case elfcpp::R_X86_64_REX_GOTPCRELX
:
4424 bool converted_p
= false;
4426 if (rela
.get_r_addend() == -4)
4429 // mov foo@GOTPCREL(%rip), %reg
4430 // to lea foo(%rip), %reg.
4432 if (!parameters
->incremental()
4434 && rela
.get_r_offset() >= 2
4436 && !psymval
->is_ifunc_symbol())
4438 && rela
.get_r_offset() >= 2
4439 && Target_x86_64
<size
>::can_convert_mov_to_lea(gsym
,
4445 Reloc_funcs::pcrela32(view
, object
, psymval
, addend
, address
);
4449 // callq *foo@GOTPCRELX(%rip) to
4451 // and jmpq *foo@GOTPCRELX(%rip) to
4454 else if (!parameters
->incremental()
4456 && rela
.get_r_offset() >= 2
4457 && Target_x86_64
<size
>::can_convert_callq_to_direct(gsym
,
4462 if (view
[-1] == 0x15)
4464 // Convert callq *foo@GOTPCRELX(%rip) to addr32 callq.
4465 // Opcode of addr32 is 0x67 and opcode of direct callq
4469 // Convert GOTPCRELX to 32-bit pc relative reloc.
4470 Reloc_funcs::pcrela32(view
, object
, psymval
, addend
,
4476 // Convert jmpq *foo@GOTPCRELX(%rip) to
4479 // The opcode of direct jmpq is 0xe9.
4481 // The opcode of nop is 0x90.
4483 // Convert GOTPCRELX to 32-bit pc relative reloc. jmpq
4484 // is rip relative and since the instruction following
4485 // the jmpq is now the nop, offset the address by 1
4486 // byte. The start of the relocation also moves ahead
4488 Reloc_funcs::pcrela32(&view
[-1], object
, psymval
, addend
,
4499 gold_assert(gsym
->has_got_offset(GOT_TYPE_STANDARD
));
4500 got_offset
= (gsym
->got_offset(GOT_TYPE_STANDARD
)
4501 - target
->got_size());
4505 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4506 gold_assert(object
->local_has_got_offset(r_sym
,
4507 GOT_TYPE_STANDARD
));
4508 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_STANDARD
)
4509 - target
->got_size());
4511 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
4512 value
= target
->got_plt_section()->address() + got_offset
;
4513 Reloc_funcs::pcrela32_check(view
, value
, addend
, address
);
4518 case elfcpp::R_X86_64_GOTPCREL64
:
4520 gold_assert(have_got_offset
);
4521 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
;
4522 value
= target
->got_plt_section()->address() + got_offset
;
4523 Reloc_funcs::pcrela64(view
, value
, addend
, address
);
4527 case elfcpp::R_X86_64_COPY
:
4528 case elfcpp::R_X86_64_GLOB_DAT
:
4529 case elfcpp::R_X86_64_JUMP_SLOT
:
4530 case elfcpp::R_X86_64_RELATIVE
:
4531 case elfcpp::R_X86_64_IRELATIVE
:
4532 // These are outstanding tls relocs, which are unexpected when linking
4533 case elfcpp::R_X86_64_TPOFF64
:
4534 case elfcpp::R_X86_64_DTPMOD64
:
4535 case elfcpp::R_X86_64_TLSDESC
:
4536 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4537 _("unexpected reloc %u in object file"),
4541 // These are initial tls relocs, which are expected when linking
4542 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
4543 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
4544 case elfcpp::R_X86_64_TLSDESC_CALL
:
4545 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
4546 case elfcpp::R_X86_64_DTPOFF32
:
4547 case elfcpp::R_X86_64_DTPOFF64
:
4548 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
4549 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
4550 this->relocate_tls(relinfo
, target
, relnum
, rela
, r_type
, gsym
, psymval
,
4551 view
, address
, view_size
);
4554 case elfcpp::R_X86_64_SIZE32
:
4555 case elfcpp::R_X86_64_SIZE64
:
4557 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4558 _("unsupported reloc %u"),
4563 if (rstatus
== Reloc_funcs::RELOC_OVERFLOW
)
4567 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4568 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4569 _("relocation overflow: "
4570 "reference to local symbol %u in %s"),
4571 r_sym
, object
->name().c_str());
4573 else if (gsym
->is_defined() && gsym
->source() == Symbol::FROM_OBJECT
)
4575 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4576 _("relocation overflow: "
4577 "reference to '%s' defined in %s"),
4579 gsym
->object()->name().c_str());
4583 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4584 _("relocation overflow: reference to '%s'"),
4592 // Perform a TLS relocation.
4596 Target_x86_64
<size
>::Relocate::relocate_tls(
4597 const Relocate_info
<size
, false>* relinfo
,
4598 Target_x86_64
<size
>* target
,
4600 const elfcpp::Rela
<size
, false>& rela
,
4601 unsigned int r_type
,
4602 const Sized_symbol
<size
>* gsym
,
4603 const Symbol_value
<size
>* psymval
,
4604 unsigned char* view
,
4605 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4606 section_size_type view_size
)
4608 Output_segment
* tls_segment
= relinfo
->layout
->tls_segment();
4610 const Sized_relobj_file
<size
, false>* object
= relinfo
->object
;
4611 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
4612 elfcpp::Shdr
<size
, false> data_shdr(relinfo
->data_shdr
);
4613 bool is_executable
= (data_shdr
.get_sh_flags() & elfcpp::SHF_EXECINSTR
) != 0;
4615 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
= psymval
->value(relinfo
->object
, 0);
4617 const bool is_final
= (gsym
== NULL
4618 ? !parameters
->options().shared()
4619 : gsym
->final_value_is_known());
4620 tls::Tls_optimization optimized_type
4621 = Target_x86_64
<size
>::optimize_tls_reloc(is_final
, r_type
);
4624 case elfcpp::R_X86_64_TLSGD
: // Global-dynamic
4625 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
4627 // If this code sequence is used in a non-executable section,
4628 // we will not optimize the R_X86_64_DTPOFF32/64 relocation,
4629 // on the assumption that it's being used by itself in a debug
4630 // section. Therefore, in the unlikely event that the code
4631 // sequence appears in a non-executable section, we simply
4632 // leave it unoptimized.
4633 optimized_type
= tls::TLSOPT_NONE
;
4635 if (optimized_type
== tls::TLSOPT_TO_LE
)
4637 if (tls_segment
== NULL
)
4639 gold_assert(parameters
->errors()->error_count() > 0
4640 || issue_undefined_symbol_error(gsym
));
4643 this->tls_gd_to_le(relinfo
, relnum
, tls_segment
,
4644 rela
, r_type
, value
, view
,
4650 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
4651 ? GOT_TYPE_TLS_OFFSET
4652 : GOT_TYPE_TLS_PAIR
);
4653 unsigned int got_offset
;
4656 gold_assert(gsym
->has_got_offset(got_type
));
4657 got_offset
= gsym
->got_offset(got_type
) - target
->got_size();
4661 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4662 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
4663 got_offset
= (object
->local_got_offset(r_sym
, got_type
)
4664 - target
->got_size());
4666 if (optimized_type
== tls::TLSOPT_TO_IE
)
4668 value
= target
->got_plt_section()->address() + got_offset
;
4669 this->tls_gd_to_ie(relinfo
, relnum
, rela
, r_type
,
4670 value
, view
, address
, view_size
);
4673 else if (optimized_type
== tls::TLSOPT_NONE
)
4675 // Relocate the field with the offset of the pair of GOT
4677 value
= target
->got_plt_section()->address() + got_offset
;
4678 Relocate_functions
<size
, false>::pcrela32(view
, value
, addend
,
4683 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4684 _("unsupported reloc %u"), r_type
);
4687 case elfcpp::R_X86_64_GOTPC32_TLSDESC
: // Global-dynamic (from ~oliva url)
4688 case elfcpp::R_X86_64_TLSDESC_CALL
:
4689 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
4691 // See above comment for R_X86_64_TLSGD.
4692 optimized_type
= tls::TLSOPT_NONE
;
4694 if (optimized_type
== tls::TLSOPT_TO_LE
)
4696 if (tls_segment
== NULL
)
4698 gold_assert(parameters
->errors()->error_count() > 0
4699 || issue_undefined_symbol_error(gsym
));
4702 this->tls_desc_gd_to_le(relinfo
, relnum
, tls_segment
,
4703 rela
, r_type
, value
, view
,
4709 unsigned int got_type
= (optimized_type
== tls::TLSOPT_TO_IE
4710 ? GOT_TYPE_TLS_OFFSET
4711 : GOT_TYPE_TLS_DESC
);
4712 unsigned int got_offset
= 0;
4713 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
4714 && optimized_type
== tls::TLSOPT_NONE
)
4716 // We created GOT entries in the .got.tlsdesc portion of
4717 // the .got.plt section, but the offset stored in the
4718 // symbol is the offset within .got.tlsdesc.
4719 got_offset
= (target
->got_size()
4720 + target
->got_plt_section()->data_size());
4724 gold_assert(gsym
->has_got_offset(got_type
));
4725 got_offset
+= gsym
->got_offset(got_type
) - target
->got_size();
4729 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4730 gold_assert(object
->local_has_got_offset(r_sym
, got_type
));
4731 got_offset
+= (object
->local_got_offset(r_sym
, got_type
)
4732 - target
->got_size());
4734 if (optimized_type
== tls::TLSOPT_TO_IE
)
4736 value
= target
->got_plt_section()->address() + got_offset
;
4737 this->tls_desc_gd_to_ie(relinfo
, relnum
,
4738 rela
, r_type
, value
, view
, address
,
4742 else if (optimized_type
== tls::TLSOPT_NONE
)
4744 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
4746 // Relocate the field with the offset of the pair of GOT
4748 value
= target
->got_plt_section()->address() + got_offset
;
4749 Relocate_functions
<size
, false>::pcrela32(view
, value
, addend
,
4755 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4756 _("unsupported reloc %u"), r_type
);
4759 case elfcpp::R_X86_64_TLSLD
: // Local-dynamic
4760 if (!is_executable
&& optimized_type
== tls::TLSOPT_TO_LE
)
4762 // See above comment for R_X86_64_TLSGD.
4763 optimized_type
= tls::TLSOPT_NONE
;
4765 if (optimized_type
== tls::TLSOPT_TO_LE
)
4767 if (tls_segment
== NULL
)
4769 gold_assert(parameters
->errors()->error_count() > 0
4770 || issue_undefined_symbol_error(gsym
));
4773 this->tls_ld_to_le(relinfo
, relnum
, tls_segment
, rela
, r_type
,
4774 value
, view
, view_size
);
4777 else if (optimized_type
== tls::TLSOPT_NONE
)
4779 // Relocate the field with the offset of the GOT entry for
4780 // the module index.
4781 unsigned int got_offset
;
4782 got_offset
= (target
->got_mod_index_entry(NULL
, NULL
, NULL
)
4783 - target
->got_size());
4784 value
= target
->got_plt_section()->address() + got_offset
;
4785 Relocate_functions
<size
, false>::pcrela32(view
, value
, addend
,
4789 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4790 _("unsupported reloc %u"), r_type
);
4793 case elfcpp::R_X86_64_DTPOFF32
:
4794 // This relocation type is used in debugging information.
4795 // In that case we need to not optimize the value. If the
4796 // section is not executable, then we assume we should not
4797 // optimize this reloc. See comments above for R_X86_64_TLSGD,
4798 // R_X86_64_GOTPC32_TLSDESC, R_X86_64_TLSDESC_CALL, and
4800 if (optimized_type
== tls::TLSOPT_TO_LE
&& is_executable
)
4802 if (tls_segment
== NULL
)
4804 gold_assert(parameters
->errors()->error_count() > 0
4805 || issue_undefined_symbol_error(gsym
));
4808 value
-= tls_segment
->memsz();
4810 Relocate_functions
<size
, false>::rela32(view
, value
, addend
);
4813 case elfcpp::R_X86_64_DTPOFF64
:
4814 // See R_X86_64_DTPOFF32, just above, for why we check for is_executable.
4815 if (optimized_type
== tls::TLSOPT_TO_LE
&& is_executable
)
4817 if (tls_segment
== NULL
)
4819 gold_assert(parameters
->errors()->error_count() > 0
4820 || issue_undefined_symbol_error(gsym
));
4823 value
-= tls_segment
->memsz();
4825 Relocate_functions
<size
, false>::rela64(view
, value
, addend
);
4828 case elfcpp::R_X86_64_GOTTPOFF
: // Initial-exec
4830 && gsym
->is_undefined()
4831 && parameters
->options().output_is_executable())
4833 Target_x86_64
<size
>::Relocate::tls_ie_to_le(relinfo
, relnum
,
4835 r_type
, value
, view
,
4839 else if (optimized_type
== tls::TLSOPT_TO_LE
)
4841 if (tls_segment
== NULL
)
4843 gold_assert(parameters
->errors()->error_count() > 0
4844 || issue_undefined_symbol_error(gsym
));
4847 Target_x86_64
<size
>::Relocate::tls_ie_to_le(relinfo
, relnum
,
4849 r_type
, value
, view
,
4853 else if (optimized_type
== tls::TLSOPT_NONE
)
4855 // Relocate the field with the offset of the GOT entry for
4856 // the tp-relative offset of the symbol.
4857 unsigned int got_offset
;
4860 gold_assert(gsym
->has_got_offset(GOT_TYPE_TLS_OFFSET
));
4861 got_offset
= (gsym
->got_offset(GOT_TYPE_TLS_OFFSET
)
4862 - target
->got_size());
4866 unsigned int r_sym
= elfcpp::elf_r_sym
<size
>(rela
.get_r_info());
4867 gold_assert(object
->local_has_got_offset(r_sym
,
4868 GOT_TYPE_TLS_OFFSET
));
4869 got_offset
= (object
->local_got_offset(r_sym
, GOT_TYPE_TLS_OFFSET
)
4870 - target
->got_size());
4872 value
= target
->got_plt_section()->address() + got_offset
;
4873 Relocate_functions
<size
, false>::pcrela32(view
, value
, addend
,
4877 gold_error_at_location(relinfo
, relnum
, rela
.get_r_offset(),
4878 _("unsupported reloc type %u"),
4882 case elfcpp::R_X86_64_TPOFF32
: // Local-exec
4883 if (tls_segment
== NULL
)
4885 gold_assert(parameters
->errors()->error_count() > 0
4886 || issue_undefined_symbol_error(gsym
));
4889 value
-= tls_segment
->memsz();
4890 Relocate_functions
<size
, false>::rela32(view
, value
, addend
);
4895 // Do a relocation in which we convert a TLS General-Dynamic to an
4900 Target_x86_64
<size
>::Relocate::tls_gd_to_ie(
4901 const Relocate_info
<size
, false>* relinfo
,
4903 const elfcpp::Rela
<size
, false>& rela
,
4905 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
4906 unsigned char* view
,
4907 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
4908 section_size_type view_size
)
4911 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
4912 // .word 0x6666; rex64; call __tls_get_addr@PLT
4913 // ==> movq %fs:0,%rax; addq x@gottpoff(%rip),%rax
4914 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
4915 // .word 0x66; rex64; call *__tls_get_addr@GOTPCREL(%rip)
4916 // ==> movq %fs:0,%rax; addq x@gottpoff(%rip),%rax
4918 // leaq foo@tlsgd(%rip),%rdi;
4919 // .word 0x6666; rex64; call __tls_get_addr@PLT
4920 // ==> movl %fs:0,%eax; addq x@gottpoff(%rip),%rax
4921 // leaq foo@tlsgd(%rip),%rdi;
4922 // .word 0x66; rex64; call *__tls_get_addr@GOTPCREL(%rip)
4923 // ==> movl %fs:0,%eax; addq x@gottpoff(%rip),%rax
4925 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 12);
4926 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
4927 (memcmp(view
+ 4, "\x66\x66\x48\xe8", 4) == 0
4928 || memcmp(view
+ 4, "\x66\x48\xff", 3) == 0));
4932 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
,
4934 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
4935 (memcmp(view
- 4, "\x66\x48\x8d\x3d", 4) == 0));
4936 memcpy(view
- 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0\0",
4941 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
,
4943 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
4944 (memcmp(view
- 3, "\x48\x8d\x3d", 3) == 0));
4945 memcpy(view
- 3, "\x64\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0\0",
4949 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
4950 Relocate_functions
<size
, false>::pcrela32(view
+ 8, value
, addend
- 8,
4953 // The next reloc should be a PLT32 reloc against __tls_get_addr.
4955 this->skip_call_tls_get_addr_
= true;
4958 // Do a relocation in which we convert a TLS General-Dynamic to a
4963 Target_x86_64
<size
>::Relocate::tls_gd_to_le(
4964 const Relocate_info
<size
, false>* relinfo
,
4966 Output_segment
* tls_segment
,
4967 const elfcpp::Rela
<size
, false>& rela
,
4969 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
4970 unsigned char* view
,
4971 section_size_type view_size
)
4974 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
4975 // .word 0x6666; rex64; call __tls_get_addr@PLT
4976 // ==> movq %fs:0,%rax; leaq x@tpoff(%rax),%rax
4977 // .byte 0x66; leaq foo@tlsgd(%rip),%rdi;
4978 // .word 0x66; rex64; call *__tls_get_addr@GOTPCREL(%rip)
4979 // ==> movq %fs:0,%rax; leaq x@tpoff(%rax),%rax
4981 // leaq foo@tlsgd(%rip),%rdi;
4982 // .word 0x6666; rex64; call __tls_get_addr@PLT
4983 // ==> movl %fs:0,%eax; leaq x@tpoff(%rax),%rax
4984 // leaq foo@tlsgd(%rip),%rdi;
4985 // .word 0x66; rex64; call *__tls_get_addr@GOTPCREL(%rip)
4986 // ==> movl %fs:0,%eax; leaq x@tpoff(%rax),%rax
4988 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 12);
4989 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
4990 (memcmp(view
+ 4, "\x66\x66\x48\xe8", 4) == 0
4991 || memcmp(view
+ 4, "\x66\x48\xff", 3) == 0));
4995 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
,
4997 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
4998 (memcmp(view
- 4, "\x66\x48\x8d\x3d", 4) == 0));
4999 memcpy(view
- 4, "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0\0",
5004 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
,
5006 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5007 (memcmp(view
- 3, "\x48\x8d\x3d", 3) == 0));
5009 memcpy(view
- 3, "\x64\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0\0",
5013 value
-= tls_segment
->memsz();
5014 Relocate_functions
<size
, false>::rela32(view
+ 8, value
, 0);
5016 // The next reloc should be a PLT32 reloc against __tls_get_addr.
5018 this->skip_call_tls_get_addr_
= true;
5021 // Do a TLSDESC-style General-Dynamic to Initial-Exec transition.
5025 Target_x86_64
<size
>::Relocate::tls_desc_gd_to_ie(
5026 const Relocate_info
<size
, false>* relinfo
,
5028 const elfcpp::Rela
<size
, false>& rela
,
5029 unsigned int r_type
,
5030 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
5031 unsigned char* view
,
5032 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
5033 section_size_type view_size
)
5035 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
5037 // LP64: leaq foo@tlsdesc(%rip), %rax
5038 // ==> movq foo@gottpoff(%rip), %rax
5039 // X32: rex leal foo@tlsdesc(%rip), %eax
5040 // ==> rex movl foo@gottpoff(%rip), %eax
5041 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
5042 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
5043 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5044 (((view
[-3] & 0xfb) == 0x48
5045 || (size
== 32 && (view
[-3] & 0xfb) == 0x40))
5047 && (view
[-1] & 0xc7) == 0x05));
5049 const elfcpp::Elf_Xword addend
= rela
.get_r_addend();
5050 Relocate_functions
<size
, false>::pcrela32(view
, value
, addend
, address
);
5054 // LP64: call *foo@tlscall(%rax)
5055 // ==> xchg %ax, %ax
5056 // X32: call *foo@tlscall(%eax)
5058 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC_CALL
);
5059 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 2);
5061 if (size
== 32 && view
[0] == 0x67)
5063 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(),
5067 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5068 view
[prefix
] == 0xff && view
[prefix
+ 1] == 0x10);
5083 // Do a TLSDESC-style General-Dynamic to Local-Exec transition.
5087 Target_x86_64
<size
>::Relocate::tls_desc_gd_to_le(
5088 const Relocate_info
<size
, false>* relinfo
,
5090 Output_segment
* tls_segment
,
5091 const elfcpp::Rela
<size
, false>& rela
,
5092 unsigned int r_type
,
5093 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
5094 unsigned char* view
,
5095 section_size_type view_size
)
5097 if (r_type
== elfcpp::R_X86_64_GOTPC32_TLSDESC
)
5099 // LP64: leaq foo@tlsdesc(%rip), %rax
5100 // ==> movq foo@tpoff, %rax
5101 // X32: rex leal foo@tlsdesc(%rip), %eax
5102 // ==> rex movl foo@tpoff, %eax
5103 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
5104 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
5105 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5106 (((view
[-3] & 0xfb) == 0x48
5107 || (size
== 32 && (view
[-3] & 0xfb) == 0x40))
5109 && (view
[-1] & 0xc7) == 0x05));
5110 view
[-3] = (view
[-3] & 0x48) | ((view
[-3] >> 2) & 1);
5112 view
[-1] = 0xc0 | ((view
[-1] >> 3) & 7);
5113 value
-= tls_segment
->memsz();
5114 Relocate_functions
<size
, false>::rela32(view
, value
, 0);
5118 // LP64: call *foo@tlscall(%rax)
5119 // ==> xchg %ax, %ax
5120 // X32: call *foo@tlscall(%eax)
5122 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC_CALL
);
5123 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 2);
5125 if (size
== 32 && view
[0] == 0x67)
5127 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(),
5131 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5132 view
[prefix
] == 0xff && view
[prefix
+ 1] == 0x10);
5149 Target_x86_64
<size
>::Relocate::tls_ld_to_le(
5150 const Relocate_info
<size
, false>* relinfo
,
5153 const elfcpp::Rela
<size
, false>& rela
,
5155 typename
elfcpp::Elf_types
<size
>::Elf_Addr
,
5156 unsigned char* view
,
5157 section_size_type view_size
)
5159 // leaq foo@tlsld(%rip),%rdi; call __tls_get_addr@plt;
5161 // ... leq foo@dtpoff(%rax),%reg
5162 // ==> .word 0x6666; .byte 0x66; movq %fs:0,%rax ... leaq x@tpoff(%rax),%rdx
5164 // ... leq foo@dtpoff(%rax),%reg
5165 // ==> nopl 0x0(%rax); movl %fs:0,%eax ... leaq x@tpoff(%rax),%rdx
5166 // leaq foo@tlsld(%rip),%rdi; call *__tls_get_addr@GOTPCREL(%rip)
5168 // ... leq foo@dtpoff(%rax),%reg
5169 // ==> .word 0x6666; .byte 0x6666; movq %fs:0,%rax ... leaq x@tpoff(%rax),%rdx
5171 // ... leq foo@dtpoff(%rax),%reg
5172 // ==> nopw 0x0(%rax); movl %fs:0,%eax ... leaq x@tpoff(%rax),%rdx
5174 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
5175 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 9);
5177 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5178 view
[-3] == 0x48 && view
[-2] == 0x8d && view
[-1] == 0x3d);
5180 tls::check_tls(relinfo
, relnum
, rela
.get_r_offset(),
5181 view
[4] == 0xe8 || view
[4] == 0xff);
5183 if (view
[4] == 0xe8)
5186 memcpy(view
- 3, "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0\0", 12);
5188 memcpy(view
- 3, "\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0\0", 12);
5193 memcpy(view
- 3, "\x66\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0\0",
5196 memcpy(view
- 3, "\x66\x0f\x1f\x40\x00\x64\x8b\x04\x25\0\0\0\0",
5200 // The next reloc should be a PLT32 reloc against __tls_get_addr.
5202 this->skip_call_tls_get_addr_
= true;
5205 // Do a relocation in which we convert a TLS Initial-Exec to a
5210 Target_x86_64
<size
>::Relocate::tls_ie_to_le(
5211 const Relocate_info
<size
, false>* relinfo
,
5213 Output_segment
* tls_segment
,
5214 const elfcpp::Rela
<size
, false>& rela
,
5216 typename
elfcpp::Elf_types
<size
>::Elf_Addr value
,
5217 unsigned char* view
,
5218 section_size_type view_size
)
5220 // We need to examine the opcodes to figure out which instruction we
5223 // movq foo@gottpoff(%rip),%reg ==> movq $YY,%reg
5224 // addq foo@gottpoff(%rip),%reg ==> addq $YY,%reg
5226 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, -3);
5227 tls::check_range(relinfo
, relnum
, rela
.get_r_offset(), view_size
, 4);
5229 unsigned char op1
= view
[-3];
5230 unsigned char op2
= view
[-2];
5231 unsigned char op3
= view
[-1];
5232 unsigned char reg
= op3
>> 3;
5239 else if (size
== 32 && op1
== 0x44)
5242 view
[-1] = 0xc0 | reg
;
5246 // Special handling for %rsp.
5249 else if (size
== 32 && op1
== 0x44)
5252 view
[-1] = 0xc0 | reg
;
5259 else if (size
== 32 && op1
== 0x44)
5262 view
[-1] = 0x80 | reg
| (reg
<< 3);
5265 if (tls_segment
!= NULL
)
5266 value
-= tls_segment
->memsz();
5267 Relocate_functions
<size
, false>::rela32(view
, value
, 0);
5270 // Relocate section data.
5274 Target_x86_64
<size
>::relocate_section(
5275 const Relocate_info
<size
, false>* relinfo
,
5276 unsigned int sh_type
,
5277 const unsigned char* prelocs
,
5279 Output_section
* output_section
,
5280 bool needs_special_offset_handling
,
5281 unsigned char* view
,
5282 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
5283 section_size_type view_size
,
5284 const Reloc_symbol_changes
* reloc_symbol_changes
)
5286 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
5289 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5291 gold::relocate_section
<size
, false, Target_x86_64
<size
>, Relocate
,
5292 gold::Default_comdat_behavior
, Classify_reloc
>(
5298 needs_special_offset_handling
,
5302 reloc_symbol_changes
);
5305 // Apply an incremental relocation. Incremental relocations always refer
5306 // to global symbols.
5310 Target_x86_64
<size
>::apply_relocation(
5311 const Relocate_info
<size
, false>* relinfo
,
5312 typename
elfcpp::Elf_types
<size
>::Elf_Addr r_offset
,
5313 unsigned int r_type
,
5314 typename
elfcpp::Elf_types
<size
>::Elf_Swxword r_addend
,
5316 unsigned char* view
,
5317 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
,
5318 section_size_type view_size
)
5320 gold::apply_relocation
<size
, false, Target_x86_64
<size
>,
5321 typename Target_x86_64
<size
>::Relocate
>(
5333 // Scan the relocs during a relocatable link.
5337 Target_x86_64
<size
>::scan_relocatable_relocs(
5338 Symbol_table
* symtab
,
5340 Sized_relobj_file
<size
, false>* object
,
5341 unsigned int data_shndx
,
5342 unsigned int sh_type
,
5343 const unsigned char* prelocs
,
5345 Output_section
* output_section
,
5346 bool needs_special_offset_handling
,
5347 size_t local_symbol_count
,
5348 const unsigned char* plocal_symbols
,
5349 Relocatable_relocs
* rr
)
5351 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
5353 typedef gold::Default_scan_relocatable_relocs
<Classify_reloc
>
5354 Scan_relocatable_relocs
;
5356 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5358 gold::scan_relocatable_relocs
<size
, false, Scan_relocatable_relocs
>(
5366 needs_special_offset_handling
,
5372 // Scan the relocs for --emit-relocs.
5376 Target_x86_64
<size
>::emit_relocs_scan(
5377 Symbol_table
* symtab
,
5379 Sized_relobj_file
<size
, false>* object
,
5380 unsigned int data_shndx
,
5381 unsigned int sh_type
,
5382 const unsigned char* prelocs
,
5384 Output_section
* output_section
,
5385 bool needs_special_offset_handling
,
5386 size_t local_symbol_count
,
5387 const unsigned char* plocal_syms
,
5388 Relocatable_relocs
* rr
)
5390 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
5392 typedef gold::Default_emit_relocs_strategy
<Classify_reloc
>
5393 Emit_relocs_strategy
;
5395 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5397 gold::scan_relocatable_relocs
<size
, false, Emit_relocs_strategy
>(
5405 needs_special_offset_handling
,
5411 // Relocate a section during a relocatable link.
5415 Target_x86_64
<size
>::relocate_relocs(
5416 const Relocate_info
<size
, false>* relinfo
,
5417 unsigned int sh_type
,
5418 const unsigned char* prelocs
,
5420 Output_section
* output_section
,
5421 typename
elfcpp::Elf_types
<size
>::Elf_Off offset_in_output_section
,
5422 unsigned char* view
,
5423 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
5424 section_size_type view_size
,
5425 unsigned char* reloc_view
,
5426 section_size_type reloc_view_size
)
5428 typedef gold::Default_classify_reloc
<elfcpp::SHT_RELA
, size
, false>
5431 gold_assert(sh_type
== elfcpp::SHT_RELA
);
5433 gold::relocate_relocs
<size
, false, Classify_reloc
>(
5438 offset_in_output_section
,
5446 // Return the value to use for a dynamic which requires special
5447 // treatment. This is how we support equality comparisons of function
5448 // pointers across shared library boundaries, as described in the
5449 // processor specific ABI supplement.
5453 Target_x86_64
<size
>::do_dynsym_value(const Symbol
* gsym
) const
5455 gold_assert(gsym
->is_from_dynobj() && gsym
->has_plt_offset());
5456 return this->plt_address_for_global(gsym
);
5459 // Return a string used to fill a code section with nops to take up
5460 // the specified length.
5464 Target_x86_64
<size
>::do_code_fill(section_size_type length
) const
5468 // Build a jmpq instruction to skip over the bytes.
5469 unsigned char jmp
[5];
5471 elfcpp::Swap_unaligned
<32, false>::writeval(jmp
+ 1, length
- 5);
5472 return (std::string(reinterpret_cast<char*>(&jmp
[0]), 5)
5473 + std::string(length
- 5, static_cast<char>(0x90)));
5476 // Nop sequences of various lengths.
5477 const char nop1
[1] = { '\x90' }; // nop
5478 const char nop2
[2] = { '\x66', '\x90' }; // xchg %ax %ax
5479 const char nop3
[3] = { '\x0f', '\x1f', '\x00' }; // nop (%rax)
5480 const char nop4
[4] = { '\x0f', '\x1f', '\x40', // nop 0(%rax)
5482 const char nop5
[5] = { '\x0f', '\x1f', '\x44', // nop 0(%rax,%rax,1)
5484 const char nop6
[6] = { '\x66', '\x0f', '\x1f', // nopw 0(%rax,%rax,1)
5485 '\x44', '\x00', '\x00' };
5486 const char nop7
[7] = { '\x0f', '\x1f', '\x80', // nopl 0L(%rax)
5487 '\x00', '\x00', '\x00',
5489 const char nop8
[8] = { '\x0f', '\x1f', '\x84', // nopl 0L(%rax,%rax,1)
5490 '\x00', '\x00', '\x00',
5492 const char nop9
[9] = { '\x66', '\x0f', '\x1f', // nopw 0L(%rax,%rax,1)
5493 '\x84', '\x00', '\x00',
5494 '\x00', '\x00', '\x00' };
5495 const char nop10
[10] = { '\x66', '\x2e', '\x0f', // nopw %cs:0L(%rax,%rax,1)
5496 '\x1f', '\x84', '\x00',
5497 '\x00', '\x00', '\x00',
5499 const char nop11
[11] = { '\x66', '\x66', '\x2e', // data16
5500 '\x0f', '\x1f', '\x84', // nopw %cs:0L(%rax,%rax,1)
5501 '\x00', '\x00', '\x00',
5503 const char nop12
[12] = { '\x66', '\x66', '\x66', // data16; data16
5504 '\x2e', '\x0f', '\x1f', // nopw %cs:0L(%rax,%rax,1)
5505 '\x84', '\x00', '\x00',
5506 '\x00', '\x00', '\x00' };
5507 const char nop13
[13] = { '\x66', '\x66', '\x66', // data16; data16; data16
5508 '\x66', '\x2e', '\x0f', // nopw %cs:0L(%rax,%rax,1)
5509 '\x1f', '\x84', '\x00',
5510 '\x00', '\x00', '\x00',
5512 const char nop14
[14] = { '\x66', '\x66', '\x66', // data16; data16; data16
5513 '\x66', '\x66', '\x2e', // data16
5514 '\x0f', '\x1f', '\x84', // nopw %cs:0L(%rax,%rax,1)
5515 '\x00', '\x00', '\x00',
5517 const char nop15
[15] = { '\x66', '\x66', '\x66', // data16; data16; data16
5518 '\x66', '\x66', '\x66', // data16; data16
5519 '\x2e', '\x0f', '\x1f', // nopw %cs:0L(%rax,%rax,1)
5520 '\x84', '\x00', '\x00',
5521 '\x00', '\x00', '\x00' };
5523 const char* nops
[16] = {
5525 nop1
, nop2
, nop3
, nop4
, nop5
, nop6
, nop7
,
5526 nop8
, nop9
, nop10
, nop11
, nop12
, nop13
, nop14
, nop15
5529 return std::string(nops
[length
], length
);
5532 // Return the addend to use for a target specific relocation. The
5533 // only target specific relocation is R_X86_64_TLSDESC for a local
5534 // symbol. We want to set the addend is the offset of the local
5535 // symbol in the TLS segment.
5539 Target_x86_64
<size
>::do_reloc_addend(void* arg
, unsigned int r_type
,
5542 gold_assert(r_type
== elfcpp::R_X86_64_TLSDESC
);
5543 uintptr_t intarg
= reinterpret_cast<uintptr_t>(arg
);
5544 gold_assert(intarg
< this->tlsdesc_reloc_info_
.size());
5545 const Tlsdesc_info
& ti(this->tlsdesc_reloc_info_
[intarg
]);
5546 const Symbol_value
<size
>* psymval
= ti
.object
->local_symbol(ti
.r_sym
);
5547 gold_assert(psymval
->is_tls_symbol());
5548 // The value of a TLS symbol is the offset in the TLS segment.
5549 return psymval
->value(ti
.object
, 0);
5552 // Return the value to use for the base of a DW_EH_PE_datarel offset
5553 // in an FDE. Solaris and SVR4 use DW_EH_PE_datarel because their
5554 // assembler can not write out the difference between two labels in
5555 // different sections, so instead of using a pc-relative value they
5556 // use an offset from the GOT.
5560 Target_x86_64
<size
>::do_ehframe_datarel_base() const
5562 gold_assert(this->global_offset_table_
!= NULL
);
5563 Symbol
* sym
= this->global_offset_table_
;
5564 Sized_symbol
<size
>* ssym
= static_cast<Sized_symbol
<size
>*>(sym
);
5565 return ssym
->value();
5568 // FNOFFSET in section SHNDX in OBJECT is the start of a function
5569 // compiled with -fsplit-stack. The function calls non-split-stack
5570 // code. We have to change the function so that it always ensures
5571 // that it has enough stack space to run some random function.
5573 static const unsigned char cmp_insn_32
[] = { 0x64, 0x3b, 0x24, 0x25 };
5574 static const unsigned char lea_r10_insn_32
[] = { 0x44, 0x8d, 0x94, 0x24 };
5575 static const unsigned char lea_r11_insn_32
[] = { 0x44, 0x8d, 0x9c, 0x24 };
5577 static const unsigned char cmp_insn_64
[] = { 0x64, 0x48, 0x3b, 0x24, 0x25 };
5578 static const unsigned char lea_r10_insn_64
[] = { 0x4c, 0x8d, 0x94, 0x24 };
5579 static const unsigned char lea_r11_insn_64
[] = { 0x4c, 0x8d, 0x9c, 0x24 };
5583 Target_x86_64
<size
>::do_calls_non_split(Relobj
* object
, unsigned int shndx
,
5584 section_offset_type fnoffset
,
5585 section_size_type fnsize
,
5586 const unsigned char*,
5588 unsigned char* view
,
5589 section_size_type view_size
,
5591 std::string
* to
) const
5593 const char* const cmp_insn
= reinterpret_cast<const char*>
5594 (size
== 32 ? cmp_insn_32
: cmp_insn_64
);
5595 const char* const lea_r10_insn
= reinterpret_cast<const char*>
5596 (size
== 32 ? lea_r10_insn_32
: lea_r10_insn_64
);
5597 const char* const lea_r11_insn
= reinterpret_cast<const char*>
5598 (size
== 32 ? lea_r11_insn_32
: lea_r11_insn_64
);
5600 const size_t cmp_insn_len
=
5601 (size
== 32 ? sizeof(cmp_insn_32
) : sizeof(cmp_insn_64
));
5602 const size_t lea_r10_insn_len
=
5603 (size
== 32 ? sizeof(lea_r10_insn_32
) : sizeof(lea_r10_insn_64
));
5604 const size_t lea_r11_insn_len
=
5605 (size
== 32 ? sizeof(lea_r11_insn_32
) : sizeof(lea_r11_insn_64
));
5606 const size_t nop_len
= (size
== 32 ? 7 : 8);
5608 // The function starts with a comparison of the stack pointer and a
5609 // field in the TCB. This is followed by a jump.
5612 if (this->match_view(view
, view_size
, fnoffset
, cmp_insn
, cmp_insn_len
)
5613 && fnsize
> nop_len
+ 1)
5615 // We will call __morestack if the carry flag is set after this
5616 // comparison. We turn the comparison into an stc instruction
5618 view
[fnoffset
] = '\xf9';
5619 this->set_view_to_nop(view
, view_size
, fnoffset
+ 1, nop_len
);
5621 // lea NN(%rsp),%r10
5622 // lea NN(%rsp),%r11
5623 else if ((this->match_view(view
, view_size
, fnoffset
,
5624 lea_r10_insn
, lea_r10_insn_len
)
5625 || this->match_view(view
, view_size
, fnoffset
,
5626 lea_r11_insn
, lea_r11_insn_len
))
5629 // This is loading an offset from the stack pointer for a
5630 // comparison. The offset is negative, so we decrease the
5631 // offset by the amount of space we need for the stack. This
5632 // means we will avoid calling __morestack if there happens to
5633 // be plenty of space on the stack already.
5634 unsigned char* pval
= view
+ fnoffset
+ 4;
5635 uint32_t val
= elfcpp::Swap_unaligned
<32, false>::readval(pval
);
5636 val
-= parameters
->options().split_stack_adjust_size();
5637 elfcpp::Swap_unaligned
<32, false>::writeval(pval
, val
);
5641 if (!object
->has_no_split_stack())
5642 object
->error(_("failed to match split-stack sequence at "
5643 "section %u offset %0zx"),
5644 shndx
, static_cast<size_t>(fnoffset
));
5648 // We have to change the function so that it calls
5649 // __morestack_non_split instead of __morestack. The former will
5650 // allocate additional stack space.
5651 *from
= "__morestack";
5652 *to
= "__morestack_non_split";
5655 // The selector for x86_64 object files. Note this is never instantiated
5656 // directly. It's only used in Target_selector_x86_64_nacl, below.
5659 class Target_selector_x86_64
: public Target_selector_freebsd
5662 Target_selector_x86_64()
5663 : Target_selector_freebsd(elfcpp::EM_X86_64
, size
, false,
5665 ? "elf64-x86-64" : "elf32-x86-64"),
5667 ? "elf64-x86-64-freebsd"
5668 : "elf32-x86-64-freebsd"),
5669 (size
== 64 ? "elf_x86_64" : "elf32_x86_64"))
5673 do_instantiate_target()
5674 { return new Target_x86_64
<size
>(); }
5678 // NaCl variant. It uses different PLT contents.
5681 class Output_data_plt_x86_64_nacl
: public Output_data_plt_x86_64
<size
>
5684 Output_data_plt_x86_64_nacl(Layout
* layout
,
5685 Output_data_got
<64, false>* got
,
5686 Output_data_got_plt_x86_64
* got_plt
,
5687 Output_data_space
* got_irelative
)
5688 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
5689 got
, got_plt
, got_irelative
)
5692 Output_data_plt_x86_64_nacl(Layout
* layout
,
5693 Output_data_got
<64, false>* got
,
5694 Output_data_got_plt_x86_64
* got_plt
,
5695 Output_data_space
* got_irelative
,
5696 unsigned int plt_count
)
5697 : Output_data_plt_x86_64
<size
>(layout
, plt_entry_size
,
5698 got
, got_plt
, got_irelative
,
5703 virtual unsigned int
5704 do_get_plt_entry_size() const
5705 { return plt_entry_size
; }
5708 do_add_eh_frame(Layout
* layout
)
5710 layout
->add_eh_frame_for_plt(this,
5711 this->plt_eh_frame_cie
,
5712 this->plt_eh_frame_cie_size
,
5714 plt_eh_frame_fde_size
);
5718 do_fill_first_plt_entry(unsigned char* pov
,
5719 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_addr
,
5720 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_addr
);
5722 virtual unsigned int
5723 do_fill_plt_entry(unsigned char* pov
,
5724 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
5725 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
5726 unsigned int got_offset
,
5727 unsigned int plt_offset
,
5728 unsigned int plt_index
);
5731 do_fill_tlsdesc_entry(unsigned char* pov
,
5732 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
5733 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
5734 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
5735 unsigned int tlsdesc_got_offset
,
5736 unsigned int plt_offset
);
5739 // The size of an entry in the PLT.
5740 static const int plt_entry_size
= 64;
5742 // The first entry in the PLT.
5743 static const unsigned char first_plt_entry
[plt_entry_size
];
5745 // Other entries in the PLT for an executable.
5746 static const unsigned char plt_entry
[plt_entry_size
];
5748 // The reserved TLSDESC entry in the PLT for an executable.
5749 static const unsigned char tlsdesc_plt_entry
[plt_entry_size
];
5751 // The .eh_frame unwind information for the PLT.
5752 static const int plt_eh_frame_fde_size
= 32;
5753 static const unsigned char plt_eh_frame_fde
[plt_eh_frame_fde_size
];
5757 class Target_x86_64_nacl
: public Target_x86_64
<size
>
5760 Target_x86_64_nacl()
5761 : Target_x86_64
<size
>(&x86_64_nacl_info
)
5764 virtual Output_data_plt_x86_64
<size
>*
5765 do_make_data_plt(Layout
* layout
,
5766 Output_data_got
<64, false>* got
,
5767 Output_data_got_plt_x86_64
* got_plt
,
5768 Output_data_space
* got_irelative
)
5770 return new Output_data_plt_x86_64_nacl
<size
>(layout
, got
, got_plt
,
5774 virtual Output_data_plt_x86_64
<size
>*
5775 do_make_data_plt(Layout
* layout
,
5776 Output_data_got
<64, false>* got
,
5777 Output_data_got_plt_x86_64
* got_plt
,
5778 Output_data_space
* got_irelative
,
5779 unsigned int plt_count
)
5781 return new Output_data_plt_x86_64_nacl
<size
>(layout
, got
, got_plt
,
5787 do_code_fill(section_size_type length
) const;
5790 static const Target::Target_info x86_64_nacl_info
;
5794 const Target::Target_info Target_x86_64_nacl
<64>::x86_64_nacl_info
=
5797 false, // is_big_endian
5798 elfcpp::EM_X86_64
, // machine_code
5799 false, // has_make_symbol
5800 false, // has_resolve
5801 true, // has_code_fill
5802 true, // is_default_stack_executable
5803 true, // can_icf_inline_merge_sections
5805 "/lib64/ld-nacl-x86-64.so.1", // dynamic_linker
5806 0x20000, // default_text_segment_address
5807 0x10000, // abi_pagesize (overridable by -z max-page-size)
5808 0x10000, // common_pagesize (overridable by -z common-page-size)
5809 true, // isolate_execinstr
5810 0x10000000, // rosegment_gap
5811 elfcpp::SHN_UNDEF
, // small_common_shndx
5812 elfcpp::SHN_X86_64_LCOMMON
, // large_common_shndx
5813 0, // small_common_section_flags
5814 elfcpp::SHF_X86_64_LARGE
, // large_common_section_flags
5815 NULL
, // attributes_section
5816 NULL
, // attributes_vendor
5817 "_start", // entry_symbol_name
5818 32, // hash_entry_size
5819 elfcpp::SHT_X86_64_UNWIND
, // unwind_section_type
5823 const Target::Target_info Target_x86_64_nacl
<32>::x86_64_nacl_info
=
5826 false, // is_big_endian
5827 elfcpp::EM_X86_64
, // machine_code
5828 false, // has_make_symbol
5829 false, // has_resolve
5830 true, // has_code_fill
5831 true, // is_default_stack_executable
5832 true, // can_icf_inline_merge_sections
5834 "/lib/ld-nacl-x86-64.so.1", // dynamic_linker
5835 0x20000, // default_text_segment_address
5836 0x10000, // abi_pagesize (overridable by -z max-page-size)
5837 0x10000, // common_pagesize (overridable by -z common-page-size)
5838 true, // isolate_execinstr
5839 0x10000000, // rosegment_gap
5840 elfcpp::SHN_UNDEF
, // small_common_shndx
5841 elfcpp::SHN_X86_64_LCOMMON
, // large_common_shndx
5842 0, // small_common_section_flags
5843 elfcpp::SHF_X86_64_LARGE
, // large_common_section_flags
5844 NULL
, // attributes_section
5845 NULL
, // attributes_vendor
5846 "_start", // entry_symbol_name
5847 32, // hash_entry_size
5848 elfcpp::SHT_X86_64_UNWIND
, // unwind_section_type
5851 #define NACLMASK 0xe0 // 32-byte alignment mask.
5853 // The first entry in the PLT.
5857 Output_data_plt_x86_64_nacl
<size
>::first_plt_entry
[plt_entry_size
] =
5859 0xff, 0x35, // pushq contents of memory address
5860 0, 0, 0, 0, // replaced with address of .got + 8
5861 0x4c, 0x8b, 0x1d, // mov GOT+16(%rip), %r11
5862 0, 0, 0, 0, // replaced with address of .got + 16
5863 0x41, 0x83, 0xe3, NACLMASK
, // and $-32, %r11d
5864 0x4d, 0x01, 0xfb, // add %r15, %r11
5865 0x41, 0xff, 0xe3, // jmpq *%r11
5867 // 9-byte nop sequence to pad out to the next 32-byte boundary.
5868 0x66, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw 0x0(%rax,%rax,1)
5870 // 32 bytes of nop to pad out to the standard size
5871 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5872 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5873 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5874 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5875 0x66, // excess data32 prefix
5881 Output_data_plt_x86_64_nacl
<size
>::do_fill_first_plt_entry(
5883 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
5884 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
)
5886 memcpy(pov
, first_plt_entry
, plt_entry_size
);
5887 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
5889 - (plt_address
+ 2 + 4)));
5890 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 9,
5892 - (plt_address
+ 9 + 4)));
5895 // Subsequent entries in the PLT.
5899 Output_data_plt_x86_64_nacl
<size
>::plt_entry
[plt_entry_size
] =
5901 0x4c, 0x8b, 0x1d, // mov name@GOTPCREL(%rip),%r11
5902 0, 0, 0, 0, // replaced with address of symbol in .got
5903 0x41, 0x83, 0xe3, NACLMASK
, // and $-32, %r11d
5904 0x4d, 0x01, 0xfb, // add %r15, %r11
5905 0x41, 0xff, 0xe3, // jmpq *%r11
5907 // 15-byte nop sequence to pad out to the next 32-byte boundary.
5908 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5909 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5911 // Lazy GOT entries point here (32-byte aligned).
5912 0x68, // pushq immediate
5913 0, 0, 0, 0, // replaced with index into relocation table
5914 0xe9, // jmp relative
5915 0, 0, 0, 0, // replaced with offset to start of .plt0
5917 // 22 bytes of nop to pad out to the standard size.
5918 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5919 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5920 0x0f, 0x1f, 0x80, 0, 0, 0, 0, // nopl 0x0(%rax)
5925 Output_data_plt_x86_64_nacl
<size
>::do_fill_plt_entry(
5927 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
5928 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
5929 unsigned int got_offset
,
5930 unsigned int plt_offset
,
5931 unsigned int plt_index
)
5933 memcpy(pov
, plt_entry
, plt_entry_size
);
5934 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 3,
5935 (got_address
+ got_offset
5936 - (plt_address
+ plt_offset
5939 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 33, plt_index
);
5940 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 38,
5941 - (plt_offset
+ 38 + 4));
5946 // The reserved TLSDESC entry in the PLT.
5950 Output_data_plt_x86_64_nacl
<size
>::tlsdesc_plt_entry
[plt_entry_size
] =
5952 0xff, 0x35, // pushq x(%rip)
5953 0, 0, 0, 0, // replaced with address of linkmap GOT entry (at PLTGOT + 8)
5954 0x4c, 0x8b, 0x1d, // mov y(%rip),%r11
5955 0, 0, 0, 0, // replaced with offset of reserved TLSDESC_GOT entry
5956 0x41, 0x83, 0xe3, NACLMASK
, // and $-32, %r11d
5957 0x4d, 0x01, 0xfb, // add %r15, %r11
5958 0x41, 0xff, 0xe3, // jmpq *%r11
5960 // 41 bytes of nop to pad out to the standard size.
5961 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5962 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5963 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, // excess data32 prefixes
5964 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5965 0x66, 0x66, // excess data32 prefixes
5966 0x2e, 0x0f, 0x1f, 0x84, 0, 0, 0, 0, 0, // nopw %cs:0x0(%rax,%rax,1)
5971 Output_data_plt_x86_64_nacl
<size
>::do_fill_tlsdesc_entry(
5973 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_address
,
5974 typename
elfcpp::Elf_types
<size
>::Elf_Addr plt_address
,
5975 typename
elfcpp::Elf_types
<size
>::Elf_Addr got_base
,
5976 unsigned int tlsdesc_got_offset
,
5977 unsigned int plt_offset
)
5979 memcpy(pov
, tlsdesc_plt_entry
, plt_entry_size
);
5980 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 2,
5982 - (plt_address
+ plt_offset
5984 elfcpp::Swap_unaligned
<32, false>::writeval(pov
+ 9,
5986 + tlsdesc_got_offset
5987 - (plt_address
+ plt_offset
5991 // The .eh_frame unwind information for the PLT.
5995 Output_data_plt_x86_64_nacl
<size
>::plt_eh_frame_fde
[plt_eh_frame_fde_size
] =
5997 0, 0, 0, 0, // Replaced with offset to .plt.
5998 0, 0, 0, 0, // Replaced with size of .plt.
5999 0, // Augmentation size.
6000 elfcpp::DW_CFA_def_cfa_offset
, 16, // DW_CFA_def_cfa_offset: 16.
6001 elfcpp::DW_CFA_advance_loc
+ 6, // Advance 6 to __PLT__ + 6.
6002 elfcpp::DW_CFA_def_cfa_offset
, 24, // DW_CFA_def_cfa_offset: 24.
6003 elfcpp::DW_CFA_advance_loc
+ 58, // Advance 58 to __PLT__ + 64.
6004 elfcpp::DW_CFA_def_cfa_expression
, // DW_CFA_def_cfa_expression.
6005 13, // Block length.
6006 elfcpp::DW_OP_breg7
, 8, // Push %rsp + 8.
6007 elfcpp::DW_OP_breg16
, 0, // Push %rip.
6008 elfcpp::DW_OP_const1u
, 63, // Push 0x3f.
6009 elfcpp::DW_OP_and
, // & (%rip & 0x3f).
6010 elfcpp::DW_OP_const1u
, 37, // Push 0x25.
6011 elfcpp::DW_OP_ge
, // >= ((%rip & 0x3f) >= 0x25)
6012 elfcpp::DW_OP_lit3
, // Push 3.
6013 elfcpp::DW_OP_shl
, // << (((%rip & 0x3f) >= 0x25) << 3)
6014 elfcpp::DW_OP_plus
, // + ((((%rip&0x3f)>=0x25)<<3)+%rsp+8
6015 elfcpp::DW_CFA_nop
, // Align to 32 bytes.
6019 // Return a string used to fill a code section with nops.
6020 // For NaCl, long NOPs are only valid if they do not cross
6021 // bundle alignment boundaries, so keep it simple with one-byte NOPs.
6024 Target_x86_64_nacl
<size
>::do_code_fill(section_size_type length
) const
6026 return std::string(length
, static_cast<char>(0x90));
6029 // The selector for x86_64-nacl object files.
6032 class Target_selector_x86_64_nacl
6033 : public Target_selector_nacl
<Target_selector_x86_64
<size
>,
6034 Target_x86_64_nacl
<size
> >
6037 Target_selector_x86_64_nacl()
6038 : Target_selector_nacl
<Target_selector_x86_64
<size
>,
6039 Target_x86_64_nacl
<size
> >("x86-64",
6041 ? "elf64-x86-64-nacl"
6042 : "elf32-x86-64-nacl",
6045 : "elf32_x86_64_nacl")
6049 Target_selector_x86_64_nacl
<64> target_selector_x86_64
;
6050 Target_selector_x86_64_nacl
<32> target_selector_x32
;
6052 } // End anonymous namespace.